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

Side by Side Diff: chrome/browser/chrome_content_browser_client.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 all extension-related RVH 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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/app/breakpad_mac.h" 8 #include "chrome/app/breakpad_mac.h"
9 #include "chrome/browser/browser_about_handler.h" 9 #include "chrome/browser/browser_about_handler.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 27 matching lines...) Expand all
38 #include "chrome/browser/ssl/ssl_add_cert_handler.h" 38 #include "chrome/browser/ssl/ssl_add_cert_handler.h"
39 #include "chrome/browser/ssl/ssl_blocking_page.h" 39 #include "chrome/browser/ssl/ssl_blocking_page.h"
40 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" 40 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
41 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" 41 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
42 #include "chrome/browser/tab_contents/tab_util.h" 42 #include "chrome/browser/tab_contents/tab_util.h"
43 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 43 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
44 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" 44 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
45 #include "chrome/common/child_process_logging.h" 45 #include "chrome/common/child_process_logging.h"
46 #include "chrome/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/extensions/extension.h" 47 #include "chrome/common/extensions/extension.h"
48 #include "chrome/common/extensions/extension_messages.h"
49 #include "chrome/common/logging_chrome.h" 48 #include "chrome/common/logging_chrome.h"
50 #include "chrome/common/pref_names.h" 49 #include "chrome/common/pref_names.h"
51 #include "chrome/common/render_messages.h" 50 #include "chrome/common/render_messages.h"
52 #include "chrome/common/url_constants.h" 51 #include "chrome/common/url_constants.h"
53 #include "content/browser/browser_url_handler.h" 52 #include "content/browser/browser_url_handler.h"
54 #include "content/browser/browsing_instance.h" 53 #include "content/browser/browsing_instance.h"
55 #include "content/browser/child_process_security_policy.h"
56 #include "content/browser/debugger/devtools_handler.h" 54 #include "content/browser/debugger/devtools_handler.h"
57 #include "content/browser/plugin_process_host.h" 55 #include "content/browser/plugin_process_host.h"
58 #include "content/browser/renderer_host/browser_render_process_host.h" 56 #include "content/browser/renderer_host/browser_render_process_host.h"
59 #include "content/browser/renderer_host/render_view_host.h" 57 #include "content/browser/renderer_host/render_view_host.h"
60 #include "content/browser/resource_context.h" 58 #include "content/browser/resource_context.h"
61 #include "content/browser/site_instance.h" 59 #include "content/browser/site_instance.h"
62 #include "content/browser/ssl/ssl_cert_error_handler.h" 60 #include "content/browser/ssl/ssl_cert_error_handler.h"
63 #include "content/browser/ssl/ssl_client_auth_handler.h" 61 #include "content/browser/ssl/ssl_client_auth_handler.h"
64 #include "content/browser/tab_contents/tab_contents.h" 62 #include "content/browser/tab_contents/tab_contents.h"
65 #include "content/browser/worker_host/worker_process_host.h" 63 #include "content/browser/worker_host/worker_process_host.h"
66 #include "content/common/bindings_policy.h"
67 #include "content/common/desktop_notification_messages.h" 64 #include "content/common/desktop_notification_messages.h"
68 #include "grit/ui_resources.h" 65 #include "grit/ui_resources.h"
69 #include "net/base/cookie_monster.h" 66 #include "net/base/cookie_monster.h"
70 #include "net/base/cookie_options.h" 67 #include "net/base/cookie_options.h"
71 #include "ui/base/resource/resource_bundle.h" 68 #include "ui/base/resource/resource_bundle.h"
72 69
73 #if defined(OS_LINUX) 70 #if defined(OS_LINUX)
74 #include "base/linux_util.h" 71 #include "base/linux_util.h"
75 #include "chrome/browser/crash_handler_host_linux.h" 72 #include "chrome/browser/crash_handler_host_linux.h"
76 #endif 73 #endif
77 74
78 #if defined(USE_NSS) 75 #if defined(USE_NSS)
79 #include "chrome/browser/ui/crypto_module_password_dialog.h" 76 #include "chrome/browser/ui/crypto_module_password_dialog.h"
80 #endif 77 #endif
81 78
82 namespace { 79 namespace {
83 80
84 void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
85 // Note that due to GetEffectiveURL(), even hosted apps will have a
86 // chrome-extension:// URL for their site, so we can ignore that wrinkle here.
87 SiteInstance* site_instance = render_view_host->site_instance();
88 const GURL& site = site_instance->site();
89
90 if (!site.SchemeIs(chrome::kExtensionScheme))
91 return;
92
93 Profile* profile = Profile::FromBrowserContext(
94 site_instance->browsing_instance()->browser_context());
95 ExtensionService* service = profile->GetExtensionService();
96 if (!service)
97 return;
98
99 ExtensionProcessManager* process_manager =
100 profile->GetExtensionProcessManager();
101 CHECK(process_manager);
102
103 // This can happen if somebody typos a chrome-extension:// URL.
104 const Extension* extension = service->GetExtensionByURL(site);
105 if (!extension)
106 return;
107
108 site_instance->GetProcess()->mark_is_extension_process();
109
110 // Register the association between extension and SiteInstance with
111 // ExtensionProcessManager.
112 // TODO(creis): Use this to replace SetInstalledAppForRenderer below.
113 process_manager->RegisterExtensionSiteInstance(site_instance->id(),
114 extension->id());
115
116 RenderProcessHost* process = render_view_host->process();
117
118 if (extension->is_app()) {
119 render_view_host->Send(
120 new ExtensionMsg_ActivateApplication(extension->id()));
121 // Record which, if any, installed app is associated with this process.
122 // TODO(aa): Totally lame to store this state in a global map in extension
123 // service. Can we get it from EPM instead?
124 service->SetInstalledAppForRenderer(process->id(), extension);
125 }
126
127 // Some extensions use chrome:// URLs.
128 Extension::Type type = extension->GetType();
129 if (type == Extension::TYPE_EXTENSION ||
130 type == Extension::TYPE_PACKAGED_APP) {
131 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
132 process->id(), chrome::kChromeUIScheme);
133 }
134
135 // Enable extension bindings for the renderer. Currently only extensions,
136 // packaged apps, and hosted component apps use extension bindings.
137 if (type == Extension::TYPE_EXTENSION ||
138 type == Extension::TYPE_USER_SCRIPT ||
139 type == Extension::TYPE_PACKAGED_APP ||
140 (type == Extension::TYPE_HOSTED_APP &&
141 extension->location() == Extension::COMPONENT)) {
142 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id()));
143 render_view_host->AllowBindings(BindingsPolicy::EXTENSION);
144 }
145 }
146
147 // Handles rewriting Web UI URLs. 81 // Handles rewriting Web UI URLs.
148 static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 82 static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
149 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url)) 83 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
150 return false; 84 return false;
151 85
152 // Special case the new tab page. In older versions of Chrome, the new tab 86 // Special case the new tab page. In older versions of Chrome, the new tab
153 // page was hosted at chrome-internal:<blah>. This might be in people's saved 87 // page was hosted at chrome-internal:<blah>. This might be in people's saved
154 // sessions or bookmarks, so we say any URL with that scheme triggers the new 88 // sessions or bookmarks, so we say any URL with that scheme triggers the new
155 // tab page. 89 // tab page.
156 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 90 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
157 // Rewrite it with the proper new tab URL. 91 // Rewrite it with the proper new tab URL.
158 *url = GURL(chrome::kChromeUINewTabURL); 92 *url = GURL(chrome::kChromeUINewTabURL);
159 } 93 }
160 94
161 return true; 95 return true;
162 } 96 }
163 97
164 } // namespace 98 } // namespace
165 99
166 namespace chrome { 100 namespace chrome {
167 101
168 void ChromeContentBrowserClient::RenderViewHostCreated( 102 void ChromeContentBrowserClient::RenderViewHostCreated(
169 RenderViewHost* render_view_host) { 103 RenderViewHost* render_view_host) {
170 new ChromeRenderViewHostObserver(render_view_host); 104 new ChromeRenderViewHostObserver(render_view_host);
171 new DevToolsHandler(render_view_host); 105 new DevToolsHandler(render_view_host);
172 new ExtensionMessageHandler(render_view_host); 106 new ExtensionMessageHandler(render_view_host);
173
174 InitRenderViewHostForExtensions(render_view_host);
175 } 107 }
176 108
177 void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( 109 void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
178 BrowserRenderProcessHost* host) { 110 BrowserRenderProcessHost* host) {
179 int id = host->id(); 111 int id = host->id();
180 Profile* profile = Profile::FromBrowserContext(host->browser_context()); 112 Profile* profile = Profile::FromBrowserContext(host->browser_context());
181 host->channel()->AddFilter(new ChromeRenderMessageFilter( 113 host->channel()->AddFilter(new ChromeRenderMessageFilter(
182 id, profile, profile->GetRequestContextForRenderProcess(id))); 114 id, profile, profile->GetRequestContextForRenderProcess(id)));
183 host->channel()->AddFilter(new PrintingMessageFilter()); 115 host->channel()->AddFilter(new PrintingMessageFilter());
184 host->channel()->AddFilter( 116 host->channel()->AddFilter(
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 #if defined(USE_NSS) 717 #if defined(USE_NSS)
786 crypto::CryptoModuleBlockingPasswordDelegate* 718 crypto::CryptoModuleBlockingPasswordDelegate*
787 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 719 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
788 const GURL& url) { 720 const GURL& url) {
789 return browser::NewCryptoModuleBlockingDialogDelegate( 721 return browser::NewCryptoModuleBlockingDialogDelegate(
790 browser::kCryptoModulePasswordKeygen, url.host()); 722 browser::kCryptoModulePasswordKeygen, url.host());
791 } 723 }
792 #endif 724 #endif
793 725
794 } // namespace chrome 726 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698