summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-14 21:38:30 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-14 21:38:30 +0000
commit03bb953da2a51fa35e7735ce711c1be6946312ea (patch)
treebd9fe31bd34036670ccc5247dcdba72cb9609400 /chrome/browser/browser.cc
parent037d1e192cfbad001946fe026d0460e636fa8e76 (diff)
downloadchromium_src-03bb953da2a51fa35e7735ce711c1be6946312ea.zip
chromium_src-03bb953da2a51fa35e7735ce711c1be6946312ea.tar.gz
chromium_src-03bb953da2a51fa35e7735ce711c1be6946312ea.tar.bz2
Bunch of match preview tweaks:
. Makes MatchPreview owned by Browser rather than each TabContents. . Makes MatchPreview dismiss when the omnibox closes. . Supports the ability to send script to the page rather than reloading on every keystroke. . Supports receiving results from the page that drives the suggest text in the omnbox. BUG=54833 TEST=none Review URL: http://codereview.chromium.org/3332022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser.cc')
-rw-r--r--chrome/browser/browser.cc56
1 files changed, 46 insertions, 10 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index a597915..1432000 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -254,6 +254,11 @@ Browser::Browser(Type type, Profile* profile)
if (profile_->GetProfileSyncService())
profile_->GetProfileSyncService()->AddObserver(this);
+
+ if (type == TYPE_NORMAL && MatchPreview::IsEnabled() &&
+ !profile->IsOffTheRecord()) {
+ match_preview_.reset(new MatchPreview(this));
+ }
}
Browser::~Browser() {
@@ -1263,6 +1268,13 @@ void Browser::OpenCurrentURL() {
LocationBar* location_bar = window_->GetLocationBar();
WindowOpenDisposition open_disposition =
location_bar->GetWindowOpenDisposition();
+ // TODO(sky): support other dispositions.
+ if (open_disposition == CURRENT_TAB && match_preview() &&
+ match_preview()->is_active()) {
+ match_preview()->CommitCurrentPreview();
+ return;
+ }
+
GURL url(WideToUTF8(location_bar->GetInputString()));
// Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least
@@ -2500,6 +2512,9 @@ void Browser::TabDetachedAt(TabContents* contents, int index) {
}
void Browser::TabDeselectedAt(TabContents* contents, int index) {
+ if (match_preview())
+ match_preview()->DestroyPreviewContents();
+
// Save what the user's currently typing, so it can be restored when we
// switch back to this tab.
window_->GetLocationBar()->SaveStateToContents(contents);
@@ -3039,16 +3054,6 @@ void Browser::ContentTypeChanged(TabContents* source) {
UpdateZoomCommandsForTabState();
}
-void Browser::CommitMatchPreview(TabContents* source) {
- int index = tabstrip_model_.GetIndexOfTabContents(source);
- DCHECK_NE(-1, index);
- TabContents* preview_contents =
- source->match_preview()->ReleasePreviewContents();
- // TabStripModel takes ownership of preview_contents.
- tabstrip_model_.ReplaceTabContentsAt(
- index, preview_contents, TabStripModelObserver::REPLACE_MATCH_PREVIEW);
-}
-
///////////////////////////////////////////////////////////////////////////////
// Browser, SelectFileDialog::Listener implementation:
@@ -3218,6 +3223,37 @@ void Browser::OnStateChanged() {
}
///////////////////////////////////////////////////////////////////////////////
+// Browser, MatchPreviewDelegate implementation:
+
+void Browser::ShowMatchPreview() {
+ DCHECK(match_preview_->tab_contents() == GetSelectedTabContents());
+ window_->ShowMatchPreview();
+}
+
+void Browser::HideMatchPreview() {
+ if (match_preview_->tab_contents() == GetSelectedTabContents())
+ window_->HideMatchPreview();
+}
+
+void Browser::CommitMatchPreview() {
+ TabContents* tab_contents = match_preview_->tab_contents();
+ int index = tabstrip_model_.GetIndexOfTabContents(tab_contents);
+ DCHECK_NE(-1, index);
+ scoped_ptr<TabContents> preview_contents(
+ match_preview()->ReleasePreviewContents(true));
+ preview_contents->controller().CopyStateFromAndPrune(
+ tab_contents->controller());
+ // TabStripModel takes ownership of preview_contents.
+ tabstrip_model_.ReplaceTabContentsAt(
+ index, preview_contents.release(),
+ TabStripModelObserver::REPLACE_MATCH_PREVIEW);
+}
+
+void Browser::SetSuggestedText(const string16& text) {
+ window()->GetLocationBar()->SetSuggestedText(text);
+}
+
+///////////////////////////////////////////////////////////////////////////////
// Browser, Command and state updating (private):
void Browser::InitCommandState() {