summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 22:56:53 +0000
committershishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 22:56:53 +0000
commit6d6587c3b5f3d1a3a5b7b03272c957a44d6acc71 (patch)
treee16c3081673d9eef9b4daa48ced24a11d2b04037
parent143633ce2b47eac6061dcafa32be11e411218ddd (diff)
downloadchromium_src-6d6587c3b5f3d1a3a5b7b03272c957a44d6acc71.zip
chromium_src-6d6587c3b5f3d1a3a5b7b03272c957a44d6acc71.tar.gz
chromium_src-6d6587c3b5f3d1a3a5b7b03272c957a44d6acc71.tar.bz2
Commit instant loader when the instant page navigates away from instant URL.
BUG=161784 Review URL: https://chromiumcodereview.appspot.com/11416187 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172168 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/instant/instant_client.cc11
-rw-r--r--chrome/browser/instant/instant_client.h9
-rw-r--r--chrome/browser/instant/instant_commit_type.h3
-rw-r--r--chrome/browser/instant/instant_controller.cc24
-rw-r--r--chrome/browser/instant/instant_controller.h3
-rw-r--r--chrome/browser/instant/instant_loader.cc20
-rw-r--r--chrome/browser/instant/instant_loader.h1
-rw-r--r--chrome/browser/instant/instant_tab.cc4
-rw-r--r--chrome/browser/instant/instant_tab.h1
9 files changed, 73 insertions, 3 deletions
diff --git a/chrome/browser/instant/instant_client.cc b/chrome/browser/instant/instant_client.cc
index 8aa53fb..50d7852 100644
--- a/chrome/browser/instant/instant_client.cc
+++ b/chrome/browser/instant/instant_client.cc
@@ -101,6 +101,17 @@ void InstantClient::RenderViewGone(base::TerminationStatus status) {
delegate_->RenderViewGone();
}
+void InstantClient::DidCommitProvisionalLoadForFrame(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& url,
+ content::PageTransition transition_type,
+ content::RenderViewHost* render_view_host) {
+ if (!is_main_frame)
+ return;
+ delegate_->AboutToNavigateMainFrame(url);
+}
+
void InstantClient::SetSuggestions(
int page_id,
const std::vector<InstantSuggestion>& suggestions) {
diff --git a/chrome/browser/instant/instant_client.h b/chrome/browser/instant/instant_client.h
index c22a0a6..821c36c 100644
--- a/chrome/browser/instant/instant_client.h
+++ b/chrome/browser/instant/instant_client.h
@@ -61,6 +61,9 @@ class InstantClient : public content::WebContentsObserver {
// Called when the underlying RenderView crashes.
virtual void RenderViewGone() = 0;
+ // Called when the page is about to navigate.
+ virtual void AboutToNavigateMainFrame(const GURL& url) = 0;
+
protected:
virtual ~Delegate();
};
@@ -127,6 +130,12 @@ class InstantClient : public content::WebContentsObserver {
content::RenderViewHost* render_view_host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
+ virtual void DidCommitProvisionalLoadForFrame(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& url,
+ content::PageTransition transition_type,
+ content::RenderViewHost* render_view_host) OVERRIDE;
void SetSuggestions(int page_id,
const std::vector<InstantSuggestion>& suggestions);
diff --git a/chrome/browser/instant/instant_commit_type.h b/chrome/browser/instant/instant_commit_type.h
index b025542..730e2c1 100644
--- a/chrome/browser/instant/instant_commit_type.h
+++ b/chrome/browser/instant/instant_commit_type.h
@@ -17,6 +17,9 @@ enum InstantCommitType {
// The commit is due to the omnibox losing focus, usually due to the user
// clicking on the preview.
INSTANT_COMMIT_FOCUS_LOST,
+
+ // The commit is due to the instant page navigating.
+ INSTANT_COMMIT_NAVIGATED,
};
#endif // CHROME_BROWSER_INSTANT_INSTANT_COMMIT_TYPE_H_
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index be835bb..d3e6545 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -444,12 +444,12 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
return false;
}
- if (!IsPreviewingSearchResults())
+ if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED)
return false;
if (type == INSTANT_COMMIT_FOCUS_LOST)
loader_->Cancel(last_omnibox_text_);
- else
+ else if (type != INSTANT_COMMIT_NAVIGATED)
loader_->Submit(last_omnibox_text_);
content::WebContents* preview = loader_->ReleaseContents();
@@ -487,7 +487,15 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
loader_->last_navigation();
if (!last_navigation.url.is_empty()) {
content::NavigationEntry* entry = preview->GetController().GetActiveEntry();
- DCHECK_EQ(last_navigation.url, entry->GetURL());
+
+ // The last navigation should be the same as the active entry if the loader
+ // is in search mode. During navigation, the active entry could have
+ // changed since DidCommitProvisionalLoadForFrame is called after the entry
+ // is changed.
+ // TODO(shishir): Should we commit the last navigation for
+ // INSTANT_COMMIT_NAVIGATED.
+ DCHECK(type == INSTANT_COMMIT_NAVIGATED ||
+ last_navigation.url == entry->GetURL());
// Add the page to history.
HistoryTabHelper* history_tab_helper =
@@ -792,6 +800,16 @@ void InstantController::InstantLoaderRenderViewGone() {
CreateDefaultLoader();
}
+void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) {
+ GURL instant_url(loader_->instant_url());
+
+ // Don't commit if the URL being navigated to has the same host and path as
+ // the instant URL. This enables the instant page to change the query
+ // parameters and fragments of the URL without it navigating.
+ if (url.host() != instant_url.host() || url.path() != instant_url.path())
+ CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
+}
+
bool InstantController::ResetLoader(const TemplateURL* template_url,
const content::WebContents* active_tab) {
std::string instant_url;
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 30821de..0f37e86 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -145,6 +145,9 @@ class InstantController {
// Invoked by the InstantLoader when its RenderView crashes.
void InstantLoaderRenderViewGone();
+ // Invoked by InstantLoader when the instant page is about to navigate.
+ void InstantLoaderAboutToNavigateMainFrame(const GURL& url);
+
private:
FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant);
FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider);
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index 9d08d42..5116497 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/instant/instant_loader.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
+#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
@@ -71,6 +72,9 @@ class InstantLoader::WebContentsDelegateImpl
virtual void HandleGestureEnd() OVERRIDE;
virtual void DragEnded() OVERRIDE;
virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
+ virtual content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE;
void MaybeCommitFromPointerRelease();
@@ -156,6 +160,15 @@ bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) {
return false;
}
+content::WebContents* InstantLoader::WebContentsDelegateImpl::OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ content::WebContents* preview = loader_->contents_.get();
+ if (loader_->controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED))
+ return preview->GetDelegate()->OpenURLFromTab(source, params);
+ return NULL;
+}
+
void InstantLoader::WebContentsDelegateImpl::MaybeCommitFromPointerRelease() {
if (loader_->is_pointer_down_from_activate_) {
loader_->is_pointer_down_from_activate_ = false;
@@ -297,6 +310,10 @@ void InstantLoader::RenderViewGone() {
controller_->InstantLoaderRenderViewGone();
}
+void InstantLoader::AboutToNavigateMainFrame(const GURL& url) {
+ controller_->InstantLoaderAboutToNavigateMainFrame(url);
+}
+
void InstantLoader::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -340,6 +357,9 @@ void InstantLoader::SetupPreviewContents() {
chrome::search::SearchTabHelper::CreateForWebContents(contents());
HistoryTabHelper::CreateForWebContents(contents());
+ // Observers.
+ extensions::WebNavigationTabObserver::CreateForWebContents(contents());
+
// And some flat-out paranoia.
safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents());
diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h
index 458e5c6..25257c7 100644
--- a/chrome/browser/instant/instant_loader.h
+++ b/chrome/browser/instant/instant_loader.h
@@ -115,6 +115,7 @@ class InstantLoader : public InstantClient::Delegate,
virtual void StartCapturingKeyStrokes() OVERRIDE;
virtual void StopCapturingKeyStrokes() OVERRIDE;
virtual void RenderViewGone() OVERRIDE;
+ virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE;
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
diff --git a/chrome/browser/instant/instant_tab.cc b/chrome/browser/instant/instant_tab.cc
index 302dba9..82870cf 100644
--- a/chrome/browser/instant/instant_tab.cc
+++ b/chrome/browser/instant/instant_tab.cc
@@ -83,3 +83,7 @@ void InstantTab::StopCapturingKeyStrokes() {
void InstantTab::RenderViewGone() {
// For a commit page, a crash should not be handled differently.
}
+
+void InstantTab::AboutToNavigateMainFrame(const GURL& url) {
+ // The client is a committed tab, navigations will happen as expected.
+}
diff --git a/chrome/browser/instant/instant_tab.h b/chrome/browser/instant/instant_tab.h
index f8fe8e7..b52f87d 100644
--- a/chrome/browser/instant/instant_tab.h
+++ b/chrome/browser/instant/instant_tab.h
@@ -56,6 +56,7 @@ class InstantTab : public InstantClient::Delegate {
virtual void StartCapturingKeyStrokes() OVERRIDE;
virtual void StopCapturingKeyStrokes() OVERRIDE;
virtual void RenderViewGone() OVERRIDE;
+ virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE;
InstantClient client_;
InstantController* const controller_;