Chromium Code Reviews| 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 if (!win8::IsSingleWindowMetroMode() || | |
|
Peter Kasting
2013/03/22 19:48:21
Nit: Simpler, more similar to constructor, and com
tapted
2013/03/24 22:02:46
Done.
| |
| 34 (mode == LAUNCH_PACKAGED_APP && extension_id.empty())) { | |
| 35 NOTREACHED(); | |
| 36 return; | |
| 37 } | |
| 38 | |
| 29 // Chrome should never get here via the Ash desktop, so only look for browsers | 39 // Chrome should never get here via the Ash desktop, so only look for browsers |
| 30 // on the native desktop. | 40 // on the native desktop. |
| 31 CHECK(win8::IsSingleWindowMetroMode()); | |
| 32 Browser* browser = FindOrCreateTabbedBrowser( | 41 Browser* browser = FindOrCreateTabbedBrowser( |
| 33 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 42 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 34 | 43 |
| 35 // Create a new tab at about:blank, and add the infobar. | 44 // Create a new tab at about:blank, and add the infobar. |
| 36 content::OpenURLParams params( | 45 content::OpenURLParams params( |
| 37 GURL(chrome::kAboutBlankURL), | 46 GURL(chrome::kAboutBlankURL), |
| 38 content::Referrer(), | 47 content::Referrer(), |
| 39 NEW_FOREGROUND_TAB, | 48 NEW_FOREGROUND_TAB, |
| 40 content::PAGE_TRANSITION_LINK, false); | 49 content::PAGE_TRANSITION_LINK, false); |
| 41 content::WebContents* web_contents = browser->OpenURL(params); | 50 content::WebContents* web_contents = browser->OpenURL(params); |
| 42 InfoBarService* info_bar_service = | 51 InfoBarService* info_bar_service = |
| 43 InfoBarService::FromWebContents(web_contents); | 52 InfoBarService::FromWebContents(web_contents); |
| 44 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 53 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 45 new AppMetroInfoBarDelegateWin(info_bar_service))); | 54 new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id))); |
| 46 | 55 |
| 47 // Use PostTask because we can get here in a COM SendMessage, and | 56 // Use PostTask because we can get here in a COM SendMessage, and |
| 48 // ActivateApplication can not be sent nested (returns error | 57 // ActivateApplication can not be sent nested (returns error |
| 49 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL). | 58 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL). |
| 50 MessageLoop::current()->PostTask( | 59 MessageLoop::current()->PostTask( |
| 51 FROM_HERE, | 60 FROM_HERE, |
| 52 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome))); | 61 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome))); |
| 53 } | 62 } |
| 54 | 63 |
| 55 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( | 64 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( |
| 56 InfoBarService* info_bar_service) | 65 InfoBarService* info_bar_service, |
| 57 : ConfirmInfoBarDelegate(info_bar_service) { | 66 Mode mode, |
| 67 const std::string& extension_id) | |
| 68 : ConfirmInfoBarDelegate(info_bar_service), | |
| 69 mode_(mode), | |
| 70 extension_id_(extension_id) { | |
| 71 DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty()); | |
| 58 } | 72 } |
| 59 | 73 |
| 60 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {} | 74 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {} |
| 61 | 75 |
| 62 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const { | 76 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const { |
| 63 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST); | 77 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST); |
| 64 } | 78 } |
| 65 | 79 |
| 66 string16 AppMetroInfoBarDelegateWin::GetMessageText() const { | 80 string16 AppMetroInfoBarDelegateWin::GetMessageText() const { |
| 67 return l10n_util::GetStringUTF16( | 81 return l10n_util::GetStringUTF16(mode_ == SHOW_APP_LIST ? |
| 68 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS); | 82 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_APP_LIST : |
| 83 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_PACKAGED_APP); | |
| 69 } | 84 } |
| 70 | 85 |
| 71 int AppMetroInfoBarDelegateWin::GetButtons() const { | 86 int AppMetroInfoBarDelegateWin::GetButtons() const { |
| 72 return BUTTON_OK | BUTTON_CANCEL; | 87 return BUTTON_OK | BUTTON_CANCEL; |
| 73 } | 88 } |
| 74 | 89 |
| 75 string16 AppMetroInfoBarDelegateWin::GetButtonLabel( | 90 string16 AppMetroInfoBarDelegateWin::GetButtonLabel( |
| 76 InfoBarButton button) const { | 91 InfoBarButton button) const { |
| 77 if (button == BUTTON_CANCEL) { | 92 if (button == BUTTON_CANCEL) { |
|
Peter Kasting
2013/03/22 19:48:21
Nit: This function can be collapsed by using ?: th
tapted
2013/03/24 22:02:46
Done.
| |
| 78 return l10n_util::GetStringUTF16( | 93 return l10n_util::GetStringUTF16( |
| 79 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON); | 94 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON); |
| 80 } | 95 } |
| 81 | 96 |
| 82 return l10n_util::GetStringUTF16( | 97 return l10n_util::GetStringUTF16( |
| 83 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON); | 98 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON); |
| 84 } | 99 } |
| 85 | 100 |
| 86 bool AppMetroInfoBarDelegateWin::Accept() { | 101 bool AppMetroInfoBarDelegateWin::Accept() { |
| 87 owner()->GetWebContents()->Close(); | |
| 88 PrefService* prefs = g_browser_process->local_state(); | 102 PrefService* prefs = g_browser_process->local_state(); |
| 89 prefs->SetBoolean(prefs::kRestartWithAppList, true); | 103 content::WebContents* web_contents = owner()->GetWebContents(); |
| 104 if (mode_ == SHOW_APP_LIST) { | |
| 105 prefs->SetBoolean(prefs::kRestartWithAppList, true); | |
| 106 } else { | |
| 107 apps::SetAppLaunchForMetroRestart( | |
| 108 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
| 109 extension_id_); | |
| 110 } | |
| 111 | |
| 112 web_contents->Close(); // Note: deletes |this|. | |
| 90 chrome::AttemptRestartWithModeSwitch(); | 113 chrome::AttemptRestartWithModeSwitch(); |
| 91 return false; | 114 return false; |
| 92 } | 115 } |
| 93 | 116 |
| 94 bool AppMetroInfoBarDelegateWin::Cancel() { | 117 bool AppMetroInfoBarDelegateWin::Cancel() { |
| 95 owner()->GetWebContents()->Close(); | 118 owner()->GetWebContents()->Close(); |
| 96 return false; | 119 return false; |
| 97 } | 120 } |
| 98 | 121 |
| 99 string16 AppMetroInfoBarDelegateWin::GetLinkText() const { | 122 string16 AppMetroInfoBarDelegateWin::GetLinkText() const { |
| 100 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 123 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 101 } | 124 } |
| 102 | 125 |
| 103 bool AppMetroInfoBarDelegateWin::LinkClicked( | 126 bool AppMetroInfoBarDelegateWin::LinkClicked( |
| 104 WindowOpenDisposition disposition) { | 127 WindowOpenDisposition disposition) { |
| 105 content::OpenURLParams params( | 128 content::OpenURLParams params( |
| 106 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"), | 129 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"), |
| 107 content::Referrer(), | 130 content::Referrer(), |
| 108 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 131 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 109 content::PAGE_TRANSITION_LINK, false); | 132 content::PAGE_TRANSITION_LINK, false); |
| 110 owner()->GetWebContents()->OpenURL(params); | 133 owner()->GetWebContents()->OpenURL(params); |
| 111 return false; | 134 return false; |
| 112 } | 135 } |
| 113 | 136 |
| 114 } // namespace chrome | 137 } // namespace chrome |
| OLD | NEW |