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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" | 55 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" |
56 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" | 56 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" |
57 #include "chrome/browser/ui/webui/version_ui.h" | 57 #include "chrome/browser/ui/webui/version_ui.h" |
58 #include "chrome/common/chrome_switches.h" | 58 #include "chrome/common/chrome_switches.h" |
59 #include "chrome/common/extensions/extension_constants.h" | 59 #include "chrome/common/extensions/extension_constants.h" |
60 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
61 #include "chrome/common/url_constants.h" | 61 #include "chrome/common/url_constants.h" |
62 #include "components/dom_distiller/core/dom_distiller_constants.h" | 62 #include "components/dom_distiller/core/dom_distiller_constants.h" |
63 #include "components/dom_distiller/core/dom_distiller_service.h" | 63 #include "components/dom_distiller/core/dom_distiller_service.h" |
64 #include "components/dom_distiller/webui/dom_distiller_ui.h" | 64 #include "components/dom_distiller/webui/dom_distiller_ui.h" |
| 65 #include "components/favicon_base/favicon_util.h" |
| 66 #include "components/favicon_base/select_favicon_frames.h" |
65 #include "components/password_manager/core/common/password_manager_switches.h" | 67 #include "components/password_manager/core/common/password_manager_switches.h" |
66 #include "components/signin/core/common/profile_management_switches.h" | 68 #include "components/signin/core/common/profile_management_switches.h" |
67 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
68 #include "content/public/browser/web_ui.h" | 70 #include "content/public/browser/web_ui.h" |
69 #include "content/public/common/content_client.h" | 71 #include "content/public/common/content_client.h" |
70 #include "content/public/common/url_utils.h" | 72 #include "content/public/common/url_utils.h" |
71 #include "extensions/browser/extension_registry.h" | 73 #include "extensions/browser/extension_registry.h" |
72 #include "extensions/browser/extension_system.h" | 74 #include "extensions/browser/extension_system.h" |
73 #include "extensions/common/constants.h" | 75 #include "extensions/common/constants.h" |
74 #include "extensions/common/extension.h" | 76 #include "extensions/common/extension.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); | 565 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); |
564 if (!function) | 566 if (!function) |
565 return NULL; | 567 return NULL; |
566 | 568 |
567 return (*function)(web_ui, url); | 569 return (*function)(web_ui, url); |
568 } | 570 } |
569 | 571 |
570 void ChromeWebUIControllerFactory::GetFaviconForURL( | 572 void ChromeWebUIControllerFactory::GetFaviconForURL( |
571 Profile* profile, | 573 Profile* profile, |
572 const GURL& page_url, | 574 const GURL& page_url, |
573 const std::vector<ui::ScaleFactor>& scale_factors, | 575 const std::vector<int>& desired_sizes_in_pixel, |
574 const favicon_base::FaviconResultsCallback& callback) const { | 576 const favicon_base::FaviconResultsCallback& callback) const { |
575 // Before determining whether page_url is an extension url, we must handle | 577 // Before determining whether page_url is an extension url, we must handle |
576 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and | 578 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and |
577 // allows to use ExtensionWebUI::GetFaviconForURL. | 579 // allows to use ExtensionWebUI::GetFaviconForURL. |
578 GURL url(page_url); | 580 GURL url(page_url); |
579 ExtensionWebUI::HandleChromeURLOverride(&url, profile); | 581 ExtensionWebUI::HandleChromeURLOverride(&url, profile); |
580 | 582 |
581 // All extensions but the bookmark manager get their favicon from the icons | 583 // All extensions but the bookmark manager get their favicon from the icons |
582 // part of the manifest. | 584 // part of the manifest. |
583 if (url.SchemeIs(extensions::kExtensionScheme) && | 585 if (url.SchemeIs(extensions::kExtensionScheme) && |
584 url.host() != extension_misc::kBookmarkManagerId) { | 586 url.host() != extension_misc::kBookmarkManagerId) { |
585 #if defined(ENABLE_EXTENSIONS) | 587 #if defined(ENABLE_EXTENSIONS) |
586 ExtensionWebUI::GetFaviconForURL(profile, url, callback); | 588 ExtensionWebUI::GetFaviconForURL(profile, url, callback); |
587 #else | 589 #else |
588 RunFaviconCallbackAsync( | 590 RunFaviconCallbackAsync( |
589 callback, new std::vector<favicon_base::FaviconRawBitmapResult>()); | 591 callback, new std::vector<favicon_base::FaviconRawBitmapResult>()); |
590 #endif | 592 #endif |
591 return; | 593 return; |
592 } | 594 } |
593 | 595 |
594 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results = | 596 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results = |
595 new std::vector<favicon_base::FaviconRawBitmapResult>(); | 597 new std::vector<favicon_base::FaviconRawBitmapResult>(); |
596 | 598 |
| 599 // Assume that GetFaviconResourceBytes() returns favicons which are |
| 600 // |gfx::kFaviconSize| x |gfx::kFaviconSize| DIP. |
| 601 std::vector<ui::ScaleFactor> scale_factors = |
| 602 favicon_base::GetFaviconScaleFactors(); |
| 603 std::vector<gfx::Size> candidate_sizes; |
597 for (size_t i = 0; i < scale_factors.size(); ++i) { | 604 for (size_t i = 0; i < scale_factors.size(); ++i) { |
| 605 float scale = ui::GetScaleForScaleFactor(scale_factors[i]); |
| 606 int candidate_edge_size = |
| 607 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); |
| 608 candidate_sizes.push_back( |
| 609 gfx::Size(candidate_edge_size, candidate_edge_size)); |
| 610 } |
| 611 std::vector<size_t> selected_indices; |
| 612 SelectFaviconFrameIndices(candidate_sizes, |
| 613 desired_sizes_in_pixel, |
| 614 &selected_indices, |
| 615 NULL); |
| 616 for (size_t i = 0; i < selected_indices.size(); ++i) { |
| 617 size_t selected_index = selected_indices[i]; |
598 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( | 618 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( |
599 url, scale_factors[i])); | 619 url, scale_factors[selected_index])); |
600 if (bitmap.get() && bitmap->size()) { | 620 if (bitmap.get() && bitmap->size()) { |
601 favicon_base::FaviconRawBitmapResult bitmap_result; | 621 favicon_base::FaviconRawBitmapResult bitmap_result; |
602 bitmap_result.bitmap_data = bitmap; | 622 bitmap_result.bitmap_data = bitmap; |
603 // Leave |bitmap_result|'s icon URL as the default of GURL(). | 623 // Leave |bitmap_result|'s icon URL as the default of GURL(). |
604 bitmap_result.icon_type = favicon_base::FAVICON; | 624 bitmap_result.icon_type = favicon_base::FAVICON; |
605 favicon_bitmap_results->push_back(bitmap_result); | 625 favicon_bitmap_results->push_back(bitmap_result); |
606 | 626 |
607 // Assume that |bitmap| is |gfx::kFaviconSize| x |gfx::kFaviconSize| | 627 bitmap_result.pixel_size = candidate_sizes[selected_index]; |
608 // DIP. | |
609 float scale = ui::GetScaleForScaleFactor(scale_factors[i]); | |
610 int edge_pixel_size = | |
611 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); | |
612 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); | |
613 } | 628 } |
614 } | 629 } |
615 | 630 |
616 RunFaviconCallbackAsync(callback, favicon_bitmap_results); | 631 RunFaviconCallbackAsync(callback, favicon_bitmap_results); |
617 } | 632 } |
618 | 633 |
619 // static | 634 // static |
620 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { | 635 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { |
621 return Singleton<ChromeWebUIControllerFactory>::get(); | 636 return Singleton<ChromeWebUIControllerFactory>::get(); |
622 } | 637 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 #endif | 702 #endif |
688 | 703 |
689 // Android doesn't use the plugins pages. | 704 // Android doesn't use the plugins pages. |
690 if (page_url.host() == chrome::kChromeUIPluginsHost) | 705 if (page_url.host() == chrome::kChromeUIPluginsHost) |
691 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 706 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
692 | 707 |
693 #endif | 708 #endif |
694 | 709 |
695 return NULL; | 710 return NULL; |
696 } | 711 } |
OLD | NEW |