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 "content/public/renderer/render_frame.h" | 7 #include "content/public/renderer/render_frame.h" |
| 8 #include "extensions/common/api/messaging/message.h" | 8 #include "extensions/common/api/messaging/message.h" |
| 9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" |
| 10 #include "extensions/common/extension_messages.h" | 10 #include "extensions/common/extension_messages.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 if (url.host() != match_extension_id) | 40 if (url.host() != match_extension_id) |
| 41 return false; | 41 return false; |
| 42 if (match_window_id != extension_misc::kUnknownWindowId && | 42 if (match_window_id != extension_misc::kUnknownWindowId && |
| 43 frame_helper->browser_window_id() != match_window_id) | 43 frame_helper->browser_window_id() != match_window_id) |
| 44 return false; | 44 return false; |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 struct ExtensionFrameHelper::PendingContext { | |
| 51 v8::Global<v8::Context> context; | |
|
Devlin
2015/11/16 22:46:45
(responding to the question of global vs local vs
| |
| 52 int extension_group; | |
| 53 int world_id; | |
| 54 v8::Isolate* isolate; | |
| 55 | |
| 56 PendingContext(v8::Local<v8::Context> context, | |
| 57 int extension_group, | |
| 58 int world_id) | |
| 59 : context(context->GetIsolate(), context), | |
|
dcheng
2015/11/18 00:57:22
I'd suggest just capturing context here (you can a
Devlin
2015/11/18 18:02:11
Except that we store the context as a global - so
dcheng
2015/11/18 18:19:53
Right, makes sense. v8 is magic.
| |
| 60 extension_group(extension_group), | |
| 61 world_id(world_id), | |
| 62 isolate(context->GetIsolate()) {} | |
| 63 }; | |
| 64 | |
| 50 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, | 65 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, |
| 51 Dispatcher* extension_dispatcher) | 66 Dispatcher* extension_dispatcher) |
| 52 : content::RenderFrameObserver(render_frame), | 67 : content::RenderFrameObserver(render_frame), |
| 53 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame), | 68 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame), |
| 69 did_clear_window_(false), | |
| 54 view_type_(VIEW_TYPE_INVALID), | 70 view_type_(VIEW_TYPE_INVALID), |
| 55 tab_id_(-1), | 71 tab_id_(-1), |
| 56 browser_window_id_(-1), | 72 browser_window_id_(-1), |
| 57 extension_dispatcher_(extension_dispatcher), | 73 extension_dispatcher_(extension_dispatcher) { |
| 58 did_create_current_document_element_(false) { | |
| 59 g_frame_helpers.Get().insert(this); | 74 g_frame_helpers.Get().insert(this); |
| 60 } | 75 } |
| 61 | 76 |
| 62 ExtensionFrameHelper::~ExtensionFrameHelper() { | 77 ExtensionFrameHelper::~ExtensionFrameHelper() { |
| 63 g_frame_helpers.Get().erase(this); | 78 g_frame_helpers.Get().erase(this); |
| 64 } | 79 } |
| 65 | 80 |
| 66 // static | 81 // static |
| 67 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames( | 82 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames( |
| 68 const std::string& extension_id, | 83 const std::string& extension_id, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 void ExtensionFrameHelper::DidCreateDocumentElement() { | 118 void ExtensionFrameHelper::DidCreateDocumentElement() { |
| 104 did_create_current_document_element_ = true; | 119 did_create_current_document_element_ = true; |
| 105 extension_dispatcher_->DidCreateDocumentElement( | 120 extension_dispatcher_->DidCreateDocumentElement( |
| 106 render_frame()->GetWebFrame()); | 121 render_frame()->GetWebFrame()); |
| 107 } | 122 } |
| 108 | 123 |
| 109 void ExtensionFrameHelper::DidCreateNewDocument() { | 124 void ExtensionFrameHelper::DidCreateNewDocument() { |
| 110 did_create_current_document_element_ = false; | 125 did_create_current_document_element_ = false; |
| 111 } | 126 } |
| 112 | 127 |
| 128 void ExtensionFrameHelper::DidStartProvisionalLoad() { | |
| 129 did_clear_window_ = false; | |
| 130 } | |
| 131 | |
| 113 void ExtensionFrameHelper::DidMatchCSS( | 132 void ExtensionFrameHelper::DidMatchCSS( |
| 114 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 133 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 115 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 134 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 116 extension_dispatcher_->content_watcher()->DidMatchCSS( | 135 extension_dispatcher_->content_watcher()->DidMatchCSS( |
| 117 render_frame()->GetWebFrame(), newly_matching_selectors, | 136 render_frame()->GetWebFrame(), newly_matching_selectors, |
| 118 stopped_matching_selectors); | 137 stopped_matching_selectors); |
| 119 } | 138 } |
| 120 | 139 |
| 121 void ExtensionFrameHelper::DidCreateScriptContext( | 140 void ExtensionFrameHelper::DidCreateScriptContext( |
| 122 v8::Local<v8::Context> context, | 141 v8::Local<v8::Context> context, |
| 123 int extension_group, | 142 int extension_group, |
| 124 int world_id) { | 143 int world_id) { |
| 125 extension_dispatcher_->DidCreateScriptContext( | 144 if (did_clear_window_) { |
| 126 render_frame()->GetWebFrame(), context, extension_group, world_id); | 145 extension_dispatcher_->DidCreateScriptContext( |
| 146 render_frame()->GetWebFrame(), context, extension_group, world_id); | |
| 147 } else { | |
| 148 pending_contexts_.push_back(make_scoped_ptr( | |
| 149 new PendingContext(context, extension_group, world_id))); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 void ExtensionFrameHelper::DidClearWindowObject() { | |
| 154 did_clear_window_ = true; | |
| 155 for (const auto& context : pending_contexts_) { | |
|
dcheng
2015/11/18 18:19:53
Nit: s/context/pending_context/? To avoid the name
Devlin
2015/11/18 18:36:28
Done.
| |
| 156 v8::HandleScope scope(context->isolate); | |
|
dcheng
2015/11/18 18:19:53
Nit: v8::Local<v8::Context> context(context->conte
Devlin
2015/11/18 18:36:28
heh - just what we needed - another context variab
| |
| 157 v8::Context::Scope context_scope( | |
| 158 v8::Local<v8::Context>::New(context->isolate, context->context)); | |
|
dcheng
2015/11/18 00:57:22
I'm assuming this is required because DidCreateScr
Devlin
2015/11/18 18:02:11
Right - we set up the extension bindings, which in
| |
| 159 extension_dispatcher_->DidCreateScriptContext( | |
| 160 render_frame()->GetWebFrame(), | |
| 161 v8::Local<v8::Context>::New(context->isolate, context->context), | |
| 162 context->extension_group, context->world_id); | |
| 163 } | |
| 164 pending_contexts_.clear(); | |
| 127 } | 165 } |
| 128 | 166 |
| 129 void ExtensionFrameHelper::WillReleaseScriptContext( | 167 void ExtensionFrameHelper::WillReleaseScriptContext( |
| 130 v8::Local<v8::Context> context, | 168 v8::Local<v8::Context> v8_context, |
| 131 int world_id) { | 169 int world_id) { |
| 132 extension_dispatcher_->WillReleaseScriptContext( | 170 for (auto iter = pending_contexts_.begin(); iter != pending_contexts_.end(); |
| 133 render_frame()->GetWebFrame(), context, world_id); | 171 ++iter) { |
| 172 if ((*iter)->context == v8_context) { | |
| 173 pending_contexts_.erase(iter); | |
| 174 return; | |
| 175 } | |
| 176 } | |
| 177 extension_dispatcher_->WillReleaseScriptContext(render_frame()->GetWebFrame(), | |
| 178 v8_context, world_id); | |
| 134 } | 179 } |
| 135 | 180 |
| 136 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { | 181 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { |
| 137 bool handled = true; | 182 bool handled = true; |
| 138 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) | 183 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) |
| 139 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, | 184 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, |
| 140 OnExtensionDispatchOnConnect) | 185 OnExtensionDispatchOnConnect) |
| 141 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 186 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
| 142 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 187 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
| 143 OnExtensionDispatchOnDisconnect) | 188 OnExtensionDispatchOnDisconnect) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 const std::string& module_name, | 260 const std::string& module_name, |
| 216 const std::string& function_name, | 261 const std::string& function_name, |
| 217 const base::ListValue& args, | 262 const base::ListValue& args, |
| 218 bool user_gesture) { | 263 bool user_gesture) { |
| 219 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 264 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
| 220 module_name, function_name, | 265 module_name, function_name, |
| 221 args, user_gesture); | 266 args, user_gesture); |
| 222 } | 267 } |
| 223 | 268 |
| 224 } // namespace extensions | 269 } // namespace extensions |
| OLD | NEW |