| 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 render_view()->GetContentStateImmediately() ? | 689 render_view()->GetContentStateImmediately() ? |
| 690 0 : kDelayForCaptureMs)); | 690 0 : kDelayForCaptureMs)); |
| 691 | 691 |
| 692 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 692 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 693 GURL osd_url = main_frame->document().openSearchDescriptionURL(); | 693 GURL osd_url = main_frame->document().openSearchDescriptionURL(); |
| 694 if (!osd_url.is_empty()) { | 694 if (!osd_url.is_empty()) { |
| 695 Send(new ChromeViewHostMsg_PageHasOSDD( | 695 Send(new ChromeViewHostMsg_PageHasOSDD( |
| 696 routing_id(), render_view()->GetPageId(), osd_url, | 696 routing_id(), render_view()->GetPageId(), osd_url, |
| 697 search_provider::AUTODETECTED_PROVIDER)); | 697 search_provider::AUTODETECTED_PROVIDER)); |
| 698 } | 698 } |
| 699 } |
| 699 | 700 |
| 701 void ChromeRenderViewObserver::DidFinishLoad(WebKit::WebFrame* frame) { |
| 702 if (frame->parent()) |
| 703 return; |
| 704 |
| 705 // Please note that we are updating favicons only for the _main_ frame. |
| 706 // Updating Favicon URLs at DidFinishLoad ensures that icon loads always get |
| 707 // initiated after all of the other page resources have been fetched, so icon |
| 708 // loads should not compete with page resources for network bandwidth. |
| 700 int icon_types = WebIconURL::TypeFavicon; | 709 int icon_types = WebIconURL::TypeFavicon; |
| 701 if (chrome::kEnableTouchIcon) | 710 if (chrome::kEnableTouchIcon) |
| 702 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; | 711 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 703 | 712 |
| 704 WebVector<WebIconURL> icon_urls = | 713 CollectAndUpdateFaviconURLs(frame, icon_types); |
| 705 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); | |
| 706 std::vector<FaviconURL> urls; | |
| 707 for (size_t i = 0; i < icon_urls.size(); i++) { | |
| 708 WebURL url = icon_urls[i].iconURL(); | |
| 709 if (!url.isEmpty()) | |
| 710 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); | |
| 711 } | |
| 712 if (!urls.empty()) { | |
| 713 Send(new IconHostMsg_UpdateFaviconURL( | |
| 714 routing_id(), render_view()->GetPageId(), urls)); | |
| 715 } | |
| 716 } | 714 } |
| 717 | 715 |
| 718 void ChromeRenderViewObserver::DidChangeIcon(WebFrame* frame, | 716 void ChromeRenderViewObserver::DidChangeIcon(WebFrame* frame, |
| 719 WebIconURL::Type icon_type) { | 717 WebIconURL::Type icon_type) { |
| 720 if (frame->parent()) | 718 if (frame->parent()) |
| 721 return; | 719 return; |
| 722 | 720 |
| 723 if (!chrome::kEnableTouchIcon && | 721 if (!chrome::kEnableTouchIcon && |
| 724 icon_type != WebIconURL::TypeFavicon) | 722 icon_type != WebIconURL::TypeFavicon) |
| 725 return; | 723 return; |
| 726 | 724 |
| 727 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | 725 CollectAndUpdateFaviconURLs(frame, icon_type); |
| 728 std::vector<FaviconURL> urls; | |
| 729 for (size_t i = 0; i < icon_urls.size(); i++) { | |
| 730 urls.push_back(FaviconURL(icon_urls[i].iconURL(), | |
| 731 ToFaviconType(icon_urls[i].iconType()))); | |
| 732 } | |
| 733 Send(new IconHostMsg_UpdateFaviconURL( | |
| 734 routing_id(), render_view()->GetPageId(), urls)); | |
| 735 } | 726 } |
| 736 | 727 |
| 737 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 728 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 738 WebFrame* frame, bool is_new_navigation) { | 729 WebFrame* frame, bool is_new_navigation) { |
| 739 if (!is_new_navigation) | 730 if (!is_new_navigation) |
| 740 return; | 731 return; |
| 741 | 732 |
| 742 CapturePageInfoLater( | 733 CapturePageInfoLater( |
| 743 true, // preliminary_capture | 734 true, // preliminary_capture |
| 744 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 735 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 webkit_glue::ImageDecoder decoder( | 1077 webkit_glue::ImageDecoder decoder( |
| 1087 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | 1078 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); |
| 1088 const unsigned char* src_data = | 1079 const unsigned char* src_data = |
| 1089 reinterpret_cast<const unsigned char*>(&data[0]); | 1080 reinterpret_cast<const unsigned char*>(&data[0]); |
| 1090 | 1081 |
| 1091 return decoder.Decode(src_data, data.size()); | 1082 return decoder.Decode(src_data, data.size()); |
| 1092 } | 1083 } |
| 1093 return SkBitmap(); | 1084 return SkBitmap(); |
| 1094 } | 1085 } |
| 1095 | 1086 |
| 1087 void ChromeRenderViewObserver::CollectAndUpdateFaviconURLs( |
| 1088 WebKit::WebFrame* frame, int icon_types) { |
| 1089 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_types); |
| 1090 std::vector<FaviconURL> urls; |
| 1091 for (size_t i = 0; i < icon_urls.size(); i++) { |
| 1092 WebURL url = icon_urls[i].iconURL(); |
| 1093 if (!url.isEmpty()) |
| 1094 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); |
| 1095 } |
| 1096 if (!urls.empty()) { |
| 1097 Send(new IconHostMsg_UpdateFaviconURL( |
| 1098 routing_id(), render_view()->GetPageId(), urls)); |
| 1099 } |
| 1100 } |
| 1101 |
| 1096 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 1102 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
| 1097 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 1103 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
| 1098 } | 1104 } |
| OLD | NEW |