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/extensions/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" | 13 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
16 #include "chrome/browser/extensions/image_loading_tracker.h" | 16 #include "chrome/browser/extensions/image_loading_tracker.h" |
17 #include "chrome/browser/favicon/favicon_util.h" | |
18 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
26 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
27 #include "chrome/common/extensions/extension_icon_set.h" | 26 #include "chrome/common/extensions/extension_icon_set.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Even when the extensions service is enabled by default, it's still | 91 // Even when the extensions service is enabled by default, it's still |
93 // disabled in incognito mode. | 92 // disabled in incognito mode. |
94 ExtensionService* service = profile->GetExtensionService(); | 93 ExtensionService* service = profile->GetExtensionService(); |
95 if (service) | 94 if (service) |
96 extension_ = service->extensions()->GetByID(page_url.host()); | 95 extension_ = service->extensions()->GetByID(page_url.host()); |
97 } | 96 } |
98 | 97 |
99 void Init() { | 98 void Init() { |
100 if (extension_) { | 99 if (extension_) { |
101 // Fetch resources for all supported scale factors for which there are | 100 // Fetch resources for all supported scale factors for which there are |
102 // resources. Load image reps for all supported scale factors (in | 101 // resources. Load image reps for all supported scale factors immediately |
103 // addition to 1x) immediately instead of in an as needed fashion to be | 102 // instead of in an as needed fashion to be consistent with how favicons |
104 // consistent with how favicons are requested for chrome:// and page | 103 // are requested for chrome:// and page URLs. |
105 // URLs. | |
106 const std::vector<ui::ScaleFactor>& scale_factors = | 104 const std::vector<ui::ScaleFactor>& scale_factors = |
107 FaviconUtil::GetFaviconScaleFactors(); | 105 ui::GetSupportedScaleFactors(); |
108 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; | 106 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
109 for (size_t i = 0; i < scale_factors.size(); ++i) { | 107 for (size_t i = 0; i < scale_factors.size(); ++i) { |
110 float scale = ui::GetScaleFactorScale(scale_factors[i]); | 108 float scale = ui::GetScaleFactorScale(scale_factors[i]); |
111 int pixel_size = static_cast<int>(gfx::kFaviconSize * scale); | 109 int pixel_size = static_cast<int>(gfx::kFaviconSize * scale); |
112 ExtensionResource icon_resource = | 110 ExtensionResource icon_resource = |
113 extension_->GetIconResource(pixel_size, | 111 extension_->GetIconResource(pixel_size, |
114 ExtensionIconSet::MATCH_BIGGER); | 112 ExtensionIconSet::MATCH_BIGGER); |
115 | 113 |
116 info_list.push_back( | 114 info_list.push_back( |
117 ImageLoadingTracker::ImageRepresentation( | 115 ImageLoadingTracker::ImageRepresentation( |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 462 } |
465 | 463 |
466 // static | 464 // static |
467 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 465 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
468 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 466 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
469 // tracker deletes itself when done. | 467 // tracker deletes itself when done. |
470 ExtensionWebUIImageLoadingTracker* tracker = | 468 ExtensionWebUIImageLoadingTracker* tracker = |
471 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 469 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
472 tracker->Init(); | 470 tracker->Init(); |
473 } | 471 } |
OLD | NEW |