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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 127 |
110 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); | 128 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); |
111 }; | 129 }; |
112 | 130 |
113 OverscrollNavigationOverlay::OverscrollNavigationOverlay( | 131 OverscrollNavigationOverlay::OverscrollNavigationOverlay( |
114 WebContentsImpl* web_contents) | 132 WebContentsImpl* web_contents) |
115 : web_contents_(web_contents), | 133 : web_contents_(web_contents), |
116 image_delegate_(NULL), | 134 image_delegate_(NULL), |
117 loading_complete_(false), | 135 loading_complete_(false), |
118 received_paint_update_(false), | 136 received_paint_update_(false), |
119 pending_entry_id_(0), | |
120 slide_direction_(SLIDE_UNKNOWN) { | 137 slide_direction_(SLIDE_UNKNOWN) { |
121 } | 138 } |
122 | 139 |
123 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { | 140 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { |
124 } | 141 } |
125 | 142 |
126 void OverscrollNavigationOverlay::StartObserving() { | 143 void OverscrollNavigationOverlay::StartObserving() { |
127 loading_complete_ = false; | 144 loading_complete_ = false; |
128 received_paint_update_ = false; | 145 received_paint_update_ = false; |
129 overlay_dismiss_layer_.reset(); | 146 overlay_dismiss_layer_.reset(); |
130 pending_entry_id_ = 0; | |
131 Observe(web_contents_); | 147 Observe(web_contents_); |
132 | 148 |
133 // Make sure the overlay window is on top. | 149 // Make sure the overlay window is on top. |
134 if (window_.get() && window_->parent()) | 150 if (window_.get() && window_->parent()) |
135 window_->parent()->StackChildAtTop(window_.get()); | 151 window_->parent()->StackChildAtTop(window_.get()); |
136 | 152 |
137 // Assumes the navigation has been initiated. | 153 // Assumes the navigation has been initiated. |
138 NavigationEntry* pending_entry = | 154 NavigationEntry* pending_entry = |
139 web_contents_->GetController().GetPendingEntry(); | 155 web_contents_->GetController().GetPendingEntry(); |
140 // Save id of the pending entry to identify when it loads and paints later. | 156 // Save url of the pending entry to identify when it loads and paints later. |
141 // Under some circumstances navigation can leave a null pending entry - | 157 // Under some circumstances navigation can leave a null pending entry - |
142 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). | 158 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). |
143 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0; | 159 pending_entry_url_ = pending_entry ? pending_entry->GetURL() : GURL(); |
144 } | 160 } |
145 | 161 |
146 void OverscrollNavigationOverlay::SetOverlayWindow( | 162 void OverscrollNavigationOverlay::SetOverlayWindow( |
147 scoped_ptr<aura::Window> window, | 163 scoped_ptr<aura::Window> window, |
148 ImageWindowDelegate* delegate) { | 164 ImageWindowDelegate* delegate) { |
149 window_ = window.Pass(); | 165 window_ = window.Pass(); |
150 if (window_.get() && window_->parent()) | 166 if (window_.get() && window_->parent()) |
151 window_->parent()->StackChildAtTop(window_.get()); | 167 window_->parent()->StackChildAtTop(window_.get()); |
152 image_delegate_ = delegate; | 168 image_delegate_ = delegate; |
153 | 169 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // This check prevents StopObservingIfDone() being called multiple times | 288 // This check prevents StopObservingIfDone() being called multiple times |
273 // (including recursively) for a single event. | 289 // (including recursively) for a single event. |
274 if (window_slider_.get()) { | 290 if (window_slider_.get()) { |
275 // The slider has just been destroyed. Release the ownership. | 291 // The slider has just been destroyed. Release the ownership. |
276 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); | 292 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); |
277 StopObservingIfDone(); | 293 StopObservingIfDone(); |
278 } | 294 } |
279 } | 295 } |
280 | 296 |
281 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { | 297 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { |
282 int visible_entry_id = | 298 NavigationEntry* visible_entry = |
283 web_contents_->GetController().GetVisibleEntry()->GetUniqueID(); | 299 web_contents_->GetController().GetVisibleEntry(); |
284 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { | 300 if (pending_entry_url_.is_empty() || |
| 301 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { |
285 received_paint_update_ = true; | 302 received_paint_update_ = true; |
286 StopObservingIfDone(); | 303 StopObservingIfDone(); |
287 } | 304 } |
288 } | 305 } |
289 | 306 |
290 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { | 307 void OverscrollNavigationOverlay::DidStopLoading(RenderViewHost* host) { |
291 // Use the last committed entry rather than the active one, in case a | 308 // Don't compare URLs in this case - it's possible they won't match if |
292 // pending entry has been created. | 309 // a gesture-nav initiated navigation was interrupted by some other in-site |
293 int committed_entry_id = | 310 // navigation ((e.g., from a script, or from a bookmark). |
294 web_contents_->GetController().GetLastCommittedEntry()->GetUniqueID(); | 311 loading_complete_ = true; |
295 if (committed_entry_id == pending_entry_id_ || !pending_entry_id_) { | 312 StopObservingIfDone(); |
296 loading_complete_ = true; | |
297 StopObservingIfDone(); | |
298 } | |
299 } | 313 } |
300 | 314 |
301 } // namespace content | 315 } // namespace content |
OLD | NEW |