| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
| 6 | 6 |
| 7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/browser/web_contents/aura/image_window_delegate.h" | 9 #include "content/browser/web_contents/aura/image_window_delegate.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/base/layout.h" | 15 #include "ui/base/layout.h" |
| 16 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
| 17 #include "ui/compositor/layer_animation_observer.h" | 17 #include "ui/compositor/layer_animation_observer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/image/image_png_rep.h" | 20 #include "ui/gfx/image/image_png_rep.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 namespace { |
| 25 |
| 26 // Returns true if the entry's URL or any of the URLs in entry's redirect chain |
| 27 // match |url|. |
| 28 bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) { |
| 29 if (entry->GetURL() == url) |
| 30 return true; |
| 31 const std::vector<GURL>& redirect_chain = entry->GetRedirectChain(); |
| 32 for (std::vector<GURL>::const_iterator it = redirect_chain.begin(); |
| 33 it != redirect_chain.end(); |
| 34 it++) { |
| 35 if (*it == url) |
| 36 return true; |
| 37 } |
| 38 return false; |
| 39 } |
| 40 |
| 41 } // namespace |
| 24 | 42 |
| 25 // A LayerDelegate that paints an image for the layer. | 43 // A LayerDelegate that paints an image for the layer. |
| 26 class ImageLayerDelegate : public ui::LayerDelegate { | 44 class ImageLayerDelegate : public ui::LayerDelegate { |
| 27 public: | 45 public: |
| 28 ImageLayerDelegate() {} | 46 ImageLayerDelegate() {} |
| 29 | 47 |
| 30 virtual ~ImageLayerDelegate() {} | 48 virtual ~ImageLayerDelegate() {} |
| 31 | 49 |
| 32 void SetImage(const gfx::Image& image) { | 50 void SetImage(const gfx::Image& image) { |
| 33 image_ = image; | 51 image_ = image; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 130 |
| 113 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); | 131 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); |
| 114 }; | 132 }; |
| 115 | 133 |
| 116 OverscrollNavigationOverlay::OverscrollNavigationOverlay( | 134 OverscrollNavigationOverlay::OverscrollNavigationOverlay( |
| 117 WebContentsImpl* web_contents) | 135 WebContentsImpl* web_contents) |
| 118 : web_contents_(web_contents), | 136 : web_contents_(web_contents), |
| 119 image_delegate_(NULL), | 137 image_delegate_(NULL), |
| 120 loading_complete_(false), | 138 loading_complete_(false), |
| 121 received_paint_update_(false), | 139 received_paint_update_(false), |
| 122 pending_entry_id_(0), | |
| 123 slide_direction_(SLIDE_UNKNOWN) { | 140 slide_direction_(SLIDE_UNKNOWN) { |
| 124 } | 141 } |
| 125 | 142 |
| 126 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { | 143 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { |
| 127 } | 144 } |
| 128 | 145 |
| 129 void OverscrollNavigationOverlay::StartObserving() { | 146 void OverscrollNavigationOverlay::StartObserving() { |
| 130 loading_complete_ = false; | 147 loading_complete_ = false; |
| 131 received_paint_update_ = false; | 148 received_paint_update_ = false; |
| 132 overlay_dismiss_layer_.reset(); | 149 overlay_dismiss_layer_.reset(); |
| 133 pending_entry_id_ = 0; | |
| 134 Observe(web_contents_); | 150 Observe(web_contents_); |
| 135 | 151 |
| 136 // Make sure the overlay window is on top. | 152 // Make sure the overlay window is on top. |
| 137 if (window_.get() && window_->parent()) | 153 if (window_.get() && window_->parent()) |
| 138 window_->parent()->StackChildAtTop(window_.get()); | 154 window_->parent()->StackChildAtTop(window_.get()); |
| 139 | 155 |
| 140 // Assumes the navigation has been initiated. | 156 // Assumes the navigation has been initiated. |
| 141 NavigationEntry* pending_entry = | 157 NavigationEntry* pending_entry = |
| 142 web_contents_->GetController().GetPendingEntry(); | 158 web_contents_->GetController().GetPendingEntry(); |
| 143 // Save id of the pending entry to identify when it loads and paints later. | 159 // Save url of the pending entry to identify when it loads and paints later. |
| 144 // Under some circumstances navigation can leave a null pending entry - | 160 // Under some circumstances navigation can leave a null pending entry - |
| 145 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). | 161 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). |
| 146 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0; | 162 pending_entry_url_ = pending_entry ? pending_entry->GetURL() : GURL(); |
| 147 } | 163 } |
| 148 | 164 |
| 149 void OverscrollNavigationOverlay::SetOverlayWindow( | 165 void OverscrollNavigationOverlay::SetOverlayWindow( |
| 150 scoped_ptr<aura::Window> window, | 166 scoped_ptr<aura::Window> window, |
| 151 ImageWindowDelegate* delegate) { | 167 ImageWindowDelegate* delegate) { |
| 152 window_ = window.Pass(); | 168 window_ = window.Pass(); |
| 153 if (window_.get() && window_->parent()) | 169 if (window_.get() && window_->parent()) |
| 154 window_->parent()->StackChildAtTop(window_.get()); | 170 window_->parent()->StackChildAtTop(window_.get()); |
| 155 image_delegate_ = delegate; | 171 image_delegate_ = delegate; |
| 156 | 172 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // This check prevents StopObservingIfDone() being called multiple times | 291 // This check prevents StopObservingIfDone() being called multiple times |
| 276 // (including recursively) for a single event. | 292 // (including recursively) for a single event. |
| 277 if (window_slider_.get()) { | 293 if (window_slider_.get()) { |
| 278 // The slider has just been destroyed. Release the ownership. | 294 // The slider has just been destroyed. Release the ownership. |
| 279 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); | 295 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); |
| 280 StopObservingIfDone(); | 296 StopObservingIfDone(); |
| 281 } | 297 } |
| 282 } | 298 } |
| 283 | 299 |
| 284 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { | 300 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { |
| 285 int visible_entry_id = | 301 NavigationEntry* visible_entry = |
| 286 web_contents_->GetController().GetVisibleEntry()->GetUniqueID(); | 302 web_contents_->GetController().GetVisibleEntry(); |
| 287 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { | 303 if (pending_entry_url_.is_empty() || |
| 304 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { |
| 288 received_paint_update_ = true; | 305 received_paint_update_ = true; |
| 289 StopObservingIfDone(); | 306 StopObservingIfDone(); |
| 290 } | 307 } |
| 291 } | 308 } |
| 292 | 309 |
| 293 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { | 310 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { |
| 294 // Use the last committed entry rather than the active one, in case a | 311 // Don't compare URLs in this case - it's possible they won't match if |
| 295 // pending entry has been created. | 312 // a gesture-nav initiated navigation was interrupted by some other in-site |
| 296 int committed_entry_id = | 313 // navigation ((e.g., from a script, or from a bookmark). |
| 297 web_contents_->GetController().GetLastCommittedEntry()->GetUniqueID(); | 314 loading_complete_ = true; |
| 298 if (committed_entry_id == pending_entry_id_ || !pending_entry_id_) { | 315 StopObservingIfDone(); |
| 299 loading_complete_ = true; | |
| 300 StopObservingIfDone(); | |
| 301 } | |
| 302 } | 316 } |
| 303 | 317 |
| 304 } // namespace content | 318 } // namespace content |
| OLD | NEW |