| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 411 |
| 405 bool ChromeRenderViewObserver::allowWriteToClipboard(WebFrame* frame, | 412 bool ChromeRenderViewObserver::allowWriteToClipboard(WebFrame* frame, |
| 406 bool default_value) { | 413 bool default_value) { |
| 407 bool allowed = false; | 414 bool allowed = false; |
| 408 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( | 415 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( |
| 409 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()), | 416 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()), |
| 410 &allowed)); | 417 &allowed)); |
| 411 return allowed; | 418 return allowed; |
| 412 } | 419 } |
| 413 | 420 |
| 414 const extensions::Extension* ChromeRenderViewObserver::GetExtension( | |
| 415 const WebSecurityOrigin& origin) const { | |
| 416 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | |
| 417 return NULL; | |
| 418 | |
| 419 const std::string extension_id = origin.host().utf8().data(); | |
| 420 if (!extension_dispatcher_->IsExtensionActive(extension_id)) | |
| 421 return NULL; | |
| 422 | |
| 423 return extension_dispatcher_->extensions()->GetByID(extension_id); | |
| 424 } | |
| 425 | |
| 426 bool ChromeRenderViewObserver::allowWebComponents(const WebDocument& document, | 421 bool ChromeRenderViewObserver::allowWebComponents(const WebDocument& document, |
| 427 bool defaultValue) { | 422 bool defaultValue) { |
| 428 if (defaultValue) | 423 if (defaultValue) |
| 429 return true; | 424 return true; |
| 430 | 425 |
| 431 WebSecurityOrigin origin = document.securityOrigin(); | 426 WebSecurityOrigin origin = document.securityOrigin(); |
| 432 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) | 427 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 433 return true; | 428 return true; |
| 434 | 429 |
| 435 if (const extensions::Extension* extension = GetExtension(origin)) { | 430 if (const extensions::Extension* extension = GetExtension(origin)) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 webui_javascript_.get()) { | 612 webui_javascript_.get()) { |
| 618 render_view()->EvaluateScript(webui_javascript_->frame_xpath, | 613 render_view()->EvaluateScript(webui_javascript_->frame_xpath, |
| 619 webui_javascript_->jscript, | 614 webui_javascript_->jscript, |
| 620 webui_javascript_->id, | 615 webui_javascript_->id, |
| 621 webui_javascript_->notify_result); | 616 webui_javascript_->notify_result); |
| 622 webui_javascript_.reset(); | 617 webui_javascript_.reset(); |
| 623 } | 618 } |
| 624 } | 619 } |
| 625 | 620 |
| 626 void ChromeRenderViewObserver::DidStopLoading() { | 621 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(); | 622 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 634 GURL osd_url = main_frame->document().openSearchDescriptionURL(); | 623 GURL osd_url = main_frame->document().openSearchDescriptionURL(); |
| 635 if (!osd_url.is_empty()) { | 624 if (!osd_url.is_empty()) { |
| 636 Send(new ChromeViewHostMsg_PageHasOSDD( | 625 Send(new ChromeViewHostMsg_PageHasOSDD( |
| 637 routing_id(), render_view()->GetPageId(), osd_url, | 626 routing_id(), render_view()->GetPageId(), osd_url, |
| 638 search_provider::AUTODETECTED_PROVIDER)); | 627 search_provider::AUTODETECTED_PROVIDER)); |
| 639 } | 628 } |
| 629 |
| 630 // Don't capture pages including refresh meta tag. |
| 631 if (HasRefreshMetaTag(main_frame)) |
| 632 return; |
| 633 |
| 634 CapturePageInfoLater( |
| 635 render_view()->GetPageId(), |
| 636 false, // preliminary_capture |
| 637 base::TimeDelta::FromMilliseconds( |
| 638 render_view()->GetContentStateImmediately() ? |
| 639 0 : kDelayForCaptureMs)); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 642 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 643 WebFrame* frame, bool is_new_navigation) { | 643 WebFrame* frame, bool is_new_navigation) { |
| 644 if (!is_new_navigation) | 644 // Don't capture pages being not new, or including refresh meta tag. |
| 645 if (!is_new_navigation || HasRefreshMetaTag(frame)) |
| 645 return; | 646 return; |
| 646 | 647 |
| 647 CapturePageInfoLater( | 648 CapturePageInfoLater( |
| 649 render_view()->GetPageId(), |
| 648 true, // preliminary_capture | 650 true, // preliminary_capture |
| 649 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 651 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
| 650 } | 652 } |
| 651 | 653 |
| 652 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { | 654 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { |
| 653 if (render_view()->GetEnabledBindings() & | 655 if (render_view()->GetEnabledBindings() & |
| 654 content::BINDINGS_POLICY_EXTERNAL_HOST) { | 656 content::BINDINGS_POLICY_EXTERNAL_HOST) { |
| 655 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); | 657 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); |
| 656 } | 658 } |
| 657 } | 659 } |
| 658 | 660 |
| 659 void ChromeRenderViewObserver::DidHandleGestureEvent( | 661 void ChromeRenderViewObserver::DidHandleGestureEvent( |
| 660 const WebGestureEvent& event) { | 662 const WebGestureEvent& event) { |
| 661 if (event.type != WebKit::WebGestureEvent::GestureTap) | 663 if (event.type != WebKit::WebGestureEvent::GestureTap) |
| 662 return; | 664 return; |
| 663 | 665 |
| 664 WebKit::WebTextInputType text_input_type = | 666 WebKit::WebTextInputType text_input_type = |
| 665 render_view()->GetWebView()->textInputType(); | 667 render_view()->GetWebView()->textInputType(); |
| 666 | 668 |
| 667 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( | 669 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( |
| 668 routing_id(), | 670 routing_id(), |
| 669 text_input_type != WebKit::WebTextInputTypeNone)); | 671 text_input_type != WebKit::WebTextInputTypeNone)); |
| 670 } | 672 } |
| 671 | 673 |
| 672 void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture, | 674 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id, |
| 675 bool preliminary_capture, |
| 673 base::TimeDelta delay) { | 676 base::TimeDelta delay) { |
| 674 capture_timer_.Start( | 677 capture_timer_.Start( |
| 675 FROM_HERE, | 678 FROM_HERE, |
| 676 delay, | 679 delay, |
| 677 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, | 680 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, |
| 678 base::Unretained(this), | 681 base::Unretained(this), |
| 682 page_id, |
| 679 preliminary_capture)); | 683 preliminary_capture)); |
| 680 } | 684 } |
| 681 | 685 |
| 682 void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { | 686 void ChromeRenderViewObserver::CapturePageInfo(int page_id, |
| 683 int page_id = render_view()->GetPageId(); | 687 bool preliminary_capture) { |
| 688 // If |page_id| is obsolete, we should stop indexing and capturing a page. |
| 689 if (render_view()->GetPageId() != page_id) |
| 690 return; |
| 684 | 691 |
| 685 if (!render_view()->GetWebView()) | 692 if (!render_view()->GetWebView()) |
| 686 return; | 693 return; |
| 687 | 694 |
| 688 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 695 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 689 if (!main_frame) | 696 if (!main_frame) |
| 690 return; | 697 return; |
| 691 | 698 |
| 692 // Don't index/capture pages that are in view source mode. | 699 // Don't index/capture pages that are in view source mode. |
| 693 if (main_frame->isViewSourceModeEnabled()) | 700 if (main_frame->isViewSourceModeEnabled()) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 if (!external_host_bindings_.get()) { | 803 if (!external_host_bindings_.get()) { |
| 797 external_host_bindings_.reset(new ExternalHostBindings( | 804 external_host_bindings_.reset(new ExternalHostBindings( |
| 798 render_view(), routing_id())); | 805 render_view(), routing_id())); |
| 799 } | 806 } |
| 800 return external_host_bindings_.get(); | 807 return external_host_bindings_.get(); |
| 801 } | 808 } |
| 802 | 809 |
| 803 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 810 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
| 804 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 811 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
| 805 } | 812 } |
| 813 |
| 814 const extensions::Extension* ChromeRenderViewObserver::GetExtension( |
| 815 const WebSecurityOrigin& origin) const { |
| 816 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
| 817 return NULL; |
| 818 |
| 819 const std::string extension_id = origin.host().utf8().data(); |
| 820 if (!extension_dispatcher_->IsExtensionActive(extension_id)) |
| 821 return NULL; |
| 822 |
| 823 return extension_dispatcher_->extensions()->GetByID(extension_id); |
| 824 } |
| 825 |
| 826 bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) { |
| 827 if (!frame) |
| 828 return false; |
| 829 WebElement head = frame->document().head(); |
| 830 if (head.isNull() || !head.hasChildNodes()) |
| 831 return false; |
| 832 |
| 833 const WebString tag_name(ASCIIToUTF16("meta")); |
| 834 const WebString attribute_name(ASCIIToUTF16("http-equiv")); |
| 835 const WebString attribute_value(ASCIIToUTF16("refresh")); |
| 836 |
| 837 WebNodeList children = head.childNodes(); |
| 838 for (size_t i = 0; i < children.length(); ++i) { |
| 839 WebNode node = children.item(i); |
| 840 if (!node.isElementNode()) |
| 841 continue; |
| 842 WebElement element = node.to<WebElement>(); |
| 843 if (!element.hasTagName(tag_name)) |
| 844 continue; |
| 845 WebString value = element.getAttribute(attribute_name); |
| 846 if (value.isNull() || value != attribute_value) |
| 847 continue; |
| 848 return true; |
| 849 } |
| 850 return false; |
| 851 } |
| OLD | NEW |