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" |
| 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" | |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 46 #include "ui/base/ui_base_switches_util.h" | 49 #include "ui/base/ui_base_switches_util.h" |
| 47 #include "ui/gfx/favicon_size.h" | 50 #include "ui/gfx/favicon_size.h" |
| 48 #include "ui/gfx/size.h" | 51 #include "ui/gfx/size.h" |
| 49 #include "ui/gfx/skbitmap_operations.h" | 52 #include "ui/gfx/skbitmap_operations.h" |
| 50 #include "v8/include/v8-testing.h" | 53 #include "v8/include/v8-testing.h" |
| 54 #include "webkit/glue/dom_operations.h" | |
| 51 #include "webkit/glue/image_decoder.h" | 55 #include "webkit/glue/image_decoder.h" |
| 52 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" | 56 #include "webkit/glue/multi_resolution_image_resource_fetcher.h" |
| 53 #include "webkit/glue/webkit_glue.h" | 57 #include "webkit/glue/webkit_glue.h" |
| 54 | 58 |
| 55 using WebKit::WebAccessibilityObject; | 59 using WebKit::WebAccessibilityObject; |
| 56 using WebKit::WebCString; | 60 using WebKit::WebCString; |
| 57 using WebKit::WebDataSource; | 61 using WebKit::WebDataSource; |
| 58 using WebKit::WebDocument; | 62 using WebKit::WebDocument; |
| 63 using WebKit::WebElement; | |
| 59 using WebKit::WebFrame; | 64 using WebKit::WebFrame; |
| 60 using WebKit::WebGestureEvent; | 65 using WebKit::WebGestureEvent; |
| 61 using WebKit::WebIconURL; | 66 using WebKit::WebIconURL; |
| 67 using WebKit::WebNode; | |
| 68 using WebKit::WebNodeList; | |
| 62 using WebKit::WebRect; | 69 using WebKit::WebRect; |
| 63 using WebKit::WebSecurityOrigin; | 70 using WebKit::WebSecurityOrigin; |
| 64 using WebKit::WebSize; | 71 using WebKit::WebSize; |
| 65 using WebKit::WebString; | 72 using WebKit::WebString; |
| 66 using WebKit::WebTouchEvent; | 73 using WebKit::WebTouchEvent; |
| 67 using WebKit::WebURL; | 74 using WebKit::WebURL; |
| 68 using WebKit::WebURLRequest; | 75 using WebKit::WebURLRequest; |
| 69 using WebKit::WebView; | 76 using WebKit::WebView; |
| 70 using WebKit::WebVector; | 77 using WebKit::WebVector; |
| 71 using extensions::APIPermission; | 78 using extensions::APIPermission; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 capture_timer_(false, false) { | 191 capture_timer_(false, false) { |
| 185 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 192 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 186 render_view->GetWebView()->setPermissionClient(this); | 193 render_view->GetWebView()->setPermissionClient(this); |
| 187 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) | 194 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) |
| 188 OnSetClientSidePhishingDetection(true); | 195 OnSetClientSidePhishingDetection(true); |
| 189 } | 196 } |
| 190 | 197 |
| 191 ChromeRenderViewObserver::~ChromeRenderViewObserver() { | 198 ChromeRenderViewObserver::~ChromeRenderViewObserver() { |
| 192 } | 199 } |
| 193 | 200 |
| 201 // static | |
| 202 bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) { | |
| 203 if (!frame) | |
| 204 return false; | |
|
Takashi Toyoshima
2013/05/14 14:38:29
webkit_glue::GetMetaElementsWithAttribute is remov
| |
| 205 WebElement head = frame->document().head(); | |
| 206 if (head.isNull() || !head.hasChildNodes()) | |
| 207 return false; | |
| 208 | |
| 209 const WebString tag_name(ASCIIToUTF16("meta")); | |
| 210 const WebString attribute_name(ASCIIToUTF16("http-equiv")); | |
| 211 const WebString attribute_value(ASCIIToUTF16("refresh")); | |
| 212 | |
| 213 WebNodeList children = head.childNodes(); | |
| 214 for (size_t i = 0; i < children.length(); ++i) { | |
| 215 WebNode node = children.item(i); | |
| 216 if (!node.isElementNode()) | |
| 217 continue; | |
| 218 WebElement element = node.to<WebElement>(); | |
| 219 if (!element.hasTagName(tag_name)) | |
| 220 continue; | |
| 221 WebString value = element.getAttribute(attribute_name); | |
| 222 if (value.isNull() || value != attribute_value) | |
| 223 continue; | |
| 224 return true; | |
| 225 } | |
| 226 return false; | |
| 227 } | |
| 228 | |
| 194 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 229 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
| 195 bool handled = true; | 230 bool handled = true; |
| 196 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 231 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
| 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 232 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
| 198 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, | 233 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, |
| 199 OnHandleMessageFromExternalHost) | 234 OnHandleMessageFromExternalHost) |
| 200 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, | 235 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, |
| 201 OnJavaScriptStressTestControl) | 236 OnJavaScriptStressTestControl) |
| 202 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, | 237 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, |
| 203 OnSetAllowDisplayingInsecureContent) | 238 OnSetAllowDisplayingInsecureContent) |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 webui_javascript_.get()) { | 652 webui_javascript_.get()) { |
| 618 render_view()->EvaluateScript(webui_javascript_->frame_xpath, | 653 render_view()->EvaluateScript(webui_javascript_->frame_xpath, |
| 619 webui_javascript_->jscript, | 654 webui_javascript_->jscript, |
| 620 webui_javascript_->id, | 655 webui_javascript_->id, |
| 621 webui_javascript_->notify_result); | 656 webui_javascript_->notify_result); |
| 622 webui_javascript_.reset(); | 657 webui_javascript_.reset(); |
| 623 } | 658 } |
| 624 } | 659 } |
| 625 | 660 |
| 626 void ChromeRenderViewObserver::DidStopLoading() { | 661 void ChromeRenderViewObserver::DidStopLoading() { |
| 627 CapturePageInfoLater( | |
| 628 false, // preliminary_capture | |
| 629 base::TimeDelta::FromMilliseconds( | |
| 630 render_view()->GetContentStateImmediately() ? | |
| 631 0 : kDelayForCaptureMs)); | |
| 632 | |
| 633 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 662 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 634 GURL osd_url = main_frame->document().openSearchDescriptionURL(); | 663 GURL osd_url = main_frame->document().openSearchDescriptionURL(); |
| 635 if (!osd_url.is_empty()) { | 664 if (!osd_url.is_empty()) { |
| 636 Send(new ChromeViewHostMsg_PageHasOSDD( | 665 Send(new ChromeViewHostMsg_PageHasOSDD( |
| 637 routing_id(), render_view()->GetPageId(), osd_url, | 666 routing_id(), render_view()->GetPageId(), osd_url, |
| 638 search_provider::AUTODETECTED_PROVIDER)); | 667 search_provider::AUTODETECTED_PROVIDER)); |
| 639 } | 668 } |
| 669 | |
| 670 // Don't capture pages including refresh meta tag. | |
| 671 if (HasRefreshMetaTag(main_frame)) | |
| 672 return; | |
| 673 | |
| 674 CapturePageInfoLater( | |
| 675 render_view()->GetPageId(), | |
| 676 false, // preliminary_capture | |
| 677 base::TimeDelta::FromMilliseconds( | |
| 678 render_view()->GetContentStateImmediately() ? | |
| 679 0 : kDelayForCaptureMs)); | |
| 640 } | 680 } |
| 641 | 681 |
| 642 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 682 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 643 WebFrame* frame, bool is_new_navigation) { | 683 WebFrame* frame, bool is_new_navigation) { |
| 644 if (!is_new_navigation) | 684 // Don't capture pages being not new, or including refresh meta tag. |
| 685 if (!is_new_navigation || HasRefreshMetaTag(frame)) | |
| 645 return; | 686 return; |
| 646 | 687 |
| 647 CapturePageInfoLater( | 688 CapturePageInfoLater( |
| 689 render_view()->GetPageId(), | |
| 648 true, // preliminary_capture | 690 true, // preliminary_capture |
| 649 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 691 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
| 650 } | 692 } |
| 651 | 693 |
| 652 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { | 694 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { |
| 653 if (render_view()->GetEnabledBindings() & | 695 if (render_view()->GetEnabledBindings() & |
| 654 content::BINDINGS_POLICY_EXTERNAL_HOST) { | 696 content::BINDINGS_POLICY_EXTERNAL_HOST) { |
| 655 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); | 697 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); |
| 656 } | 698 } |
| 657 } | 699 } |
| 658 | 700 |
| 659 void ChromeRenderViewObserver::DidHandleGestureEvent( | 701 void ChromeRenderViewObserver::DidHandleGestureEvent( |
| 660 const WebGestureEvent& event) { | 702 const WebGestureEvent& event) { |
| 661 if (event.type != WebKit::WebGestureEvent::GestureTap) | 703 if (event.type != WebKit::WebGestureEvent::GestureTap) |
| 662 return; | 704 return; |
| 663 | 705 |
| 664 WebKit::WebTextInputType text_input_type = | 706 WebKit::WebTextInputType text_input_type = |
| 665 render_view()->GetWebView()->textInputType(); | 707 render_view()->GetWebView()->textInputType(); |
| 666 | 708 |
| 667 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( | 709 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( |
| 668 routing_id(), | 710 routing_id(), |
| 669 text_input_type != WebKit::WebTextInputTypeNone)); | 711 text_input_type != WebKit::WebTextInputTypeNone)); |
| 670 } | 712 } |
| 671 | 713 |
| 672 void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture, | 714 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id, |
| 715 bool preliminary_capture, | |
| 673 base::TimeDelta delay) { | 716 base::TimeDelta delay) { |
| 674 capture_timer_.Start( | 717 capture_timer_.Start( |
| 675 FROM_HERE, | 718 FROM_HERE, |
| 676 delay, | 719 delay, |
| 677 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, | 720 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, |
| 678 base::Unretained(this), | 721 base::Unretained(this), |
| 722 page_id, | |
| 679 preliminary_capture)); | 723 preliminary_capture)); |
| 680 } | 724 } |
| 681 | 725 |
| 682 void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { | 726 void ChromeRenderViewObserver::CapturePageInfo(int page_id, |
| 683 int page_id = render_view()->GetPageId(); | 727 bool preliminary_capture) { |
| 728 // If |page_id| is obsolete, we should stop indexing and capturing a page. | |
| 729 if (render_view()->GetPageId() != page_id) | |
| 730 return; | |
| 684 | 731 |
| 685 if (!render_view()->GetWebView()) | 732 if (!render_view()->GetWebView()) |
| 686 return; | 733 return; |
| 687 | 734 |
| 688 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 735 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 689 if (!main_frame) | 736 if (!main_frame) |
| 690 return; | 737 return; |
| 691 | 738 |
| 692 // Don't index/capture pages that are in view source mode. | 739 // Don't index/capture pages that are in view source mode. |
| 693 if (main_frame->isViewSourceModeEnabled()) | 740 if (main_frame->isViewSourceModeEnabled()) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 if (!external_host_bindings_.get()) { | 843 if (!external_host_bindings_.get()) { |
| 797 external_host_bindings_.reset(new ExternalHostBindings( | 844 external_host_bindings_.reset(new ExternalHostBindings( |
| 798 render_view(), routing_id())); | 845 render_view(), routing_id())); |
| 799 } | 846 } |
| 800 return external_host_bindings_.get(); | 847 return external_host_bindings_.get(); |
| 801 } | 848 } |
| 802 | 849 |
| 803 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 850 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
| 804 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 851 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
| 805 } | 852 } |
| OLD | NEW |