diff options
author | pedrosimonetti@chromium.org <pedrosimonetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 11:54:44 +0000 |
---|---|---|
committer | pedrosimonetti@chromium.org <pedrosimonetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 11:54:44 +0000 |
commit | b4cba0f57def715e9a9db4defe0ab9776613d542 (patch) | |
tree | b02b1060168aad5de2819085b240996faabeea01 /chrome/browser | |
parent | f2eda3dfa1bfdecc30c5dff92fcade383a7b2341 (diff) | |
download | chromium_src-b4cba0f57def715e9a9db4defe0ab9776613d542.zip chromium_src-b4cba0f57def715e9a9db4defe0ab9776613d542.tar.gz chromium_src-b4cba0f57def715e9a9db4defe0ab9776613d542.tar.bz2 |
Preparation for supporting high dpi favicons in Instant Extended.
The logic in FaviconSource::ParsePath() has been moved from chrome/browser/ui/* to chrome/common/favicon* allowing it to be used from the renderer. Also, chrome/browser/favicon/favicon_types.h to chrome/common/favicon/favicon_types.h for the same reason.
Related internal CL: cl/46805180
To test this CL:
1) git cl patch 15388002
2) ./build/gyp_chromium
2) compile chrome
3) run chrome with --enable-instant-extended-api
BUG=227087
Review URL: https://chromiumcodereview.appspot.com/15388002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
21 files changed, 31 insertions, 444 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index 47eee0a..3653753 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -19,8 +19,8 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/favicon/favicon_types.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_source.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index eff176e..e8c5729 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -25,11 +25,11 @@ #include "chrome/browser/favicon/favicon_changed_details.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/favicon/favicon_types.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/favicon/DEPS b/chrome/browser/favicon/DEPS index 2ed7139..a317574 100644 --- a/chrome/browser/favicon/DEPS +++ b/chrome/browser/favicon/DEPS @@ -32,8 +32,8 @@ specific_include_rules = { 'favicon_util\.(h|cc)': [ "-chrome", "-chrome/browser", - "+chrome/browser/favicon/favicon_types.h", "+chrome/browser/favicon/favicon_util.h", + "+chrome/common/favicon/favicon_types.h", "+chrome/common/icon_messages.h", "!chrome/browser/history/history_types.h", "!chrome/browser/history/select_favicon_frames.h", diff --git a/chrome/browser/favicon/favicon_service.cc b/chrome/browser/favicon/favicon_service.cc index dc4cab9..555cdb1 100644 --- a/chrome/browser/favicon/favicon_service.cc +++ b/chrome/browser/favicon/favicon_service.cc @@ -6,13 +6,13 @@ #include "base/hash.h" #include "base/message_loop/message_loop_proxy.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/select_favicon_frames.h" #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/importer/imported_favicon_usage.h" #include "chrome/common/url_constants.h" #include "extensions/common/constants.h" @@ -371,4 +371,3 @@ void FaviconService::RunFaviconRawCallbackWithBitmapResults( &resized_bitmap_data); callback.Run(bitmap_result); } - diff --git a/chrome/browser/favicon/favicon_service.h b/chrome/browser/favicon/favicon_service.h index dc13360..692a6eb 100644 --- a/chrome/browser/favicon/favicon_service.h +++ b/chrome/browser/favicon/favicon_service.h @@ -11,8 +11,8 @@ #include "base/containers/hash_tables.h" #include "base/memory/ref_counted.h" #include "chrome/browser/common/cancelable_request.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/common/cancelable_task_tracker.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/ref_counted_util.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "ui/base/layout.h" diff --git a/chrome/browser/favicon/favicon_types.cc b/chrome/browser/favicon/favicon_types.cc deleted file mode 100644 index ca49db8..0000000 --- a/chrome/browser/favicon/favicon_types.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/favicon/favicon_types.h" - -namespace chrome { - -// FaviconImageResult --------------------------------------------------------- - -FaviconImageResult::FaviconImageResult() {} - -FaviconImageResult::~FaviconImageResult() {} - -// FaviconBitmapResult -------------------------------------------------------- - -FaviconBitmapResult::FaviconBitmapResult() - : expired(false), - icon_type(INVALID_ICON) {} - -FaviconBitmapResult::~FaviconBitmapResult() {} - -} // namespace chrome diff --git a/chrome/browser/favicon/favicon_types.h b/chrome/browser/favicon/favicon_types.h deleted file mode 100644 index 16724e0..0000000 --- a/chrome/browser/favicon/favicon_types.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FAVICON_FAVICON_TYPES_H_ -#define CHROME_BROWSER_FAVICON_FAVICON_TYPES_H_ - -#include "base/memory/ref_counted_memory.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/size.h" -#include "url/gurl.h" - -namespace chrome { - -typedef int64 FaviconID; - -// Defines the icon types. They are also stored in icon_type field of favicons -// table. -// The values of the IconTypes are used to select the priority in which favicon -// data is returned in HistoryBackend and ThumbnailDatabase. Data for the -// largest IconType takes priority if data for multiple IconTypes is available. -enum IconType { - INVALID_ICON = 0x0, - FAVICON = 1 << 0, - TOUCH_ICON = 1 << 1, - TOUCH_PRECOMPOSED_ICON = 1 << 2 -}; - -// Defines a gfx::Image of size desired_size_in_dip composed of image -// representations for each of the desired scale factors. -struct FaviconImageResult { - FaviconImageResult(); - ~FaviconImageResult(); - - // The resulting image. - gfx::Image image; - - // The URL of the favicon which contains all of the image representations of - // |image|. - // TODO(pkotwicz): Return multiple |icon_urls| to allow |image| to have - // representations from several favicons once content::FaviconStatus supports - // multiple URLs. - GURL icon_url; -}; - -// Defines a favicon bitmap which best matches the desired DIP size and one of -// the desired scale factors. -struct FaviconBitmapResult { - FaviconBitmapResult(); - ~FaviconBitmapResult(); - - // Returns true if |bitmap_data| contains a valid bitmap. - bool is_valid() const { return bitmap_data.get() && bitmap_data->size(); } - - // Indicates whether |bitmap_data| is expired. - bool expired; - - // The bits of the bitmap. - scoped_refptr<base::RefCountedMemory> bitmap_data; - - // The pixel dimensions of |bitmap_data|. - gfx::Size pixel_size; - - // The URL of the containing favicon. - GURL icon_url; - - // The icon type of the containing favicon. - IconType icon_type; -}; - -// Define type with same structure as FaviconBitmapResult for passing data to -// HistoryBackend::SetFavicons(). -typedef FaviconBitmapResult FaviconBitmapData; - -} // namespace chrome - -#endif // CHROME_BROWSER_FAVICON_FAVICON_TYPES_H_ diff --git a/chrome/browser/favicon/favicon_util.cc b/chrome/browser/favicon/favicon_util.cc index 21c9d75..456df8f6 100644 --- a/chrome/browser/favicon/favicon_util.cc +++ b/chrome/browser/favicon/favicon_util.cc @@ -4,8 +4,8 @@ #include "chrome/browser/favicon/favicon_util.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/select_favicon_frames.h" +#include "chrome/common/favicon/favicon_types.h" #include "content/public/browser/render_view_host.h" #include "content/public/child/image_decoder_utils.h" #include "skia/ext/image_operations.h" diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h index d78d40f..c3874f5 100644 --- a/chrome/browser/history/history_types.h +++ b/chrome/browser/history/history_types.h @@ -17,9 +17,9 @@ #include "base/memory/scoped_vector.h" #include "base/strings/string16.h" #include "base/time/time.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/snippet.h" #include "chrome/browser/search_engines/template_url_id.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/ref_counted_util.h" #include "chrome/common/thumbnail_score.h" #include "content/public/common/page_transition_types.h" diff --git a/chrome/browser/jumplist_win.cc b/chrome/browser/jumplist_win.cc index 4447141..d2da247 100644 --- a/chrome/browser/jumplist_win.cc +++ b/chrome/browser/jumplist_win.cc @@ -25,7 +25,6 @@ #include "base/win/windows_version.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/history/top_sites.h" @@ -37,6 +36,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/notifications/message_center_settings_controller.cc b/chrome/browser/notifications/message_center_settings_controller.cc index 9acefdf..2a0666a 100644 --- a/chrome/browser/notifications/message_center_settings_controller.cc +++ b/chrome/browser/notifications/message_center_settings_controller.cc @@ -13,7 +13,6 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" @@ -23,6 +22,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/cancelable_task_tracker.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/favicon/favicon_types.h" #include "grit/theme_resources.h" #include "grit/ui_strings.h" #include "ui/base/l10n/l10n_util.h" diff --git a/chrome/browser/resources/local_ntp/local_ntp.css b/chrome/browser/resources/local_ntp/local_ntp.css index bd4f319..727298d 100644 --- a/chrome/browser/resources/local_ntp/local_ntp.css +++ b/chrome/browser/resources/local_ntp/local_ntp.css @@ -279,6 +279,7 @@ body.rtl .mv-page .mv-x { } .mv-favicon { + background-size: 16px; bottom: -8px; height: 16px; left: 61px; diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm index 0fc7438..c97ada7 100644 --- a/chrome/browser/ui/cocoa/history_menu_bridge.mm +++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm @@ -13,7 +13,6 @@ #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU #import "chrome/browser/app_controller_mac.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/profiles/profile.h" @@ -21,6 +20,7 @@ #include "chrome/browser/sessions/tab_restore_service_factory.h" #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/url_constants.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" diff --git a/chrome/browser/ui/cocoa/history_menu_bridge_unittest.mm b/chrome/browser/ui/cocoa/history_menu_bridge_unittest.mm index 8ff1cf8..315f96d 100644 --- a/chrome/browser/ui/cocoa/history_menu_bridge_unittest.mm +++ b/chrome/browser/ui/cocoa/history_menu_bridge_unittest.mm @@ -12,10 +12,10 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/common/cancelable_request.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/sessions/persistent_tab_restore_service.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/history_menu_bridge.h" +#include "chrome/common/favicon/favicon_types.h" #include "components/sessions/serialized_navigation_entry_test_helper.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/ui/search_engines/template_url_table_model.cc b/chrome/browser/ui/search_engines/template_url_table_model.cc index 44dab8d..918ae0f 100644 --- a/chrome/browser/ui/search_engines/template_url_table_model.cc +++ b/chrome/browser/ui/search_engines/template_url_table_model.cc @@ -11,11 +11,11 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/common/cancelable_task_tracker.h" +#include "chrome/common/favicon/favicon_types.h" #include "grit/generated_resources.h" #include "grit/ui_resources.h" #include "third_party/skia/include/core/SkBitmap.h" diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model.cc b/chrome/browser/ui/toolbar/back_forward_menu_model.cc index 09ae305c..cdce413 100644 --- a/chrome/browser/ui/toolbar/back_forward_menu_model.cc +++ b/chrome/browser/ui/toolbar/back_forward_menu_model.cc @@ -10,12 +10,12 @@ #include "base/strings/string_number_conversions.h" #include "build/build_config.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/singleton_tabs.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/public/browser/favicon_status.h" diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc index d32cb3c..072c5df 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc @@ -10,7 +10,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_restore.h" @@ -24,6 +23,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/time_format.h" #include "chrome/common/url_constants.h" diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index 4552273..3c322bc 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -13,6 +13,7 @@ #include "chrome/browser/search/instant_io_context.h" #include "chrome/browser/search/instant_service.h" #include "chrome/browser/search/instant_service_factory.h" +#include "chrome/common/favicon/favicon_url_parser.h" #include "chrome/common/url_constants.h" #include "grit/locale_settings.h" #include "grit/ui_resources.h" @@ -22,31 +23,6 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/webui/web_ui_util.h" -namespace { - -// Parameters which can be used in chrome://favicon path. See .h file for a -// description of what each does. -const char kIconURLParameter[] = "iconurl/"; -const char kLargestParameter[] = "largest/"; -const char kOriginParameter[] = "origin/"; -const char kSizeParameter[] = "size/"; - -// Returns true if |search| is a substring of |path| which starts at -// |start_index|. -bool HasSubstringAt(const std::string& path, - size_t start_index, - const std::string& search) { - if (search.empty()) - return false; - - if (start_index + search.size() >= path.size()) - return false; - - return (path.compare(start_index, search.size(), search) == 0); -} - -} // namespace - FaviconSource::IconRequest::IconRequest() : size_in_dip(gfx::kFaviconSize), scale_factor(ui::SCALE_FACTOR_NONE) { @@ -93,32 +69,29 @@ void FaviconSource::StartDataRequest( return; } - bool is_icon_url = false; - GURL url; - int size_in_dip = 16; - ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; - bool success = ParsePath(path, &is_icon_url, &url, &size_in_dip, - &scale_factor); - + chrome::ParsedFaviconPath parsed; + bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); if (!success) { SendDefaultResponse(callback); return; } - if (is_icon_url) { + GURL url(parsed.url); + + if (parsed.is_icon_url) { // TODO(michaelbai): Change GetRawFavicon to support combination of // IconType. favicon_service->GetRawFavicon( url, chrome::FAVICON, - size_in_dip, - scale_factor, + parsed.size_in_dip, + parsed.scale_factor, base::Bind(&FaviconSource::OnFaviconDataAvailable, base::Unretained(this), IconRequest(callback, url, - size_in_dip, - scale_factor)), + parsed.size_in_dip, + parsed.scale_factor)), &cancelable_task_tracker_); } else { // Intercept requests for prepopulated pages. @@ -128,21 +101,21 @@ void FaviconSource::StartDataRequest( callback.Run( ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( history::kPrepopulatedPages[i].favicon_id, - scale_factor)); + parsed.scale_factor)); return; } } favicon_service->GetRawFaviconForURL( FaviconService::FaviconForURLParams( - profile_, url, icon_types_, size_in_dip), - scale_factor, + profile_, url, icon_types_, parsed.size_in_dip), + parsed.scale_factor, base::Bind(&FaviconSource::OnFaviconDataAvailable, base::Unretained(this), IconRequest(callback, url, - size_in_dip, - scale_factor)), + parsed.size_in_dip, + parsed.scale_factor)), &cancelable_task_tracker_); } } @@ -171,93 +144,6 @@ bool FaviconSource::HandleMissingResource(const IconRequest& request) { return false; } -bool FaviconSource::ParsePath(const std::string& path, - bool* is_icon_url, - GURL* url, - int* size_in_dip, - ui::ScaleFactor* scale_factor) const { - DCHECK_EQ(16, gfx::kFaviconSize); - - *is_icon_url = false; - *url = GURL(); - *size_in_dip = 16; - *scale_factor = ui::SCALE_FACTOR_100P; - - if (path.empty()) - return false; - - size_t parsed_index = 0; - if (HasSubstringAt(path, parsed_index, kLargestParameter)) { - parsed_index += strlen(kLargestParameter); - *size_in_dip = 0; - } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { - parsed_index += strlen(kSizeParameter); - - size_t slash = path.find("/", parsed_index); - if (slash == std::string::npos) - return false; - - size_t scale_delimiter = path.find("@", parsed_index); - std::string size_str; - std::string scale_str; - if (scale_delimiter == std::string::npos) { - // Support the legacy size format of 'size/aa/' where 'aa' is the desired - // size in DIP for the sake of not regressing the extensions which use it. - size_str = path.substr(parsed_index, slash - parsed_index); - } else { - size_str = path.substr(parsed_index, scale_delimiter - parsed_index); - scale_str = path.substr(scale_delimiter + 1, slash - scale_delimiter - 1); - } - - if (!base::StringToInt(size_str, size_in_dip)) - return false; - - if (*size_in_dip != 64 && *size_in_dip != 32) { - // Only 64x64, 32x32 and 16x16 icons are supported. - *size_in_dip = 16; - } - - if (!scale_str.empty()) - webui::ParseScaleFactor(scale_str, scale_factor); - - // Return the default favicon (as opposed to a resized favicon) for - // favicon sizes which are not cached by the favicon service. - // Currently the favicon service caches: - // - favicons of sizes "16 * scale factor" px of type FAVICON - // where scale factor is one of FaviconUtil::GetFaviconScaleFactors(). - // - the largest TOUCH_ICON / TOUCH_PRECOMPOSED_ICON - if (*size_in_dip != 16 && icon_types_ == chrome::FAVICON) - return false; - - parsed_index = slash + 1; - } - - if (HasSubstringAt(path, parsed_index, kIconURLParameter)) { - parsed_index += strlen(kIconURLParameter); - *is_icon_url = true; - *url = GURL(path.substr(parsed_index)); - } else { - // URL requests prefixed with "origin/" are converted to a form with an - // empty path and a valid scheme. (e.g., example.com --> - // http://example.com/ or http://example.com/a --> http://example.com/) - if (HasSubstringAt(path, parsed_index, kOriginParameter)) { - parsed_index += strlen(kOriginParameter); - std::string possibly_invalid_url = path.substr(parsed_index); - - // If the URL does not specify a scheme (e.g., example.com instead of - // http://example.com), add "http://" as a default. - if (!GURL(possibly_invalid_url).has_scheme()) - possibly_invalid_url = "http://" + possibly_invalid_url; - - // Strip the path beyond the top-level domain. - *url = GURL(possibly_invalid_url).GetOrigin(); - } else { - *url = GURL(path.substr(parsed_index)); - } - } - return true; -} - void FaviconSource::OnFaviconDataAvailable( const IconRequest& request, const chrome::FaviconBitmapResult& bitmap_result) { diff --git a/chrome/browser/ui/webui/favicon_source.h b/chrome/browser/ui/webui/favicon_source.h index b880374..13203173 100644 --- a/chrome/browser/ui/webui/favicon_source.h +++ b/chrome/browser/ui/webui/favicon_source.h @@ -117,14 +117,6 @@ class FaviconSource : public content::URLDataSource { NUM_SIZES }; - // Parses |path|, which should be in the format described at the top of the - // file. Returns true if |path| could be parsed. - bool ParsePath(const std::string& path, - bool* is_icon_url, - GURL* url, - int* size_in_dip, - ui::ScaleFactor* scale_factor) const; - // Called when favicon data is available from the history backend. void OnFaviconDataAvailable( const IconRequest& request, diff --git a/chrome/browser/ui/webui/favicon_source_unittest.cc b/chrome/browser/ui/webui/favicon_source_unittest.cc deleted file mode 100644 index 2710503..0000000 --- a/chrome/browser/ui/webui/favicon_source_unittest.cc +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/favicon_source.h" - -#include "base/message_loop.h" -#include "base/strings/string_number_conversions.h" -#include "chrome/browser/search/instant_service.h" -#include "chrome/browser/search/instant_service_factory.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/layout.h" - -class FaviconSourceTest : public testing::Test { - public: - FaviconSourceTest() - : loop_(base::MessageLoop::TYPE_UI), - ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), - io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), - profile_(new TestingProfile()), - favicon_source_( - new FaviconSource(profile_.get(), FaviconSource::ANY)) { - - // Set the supported scale factors because the supported scale factors - // affect the result of ParsePathAndScale(). - std::vector<ui::ScaleFactor> supported_scale_factors; - supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); - supported_scale_factors.push_back(ui::SCALE_FACTOR_140P); - scoped_set_supported_scale_factors_.reset( - new ui::test::ScopedSetSupportedScaleFactors(supported_scale_factors)); - } - - virtual ~FaviconSourceTest() { - } - - FaviconSource* favicon_source() const { return favicon_source_.get(); } - - private: - base::MessageLoop loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; - scoped_ptr<TestingProfile> profile_; - - typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> - ScopedSetSupportedScaleFactors; - ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; - - scoped_ptr<FaviconSource> favicon_source_; - - DISALLOW_COPY_AND_ASSIGN(FaviconSourceTest); -}; - -// Test parsing the chrome-search://favicon/ URLs -TEST_F(FaviconSourceTest, InstantParsing) { - const std::string path("chrome-search://favicon/http://www.google.com"); - bool is_icon_url; - GURL url; - int size_in_dip; - ui::ScaleFactor scale_factor; - - EXPECT_TRUE(favicon_source()->ParsePath(path, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(GURL(path), url); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); -} - -// Test parsing the chrome://favicon URLs -TEST_F(FaviconSourceTest, Parsing) { - const GURL kUrl("https://www.google.ca/imghp?hl=en&tab=wi"); - - bool is_icon_url; - GURL url; - int size_in_dip; - ui::ScaleFactor scale_factor; - - // 1) Test parsing path with no extra parameters. - const std::string path1 = kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path1, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(kUrl, url); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - // 2) Test parsing path with a 'size' parameter. - // - // Test that we can still parse the legacy 'size' parameter format. - const std::string path2 = "size/32/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path2, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(kUrl, url); - EXPECT_EQ(32, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - // Test parsing current 'size' parameter format. - const std::string path3 = "size/32@1.4x/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path3, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(kUrl, url); - EXPECT_EQ(32, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_140P, scale_factor); - - // Test that we pick the ui::ScaleFactor which is closest to the passed in - // scale factor. - const std::string path4 = "size/16@1.41x/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path4, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(kUrl, url); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_140P, scale_factor); - - // Invalid cases. - const std::string path5 = "size/" + kUrl.spec(); - EXPECT_FALSE(favicon_source()->ParsePath(path5, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - const std::string path6 = "size/@1x/" + kUrl.spec(); - EXPECT_FALSE(favicon_source()->ParsePath(path6, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - const std::string path7 = "size/abc@1x/" + kUrl.spec(); - EXPECT_FALSE(favicon_source()->ParsePath(path7, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - - // Part of url looks like 'size' parameter. - const std::string path8 = "http://www.google.com/size/32@1.4x"; - EXPECT_TRUE(favicon_source()->ParsePath(path8, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(path8, url.spec()); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - // 3) Test parsing path with the 'largest' parameter. - const std::string path9 = "largest/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path9, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ(kUrl, url); - EXPECT_EQ(0, size_in_dip); - // The scale factor is meaningless when requesting the largest favicon. - - // 4) Test parsing path with 'iconurl' parameter. - const std::string path10 = "iconurl/http://www.google.com/favicon.ico"; - EXPECT_TRUE(favicon_source()->ParsePath(path10, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_TRUE(is_icon_url); - EXPECT_EQ("http://www.google.com/favicon.ico", url.spec()); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - // 5) Test parsing path with 'origin' parameter. - const std::string path11 = "origin/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path11, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ("https://www.google.ca/", url.spec()); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - const std::string path12 = "origin/google.com"; - EXPECT_TRUE(favicon_source()->ParsePath(path12, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ("http://google.com/", url.spec()); - EXPECT_EQ(16, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_100P, scale_factor); - - // 6) Test parsing paths with both a 'size' parameter and a 'url modifier' - // parameter. - const std::string path13 = "size/32@1.4x/origin/" + kUrl.spec(); - EXPECT_TRUE(favicon_source()->ParsePath(path13, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_FALSE(is_icon_url); - EXPECT_EQ("https://www.google.ca/", url.spec()); - EXPECT_EQ(32, size_in_dip); - EXPECT_EQ(ui::SCALE_FACTOR_140P, scale_factor); - - const std::string path14 = - "largest/iconurl/http://www.google.com/favicon.ico"; - EXPECT_TRUE(favicon_source()->ParsePath(path14, &is_icon_url, &url, - &size_in_dip, &scale_factor)); - EXPECT_TRUE(is_icon_url); - EXPECT_EQ("http://www.google.com/favicon.ico", url.spec()); - EXPECT_EQ(0, size_in_dip); -} diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 02c3179..ceaa778 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -26,7 +26,6 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/management_policy.h" #include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/favicon/favicon_types.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_finder.h" @@ -43,6 +42,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" +#include "chrome/common/favicon/favicon_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/common/web_application_info.h" |