Chromium Code Reviews| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/icon_messages.h" | 16 #include "chrome/common/favicon_url.h" |
| 17 #include "chrome/common/prerender_messages.h" | 17 #include "chrome/common/prerender_messages.h" |
| 18 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/renderer/chrome_render_process_observer.h" | 20 #include "chrome/renderer/chrome_render_process_observer.h" |
| 21 #include "chrome/renderer/content_settings_observer.h" | 21 #include "chrome/renderer/content_settings_observer.h" |
| 22 #include "chrome/renderer/extensions/dispatcher.h" | 22 #include "chrome/renderer/extensions/dispatcher.h" |
| 23 #include "chrome/renderer/external_host_bindings.h" | 23 #include "chrome/renderer/external_host_bindings.h" |
| 24 #include "chrome/renderer/favicon_helper.h" | |
| 24 #include "chrome/renderer/frame_sniffer.h" | 25 #include "chrome/renderer/frame_sniffer.h" |
| 25 #include "chrome/renderer/prerender/prerender_helper.h" | 26 #include "chrome/renderer/prerender/prerender_helper.h" |
| 26 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 27 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 27 #include "chrome/renderer/translate_helper.h" | 28 #include "chrome/renderer/translate_helper.h" |
| 28 #include "chrome/renderer/webview_color_overlay.h" | 29 #include "chrome/renderer/webview_color_overlay.h" |
| 29 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
| 30 #include "content/public/renderer/render_view.h" | 31 #include "content/public/renderer/render_view.h" |
| 31 #include "content/public/renderer/content_renderer_client.h" | 32 #include "content/public/renderer/content_renderer_client.h" |
| 32 #include "net/base/data_url.h" | 33 #include "net/base/data_url.h" |
| 33 #include "skia/ext/platform_canvas.h" | 34 #include "skia/ext/platform_canvas.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 replacements.ClearRef(); | 193 replacements.ClearRef(); |
| 193 return url.ReplaceComponents(replacements); | 194 return url.ReplaceComponents(replacements); |
| 194 } | 195 } |
| 195 } // namespace | 196 } // namespace |
| 196 | 197 |
| 197 ChromeRenderViewObserver::ChromeRenderViewObserver( | 198 ChromeRenderViewObserver::ChromeRenderViewObserver( |
| 198 content::RenderView* render_view, | 199 content::RenderView* render_view, |
| 199 ContentSettingsObserver* content_settings, | 200 ContentSettingsObserver* content_settings, |
| 200 ChromeRenderProcessObserver* chrome_render_process_observer, | 201 ChromeRenderProcessObserver* chrome_render_process_observer, |
| 201 extensions::Dispatcher* extension_dispatcher, | 202 extensions::Dispatcher* extension_dispatcher, |
| 202 TranslateHelper* translate_helper) | 203 TranslateHelper* translate_helper, |
| 204 FaviconHelper* favicon_helper) | |
| 203 : content::RenderViewObserver(render_view), | 205 : content::RenderViewObserver(render_view), |
| 204 chrome_render_process_observer_(chrome_render_process_observer), | 206 chrome_render_process_observer_(chrome_render_process_observer), |
| 205 extension_dispatcher_(extension_dispatcher), | 207 extension_dispatcher_(extension_dispatcher), |
| 206 content_settings_(content_settings), | 208 content_settings_(content_settings), |
| 207 translate_helper_(translate_helper), | 209 translate_helper_(translate_helper), |
| 208 phishing_classifier_(NULL), | 210 phishing_classifier_(NULL), |
| 211 favicon_helper_(favicon_helper), | |
| 209 last_indexed_page_id_(-1), | 212 last_indexed_page_id_(-1), |
| 210 allow_displaying_insecure_content_(false), | 213 allow_displaying_insecure_content_(false), |
| 211 allow_running_insecure_content_(false), | 214 allow_running_insecure_content_(false), |
| 212 capture_timer_(false, false) { | 215 capture_timer_(false, false) { |
| 213 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 216 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 214 render_view->GetWebView()->setPermissionClient(this); | 217 render_view->GetWebView()->setPermissionClient(this); |
| 215 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 218 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
| 216 OnSetClientSidePhishingDetection(true); | 219 OnSetClientSidePhishingDetection(true); |
| 217 } | 220 } |
| 218 | 221 |
| 219 ChromeRenderViewObserver::~ChromeRenderViewObserver() { | 222 ChromeRenderViewObserver::~ChromeRenderViewObserver() { |
| 220 } | 223 } |
| 221 | 224 |
| 222 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 225 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
| 223 bool handled = true; | 226 bool handled = true; |
| 224 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 227 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
| 225 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 228 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
| 226 IPC_MESSAGE_HANDLER(ChromeViewMsg_CaptureSnapshot, OnCaptureSnapshot) | 229 IPC_MESSAGE_HANDLER(ChromeViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
| 227 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, | 230 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, |
| 228 OnHandleMessageFromExternalHost) | 231 OnHandleMessageFromExternalHost) |
| 229 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, | 232 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, |
| 230 OnJavaScriptStressTestControl) | 233 OnJavaScriptStressTestControl) |
| 231 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon) | |
| 232 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, | 234 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, |
| 233 OnSetAllowDisplayingInsecureContent) | 235 OnSetAllowDisplayingInsecureContent) |
| 234 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, | 236 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, |
| 235 OnSetAllowRunningInsecureContent) | 237 OnSetAllowRunningInsecureContent) |
| 236 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 238 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
| 237 OnSetClientSidePhishingDetection) | 239 OnSetClientSidePhishingDetection) |
| 238 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, | 240 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized, |
| 239 OnSetVisuallyDeemphasized) | 241 OnSetVisuallyDeemphasized) |
| 240 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
| 241 IPC_MESSAGE_HANDLER(ChromeViewMsg_StartFrameSniffer, OnStartFrameSniffer) | 243 IPC_MESSAGE_HANDLER(ChromeViewMsg_StartFrameSniffer, OnStartFrameSniffer) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 | 298 |
| 297 void ChromeRenderViewObserver::OnJavaScriptStressTestControl(int cmd, | 299 void ChromeRenderViewObserver::OnJavaScriptStressTestControl(int cmd, |
| 298 int param) { | 300 int param) { |
| 299 if (cmd == kJavaScriptStressTestSetStressRunType) { | 301 if (cmd == kJavaScriptStressTestSetStressRunType) { |
| 300 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); | 302 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); |
| 301 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { | 303 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { |
| 302 v8::Testing::PrepareStressRun(param); | 304 v8::Testing::PrepareStressRun(param); |
| 303 } | 305 } |
| 304 } | 306 } |
| 305 | 307 |
| 306 void ChromeRenderViewObserver::OnDownloadFavicon(int id, | |
| 307 const GURL& image_url, | |
| 308 int image_size) { | |
| 309 bool data_image_failed = false; | |
| 310 if (image_url.SchemeIs("data")) { | |
| 311 SkBitmap data_image = ImageFromDataUrl(image_url); | |
| 312 data_image_failed = data_image.empty(); | |
| 313 if (!data_image_failed) { | |
| 314 std::vector<SkBitmap> images(1, data_image); | |
| 315 Send(new IconHostMsg_DidDownloadFavicon( | |
| 316 routing_id(), id, image_url, false, image_size, images)); | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 if (data_image_failed || | |
| 321 !DownloadFavicon(id, image_url, image_size)) { | |
| 322 Send(new IconHostMsg_DidDownloadFavicon( | |
| 323 routing_id(), id, image_url, true, image_size, | |
| 324 std::vector<SkBitmap>())); | |
| 325 } | |
| 326 } | |
| 327 | |
| 328 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) { | 308 void ChromeRenderViewObserver::OnSetAllowDisplayingInsecureContent(bool allow) { |
| 329 allow_displaying_insecure_content_ = allow; | 309 allow_displaying_insecure_content_ = allow; |
| 330 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 310 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 331 if (main_frame) | 311 if (main_frame) |
| 332 main_frame->reload(); | 312 main_frame->reload(); |
| 333 } | 313 } |
| 334 | 314 |
| 335 void ChromeRenderViewObserver::OnSetAllowRunningInsecureContent(bool allow) { | 315 void ChromeRenderViewObserver::OnSetAllowRunningInsecureContent(bool allow) { |
| 336 allow_running_insecure_content_ = allow; | 316 allow_running_insecure_content_ = allow; |
| 337 OnSetAllowDisplayingInsecureContent(allow); | 317 OnSetAllowDisplayingInsecureContent(allow); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; | 668 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch; |
| 689 | 669 |
| 690 WebVector<WebIconURL> icon_urls = | 670 WebVector<WebIconURL> icon_urls = |
| 691 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); | 671 render_view()->GetWebView()->mainFrame()->iconURLs(icon_types); |
| 692 std::vector<FaviconURL> urls; | 672 std::vector<FaviconURL> urls; |
| 693 for (size_t i = 0; i < icon_urls.size(); i++) { | 673 for (size_t i = 0; i < icon_urls.size(); i++) { |
| 694 WebURL url = icon_urls[i].iconURL(); | 674 WebURL url = icon_urls[i].iconURL(); |
| 695 if (!url.isEmpty()) | 675 if (!url.isEmpty()) |
| 696 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); | 676 urls.push_back(FaviconURL(url, ToFaviconType(icon_urls[i].iconType()))); |
| 697 } | 677 } |
| 698 if (!urls.empty()) { | 678 favicon_helper_->SendUpdateFaviconURL( |
| 699 Send(new IconHostMsg_UpdateFaviconURL( | 679 routing_id(), render_view()->GetPageId(), urls); |
|
joth
2012/10/30 14:41:45
rather than have this observer call into favicon o
Cait (Slow)
2012/10/30 20:07:33
Done.
| |
| 700 routing_id(), render_view()->GetPageId(), urls)); | |
| 701 } | |
| 702 } | 680 } |
| 703 | 681 |
| 704 void ChromeRenderViewObserver::DidChangeIcon(WebFrame* frame, | 682 void ChromeRenderViewObserver::DidChangeIcon(WebFrame* frame, |
| 705 WebIconURL::Type icon_type) { | 683 WebIconURL::Type icon_type) { |
| 706 if (frame->parent()) | 684 if (frame->parent()) |
| 707 return; | 685 return; |
| 708 | 686 |
| 709 if (!chrome::kEnableTouchIcon && | 687 if (!chrome::kEnableTouchIcon && |
| 710 icon_type != WebIconURL::TypeFavicon) | 688 icon_type != WebIconURL::TypeFavicon) |
| 711 return; | 689 return; |
| 712 | 690 |
| 713 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | 691 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 714 std::vector<FaviconURL> urls; | 692 std::vector<FaviconURL> urls; |
| 715 for (size_t i = 0; i < icon_urls.size(); i++) { | 693 for (size_t i = 0; i < icon_urls.size(); i++) { |
| 716 urls.push_back(FaviconURL(icon_urls[i].iconURL(), | 694 urls.push_back(FaviconURL(icon_urls[i].iconURL(), |
| 717 ToFaviconType(icon_urls[i].iconType()))); | 695 ToFaviconType(icon_urls[i].iconType()))); |
| 718 } | 696 } |
| 719 Send(new IconHostMsg_UpdateFaviconURL( | 697 favicon_helper_->SendUpdateFaviconURL( |
| 720 routing_id(), render_view()->GetPageId(), urls)); | 698 routing_id(), render_view()->GetPageId(), urls); |
|
joth
2012/10/30 14:41:45
likewise, this entire method (line 684 - 698) coul
Cait (Slow)
2012/10/30 20:07:33
Done.
| |
| 721 } | 699 } |
| 722 | 700 |
| 723 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 701 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 724 WebFrame* frame, bool is_new_navigation) { | 702 WebFrame* frame, bool is_new_navigation) { |
| 725 if (!is_new_navigation) | 703 if (!is_new_navigation) |
| 726 return; | 704 return; |
| 727 | 705 |
| 728 CapturePageInfoLater( | 706 CapturePageInfoLater( |
| 729 true, // preliminary_capture | 707 true, // preliminary_capture |
| 730 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 708 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 } | 884 } |
| 907 | 885 |
| 908 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { | 886 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { |
| 909 if (!external_host_bindings_.get()) { | 887 if (!external_host_bindings_.get()) { |
| 910 external_host_bindings_.reset(new ExternalHostBindings( | 888 external_host_bindings_.reset(new ExternalHostBindings( |
| 911 render_view(), routing_id())); | 889 render_view(), routing_id())); |
| 912 } | 890 } |
| 913 return external_host_bindings_.get(); | 891 return external_host_bindings_.get(); |
| 914 } | 892 } |
| 915 | 893 |
| 916 bool ChromeRenderViewObserver::DownloadFavicon(int id, | |
| 917 const GURL& image_url, | |
| 918 int image_size) { | |
| 919 // Make sure webview was not shut down. | |
| 920 if (!render_view()->GetWebView()) | |
| 921 return false; | |
| 922 // Create an image resource fetcher and assign it with a call back object. | |
| 923 image_fetchers_.push_back(linked_ptr<MultiResolutionImageResourceFetcher>( | |
| 924 new MultiResolutionImageResourceFetcher( | |
| 925 image_url, render_view()->GetWebView()->mainFrame(), id, | |
| 926 WebURLRequest::TargetIsFavicon, | |
| 927 base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon, | |
| 928 base::Unretained(this), image_size)))); | |
| 929 return true; | |
| 930 } | |
| 931 | |
| 932 void ChromeRenderViewObserver::DidDownloadFavicon( | |
| 933 int requested_size, | |
| 934 MultiResolutionImageResourceFetcher* fetcher, | |
| 935 const std::vector<SkBitmap>& images) { | |
| 936 // Notify requester of image download status. | |
| 937 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), | |
| 938 fetcher->id(), | |
| 939 fetcher->image_url(), | |
| 940 images.empty(), | |
| 941 requested_size, | |
| 942 images)); | |
| 943 | |
| 944 // Remove the image fetcher from our pending list. We're in the callback from | |
| 945 // MultiResolutionImageResourceFetcher, best to delay deletion. | |
| 946 ImageResourceFetcherList::iterator iter; | |
| 947 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { | |
| 948 if (iter->get() == fetcher) { | |
| 949 iter->release(); | |
| 950 image_fetchers_.erase(iter); | |
| 951 break; | |
| 952 } | |
| 953 } | |
| 954 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | |
| 955 } | |
| 956 | |
| 957 SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { | |
| 958 std::string mime_type, char_set, data; | |
| 959 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | |
| 960 // Decode the favicon using WebKit's image decoder. | |
| 961 webkit_glue::ImageDecoder decoder( | |
| 962 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | |
| 963 const unsigned char* src_data = | |
| 964 reinterpret_cast<const unsigned char*>(&data[0]); | |
| 965 | |
| 966 return decoder.Decode(src_data, data.size()); | |
| 967 } | |
| 968 return SkBitmap(); | |
| 969 } | |
| 970 | |
| 971 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 894 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
| 972 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 895 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
| 973 } | 896 } |
| OLD | NEW |