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

Unified Diff: chrome/browser/instant/instant_controller.cc

Issue 11555033: Adding local html page used in Instant Extended mode when instant is disabled or unavailable. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing comments from estade, dhollowa and samarth. Created 8 years 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
Index: chrome/browser/instant/instant_controller.cc
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index e0fc9e77fef1b23103ee22eca53921410a28aee3..cf3212f633ec1165e105b98a3959964c0fa873a6 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -146,11 +146,16 @@ bool IsFullHeight(const InstantModel& model) {
} // namespace
+const char* InstantController::kLocalOmniboxPopupURL =
sky 2012/12/13 23:39:02 For static we put // static on the previous line.
Shishir 2012/12/14 00:03:15 Done.
+ "chrome://local-omnibox-popup/local-omnibox-popup.html";
+
InstantController::InstantController(chrome::BrowserInstantController* browser,
- bool extended_enabled)
+ bool extended_enabled,
+ bool use_local_preview_only)
: browser_(browser),
extended_enabled_(extended_enabled),
instant_enabled_(false),
+ use_local_preview_only_(use_local_preview_only),
model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
last_omnibox_text_has_inline_autocompletion_(false),
last_verbatim_(false),
@@ -451,6 +456,10 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED)
return false;
+ // Never commit the local omnibox.
+ if (loader_->IsUsingLocalPreview())
+ return false;
+
if (type == INSTANT_COMMIT_FOCUS_LOST)
loader_->Cancel(last_omnibox_text_);
else if (type != INSTANT_COMMIT_NAVIGATED &&
@@ -841,10 +850,16 @@ void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
}
bool InstantController::ResetLoader(const TemplateURL* template_url,
- const content::WebContents* active_tab) {
+ const content::WebContents* active_tab,
+ bool fallback_to_local) {
std::string instant_url;
- if (!GetInstantURL(template_url, &instant_url))
- return false;
+ if (!GetInstantURL(template_url, &instant_url)) {
+ if (!fallback_to_local || !extended_enabled_)
+ return false;
+
+ // If we are in extended mode, fallback to the local popup.
+ instant_url = kLocalOmniboxPopupURL;
+ }
if (loader_ && loader_->instant_url() == instant_url)
return true;
@@ -879,10 +894,14 @@ bool InstantController::CreateDefaultLoader() {
Profile::FromBrowserContext(active_tab->GetBrowserContext()))->
GetDefaultSearchProvider();
- return ResetLoader(template_url, active_tab);
+ return ResetLoader(template_url, active_tab, true);
}
void InstantController::OnStaleLoader() {
+ // The local popup is never stale.
+ if (loader_ && loader_->IsUsingLocalPreview())
+ return;
+
// If the preview is showing or the omnibox has focus, don't delete the
// loader. It will get refreshed the next time the preview is hidden or the
// omnibox loses focus.
@@ -923,9 +942,12 @@ bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) {
return false;
// Try to create a loader for the instant_url in the TemplateURL of |match|.
+ // Do not fallback to the local preview because if the keyword specific
+ // instant URL fails, we want to first try the default instant URL which
+ // happens in the CreateDefaultLoader call below.
const TemplateURL* template_url = match.GetTemplateURL(
Profile::FromBrowserContext(active_tab->GetBrowserContext()), false);
- if (ResetLoader(template_url, active_tab))
+ if (ResetLoader(template_url, active_tab, false))
return true;
// In non-extended mode, stop if we couldn't get a loader for the |match|.
@@ -999,11 +1021,13 @@ void InstantController::ShowLoader(InstantShownReason reason,
}
// Show at 100% height except in the following cases:
+ // - The local omnibox popup is being loaded.
// - Instant is disabled. The page needs to be able to show only a dropdown.
// - The page wants to show custom NTP content.
// - The page is over a website other than search or an NTP, and is not
// already showing at 100% height.
- if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT ||
+ if (loader_->IsUsingLocalPreview() || !instant_enabled_ ||
+ reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT ||
(search_mode_.is_origin_default() && !IsFullHeight(model_)))
model_.SetPreviewState(search_mode_, height, units);
else
@@ -1046,6 +1070,11 @@ void InstantController::SendBoundsToPage() {
bool InstantController::GetInstantURL(const TemplateURL* template_url,
std::string* instant_url) const {
+ if (extended_enabled_ && use_local_preview_only_) {
+ *instant_url = kLocalOmniboxPopupURL;
+ return true;
+ }
+
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kInstantURL)) {
*instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);

Powered by Google App Engine
This is Rietveld 408576698