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

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

Issue 10905301: Switch CoreTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/instant/instant_loader.h" 5 #include "chrome/browser/instant/instant_loader.h"
6 6
7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
8 #include "chrome/browser/history/history_types.h" 8 #include "chrome/browser/history/history_types.h"
9 #include "chrome/browser/instant/instant_loader_delegate.h" 9 #include "chrome/browser/instant/instant_loader_delegate.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 24 matching lines...) Expand all
35 explicit WebContentsDelegateImpl(InstantLoader* loader); 35 explicit WebContentsDelegateImpl(InstantLoader* loader);
36 36
37 bool is_pointer_down_from_activate() const { 37 bool is_pointer_down_from_activate() const {
38 return is_pointer_down_from_activate_; 38 return is_pointer_down_from_activate_;
39 } 39 }
40 40
41 // ConstrainedWindowTabHelperDelegate: 41 // ConstrainedWindowTabHelperDelegate:
42 virtual bool ShouldFocusConstrainedWindow() OVERRIDE; 42 virtual bool ShouldFocusConstrainedWindow() OVERRIDE;
43 43
44 // CoreTabHelperDelegate: 44 // CoreTabHelperDelegate:
45 virtual void SwapTabContents(TabContents* old_tc, 45 virtual void SwapTabContents(content::WebContents* old_contents,
46 TabContents* new_tc) OVERRIDE; 46 content::WebContents* new_contents) OVERRIDE;
47 47
48 // content::WebContentsDelegate: 48 // content::WebContentsDelegate:
49 virtual bool ShouldSuppressDialogs() OVERRIDE; 49 virtual bool ShouldSuppressDialogs() OVERRIDE;
50 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; 50 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
51 virtual void LostCapture() OVERRIDE; 51 virtual void LostCapture() OVERRIDE;
52 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; 52 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
53 virtual bool CanDownload(content::RenderViewHost* render_view_host, 53 virtual bool CanDownload(content::RenderViewHost* render_view_host,
54 int request_id, 54 int request_id,
55 const std::string& request_method) OVERRIDE; 55 const std::string& request_method) OVERRIDE;
56 virtual void HandleMouseUp() OVERRIDE; 56 virtual void HandleMouseUp() OVERRIDE;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusConstrainedWindow() { 100 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusConstrainedWindow() {
101 // Return false so that constrained windows are not initially focused. If we 101 // Return false so that constrained windows are not initially focused. If we
102 // did otherwise the preview would prematurely get committed when focus goes 102 // did otherwise the preview would prematurely get committed when focus goes
103 // to the constrained window. 103 // to the constrained window.
104 return false; 104 return false;
105 } 105 }
106 106
107 void InstantLoader::WebContentsDelegateImpl::SwapTabContents( 107 void InstantLoader::WebContentsDelegateImpl::SwapTabContents(
108 TabContents* old_tc, 108 content::WebContents* old_contents,
109 TabContents* new_tc) { 109 content::WebContents* new_contents) {
110 // If this is being called, something is swapping in to our 110 // If this is being called, something is swapping in to our
111 // |preview_contents_| before we've added it to the tab strip. 111 // |preview_contents_| before we've added it to the tab strip.
112 loader_->ReplacePreviewContents(old_tc, new_tc); 112 loader_->ReplacePreviewContents(old_contents, new_contents);
113 } 113 }
114 114
115 bool InstantLoader::WebContentsDelegateImpl::ShouldSuppressDialogs() { 115 bool InstantLoader::WebContentsDelegateImpl::ShouldSuppressDialogs() {
116 // Any message shown during Instant cancels Instant, so we suppress them. 116 // Any message shown during Instant cancels Instant, so we suppress them.
117 return true; 117 return true;
118 } 118 }
119 119
120 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { 120 bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() {
121 return false; 121 return false;
122 } 122 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 void InstantLoader::SetupPreviewContents() { 342 void InstantLoader::SetupPreviewContents() {
343 content::WebContents* new_contents = preview_contents_->web_contents(); 343 content::WebContents* new_contents = preview_contents_->web_contents();
344 preview_delegate_.reset(new WebContentsDelegateImpl(this)); 344 preview_delegate_.reset(new WebContentsDelegateImpl(this));
345 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); 345 WebContentsDelegateImpl* new_delegate = preview_delegate_.get();
346 new_contents->SetDelegate(new_delegate); 346 new_contents->SetDelegate(new_delegate);
347 347
348 // Disable popups and such (mainly to avoid losing focus and reverting the 348 // Disable popups and such (mainly to avoid losing focus and reverting the
349 // preview prematurely). 349 // preview prematurely).
350 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 350 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
351 preview_contents_->constrained_window_tab_helper()->set_delegate( 351 preview_contents_->constrained_window_tab_helper()->
352 new_delegate); 352 set_delegate(new_delegate);
353 preview_contents_->content_settings()->SetPopupsBlocked(true); 353 preview_contents_->content_settings()->SetPopupsBlocked(true);
354 preview_contents_->core_tab_helper()->set_delegate(new_delegate); 354 CoreTabHelper::FromWebContents(new_contents)->set_delegate(new_delegate);
355 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 355 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
356 tg->set_enabled(false); 356 tg->set_enabled(false);
357 357
358 #if defined(OS_MACOSX) 358 #if defined(OS_MACOSX)
359 // If |preview_contents_| does not currently have a RWHV, we will call 359 // If |preview_contents_| does not currently have a RWHV, we will call
360 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED 360 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED
361 // notification. 361 // notification.
362 if (content::RenderWidgetHostView* rwhv = 362 if (content::RenderWidgetHostView* rwhv =
363 new_contents->GetRenderWidgetHostView()) 363 new_contents->GetRenderWidgetHostView())
364 rwhv->SetTakesFocusOnlyOnMouseDown(true); 364 rwhv->SetTakesFocusOnlyOnMouseDown(true);
365 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 365 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
366 content::Source<content::NavigationController>( 366 content::Source<content::NavigationController>(
367 &new_contents->GetController())); 367 &new_contents->GetController()));
368 #endif 368 #endif
369 } 369 }
370 370
371 void InstantLoader::CleanupPreviewContents() { 371 void InstantLoader::CleanupPreviewContents() {
372 content::WebContents* old_contents = preview_contents_->web_contents(); 372 content::WebContents* old_contents = preview_contents_->web_contents();
373 old_contents->SetDelegate(NULL); 373 old_contents->SetDelegate(NULL);
374 preview_delegate_.reset(); 374 preview_delegate_.reset();
375 375
376 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false); 376 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false);
377 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL); 377 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL);
378 preview_contents_->content_settings()->SetPopupsBlocked(false); 378 preview_contents_->content_settings()->SetPopupsBlocked(false);
379 preview_contents_->core_tab_helper()->set_delegate(NULL); 379 CoreTabHelper::FromWebContents(old_contents)->set_delegate(NULL);
380 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 380 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
381 tg->set_enabled(true); 381 tg->set_enabled(true);
382 382
383 #if defined(OS_MACOSX) 383 #if defined(OS_MACOSX)
384 if (content::RenderWidgetHostView* rwhv = 384 if (content::RenderWidgetHostView* rwhv =
385 old_contents->GetRenderWidgetHostView()) 385 old_contents->GetRenderWidgetHostView())
386 rwhv->SetTakesFocusOnlyOnMouseDown(false); 386 rwhv->SetTakesFocusOnlyOnMouseDown(false);
387 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 387 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
388 content::Source<content::NavigationController>( 388 content::Source<content::NavigationController>(
389 &old_contents->GetController())); 389 &old_contents->GetController()));
390 #endif 390 #endif
391 } 391 }
392 392
393 void InstantLoader::ReplacePreviewContents(TabContents* old_tc, 393 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents,
394 TabContents* new_tc) { 394 content::WebContents* new_contents) {
395 DCHECK(old_tc == preview_contents_); 395 DCHECK(old_contents == preview_contents_->web_contents());
396 CleanupPreviewContents(); 396 CleanupPreviewContents();
397 // We release here without deleting so that the caller still has the 397 // We release here without deleting so that the caller still has the
398 // responsibility for deleting the TabContents. 398 // responsibility for deleting the TabContents.
399 ignore_result(preview_contents_.release()); 399 ignore_result(preview_contents_.release());
400 preview_contents_.reset(new_tc); 400 preview_contents_.reset(TabContents::FromWebContents(new_contents));
401 SetupPreviewContents(); 401 SetupPreviewContents();
402 loader_delegate_->SwappedTabContents(this); 402 loader_delegate_->SwappedTabContents(this);
403 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698