Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: extensions/renderer/script_context.cc

Issue 359413004: Add support for using AMD modules from extensions modules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
14 #include "content/public/renderer/v8_value_converter.h" 14 #include "content/public/renderer/v8_value_converter.h"
15 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
16 #include "extensions/common/extension_api.h" 16 #include "extensions/common/extension_api.h"
17 #include "extensions/common/extension_urls.h" 17 #include "extensions/common/extension_urls.h"
18 #include "extensions/common/features/base_feature_provider.h" 18 #include "extensions/common/features/base_feature_provider.h"
19 #include "gin/per_context_data.h"
19 #include "third_party/WebKit/public/web/WebDataSource.h" 20 #include "third_party/WebKit/public/web/WebDataSource.h"
20 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
21 #include "third_party/WebKit/public/web/WebFrame.h" 22 #include "third_party/WebKit/public/web/WebFrame.h"
22 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" 23 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 24 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
24 #include "third_party/WebKit/public/web/WebView.h" 25 #include "third_party/WebKit/public/web/WebView.h"
25 #include "v8/include/v8.h" 26 #include "v8/include/v8.h"
26 27
27 using content::V8ValueConverter; 28 using content::V8ValueConverter;
28 29
29 namespace extensions { 30 namespace extensions {
30 31
31 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, 32 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context,
32 blink::WebFrame* web_frame, 33 blink::WebFrame* web_frame,
33 const Extension* extension, 34 const Extension* extension,
34 Feature::Context context_type) 35 Feature::Context context_type)
35 : v8_context_(v8_context), 36 : v8_context_(v8_context),
36 web_frame_(web_frame), 37 web_frame_(web_frame),
37 extension_(extension), 38 extension_(extension),
38 context_type_(context_type), 39 context_type_(context_type),
39 safe_builtins_(this), 40 safe_builtins_(this),
40 isolate_(v8_context->GetIsolate()) { 41 isolate_(v8_context->GetIsolate()) {
41 VLOG(1) << "Created context:\n" 42 VLOG(1) << "Created context:\n"
42 << " extension id: " << GetExtensionID() << "\n" 43 << " extension id: " << GetExtensionID() << "\n"
43 << " frame: " << web_frame_ << "\n" 44 << " frame: " << web_frame_ << "\n"
44 << " context type: " << GetContextTypeDescription(); 45 << " context type: " << GetContextTypeDescription();
46 gin::PerContextData::From(v8_context)->set_runner(this);
45 } 47 }
46 48
47 ScriptContext::~ScriptContext() { 49 ScriptContext::~ScriptContext() {
48 VLOG(1) << "Destroyed context for extension\n" 50 VLOG(1) << "Destroyed context for extension\n"
49 << " extension id: " << GetExtensionID(); 51 << " extension id: " << GetExtensionID();
50 Invalidate(); 52 Invalidate();
51 } 53 }
52 54
53 void ScriptContext::Invalidate() { 55 void ScriptContext::Invalidate() {
54 if (!is_valid()) 56 if (!is_valid())
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 216
215 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod( 217 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod(
216 "sendRequest", "handleResponse", arraysize(argv), argv); 218 "sendRequest", "handleResponse", arraysize(argv), argv);
217 219
218 // In debug, the js will validate the callback parameters and return a 220 // In debug, the js will validate the callback parameters and return a
219 // string if a validation error has occured. 221 // string if a validation error has occured.
220 DCHECK(retval.IsEmpty() || retval->IsUndefined()) 222 DCHECK(retval.IsEmpty() || retval->IsUndefined())
221 << *v8::String::Utf8Value(retval); 223 << *v8::String::Utf8Value(retval);
222 } 224 }
223 225
226 void ScriptContext::Run(const std::string& source,
227 const std::string& resource_name) {
228 module_system_->RunString(source, resource_name);
229 }
230
231 v8::Handle<v8::Value> ScriptContext::Call(v8::Handle<v8::Function> function,
232 v8::Handle<v8::Value> receiver,
233 int argc,
234 v8::Handle<v8::Value> argv[]) {
235 return CallFunction(function, argc, argv);
236 }
237
238 gin::ContextHolder* ScriptContext::GetContextHolder() {
239 v8::HandleScope handle_scope(isolate());
240 return gin::PerContextData::From(v8_context())->context_holder();
241 }
242
224 } // namespace extensions 243 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698