BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / startup / default_browser_prompt_win.cc
blobd2d01ce10c9d186de1b9c7205391c90022c0ec54
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 "base/win/windows_version.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/shell_integration.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/webui/set_as_default_browser_ui.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 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 // The behavior on Windows 10 is no good at the moment, since there is no
75 // known way to lead the user directly to a default browser picker.
76 if (base::win::GetVersion() >= base::win::VERSION_WIN10)
77 return false;
79 // If the only available mode of setting the default browser requires
80 // user interaction, it means this couldn't have been done yet. Therefore,
81 // we launch the dialog and inform the caller of it.
82 bool show_status =
83 (ShellIntegration::CanSetAsDefaultBrowser() ==
84 ShellIntegration::SET_DEFAULT_INTERACTIVE) &&
85 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT);
87 if (show_status) {
88 startup_metric_utils::SetNonBrowserUIDisplayed();
89 SetMetroBrowserFlowLauncher::LaunchSoon(profile);
92 return show_status;
95 } // namespace chrome