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

Side by Side Diff: chrome/browser/renderer_host/chrome_render_view_host_observer.cc

Issue 7612016: Tie extension/app initialization to RenderView creation, not RenderViewHost creation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move initialization to ChromeRenderViewHostObserver. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/renderer_host/chrome_render_view_host_observer.h" 5 #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/dom_operation_notification_details.h" 8 #include "chrome/browser/dom_operation_notification_details.h"
9 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/net/predictor_api.h" 10 #include "chrome/browser/net/predictor_api.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/extensions/extension_messages.h"
11 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
16 #include "content/browser/browsing_instance.h"
17 #include "content/browser/child_process_security_policy.h"
18 #include "content/browser/renderer_host/render_view_host_delegate.h"
12 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/renderer_host/render_view_host_delegate.h" 20 #include "content/browser/site_instance.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
16 #include "content/common/url_constants.h" 22 #include "content/common/url_constants.h"
17 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
18 24
19 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( 25 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver(
20 RenderViewHost* render_view_host) 26 RenderViewHost* render_view_host)
21 : RenderViewHostObserver(render_view_host) { 27 : RenderViewHostObserver(render_view_host) {
22 } 28 }
23 29
24 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() { 30 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() {
25 } 31 }
26 32
33 void ChromeRenderViewHostObserver::RenderViewHostInitialized() {
34 InitRenderViewHostForExtensions();
35 }
36
37 void ChromeRenderViewHostObserver::InitRenderViewHostForExtensions() {
38 // Note that due to GetEffectiveURL(), even hosted apps will have a
Charlie Reis 2011/08/11 19:10:55 A little unfortunate that we're duplicating the co
39 // chrome-extension:// URL for their site, so we can ignore that wrinkle here.
40 SiteInstance* site_instance = render_view_host()->site_instance();
41 const GURL& site = site_instance->site();
42
43 if (!site.SchemeIs(chrome::kExtensionScheme))
44 return;
45
46 Profile* profile = Profile::FromBrowserContext(
47 site_instance->browsing_instance()->browser_context());
48 ExtensionService* service = profile->GetExtensionService();
49 if (!service)
50 return;
51
52 // This can happen if somebody typos a chrome-extension:// URL.
53 const Extension* extension = service->GetExtensionByURL(site);
54 if (!extension)
55 return;
56
57 RenderProcessHost* process = render_view_host()->process();
58
59 if (extension->is_app()) {
60 Send(new ExtensionMsg_ActivateApplication(extension->id()));
61 // Record which, if any, installed app is associated with this process.
62 // TODO(aa): Totally lame to store this state in a global map in extension
63 // service. Can we get it from EPM instead?
64 service->SetInstalledAppForRenderer(process->id(), extension);
65 }
66
67 // Some extensions use chrome:// URLs.
68 Extension::Type type = extension->GetType();
69 if (type == Extension::TYPE_EXTENSION ||
70 type == Extension::TYPE_PACKAGED_APP) {
71 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
72 process->id(), chrome::kChromeUIScheme);
73 }
74
75 if (type == Extension::TYPE_EXTENSION ||
76 type == Extension::TYPE_USER_SCRIPT ||
77 type == Extension::TYPE_PACKAGED_APP ||
78 (type == Extension::TYPE_HOSTED_APP &&
79 extension->location() == Extension::COMPONENT)) {
80 Send(new ExtensionMsg_ActivateExtension(extension->id()));
81 }
82 }
83
27 void ChromeRenderViewHostObserver::Navigate( 84 void ChromeRenderViewHostObserver::Navigate(
28 const ViewMsg_Navigate_Params& params) { 85 const ViewMsg_Navigate_Params& params) {
29 const GURL& url = params.url; 86 const GURL& url = params.url;
30 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame) && 87 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame) &&
31 (url.SchemeIs(chrome::kHttpScheme) || url.SchemeIs(chrome::kHttpsScheme))) 88 (url.SchemeIs(chrome::kHttpScheme) || url.SchemeIs(chrome::kHttpsScheme)))
32 chrome_browser_net::PreconnectUrlAndSubresources(url); 89 chrome_browser_net::PreconnectUrlAndSubresources(url);
33 } 90 }
34 91
35 bool ChromeRenderViewHostObserver::OnMessageReceived( 92 bool ChromeRenderViewHostObserver::OnMessageReceived(
36 const IPC::Message& message) { 93 const IPC::Message& message) {
37 bool handled = true; 94 bool handled = true;
38 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewHostObserver, message) 95 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewHostObserver, message)
39 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, 96 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse,
40 OnDomOperationResponse) 97 OnDomOperationResponse)
41 IPC_MESSAGE_UNHANDLED(handled = false) 98 IPC_MESSAGE_UNHANDLED(handled = false)
42 IPC_END_MESSAGE_MAP() 99 IPC_END_MESSAGE_MAP()
43 return handled; 100 return handled;
44 } 101 }
45 102
46 void ChromeRenderViewHostObserver::OnDomOperationResponse( 103 void ChromeRenderViewHostObserver::OnDomOperationResponse(
47 const std::string& json_string, int automation_id) { 104 const std::string& json_string, int automation_id) {
48 DomOperationNotificationDetails details(json_string, automation_id); 105 DomOperationNotificationDetails details(json_string, automation_id);
49 NotificationService::current()->Notify( 106 NotificationService::current()->Notify(
50 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, 107 chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
51 Source<RenderViewHost>(render_view_host()), 108 Source<RenderViewHost>(render_view_host()),
52 Details<DomOperationNotificationDetails>(&details)); 109 Details<DomOperationNotificationDetails>(&details));
53 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698