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/utf_string_conversions.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/prerender_messages.h" | 16 #include "chrome/common/prerender_messages.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/renderer/chrome_render_process_observer.h" | 19 #include "chrome/renderer/chrome_render_process_observer.h" |
| 20 #include "chrome/renderer/content_settings_observer.h" | 20 #include "chrome/renderer/content_settings_observer.h" |
| 21 #include "chrome/renderer/extensions/dispatcher.h" | 21 #include "chrome/renderer/extensions/dispatcher.h" |
| 22 #include "chrome/renderer/external_host_bindings.h" | 22 #include "chrome/renderer/external_host_bindings.h" |
| 23 #include "chrome/renderer/frame_sniffer.h" | 23 #include "chrome/renderer/frame_sniffer.h" |
| 24 #include "chrome/renderer/prerender/prerender_helper.h" | 24 #include "chrome/renderer/prerender/prerender_helper.h" |
| 25 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 25 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 26 #include "chrome/renderer/translate/translate_helper.h" | 26 #include "chrome/renderer/translate/translate_helper.h" |
| 27 #include "chrome/renderer/webview_color_overlay.h" | 27 #include "chrome/renderer/webview_color_overlay.h" |
| 28 #include "content/public/common/bindings_policy.h" | 28 #include "content/public/common/bindings_policy.h" |
| 29 #include "content/public/renderer/content_renderer_client.h" | 29 #include "content/public/renderer/content_renderer_client.h" |
| 30 #include "content/public/renderer/render_view.h" | 30 #include "content/public/renderer/render_view.h" |
| 31 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
| 32 #include "net/base/data_url.h" | 32 #include "net/base/data_url.h" |
| 33 #include "skia/ext/platform_canvas.h" | 33 #include "skia/ext/platform_canvas.h" |
| 34 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 34 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
| 35 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 35 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 36 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 36 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 37 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 37 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 38 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 38 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
| 39 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 39 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
| 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec t.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | |
| 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 46 #include "ui/base/ui_base_switches.h" | 47 #include "ui/base/ui_base_switches.h" |
| 47 #include "ui/gfx/favicon_size.h" | 48 #include "ui/gfx/favicon_size.h" |
| 48 #include "ui/gfx/size.h" | 49 #include "ui/gfx/size.h" |
| 49 #include "ui/gfx/skbitmap_operations.h" | 50 #include "ui/gfx/skbitmap_operations.h" |
| 50 #include "v8/include/v8-testing.h" | 51 #include "v8/include/v8-testing.h" |
| 52 #include "webkit/glue/dom_operations.h" | |
| 51 #include "webkit/glue/image_decoder.h" | 53 #include "webkit/glue/image_decoder.h" |
| 52 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" | 54 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" |
| 53 #include "webkit/glue/webkit_glue.h" | 55 #include "webkit/glue/webkit_glue.h" |
| 54 | 56 |
| 55 using WebKit::WebAccessibilityObject; | 57 using WebKit::WebAccessibilityObject; |
| 56 using WebKit::WebCString; | 58 using WebKit::WebCString; |
| 57 using WebKit::WebDataSource; | 59 using WebKit::WebDataSource; |
| 58 using WebKit::WebDocument; | 60 using WebKit::WebDocument; |
| 61 using WebKit::WebElement; | |
| 59 using WebKit::WebFrame; | 62 using WebKit::WebFrame; |
| 60 using WebKit::WebGestureEvent; | 63 using WebKit::WebGestureEvent; |
| 61 using WebKit::WebIconURL; | 64 using WebKit::WebIconURL; |
| 62 using WebKit::WebRect; | 65 using WebKit::WebRect; |
| 63 using WebKit::WebSecurityOrigin; | 66 using WebKit::WebSecurityOrigin; |
| 64 using WebKit::WebSize; | 67 using WebKit::WebSize; |
| 65 using WebKit::WebString; | 68 using WebKit::WebString; |
| 66 using WebKit::WebTouchEvent; | 69 using WebKit::WebTouchEvent; |
| 67 using WebKit::WebURL; | 70 using WebKit::WebURL; |
| 68 using WebKit::WebURLRequest; | 71 using WebKit::WebURLRequest; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 capture_timer_(false, false) { | 187 capture_timer_(false, false) { |
| 185 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 188 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 186 render_view->GetWebView()->setPermissionClient(this); | 189 render_view->GetWebView()->setPermissionClient(this); |
| 187 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 190 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
| 188 OnSetClientSidePhishingDetection(true); | 191 OnSetClientSidePhishingDetection(true); |
| 189 } | 192 } |
| 190 | 193 |
| 191 ChromeRenderViewObserver::~ChromeRenderViewObserver() { | 194 ChromeRenderViewObserver::~ChromeRenderViewObserver() { |
| 192 } | 195 } |
| 193 | 196 |
| 197 // static | |
| 198 bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) { | |
|
jochen (gone - plz use gerrit)
2013/05/02 14:00:31
why is this static?
| |
| 199 if (!frame) | |
| 200 return false; | |
| 201 std::vector<WebElement> meta_elements; | |
| 202 WebDocument document = frame->document(); | |
| 203 webkit_glue::GetMetaElementsWithAttribute(&document, | |
| 204 ASCIIToUTF16("http-equiv"), | |
| 205 ASCIIToUTF16("refresh"), | |
| 206 &meta_elements); | |
| 207 return meta_elements.size() != 0; | |
| 208 } | |
| 209 | |
| 194 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 210 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
| 195 bool handled = true; | 211 bool handled = true; |
| 196 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 212 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
| 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 213 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
| 198 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, | 214 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, |
| 199 OnHandleMessageFromExternalHost) | 215 OnHandleMessageFromExternalHost) |
| 200 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, | 216 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, |
| 201 OnJavaScriptStressTestControl) | 217 OnJavaScriptStressTestControl) |
| 202 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, | 218 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, |
| 203 OnSetAllowDisplayingInsecureContent) | 219 OnSetAllowDisplayingInsecureContent) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 webui_javascript_.get()) { | 625 webui_javascript_.get()) { |
| 610 render_view()->EvaluateScript(webui_javascript_->frame_xpath, | 626 render_view()->EvaluateScript(webui_javascript_->frame_xpath, |
| 611 webui_javascript_->jscript, | 627 webui_javascript_->jscript, |
| 612 webui_javascript_->id, | 628 webui_javascript_->id, |
| 613 webui_javascript_->notify_result); | 629 webui_javascript_->notify_result); |
| 614 webui_javascript_.reset(); | 630 webui_javascript_.reset(); |
| 615 } | 631 } |
| 616 } | 632 } |
| 617 | 633 |
| 618 void ChromeRenderViewObserver::DidStopLoading() { | 634 void ChromeRenderViewObserver::DidStopLoading() { |
| 619 CapturePageInfoLater( | |
| 620 false, // preliminary_capture | |
| 621 base::TimeDelta::FromMilliseconds( | |
| 622 render_view()->GetContentStateImmediately() ? | |
| 623 0 : kDelayForCaptureMs)); | |
| 624 | |
| 625 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 635 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 626 GURL osd_url = main_frame->document().openSearchDescriptionURL(); | 636 GURL osd_url = main_frame->document().openSearchDescriptionURL(); |
| 627 if (!osd_url.is_empty()) { | 637 if (!osd_url.is_empty()) { |
| 628 Send(new ChromeViewHostMsg_PageHasOSDD( | 638 Send(new ChromeViewHostMsg_PageHasOSDD( |
| 629 routing_id(), render_view()->GetPageId(), osd_url, | 639 routing_id(), render_view()->GetPageId(), osd_url, |
| 630 search_provider::AUTODETECTED_PROVIDER)); | 640 search_provider::AUTODETECTED_PROVIDER)); |
| 631 } | 641 } |
| 642 | |
| 643 // Don't capture pages including refresh meta tag. | |
| 644 if(HasRefreshMetaTag(main_frame)) | |
| 645 return; | |
| 646 | |
| 647 CapturePageInfoLater( | |
| 648 render_view()->GetPageId(), | |
| 649 false, // preliminary_capture | |
| 650 base::TimeDelta::FromMilliseconds( | |
| 651 render_view()->GetContentStateImmediately() ? | |
| 652 0 : kDelayForCaptureMs)); | |
| 632 } | 653 } |
| 633 | 654 |
| 634 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 655 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 635 WebFrame* frame, bool is_new_navigation) { | 656 WebFrame* frame, bool is_new_navigation) { |
| 636 if (!is_new_navigation) | 657 // Don't capture pages being not new, or including refresh meta tag. |
| 658 if (!is_new_navigation || HasRefreshMetaTag(frame)) | |
| 637 return; | 659 return; |
| 638 | 660 |
| 639 CapturePageInfoLater( | 661 CapturePageInfoLater( |
| 662 render_view()->GetPageId(), | |
| 640 true, // preliminary_capture | 663 true, // preliminary_capture |
| 641 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 664 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
| 642 } | 665 } |
| 643 | 666 |
| 644 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { | 667 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { |
| 645 if (render_view()->GetEnabledBindings() & | 668 if (render_view()->GetEnabledBindings() & |
| 646 content::BINDINGS_POLICY_EXTERNAL_HOST) { | 669 content::BINDINGS_POLICY_EXTERNAL_HOST) { |
| 647 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); | 670 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); |
| 648 } | 671 } |
| 649 } | 672 } |
| 650 | 673 |
| 651 void ChromeRenderViewObserver::DidHandleGestureEvent( | 674 void ChromeRenderViewObserver::DidHandleGestureEvent( |
| 652 const WebGestureEvent& event) { | 675 const WebGestureEvent& event) { |
| 653 if (event.type != WebKit::WebGestureEvent::GestureTap) | 676 if (event.type != WebKit::WebGestureEvent::GestureTap) |
| 654 return; | 677 return; |
| 655 | 678 |
| 656 WebKit::WebTextInputType text_input_type = | 679 WebKit::WebTextInputType text_input_type = |
| 657 render_view()->GetWebView()->textInputType(); | 680 render_view()->GetWebView()->textInputType(); |
| 658 | 681 |
| 659 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( | 682 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( |
| 660 routing_id(), | 683 routing_id(), |
| 661 text_input_type != WebKit::WebTextInputTypeNone)); | 684 text_input_type != WebKit::WebTextInputTypeNone)); |
| 662 } | 685 } |
| 663 | 686 |
| 664 void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture, | 687 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id, |
| 688 bool preliminary_capture, | |
| 665 base::TimeDelta delay) { | 689 base::TimeDelta delay) { |
| 666 capture_timer_.Start( | 690 capture_timer_.Start( |
| 667 FROM_HERE, | 691 FROM_HERE, |
| 668 delay, | 692 delay, |
| 669 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, | 693 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, |
| 670 base::Unretained(this), | 694 base::Unretained(this), |
| 695 page_id, | |
| 671 preliminary_capture)); | 696 preliminary_capture)); |
| 672 } | 697 } |
| 673 | 698 |
| 674 void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { | 699 void ChromeRenderViewObserver::CapturePageInfo(int page_id, |
| 675 int page_id = render_view()->GetPageId(); | 700 bool preliminary_capture) { |
| 676 | |
| 677 if (!render_view()->GetWebView()) | 701 if (!render_view()->GetWebView()) |
| 678 return; | 702 return; |
| 679 | 703 |
| 680 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 704 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 681 if (!main_frame) | 705 if (!main_frame) |
| 682 return; | 706 return; |
| 683 | 707 |
| 684 // Don't index/capture pages that are in view source mode. | 708 // Don't index/capture pages that are in view source mode. |
| 685 if (main_frame->isViewSourceModeEnabled()) | 709 if (main_frame->isViewSourceModeEnabled()) |
| 686 return; | 710 return; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 if (!external_host_bindings_.get()) { | 812 if (!external_host_bindings_.get()) { |
| 789 external_host_bindings_.reset(new ExternalHostBindings( | 813 external_host_bindings_.reset(new ExternalHostBindings( |
| 790 render_view(), routing_id())); | 814 render_view(), routing_id())); |
| 791 } | 815 } |
| 792 return external_host_bindings_.get(); | 816 return external_host_bindings_.get(); |
| 793 } | 817 } |
| 794 | 818 |
| 795 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 819 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
| 796 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 820 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
| 797 } | 821 } |
| OLD | NEW |