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/metroizer_ui_win.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 CheckDefaultAndShowMetroizerCallback(Profile* profile, | |
|
sky
2012/06/20 22:34:45
nit: keep SetMetroBrowserFlowLauncher definition a
motek.
2012/06/21 18:28:10
Right. We don't really need this check anymore. It
| |
| 52 Browser* browser, | |
| 53 bool dialog) { | |
| 54 if (!ShellIntegration::IsDefaultBrowser() && | |
| 55 (ShellIntegration::CanSetAsDefaultBrowser() == | |
| 56 ShellIntegration::SET_DEFAULT_INTERACTIVE)) { | |
| 57 MetroizerUI::Show(profile, browser, dialog); | |
|
sky
2012/06/20 22:34:45
MetroizerUI is an awful name. How about something
motek.
2012/06/21 18:28:10
Oh, bother. This was my favourite part. Gone now.
| |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void SetMetroBrowserFlowLauncher::Observe( | |
| 62 int type, | |
| 63 const content::NotificationSource& source, | |
| 64 const content::NotificationDetails& details) { | |
| 65 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); | |
| 66 Browser* browser = browser::FindBrowserWithWebContents( | |
| 67 content::Source<content::WebContents>(source).ptr()); | |
| 68 | |
| 69 if (!browser || !browser->is_type_tabbed()) | |
| 70 return; | |
| 71 | |
| 72 // Unregister and delete. | |
| 73 registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 74 content::NotificationService::AllSources()); | |
| 75 | |
| 76 bool as_dialog = | |
| 77 profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog); | |
| 78 BrowserThread::PostTask( | |
|
sky
2012/06/20 22:34:45
Why is this delayed? Its entirely possible the bro
motek.
2012/06/21 18:28:10
I think that these 'is default' checks should be u
| |
| 79 BrowserThread::FILE, FROM_HERE, | |
| 80 base::Bind(&CheckDefaultAndShowMetroizerCallback, | |
| 81 profile_, browser, as_dialog)); | |
| 82 delete this; | |
| 83 } | |
| 84 | |
| 85 } // namespace | |
| 86 | |
| 87 namespace browser { | |
| 88 | |
| 89 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | |
| 90 if (ShellIntegration::CanSetAsDefaultBrowser() == | |
| 91 ShellIntegration::SET_DEFAULT_INTERACTIVE) { | |
| 92 // If the only available mode of setting the default browser requires | |
| 93 // user interaction, it means this couldn't have been done yet. Perform | |
| 94 // this action as a delayed task (including the check). | |
| 95 SetMetroBrowserFlowLauncher::LaunchSoon(profile); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 } // namespace browser | |
| OLD | NEW |