| 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/startup/default_browser_prompt.h" | 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | |
| 8 #include "base/win/windows_version.h" | 7 #include "base/win/windows_version.h" |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/shell_integration.h" | 8 #include "chrome/browser/shell_integration.h" |
| 11 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/webui/set_as_default_browser_ui_win.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | |
| 13 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" | |
| 14 #include "components/prefs/pref_service.h" | |
| 15 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 10 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/browser/notification_service.h" | |
| 18 #include "content/public/browser/notification_types.h" | |
| 19 | |
| 20 using content::BrowserThread; | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // Show the page prompting the user to make Chrome the default browser on | |
| 25 // Windows 8 (which means becoming "the browser" in Metro mode). The page | |
| 26 // will be shown at the first appropriate opportunity. It can be placed in | |
| 27 // a tab or in a dialog, depending on other settings. | |
| 28 class SetMetroBrowserFlowLauncher : public content::NotificationObserver { | |
| 29 public: | |
| 30 static void LaunchSoon(Profile* profile) { | |
| 31 // The instance will manage its own lifetime. | |
| 32 new SetMetroBrowserFlowLauncher(profile); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 explicit SetMetroBrowserFlowLauncher(Profile* profile) | |
| 37 : profile_(profile) { | |
| 38 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 39 content::NotificationService::AllSources()); | |
| 40 } | |
| 41 | |
| 42 // content::NotificationObserver override: | |
| 43 void Observe(int type, | |
| 44 const content::NotificationSource& source, | |
| 45 const content::NotificationDetails& details) override; | |
| 46 | |
| 47 content::NotificationRegistrar registrar_; | |
| 48 Profile* profile_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); | |
| 51 }; | |
| 52 | |
| 53 void SetMetroBrowserFlowLauncher::Observe( | |
| 54 int type, | |
| 55 const content::NotificationSource& source, | |
| 56 const content::NotificationDetails& details) { | |
| 57 DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type); | |
| 58 | |
| 59 Browser* browser = chrome::FindBrowserWithWebContents( | |
| 60 content::Source<content::WebContents>(source).ptr()); | |
| 61 if (!browser || !browser->is_type_tabbed()) | |
| 62 return; | |
| 63 | |
| 64 // Unregister and delete. | |
| 65 registrar_.RemoveAll(); | |
| 66 SetAsDefaultBrowserUI::Show(profile_, browser); | |
| 67 delete this; | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | 11 |
| 72 namespace chrome { | 12 namespace chrome { |
| 73 | 13 |
| 74 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 14 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 75 // The behavior on Windows 10 is no good at the moment, since there is no | 15 // The behavior on Windows 10 is no good at the moment, since there is no |
| 76 // known way to lead the user directly to a default browser picker. | 16 // known way to lead the user directly to a default browser picker. |
| 77 if (base::win::GetVersion() >= base::win::VERSION_WIN10) | 17 if (base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 78 return false; | 18 return false; |
| 79 | 19 |
| 80 // If the only available mode of setting the default browser requires | 20 // If the only available mode of setting the default browser requires |
| 81 // user interaction, it means this couldn't have been done yet. Therefore, | 21 // user interaction, it means this couldn't have been done yet. Therefore, |
| 82 // we launch the dialog and inform the caller of it. | 22 // we launch the dialog and inform the caller of it. |
| 83 bool show_status = (shell_integration::GetDefaultWebClientSetPermission() == | 23 bool show_status = (shell_integration::GetDefaultWebClientSetPermission() == |
| 84 shell_integration::SET_DEFAULT_INTERACTIVE) && | 24 shell_integration::SET_DEFAULT_INTERACTIVE) && |
| 85 (shell_integration::GetDefaultBrowser() == | 25 (shell_integration::GetDefaultBrowser() == |
| 86 shell_integration::NOT_DEFAULT); | 26 shell_integration::NOT_DEFAULT); |
| 87 | 27 |
| 88 if (show_status) { | 28 if (show_status) { |
| 89 startup_metric_utils::SetNonBrowserUIDisplayed(); | 29 startup_metric_utils::SetNonBrowserUIDisplayed(); |
| 90 SetMetroBrowserFlowLauncher::LaunchSoon(profile); | 30 SetAsDefaultBrowserUI::Show(profile); |
| 91 } | 31 } |
| 92 | 32 |
| 93 return show_status; | 33 return show_status; |
| 94 } | 34 } |
| 95 | 35 |
| 96 } // namespace chrome | 36 } // namespace chrome |
| OLD | NEW |