Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 10692195: Consolidate Browser Creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; 237 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard";
238 238
239 // How long we wait before updating the browser chrome while loading a page. 239 // How long we wait before updating the browser chrome while loading a page.
240 const int kUIUpdateCoalescingTimeMS = 200; 240 const int kUIUpdateCoalescingTimeMS = 200;
241 241
242 bool AllowPanels(const std::string& app_name) { 242 bool AllowPanels(const std::string& app_name) {
243 return PanelManager::ShouldUsePanels( 243 return PanelManager::ShouldUsePanels(
244 web_app::GetExtensionIdFromApplicationName(app_name)); 244 web_app::GetExtensionIdFromApplicationName(app_name));
245 } 245 }
246 246
247 BrowserWindow* CreateBrowserWindow(Browser* browser) {
248 #if !defined(USE_ASH)
249 if (browser->is_type_panel())
250 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window();
251 #endif
252 return BrowserWindow::CreateBrowserWindow(browser);
253 }
254
247 } // namespace 255 } // namespace
248 256
249 //////////////////////////////////////////////////////////////////////////////// 257 ////////////////////////////////////////////////////////////////////////////////
250 // Browser, CreateParams: 258 // Browser, CreateParams:
251 259
252 Browser::CreateParams::CreateParams() 260 Browser::CreateParams::CreateParams()
253 : type(TYPE_TABBED), 261 : type(TYPE_TABBED),
254 profile(NULL), 262 profile(NULL),
263 app_type(APP_TYPE_HOST),
255 initial_show_state(ui::SHOW_STATE_DEFAULT), 264 initial_show_state(ui::SHOW_STATE_DEFAULT),
256 is_session_restore(false) { 265 is_session_restore(false),
266 window(NULL) {
267 }
268
269 Browser::CreateParams::CreateParams(Profile* profile)
270 : type(TYPE_TABBED),
271 profile(profile),
272 app_type(APP_TYPE_HOST),
273 initial_show_state(ui::SHOW_STATE_DEFAULT),
274 is_session_restore(false),
275 window(NULL) {
257 } 276 }
258 277
259 Browser::CreateParams::CreateParams(Type type, Profile* profile) 278 Browser::CreateParams::CreateParams(Type type, Profile* profile)
260 : type(type), 279 : type(type),
261 profile(profile), 280 profile(profile),
262 app_type(APP_TYPE_HOST), 281 app_type(APP_TYPE_HOST),
263 initial_show_state(ui::SHOW_STATE_DEFAULT), 282 initial_show_state(ui::SHOW_STATE_DEFAULT),
264 is_session_restore(false) { 283 is_session_restore(false),
284 window(NULL) {
265 } 285 }
266 286
267 // static 287 // static
268 Browser::CreateParams Browser::CreateParams::CreateForApp( 288 Browser::CreateParams Browser::CreateParams::CreateForApp(
269 Type type, 289 Type type,
270 const std::string& app_name, 290 const std::string& app_name,
271 const gfx::Rect& window_bounds, 291 const gfx::Rect& window_bounds,
272 Profile* profile) { 292 Profile* profile) {
273 DCHECK(type != TYPE_TABBED); 293 DCHECK(type != TYPE_TABBED);
274 DCHECK(!app_name.empty()); 294 DCHECK(!app_name.empty());
(...skipping 13 matching lines...) Expand all
288 Browser::CreateParams Browser::CreateParams::CreateForDevTools( 308 Browser::CreateParams Browser::CreateParams::CreateForDevTools(
289 Profile* profile) { 309 Profile* profile) {
290 CreateParams params(TYPE_POPUP, profile); 310 CreateParams params(TYPE_POPUP, profile);
291 params.app_name = DevToolsWindow::kDevToolsApp; 311 params.app_name = DevToolsWindow::kDevToolsApp;
292 return params; 312 return params;
293 } 313 }
294 314
295 /////////////////////////////////////////////////////////////////////////////// 315 ///////////////////////////////////////////////////////////////////////////////
296 // Browser, Constructors, Creation, Showing: 316 // Browser, Constructors, Creation, Showing:
297 317
298 Browser::Browser(Type type, Profile* profile) 318 Browser::Browser(const CreateParams& params)
299 : type_(type), 319 : type_(params.type),
300 profile_(profile), 320 profile_(params.profile),
301 window_(NULL), 321 window_(NULL),
302 ALLOW_THIS_IN_INITIALIZER_LIST( 322 ALLOW_THIS_IN_INITIALIZER_LIST(
303 tab_strip_model_delegate_( 323 tab_strip_model_delegate_(
304 new chrome::BrowserTabStripModelDelegate(this))), 324 new chrome::BrowserTabStripModelDelegate(this))),
305 ALLOW_THIS_IN_INITIALIZER_LIST( 325 ALLOW_THIS_IN_INITIALIZER_LIST(
306 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), 326 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
307 profile))), 327 params.profile))),
308 app_type_(APP_TYPE_HOST), 328 app_name_(params.app_name),
329 app_type_(params.app_type),
309 chrome_updater_factory_(this), 330 chrome_updater_factory_(this),
310 cancel_download_confirmation_state_(NOT_PROMPTED), 331 cancel_download_confirmation_state_(NOT_PROMPTED),
311 initial_show_state_(ui::SHOW_STATE_DEFAULT), 332 override_bounds_(params.initial_bounds),
312 is_session_restore_(false), 333 initial_show_state_(params.initial_show_state),
334 is_session_restore_(params.is_session_restore),
313 ALLOW_THIS_IN_INITIALIZER_LIST( 335 ALLOW_THIS_IN_INITIALIZER_LIST(
314 unload_controller_(new chrome::UnloadController(this))), 336 unload_controller_(new chrome::UnloadController(this))),
315 weak_factory_(this), 337 weak_factory_(this),
316 ALLOW_THIS_IN_INITIALIZER_LIST( 338 ALLOW_THIS_IN_INITIALIZER_LIST(
317 content_setting_bubble_model_delegate_( 339 content_setting_bubble_model_delegate_(
318 new BrowserContentSettingBubbleModelDelegate(this))), 340 new BrowserContentSettingBubbleModelDelegate(this))),
319 ALLOW_THIS_IN_INITIALIZER_LIST( 341 ALLOW_THIS_IN_INITIALIZER_LIST(
320 toolbar_model_delegate_( 342 toolbar_model_delegate_(
321 new BrowserToolbarModelDelegate(this))), 343 new BrowserToolbarModelDelegate(this))),
322 ALLOW_THIS_IN_INITIALIZER_LIST( 344 ALLOW_THIS_IN_INITIALIZER_LIST(
323 tab_restore_service_delegate_( 345 tab_restore_service_delegate_(
324 new BrowserTabRestoreServiceDelegate(this))), 346 new BrowserTabRestoreServiceDelegate(this))),
325 ALLOW_THIS_IN_INITIALIZER_LIST( 347 ALLOW_THIS_IN_INITIALIZER_LIST(
326 synced_window_delegate_( 348 synced_window_delegate_(
327 new BrowserSyncedWindowDelegate(this))), 349 new BrowserSyncedWindowDelegate(this))),
328 bookmark_bar_state_(BookmarkBar::HIDDEN), 350 bookmark_bar_state_(BookmarkBar::HIDDEN),
329 device_attached_intent_source_(this, this), 351 device_attached_intent_source_(this, this),
330 ALLOW_THIS_IN_INITIALIZER_LIST( 352 ALLOW_THIS_IN_INITIALIZER_LIST(
331 command_controller_(new chrome::BrowserCommandController(this))), 353 command_controller_(new chrome::BrowserCommandController(this))),
332 window_has_shown_(false) { 354 window_has_shown_(false) {
355 if (!app_name_.empty())
356 chrome::RegisterAppPrefs(app_name_, profile_);
333 tab_strip_model_->AddObserver(this); 357 tab_strip_model_->AddObserver(this);
334 358
335 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); 359 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get()));
336 search_model_.reset(new chrome::search::SearchModel(NULL)); 360 search_model_.reset(new chrome::search::SearchModel(NULL));
337 search_delegate_.reset( 361 search_delegate_.reset(
338 new chrome::search::SearchDelegate(search_model_.get())); 362 new chrome::search::SearchDelegate(search_model_.get()));
339 363
340 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, 364 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
341 content::NotificationService::AllSources()); 365 content::NotificationService::AllSources());
342 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 366 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
(...skipping 22 matching lines...) Expand all
365 389
366 // NOTE: These prefs all need to be explicitly destroyed in the destructor 390 // NOTE: These prefs all need to be explicitly destroyed in the destructor
367 // or you'll get a nasty surprise when you run the incognito tests. 391 // or you'll get a nasty surprise when you run the incognito tests.
368 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, 392 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
369 profile_->GetPrefs(), NULL); 393 profile_->GetPrefs(), NULL);
370 394
371 instant_controller_.reset(new chrome::BrowserInstantController(this)); 395 instant_controller_.reset(new chrome::BrowserInstantController(this));
372 396
373 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); 397 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
374 398
375 FilePath profile_path = profile->GetPath(); 399 FilePath profile_path = profile_->GetPath();
376 ProfileMetrics::LogProfileLaunch(profile_path); 400 ProfileMetrics::LogProfileLaunch(profile_path);
401
402 window_ = params.window ? params.window : CreateBrowserWindow(this);
403
404 // TODO(beng): move to BrowserFrameWin.
405 #if defined(OS_WIN) && !defined(USE_AURA)
406 // Set the app user model id for this application to that of the application
407 // name. See http://crbug.com/7028.
408 ui::win::SetAppIdForWindow(
409 is_app() && !is_type_panel() ?
410 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_),
411 profile_->GetPath()) :
412 ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()),
413 window()->GetNativeWindow());
414
415 if (is_type_panel()) {
416 ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(),
417 window()->GetNativeWindow());
418 }
419 #endif
420
421 // Create the extension window controller before sending notifications.
422 extension_window_controller_.reset(
423 new BrowserExtensionWindowController(this));
424
425 // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and
426 // replace uses of this with BL's notifications.
427 content::NotificationService::current()->Notify(
428 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
429 content::Source<Browser>(this),
430 content::NotificationService::NoDetails());
431
432 // TODO(beng): move to ChromeBrowserMain:
433 PrefService* local_state = g_browser_process->local_state();
434 if (local_state && local_state->FindPreference(
435 prefs::kAutofillPersonalDataManagerFirstRun) &&
436 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
437 // Notify PDM that this is a first run.
438 #if defined(OS_WIN)
439 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_));
440 #endif // defined(OS_WIN)
441 // Reset the preference so we don't call it again for subsequent windows.
442 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun);
443 }
444
445 fullscreen_controller_ = new FullscreenController(window_, profile_, this);
377 } 446 }
378 447
379 Browser::~Browser() { 448 Browser::~Browser() {
380 // The tab strip should not have any tabs at this point. 449 // The tab strip should not have any tabs at this point.
381 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) 450 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
382 DCHECK(tab_strip_model_->empty()); 451 DCHECK(tab_strip_model_->empty());
383 tab_strip_model_->RemoveObserver(this); 452 tab_strip_model_->RemoveObserver(this);
384 453
385 BrowserList::RemoveBrowser(this); 454 BrowserList::RemoveBrowser(this);
386 455
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // its cache and cookies once it gets destroyed at the appropriate time. 490 // its cache and cookies once it gets destroyed at the appropriate time.
422 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); 491 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
423 } 492 }
424 493
425 // There may be pending file dialogs, we need to tell them that we've gone 494 // There may be pending file dialogs, we need to tell them that we've gone
426 // away so they don't try and call back to us. 495 // away so they don't try and call back to us.
427 if (select_file_dialog_.get()) 496 if (select_file_dialog_.get())
428 select_file_dialog_->ListenerDestroyed(); 497 select_file_dialog_->ListenerDestroyed();
429 } 498 }
430 499
431 // static
432 Browser* Browser::Create(Profile* profile) {
433 Browser* browser = new Browser(TYPE_TABBED, profile);
434 browser->InitBrowserWindow();
435 return browser;
436 }
437
438 // static
439 Browser* Browser::CreateWithParams(const CreateParams& params) {
440 if (!params.app_name.empty())
441 chrome::RegisterAppPrefs(params.app_name, params.profile);
442
443 Browser* browser = new Browser(params.type, params.profile);
444 browser->app_name_ = params.app_name;
445 browser->app_type_ = params.app_type;
446 browser->set_override_bounds(params.initial_bounds);
447 browser->set_initial_show_state(params.initial_show_state);
448 browser->set_is_session_restore(params.is_session_restore);
449
450 browser->InitBrowserWindow();
451 return browser;
452 }
453
454 void Browser::InitBrowserWindow() {
455 DCHECK(!window_);
456
457 window_ = CreateBrowserWindow();
458 fullscreen_controller_ = new FullscreenController(window_, profile_, this);
459
460 #if defined(OS_WIN) && !defined(USE_AURA)
461 // Set the app user model id for this application to that of the application
462 // name. See http://crbug.com/7028.
463 ui::win::SetAppIdForWindow(
464 is_app() && !is_type_panel() ?
465 ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_),
466 profile_->GetPath()) :
467 ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()),
468 window()->GetNativeWindow());
469
470 if (is_type_panel()) {
471 ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(),
472 window()->GetNativeWindow());
473 }
474 #endif
475
476 // Create the extension window controller before sending notifications.
477 extension_window_controller_.reset(
478 new BrowserExtensionWindowController(this));
479
480 content::NotificationService::current()->Notify(
481 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
482 content::Source<Browser>(this),
483 content::NotificationService::NoDetails());
484
485 PrefService* local_state = g_browser_process->local_state();
486 if (local_state && local_state->FindPreference(
487 prefs::kAutofillPersonalDataManagerFirstRun) &&
488 local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) {
489 // Notify PDM that this is a first run.
490 #if defined(OS_WIN)
491 ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_));
492 #endif // defined(OS_WIN)
493 // Reset the preference so we don't call it again for subsequent windows.
494 local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun);
495 }
496 }
497
498 void Browser::SetWindowForTesting(BrowserWindow* window) {
499 DCHECK(!window_);
500 window_ = window;
501 fullscreen_controller_ = new FullscreenController(window_, profile_, this);
502 }
503
504 /////////////////////////////////////////////////////////////////////////////// 500 ///////////////////////////////////////////////////////////////////////////////
505 // Getters & Setters 501 // Getters & Setters
506 502
507 FindBarController* Browser::GetFindBarController() { 503 FindBarController* Browser::GetFindBarController() {
508 if (!find_bar_controller_.get()) { 504 if (!find_bar_controller_.get()) {
509 FindBar* find_bar = window_->CreateFindBar(); 505 FindBar* find_bar = window_->CreateFindBar();
510 find_bar_controller_.reset(new FindBarController(find_bar)); 506 find_bar_controller_.reset(new FindBarController(find_bar));
511 find_bar->SetFindBarController(find_bar_controller_.get()); 507 find_bar->SetFindBarController(find_bar_controller_.get());
512 find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this)); 508 find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this));
513 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 509 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); 1208 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
1213 if (error) 1209 if (error)
1214 error->ShowBubbleView(this); 1210 error->ShowBubbleView(this);
1215 } 1211 }
1216 1212
1217 void Browser::ShowFirstRunBubble() { 1213 void Browser::ShowFirstRunBubble() {
1218 window()->GetLocationBar()->ShowFirstRunBubble(); 1214 window()->GetLocationBar()->ShowFirstRunBubble();
1219 } 1215 }
1220 1216
1221 /////////////////////////////////////////////////////////////////////////////// 1217 ///////////////////////////////////////////////////////////////////////////////
1222 // Browser, protected:
1223
1224 BrowserWindow* Browser::CreateBrowserWindow() {
1225 #if !defined(USE_ASH)
1226 if (is_type_panel())
1227 return PanelManager::GetInstance()->CreatePanel(this)->browser_window();
1228 #endif
1229 return BrowserWindow::CreateBrowserWindow(this);
1230 }
1231
1232 ///////////////////////////////////////////////////////////////////////////////
1233 // Browser, content::WebContentsDelegate implementation: 1218 // Browser, content::WebContentsDelegate implementation:
1234 1219
1235 WebContents* Browser::OpenURLFromTab(WebContents* source, 1220 WebContents* Browser::OpenURLFromTab(WebContents* source,
1236 const OpenURLParams& params) { 1221 const OpenURLParams& params) {
1237 chrome::NavigateParams nav_params(this, params.url, params.transition); 1222 chrome::NavigateParams nav_params(this, params.url, params.transition);
1238 nav_params.source_contents = chrome::GetTabContentsAt(this, 1223 nav_params.source_contents = chrome::GetTabContentsAt(this,
1239 tab_strip_model_->GetIndexOfWebContents(source)); 1224 tab_strip_model_->GetIndexOfWebContents(source));
1240 nav_params.referrer = params.referrer; 1225 nav_params.referrer = params.referrer;
1241 nav_params.disposition = params.disposition; 1226 nav_params.disposition = params.disposition;
1242 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; 1227 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 if (contents && !allow_js_access) { 2261 if (contents && !allow_js_access) {
2277 contents->web_contents()->GetController().LoadURL( 2262 contents->web_contents()->GetController().LoadURL(
2278 target_url, 2263 target_url,
2279 content::Referrer(), 2264 content::Referrer(),
2280 content::PAGE_TRANSITION_LINK, 2265 content::PAGE_TRANSITION_LINK,
2281 std::string()); // No extra headers. 2266 std::string()); // No extra headers.
2282 } 2267 }
2283 2268
2284 return contents != NULL; 2269 return contents != NULL;
2285 } 2270 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698