| Index: extensions/renderer/dispatcher.cc
|
| diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc
|
| index cf4bb57884563c16530c38bf7769cb048d9faee6..e7d62477845eca014295a07bdffbd8031eb3fefb 100644
|
| --- a/extensions/renderer/dispatcher.cc
|
| +++ b/extensions/renderer/dispatcher.cc
|
| @@ -80,6 +80,7 @@
|
| #include "extensions/renderer/user_gestures_native_handler.h"
|
| #include "extensions/renderer/utils_native_handler.h"
|
| #include "extensions/renderer/v8_context_native_handler.h"
|
| +#include "extensions/renderer/v8_maybe_helpers.h"
|
| #include "grit/extensions_renderer_resources.h"
|
| #include "third_party/WebKit/public/platform/WebString.h"
|
| #include "third_party/WebKit/public/platform/WebURLRequest.h"
|
| @@ -124,13 +125,14 @@ static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled";
|
| // Note that this isn't necessarily an object, since webpages can write, for
|
| // example, "window.chrome = true".
|
| v8::Local<v8::Value> GetOrCreateChrome(ScriptContext* context) {
|
| - v8::Local<v8::String> chrome_string(
|
| - v8::String::NewFromUtf8(context->isolate(), "chrome"));
|
| - v8::Local<v8::Object> global(context->v8_context()->Global());
|
| - v8::Local<v8::Value> chrome(global->Get(chrome_string));
|
| - if (chrome->IsUndefined()) {
|
| + v8::Local<v8::Context> v8_context(context->v8_context());
|
| + v8::Local<v8::String> chrome_string(ToV8String(context->isolate(), "chrome"));
|
| + v8::Local<v8::Object> global(v8_context->Global());
|
| + v8::Local<v8::Value> chrome;
|
| + if (!global->Get(v8_context, chrome_string).ToLocal(&chrome) ||
|
| + chrome->IsUndefined()) {
|
| chrome = v8::Object::New(context->isolate());
|
| - global->Set(chrome_string, chrome);
|
| + SetProperty(v8_context, global, chrome_string, chrome);
|
| }
|
| return chrome;
|
| }
|
| @@ -1194,9 +1196,11 @@ void Dispatcher::RegisterBinding(const std::string& api_name,
|
| if (bind_object.IsEmpty())
|
| return;
|
|
|
| + v8::Local<v8::Context> v8_context = context->v8_context();
|
| v8::Local<v8::String> v8_bind_name =
|
| - v8::String::NewFromUtf8(context->isolate(), bind_name.c_str());
|
| - if (bind_object->HasRealNamedProperty(v8_bind_name)) {
|
| + ToV8String(context->isolate(), bind_name.c_str());
|
| + if (CheckV8Call(
|
| + bind_object->HasRealNamedProperty(v8_context, v8_bind_name))) {
|
| // The bind object may already have the property if the API has been
|
| // registered before (or if the extension has put something there already,
|
| // but, whatevs).
|
| @@ -1206,9 +1210,12 @@ void Dispatcher::RegisterBinding(const std::string& api_name,
|
| // others so that we don't destroy state such as event listeners.
|
| //
|
| // TODO(kalman): Only register available APIs to make this all moot.
|
| - if (bind_object->HasRealNamedCallbackProperty(v8_bind_name))
|
| + if (CheckV8Call(bind_object->HasRealNamedCallbackProperty(v8_context,
|
| + v8_bind_name)))
|
| return; // lazy binding still there, nothing to do
|
| - if (bind_object->Get(v8_bind_name)->IsObject())
|
| + v8::Local<v8::Value> bind;
|
| + if (bind_object->Get(v8_context, v8_bind_name).ToLocal(&bind) &&
|
| + bind->IsObject())
|
| return; // binding has already been fully installed
|
| }
|
|
|
| @@ -1308,20 +1315,22 @@ v8::Local<v8::Object> Dispatcher::GetOrCreateObject(
|
| const v8::Local<v8::Object>& object,
|
| const std::string& field,
|
| v8::Isolate* isolate) {
|
| - v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, field.c_str());
|
| + DCHECK(field.size() < v8::String::kMaxLength);
|
| + v8::Local<v8::String> key = ToV8String(isolate, field.c_str());
|
| + v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
| // If the object has a callback property, it is assumed it is an unavailable
|
| // API, so it is safe to delete. This is checked before GetOrCreateObject is
|
| // called.
|
| - if (object->HasRealNamedCallbackProperty(key)) {
|
| - object->Delete(key);
|
| - } else if (object->HasRealNamedProperty(key)) {
|
| - v8::Local<v8::Value> value = object->Get(key);
|
| + if (CheckV8Call(object->HasRealNamedCallbackProperty(context, key))) {
|
| + object->Delete(context, key);
|
| + } else if (CheckV8Call(object->HasRealNamedProperty(context, key))) {
|
| + v8::Local<v8::Value> value = object->Get(context, key).ToLocalChecked();
|
| CHECK(value->IsObject());
|
| return v8::Local<v8::Object>::Cast(value);
|
| }
|
|
|
| v8::Local<v8::Object> new_object = v8::Object::New(isolate);
|
| - object->Set(key, new_object);
|
| + SetProperty(context, object, key, new_object);
|
| return new_object;
|
| }
|
|
|
|
|