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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #include "content/public/browser/web_contents.h" | 67 #include "content/public/browser/web_contents.h" |
68 #include "content/public/browser/web_ui.h" | 68 #include "content/public/browser/web_ui.h" |
69 #include "content/public/common/content_client.h" | 69 #include "content/public/common/content_client.h" |
70 #include "content/public/common/url_utils.h" | 70 #include "content/public/common/url_utils.h" |
71 #include "extensions/browser/extension_registry.h" | 71 #include "extensions/browser/extension_registry.h" |
72 #include "extensions/browser/extension_system.h" | 72 #include "extensions/browser/extension_system.h" |
73 #include "extensions/common/constants.h" | 73 #include "extensions/common/constants.h" |
74 #include "extensions/common/extension.h" | 74 #include "extensions/common/extension.h" |
75 #include "extensions/common/feature_switch.h" | 75 #include "extensions/common/feature_switch.h" |
76 #include "extensions/common/manifest.h" | 76 #include "extensions/common/manifest.h" |
| 77 #include "ui/base/layout.h" |
77 #include "ui/gfx/favicon_size.h" | 78 #include "ui/gfx/favicon_size.h" |
78 #include "ui/web_dialogs/web_dialog_ui.h" | 79 #include "ui/web_dialogs/web_dialog_ui.h" |
79 #include "url/gurl.h" | 80 #include "url/gurl.h" |
80 | 81 |
81 #if !defined(DISABLE_NACL) | 82 #if !defined(DISABLE_NACL) |
82 #include "chrome/browser/ui/webui/nacl_ui.h" | 83 #include "chrome/browser/ui/webui/nacl_ui.h" |
83 #endif | 84 #endif |
84 | 85 |
85 #if defined(ENABLE_CONFIGURATION_POLICY) | 86 #if defined(ENABLE_CONFIGURATION_POLICY) |
86 #include "chrome/browser/ui/webui/policy_ui.h" | 87 #include "chrome/browser/ui/webui/policy_ui.h" |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); | 564 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); |
564 if (!function) | 565 if (!function) |
565 return NULL; | 566 return NULL; |
566 | 567 |
567 return (*function)(web_ui, url); | 568 return (*function)(web_ui, url); |
568 } | 569 } |
569 | 570 |
570 void ChromeWebUIControllerFactory::GetFaviconForURL( | 571 void ChromeWebUIControllerFactory::GetFaviconForURL( |
571 Profile* profile, | 572 Profile* profile, |
572 const GURL& page_url, | 573 const GURL& page_url, |
573 const std::vector<ui::ScaleFactor>& scale_factors, | 574 const std::vector<float>& favicon_scales, |
574 const favicon_base::FaviconResultsCallback& callback) const { | 575 const favicon_base::FaviconResultsCallback& callback) const { |
575 // Before determining whether page_url is an extension url, we must handle | 576 // Before determining whether page_url is an extension url, we must handle |
576 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and | 577 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and |
577 // allows to use ExtensionWebUI::GetFaviconForURL. | 578 // allows to use ExtensionWebUI::GetFaviconForURL. |
578 GURL url(page_url); | 579 GURL url(page_url); |
579 ExtensionWebUI::HandleChromeURLOverride(&url, profile); | 580 ExtensionWebUI::HandleChromeURLOverride(&url, profile); |
580 | 581 |
581 // All extensions but the bookmark manager get their favicon from the icons | 582 // All extensions but the bookmark manager get their favicon from the icons |
582 // part of the manifest. | 583 // part of the manifest. |
583 if (url.SchemeIs(extensions::kExtensionScheme) && | 584 if (url.SchemeIs(extensions::kExtensionScheme) && |
584 url.host() != extension_misc::kBookmarkManagerId) { | 585 url.host() != extension_misc::kBookmarkManagerId) { |
585 #if defined(ENABLE_EXTENSIONS) | 586 #if defined(ENABLE_EXTENSIONS) |
586 ExtensionWebUI::GetFaviconForURL(profile, url, callback); | 587 ExtensionWebUI::GetFaviconForURL(profile, url, callback); |
587 #else | 588 #else |
588 RunFaviconCallbackAsync( | 589 RunFaviconCallbackAsync( |
589 callback, new std::vector<favicon_base::FaviconRawBitmapResult>()); | 590 callback, new std::vector<favicon_base::FaviconRawBitmapResult>()); |
590 #endif | 591 #endif |
591 return; | 592 return; |
592 } | 593 } |
593 | 594 |
594 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results = | 595 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results = |
595 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 596 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
596 | 597 |
597 for (size_t i = 0; i < scale_factors.size(); ++i) { | 598 for (size_t i = 0; i < favicon_scales.size(); ++i) { |
598 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( | 599 scoped_refptr<base::RefCountedMemory> bitmap( |
599 url, scale_factors[i])); | 600 GetFaviconResourceBytes(url, favicon_scales[i])); |
600 if (bitmap.get() && bitmap->size()) { | 601 if (bitmap.get() && bitmap->size()) { |
601 favicon_base::FaviconRawBitmapResult bitmap_result; | 602 favicon_base::FaviconRawBitmapResult bitmap_result; |
602 bitmap_result.bitmap_data = bitmap; | 603 bitmap_result.bitmap_data = bitmap; |
603 // Leave |bitmap_result|'s icon URL as the default of GURL(). | 604 // Leave |bitmap_result|'s icon URL as the default of GURL(). |
604 bitmap_result.icon_type = favicon_base::FAVICON; | 605 bitmap_result.icon_type = favicon_base::FAVICON; |
605 favicon_bitmap_results->push_back(bitmap_result); | 606 favicon_bitmap_results->push_back(bitmap_result); |
606 | 607 |
607 // Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize| | 608 // Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize| |
608 // DIP. | 609 // DIP. |
609 float scale = ui::GetScaleForScaleFactor(scale_factors[i]); | 610 float scale = favicon_scales[i]; |
610 int edge_pixel_size = | 611 int edge_pixel_size = |
611 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); | 612 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); |
612 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); | 613 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); |
613 } | 614 } |
614 } | 615 } |
615 | 616 |
616 RunFaviconCallbackAsync(callback, favicon_bitmap_results); | 617 RunFaviconCallbackAsync(callback, favicon_bitmap_results); |
617 } | 618 } |
618 | 619 |
619 // static | 620 // static |
620 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { | 621 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { |
621 return Singleton<ChromeWebUIControllerFactory>::get(); | 622 return Singleton<ChromeWebUIControllerFactory>::get(); |
622 } | 623 } |
623 | 624 |
624 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { | 625 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { |
625 } | 626 } |
626 | 627 |
627 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() { | 628 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() { |
628 } | 629 } |
629 | 630 |
630 base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes( | 631 base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes( |
631 const GURL& page_url, ui::ScaleFactor scale_factor) const { | 632 const GURL& page_url, |
| 633 float scale) const { |
| 634 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); |
632 #if !defined(OS_ANDROID) // Bookmarks are part of NTP on Android. | 635 #if !defined(OS_ANDROID) // Bookmarks are part of NTP on Android. |
633 // The bookmark manager is a chrome extension, so we have to check for it | 636 // The bookmark manager is a chrome extension, so we have to check for it |
634 // before we check for extension scheme. | 637 // before we check for extension scheme. |
635 if (page_url.host() == extension_misc::kBookmarkManagerId) | 638 if (page_url.host() == extension_misc::kBookmarkManagerId) |
636 return BookmarksUI::GetFaviconResourceBytes(scale_factor); | 639 return BookmarksUI::GetFaviconResourceBytes(scale_factor); |
637 | 640 |
638 // The extension scheme is handled in GetFaviconForURL. | 641 // The extension scheme is handled in GetFaviconForURL. |
639 if (page_url.SchemeIs(extensions::kExtensionScheme)) { | 642 if (page_url.SchemeIs(extensions::kExtensionScheme)) { |
640 NOTREACHED(); | 643 NOTREACHED(); |
641 return NULL; | 644 return NULL; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 #endif | 690 #endif |
688 | 691 |
689 // Android doesn't use the plugins pages. | 692 // Android doesn't use the plugins pages. |
690 if (page_url.host() == chrome::kChromeUIPluginsHost) | 693 if (page_url.host() == chrome::kChromeUIPluginsHost) |
691 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 694 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
692 | 695 |
693 #endif | 696 #endif |
694 | 697 |
695 return NULL; | 698 return NULL; |
696 } | 699 } |
OLD | NEW |