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 | |
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 ResponseDelegate { | |
robertshield
2012/08/08 18:09:38
nit: indent, why private inheritance?
motek.
2012/08/08 19:55:37
Habits. Changed to public.
| |
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), browser_(browser), owns_handler_(true), |
248 handler_(new SetAsDefaultBrowserHandler(this)), | |
249 response_is_close_chrome_(false) { | |
250 } | |
251 | |
252 SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() { | |
253 if (owns_handler_) | |
254 delete handler_; | |
235 } | 255 } |
236 | 256 |
237 void SetAsDefaultBrowserDialogImpl::ShowDialog() { | 257 void SetAsDefaultBrowserDialogImpl::ShowDialog() { |
238 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), | 258 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), |
239 browser_->profile(), this); | 259 browser_->profile(), this); |
240 } | 260 } |
241 | 261 |
242 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const { | 262 ui::ModalType SetAsDefaultBrowserDialogImpl::GetDialogModalType() const { |
243 return ui::MODAL_TYPE_SYSTEM; | 263 return ui::MODAL_TYPE_SYSTEM; |
244 } | 264 } |
245 | 265 |
246 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const { | 266 string16 SetAsDefaultBrowserDialogImpl::GetDialogTitle() const { |
247 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE); | 267 return l10n_util::GetStringUTF16(IDS_METRO_FLOW_TAB_TITLE); |
248 } | 268 } |
249 | 269 |
250 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const { | 270 GURL SetAsDefaultBrowserDialogImpl::GetDialogContentURL() const { |
251 std::string url_string(chrome::kChromeUIMetroFlowURL); | 271 std::string url_string(chrome::kChromeUIMetroFlowURL); |
252 return GURL(url_string); | 272 return GURL(url_string); |
253 } | 273 } |
254 | 274 |
255 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers( | 275 void SetAsDefaultBrowserDialogImpl::GetWebUIMessageHandlers( |
256 std::vector<WebUIMessageHandler*>* handlers) const { | 276 std::vector<WebUIMessageHandler*>* handlers) const { |
277 handlers->push_back(handler_); | |
278 owns_handler_ = false; | |
257 } | 279 } |
258 | 280 |
259 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const { | 281 void SetAsDefaultBrowserDialogImpl::GetDialogSize(gfx::Size* size) const { |
260 PrefService* prefs = profile_->GetPrefs(); | 282 PrefService* prefs = profile_->GetPrefs(); |
261 gfx::Font approximate_web_font( | 283 gfx::Font approximate_web_font( |
262 prefs->GetString(prefs::kWebKitSansSerifFontFamily), | 284 prefs->GetString(prefs::kWebKitSansSerifFontFamily), |
263 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); | 285 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); |
264 | 286 |
265 *size = ui::GetLocalizedContentsSizeForFont( | 287 *size = ui::GetLocalizedContentsSizeForFont( |
266 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, | 288 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, |
267 approximate_web_font); | 289 approximate_web_font); |
268 } | 290 } |
269 | 291 |
270 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { | 292 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { |
271 return "[]"; | 293 return "[]"; |
272 } | 294 } |
273 | 295 |
274 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( | 296 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( |
275 const std::string& json_retval) { | 297 const std::string& json_retval) { |
298 if (response_is_close_chrome_) { | |
299 // If Metro Chrome has been activated, we should close this process. | |
300 // We are restarting as metro now. | |
301 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
302 base::Bind(&BrowserList::CloseAllBrowsersWithProfile, profile_)); | |
303 } else { | |
304 // This will be false if the user closed the dialog without doing anything | |
305 // or if operation failed for any reason (including invocation under a | |
306 // Windows version earlier than 8). | |
307 // In such case we just carry on with normal chrome session. However, for | |
robertshield
2012/08/08 18:09:38
nit: with normal -> with a normal
motek.
2012/08/08 19:55:37
Done.
| |
308 // the purpose of surfacing this dialog actual browser windows had to | |
309 // remain hidden. Now it's the time to show them. | |
310 for (BrowserList::const_iterator it = BrowserList::begin(); | |
311 it != BrowserList::end(); ++it) { | |
312 BrowserWindow* window = NULL; | |
313 WebContents* contents = chrome::GetActiveWebContents(*it); | |
314 window = (*it)->window(); | |
315 if (window && contents) { | |
316 window->Show(); | |
317 contents->GetView()->SetInitialFocus(); | |
robertshield
2012/08/08 18:09:38
question: do we want to set focus to each window i
motek.
2012/08/08 19:55:37
Good question. I assumed the initial focus is basi
| |
318 } | |
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 |