Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/web_contents/aura/overscroll_window_delegate.h" | 15 #include "content/browser/web_contents/aura/overscroll_window_delegate.h" |
| 16 #include "content/browser/web_contents/aura/uma_navigation_type.h" | |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/browser/user_metrics.h" | |
| 20 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 21 #include "ui/base/layout.h" | 23 #include "ui/base/layout.h" |
| 22 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/layer_animation_observer.h" | 25 #include "ui/compositor/layer_animation_observer.h" |
| 24 #include "ui/compositor/paint_recorder.h" | 26 #include "ui/compositor/paint_recorder.h" |
| 25 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 26 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/image/image_png_rep.h" | 29 #include "ui/gfx/image/image_png_rep.h" |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Returns true if the entry's URL or any of the URLs in entry's redirect chain | 34 // Returns true if the entry's URL or any of the URLs in entry's redirect chain |
| 33 // match |url|. | 35 // match |url|. |
| 34 bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) { | 36 bool DoesEntryMatchURL(NavigationEntry* entry, const GURL& url) { |
| 35 if (!entry) | 37 if (!entry) |
| 36 return false; | 38 return false; |
| 37 if (entry->GetURL() == url) | 39 if (entry->GetURL() == url) |
| 38 return true; | 40 return true; |
| 39 const std::vector<GURL>& redirect_chain = entry->GetRedirectChain(); | 41 const std::vector<GURL>& redirect_chain = entry->GetRedirectChain(); |
| 40 for (std::vector<GURL>::const_iterator it = redirect_chain.begin(); | 42 for (std::vector<GURL>::const_iterator it = redirect_chain.begin(); |
| 41 it != redirect_chain.end(); | 43 it != redirect_chain.end(); |
| 42 it++) { | 44 it++) { |
| 43 if (*it == url) | 45 if (*it == url) |
| 44 return true; | 46 return true; |
| 45 } | 47 } |
| 46 return false; | 48 return false; |
| 47 } | 49 } |
| 48 | 50 |
| 51 UmaNavigationType GetUmaNavigationType( | |
| 52 OverscrollNavigationOverlay::NavigationDirection direction, | |
| 53 OverscrollSource source) { | |
| 54 if (direction == OverscrollNavigationOverlay::NONE || | |
| 55 source == OVERSCROLL_SOURCE_NONE) | |
| 56 return NAVIGATION_TYPE_NONE; | |
| 57 if (direction == OverscrollNavigationOverlay::BACK) | |
| 58 return source == OVERSCROLL_TOUCHPAD ? BACK_TOUCHPAD : BACK_TOUCHSCREEN; | |
| 59 DCHECK_EQ(direction, OverscrollNavigationOverlay::FORWARD); | |
| 60 return source == OVERSCROLL_TOUCHPAD ? FORWARD_TOUCHPAD : FORWARD_TOUCHSCREEN; | |
| 61 } | |
| 62 | |
| 63 // Records UMA historgram and also user action for the cancelled overscroll. | |
| 64 void RecordCancelled(OverscrollNavigationOverlay::NavigationDirection direction, | |
| 65 OverscrollSource source) { | |
| 66 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3", | |
|
mohsen
2017/02/21 20:47:58
Is there a "Cancelled2" or you just want to name t
mfomitchev
2017/02/23 02:59:42
Yes - it seems less confusing this way.
mohsen
2017/02/23 19:19:09
Acknowledged.
| |
| 67 GetUmaNavigationType(direction, source), | |
| 68 NAVIGATION_TYPE_COUNT); | |
| 69 if (direction == OverscrollNavigationOverlay::BACK) | |
| 70 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back")); | |
| 71 else | |
| 72 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward")); | |
| 73 } | |
| 74 | |
| 49 } // namespace | 75 } // namespace |
| 50 | 76 |
| 51 // Responsible for fading out and deleting the layer of the overlay window. | 77 // Responsible for fading out and deleting the layer of the overlay window. |
| 52 class OverlayDismissAnimator | 78 class OverlayDismissAnimator |
| 53 : public ui::LayerAnimationObserver { | 79 : public ui::LayerAnimationObserver { |
| 54 public: | 80 public: |
| 55 // Takes ownership of the layer. | 81 // Takes ownership of the layer. |
| 56 explicit OverlayDismissAnimator(std::unique_ptr<ui::Layer> layer) | 82 explicit OverlayDismissAnimator(std::unique_ptr<ui::Layer> layer) |
| 57 : layer_(std::move(layer)) { | 83 : layer_(std::move(layer)) { |
| 58 CHECK(layer_.get()); | 84 CHECK(layer_.get()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 window_.reset(); | 163 window_.reset(); |
| 138 (new OverlayDismissAnimator(std::move(dismiss_layer)))->Animate(); | 164 (new OverlayDismissAnimator(std::move(dismiss_layer)))->Animate(); |
| 139 Observe(nullptr); | 165 Observe(nullptr); |
| 140 received_paint_update_ = false; | 166 received_paint_update_ = false; |
| 141 loading_complete_ = false; | 167 loading_complete_ = false; |
| 142 } | 168 } |
| 143 | 169 |
| 144 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( | 170 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( |
| 145 const gfx::Rect& bounds) { | 171 const gfx::Rect& bounds) { |
| 146 UMA_HISTOGRAM_ENUMERATION( | 172 UMA_HISTOGRAM_ENUMERATION( |
| 147 "Overscroll.Started2", direction_, NAVIGATION_COUNT); | 173 "Overscroll.Started3", |
| 174 GetUmaNavigationType(direction_, owa_->overscroll_source()), | |
| 175 NAVIGATION_TYPE_COUNT); | |
| 148 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( | 176 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( |
| 149 owa_.get(), GetImageForDirection(direction_)); | 177 owa_.get(), GetImageForDirection(direction_)); |
| 150 std::unique_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); | 178 std::unique_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); |
| 151 window->set_owned_by_parent(false); | 179 window->set_owned_by_parent(false); |
| 152 window->SetTransparent(true); | 180 window->SetTransparent(true); |
| 153 window->Init(ui::LAYER_TEXTURED); | 181 window->Init(ui::LAYER_TEXTURED); |
| 154 window->layer()->SetMasksToBounds(false); | 182 window->layer()->SetMasksToBounds(false); |
| 155 window->SetName("OverscrollOverlay"); | 183 window->SetName("OverscrollOverlay"); |
| 156 web_contents_window_->AddChild(window.get()); | 184 web_contents_window_->AddChild(window.get()); |
| 157 aura::Window* event_window = GetMainWindow(); | 185 aura::Window* event_window = GetMainWindow(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 if (!main_window) | 239 if (!main_window) |
| 212 return; | 240 return; |
| 213 main_window->ReleaseCapture(); | 241 main_window->ReleaseCapture(); |
| 214 } | 242 } |
| 215 | 243 |
| 216 void OverscrollNavigationOverlay::OnOverscrollCompleted( | 244 void OverscrollNavigationOverlay::OnOverscrollCompleted( |
| 217 std::unique_ptr<aura::Window> window) { | 245 std::unique_ptr<aura::Window> window) { |
| 218 DCHECK(direction_ != NONE); | 246 DCHECK(direction_ != NONE); |
| 219 aura::Window* main_window = GetMainWindow(); | 247 aura::Window* main_window = GetMainWindow(); |
| 220 if (!main_window) { | 248 if (!main_window) { |
| 221 UMA_HISTOGRAM_ENUMERATION( | 249 RecordCancelled(direction_, owa_->overscroll_source()); |
| 222 "Overscroll.Cancelled", direction_, NAVIGATION_COUNT); | |
| 223 return; | 250 return; |
| 224 } | 251 } |
| 225 | 252 |
| 226 main_window->SetTransform(gfx::Transform()); | 253 main_window->SetTransform(gfx::Transform()); |
| 227 window_ = std::move(window); | 254 window_ = std::move(window); |
| 228 // Make sure the window is in its default position. | 255 // Make sure the window is in its default position. |
| 229 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size())); | 256 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size())); |
| 230 window_->SetTransform(gfx::Transform()); | 257 window_->SetTransform(gfx::Transform()); |
| 231 // Make sure the overlay window is on top. | 258 // Make sure the overlay window is on top. |
| 232 web_contents_window_->StackChildAtTop(window_.get()); | 259 web_contents_window_->StackChildAtTop(window_.get()); |
| 233 | 260 |
| 234 // Make sure we can navigate first, as other factors can trigger a navigation | 261 // Make sure we can navigate first, as other factors can trigger a navigation |
| 235 // during an overscroll gesture and navigating without history produces a | 262 // during an overscroll gesture and navigating without history produces a |
| 236 // crash. | 263 // crash. |
| 237 bool navigated = false; | 264 bool navigated = false; |
| 238 if (direction_ == FORWARD && web_contents_->GetController().CanGoForward()) { | 265 if (direction_ == FORWARD && web_contents_->GetController().CanGoForward()) { |
| 239 web_contents_->GetController().GoForward(); | 266 web_contents_->GetController().GoForward(); |
| 240 navigated = true; | 267 navigated = true; |
| 241 } else if (direction_ == BACK && web_contents_->GetController().CanGoBack()) { | 268 } else if (direction_ == BACK && web_contents_->GetController().CanGoBack()) { |
| 242 web_contents_->GetController().GoBack(); | 269 web_contents_->GetController().GoBack(); |
| 243 navigated = true; | 270 navigated = true; |
| 244 } else { | 271 } else { |
| 245 // We need to dismiss the overlay without navigating as soon as the | 272 // We need to dismiss the overlay without navigating as soon as the |
| 246 // overscroll finishes. | 273 // overscroll finishes. |
| 247 UMA_HISTOGRAM_ENUMERATION( | 274 RecordCancelled(direction_, owa_->overscroll_source()); |
| 248 "Overscroll.Cancelled", direction_, NAVIGATION_COUNT); | |
| 249 loading_complete_ = true; | 275 loading_complete_ = true; |
| 250 } | 276 } |
| 251 | 277 |
| 252 if (navigated) { | 278 if (navigated) { |
| 253 UMA_HISTOGRAM_ENUMERATION( | 279 UMA_HISTOGRAM_ENUMERATION( |
| 254 "Overscroll.Navigated2", direction_, NAVIGATION_COUNT); | 280 "Overscroll.Navigated3", |
| 281 GetUmaNavigationType(direction_, owa_->overscroll_source()), | |
| 282 NAVIGATION_TYPE_COUNT); | |
| 283 if (direction_ == BACK) | |
| 284 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back")); | |
| 285 else | |
| 286 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward")); | |
| 255 StartObserving(); | 287 StartObserving(); |
| 256 } | 288 } |
| 257 | 289 |
| 258 direction_ = NONE; | 290 direction_ = NONE; |
| 259 StopObservingIfDone(); | 291 StopObservingIfDone(); |
| 260 } | 292 } |
| 261 | 293 |
| 262 void OverscrollNavigationOverlay::OnOverscrollCancelled() { | 294 void OverscrollNavigationOverlay::OnOverscrollCancelled() { |
| 263 UMA_HISTOGRAM_ENUMERATION( | 295 RecordCancelled(direction_, owa_->overscroll_source()); |
| 264 "Overscroll.Cancelled", direction_, NAVIGATION_COUNT); | |
| 265 aura::Window* main_window = GetMainWindow(); | 296 aura::Window* main_window = GetMainWindow(); |
| 266 if (!main_window) | 297 if (!main_window) |
| 267 return; | 298 return; |
| 268 main_window->ReleaseCapture(); | 299 main_window->ReleaseCapture(); |
| 269 direction_ = NONE; | 300 direction_ = NONE; |
| 270 StopObservingIfDone(); | 301 StopObservingIfDone(); |
| 271 } | 302 } |
| 272 | 303 |
| 273 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { | 304 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { |
| 274 NavigationEntry* visible_entry = | 305 NavigationEntry* visible_entry = |
| 275 web_contents_->GetController().GetVisibleEntry(); | 306 web_contents_->GetController().GetVisibleEntry(); |
| 276 if (pending_entry_url_.is_empty() || | 307 if (pending_entry_url_.is_empty() || |
| 277 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { | 308 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { |
| 278 received_paint_update_ = true; | 309 received_paint_update_ = true; |
| 279 StopObservingIfDone(); | 310 StopObservingIfDone(); |
| 280 } | 311 } |
| 281 } | 312 } |
| 282 | 313 |
| 283 void OverscrollNavigationOverlay::DidStopLoading() { | 314 void OverscrollNavigationOverlay::DidStopLoading() { |
| 284 // Don't compare URLs in this case - it's possible they won't match if | 315 // Don't compare URLs in this case - it's possible they won't match if |
| 285 // a gesture-nav initiated navigation was interrupted by some other in-site | 316 // a gesture-nav initiated navigation was interrupted by some other in-site |
| 286 // navigation (e.g., from a script, or from a bookmark). | 317 // navigation (e.g., from a script, or from a bookmark). |
| 287 loading_complete_ = true; | 318 loading_complete_ = true; |
| 288 StopObservingIfDone(); | 319 StopObservingIfDone(); |
| 289 } | 320 } |
| 290 | 321 |
| 291 } // namespace content | 322 } // namespace content |
| OLD | NEW |