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/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
9 #include "extensions/common/api/messaging/message.h" | 9 #include "extensions/common/api/messaging/message.h" |
10 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, | 85 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, |
86 Dispatcher* extension_dispatcher) | 86 Dispatcher* extension_dispatcher) |
87 : content::RenderFrameObserver(render_frame), | 87 : content::RenderFrameObserver(render_frame), |
88 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame), | 88 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame), |
89 view_type_(VIEW_TYPE_INVALID), | 89 view_type_(VIEW_TYPE_INVALID), |
90 tab_id_(-1), | 90 tab_id_(-1), |
91 browser_window_id_(-1), | 91 browser_window_id_(-1), |
92 extension_dispatcher_(extension_dispatcher), | 92 extension_dispatcher_(extension_dispatcher), |
93 did_create_current_document_element_(false), | 93 did_create_current_document_element_(false), |
| 94 next_port_request_id_(0), |
94 weak_ptr_factory_(this) { | 95 weak_ptr_factory_(this) { |
95 g_frame_helpers.Get().insert(this); | 96 g_frame_helpers.Get().insert(this); |
96 } | 97 } |
97 | 98 |
98 ExtensionFrameHelper::~ExtensionFrameHelper() { | 99 ExtensionFrameHelper::~ExtensionFrameHelper() { |
99 g_frame_helpers.Get().erase(this); | 100 g_frame_helpers.Get().erase(this); |
100 } | 101 } |
101 | 102 |
102 // static | 103 // static |
103 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames( | 104 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void ExtensionFrameHelper::ScheduleAtDocumentStart( | 166 void ExtensionFrameHelper::ScheduleAtDocumentStart( |
166 const base::Closure& callback) { | 167 const base::Closure& callback) { |
167 document_element_created_callbacks_.push_back(callback); | 168 document_element_created_callbacks_.push_back(callback); |
168 } | 169 } |
169 | 170 |
170 void ExtensionFrameHelper::ScheduleAtDocumentEnd( | 171 void ExtensionFrameHelper::ScheduleAtDocumentEnd( |
171 const base::Closure& callback) { | 172 const base::Closure& callback) { |
172 document_load_finished_callbacks_.push_back(callback); | 173 document_load_finished_callbacks_.push_back(callback); |
173 } | 174 } |
174 | 175 |
| 176 void ExtensionFrameHelper::RequestPortId( |
| 177 const ExtensionMsg_ExternalConnectionInfo& info, |
| 178 const std::string& channel_name, |
| 179 bool include_tls_channel_id, |
| 180 const base::Callback<void(int)>& callback) { |
| 181 int port_request_id = next_port_request_id_++; |
| 182 pending_port_requests_[port_request_id] = callback; |
| 183 render_frame()->Send(new ExtensionHostMsg_OpenChannelToExtension( |
| 184 render_frame()->GetRoutingID(), info, channel_name, |
| 185 include_tls_channel_id, port_request_id)); |
| 186 } |
| 187 |
| 188 void ExtensionFrameHelper::OnAssignPortId(int port_id, int request_id) { |
| 189 auto iter = pending_port_requests_.find(request_id); |
| 190 DCHECK(iter != pending_port_requests_.end()); |
| 191 iter->second.Run(port_id); |
| 192 pending_port_requests_.erase(iter); |
| 193 } |
| 194 |
175 void ExtensionFrameHelper::DidMatchCSS( | 195 void ExtensionFrameHelper::DidMatchCSS( |
176 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 196 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
177 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 197 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
178 extension_dispatcher_->content_watcher()->DidMatchCSS( | 198 extension_dispatcher_->content_watcher()->DidMatchCSS( |
179 render_frame()->GetWebFrame(), newly_matching_selectors, | 199 render_frame()->GetWebFrame(), newly_matching_selectors, |
180 stopped_matching_selectors); | 200 stopped_matching_selectors); |
181 } | 201 } |
182 | 202 |
183 void ExtensionFrameHelper::DidCreateScriptContext( | 203 void ExtensionFrameHelper::DidCreateScriptContext( |
184 v8::Local<v8::Context> context, | 204 v8::Local<v8::Context> context, |
(...skipping 20 matching lines...) Expand all Loading... |
205 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 225 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
206 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 226 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
207 OnExtensionDispatchOnDisconnect) | 227 OnExtensionDispatchOnDisconnect) |
208 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnExtensionSetTabId) | 228 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnExtensionSetTabId) |
209 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, | 229 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, |
210 OnUpdateBrowserWindowId) | 230 OnUpdateBrowserWindowId) |
211 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, | 231 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, |
212 OnNotifyRendererViewType) | 232 OnNotifyRendererViewType) |
213 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) | 233 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) |
214 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) | 234 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
| 235 IPC_MESSAGE_HANDLER(ExtensionMsg_AssignPortId, OnAssignPortId) |
215 IPC_MESSAGE_UNHANDLED(handled = false) | 236 IPC_MESSAGE_UNHANDLED(handled = false) |
216 IPC_END_MESSAGE_MAP() | 237 IPC_END_MESSAGE_MAP() |
217 return handled; | 238 return handled; |
218 } | 239 } |
219 | 240 |
220 void ExtensionFrameHelper::OnExtensionValidateMessagePort(int port_id) { | 241 void ExtensionFrameHelper::OnExtensionValidateMessagePort(int port_id) { |
221 MessagingBindings::ValidateMessagePort( | 242 MessagingBindings::ValidateMessagePort( |
222 extension_dispatcher_->script_context_set(), port_id, render_frame()); | 243 extension_dispatcher_->script_context_set(), port_id, render_frame()); |
223 } | 244 } |
224 | 245 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 310 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
290 module_name, function_name, | 311 module_name, function_name, |
291 args, user_gesture); | 312 args, user_gesture); |
292 } | 313 } |
293 | 314 |
294 void ExtensionFrameHelper::OnDestruct() { | 315 void ExtensionFrameHelper::OnDestruct() { |
295 delete this; | 316 delete this; |
296 } | 317 } |
297 | 318 |
298 } // namespace extensions | 319 } // namespace extensions |
OLD | NEW |