Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 class InstantLoaderUserData : public base::SupportsUserData::Data { | |
| 29 public: | |
| 30 InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} | |
|
sky
2012/09/25 22:23:19
explicit
jam
2012/09/25 22:42:39
Done.
| |
| 31 virtual ~InstantLoaderUserData() {} | |
| 32 | |
| 33 InstantLoader* loader() const { return loader_; } | |
| 34 | |
| 35 private: | |
| 36 InstantLoader* loader_; | |
| 37 }; | |
|
sky
2012/09/25 22:23:19
DISALLOW_...
jam
2012/09/25 22:42:39
Done.
| |
| 38 | |
| 39 } | |
| 40 | |
| 27 // WebContentsDelegateImpl ----------------------------------------------------- | 41 // WebContentsDelegateImpl ----------------------------------------------------- |
| 28 | 42 |
| 29 class InstantLoader::WebContentsDelegateImpl | 43 class InstantLoader::WebContentsDelegateImpl |
| 30 : public ConstrainedWindowTabHelperDelegate, | 44 : public ConstrainedWindowTabHelperDelegate, |
| 31 public CoreTabHelperDelegate, | 45 public CoreTabHelperDelegate, |
| 32 public content::WebContentsDelegate, | 46 public content::WebContentsDelegate, |
| 33 public content::WebContentsObserver { | 47 public content::WebContentsObserver { |
| 34 public: | 48 public: |
| 35 explicit WebContentsDelegateImpl(InstantLoader* loader); | 49 explicit WebContentsDelegateImpl(InstantLoader* loader); |
| 36 | 50 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 52 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; | 66 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; |
| 53 virtual bool CanDownload(content::RenderViewHost* render_view_host, | 67 virtual bool CanDownload(content::RenderViewHost* render_view_host, |
| 54 int request_id, | 68 int request_id, |
| 55 const std::string& request_method) OVERRIDE; | 69 const std::string& request_method) OVERRIDE; |
| 56 virtual void HandleMouseUp() OVERRIDE; | 70 virtual void HandleMouseUp() OVERRIDE; |
| 57 virtual void HandlePointerActivate() OVERRIDE; | 71 virtual void HandlePointerActivate() OVERRIDE; |
| 58 virtual void HandleGestureBegin() OVERRIDE; | 72 virtual void HandleGestureBegin() OVERRIDE; |
| 59 virtual void HandleGestureEnd() OVERRIDE; | 73 virtual void HandleGestureEnd() OVERRIDE; |
| 60 virtual void DragEnded() OVERRIDE; | 74 virtual void DragEnded() OVERRIDE; |
| 61 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; | 75 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; |
| 62 virtual bool ShouldAddNavigationToHistory( | |
| 63 const history::HistoryAddPageArgs& add_page_args, | |
| 64 content::NavigationType navigation_type) OVERRIDE; | |
| 65 | 76 |
| 66 // content::WebContentsObserver: | 77 // content::WebContentsObserver: |
| 67 virtual void DidFinishLoad( | 78 virtual void DidFinishLoad( |
| 68 int64 frame_id, | 79 int64 frame_id, |
| 69 const GURL& validated_url, | 80 const GURL& validated_url, |
| 70 bool is_main_frame, | 81 bool is_main_frame, |
| 71 content::RenderViewHost* render_view_host) OVERRIDE; | 82 content::RenderViewHost* render_view_host) OVERRIDE; |
| 72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 83 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 73 | 84 |
| 74 private: | 85 private: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 // If the user drags, we won't get a mouse up (at least on Linux). Commit the | 173 // 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 | 174 // Instant result when the drag ends, so that during the drag the page won't |
| 164 // move around. | 175 // move around. |
| 165 CommitFromPointerReleaseIfNecessary(); | 176 CommitFromPointerReleaseIfNecessary(); |
| 166 } | 177 } |
| 167 | 178 |
| 168 bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { | 179 bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { |
| 169 return false; | 180 return false; |
| 170 } | 181 } |
| 171 | 182 |
| 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( | 183 void InstantLoader::WebContentsDelegateImpl::DidFinishLoad( |
| 180 int64 frame_id, | 184 int64 frame_id, |
| 181 const GURL& validated_url, | 185 const GURL& validated_url, |
| 182 bool is_main_frame, | 186 bool is_main_frame, |
| 183 content::RenderViewHost* render_view_host) { | 187 content::RenderViewHost* render_view_host) { |
| 184 if (is_main_frame) { | 188 if (is_main_frame) { |
| 185 if (!loader_->supports_instant_) | 189 if (!loader_->supports_instant_) |
| 186 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); | 190 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| 187 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); | 191 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); |
| 188 } | 192 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 Observe(NULL); | 278 Observe(NULL); |
| 275 } | 279 } |
| 276 | 280 |
| 277 loader_->supports_instant_ = supports_instant; | 281 loader_->supports_instant_ = supports_instant; |
| 278 loader_->loader_delegate_->InstantSupportDetermined(loader_, | 282 loader_->loader_delegate_->InstantSupportDetermined(loader_, |
| 279 supports_instant); | 283 supports_instant); |
| 280 } | 284 } |
| 281 | 285 |
| 282 // InstantLoader --------------------------------------------------------------- | 286 // InstantLoader --------------------------------------------------------------- |
| 283 | 287 |
| 288 int InstantLoader::kUserDataKey; | |
| 289 | |
| 290 // static | |
| 291 InstantLoader* InstantLoader::FromWebContents( | |
| 292 content::WebContents* web_contents) { | |
| 293 InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( | |
| 294 web_contents->GetUserData(&kUserDataKey)); | |
| 295 return data ? data->loader() : NULL; | |
| 296 } | |
| 297 | |
| 284 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, | 298 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, |
| 285 const std::string& instant_url, | 299 const std::string& instant_url, |
| 286 const TabContents* tab_contents) | 300 const TabContents* tab_contents) |
| 287 : loader_delegate_(delegate), | 301 : loader_delegate_(delegate), |
| 288 preview_contents_( | 302 preview_contents_( |
| 289 TabContents::Factory::CreateTabContents( | 303 TabContents::Factory::CreateTabContents( |
| 290 content::WebContents::CreateWithSessionStorage( | 304 content::WebContents::CreateWithSessionStorage( |
| 291 tab_contents->profile(), NULL, MSG_ROUTING_NONE, | 305 tab_contents->profile(), NULL, MSG_ROUTING_NONE, |
| 292 tab_contents->web_contents(), | 306 tab_contents->web_contents(), |
| 293 tab_contents->web_contents()->GetController(). | 307 tab_contents->web_contents()->GetController(). |
| 294 GetSessionStorageNamespaceMap()))), | 308 GetSessionStorageNamespaceMap()))), |
| 295 supports_instant_(false), | 309 supports_instant_(false), |
| 296 instant_url_(instant_url) { | 310 instant_url_(instant_url) { |
| 311 preview_contents_->web_contents()->SetUserData( | |
| 312 &kUserDataKey, new InstantLoaderUserData(this)); | |
|
sreeram
2012/09/25 22:22:29
Move this to inside SetupPreviewContents(), so tha
jam
2012/09/25 22:42:39
Done.
| |
| 297 } | 313 } |
| 298 | 314 |
| 299 InstantLoader::~InstantLoader() { | 315 InstantLoader::~InstantLoader() { |
| 300 if (preview_contents()) | 316 if (preview_contents()) |
| 301 preview_contents_->web_contents()->SetDelegate(NULL); | 317 preview_contents_->web_contents()->SetDelegate(NULL); |
| 302 } | 318 } |
| 303 | 319 |
| 304 void InstantLoader::Init() { | 320 void InstantLoader::Init() { |
| 305 SetupPreviewContents(); | 321 SetupPreviewContents(); |
| 306 // This HTTP header and value are set on loads that originate from instant. | 322 // This HTTP header and value are set on loads that originate from instant. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 333 results)); | 349 results)); |
| 334 } | 350 } |
| 335 | 351 |
| 336 void InstantLoader::OnUpOrDownKeyPressed(int count) { | 352 void InstantLoader::OnUpOrDownKeyPressed(int count) { |
| 337 content::RenderViewHost* rvh = | 353 content::RenderViewHost* rvh = |
| 338 preview_contents_->web_contents()->GetRenderViewHost(); | 354 preview_contents_->web_contents()->GetRenderViewHost(); |
| 339 rvh->Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(rvh->GetRoutingID(), | 355 rvh->Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(rvh->GetRoutingID(), |
| 340 count)); | 356 count)); |
| 341 } | 357 } |
| 342 | 358 |
| 359 void InstantLoader::DidNavigate( | |
| 360 const history::HistoryAddPageArgs& add_page_args) { | |
| 361 last_navigation_ = add_page_args; | |
| 362 } | |
| 363 | |
| 343 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type, | 364 TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type, |
| 344 const string16& text) { | 365 const string16& text) { |
| 345 content::RenderViewHost* rvh = | 366 content::RenderViewHost* rvh = |
| 346 preview_contents_->web_contents()->GetRenderViewHost(); | 367 preview_contents_->web_contents()->GetRenderViewHost(); |
| 347 if (type == INSTANT_COMMIT_PRESSED_ENTER) | 368 if (type == INSTANT_COMMIT_PRESSED_ENTER) |
| 348 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text)); | 369 rvh->Send(new ChromeViewMsg_SearchBoxSubmit(rvh->GetRoutingID(), text)); |
| 349 else | 370 else |
| 350 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text)); | 371 rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text)); |
| 351 CleanupPreviewContents(); | 372 CleanupPreviewContents(); |
| 373 preview_contents_->web_contents()->RemoveUserData(&kUserDataKey); | |
| 352 return preview_contents_.release(); | 374 return preview_contents_.release(); |
| 353 } | 375 } |
| 354 | 376 |
| 355 bool InstantLoader::IsPointerDownFromActivate() const { | 377 bool InstantLoader::IsPointerDownFromActivate() const { |
| 356 return preview_delegate_->is_pointer_down_from_activate(); | 378 return preview_delegate_->is_pointer_down_from_activate(); |
| 357 } | 379 } |
| 358 | 380 |
| 359 void InstantLoader::Observe(int type, | 381 void InstantLoader::Observe(int type, |
| 360 const content::NotificationSource& source, | 382 const content::NotificationSource& source, |
| 361 const content::NotificationDetails& details) { | 383 const content::NotificationDetails& details) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| OLD | NEW |