Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extension_frame_helper.h" | 5 #include "extensions/renderer/extension_frame_helper.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/timer/elapsed_timer.h" | 9 #include "base/timer/elapsed_timer.h" |
| 10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
| 11 #include "extensions/common/api/messaging/message.h" | 11 #include "extensions/common/api/messaging/message.h" |
| 12 #include "extensions/common/api/messaging/port_id.h" | 12 #include "extensions/common/api/messaging/port_id.h" |
| 13 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
| 15 #include "extensions/common/manifest_handlers/background_info.h" | 15 #include "extensions/common/manifest_handlers/background_info.h" |
| 16 #include "extensions/renderer/console.h" | 16 #include "extensions/renderer/console.h" |
| 17 #include "extensions/renderer/content_watcher.h" | 17 #include "extensions/renderer/content_watcher.h" |
| 18 #include "extensions/renderer/dispatcher.h" | 18 #include "extensions/renderer/dispatcher.h" |
| 19 #include "extensions/renderer/messaging_bindings.h" | 19 #include "extensions/renderer/messaging_bindings.h" |
| 20 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
| 21 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 21 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 22 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 22 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 23 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 constexpr int kMainWorldId = 0; | |
|
Yuki
2017/03/10 07:34:46
side note: Probably, we should get rid of exposing
haraken
2017/03/10 09:17:26
Yeah, agreed. Ideally I want to entirely remove wo
| |
| 31 | |
| 30 base::LazyInstance<std::set<const ExtensionFrameHelper*>>::DestructorAtExit | 32 base::LazyInstance<std::set<const ExtensionFrameHelper*>>::DestructorAtExit |
| 31 g_frame_helpers = LAZY_INSTANCE_INITIALIZER; | 33 g_frame_helpers = LAZY_INSTANCE_INITIALIZER; |
| 32 | 34 |
| 33 // Returns true if the render frame corresponding with |frame_helper| matches | 35 // Returns true if the render frame corresponding with |frame_helper| matches |
| 34 // the given criteria. | 36 // the given criteria. |
| 35 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper, | 37 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper, |
| 36 ViewType match_view_type, | 38 ViewType match_view_type, |
| 37 int match_window_id, | 39 int match_window_id, |
| 38 int match_tab_id, | 40 int match_tab_id, |
| 39 const std::string& match_extension_id) { | 41 const std::string& match_extension_id) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 blink::WebDataSource* data_source) { | 193 blink::WebDataSource* data_source) { |
| 192 if (!delayed_main_world_script_initialization_) | 194 if (!delayed_main_world_script_initialization_) |
| 193 return; | 195 return; |
| 194 | 196 |
| 195 delayed_main_world_script_initialization_ = false; | 197 delayed_main_world_script_initialization_ = false; |
| 196 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 198 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 197 v8::Local<v8::Context> context = | 199 v8::Local<v8::Context> context = |
| 198 render_frame()->GetWebFrame()->mainWorldScriptContext(); | 200 render_frame()->GetWebFrame()->mainWorldScriptContext(); |
| 199 v8::Context::Scope context_scope(context); | 201 v8::Context::Scope context_scope(context); |
| 200 extension_dispatcher_->DidCreateScriptContext(render_frame()->GetWebFrame(), | 202 extension_dispatcher_->DidCreateScriptContext(render_frame()->GetWebFrame(), |
| 201 context, 0); | 203 context, kMainWorldId); |
| 202 // TODO(devlin): Add constants for main world id, no extension group. | 204 // TODO(devlin): Add constants for main world id, no extension group. |
| 203 } | 205 } |
| 204 | 206 |
| 205 void ExtensionFrameHelper::DidCreateScriptContext( | 207 void ExtensionFrameHelper::DidCreateScriptContext( |
| 206 v8::Local<v8::Context> context, | 208 v8::Local<v8::Context> context, |
| 207 int world_id) { | 209 int world_id) { |
| 208 if (context == render_frame()->GetWebFrame()->mainWorldScriptContext() && | 210 if (world_id == kMainWorldId && |
| 209 render_frame()->IsBrowserSideNavigationPending()) { | 211 render_frame()->IsBrowserSideNavigationPending()) { |
| 210 DCHECK_EQ(0, world_id); | |
| 211 DCHECK(!delayed_main_world_script_initialization_); | 212 DCHECK(!delayed_main_world_script_initialization_); |
| 212 // Defer initializing the extensions script context now because it depends | 213 // Defer initializing the extensions script context now because it depends |
| 213 // on having the URL of the provisional load which isn't available at this | 214 // on having the URL of the provisional load which isn't available at this |
| 214 // point with PlzNavigate. | 215 // point with PlzNavigate. |
| 215 delayed_main_world_script_initialization_ = true; | 216 delayed_main_world_script_initialization_ = true; |
| 216 } else { | 217 } else { |
| 217 extension_dispatcher_->DidCreateScriptContext(render_frame()->GetWebFrame(), | 218 extension_dispatcher_->DidCreateScriptContext(render_frame()->GetWebFrame(), |
| 218 context, world_id); | 219 context, world_id); |
| 219 } | 220 } |
| 220 } | 221 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 const base::ListValue& args) { | 318 const base::ListValue& args) { |
| 318 extension_dispatcher_->InvokeModuleSystemMethod( | 319 extension_dispatcher_->InvokeModuleSystemMethod( |
| 319 render_frame(), extension_id, module_name, function_name, args); | 320 render_frame(), extension_id, module_name, function_name, args); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void ExtensionFrameHelper::OnDestruct() { | 323 void ExtensionFrameHelper::OnDestruct() { |
| 323 delete this; | 324 delete this; |
| 324 } | 325 } |
| 325 | 326 |
| 326 } // namespace extensions | 327 } // namespace extensions |
| OLD | NEW |