| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 #include "chrome/browser/chromeos/sms_observer.h" | 109 #include "chrome/browser/chromeos/sms_observer.h" |
| 109 #if defined(TOOLKIT_USES_GTK) | 110 #if defined(TOOLKIT_USES_GTK) |
| 110 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h" | 111 #include "chrome/browser/chromeos/legacy_window_manager/wm_message_listener.h" |
| 111 #endif | 112 #endif |
| 112 #endif | 113 #endif |
| 113 | 114 |
| 114 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) | 115 #if defined(TOOLKIT_VIEWS) && defined(OS_LINUX) |
| 115 #include "ui/base/touch/touch_factory.h" | 116 #include "ui/base/touch/touch_factory.h" |
| 116 #endif | 117 #endif |
| 117 | 118 |
| 119 #if defined(OS_WIN) |
| 120 #include "chrome/installer/util/auto_launch_util.h" |
| 121 #endif |
| 122 |
| 118 using content::BrowserThread; | 123 using content::BrowserThread; |
| 119 | 124 |
| 120 namespace { | 125 namespace { |
| 121 | 126 |
| 127 static const int kMaxInfobarShown = 5; |
| 128 |
| 129 #if defined(OS_WIN) |
| 130 // The delegate for the infobar shown when Chrome was auto-launched. |
| 131 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 132 public: |
| 133 AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
| 134 PrefService* prefs); |
| 135 virtual ~AutolaunchInfoBarDelegate(); |
| 136 |
| 137 private: |
| 138 void AllowExpiry() { should_expire_ = true; } |
| 139 |
| 140 // ConfirmInfoBarDelegate: |
| 141 virtual bool ShouldExpire( |
| 142 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 143 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 144 virtual string16 GetMessageText() const OVERRIDE; |
| 145 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 146 virtual bool Accept() OVERRIDE; |
| 147 virtual bool Cancel() OVERRIDE; |
| 148 |
| 149 // The prefs to use. |
| 150 PrefService* prefs_; |
| 151 |
| 152 // Whether the user clicked one of the buttons. |
| 153 bool action_taken_; |
| 154 |
| 155 // Whether the info-bar should be dismissed on the next navigation. |
| 156 bool should_expire_; |
| 157 |
| 158 // Used to delay the expiration of the info-bar. |
| 159 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; |
| 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); |
| 162 }; |
| 163 |
| 164 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( |
| 165 InfoBarTabHelper* infobar_helper, |
| 166 PrefService* prefs) |
| 167 : ConfirmInfoBarDelegate(infobar_helper), |
| 168 prefs_(prefs), |
| 169 action_taken_(false), |
| 170 should_expire_(false), |
| 171 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 172 auto_launch_trial::UpdateInfobarShownMetric(); |
| 173 |
| 174 int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar); |
| 175 prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1); |
| 176 |
| 177 // We want the info-bar to stick-around for a few seconds and then be hidden |
| 178 // on the next navigation after that. |
| 179 MessageLoop::current()->PostDelayedTask( |
| 180 FROM_HERE, |
| 181 base::Bind(&AutolaunchInfoBarDelegate::AllowExpiry, |
| 182 weak_factory_.GetWeakPtr()), |
| 183 8000); // 8 seconds. |
| 184 } |
| 185 |
| 186 AutolaunchInfoBarDelegate::~AutolaunchInfoBarDelegate() { |
| 187 if (!action_taken_) { |
| 188 auto_launch_trial::UpdateInfobarResponseMetric( |
| 189 auto_launch_trial::INFOBAR_IGNORE); |
| 190 } |
| 191 } |
| 192 |
| 193 bool AutolaunchInfoBarDelegate::ShouldExpire( |
| 194 const content::LoadCommittedDetails& details) const { |
| 195 return details.is_navigation_to_different_page() && should_expire_; |
| 196 } |
| 197 |
| 198 gfx::Image* AutolaunchInfoBarDelegate::GetIcon() const { |
| 199 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 200 IDR_PRODUCT_LOGO_32); |
| 201 } |
| 202 |
| 203 string16 AutolaunchInfoBarDelegate::GetMessageText() const { |
| 204 return l10n_util::GetStringFUTF16(IDS_AUTO_LAUNCH_INFOBAR_TEXT, |
| 205 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 206 } |
| 207 |
| 208 string16 AutolaunchInfoBarDelegate::GetButtonLabel( |
| 209 InfoBarButton button) const { |
| 210 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 211 IDS_AUTO_LAUNCH_OK : IDS_AUTO_LAUNCH_REVERT); |
| 212 } |
| 213 |
| 214 bool AutolaunchInfoBarDelegate::Accept() { |
| 215 action_taken_ = true; |
| 216 auto_launch_trial::UpdateInfobarResponseMetric( |
| 217 auto_launch_trial::INFOBAR_OK); |
| 218 return true; |
| 219 } |
| 220 |
| 221 bool AutolaunchInfoBarDelegate::Cancel() { |
| 222 action_taken_ = true; |
| 223 |
| 224 // Track infobar reponse. |
| 225 auto_launch_trial::UpdateInfobarResponseMetric( |
| 226 auto_launch_trial::INFOBAR_CUT_IT_OUT); |
| 227 // Also make sure we keep track of how many disable and how many enable. |
| 228 const bool auto_launch = false; |
| 229 auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); |
| 230 |
| 231 content::BrowserThread::PostTask( |
| 232 content::BrowserThread::FILE, FROM_HERE, |
| 233 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, |
| 234 auto_launch, FilePath())); |
| 235 return true; |
| 236 } |
| 237 |
| 238 #endif // OS_WIN |
| 239 |
| 122 // DefaultBrowserInfoBarDelegate ---------------------------------------------- | 240 // DefaultBrowserInfoBarDelegate ---------------------------------------------- |
| 123 | 241 |
| 124 // The delegate for the infobar shown when Chrome is not the default browser. | 242 // The delegate for the infobar shown when Chrome is not the default browser. |
| 125 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 243 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 126 public: | 244 public: |
| 127 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 245 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
| 128 PrefService* prefs); | 246 PrefService* prefs); |
| 129 | 247 |
| 130 private: | 248 private: |
| 131 virtual ~DefaultBrowserInfoBarDelegate(); | 249 virtual ~DefaultBrowserInfoBarDelegate(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 333 } |
| 216 | 334 |
| 217 bool DefaultBrowserInfoBarDelegate::Cancel() { | 335 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 218 action_taken_ = true; | 336 action_taken_ = true; |
| 219 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 337 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 220 // User clicked "Don't ask me again", remember that. | 338 // User clicked "Don't ask me again", remember that. |
| 221 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 339 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 222 return true; | 340 return true; |
| 223 } | 341 } |
| 224 | 342 |
| 343 #if defined(OS_WIN) |
| 344 void CheckAutoLaunchCallback() { |
| 345 if (!auto_launch_trial::IsInAutoLaunchGroup()) |
| 346 return; |
| 347 |
| 348 Browser* browser = BrowserList::GetLastActive(); |
| 349 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); |
| 350 |
| 351 int infobar_shown = |
| 352 tab->profile()->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar); |
| 353 if (infobar_shown >= kMaxInfobarShown) |
| 354 return; |
| 355 |
| 356 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 357 infobar_helper->AddInfoBar( |
| 358 new AutolaunchInfoBarDelegate(infobar_helper, |
| 359 tab->profile()->GetPrefs())); |
| 360 } |
| 361 #endif |
| 362 |
| 225 void NotifyNotDefaultBrowserCallback() { | 363 void NotifyNotDefaultBrowserCallback() { |
| 226 Browser* browser = BrowserList::GetLastActive(); | 364 Browser* browser = BrowserList::GetLastActive(); |
| 227 if (!browser) | 365 if (!browser) |
| 228 return; // Reached during ui tests. | 366 return; // Reached during ui tests. |
| 229 | 367 |
| 230 // In ChromeBot tests, there might be a race. This line appears to get | 368 // In ChromeBot tests, there might be a race. This line appears to get |
| 231 // called during shutdown and |tab| can be NULL. | 369 // called during shutdown and |tab| can be NULL. |
| 232 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); | 370 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); |
| 233 if (!tab) | 371 if (!tab) |
| 234 return; | 372 return; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 645 |
| 508 void BrowserInit::AddFirstRunTab(const GURL& url) { | 646 void BrowserInit::AddFirstRunTab(const GURL& url) { |
| 509 first_run_tabs_.push_back(url); | 647 first_run_tabs_.push_back(url); |
| 510 } | 648 } |
| 511 | 649 |
| 512 // static | 650 // static |
| 513 bool BrowserInit::InProcessStartup() { | 651 bool BrowserInit::InProcessStartup() { |
| 514 return in_startup; | 652 return in_startup; |
| 515 } | 653 } |
| 516 | 654 |
| 655 // static |
| 656 void BrowserInit::RegisterUserPrefs(PrefService* prefs) { |
| 657 prefs->RegisterIntegerPref( |
| 658 prefs::kShownAutoLaunchInfobar, 0, PrefService::UNSYNCABLE_PREF); |
| 659 } |
| 660 |
| 517 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, | 661 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, |
| 518 Profile* profile, | 662 Profile* profile, |
| 519 const FilePath& cur_dir, | 663 const FilePath& cur_dir, |
| 520 IsProcessStartup process_startup, | 664 IsProcessStartup process_startup, |
| 521 IsFirstRun is_first_run, | 665 IsFirstRun is_first_run, |
| 522 int* return_code) { | 666 int* return_code) { |
| 523 in_startup = process_startup == IS_PROCESS_STARTUP; | 667 in_startup = process_startup == IS_PROCESS_STARTUP; |
| 524 DCHECK(profile); | 668 DCHECK(profile); |
| 525 | 669 |
| 526 // Continue with the incognito profile from here on if Incognito mode | 670 // Continue with the incognito profile from here on if Incognito mode |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 LM_TO_BE_DECIDED : LM_WITH_URLS); | 827 LM_TO_BE_DECIDED : LM_WITH_URLS); |
| 684 ProcessLaunchURLs(process_startup, urls_to_open); | 828 ProcessLaunchURLs(process_startup, urls_to_open); |
| 685 | 829 |
| 686 // If this is an app launch, but we didn't open an app window, it may | 830 // If this is an app launch, but we didn't open an app window, it may |
| 687 // be an app tab. | 831 // be an app tab. |
| 688 OpenApplicationTab(profile); | 832 OpenApplicationTab(profile); |
| 689 | 833 |
| 690 if (process_startup) { | 834 if (process_startup) { |
| 691 if (browser_defaults::kOSSupportsOtherBrowsers && | 835 if (browser_defaults::kOSSupportsOtherBrowsers && |
| 692 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { | 836 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { |
| 837 CheckIfAutoLaunched(profile); |
| 838 |
| 693 // Check whether we are the default browser. | 839 // Check whether we are the default browser. |
| 694 CheckDefaultBrowser(profile); | 840 CheckDefaultBrowser(profile); |
| 695 } | 841 } |
| 696 #if defined(OS_MACOSX) | 842 #if defined(OS_MACOSX) |
| 697 // Check whether the auto-update system needs to be promoted from user | 843 // Check whether the auto-update system needs to be promoted from user |
| 698 // to system. | 844 // to system. |
| 699 KeystoneInfoBar::PromotionInfoBar(profile); | 845 KeystoneInfoBar::PromotionInfoBar(profile); |
| 700 #endif | 846 #endif |
| 701 } | 847 } |
| 702 } | 848 } |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 } else { | 1439 } else { |
| 1294 // TODO(pastarmovj): We can't really do anything meaningful here yet but | 1440 // TODO(pastarmovj): We can't really do anything meaningful here yet but |
| 1295 // just prevent showing the infobar. | 1441 // just prevent showing the infobar. |
| 1296 } | 1442 } |
| 1297 return; | 1443 return; |
| 1298 } | 1444 } |
| 1299 BrowserThread::PostTask( | 1445 BrowserThread::PostTask( |
| 1300 BrowserThread::FILE, FROM_HERE, base::Bind(&CheckDefaultBrowserCallback)); | 1446 BrowserThread::FILE, FROM_HERE, base::Bind(&CheckDefaultBrowserCallback)); |
| 1301 } | 1447 } |
| 1302 | 1448 |
| 1449 void BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) { |
| 1450 #if defined(OS_WIN) |
| 1451 if (!auto_launch_trial::IsInAutoLaunchGroup()) |
| 1452 return; |
| 1453 |
| 1454 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1455 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup)) { |
| 1456 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1457 base::Bind(&CheckAutoLaunchCallback)); |
| 1458 } |
| 1459 #endif |
| 1460 } |
| 1461 |
| 1303 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( | 1462 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( |
| 1304 const CommandLine& command_line, | 1463 const CommandLine& command_line, |
| 1305 const FilePath& cur_dir, | 1464 const FilePath& cur_dir, |
| 1306 Profile* profile) { | 1465 Profile* profile) { |
| 1307 std::vector<GURL> urls; | 1466 std::vector<GURL> urls; |
| 1308 const CommandLine::StringVector& params = command_line.GetArgs(); | 1467 const CommandLine::StringVector& params = command_line.GetArgs(); |
| 1309 | 1468 |
| 1310 for (size_t i = 0; i < params.size(); ++i) { | 1469 for (size_t i = 0; i < params.size(); ++i) { |
| 1311 FilePath param = FilePath(params[i]); | 1470 FilePath param = FilePath(params[i]); |
| 1312 // Handle Vista way of searching - "? <search-term>" | 1471 // Handle Vista way of searching - "? <search-term>" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 | 1697 |
| 1539 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1698 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 1540 if (!profile) { | 1699 if (!profile) { |
| 1541 // We should only be able to get here if the profile already exists and | 1700 // We should only be able to get here if the profile already exists and |
| 1542 // has been created. | 1701 // has been created. |
| 1543 NOTREACHED(); | 1702 NOTREACHED(); |
| 1544 return; | 1703 return; |
| 1545 } | 1704 } |
| 1546 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); | 1705 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); |
| 1547 } | 1706 } |
| OLD | NEW |