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> v8_context; | |
| 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 : v8_context(context->GetIsolate(), context), | |
| 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) { | 74 did_create_current_document_element_(false) { |
| 59 g_frame_helpers.Get().insert(this); | 75 g_frame_helpers.Get().insert(this); |
| 60 } | 76 } |
| 61 | 77 |
| 62 ExtensionFrameHelper::~ExtensionFrameHelper() { | 78 ExtensionFrameHelper::~ExtensionFrameHelper() { |
| 63 g_frame_helpers.Get().erase(this); | 79 g_frame_helpers.Get().erase(this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 void ExtensionFrameHelper::DidCreateDocumentElement() { | 119 void ExtensionFrameHelper::DidCreateDocumentElement() { |
| 104 did_create_current_document_element_ = true; | 120 did_create_current_document_element_ = true; |
| 105 extension_dispatcher_->DidCreateDocumentElement( | 121 extension_dispatcher_->DidCreateDocumentElement( |
| 106 render_frame()->GetWebFrame()); | 122 render_frame()->GetWebFrame()); |
| 107 } | 123 } |
| 108 | 124 |
| 109 void ExtensionFrameHelper::DidCreateNewDocument() { | 125 void ExtensionFrameHelper::DidCreateNewDocument() { |
| 110 did_create_current_document_element_ = false; | 126 did_create_current_document_element_ = false; |
| 111 } | 127 } |
| 112 | 128 |
| 129 void ExtensionFrameHelper::DidStartProvisionalLoad() { | |
| 130 did_clear_window_ = false; | |
| 131 } | |
| 132 | |
| 113 void ExtensionFrameHelper::DidMatchCSS( | 133 void ExtensionFrameHelper::DidMatchCSS( |
| 114 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 134 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 115 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 135 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
| 116 extension_dispatcher_->content_watcher()->DidMatchCSS( | 136 extension_dispatcher_->content_watcher()->DidMatchCSS( |
| 117 render_frame()->GetWebFrame(), newly_matching_selectors, | 137 render_frame()->GetWebFrame(), newly_matching_selectors, |
| 118 stopped_matching_selectors); | 138 stopped_matching_selectors); |
| 119 } | 139 } |
| 120 | 140 |
| 121 void ExtensionFrameHelper::DidCreateScriptContext( | 141 void ExtensionFrameHelper::DidCreateScriptContext( |
| 122 v8::Local<v8::Context> context, | 142 v8::Local<v8::Context> context, |
| 123 int extension_group, | 143 int extension_group, |
| 124 int world_id) { | 144 int world_id) { |
| 125 extension_dispatcher_->DidCreateScriptContext( | 145 if (did_clear_window_) { |
| 126 render_frame()->GetWebFrame(), context, extension_group, world_id); | 146 extension_dispatcher_->DidCreateScriptContext( |
| 147 render_frame()->GetWebFrame(), context, extension_group, world_id); | |
| 148 } else { | |
| 149 pending_contexts_.push_back(make_scoped_ptr( | |
| 150 new PendingContext(context, extension_group, world_id))); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 void ExtensionFrameHelper::DidClearWindowObject() { | |
| 155 did_clear_window_ = true; | |
| 156 for (const auto& pending_context : pending_contexts_) { | |
| 157 v8::HandleScope scope(pending_context->isolate); | |
| 158 v8::Local<v8::Context> context_local = | |
|
dcheng
2015/11/18 18:42:51
Sorry: my comment was unclear. You can just call t
| |
| 159 v8::Local<v8::Context>::New(pending_context->isolate, | |
| 160 pending_context->v8_context); | |
| 161 v8::Context::Scope context_scope(context_local); | |
| 162 extension_dispatcher_->DidCreateScriptContext( | |
| 163 render_frame()->GetWebFrame(), context_local, | |
| 164 pending_context->extension_group, pending_context->world_id); | |
| 165 } | |
| 166 pending_contexts_.clear(); | |
| 127 } | 167 } |
| 128 | 168 |
| 129 void ExtensionFrameHelper::WillReleaseScriptContext( | 169 void ExtensionFrameHelper::WillReleaseScriptContext( |
| 130 v8::Local<v8::Context> context, | 170 v8::Local<v8::Context> v8_context, |
| 131 int world_id) { | 171 int world_id) { |
| 132 extension_dispatcher_->WillReleaseScriptContext( | 172 for (auto iter = pending_contexts_.begin(); iter != pending_contexts_.end(); |
| 133 render_frame()->GetWebFrame(), context, world_id); | 173 ++iter) { |
| 174 if ((*iter)->v8_context == v8_context) { | |
| 175 pending_contexts_.erase(iter); | |
| 176 return; | |
| 177 } | |
| 178 } | |
| 179 extension_dispatcher_->WillReleaseScriptContext(render_frame()->GetWebFrame(), | |
| 180 v8_context, world_id); | |
| 134 } | 181 } |
| 135 | 182 |
| 136 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { | 183 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { |
| 137 bool handled = true; | 184 bool handled = true; |
| 138 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) | 185 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) |
| 139 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, | 186 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, |
| 140 OnExtensionDispatchOnConnect) | 187 OnExtensionDispatchOnConnect) |
| 141 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 188 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
| 142 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 189 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
| 143 OnExtensionDispatchOnDisconnect) | 190 OnExtensionDispatchOnDisconnect) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 const std::string& module_name, | 262 const std::string& module_name, |
| 216 const std::string& function_name, | 263 const std::string& function_name, |
| 217 const base::ListValue& args, | 264 const base::ListValue& args, |
| 218 bool user_gesture) { | 265 bool user_gesture) { |
| 219 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 266 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
| 220 module_name, function_name, | 267 module_name, function_name, |
| 221 args, user_gesture); | 268 args, user_gesture); |
| 222 } | 269 } |
| 223 | 270 |
| 224 } // namespace extensions | 271 } // namespace extensions |
| OLD | NEW |