OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser_init.h" | 5 #include "chrome/browser/browser_init.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/event_recorder.h" | 9 #include "base/event_recorder.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "base/win_util.h" | 31 #include "base/win_util.h" |
32 #include "chrome/app/locales/locale_settings.h" | 32 #include "chrome/app/locales/locale_settings.h" |
33 #include "chrome/app/theme/theme_resources.h" | 33 #include "chrome/app/theme/theme_resources.h" |
34 #include "chrome/browser/automation/automation_provider.h" | 34 #include "chrome/browser/automation/automation_provider.h" |
35 #include "chrome/browser/automation/automation_provider_list.h" | 35 #include "chrome/browser/automation/automation_provider_list.h" |
36 #include "chrome/browser/net/url_fixer_upper.h" | 36 #include "chrome/browser/net/url_fixer_upper.h" |
37 #include "chrome/browser/search_engines/template_url_model.h" | 37 #include "chrome/browser/search_engines/template_url_model.h" |
38 #include "chrome/browser/sessions/session_restore.h" | 38 #include "chrome/browser/sessions/session_restore.h" |
39 #include "chrome/browser/tab_contents/infobar_delegate.h" | 39 #include "chrome/browser/tab_contents/infobar_delegate.h" |
40 #include "chrome/browser/tab_contents/navigation_controller.h" | 40 #include "chrome/browser/tab_contents/navigation_controller.h" |
41 #include "chrome/browser/web_app_launcher.h" | |
42 #include "chrome/common/resource_bundle.h" | 41 #include "chrome/common/resource_bundle.h" |
43 | 42 |
44 #include "chromium_strings.h" | 43 #include "chromium_strings.h" |
45 #include "generated_resources.h" | 44 #include "generated_resources.h" |
46 | 45 |
47 #endif | 46 #endif |
48 | 47 |
49 namespace { | 48 namespace { |
50 | 49 |
51 // A delegate for the InfoBar shown when the previous session has crashed. The | 50 // A delegate for the InfoBar shown when the previous session has crashed. The |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return true; | 95 return true; |
97 } | 96 } |
98 | 97 |
99 private: | 98 private: |
100 // The Profile that we restore sessions from. | 99 // The Profile that we restore sessions from. |
101 Profile* profile_; | 100 Profile* profile_; |
102 | 101 |
103 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); | 102 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); |
104 }; | 103 }; |
105 | 104 |
106 void SetOverrideHomePage(PrefService* prefs) { | 105 void SetOverrideHomePage(const CommandLine& command_line, |
107 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 106 PrefService* prefs) { |
108 // If homepage is specified on the command line, canonify & store it. | 107 // If homepage is specified on the command line, canonify & store it. |
109 if (command_line->HasSwitch(switches::kHomePage)) { | 108 if (command_line.HasSwitch(switches::kHomePage)) { |
110 std::wstring browser_directory; | 109 std::wstring browser_directory; |
111 PathService::Get(base::DIR_CURRENT, &browser_directory); | 110 PathService::Get(base::DIR_CURRENT, &browser_directory); |
112 std::wstring new_homepage = URLFixerUpper::FixupRelativeFile( | 111 std::wstring new_homepage = URLFixerUpper::FixupRelativeFile( |
113 browser_directory, | 112 browser_directory, |
114 command_line->GetSwitchValue(switches::kHomePage)); | 113 command_line.GetSwitchValue(switches::kHomePage)); |
115 prefs->transient()->SetString(prefs::kHomePage, new_homepage); | 114 prefs->transient()->SetString(prefs::kHomePage, new_homepage); |
116 prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false); | 115 prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
120 SessionStartupPref GetSessionStartupPref(Profile* profile) { | 119 SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, |
121 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 120 Profile* profile) { |
122 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); | 121 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); |
123 if (command_line->HasSwitch(switches::kRestoreLastSession)) | 122 if (command_line.HasSwitch(switches::kRestoreLastSession)) |
124 pref.type = SessionStartupPref::LAST; | 123 pref.type = SessionStartupPref::LAST; |
125 if (command_line->HasSwitch(switches::kIncognito) && | 124 if (command_line.HasSwitch(switches::kIncognito) && |
126 pref.type == SessionStartupPref::LAST) { | 125 pref.type == SessionStartupPref::LAST) { |
127 // We don't store session information when incognito. If the user has | 126 // We don't store session information when incognito. If the user has |
128 // chosen to restore last session and launched incognito, fallback to | 127 // chosen to restore last session and launched incognito, fallback to |
129 // default launch behavior. | 128 // default launch behavior. |
130 pref.type = SessionStartupPref::DEFAULT; | 129 pref.type = SessionStartupPref::DEFAULT; |
131 } | 130 } |
132 return pref; | 131 return pref; |
133 } | 132 } |
134 | 133 |
135 } // namespace | 134 } // namespace |
136 | 135 |
137 static bool in_startup = false; | 136 static bool in_startup = false; |
138 | 137 |
139 // static | 138 // static |
140 bool BrowserInit::InProcessStartup() { | 139 bool BrowserInit::InProcessStartup() { |
141 return in_startup; | 140 return in_startup; |
142 } | 141 } |
143 | 142 |
144 // LaunchWithProfile ---------------------------------------------------------- | 143 // LaunchWithProfile ---------------------------------------------------------- |
145 | 144 |
146 BrowserInit::LaunchWithProfile::LaunchWithProfile(const std::wstring& cur_dir) | 145 BrowserInit::LaunchWithProfile::LaunchWithProfile( |
147 : cur_dir_(cur_dir) { | 146 const std::wstring& cur_dir, |
| 147 const CommandLine& command_line) |
| 148 : cur_dir_(cur_dir), |
| 149 command_line_(command_line) { |
148 } | 150 } |
149 | 151 |
150 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, | 152 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, |
151 bool process_startup) { | 153 bool process_startup) { |
152 DCHECK(profile); | 154 DCHECK(profile); |
153 profile_ = profile; | 155 profile_ = profile; |
154 | 156 |
155 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 157 if (command_line_.HasSwitch(switches::kDnsLogDetails)) |
156 if (command_line->HasSwitch(switches::kDnsLogDetails)) | |
157 chrome_browser_net::EnableDnsDetailedLog(true); | 158 chrome_browser_net::EnableDnsDetailedLog(true); |
158 if (command_line->HasSwitch(switches::kDnsPrefetchDisable)) | 159 if (command_line_.HasSwitch(switches::kDnsPrefetchDisable)) |
159 chrome_browser_net::EnableDnsPrefetch(false); | 160 chrome_browser_net::EnableDnsPrefetch(false); |
160 | 161 |
161 if (command_line->HasSwitch(switches::kDumpHistogramsOnExit)) | 162 if (command_line_.HasSwitch(switches::kDumpHistogramsOnExit)) |
162 StatisticsRecorder::set_dump_on_exit(true); | 163 StatisticsRecorder::set_dump_on_exit(true); |
163 | 164 |
164 if (command_line->HasSwitch(switches::kRemoteShellPort)) { | 165 if (command_line_.HasSwitch(switches::kRemoteShellPort)) { |
165 if (!RenderProcessHost::run_renderer_in_process()) { | 166 if (!RenderProcessHost::run_renderer_in_process()) { |
166 std::wstring port_str = | 167 std::wstring port_str = |
167 command_line->GetSwitchValue(switches::kRemoteShellPort); | 168 command_line_.GetSwitchValue(switches::kRemoteShellPort); |
168 int64 port = StringToInt64(port_str); | 169 int64 port = StringToInt64(port_str); |
169 if (port > 0 && port < 65535) { | 170 if (port > 0 && port < 65535) { |
170 g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); | 171 g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); |
171 } else { | 172 } else { |
172 DLOG(WARNING) << "Invalid port number " << port; | 173 DLOG(WARNING) << "Invalid port number " << port; |
173 } | 174 } |
174 } | 175 } |
175 } | 176 } |
176 | 177 |
177 if (command_line->HasSwitch(switches::kEnableFileCookies)) | 178 if (command_line_.HasSwitch(switches::kEnableFileCookies)) |
178 net::CookieMonster::EnableFileScheme(); | 179 net::CookieMonster::EnableFileScheme(); |
179 | 180 |
180 if (command_line->HasSwitch(switches::kUserAgent)) { | 181 if (command_line_.HasSwitch(switches::kUserAgent)) { |
181 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
182 webkit_glue::SetUserAgent(WideToUTF8( | 183 webkit_glue::SetUserAgent(WideToUTF8( |
183 command_line->GetSwitchValue(switches::kUserAgent))); | 184 command_line_.GetSwitchValue(switches::kUserAgent))); |
184 // TODO(port): hook this up when we bring in webkit. | 185 // TODO(port): hook this up when we bring in webkit. |
185 #endif | 186 #endif |
186 } | 187 } |
187 | 188 |
188 #ifndef NDEBUG | 189 // Open the required browser windows and tabs. |
189 if (command_line->HasSwitch(switches::kApp)) | 190 // First, see if we're being run as a web application (thin frame window). |
190 NOTREACHED(); | 191 if (!OpenApplicationURL(profile)) { |
191 #endif // NDEBUG | 192 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); |
192 | 193 // Always attempt to restore the last session. OpenStartupURLs only opens |
193 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); | 194 // the home pages if no additional URLs were passed on the command line. |
194 | 195 if (!OpenStartupURLs(process_startup, urls_to_open)) { |
195 Browser* browser = NULL; | 196 // Add the home page and any special first run URLs. |
196 | 197 AddStartupURLs(&urls_to_open); |
197 // Always attempt to restore the last session. OpenStartupURLs only opens the | 198 OpenURLsInBrowser(BrowserList::GetLastActive(), process_startup, |
198 // home pages if no additional URLs were passed on the command line. | 199 urls_to_open); |
199 bool opened_startup_urls = OpenStartupURLs(process_startup, urls_to_open); | |
200 | |
201 if (!opened_startup_urls) { | |
202 if (urls_to_open.empty()) { | |
203 urls_to_open.push_back(GURL()); // New tab page. | |
204 PrefService* prefs = g_browser_process->local_state(); | |
205 if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) && | |
206 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { | |
207 // Reset the preference so we don't show the welcome page next time. | |
208 prefs->ClearPref(prefs::kShouldShowWelcomePage); | |
209 | |
210 #if defined(OS_WIN) | |
211 // Add the welcome page. | |
212 std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL); | |
213 urls_to_open.push_back(GURL(welcome_url)); | |
214 #else | |
215 // TODO(port): implement welcome page. | |
216 NOTIMPLEMENTED(); | |
217 #endif | |
218 } | |
219 } else { | |
220 browser = BrowserList::GetLastActive(); | |
221 } | 200 } |
222 | |
223 browser = OpenURLsInBrowser(browser, process_startup, urls_to_open); | |
224 } | 201 } |
225 | 202 |
226 // It is possible to end here with a NULL 'browser'. For example if the user | 203 // If we're recording or playing back, startup the EventRecorder now |
227 // has tweaked the startup session restore preferences. | 204 // unless otherwise specified. |
| 205 if (!command_line_.HasSwitch(switches::kNoEvents)) { |
| 206 std::wstring script_path; |
| 207 PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); |
228 | 208 |
229 if (browser) { | 209 bool record_mode = command_line_.HasSwitch(switches::kRecordMode); |
230 // If we're recording or playing back, startup the EventRecorder now | 210 bool playback_mode = command_line_.HasSwitch(switches::kPlaybackMode); |
231 // unless otherwise specified. | |
232 if (!command_line->HasSwitch(switches::kNoEvents)) { | |
233 std::wstring script_path; | |
234 PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); | |
235 | 211 |
236 bool record_mode = command_line->HasSwitch(switches::kRecordMode); | 212 if (record_mode && chrome::kRecordModeEnabled) |
237 bool playback_mode = command_line->HasSwitch(switches::kPlaybackMode); | 213 base::EventRecorder::current()->StartRecording(script_path); |
238 | 214 if (playback_mode) |
239 if (record_mode && chrome::kRecordModeEnabled) | 215 base::EventRecorder::current()->StartPlayback(script_path); |
240 base::EventRecorder::current()->StartRecording(script_path); | |
241 if (playback_mode) | |
242 base::EventRecorder::current()->StartPlayback(script_path); | |
243 } | |
244 } | 216 } |
245 | 217 |
246 return true; | 218 return true; |
247 } | 219 } |
248 | 220 |
| 221 bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { |
| 222 if (!command_line_.HasSwitch(switches::kApp)) |
| 223 return false; |
| 224 |
| 225 GURL url(WideToUTF8(command_line_.GetSwitchValue(switches::kApp))); |
| 226 if (!url.is_empty() && url.is_valid()) { |
| 227 Browser::OpenApplicationWindow(profile, url); |
| 228 return true; |
| 229 } |
| 230 return false; |
| 231 } |
| 232 |
249 bool BrowserInit::LaunchWithProfile::OpenStartupURLs( | 233 bool BrowserInit::LaunchWithProfile::OpenStartupURLs( |
250 bool is_process_startup, | 234 bool is_process_startup, |
251 const std::vector<GURL>& urls_to_open) { | 235 const std::vector<GURL>& urls_to_open) { |
252 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 236 SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); |
253 SessionStartupPref pref = GetSessionStartupPref(profile_); | |
254 switch (pref.type) { | 237 switch (pref.type) { |
255 case SessionStartupPref::LAST: | 238 case SessionStartupPref::LAST: |
256 if (!is_process_startup) | 239 if (!is_process_startup) |
257 return false; | 240 return false; |
258 | 241 |
259 if (!profile_->DidLastSessionExitCleanly() && | 242 if (!profile_->DidLastSessionExitCleanly() && |
260 !command_line->HasSwitch(switches::kRestoreLastSession)) { | 243 !command_line_.HasSwitch(switches::kRestoreLastSession)) { |
261 // The last session crashed. It's possible automatically loading the | 244 // The last session crashed. It's possible automatically loading the |
262 // page will trigger another crash, locking the user out of chrome. | 245 // page will trigger another crash, locking the user out of chrome. |
263 // To avoid this, don't restore on startup but instead show the crashed | 246 // To avoid this, don't restore on startup but instead show the crashed |
264 // infobar. | 247 // infobar. |
265 return false; | 248 return false; |
266 } | 249 } |
267 SessionRestore::RestoreSessionSynchronously(profile_, urls_to_open); | 250 SessionRestore::RestoreSessionSynchronously(profile_, urls_to_open); |
268 return true; | 251 return true; |
269 | 252 |
270 case SessionStartupPref::URLS: | 253 case SessionStartupPref::URLS: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // The last session didn't exit cleanly. Show an infobar to the user | 293 // The last session didn't exit cleanly. Show an infobar to the user |
311 // so that they can restore if they want. The delegate deletes itself when | 294 // so that they can restore if they want. The delegate deletes itself when |
312 // it is closed. | 295 // it is closed. |
313 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab)); | 296 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab)); |
314 } | 297 } |
315 } | 298 } |
316 | 299 |
317 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( | 300 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( |
318 Profile* profile) { | 301 Profile* profile) { |
319 std::vector<GURL> urls; | 302 std::vector<GURL> urls; |
320 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 303 std::vector<std::wstring> params = command_line_.GetLooseValues(); |
321 std::vector<std::wstring> params = command_line->GetLooseValues(); | |
322 for (size_t i = 0; i < params.size(); ++i) { | 304 for (size_t i = 0; i < params.size(); ++i) { |
323 std::wstring& value = params[i]; | 305 std::wstring& value = params[i]; |
324 // Handle Vista way of searching - "? <search-term>" | 306 // Handle Vista way of searching - "? <search-term>" |
325 if (value.find(L"? ") == 0) { | 307 if (value.find(L"? ") == 0) { |
326 const TemplateURL* default_provider = | 308 const TemplateURL* default_provider = |
327 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); | 309 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); |
328 if (!default_provider || !default_provider->url()) { | 310 if (!default_provider || !default_provider->url()) { |
329 // No search provider available. Just treat this as regular URL. | 311 // No search provider available. Just treat this as regular URL. |
330 urls.push_back( | 312 urls.push_back( |
331 GURL(WideToUTF8(URLFixerUpper::FixupRelativeFile(cur_dir_, | 313 GURL(WideToUTF8(URLFixerUpper::FixupRelativeFile(cur_dir_, |
332 value)))); | 314 value)))); |
333 continue; | 315 continue; |
334 } | 316 } |
335 const TemplateURLRef* search_url = default_provider->url(); | 317 const TemplateURLRef* search_url = default_provider->url(); |
336 DCHECK(search_url->SupportsReplacement()); | 318 DCHECK(search_url->SupportsReplacement()); |
337 urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider, | 319 urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider, |
338 value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, | 320 value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
339 std::wstring()))); | 321 std::wstring()))); |
340 } else { | 322 } else { |
341 // This will create a file URL or a regular URL. | 323 // This will create a file URL or a regular URL. |
342 urls.push_back(GURL(WideToUTF8( | 324 urls.push_back(GURL(WideToUTF8( |
343 URLFixerUpper::FixupRelativeFile(cur_dir_, value)))); | 325 URLFixerUpper::FixupRelativeFile(cur_dir_, value)))); |
344 } | 326 } |
345 } | 327 } |
346 return urls; | 328 return urls; |
347 } | 329 } |
348 | 330 |
| 331 void BrowserInit::LaunchWithProfile::AddStartupURLs( |
| 332 std::vector<GURL>* startup_urls) const { |
| 333 // Otherwise open at least the new tab page (and the welcome page, if this |
| 334 // is the first time the browser is being started), or the set of URLs |
| 335 // specified on the command line. |
| 336 if (startup_urls->empty()) { |
| 337 startup_urls->push_back(GURL()); // New tab page. |
| 338 PrefService* prefs = g_browser_process->local_state(); |
| 339 if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) && |
| 340 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { |
| 341 // Reset the preference so we don't show the welcome page next time. |
| 342 prefs->ClearPref(prefs::kShouldShowWelcomePage); |
| 343 |
| 344 #if defined(OS_WIN) |
| 345 // Add the welcome page. |
| 346 std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL); |
| 347 startup_urls->push_back(GURL(welcome_url)); |
| 348 #else |
| 349 // TODO(port): implement welcome page. |
| 350 NOTIMPLEMENTED(); |
| 351 #endif |
| 352 } |
| 353 } |
| 354 } |
| 355 |
349 bool BrowserInit::ProcessCommandLine( | 356 bool BrowserInit::ProcessCommandLine( |
350 const std::wstring& cur_dir, PrefService* prefs, bool process_startup, | 357 const CommandLine& command_line, const std::wstring& cur_dir, |
351 Profile* profile, int* return_code) { | 358 PrefService* prefs, bool process_startup, Profile* profile, |
| 359 int* return_code) { |
352 DCHECK(profile); | 360 DCHECK(profile); |
353 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
354 if (process_startup) { | 361 if (process_startup) { |
355 const std::wstring popup_count_string = | 362 const std::wstring popup_count_string = |
356 command_line->GetSwitchValue(switches::kOmniBoxPopupCount); | 363 command_line.GetSwitchValue(switches::kOmniBoxPopupCount); |
357 if (!popup_count_string.empty()) { | 364 if (!popup_count_string.empty()) { |
358 int count = 0; | 365 int count = 0; |
359 if (StringToInt(popup_count_string, &count)) { | 366 if (StringToInt(popup_count_string, &count)) { |
360 const int popup_count = std::max(0, count); | 367 const int popup_count = std::max(0, count); |
361 AutocompleteResult::set_max_matches(popup_count); | 368 AutocompleteResult::set_max_matches(popup_count); |
362 AutocompleteProvider::set_max_matches(popup_count / 2); | 369 AutocompleteProvider::set_max_matches(popup_count / 2); |
363 } | 370 } |
364 } | 371 } |
365 | 372 |
366 if (command_line->HasSwitch(switches::kDisablePromptOnRepost)) | 373 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
367 NavigationController::DisablePromptOnRepost(); | 374 NavigationController::DisablePromptOnRepost(); |
368 | 375 |
369 const std::wstring tab_count_string = | 376 const std::wstring tab_count_string = |
370 command_line->GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); | 377 command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); |
371 if (!tab_count_string.empty()) { | 378 if (!tab_count_string.empty()) { |
372 int count = 0; | 379 int count = 0; |
373 if (StringToInt(tab_count_string, &count)) { | 380 if (StringToInt(tab_count_string, &count)) { |
374 const int tab_count = std::max(0, count); | 381 const int tab_count = std::max(0, count); |
375 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); | 382 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); |
376 } | 383 } |
377 } | 384 } |
378 | 385 |
379 #if defined(OS_WIN) | 386 #if defined(OS_WIN) |
380 // Look for the testing channel ID ONLY during process startup | 387 // Look for the testing channel ID ONLY during process startup |
381 if (command_line->HasSwitch(switches::kTestingChannelID)) { | 388 if (command_line.HasSwitch(switches::kTestingChannelID)) { |
382 std::wstring testing_channel_id = | 389 std::wstring testing_channel_id = |
383 command_line->GetSwitchValue(switches::kTestingChannelID); | 390 command_line.GetSwitchValue(switches::kTestingChannelID); |
384 // TODO(sanjeevr) Check if we need to make this a singleton for | 391 // TODO(sanjeevr) Check if we need to make this a singleton for |
385 // compatibility with the old testing code | 392 // compatibility with the old testing code |
386 // If there are any loose parameters, we expect each one to generate a | 393 // If there are any loose parameters, we expect each one to generate a |
387 // new tab; if there are none then we get one homepage tab. | 394 // new tab; if there are none then we get one homepage tab. |
388 CreateAutomationProvider<TestingAutomationProvider>( | 395 CreateAutomationProvider<TestingAutomationProvider>( |
389 testing_channel_id, | 396 testing_channel_id, |
390 profile, | 397 profile, |
391 std::max(static_cast<int>(command_line->GetLooseValues().size()), | 398 std::max(static_cast<int>(command_line.GetLooseValues().size()), |
392 1)); | 399 1)); |
393 } | 400 } |
394 #endif | 401 #endif |
395 } | 402 } |
396 | 403 |
397 // Allow the command line to override the persisted setting of home page. | 404 // Allow the command line to override the persisted setting of home page. |
398 SetOverrideHomePage(profile->GetPrefs()); | 405 SetOverrideHomePage(command_line, profile->GetPrefs()); |
399 | 406 |
400 if (command_line->HasSwitch(switches::kBrowserStartRenderersManually)) | 407 if (command_line.HasSwitch(switches::kBrowserStartRenderersManually)) |
401 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true); | 408 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true); |
402 | 409 |
403 bool silent_launch = false; | 410 bool silent_launch = false; |
404 #if defined(OS_WIN) | 411 #if defined(OS_WIN) |
405 if (command_line->HasSwitch(switches::kAutomationClientChannelID)) { | 412 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
406 std::wstring automation_channel_id = | 413 std::wstring automation_channel_id = |
407 command_line->GetSwitchValue(switches::kAutomationClientChannelID); | 414 command_line.GetSwitchValue(switches::kAutomationClientChannelID); |
408 // If there are any loose parameters, we expect each one to generate a | 415 // If there are any loose parameters, we expect each one to generate a |
409 // new tab; if there are none then we have no tabs | 416 // new tab; if there are none then we have no tabs |
410 size_t expected_tabs = | 417 size_t expected_tabs = |
411 std::max(static_cast<int>(command_line->GetLooseValues().size()), | 418 std::max(static_cast<int>(command_line.GetLooseValues().size()), |
412 0); | 419 0); |
413 if (expected_tabs == 0) | 420 if (expected_tabs == 0) |
414 silent_launch = true; | 421 silent_launch = true; |
415 CreateAutomationProvider<AutomationProvider>(automation_channel_id, | 422 CreateAutomationProvider<AutomationProvider>(automation_channel_id, |
416 profile, expected_tabs); | 423 profile, expected_tabs); |
417 } | 424 } |
418 | 425 |
419 // Start up the extensions service http://crbug.com/7265 | 426 // Start up the extensions service http://crbug.com/7265 |
420 profile->InitExtensions(); | 427 profile->InitExtensions(); |
421 // TODO(port): figure out why this call crashes. | 428 // TODO(port): figure out why this call crashes. |
422 #endif | 429 #endif |
423 | 430 |
424 if (command_line->HasSwitch(switches::kInstallExtension)) { | 431 if (command_line.HasSwitch(switches::kInstallExtension)) { |
425 std::wstring path_string = | 432 std::wstring path_string = |
426 command_line->GetSwitchValue(switches::kInstallExtension); | 433 command_line.GetSwitchValue(switches::kInstallExtension); |
427 FilePath path = FilePath::FromWStringHack(path_string); | 434 FilePath path = FilePath::FromWStringHack(path_string); |
428 profile->GetExtensionsService()->InstallExtension(path); | 435 profile->GetExtensionsService()->InstallExtension(path); |
429 silent_launch = true; | 436 silent_launch = true; |
430 } | 437 } |
431 | 438 |
432 // If we don't want to launch a new browser window or tab (in the case | 439 // If we don't want to launch a new browser window or tab (in the case |
433 // of an automation request), we are done here. | 440 // of an automation request), we are done here. |
434 if (!silent_launch) | 441 if (!silent_launch) { |
435 return LaunchBrowser(profile, cur_dir, process_startup, return_code); | 442 return LaunchBrowser(command_line, profile, cur_dir, process_startup, |
| 443 return_code); |
| 444 } |
436 return true; | 445 return true; |
437 } | 446 } |
438 | 447 |
439 bool BrowserInit::LaunchBrowser(Profile* profile, const std::wstring& cur_dir, | 448 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, |
| 449 Profile* profile, const std::wstring& cur_dir, |
440 bool process_startup, int* return_code) { | 450 bool process_startup, int* return_code) { |
441 in_startup = process_startup; | 451 in_startup = process_startup; |
442 bool result = LaunchBrowserImpl(profile, cur_dir, process_startup, | 452 bool result = LaunchBrowserImpl(command_line, profile, cur_dir, |
443 return_code); | 453 process_startup, return_code); |
444 in_startup = false; | 454 in_startup = false; |
445 return result; | 455 return result; |
446 } | 456 } |
447 | 457 |
448 #if defined(OS_WIN) | 458 #if defined(OS_WIN) |
449 template <class AutomationProviderClass> | 459 template <class AutomationProviderClass> |
450 void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, | 460 void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, |
451 Profile* profile, | 461 Profile* profile, |
452 size_t expected_tabs) { | 462 size_t expected_tabs) { |
453 scoped_refptr<AutomationProviderClass> automation = | 463 scoped_refptr<AutomationProviderClass> automation = |
454 new AutomationProviderClass(profile); | 464 new AutomationProviderClass(profile); |
455 automation->ConnectToChannel(channel_id); | 465 automation->ConnectToChannel(channel_id); |
456 automation->SetExpectedTabCount(expected_tabs); | 466 automation->SetExpectedTabCount(expected_tabs); |
457 | 467 |
458 AutomationProviderList* list = | 468 AutomationProviderList* list = |
459 g_browser_process->InitAutomationProviderList(); DCHECK(list); | 469 g_browser_process->InitAutomationProviderList(); DCHECK(list); |
460 list->AddProvider(automation); | 470 list->AddProvider(automation); |
461 } | 471 } |
462 #endif | 472 #endif |
463 | 473 |
464 bool BrowserInit::LaunchBrowserImpl(Profile* profile, | 474 bool BrowserInit::LaunchBrowserImpl(const CommandLine& command_line, |
| 475 Profile* profile, |
465 const std::wstring& cur_dir, | 476 const std::wstring& cur_dir, |
466 bool process_startup, | 477 bool process_startup, |
467 int* return_code) { | 478 int* return_code) { |
468 DCHECK(profile); | 479 DCHECK(profile); |
469 | 480 |
470 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
471 | |
472 // Continue with the off-the-record profile from here on if --incognito | 481 // Continue with the off-the-record profile from here on if --incognito |
473 if (command_line->HasSwitch(switches::kIncognito)) | 482 if (command_line.HasSwitch(switches::kIncognito)) |
474 profile = profile->GetOffTheRecordProfile(); | 483 profile = profile->GetOffTheRecordProfile(); |
475 | 484 |
476 // Are we starting an application? | 485 LaunchWithProfile lwp(cur_dir, command_line); |
477 std::wstring app_url = command_line->GetSwitchValue(switches::kApp); | |
478 if (!app_url.empty()) { | |
479 GURL url(WideToUTF8(app_url)); | |
480 // If the application is started for a mailto:url, this machine has some | |
481 // old configuration that we should ignore. This hack saves us from some | |
482 // infinite loops where we keep forwarding mailto: to the system, resulting | |
483 // in the system asking us to open the mailto app. | |
484 if (url.SchemeIs("mailto")) | |
485 url = GURL("about:blank"); | |
486 | |
487 WebAppLauncher::Launch(profile, url); | |
488 return true; | |
489 } | |
490 | |
491 LaunchWithProfile lwp(cur_dir); | |
492 bool launched = lwp.Launch(profile, process_startup); | 486 bool launched = lwp.Launch(profile, process_startup); |
493 if (!launched) { | 487 if (!launched) { |
494 LOG(ERROR) << "launch error"; | 488 LOG(ERROR) << "launch error"; |
495 if (return_code != NULL) { | 489 if (return_code != NULL) |
496 *return_code = ResultCodes::INVALID_CMDLINE_URL; | 490 *return_code = ResultCodes::INVALID_CMDLINE_URL; |
497 } | |
498 return false; | 491 return false; |
499 } | 492 } |
500 | 493 |
501 return true; | 494 return true; |
502 } | 495 } |
OLD | NEW |