From 88c4f1b16ad0b8867080d2be1ddd34156af276a0 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 12 Sep 2016 13:17:32 -0700 Subject: [PATCH] only remove spellcheck client when the main frame is invalidated add better logging fix https://github.com/brave/browser-laptop/issues/3904 auditors: @bbondy --- atom/common/javascript_bindings.cc | 23 +++++++++++-------- .../renderer/extensions/web_frame_bindings.cc | 17 +++++++++++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/atom/common/javascript_bindings.cc b/atom/common/javascript_bindings.cc index e7cf6203ca..18d199107a 100644 --- a/atom/common/javascript_bindings.cc +++ b/atom/common/javascript_bindings.cc @@ -11,6 +11,7 @@ #include "atom/common/native_mate_converters/value_converter.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_view.h" +#include "extensions/renderer/console.h" #include "native_mate/dictionary.h" #include "third_party/WebKit/public/web/WebView.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" @@ -51,21 +52,22 @@ v8::Local JavascriptBindings::GetHiddenValue(v8::Isolate* isolate, if (!is_valid() || !render_view()) return v8::Local(); - v8::Local context = + v8::Local main_context = render_view()->GetWebView()->mainFrame()->mainWorldScriptContext(); v8::Local privateKey = v8::Private::ForApi(isolate, key); v8::Local value; - v8::Local object = context->Global(); + v8::Local object = main_context->Global(); - if (!ContextCanAccessObject(context, context->Global(), false)) { - LOG(ERROR) << "cannot access global main"; + if (!ContextCanAccessObject(main_context, main_context->Global(), false)) { + extensions::console::Warn(context()->GetRenderFrame(), + "cannot access global in main frame script context"); return v8::Local(); } - v8::Maybe result = object->HasPrivate(context, privateKey); + v8::Maybe result = object->HasPrivate(main_context, privateKey); if (!(result.IsJust() && result.FromJust())) return v8::Local(); - if (object->GetPrivate(context, privateKey).ToLocal(&value)) + if (object->GetPrivate(main_context, privateKey).ToLocal(&value)) return value; return v8::Local(); } @@ -76,16 +78,17 @@ void JavascriptBindings::SetHiddenValue(v8::Isolate* isolate, if (!is_valid() || !render_view() || value.IsEmpty()) return; - v8::Local context = + v8::Local main_context = render_view()->GetWebView()->mainFrame()->mainWorldScriptContext(); - if (!ContextCanAccessObject(context, context->Global(), false)) { - LOG(ERROR) << "cannot access global main"; + if (!ContextCanAccessObject(main_context, main_context->Global(), false)) { + extensions::console::Warn(context()->GetRenderFrame(), + "cannot access global in main frame script context"); return; } v8::Local privateKey = v8::Private::ForApi(isolate, key); - context->Global()->SetPrivate(context, privateKey, value); + main_context->Global()->SetPrivate(main_context, privateKey, value); } void JavascriptBindings::IPCSend(mate::Arguments* args, diff --git a/brave/renderer/extensions/web_frame_bindings.cc b/brave/renderer/extensions/web_frame_bindings.cc index 178d5378da..07f0200bca 100644 --- a/brave/renderer/extensions/web_frame_bindings.cc +++ b/brave/renderer/extensions/web_frame_bindings.cc @@ -8,6 +8,7 @@ #include #include "base/strings/utf_string_conversions.h" +#include "extensions/renderer/console.h" #include "extensions/renderer/script_context.h" #include "third_party/WebKit/public/web/WebView.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" @@ -52,13 +53,22 @@ WebFrameBindings::~WebFrameBindings() { } void WebFrameBindings::Invalidate() { - context()->web_frame()->view()->setSpellCheckClient(nullptr); - spell_check_client_.reset(nullptr); + // only remove the spell check client when the main frame is invalidated + if (!context()->web_frame()->parent()) { + context()->web_frame()->view()->setSpellCheckClient(nullptr); + spell_check_client_.reset(nullptr); + } ObjectBackedNativeHandler::Invalidate(); } void WebFrameBindings::SetSpellCheckProvider( const v8::FunctionCallbackInfo& args) { + if (context()->web_frame()->parent()) { + extensions::console::Warn(context()->GetRenderFrame(), + "spellcheck provider can only be set by the main frame"); + return; + } + const std::string lang = mate::V8ToString(args[0].As()); bool auto_spell_correct_turned_on = args[1].As()->Value(); v8::Local provider = v8::Local::Cast(args[2]); @@ -100,7 +110,8 @@ void WebFrameBindings::SetGlobal( v8::Context::Scope context_scope(main_context); if (!ContextCanAccessObject(main_context, main_context->Global(), false)) { - LOG(ERROR) << "cannot access global main"; + extensions::console::Warn(context()->GetRenderFrame(), + "cannot access global in main frame script context"); return; }