Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: extensions/browser/extension_host.cc

Issue 823703004: Tracking push events for lucid sleep (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Validate message id from ipc Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/extension_host.h" 5 #include "extensions/browser/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
23 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
27 #include "content/public/browser/site_instance.h" 27 #include "content/public/browser/site_instance.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "extensions/browser/event_router.h" 29 #include "extensions/browser/event_router.h"
30 #include "extensions/browser/extension_error.h" 30 #include "extensions/browser/extension_error.h"
31 #include "extensions/browser/extension_host_delegate.h" 31 #include "extensions/browser/extension_host_delegate.h"
32 #include "extensions/browser/extension_host_observer.h"
32 #include "extensions/browser/extension_system.h" 33 #include "extensions/browser/extension_system.h"
33 #include "extensions/browser/extensions_browser_client.h" 34 #include "extensions/browser/extensions_browser_client.h"
34 #include "extensions/browser/notification_types.h" 35 #include "extensions/browser/notification_types.h"
35 #include "extensions/browser/process_manager.h" 36 #include "extensions/browser/process_manager.h"
36 #include "extensions/browser/runtime_data.h" 37 #include "extensions/browser/runtime_data.h"
37 #include "extensions/browser/view_type_utils.h" 38 #include "extensions/browser/view_type_utils.h"
38 #include "extensions/common/extension.h" 39 #include "extensions/common/extension.h"
39 #include "extensions/common/extension_messages.h" 40 #include "extensions/common/extension_messages.h"
40 #include "extensions/common/extension_urls.h" 41 #include "extensions/common/extension_urls.h"
41 #include "extensions/common/feature_switch.h" 42 #include "extensions/common/feature_switch.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ExtensionHost::~ExtensionHost() { 153 ExtensionHost::~ExtensionHost() {
153 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && 154 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
154 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { 155 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) {
155 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", 156 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime",
156 since_created_.Elapsed()); 157 since_created_.Elapsed());
157 } 158 }
158 content::NotificationService::current()->Notify( 159 content::NotificationService::current()->Notify(
159 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 160 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
160 content::Source<BrowserContext>(browser_context_), 161 content::Source<BrowserContext>(browser_context_),
161 content::Details<ExtensionHost>(this)); 162 content::Details<ExtensionHost>(this));
163 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
164 OnExtensionHostDestroyed(this));
162 ProcessCreationQueue::GetInstance()->Remove(this); 165 ProcessCreationQueue::GetInstance()->Remove(this);
163 } 166 }
164 167
165 content::RenderProcessHost* ExtensionHost::render_process_host() const { 168 content::RenderProcessHost* ExtensionHost::render_process_host() const {
166 return render_view_host()->GetProcess(); 169 return render_view_host()->GetProcess();
167 } 170 }
168 171
169 RenderViewHost* ExtensionHost::render_view_host() const { 172 RenderViewHost* ExtensionHost::render_view_host() const {
170 // TODO(mpcomplete): This can be NULL. How do we handle that? 173 // TODO(mpcomplete): This can be NULL. How do we handle that?
171 return render_view_host_; 174 return render_view_host_;
(...skipping 26 matching lines...) Expand all
198 extension_)) || 201 extension_)) ||
199 group_name == "ThrottleAll") { 202 group_name == "ThrottleAll") {
200 host_contents_->WasHidden(); 203 host_contents_->WasHidden();
201 } 204 }
202 } 205 }
203 // Connect orphaned dev-tools instances. 206 // Connect orphaned dev-tools instances.
204 delegate_->OnRenderViewCreatedForBackgroundPage(this); 207 delegate_->OnRenderViewCreatedForBackgroundPage(this);
205 } 208 }
206 } 209 }
207 210
211 void ExtensionHost::AddObserver(ExtensionHostObserver* observer) {
212 observer_list_.AddObserver(observer);
213 }
214
215 void ExtensionHost::RemoveObserver(ExtensionHostObserver* observer) {
216 observer_list_.RemoveObserver(observer);
217 }
218
219 void ExtensionHost::OnMessageDispatched(const std::string& event_name,
220 int message_id) {
221 unacked_messages_.insert(message_id);
not at google - send to devlin 2015/02/26 23:24:32 This method is called on the IO thread, but below
Chirantan Ekbote 2015/02/26 23:38:57 This method is called by NotifyEventDispatched in
not at google - send to devlin 2015/02/26 23:52:33 Ah, you're right. NotifyEventDispatched tricked me
Chirantan Ekbote 2015/02/27 00:15:00 I don't understand this. Both this function and E
not at google - send to devlin 2015/02/27 01:00:50 Yep you're right, sorry.
222 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
223 OnExtensionMessageDispatched(this, event_name, message_id));
224 }
225
226 void ExtensionHost::OnNetworkRequestStarted(uint64 request_id) {
227 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
228 OnNetworkRequestStarted(this, request_id));
229 }
230
231 void ExtensionHost::OnNetworkRequestDone(uint64 request_id) {
232 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
233 OnNetworkRequestDone(this, request_id));
234 }
235
208 const GURL& ExtensionHost::GetURL() const { 236 const GURL& ExtensionHost::GetURL() const {
209 return host_contents()->GetURL(); 237 return host_contents()->GetURL();
210 } 238 }
211 239
212 void ExtensionHost::LoadInitialURL() { 240 void ExtensionHost::LoadInitialURL() {
213 host_contents_->GetController().LoadURL( 241 host_contents_->GetController().LoadURL(
214 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, 242 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK,
215 std::string()); 243 std::string());
216 } 244 }
217 245
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 OnDecrementLazyKeepaliveCount) 374 OnDecrementLazyKeepaliveCount)
347 IPC_MESSAGE_UNHANDLED(handled = false) 375 IPC_MESSAGE_UNHANDLED(handled = false)
348 IPC_END_MESSAGE_MAP() 376 IPC_END_MESSAGE_MAP()
349 return handled; 377 return handled;
350 } 378 }
351 379
352 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { 380 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
353 extension_function_dispatcher_.Dispatch(params, render_view_host()); 381 extension_function_dispatcher_.Dispatch(params, render_view_host());
354 } 382 }
355 383
356 void ExtensionHost::OnEventAck() { 384 void ExtensionHost::OnEventAck(int message_id) {
357 EventRouter* router = EventRouter::Get(browser_context_); 385 EventRouter* router = EventRouter::Get(browser_context_);
358 if (router) 386 if (router)
359 router->OnEventAck(browser_context_, extension_id()); 387 router->OnEventAck(browser_context_, extension_id());
388
389 // A compromised renderer could start sending out arbitrary message ids, which
390 // may affect other renderers by causing downstream methods to think that
391 // messages for other extensions have been acked. Make sure that the message
392 // id sent by the renderer is one that this ExtensionHost expects to receive.
393 // This way if a renderer _is_ compromised, it can really only affect itself.
394 if (unacked_messages_.erase(message_id) > 0) {
395 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
396 OnExtensionMessageAcked(this, message_id));
397 }
jln (very slow on Chromium) 2015/01/28 01:18:27 We should kill the renderer in the else {} clause
Chirantan Ekbote 2015/01/28 22:11:52 Done.
360 } 398 }
361 399
362 void ExtensionHost::OnIncrementLazyKeepaliveCount() { 400 void ExtensionHost::OnIncrementLazyKeepaliveCount() {
363 ProcessManager::Get(browser_context_) 401 ProcessManager::Get(browser_context_)
364 ->IncrementLazyKeepaliveCount(extension()); 402 ->IncrementLazyKeepaliveCount(extension());
365 } 403 }
366 404
367 void ExtensionHost::OnDecrementLazyKeepaliveCount() { 405 void ExtensionHost::OnDecrementLazyKeepaliveCount() {
368 ProcessManager::Get(browser_context_) 406 ProcessManager::Get(browser_context_)
369 ->DecrementLazyKeepaliveCount(extension()); 407 ->DecrementLazyKeepaliveCount(extension());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 return delegate_->CheckMediaAccessPermission( 481 return delegate_->CheckMediaAccessPermission(
444 web_contents, security_origin, type, extension()); 482 web_contents, security_origin, type, extension());
445 } 483 }
446 484
447 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { 485 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) {
448 ViewType view_type = extensions::GetViewType(web_contents); 486 ViewType view_type = extensions::GetViewType(web_contents);
449 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 487 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
450 } 488 }
451 489
452 } // namespace extensions 490 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698