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

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: rebase 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
« no previous file with comments | « chrome/browser/instant/instant_loader.h ('k') | chrome/browser/prerender/prerender_manager.cc » ('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_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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 void InstantLoader::SetupPreviewContents() { 349 void InstantLoader::SetupPreviewContents() {
350 content::WebContents* new_contents = preview_contents_->web_contents(); 350 content::WebContents* new_contents = preview_contents_->web_contents();
351 preview_delegate_.reset(new WebContentsDelegateImpl(this)); 351 preview_delegate_.reset(new WebContentsDelegateImpl(this));
352 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); 352 WebContentsDelegateImpl* new_delegate = preview_delegate_.get();
353 new_contents->SetDelegate(new_delegate); 353 new_contents->SetDelegate(new_delegate);
354 354
355 // Disable popups and such (mainly to avoid losing focus and reverting the 355 // Disable popups and such (mainly to avoid losing focus and reverting the
356 // preview prematurely). 356 // preview prematurely).
357 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 357 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
358 preview_contents_->constrained_window_tab_helper()->set_delegate( 358 preview_contents_->constrained_window_tab_helper()->
359 new_delegate); 359 set_delegate(new_delegate);
360 preview_contents_->content_settings()->SetPopupsBlocked(true); 360 preview_contents_->content_settings()->SetPopupsBlocked(true);
361 preview_contents_->core_tab_helper()->set_delegate(new_delegate); 361 CoreTabHelper::FromWebContents(new_contents)->set_delegate(new_delegate);
362 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 362 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
363 tg->set_enabled(false); 363 tg->set_enabled(false);
364 364
365 #if defined(OS_MACOSX) 365 #if defined(OS_MACOSX)
366 // If |preview_contents_| does not currently have a RWHV, we will call 366 // If |preview_contents_| does not currently have a RWHV, we will call
367 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED 367 // SetTakesFocusOnlyOnMouseDown() as a result of the RENDER_VIEW_HOST_CHANGED
368 // notification. 368 // notification.
369 if (content::RenderWidgetHostView* rwhv = 369 if (content::RenderWidgetHostView* rwhv =
370 new_contents->GetRenderWidgetHostView()) 370 new_contents->GetRenderWidgetHostView())
371 rwhv->SetTakesFocusOnlyOnMouseDown(true); 371 rwhv->SetTakesFocusOnlyOnMouseDown(true);
372 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 372 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
373 content::Source<content::NavigationController>( 373 content::Source<content::NavigationController>(
374 &new_contents->GetController())); 374 &new_contents->GetController()));
375 #endif 375 #endif
376 } 376 }
377 377
378 void InstantLoader::CleanupPreviewContents() { 378 void InstantLoader::CleanupPreviewContents() {
379 content::WebContents* old_contents = preview_contents_->web_contents(); 379 content::WebContents* old_contents = preview_contents_->web_contents();
380 old_contents->SetDelegate(NULL); 380 old_contents->SetDelegate(NULL);
381 preview_delegate_.reset(); 381 preview_delegate_.reset();
382 382
383 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false); 383 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false);
384 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL); 384 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL);
385 preview_contents_->content_settings()->SetPopupsBlocked(false); 385 preview_contents_->content_settings()->SetPopupsBlocked(false);
386 preview_contents_->core_tab_helper()->set_delegate(NULL); 386 CoreTabHelper::FromWebContents(old_contents)->set_delegate(NULL);
387 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) 387 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator())
388 tg->set_enabled(true); 388 tg->set_enabled(true);
389 389
390 #if defined(OS_MACOSX) 390 #if defined(OS_MACOSX)
391 if (content::RenderWidgetHostView* rwhv = 391 if (content::RenderWidgetHostView* rwhv =
392 old_contents->GetRenderWidgetHostView()) 392 old_contents->GetRenderWidgetHostView())
393 rwhv->SetTakesFocusOnlyOnMouseDown(false); 393 rwhv->SetTakesFocusOnlyOnMouseDown(false);
394 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 394 registrar_.Remove(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
395 content::Source<content::NavigationController>( 395 content::Source<content::NavigationController>(
396 &old_contents->GetController())); 396 &old_contents->GetController()));
397 #endif 397 #endif
398 } 398 }
399 399
400 void InstantLoader::ReplacePreviewContents(TabContents* old_tc, 400 void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents,
401 TabContents* new_tc) { 401 content::WebContents* new_contents) {
402 DCHECK(old_tc == preview_contents_); 402 DCHECK(old_contents == preview_contents_->web_contents());
403 CleanupPreviewContents(); 403 CleanupPreviewContents();
404 // We release here without deleting so that the caller still has the 404 // We release here without deleting so that the caller still has the
405 // responsibility for deleting the TabContents. 405 // responsibility for deleting the TabContents.
406 ignore_result(preview_contents_.release()); 406 ignore_result(preview_contents_.release());
407 preview_contents_.reset(new_tc); 407 preview_contents_.reset(TabContents::FromWebContents(new_contents));
408 SetupPreviewContents(); 408 SetupPreviewContents();
409 loader_delegate_->SwappedTabContents(this); 409 loader_delegate_->SwappedTabContents(this);
410 } 410 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_loader.h ('k') | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698