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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/chrome_render_view_observer.cc
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index 8e0420c41d54153aa37eb1daf51e578784e4dfc1..344f6038aa7c9fd2a755f20e023e77b40b05a362 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -10,7 +10,7 @@
#include "base/debug/trace_event.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
-#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/prerender_messages.h"
@@ -40,6 +40,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
@@ -48,6 +49,7 @@
#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
#include "v8/include/v8-testing.h"
+#include "webkit/glue/dom_operations.h"
#include "webkit/glue/image_decoder.h"
#include "webkit/glue/multi_resolution_image_resource_fetcher.h"
#include "webkit/glue/webkit_glue.h"
@@ -56,6 +58,7 @@ using WebKit::WebAccessibilityObject;
using WebKit::WebCString;
using WebKit::WebDataSource;
using WebKit::WebDocument;
+using WebKit::WebElement;
using WebKit::WebFrame;
using WebKit::WebGestureEvent;
using WebKit::WebIconURL;
@@ -190,6 +193,19 @@ ChromeRenderViewObserver::ChromeRenderViewObserver(
ChromeRenderViewObserver::~ChromeRenderViewObserver() {
}
+// static
+bool ChromeRenderViewObserver::HasRefreshMetaTag(WebFrame* frame) {
+ if (!frame)
+ return false;
+ std::vector<WebElement> meta_elements;
+ WebDocument document = frame->document();
+ webkit_glue::GetMetaElementsWithAttribute(&document,
+ ASCIIToUTF16("http-equiv"),
+ ASCIIToUTF16("refresh"),
+ &meta_elements);
+ return meta_elements.size() != 0;
+}
+
bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message)
@@ -615,13 +631,16 @@ void ChromeRenderViewObserver::DidStartLoading() {
}
void ChromeRenderViewObserver::DidStopLoading() {
+ int page_id = render_view()->GetPageId();
+ WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
CapturePageInfoLater(
+ page_id,
+ HasRefreshMetaTag(main_frame),
false, // preliminary_capture
base::TimeDelta::FromMilliseconds(
render_view()->GetContentStateImmediately() ?
0 : kDelayForCaptureMs));
- WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
GURL osd_url = main_frame->document().openSearchDescriptionURL();
if (!osd_url.is_empty()) {
Send(new ChromeViewHostMsg_PageHasOSDD(
@@ -635,7 +654,10 @@ void ChromeRenderViewObserver::DidCommitProvisionalLoad(
if (!is_new_navigation)
return;
+ int page_id = render_view()->GetPageId();
CapturePageInfoLater(
+ page_id,
+ HasRefreshMetaTag(frame),
true, // preliminary_capture
base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs));
}
@@ -660,19 +682,23 @@ void ChromeRenderViewObserver::DidHandleGestureEvent(
text_input_type != WebKit::WebTextInputTypeNone));
}
-void ChromeRenderViewObserver::CapturePageInfoLater(bool preliminary_capture,
+void ChromeRenderViewObserver::CapturePageInfoLater(int page_id,
+ bool has_refresh,
+ bool preliminary_capture,
base::TimeDelta delay) {
capture_timer_.Start(
FROM_HERE,
delay,
base::Bind(&ChromeRenderViewObserver::CapturePageInfo,
base::Unretained(this),
+ page_id,
+ has_refresh,
preliminary_capture));
}
-void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) {
- int page_id = render_view()->GetPageId();
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
-
+void ChromeRenderViewObserver::CapturePageInfo(int page_id,
+ bool has_refresh,
+ bool preliminary_capture) {
if (!render_view()->GetWebView())
return;
@@ -698,7 +724,9 @@ void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) {
// translate helper for language detection and possible translation.
string16 contents;
CaptureText(main_frame, &contents);
- if (translate_helper_)
+ // Skip to handle translation when the page includes refresh meta tag.
+ // Because this page will be replaced without updating |page_id| soon.
+ if (translate_helper_ && !has_refresh)
translate_helper_->PageCaptured(contents);
// Skip indexing if this is not a new load. Note that the case where
« 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