Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/ui/webui/set_as_default_browser_ui.cc

Issue 10696093: Hide the main window when Set-As-Default dialog is present. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed owner's remarks. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/set_as_default_browser_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 };
sky 2012/08/09 16:13:47 Add a protected virtual destructor.
motek. 2012/08/09 17:17:48 Done.
70
62 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the 71 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the
63 // default browser on button click, closing itself and triggering Chrome 72 // default browser on button click, closing itself and triggering Chrome
64 // restart. 73 // restart.
65 class SetAsDefaultBrowserHandler 74 class SetAsDefaultBrowserHandler
66 : public WebUIMessageHandler, 75 : public WebUIMessageHandler,
67 public base::SupportsWeakPtr<SetAsDefaultBrowserHandler>, 76 public base::SupportsWeakPtr<SetAsDefaultBrowserHandler>,
68 public ShellIntegration::DefaultWebClientObserver { 77 public ShellIntegration::DefaultWebClientObserver {
69 public: 78 public:
70 SetAsDefaultBrowserHandler(); 79 explicit SetAsDefaultBrowserHandler(ResponseDelegate* response_delegate);
71 virtual ~SetAsDefaultBrowserHandler(); 80 virtual ~SetAsDefaultBrowserHandler();
72 81
73 // WebUIMessageHandler implementation. 82 // WebUIMessageHandler implementation.
74 virtual void RegisterMessages() OVERRIDE; 83 virtual void RegisterMessages() OVERRIDE;
75 84
76 // ShellIntegration::DefaultWebClientObserver implementation. 85 // ShellIntegration::DefaultWebClientObserver implementation.
77 virtual void SetDefaultWebClientUIState( 86 virtual void SetDefaultWebClientUIState(
78 ShellIntegration::DefaultWebClientUIState state) OVERRIDE; 87 ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
79 virtual void OnSetAsDefaultConcluded(bool call_result) OVERRIDE; 88 virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE;
80 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; 89 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
81 90
82 private: 91 private:
83 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. 92 // Handler for the 'Next' (or 'make Chrome the Metro browser') button.
84 void HandleLaunchSetDefaultBrowserFlow(const ListValue* args); 93 void HandleLaunchSetDefaultBrowserFlow(const ListValue* args);
85 94
86 // Close this web ui. 95 // Close this web ui.
87 void ConcludeInteraction(); 96 void ConcludeInteraction(bool mark_success);
88 97
89 // If required and possible, spawns a new Chrome in Metro mode and closes the 98 // 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 99 // current instance. Windows 8 only, on earlier systems it will simply close
91 // this UI. 100 // this UI.
92 void ActivateMetroChrome(); 101 void ActivateMetroChrome();
93 102
94 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; 103 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
95 bool set_default_returned_; 104 bool set_default_returned_;
96 bool set_default_result_; 105 bool set_default_result_;
106 ResponseDelegate* response_delegate_;
97 107
98 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); 108 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler);
99 }; 109 };
100 110
101 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler() 111 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler(
112 ResponseDelegate* response_delegate)
102 : ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_( 113 : ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_(
103 new ShellIntegration::DefaultBrowserWorker(this))), 114 new ShellIntegration::DefaultBrowserWorker(this))),
104 set_default_returned_(false), set_default_result_(false) { 115 set_default_returned_(false), set_default_result_(false),
116 response_delegate_(response_delegate) {
105 } 117 }
106 118
107 SetAsDefaultBrowserHandler::~SetAsDefaultBrowserHandler() { 119 SetAsDefaultBrowserHandler::~SetAsDefaultBrowserHandler() {
108 default_browser_worker_->ObserverDestroyed(); 120 default_browser_worker_->ObserverDestroyed();
109 } 121 }
110 122
111 void SetAsDefaultBrowserHandler::RegisterMessages() { 123 void SetAsDefaultBrowserHandler::RegisterMessages() {
112 web_ui()->RegisterMessageCallback( 124 web_ui()->RegisterMessageCallback(
113 "SetAsDefaultBrowser:LaunchSetDefaultBrowserFlow", 125 "SetAsDefaultBrowser:LaunchSetDefaultBrowserFlow",
114 base::Bind(&SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow, 126 base::Bind(&SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow,
115 base::Unretained(this))); 127 base::Unretained(this)));
116 } 128 }
117 129
118 void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState( 130 void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState(
119 ShellIntegration::DefaultWebClientUIState state) { 131 ShellIntegration::DefaultWebClientUIState state) {
120 // The callback is expected to be invoked once the procedure has completed. 132 // The callback is expected to be invoked once the procedure has completed.
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
122 if (!set_default_returned_) 134 if (!set_default_returned_)
123 return; 135 return;
124 136
125 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { 137 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) {
126 // The operation concluded, but Chrome is still not the default. 138 // The operation concluded, but Chrome is still not the default.
127 // If the call has succeeded, this suggests user has decided not to make 139 // If the call has succeeded, this suggests user has decided not to make
128 // chrome the default. We fold this UI and move on. 140 // chrome the default. We fold this UI and move on.
129 ConcludeInteraction(); 141 ConcludeInteraction(false);
130 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { 142 } else if (state == ShellIntegration::STATE_IS_DEFAULT) {
131 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( 143 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
132 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { 144 prefs::kSuppressSwitchToMetroModeOnSetDefault)) {
133 BrowserThread::PostTask( 145 BrowserThread::PostTask(
134 BrowserThread::FILE, FROM_HERE, 146 BrowserThread::FILE, FROM_HERE,
135 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, 147 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome,
136 base::Unretained(this))); 148 base::Unretained(this)));
137 } else { 149 } else {
138 ConcludeInteraction(); 150 ConcludeInteraction(false);
139 } 151 }
140 } 152 }
141 } 153 }
142 154
143 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { 155 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) {
144 set_default_returned_ = true; 156 set_default_returned_ = true;
145 set_default_result_ = call_result; 157 set_default_result_ = call_result;
146 } 158 }
147 159
148 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() { 160 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() {
149 return true; 161 return true;
150 } 162 }
151 163
152 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( 164 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow(
153 const ListValue* args) { 165 const ListValue* args) {
154 set_default_returned_ = false; 166 set_default_returned_ = false;
155 set_default_result_ = false; 167 set_default_result_ = false;
156 default_browser_worker_->StartSetAsDefault(); 168 default_browser_worker_->StartSetAsDefault();
157 } 169 }
158 170
159 void SetAsDefaultBrowserHandler::ConcludeInteraction() { 171 void SetAsDefaultBrowserHandler::ConcludeInteraction(bool close_chrome) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161 WebContents* contents = web_ui()->GetWebContents(); 173 WebContents* contents = web_ui()->GetWebContents();
174 if (response_delegate_)
175 response_delegate_->SetChromeShutdownRequired(close_chrome);
176
162 if (contents) { 177 if (contents) {
163 content::WebContentsDelegate* delegate = contents->GetDelegate(); 178 content::WebContentsDelegate* delegate = contents->GetDelegate();
164 if (delegate) 179 if (delegate)
165 delegate->CloseContents(contents); 180 delegate->CloseContents(contents);
166 } 181 }
167 } 182 }
168 183
169 void SetAsDefaultBrowserHandler::ActivateMetroChrome() { 184 void SetAsDefaultBrowserHandler::ActivateMetroChrome() {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
171 FilePath cur_chrome_exe; 186 FilePath cur_chrome_exe;
172 bool sentinel_removed = false; 187 bool sentinel_removed = false;
173 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) && 188 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) &&
174 first_run::IsChromeFirstRun() && 189 first_run::IsChromeFirstRun() &&
175 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) { 190 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) {
176 // If this is per-user install, we will have to remove the sentinel file 191 // 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'. 192 // to assure the user goes through the intended 'first-run flow'.
178 sentinel_removed = first_run::RemoveSentinel(); 193 sentinel_removed = first_run::RemoveSentinel();
179 } 194 }
180 195
181 if (ShellIntegration::ActivateMetroChrome()) { 196 bool metro_chrome_activated = ShellIntegration::ActivateMetroChrome();
182 // If Metro Chrome has been activated, we should close this process. 197 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(); 198 first_run::CreateSentinel();
193 199
194 BrowserThread::PostTask( 200 BrowserThread::PostTask(
195 BrowserThread::UI, FROM_HERE, 201 BrowserThread::UI, FROM_HERE,
196 base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction, 202 base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction,
197 base::Unretained(this))); 203 base::Unretained(this), metro_chrome_activated));
198 }
199 } 204 }
200 205
201 // A web dialog delegate implementation for when 'Make Chrome Metro' UI 206 // A web dialog delegate implementation for when 'Make Chrome Metro' UI
202 // is displayed on a dialog. 207 // is displayed on a dialog.
203 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate { 208 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate,
209 public ResponseDelegate {
204 public: 210 public:
205 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); 211 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser);
212 virtual ~SetAsDefaultBrowserDialogImpl();
206 // Show a modal web dialog with kChromeUIMetroFlowURL page. 213 // Show a modal web dialog with kChromeUIMetroFlowURL page.
207 void ShowDialog(); 214 void ShowDialog();
208 215
209 protected: 216 protected:
210 // Overridden from WebDialogDelegate: 217 // Overridden from WebDialogDelegate:
211 virtual ui::ModalType GetDialogModalType() const OVERRIDE; 218 virtual ui::ModalType GetDialogModalType() const OVERRIDE;
212 virtual string16 GetDialogTitle() const OVERRIDE; 219 virtual string16 GetDialogTitle() const OVERRIDE;
213 virtual GURL GetDialogContentURL() const OVERRIDE; 220 virtual GURL GetDialogContentURL() const OVERRIDE;
214 virtual void GetWebUIMessageHandlers( 221 virtual void GetWebUIMessageHandlers(
215 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; 222 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
216 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; 223 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
217 virtual std::string GetDialogArgs() const OVERRIDE; 224 virtual std::string GetDialogArgs() const OVERRIDE;
218 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; 225 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
219 virtual void OnCloseContents(WebContents* source, 226 virtual void OnCloseContents(WebContents* source,
220 bool* out_close_dialog) OVERRIDE; 227 bool* out_close_dialog) OVERRIDE;
221 virtual bool ShouldShowDialogTitle() const OVERRIDE; 228 virtual bool ShouldShowDialogTitle() const OVERRIDE;
222 virtual bool HandleContextMenu( 229 virtual bool HandleContextMenu(
223 const content::ContextMenuParams& params) OVERRIDE; 230 const content::ContextMenuParams& params) OVERRIDE;
224 231
232 // Overridden from ResponseDelegate:
233 virtual void SetChromeShutdownRequired(bool shutdown_chrome);
234
225 private: 235 private:
226 Profile* profile_; 236 Profile* profile_;
227 Browser* browser_; 237 Browser* browser_;
238 mutable bool owns_handler_;
239 SetAsDefaultBrowserHandler* handler_;
240 bool response_is_close_chrome_;
228 241
229 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); 242 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl);
230 }; 243 };
231 244
232 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile, 245 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile,
233 Browser* browser) 246 Browser* browser)
234 : profile_(profile), browser_(browser) { 247 : profile_(profile),
248 browser_(browser),
249 owns_handler_(true),
250 handler_(new SetAsDefaultBrowserHandler(this)),
251 response_is_close_chrome_(false) {
252 }
253
254 SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() {
255 if (owns_handler_)
256 delete handler_;
235 } 257 }
236 258
237 void SetAsDefaultBrowserDialogImpl::ShowDialog() { 259 void SetAsDefaultBrowserDialogImpl::ShowDialog() {
238 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), 260 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(),
239 browser_->profile(), this); 261 browser_->profile(), this);
240 } 262 }
241 263
242 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const { 264 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const {
243 return ui::MODAL_TYPE_SYSTEM; 265 return ui::MODAL_TYPE_SYSTEM;
244 } 266 }
245 267
246 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const { 268 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const {
247 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE); 269 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE);
248 } 270 }
249 271
250 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const { 272 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const {
251 std::string url_string(chrome::kChromeUIMetroFlowURL); 273 std::string url_string(chrome::kChromeUIMetroFlowURL);
252 return GURL(url_string); 274 return GURL(url_string);
253 } 275 }
254 276
255 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers( 277 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers(
256 std::vector<WebUIMessageHandler*>* handlers) const { 278 std::vector<WebUIMessageHandler*>* handlers) const {
279 handlers->push_back(handler_);
280 owns_handler_ = false;
257 } 281 }
258 282
259 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const { 283 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const {
260 PrefService* prefs = profile_->GetPrefs(); 284 PrefService* prefs = profile_->GetPrefs();
261 gfx::Font approximate_web_font( 285 gfx::Font approximate_web_font(
262 prefs->GetString(prefs::kWebKitSansSerifFontFamily), 286 prefs->GetString(prefs::kWebKitSansSerifFontFamily),
263 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); 287 prefs->GetInteger(prefs::kWebKitDefaultFontSize));
264 288
265 *size = ui::GetLocalizedContentsSizeForFont( 289 *size = ui::GetLocalizedContentsSizeForFont(
266 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, 290 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES,
267 approximate_web_font); 291 approximate_web_font);
268 } 292 }
269 293
270 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { 294 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const {
271 return "[]"; 295 return "[]";
272 } 296 }
273 297
274 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( 298 void SetAsDefaultBrowserDialogImpl::OnDialogClosed(
275 const std::string& json_retval) { 299 const std::string& json_retval) {
300 if (response_is_close_chrome_) {
301 // If Metro Chrome has been activated, we should close this process.
302 // We are restarting as metro now.
303 BrowserList::CloseAllBrowsersWithProfile(profile_);
304 } else {
305 // This will be false if the user closed the dialog without doing anything
306 // or if operation failed for any reason (including invocation under a
307 // Windows version earlier than 8).
308 // In such case we just carry on with a normal chrome session. However, for
309 // the purpose of surfacing this dialog the actual browser window had to
310 // remain hidden. Now it's the time to show it.
311 BrowserWindow* window = browser_->window();
sky 2012/08/09 16:13:47 Do you need to worry about browser being deleted o
motek. 2012/08/09 17:17:48 I did, sort of. But if I am not mistaken, this cod
312 WebContents* contents = chrome::GetActiveWebContents(browser_);
313 if (window)
sky 2012/08/09 16:13:47 This should never be NULL.
motek. 2012/08/09 17:17:48 Done.
314 window->Show();
315 if (contents)
316 contents->GetView()->SetInitialFocus();
317 }
318
276 delete this; 319 delete this;
277 } 320 }
278 321
279 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, 322 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source,
280 bool* out_close_dialog) { 323 bool* out_close_dialog) {
281 *out_close_dialog = true; 324 *out_close_dialog = true;
282 } 325 }
283 326
284 bool SetAsDefaultBrowserDialogImpl::ShouldShowDialogTitle() const { 327 bool SetAsDefaultBrowserDialogImpl::ShouldShowDialogTitle() const {
285 return true; 328 return true;
286 } 329 }
287 330
288 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu( 331 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu(
289 const content::ContextMenuParams& params) { 332 const content::ContextMenuParams& params) {
290 return true; 333 return true;
291 } 334 }
292 335
336 void SetAsDefaultBrowserDialogImpl::SetChromeShutdownRequired(
337 bool shutdown_chrome) {
338 response_is_close_chrome_ = shutdown_chrome;
339 }
340
293 } // namespace 341 } // namespace
294 342
295 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) 343 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui)
296 : WebUIController(web_ui) { 344 : ui::WebDialogUI(web_ui) {
297 web_ui->AddMessageHandler(new SetAsDefaultBrowserHandler());
298 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), 345 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui),
299 CreateSetAsDefaultBrowserUIHTMLSource()); 346 CreateSetAsDefaultBrowserUIHTMLSource());
300 } 347 }
301 348
302 // static 349 // static
303 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { 350 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
305 SetAsDefaultBrowserDialogImpl* dialog = 352 SetAsDefaultBrowserDialogImpl* dialog =
306 new SetAsDefaultBrowserDialogImpl(profile, browser); 353 new SetAsDefaultBrowserDialogImpl(profile, browser);
307 dialog->ShowDialog(); 354 dialog->ShowDialog();
308 } 355 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/set_as_default_browser_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698