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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/startup/default_browser_prompt.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/startup_metric_utils/startup_metric_utils.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h"
19 using content::BrowserThread
;
23 // Show the page prompting the user to make Chrome the default browser on
24 // Windows 8 (which means becoming "the browser" in Metro mode). The page
25 // will be shown at the first appropriate opportunity. It can be placed in
26 // a tab or in a dialog, depending on other settings.
27 class SetMetroBrowserFlowLauncher
: public content::NotificationObserver
{
29 static void LaunchSoon(Profile
* profile
) {
30 // The instance will manage its own lifetime.
31 new SetMetroBrowserFlowLauncher(profile
);
35 explicit SetMetroBrowserFlowLauncher(Profile
* profile
)
37 registrar_
.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
,
38 content::NotificationService::AllSources());
41 // content::NotificationObserver override:
42 virtual void Observe(int type
,
43 const content::NotificationSource
& source
,
44 const content::NotificationDetails
& details
) OVERRIDE
;
46 content::NotificationRegistrar registrar_
;
49 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher
);
52 void SetMetroBrowserFlowLauncher::Observe(
54 const content::NotificationSource
& source
,
55 const content::NotificationDetails
& details
) {
56 DCHECK_EQ(type
, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME
);
57 Browser
* browser
= chrome::FindBrowserWithWebContents(
58 content::Source
<content::WebContents
>(source
).ptr());
60 if (!browser
|| !browser
->is_type_tabbed())
63 // Unregister and delete.
64 registrar_
.RemoveAll();
65 SetAsDefaultBrowserUI::Show(profile_
, browser
);
73 bool ShowFirstRunDefaultBrowserPrompt(Profile
* profile
) {
74 // If the only available mode of setting the default browser requires
75 // user interaction, it means this couldn't have been done yet. Therefore,
76 // we launch the dialog and inform the caller of it.
78 (ShellIntegration::CanSetAsDefaultBrowser() ==
79 ShellIntegration::SET_DEFAULT_INTERACTIVE
) &&
80 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT
);
83 startup_metric_utils::SetNonBrowserUIDisplayed();
84 SetMetroBrowserFlowLauncher::LaunchSoon(profile
);