Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 } | 325 } |
| 326 #endif // !OS_CHROMEOS || USE_AURA | 326 #endif // !OS_CHROMEOS || USE_AURA |
| 327 return true; | 327 return true; |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace | 330 } // namespace |
| 331 | 331 |
| 332 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
| 333 // Browser, CreateParams: | 333 // Browser, CreateParams: |
| 334 | 334 |
| 335 Browser::CreateParams::CreateParams() | |
| 336 : type(TYPE_TABBED), | |
| 337 profile(NULL), | |
| 338 initial_show_state(ui::SHOW_STATE_DEFAULT), | |
| 339 is_session_restore(false) { | |
| 340 } | |
| 341 | |
| 335 Browser::CreateParams::CreateParams(Type type, Profile* profile) | 342 Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 336 : type(type), | 343 : type(type), |
| 337 profile(profile), | 344 profile(profile), |
| 338 app_type(APP_TYPE_HOST), | 345 app_type(APP_TYPE_HOST), |
| 339 initial_show_state(ui::SHOW_STATE_DEFAULT), | 346 initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 340 is_session_restore(false) { | 347 is_session_restore(false) { |
| 341 } | 348 } |
| 342 | 349 |
| 350 // static | |
| 351 Browser::CreateParams Browser::CreateParams::CreateForApp( | |
| 352 Type type, | |
| 353 const std::string& app_name, | |
| 354 const gfx::Rect& window_bounds, | |
| 355 Profile* profile) { | |
| 356 DCHECK(type != TYPE_TABBED); | |
| 357 DCHECK(!app_name.empty()); | |
| 358 | |
| 359 if (type == TYPE_PANEL && !AllowPanels(app_name)) | |
| 360 type = TYPE_POPUP; | |
| 361 | |
| 362 CreateParams params(type, profile); | |
| 363 params.app_name = app_name; | |
| 364 params.app_type = APP_TYPE_CHILD; | |
| 365 params.initial_bounds = window_bounds; | |
| 366 | |
| 367 return params; | |
| 368 } | |
| 369 | |
| 370 // static | |
| 371 Browser::CreateParams Browser::CreateParams::CreateForDevTools( | |
| 372 Profile* profile) { | |
| 373 #if defined(OS_CHROMEOS) | |
|
Ben Goodger (Google)
2012/04/04 16:14:42
I think you can just do the same code for both pla
Aaron Boodman
2012/04/04 18:46:58
Done.
| |
| 374 CreateParams params(TYPE_TABBED, profile); | |
| 375 #else | |
| 376 CreateParams params(TYPE_POPUP, profile); | |
| 377 #endif | |
| 378 params.app_name = DevToolsWindow::kDevToolsApp; | |
| 379 return params; | |
| 380 } | |
| 381 | |
| 343 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 344 // Browser, Constructors, Creation, Showing: | 383 // Browser, Constructors, Creation, Showing: |
| 345 | 384 |
| 346 Browser::Browser(Type type, Profile* profile) | 385 Browser::Browser(Type type, Profile* profile) |
| 347 : type_(type), | 386 : type_(type), |
| 348 profile_(profile), | 387 profile_(profile), |
| 349 window_(NULL), | 388 window_(NULL), |
| 350 ALLOW_THIS_IN_INITIALIZER_LIST( | 389 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 351 tab_handler_(TabHandler::CreateTabHandler(this))), | 390 tab_handler_(TabHandler::CreateTabHandler(this))), |
| 352 command_updater_(this), | 391 command_updater_(this), |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 browser->app_name_ = params.app_name; | 556 browser->app_name_ = params.app_name; |
| 518 browser->app_type_ = params.app_type; | 557 browser->app_type_ = params.app_type; |
| 519 browser->set_override_bounds(params.initial_bounds); | 558 browser->set_override_bounds(params.initial_bounds); |
| 520 browser->set_show_state(params.initial_show_state); | 559 browser->set_show_state(params.initial_show_state); |
| 521 browser->set_is_session_restore(params.is_session_restore); | 560 browser->set_is_session_restore(params.is_session_restore); |
| 522 | 561 |
| 523 browser->InitBrowserWindow(); | 562 browser->InitBrowserWindow(); |
| 524 return browser; | 563 return browser; |
| 525 } | 564 } |
| 526 | 565 |
| 527 // static | |
| 528 Browser* Browser::CreateForType(Type type, Profile* profile) { | |
| 529 CreateParams params(type, profile); | |
| 530 return CreateWithParams(params); | |
| 531 } | |
| 532 | |
| 533 // static | |
| 534 Browser* Browser::CreateForApp(Type type, | |
| 535 const std::string& app_name, | |
| 536 const gfx::Rect& window_bounds, | |
| 537 Profile* profile) { | |
| 538 DCHECK(type != TYPE_TABBED); | |
| 539 DCHECK(!app_name.empty()); | |
| 540 | |
| 541 if (type == TYPE_PANEL && !AllowPanels(app_name)) | |
| 542 type = TYPE_POPUP; | |
| 543 | |
| 544 CreateParams params(type, profile); | |
| 545 params.app_name = app_name; | |
| 546 params.app_type = APP_TYPE_CHILD; | |
| 547 params.initial_bounds = window_bounds; | |
| 548 return CreateWithParams(params); | |
| 549 } | |
| 550 | |
| 551 // static | |
| 552 Browser* Browser::CreateForDevTools(Profile* profile) { | |
| 553 #if defined(OS_CHROMEOS) | |
| 554 CreateParams params(TYPE_TABBED, profile); | |
| 555 #else | |
| 556 CreateParams params(TYPE_POPUP, profile); | |
| 557 #endif | |
| 558 params.app_name = DevToolsWindow::kDevToolsApp; | |
| 559 return CreateWithParams(params); | |
| 560 } | |
| 561 | |
| 562 void Browser::InitBrowserWindow() { | 566 void Browser::InitBrowserWindow() { |
| 563 DCHECK(!window_); | 567 DCHECK(!window_); |
| 564 | 568 |
| 565 window_ = CreateBrowserWindow(); | 569 window_ = CreateBrowserWindow(); |
| 566 fullscreen_controller_ = new FullscreenController(window_, profile_, this); | 570 fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
| 567 | 571 |
| 568 #if defined(OS_WIN) && !defined(USE_AURA) | 572 #if defined(OS_WIN) && !defined(USE_AURA) |
| 569 // Set the app user model id for this application to that of the application | 573 // Set the app user model id for this application to that of the application |
| 570 // name. See http://crbug.com/7028. | 574 // name. See http://crbug.com/7028. |
| 571 ui::win::SetAppIdForWindow( | 575 ui::win::SetAppIdForWindow( |
| (...skipping 2791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3363 TabStripModel::ADD_INHERIT_GROUP | | 3367 TabStripModel::ADD_INHERIT_GROUP | |
| 3364 (pinned ? TabStripModel::ADD_PINNED : 0); | 3368 (pinned ? TabStripModel::ADD_PINNED : 0); |
| 3365 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, | 3369 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 3366 contents_dupe, | 3370 contents_dupe, |
| 3367 add_types); | 3371 add_types); |
| 3368 } else { | 3372 } else { |
| 3369 Browser* browser = NULL; | 3373 Browser* browser = NULL; |
| 3370 if (is_app()) { | 3374 if (is_app()) { |
| 3371 CHECK(!is_type_popup()); | 3375 CHECK(!is_type_popup()); |
| 3372 CHECK(!is_type_panel()); | 3376 CHECK(!is_type_panel()); |
| 3373 browser = Browser::CreateForApp(TYPE_POPUP, app_name_, gfx::Rect(), | 3377 browser = Browser::CreateWithParams( |
| 3374 profile_); | 3378 Browser::CreateParams::CreateForApp( |
| 3379 TYPE_POPUP, app_name_, gfx::Rect(),profile_)); | |
| 3375 } else if (is_type_popup()) { | 3380 } else if (is_type_popup()) { |
| 3376 browser = Browser::CreateForType(TYPE_POPUP, profile_); | 3381 browser = Browser::CreateWithParams( |
| 3382 Browser::CreateParams(TYPE_POPUP, profile_)); | |
| 3377 } | 3383 } |
| 3378 | 3384 |
| 3379 // Preserve the size of the original window. The new window has already | 3385 // Preserve the size of the original window. The new window has already |
| 3380 // been given an offset by the OS, so we shouldn't copy the old bounds. | 3386 // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 3381 BrowserWindow* new_window = browser->window(); | 3387 BrowserWindow* new_window = browser->window(); |
| 3382 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 3388 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 3383 window()->GetRestoredBounds().size())); | 3389 window()->GetRestoredBounds().size())); |
| 3384 | 3390 |
| 3385 // We need to show the browser now. Otherwise ContainerWin assumes the | 3391 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 3386 // TabContents is invisible and won't size it. | 3392 // TabContents is invisible and won't size it. |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3883 | 3889 |
| 3884 bool Browser::IsApplication() const { | 3890 bool Browser::IsApplication() const { |
| 3885 return is_app(); | 3891 return is_app(); |
| 3886 } | 3892 } |
| 3887 | 3893 |
| 3888 void Browser::ConvertContentsToApplication(WebContents* contents) { | 3894 void Browser::ConvertContentsToApplication(WebContents* contents) { |
| 3889 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); | 3895 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); |
| 3890 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 3896 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
| 3891 | 3897 |
| 3892 DetachContents(contents); | 3898 DetachContents(contents); |
| 3893 Browser* app_browser = Browser::CreateForApp( | 3899 Browser* app_browser = Browser::CreateWithParams( |
| 3894 TYPE_POPUP, app_name, gfx::Rect(), profile_); | 3900 Browser::CreateParams::CreateForApp( |
| 3901 TYPE_POPUP, app_name, gfx::Rect(), profile_)); | |
| 3895 TabContentsWrapper* wrapper = | 3902 TabContentsWrapper* wrapper = |
| 3896 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 3903 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 3897 if (!wrapper) | 3904 if (!wrapper) |
| 3898 wrapper = new TabContentsWrapper(contents); | 3905 wrapper = new TabContentsWrapper(contents); |
| 3899 app_browser->tabstrip_model()->AppendTabContents(wrapper, true); | 3906 app_browser->tabstrip_model()->AppendTabContents(wrapper, true); |
| 3900 | 3907 |
| 3901 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 3908 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 3902 contents->GetRenderViewHost()->SyncRendererPrefs(); | 3909 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 3903 app_browser->window()->Show(); | 3910 app_browser->window()->Show(); |
| 3904 } | 3911 } |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5574 // If this is a tabbed browser, just create a duplicate tab inside the same | 5581 // If this is a tabbed browser, just create a duplicate tab inside the same |
| 5575 // window next to the tab being duplicated. | 5582 // window next to the tab being duplicated. |
| 5576 int index = | 5583 int index = |
| 5577 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents); | 5584 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents); |
| 5578 int add_types = TabStripModel::ADD_ACTIVE | | 5585 int add_types = TabStripModel::ADD_ACTIVE | |
| 5579 TabStripModel::ADD_INHERIT_GROUP; | 5586 TabStripModel::ADD_INHERIT_GROUP; |
| 5580 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, | 5587 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, |
| 5581 view_source_contents, | 5588 view_source_contents, |
| 5582 add_types); | 5589 add_types); |
| 5583 } else { | 5590 } else { |
| 5584 Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_); | 5591 Browser* browser = Browser::CreateWithParams( |
| 5592 Browser::CreateParams(TYPE_TABBED, profile_)); | |
| 5585 | 5593 |
| 5586 // Preserve the size of the original window. The new window has already | 5594 // Preserve the size of the original window. The new window has already |
| 5587 // been given an offset by the OS, so we shouldn't copy the old bounds. | 5595 // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 5588 BrowserWindow* new_window = browser->window(); | 5596 BrowserWindow* new_window = browser->window(); |
| 5589 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 5597 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 5590 window()->GetRestoredBounds().size())); | 5598 window()->GetRestoredBounds().size())); |
| 5591 | 5599 |
| 5592 // We need to show the browser now. Otherwise ContainerWin assumes the | 5600 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 5593 // TabContents is invisible and won't size it. | 5601 // TabContents is invisible and won't size it. |
| 5594 browser->window()->Show(); | 5602 browser->window()->Show(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5674 ShowSingletonTabOverwritingNTP(params); | 5682 ShowSingletonTabOverwritingNTP(params); |
| 5675 } else { | 5683 } else { |
| 5676 LoginUIServiceFactory::GetForProfile( | 5684 LoginUIServiceFactory::GetForProfile( |
| 5677 profile()->GetOriginalProfile())->ShowLoginUI(false); | 5685 profile()->GetOriginalProfile())->ShowLoginUI(false); |
| 5678 } | 5686 } |
| 5679 } | 5687 } |
| 5680 | 5688 |
| 5681 void Browser::ToggleSpeechInput() { | 5689 void Browser::ToggleSpeechInput() { |
| 5682 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); | 5690 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); |
| 5683 } | 5691 } |
| OLD | NEW |