| 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/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/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | 22 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
| 23 #include "extensions/common/permissions/permissions_data.h" | 23 #include "extensions/common/permissions/permissions_data.h" |
| 24 #include "extensions/renderer/renderer_extension_registry.h" | 24 #include "extensions/renderer/renderer_extension_registry.h" |
| 25 #include "extensions/renderer/v8_helpers.h" | 25 #include "extensions/renderer/v8_helpers.h" |
| 26 #include "gin/per_context_data.h" | 26 #include "gin/per_context_data.h" |
| 27 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 27 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 28 #include "third_party/WebKit/public/web/WebDataSource.h" | 28 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebFrame.h" | 30 #include "third_party/WebKit/public/web/WebFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 32 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
| 34 | 35 |
| 35 using content::V8ValueConverter; | 36 using content::V8ValueConverter; |
| 36 | 37 |
| 37 namespace extensions { | 38 namespace extensions { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 std::string GetContextTypeDescriptionString(Feature::Context context_type) { | 42 std::string GetContextTypeDescriptionString(Feature::Context context_type) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 178 } |
| 178 | 179 |
| 179 v8::Local<v8::Value> ScriptContext::CallFunction( | 180 v8::Local<v8::Value> ScriptContext::CallFunction( |
| 180 const v8::Local<v8::Function>& function, | 181 const v8::Local<v8::Function>& function, |
| 181 int argc, | 182 int argc, |
| 182 v8::Local<v8::Value> argv[]) const { | 183 v8::Local<v8::Value> argv[]) const { |
| 183 DCHECK(thread_checker_.CalledOnValidThread()); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
| 184 v8::EscapableHandleScope handle_scope(isolate()); | 185 v8::EscapableHandleScope handle_scope(isolate()); |
| 185 v8::Context::Scope scope(v8_context()); | 186 v8::Context::Scope scope(v8_context()); |
| 186 | 187 |
| 187 v8::MicrotasksScope microtasks( | 188 blink::WebScopedMicrotaskSuppression suppression; |
| 188 isolate(), v8::MicrotasksScope::kDoNotRunMicrotasks); | |
| 189 if (!is_valid_) { | 189 if (!is_valid_) { |
| 190 return handle_scope.Escape( | 190 return handle_scope.Escape( |
| 191 v8::Local<v8::Primitive>(v8::Undefined(isolate()))); | 191 v8::Local<v8::Primitive>(v8::Undefined(isolate()))); |
| 192 } | 192 } |
| 193 | 193 |
| 194 v8::Local<v8::Object> global = v8_context()->Global(); | 194 v8::Local<v8::Object> global = v8_context()->Global(); |
| 195 if (!web_frame_) | 195 if (!web_frame_) |
| 196 return handle_scope.Escape(function->Call(global, argc, argv)); | 196 return handle_scope.Escape(function->Call(global, argc, argv)); |
| 197 return handle_scope.Escape( | 197 return handle_scope.Escape( |
| 198 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( | 198 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Prepend extensions:: to |name| so that internal code can be differentiated | 427 // Prepend extensions:: to |name| so that internal code can be differentiated |
| 428 // from external code in stack traces. This has no effect on behaviour. | 428 // from external code in stack traces. This has no effect on behaviour. |
| 429 std::string internal_name = | 429 std::string internal_name = |
| 430 base::StringPrintf("extensions::%s", *v8::String::Utf8Value(name)); | 430 base::StringPrintf("extensions::%s", *v8::String::Utf8Value(name)); |
| 431 | 431 |
| 432 if (internal_name.size() >= v8::String::kMaxLength) { | 432 if (internal_name.size() >= v8::String::kMaxLength) { |
| 433 NOTREACHED() << "internal_name is too long."; | 433 NOTREACHED() << "internal_name is too long."; |
| 434 return v8::Undefined(isolate()); | 434 return v8::Undefined(isolate()); |
| 435 } | 435 } |
| 436 | 436 |
| 437 v8::MicrotasksScope microtasks( | 437 blink::WebScopedMicrotaskSuppression suppression; |
| 438 isolate(), v8::MicrotasksScope::kDoNotRunMicrotasks); | |
| 439 v8::TryCatch try_catch(isolate()); | 438 v8::TryCatch try_catch(isolate()); |
| 440 try_catch.SetCaptureMessage(true); | 439 try_catch.SetCaptureMessage(true); |
| 441 v8::ScriptOrigin origin( | 440 v8::ScriptOrigin origin( |
| 442 v8_helpers::ToV8StringUnsafe(isolate(), internal_name.c_str())); | 441 v8_helpers::ToV8StringUnsafe(isolate(), internal_name.c_str())); |
| 443 v8::Local<v8::Script> script; | 442 v8::Local<v8::Script> script; |
| 444 if (!v8::Script::Compile(v8_context(), code, &origin).ToLocal(&script)) { | 443 if (!v8::Script::Compile(v8_context(), code, &origin).ToLocal(&script)) { |
| 445 exception_handler.Run(try_catch); | 444 exception_handler.Run(try_catch); |
| 446 return v8::Undefined(isolate()); | 445 return v8::Undefined(isolate()); |
| 447 } | 446 } |
| 448 | 447 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 470 v8::Local<v8::Value> argv[]) { | 469 v8::Local<v8::Value> argv[]) { |
| 471 return context_->CallFunction(function, argc, argv); | 470 return context_->CallFunction(function, argc, argv); |
| 472 } | 471 } |
| 473 | 472 |
| 474 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { | 473 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { |
| 475 v8::HandleScope handle_scope(context_->isolate()); | 474 v8::HandleScope handle_scope(context_->isolate()); |
| 476 return gin::PerContextData::From(context_->v8_context())->context_holder(); | 475 return gin::PerContextData::From(context_->v8_context())->context_holder(); |
| 477 } | 476 } |
| 478 | 477 |
| 479 } // namespace extensions | 478 } // namespace extensions |
| OLD | NEW |