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

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

Issue 6992019: Allow overriding WebUIFactory when test flag is set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment namespace end. Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
11 #include "chrome/browser/extensions/extensions_ui.h" 11 #include "chrome/browser/extensions/extensions_ui.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/webui/bookmarks_ui.h" 13 #include "chrome/browser/ui/webui/bookmarks_ui.h"
14 #include "chrome/browser/ui/webui/bug_report_ui.h" 14 #include "chrome/browser/ui/webui/bug_report_ui.h"
15 #include "chrome/browser/ui/webui/constrained_html_ui.h" 15 #include "chrome/browser/ui/webui/constrained_html_ui.h"
16 #include "chrome/browser/ui/webui/crashes_ui.h" 16 #include "chrome/browser/ui/webui/crashes_ui.h"
17 #include "chrome/browser/ui/webui/devtools_ui.h" 17 #include "chrome/browser/ui/webui/devtools_ui.h"
18 #include "chrome/browser/ui/webui/downloads_ui.h" 18 #include "chrome/browser/ui/webui/downloads_ui.h"
19 #include "chrome/browser/ui/webui/flags_ui.h" 19 #include "chrome/browser/ui/webui/flags_ui.h"
20 #include "chrome/browser/ui/webui/gpu_internals_ui.h" 20 #include "chrome/browser/ui/webui/gpu_internals_ui.h"
21 #include "chrome/browser/ui/webui/history2_ui.h" 21 #include "chrome/browser/ui/webui/history2_ui.h"
22 #include "chrome/browser/ui/webui/history_ui.h" 22 #include "chrome/browser/ui/webui/history_ui.h"
23 #include "chrome/browser/ui/webui/html_dialog_ui.h" 23 #include "chrome/browser/ui/webui/html_dialog_ui.h"
24 #include "chrome/browser/ui/webui/net_internals_ui.h" 24 #include "chrome/browser/ui/webui/net_internals_ui.h"
25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
26 #include "chrome/browser/ui/webui/options/options_ui.h" 26 #include "chrome/browser/ui/webui/options/options_ui.h"
27 #include "chrome/browser/ui/webui/plugins_ui.h" 27 #include "chrome/browser/ui/webui/plugins_ui.h"
28 #include "chrome/browser/ui/webui/print_preview_ui.h" 28 #include "chrome/browser/ui/webui/print_preview_ui.h"
29 #include "chrome/browser/ui/webui/sync_internals_ui.h" 29 #include "chrome/browser/ui/webui/sync_internals_ui.h"
30 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
30 #include "chrome/browser/ui/webui/textfields_ui.h" 31 #include "chrome/browser/ui/webui/textfields_ui.h"
31 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/extension_constants.h" 33 #include "chrome/common/extensions/extension_constants.h"
33 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
34 #include "content/browser/tab_contents/tab_contents.h" 35 #include "content/browser/tab_contents/tab_contents.h"
35 #include "content/browser/webui/web_ui.h" 36 #include "content/browser/webui/web_ui.h"
36 #include "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
37 38
38 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
39 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h" 40 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (url.host() == chrome::kChromeUILoginHost) 211 if (url.host() == chrome::kChromeUILoginHost)
211 return &NewWebUI<chromeos::LoginUI>; 212 return &NewWebUI<chromeos::LoginUI>;
212 #endif 213 #endif
213 214
214 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) 215 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL)
215 return &NewWebUI<ConstrainedHtmlUI>; 216 return &NewWebUI<ConstrainedHtmlUI>;
216 217
217 return NULL; 218 return NULL;
218 } 219 }
219 220
221 // When the test-type switch is set, return a TestType object, which should be a
222 // subclass of Type.
223 template<typename Type, typename TestType>
224 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> {
Evan Stade 2011/05/24 17:25:59 explicitly state privacy level
Lei Zhang (Do not use) 2011/05/24 18:00:06 Do you need this template? Why can't you just do t
Sheridan Rawlins 2011/05/24 20:17:22 This doesn't play nicely with the privacy/friendsh
Sheridan Rawlins 2011/05/24 20:17:22 As a derived struct of DefaultSingletonTraits, whi
Sheridan Rawlins 2011/05/25 18:29:42 As discussed in email thread, my main argument for
225 static Type* New() {
226 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
227 return DefaultSingletonTraits<TestType>::New();
228 else
229 return DefaultSingletonTraits<Type>::New();
230 }
231 };
232
220 } // namespace 233 } // namespace
221 234
222 WebUI::TypeID ChromeWebUIFactory::GetWebUIType(Profile* profile, 235 WebUI::TypeID ChromeWebUIFactory::GetWebUIType(Profile* profile,
223 const GURL& url) const { 236 const GURL& url) const {
224 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); 237 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url);
225 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; 238 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI;
226 } 239 }
227 240
228 bool ChromeWebUIFactory::UseWebUIForURL(Profile* profile, 241 bool ChromeWebUIFactory::UseWebUIForURL(Profile* profile,
229 const GURL& url) const { 242 const GURL& url) const {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 favicon.known_icon = favicon.image_data.get() != NULL && 292 favicon.known_icon = favicon.image_data.get() != NULL &&
280 favicon.image_data->size() > 0; 293 favicon.image_data->size() > 0;
281 request->ForwardResultAsync( 294 request->ForwardResultAsync(
282 FaviconService::FaviconDataCallback::TupleType(request->handle(), 295 FaviconService::FaviconDataCallback::TupleType(request->handle(),
283 favicon)); 296 favicon));
284 } 297 }
285 } 298 }
286 299
287 // static 300 // static
288 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() { 301 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() {
289 return Singleton<ChromeWebUIFactory>::get(); 302 return Singleton<ChromeWebUIFactory, PossibleTestSingletonTraits<
303 ChromeWebUIFactory, TestChromeWebUIFactory> >::get();
290 } 304 }
291 305
292 ChromeWebUIFactory::ChromeWebUIFactory() { 306 ChromeWebUIFactory::ChromeWebUIFactory() {
293 } 307 }
294 308
295 ChromeWebUIFactory::~ChromeWebUIFactory() { 309 ChromeWebUIFactory::~ChromeWebUIFactory() {
296 } 310 }
297 311
298 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes( 312 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes(
299 const GURL& page_url) const { 313 const GURL& page_url) const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return FlagsUI::GetFaviconResourceBytes(); 349 return FlagsUI::GetFaviconResourceBytes();
336 350
337 if (page_url.host() == chrome::kChromeUISettingsHost) 351 if (page_url.host() == chrome::kChromeUISettingsHost)
338 return OptionsUI::GetFaviconResourceBytes(); 352 return OptionsUI::GetFaviconResourceBytes();
339 353
340 if (page_url.host() == chrome::kChromeUIPluginsHost) 354 if (page_url.host() == chrome::kChromeUIPluginsHost)
341 return PluginsUI::GetFaviconResourceBytes(); 355 return PluginsUI::GetFaviconResourceBytes();
342 356
343 return NULL; 357 return NULL;
344 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698