Index: chrome/browser/browser.cc |
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc |
index deddb0b5caa3aee1b8ac79c596dd06c8f3a0fc5e..c934004e56c1748c1c227da99a1a08f34dc57237 100644 |
--- a/chrome/browser/browser.cc |
+++ b/chrome/browser/browser.cc |
@@ -251,6 +251,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() { |
@@ -1260,6 +1265,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 |
@@ -2494,6 +2506,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); |
@@ -3025,16 +3040,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: |
@@ -3204,6 +3209,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() { |