- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / chrome_new_window_delegate_chromeos.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_new_window_delegate_chromeos.h"
6
7 #include "apps/shell_window_registry.h"
8 #include "apps/ui/native_app_window.h"
9 #include "ash/keyboard_overlay/keyboard_overlay_view.h"
10 #include "chrome/browser/chromeos/file_manager/app_id.h"
11 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/extensions/application_launch.h"
17 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
18 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_view.h"
22
23 ChromeNewWindowDelegateChromeos::ChromeNewWindowDelegateChromeos() {}
24 ChromeNewWindowDelegateChromeos::~ChromeNewWindowDelegateChromeos() {}
25
26 void ChromeNewWindowDelegateChromeos::OpenFileManager() {
27   using file_manager::kFileManagerAppId;
28   Profile* const profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
29   const ExtensionService* const service = profile->GetExtensionService();
30   if (service == NULL ||
31       !service->IsExtensionEnabledForLauncher(kFileManagerAppId))
32     return;
33   const extensions::Extension* const extension =
34       service->GetInstalledExtension(kFileManagerAppId);
35   // event_flags = 0 means this invokes the same behavior as the launcher
36   // item is clicked without any keyboard modifiers.
37   OpenApplication(AppLaunchParams(profile,
38                                   extension,
39                                   0 /* event_flags */,
40                                   chrome::HOST_DESKTOP_TYPE_ASH));
41 }
42
43 void ChromeNewWindowDelegateChromeos::OpenCrosh() {
44   GURL crosh_url = extensions::TerminalExtensionHelper::GetCroshExtensionURL(
45       ProfileManager::GetDefaultProfileOrOffTheRecord());
46   if (!crosh_url.is_valid())
47     return;
48   chrome::ScopedTabbedBrowserDisplayer displayer(
49       ProfileManager::GetDefaultProfileOrOffTheRecord(),
50       chrome::HOST_DESKTOP_TYPE_ASH);
51   Browser* browser = displayer.browser();
52   content::WebContents* page = browser->OpenURL(
53       content::OpenURLParams(crosh_url,
54                              content::Referrer(),
55                              NEW_FOREGROUND_TAB,
56                              content::PAGE_TRANSITION_GENERATED,
57                              false));
58   browser->window()->Show();
59   browser->window()->Activate();
60   page->GetView()->Focus();
61 }
62
63 void ChromeNewWindowDelegateChromeos::ShowKeyboardOverlay() {
64   // TODO(mazda): Move the show logic to ash (http://crbug.com/124222).
65   Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
66   std::string url(chrome::kChromeUIKeyboardOverlayURL);
67   ash::KeyboardOverlayView::ShowDialog(profile,
68                                        new ChromeWebContentsHandler,
69                                        GURL(url));
70 }