Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / screensaver / screensaver_view.h
1 // Copyright (c) 2012 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.
4
5 #ifndef ASH_SCREENSAVER_SCREENSAVER_VIEW_H_
6 #define ASH_SCREENSAVER_SCREENSAVER_VIEW_H_
7
8 #include "ash/content_support/ash_with_content_export.h"
9 #include "base/callback.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "ui/views/widget/widget_delegate.h"
12 #include "url/gurl.h"
13
14 namespace content {
15 class BrowserContent;
16 }
17
18 namespace views {
19 class WebView;
20 }
21
22 namespace ash {
23
24 namespace test {
25 class ScreensaverViewTest;
26 }
27
28 ASH_WITH_CONTENT_EXPORT void ShowScreensaver(const GURL& url);
29 ASH_WITH_CONTENT_EXPORT void CloseScreensaver();
30 ASH_WITH_CONTENT_EXPORT bool IsScreensaverShown();
31
32 typedef
33     base::Callback<views::WebView*(content::BrowserContext*)> WebViewFactory;
34
35 // Shows a URL as a screensaver. The screensaver window is fullscreen,
36 // always on top of every other window and will reload the URL if the
37 // renderer crashes for any reason.
38 class ScreensaverView : public views::WidgetDelegateView,
39                         public content::WebContentsObserver {
40  public:
41   static void ShowScreensaver(const GURL& url);
42   static void CloseScreensaver();
43
44   static bool IsScreensaverShown();
45
46  private:
47   friend class test::ScreensaverViewTest;
48
49   explicit ScreensaverView(const GURL& url);
50   virtual ~ScreensaverView();
51
52   // views::WidgetDelegate overrides.
53   virtual views::View* GetContentsView() OVERRIDE;
54
55   // content::WebContentsObserver overrides.
56   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
57
58   void Show();
59   void Close();
60
61   // Creates and adds web contents to our view.
62   void AddChildWebContents();
63   // Load the screensaver in the WebView's webcontent. If the webcontents
64   // don't exist, they'll be created by WebView.
65   void LoadScreensaver();
66   // Creates and shows a frameless full screen window containing our view.
67   void ShowWindow();
68
69   // For testing purposes.
70   static ASH_WITH_CONTENT_EXPORT ScreensaverView* GetInstance();
71   ASH_WITH_CONTENT_EXPORT bool IsScreensaverShowingURL(const GURL& url);
72
73   // URL to show in the screensaver.
74   GURL url_;
75
76   // Number of times the screensaver has been terminated (usually this will be
77   // synonymous with the number of times it has crashed).
78   int termination_count_;
79
80   // Host for the extension that implements this dialog.
81   views::WebView* screensaver_webview_;
82
83   // Window that holds the screensaver webview.
84   views::Widget* container_window_;
85
86   DISALLOW_COPY_AND_ASSIGN(ScreensaverView);
87 };
88
89 }  // namespace ash
90
91 #endif  // ASH_SCREENSAVER_SCREENSAVER_VIEW_H_