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

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

Issue 202183003: Fixing race conditions in ui::content::WindowSlider which could cause the overscroll overlay to nev… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 "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/render_widget_host_view.h"
12 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
13 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
14 #include "ui/compositor/layer_animation_observer.h" 15 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/image/image_png_rep.h" 18 #include "ui/gfx/image/image_png_rep.h"
18 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
19 20
20 namespace content { 21 namespace content {
21 22
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 int visible_entry_id = visible_entry ? visible_entry->GetUniqueID() : 0; 216 int visible_entry_id = visible_entry ? visible_entry->GetUniqueID() : 0;
216 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) { 217 if (visible_entry_id == pending_entry_id_ || !pending_entry_id_) {
217 // This is a paint update after the page has been loaded. So do not wait 218 // This is a paint update after the page has been loaded. So do not wait
218 // for a 'first non-empty' paint update. 219 // for a 'first non-empty' paint update.
219 received_paint_update_ = true; 220 received_paint_update_ = true;
220 StopObservingIfDone(); 221 StopObservingIfDone();
221 } 222 }
222 } 223 }
223 } 224 }
224 225
225 ui::Layer* OverscrollNavigationOverlay::CreateBackLayer() { 226 ui::Layer* OverscrollNavigationOverlay::OnSlideBackStartedCreateLayer() {
226 if (!web_contents_->GetController().CanGoBack()) 227 if (!web_contents_->GetController().CanGoBack())
227 return NULL; 228 return NULL;
228 slide_direction_ = SLIDE_BACK; 229 slide_direction_ = SLIDE_BACK;
229 return CreateSlideLayer(-1); 230 return CreateSlideLayer(-1);
230 } 231 }
231 232
232 ui::Layer* OverscrollNavigationOverlay::CreateFrontLayer() { 233 ui::Layer* OverscrollNavigationOverlay::OnSlideForwardStartedCreateLayer() {
233 if (!web_contents_->GetController().CanGoForward()) 234 if (!web_contents_->GetController().CanGoForward())
234 return NULL; 235 return NULL;
235 slide_direction_ = SLIDE_FRONT; 236 slide_direction_ = SLIDE_FRONT;
236 return CreateSlideLayer(1); 237 return CreateSlideLayer(1);
237 } 238 }
238 239
239 void OverscrollNavigationOverlay::OnWindowSlideComplete() { 240 void OverscrollNavigationOverlay::OnWindowFlingStarted() {
240 if (slide_direction_ == SLIDE_UNKNOWN) { 241 if (slide_direction_ == SLIDE_UNKNOWN) {
sadrul 2014/03/19 20:21:18 You can remove the braces
mfomitchev 2014/03/20 15:10:06 Done.
241 window_slider_.reset();
242 StopObservingIfDone();
243 return; 242 return;
244 } 243 }
245 244
246 // Change the image used for the overlay window.
247 image_delegate_->SetImage(layer_delegate_->image());
248 window_->layer()->SetTransform(gfx::Transform());
249 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size()));
250
251 SlideDirection direction = slide_direction_;
252 slide_direction_ = SLIDE_UNKNOWN;
253
254 // Reset state and wait for the new navigation page to complete 245 // Reset state and wait for the new navigation page to complete
255 // loading/painting. 246 // loading/painting.
256 StartObserving(); 247 StartObserving();
257 248
258 // Perform the navigation. 249 // Perform the navigation.
259 if (direction == SLIDE_BACK) 250 if (slide_direction_ == SLIDE_BACK)
260 web_contents_->GetController().GoBack(); 251 web_contents_->GetController().GoBack();
261 else if (direction == SLIDE_FRONT) 252 else if (slide_direction_ == SLIDE_FRONT)
262 web_contents_->GetController().GoForward(); 253 web_contents_->GetController().GoForward();
263 else 254 else
264 NOTREACHED(); 255 NOTREACHED();
265 256
266 NavigationEntry* pending_entry = 257 NavigationEntry* pending_entry =
267 web_contents_->GetController().GetPendingEntry(); 258 web_contents_->GetController().GetPendingEntry();
268 // Save id of the pending entry to identify when it loads and paints later. 259 // Save id of the pending entry to identify when it loads and paints later.
269 // Under some circumstances navigation can leave a null pending entry - 260 // Under some circumstances navigation can leave a null pending entry -
270 // see comments in NavigationControllerImpl::NavigateToPendingEntry(). 261 // see comments in NavigationControllerImpl::NavigateToPendingEntry().
271 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0; 262 pending_entry_id_ = pending_entry ? pending_entry->GetUniqueID() : 0;
272 } 263 }
273 264
265 void OverscrollNavigationOverlay::OnWindowFlingCompleted() {
266 if (slide_direction_ == SLIDE_UNKNOWN) {
267 window_slider_.reset();
268 StopObservingIfDone();
269 return;
270 }
271
272 // Change the image used for the overlay window.
273 image_delegate_->SetImage(layer_delegate_->image());
274 window_->layer()->SetTransform(gfx::Transform());
275 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size()));
276 slide_direction_ = SLIDE_UNKNOWN;
277
278 // Make sure the overlay layer is repainted before we dismiss it, otherwise
279 // OverlayDismissAnimator may end up showing the wrong screenshot during the
280 // fadeout animation.
281 if (received_paint_update_ && need_paint_update_) {
282 received_paint_update_ = false;
283 RenderWidgetHost* host =
284 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost();
285 RenderViewHostImpl* view_host =
286 static_cast<RenderViewHostImpl*> (RenderViewHost::From(host));
287 view_host->ScheduleComposite();
288 } else if (!need_paint_update_) {
289 StopObservingIfDone();
290 }
291 }
292
274 void OverscrollNavigationOverlay::OnWindowSlideAborted() { 293 void OverscrollNavigationOverlay::OnWindowSlideAborted() {
294 // The overlay may have been kept because of an in-progress slide, so check
295 // if we need to dismiss it.
sadrul 2014/03/19 20:21:18 I am not sure I understand this comment.
mfomitchev 2014/03/20 15:10:06 Yeah, it's poorly worded. Basically I was just try
275 StopObservingIfDone(); 296 StopObservingIfDone();
276 } 297 }
277 298
278 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() { 299 void OverscrollNavigationOverlay::OnWindowSliderDestroyed() {
279 // We only want to take an action here if WindowSlider is being destroyed 300 // We only want to take an action here if WindowSlider is being destroyed
280 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL, 301 // outside of OverscrollNavigationOverlay. If window_slider_.get() is NULL,
281 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and 302 // then OverscrollNavigationOverlay is the one destroying WindowSlider, and
282 // we don't need to do anything. 303 // we don't need to do anything.
283 // This check prevents StopObservingIfDone() being called multiple times 304 // This check prevents StopObservingIfDone() being called multiple times
284 // (including recursively) for a single event. 305 // (including recursively) for a single event.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 bool OverscrollNavigationOverlay::OnMessageReceived( 352 bool OverscrollNavigationOverlay::OnMessageReceived(
332 const IPC::Message& message) { 353 const IPC::Message& message) {
333 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 354 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 IPC_BEGIN_MESSAGE_MAP(OverscrollNavigationOverlay, message) 355 IPC_BEGIN_MESSAGE_MAP(OverscrollNavigationOverlay, message)
335 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) 356 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
336 IPC_END_MESSAGE_MAP() 357 IPC_END_MESSAGE_MAP()
337 return false; 358 return false;
338 } 359 }
339 360
340 } // namespace content 361 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698