- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / apps / app_metro_infobar_delegate_win.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/apps/app_metro_infobar_delegate_win.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/lifetime/application_lifetime.h"
13 #include "chrome/browser/metro_utils/metro_chrome_win.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/app_list_icon_win.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
20 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/url_constants.h"
23 #include "grit/generated_resources.h"
24 #include "grit/google_chrome_strings.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "win8/util/win8_util.h"
27
28 // static
29 void AppMetroInfoBarDelegateWin::Create(
30     Profile* profile,
31     Mode mode,
32     const std::string& extension_id) {
33   DCHECK(win8::IsSingleWindowMetroMode());
34   DCHECK_EQ(mode == SHOW_APP_LIST, extension_id.empty());
35
36   // Chrome should never get here via the Ash desktop, so only look for browsers
37   // on the native desktop.
38   chrome::ScopedTabbedBrowserDisplayer displayer(
39       profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
40
41   // Create a new tab at about:blank, and add the infobar.
42   content::OpenURLParams params(GURL(content::kAboutBlankURL),
43       content::Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK,
44       false);
45   content::WebContents* web_contents = displayer.browser()->OpenURL(params);
46   InfoBarService* info_bar_service =
47       InfoBarService::FromWebContents(web_contents);
48   info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
49       new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id)));
50
51   // Use PostTask because we can get here in a COM SendMessage, and
52   // ActivateApplication can not be sent nested (returns error
53   // RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
54   base::MessageLoop::current()->PostTask(
55       FROM_HERE, base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome)));
56 }
57
58 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin(
59     InfoBarService* info_bar_service,
60     Mode mode,
61     const std::string& extension_id)
62     : ConfirmInfoBarDelegate(info_bar_service),
63       mode_(mode),
64       extension_id_(extension_id) {
65   DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty());
66 }
67
68 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {}
69
70 int AppMetroInfoBarDelegateWin::GetIconID() const {
71   return GetAppListIconResourceId();
72 }
73
74 string16 AppMetroInfoBarDelegateWin::GetMessageText() const {
75   return l10n_util::GetStringUTF16(mode_ == SHOW_APP_LIST ?
76       IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_APP_LIST :
77       IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_PACKAGED_APP);
78 }
79
80 string16 AppMetroInfoBarDelegateWin::GetButtonLabel(
81     InfoBarButton button) const {
82   return l10n_util::GetStringUTF16(button == BUTTON_CANCEL ?
83       IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON :
84       IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON);
85 }
86
87 bool AppMetroInfoBarDelegateWin::Accept() {
88   PrefService* prefs = g_browser_process->local_state();
89   if (mode_ == SHOW_APP_LIST) {
90     prefs->SetBoolean(prefs::kRestartWithAppList, true);
91   } else {
92     app_metro_launch::SetAppLaunchForMetroRestart(
93         Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
94         extension_id_);
95   }
96
97   web_contents()->Close();  // Note: deletes |this|.
98   chrome::AttemptRestartToDesktopMode();
99   return false;
100 }
101
102 bool AppMetroInfoBarDelegateWin::Cancel() {
103   web_contents()->Close();
104   return false;
105 }
106
107 string16 AppMetroInfoBarDelegateWin::GetLinkText() const {
108   return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
109 }
110
111 bool AppMetroInfoBarDelegateWin::LinkClicked(
112     WindowOpenDisposition disposition) {
113   web_contents()->OpenURL(content::OpenURLParams(
114       GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"),
115       content::Referrer(),
116       (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
117       content::PAGE_TRANSITION_LINK, false));
118   return false;
119 }