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