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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 10539064: TabContentsWrapper -> TabContents, part 18. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/autocomplete/autocomplete_match.h" 12 #include "chrome/browser/autocomplete/autocomplete_match.h"
13 #include "chrome/browser/instant/instant_delegate.h" 13 #include "chrome/browser/instant/instant_delegate.h"
14 #include "chrome/browser/instant/instant_loader.h" 14 #include "chrome/browser/instant/instant_loader.h"
15 #include "chrome/browser/platform_util.h" 15 #include "chrome/browser/platform_util.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
19 #include "chrome/browser/search_engines/template_url_service.h" 19 #include "chrome/browser/search_engines/template_url_service.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 20 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 21 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/render_widget_host_view.h" 27 #include "content/public/browser/render_widget_host_view.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 29
30 #if defined(TOOLKIT_VIEWS) 30 #if defined(TOOLKIT_VIEWS)
31 #include "ui/views/focus/focus_manager.h" 31 #include "ui/views/focus/focus_manager.h"
32 #include "ui/views/view.h" 32 #include "ui/views/view.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool verbatim, 96 bool verbatim,
97 string16* suggested_text) { 97 string16* suggested_text) {
98 suggested_text->clear(); 98 suggested_text->clear();
99 99
100 is_out_of_date_ = false; 100 is_out_of_date_ = false;
101 commit_on_mouse_up_ = false; 101 commit_on_mouse_up_ = false;
102 last_transition_type_ = match.transition; 102 last_transition_type_ = match.transition;
103 last_url_ = match.destination_url; 103 last_url_ = match.destination_url;
104 last_user_text_ = user_text; 104 last_user_text_ = user_text;
105 105
106 TabContentsWrapper* tab_contents = delegate_->GetInstantHostTabContents(); 106 TabContents* tab_contents = delegate_->GetInstantHostTabContents();
107 if (!tab_contents) { 107 if (!tab_contents) {
108 Hide(); 108 Hide();
109 return false; 109 return false;
110 } 110 }
111 111
112 Profile* profile = tab_contents->profile(); 112 Profile* profile = tab_contents->profile();
113 const TemplateURL* template_url = match.GetTemplateURL(profile); 113 const TemplateURL* template_url = match.GetTemplateURL(profile);
114 const TemplateURL* default_t_url = 114 const TemplateURL* default_t_url =
115 TemplateURLServiceFactory::GetForProfile(profile) 115 TemplateURLServiceFactory::GetForProfile(profile)
116 ->GetDefaultSearchProvider(); 116 ->GetDefaultSearchProvider();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 181 }
182 182
183 bool InstantController::PrepareForCommit() { 183 bool InstantController::PrepareForCommit() {
184 if (is_out_of_date_ || !loader_.get()) 184 if (is_out_of_date_ || !loader_.get())
185 return false; 185 return false;
186 186
187 // If we are in the visible (INSTANT) mode, return the status of the preview. 187 // If we are in the visible (INSTANT) mode, return the status of the preview.
188 if (mode_ == INSTANT) 188 if (mode_ == INSTANT)
189 return IsCurrent(); 189 return IsCurrent();
190 190
191 TabContentsWrapper* tab_contents = delegate_->GetInstantHostTabContents(); 191 TabContents* tab_contents = delegate_->GetInstantHostTabContents();
192 if (!tab_contents) 192 if (!tab_contents)
193 return false; 193 return false;
194 194
195 const TemplateURL* template_url = 195 const TemplateURL* template_url =
196 TemplateURLServiceFactory::GetForProfile(tab_contents->profile()) 196 TemplateURLServiceFactory::GetForProfile(tab_contents->profile())
197 ->GetDefaultSearchProvider(); 197 ->GetDefaultSearchProvider();
198 if (!IsValidInstantTemplateURL(template_url) || 198 if (!IsValidInstantTemplateURL(template_url) ||
199 loader_->template_url_id() != template_url->id() || 199 loader_->template_url_id() != template_url->id() ||
200 loader_->IsNavigationPending() || 200 loader_->IsNavigationPending() ||
201 loader_->is_determining_if_page_supports_instant()) { 201 loader_->is_determining_if_page_supports_instant()) {
202 return false; 202 return false;
203 } 203 }
204 204
205 // In the SUGGEST and HIDDEN modes, we must have sent an Update() by now, so 205 // In the SUGGEST and HIDDEN modes, we must have sent an Update() by now, so
206 // check if the loader failed to process it. 206 // check if the loader failed to process it.
207 if ((mode_ == SUGGEST || mode_ == HIDDEN) 207 if ((mode_ == SUGGEST || mode_ == HIDDEN)
208 && (!loader_->ready() || !loader_->http_status_ok())) { 208 && (!loader_->ready() || !loader_->http_status_ok())) {
209 return false; 209 return false;
210 } 210 }
211 211
212 // Ignore the suggested text, as we are about to commit the verbatim query. 212 // Ignore the suggested text, as we are about to commit the verbatim query.
213 string16 suggested_text; 213 string16 suggested_text;
214 UpdateLoader(tab_contents, template_url, last_url_, last_transition_type_, 214 UpdateLoader(tab_contents, template_url, last_url_, last_transition_type_,
215 last_user_text_, true, &suggested_text); 215 last_user_text_, true, &suggested_text);
216 return true; 216 return true;
217 } 217 }
218 218
219 TabContentsWrapper* InstantController::CommitCurrentPreview( 219 TabContents* InstantController::CommitCurrentPreview(InstantCommitType type) {
220 InstantCommitType type) {
221 DCHECK(loader_.get()); 220 DCHECK(loader_.get());
222 TabContentsWrapper* tab_contents = delegate_->GetInstantHostTabContents(); 221 TabContents* tab_contents = delegate_->GetInstantHostTabContents();
223 DCHECK(tab_contents); 222 DCHECK(tab_contents);
224 TabContentsWrapper* preview = ReleasePreviewContents(type, tab_contents); 223 TabContents* preview = ReleasePreviewContents(type, tab_contents);
225 preview->web_contents()->GetController().CopyStateFromAndPrune( 224 preview->web_contents()->GetController().CopyStateFromAndPrune(
226 &tab_contents->web_contents()->GetController()); 225 &tab_contents->web_contents()->GetController());
227 delegate_->CommitInstant(preview); 226 delegate_->CommitInstant(preview);
228 CompleteRelease(preview); 227 CompleteRelease(preview);
229 return preview; 228 return preview;
230 } 229 }
231 230
232 bool InstantController::CommitIfCurrent() { 231 bool InstantController::CommitIfCurrent() {
233 if (IsCurrent()) { 232 if (IsCurrent()) {
234 CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); 233 CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (view_gaining_focus_ancestor) { 321 if (view_gaining_focus_ancestor) {
323 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); 322 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST);
324 return; 323 return;
325 } 324 }
326 325
327 DestroyPreviewContents(); 326 DestroyPreviewContents();
328 } 327 }
329 #endif 328 #endif
330 329
331 void InstantController::OnAutocompleteGotFocus() { 330 void InstantController::OnAutocompleteGotFocus() {
332 TabContentsWrapper* tab_contents = delegate_->GetInstantHostTabContents(); 331 TabContents* tab_contents = delegate_->GetInstantHostTabContents();
333 if (!tab_contents) 332 if (!tab_contents)
334 return; 333 return;
335 334
336 const TemplateURL* template_url = 335 const TemplateURL* template_url =
337 TemplateURLServiceFactory::GetForProfile(tab_contents->profile()) 336 TemplateURLServiceFactory::GetForProfile(tab_contents->profile())
338 ->GetDefaultSearchProvider(); 337 ->GetDefaultSearchProvider();
339 if (!IsValidInstantTemplateURL(template_url)) 338 if (!IsValidInstantTemplateURL(template_url))
340 return; 339 return;
341 340
342 if (!loader_.get() || loader_->template_url_id() != template_url->id()) 341 if (!loader_.get() || loader_->template_url_id() != template_url->id())
343 loader_.reset(new InstantLoader(this, template_url->id(), std::string())); 342 loader_.reset(new InstantLoader(this, template_url->id(), std::string()));
344 loader_->MaybeLoadInstantURL(tab_contents, template_url); 343 loader_->MaybeLoadInstantURL(tab_contents, template_url);
345 } 344 }
346 345
347 TabContentsWrapper* InstantController::ReleasePreviewContents( 346 TabContents* InstantController::ReleasePreviewContents(
348 InstantCommitType type, 347 InstantCommitType type,
349 TabContentsWrapper* current_tab) { 348 TabContents* current_tab) {
350 if (!loader_.get()) 349 if (!loader_.get())
351 return NULL; 350 return NULL;
352 351
353 TabContentsWrapper* tab = loader_->ReleasePreviewContents(type, current_tab); 352 TabContents* tab = loader_->ReleasePreviewContents(type, current_tab);
354 ClearBlacklist(); 353 ClearBlacklist();
355 is_out_of_date_ = true; 354 is_out_of_date_ = true;
356 is_displayable_ = false; 355 is_displayable_ = false;
357 commit_on_mouse_up_ = false; 356 commit_on_mouse_up_ = false;
358 omnibox_bounds_ = gfx::Rect(); 357 omnibox_bounds_ = gfx::Rect();
359 loader_.reset(); 358 loader_.reset();
360 return tab; 359 return tab;
361 } 360 }
362 361
363 void InstantController::CompleteRelease(TabContentsWrapper* tab) { 362 void InstantController::CompleteRelease(TabContents* tab) {
364 tab->blocked_content_tab_helper()->SetAllContentsBlocked(false); 363 tab->blocked_content_tab_helper()->SetAllContentsBlocked(false);
365 } 364 }
366 365
367 TabContentsWrapper* InstantController::GetPreviewContents() const { 366 TabContents* InstantController::GetPreviewContents() const {
368 return loader_.get() ? loader_->preview_contents() : NULL; 367 return loader_.get() ? loader_->preview_contents() : NULL;
369 } 368 }
370 369
371 void InstantController::InstantStatusChanged(InstantLoader* loader) { 370 void InstantController::InstantStatusChanged(InstantLoader* loader) {
372 DCHECK(loader_.get()); 371 DCHECK(loader_.get());
373 UpdateIsDisplayable(); 372 UpdateIsDisplayable();
374 } 373 }
375 374
376 void InstantController::SetSuggestedTextFor( 375 void InstantController::SetSuggestedTextFor(
377 InstantLoader* loader, 376 InstantLoader* loader,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 delegate_->HideInstant(); 440 delegate_->HideInstant();
442 } else { 441 } else {
443 delegate_->ShowInstant(loader_->preview_contents()); 442 delegate_->ShowInstant(loader_->preview_contents());
444 content::NotificationService::current()->Notify( 443 content::NotificationService::current()->Notify(
445 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, 444 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
446 content::Source<InstantController>(this), 445 content::Source<InstantController>(this),
447 content::NotificationService::NoDetails()); 446 content::NotificationService::NoDetails());
448 } 447 }
449 } 448 }
450 449
451 void InstantController::UpdateLoader(TabContentsWrapper* tab_contents, 450 void InstantController::UpdateLoader(TabContents* tab_contents,
452 const TemplateURL* template_url, 451 const TemplateURL* template_url,
453 const GURL& url, 452 const GURL& url,
454 content::PageTransition transition_type, 453 content::PageTransition transition_type,
455 const string16& user_text, 454 const string16& user_text,
456 bool verbatim, 455 bool verbatim,
457 string16* suggested_text) { 456 string16* suggested_text) {
458 if (mode_ == INSTANT) 457 if (mode_ == INSTANT)
459 loader_->SetOmniboxBounds(omnibox_bounds_); 458 loader_->SetOmniboxBounds(omnibox_bounds_);
460 loader_->Update(tab_contents, template_url, url, transition_type, user_text, 459 loader_->Update(tab_contents, template_url, url, transition_type, user_text,
461 verbatim, suggested_text); 460 verbatim, suggested_text);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 if (!weak_factory_.HasWeakPtrs()) { 497 if (!weak_factory_.HasWeakPtrs()) {
499 MessageLoop::current()->PostTask( 498 MessageLoop::current()->PostTask(
500 FROM_HERE, base::Bind(&InstantController::DestroyLoaders, 499 FROM_HERE, base::Bind(&InstantController::DestroyLoaders,
501 weak_factory_.GetWeakPtr())); 500 weak_factory_.GetWeakPtr()));
502 } 501 }
503 } 502 }
504 503
505 void InstantController::DestroyLoaders() { 504 void InstantController::DestroyLoaders() {
506 loaders_to_destroy_.reset(); 505 loaders_to_destroy_.reset();
507 } 506 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698