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

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 57923009: Move ExtensionProcessManager to src/extensions, part 3 - remove Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_process_manager.h" 5 #include "chrome/browser/extensions/extension_process_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 17 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
18 #include "chrome/browser/extensions/extension_host.h" 18 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/extensions/extension_info_map.h" 19 #include "chrome/browser/extensions/extension_info_map.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h" 21 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/extensions/extension_util.h" 22 #include "chrome/browser/extensions/extension_util.h"
23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/common/extensions/background_info.h" 23 #include "chrome/common/extensions/background_info.h"
25 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
26 #include "chrome/common/extensions/extension_messages.h" 25 #include "chrome/common/extensions/extension_messages.h"
27 #include "chrome/common/extensions/incognito_handler.h" 26 #include "chrome/common/extensions/incognito_handler.h"
28 #include "chrome/common/extensions/manifest_url_handler.h" 27 #include "chrome/common/extensions/manifest_url_handler.h"
29 #include "chrome/common/url_constants.h" 28 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/devtools_agent_host.h" 30 #include "content/public/browser/devtools_agent_host.h"
32 #include "content/public/browser/devtools_manager.h" 31 #include "content/public/browser/devtools_manager.h"
33 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
35 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/site_instance.h" 35 #include "content/public/browser/site_instance.h"
37 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
38 #include "content/public/browser/web_contents_delegate.h" 37 #include "content/public/browser/web_contents_delegate.h"
39 #include "content/public/browser/web_contents_observer.h" 38 #include "content/public/browser/web_contents_observer.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 80 }
82 81
83 // Incognito profiles use this process manager. It is mostly a shim that decides 82 // Incognito profiles use this process manager. It is mostly a shim that decides
84 // whether to fall back on the original profile's ExtensionProcessManager based 83 // whether to fall back on the original profile's ExtensionProcessManager based
85 // on whether a given extension uses "split" or "spanning" incognito behavior. 84 // on whether a given extension uses "split" or "spanning" incognito behavior.
86 class IncognitoExtensionProcessManager : public ExtensionProcessManager { 85 class IncognitoExtensionProcessManager : public ExtensionProcessManager {
87 public: 86 public:
88 IncognitoExtensionProcessManager(BrowserContext* incognito_context, 87 IncognitoExtensionProcessManager(BrowserContext* incognito_context,
89 BrowserContext* original_context); 88 BrowserContext* original_context);
90 virtual ~IncognitoExtensionProcessManager(); 89 virtual ~IncognitoExtensionProcessManager();
91 virtual ExtensionHost* CreateViewHost(
92 const Extension* extension,
93 const GURL& url,
94 Browser* browser,
95 extensions::ViewType view_type) OVERRIDE;
96 virtual ExtensionHost* CreateBackgroundHost(const Extension* extension, 90 virtual ExtensionHost* CreateBackgroundHost(const Extension* extension,
97 const GURL& url) OVERRIDE; 91 const GURL& url) OVERRIDE;
98 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE; 92 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE;
99 93
100 private: 94 private:
101 // Returns true if the extension is allowed to run in incognito mode. 95 // Returns true if the extension is allowed to run in incognito mode.
102 bool IsIncognitoEnabled(const Extension* extension); 96 bool IsIncognitoEnabled(const Extension* extension);
103 97
104 ExtensionProcessManager* original_manager_; 98 ExtensionProcessManager* original_manager_;
105 99
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ExtensionProcessManager::GetAllViews() const { 235 ExtensionProcessManager::GetAllViews() const {
242 ViewSet result; 236 ViewSet result;
243 for (ExtensionRenderViews::const_iterator iter = 237 for (ExtensionRenderViews::const_iterator iter =
244 all_extension_views_.begin(); 238 all_extension_views_.begin();
245 iter != all_extension_views_.end(); ++iter) { 239 iter != all_extension_views_.end(); ++iter) {
246 result.insert(iter->first); 240 result.insert(iter->first);
247 } 241 }
248 return result; 242 return result;
249 } 243 }
250 244
251 void ExtensionProcessManager::EnsureBrowserWhenRequired(
252 Browser* browser,
253 extensions::ViewType view_type) {
254 if (!browser) {
255 // A NULL browser may only be given for pop-up views and dialogs.
256 DCHECK(view_type == extensions::VIEW_TYPE_EXTENSION_POPUP ||
257 view_type == extensions::VIEW_TYPE_EXTENSION_DIALOG);
258 }
259 }
260
261 ExtensionHost* ExtensionProcessManager::CreateViewHost(
262 const Extension* extension,
263 const GURL& url,
264 Browser* browser,
265 extensions::ViewType view_type) {
266 DVLOG(1) << "CreateViewHost";
267 DCHECK(extension);
268 EnsureBrowserWhenRequired(browser, view_type);
269 ExtensionHost* host =
270 #if defined(OS_MACOSX)
271 new extensions::ExtensionHostMac(
272 extension, GetSiteInstanceForURL(url), url, view_type);
273 #else
274 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type);
275 #endif
276 host->CreateView(browser);
277 OnExtensionHostCreated(host, false);
278 return host;
279 }
280
281 ExtensionHost* ExtensionProcessManager::CreateViewHost(
282 const GURL& url, Browser* browser, extensions::ViewType view_type) {
283 EnsureBrowserWhenRequired(browser, view_type);
284 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
285 GetBrowserContext())->extension_service();
286 if (service) {
287 std::string extension_id = url.host();
288 if (url.SchemeIs(chrome::kChromeUIScheme) &&
289 url.host() == chrome::kChromeUIExtensionInfoHost)
290 extension_id = url.path().substr(1);
291 const Extension* extension =
292 service->extensions()->GetByID(extension_id);
293 if (extension)
294 return CreateViewHost(extension, url, browser, view_type);
295 }
296 return NULL;
297 }
298
299 ExtensionHost* ExtensionProcessManager::CreatePopupHost(
300 const Extension* extension, const GURL& url, Browser* browser) {
301 return CreateViewHost(
302 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_POPUP);
303 }
304
305 ExtensionHost* ExtensionProcessManager::CreatePopupHost(
306 const GURL& url, Browser* browser) {
307 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_POPUP);
308 }
309
310 ExtensionHost* ExtensionProcessManager::CreateDialogHost(const GURL& url) {
311 return CreateViewHost(url, NULL, extensions::VIEW_TYPE_EXTENSION_DIALOG);
312 }
313
314 ExtensionHost* ExtensionProcessManager::CreateInfobarHost(
315 const Extension* extension, const GURL& url, Browser* browser) {
316 return CreateViewHost(
317 extension, url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR);
318 }
319
320 ExtensionHost* ExtensionProcessManager::CreateInfobarHost(
321 const GURL& url, Browser* browser) {
322 return CreateViewHost(url, browser, extensions::VIEW_TYPE_EXTENSION_INFOBAR);
323 }
324
325 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( 245 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost(
326 const Extension* extension, const GURL& url) { 246 const Extension* extension, const GURL& url) {
327 DVLOG(1) << "CreateBackgroundHost " << url.spec(); 247 DVLOG(1) << "CreateBackgroundHost " << url.spec();
328 // Hosted apps are taken care of from BackgroundContentsService. Ignore them 248 // Hosted apps are taken care of from BackgroundContentsService. Ignore them
329 // here. 249 // here.
330 if (extension->is_hosted_app()) 250 if (extension->is_hosted_app())
331 return NULL; 251 return NULL;
332 252
333 // Don't create multiple background hosts for an extension. 253 // Don't create multiple background hosts for an extension.
334 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id())) 254 if (ExtensionHost* host = GetBackgroundHostForExtension(extension->id()))
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 chrome::NOTIFICATION_EXTENSIONS_READY, 707 chrome::NOTIFICATION_EXTENSIONS_READY,
788 content::Source<BrowserContext>(original_context))) { 708 content::Source<BrowserContext>(original_context))) {
789 registrar_.Remove(this, 709 registrar_.Remove(this,
790 chrome::NOTIFICATION_EXTENSIONS_READY, 710 chrome::NOTIFICATION_EXTENSIONS_READY,
791 content::Source<BrowserContext>(original_context)); 711 content::Source<BrowserContext>(original_context));
792 } 712 }
793 } 713 }
794 714
795 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 715 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
796 bool is_background) { 716 bool is_background) {
797 DCHECK_EQ(site_instance_->GetBrowserContext(), host->browser_context()); 717 DCHECK_EQ(GetBrowserContext(), host->browser_context());
798 if (is_background) { 718 if (is_background) {
799 background_hosts_.insert(host); 719 background_hosts_.insert(host);
800 720
801 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) { 721 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) {
802 linked_ptr<base::ElapsedTimer> since_suspended( 722 linked_ptr<base::ElapsedTimer> since_suspended(
803 background_page_data_[host->extension()->id()]. 723 background_page_data_[host->extension()->id()].
804 since_suspended.release()); 724 since_suspended.release());
805 if (since_suspended.get()) { 725 if (since_suspended.get()) {
806 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", 726 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime",
807 since_suspended->Elapsed()); 727 since_suspended->Elapsed());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 815
896 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() { 816 IncognitoExtensionProcessManager::~IncognitoExtensionProcessManager() {
897 // TODO(yoz): This cleanup code belongs in the MenuManager. 817 // TODO(yoz): This cleanup code belongs in the MenuManager.
898 // Remove "incognito" "split" mode context menu items. 818 // Remove "incognito" "split" mode context menu items.
899 ExtensionService* service = ExtensionSystem::GetForBrowserContext( 819 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
900 GetBrowserContext())->extension_service(); 820 GetBrowserContext())->extension_service();
901 if (service) 821 if (service)
902 service->menu_manager()->RemoveAllIncognitoContextItems(); 822 service->menu_manager()->RemoveAllIncognitoContextItems();
903 } 823 }
904 824
905 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
906 const Extension* extension,
907 const GURL& url,
908 Browser* browser,
909 extensions::ViewType view_type) {
910 if (extensions::IncognitoInfo::IsSplitMode(extension)) {
911 if (IsIncognitoEnabled(extension)) {
912 return ExtensionProcessManager::CreateViewHost(extension, url,
913 browser, view_type);
914 } else {
915 NOTREACHED() <<
916 "We shouldn't be trying to create an incognito extension view unless "
917 "it has been enabled for incognito.";
918 return NULL;
919 }
920 } else {
921 return original_manager_->CreateViewHost(extension, url,
922 browser, view_type);
923 }
924 }
925
926 ExtensionHost* IncognitoExtensionProcessManager::CreateBackgroundHost( 825 ExtensionHost* IncognitoExtensionProcessManager::CreateBackgroundHost(
927 const Extension* extension, const GURL& url) { 826 const Extension* extension, const GURL& url) {
928 if (extensions::IncognitoInfo::IsSplitMode(extension)) { 827 if (extensions::IncognitoInfo::IsSplitMode(extension)) {
929 if (IsIncognitoEnabled(extension)) 828 if (IsIncognitoEnabled(extension))
930 return ExtensionProcessManager::CreateBackgroundHost(extension, url); 829 return ExtensionProcessManager::CreateBackgroundHost(extension, url);
931 } else { 830 } else {
932 // Do nothing. If an extension is spanning, then its original-profile 831 // Do nothing. If an extension is spanning, then its original-profile
933 // background page is shared with incognito, so we don't create another. 832 // background page is shared with incognito, so we don't create another.
934 } 833 }
935 return NULL; 834 return NULL;
(...skipping 14 matching lines...) Expand all
950 return ExtensionProcessManager::GetSiteInstanceForURL(url); 849 return ExtensionProcessManager::GetSiteInstanceForURL(url);
951 } 850 }
952 851
953 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( 852 bool IncognitoExtensionProcessManager::IsIncognitoEnabled(
954 const Extension* extension) { 853 const Extension* extension) {
955 // Keep in sync with duplicate in extension_info_map.cc. 854 // Keep in sync with duplicate in extension_info_map.cc.
956 ExtensionService* service = ExtensionSystem::GetForBrowserContext( 855 ExtensionService* service = ExtensionSystem::GetForBrowserContext(
957 GetBrowserContext())->extension_service(); 856 GetBrowserContext())->extension_service();
958 return extension_util::IsIncognitoEnabled(extension->id(), service); 857 return extension_util::IsIncognitoEnabled(extension->id(), service);
959 } 858 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698