| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/safe_builtins.h" | 5 #include "extensions/renderer/safe_builtins.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SaveImpl(const char* name, | 130 void SaveImpl(const char* name, |
| 131 v8::Local<v8::Value> value, | 131 v8::Local<v8::Value> value, |
| 132 v8::Local<v8::Context> context) { | 132 v8::Local<v8::Context> context) { |
| 133 CHECK(!value.IsEmpty() && value->IsObject()) << name; | 133 CHECK(!value.IsEmpty() && value->IsObject()) << name; |
| 134 context->Global()->SetHiddenValue(MakeKey(name, context->GetIsolate()), | 134 context->Global()->SetHiddenValue(MakeKey(name, context->GetIsolate()), |
| 135 value); | 135 value); |
| 136 } | 136 } |
| 137 | 137 |
| 138 v8::Local<v8::Object> Load(const char* name, v8::Handle<v8::Context> context) { | 138 v8::Local<v8::Object> Load(const char* name, v8::Local<v8::Context> context) { |
| 139 v8::Local<v8::Value> value = | 139 v8::Local<v8::Value> value = |
| 140 context->Global()->GetHiddenValue(MakeKey(name, context->GetIsolate())); | 140 context->Global()->GetHiddenValue(MakeKey(name, context->GetIsolate())); |
| 141 CHECK(!value.IsEmpty() && value->IsObject()) << name; | 141 CHECK(!value.IsEmpty() && value->IsObject()) << name; |
| 142 return v8::Local<v8::Object>::Cast(value); | 142 return v8::Local<v8::Object>::Cast(value); |
| 143 } | 143 } |
| 144 | 144 |
| 145 class ExtensionImpl : public v8::Extension { | 145 class ExtensionImpl : public v8::Extension { |
| 146 public: | 146 public: |
| 147 ExtensionImpl() : v8::Extension(kClassName, kScript) {} | 147 ExtensionImpl() : v8::Extension(kClassName, kScript) {} |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 150 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 151 v8::Isolate* isolate, | 151 v8::Isolate* isolate, |
| 152 v8::Handle<v8::String> name) override { | 152 v8::Local<v8::String> name) override { |
| 153 if (name->Equals(v8::String::NewFromUtf8(isolate, "Apply"))) | 153 if (name->Equals(v8::String::NewFromUtf8(isolate, "Apply"))) |
| 154 return v8::FunctionTemplate::New(isolate, Apply); | 154 return v8::FunctionTemplate::New(isolate, Apply); |
| 155 if (name->Equals(v8::String::NewFromUtf8(isolate, "Save"))) | 155 if (name->Equals(v8::String::NewFromUtf8(isolate, "Save"))) |
| 156 return v8::FunctionTemplate::New(isolate, Save); | 156 return v8::FunctionTemplate::New(isolate, Save); |
| 157 NOTREACHED() << *v8::String::Utf8Value(name); | 157 NOTREACHED() << *v8::String::Utf8Value(name); |
| 158 return v8::Handle<v8::FunctionTemplate>(); | 158 return v8::Local<v8::FunctionTemplate>(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 static void Apply(const v8::FunctionCallbackInfo<v8::Value>& info) { | 161 static void Apply(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 162 CHECK(info.Length() == 5 && info[0]->IsFunction() && // function | 162 CHECK(info.Length() == 5 && info[0]->IsFunction() && // function |
| 163 // info[1] could be an object or a string | 163 // info[1] could be an object or a string |
| 164 info[2]->IsObject() && // args | 164 info[2]->IsObject() && // args |
| 165 info[3]->IsInt32() && // first_arg_index | 165 info[3]->IsInt32() && // first_arg_index |
| 166 info[4]->IsInt32()); // args_length | 166 info[4]->IsInt32()); // args_length |
| 167 v8::Local<v8::Function> function = info[0].As<v8::Function>(); | 167 v8::Local<v8::Function> function = info[0].As<v8::Function>(); |
| 168 v8::Local<v8::Object> recv; | 168 v8::Local<v8::Object> recv; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 233 |
| 234 v8::Local<v8::Object> SafeBuiltins::GetString() const { | 234 v8::Local<v8::Object> SafeBuiltins::GetString() const { |
| 235 return Load("String", context_->v8_context()); | 235 return Load("String", context_->v8_context()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 v8::Local<v8::Object> SafeBuiltins::GetError() const { | 238 v8::Local<v8::Object> SafeBuiltins::GetError() const { |
| 239 return Load("Error", context_->v8_context()); | 239 return Load("Error", context_->v8_context()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace extensions | 242 } // namespace extensions |
| OLD | NEW |