| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "chrome/browser/ui/webui/signin/user_manager_ui.h" | 47 #include "chrome/browser/ui/webui/signin/user_manager_ui.h" |
| 48 #include "chrome/browser/ui/webui/signin_internals_ui.h" | 48 #include "chrome/browser/ui/webui/signin_internals_ui.h" |
| 49 #include "chrome/browser/ui/webui/sync_internals_ui.h" | 49 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
| 50 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" | 50 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" |
| 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/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" |
| 58 #include "components/dom_distiller/webui/dom_distiller_ui.h" | 60 #include "components/dom_distiller/webui/dom_distiller_ui.h" |
| 59 #include "content/public/browser/web_contents.h" | 61 #include "content/public/browser/web_contents.h" |
| 60 #include "content/public/browser/web_ui.h" | 62 #include "content/public/browser/web_ui.h" |
| 61 #include "content/public/common/content_client.h" | 63 #include "content/public/common/content_client.h" |
| 62 #include "content/public/common/url_utils.h" | 64 #include "content/public/common/url_utils.h" |
| 63 #include "extensions/common/constants.h" | 65 #include "extensions/common/constants.h" |
| 64 #include "extensions/common/feature_switch.h" | 66 #include "extensions/common/feature_switch.h" |
| 65 #include "ui/gfx/favicon_size.h" | 67 #include "ui/gfx/favicon_size.h" |
| 66 #include "ui/web_dialogs/web_dialog_ui.h" | 68 #include "ui/web_dialogs/web_dialog_ui.h" |
| 67 #include "url/gurl.h" | 69 #include "url/gurl.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return new AboutUI(web_ui, url.host()); | 181 return new AboutUI(web_ui, url.host()); |
| 180 } | 182 } |
| 181 | 183 |
| 182 #if defined(OS_CHROMEOS) | 184 #if defined(OS_CHROMEOS) |
| 183 template<> | 185 template<> |
| 184 WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) { | 186 WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) { |
| 185 return new chromeos::OobeUI(web_ui, url); | 187 return new chromeos::OobeUI(web_ui, url); |
| 186 } | 188 } |
| 187 #endif | 189 #endif |
| 188 | 190 |
| 191 // Special cases for DOM distiller. |
| 192 template<> |
| 193 WebUIController* NewWebUI<dom_distiller::DomDistillerUi>(WebUI* web_ui, |
| 194 const GURL& url) { |
| 195 // The DomDistillerUi can not depend on components/dom_distiller/content, |
| 196 // so inject the correct DomDistillerService from chrome/. |
| 197 content::BrowserContext* browser_context = |
| 198 web_ui->GetWebContents()->GetBrowserContext(); |
| 199 dom_distiller::DomDistillerService* service = |
| 200 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( |
| 201 browser_context); |
| 202 // TODO(nyquist): Add real scheme. |
| 203 return new dom_distiller::DomDistillerUi(web_ui, service, "dummy"); |
| 204 } |
| 205 |
| 189 // Only create ExtensionWebUI for URLs that are allowed extension bindings, | 206 // Only create ExtensionWebUI for URLs that are allowed extension bindings, |
| 190 // hosted by actual tabs. | 207 // hosted by actual tabs. |
| 191 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { | 208 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { |
| 192 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; | 209 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; |
| 193 return service && service->ExtensionBindingsAllowed(url); | 210 return service && service->ExtensionBindingsAllowed(url); |
| 194 } | 211 } |
| 195 | 212 |
| 196 // Returns a function that can be used to create the right type of WebUI for a | 213 // Returns a function that can be used to create the right type of WebUI for a |
| 197 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 214 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
| 198 // with it. | 215 // with it. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return &NewWebUI<ConstrainedWebDialogUI>; | 255 return &NewWebUI<ConstrainedWebDialogUI>; |
| 239 if (url.host() == chrome::kChromeUICrashesHost) | 256 if (url.host() == chrome::kChromeUICrashesHost) |
| 240 return &NewWebUI<CrashesUI>; | 257 return &NewWebUI<CrashesUI>; |
| 241 #if defined(ENABLE_MDNS) | 258 #if defined(ENABLE_MDNS) |
| 242 if (url.host() == chrome::kChromeUIDevicesHost && | 259 if (url.host() == chrome::kChromeUIDevicesHost && |
| 243 !CommandLine::ForCurrentProcess()->HasSwitch( | 260 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 244 switches::kDisableDeviceDiscovery)) { | 261 switches::kDisableDeviceDiscovery)) { |
| 245 return &NewWebUI<LocalDiscoveryUI>; | 262 return &NewWebUI<LocalDiscoveryUI>; |
| 246 } | 263 } |
| 247 #endif | 264 #endif |
| 248 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 249 switches::kEnableDomDistiller) && | |
| 250 url.host() == dom_distiller::kChromeUIDomDistillerHost) { | |
| 251 return &NewWebUI<dom_distiller::DomDistillerUI>; | |
| 252 } | |
| 253 if (url.host() == chrome::kChromeUIFlagsHost) | 265 if (url.host() == chrome::kChromeUIFlagsHost) |
| 254 return &NewWebUI<FlagsUI>; | 266 return &NewWebUI<FlagsUI>; |
| 255 if (url.host() == chrome::kChromeUIHistoryFrameHost) | 267 if (url.host() == chrome::kChromeUIHistoryFrameHost) |
| 256 return &NewWebUI<HistoryUI>; | 268 return &NewWebUI<HistoryUI>; |
| 257 if (url.host() == chrome::kChromeUIInstantHost) | 269 if (url.host() == chrome::kChromeUIInstantHost) |
| 258 return &NewWebUI<InstantUI>; | 270 return &NewWebUI<InstantUI>; |
| 259 if (url.host() == chrome::kChromeUIManagedUserPassphrasePageHost) | 271 if (url.host() == chrome::kChromeUIManagedUserPassphrasePageHost) |
| 260 return &NewWebUI<ConstrainedWebDialogUI>; | 272 return &NewWebUI<ConstrainedWebDialogUI>; |
| 261 if (url.host() == chrome::kChromeUIMemoryInternalsHost) | 273 if (url.host() == chrome::kChromeUIMemoryInternalsHost) |
| 262 return &NewWebUI<MemoryInternalsUI>; | 274 return &NewWebUI<MemoryInternalsUI>; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 } | 485 } |
| 474 if (url.host() == chrome::kChromeUIExtensionsFrameHost) | 486 if (url.host() == chrome::kChromeUIExtensionsFrameHost) |
| 475 return &NewWebUI<extensions::ExtensionsUI>; | 487 return &NewWebUI<extensions::ExtensionsUI>; |
| 476 #endif | 488 #endif |
| 477 #if defined(ENABLE_FULL_PRINTING) | 489 #if defined(ENABLE_FULL_PRINTING) |
| 478 if (url.host() == chrome::kChromeUIPrintHost && | 490 if (url.host() == chrome::kChromeUIPrintHost && |
| 479 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) | 491 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 480 return &NewWebUI<PrintPreviewUI>; | 492 return &NewWebUI<PrintPreviewUI>; |
| 481 #endif | 493 #endif |
| 482 | 494 |
| 495 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 496 switches::kEnableDomDistiller)) { |
| 497 if (url.host() == dom_distiller::kChromeUIDomDistillerHost) { |
| 498 return &NewWebUI<dom_distiller::DomDistillerUi>; |
| 499 } |
| 500 } |
| 501 |
| 483 return NULL; | 502 return NULL; |
| 484 } | 503 } |
| 485 | 504 |
| 486 void RunFaviconCallbackAsync( | 505 void RunFaviconCallbackAsync( |
| 487 const FaviconService::FaviconResultsCallback& callback, | 506 const FaviconService::FaviconResultsCallback& callback, |
| 488 const std::vector<chrome::FaviconBitmapResult>* results) { | 507 const std::vector<chrome::FaviconBitmapResult>* results) { |
| 489 base::MessageLoopProxy::current()->PostTask( | 508 base::MessageLoopProxy::current()->PostTask( |
| 490 FROM_HERE, | 509 FROM_HERE, |
| 491 base::Bind(&FaviconService::FaviconResultsCallbackRunner, | 510 base::Bind(&FaviconService::FaviconResultsCallbackRunner, |
| 492 callback, base::Owned(results))); | 511 callback, base::Owned(results))); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 if (page_url.host() == chrome::kChromeUIPluginsHost) | 665 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 647 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 666 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
| 648 | 667 |
| 649 // Android doesn't use the components pages. | 668 // Android doesn't use the components pages. |
| 650 if (page_url.host() == chrome::kChromeUIComponentsHost) | 669 if (page_url.host() == chrome::kChromeUIComponentsHost) |
| 651 return ComponentsUI::GetFaviconResourceBytes(scale_factor); | 670 return ComponentsUI::GetFaviconResourceBytes(scale_factor); |
| 652 #endif | 671 #endif |
| 653 | 672 |
| 654 return NULL; | 673 return NULL; |
| 655 } | 674 } |
| OLD | NEW |