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/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 Loading... |
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int image_size) { |
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, image_size, 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, image_size, |
| 345 std::vector<SkBitmap>())); |
344 } | 346 } |
345 } | 347 } |
346 | 348 |
347 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) { | 349 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) { |
348 allow_displaying_insecure_content_ = allow; | 350 allow_displaying_insecure_content_ = allow; |
349 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 351 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
350 if (main_frame) | 352 if (main_frame) |
351 main_frame->reload(); | 353 main_frame->reload(); |
352 } | 354 } |
353 | 355 |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 return external_host_bindings_.get(); | 1043 return external_host_bindings_.get(); |
1042 } | 1044 } |
1043 | 1045 |
1044 bool ChromeRenderViewObserver::DownloadFavicon(int id, | 1046 bool ChromeRenderViewObserver::DownloadFavicon(int id, |
1045 const GURL& image_url, | 1047 const GURL& image_url, |
1046 int image_size) { | 1048 int image_size) { |
1047 // Make sure webview was not shut down. | 1049 // Make sure webview was not shut down. |
1048 if (!render_view()->GetWebView()) | 1050 if (!render_view()->GetWebView()) |
1049 return false; | 1051 return false; |
1050 // Create an image resource fetcher and assign it with a call back object. | 1052 // Create an image resource fetcher and assign it with a call back object. |
1051 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( | 1053 image_fetchers_.push_back(linked_ptr<MultiResolutionImageResourceFetcher>( |
1052 new ImageResourceFetcher( | 1054 new MultiResolutionImageResourceFetcher( |
1053 image_url, render_view()->GetWebView()->mainFrame(), id, image_size, | 1055 image_url, render_view()->GetWebView()->mainFrame(), id, |
1054 WebURLRequest::TargetIsFavicon, | 1056 WebURLRequest::TargetIsFavicon, |
1055 base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon, | 1057 base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon, |
1056 base::Unretained(this))))); | 1058 base::Unretained(this), image_size)))); |
1057 return true; | 1059 return true; |
1058 } | 1060 } |
1059 | 1061 |
1060 void ChromeRenderViewObserver::DidDownloadFavicon( | 1062 void ChromeRenderViewObserver::DidDownloadFavicon( |
1061 ImageResourceFetcher* fetcher, const SkBitmap& image) { | 1063 int requested_size, |
| 1064 MultiResolutionImageResourceFetcher* fetcher, |
| 1065 const std::vector<SkBitmap>& images) { |
1062 // Notify requester of image download status. | 1066 // Notify requester of image download status. |
1063 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), | 1067 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), |
1064 fetcher->id(), | 1068 fetcher->id(), |
1065 fetcher->image_url(), | 1069 fetcher->image_url(), |
1066 image.isNull(), | 1070 images.empty(), |
1067 image)); | 1071 requested_size, |
| 1072 images)); |
1068 | 1073 |
1069 // Remove the image fetcher from our pending list. We're in the callback from | 1074 // Remove the image fetcher from our pending list. We're in the callback from |
1070 // ImageResourceFetcher, best to delay deletion. | 1075 // MultiResolutionImageResourceFetcher, best to delay deletion. |
1071 ImageResourceFetcherList::iterator iter; | 1076 ImageResourceFetcherList::iterator iter; |
1072 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { | 1077 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { |
1073 if (iter->get() == fetcher) { | 1078 if (iter->get() == fetcher) { |
1074 iter->release(); | 1079 iter->release(); |
1075 image_fetchers_.erase(iter); | 1080 image_fetchers_.erase(iter); |
1076 break; | 1081 break; |
1077 } | 1082 } |
1078 } | 1083 } |
1079 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 1084 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
1080 } | 1085 } |
1081 | 1086 |
1082 SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { | 1087 SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { |
1083 std::string mime_type, char_set, data; | 1088 std::string mime_type, char_set, data; |
1084 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 1089 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
1085 // Decode the favicon using WebKit's image decoder. | 1090 // Decode the favicon using WebKit's image decoder. |
1086 webkit_glue::ImageDecoder decoder( | 1091 webkit_glue::ImageDecoder decoder( |
1087 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | 1092 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); |
1088 const unsigned char* src_data = | 1093 const unsigned char* src_data = |
1089 reinterpret_cast<const unsigned char*>(&data[0]); | 1094 reinterpret_cast<const unsigned char*>(&data[0]); |
1090 | 1095 |
1091 return decoder.Decode(src_data, data.size()); | 1096 return decoder.Decode(src_data, data.size()); |
1092 } | 1097 } |
1093 return SkBitmap(); | 1098 return SkBitmap(); |
1094 } | 1099 } |
1095 | 1100 |
1096 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 1101 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
1097 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 1102 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
1098 } | 1103 } |
OLD | NEW |