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

Side by Side Diff: chrome/browser/ui/webui/chrome_web_ui_factory.cc

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures Created 8 years, 11 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) 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/ui/webui/chrome_web_ui_factory.h" 5 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/about_flags.h" 8 #include "chrome/browser/about_flags.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_web_ui.h" 10 #include "chrome/browser/extensions/extension_web_ui.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 #if defined(OS_POSIX) && !defined(OS_MACOSX) 79 #if defined(OS_POSIX) && !defined(OS_MACOSX)
80 #include "chrome/browser/ui/webui/certificate_viewer_ui.h" 80 #include "chrome/browser/ui/webui/certificate_viewer_ui.h"
81 #endif 81 #endif
82 82
83 #if !defined(USE_AURA) 83 #if !defined(USE_AURA)
84 #include "chrome/browser/ui/webui/input_window_dialog_ui.h" 84 #include "chrome/browser/ui/webui/input_window_dialog_ui.h"
85 #endif 85 #endif
86 86
87 using content::WebContents; 87 using content::WebContents;
88 using content::WebUIController;
88 89
89 namespace { 90 namespace {
90 91
91 // A function for creating a new WebUI. The caller owns the return value, which 92 // A function for creating a new WebUI. The caller owns the return value, which
92 // may be NULL (for example, if the URL refers to an non-existent extension). 93 // may be NULL (for example, if the URL refers to an non-existent extension).
93 typedef WebUI* (*WebUIFactoryFunction)(WebContents* web_contents, 94 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui,
94 const GURL& url); 95 const GURL& url);
95 96
96 // Template for defining WebUIFactoryFunction. 97 // Template for defining WebUIFactoryFunction.
97 template<class T> 98 template<class T>
98 WebUI* NewWebUI(WebContents* contents, const GURL& url) { 99 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
99 return new T(contents); 100 return new T(web_ui);
100 } 101 }
101 102
102 // Special case for extensions. 103 // Special case for extensions.
103 template<> 104 template<>
104 WebUI* NewWebUI<ExtensionWebUI>(WebContents* contents, const GURL& url) { 105 WebUIController* NewWebUI<ExtensionWebUI>(WebUI* web_ui, const GURL& url) {
105 return new ExtensionWebUI(contents, url); 106 return new ExtensionWebUI(web_ui, url);
106 } 107 }
107 108
108 // Special case for older about: handlers. 109 // Special case for older about: handlers.
109 template<> 110 template<>
110 WebUI* NewWebUI<AboutUI>(WebContents* contents, const GURL& url) { 111 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
111 return new AboutUI(contents, url.host()); 112 return new AboutUI(web_ui, url.host());
112 } 113 }
113 114
114 // Only create ExtensionWebUI for URLs that are allowed extension bindings, 115 // Only create ExtensionWebUI for URLs that are allowed extension bindings,
115 // hosted by actual tabs. If tab_contents has no wrapper, it likely refers 116 // hosted by actual tabs. If tab_contents has no wrapper, it likely refers
116 // to another container type, like an extension background page. If there is 117 // to another container type, like an extension background page. If there is
117 // no tab_contents (it's not accessible when calling GetWebUIType and related 118 // no WebUI (it's not accessible when calling GetWebUIType and related
118 // functions) then we conservatively assume that we need a WebUI. 119 // functions) then we conservatively assume that we need a WebUI.
119 bool NeedsExtensionWebUI(WebContents* web_contents, 120 bool NeedsExtensionWebUI(WebUI* web_ui,
120 Profile* profile, 121 Profile* profile,
121 const GURL& url) { 122 const GURL& url) {
122 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; 123 ExtensionService* service = profile ? profile->GetExtensionService() : NULL;
123 return service && service->ExtensionBindingsAllowed(url) && 124 return service && service->ExtensionBindingsAllowed(url) &&
124 (!web_contents || 125 (!web_ui ||
125 TabContentsWrapper::GetCurrentWrapperForContents(web_contents)); 126 TabContentsWrapper::GetCurrentWrapperForContents(
127 web_ui->GetWebContents()));
126 } 128 }
127 129
128 // Returns a function that can be used to create the right type of WebUI for a 130 // Returns a function that can be used to create the right type of WebUI for a
129 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated 131 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
130 // with it. 132 // with it.
131 WebUIFactoryFunction GetWebUIFactoryFunction(WebContents* web_contents, 133 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
132 Profile* profile, 134 Profile* profile,
133 const GURL& url) { 135 const GURL& url) {
134 if (NeedsExtensionWebUI(web_contents, profile, url)) 136 if (NeedsExtensionWebUI(web_ui, profile, url))
135 return &NewWebUI<ExtensionWebUI>; 137 return &NewWebUI<ExtensionWebUI>;
136 138
137 // This will get called a lot to check all URLs, so do a quick check of other 139 // This will get called a lot to check all URLs, so do a quick check of other
138 // schemes to filter out most URLs. 140 // schemes to filter out most URLs.
139 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && 141 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) &&
140 !url.SchemeIs(chrome::kChromeInternalScheme) && 142 !url.SchemeIs(chrome::kChromeInternalScheme) &&
141 !url.SchemeIs(chrome::kChromeUIScheme)) { 143 !url.SchemeIs(chrome::kChromeUIScheme)) {
142 return NULL; 144 return NULL;
143 } 145 }
144 146
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // It's possible to load about:blank in a Web UI renderer. 390 // It's possible to load about:blank in a Web UI renderer.
389 // See http://crbug.com/42547 391 // See http://crbug.com/42547
390 url.spec() == chrome::kAboutBlankURL || 392 url.spec() == chrome::kAboutBlankURL ||
391 // Chrome URLs crash, kill, hang, and shorthang are allowed. 393 // Chrome URLs crash, kill, hang, and shorthang are allowed.
392 url == GURL(chrome::kChromeUICrashURL) || 394 url == GURL(chrome::kChromeUICrashURL) ||
393 url == GURL(chrome::kChromeUIKillURL) || 395 url == GURL(chrome::kChromeUIKillURL) ||
394 url == GURL(chrome::kChromeUIHangURL) || 396 url == GURL(chrome::kChromeUIHangURL) ||
395 url == GURL(chrome::kChromeUIShorthangURL); 397 url == GURL(chrome::kChromeUIShorthangURL);
396 } 398 }
397 399
398 WebUI* ChromeWebUIFactory::CreateWebUIForURL( 400 WebUIController* ChromeWebUIFactory::CreateWebUIForURL(
399 content::WebContents* web_contents, 401 WebUI* web_ui,
400 const GURL& url) const { 402 const GURL& url) const {
401 Profile* profile = 403 Profile* profile = Profile::FromBrowserContext(
402 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 404 web_ui->GetWebContents()->GetBrowserContext());
403 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_contents, 405 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui,
404 profile, url); 406 profile, url);
405 if (!function) 407 if (!function)
406 return NULL; 408 return NULL;
407 return (*function)(web_contents, url); 409
410 return (*function)(web_ui, url);
408 } 411 }
409 412
410 void ChromeWebUIFactory::GetFaviconForURL( 413 void ChromeWebUIFactory::GetFaviconForURL(
411 Profile* profile, 414 Profile* profile,
412 FaviconService::GetFaviconRequest* request, 415 FaviconService::GetFaviconRequest* request,
413 const GURL& page_url) const { 416 const GURL& page_url) const {
414 // All extensions but the bookmark manager get their favicon from the icons 417 // All extensions but the bookmark manager get their favicon from the icons
415 // part of the manifest. 418 // part of the manifest.
416 if (page_url.SchemeIs(chrome::kExtensionScheme) && 419 if (page_url.SchemeIs(chrome::kExtensionScheme) &&
417 page_url.host() != extension_misc::kBookmarkManagerId) { 420 page_url.host() != extension_misc::kBookmarkManagerId) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 return OptionsUI::GetFaviconResourceBytes(); 485 return OptionsUI::GetFaviconResourceBytes();
483 486
484 if (page_url.host() == chrome::kChromeUISettingsFrameHost) 487 if (page_url.host() == chrome::kChromeUISettingsFrameHost)
485 return options2::OptionsUI::GetFaviconResourceBytes(); 488 return options2::OptionsUI::GetFaviconResourceBytes();
486 489
487 if (page_url.host() == chrome::kChromeUIPluginsHost) 490 if (page_url.host() == chrome::kChromeUIPluginsHost)
488 return PluginsUI::GetFaviconResourceBytes(); 491 return PluginsUI::GetFaviconResourceBytes();
489 492
490 return NULL; 493 return NULL;
491 } 494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698