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

Side by Side Diff: chrome/browser/ui/views/ash/chrome_shell_delegate.cc

Issue 10825435: views: Remove old ash files and update DEPS whitelist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | « chrome/browser/ui/views/ash/chrome_shell_delegate.h ('k') | no next file » | 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 "chrome/browser/ui/views/ash/chrome_shell_delegate.h"
6
7 #include "ash/launcher/launcher_types.h"
8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/wm/window_util.h"
10 #include "base/command_line.h"
11 #include "chrome/browser/chromeos/login/screen_locker.h"
12 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
13 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/sessions/tab_restore_service.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h"
17 #include "chrome/browser/ui/ash/app_list/app_list_view_delegate.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
19 #include "chrome/browser/ui/ash/user_action_handler.h"
20 #include "chrome/browser/ui/ash/window_positioner.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/views/frame/browser_view.h"
25 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/user_metrics.h"
31 #include "content/public/browser/web_contents.h"
32 #include "grit/generated_resources.h"
33 #include "ui/aura/client/user_action_client.h"
34 #include "ui/aura/window.h"
35
36 #if defined(OS_CHROMEOS)
37 #include "ash/keyboard_overlay/keyboard_overlay_view.h"
38 #include "base/chromeos/chromeos_version.h"
39 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
40 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
41 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
42 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
43 #include "chrome/browser/chromeos/login/user_manager.h"
44 #include "chrome/browser/chromeos/login/webui_login_display_host.h"
45 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h"
46 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
47 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
48 #include "chromeos/dbus/dbus_thread_manager.h"
49 #include "chromeos/dbus/power_manager_client.h"
50 #include "chromeos/dbus/session_manager_client.h"
51 #endif
52
53 namespace {
54
55 // Returns the browser that should handle accelerators.
56 Browser* GetTargetBrowser() {
57 Browser* browser = browser::FindBrowserWithWindow(ash::wm::GetActiveWindow());
58 if (browser)
59 return browser;
60 return browser::FindOrCreateTabbedBrowser(
61 ProfileManager::GetDefaultProfileOrOffTheRecord());
62 }
63
64 } // namespace
65
66 // static
67 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
68
69 ChromeShellDelegate::ChromeShellDelegate()
70 : window_positioner_(new WindowPositioner()),
71 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
72 instance_ = this;
73 #if defined(OS_CHROMEOS)
74 registrar_.Add(
75 this,
76 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
77 content::NotificationService::AllSources());
78 registrar_.Add(
79 this,
80 chrome::NOTIFICATION_SESSION_STARTED,
81 content::NotificationService::AllSources());
82 #endif
83 }
84
85 ChromeShellDelegate::~ChromeShellDelegate() {
86 if (instance_ == this)
87 instance_ = NULL;
88 }
89
90 bool ChromeShellDelegate::IsUserLoggedIn() {
91 #if defined(OS_CHROMEOS)
92 // When running a Chrome OS build outside of a device (i.e. on a developer's
93 // workstation) and not running as login-manager, pretend like we're always
94 // logged in.
95 if (!base::chromeos::IsRunningOnChromeOS() &&
96 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager)) {
97 return true;
98 }
99
100 return chromeos::UserManager::Get()->IsUserLoggedIn();
101 #else
102 return true;
103 #endif
104 }
105
106 // Returns true if we're logged in and browser has been started
107 bool ChromeShellDelegate::IsSessionStarted() {
108 #if defined(OS_CHROMEOS)
109 return chromeos::UserManager::Get()->IsSessionStarted();
110 #else
111 return true;
112 #endif
113 }
114
115 void ChromeShellDelegate::LockScreen() {
116 #if defined(OS_CHROMEOS)
117 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession) &&
118 !chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) {
119 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
120 RequestLockScreen();
121 }
122 #endif
123 }
124
125 void ChromeShellDelegate::UnlockScreen() {
126 // This is used only for testing thus far.
127 NOTIMPLEMENTED();
128 }
129
130 bool ChromeShellDelegate::IsScreenLocked() const {
131 #if defined(OS_CHROMEOS)
132 if (!chromeos::ScreenLocker::default_screen_locker())
133 return false;
134 return chromeos::ScreenLocker::default_screen_locker()->locked();
135 #else
136 return false;
137 #endif
138 }
139
140 void ChromeShellDelegate::Shutdown() {
141 #if defined(OS_CHROMEOS)
142 content::RecordAction(content::UserMetricsAction("Shutdown"));
143 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
144 RequestShutdown();
145 #endif
146 }
147
148 void ChromeShellDelegate::Exit() {
149 browser::AttemptUserExit();
150 }
151
152 void ChromeShellDelegate::NewTab() {
153 Browser* browser = GetTargetBrowser();
154 // If the browser was not active, we call BrowserWindow::Show to make it
155 // visible. Otherwise, we let Browser::NewTab handle the active window change.
156 const bool was_active = browser->window()->IsActive();
157 chrome::NewTab(browser);
158 if (!was_active)
159 browser->window()->Show();
160 }
161
162 void ChromeShellDelegate::NewWindow(bool is_incognito) {
163 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
164 chrome::NewEmptyWindow(
165 is_incognito ? profile->GetOffTheRecordProfile() : profile);
166 }
167
168 void ChromeShellDelegate::OpenFileManager(bool as_dialog) {
169 #if defined(OS_CHROMEOS)
170 if (as_dialog) {
171 Browser* browser =
172 browser::FindBrowserWithWindow(ash::wm::GetActiveWindow());
173 // Open the select file dialog only if there is an active browser where the
174 // selected file is displayed. Otherwise open a file manager in a tab.
175 if (browser) {
176 browser->OpenFile();
177 return;
178 }
179 }
180 file_manager_util::OpenApplication();
181 #endif
182 }
183
184 void ChromeShellDelegate::OpenCrosh() {
185 #if defined(OS_CHROMEOS)
186 Browser* browser = GetTargetBrowser();
187 GURL crosh_url = TerminalExtensionHelper::GetCroshExtensionURL(
188 browser->profile());
189 if (!crosh_url.is_valid())
190 return;
191 browser->OpenURL(
192 content::OpenURLParams(crosh_url,
193 content::Referrer(),
194 NEW_FOREGROUND_TAB,
195 content::PAGE_TRANSITION_GENERATED,
196 false));
197 #endif
198 }
199
200 void ChromeShellDelegate::OpenMobileSetup(const std::string& service_path) {
201 #if defined(OS_CHROMEOS)
202 MobileSetupDialog::Show(service_path);
203 #endif
204 }
205
206 void ChromeShellDelegate::RestoreTab() {
207 Browser* browser = GetTargetBrowser();
208 // Do not restore tabs while in the incognito mode.
209 if (browser->profile()->IsOffTheRecord())
210 return;
211 TabRestoreService* service =
212 TabRestoreServiceFactory::GetForProfile(browser->profile());
213 if (!service)
214 return;
215 if (service->IsLoaded()) {
216 chrome::RestoreTab(browser);
217 } else {
218 service->LoadTabsFromLastSession();
219 // LoadTabsFromLastSession is asynchronous, so TabRestoreService has not
220 // finished loading the entries at this point. Wait for next event cycle
221 // which loads the restored tab entries.
222 MessageLoop::current()->PostTask(
223 FROM_HERE,
224 base::Bind(&ChromeShellDelegate::RestoreTab,
225 weak_factory_.GetWeakPtr()));
226 }
227 }
228
229 bool ChromeShellDelegate::RotatePaneFocus(ash::Shell::Direction direction) {
230 aura::Window* window = ash::wm::GetActiveWindow();
231 if (!window)
232 return false;
233
234 Browser* browser = browser::FindBrowserWithWindow(window);
235 if (!browser)
236 return false;
237
238 switch (direction) {
239 case ash::Shell::FORWARD:
240 chrome::FocusNextPane(browser);
241 break;
242 case ash::Shell::BACKWARD:
243 chrome::FocusPreviousPane(browser);
244 break;
245 }
246 return true;
247 }
248
249 void ChromeShellDelegate::ShowKeyboardOverlay() {
250 #if defined(OS_CHROMEOS)
251 // TODO(mazda): Move the show logic to ash (http://crbug.com/124222).
252 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
253 std::string url(chrome::kChromeUIKeyboardOverlayURL);
254 KeyboardOverlayView::ShowDialog(profile,
255 new ChromeWebContentsHandler,
256 GURL(url));
257 #endif
258 }
259
260 void ChromeShellDelegate::ShowTaskManager() {
261 Browser* browser = browser::FindOrCreateTabbedBrowser(
262 ProfileManager::GetDefaultProfileOrOffTheRecord());
263 chrome::OpenTaskManager(browser, false);
264 }
265
266 content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() {
267 return ProfileManager::GetDefaultProfile();
268 }
269
270 void ChromeShellDelegate::ToggleSpokenFeedback() {
271 #if defined(OS_CHROMEOS)
272 content::WebUI* login_screen_web_ui = NULL;
273 chromeos::WebUILoginDisplayHost* host =
274 static_cast<chromeos::WebUILoginDisplayHost*>(
275 chromeos::BaseLoginDisplayHost::default_host());
276 if (host && host->GetOobeUI())
277 login_screen_web_ui = host->GetOobeUI()->web_ui();
278 chromeos::accessibility::ToggleSpokenFeedback(login_screen_web_ui);
279 #endif
280 }
281
282 bool ChromeShellDelegate::IsSpokenFeedbackEnabled() const {
283 #if defined(OS_CHROMEOS)
284 return chromeos::accessibility::IsSpokenFeedbackEnabled();
285 #else
286 return false;
287 #endif
288 }
289
290 app_list::AppListViewDelegate*
291 ChromeShellDelegate::CreateAppListViewDelegate() {
292 // Shell will own the created delegate.
293 return new AppListViewDelegate;
294 }
295
296 ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate(
297 ash::LauncherModel* model) {
298 ChromeLauncherController* controller =
299 new ChromeLauncherController(NULL, model);
300 controller->Init();
301 return controller;
302 }
303
304 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate(
305 ash::SystemTray* tray) {
306 #if defined(OS_CHROMEOS)
307 return chromeos::CreateSystemTrayDelegate(tray);
308 #else
309 return NULL;
310 #endif
311 }
312
313 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
314 #if defined(OS_CHROMEOS)
315 return chromeos::CreateUserWallpaperDelegate();
316 #else
317 return NULL;
318 #endif
319 }
320
321 aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
322 return new UserActionHandler;
323 }
324
325 void ChromeShellDelegate::OpenFeedbackPage() {
326 chrome::OpenFeedbackDialog(GetTargetBrowser());
327 }
328
329 void ChromeShellDelegate::RecordUserMetricsAction(
330 ash::UserMetricsAction action) {
331 switch (action) {
332 case ash::UMA_ACCEL_PREVWINDOW_TAB:
333 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab"));
334 break;
335 case ash::UMA_ACCEL_NEXTWINDOW_TAB:
336 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab"));
337 break;
338 case ash::UMA_ACCEL_PREVWINDOW_F5:
339 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_F5"));
340 break;
341 case ash::UMA_ACCEL_NEXTWINDOW_F5:
342 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5"));
343 break;
344 case ash::UMA_ACCEL_NEWTAB_T:
345 content::RecordAction(content::UserMetricsAction("Accel_NewTab_T"));
346 break;
347 case ash::UMA_ACCEL_SEARCH_LWIN:
348 content::RecordAction(content::UserMetricsAction("Accel_Search_LWin"));
349 break;
350 case ash::UMA_MOUSE_DOWN:
351 content::RecordAction(content::UserMetricsAction("Mouse_Down"));
352 break;
353 case ash::UMA_TOUCHSCREEN_TAP_DOWN:
354 content::RecordAction(content::UserMetricsAction("Touchscreen_Down"));
355 break;
356 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
357 content::RecordAction(
358 content::UserMetricsAction("Launcher_ClickOnApplistButton"));
359 break;
360 case ash::UMA_LAUNCHER_CLICK_ON_APP:
361 content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp"));
362 break;
363 }
364 }
365
366 void ChromeShellDelegate::Observe(int type,
367 const content::NotificationSource& source,
368 const content::NotificationDetails& details) {
369 #if defined(OS_CHROMEOS)
370 switch (type) {
371 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED:
372 ash::Shell::GetInstance()->CreateLauncher();
373 break;
374 case chrome::NOTIFICATION_SESSION_STARTED:
375 ash::Shell::GetInstance()->ShowLauncher();
376 break;
377 default:
378 NOTREACHED() << "Unexpected notification " << type;
379 }
380 #else
381 // MSVC++ warns about switch statements without any cases.
382 NOTREACHED() << "Unexpected notification " << type;
383 #endif
384 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/chrome_shell_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698