Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/web_contents/aura/overscroll_navigation_overlay.cc

Issue 2986483002: Adding metrics logging for Simplified Gesture Navigation. (Closed)
Patch Set: Addressing feedback Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/metrics/user_metrics.h" 13 #include "base/metrics/user_metrics.h"
14 #include "content/browser/frame_host/navigation_entry_impl.h" 14 #include "content/browser/frame_host/navigation_entry_impl.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/web_contents/aura/overscroll_window_delegate.h" 16 #include "content/browser/web_contents/aura/overscroll_window_delegate.h"
17 #include "content/browser/web_contents/aura/uma_navigation_type.h"
18 #include "content/browser/web_contents/web_contents_impl.h" 17 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
22 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
23 #include "ui/base/layout.h" 22 #include "ui/base/layout.h"
24 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
25 #include "ui/compositor/layer_animation_observer.h" 24 #include "ui/compositor/layer_animation_observer.h"
26 #include "ui/compositor/paint_recorder.h" 25 #include "ui/compositor/paint_recorder.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h" 26 #include "ui/compositor/scoped_layer_animation_settings.h"
(...skipping 13 matching lines...) Expand all
41 const std::vector<GURL>& redirect_chain = entry->GetRedirectChain(); 40 const std::vector<GURL>& redirect_chain = entry->GetRedirectChain();
42 for (std::vector<GURL>::const_iterator it = redirect_chain.begin(); 41 for (std::vector<GURL>::const_iterator it = redirect_chain.begin();
43 it != redirect_chain.end(); 42 it != redirect_chain.end();
44 it++) { 43 it++) {
45 if (*it == url) 44 if (*it == url)
46 return true; 45 return true;
47 } 46 }
48 return false; 47 return false;
49 } 48 }
50 49
51 UmaNavigationType GetUmaNavigationType(
52 OverscrollNavigationOverlay::NavigationDirection direction,
53 OverscrollSource source) {
54 if (direction == OverscrollNavigationOverlay::NONE ||
55 source == OverscrollSource::NONE)
56 return NAVIGATION_TYPE_NONE;
57 if (direction == OverscrollNavigationOverlay::BACK)
58 return source == OverscrollSource::TOUCHPAD
59 ? UmaNavigationType::BACK_TOUCHPAD
60 : UmaNavigationType::BACK_TOUCHSCREEN;
61 DCHECK_EQ(direction, OverscrollNavigationOverlay::FORWARD);
62 return source == OverscrollSource::TOUCHPAD
63 ? UmaNavigationType::FORWARD_TOUCHPAD
64 : UmaNavigationType::FORWARD_TOUCHSCREEN;
65 }
66
67 // Records UMA historgram and also user action for the cancelled overscroll. 50 // Records UMA historgram and also user action for the cancelled overscroll.
68 void RecordCancelled(OverscrollNavigationOverlay::NavigationDirection direction, 51 void RecordCancelled(NavigationDirection direction,
69 OverscrollSource source) { 52 OverscrollSource source) {
mohsen 2017/07/21 00:51:12 nit: Fits on one line.
mfomitchev 2017/07/22 02:34:31 Done.
70 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3", 53 UMA_HISTOGRAM_ENUMERATION("Overscroll.Cancelled3",
71 GetUmaNavigationType(direction, source), 54 GetUmaNavigationType(direction, source),
72 NAVIGATION_TYPE_COUNT); 55 NAVIGATION_TYPE_COUNT);
73 if (direction == OverscrollNavigationOverlay::BACK) 56 if (direction == NavigationDirection::BACK)
74 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back")); 57 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Back"));
75 else 58 else
76 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward")); 59 RecordAction(base::UserMetricsAction("Overscroll_Cancelled.Forward"));
77 } 60 }
78 61
79 } // namespace 62 } // namespace
80 63
81 // Responsible for fading out and deleting the layer of the overlay window. 64 // Responsible for fading out and deleting the layer of the overlay window.
82 class OverlayDismissAnimator 65 class OverlayDismissAnimator
83 : public ui::LayerAnimationObserver { 66 : public ui::LayerAnimationObserver {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ~OverlayDismissAnimator() override {} 99 ~OverlayDismissAnimator() override {}
117 100
118 std::unique_ptr<ui::Layer> layer_; 101 std::unique_ptr<ui::Layer> layer_;
119 102
120 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); 103 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator);
121 }; 104 };
122 105
123 OverscrollNavigationOverlay::OverscrollNavigationOverlay( 106 OverscrollNavigationOverlay::OverscrollNavigationOverlay(
124 WebContentsImpl* web_contents, 107 WebContentsImpl* web_contents,
125 aura::Window* web_contents_window) 108 aura::Window* web_contents_window)
126 : direction_(NONE), 109 : direction_(NavigationDirection::NONE),
127 web_contents_(web_contents), 110 web_contents_(web_contents),
128 loading_complete_(false), 111 loading_complete_(false),
129 received_paint_update_(false), 112 received_paint_update_(false),
130 owa_(new OverscrollWindowAnimation(this)), 113 owa_(new OverscrollWindowAnimation(this)),
131 web_contents_window_(web_contents_window) { 114 web_contents_window_(web_contents_window) {
132 } 115 }
133 116
134 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() { 117 OverscrollNavigationOverlay::~OverscrollNavigationOverlay() {
135 aura::Window* event_window = GetMainWindow(); 118 aura::Window* event_window = GetMainWindow();
136 if (owa_->is_active() && event_window) 119 if (owa_->is_active() && event_window)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( 163 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate(
181 owa_.get(), GetImageForDirection(direction_)); 164 owa_.get(), GetImageForDirection(direction_));
182 std::unique_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); 165 std::unique_ptr<aura::Window> window(new aura::Window(overscroll_delegate));
183 window->set_owned_by_parent(false); 166 window->set_owned_by_parent(false);
184 window->SetTransparent(true); 167 window->SetTransparent(true);
185 window->Init(ui::LAYER_TEXTURED); 168 window->Init(ui::LAYER_TEXTURED);
186 window->layer()->SetMasksToBounds(false); 169 window->layer()->SetMasksToBounds(false);
187 window->SetName("OverscrollOverlay"); 170 window->SetName("OverscrollOverlay");
188 web_contents_window_->AddChild(window.get()); 171 web_contents_window_->AddChild(window.get());
189 aura::Window* event_window = GetMainWindow(); 172 aura::Window* event_window = GetMainWindow();
190 if (direction_ == FORWARD) 173 if (direction_ == NavigationDirection::FORWARD)
191 web_contents_window_->StackChildAbove(window.get(), event_window); 174 web_contents_window_->StackChildAbove(window.get(), event_window);
192 else 175 else
193 web_contents_window_->StackChildBelow(window.get(), event_window); 176 web_contents_window_->StackChildBelow(window.get(), event_window);
194 window->SetBounds(bounds); 177 window->SetBounds(bounds);
195 // Set capture on the window that is receiving the overscroll events so that 178 // Set capture on the window that is receiving the overscroll events so that
196 // trackpad scroll gestures keep targetting it even if the mouse pointer moves 179 // trackpad scroll gestures keep targetting it even if the mouse pointer moves
197 // off its bounds. 180 // off its bounds.
198 event_window->SetCapture(); 181 event_window->SetCapture();
199 window->Show(); 182 window->Show();
200 return window; 183 return window;
201 } 184 }
202 185
203 const gfx::Image OverscrollNavigationOverlay::GetImageForDirection( 186 const gfx::Image OverscrollNavigationOverlay::GetImageForDirection(
204 NavigationDirection direction) const { 187 NavigationDirection direction) const {
205 const NavigationControllerImpl& controller = web_contents_->GetController(); 188 const NavigationControllerImpl& controller = web_contents_->GetController();
206 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 189 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
207 controller.GetEntryAtOffset(direction == FORWARD ? 1 : -1)); 190 controller.GetEntryAtOffset(
191 direction == NavigationDirection::FORWARD ? 1 : -1));
208 192
209 if (entry && entry->screenshot().get()) { 193 if (entry && entry->screenshot().get()) {
210 std::vector<gfx::ImagePNGRep> image_reps; 194 std::vector<gfx::ImagePNGRep> image_reps;
211 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); 195 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f));
212 return gfx::Image(image_reps); 196 return gfx::Image(image_reps);
213 } 197 }
214 return gfx::Image(); 198 return gfx::Image();
215 } 199 }
216 200
217 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateFrontWindow( 201 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateFrontWindow(
218 const gfx::Rect& bounds) { 202 const gfx::Rect& bounds) {
219 if (!web_contents_->GetController().CanGoForward()) 203 if (!web_contents_->GetController().CanGoForward())
220 return nullptr; 204 return nullptr;
221 direction_ = FORWARD; 205 direction_ = NavigationDirection::FORWARD;
222 return CreateOverlayWindow(bounds); 206 return CreateOverlayWindow(bounds);
223 } 207 }
224 208
225 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateBackWindow( 209 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateBackWindow(
226 const gfx::Rect& bounds) { 210 const gfx::Rect& bounds) {
227 if (!web_contents_->GetController().CanGoBack()) 211 if (!web_contents_->GetController().CanGoBack())
228 return nullptr; 212 return nullptr;
229 direction_ = BACK; 213 direction_ = NavigationDirection::BACK;
230 return CreateOverlayWindow(bounds); 214 return CreateOverlayWindow(bounds);
231 } 215 }
232 216
233 aura::Window* OverscrollNavigationOverlay::GetMainWindow() const { 217 aura::Window* OverscrollNavigationOverlay::GetMainWindow() const {
234 if (window_) 218 if (window_)
235 return window_.get(); 219 return window_.get();
236 return web_contents_->IsBeingDestroyed() 220 return web_contents_->IsBeingDestroyed()
237 ? nullptr 221 ? nullptr
238 : web_contents_->GetContentNativeView(); 222 : web_contents_->GetContentNativeView();
239 } 223 }
240 224
241 void OverscrollNavigationOverlay::OnOverscrollCompleting() { 225 void OverscrollNavigationOverlay::OnOverscrollCompleting() {
242 aura::Window* main_window = GetMainWindow(); 226 aura::Window* main_window = GetMainWindow();
243 if (!main_window) 227 if (!main_window)
244 return; 228 return;
245 main_window->ReleaseCapture(); 229 main_window->ReleaseCapture();
246 } 230 }
247 231
248 void OverscrollNavigationOverlay::OnOverscrollCompleted( 232 void OverscrollNavigationOverlay::OnOverscrollCompleted(
249 std::unique_ptr<aura::Window> window) { 233 std::unique_ptr<aura::Window> window) {
250 DCHECK(direction_ != NONE); 234 DCHECK_NE(direction_, NavigationDirection::NONE);
251 aura::Window* main_window = GetMainWindow(); 235 aura::Window* main_window = GetMainWindow();
252 if (!main_window) { 236 if (!main_window) {
253 RecordCancelled(direction_, owa_->overscroll_source()); 237 RecordCancelled(direction_, owa_->overscroll_source());
254 return; 238 return;
255 } 239 }
256 240
257 main_window->SetTransform(gfx::Transform()); 241 main_window->SetTransform(gfx::Transform());
258 window_ = std::move(window); 242 window_ = std::move(window);
259 // Make sure the window is in its default position. 243 // Make sure the window is in its default position.
260 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size())); 244 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size()));
261 window_->SetTransform(gfx::Transform()); 245 window_->SetTransform(gfx::Transform());
262 // Make sure the overlay window is on top. 246 // Make sure the overlay window is on top.
263 web_contents_window_->StackChildAtTop(window_.get()); 247 web_contents_window_->StackChildAtTop(window_.get());
264 248
265 // Make sure we can navigate first, as other factors can trigger a navigation 249 // Make sure we can navigate first, as other factors can trigger a navigation
266 // during an overscroll gesture and navigating without history produces a 250 // during an overscroll gesture and navigating without history produces a
267 // crash. 251 // crash.
268 bool navigated = false; 252 bool navigated = false;
269 if (direction_ == FORWARD && web_contents_->GetController().CanGoForward()) { 253 if (direction_ == NavigationDirection::FORWARD &&
254 web_contents_->GetController().CanGoForward()) {
270 web_contents_->GetController().GoForward(); 255 web_contents_->GetController().GoForward();
271 navigated = true; 256 navigated = true;
272 } else if (direction_ == BACK && web_contents_->GetController().CanGoBack()) { 257 } else if (direction_ == NavigationDirection::BACK &&
258 web_contents_->GetController().CanGoBack()) {
273 web_contents_->GetController().GoBack(); 259 web_contents_->GetController().GoBack();
274 navigated = true; 260 navigated = true;
275 } else { 261 } else {
276 // We need to dismiss the overlay without navigating as soon as the 262 // We need to dismiss the overlay without navigating as soon as the
277 // overscroll finishes. 263 // overscroll finishes.
278 RecordCancelled(direction_, owa_->overscroll_source()); 264 RecordCancelled(direction_, owa_->overscroll_source());
279 loading_complete_ = true; 265 loading_complete_ = true;
280 } 266 }
281 267
282 if (navigated) { 268 if (navigated) {
283 UMA_HISTOGRAM_ENUMERATION( 269 UMA_HISTOGRAM_ENUMERATION(
284 "Overscroll.Navigated3", 270 "Overscroll.Navigated3",
285 GetUmaNavigationType(direction_, owa_->overscroll_source()), 271 GetUmaNavigationType(direction_, owa_->overscroll_source()),
286 NAVIGATION_TYPE_COUNT); 272 NAVIGATION_TYPE_COUNT);
287 if (direction_ == BACK) 273 if (direction_ == NavigationDirection::BACK)
288 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back")); 274 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Back"));
289 else 275 else
290 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward")); 276 RecordAction(base::UserMetricsAction("Overscroll_Navigated.Forward"));
291 StartObserving(); 277 StartObserving();
292 } 278 }
293 279
294 direction_ = NONE; 280 direction_ = NavigationDirection::NONE;
295 StopObservingIfDone(); 281 StopObservingIfDone();
296 } 282 }
297 283
298 void OverscrollNavigationOverlay::OnOverscrollCancelled() { 284 void OverscrollNavigationOverlay::OnOverscrollCancelled() {
299 RecordCancelled(direction_, owa_->overscroll_source()); 285 RecordCancelled(direction_, owa_->overscroll_source());
300 aura::Window* main_window = GetMainWindow(); 286 aura::Window* main_window = GetMainWindow();
301 if (!main_window) 287 if (!main_window)
302 return; 288 return;
303 main_window->ReleaseCapture(); 289 main_window->ReleaseCapture();
304 direction_ = NONE; 290 direction_ = NavigationDirection::NONE;
305 StopObservingIfDone(); 291 StopObservingIfDone();
306 } 292 }
307 293
308 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() { 294 void OverscrollNavigationOverlay::DidFirstVisuallyNonEmptyPaint() {
309 NavigationEntry* visible_entry = 295 NavigationEntry* visible_entry =
310 web_contents_->GetController().GetVisibleEntry(); 296 web_contents_->GetController().GetVisibleEntry();
311 if (pending_entry_url_.is_empty() || 297 if (pending_entry_url_.is_empty() ||
312 DoesEntryMatchURL(visible_entry, pending_entry_url_)) { 298 DoesEntryMatchURL(visible_entry, pending_entry_url_)) {
313 received_paint_update_ = true; 299 received_paint_update_ = true;
314 StopObservingIfDone(); 300 StopObservingIfDone();
315 } 301 }
316 } 302 }
317 303
318 void OverscrollNavigationOverlay::DidStopLoading() { 304 void OverscrollNavigationOverlay::DidStopLoading() {
319 // Don't compare URLs in this case - it's possible they won't match if 305 // Don't compare URLs in this case - it's possible they won't match if
320 // a gesture-nav initiated navigation was interrupted by some other in-site 306 // a gesture-nav initiated navigation was interrupted by some other in-site
321 // navigation (e.g., from a script, or from a bookmark). 307 // navigation (e.g., from a script, or from a bookmark).
322 loading_complete_ = true; 308 loading_complete_ = true;
323 StopObservingIfDone(); 309 StopObservingIfDone();
324 } 310 }
325 311
326 } // namespace content 312 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698