summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/browser_instant_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/browser_instant_controller.cc')
-rw-r--r--chrome/browser/ui/browser_instant_controller.cc99
1 files changed, 29 insertions, 70 deletions
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index e58bcb2..f8fd4f5 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,38 +6,23 @@
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
+#include "chrome/browser/ui/search/search.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
-namespace {
-
-// Returns true iff the search model for |tab| is in an NTP state, that is, a
-// state in which the Instant overlay may be showing custom NTP content in
-// EXTENDED mode.
-bool IsSearchModelNTP(content::WebContents* tab) {
- if (!tab)
- return false;
- chrome::search::SearchModel* model =
- chrome::search::SearchTabHelper::FromWebContents(tab)->model();
- return model && model->mode().is_ntp();
-}
-
-} // namespace
-
namespace chrome {
////////////////////////////////////////////////////////////////////////////////
@@ -45,23 +30,34 @@ namespace chrome {
BrowserInstantController::BrowserInstantController(Browser* browser)
: browser_(browser),
+ instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
+ chrome::search::IsInstantExtendedAPIEnabled(browser->profile())),
instant_unload_handler_(browser) {
profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
profile_pref_registrar_.Add(prefs::kInstantEnabled, this);
- ResetInstant();
- browser_->tab_strip_model()->AddObserver(this);
+ instant_.SetInstantEnabled(IsInstantEnabled(browser_->profile()));
browser_->search_model()->AddObserver(this);
}
BrowserInstantController::~BrowserInstantController() {
- browser_->tab_strip_model()->RemoveObserver(this);
browser_->search_model()->RemoveObserver(this);
}
+bool BrowserInstantController::IsInstantEnabled(Profile* profile) {
+ return profile && !profile->IsOffTheRecord() && profile->GetPrefs() &&
+ profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled);
+}
+
+void BrowserInstantController::RegisterUserPrefs(PrefService* prefs) {
+ prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false,
+ PrefService::SYNCABLE_PREF);
+ prefs->RegisterBooleanPref(prefs::kInstantEnabled, false,
+ PrefService::SYNCABLE_PREF);
+}
+
bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
- // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't attempt
- // to use the Instant preview.
- if (!instant() || !instant_->IsCurrent() || disposition == NEW_BACKGROUND_TAB)
+ // Unsupported dispositions.
+ if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW)
return false;
// The omnibox currently doesn't use other dispositions, so we don't attempt
@@ -70,9 +66,8 @@ bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
DCHECK(disposition == CURRENT_TAB ||
disposition == NEW_FOREGROUND_TAB) << disposition;
- instant_->CommitCurrentPreview(disposition == CURRENT_TAB ?
+ return instant_.CommitIfCurrent(disposition == CURRENT_TAB ?
INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER);
- return true;
}
void BrowserInstantController::CommitInstant(TabContents* preview,
@@ -80,7 +75,7 @@ void BrowserInstantController::CommitInstant(TabContents* preview,
if (in_new_tab) {
// TabStripModel takes ownership of |preview|.
browser_->tab_strip_model()->AddTabContents(preview, -1,
- instant_->last_transition_type(), TabStripModel::ADD_ACTIVE);
+ instant_.last_transition_type(), TabStripModel::ADD_ACTIVE);
} else {
TabContents* active_tab =
browser_->tab_strip_model()->GetActiveTabContents();
@@ -113,43 +108,24 @@ gfx::Rect BrowserInstantController::GetInstantBounds() {
void BrowserInstantController::InstantPreviewFocused() {
// NOTE: This is only invoked on aura.
browser_->window()->WebContentsFocused(
- instant_->GetPreviewContents()->web_contents());
+ instant_.GetPreviewContents()->web_contents());
}
TabContents* BrowserInstantController::GetActiveTabContents() const {
return browser_->tab_strip_model()->GetActiveTabContents();
}
+void BrowserInstantController::ActiveTabChanged() {
+ instant_.ActiveTabChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// BrowserInstantController, PrefObserver implementation:
void BrowserInstantController::OnPreferenceChanged(
PrefServiceBase* service,
const std::string& pref_name) {
- DCHECK_EQ(std::string(prefs::kInstantEnabled), pref_name);
- ResetInstant();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// BrowserInstantController, TabStripModelObserver implementation:
-
-void BrowserInstantController::ActiveTabChanged(
- content::WebContents* old_contents,
- content::WebContents* new_contents,
- int index,
- bool user_gesture) {
- if (instant()) {
- const bool old_is_ntp = IsSearchModelNTP(old_contents);
- const bool new_is_ntp = IsSearchModelNTP(new_contents);
- // Do not hide Instant if switching from an NTP to another NTP since that
- // would cause custom NTP content to flicker.
- if (!(old_is_ntp && new_is_ntp))
- instant()->Hide();
- }
-}
-
-void BrowserInstantController::TabStripEmpty() {
- instant_.reset();
+ instant_.SetInstantEnabled(IsInstantEnabled(browser_->profile()));
}
////////////////////////////////////////////////////////////////////////////////
@@ -157,24 +133,7 @@ void BrowserInstantController::TabStripEmpty() {
void BrowserInstantController::ModeChanged(const search::Mode& old_mode,
const search::Mode& new_mode) {
- if (instant())
- instant_->OnActiveTabModeChanged(new_mode);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// BrowserInstantController, private:
-
-void BrowserInstantController::ResetInstant() {
- instant_.reset(
- !browser_shutdown::ShuttingDownWithoutClosingBrowsers() &&
- browser_->is_type_tabbed() ?
- InstantController::CreateInstant(browser_->profile(), this) : NULL);
-
- // Notify any observers that they need to reset.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_BROWSER_INSTANT_RESET,
- content::Source<BrowserInstantController>(this),
- content::NotificationService::NoDetails());
+ instant_.SearchModeChanged(old_mode, new_mode);
}
} // namespace chrome