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

Side by Side Diff: ash/screensaver/screensaver_view.cc

Issue 10191010: Re-implement the screensaver to use WebView instead of ExtensionDialogHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ut fix. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/screensaver/screensaver_view.h ('k') | ash/screensaver/screensaver_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "ash/screensaver/screensaver_view.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h"
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "ui/gfx/screen.h"
14 #include "ui/aura/root_window.h"
15 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/controls/webview/webview.h"
17 #include "ui/views/widget/widget.h"
18
19 using content::BrowserThread;
20
21 namespace {
22
23 ash::internal::ScreensaverView* g_instance = NULL;
24
25 } // namespace
26
27 namespace ash {
28
29 void ShowScreensaver(const GURL& url) {
30 internal::ScreensaverView::ShowScreensaver(url);
31 }
32
33 void CloseScreensaver() {
34 internal::ScreensaverView::CloseScreensaver();
35 }
36
37 namespace internal {
38
39 // static
40 void ScreensaverView::ShowScreensaver(const GURL& url) {
41 if (!g_instance) {
42 g_instance = new ScreensaverView(url);
43 g_instance->Show();
44 }
45 }
46
47 // static
48 void ScreensaverView::CloseScreensaver() {
49 if (g_instance) {
50 g_instance->Close();
51 g_instance = NULL;
52 }
53 }
54
55 ////////////////////////////////////////////////////////////////////////////////
56 // ScreensaverView, views::WidgetDelegateView implementation.
57 views::View* ScreensaverView::GetContentsView() {
58 return this;
59 }
60
61 ////////////////////////////////////////////////////////////////////////////////
62 // ScreensaverView, content::WebContentsObserver implementation.
63 void ScreensaverView::RenderViewGone(
64 base::TerminationStatus status) {
65 LOG(ERROR) << "Screensaver terminated with status " << status
66 << ", reloading.";
67 // Reload the screensaver url into the webcontents.
68 LoadScreensaver();
69 }
70
71 ////////////////////////////////////////////////////////////////////////////////
72 // ScreensaverView private methods.
73 ScreensaverView::ScreensaverView(const GURL& url)
74 : url_(url),
75 screensaver_webview_(NULL),
76 container_window_(NULL) {
77 }
78
79 ScreensaverView::~ScreensaverView() {
80 }
81
82 void ScreensaverView::Show() {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 // Add the WebView to our view.
85 AddChildWebContents();
86 // Show the window.
87 ShowWindow();
88 }
89
90 void ScreensaverView::Close() {
91 DCHECK(GetWidget());
92 GetWidget()->Close();
93 }
94
95 void ScreensaverView::AddChildWebContents() {
96 content::BrowserContext* context =
97 Shell::GetInstance()->delegate()->GetCurrentBrowserContext();
98 screensaver_webview_ = new views::WebView(context);
99 SetLayoutManager(new views::FillLayout);
100 AddChildView(screensaver_webview_);
101
102 LoadScreensaver();
103 content::WebContentsObserver::Observe(
104 screensaver_webview_->GetWebContents());
105 }
106
107 void ScreensaverView::LoadScreensaver() {
108 screensaver_webview_->GetWebContents()->GetController().LoadURL(
109 url_,
110 content::Referrer(),
111 content::PAGE_TRANSITION_START_PAGE,
112 std::string());
113 }
114
115 void ScreensaverView::ShowWindow() {
116 aura::RootWindow* root_window = ash::Shell::GetRootWindow();
117 gfx::Rect screen_rect =
118 gfx::Screen::GetMonitorNearestWindow(root_window).bounds();
119
120 // We want to be the fullscreen topmost child of the root window.
121 // There should be nothing ever really that should show up on top of us.
122 container_window_ = new views::Widget();
123 views::Widget::InitParams params(
124 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
125 params.delegate = this;
126 params.parent = root_window;
127 container_window_->Init(params);
128
129 container_window_->StackAtTop();
130 container_window_->SetBounds(screen_rect);
131 container_window_->Show();
132 }
133
134 // static
135 ScreensaverView* ScreensaverView::GetInstance() {
136 return g_instance;
137 }
138
139 } // namespace internal
140 } // namespace ash
OLDNEW
« no previous file with comments | « ash/screensaver/screensaver_view.h ('k') | ash/screensaver/screensaver_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698