Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" | 51 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" |
| 52 #include "chrome/browser/ui/webui/version_ui.h" | 52 #include "chrome/browser/ui/webui/version_ui.h" |
| 53 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
| 54 #include "chrome/common/extensions/extension_constants.h" | 54 #include "chrome/common/extensions/extension_constants.h" |
| 55 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
| 56 #include "chrome/common/url_constants.h" | 56 #include "chrome/common/url_constants.h" |
| 57 #include "components/dom_distiller/content/dom_distiller_service_factory.h" | 57 #include "components/dom_distiller/content/dom_distiller_service_factory.h" |
| 58 #include "components/dom_distiller/core/dom_distiller_constants.h" | 58 #include "components/dom_distiller/core/dom_distiller_constants.h" |
| 59 #include "components/dom_distiller/core/dom_distiller_service.h" | 59 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 60 #include "components/dom_distiller/webui/dom_distiller_ui.h" | 60 #include "components/dom_distiller/webui/dom_distiller_ui.h" |
| 61 #include "components/dom_distiller/webui/dom_distiller_viewer_ui.h" | |
| 61 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
| 62 #include "content/public/browser/web_ui.h" | 63 #include "content/public/browser/web_ui.h" |
| 63 #include "content/public/common/content_client.h" | 64 #include "content/public/common/content_client.h" |
| 64 #include "content/public/common/url_utils.h" | 65 #include "content/public/common/url_utils.h" |
| 65 #include "extensions/common/constants.h" | 66 #include "extensions/common/constants.h" |
| 66 #include "extensions/common/feature_switch.h" | 67 #include "extensions/common/feature_switch.h" |
| 67 #include "ui/gfx/favicon_size.h" | 68 #include "ui/gfx/favicon_size.h" |
| 68 #include "ui/web_dialogs/web_dialog_ui.h" | 69 #include "ui/web_dialogs/web_dialog_ui.h" |
| 69 #include "url/gurl.h" | 70 #include "url/gurl.h" |
| 70 | 71 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 template<> | 193 template<> |
| 193 WebUIController* NewWebUI<dom_distiller::DomDistillerUi>(WebUI* web_ui, | 194 WebUIController* NewWebUI<dom_distiller::DomDistillerUi>(WebUI* web_ui, |
| 194 const GURL& url) { | 195 const GURL& url) { |
| 195 // The DomDistillerUi can not depend on components/dom_distiller/content, | 196 // The DomDistillerUi can not depend on components/dom_distiller/content, |
| 196 // so inject the correct DomDistillerService from chrome/. | 197 // so inject the correct DomDistillerService from chrome/. |
| 197 content::BrowserContext* browser_context = | 198 content::BrowserContext* browser_context = |
| 198 web_ui->GetWebContents()->GetBrowserContext(); | 199 web_ui->GetWebContents()->GetBrowserContext(); |
| 199 dom_distiller::DomDistillerService* service = | 200 dom_distiller::DomDistillerService* service = |
| 200 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( | 201 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( |
| 201 browser_context); | 202 browser_context); |
| 202 return new dom_distiller::DomDistillerUi(web_ui, service, "dummy"); | 203 return new dom_distiller::DomDistillerUi(web_ui, |
| 204 service, | |
| 205 chrome::kDomDistillerScheme); | |
| 206 } | |
| 207 | |
| 208 template<> | |
| 209 WebUIController* NewWebUI<dom_distiller::DomDistillerViewerUi>( | |
| 210 WebUI* web_ui, | |
| 211 const GURL& url) { | |
| 212 // The DomDistillerViewerUi can not depend on | |
| 213 // components/dom_distiller/content, so inject the correct DomDistillerService | |
| 214 // from chrome/. | |
| 215 content::BrowserContext* browser_context = | |
| 216 web_ui->GetWebContents()->GetBrowserContext(); | |
| 217 dom_distiller::DomDistillerService* service = | |
| 218 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( | |
| 219 browser_context); | |
| 220 return new dom_distiller::DomDistillerViewerUi(web_ui, service); | |
|
nyquist
2013/12/04 23:56:56
I think this can be added in the next CL instead.
| |
| 203 } | 221 } |
| 204 | 222 |
| 205 // Only create ExtensionWebUI for URLs that are allowed extension bindings, | 223 // Only create ExtensionWebUI for URLs that are allowed extension bindings, |
| 206 // hosted by actual tabs. | 224 // hosted by actual tabs. |
| 207 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { | 225 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { |
| 208 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; | 226 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; |
| 209 return service && service->ExtensionBindingsAllowed(url); | 227 return service && service->ExtensionBindingsAllowed(url); |
| 210 } | 228 } |
| 211 | 229 |
| 212 // Returns a function that can be used to create the right type of WebUI for a | 230 // Returns a function that can be used to create the right type of WebUI for a |
| 213 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 231 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
| 214 // with it. | 232 // with it. |
| 215 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, | 233 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, |
| 216 Profile* profile, | 234 Profile* profile, |
| 217 const GURL& url) { | 235 const GURL& url) { |
| 218 #if defined(ENABLE_EXTENSIONS) | 236 #if defined(ENABLE_EXTENSIONS) |
| 219 if (NeedsExtensionWebUI(profile, url)) | 237 if (NeedsExtensionWebUI(profile, url)) |
| 220 return &NewWebUI<ExtensionWebUI>; | 238 return &NewWebUI<ExtensionWebUI>; |
| 221 #endif | 239 #endif |
| 222 | 240 |
| 223 // This will get called a lot to check all URLs, so do a quick check of other | 241 // This will get called a lot to check all URLs, so do a quick check of other |
| 224 // schemes to filter out most URLs. | 242 // schemes to filter out most URLs. |
| 225 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && | 243 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && |
| 226 !url.SchemeIs(chrome::kChromeInternalScheme) && | 244 !url.SchemeIs(chrome::kChromeInternalScheme) && |
| 227 !url.SchemeIs(chrome::kChromeUIScheme)) { | 245 !url.SchemeIs(chrome::kChromeUIScheme) && |
| 246 !url.SchemeIs(chrome::kDomDistillerScheme)) { | |
| 228 return NULL; | 247 return NULL; |
| 229 } | 248 } |
| 230 | 249 |
| 231 // Special case the new tab page. In older versions of Chrome, the new tab | 250 // Special case the new tab page. In older versions of Chrome, the new tab |
| 232 // page was hosted at chrome-internal:<blah>. This might be in people's saved | 251 // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 233 // sessions or bookmarks, so we say any URL with that scheme triggers the new | 252 // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 234 // tab page. | 253 // tab page. |
| 235 if (url.host() == chrome::kChromeUINewTabHost || | 254 if (url.host() == chrome::kChromeUINewTabHost || |
| 236 url.SchemeIs(chrome::kChromeInternalScheme)) { | 255 url.SchemeIs(chrome::kChromeInternalScheme)) { |
| 237 return &NewWebUI<NewTabUI>; | 256 return &NewWebUI<NewTabUI>; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 return &NewWebUI<extensions::ExtensionsUI>; | 503 return &NewWebUI<extensions::ExtensionsUI>; |
| 485 #endif | 504 #endif |
| 486 #if defined(ENABLE_FULL_PRINTING) | 505 #if defined(ENABLE_FULL_PRINTING) |
| 487 if (url.host() == chrome::kChromeUIPrintHost && | 506 if (url.host() == chrome::kChromeUIPrintHost && |
| 488 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) | 507 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 489 return &NewWebUI<PrintPreviewUI>; | 508 return &NewWebUI<PrintPreviewUI>; |
| 490 #endif | 509 #endif |
| 491 | 510 |
| 492 if (CommandLine::ForCurrentProcess()->HasSwitch( | 511 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 493 switches::kEnableDomDistiller)) { | 512 switches::kEnableDomDistiller)) { |
| 494 if (url.host() == dom_distiller::kChromeUIDomDistillerHost) { | 513 if (url.SchemeIs(chrome::kDomDistillerScheme)) { |
| 514 return &NewWebUI<dom_distiller::DomDistillerViewerUi>; | |
| 515 } else if (url.host() == dom_distiller::kChromeUIDomDistillerHost) { | |
| 495 return &NewWebUI<dom_distiller::DomDistillerUi>; | 516 return &NewWebUI<dom_distiller::DomDistillerUi>; |
| 496 } | 517 } |
| 497 } | 518 } |
| 498 | 519 |
| 499 return NULL; | 520 return NULL; |
| 500 } | 521 } |
| 501 | 522 |
| 502 void RunFaviconCallbackAsync( | 523 void RunFaviconCallbackAsync( |
| 503 const FaviconService::FaviconResultsCallback& callback, | 524 const FaviconService::FaviconResultsCallback& callback, |
| 504 const std::vector<chrome::FaviconBitmapResult>* results) { | 525 const std::vector<chrome::FaviconBitmapResult>* results) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 if (page_url.host() == chrome::kChromeUIPluginsHost) | 683 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 663 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 684 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
| 664 | 685 |
| 665 // Android doesn't use the components pages. | 686 // Android doesn't use the components pages. |
| 666 if (page_url.host() == chrome::kChromeUIComponentsHost) | 687 if (page_url.host() == chrome::kChromeUIComponentsHost) |
| 667 return ComponentsUI::GetFaviconResourceBytes(scale_factor); | 688 return ComponentsUI::GetFaviconResourceBytes(scale_factor); |
| 668 #endif | 689 #endif |
| 669 | 690 |
| 670 return NULL; | 691 return NULL; |
| 671 } | 692 } |
| OLD | NEW |