Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
only remove spellcheck client when the main frame is invalidated
Browse files Browse the repository at this point in the history
add better logging
fix brave/browser-laptop#3904
auditors: @bbondy
  • Loading branch information
bridiver committed Sep 16, 2016
1 parent dd0acb1 commit 88c4f1b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
23 changes: 13 additions & 10 deletions atom/common/javascript_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,21 +52,22 @@ v8::Local<v8::Value> JavascriptBindings::GetHiddenValue(v8::Isolate* isolate,
if (!is_valid() || !render_view())
return v8::Local<v8::Value>();

v8::Local<v8::Context> context =
v8::Local<v8::Context> main_context =
render_view()->GetWebView()->mainFrame()->mainWorldScriptContext();
v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, key);
v8::Local<v8::Value> value;
v8::Local<v8::Object> object = context->Global();
v8::Local<v8::Object> 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::Value>();
}

v8::Maybe<bool> result = object->HasPrivate(context, privateKey);
v8::Maybe<bool> result = object->HasPrivate(main_context, privateKey);
if (!(result.IsJust() && result.FromJust()))
return v8::Local<v8::Value>();
if (object->GetPrivate(context, privateKey).ToLocal(&value))
if (object->GetPrivate(main_context, privateKey).ToLocal(&value))
return value;
return v8::Local<v8::Value>();
}
Expand All @@ -76,16 +78,17 @@ void JavascriptBindings::SetHiddenValue(v8::Isolate* isolate,
if (!is_valid() || !render_view() || value.IsEmpty())
return;

v8::Local<v8::Context> context =
v8::Local<v8::Context> 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<v8::Private> 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,
Expand Down
17 changes: 14 additions & 3 deletions brave/renderer/extensions/web_frame_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#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"
Expand Down Expand Up @@ -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<v8::Value>& 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<v8::String>());
bool auto_spell_correct_turned_on = args[1].As<v8::Boolean>()->Value();
v8::Local<v8::Object> provider = v8::Local<v8::Object>::Cast(args[2]);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 88c4f1b

Please sign in to comment.