Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 14769004: Translate: infobars should not appear when a page has a refresh meta tag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase fix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
51 #include "webkit/glue/image_decoder.h" 54 #include "webkit/glue/image_decoder.h"
52 #include "webkit/glue/webkit_glue.h" 55 #include "webkit/glue/webkit_glue.h"
53 56
54 using WebKit::WebAccessibilityObject; 57 using WebKit::WebAccessibilityObject;
55 using WebKit::WebCString; 58 using WebKit::WebCString;
56 using WebKit::WebDataSource; 59 using WebKit::WebDataSource;
57 using WebKit::WebDocument; 60 using WebKit::WebDocument;
61 using WebKit::WebElement;
58 using WebKit::WebFrame; 62 using WebKit::WebFrame;
59 using WebKit::WebGestureEvent; 63 using WebKit::WebGestureEvent;
60 using WebKit::WebIconURL; 64 using WebKit::WebIconURL;
65 using WebKit::WebNode;
66 using WebKit::WebNodeList;
61 using WebKit::WebRect; 67 using WebKit::WebRect;
62 using WebKit::WebSecurityOrigin; 68 using WebKit::WebSecurityOrigin;
63 using WebKit::WebSize; 69 using WebKit::WebSize;
64 using WebKit::WebString; 70 using WebKit::WebString;
65 using WebKit::WebTouchEvent; 71 using WebKit::WebTouchEvent;
66 using WebKit::WebURL; 72 using WebKit::WebURL;
67 using WebKit::WebURLRequest; 73 using WebKit::WebURLRequest;
68 using WebKit::WebView; 74 using WebKit::WebView;
69 using WebKit::WebVector; 75 using WebKit::WebVector;
70 using extensions::APIPermission; 76 using extensions::APIPermission;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 421
416 bool ChromeRenderViewObserver::allowWriteToClipboard(WebFrame* frame, 422 bool ChromeRenderViewObserver::allowWriteToClipboard(WebFrame* frame,
417 bool default_value) { 423 bool default_value) {
418 bool allowed = false; 424 bool allowed = false;
419 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( 425 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite(
420 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()), 426 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()),
421 &allowed)); 427 &allowed));
422 return allowed; 428 return allowed;
423 } 429 }
424 430
425 const extensions::Extension* ChromeRenderViewObserver::GetExtension(
426 const WebSecurityOrigin& origin) const {
427 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
428 return NULL;
429
430 const std::string extension_id = origin.host().utf8().data();
431 if (!extension_dispatcher_->IsExtensionActive(extension_id))
432 return NULL;
433
434 return extension_dispatcher_->extensions()->GetByID(extension_id);
435 }
436
437 bool ChromeRenderViewObserver::allowWebComponents(const WebDocument& document, 431 bool ChromeRenderViewObserver::allowWebComponents(const WebDocument& document,
438 bool defaultValue) { 432 bool defaultValue) {
439 if (defaultValue) 433 if (defaultValue)
440 return true; 434 return true;
441 435
442 WebSecurityOrigin origin = document.securityOrigin(); 436 WebSecurityOrigin origin = document.securityOrigin();
443 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) 437 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
444 return true; 438 return true;
445 439
446 if (const extensions::Extension* extension = GetExtension(origin)) { 440 if (const extensions::Extension* extension = GetExtension(origin)) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 webui_javascript_.get()) { 622 webui_javascript_.get()) {
629 render_view()->EvaluateScript(webui_javascript_->frame_xpath, 623 render_view()->EvaluateScript(webui_javascript_->frame_xpath,
630 webui_javascript_->jscript, 624 webui_javascript_->jscript,
631 webui_javascript_->id, 625 webui_javascript_->id,
632 webui_javascript_->notify_result); 626 webui_javascript_->notify_result);
633 webui_javascript_.reset(); 627 webui_javascript_.reset();
634 } 628 }
635 } 629 }
636 630
637 void ChromeRenderViewObserver::DidStopLoading() { 631 void ChromeRenderViewObserver::DidStopLoading() {
638 CapturePageInfoLater(
639 false, // preliminary_capture
640 base::TimeDelta::FromMilliseconds(
641 render_view()->GetContentStateImmediately() ?
642 0 : kDelayForCaptureMs));
643
644 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 632 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
645 GURL osd_url = main_frame->document().openSearchDescriptionURL(); 633 GURL osd_url = main_frame->document().openSearchDescriptionURL();
646 if (!osd_url.is_empty()) { 634 if (!osd_url.is_empty()) {
647 Send(new ChromeViewHostMsg_PageHasOSDD( 635 Send(new ChromeViewHostMsg_PageHasOSDD(
648 routing_id(), render_view()->GetPageId(), osd_url, 636 routing_id(), render_view()->GetPageId(), osd_url,
649 search_provider::AUTODETECTED_PROVIDER)); 637 search_provider::AUTODETECTED_PROVIDER));
650 } 638 }
639
640 // Don't capture pages including refresh meta tag.
641 if (HasRefreshMetaTag(main_frame))
642 return;
643
644 CapturePageInfoLater(
645 render_view()->GetPageId(),
646 false, // preliminary_capture
647 base::TimeDelta::FromMilliseconds(
648 render_view()->GetContentStateImmediately() ?
649 0 : kDelayForCaptureMs));
651 } 650 }
652 651
653 void ChromeRenderViewObserver::DidCommitProvisionalLoad( 652 void ChromeRenderViewObserver::DidCommitProvisionalLoad(
654 WebFrame* frame, bool is_new_navigation) { 653 WebFrame* frame, bool is_new_navigation) {
655 if (!is_new_navigation) 654 // Don't capture pages being not new, or including refresh meta tag.
655 if (!is_new_navigation || HasRefreshMetaTag(frame))
656 return; 656 return;
657 657
658 CapturePageInfoLater( 658 CapturePageInfoLater(
659 render_view()->GetPageId(),
659 true, // preliminary_capture 660 true, // preliminary_capture
660 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); 661 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs));
661 } 662 }
662 663
663 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { 664 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) {
664 if (render_view()->GetEnabledBindings() & 665 if (render_view()->GetEnabledBindings() &
665 content::BINDINGS_POLICY_EXTERNAL_HOST) { 666 content::BINDINGS_POLICY_EXTERNAL_HOST) {
666 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); 667 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
667 } 668 }
668 } 669 }
669 670
670 void ChromeRenderViewObserver::DidHandleGestureEvent( 671 void ChromeRenderViewObserver::DidHandleGestureEvent(
671 const WebGestureEvent& event) { 672 const WebGestureEvent& event) {
672 if (event.type != WebKit::WebGestureEvent::GestureTap) 673 if (event.type != WebKit::WebGestureEvent::GestureTap)
673 return; 674 return;
674 675
675 WebKit::WebTextInputType text_input_type = 676 WebKit::WebTextInputType text_input_type =
676 render_view()->GetWebView()->textInputType(); 677 render_view()->GetWebView()->textInputType();
677 678
678 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( 679 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched(
679 routing_id(), 680 routing_id(),
680 text_input_type != WebKit::WebTextInputTypeNone)); 681 text_input_type != WebKit::WebTextInputTypeNone));
681 } 682 }
682 683
683 void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture, 684 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id,
685 bool preliminary_capture,
684 base::TimeDelta delay) { 686 base::TimeDelta delay) {
685 capture_timer_.Start( 687 capture_timer_.Start(
686 FROM_HERE, 688 FROM_HERE,
687 delay, 689 delay,
688 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, 690 base::Bind(&ChromeRenderViewObserver::CapturePageInfo,
689 base::Unretained(this), 691 base::Unretained(this),
692 page_id,
690 preliminary_capture)); 693 preliminary_capture));
691 } 694 }
692 695
693 void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { 696 void ChromeRenderViewObserver::CapturePageInfo(int page_id,
694 int page_id = render_view()->GetPageId(); 697 bool preliminary_capture) {
698 // If |page_id| is obsolete, we should stop indexing and capturing a page.
699 if (render_view()->GetPageId() != page_id)
700 return;
695 701
696 if (!render_view()->GetWebView()) 702 if (!render_view()->GetWebView())
697 return; 703 return;
698 704
699 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 705 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
700 if (!main_frame) 706 if (!main_frame)
701 return; 707 return;
702 708
703 // Don't index/capture pages that are in view source mode. 709 // Don't index/capture pages that are in view source mode.
704 if (main_frame->isViewSourceModeEnabled()) 710 if (main_frame->isViewSourceModeEnabled())
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (!external_host_bindings_.get()) { 813 if (!external_host_bindings_.get()) {
808 external_host_bindings_.reset(new ExternalHostBindings( 814 external_host_bindings_.reset(new ExternalHostBindings(
809 render_view(), routing_id())); 815 render_view(), routing_id()));
810 } 816 }
811 return external_host_bindings_.get(); 817 return external_host_bindings_.get();
812 } 818 }
813 819
814 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { 820 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) {
815 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); 821 return (strict_security_hosts_.find(host) != strict_security_hosts_.end());
816 } 822 }
823
824 const extensions::Extension* ChromeRenderViewObserver::GetExtension(
825 const WebSecurityOrigin& origin) const {
826 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
827 return NULL;
828
829 const std::string extension_id = origin.host().utf8().data();
830 if (!extension_dispatcher_->IsExtensionActive(extension_id))
831 return NULL;
832
833 return extension_dispatcher_->extensions()->GetByID(extension_id);
834 }
835
836 bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) {
837 if (!frame)
838 return false;
839 WebElement head = frame->document().head();
840 if (head.isNull() || !head.hasChildNodes())
841 return false;
842
843 const WebString tag_name(ASCIIToUTF16("meta"));
844 const WebString attribute_name(ASCIIToUTF16("http-equiv"));
845 const WebString attribute_value(ASCIIToUTF16("refresh"));
846
847 WebNodeList children = head.childNodes();
848 for (size_t i = 0; i < children.length(); ++i) {
849 WebNode node = children.item(i);
850 if (!node.isElementNode())
851 continue;
852 WebElement element = node.to<WebElement>();
853 if (!element.hasTagName(tag_name))
854 continue;
855 WebString value = element.getAttribute(attribute_name);
856 if (value.isNull() || value != attribute_value)
857 continue;
858 return true;
859 }
860 return false;
861 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.h ('k') | chrome/test/data/translate/refresh_meta_tag.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698