Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: chrome/browser/ui/webui/fallback_icon_source.cc

Issue 835903005: [Favicon] Add new fallback icon rendering flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding new host chrome://fallback-icon. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/fallback_icon_source.cc
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 0000000000000000000000000000000000000000..7684423d7d8ad7d4beb284fa883144a4f6827893
--- /dev/null
+++ b/chrome/browser/ui/webui/fallback_icon_source.cc
@@ -0,0 +1,70 @@
+// 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 "chrome/browser/search/instant_io_context.h"
+#include "chrome/common/favicon/fallback_icon_url_parser.h"
+#include "chrome/common/url_constants.h"
+#include "net/url_request/url_request.h"
+
+FallbackIconSource::FallbackIconSource() {
+}
+
+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 = chrome::ParseFallbackIconPath(path, &parsed);
+ if (!success) {
+ SendDefaultResponse(callback);
+ return;
+ }
+
+ GURL url(parsed.url);
+ int desired_size_in_pixel =
+ std::ceil(parsed.size_in_dip * parsed.device_scale_factor);
+
+ std::vector<unsigned char> bitmap_data =
+ fallback_icon_service_.RenderFallbackIconBitmap(
+ url, desired_size_in_pixel, parsed.style_builder.Build());
+ 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) {
+ favicon_base::FallbackIconStyleBuilder builder;
+ std::vector<unsigned char> bitmap_data =
+ fallback_icon_service_.RenderFallbackIconBitmap(
+ GURL(), 16, builder.Build());
+ callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
+}

Powered by Google App Engine
This is Rietveld 408576698