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

Side by Side Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 10828127: Use hi-resolution favicon variants if available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: daringfireball hackfix Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer/chrome_render_view_observer.h" 5 #include "chrome/renderer/chrome_render_view_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 44 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
45 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 45 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
46 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
47 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
49 #include "ui/gfx/color_utils.h" 49 #include "ui/gfx/color_utils.h"
50 #include "ui/gfx/favicon_size.h" 50 #include "ui/gfx/favicon_size.h"
51 #include "ui/gfx/size.h" 51 #include "ui/gfx/size.h"
52 #include "ui/gfx/skbitmap_operations.h" 52 #include "ui/gfx/skbitmap_operations.h"
53 #include "webkit/glue/image_decoder.h" 53 #include "webkit/glue/image_decoder.h"
54 #include "webkit/glue/image_resource_fetcher.h" 54 #include "webkit/glue/multi_resolution_image_resource_fetcher.h"
55 #include "webkit/glue/webkit_glue.h" 55 #include "webkit/glue/webkit_glue.h"
56 #include "v8/include/v8-testing.h" 56 #include "v8/include/v8-testing.h"
57 57
58 using WebKit::WebAccessibilityObject; 58 using WebKit::WebAccessibilityObject;
59 using WebKit::WebCString; 59 using WebKit::WebCString;
60 using WebKit::WebDataSource; 60 using WebKit::WebDataSource;
61 using WebKit::WebDocument; 61 using WebKit::WebDocument;
62 using WebKit::WebFrame; 62 using WebKit::WebFrame;
63 using WebKit::WebIconURL; 63 using WebKit::WebIconURL;
64 using WebKit::WebRect; 64 using WebKit::WebRect;
65 using WebKit::WebSecurityOrigin; 65 using WebKit::WebSecurityOrigin;
66 using WebKit::WebSize; 66 using WebKit::WebSize;
67 using WebKit::WebString; 67 using WebKit::WebString;
68 using WebKit::WebTouchEvent; 68 using WebKit::WebTouchEvent;
69 using WebKit::WebURL; 69 using WebKit::WebURL;
70 using WebKit::WebURLRequest; 70 using WebKit::WebURLRequest;
71 using WebKit::WebView; 71 using WebKit::WebView;
72 using WebKit::WebVector; 72 using WebKit::WebVector;
73 using extensions::APIPermission; 73 using extensions::APIPermission;
74 using webkit_glue::ImageResourceFetcher; 74 using webkit_glue::MultiResolutionImageResourceFetcher;
75 75
76 // Delay in milliseconds that we'll wait before capturing the page contents 76 // Delay in milliseconds that we'll wait before capturing the page contents
77 // and thumbnail. 77 // and thumbnail.
78 static const int kDelayForCaptureMs = 500; 78 static const int kDelayForCaptureMs = 500;
79 79
80 // Typically, we capture the page data once the page is loaded. 80 // Typically, we capture the page data once the page is loaded.
81 // Sometimes, the page never finishes to load, preventing the page capture 81 // Sometimes, the page never finishes to load, preventing the page capture
82 // To workaround this problem, we always perform a capture after the following 82 // To workaround this problem, we always perform a capture after the following
83 // delay. 83 // delay.
84 static const int kDelayForForcedCaptureMs = 6000; 84 static const int kDelayForForcedCaptureMs = 6000;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 int param) { 319 int param) {
320 if (cmd == kJavaScriptStressTestSetStressRunType) { 320 if (cmd == kJavaScriptStressTestSetStressRunType) {
321 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); 321 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
322 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { 322 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
323 v8::Testing::PrepareStressRun(param); 323 v8::Testing::PrepareStressRun(param);
324 } 324 }
325 } 325 }
326 326
327 void ChromeRenderViewObserver::OnDownloadFavicon(int id, 327 void ChromeRenderViewObserver::OnDownloadFavicon(int id,
328 const GURL& image_url, 328 const GURL& image_url,
329 int image_size) { 329 const std::vector<int>& image_s ize) {
330 bool data_image_failed = false; 330 bool data_image_failed = false;
331 if (image_url.SchemeIs("data")) { 331 if (image_url.SchemeIs("data")) {
332 SkBitmap data_image = ImageFromDataUrl(image_url); 332 SkBitmap data_image = ImageFromDataUrl(image_url);
333 data_image_failed = data_image.empty(); 333 data_image_failed = data_image.empty();
334 if (!data_image_failed) { 334 if (!data_image_failed) {
335 std::vector<SkBitmap> images(1, data_image);
335 Send(new IconHostMsg_DidDownloadFavicon( 336 Send(new IconHostMsg_DidDownloadFavicon(
336 routing_id(), id, image_url, false, data_image)); 337 routing_id(), id, image_url, false, images));
337 } 338 }
338 } 339 }
339 340
340 if (data_image_failed || 341 if (data_image_failed ||
341 !DownloadFavicon(id, image_url, image_size)) { 342 !DownloadFavicon(id, image_url, image_size)) {
342 Send(new IconHostMsg_DidDownloadFavicon( 343 Send(new IconHostMsg_DidDownloadFavicon(
343 routing_id(), id, image_url, true, SkBitmap())); 344 routing_id(), id, image_url, true, std::vector<SkBitmap>()));
344 } 345 }
345 } 346 }
346 347
347 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) { 348 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) {
348 allow_displaying_insecure_content_ = allow; 349 allow_displaying_insecure_content_ = allow;
349 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 350 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
350 if (main_frame) 351 if (main_frame)
351 main_frame->reload(); 352 main_frame->reload();
352 } 353 }
353 354
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { 1037 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() {
1037 if (!external_host_bindings_.get()) { 1038 if (!external_host_bindings_.get()) {
1038 external_host_bindings_.reset(new ExternalHostBindings( 1039 external_host_bindings_.reset(new ExternalHostBindings(
1039 render_view(), routing_id())); 1040 render_view(), routing_id()));
1040 } 1041 }
1041 return external_host_bindings_.get(); 1042 return external_host_bindings_.get();
1042 } 1043 }
1043 1044
1044 bool ChromeRenderViewObserver::DownloadFavicon(int id, 1045 bool ChromeRenderViewObserver::DownloadFavicon(int id,
1045 const GURL& image_url, 1046 const GURL& image_url,
1046 int image_size) { 1047 const std::vector<int>& image_siz es) {
1047 // Make sure webview was not shut down. 1048 // Make sure webview was not shut down.
1048 if (!render_view()->GetWebView()) 1049 if (!render_view()->GetWebView())
1049 return false; 1050 return false;
1050 // Create an image resource fetcher and assign it with a call back object. 1051 // Create an image resource fetcher and assign it with a call back object.
1051 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( 1052 image_fetchers_.push_back(linked_ptr<MultiResolutionImageResourceFetcher>(
1052 new ImageResourceFetcher( 1053 new MultiResolutionImageResourceFetcher(
1053 image_url, render_view()->GetWebView()->mainFrame(), id, image_size, 1054 image_url, render_view()->GetWebView()->mainFrame(), id, image_sizes,
1054 WebURLRequest::TargetIsFavicon, 1055 WebURLRequest::TargetIsFavicon,
1055 base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon, 1056 base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon,
1056 base::Unretained(this))))); 1057 base::Unretained(this)))));
1057 return true; 1058 return true;
1058 } 1059 }
1059 1060
1060 void ChromeRenderViewObserver::DidDownloadFavicon( 1061 void ChromeRenderViewObserver::DidDownloadFavicon(
1061 ImageResourceFetcher* fetcher, const SkBitmap& image) { 1062 MultiResolutionImageResourceFetcher* fetcher,
1063 const std::vector<SkBitmap>& images) {
pkotwicz 2012/08/02 23:47:08 Nit: bitmaps
1062 // Notify requester of image download status. 1064 // Notify requester of image download status.
1063 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), 1065 Send(new IconHostMsg_DidDownloadFavicon(routing_id(),
1064 fetcher->id(), 1066 fetcher->id(),
1065 fetcher->image_url(), 1067 fetcher->image_url(),
1066 image.isNull(), 1068 images.empty(), // XXX
1067 image)); 1069 images));
1068 1070
1069 // Remove the image fetcher from our pending list. We're in the callback from 1071 // Remove the image fetcher from our pending list. We're in the callback from
1070 // ImageResourceFetcher, best to delay deletion. 1072 // MultiResolutionImageResourceFetcher, best to delay deletion.
1071 ImageResourceFetcherList::iterator iter; 1073 ImageResourceFetcherList::iterator iter;
1072 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { 1074 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) {
1073 if (iter->get() == fetcher) { 1075 if (iter->get() == fetcher) {
1074 iter->release(); 1076 iter->release();
1075 image_fetchers_.erase(iter); 1077 image_fetchers_.erase(iter);
1076 break; 1078 break;
1077 } 1079 }
1078 } 1080 }
1079 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); 1081 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
1080 } 1082 }
1081 1083
1082 SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { 1084 SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const {
1083 std::string mime_type, char_set, data; 1085 std::string mime_type, char_set, data;
1084 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { 1086 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
1085 // Decode the favicon using WebKit's image decoder. 1087 // Decode the favicon using WebKit's image decoder.
1086 webkit_glue::ImageDecoder decoder( 1088 webkit_glue::ImageDecoder decoder(
1087 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); 1089 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize));
1088 const unsigned char* src_data = 1090 const unsigned char* src_data =
1089 reinterpret_cast<const unsigned char*>(&data[0]); 1091 reinterpret_cast<const unsigned char*>(&data[0]);
1090 1092
1091 return decoder.Decode(src_data, data.size()); 1093 return decoder.Decode(src_data, data.size());
1092 } 1094 }
1093 return SkBitmap(); 1095 return SkBitmap();
1094 } 1096 }
1095 1097
1096 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { 1098 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) {
1097 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); 1099 return (strict_security_hosts_.find(host) != strict_security_hosts_.end());
1098 } 1100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698