Chromium Code Reviews| 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_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
|
sky
2012/06/22 19:19:32
registrar_.RemoveAll(). Although since you're abou
motek.
2012/06/22 20:40:18
I am not sure. I got this from first run bubble, t
| |
| 64 content::NotificationService::AllSources()); | |
| 65 | |
| 66 bool as_dialog = | |
| 67 profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog); | |
| 68 | |
| 69 SetAsDefaultBrowserUI::Show(profile_, browser, as_dialog); | |
| 70 delete this; | |
| 71 } | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 namespace browser { | |
| 76 | |
| 77 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | |
| 78 if ((ShellIntegration::IsDefaultBrowser() == | |
| 79 ShellIntegration::NOT_DEFAULT_WEB_CLIENT) && | |
| 80 (ShellIntegration::CanSetAsDefaultBrowser() == | |
| 81 ShellIntegration::SET_DEFAULT_INTERACTIVE)) { | |
| 82 // If the only available mode of setting the default browser requires | |
| 83 // user interaction, it means this couldn't have been done yet. Perform | |
| 84 // this action as a delayed task (including the check). | |
|
sky
2012/06/22 19:19:32
The second sentence here is confusing. In particul
motek.
2012/06/22 20:40:18
Done.
| |
| 85 SetMetroBrowserFlowLauncher::LaunchSoon(profile); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace browser | |
| OLD | NEW |