Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / startup / default_browser_prompt_win.cc
blobc7843e2521fda7cf02380f0e6b8f4cd3d5309f59
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;
21 namespace {
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 {
28 public:
29 static void LaunchSoon(Profile* profile) {
30 // The instance will manage its own lifetime.
31 new SetMetroBrowserFlowLauncher(profile);
34 private:
35 explicit SetMetroBrowserFlowLauncher(Profile* profile)
36 : 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_;
47 Profile* profile_;
49 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher);
52 void SetMetroBrowserFlowLauncher::Observe(
53 int type,
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())
61 return;
63 // Unregister and delete.
64 registrar_.RemoveAll();
65 SetAsDefaultBrowserUI::Show(profile_, browser);
66 delete this;
69 } // namespace
71 namespace chrome {
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.
77 bool show_status =
78 (ShellIntegration::CanSetAsDefaultBrowser() ==
79 ShellIntegration::SET_DEFAULT_INTERACTIVE) &&
80 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT);
82 if (show_status) {
83 startup_metric_utils::SetNonBrowserUIDisplayed();
84 SetMetroBrowserFlowLauncher::LaunchSoon(profile);
87 return show_status;
90 } // namespace chrome