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; | |
| 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), | |
| 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( | |
| 150 new PendingContext(context, extension_group, world_id)); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 void ExtensionFrameHelper::DidClearWindowObject() { | |
| 155 did_clear_window_ = true; | |
| 156 for (PendingContext* context : pending_contexts_) { | |
|
Devlin
2015/11/12 01:12:03
This would be a lot cleaner if we could have a Web
dcheng
2015/11/13 00:26:33
I don't think we should add one. At the end of the
Devlin
2015/11/13 19:50:05
Stack traces: https://paste.googleplex.com/6093038
| |
| 157 v8::HandleScope scope(context->isolate); | |
| 158 v8::Context::Scope context_scope( | |
| 159 v8::Local<v8::Context>::New(context->isolate, context->context)); | |
| 160 extension_dispatcher_->DidCreateScriptContext( | |
| 161 render_frame()->GetWebFrame(), | |
| 162 v8::Local<v8::Context>::New(context->isolate, context->context), | |
| 163 context->extension_group, context->world_id); | |
| 164 } | |
| 165 pending_contexts_.clear(); | |
| 127 } | 166 } |
| 128 | 167 |
| 129 void ExtensionFrameHelper::WillReleaseScriptContext( | 168 void ExtensionFrameHelper::WillReleaseScriptContext( |
| 130 v8::Local<v8::Context> context, | 169 v8::Local<v8::Context> v8_context, |
| 131 int world_id) { | 170 int world_id) { |
| 132 extension_dispatcher_->WillReleaseScriptContext( | 171 for (auto iter = pending_contexts_.begin(); iter != pending_contexts_.end(); |
|
dcheng
2015/11/13 00:26:33
Maybe pending_context_ should be a map of v8::Glob
Devlin
2015/11/16 22:46:45
I don't know if that would work very well... using
| |
| 133 render_frame()->GetWebFrame(), context, world_id); | 172 ++iter) { |
| 173 if ((*iter)->context == v8_context) { | |
| 174 pending_contexts_.erase(iter); | |
| 175 return; | |
| 176 } | |
| 177 } | |
| 178 extension_dispatcher_->WillReleaseScriptContext(render_frame()->GetWebFrame(), | |
| 179 v8_context, world_id); | |
| 134 } | 180 } |
| 135 | 181 |
| 136 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { | 182 bool ExtensionFrameHelper::OnMessageReceived(const IPC::Message& message) { |
| 137 bool handled = true; | 183 bool handled = true; |
| 138 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) | 184 IPC_BEGIN_MESSAGE_MAP(ExtensionFrameHelper, message) |
| 139 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, | 185 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, |
| 140 OnExtensionDispatchOnConnect) | 186 OnExtensionDispatchOnConnect) |
| 141 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 187 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
| 142 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 188 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
| 143 OnExtensionDispatchOnDisconnect) | 189 OnExtensionDispatchOnDisconnect) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 const std::string& module_name, | 261 const std::string& module_name, |
| 216 const std::string& function_name, | 262 const std::string& function_name, |
| 217 const base::ListValue& args, | 263 const base::ListValue& args, |
| 218 bool user_gesture) { | 264 bool user_gesture) { |
| 219 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 265 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
| 220 module_name, function_name, | 266 module_name, function_name, |
| 221 args, user_gesture); | 267 args, user_gesture); |
| 222 } | 268 } |
| 223 | 269 |
| 224 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |