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_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 static Type* New() { | 418 static Type* New() { |
419 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) | 419 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) |
420 return DefaultSingletonTraits<TestType>::New(); | 420 return DefaultSingletonTraits<TestType>::New(); |
421 else | 421 else |
422 return DefaultSingletonTraits<Type>::New(); | 422 return DefaultSingletonTraits<Type>::New(); |
423 } | 423 } |
424 }; | 424 }; |
425 | 425 |
426 void RunFaviconCallbackAsync( | 426 void RunFaviconCallbackAsync( |
427 const FaviconService::FaviconResultsCallback& callback, | 427 const FaviconService::FaviconResultsCallback& callback, |
428 const std::vector<history::FaviconBitmapResult>* results, | 428 const std::vector<history::FaviconBitmapResult>* results) { |
429 const history::IconURLSizesMap* size_map) { | |
430 base::MessageLoopProxy::current()->PostTask( | 429 base::MessageLoopProxy::current()->PostTask( |
431 FROM_HERE, | 430 FROM_HERE, |
432 base::Bind(&FaviconService::FaviconResultsCallbackRunner, | 431 base::Bind(&FaviconService::FaviconResultsCallbackRunner, |
433 callback, base::Owned(results), base::Owned(size_map))); | 432 callback, base::Owned(results))); |
434 } | 433 } |
435 | 434 |
436 } // namespace | 435 } // namespace |
437 | 436 |
438 WebUI::TypeID ChromeWebUIControllerFactory::GetWebUIType( | 437 WebUI::TypeID ChromeWebUIControllerFactory::GetWebUIType( |
439 content::BrowserContext* browser_context, const GURL& url) const { | 438 content::BrowserContext* browser_context, const GURL& url) const { |
440 Profile* profile = Profile::FromBrowserContext(browser_context); | 439 Profile* profile = Profile::FromBrowserContext(browser_context); |
441 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url); | 440 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url); |
442 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; | 441 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; |
443 } | 442 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 ExtensionWebUI::HandleChromeURLOverride(&url, profile); | 502 ExtensionWebUI::HandleChromeURLOverride(&url, profile); |
504 | 503 |
505 // All extensions but the bookmark manager get their favicon from the icons | 504 // All extensions but the bookmark manager get their favicon from the icons |
506 // part of the manifest. | 505 // part of the manifest. |
507 if (url.SchemeIs(extensions::kExtensionScheme) && | 506 if (url.SchemeIs(extensions::kExtensionScheme) && |
508 url.host() != extension_misc::kBookmarkManagerId) { | 507 url.host() != extension_misc::kBookmarkManagerId) { |
509 #if defined(ENABLE_EXTENSIONS) | 508 #if defined(ENABLE_EXTENSIONS) |
510 ExtensionWebUI::GetFaviconForURL(profile, url, callback); | 509 ExtensionWebUI::GetFaviconForURL(profile, url, callback); |
511 #else | 510 #else |
512 RunFaviconCallbackAsync(callback, | 511 RunFaviconCallbackAsync(callback, |
513 new std::vector<history::FaviconBitmapResult>(), | 512 new std::vector<history::FaviconBitmapResult>()); |
514 new history::IconURLSizesMap()); | |
515 #endif | 513 #endif |
516 return; | 514 return; |
517 } | 515 } |
518 | 516 |
519 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results = | 517 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results = |
520 new std::vector<history::FaviconBitmapResult>(); | 518 new std::vector<history::FaviconBitmapResult>(); |
521 history::IconURLSizesMap* icon_url_sizes = new history::IconURLSizesMap(); | |
522 | 519 |
523 for (size_t i = 0; i < scale_factors.size(); ++i) { | 520 for (size_t i = 0; i < scale_factors.size(); ++i) { |
524 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( | 521 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( |
525 url, scale_factors[i])); | 522 url, scale_factors[i])); |
526 if (bitmap.get() && bitmap->size()) { | 523 if (bitmap.get() && bitmap->size()) { |
527 history::FaviconBitmapResult bitmap_result; | 524 history::FaviconBitmapResult bitmap_result; |
528 bitmap_result.bitmap_data = bitmap; | 525 bitmap_result.bitmap_data = bitmap; |
529 // Leave |bitmap_result|'s icon URL as the default of GURL(). | 526 // Leave |bitmap_result|'s icon URL as the default of GURL(). |
530 bitmap_result.icon_type = history::FAVICON; | 527 bitmap_result.icon_type = history::FAVICON; |
531 favicon_bitmap_results->push_back(bitmap_result); | 528 favicon_bitmap_results->push_back(bitmap_result); |
532 | 529 |
533 // Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize| | 530 // Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize| |
534 // DIP. | 531 // DIP. |
535 float scale = ui::GetScaleFactorScale(scale_factors[i]); | 532 float scale = ui::GetScaleFactorScale(scale_factors[i]); |
536 int edge_pixel_size = | 533 int edge_pixel_size = |
537 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); | 534 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); |
538 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); | 535 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); |
539 } | 536 } |
540 } | 537 } |
541 | 538 |
542 // Populate IconURLSizesMap such that the requirement that all the icon URLs | 539 RunFaviconCallbackAsync(callback, favicon_bitmap_results); |
543 // in |favicon_bitmap_results| be present in |icon_url_sizes| holds. | |
544 // Populate the favicon sizes with the pixel sizes of the bitmaps available | |
545 // for |url|. | |
546 for (size_t i = 0; i < favicon_bitmap_results->size(); ++i) { | |
547 const history::FaviconBitmapResult& bitmap_result = | |
548 (*favicon_bitmap_results)[i]; | |
549 const GURL& icon_url = bitmap_result.icon_url; | |
550 (*icon_url_sizes)[icon_url].push_back(bitmap_result.pixel_size); | |
551 } | |
552 | |
553 RunFaviconCallbackAsync(callback, favicon_bitmap_results, icon_url_sizes); | |
554 } | 540 } |
555 | 541 |
556 // static | 542 // static |
557 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { | 543 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { |
558 return Singleton< ChromeWebUIControllerFactory, PossibleTestSingletonTraits< | 544 return Singleton< ChromeWebUIControllerFactory, PossibleTestSingletonTraits< |
559 ChromeWebUIControllerFactory, TestChromeWebUIControllerFactory> >::get(); | 545 ChromeWebUIControllerFactory, TestChromeWebUIControllerFactory> >::get(); |
560 } | 546 } |
561 | 547 |
562 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { | 548 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { |
563 } | 549 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 if (page_url.host() == chrome::kChromeUISettingsFrameHost) | 596 if (page_url.host() == chrome::kChromeUISettingsFrameHost) |
611 return options::OptionsUI::GetFaviconResourceBytes(scale_factor); | 597 return options::OptionsUI::GetFaviconResourceBytes(scale_factor); |
612 | 598 |
613 // Android doesn't use the plugins pages. | 599 // Android doesn't use the plugins pages. |
614 if (page_url.host() == chrome::kChromeUIPluginsHost) | 600 if (page_url.host() == chrome::kChromeUIPluginsHost) |
615 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 601 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
616 #endif | 602 #endif |
617 | 603 |
618 return NULL; | 604 return NULL; |
619 } | 605 } |
OLD | NEW |