| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 6 |
| 7 #include "chrome/browser/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 "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_types.h" |
| 17 |
| 18 using content::BrowserThread; |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Show the page prompting the user to make Chrome the default browser on |
| 23 // Windows 8 (which means becoming "the browser" in Metro mode). The page |
| 24 // will be shown at the first appropriate opportunity. It can be placed in |
| 25 // a tab or in a dialog, depending on other settings. |
| 26 class SetMetroBrowserFlowLauncher : public content::NotificationObserver { |
| 27 public: |
| 28 static void LaunchSoon(Profile* profile) { |
| 29 // The instance will manage its own lifetime. |
| 30 new SetMetroBrowserFlowLauncher(profile); |
| 31 } |
| 32 |
| 33 private: |
| 34 explicit SetMetroBrowserFlowLauncher(Profile* profile) |
| 35 : profile_(profile) { |
| 36 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 37 content::NotificationService::AllSources()); |
| 38 } |
| 39 |
| 40 // content::NotificationObserver override: |
| 41 virtual void Observe(int type, |
| 42 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) OVERRIDE; |
| 44 |
| 45 content::NotificationRegistrar registrar_; |
| 46 Profile* profile_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); |
| 49 }; |
| 50 |
| 51 void SetMetroBrowserFlowLauncher::Observe( |
| 52 int type, |
| 53 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) { |
| 55 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); |
| 56 Browser* browser = browser::FindBrowserWithWebContents( |
| 57 content::Source<content::WebContents>(source).ptr()); |
| 58 |
| 59 if (!browser || !browser->is_type_tabbed()) |
| 60 return; |
| 61 |
| 62 // Unregister and delete. |
| 63 registrar_.RemoveAll(); |
| 64 bool as_dialog = |
| 65 profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog); |
| 66 |
| 67 SetAsDefaultBrowserUI::Show(profile_, browser, as_dialog); |
| 68 delete this; |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
| 73 namespace browser { |
| 74 |
| 75 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 76 if ((ShellIntegration::IsDefaultBrowser() == |
| 77 ShellIntegration::NOT_DEFAULT_WEB_CLIENT) && |
| 78 (ShellIntegration::CanSetAsDefaultBrowser() == |
| 79 ShellIntegration::SET_DEFAULT_INTERACTIVE)) { |
| 80 // If the only available mode of setting the default browser requires |
| 81 // user interaction, it means this couldn't have been done yet. |
| 82 SetMetroBrowserFlowLauncher::LaunchSoon(profile); |
| 83 } |
| 84 } |
| 85 |
| 86 } // namespace browser |
| OLD | NEW |