summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 21:27:56 +0000
committershishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 21:27:56 +0000
commit30889c2b4576c4c613b57b279184eb522a97684f (patch)
tree0da8d2d6ac4d86f4cbeefd18727d1d187114097a
parent7ccb08c489010679739680adb84fd60d288ee20b (diff)
downloadchromium_src-30889c2b4576c4c613b57b279184eb522a97684f.zip
chromium_src-30889c2b4576c4c613b57b279184eb522a97684f.tar.gz
chromium_src-30889c2b4576c4c613b57b279184eb522a97684f.tar.bz2
Instant Extended: Fallback to local preview if the remote instant page is not ready on user input.
Reverts back to the remote URL when the preview is not showing and the omnibox looses focus. BUG=159289 Review URL: https://chromiumcodereview.appspot.com/11833043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180520 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/instant/instant_client.cc26
-rw-r--r--chrome/browser/instant/instant_client.h8
-rw-r--r--chrome/browser/instant/instant_controller.cc51
-rw-r--r--chrome/browser/instant/instant_controller.h10
-rw-r--r--chrome/browser/instant/instant_loader.cc8
-rw-r--r--chrome/browser/instant/instant_loader.h2
-rw-r--r--chrome/browser/instant/instant_tab.cc7
-rw-r--r--chrome/browser/instant/instant_tab.h2
-rw-r--r--chrome/browser/instant/instant_test_utils.cc4
-rw-r--r--chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js10
10 files changed, 100 insertions, 28 deletions
diff --git a/chrome/browser/instant/instant_client.cc b/chrome/browser/instant/instant_client.cc
index c77f7cd..ab5d339 100644
--- a/chrome/browser/instant/instant_client.cc
+++ b/chrome/browser/instant/instant_client.cc
@@ -47,6 +47,16 @@ void InstantClient::SetMarginSize(const int start, const int end) {
Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end));
}
+void InstantClient::InitializeFonts() {
+ const gfx::Font& omnibox_font =
+ ui::ResourceBundle::GetSharedInstance().GetFont(
+ ui::ResourceBundle::MediumFont);
+ string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
+ size_t omnibox_font_size = omnibox_font.GetFontSize();
+ Send(new ChromeViewMsg_SearchBoxFontInformation(
+ routing_id(), omnibox_font_name, omnibox_font_size));
+}
+
void InstantClient::DetermineIfPageSupportsInstant() {
Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
}
@@ -83,6 +93,11 @@ void InstantClient::KeyCaptureChanged(bool is_key_capture_enabled) {
is_key_capture_enabled));
}
+void InstantClient::RenderViewCreated(
+ content::RenderViewHost* render_view_host) {
+ delegate_->RenderViewCreated();
+}
+
void InstantClient::DidFinishLoad(
int64 /* frame_id */,
const GURL& /* validated_url */,
@@ -134,17 +149,6 @@ void InstantClient::SetSuggestions(
}
void InstantClient::InstantSupportDetermined(int page_id, bool result) {
- if (result) {
- // Inform the renderer process of the Omnibox's font information.
- const gfx::Font& omnibox_font =
- ui::ResourceBundle::GetSharedInstance().GetFont(
- ui::ResourceBundle::MediumFont);
- string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
- size_t omnibox_font_size = omnibox_font.GetFontSize();
-
- Send(new ChromeViewMsg_SearchBoxFontInformation(
- routing_id(), omnibox_font_name, omnibox_font_size));
- }
if (web_contents()->IsActiveEntry(page_id))
delegate_->InstantSupportDetermined(result);
}
diff --git a/chrome/browser/instant/instant_client.h b/chrome/browser/instant/instant_client.h
index 0f44868..dffdc6b 100644
--- a/chrome/browser/instant/instant_client.h
+++ b/chrome/browser/instant/instant_client.h
@@ -68,6 +68,9 @@ class InstantClient : public content::WebContentsObserver {
virtual void NavigateToURL(const GURL& url,
content::PageTransition transition) = 0;
+ // Called when a RenderView is created, so that state can be initialized.
+ virtual void RenderViewCreated() = 0;
+
protected:
virtual ~Delegate();
};
@@ -104,6 +107,9 @@ class InstantClient : public content::WebContentsObserver {
// Tells the page what size start and end margins to use.
void SetMarginSize(const int start, const int end);
+ // Tells the page about the font information.
+ void InitializeFonts();
+
// Tells the renderer to determine if the page supports the Instant API, which
// results in a call to InstantSupportDetermined() when the reply is received.
void DetermineIfPageSupportsInstant();
@@ -133,6 +139,8 @@ class InstantClient : public content::WebContentsObserver {
private:
// Overridden from content::WebContentsObserver:
+ virtual void RenderViewCreated(
+ content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidFinishLoad(
int64 frame_id,
const GURL& validated_url,
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 7c8880b..00df280 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -261,8 +261,10 @@ bool InstantController::Update(const AutocompleteMatch& match,
return false;
}
- // If we have an |instant_tab_| use it, else ensure we have a loader.
- if (!instant_tab_ && !EnsureLoaderIsCurrent()) {
+ // If we have an |instant_tab_| use it, else ensure we have a loader that is
+ // current or is using local preview.
+ if (!instant_tab_ && !(loader_ && loader_->IsUsingLocalPreview()) &&
+ !EnsureLoaderIsCurrent()) {
HideLoader();
return false;
}
@@ -383,6 +385,14 @@ bool InstantController::Update(const AutocompleteMatch& match,
if (first_interaction_time_.is_null())
first_interaction_time_ = base::Time::Now();
allow_preview_to_show_search_suggestions_ = true;
+
+ // For extended mode, if the loader is not ready at this point, switch over
+ // to a backup loader.
+ if (extended_enabled_ && !loader_->supports_instant() &&
+ !loader_->IsUsingLocalPreview() && browser_->GetActiveWebContents()) {
+ CreateLoader(kLocalOmniboxPopupURL, browser_->GetActiveWebContents());
+ }
+
loader_->Update(extended_enabled_ ? user_text : full_text,
selection_start, selection_end, verbatim);
}
@@ -943,6 +953,18 @@ void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) {
}
}
+void InstantController::InstantLoaderRenderViewCreated() {
+ if (!extended_enabled_)
+ return;
+
+ // Ensure the searchbox API has the correct initial state.
+ loader_->SetDisplayInstantResults(instant_enabled_);
+ loader_->SearchModeChanged(search_mode_);
+ loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
+ loader_->SetMarginSize(start_margin_, end_margin_);
+ loader_->InitializeFonts();
+}
+
void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
// If the preview is showing custom NTP content, don't hide it, commit it
// (no matter where the user clicked) or try to recreate it.
@@ -952,6 +974,7 @@ void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
// If the preview is not showing at all, recreate it if it's stale.
if (model_.mode().is_default()) {
OnStaleLoader();
+ MaybeSwitchToRemoteLoader();
return;
}
@@ -1018,21 +1041,16 @@ bool InstantController::EnsureLoaderIsCurrent() {
void InstantController::CreateLoader(const std::string& instant_url,
const content::WebContents* active_tab) {
+ // Update theme info so that the loader picks up the correct fonts.
+ if (extended_enabled_)
+ browser_->UpdateThemeInfoForPreview();
+
HideInternal();
loader_.reset(new InstantLoader(this, instant_url));
loader_->InitContents(active_tab);
LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
"CreateLoader: instant_url='%s'", instant_url.c_str()));
- // Ensure the searchbox API has the correct initial state.
- if (extended_enabled_) {
- browser_->UpdateThemeInfoForPreview();
- loader_->SetDisplayInstantResults(instant_enabled_);
- loader_->SearchModeChanged(search_mode_);
- loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
- loader_->SetMarginSize(start_margin_, end_margin_);
- }
-
// Restart the stale loader timer.
stale_loader_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this,
@@ -1055,6 +1073,15 @@ void InstantController::OnStaleLoader() {
}
}
+void InstantController::MaybeSwitchToRemoteLoader() {
+ if (!loader_ || omnibox_focus_state_ != OMNIBOX_FOCUS_NONE ||
+ !model_.mode().is_default()) {
+ return;
+ }
+
+ EnsureLoaderIsCurrent();
+}
+
void InstantController::ResetInstantTab() {
// Do not wire up the InstantTab if instant should only use local previews, to
// prevent it from sending data to the page.
@@ -1065,6 +1092,7 @@ void InstantController::ResetInstantTab() {
instant_tab_->Init();
instant_tab_->SetDisplayInstantResults(instant_enabled_);
instant_tab_->SetMarginSize(start_margin_, end_margin_);
+ instant_tab_->InitializeFonts();
}
// Hide the |loader_| since we are now using |instant_tab_| instead.
@@ -1077,6 +1105,7 @@ void InstantController::ResetInstantTab() {
void InstantController::HideLoader() {
HideInternal();
OnStaleLoader();
+ MaybeSwitchToRemoteLoader();
}
void InstantController::HideInternal() {
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 19acbb4..01b2623 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -176,6 +176,11 @@ class InstantController {
// Invoked by InstantLoader when the instant page is about to navigate.
void InstantLoaderAboutToNavigateMainFrame(const GURL& url);
+ // Invoked by InstantLoader when it's underlying RenderView is created.
+ // TODO(shishir): We assume that the WebContent's current RenderViewHost is
+ // the RenderViewHost being created which is not always true. Fix this.
+ void InstantLoaderRenderViewCreated();
+
// Invoked by the InstantLoader when the instant page wants to navigate to
// the speicfied URL.
void NavigateToURL(const GURL& url, content::PageTransition transition);
@@ -217,6 +222,11 @@ class InstantController {
// deleted and recreated. Else the refresh is skipped.
void OnStaleLoader();
+ // If the |loader_| being used is in fallback mode, it will be switched back
+ // to the remote loader if the loader is not showing and the omnibox does not
+ // have focus.
+ void MaybeSwitchToRemoteLoader();
+
// If the active tab is an Instant search results page, sets |instant_tab_| to
// point to it. Else, deletes any existing |instant_tab_|.
void ResetInstantTab();
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index b28fdc6..7f64072 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -248,6 +248,10 @@ void InstantLoader::SetMarginSize(int start, int end) {
client_.SetMarginSize(start, end);
}
+void InstantLoader::InitializeFonts() {
+ client_.InitializeFonts();
+}
+
void InstantLoader::SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results) {
client_.SendAutocompleteResults(results);
@@ -324,6 +328,10 @@ void InstantLoader::NavigateToURL(const GURL& url,
controller_->NavigateToURL(url, transition);
}
+void InstantLoader::RenderViewCreated() {
+ controller_->InstantLoaderRenderViewCreated();
+}
+
void InstantLoader::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h
index 185d2ff..be244f5 100644
--- a/chrome/browser/instant/instant_loader.h
+++ b/chrome/browser/instant/instant_loader.h
@@ -99,6 +99,7 @@ class InstantLoader : public InstantClient::Delegate,
void Cancel(const string16& text);
void SetPopupBounds(const gfx::Rect& bounds);
void SetMarginSize(int start, int end);
+ void InitializeFonts();
void SendAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results);
void UpOrDownKeyPressed(int count);
@@ -124,6 +125,7 @@ class InstantLoader : public InstantClient::Delegate,
virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE;
virtual void NavigateToURL(const GURL& url,
content::PageTransition transition) OVERRIDE;
+ virtual void RenderViewCreated() 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 33cfe62..733c6f0 100644
--- a/chrome/browser/instant/instant_tab.cc
+++ b/chrome/browser/instant/instant_tab.cc
@@ -50,6 +50,10 @@ void InstantTab::SetMarginSize(int start, int end) {
client_.SetMarginSize(start, end);
}
+void InstantTab::InitializeFonts() {
+ client_.InitializeFonts();
+}
+
void InstantTab::SetSuggestions(
const std::vector<InstantSuggestion>& suggestions) {
InstantSupportDetermined(true);
@@ -96,3 +100,6 @@ void InstantTab::NavigateToURL(const GURL& url,
content::PageTransition transition) {
controller_->NavigateToURL(url, transition);
}
+
+void InstantTab::RenderViewCreated() {
+}
diff --git a/chrome/browser/instant/instant_tab.h b/chrome/browser/instant/instant_tab.h
index 2e0321a..8546c08 100644
--- a/chrome/browser/instant/instant_tab.h
+++ b/chrome/browser/instant/instant_tab.h
@@ -45,6 +45,7 @@ class InstantTab : public InstantClient::Delegate {
void SetDisplayInstantResults(bool display_instant_results);
void UpOrDownKeyPressed(int count);
void SetMarginSize(int start, int end);
+ void InitializeFonts();
private:
// Overridden from InstantClient::Delegate:
@@ -60,6 +61,7 @@ class InstantTab : public InstantClient::Delegate {
virtual void AboutToNavigateMainFrame(const GURL& url) OVERRIDE;
virtual void NavigateToURL(const GURL& url,
content::PageTransition transition) OVERRIDE;
+ virtual void RenderViewCreated() OVERRIDE;
InstantClient client_;
InstantController* const controller_;
diff --git a/chrome/browser/instant/instant_test_utils.cc b/chrome/browser/instant/instant_test_utils.cc
index 56aed0f..515a965 100644
--- a/chrome/browser/instant/instant_test_utils.cc
+++ b/chrome/browser/instant/instant_test_utils.cc
@@ -57,6 +57,10 @@ void InstantTestBase::SetupInstant() {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kInstantURL, instant_url_.spec());
SetupInstantUsingTemplateURL();
+
+ // TODO(shishir): Fix this ugly hack.
+ instant()->SetInstantEnabled(false);
+ instant()->SetInstantEnabled(true);
}
void InstantTestBase::SetupInstantUsingTemplateURL() {
diff --git a/chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js b/chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js
index fa44d0e..c91b7f3 100644
--- a/chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js
+++ b/chrome/browser/resources/local_omnibox_popup/local_omnibox_popup.js
@@ -145,12 +145,6 @@ function updateSelectedSuggestion(increment) {
* chrome.searchBox.onnativesuggestions implementation.
*/
function handleNativeSuggestions() {
- // This can't be done in setUpApi(), because apiHandle.font/fontSize
- // isn't available yet.
- var suggestionStyleNode = $('suggestionStyle');
- if (!suggestionStyleNode)
- appendSuggestionStyles();
-
var apiHandle = getApiObjectHandle();
// Used to workaround repeated undesired asynchronous onnativesuggestions
@@ -234,6 +228,10 @@ function setUpApi() {
apiHandle.onnativesuggestions = handleNativeSuggestions;
apiHandle.onkeypress = handleKeyPress;
apiHandle.onsubmit = onSubmit;
+ appendSuggestionStyles();
+
+ if (apiHandle.nativeSuggestions.length)
+ handleNativeSuggestions();
}
document.addEventListener('DOMContentLoaded', setUpApi);