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

Side by Side Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 10 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_instant_controller.h" 5 #include "chrome/browser/ui/browser_instant_controller.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 void BrowserInstantController::RegisterUserPrefs(PrefServiceSyncable* prefs) { 72 void BrowserInstantController::RegisterUserPrefs(PrefServiceSyncable* prefs) {
73 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, 73 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false,
74 PrefServiceSyncable::SYNCABLE_PREF); 74 PrefServiceSyncable::SYNCABLE_PREF);
75 prefs->RegisterBooleanPref(prefs::kInstantExtendedEnabled, true, 75 prefs->RegisterBooleanPref(prefs::kInstantExtendedEnabled, true,
76 PrefServiceSyncable::SYNCABLE_PREF); 76 PrefServiceSyncable::SYNCABLE_PREF);
77 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false, 77 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false,
78 PrefServiceSyncable::SYNCABLE_PREF); 78 PrefServiceSyncable::SYNCABLE_PREF);
79 } 79 }
80 80
81 bool BrowserInstantController::MaybeSwapInInstantContents(
82 const GURL& url,
83 content::WebContents* source_contents,
84 content::WebContents** target_contents) {
85 if (url != GURL(chrome::kChromeUINewTabURL))
86 return false;
87
88 scoped_ptr<content::WebContents> instant_ntp = instant_.ReleaseNTPContents();
89 if (!instant_ntp)
90 return false;
91
92 *target_contents = instant_ntp.get();
93 instant_ntp->GetController().PruneAllButActive();
94 if (source_contents) {
95 instant_ntp->GetController().CopyStateFromAndPrune(
96 &source_contents->GetController());
97 ReplaceWebContentsAt(
98 browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
99 instant_ntp.Pass());
100 } else {
101 // If |source_contents| is NULL, then the caller is responsible for
102 // inserting instant_ntp into the tabstrip and will take ownership.
103 ignore_result(instant_ntp.release());
104 }
105 return true;
106 }
107
81 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { 108 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
82 // Unsupported dispositions. 109 // Unsupported dispositions.
83 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) 110 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW)
84 return false; 111 return false;
85 112
86 // The omnibox currently doesn't use other dispositions, so we don't attempt 113 // The omnibox currently doesn't use other dispositions, so we don't attempt
87 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add 114 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add
88 // support for the new disposition. 115 // support for the new disposition.
89 DCHECK(disposition == CURRENT_TAB || 116 DCHECK(disposition == CURRENT_TAB ||
90 disposition == NEW_FOREGROUND_TAB) << disposition; 117 disposition == NEW_FOREGROUND_TAB) << disposition;
91 118
92 return instant_.CommitIfPossible(disposition == CURRENT_TAB ? 119 return instant_.CommitIfPossible(disposition == CURRENT_TAB ?
93 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); 120 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER);
94 } 121 }
95 122
96 void BrowserInstantController::CommitInstant(content::WebContents* preview, 123 void BrowserInstantController::CommitInstant(
97 bool in_new_tab) { 124 scoped_ptr<content::WebContents> preview,
125 bool in_new_tab) {
98 if (in_new_tab) { 126 if (in_new_tab) {
99 // TabStripModel takes ownership of |preview|. 127 // TabStripModel takes ownership of |preview|.
100 browser_->tab_strip_model()->AddWebContents(preview, -1, 128 browser_->tab_strip_model()->AddWebContents(preview.release(), -1,
101 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); 129 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE);
102 } else { 130 } else {
103 int index = browser_->tab_strip_model()->active_index(); 131 int index = browser_->tab_strip_model()->active_index();
104 DCHECK_NE(TabStripModel::kNoTab, index); 132 const GURL& url = preview->GetURL();
105 content::WebContents* active_tab = 133 ReplaceWebContentsAt(index, preview.Pass());
106 browser_->tab_strip_model()->GetWebContentsAt(index);
107 // TabStripModel takes ownership of |preview|.
108 browser_->tab_strip_model()->ReplaceWebContentsAt(index, preview);
109 // InstantUnloadHandler takes ownership of |active_tab|.
110 instant_unload_handler_.RunUnloadListenersOrDestroy(active_tab, index);
111
112 GURL url = preview->GetURL();
113 DCHECK(browser_->profile()->GetExtensionService()); 134 DCHECK(browser_->profile()->GetExtensionService());
114 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) { 135 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) {
115 AppLauncherHandler::RecordAppLaunchType( 136 AppLauncherHandler::RecordAppLaunchType(
116 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); 137 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT);
117 } 138 }
118 } 139 }
119 } 140 }
120 141
142 void BrowserInstantController::ReplaceWebContentsAt(
143 int index,
144 scoped_ptr<content::WebContents> new_contents) {
145 DCHECK_NE(TabStripModel::kNoTab, index);
146 content::WebContents* old_contents =
147 browser_->tab_strip_model()->GetWebContentsAt(index);
148 // TabStripModel takes ownership of |new_contents|.
149 browser_->tab_strip_model()->ReplaceWebContentsAt(
150 index, new_contents.release());
151 // TODO(samarth): use scoped_ptr instead of comments to document ownership
152 // transfer.
153 // InstantUnloadHandler takes ownership of |old_contents|.
154 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents, index);
155 }
156
121 void BrowserInstantController::SetInstantSuggestion( 157 void BrowserInstantController::SetInstantSuggestion(
122 const InstantSuggestion& suggestion) { 158 const InstantSuggestion& suggestion) {
123 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); 159 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion);
124 } 160 }
125 161
126 gfx::Rect BrowserInstantController::GetInstantBounds() { 162 gfx::Rect BrowserInstantController::GetInstantBounds() {
127 return browser_->window()->GetInstantBounds(); 163 return browser_->window()->GetInstantBounds();
128 } 164 }
129 165
130 void BrowserInstantController::InstantPreviewFocused() { 166 void BrowserInstantController::InstantPreviewFocused() {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // part of the image overlay should draw, 'cos the origin is top-left. 332 // part of the image overlay should draw, 'cos the origin is top-left.
297 if (!browser_->search_model()->mode().is_ntp() || 333 if (!browser_->search_model()->mode().is_ntp() ||
298 theme_info_.theme_id.empty() || 334 theme_info_.theme_id.empty() ||
299 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { 335 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) {
300 return; 336 return;
301 } 337 }
302 instant_.ThemeAreaHeightChanged(theme_area_height_); 338 instant_.ThemeAreaHeightChanged(theme_area_height_);
303 } 339 }
304 340
305 } // namespace chrome 341 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698