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

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

Issue 10732002: Upstream rewrite of Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try again. Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser_shutdown.h" 7 #include "chrome/browser/browser_shutdown.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/instant/instant_controller.h" 9 #include "chrome/browser/instant/instant_controller.h"
10 #include "chrome/browser/instant/instant_unload_handler.h" 10 #include "chrome/browser/instant/instant_unload_handler.h"
(...skipping 23 matching lines...) Expand all
34 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); 34 profile_pref_registrar_.Add(prefs::kInstantEnabled, this);
35 CreateInstantIfNecessary(); 35 CreateInstantIfNecessary();
36 browser_->tab_strip_model()->AddObserver(this); 36 browser_->tab_strip_model()->AddObserver(this);
37 } 37 }
38 38
39 BrowserInstantController::~BrowserInstantController() { 39 BrowserInstantController::~BrowserInstantController() {
40 browser_->tab_strip_model()->RemoveObserver(this); 40 browser_->tab_strip_model()->RemoveObserver(this);
41 } 41 }
42 42
43 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { 43 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
44 if (!instant() || !instant()->PrepareForCommit() || 44 if (!instant() || !instant()->IsCurrent() ||
45 disposition == NEW_BACKGROUND_TAB) { 45 disposition == NEW_BACKGROUND_TAB) {
46 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't 46 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't
47 // attempt to use the instant preview. 47 // attempt to use the instant preview.
48 return false; 48 return false;
49 } 49 }
50 50
51 if (disposition == CURRENT_TAB) { 51 if (disposition == CURRENT_TAB) {
52 content::NotificationService::current()->Notify( 52 content::NotificationService::current()->Notify(
53 chrome::NOTIFICATION_INSTANT_COMMITTED, 53 chrome::NOTIFICATION_INSTANT_COMMITTED,
54 content::Source<TabContents>(instant()->CommitCurrentPreview( 54 content::Source<TabContents>(instant()->CommitCurrentPreview(
55 INSTANT_COMMIT_PRESSED_ENTER)), 55 INSTANT_COMMIT_PRESSED_ENTER)),
56 content::NotificationService::NoDetails()); 56 content::NotificationService::NoDetails());
57 return true; 57 return true;
58 } 58 }
59 if (disposition == NEW_FOREGROUND_TAB) { 59 if (disposition == NEW_FOREGROUND_TAB) {
60 TabContents* preview_contents = instant()->ReleasePreviewContents( 60 TabContents* preview_contents = instant()->ReleasePreviewContents(
61 INSTANT_COMMIT_PRESSED_ENTER, NULL); 61 INSTANT_COMMIT_PRESSED_ENTER);
62 // HideInstant is invoked after release so that InstantController is not
63 // active when HideInstant asks it for its state.
64 HideInstant();
65 preview_contents->web_contents()->GetController().PruneAllButActive(); 62 preview_contents->web_contents()->GetController().PruneAllButActive();
66 browser_->tab_strip_model()->AddTabContents( 63 browser_->tab_strip_model()->AddTabContents(
67 preview_contents, 64 preview_contents,
68 -1, 65 -1,
69 instant()->last_transition_type(), 66 content::PAGE_TRANSITION_GENERATED,
sky 2012/07/25 17:29:56 How do we know the transition is always GENERATED?
70 TabStripModel::ADD_ACTIVE); 67 TabStripModel::ADD_ACTIVE);
71 instant()->CompleteRelease(preview_contents);
72 content::NotificationService::current()->Notify( 68 content::NotificationService::current()->Notify(
73 chrome::NOTIFICATION_INSTANT_COMMITTED, 69 chrome::NOTIFICATION_INSTANT_COMMITTED,
74 content::Source<TabContents>(preview_contents), 70 content::Source<TabContents>(preview_contents),
75 content::NotificationService::NoDetails()); 71 content::NotificationService::NoDetails());
76 return true; 72 return true;
77 } 73 }
78 // The omnibox currently doesn't use other dispositions, so we don't attempt 74 // The omnibox currently doesn't use other dispositions, so we don't attempt
79 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 75 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
80 // support for the new disposition. 76 // support for the new disposition.
81 NOTREACHED(); 77 NOTREACHED();
82 return false; 78 return false;
83 } 79 }
84 80
85 //////////////////////////////////////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////////////////
86 // BrowserInstantController, InstantControllerDelegate implementation: 82 // BrowserInstantController, InstantControllerDelegate implementation:
87 83
88 void BrowserInstantController::ShowInstant(TabContents* preview_contents) { 84 void BrowserInstantController::ShowInstant() {
85 TabContents* preview_contents = instant_->GetPreviewContents();
89 browser_->window()->ShowInstant(preview_contents); 86 browser_->window()->ShowInstant(preview_contents);
90 87
91 // TODO(beng): investigate if we can avoid this and instead rely on the 88 content::NotificationService::current()->Notify(
92 // visibility of the WebContentsView 89 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
93 chrome::GetActiveWebContents(browser_)->WasHidden(); 90 content::Source<InstantController>(instant_.get()),
sky 2012/07/25 17:29:56 Does this mean both the active and instant preview
91 content::NotificationService::NoDetails());
92
94 preview_contents->web_contents()->WasRestored(); 93 preview_contents->web_contents()->WasRestored();
95 } 94 }
96 95
97 void BrowserInstantController::HideInstant() { 96 void BrowserInstantController::HideInstant() {
98 browser_->window()->HideInstant(); 97 browser_->window()->HideInstant();
99 if (chrome::GetActiveWebContents(browser_)) 98 if (TabContents* preview_contents = instant_->GetPreviewContents())
100 chrome::GetActiveWebContents(browser_)->WasRestored(); 99 preview_contents->web_contents()->WasHidden();
101 if (instant_->GetPreviewContents())
102 instant_->GetPreviewContents()->web_contents()->WasHidden();
103 } 100 }
104 101
105 void BrowserInstantController::CommitInstant(TabContents* preview_contents) { 102 void BrowserInstantController::CommitInstant(TabContents* preview_contents) {
106 TabContents* tab_contents = chrome::GetActiveTabContents(browser_); 103 TabContents* tab_contents = chrome::GetActiveTabContents(browser_);
107 int index = browser_->tab_strip_model()->GetIndexOfTabContents(tab_contents); 104 int index = browser_->tab_strip_model()->GetIndexOfTabContents(tab_contents);
108 DCHECK_NE(TabStripModel::kNoTab, index); 105 DCHECK_NE(TabStripModel::kNoTab, index);
109 // TabStripModel takes ownership of preview_contents. 106 // TabStripModel takes ownership of preview_contents.
110 browser_->tab_strip_model()->ReplaceTabContentsAt(index, preview_contents); 107 browser_->tab_strip_model()->ReplaceTabContentsAt(index, preview_contents);
111 // InstantUnloadHandler takes ownership of tab_contents. 108 // InstantUnloadHandler takes ownership of tab_contents.
112 instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); 109 instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 int type, 144 int type,
148 const content::NotificationSource& source, 145 const content::NotificationSource& source,
149 const content::NotificationDetails& details) { 146 const content::NotificationDetails& details) {
150 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); 147 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED);
151 const std::string& pref_name = 148 const std::string& pref_name =
152 *content::Details<std::string>(details).ptr(); 149 *content::Details<std::string>(details).ptr();
153 DCHECK(pref_name == prefs::kInstantEnabled); 150 DCHECK(pref_name == prefs::kInstantEnabled);
154 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || 151 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() ||
155 !InstantController::IsEnabled(browser_->profile())) { 152 !InstantController::IsEnabled(browser_->profile())) {
156 if (instant()) { 153 if (instant()) {
157 instant()->DestroyPreviewContents();
158 instant_.reset(); 154 instant_.reset();
159 instant_unload_handler_.reset(); 155 instant_unload_handler_.reset();
160 } 156 }
161 } else { 157 } else {
162 CreateInstantIfNecessary(); 158 CreateInstantIfNecessary();
163 } 159 }
164 } 160 }
165 161
166 //////////////////////////////////////////////////////////////////////////////// 162 ////////////////////////////////////////////////////////////////////////////////
167 // BrowserInstantController, TabStripModelObserver implementation: 163 // BrowserInstantController, TabStripModelObserver implementation:
168 164
169 void BrowserInstantController::TabDeactivated(TabContents* contents) { 165 void BrowserInstantController::TabDeactivated(TabContents* contents) {
170 if (instant()) 166 if (instant())
171 instant()->Hide(); 167 instant()->Hide();
172 } 168 }
173 169
174 //////////////////////////////////////////////////////////////////////////////// 170 ////////////////////////////////////////////////////////////////////////////////
175 // BrowserInstantController, private: 171 // BrowserInstantController, private:
176 172
177 void BrowserInstantController::CreateInstantIfNecessary() { 173 void BrowserInstantController::CreateInstantIfNecessary() {
178 if (browser_->is_type_tabbed() && 174 if (browser_->is_type_tabbed() &&
179 InstantController::IsEnabled(browser_->profile()) && 175 InstantController::IsEnabled(browser_->profile()) &&
180 !browser_->profile()->IsOffTheRecord()) { 176 !browser_->profile()->IsOffTheRecord()) {
181 instant_.reset(new InstantController(this, InstantController::INSTANT)); 177 instant_.reset(new InstantController(this, InstantController::INSTANT));
182 instant_unload_handler_.reset(new InstantUnloadHandler(browser_)); 178 instant_unload_handler_.reset(new InstantUnloadHandler(browser_));
183 } 179 }
184 } 180 }
185 181
186 } // namespace chrome 182 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698