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