| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webui/set_as_default_browser_ui.h" | 5 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/shell_integration.h" | 13 #include "chrome/browser/shell_integration.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/chrome_pages.h" | 20 #include "chrome/browser/ui/chrome_pages.h" |
| 20 #include "chrome/browser/ui/singleton_tabs.h" | 21 #include "chrome/browser/ui/singleton_tabs.h" |
| 21 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 22 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/installer/util/install_util.h" | 26 #include "chrome/installer/util/install_util.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
| 29 #include "content/public/browser/web_contents_view.h" |
| 28 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 29 #include "content/public/browser/web_ui_message_handler.h" | 31 #include "content/public/browser/web_ui_message_handler.h" |
| 30 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
| 31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 32 #include "grit/locale_settings.h" | 34 #include "grit/locale_settings.h" |
| 33 #include "ui/base/l10n/l10n_font_util.h" | 35 #include "ui/base/l10n/l10n_font_util.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/gfx/font.h" | 37 #include "ui/gfx/font.h" |
| 36 #include "ui/web_dialogs/web_dialog_delegate.h" | 38 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 37 | 39 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 IDS_METRO_FLOW_SET_DEFAULT); | 54 IDS_METRO_FLOW_SET_DEFAULT); |
| 53 data_source->AddLocalizedString("chromeLogoString", | 55 data_source->AddLocalizedString("chromeLogoString", |
| 54 IDS_METRO_FLOW_LOGO_STRING_ALT); | 56 IDS_METRO_FLOW_LOGO_STRING_ALT); |
| 55 data_source->set_json_path("strings.js"); | 57 data_source->set_json_path("strings.js"); |
| 56 data_source->add_resource_path("set_as_default_browser.js", | 58 data_source->add_resource_path("set_as_default_browser.js", |
| 57 IDR_SET_AS_DEFAULT_BROWSER_JS); | 59 IDR_SET_AS_DEFAULT_BROWSER_JS); |
| 58 data_source->set_default_resource(IDR_SET_AS_DEFAULT_BROWSER_HTML); | 60 data_source->set_default_resource(IDR_SET_AS_DEFAULT_BROWSER_HTML); |
| 59 return data_source; | 61 return data_source; |
| 60 } | 62 } |
| 61 | 63 |
| 64 // A simple class serving as a delegate for passing down the result of the |
| 65 // interaction. |
| 66 class ResponseDelegate { |
| 67 public: |
| 68 virtual void SetChromeShutdownRequired(bool shutdown_chrome) = 0; |
| 69 |
| 70 protected: |
| 71 virtual ~ResponseDelegate() { } |
| 72 }; |
| 73 |
| 62 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the | 74 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the |
| 63 // default browser on button click, closing itself and triggering Chrome | 75 // default browser on button click, closing itself and triggering Chrome |
| 64 // restart. | 76 // restart. |
| 65 class SetAsDefaultBrowserHandler | 77 class SetAsDefaultBrowserHandler |
| 66 : public WebUIMessageHandler, | 78 : public WebUIMessageHandler, |
| 67 public base::SupportsWeakPtr<SetAsDefaultBrowserHandler>, | 79 public base::SupportsWeakPtr<SetAsDefaultBrowserHandler>, |
| 68 public ShellIntegration::DefaultWebClientObserver { | 80 public ShellIntegration::DefaultWebClientObserver { |
| 69 public: | 81 public: |
| 70 SetAsDefaultBrowserHandler(); | 82 explicit SetAsDefaultBrowserHandler(ResponseDelegate* response_delegate); |
| 71 virtual ~SetAsDefaultBrowserHandler(); | 83 virtual ~SetAsDefaultBrowserHandler(); |
| 72 | 84 |
| 73 // WebUIMessageHandler implementation. | 85 // WebUIMessageHandler implementation. |
| 74 virtual void RegisterMessages() OVERRIDE; | 86 virtual void RegisterMessages() OVERRIDE; |
| 75 | 87 |
| 76 // ShellIntegration::DefaultWebClientObserver implementation. | 88 // ShellIntegration::DefaultWebClientObserver implementation. |
| 77 virtual void SetDefaultWebClientUIState( | 89 virtual void SetDefaultWebClientUIState( |
| 78 ShellIntegration::DefaultWebClientUIState state) OVERRIDE; | 90 ShellIntegration::DefaultWebClientUIState state) OVERRIDE; |
| 79 virtual void OnSetAsDefaultConcluded(bool call_result) OVERRIDE; | 91 virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE; |
| 80 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; | 92 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; |
| 81 | 93 |
| 82 private: | 94 private: |
| 83 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. | 95 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. |
| 84 void HandleLaunchSetDefaultBrowserFlow(const ListValue* args); | 96 void HandleLaunchSetDefaultBrowserFlow(const ListValue* args); |
| 85 | 97 |
| 86 // Close this web ui. | 98 // Close this web ui. |
| 87 void ConcludeInteraction(); | 99 void ConcludeInteraction(bool mark_success); |
| 88 | 100 |
| 89 // If required and possible, spawns a new Chrome in Metro mode and closes the | 101 // If required and possible, spawns a new Chrome in Metro mode and closes the |
| 90 // current instance. Windows 8 only, on earlier systems it will simply close | 102 // current instance. Windows 8 only, on earlier systems it will simply close |
| 91 // this UI. | 103 // this UI. |
| 92 void ActivateMetroChrome(); | 104 void ActivateMetroChrome(); |
| 93 | 105 |
| 94 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; | 106 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; |
| 95 bool set_default_returned_; | 107 bool set_default_returned_; |
| 96 bool set_default_result_; | 108 bool set_default_result_; |
| 109 ResponseDelegate* response_delegate_; |
| 97 | 110 |
| 98 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); | 111 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); |
| 99 }; | 112 }; |
| 100 | 113 |
| 101 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler() | 114 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( |
| 115 ResponseDelegate* response_delegate) |
| 102 : ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_( | 116 : ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_( |
| 103 new ShellIntegration::DefaultBrowserWorker(this))), | 117 new ShellIntegration::DefaultBrowserWorker(this))), |
| 104 set_default_returned_(false), set_default_result_(false) { | 118 set_default_returned_(false), set_default_result_(false), |
| 119 response_delegate_(response_delegate) { |
| 105 } | 120 } |
| 106 | 121 |
| 107 SetAsDefaultBrowserHandler::~SetAsDefaultBrowserHandler() { | 122 SetAsDefaultBrowserHandler::~SetAsDefaultBrowserHandler() { |
| 108 default_browser_worker_->ObserverDestroyed(); | 123 default_browser_worker_->ObserverDestroyed(); |
| 109 } | 124 } |
| 110 | 125 |
| 111 void SetAsDefaultBrowserHandler::RegisterMessages() { | 126 void SetAsDefaultBrowserHandler::RegisterMessages() { |
| 112 web_ui()->RegisterMessageCallback( | 127 web_ui()->RegisterMessageCallback( |
| 113 "SetAsDefaultBrowser:LaunchSetDefaultBrowserFlow", | 128 "SetAsDefaultBrowser:LaunchSetDefaultBrowserFlow", |
| 114 base::Bind(&SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow, | 129 base::Bind(&SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow, |
| 115 base::Unretained(this))); | 130 base::Unretained(this))); |
| 116 } | 131 } |
| 117 | 132 |
| 118 void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState( | 133 void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState( |
| 119 ShellIntegration::DefaultWebClientUIState state) { | 134 ShellIntegration::DefaultWebClientUIState state) { |
| 120 // The callback is expected to be invoked once the procedure has completed. | 135 // The callback is expected to be invoked once the procedure has completed. |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 122 if (!set_default_returned_) | 137 if (!set_default_returned_) |
| 123 return; | 138 return; |
| 124 | 139 |
| 125 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { | 140 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { |
| 126 // The operation concluded, but Chrome is still not the default. | 141 // The operation concluded, but Chrome is still not the default. |
| 127 // If the call has succeeded, this suggests user has decided not to make | 142 // If the call has succeeded, this suggests user has decided not to make |
| 128 // chrome the default. We fold this UI and move on. | 143 // chrome the default. We fold this UI and move on. |
| 129 ConcludeInteraction(); | 144 ConcludeInteraction(false); |
| 130 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { | 145 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { |
| 131 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( | 146 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( |
| 132 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { | 147 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { |
| 133 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 134 BrowserThread::FILE, FROM_HERE, | 149 BrowserThread::FILE, FROM_HERE, |
| 135 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, | 150 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, |
| 136 base::Unretained(this))); | 151 base::Unretained(this))); |
| 137 } else { | 152 } else { |
| 138 ConcludeInteraction(); | 153 ConcludeInteraction(false); |
| 139 } | 154 } |
| 140 } | 155 } |
| 141 } | 156 } |
| 142 | 157 |
| 143 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { | 158 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { |
| 144 set_default_returned_ = true; | 159 set_default_returned_ = true; |
| 145 set_default_result_ = call_result; | 160 set_default_result_ = call_result; |
| 146 } | 161 } |
| 147 | 162 |
| 148 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() { | 163 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() { |
| 149 return true; | 164 return true; |
| 150 } | 165 } |
| 151 | 166 |
| 152 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( | 167 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( |
| 153 const ListValue* args) { | 168 const ListValue* args) { |
| 154 set_default_returned_ = false; | 169 set_default_returned_ = false; |
| 155 set_default_result_ = false; | 170 set_default_result_ = false; |
| 156 default_browser_worker_->StartSetAsDefault(); | 171 default_browser_worker_->StartSetAsDefault(); |
| 157 } | 172 } |
| 158 | 173 |
| 159 void SetAsDefaultBrowserHandler::ConcludeInteraction() { | 174 void SetAsDefaultBrowserHandler::ConcludeInteraction(bool close_chrome) { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 WebContents* contents = web_ui()->GetWebContents(); | 176 WebContents* contents = web_ui()->GetWebContents(); |
| 177 if (response_delegate_) |
| 178 response_delegate_->SetChromeShutdownRequired(close_chrome); |
| 179 |
| 162 if (contents) { | 180 if (contents) { |
| 163 content::WebContentsDelegate* delegate = contents->GetDelegate(); | 181 content::WebContentsDelegate* delegate = contents->GetDelegate(); |
| 164 if (delegate) | 182 if (delegate) |
| 165 delegate->CloseContents(contents); | 183 delegate->CloseContents(contents); |
| 166 } | 184 } |
| 167 } | 185 } |
| 168 | 186 |
| 169 void SetAsDefaultBrowserHandler::ActivateMetroChrome() { | 187 void SetAsDefaultBrowserHandler::ActivateMetroChrome() { |
| 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 171 FilePath cur_chrome_exe; | 189 FilePath cur_chrome_exe; |
| 172 bool sentinel_removed = false; | 190 bool sentinel_removed = false; |
| 173 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) && | 191 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) && |
| 174 first_run::IsChromeFirstRun() && | 192 first_run::IsChromeFirstRun() && |
| 175 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) { | 193 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) { |
| 176 // If this is per-user install, we will have to remove the sentinel file | 194 // If this is per-user install, we will have to remove the sentinel file |
| 177 // to assure the user goes through the intended 'first-run flow'. | 195 // to assure the user goes through the intended 'first-run flow'. |
| 178 sentinel_removed = first_run::RemoveSentinel(); | 196 sentinel_removed = first_run::RemoveSentinel(); |
| 179 } | 197 } |
| 180 | 198 |
| 181 if (ShellIntegration::ActivateMetroChrome()) { | 199 bool metro_chrome_activated = ShellIntegration::ActivateMetroChrome(); |
| 182 // If Metro Chrome has been activated, we should close this process. | 200 if (!metro_chrome_activated && sentinel_removed) |
| 183 // We are restarting as metro now. | |
| 184 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 185 base::Bind(&BrowserList::CloseAllBrowsersWithProfile, | |
| 186 Profile::FromWebUI(web_ui()))); | |
| 187 } else { | |
| 188 // This will return false if the operation failed for any reason, | |
| 189 // including invocation under a Windows version earlier than 8. | |
| 190 // In such case we simply close the window and carry on. | |
| 191 if (sentinel_removed) | |
| 192 first_run::CreateSentinel(); | 201 first_run::CreateSentinel(); |
| 193 | 202 |
| 194 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
| 195 BrowserThread::UI, FROM_HERE, | 204 BrowserThread::UI, FROM_HERE, |
| 196 base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction, | 205 base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction, |
| 197 base::Unretained(this))); | 206 base::Unretained(this), metro_chrome_activated)); |
| 198 } | |
| 199 } | 207 } |
| 200 | 208 |
| 201 // A web dialog delegate implementation for when 'Make Chrome Metro' UI | 209 // A web dialog delegate implementation for when 'Make Chrome Metro' UI |
| 202 // is displayed on a dialog. | 210 // is displayed on a dialog. |
| 203 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate { | 211 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate, |
| 212 public ResponseDelegate { |
| 204 public: | 213 public: |
| 205 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); | 214 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); |
| 215 virtual ~SetAsDefaultBrowserDialogImpl(); |
| 206 // Show a modal web dialog with kChromeUIMetroFlowURL page. | 216 // Show a modal web dialog with kChromeUIMetroFlowURL page. |
| 207 void ShowDialog(); | 217 void ShowDialog(); |
| 208 | 218 |
| 209 protected: | 219 protected: |
| 210 // Overridden from WebDialogDelegate: | 220 // Overridden from WebDialogDelegate: |
| 211 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | 221 virtual ui::ModalType GetDialogModalType() const OVERRIDE; |
| 212 virtual string16 GetDialogTitle() const OVERRIDE; | 222 virtual string16 GetDialogTitle() const OVERRIDE; |
| 213 virtual GURL GetDialogContentURL() const OVERRIDE; | 223 virtual GURL GetDialogContentURL() const OVERRIDE; |
| 214 virtual void GetWebUIMessageHandlers( | 224 virtual void GetWebUIMessageHandlers( |
| 215 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; | 225 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
| 216 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; | 226 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
| 217 virtual std::string GetDialogArgs() const OVERRIDE; | 227 virtual std::string GetDialogArgs() const OVERRIDE; |
| 218 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 228 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
| 219 virtual void OnCloseContents(WebContents* source, | 229 virtual void OnCloseContents(WebContents* source, |
| 220 bool* out_close_dialog) OVERRIDE; | 230 bool* out_close_dialog) OVERRIDE; |
| 221 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 231 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
| 222 virtual bool HandleContextMenu( | 232 virtual bool HandleContextMenu( |
| 223 const content::ContextMenuParams& params) OVERRIDE; | 233 const content::ContextMenuParams& params) OVERRIDE; |
| 224 | 234 |
| 235 // Overridden from ResponseDelegate: |
| 236 virtual void SetChromeShutdownRequired(bool shutdown_chrome); |
| 237 |
| 225 private: | 238 private: |
| 226 Profile* profile_; | 239 Profile* profile_; |
| 227 Browser* browser_; | 240 Browser* browser_; |
| 241 mutable bool owns_handler_; |
| 242 SetAsDefaultBrowserHandler* handler_; |
| 243 bool response_is_close_chrome_; |
| 228 | 244 |
| 229 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); | 245 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); |
| 230 }; | 246 }; |
| 231 | 247 |
| 232 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile, | 248 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile, |
| 233 Browser* browser) | 249 Browser* browser) |
| 234 : profile_(profile), browser_(browser) { | 250 : profile_(profile), |
| 251 browser_(browser), |
| 252 owns_handler_(true), |
| 253 handler_(new SetAsDefaultBrowserHandler(this)), |
| 254 response_is_close_chrome_(false) { |
| 255 } |
| 256 |
| 257 SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() { |
| 258 if (owns_handler_) |
| 259 delete handler_; |
| 235 } | 260 } |
| 236 | 261 |
| 237 void SetAsDefaultBrowserDialogImpl::ShowDialog() { | 262 void SetAsDefaultBrowserDialogImpl::ShowDialog() { |
| 238 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), | 263 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), |
| 239 browser_->profile(), this); | 264 browser_->profile(), this); |
| 240 } | 265 } |
| 241 | 266 |
| 242 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const { | 267 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const { |
| 243 return ui::MODAL_TYPE_SYSTEM; | 268 return ui::MODAL_TYPE_SYSTEM; |
| 244 } | 269 } |
| 245 | 270 |
| 246 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const { | 271 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const { |
| 247 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE); | 272 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE); |
| 248 } | 273 } |
| 249 | 274 |
| 250 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const { | 275 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const { |
| 251 std::string url_string(chrome::kChromeUIMetroFlowURL); | 276 std::string url_string(chrome::kChromeUIMetroFlowURL); |
| 252 return GURL(url_string); | 277 return GURL(url_string); |
| 253 } | 278 } |
| 254 | 279 |
| 255 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers( | 280 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers( |
| 256 std::vector<WebUIMessageHandler*>* handlers) const { | 281 std::vector<WebUIMessageHandler*>* handlers) const { |
| 282 handlers->push_back(handler_); |
| 283 owns_handler_ = false; |
| 257 } | 284 } |
| 258 | 285 |
| 259 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const { | 286 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const { |
| 260 PrefService* prefs = profile_->GetPrefs(); | 287 PrefService* prefs = profile_->GetPrefs(); |
| 261 gfx::Font approximate_web_font( | 288 gfx::Font approximate_web_font( |
| 262 prefs->GetString(prefs::kWebKitSansSerifFontFamily), | 289 prefs->GetString(prefs::kWebKitSansSerifFontFamily), |
| 263 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); | 290 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); |
| 264 | 291 |
| 265 *size = ui::GetLocalizedContentsSizeForFont( | 292 *size = ui::GetLocalizedContentsSizeForFont( |
| 266 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, | 293 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, |
| 267 approximate_web_font); | 294 approximate_web_font); |
| 268 } | 295 } |
| 269 | 296 |
| 270 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { | 297 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { |
| 271 return "[]"; | 298 return "[]"; |
| 272 } | 299 } |
| 273 | 300 |
| 274 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( | 301 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( |
| 275 const std::string& json_retval) { | 302 const std::string& json_retval) { |
| 303 if (response_is_close_chrome_) { |
| 304 // If Metro Chrome has been activated, we should close this process. |
| 305 // We are restarting as metro now. |
| 306 BrowserList::CloseAllBrowsersWithProfile(profile_); |
| 307 } else { |
| 308 // This will be false if the user closed the dialog without doing anything |
| 309 // or if operation failed for any reason (including invocation under a |
| 310 // Windows version earlier than 8). |
| 311 // In such case we just carry on with a normal chrome session. However, for |
| 312 // the purpose of surfacing this dialog the actual browser window had to |
| 313 // remain hidden. Now it's the time to show it. |
| 314 BrowserWindow* window = browser_->window(); |
| 315 WebContents* contents = chrome::GetActiveWebContents(browser_); |
| 316 window->Show(); |
| 317 if (contents) |
| 318 contents->GetView()->SetInitialFocus(); |
| 319 } |
| 320 |
| 276 delete this; | 321 delete this; |
| 277 } | 322 } |
| 278 | 323 |
| 279 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, | 324 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, |
| 280 bool* out_close_dialog) { | 325 bool* out_close_dialog) { |
| 281 *out_close_dialog = true; | 326 *out_close_dialog = true; |
| 282 } | 327 } |
| 283 | 328 |
| 284 bool SetAsDefaultBrowserDialogImpl::ShouldShowDialogTitle() const { | 329 bool SetAsDefaultBrowserDialogImpl::ShouldShowDialogTitle() const { |
| 285 return true; | 330 return true; |
| 286 } | 331 } |
| 287 | 332 |
| 288 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu( | 333 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu( |
| 289 const content::ContextMenuParams& params) { | 334 const content::ContextMenuParams& params) { |
| 290 return true; | 335 return true; |
| 291 } | 336 } |
| 292 | 337 |
| 338 void SetAsDefaultBrowserDialogImpl::SetChromeShutdownRequired( |
| 339 bool shutdown_chrome) { |
| 340 response_is_close_chrome_ = shutdown_chrome; |
| 341 } |
| 342 |
| 293 } // namespace | 343 } // namespace |
| 294 | 344 |
| 295 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) | 345 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) |
| 296 : WebUIController(web_ui) { | 346 : ui::WebDialogUI(web_ui) { |
| 297 web_ui->AddMessageHandler(new SetAsDefaultBrowserHandler()); | |
| 298 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), | 347 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), |
| 299 CreateSetAsDefaultBrowserUIHTMLSource()); | 348 CreateSetAsDefaultBrowserUIHTMLSource()); |
| 300 } | 349 } |
| 301 | 350 |
| 302 // static | 351 // static |
| 303 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { | 352 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { |
| 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 305 SetAsDefaultBrowserDialogImpl* dialog = | 354 SetAsDefaultBrowserDialogImpl* dialog = |
| 306 new SetAsDefaultBrowserDialogImpl(profile, browser); | 355 new SetAsDefaultBrowserDialogImpl(profile, browser); |
| 307 dialog->ShowDialog(); | 356 dialog->ShowDialog(); |
| 308 } | 357 } |
| OLD | NEW |