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

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: 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
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 capture_timer_(false, false) { 186 capture_timer_(false, false) {
184 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 187 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
185 render_view->GetWebView()->setPermissionClient(this); 188 render_view->GetWebView()->setPermissionClient(this);
186 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection)) 189 if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
187 OnSetClientSidePhishingDetection(true); 190 OnSetClientSidePhishingDetection(true);
188 } 191 }
189 192
190 ChromeRenderViewObserver::~ChromeRenderViewObserver() { 193 ChromeRenderViewObserver::~ChromeRenderViewObserver() {
191 } 194 }
192 195
196 // static
197 bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) {
198 if (!frame)
199 return false;
200 std::vector<WebElement> meta_elements;
201 WebDocument document = frame->document();
202 webkit_glue::GetMetaElementsWithAttribute(&document,
203 ASCIIToUTF16("http-equiv"),
204 ASCIIToUTF16("refresh"),
205 &meta_elements);
206 return meta_elements.size() != 0;
207 }
208
193 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { 209 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
194 bool handled = true; 210 bool handled = true;
195 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) 211 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message)
196 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) 212 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript)
197 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, 213 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost,
198 OnHandleMessageFromExternalHost) 214 OnHandleMessageFromExternalHost)
199 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, 215 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl,
200 OnJavaScriptStressTestControl) 216 OnJavaScriptStressTestControl)
201 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, 217 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent,
202 OnSetAllowDisplayingInsecureContent) 218 OnSetAllowDisplayingInsecureContent)
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 webui_javascript_.get()) { 624 webui_javascript_.get()) {
609 render_view()->EvaluateScript(webui_javascript_->frame_xpath, 625 render_view()->EvaluateScript(webui_javascript_->frame_xpath,
610 webui_javascript_->jscript, 626 webui_javascript_->jscript,
611 webui_javascript_->id, 627 webui_javascript_->id,
612 webui_javascript_->notify_result); 628 webui_javascript_->notify_result);
613 webui_javascript_.reset(); 629 webui_javascript_.reset();
614 } 630 }
615 } 631 }
616 632
617 void ChromeRenderViewObserver::DidStopLoading() { 633 void ChromeRenderViewObserver::DidStopLoading() {
634 int page_id = render_view()->GetPageId();
635 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
618 CapturePageInfoLater( 636 CapturePageInfoLater(
637 page_id,
638 HasRefreshMetaTag(main_frame),
619 false, // preliminary_capture 639 false, // preliminary_capture
620 base::TimeDelta::FromMilliseconds( 640 base::TimeDelta::FromMilliseconds(
621 render_view()->GetContentStateImmediately() ? 641 render_view()->GetContentStateImmediately() ?
622 0 : kDelayForCaptureMs)); 642 0 : kDelayForCaptureMs));
623 643
624 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
625 GURL osd_url = main_frame->document().openSearchDescriptionURL(); 644 GURL osd_url = main_frame->document().openSearchDescriptionURL();
626 if (!osd_url.is_empty()) { 645 if (!osd_url.is_empty()) {
627 Send(new ChromeViewHostMsg_PageHasOSDD( 646 Send(new ChromeViewHostMsg_PageHasOSDD(
628 routing_id(), render_view()->GetPageId(), osd_url, 647 routing_id(), render_view()->GetPageId(), osd_url,
629 search_provider::AUTODETECTED_PROVIDER)); 648 search_provider::AUTODETECTED_PROVIDER));
630 } 649 }
631 } 650 }
632 651
633 void ChromeRenderViewObserver::DidCommitProvisionalLoad( 652 void ChromeRenderViewObserver::DidCommitProvisionalLoad(
634 WebFrame* frame, bool is_new_navigation) { 653 WebFrame* frame, bool is_new_navigation) {
635 if (!is_new_navigation) 654 if (!is_new_navigation)
636 return; 655 return;
637 656
657 int page_id = render_view()->GetPageId();
638 CapturePageInfoLater( 658 CapturePageInfoLater(
659 page_id,
660 HasRefreshMetaTag(frame),
639 true, // preliminary_capture 661 true, // preliminary_capture
640 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); 662 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs));
641 } 663 }
642 664
643 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { 665 void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) {
644 if (render_view()->GetEnabledBindings() & 666 if (render_view()->GetEnabledBindings() &
645 content::BINDINGS_POLICY_EXTERNAL_HOST) { 667 content::BINDINGS_POLICY_EXTERNAL_HOST) {
646 GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); 668 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
647 } 669 }
648 } 670 }
649 671
650 void ChromeRenderViewObserver::DidHandleGestureEvent( 672 void ChromeRenderViewObserver::DidHandleGestureEvent(
651 const WebGestureEvent& event) { 673 const WebGestureEvent& event) {
652 if (event.type != WebKit::WebGestureEvent::GestureTap) 674 if (event.type != WebKit::WebGestureEvent::GestureTap)
653 return; 675 return;
654 676
655 WebKit::WebTextInputType text_input_type = 677 WebKit::WebTextInputType text_input_type =
656 render_view()->GetWebView()->textInputType(); 678 render_view()->GetWebView()->textInputType();
657 679
658 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched( 680 render_view()->Send(new ChromeViewHostMsg_FocusedNodeTouched(
659 routing_id(), 681 routing_id(),
660 text_input_type != WebKit::WebTextInputTypeNone)); 682 text_input_type != WebKit::WebTextInputTypeNone));
661 } 683 }
662 684
663 void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture, 685 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id,
686 bool has_refresh,
687 bool preliminary_capture,
664 base::TimeDelta delay) { 688 base::TimeDelta delay) {
665 capture_timer_.Start( 689 capture_timer_.Start(
666 FROM_HERE, 690 FROM_HERE,
667 delay, 691 delay,
668 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, 692 base::Bind(&ChromeRenderViewObserver::CapturePageInfo,
669 base::Unretained(this), 693 base::Unretained(this),
694 page_id,
695 has_refresh,
670 preliminary_capture)); 696 preliminary_capture));
671 } 697 }
672 698
673 void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { 699 void ChromeRenderViewObserver::CapturePageInfo(int page_id,
674 int page_id = render_view()->GetPageId(); 700 bool has_refresh,
jochen (gone - plz use gerrit) 2013/05/02 09:48:42 what's the reason to not just check for the meta t
Takashi Toyoshima 2013/05/02 11:51:18 Thanks. You are right. I should just pass page_id
Takashi Toyoshima 2013/05/02 12:13:58 In the case of client redirect of meta refresh, pa
675 701 bool preliminary_capture) {
676 if (!render_view()->GetWebView()) 702 if (!render_view()->GetWebView())
677 return; 703 return;
678 704
679 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 705 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
680 if (!main_frame) 706 if (!main_frame)
681 return; 707 return;
682 708
683 // Don't index/capture pages that are in view source mode. 709 // Don't index/capture pages that are in view source mode.
684 if (main_frame->isViewSourceModeEnabled()) 710 if (main_frame->isViewSourceModeEnabled())
685 return; 711 return;
686 712
687 // Don't index/capture pages that failed to load. This only checks the top 713 // Don't index/capture pages that failed to load. This only checks the top
688 // level frame so the thumbnail may contain a frame that failed to load. 714 // level frame so the thumbnail may contain a frame that failed to load.
689 WebDataSource* ds = main_frame->dataSource(); 715 WebDataSource* ds = main_frame->dataSource();
690 if (ds && ds->hasUnreachableURL()) 716 if (ds && ds->hasUnreachableURL())
691 return; 717 return;
692 718
693 // Don't index/capture pages that are being prerendered. 719 // Don't index/capture pages that are being prerendered.
694 if (prerender::PrerenderHelper::IsPrerendering(render_view())) 720 if (prerender::PrerenderHelper::IsPrerendering(render_view()))
695 return; 721 return;
696 722
697 // Retrieve the frame's full text (up to kMaxIndexChars), and pass it to the 723 // Retrieve the frame's full text (up to kMaxIndexChars), and pass it to the
698 // translate helper for language detection and possible translation. 724 // translate helper for language detection and possible translation.
699 string16 contents; 725 string16 contents;
700 CaptureText(main_frame, &contents); 726 CaptureText(main_frame, &contents);
701 if (translate_helper_) 727 // Skip to handle translation when the page includes refresh meta tag.
728 // Because this page will be replaced without updating |page_id| soon.
729 if (translate_helper_ && !has_refresh)
702 translate_helper_->PageCaptured(contents); 730 translate_helper_->PageCaptured(contents);
703 731
704 // Skip indexing if this is not a new load. Note that the case where 732 // Skip indexing if this is not a new load. Note that the case where
705 // page_id == last_indexed_page_id_ is more complicated, since we need to 733 // page_id == last_indexed_page_id_ is more complicated, since we need to
706 // reindex if the toplevel URL has changed (such as from a redirect), even 734 // reindex if the toplevel URL has changed (such as from a redirect), even
707 // though this may not cause the page id to be incremented. 735 // though this may not cause the page id to be incremented.
708 if (page_id < last_indexed_page_id_) 736 if (page_id < last_indexed_page_id_)
709 return; 737 return;
710 738
711 bool same_page_id = last_indexed_page_id_ == page_id; 739 bool same_page_id = last_indexed_page_id_ == page_id;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if (!external_host_bindings_.get()) { 812 if (!external_host_bindings_.get()) {
785 external_host_bindings_.reset(new ExternalHostBindings( 813 external_host_bindings_.reset(new ExternalHostBindings(
786 render_view(), routing_id())); 814 render_view(), routing_id()));
787 } 815 }
788 return external_host_bindings_.get(); 816 return external_host_bindings_.get();
789 } 817 }
790 818
791 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { 819 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) {
792 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); 820 return (strict_security_hosts_.find(host) != strict_security_hosts_.end());
793 } 821 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698