Home | History | Annotate | Download | only in screensaver
      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/ash_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_EXPORT void ShowScreensaver(const GURL& url);
     29 ASH_EXPORT void CloseScreensaver();
     30 ASH_EXPORT bool IsScreensaverShown();
     31 
     32 typedef
     33     base::Callback<views::WebView*(content::BrowserContext*)> WebViewFactory;
     34 
     35 namespace internal {
     36 
     37 // Shows a URL as a screensaver. The screensaver window is fullscreen,
     38 // always on top of every other window and will reload the URL if the
     39 // renderer crashes for any reason.
     40 class ScreensaverView : public views::WidgetDelegateView,
     41                         public content::WebContentsObserver {
     42  public:
     43   static void ShowScreensaver(const GURL& url);
     44   static void CloseScreensaver();
     45 
     46   static bool IsScreensaverShown();
     47 
     48  private:
     49   friend class test::ScreensaverViewTest;
     50 
     51   explicit ScreensaverView(const GURL& url);
     52   virtual ~ScreensaverView();
     53 
     54   // views::WidgetDelegate overrides.
     55   virtual views::View* GetContentsView() OVERRIDE;
     56 
     57   // content::WebContentsObserver overrides.
     58   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
     59 
     60   void Show();
     61   void Close();
     62 
     63   // Creates and adds web contents to our view.
     64   void AddChildWebContents();
     65   // Load the screensaver in the WebView's webcontent. If the webcontents
     66   // don't exist, they'll be created by WebView.
     67   void LoadScreensaver();
     68   // Creates and shows a frameless full screen window containing our view.
     69   void ShowWindow();
     70 
     71   // For testing purposes.
     72   static ASH_EXPORT ScreensaverView* GetInstance();
     73   ASH_EXPORT bool IsScreensaverShowingURL(const GURL& url);
     74 
     75   // URL to show in the screensaver.
     76   GURL url_;
     77 
     78   // Number of times the screensaver has been terminated (usually this will be
     79   // synonymous with the number of times it has crashed).
     80   int termination_count_;
     81 
     82   // Host for the extension that implements this dialog.
     83   views::WebView* screensaver_webview_;
     84 
     85   // Window that holds the screensaver webview.
     86   views::Widget* container_window_;
     87 
     88   DISALLOW_COPY_AND_ASSIGN(ScreensaverView);
     89 };
     90 
     91 }  // namespace internal
     92 }  // namespace ash
     93 
     94 #endif  // ASH_SCREENSAVER_SCREENSAVER_VIEW_H_
     95