OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/common/chrome_constants.h" | |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/icon_messages.h" | 12 #include "chrome/common/icon_messages.h" |
12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
13 #include "chrome/common/thumbnail_score.h" | 14 #include "chrome/common/thumbnail_score.h" |
14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
15 #include "chrome/renderer/about_handler.h" | 16 #include "chrome/renderer/about_handler.h" |
16 #include "chrome/renderer/content_settings_observer.h" | 17 #include "chrome/renderer/content_settings_observer.h" |
17 #include "chrome/renderer/automation/dom_automation_controller.h" | 18 #include "chrome/renderer/automation/dom_automation_controller.h" |
18 #include "chrome/renderer/extensions/extension_dispatcher.h" | 19 #include "chrome/renderer/extensions/extension_dispatcher.h" |
19 #include "chrome/renderer/external_host_bindings.h" | 20 #include "chrome/renderer/external_host_bindings.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
43 #include "ui/gfx/skbitmap_operations.h" | 44 #include "ui/gfx/skbitmap_operations.h" |
44 #include "webkit/glue/dom_operations.h" | 45 #include "webkit/glue/dom_operations.h" |
45 #include "webkit/glue/image_decoder.h" | 46 #include "webkit/glue/image_decoder.h" |
46 #include "webkit/glue/image_resource_fetcher.h" | 47 #include "webkit/glue/image_resource_fetcher.h" |
47 #include "webkit/glue/webkit_glue.h" | 48 #include "webkit/glue/webkit_glue.h" |
48 #include "v8/include/v8-testing.h" | 49 #include "v8/include/v8-testing.h" |
49 | 50 |
50 using WebKit::WebCString; | 51 using WebKit::WebCString; |
51 using WebKit::WebDataSource; | 52 using WebKit::WebDataSource; |
52 using WebKit::WebFrame; | 53 using WebKit::WebFrame; |
54 using WebKit::WebIconURL; | |
53 using WebKit::WebPageSerializer; | 55 using WebKit::WebPageSerializer; |
54 using WebKit::WebPageSerializerClient; | 56 using WebKit::WebPageSerializerClient; |
55 using WebKit::WebRect; | 57 using WebKit::WebRect; |
56 using WebKit::WebSecurityOrigin; | 58 using WebKit::WebSecurityOrigin; |
57 using WebKit::WebSize; | 59 using WebKit::WebSize; |
58 using WebKit::WebString; | 60 using WebKit::WebString; |
59 using WebKit::WebURL; | 61 using WebKit::WebURL; |
60 using WebKit::WebURLRequest; | 62 using WebKit::WebURLRequest; |
61 using WebKit::WebView; | 63 using WebKit::WebView; |
62 using WebKit::WebVector; | 64 using WebKit::WebVector; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 // bitmap are all the same brightness. | 108 // bitmap are all the same brightness. |
107 static double CalculateBoringScore(SkBitmap* bitmap) { | 109 static double CalculateBoringScore(SkBitmap* bitmap) { |
108 int histogram[256] = {0}; | 110 int histogram[256] = {0}; |
109 color_utils::BuildLumaHistogram(bitmap, histogram); | 111 color_utils::BuildLumaHistogram(bitmap, histogram); |
110 | 112 |
111 int color_count = *std::max_element(histogram, histogram + 256); | 113 int color_count = *std::max_element(histogram, histogram + 256); |
112 int pixel_count = bitmap->width() * bitmap->height(); | 114 int pixel_count = bitmap->width() * bitmap->height(); |
113 return static_cast<double>(color_count) / pixel_count; | 115 return static_cast<double>(color_count) / pixel_count; |
114 } | 116 } |
115 | 117 |
118 static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { | |
119 switch (type) { | |
120 case WebIconURL::TypeFavicon : | |
sky
2011/05/17 16:08:50
no spaces between type and colon (here and on all
| |
121 return FaviconURL::FAVICON; | |
122 case WebIconURL::TypeTouch : | |
123 return FaviconURL::TOUCH_ICON; | |
124 case WebIconURL::TypeTouchPrecomposed : | |
125 return FaviconURL::TOUCH_PRECOMPOSED_ICON; | |
126 case WebIconURL::TypeInvalid : | |
127 return FaviconURL::INVALID_ICON; | |
128 } | |
129 return FaviconURL::INVALID_ICON; | |
130 } | |
131 | |
116 ChromeRenderViewObserver::ChromeRenderViewObserver( | 132 ChromeRenderViewObserver::ChromeRenderViewObserver( |
117 RenderView* render_view, | 133 RenderView* render_view, |
118 ContentSettingsObserver* content_settings, | 134 ContentSettingsObserver* content_settings, |
119 ExtensionDispatcher* extension_dispatcher, | 135 ExtensionDispatcher* extension_dispatcher, |
120 TranslateHelper* translate_helper, | 136 TranslateHelper* translate_helper, |
121 safe_browsing::PhishingClassifierDelegate* phishing_classifier) | 137 safe_browsing::PhishingClassifierDelegate* phishing_classifier) |
122 : RenderViewObserver(render_view), | 138 : RenderViewObserver(render_view), |
123 content_settings_(content_settings), | 139 content_settings_(content_settings), |
124 extension_dispatcher_(extension_dispatcher), | 140 extension_dispatcher_(extension_dispatcher), |
125 translate_helper_(translate_helper), | 141 translate_helper_(translate_helper), |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 render_view()->content_state_immediately() ? 0 : kDelayForCaptureMs); | 399 render_view()->content_state_immediately() ? 0 : kDelayForCaptureMs); |
384 | 400 |
385 GURL osd_url = | 401 GURL osd_url = |
386 render_view()->webview()->mainFrame()->openSearchDescriptionURL(); | 402 render_view()->webview()->mainFrame()->openSearchDescriptionURL(); |
387 if (!osd_url.is_empty()) { | 403 if (!osd_url.is_empty()) { |
388 Send(new ViewHostMsg_PageHasOSDD( | 404 Send(new ViewHostMsg_PageHasOSDD( |
389 routing_id(), render_view()->page_id(), osd_url, | 405 routing_id(), render_view()->page_id(), osd_url, |
390 search_provider::AUTODETECTED_PROVIDER)); | 406 search_provider::AUTODETECTED_PROVIDER)); |
391 } | 407 } |
392 | 408 |
393 // TODO : Get both favicon and touch icon url, and send them to the browser. | 409 int icon_types = WebIconURL::TypeFavicon; |
394 GURL favicon_url(render_view()->webview()->mainFrame()->favIconURL()); | 410 if (chrome::kEnableTouchIcon) |
395 if (!favicon_url.is_empty()) { | 411 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
396 std::vector<FaviconURL> urls; | 412 |
397 urls.push_back(FaviconURL(favicon_url, FaviconURL::FAVICON)); | 413 WebVector<WebIconURL> icon_urls = |
414 render_view()->webview()->mainFrame()->iconURLs(icon_types); | |
415 std::vector<FaviconURL> urls; | |
416 for (size_t i = 0; i < icon_urls.size(); i++) { | |
417 WebURL url = icon_urls[i].iconURL(); | |
418 if (!url.isEmpty()) | |
419 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); | |
420 } | |
421 if (!urls.empty()) { | |
398 Send(new IconHostMsg_UpdateFaviconURL( | 422 Send(new IconHostMsg_UpdateFaviconURL( |
399 routing_id(), render_view()->page_id(), urls)); | 423 routing_id(), render_view()->page_id(), urls)); |
400 } | 424 } |
401 } | 425 } |
402 | 426 |
403 void ChromeRenderViewObserver::DidChangeIcons(WebFrame* frame) { | 427 void ChromeRenderViewObserver::DidChangeIcon(WebFrame* frame, |
428 WebIconURL::Type icon_type) { | |
404 if (frame->parent()) | 429 if (frame->parent()) |
405 return; | 430 return; |
406 | 431 |
432 if (!chrome::kEnableTouchIcon && | |
433 icon_type != WebIconURL::TypeFavicon) | |
434 return; | |
435 | |
436 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | |
407 std::vector<FaviconURL> urls; | 437 std::vector<FaviconURL> urls; |
408 urls.push_back(FaviconURL(frame->favIconURL(), FaviconURL::FAVICON)); | 438 for (size_t i = 0; i < icon_urls.size(); i++) { |
439 urls.push_back(FaviconURL(icon_urls[i].iconURL(), | |
440 ToFaviconType(icon_urls[i].iconType()))); | |
441 } | |
409 Send(new IconHostMsg_UpdateFaviconURL( | 442 Send(new IconHostMsg_UpdateFaviconURL( |
410 routing_id(), render_view()->page_id(), urls)); | 443 routing_id(), render_view()->page_id(), urls)); |
411 } | 444 } |
412 | 445 |
413 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 446 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
414 WebFrame* frame, bool is_new_navigation) { | 447 WebFrame* frame, bool is_new_navigation) { |
415 if (!is_new_navigation) | 448 if (!is_new_navigation) |
416 return; | 449 return; |
417 | 450 |
418 MessageLoop::current()->PostDelayedTask( | 451 MessageLoop::current()->PostDelayedTask( |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 729 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
697 // Decode the favicon using WebKit's image decoder. | 730 // Decode the favicon using WebKit's image decoder. |
698 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); | 731 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
699 const unsigned char* src_data = | 732 const unsigned char* src_data = |
700 reinterpret_cast<const unsigned char*>(&data[0]); | 733 reinterpret_cast<const unsigned char*>(&data[0]); |
701 | 734 |
702 return decoder.Decode(src_data, data.size()); | 735 return decoder.Decode(src_data, data.size()); |
703 } | 736 } |
704 return SkBitmap(); | 737 return SkBitmap(); |
705 } | 738 } |
OLD | NEW |