Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / web_contents / aura / overscroll_navigation_overlay.h
blob32b8819c89f8bd1f7ee73ebf442fecdfe170936c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "content/browser/web_contents/aura/window_slider.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h"
14 struct ViewHostMsg_UpdateRect_Params;
16 namespace content {
18 class ImageLayerDelegate;
19 class ImageWindowDelegate;
20 class OverscrollNavigationOverlayTest;
22 // When a history navigation is triggered at the end of an overscroll
23 // navigation, it is necessary to show the history-screenshot until the page is
24 // done navigating and painting. This class accomplishes this by showing the
25 // screenshot window on top of the page until the page has completed loading and
26 // painting.
27 class CONTENT_EXPORT OverscrollNavigationOverlay
28 : public WebContentsObserver,
29 public WindowSlider::Delegate {
30 public:
31 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents);
32 virtual ~OverscrollNavigationOverlay();
34 bool has_window() const { return !!window_.get(); }
36 // Resets state and starts observing |web_contents_| for page load/paint
37 // updates. This function makes sure that the screenshot window is stacked
38 // on top, so that it hides the content window behind it, and destroys the
39 // screenshot window when the page is done loading/painting.
40 void StartObserving();
42 // Sets the screenshot window and the delegate. This takes ownership of
43 // |window|.
44 // Note that ImageWindowDelegate manages its own lifetime, so this function
45 // does not take ownership of |delegate|.
46 void SetOverlayWindow(scoped_ptr<aura::Window> window,
47 ImageWindowDelegate* delegate);
49 // Sets up the overlay for tests.
50 void SetupForTesting();
52 private:
53 friend class OverscrollNavigationOverlayTest;
54 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
55 FirstVisuallyNonEmptyPaint_NoImage);
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
57 FirstVisuallyNonEmptyPaint_WithImage);
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
59 PaintUpdateWithoutNonEmptyPaint);
60 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
61 MultiNavigation_LoadingUpdate);
62 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
63 MultiNavigation_PaintUpdate);
65 enum SlideDirection {
66 SLIDE_UNKNOWN,
67 SLIDE_BACK,
68 SLIDE_FRONT
71 // Stop observing the page and start the final overlay fade-out animation
72 // if the page-load has completed and the page has been painted, and a
73 // window-slide isn't in progress.
74 void StopObservingIfDone();
76 // Creates a layer to be used for window-slide. |offset| is the offset of the
77 // NavigationEntry for the screenshot image to display.
78 ui::Layer* CreateSlideLayer(int offset);
80 // IPC message callbacks.
81 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
83 // Overridden from WindowSlider::Delegate:
84 virtual ui::Layer* CreateBackLayer() OVERRIDE;
85 virtual ui::Layer* CreateFrontLayer() OVERRIDE;
86 virtual void OnWindowSlideCompleting() OVERRIDE;
87 virtual void OnWindowSlideCompleted() OVERRIDE;
88 virtual void OnWindowSlideAborted() OVERRIDE;
89 virtual void OnWindowSliderDestroyed() OVERRIDE;
91 // Overridden from WebContentsObserver:
92 virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE;
93 virtual void DidFirstVisuallyNonEmptyPaint(int32 page_id) OVERRIDE;
94 virtual void DidStopLoading(RenderViewHost* host) OVERRIDE;
95 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
97 // The WebContents which is being navigated.
98 WebContentsImpl* web_contents_;
100 // The screenshot overlay window.
101 scoped_ptr<aura::Window> window_;
103 // This is the WindowDelegate of |window_|. The delegate manages its own
104 // lifetime (destroys itself when |window_| is destroyed).
105 ImageWindowDelegate* image_delegate_;
107 bool loading_complete_;
108 bool received_paint_update_;
110 // Unique ID of the NavigationEntry we are navigating to. This is needed to
111 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
112 // when the relevant page loads and paints.
113 int pending_entry_id_;
115 // The |WindowSlider| that allows sliding history layers while the page is
116 // being reloaded.
117 scoped_ptr<WindowSlider> window_slider_;
119 // The direction of the in-progress slide (if any).
120 SlideDirection slide_direction_;
122 // The LayerDelegate used for the back/front layers during a slide.
123 scoped_ptr<ImageLayerDelegate> layer_delegate_;
125 // During tests, the aura windows don't get any paint updates. So the overlay
126 // container keeps waiting for a paint update it never receives, causing a
127 // timeout. So during tests, disable the wait for paint updates.
128 bool need_paint_update_;
130 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
133 } // namespace content
135 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_