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 | |
193 void ExtensionFrameHelper::OnAssignPortId(int port_id, int request_id) { | |
nasko
2016/09/09 21:11:34
Methods in cc files should be ordered the same way
Devlin
2016/09/10 00:42:38
Whoops! Thanks for catching this.
| |
194 auto iter = pending_port_requests_.find(request_id); | |
195 DCHECK(iter != pending_port_requests_.end()); | |
196 iter->second.Run(port_id); | |
197 pending_port_requests_.erase(iter); | |
198 } | |
199 | |
175 void ExtensionFrameHelper::DidMatchCSS( | 200 void ExtensionFrameHelper::DidMatchCSS( |
176 const blink::WebVector<blink::WebString>& newly_matching_selectors, | 201 const blink::WebVector<blink::WebString>& newly_matching_selectors, |
177 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { | 202 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { |
178 extension_dispatcher_->content_watcher()->DidMatchCSS( | 203 extension_dispatcher_->content_watcher()->DidMatchCSS( |
179 render_frame()->GetWebFrame(), newly_matching_selectors, | 204 render_frame()->GetWebFrame(), newly_matching_selectors, |
180 stopped_matching_selectors); | 205 stopped_matching_selectors); |
181 } | 206 } |
182 | 207 |
183 void ExtensionFrameHelper::DidCreateScriptContext( | 208 void ExtensionFrameHelper::DidCreateScriptContext( |
184 v8::Local<v8::Context> context, | 209 v8::Local<v8::Context> context, |
(...skipping 20 matching lines...) Expand all Loading... | |
205 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 230 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
206 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 231 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
207 OnExtensionDispatchOnDisconnect) | 232 OnExtensionDispatchOnDisconnect) |
208 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnExtensionSetTabId) | 233 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnExtensionSetTabId) |
209 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, | 234 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, |
210 OnUpdateBrowserWindowId) | 235 OnUpdateBrowserWindowId) |
211 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, | 236 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, |
212 OnNotifyRendererViewType) | 237 OnNotifyRendererViewType) |
213 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) | 238 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) |
214 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) | 239 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
240 IPC_MESSAGE_HANDLER(ExtensionMsg_AssignPortId, OnAssignPortId) | |
215 IPC_MESSAGE_UNHANDLED(handled = false) | 241 IPC_MESSAGE_UNHANDLED(handled = false) |
216 IPC_END_MESSAGE_MAP() | 242 IPC_END_MESSAGE_MAP() |
217 return handled; | 243 return handled; |
218 } | 244 } |
219 | 245 |
220 void ExtensionFrameHelper::OnExtensionValidateMessagePort(int port_id) { | 246 void ExtensionFrameHelper::OnExtensionValidateMessagePort(int port_id) { |
221 MessagingBindings::ValidateMessagePort( | 247 MessagingBindings::ValidateMessagePort( |
222 extension_dispatcher_->script_context_set(), port_id, render_frame()); | 248 extension_dispatcher_->script_context_set(), port_id, render_frame()); |
223 } | 249 } |
224 | 250 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 315 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
290 module_name, function_name, | 316 module_name, function_name, |
291 args, user_gesture); | 317 args, user_gesture); |
292 } | 318 } |
293 | 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 |