Chromium Code Reviews| 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/select_favicon_frames.h" | |
| 65 #include "components/password_manager/core/common/password_manager_switches.h" | 66 #include "components/password_manager/core/common/password_manager_switches.h" |
| 66 #include "components/signin/core/common/profile_management_switches.h" | 67 #include "components/signin/core/common/profile_management_switches.h" |
| 67 #include "content/public/browser/web_contents.h" | 68 #include "content/public/browser/web_contents.h" |
| 68 #include "content/public/browser/web_ui.h" | 69 #include "content/public/browser/web_ui.h" |
| 69 #include "content/public/common/content_client.h" | 70 #include "content/public/common/content_client.h" |
| 70 #include "content/public/common/url_utils.h" | 71 #include "content/public/common/url_utils.h" |
| 71 #include "extensions/browser/extension_registry.h" | 72 #include "extensions/browser/extension_registry.h" |
| 72 #include "extensions/browser/extension_system.h" | 73 #include "extensions/browser/extension_system.h" |
| 73 #include "extensions/common/constants.h" | 74 #include "extensions/common/constants.h" |
| 74 #include "extensions/common/extension.h" | 75 #include "extensions/common/extension.h" |
| 75 #include "extensions/common/feature_switch.h" | 76 #include "extensions/common/feature_switch.h" |
| 76 #include "extensions/common/manifest.h" | 77 #include "extensions/common/manifest.h" |
| 78 #include "ui/base/layout.h" | |
| 77 #include "ui/gfx/favicon_size.h" | 79 #include "ui/gfx/favicon_size.h" |
| 78 #include "ui/web_dialogs/web_dialog_ui.h" | 80 #include "ui/web_dialogs/web_dialog_ui.h" |
| 79 #include "url/gurl.h" | 81 #include "url/gurl.h" |
| 80 | 82 |
| 81 #if !defined(DISABLE_NACL) | 83 #if !defined(DISABLE_NACL) |
| 82 #include "chrome/browser/ui/webui/nacl_ui.h" | 84 #include "chrome/browser/ui/webui/nacl_ui.h" |
| 83 #endif | 85 #endif |
| 84 | 86 |
| 85 #if defined(ENABLE_CONFIGURATION_POLICY) | 87 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 86 #include "chrome/browser/ui/webui/policy_ui.h" | 88 #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); | 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 = ui::GetSupportedScaleFactors(); | |
|
oshima
2014/06/18 07:03:02
Does this have to be GetFaviconScaleFactors() ?
| |
| 602 std::vector<gfx::Size> candidate_sizes; | |
| 597 for (size_t i = 0; i < scale_factors.size(); ++i) { | 603 for (size_t i = 0; i < scale_factors.size(); ++i) { |
| 604 float scale = ui::GetScaleForScaleFactor(scale_factors[i]); | |
| 605 int candidate_edge_size = | |
| 606 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); | |
| 607 candidate_sizes.push_back( | |
| 608 gfx::Size(candidate_edge_size, candidate_edge_size)); | |
| 609 } | |
| 610 std::vector<size_t> selected_indices; | |
| 611 SelectFaviconFrameIndices(candidate_sizes, | |
| 612 desired_sizes_in_pixel, | |
| 613 &selected_indices, | |
| 614 NULL); | |
| 615 for (size_t i = 0; i < selected_indices.size(); ++i) { | |
| 616 size_t selected_index = selected_indices[i]; | |
| 617 ui::ScaleFactor scale_factor = scale_factors[selected_index]; | |
| 598 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( | 618 scoped_refptr<base::RefCountedMemory> bitmap(GetFaviconResourceBytes( |
| 599 url, scale_factors[i])); | 619 url, scale_factor)); |
| 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 |