diff options
author | bryner@chromium.org <bryner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 20:21:10 +0000 |
---|---|---|
committer | bryner@chromium.org <bryner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 20:21:10 +0000 |
commit | b12631836299a784541a090f3a0293b697f6d5f3 (patch) | |
tree | 24819f40b39f245df431e4eff69a12f9b94423de /chrome/renderer | |
parent | b59dc7453baee292efb707c65aac01b9a6279cbc (diff) | |
download | chromium_src-b12631836299a784541a090f3a0293b697f6d5f3.zip chromium_src-b12631836299a784541a090f3a0293b697f6d5f3.tar.gz chromium_src-b12631836299a784541a090f3a0293b697f6d5f3.tar.bz2 |
Make sure to re-index the page after a redirect.
The code used to assume that reindexing was only needed if the page id had changed, but that doesn't work in the case of a redirect. If the page id is unchanged, we'll now check the toplevel URL and reindex if it has changed.
BUG=80742
TEST=none
Review URL: http://codereview.chromium.org/7744042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99025 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.cc | 35 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.h | 6 |
2 files changed, 36 insertions, 5 deletions
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index 2277c8f..db2baab 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -25,7 +25,6 @@ #include "content/common/bindings_policy.h" #include "content/common/view_messages.h" #include "content/renderer/content_renderer_client.h" -#include "googleurl/src/gurl.h" #include "net/base/data_url.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" @@ -187,6 +186,14 @@ static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { return FaviconURL::INVALID_ICON; } +namespace { +GURL StripRef(const GURL& url) { + GURL::Replacements replacements; + replacements.ClearRef(); + return url.ReplaceComponents(replacements); +} +} // namespace + ChromeRenderViewObserver::ChromeRenderViewObserver( RenderView* render_view, ContentSettingsObserver* content_settings, @@ -700,8 +707,12 @@ void ChromeRenderViewObserver::CapturePageInfo(int load_id, if (load_id != render_view()->page_id()) return; // This capture call is no longer relevant due to navigation. - if (load_id == last_indexed_page_id_) - return; // we already indexed this page + // Skip indexing if this is not a new load. Note that the case where + // load_id == last_indexed_page_id_ is more complicated, since we need to + // reindex if the toplevel URL has changed (such as from a redirect), even + // though this may not cause the page id to be incremented. + if (load_id < last_indexed_page_id_) + return; if (!render_view()->webview()) return; @@ -720,13 +731,29 @@ void ChromeRenderViewObserver::CapturePageInfo(int load_id, if (ds && ds->hasUnreachableURL()) return; + bool same_page_id = last_indexed_page_id_ == load_id; if (!preliminary_capture) last_indexed_page_id_ = load_id; // Get the URL for this page. GURL url(main_frame->document().url()); - if (url.is_empty()) + if (url.is_empty()) { + if (!preliminary_capture) + last_indexed_url_ = GURL(); return; + } + + // If the page id is unchanged, check whether the URL (ignoring fragments) + // has changed. If so, we need to reindex. Otherwise, assume this is a + // reload, in-page navigation, or some other load type where we don't want to + // reindex. Note: subframe navigations after onload increment the page id, + // so these will trigger a reindex. + GURL stripped_url(StripRef(url)); + if (same_page_id && stripped_url == last_indexed_url_) + return; + + if (!preliminary_capture) + last_indexed_url_ = stripped_url; // Retrieve the frame's full text. string16 contents; diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h index 21f3069..4d06aea 100644 --- a/chrome/renderer/chrome_render_view_observer.h +++ b/chrome/renderer/chrome_render_view_observer.h @@ -13,6 +13,7 @@ #include "base/task.h" #include "content/renderer/render_view.h" #include "content/renderer/render_view_observer.h" +#include "googleurl/src/gurl.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h" class ContentSettingsObserver; @@ -20,7 +21,6 @@ class DomAutomationController; class ExtensionDispatcher; class ExternalHostBindings; class FilePath; -class GURL; class SkBitmap; class TranslateHelper; struct ThumbnailScore; @@ -177,6 +177,10 @@ class ChromeRenderViewObserver : public RenderViewObserver, // Page_id from the last page we indexed. This prevents us from indexing the // same page twice in a row. int32 last_indexed_page_id_; + // The toplevel URL that was last indexed. This is used together with the + // page id to decide whether to reindex in certain cases like history + // replacement. + GURL last_indexed_url_; // Insecure content may be permitted for the duration of this render view. bool allow_displaying_insecure_content_; |