| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h" | 5 #include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h" |
| 6 | 6 |
| 7 #include "apps/app_launch_for_metro_restart_win.h" |
| 7 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
| 15 #include "chrome/browser/ui/metro_chrome_win.h" | 17 #include "chrome/browser/ui/metro_chrome_win.h" |
| 16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 20 #include "grit/google_chrome_strings.h" | 22 #include "grit/google_chrome_strings.h" |
| 21 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "win8/util/win8_util.h" | 26 #include "win8/util/win8_util.h" |
| 25 | 27 |
| 26 namespace chrome { | 28 namespace chrome { |
| 27 | 29 |
| 28 void AppMetroInfoBarDelegateWin::CreateAndActivateMetro(Profile* profile) { | 30 // static |
| 31 void AppMetroInfoBarDelegateWin::Create( |
| 32 Profile* profile, Mode mode, const std::string& extension_id) { |
| 33 DCHECK(win8::IsSingleWindowMetroMode()); |
| 34 DCHECK_EQ(mode == SHOW_APP_LIST, extension_id.empty()); |
| 35 |
| 29 // Chrome should never get here via the Ash desktop, so only look for browsers | 36 // Chrome should never get here via the Ash desktop, so only look for browsers |
| 30 // on the native desktop. | 37 // on the native desktop. |
| 31 CHECK(win8::IsSingleWindowMetroMode()); | |
| 32 Browser* browser = FindOrCreateTabbedBrowser( | 38 Browser* browser = FindOrCreateTabbedBrowser( |
| 33 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 39 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 34 | 40 |
| 35 // Create a new tab at about:blank, and add the infobar. | 41 // Create a new tab at about:blank, and add the infobar. |
| 36 content::OpenURLParams params( | 42 content::OpenURLParams params( |
| 37 GURL(chrome::kAboutBlankURL), | 43 GURL(chrome::kAboutBlankURL), |
| 38 content::Referrer(), | 44 content::Referrer(), |
| 39 NEW_FOREGROUND_TAB, | 45 NEW_FOREGROUND_TAB, |
| 40 content::PAGE_TRANSITION_LINK, false); | 46 content::PAGE_TRANSITION_LINK, false); |
| 41 content::WebContents* web_contents = browser->OpenURL(params); | 47 content::WebContents* web_contents = browser->OpenURL(params); |
| 42 InfoBarService* info_bar_service = | 48 InfoBarService* info_bar_service = |
| 43 InfoBarService::FromWebContents(web_contents); | 49 InfoBarService::FromWebContents(web_contents); |
| 44 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 50 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 45 new AppMetroInfoBarDelegateWin(info_bar_service))); | 51 new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id))); |
| 46 | 52 |
| 47 // Use PostTask because we can get here in a COM SendMessage, and | 53 // Use PostTask because we can get here in a COM SendMessage, and |
| 48 // ActivateApplication can not be sent nested (returns error | 54 // ActivateApplication can not be sent nested (returns error |
| 49 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL). | 55 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL). |
| 50 MessageLoop::current()->PostTask( | 56 MessageLoop::current()->PostTask( |
| 51 FROM_HERE, | 57 FROM_HERE, |
| 52 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome))); | 58 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome))); |
| 53 } | 59 } |
| 54 | 60 |
| 55 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( | 61 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( |
| 56 InfoBarService* info_bar_service) | 62 InfoBarService* info_bar_service, |
| 57 : ConfirmInfoBarDelegate(info_bar_service) { | 63 Mode mode, |
| 64 const std::string& extension_id) |
| 65 : ConfirmInfoBarDelegate(info_bar_service), |
| 66 mode_(mode), |
| 67 extension_id_(extension_id) { |
| 68 DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty()); |
| 58 } | 69 } |
| 59 | 70 |
| 60 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {} | 71 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {} |
| 61 | 72 |
| 62 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const { | 73 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const { |
| 63 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST); | 74 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST); |
| 64 } | 75 } |
| 65 | 76 |
| 66 string16 AppMetroInfoBarDelegateWin::GetMessageText() const { | 77 string16 AppMetroInfoBarDelegateWin::GetMessageText() const { |
| 67 return l10n_util::GetStringUTF16( | 78 return l10n_util::GetStringUTF16(mode_ == SHOW_APP_LIST ? |
| 68 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS); | 79 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_APP_LIST : |
| 80 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_PACKAGED_APP); |
| 69 } | 81 } |
| 70 | 82 |
| 71 int AppMetroInfoBarDelegateWin::GetButtons() const { | 83 int AppMetroInfoBarDelegateWin::GetButtons() const { |
| 72 return BUTTON_OK | BUTTON_CANCEL; | 84 return BUTTON_OK | BUTTON_CANCEL; |
| 73 } | 85 } |
| 74 | 86 |
| 75 string16 AppMetroInfoBarDelegateWin::GetButtonLabel( | 87 string16 AppMetroInfoBarDelegateWin::GetButtonLabel( |
| 76 InfoBarButton button) const { | 88 InfoBarButton button) const { |
| 77 if (button == BUTTON_CANCEL) { | 89 return l10n_util::GetStringUTF16(button == BUTTON_CANCEL ? |
| 78 return l10n_util::GetStringUTF16( | 90 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON : |
| 79 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON); | |
| 80 } | |
| 81 | |
| 82 return l10n_util::GetStringUTF16( | |
| 83 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON); | 91 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON); |
| 84 } | 92 } |
| 85 | 93 |
| 86 bool AppMetroInfoBarDelegateWin::Accept() { | 94 bool AppMetroInfoBarDelegateWin::Accept() { |
| 87 owner()->GetWebContents()->Close(); | |
| 88 PrefService* prefs = g_browser_process->local_state(); | 95 PrefService* prefs = g_browser_process->local_state(); |
| 89 prefs->SetBoolean(prefs::kRestartWithAppList, true); | 96 content::WebContents* web_contents = owner()->GetWebContents(); |
| 97 if (mode_ == SHOW_APP_LIST) { |
| 98 prefs->SetBoolean(prefs::kRestartWithAppList, true); |
| 99 } else { |
| 100 apps::SetAppLaunchForMetroRestart( |
| 101 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 102 extension_id_); |
| 103 } |
| 104 |
| 105 web_contents->Close(); // Note: deletes |this|. |
| 90 chrome::AttemptRestartWithModeSwitch(); | 106 chrome::AttemptRestartWithModeSwitch(); |
| 91 return false; | 107 return false; |
| 92 } | 108 } |
| 93 | 109 |
| 94 bool AppMetroInfoBarDelegateWin::Cancel() { | 110 bool AppMetroInfoBarDelegateWin::Cancel() { |
| 95 owner()->GetWebContents()->Close(); | 111 owner()->GetWebContents()->Close(); |
| 96 return false; | 112 return false; |
| 97 } | 113 } |
| 98 | 114 |
| 99 string16 AppMetroInfoBarDelegateWin::GetLinkText() const { | 115 string16 AppMetroInfoBarDelegateWin::GetLinkText() const { |
| 100 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 116 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 101 } | 117 } |
| 102 | 118 |
| 103 bool AppMetroInfoBarDelegateWin::LinkClicked( | 119 bool AppMetroInfoBarDelegateWin::LinkClicked( |
| 104 WindowOpenDisposition disposition) { | 120 WindowOpenDisposition disposition) { |
| 105 content::OpenURLParams params( | 121 content::OpenURLParams params( |
| 106 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"), | 122 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"), |
| 107 content::Referrer(), | 123 content::Referrer(), |
| 108 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 124 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 109 content::PAGE_TRANSITION_LINK, false); | 125 content::PAGE_TRANSITION_LINK, false); |
| 110 owner()->GetWebContents()->OpenURL(params); | 126 owner()->GetWebContents()->OpenURL(params); |
| 111 return false; | 127 return false; |
| 112 } | 128 } |
| 113 | 129 |
| 114 } // namespace chrome | 130 } // namespace chrome |
| OLD | NEW |