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" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
129 if (!set_default_returned_) | 129 if (!set_default_returned_) |
130 return; | 130 return; |
131 | 131 |
132 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { | 132 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { |
133 // The operation concluded, but Chrome is still not the default. | 133 // The operation concluded, but Chrome is still not the default. |
134 // If the call has succeeded, this suggests user has decided not to make | 134 // If the call has succeeded, this suggests user has decided not to make |
135 // chrome the default. We fold this UI and move on. | 135 // chrome the default. We fold this UI and move on. |
136 ConcludeInteraction(); | 136 ConcludeInteraction(); |
137 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { | 137 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { |
138 BrowserThread::PostTask( | 138 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( |
139 BrowserThread::FILE, FROM_HERE, | 139 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { |
140 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, | 140 BrowserThread::PostTask( |
141 base::Unretained(this))); | 141 BrowserThread::FILE, FROM_HERE, |
| 142 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, |
| 143 base::Unretained(this))); |
| 144 } else { |
| 145 ConcludeInteraction(); |
| 146 } |
142 } | 147 } |
143 } | 148 } |
144 | 149 |
145 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { | 150 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { |
146 set_default_returned_ = true; | 151 set_default_returned_ = true; |
147 set_default_result_ = call_result; | 152 set_default_result_ = call_result; |
148 } | 153 } |
149 | 154 |
150 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() { | 155 bool SetAsDefaultBrowserHandler::IsInteractiveSetDefaultPermitted() { |
151 return true; | 156 return true; |
152 } | 157 } |
153 | 158 |
154 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( | 159 void SetAsDefaultBrowserHandler::HandleLaunchSetDefaultBrowserFlow( |
155 const ListValue* args) { | 160 const ListValue* args) { |
156 set_default_returned_ = false; | 161 set_default_returned_ = false; |
157 set_default_result_ = false; | 162 set_default_result_ = false; |
158 default_browser_worker_->StartSetAsDefault(); | 163 default_browser_worker_->StartSetAsDefault(); |
159 } | 164 } |
160 | 165 |
161 void SetAsDefaultBrowserHandler::HandleReturnToBrowser(const ListValue* args) { | 166 void SetAsDefaultBrowserHandler::HandleReturnToBrowser(const ListValue* args) { |
162 ConcludeInteraction(); | 167 ConcludeInteraction(); |
163 } | 168 } |
164 | 169 |
165 void SetAsDefaultBrowserHandler::ConcludeInteraction() { | 170 void SetAsDefaultBrowserHandler::ConcludeInteraction() { |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
167 WebContents* contents = web_ui()->GetWebContents(); | 172 WebContents* contents = web_ui()->GetWebContents(); |
168 if (contents) { | 173 if (contents) { |
169 content::WebContentsDelegate* delegate = contents->GetDelegate(); | 174 content::WebContentsDelegate* delegate = contents->GetDelegate(); |
170 if (delegate) { | 175 if (delegate) |
171 if (!delegate->IsPopupOrPanel(contents)) { | |
172 Browser* browser = browser::FindBrowserWithWebContents(contents); | |
173 if (browser) | |
174 chrome::ShowSyncSetup(browser, SyncPromoUI::SOURCE_START_PAGE); | |
175 } | |
176 delegate->CloseContents(contents); | 176 delegate->CloseContents(contents); |
177 } | |
178 } | 177 } |
179 } | 178 } |
180 | 179 |
181 void SetAsDefaultBrowserHandler::ActivateMetroChrome() { | 180 void SetAsDefaultBrowserHandler::ActivateMetroChrome() { |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
183 | |
184 FilePath cur_chrome_exe; | 182 FilePath cur_chrome_exe; |
185 bool sentinel_removed = false; | 183 bool sentinel_removed = false; |
186 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) && | 184 if (PathService::Get(base::FILE_EXE, &cur_chrome_exe) && |
187 first_run::IsChromeFirstRun() && | 185 first_run::IsChromeFirstRun() && |
188 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) { | 186 InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str())) { |
189 // If this is per-user install, we will have to remove the sentinel file | 187 // If this is per-user install, we will have to remove the sentinel file |
190 // to assure the user goes through the intended 'first-run flow'. | 188 // to assure the user goes through the intended 'first-run flow'. |
191 sentinel_removed = first_run::RemoveSentinel(); | 189 sentinel_removed = first_run::RemoveSentinel(); |
192 } | 190 } |
193 | 191 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } // namespace | 304 } // namespace |
307 | 305 |
308 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) | 306 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) |
309 : WebUIController(web_ui) { | 307 : WebUIController(web_ui) { |
310 web_ui->AddMessageHandler(new SetAsDefaultBrowserHandler()); | 308 web_ui->AddMessageHandler(new SetAsDefaultBrowserHandler()); |
311 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), | 309 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), |
312 CreateSetAsDefaultBrowserUIHTMLSource()); | 310 CreateSetAsDefaultBrowserUIHTMLSource()); |
313 } | 311 } |
314 | 312 |
315 // static | 313 // static |
316 void SetAsDefaultBrowserUI::Show(Profile* profile, | 314 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { |
317 Browser* browser, | |
318 bool dialog) { | |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
320 if (dialog) { | 316 SetAsDefaultBrowserDialogImpl* dialog = |
321 SetAsDefaultBrowserDialogImpl* dialog = | 317 new SetAsDefaultBrowserDialogImpl(profile, browser); |
322 new SetAsDefaultBrowserDialogImpl(profile, browser); | 318 dialog->ShowDialog(); |
323 dialog->ShowDialog(); | |
324 } else { | |
325 GURL url(chrome::kChromeUIMetroFlowURL); | |
326 chrome::NavigateParams params( | |
327 chrome::GetSingletonTabNavigateParams(browser, url)); | |
328 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; | |
329 chrome::ShowSingletonTabOverwritingNTP(browser, params); | |
330 } | |
331 } | 319 } |
OLD | NEW |