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

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

Issue 10978016: Remove two functions on WebContentsDelegate which didn't belong in content. They were only called f… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits and fixed prerender browser tests Created 8 years, 2 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_contents.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_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"
9 #include "chrome/browser/instant/instant_loader_delegate.h" 8 #include "chrome/browser/instant/instant_loader_delegate.h"
10 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/tab_contents/thumbnail_generator.h" 10 #include "chrome/browser/tab_contents/thumbnail_generator.h"
12 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 11 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
13 #include "chrome/browser/ui/constrained_window_tab_helper.h" 12 #include "chrome/browser/ui/constrained_window_tab_helper.h"
14 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" 13 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" 15 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
18 #include "chrome/common/render_messages.h" 17 #include "chrome/common/render_messages.h"
19 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/render_widget_host_view.h" 22 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_delegate.h" 24 #include "content/public/browser/web_contents_delegate.h"
26 25
26 namespace {
27
28 static int kUserDataKey;
sreeram 2012/09/25 22:51:48 I don't think static adds any value, since this is
29
30 class InstantLoaderUserData : public base::SupportsUserData::Data {
31 public:
32 explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {}
33 virtual ~InstantLoaderUserData() {}
34
35 InstantLoader* loader() const { return loader_; }
36
37 private:
38 InstantLoader* loader_;
39 DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData);
sreeram 2012/09/25 22:51:48 This (and line 109) could instead be DISALLOW_IMPL
40 };
41
42 }
43
27 // WebContentsDelegateImpl ----------------------------------------------------- 44 // WebContentsDelegateImpl -----------------------------------------------------
28 45
29 class InstantLoader::WebContentsDelegateImpl 46 class InstantLoader::WebContentsDelegateImpl
30 : public ConstrainedWindowTabHelperDelegate, 47 : public ConstrainedWindowTabHelperDelegate,
31 public CoreTabHelperDelegate, 48 public CoreTabHelperDelegate,
32 public content::WebContentsDelegate, 49 public content::WebContentsDelegate,
33 public content::WebContentsObserver { 50 public content::WebContentsObserver {
34 public: 51 public:
35 explicit WebContentsDelegateImpl(InstantLoader* loader); 52 explicit WebContentsDelegateImpl(InstantLoader* loader);
36 53
(...skipping 15 matching lines...) Expand all
52 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; 69 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
53 virtual bool CanDownload(content::RenderViewHost* render_view_host, 70 virtual bool CanDownload(content::RenderViewHost* render_view_host,
54 int request_id, 71 int request_id,
55 const std::string& request_method) OVERRIDE; 72 const std::string& request_method) OVERRIDE;
56 virtual void HandleMouseUp() OVERRIDE; 73 virtual void HandleMouseUp() OVERRIDE;
57 virtual void HandlePointerActivate() OVERRIDE; 74 virtual void HandlePointerActivate() OVERRIDE;
58 virtual void HandleGestureBegin() OVERRIDE; 75 virtual void HandleGestureBegin() OVERRIDE;
59 virtual void HandleGestureEnd() OVERRIDE; 76 virtual void HandleGestureEnd() OVERRIDE;
60 virtual void DragEnded() OVERRIDE; 77 virtual void DragEnded() OVERRIDE;
61 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; 78 virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
62 virtual bool ShouldAddNavigationToHistory(
63 const history::HistoryAddPageArgs& add_page_args,
64 content::NavigationType navigation_type) OVERRIDE;
65 79
66 // content::WebContentsObserver: 80 // content::WebContentsObserver:
67 virtual void DidFinishLoad( 81 virtual void DidFinishLoad(
68 int64 frame_id, 82 int64 frame_id,
69 const GURL& validated_url, 83 const GURL& validated_url,
70 bool is_main_frame, 84 bool is_main_frame,
71 content::RenderViewHost* render_view_host) OVERRIDE; 85 content::RenderViewHost* render_view_host) OVERRIDE;
72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
73 87
74 private: 88 private:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // If the user drags, we won't get a mouse up (at least on Linux). Commit the 176 // If the user drags, we won't get a mouse up (at least on Linux). Commit the
163 // Instant result when the drag ends, so that during the drag the page won't 177 // Instant result when the drag ends, so that during the drag the page won't
164 // move around. 178 // move around.
165 CommitFromPointerReleaseIfNecessary(); 179 CommitFromPointerReleaseIfNecessary();
166 } 180 }
167 181
168 bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { 182 bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) {
169 return false; 183 return false;
170 } 184 }
171 185
172 bool InstantLoader::WebContentsDelegateImpl::ShouldAddNavigationToHistory(
173 const history::HistoryAddPageArgs& add_page_args,
174 content::NavigationType navigation_type) {
175 loader_->last_navigation_ = add_page_args;
176 return false;
177 }
178
179 void InstantLoader::WebContentsDelegateImpl::DidFinishLoad( 186 void InstantLoader::WebContentsDelegateImpl::DidFinishLoad(
180 int64 frame_id, 187 int64 frame_id,
181 const GURL& validated_url, 188 const GURL& validated_url,
182 bool is_main_frame, 189 bool is_main_frame,
183 content::RenderViewHost* render_view_host) { 190 content::RenderViewHost* render_view_host) {
184 if (is_main_frame) { 191 if (is_main_frame) {
185 if (!loader_->supports_instant_) 192 if (!loader_->supports_instant_)
186 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); 193 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
187 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); 194 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_);
188 } 195 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 Observe(NULL); 281 Observe(NULL);
275 } 282 }
276 283
277 loader_->supports_instant_ = supports_instant; 284 loader_->supports_instant_ = supports_instant;
278 loader_->loader_delegate_->InstantSupportDetermined(loader_, 285 loader_->loader_delegate_->InstantSupportDetermined(loader_,
279 supports_instant); 286 supports_instant);
280 } 287 }
281 288
282 // InstantLoader --------------------------------------------------------------- 289 // InstantLoader ---------------------------------------------------------------
283 290
291 // static
292 InstantLoader* InstantLoader::FromWebContents(
293 content::WebContents* web_contents) {
294 InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>(
295 web_contents->GetUserData(&kUserDataKey));
296 return data ? data->loader() : NULL;
297 }
298
284 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, 299 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate,
285 const std::string& instant_url, 300 const std::string& instant_url,
286 const TabContents* tab_contents) 301 const TabContents* tab_contents)
287 : loader_delegate_(delegate), 302 : loader_delegate_(delegate),
288 preview_contents_( 303 preview_contents_(
289 TabContents::Factory::CreateTabContents( 304 TabContents::Factory::CreateTabContents(
290 content::WebContents::CreateWithSessionStorage( 305 content::WebContents::CreateWithSessionStorage(
291 tab_contents->profile(), NULL, MSG_ROUTING_NONE, 306 tab_contents->profile(), NULL, MSG_ROUTING_NONE,
292 tab_contents->web_contents(), 307 tab_contents->web_contents(),
293 tab_contents->web_contents()->GetController(). 308 tab_contents->web_contents()->GetController().
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 results)); 348 results));
334 } 349 }
335 350
336 void InstantLoader::OnUpOrDownKeyPressed(int count) { 351 void InstantLoader::OnUpOrDownKeyPressed(int count) {
337 content::RenderViewHost* rvh = 352 content::RenderViewHost* rvh =
338 preview_contents_->web_contents()->GetRenderViewHost(); 353 preview_contents_->web_contents()->GetRenderViewHost();
339 rvh->Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(rvh->GetRoutingID(), 354 rvh->Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(rvh->GetRoutingID(),
340 count)); 355 count));
341 } 356 }
342 357
358 void InstantLoader::DidNavigate(
359 const history::HistoryAddPageArgs& add_page_args) {
360 last_navigation_ = add_page_args;
361 }
362
343 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type, 363 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type,
344 const string16& text) { 364 const string16& text) {
345 content::RenderViewHost* rvh = 365 content::RenderViewHost* rvh =
346 preview_contents_->web_contents()->GetRenderViewHost(); 366 preview_contents_->web_contents()->GetRenderViewHost();
347 if (type == INSTANT_COMMIT_PRESSED_ENTER) 367 if (type == INSTANT_COMMIT_PRESSED_ENTER)
348 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text)); 368 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text));
349 else 369 else
350 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text)); 370 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text));
351 CleanupPreviewContents(); 371 CleanupPreviewContents();
372 preview_contents_->web_contents()->RemoveUserData(&kUserDataKey);
352 return preview_contents_.release(); 373 return preview_contents_.release();
353 } 374 }
354 375
355 bool InstantLoader::IsPointerDownFromActivate() const { 376 bool InstantLoader::IsPointerDownFromActivate() const {
356 return preview_delegate_->is_pointer_down_from_activate(); 377 return preview_delegate_->is_pointer_down_from_activate();
357 } 378 }
358 379
359 void InstantLoader::Observe(int type, 380 void InstantLoader::Observe(int type,
360 const content::NotificationSource& source, 381 const content::NotificationSource& source,
361 const content::NotificationDetails& details) { 382 const content::NotificationDetails& details) {
362 #if defined(OS_MACOSX) 383 #if defined(OS_MACOSX)
363 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { 384 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) {
364 if (content::RenderWidgetHostView* rwhv = 385 if (content::RenderWidgetHostView* rwhv =
365 preview_contents_->web_contents()->GetRenderWidgetHostView()) 386 preview_contents_->web_contents()->GetRenderWidgetHostView())
366 rwhv->SetTakesFocusOnlyOnMouseDown(true); 387 rwhv->SetTakesFocusOnlyOnMouseDown(true);
367 return; 388 return;
368 } 389 }
369 NOTREACHED(); 390 NOTREACHED();
370 #endif 391 #endif
371 } 392 }
372 393
373 void InstantLoader::SetupPreviewContents() { 394 void InstantLoader::SetupPreviewContents() {
374 content::WebContents* new_contents = preview_contents_->web_contents(); 395 content::WebContents* new_contents = preview_contents_->web_contents();
396 new_contents->SetUserData(&kUserDataKey, new InstantLoaderUserData(this));
375 preview_delegate_.reset(new WebContentsDelegateImpl(this)); 397 preview_delegate_.reset(new WebContentsDelegateImpl(this));
376 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); 398 WebContentsDelegateImpl* new_delegate = preview_delegate_.get();
377 new_contents->SetDelegate(new_delegate); 399 new_contents->SetDelegate(new_delegate);
378 400
379 // Disable popups and such (mainly to avoid losing focus and reverting the 401 // Disable popups and such (mainly to avoid losing focus and reverting the
380 // preview prematurely). 402 // preview prematurely).
381 BlockedContentTabHelper::FromWebContents(new_contents)-> 403 BlockedContentTabHelper::FromWebContents(new_contents)->
382 SetAllContentsBlocked(true); 404 SetAllContentsBlocked(true);
383 preview_contents_->constrained_window_tab_helper()-> 405 preview_contents_->constrained_window_tab_helper()->
384 set_delegate(new_delegate); 406 set_delegate(new_delegate);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 content::WebContents* new_contents) { 449 content::WebContents* new_contents) {
428 DCHECK(old_contents == preview_contents_->web_contents()); 450 DCHECK(old_contents == preview_contents_->web_contents());
429 CleanupPreviewContents(); 451 CleanupPreviewContents();
430 // We release here without deleting so that the caller still has the 452 // We release here without deleting so that the caller still has the
431 // responsibility for deleting the TabContents. 453 // responsibility for deleting the TabContents.
432 ignore_result(preview_contents_.release()); 454 ignore_result(preview_contents_.release());
433 preview_contents_.reset(TabContents::FromWebContents(new_contents)); 455 preview_contents_.reset(TabContents::FromWebContents(new_contents));
434 SetupPreviewContents(); 456 SetupPreviewContents();
435 loader_delegate_->SwappedTabContents(this); 457 loader_delegate_->SwappedTabContents(this);
436 } 458 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_loader.h ('k') | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698