Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / chrome_shell_delegate_views.cc
1 // Copyright 2013 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/ash/chrome_shell_delegate.h"
6
7 #include "ash/accessibility_delegate.h"
8 #include "ash/magnifier/magnifier_constants.h"
9 #include "ash/media_delegate.h"
10 #include "ash/system/tray/default_system_tray_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h"
13 #include "chrome/browser/accessibility/accessibility_events.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/session_startup_pref.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/ash/caps_lock_delegate_views.h"
18 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h"
19 #include "chrome/browser/ui/ash/session_state_delegate_views.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/host_desktop.h"
26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
27 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "content/public/browser/notification_service.h"
30
31 #if defined(OS_WIN)
32 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
33 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
34 #endif
35
36 namespace {
37
38 class NewWindowDelegateImpl : public ChromeNewWindowDelegate {
39  public:
40   NewWindowDelegateImpl() {}
41   virtual ~NewWindowDelegateImpl() {}
42
43   // Overridden from ash::NewWindowDelegate:
44   virtual void OpenFileManager() OVERRIDE {}
45   virtual void OpenCrosh() OVERRIDE {}
46   virtual void ShowKeyboardOverlay() OVERRIDE {}
47
48  private:
49   DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
50 };
51
52 class MediaDelegateImpl : public ash::MediaDelegate {
53  public:
54   MediaDelegateImpl() {}
55   virtual ~MediaDelegateImpl() {}
56   virtual void HandleMediaNextTrack() OVERRIDE {}
57   virtual void HandleMediaPlayPause() OVERRIDE {}
58   virtual void HandleMediaPrevTrack() OVERRIDE {}
59
60  private:
61   DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
62 };
63
64 class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate {
65  public:
66   EmptyAccessibilityDelegate() {}
67   virtual ~EmptyAccessibilityDelegate() {}
68
69   virtual void ToggleHighContrast() OVERRIDE {
70   }
71
72   virtual bool IsHighContrastEnabled() const OVERRIDE {
73     return false;
74   }
75
76   virtual bool IsSpokenFeedbackEnabled() const OVERRIDE {
77     return false;
78   }
79
80   virtual void ToggleSpokenFeedback(
81       ash::AccessibilityNotificationVisibility notify) OVERRIDE {
82   }
83
84   virtual void SetLargeCursorEnabled(bool enalbed) OVERRIDE {
85   }
86
87   virtual bool IsLargeCursorEnabled() const OVERRIDE {
88     return false;
89   }
90
91   virtual void SetMagnifierEnabled(bool enabled) OVERRIDE {
92   }
93
94   virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
95   }
96
97   virtual bool IsMagnifierEnabled() const OVERRIDE {
98     return false;
99   }
100
101   virtual void SetAutoclickEnabled(bool enabled) OVERRIDE {
102   }
103
104   virtual bool IsAutoclickEnabled() const OVERRIDE {
105     return false;
106   }
107
108   virtual ash::MagnifierType GetMagnifierType() const OVERRIDE {
109     return ash::kDefaultMagnifierType;
110   }
111
112   virtual void SaveScreenMagnifierScale(double scale) OVERRIDE {
113   }
114
115   virtual double GetSavedScreenMagnifierScale() OVERRIDE {
116     return std::numeric_limits<double>::min();
117   }
118
119   virtual bool ShouldShowAccessibilityMenu() const OVERRIDE {
120     return false;
121   }
122
123   virtual void SilenceSpokenFeedback() const OVERRIDE {
124   }
125
126   virtual void SetVirtualKeyboardEnabled(bool enabled) OVERRIDE {
127   }
128
129   virtual bool IsVirtualKeyboardEnabled() const OVERRIDE {
130     return false;
131   }
132
133   virtual void TriggerAccessibilityAlert(
134       ash::AccessibilityAlert alert) OVERRIDE {
135   }
136
137   virtual ash::AccessibilityAlert GetLastAccessibilityAlert() OVERRIDE {
138     return ash::A11Y_ALERT_NONE;
139   }
140
141   base::TimeDelta PlayShutdownSound() const OVERRIDE {
142     return base::TimeDelta();
143   }
144
145  private:
146   DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate);
147 };
148
149 }  // namespace
150
151 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
152   return false;
153 }
154
155 void ChromeShellDelegate::PreInit() {
156 }
157
158 void ChromeShellDelegate::Shutdown() {
159 }
160
161 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
162   return new NewWindowDelegateImpl;
163 }
164
165 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
166   return new MediaDelegateImpl;
167 }
168
169 ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() {
170   return new CapsLockDelegate();
171 }
172
173 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
174   return new SessionStateDelegate;
175 }
176
177 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
178 #if defined(OS_WIN)
179   return CreateWindowsSystemTrayDelegate();
180 #else
181   return new ash::DefaultSystemTrayDelegate;
182 #endif
183 }
184
185 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
186   return new EmptyAccessibilityDelegate;
187 }
188
189 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
190 #if defined(OS_WIN)
191   return ::CreateUserWallpaperDelegate();
192 #else
193   return NULL;
194 #endif
195 }
196
197 void ChromeShellDelegate::Observe(int type,
198                                   const content::NotificationSource& source,
199                                   const content::NotificationDetails& details) {
200   switch (type) {
201     case chrome::NOTIFICATION_ASH_SESSION_STARTED: {
202 #if defined(OS_WIN)
203       // If we are launched to service a windows 8 search request then let the
204       // IPC which carries the search string create the browser and initiate
205       // the navigation.
206       if (CommandLine::ForCurrentProcess()->HasSwitch(
207           switches::kWindows8Search))
208         break;
209 #endif
210       // If Chrome ASH is launched when no browser is open in the desktop,
211       // we should execute the startup code.
212       // If there are browsers open in the desktop, we create a browser window
213       // and open a new tab page, if session restore is not on.
214       BrowserList* desktop_list = BrowserList::GetInstance(
215           chrome::HOST_DESKTOP_TYPE_NATIVE);
216       if (desktop_list->empty()) {
217         // We pass a dummy command line here, because the browser is launched in
218         // silent-mode by the metro viewer process, which causes the
219         // StartupBrowserCreatorImpl class to not create any browsers which is
220         // not the behavior we want.
221         CommandLine dummy(CommandLine::NO_PROGRAM);
222         StartupBrowserCreatorImpl startup_impl(
223             base::FilePath(),
224             dummy,
225             chrome::startup::IS_NOT_FIRST_RUN);
226         startup_impl.Launch(
227             ProfileManager::GetActiveUserProfile(),
228             std::vector<GURL>(),
229             true,
230             chrome::HOST_DESKTOP_TYPE_ASH);
231       } else {
232         Browser* browser =
233             chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
234         if (browser && browser->is_type_tabbed()) {
235           chrome::AddTabAt(browser, GURL(), -1, true);
236           return;
237         }
238
239         chrome::ScopedTabbedBrowserDisplayer displayer(
240             ProfileManager::GetActiveUserProfile(),
241             chrome::HOST_DESKTOP_TYPE_ASH);
242         chrome::AddTabAt(displayer.browser(), GURL(), -1, true);
243       }
244       break;
245     }
246     case chrome::NOTIFICATION_ASH_SESSION_ENDED:
247       break;
248     default:
249       NOTREACHED() << "Unexpected notification " << type;
250   }
251 }
252
253 void ChromeShellDelegate::PlatformInit() {
254 #if defined(OS_WIN)
255   registrar_.Add(this,
256                  chrome::NOTIFICATION_ASH_SESSION_STARTED,
257                  content::NotificationService::AllSources());
258   registrar_.Add(this,
259                  chrome::NOTIFICATION_ASH_SESSION_ENDED,
260                  content::NotificationService::AllSources());
261 #endif
262 }