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 "base/memory/weak_ptr.h" | |
|
grt (UTC plus 2)
2012/06/20 19:42:12
remove this
motek.
2012/06/20 22:02:29
Done.
| |
| 8 #include "chrome/browser/prefs/pref_service.h" | |
|
grt (UTC plus 2)
2012/06/20 19:42:12
and this
motek.
2012/06/20 22:02:29
Can't do. This is used (profile_->GetPrefs())
| |
| 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/metroizer_ui_win.h" | |
| 14 #include "chrome/common/pref_names.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" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 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); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 explicit SetMetroBrowserFlowLauncher(Profile* profile) | |
| 36 : profile_(profile) { | |
| 37 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 38 content::NotificationService::AllSources()); | |
| 39 } | |
| 40 | |
| 41 // content::NotificationObserver override: | |
| 42 virtual void Observe(int type, | |
| 43 const content::NotificationSource& source, | |
| 44 const content::NotificationDetails& details) OVERRIDE; | |
| 45 | |
| 46 content::NotificationRegistrar registrar_; | |
| 47 Profile* profile_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); | |
| 50 }; | |
| 51 | |
| 52 static void CheckDefaultAndShowMetroizerCallback(Profile* profile, | |
|
grt (UTC plus 2)
2012/06/20 19:42:12
no static within unnamed namespace
motek.
2012/06/20 22:02:29
Done.
| |
| 53 Browser* browser, | |
| 54 bool dialog) { | |
| 55 if (!ShellIntegration::IsDefaultBrowser() || | |
|
grt (UTC plus 2)
2012/06/20 19:42:12
|| -> &&
motek.
2012/06/20 22:02:29
Done.
| |
| 56 (ShellIntegration::CanSetAsDefaultBrowser() == | |
| 57 ShellIntegration::SET_DEFAULT_INTERACTIVE)) { | |
| 58 MetroizerUI::Show(profile, browser, dialog); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void SetMetroBrowserFlowLauncher::Observe( | |
| 63 int type, | |
| 64 const content::NotificationSource& source, | |
| 65 const content::NotificationDetails& details) { | |
| 66 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); | |
| 67 Browser* browser = browser::FindBrowserWithWebContents( | |
| 68 content::Source<content::WebContents>(source).ptr()); | |
| 69 | |
| 70 if (!browser || !browser->is_type_tabbed()) | |
| 71 return; | |
| 72 | |
| 73 // Unregister and delete. | |
| 74 registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 75 content::NotificationService::AllSources()); | |
| 76 | |
| 77 bool as_dialog = | |
| 78 profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog); | |
| 79 BrowserThread::PostTask( | |
| 80 BrowserThread::FILE, FROM_HERE, | |
| 81 base::Bind(&CheckDefaultAndShowMetroizerCallback, | |
| 82 profile_, browser, as_dialog)); | |
| 83 delete this; | |
| 84 } | |
| 85 | |
| 86 } // namespace | |
| 87 | |
| 88 namespace browser { | |
| 89 | |
| 90 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | |
| 91 if (ShellIntegration::SET_DEFAULT_INTERACTIVE == | |
|
grt (UTC plus 2)
2012/06/20 19:42:12
nit: chromium would prefer that you write CanSetAs
motek.
2012/06/20 22:02:29
Done.
| |
| 92 ShellIntegration::CanSetAsDefaultBrowser()) { | |
| 93 // If the only available mode of setting the default browser requires | |
| 94 // user interaction, it means this couldn't have been done yet. Perform | |
| 95 // this action as a delayed task (including the check). | |
| 96 SetMetroBrowserFlowLauncher::LaunchSoon(profile); | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 } // namespace browser | |
| OLD | NEW |