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

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

Issue 11348358: Remove an obsolete NULL test for TabContents in NeedsExtensionWebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_controller_factory.h" 5 #include "chrome/browser/ui/webui/chrome_web_ui_controller_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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return new ExtensionInfoUI(web_ui, url); 140 return new ExtensionInfoUI(web_ui, url);
141 } 141 }
142 142
143 // Special case for older about: handlers. 143 // Special case for older about: handlers.
144 template<> 144 template<>
145 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) { 145 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
146 return new AboutUI(web_ui, url.host()); 146 return new AboutUI(web_ui, url.host());
147 } 147 }
148 148
149 // Only create ExtensionWebUI for URLs that are allowed extension bindings, 149 // Only create ExtensionWebUI for URLs that are allowed extension bindings,
150 // hosted by actual tabs. If there is no TabContents, it likely refers 150 // hosted by actual tabs.
151 // to another container type, like an extension background page. If there is 151 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) {
152 // no WebUI (it's not accessible when calling GetWebUIType and related
153 // functions) then we conservatively assume that we need a WebUI.
154 bool NeedsExtensionWebUI(WebUI* web_ui,
155 Profile* profile,
156 const GURL& url) {
157 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; 152 ExtensionService* service = profile ? profile->GetExtensionService() : NULL;
158 return service && service->ExtensionBindingsAllowed(url) && 153 return service && service->ExtensionBindingsAllowed(url);
159 (!web_ui || TabContents::FromWebContents(web_ui->GetWebContents()));
160 } 154 }
161 155
162 // Returns a function that can be used to create the right type of WebUI for a 156 // Returns a function that can be used to create the right type of WebUI for a
163 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated 157 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
164 // with it. 158 // with it.
165 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, 159 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
166 Profile* profile, 160 Profile* profile,
167 const GURL& url) { 161 const GURL& url) {
168 #if defined(ENABLE_EXTENSIONS) 162 #if defined(ENABLE_EXTENSIONS)
169 if (NeedsExtensionWebUI(web_ui, profile, url)) 163 if (NeedsExtensionWebUI(profile, url))
170 return &NewWebUI<ExtensionWebUI>; 164 return &NewWebUI<ExtensionWebUI>;
171 #endif 165 #endif
172 166
173 // This will get called a lot to check all URLs, so do a quick check of other 167 // This will get called a lot to check all URLs, so do a quick check of other
174 // schemes to filter out most URLs. 168 // schemes to filter out most URLs.
175 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && 169 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) &&
176 !url.SchemeIs(chrome::kChromeInternalScheme) && 170 !url.SchemeIs(chrome::kChromeInternalScheme) &&
177 !url.SchemeIs(chrome::kChromeUIScheme)) { 171 !url.SchemeIs(chrome::kChromeUIScheme)) {
178 return NULL; 172 return NULL;
179 } 173 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 433
440 bool ChromeWebUIControllerFactory::UseWebUIForURL( 434 bool ChromeWebUIControllerFactory::UseWebUIForURL(
441 content::BrowserContext* browser_context, const GURL& url) const { 435 content::BrowserContext* browser_context, const GURL& url) const {
442 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; 436 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI;
443 } 437 }
444 438
445 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( 439 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL(
446 content::BrowserContext* browser_context, const GURL& url) const { 440 content::BrowserContext* browser_context, const GURL& url) const {
447 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI 441 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI
448 // bindings (see the ExtensionWebUI constructor). 442 // bindings (see the ExtensionWebUI constructor).
449 return !NeedsExtensionWebUI(NULL, 443 return !NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context),
450 Profile::FromBrowserContext(browser_context),
451 url) && 444 url) &&
452 UseWebUIForURL(browser_context, url); 445 UseWebUIForURL(browser_context, url);
453 } 446 }
454 447
455 bool ChromeWebUIControllerFactory::IsURLAcceptableForWebUI( 448 bool ChromeWebUIControllerFactory::IsURLAcceptableForWebUI(
456 content::BrowserContext* browser_context, 449 content::BrowserContext* browser_context,
457 const GURL& url, 450 const GURL& url,
458 bool data_urls_allowed) const { 451 bool data_urls_allowed) const {
459 return UseWebUIForURL(browser_context, url) || 452 return UseWebUIForURL(browser_context, url) ||
460 // javacsript: URLs are allowed to run in Web UI pages 453 // javacsript: URLs are allowed to run in Web UI pages
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 if (page_url.host() == chrome::kChromeUISettingsFrameHost) 595 if (page_url.host() == chrome::kChromeUISettingsFrameHost)
603 return options::OptionsUI::GetFaviconResourceBytes(scale_factor); 596 return options::OptionsUI::GetFaviconResourceBytes(scale_factor);
604 597
605 // Android doesn't use the plugins pages. 598 // Android doesn't use the plugins pages.
606 if (page_url.host() == chrome::kChromeUIPluginsHost) 599 if (page_url.host() == chrome::kChromeUIPluginsHost)
607 return PluginsUI::GetFaviconResourceBytes(scale_factor); 600 return PluginsUI::GetFaviconResourceBytes(scale_factor);
608 #endif 601 #endif
609 602
610 return NULL; 603 return NULL;
611 } 604 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698