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