diff options
-rw-r--r-- | chrome/browser/search/instant_service.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/fallback_icon_source.cc | 83 | ||||
-rw-r--r-- | chrome/browser/ui/webui/fallback_icon_source.h | 69 | ||||
-rw-r--r-- | chrome/browser/ui/webui/ntp/most_visited_handler.cc | 4 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 2 | ||||
-rw-r--r-- | components/favicon_base/fallback_icon_service.cc | 1 |
8 files changed, 164 insertions, 1 deletions
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc index f02d656..e785e0c 100644 --- a/chrome/browser/search/instant_service.cc +++ b/chrome/browser/search/instant_service.cc @@ -19,6 +19,7 @@ #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/thumbnails/thumbnail_list_source.h" #include "chrome/browser/ui/search/instant_search_prerenderer.h" +#include "chrome/browser/ui/webui/fallback_icon_source.h" #include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" #include "chrome/browser/ui/webui/theme_source.h" @@ -124,6 +125,7 @@ InstantService::InstantService(Profile* profile) content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); #endif // !defined(OS_ANDROID) + content::URLDataSource::Add(profile_, new FallbackIconSource()); content::URLDataSource::Add( profile_, new FaviconSource(profile_, FaviconSource::FAVICON)); content::URLDataSource::Add(profile_, new MostVisitedIframeSource()); diff --git a/chrome/browser/ui/webui/fallback_icon_source.cc b/chrome/browser/ui/webui/fallback_icon_source.cc new file mode 100644 index 0000000..78eae81 --- /dev/null +++ b/chrome/browser/ui/webui/fallback_icon_source.cc @@ -0,0 +1,83 @@ +// Copyright 2015 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/fallback_icon_source.h" + +#include <string> +#include <vector> + +#include "base/memory/ref_counted_memory.h" +#include "chrome/browser/search/instant_io_context.h" +#include "chrome/common/favicon/fallback_icon_url_parser.h" +#include "chrome/common/url_constants.h" +#include "grit/platform_locale_settings.h" +#include "net/url_request/url_request.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/favicon_size.h" + +FallbackIconSource::FallbackIconSource() { + std::vector<std::string> font_list; +#if defined(OS_CHROMEOS) + font_list.push_back("Noto Sans"); +#elif defined(OS_IOS) + font_list.push_back("Helvetica Neue"); +#else + font_list.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY)); +#endif + fallback_icon_service_.reset( + new favicon_base::FallbackIconService(font_list)); +} + +FallbackIconSource::~FallbackIconSource() { +} + +std::string FallbackIconSource::GetSource() const { + return chrome::kChromeUIFallbackIconHost; +} + +void FallbackIconSource::StartDataRequest( + const std::string& path, + int render_process_id, + int render_frame_id, + const content::URLDataSource::GotDataCallback& callback) { + chrome::ParsedFallbackIconPath parsed; + bool success = parsed.Parse(path); + if (!success) { + SendDefaultResponse(callback); + return; + } + + GURL url(parsed.url()); + std::vector<unsigned char> bitmap_data = + fallback_icon_service_->RenderFallbackIconBitmap( + url, parsed.size_in_pixels(), parsed.style()); + callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); +} + +std::string FallbackIconSource::GetMimeType(const std::string&) const { + // We need to explicitly return a mime type, otherwise if the user tries to + // drag the image they get no extension. + return "image/png"; +} + +bool FallbackIconSource::ShouldReplaceExistingSource() const { + // Leave the existing DataSource in place, otherwise we'll drop any pending + // requests on the floor. + return false; +} + +bool FallbackIconSource::ShouldServiceRequest( + const net::URLRequest* request) const { + if (request->url().SchemeIs(chrome::kChromeSearchScheme)) + return InstantIOContext::ShouldServiceRequest(request); + return URLDataSource::ShouldServiceRequest(request); +} + +void FallbackIconSource::SendDefaultResponse( + const content::URLDataSource::GotDataCallback& callback) { + std::vector<unsigned char> bitmap_data = + fallback_icon_service_->RenderFallbackIconBitmap( + GURL(), gfx::kFaviconSize, favicon_base::FallbackIconStyle()); + callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); +} diff --git a/chrome/browser/ui/webui/fallback_icon_source.h b/chrome/browser/ui/webui/fallback_icon_source.h new file mode 100644 index 0000000..086bbd0 --- /dev/null +++ b/chrome/browser/ui/webui/fallback_icon_source.h @@ -0,0 +1,69 @@ +// Copyright 2015 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_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ +#define CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ + +#include "base/memory/scoped_ptr.h" +#include "components/favicon_base/fallback_icon_service.h" +#include "content/public/browser/url_data_source.h" + +// FallbackIconSource services explicit chrome:// requests for fallback icons. +// +// Format: +// chrome://fallback-icon/size,bc,tc,fsr,r/url +// All of the parameters except for the url are optional. However, the order of +// the parameters is not interchangeable, and all "," must be in place. +// +// Parameter: +// 'size' +// Positive integer to specify the fallback icon's size in pixels. +// 'bc' +// Fallback icon's background color, as named CSS color, or #RGB / #RRGGBB / +// #AARRGGBB hex formats. +// 'tc' +// Fallback icon text color, as named CSS color, or #RGB / #RRGGBB / +// #AARRGGBB hex formats. +// 'fsr' +// Number in [0.0, 1.0] to specify the fallback icon's font size (pixels) +// as a ratio to the icon's size. +// 'r' +// Number in [0.0, 1.0] to specify the fallback icon's roundness. +// 0.0 specifies a square icon; 1.0 specifies a circle icon; intermediate +// values specify a rounded square icon. +// 'url' +// String to specify the page URL of the fallback icon. +// +// Example: chrome://fallback-icon/32,red,#000,0.5,1.0/http://www.google.com/ +// This requests a 32x32 fallback icon for http://www.google.com, using +// red as the background color, #000 as the text color, with font size of +// 32 * 0.5 = 16, and the icon's background shape is a circle. +class FallbackIconSource : public content::URLDataSource { + public: + FallbackIconSource(); + + ~FallbackIconSource() override; + + // content::URLDataSource implementation. + std::string GetSource() const override; + void StartDataRequest( + const std::string& path, + int render_process_id, + int render_frame_id, + const content::URLDataSource::GotDataCallback& callback) override; + std::string GetMimeType(const std::string&) const override; + bool ShouldReplaceExistingSource() const override; + bool ShouldServiceRequest(const net::URLRequest* request) const override; + + private: + // Sends the default fallback icon. + void SendDefaultResponse( + const content::URLDataSource::GotDataCallback& callback); + + scoped_ptr<favicon_base::FallbackIconService> fallback_icon_service_; + + DISALLOW_COPY_AND_ASSIGN(FallbackIconSource); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_FALLBACK_ICON_SOURCE_H_ diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc index 16d5b7c..39a1f2f 100644 --- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc +++ b/chrome/browser/ui/webui/ntp/most_visited_handler.cc @@ -27,6 +27,7 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" +#include "chrome/browser/ui/webui/fallback_icon_source.h" #include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/ntp/ntp_stats.h" @@ -79,6 +80,9 @@ void MostVisitedHandler::RegisterMessages() { // Set up our sources for top-sites data. content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); + // Register chrome://fallback-icon as a data source for fallback icons. + content::URLDataSource::Add(profile, new FallbackIconSource()); + // Register chrome://favicon as a data source for favicons. content::URLDataSource::Add( profile, new FaviconSource(profile, FaviconSource::FAVICON)); diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 435420d..902f9ed 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1040,6 +1040,8 @@ 'browser/ui/webui/device_log_ui.h', 'browser/ui/webui/domain_reliability_internals_ui.cc', 'browser/ui/webui/domain_reliability_internals_ui.h', + 'browser/ui/webui/fallback_icon_source.cc', + 'browser/ui/webui/fallback_icon_source.h', 'browser/ui/webui/favicon_source.cc', 'browser/ui/webui/favicon_source.h', 'browser/ui/webui/fileicon_source.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 3dc3a47..cf5f17e 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -45,6 +45,7 @@ const char kChromeUIEditSearchEngineDialogURL[] = "chrome://editsearchengine/"; const char kChromeUIExtensionIconURL[] = "chrome://extension-icon/"; const char kChromeUIExtensionsFrameURL[] = "chrome://extensions-frame/"; const char kChromeUIExtensionsURL[] = "chrome://extensions/"; +const char kChromeUIFallbackIconURL[] = "chrome://fallback-icon/"; const char kChromeUIFaviconURL[] = "chrome://favicon/"; const char kChromeUIFeedbackURL[] = "chrome://feedback/"; const char kChromeUIFlagsURL[] = "chrome://flags/"; @@ -186,6 +187,7 @@ const char kChromeUIEditSearchEngineDialogHost[] = "editsearchengine"; const char kChromeUIExtensionIconHost[] = "extension-icon"; const char kChromeUIExtensionsFrameHost[] = "extensions-frame"; const char kChromeUIExtensionsHost[] = "extensions"; +const char kChromeUIFallbackIconHost[] = "fallback-icon"; const char kChromeUIFaviconHost[] = "favicon"; const char kChromeUIFeedbackHost[] = "feedback"; const char kChromeUIFlagsHost[] = "flags"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index a161d58..7d4a1c7 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -40,6 +40,7 @@ extern const char kChromeUIEditSearchEngineDialogURL[]; extern const char kChromeUIExtensionIconURL[]; extern const char kChromeUIExtensionsFrameURL[]; extern const char kChromeUIExtensionsURL[]; +extern const char kChromeUIFallbackIconURL[]; extern const char kChromeUIFaviconURL[]; extern const char kChromeUIFeedbackURL[]; extern const char kChromeUIFlagsURL[]; @@ -177,6 +178,7 @@ extern const char kChromeUIEditSearchEngineDialogHost[]; extern const char kChromeUIExtensionIconHost[]; extern const char kChromeUIExtensionsFrameHost[]; extern const char kChromeUIExtensionsHost[]; +extern const char kChromeUIFallbackIconHost[]; extern const char kChromeUIFaviconHost[]; extern const char kChromeUIFeedbackHost[]; extern const char kChromeUIFlagsHost[]; diff --git a/components/favicon_base/fallback_icon_service.cc b/components/favicon_base/fallback_icon_service.cc index 1642b20..adce72e 100644 --- a/components/favicon_base/fallback_icon_service.cc +++ b/components/favicon_base/fallback_icon_service.cc @@ -11,7 +11,6 @@ #include "components/favicon_base/fallback_icon_style.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "third_party/skia/include/core/SkPaint.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/gfx/canvas.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/font_list.h" |