#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
-#include "base/win/win_util.h"
-#include "chrome/browser/first_run/first_run.h"
-#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "chrome/grit/generated_resources.h"
+#include "chrome/grit/locale_settings.h"
#include "chrome/installer/util/install_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
-#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font.h"
const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult";
-// The enum permits registering in UMA the three possible outcomes.
+// The enum permits registering in UMA the three possible outcomes (do not
+// reorder these).
// ACCEPTED: user pressed Next and made Chrome default.
// DECLINED: user simply closed the dialog without making Chrome default.
// REGRETTED: user pressed Next but then elected a different default browser.
-// ACCEPTED_IMMERSE: as above with a switch to metro mode.
enum MakeChromeDefaultResult {
- MAKE_CHROME_DEFAULT_ACCEPTED,
- MAKE_CHROME_DEFAULT_DECLINED,
- MAKE_CHROME_DEFAULT_REGRETTED,
- MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE,
+ MAKE_CHROME_DEFAULT_ACCEPTED = 0,
+ MAKE_CHROME_DEFAULT_DECLINED = 1,
+ MAKE_CHROME_DEFAULT_REGRETTED = 2,
+ // MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE = 3, // Deprecated.
MAKE_CHROME_DEFAULT_MAX
};
content::WebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() {
content::WebUIDataSource* data_source = content::WebUIDataSource::Create(
chrome::kChromeUIMetroFlowHost);
+ data_source->SetUseJsonJSFormatV2();
data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE);
data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT);
data_source->AddLocalizedString("flowDescription",
IDS_METRO_FLOW_LOGO_STRING_ALT);
data_source->SetJsonPath("strings.js");
data_source->AddResourcePath("set_as_default_browser.js",
- IDR_SET_AS_DEFAULT_BROWSER_JS);
+ IDR_SET_AS_DEFAULT_BROWSER_JS);
data_source->SetDefaultResource(IDR_SET_AS_DEFAULT_BROWSER_HTML);
return data_source;
}
// Close this web ui.
void ConcludeInteraction(MakeChromeDefaultResult interaction_result);
- // Returns true if Chrome should be restarted in immersive mode upon being
- // made the default browser.
- bool ShouldAttemptImmersiveRestart();
-
scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
bool set_default_returned_;
bool set_default_result_;
void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState(
ShellIntegration::DefaultWebClientUIState state) {
// The callback is expected to be invoked once the procedure has completed.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!set_default_returned_)
return;
// chrome the default.
ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED);
} else if (state == ShellIntegration::STATE_IS_DEFAULT) {
- ConcludeInteraction(ShouldAttemptImmersiveRestart() ?
- MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE : MAKE_CHROME_DEFAULT_ACCEPTED);
+ ConcludeInteraction(MAKE_CHROME_DEFAULT_ACCEPTED);
}
// Otherwise, keep the dialog open since the user probably didn't make a
void SetAsDefaultBrowserHandler::ConcludeInteraction(
MakeChromeDefaultResult interaction_result) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (response_delegate_)
response_delegate_->SetDialogInteractionResult(interaction_result);
}
}
-bool SetAsDefaultBrowserHandler::ShouldAttemptImmersiveRestart() {
- return (base::win::IsTouchEnabledDevice() &&
- !Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
- prefs::kSuppressSwitchToMetroModeOnSetDefault));
-}
-
// A web dialog delegate implementation for when 'Make Chrome Metro' UI
// is displayed on a dialog.
class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate,
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
private:
- // Reset the first-run sentinel file, so must be called on the FILE thread.
- // This is needed if the browser should be restarted in immersive mode.
- // The method is static because the dialog could be destroyed
- // before the task arrives on the FILE thread.
- static void AttemptImmersiveFirstRunRestartOnFileThread();
-
Profile* profile_;
Browser* browser_;
mutable bool owns_handler_;
dialog_interaction_result_,
MAKE_CHROME_DEFAULT_MAX);
- if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE) {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SetAsDefaultBrowserDialogImpl::
- AttemptImmersiveFirstRunRestartOnFileThread));
- } else {
- // If the user explicitly elected *not to* make Chrome default, we won't
- // ask again.
- if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_REGRETTED) {
- PrefService* prefs = profile_->GetPrefs();
- prefs->SetBoolean(prefs::kCheckDefaultBrowser, false);
- }
-
- // Carry on with a normal chrome session. For the purpose of surfacing this
- // dialog the actual browser window had to remain hidden. Now it's time to
- // show it.
- if (browser_) {
- BrowserWindow* window = browser_->window();
- WebContents* contents =
- browser_->tab_strip_model()->GetActiveWebContents();
- window->Show();
- if (contents)
- contents->GetView()->SetInitialFocus();
- }
+ // If the user explicitly elected *not to* make Chrome default, we won't
+ // ask again.
+ if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_REGRETTED) {
+ PrefService* prefs = profile_->GetPrefs();
+ prefs->SetBoolean(prefs::kCheckDefaultBrowser, false);
+ }
+
+ // Carry on with a normal chrome session. For the purpose of surfacing this
+ // dialog the actual browser window had to remain hidden. Now it's time to
+ // show it.
+ if (browser_) {
+ BrowserWindow* window = browser_->window();
+ WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
+ window->Show();
+ if (contents)
+ contents->SetInitialFocus();
}
delete this;
}
}
-void SetAsDefaultBrowserDialogImpl::
- AttemptImmersiveFirstRunRestartOnFileThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
- // If the sentinel was created for this launch, remove it before restarting
- // in immersive mode so that the user is taken through the full first-run
- // flow there.
- if (first_run::IsChromeFirstRun())
- first_run::RemoveSentinel();
-
- // Do a straight-up restart rather than a mode-switch restart.
- // delegate_execute.exe will choose an immersive launch on the basis of the
- // same IsTouchEnabledDevice check, but will not store this as the user's
- // choice.
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&chrome::AttemptRestart));
-}
-
} // namespace
SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui)
// static
void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
SetAsDefaultBrowserDialogImpl* dialog =
new SetAsDefaultBrowserDialogImpl(profile, browser);
dialog->ShowDialog();