OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/chrome_v8_context.h" | 5 #include "chrome/renderer/extensions/chrome_v8_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/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
12 #include "chrome/common/extensions/extension_set.h" | 12 #include "chrome/common/extensions/extension_set.h" |
13 #include "chrome/common/extensions/features/base_feature_provider.h" | 13 #include "chrome/common/extensions/features/base_feature_provider.h" |
14 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 14 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
15 #include "chrome/renderer/extensions/module_system.h" | 15 #include "chrome/renderer/extensions/module_system.h" |
16 #include "chrome/renderer/extensions/user_script_slave.h" | 16 #include "chrome/renderer/extensions/user_script_slave.h" |
17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
18 #include "content/public/renderer/v8_value_converter.h" | 18 #include "content/public/renderer/v8_value_converter.h" |
19 #include "extensions/common/extension_api.h" | 19 #include "extensions/common/extension_api.h" |
20 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
21 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 21 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
22 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
23 #include "v8/include/v8.h" | 23 #include "v8/include/v8.h" |
24 | 24 |
25 using content::V8ValueConverter; | 25 using content::V8ValueConverter; |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 | 28 |
29 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 29 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
30 WebKit::WebFrame* web_frame, | 30 blink::WebFrame* web_frame, |
31 const Extension* extension, | 31 const Extension* extension, |
32 Feature::Context context_type) | 32 Feature::Context context_type) |
33 : v8_context_(v8_context), | 33 : v8_context_(v8_context), |
34 web_frame_(web_frame), | 34 web_frame_(web_frame), |
35 extension_(extension), | 35 extension_(extension), |
36 context_type_(context_type), | 36 context_type_(context_type), |
37 safe_builtins_(this), | 37 safe_builtins_(this), |
38 isolate_(v8_context->GetIsolate()) { | 38 isolate_(v8_context->GetIsolate()) { |
39 VLOG(1) << "Created context:\n" | 39 VLOG(1) << "Created context:\n" |
40 << " extension id: " << GetExtensionID() << "\n" | 40 << " extension id: " << GetExtensionID() << "\n" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 UserScriptSlave::GetDataSourceURLForFrame(web_frame_) : GURL(); | 73 UserScriptSlave::GetDataSourceURLForFrame(web_frame_) : GURL(); |
74 } | 74 } |
75 | 75 |
76 v8::Local<v8::Value> ChromeV8Context::CallFunction( | 76 v8::Local<v8::Value> ChromeV8Context::CallFunction( |
77 v8::Handle<v8::Function> function, | 77 v8::Handle<v8::Function> function, |
78 int argc, | 78 int argc, |
79 v8::Handle<v8::Value> argv[]) const { | 79 v8::Handle<v8::Value> argv[]) const { |
80 v8::HandleScope handle_scope(isolate()); | 80 v8::HandleScope handle_scope(isolate()); |
81 v8::Context::Scope scope(v8_context()); | 81 v8::Context::Scope scope(v8_context()); |
82 | 82 |
83 WebKit::WebScopedMicrotaskSuppression suppression; | 83 blink::WebScopedMicrotaskSuppression suppression; |
84 if (!is_valid()) | 84 if (!is_valid()) |
85 return handle_scope.Close(v8::Undefined()); | 85 return handle_scope.Close(v8::Undefined()); |
86 | 86 |
87 v8::Handle<v8::Object> global = v8_context()->Global(); | 87 v8::Handle<v8::Object> global = v8_context()->Global(); |
88 if (!web_frame_) | 88 if (!web_frame_) |
89 return handle_scope.Close(function->Call(global, argc, argv)); | 89 return handle_scope.Close(function->Call(global, argc, argv)); |
90 return handle_scope.Close( | 90 return handle_scope.Close( |
91 web_frame_->callFunctionEvenIfScriptDisabled(function, | 91 web_frame_->callFunctionEvenIfScriptDisabled(function, |
92 global, | 92 global, |
93 argc, | 93 argc, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // string if a validation error has occured. | 154 // string if a validation error has occured. |
155 if (DCHECK_IS_ON()) { | 155 if (DCHECK_IS_ON()) { |
156 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 156 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
157 std::string error = *v8::String::AsciiValue(retval); | 157 std::string error = *v8::String::AsciiValue(retval); |
158 DCHECK(false) << error; | 158 DCHECK(false) << error; |
159 } | 159 } |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 } // namespace extensions | 163 } // namespace extensions |
OLD | NEW |