Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_init.h" | 5 #include "chrome/browser/ui/browser_init.h" |
| 6 | 6 |
| 7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/environment.h" | 12 #include "base/environment.h" |
| 13 #include "base/event_recorder.h" | 13 #include "base/event_recorder.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
| 20 #include "base/string_split.h" | 20 #include "base/string_split.h" |
| 21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "chrome/browser/auto_launch_trial.h" | |
| 23 #include "chrome/browser/automation/automation_provider.h" | 24 #include "chrome/browser/automation/automation_provider.h" |
| 24 #include "chrome/browser/automation/automation_provider_list.h" | 25 #include "chrome/browser/automation/automation_provider_list.h" |
| 25 #include "chrome/browser/automation/chrome_frame_automation_provider.h" | 26 #include "chrome/browser/automation/chrome_frame_automation_provider.h" |
| 26 #include "chrome/browser/automation/testing_automation_provider.h" | 27 #include "chrome/browser/automation/testing_automation_provider.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/component_updater/component_updater_service.h" | 29 #include "chrome/browser/component_updater/component_updater_service.h" |
| 29 #include "chrome/browser/component_updater/flash_component_installer.h" | 30 #include "chrome/browser/component_updater/flash_component_installer.h" |
| 30 #include "chrome/browser/component_updater/recovery_component_installer.h" | 31 #include "chrome/browser/component_updater/recovery_component_installer.h" |
| 31 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 32 #include "chrome/browser/defaults.h" | 33 #include "chrome/browser/defaults.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 #include "chrome/browser/chromeos/sms_observer.h" | 107 #include "chrome/browser/chromeos/sms_observer.h" |
| 107 #if defined(TOOLKIT_USES_GTK) | 108 #if defined(TOOLKIT_USES_GTK) |
| 108 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h" | 109 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h" |
| 109 #endif | 110 #endif |
| 110 #endif | 111 #endif |
| 111 | 112 |
| 112 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) | 113 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) |
| 113 #include "ui/base/touch/touch_factory.h" | 114 #include "ui/base/touch/touch_factory.h" |
| 114 #endif | 115 #endif |
| 115 | 116 |
| 117 #if defined(OS_WIN) | |
| 118 #include "chrome/installer/util/auto_launch_util.h" | |
| 119 #endif | |
| 120 | |
| 116 using content::BrowserThread; | 121 using content::BrowserThread; |
| 117 | 122 |
| 118 namespace { | 123 namespace { |
| 119 | 124 |
| 125 static const int kMaxInfobarShown = 5; | |
| 126 | |
| 127 #if defined(OS_WIN) | |
| 128 // The delegate for the infobar shown when Chrome was auto-launched. | |
| 129 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { | |
| 130 public: | |
| 131 explicit AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper, | |
|
grt (UTC plus 2)
2011/11/29 18:55:45
remove "explicit"
| |
| 132 PrefService* prefs); | |
| 133 | |
| 134 private: | |
| 135 virtual ~AutolaunchInfoBarDelegate(); | |
|
grt (UTC plus 2)
2011/11/29 18:55:45
why private dtor?
Finnur
2011/11/29 23:48:30
Hmm... I don't have a good reason besides the othe
| |
| 136 | |
| 137 void AllowExpiry() { should_expire_ = true; } | |
| 138 | |
| 139 // ConfirmInfoBarDelegate: | |
| 140 virtual bool ShouldExpire( | |
| 141 const content::LoadCommittedDetails& details) const OVERRIDE; | |
| 142 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 143 virtual string16 GetMessageText() const OVERRIDE; | |
| 144 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 145 virtual bool Accept() OVERRIDE; | |
| 146 virtual bool Cancel() OVERRIDE; | |
| 147 | |
| 148 // The prefs to use. | |
| 149 PrefService* prefs_; | |
| 150 | |
| 151 // Whether the user clicked one of the buttons. | |
| 152 bool action_taken_; | |
| 153 | |
| 154 // Whether the info-bar should be dismissed on the next navigation. | |
| 155 bool should_expire_; | |
| 156 | |
| 157 // Used to delay the expiration of the info-bar. | |
| 158 ScopedRunnableMethodFactory<AutolaunchInfoBarDelegate> method_factory_; | |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); | |
| 161 }; | |
| 162 | |
| 163 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( | |
| 164 InfoBarTabHelper* infobar_helper, | |
| 165 PrefService* prefs) | |
| 166 : ConfirmInfoBarDelegate(infobar_helper), | |
| 167 prefs_(prefs), | |
| 168 action_taken_(false), | |
| 169 should_expire_(false), | |
| 170 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | |
|
grt (UTC plus 2)
2011/11/29 18:55:45
indent?
| |
| 171 auto_launch_trial::UpdateInfobarShownMetric(); | |
| 172 | |
| 173 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar); | |
| 174 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1); | |
| 175 | |
| 176 // We want the info-bar to stick-around for a few seconds and then be hidden | |
| 177 // on the next navigation after that. | |
| 178 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 179 method_factory_.NewRunnableMethod( | |
| 180 &AutolaunchInfoBarDelegate::AllowExpiry), 8000); // 8 seconds. | |
| 181 } | |
| 182 | |
| 183 AutolaunchInfoBarDelegate::~AutolaunchInfoBarDelegate() { | |
| 184 if (!action_taken_) | |
| 185 auto_launch_trial::UpdateInfobarResponseMetric(2); | |
| 186 } | |
| 187 | |
| 188 bool AutolaunchInfoBarDelegate::ShouldExpire( | |
| 189 const content::LoadCommittedDetails& details) const { | |
| 190 return details.is_navigation_to_different_page() && should_expire_; | |
| 191 } | |
| 192 | |
| 193 gfx::Image* AutolaunchInfoBarDelegate::GetIcon() const { | |
| 194 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 195 IDR_PRODUCT_LOGO_32); | |
| 196 } | |
| 197 | |
| 198 string16 AutolaunchInfoBarDelegate::GetMessageText() const { | |
| 199 return l10n_util::GetStringFUTF16(IDS_AUTO_LAUNCH_INFOBAR_TEXT, | |
| 200 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 201 } | |
| 202 | |
| 203 string16 AutolaunchInfoBarDelegate::GetButtonLabel( | |
| 204 InfoBarButton button) const { | |
| 205 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 206 IDS_AUTO_LAUNCH_OK : IDS_AUTO_LAUNCH_REVERT); | |
| 207 } | |
| 208 | |
| 209 bool AutolaunchInfoBarDelegate::Accept() { | |
| 210 action_taken_ = true; | |
| 211 auto_launch_trial::UpdateInfobarResponseMetric(1); | |
| 212 return true; | |
| 213 } | |
| 214 | |
| 215 bool AutolaunchInfoBarDelegate::Cancel() { | |
| 216 action_taken_ = true; | |
| 217 | |
| 218 // Track infobar reponse. | |
| 219 auto_launch_trial::UpdateInfobarResponseMetric(0); | |
| 220 // Also make sure we keep track of how many disable and how many enable. | |
| 221 bool auto_launch = false; | |
| 222 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); | |
| 223 | |
| 224 FilePath chrome_exe; | |
| 225 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) | |
| 226 NOTREACHED(); | |
| 227 auto_launch_util::SetIsAutoLaunched(auto_launch, chrome_exe); | |
| 228 | |
| 229 return true; | |
| 230 } | |
| 231 #endif // OS_WIN | |
| 232 | |
| 120 // DefaultBrowserInfoBarDelegate ---------------------------------------------- | 233 // DefaultBrowserInfoBarDelegate ---------------------------------------------- |
| 121 | 234 |
| 122 // The delegate for the infobar shown when Chrome is not the default browser. | 235 // The delegate for the infobar shown when Chrome is not the default browser. |
| 123 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 236 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 124 public: | 237 public: |
| 125 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 238 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
| 126 PrefService* prefs); | 239 PrefService* prefs); |
| 127 | 240 |
| 128 private: | 241 private: |
| 129 virtual ~DefaultBrowserInfoBarDelegate(); | 242 virtual ~DefaultBrowserInfoBarDelegate(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 325 } |
| 213 | 326 |
| 214 bool DefaultBrowserInfoBarDelegate::Cancel() { | 327 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 215 action_taken_ = true; | 328 action_taken_ = true; |
| 216 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 329 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 217 // User clicked "Don't ask me again", remember that. | 330 // User clicked "Don't ask me again", remember that. |
| 218 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 331 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 219 return true; | 332 return true; |
| 220 } | 333 } |
| 221 | 334 |
| 335 // NotifyAutolaunchTask ------------------------------------------------ | |
| 336 | |
| 337 #if defined(OS_WIN) | |
| 338 class NotifyAutolaunchTask : public Task { | |
| 339 public: | |
| 340 NotifyAutolaunchTask(); | |
| 341 virtual ~NotifyAutolaunchTask(); | |
| 342 private: | |
| 343 virtual void Run(); | |
|
grt (UTC plus 2)
2011/11/29 18:55:45
OVERRIDE
| |
| 344 | |
| 345 DISALLOW_COPY_AND_ASSIGN(NotifyAutolaunchTask); | |
| 346 }; | |
| 347 | |
| 348 NotifyAutolaunchTask::NotifyAutolaunchTask() { | |
| 349 } | |
| 350 | |
| 351 NotifyAutolaunchTask::~NotifyAutolaunchTask() { | |
| 352 } | |
| 353 | |
| 354 void NotifyAutolaunchTask::Run() { | |
| 355 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
| 356 return; | |
| 357 | |
| 358 Browser* browser = BrowserList::GetLastActive(); | |
| 359 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); | |
| 360 | |
| 361 int infobar_shown = | |
| 362 tab->profile()->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); | |
| 363 if (infobar_shown >= kMaxInfobarShown) | |
| 364 return; | |
| 365 | |
| 366 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | |
| 367 infobar_helper->AddInfoBar( | |
| 368 new AutolaunchInfoBarDelegate(infobar_helper, | |
| 369 tab->profile()->GetPrefs())); | |
| 370 } | |
| 371 #endif // OS_WIN | |
| 222 | 372 |
| 223 // NotifyNotDefaultBrowserTask ------------------------------------------------ | 373 // NotifyNotDefaultBrowserTask ------------------------------------------------ |
| 224 | 374 |
| 225 class NotifyNotDefaultBrowserTask : public Task { | 375 class NotifyNotDefaultBrowserTask : public Task { |
| 226 public: | 376 public: |
| 227 NotifyNotDefaultBrowserTask(); | 377 NotifyNotDefaultBrowserTask(); |
| 228 virtual ~NotifyNotDefaultBrowserTask(); | 378 virtual ~NotifyNotDefaultBrowserTask(); |
| 229 | 379 |
| 230 private: | 380 private: |
| 231 virtual void Run(); | 381 virtual void Run(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 | 689 |
| 540 void BrowserInit::AddFirstRunTab(const GURL& url) { | 690 void BrowserInit::AddFirstRunTab(const GURL& url) { |
| 541 first_run_tabs_.push_back(url); | 691 first_run_tabs_.push_back(url); |
| 542 } | 692 } |
| 543 | 693 |
| 544 // static | 694 // static |
| 545 bool BrowserInit::InProcessStartup() { | 695 bool BrowserInit::InProcessStartup() { |
| 546 return in_startup; | 696 return in_startup; |
| 547 } | 697 } |
| 548 | 698 |
| 699 // static | |
| 700 void BrowserInit::RegisterUserPrefs(PrefService* prefs) { | |
| 701 prefs->RegisterIntegerPref( | |
| 702 prefs::kShownAutoLaunchInfobar, 0, PrefService::UNSYNCABLE_PREF); | |
| 703 } | |
| 704 | |
| 549 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, | 705 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, |
| 550 Profile* profile, | 706 Profile* profile, |
| 551 const FilePath& cur_dir, | 707 const FilePath& cur_dir, |
| 552 IsProcessStartup process_startup, | 708 IsProcessStartup process_startup, |
| 553 IsFirstRun is_first_run, | 709 IsFirstRun is_first_run, |
| 554 int* return_code) { | 710 int* return_code) { |
| 555 in_startup = process_startup == IS_PROCESS_STARTUP; | 711 in_startup = process_startup == IS_PROCESS_STARTUP; |
| 556 DCHECK(profile); | 712 DCHECK(profile); |
| 557 | 713 |
| 558 // Continue with the incognito profile from here on if Incognito mode | 714 // Continue with the incognito profile from here on if Incognito mode |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 // If this is an app launch, but we didn't open an app window, it may | 858 // If this is an app launch, but we didn't open an app window, it may |
| 703 // be an app tab. | 859 // be an app tab. |
| 704 OpenApplicationTab(profile); | 860 OpenApplicationTab(profile); |
| 705 | 861 |
| 706 if (process_startup) { | 862 if (process_startup) { |
| 707 if (browser_defaults::kOSSupportsOtherBrowsers && | 863 if (browser_defaults::kOSSupportsOtherBrowsers && |
| 708 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { | 864 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { |
| 709 // Check whether we are the default browser. | 865 // Check whether we are the default browser. |
| 710 CheckDefaultBrowser(profile); | 866 CheckDefaultBrowser(profile); |
| 711 } | 867 } |
| 868 CheckIfAutoLaunched(profile); | |
| 712 #if defined(OS_MACOSX) | 869 #if defined(OS_MACOSX) |
| 713 // Check whether the auto-update system needs to be promoted from user | 870 // Check whether the auto-update system needs to be promoted from user |
| 714 // to system. | 871 // to system. |
| 715 KeystoneInfoBar::PromotionInfoBar(profile); | 872 KeystoneInfoBar::PromotionInfoBar(profile); |
| 716 #endif | 873 #endif |
| 717 } | 874 } |
| 718 } | 875 } |
| 719 | 876 |
| 720 #if defined(OS_WIN) | 877 #if defined(OS_WIN) |
| 721 // Print the selected page if the command line switch exists. Note that the | 878 // Print the selected page if the command line switch exists. Note that the |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 } else { | 1466 } else { |
| 1310 // TODO(pastarmovj): We can't really do anything meaningful here yet but | 1467 // TODO(pastarmovj): We can't really do anything meaningful here yet but |
| 1311 // just prevent showing the infobar. | 1468 // just prevent showing the infobar. |
| 1312 } | 1469 } |
| 1313 return; | 1470 return; |
| 1314 } | 1471 } |
| 1315 BrowserThread::PostTask( | 1472 BrowserThread::PostTask( |
| 1316 BrowserThread::FILE, FROM_HERE, new CheckDefaultBrowserTask()); | 1473 BrowserThread::FILE, FROM_HERE, new CheckDefaultBrowserTask()); |
| 1317 } | 1474 } |
| 1318 | 1475 |
| 1476 void BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { | |
| 1477 #if defined(OS_WIN) | |
| 1478 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
| 1479 return; | |
| 1480 | |
| 1481 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 1482 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup)) { | |
| 1483 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 1484 new NotifyAutolaunchTask()); | |
| 1485 } | |
| 1486 #endif | |
| 1487 } | |
| 1488 | |
| 1319 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( | 1489 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( |
| 1320 const CommandLine& command_line, | 1490 const CommandLine& command_line, |
| 1321 const FilePath& cur_dir, | 1491 const FilePath& cur_dir, |
| 1322 Profile* profile) { | 1492 Profile* profile) { |
| 1323 std::vector<GURL> urls; | 1493 std::vector<GURL> urls; |
| 1324 const CommandLine::StringVector& params = command_line.GetArgs(); | 1494 const CommandLine::StringVector& params = command_line.GetArgs(); |
| 1325 | 1495 |
| 1326 for (size_t i = 0; i < params.size(); ++i) { | 1496 for (size_t i = 0; i < params.size(); ++i) { |
| 1327 FilePath param = FilePath(params[i]); | 1497 FilePath param = FilePath(params[i]); |
| 1328 // Handle Vista way of searching - "? <search-term>" | 1498 // Handle Vista way of searching - "? <search-term>" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 if (!automation->InitializeChannel(channel_id)) | 1691 if (!automation->InitializeChannel(channel_id)) |
| 1522 return false; | 1692 return false; |
| 1523 automation->SetExpectedTabCount(expected_tabs); | 1693 automation->SetExpectedTabCount(expected_tabs); |
| 1524 | 1694 |
| 1525 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 1695 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
| 1526 DCHECK(list); | 1696 DCHECK(list); |
| 1527 list->AddProvider(automation); | 1697 list->AddProvider(automation); |
| 1528 | 1698 |
| 1529 return true; | 1699 return true; |
| 1530 } | 1700 } |
| OLD | NEW |