Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/browser/tab_contents/navigation_controller.h" | 26 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 27 #include "chrome/browser/tab_contents/navigation_entry.h" | 27 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents.h" | 28 #include "chrome/browser/tab_contents/tab_contents.h" |
| 29 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 29 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 30 #include "chrome/browser/tab_contents/tab_contents_view.h" | 30 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 31 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 31 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/notification_details.h" | 33 #include "chrome/common/notification_details.h" |
| 34 #include "chrome/common/notification_observer.h" | 34 #include "chrome/common/notification_observer.h" |
| 35 #include "chrome/common/notification_registrar.h" | 35 #include "chrome/common/notification_registrar.h" |
| 36 #include "chrome/common/notification_service.h" | |
| 36 #include "chrome/common/notification_source.h" | 37 #include "chrome/common/notification_source.h" |
| 37 #include "chrome/common/notification_type.h" | 38 #include "chrome/common/notification_type.h" |
| 38 #include "chrome/common/page_transition_types.h" | 39 #include "chrome/common/page_transition_types.h" |
| 39 #include "chrome/common/render_messages.h" | 40 #include "chrome/common/render_messages.h" |
| 40 #include "chrome/common/renderer_preferences.h" | 41 #include "chrome/common/renderer_preferences.h" |
| 41 #include "gfx/codec/png_codec.h" | 42 #include "gfx/codec/png_codec.h" |
| 42 #include "ipc/ipc_message.h" | 43 #include "ipc/ipc_message.h" |
| 43 #include "net/http/http_util.h" | 44 #include "net/http/http_util.h" |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 DISALLOW_COPY_AND_ASSIGN(FrameLoadObserver); | 127 DISALLOW_COPY_AND_ASSIGN(FrameLoadObserver); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 // PaintObserver implementation. When the RenderWidgetHost paints itself this | 130 // PaintObserver implementation. When the RenderWidgetHost paints itself this |
| 130 // notifies the TabContentsDelegateImpl which ultimately notifies InstantLoader | 131 // notifies the TabContentsDelegateImpl which ultimately notifies InstantLoader |
| 131 // and shows the preview. | 132 // and shows the preview. |
| 132 // The ownership of this class is tricky. It's created and | 133 // The ownership of this class is tricky. It's created and |
| 133 // tracked by TabContentsDelegateImpl, but owned by RenderWidgetHost. When | 134 // tracked by TabContentsDelegateImpl, but owned by RenderWidgetHost. When |
| 134 // deleted this notifies the TabContentsDelegateImpl so that it can clean | 135 // deleted this notifies the TabContentsDelegateImpl so that it can clean |
| 135 // up appropriately. | 136 // up appropriately. |
| 136 class InstantLoader::PaintObserverImpl | 137 class InstantLoader::PaintObserverImpl : public NotificationObserver { |
| 137 : public RenderWidgetHost::PaintObserver { | |
| 138 public: | 138 public: |
| 139 PaintObserverImpl(TabContentsDelegateImpl* delegate, | 139 PaintObserverImpl(TabContentsDelegateImpl* delegate, |
| 140 RenderWidgetHost* rwh) | 140 RenderWidgetHost* render_widget_host) |
| 141 : delegate_(delegate), | 141 : delegate_(delegate) { |
| 142 rwh_(rwh) { | 142 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, |
| 143 rwh_->set_paint_observer(this); | 143 Source<RenderWidgetHost>(render_widget_host)); |
| 144 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | |
| 145 Source<RenderWidgetHost>(render_widget_host)); | |
| 144 } | 146 } |
| 145 | 147 |
| 146 ~PaintObserverImpl(); | 148 ~PaintObserverImpl(); |
| 147 | 149 |
| 148 // Deletes this object by resetting the PaintObserver on the RenderWidgetHost. | 150 void Observe(NotificationType type, |
| 149 void Destroy() { | 151 const NotificationSource& source, |
|
brettw
2011/01/03 19:48:30
Indent these two args to the first one.
DaveMoore
2011/01/07 19:04:05
N/A
On 2011/01/03 19:48:30, brettw wrote:
| |
| 150 rwh_->set_paint_observer(NULL); | 152 const NotificationDetails& details); |
| 151 } | |
| 152 | |
| 153 virtual void RenderWidgetHostWillPaint(RenderWidgetHost* rwh) {} | |
| 154 | |
| 155 virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh); | |
| 156 | 153 |
| 157 private: | 154 private: |
| 158 TabContentsDelegateImpl* delegate_; | 155 TabContentsDelegateImpl* delegate_; |
| 159 RenderWidgetHost* rwh_; | 156 NotificationRegistrar registrar_; |
| 160 | 157 |
| 161 DISALLOW_COPY_AND_ASSIGN(PaintObserverImpl); | 158 DISALLOW_COPY_AND_ASSIGN(PaintObserverImpl); |
| 162 }; | 159 }; |
| 163 | 160 |
| 164 class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { | 161 class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { |
| 165 public: | 162 public: |
| 166 explicit TabContentsDelegateImpl(InstantLoader* loader) | 163 explicit TabContentsDelegateImpl(InstantLoader* loader) |
| 167 : loader_(loader), | 164 : loader_(loader), |
| 168 paint_observer_(NULL), | 165 paint_observer_(NULL), |
| 169 waiting_for_new_page_(true), | 166 waiting_for_new_page_(true), |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 void CommitFromMouseReleaseIfNecessary() { | 405 void CommitFromMouseReleaseIfNecessary() { |
| 409 bool was_down = is_mouse_down_from_activate_; | 406 bool was_down = is_mouse_down_from_activate_; |
| 410 is_mouse_down_from_activate_ = false; | 407 is_mouse_down_from_activate_ = false; |
| 411 if (was_down && loader_->ShouldCommitInstantOnMouseUp()) | 408 if (was_down && loader_->ShouldCommitInstantOnMouseUp()) |
| 412 loader_->CommitInstantLoader(); | 409 loader_->CommitInstantLoader(); |
| 413 } | 410 } |
| 414 | 411 |
| 415 // If the PaintObserver is non-null Destroy is invoked on it. | 412 // If the PaintObserver is non-null Destroy is invoked on it. |
| 416 void DestroyPaintObserver() { | 413 void DestroyPaintObserver() { |
| 417 if (paint_observer_) { | 414 if (paint_observer_) { |
| 418 paint_observer_->Destroy(); | 415 delete paint_observer_; |
| 419 // Destroy should result in invoking PaintObserverDestroyed and NULLing | 416 // delete should result in invoking PaintObserverDestroyed and NULLing |
| 420 // out paint_observer_. | 417 // out paint_observer_. |
| 421 DCHECK(!paint_observer_); | 418 DCHECK(!paint_observer_); |
| 422 } | 419 } |
| 423 } | 420 } |
| 424 | 421 |
| 425 InstantLoader* loader_; | 422 InstantLoader* loader_; |
| 426 | 423 |
| 427 // Used to listen for paint so that we know when to show the preview. See | 424 // Used to listen for paint so that we know when to show the preview. See |
| 428 // comment in NavigationStateChanged for details on this. | 425 // comment in NavigationStateChanged for details on this. |
| 429 // Ownership of this is tricky, see comment above PaintObserverImpl class. | 426 // Ownership of this is tricky, see comment above PaintObserverImpl class. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 445 // True if the user typed in the search box before the page loaded. | 442 // True if the user typed in the search box before the page loaded. |
| 446 bool user_typed_before_load_; | 443 bool user_typed_before_load_; |
| 447 | 444 |
| 448 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); | 445 DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); |
| 449 }; | 446 }; |
| 450 | 447 |
| 451 InstantLoader::PaintObserverImpl::~PaintObserverImpl() { | 448 InstantLoader::PaintObserverImpl::~PaintObserverImpl() { |
| 452 delegate_->PaintObserverDestroyed(this); | 449 delegate_->PaintObserverDestroyed(this); |
| 453 } | 450 } |
| 454 | 451 |
| 455 void InstantLoader::PaintObserverImpl::RenderWidgetHostDidPaint( | 452 void InstantLoader::PaintObserverImpl::Observe(NotificationType type, |
|
brettw
2011/01/03 19:48:30
Move this arg to the next line, indented 4 spaces.
DaveMoore
2011/01/07 19:04:05
N/A
On 2011/01/03 19:48:30, brettw wrote:
| |
| 456 RenderWidgetHost* rwh) { | 453 const NotificationSource& source, |
| 457 TabContentsDelegateImpl* delegate = delegate_; | 454 const NotificationDetails& details) { |
| 458 // Set the paint observer to NULL, which deletes us. Showing the preview may | 455 if (type == NotificationType::RENDER_WIDGET_HOST_DID_PAINT) { |
| 459 // reset the paint observer, and delete us. By resetting the delegate first we | 456 TabContentsDelegateImpl* delegate = delegate_; |
| 460 // know we've been deleted and can deal correctly. | 457 // Delete outselves. Showing the preview may reload content. By resetting |
| 461 rwh->set_paint_observer(NULL); | 458 // the observer first we know we've been deleted and can deal correctly. |
| 462 // WARNING: we've been deleted. | 459 delete this; |
| 463 if (delegate) | 460 // WARNING: we've been deleted. |
| 464 delegate->PreviewPainted(); | 461 if (delegate) |
| 462 delegate->PreviewPainted(); | |
| 463 } else if (type == NotificationType::RENDER_WIDGET_HOST_DESTROYED) { | |
| 464 delete this; | |
| 465 } | |
| 465 } | 466 } |
| 466 | 467 |
| 467 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) | 468 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) |
| 468 : delegate_(delegate), | 469 : delegate_(delegate), |
| 469 template_url_id_(id), | 470 template_url_id_(id), |
| 470 ready_(false), | 471 ready_(false), |
| 471 last_transition_type_(PageTransition::LINK) { | 472 last_transition_type_(PageTransition::LINK) { |
| 472 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 473 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
| 473 } | 474 } |
| 474 | 475 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 user_text_, type == INSTANT_COMMIT_PRESSED_ENTER); | 622 user_text_, type == INSTANT_COMMIT_PRESSED_ENTER); |
| 622 } | 623 } |
| 623 omnibox_bounds_ = gfx::Rect(); | 624 omnibox_bounds_ = gfx::Rect(); |
| 624 last_omnibox_bounds_ = gfx::Rect(); | 625 last_omnibox_bounds_ = gfx::Rect(); |
| 625 url_ = GURL(); | 626 url_ = GURL(); |
| 626 user_text_.clear(); | 627 user_text_.clear(); |
| 627 complete_suggested_text_.clear(); | 628 complete_suggested_text_.clear(); |
| 628 if (preview_contents_.get()) { | 629 if (preview_contents_.get()) { |
| 629 if (type != INSTANT_COMMIT_DESTROY) | 630 if (type != INSTANT_COMMIT_DESTROY) |
| 630 preview_tab_contents_delegate_->CommitHistory(); | 631 preview_tab_contents_delegate_->CommitHistory(); |
| 631 // Destroy the paint observer. | |
| 632 // RenderWidgetHostView may be null during shutdown. | |
| 633 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 632 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
| 634 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | |
| 635 GetRenderWidgetHost()->set_paint_observer(NULL); | |
| 636 #if defined(OS_MACOSX) | 633 #if defined(OS_MACOSX) |
| 637 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 634 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| 638 SetTakesFocusOnlyOnMouseDown(false); | 635 SetTakesFocusOnlyOnMouseDown(false); |
| 639 registrar_.Remove( | 636 registrar_.Remove( |
| 640 this, | 637 this, |
| 641 NotificationType::RENDER_VIEW_HOST_CHANGED, | 638 NotificationType::RENDER_VIEW_HOST_CHANGED, |
| 642 Source<NavigationController>(&preview_contents_->controller())); | 639 Source<NavigationController>(&preview_contents_->controller())); |
| 643 #endif | 640 #endif |
| 644 } | 641 } |
| 645 preview_contents_->set_delegate(NULL); | 642 preview_contents_->set_delegate(NULL); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 Source<NavigationController>(&preview_contents_->controller())); | 811 Source<NavigationController>(&preview_contents_->controller())); |
| 815 #endif | 812 #endif |
| 816 | 813 |
| 817 registrar_.Add( | 814 registrar_.Add( |
| 818 this, | 815 this, |
| 819 NotificationType::NAV_ENTRY_COMMITTED, | 816 NotificationType::NAV_ENTRY_COMMITTED, |
| 820 Source<NavigationController>(&preview_contents_->controller())); | 817 Source<NavigationController>(&preview_contents_->controller())); |
| 821 | 818 |
| 822 preview_contents_->tab_contents()->ShowContents(); | 819 preview_contents_->tab_contents()->ShowContents(); |
| 823 } | 820 } |
| OLD | NEW |