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