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

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: Update Created 7 years, 11 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 content::WebContents* instant_ntp = instant_.ReleaseNTPContents();
89 if (!instant_ntp)
90 return false;
91
92 instant_ntp->GetController().PruneAllButActive();
93 if (source_contents) {
94 instant_ntp->GetController().CopyStateFromAndPrune(
95 &source_contents->GetController());
96 ReplaceWebContentsAt(
97 browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
98 instant_ntp);
99 }
100 *target_contents = instant_ntp;
101 return true;
102 }
103
81 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { 104 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
82 // Unsupported dispositions. 105 // Unsupported dispositions.
83 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) 106 if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW)
84 return false; 107 return false;
85 108
86 // The omnibox currently doesn't use other dispositions, so we don't attempt 109 // 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 110 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add
88 // support for the new disposition. 111 // support for the new disposition.
89 DCHECK(disposition == CURRENT_TAB || 112 DCHECK(disposition == CURRENT_TAB ||
90 disposition == NEW_FOREGROUND_TAB) << disposition; 113 disposition == NEW_FOREGROUND_TAB) << disposition;
91 114
92 return instant_.CommitIfPossible(disposition == CURRENT_TAB ? 115 return instant_.CommitIfPossible(disposition == CURRENT_TAB ?
93 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); 116 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER);
94 } 117 }
95 118
96 void BrowserInstantController::CommitInstant(content::WebContents* preview, 119 void BrowserInstantController::CommitInstant(content::WebContents* preview,
97 bool in_new_tab) { 120 bool in_new_tab) {
98 if (in_new_tab) { 121 if (in_new_tab) {
99 // TabStripModel takes ownership of |preview|. 122 // TabStripModel takes ownership of |preview|.
100 browser_->tab_strip_model()->AddWebContents(preview, -1, 123 browser_->tab_strip_model()->AddWebContents(preview, -1,
101 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); 124 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE);
102 } else { 125 } else {
103 int index = browser_->tab_strip_model()->active_index(); 126 int index = browser_->tab_strip_model()->active_index();
104 DCHECK_NE(TabStripModel::kNoTab, index); 127 ReplaceWebContentsAt(index, preview);
105 content::WebContents* active_tab = 128 const GURL& url = preview->GetURL();
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()); 129 DCHECK(browser_->profile()->GetExtensionService());
114 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) { 130 if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) {
115 AppLauncherHandler::RecordAppLaunchType( 131 AppLauncherHandler::RecordAppLaunchType(
116 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); 132 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT);
117 } 133 }
118 } 134 }
119 } 135 }
120 136
137 void BrowserInstantController::ReplaceWebContentsAt(
138 int index,
139 content::WebContents* new_contents) {
140 DCHECK_NE(TabStripModel::kNoTab, index);
141 content::WebContents* old_contents =
142 browser_->tab_strip_model()->GetWebContentsAt(index);
143 // TabStripModel takes ownership of |new_contents|.
144 browser_->tab_strip_model()->ReplaceWebContentsAt(index, new_contents);
145 // InstantUnloadHandler takes ownership of |old_contents|.
146 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents, index);
147 }
148
121 void BrowserInstantController::SetInstantSuggestion( 149 void BrowserInstantController::SetInstantSuggestion(
122 const InstantSuggestion& suggestion) { 150 const InstantSuggestion& suggestion) {
123 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); 151 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion);
124 } 152 }
125 153
126 gfx::Rect BrowserInstantController::GetInstantBounds() { 154 gfx::Rect BrowserInstantController::GetInstantBounds() {
127 return browser_->window()->GetInstantBounds(); 155 return browser_->window()->GetInstantBounds();
128 } 156 }
129 157
130 void BrowserInstantController::InstantPreviewFocused() { 158 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. 324 // part of the image overlay should draw, 'cos the origin is top-left.
297 if (!browser_->search_model()->mode().is_ntp() || 325 if (!browser_->search_model()->mode().is_ntp() ||
298 theme_info_.theme_id.empty() || 326 theme_info_.theme_id.empty() ||
299 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) { 327 theme_info_.image_vertical_alignment == THEME_BKGRND_IMAGE_ALIGN_TOP) {
300 return; 328 return;
301 } 329 }
302 instant_.ThemeAreaHeightChanged(theme_area_height_); 330 instant_.ThemeAreaHeightChanged(theme_area_height_);
303 } 331 }
304 332
305 } // namespace chrome 333 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698