| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 browser->SelectTabContentsAt(tab_idx, false); | 524 browser->SelectTabContentsAt(tab_idx, false); |
| 525 return tab; | 525 return tab; |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 // The app is not yet open. Load it. | 529 // The app is not yet open. Load it. |
| 530 switch (container) { | 530 switch (container) { |
| 531 case Extension::LAUNCH_WINDOW: | 531 case Extension::LAUNCH_WINDOW: |
| 532 case Extension::LAUNCH_PANEL: | 532 case Extension::LAUNCH_PANEL: |
| 533 tab = Browser::OpenApplicationWindow(profile, extension, container, | 533 tab = Browser::OpenApplicationWindow(profile, extension, container, |
| 534 GURL()); | 534 GURL(), &browser); |
| 535 break; | 535 break; |
| 536 case Extension::LAUNCH_TAB: { | 536 case Extension::LAUNCH_TAB: { |
| 537 tab = Browser::OpenApplicationTab(profile, extension); | 537 tab = Browser::OpenApplicationTab(profile, extension, &browser); |
| 538 break; | 538 break; |
| 539 } | 539 } |
| 540 default: | 540 default: |
| 541 NOTREACHED(); | 541 NOTREACHED(); |
| 542 break; | 542 break; |
| 543 } | 543 } |
| 544 if (tab) { | 544 if (tab) { |
| 545 Browser* browser = tab->delegate()->GetBrowser(); | |
| 546 if (browser && extension && extension->launch_fullscreen()) | 545 if (browser && extension && extension->launch_fullscreen()) |
| 547 browser->window()->SetFullscreen(true); | 546 browser->window()->SetFullscreen(true); |
| 548 } | 547 } |
| 549 return tab; | 548 return tab; |
| 550 } | 549 } |
| 551 | 550 |
| 552 // static | 551 // static |
| 553 TabContents* Browser::OpenApplicationWindow( | 552 TabContents* Browser::OpenApplicationWindow( |
| 554 Profile* profile, | 553 Profile* profile, |
| 555 Extension* extension, | 554 Extension* extension, |
| 556 Extension::LaunchContainer container, | 555 Extension::LaunchContainer container, |
| 557 const GURL& url_input) { | 556 const GURL& url_input, |
| 557 Browser** browser) { |
| 558 GURL url; | 558 GURL url; |
| 559 if (!url_input.is_empty()) { | 559 if (!url_input.is_empty()) { |
| 560 if (extension) | 560 if (extension) |
| 561 DCHECK(extension->web_extent().ContainsURL(url_input)); | 561 DCHECK(extension->web_extent().ContainsURL(url_input)); |
| 562 url = url_input; | 562 url = url_input; |
| 563 } else { | 563 } else { |
| 564 DCHECK(extension); | 564 DCHECK(extension); |
| 565 url = extension->GetFullLaunchURL(); | 565 url = extension->GetFullLaunchURL(); |
| 566 } | 566 } |
| 567 | 567 |
| 568 // TODO(erikkay) this can't be correct for extensions | 568 // TODO(erikkay) this can't be correct for extensions |
| 569 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); | 569 std::wstring app_name = web_app::GenerateApplicationNameFromURL(url); |
| 570 RegisterAppPrefs(app_name); | 570 RegisterAppPrefs(app_name); |
| 571 | 571 |
| 572 bool as_panel = extension && (container == Extension::LAUNCH_PANEL); | 572 bool as_panel = extension && (container == Extension::LAUNCH_PANEL); |
| 573 Browser* browser = Browser::CreateForApp(app_name, extension, profile, | 573 Browser* local_browser = Browser::CreateForApp(app_name, extension, profile, |
| 574 as_panel); | 574 as_panel); |
| 575 TabContents* tab_contents = browser->AddTabWithURL( | 575 TabContents* tab_contents = local_browser->AddTabWithURL( |
| 576 url, GURL(), PageTransition::START_PAGE, -1, TabStripModel::ADD_SELECTED, | 576 url, GURL(), PageTransition::START_PAGE, -1, TabStripModel::ADD_SELECTED, |
| 577 NULL, std::string()); | 577 NULL, std::string()); |
| 578 | 578 |
| 579 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 579 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 580 tab_contents->render_view_host()->SyncRendererPrefs(); | 580 tab_contents->render_view_host()->SyncRendererPrefs(); |
| 581 browser->window()->Show(); | 581 local_browser->window()->Show(); |
| 582 | 582 |
| 583 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 583 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 584 // focus explicitly. | 584 // focus explicitly. |
| 585 tab_contents->view()->SetInitialFocus(); | 585 tab_contents->view()->SetInitialFocus(); |
| 586 | 586 |
| 587 if (!as_panel) { | 587 if (!as_panel) { |
| 588 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked | 588 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 589 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 589 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 590 // the web app info is available, TabContents notifies Browser via | 590 // the web app info is available, TabContents notifies Browser via |
| 591 // OnDidGetApplicationInfo, which calls | 591 // OnDidGetApplicationInfo, which calls |
| 592 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 592 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 593 // pending web app action. | 593 // pending web app action. |
| 594 browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 594 local_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 595 } | 595 } |
| 596 | 596 |
| 597 if (browser) |
| 598 *browser = local_browser; |
| 599 |
| 597 return tab_contents; | 600 return tab_contents; |
| 598 } | 601 } |
| 599 | 602 |
| 600 // static | 603 // static |
| 601 TabContents* Browser::OpenApplicationWindow(Profile* profile, | 604 TabContents* Browser::OpenApplicationWindow(Profile* profile, |
| 602 GURL& url) { | 605 GURL& url, Browser** browser) { |
| 603 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url); | 606 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url, |
| 607 browser); |
| 604 } | 608 } |
| 605 | 609 |
| 606 // static | 610 // static |
| 607 TabContents* Browser::OpenApplicationTab(Profile* profile, | 611 TabContents* Browser::OpenApplicationTab(Profile* profile, |
| 608 Extension* extension) { | 612 Extension* extension, |
| 609 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 613 Browser** browser) { |
| 610 if (!browser || browser->type() != Browser::TYPE_NORMAL) | 614 Browser* local_browser = BrowserList::GetLastActiveWithProfile(profile); |
| 615 if (!local_browser || local_browser->type() != Browser::TYPE_NORMAL) |
| 611 return NULL; | 616 return NULL; |
| 612 | 617 |
| 613 // TODO(erikkay): This doesn't seem like the right transition in all cases. | 618 // TODO(erikkay): This doesn't seem like the right transition in all cases. |
| 614 PageTransition::Type transition = PageTransition::START_PAGE; | 619 PageTransition::Type transition = PageTransition::START_PAGE; |
| 615 GURL url = extension->GetFullLaunchURL(); | 620 GURL url = extension->GetFullLaunchURL(); |
| 616 TabContents* tab_contents = | 621 TabContents* tab_contents = |
| 617 browser->CreateTabContentsForURL(url, GURL(), profile, | 622 local_browser->CreateTabContentsForURL(url, GURL(), profile, |
| 618 transition, false, NULL); | 623 transition, false, NULL); |
| 619 tab_contents->SetExtensionApp(extension); | 624 tab_contents->SetExtensionApp(extension); |
| 620 browser->AddTab(tab_contents, transition); | 625 local_browser->AddTab(tab_contents, transition); |
| 626 |
| 627 if (browser) |
| 628 *browser = local_browser; |
| 629 |
| 621 return tab_contents; | 630 return tab_contents; |
| 622 } | 631 } |
| 623 | 632 |
| 624 // static | 633 // static |
| 625 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 634 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 626 Browser* browser = Browser::Create(profile); | 635 Browser* browser = Browser::Create(profile); |
| 627 browser->ShowBookmarkManagerTab(); | 636 browser->ShowBookmarkManagerTab(); |
| 628 browser->window()->Show(); | 637 browser->window()->Show(); |
| 629 } | 638 } |
| 630 | 639 |
| (...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2367 TabCloseableStateWatcher* watcher = | 2376 TabCloseableStateWatcher* watcher = |
| 2368 g_browser_process->tab_closeable_state_watcher(); | 2377 g_browser_process->tab_closeable_state_watcher(); |
| 2369 return !watcher || watcher->CanCloseTab(this); | 2378 return !watcher || watcher->CanCloseTab(this); |
| 2370 } | 2379 } |
| 2371 | 2380 |
| 2372 void Browser::ToggleUseVerticalTabs() { | 2381 void Browser::ToggleUseVerticalTabs() { |
| 2373 use_vertical_tabs_.SetValue(!UseVerticalTabs()); | 2382 use_vertical_tabs_.SetValue(!UseVerticalTabs()); |
| 2374 UseVerticalTabsChanged(); | 2383 UseVerticalTabsChanged(); |
| 2375 } | 2384 } |
| 2376 | 2385 |
| 2386 bool Browser::LargeIconsPermitted() const { |
| 2387 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 2388 // for those windows, we already have a big icon in the top-left outside any |
| 2389 // tab. Having big tab icons too looks kinda redonk. |
| 2390 return TYPE_EXTENSION_APP != type(); |
| 2391 } |
| 2392 |
| 2377 /////////////////////////////////////////////////////////////////////////////// | 2393 /////////////////////////////////////////////////////////////////////////////// |
| 2378 // Browser, TabStripModelObserver implementation: | 2394 // Browser, TabStripModelObserver implementation: |
| 2379 | 2395 |
| 2380 void Browser::TabInsertedAt(TabContents* contents, | 2396 void Browser::TabInsertedAt(TabContents* contents, |
| 2381 int index, | 2397 int index, |
| 2382 bool foreground) { | 2398 bool foreground) { |
| 2383 contents->set_delegate(this); | 2399 contents->set_delegate(this); |
| 2384 contents->controller().SetWindowID(session_id()); | 2400 contents->controller().SetWindowID(session_id()); |
| 2385 | 2401 |
| 2386 SyncHistoryWithTabs(index); | 2402 SyncHistoryWithTabs(index); |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2918 break; | 2934 break; |
| 2919 } | 2935 } |
| 2920 default: | 2936 default: |
| 2921 NOTREACHED(); | 2937 NOTREACHED(); |
| 2922 break; | 2938 break; |
| 2923 } | 2939 } |
| 2924 | 2940 |
| 2925 pending_web_app_action_ = NONE; | 2941 pending_web_app_action_ = NONE; |
| 2926 } | 2942 } |
| 2927 | 2943 |
| 2928 Browser* Browser::GetBrowser() { | |
| 2929 return this; | |
| 2930 } | |
| 2931 | |
| 2932 void Browser::ContentTypeChanged(TabContents* source) { | 2944 void Browser::ContentTypeChanged(TabContents* source) { |
| 2933 if (source == GetSelectedTabContents()) | 2945 if (source == GetSelectedTabContents()) |
| 2934 UpdateZoomCommandsForTabState(); | 2946 UpdateZoomCommandsForTabState(); |
| 2935 } | 2947 } |
| 2936 | 2948 |
| 2937 /////////////////////////////////////////////////////////////////////////////// | 2949 /////////////////////////////////////////////////////////////////////////////// |
| 2938 // Browser, SelectFileDialog::Listener implementation: | 2950 // Browser, SelectFileDialog::Listener implementation: |
| 2939 | 2951 |
| 2940 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 2952 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
| 2941 profile_->set_last_selected_directory(path.DirName()); | 2953 profile_->set_last_selected_directory(path.DirName()); |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3722 (*iter)->window()->Show(); | 3734 (*iter)->window()->Show(); |
| 3723 return true; | 3735 return true; |
| 3724 } | 3736 } |
| 3725 } | 3737 } |
| 3726 | 3738 |
| 3727 // If the extension wants to be opened in a window, but there is no | 3739 // If the extension wants to be opened in a window, but there is no |
| 3728 // existing window, create one, then open the URL there. | 3740 // existing window, create one, then open the URL there. |
| 3729 if (destination_extension->launch_container() == | 3741 if (destination_extension->launch_container() == |
| 3730 Extension::LAUNCH_WINDOW) { | 3742 Extension::LAUNCH_WINDOW) { |
| 3731 Browser::OpenApplicationWindow(profile_, destination_extension, | 3743 Browser::OpenApplicationWindow(profile_, destination_extension, |
| 3732 Extension::LAUNCH_WINDOW, url); | 3744 Extension::LAUNCH_WINDOW, url, NULL); |
| 3733 return true; | 3745 return true; |
| 3734 } | 3746 } |
| 3735 } | 3747 } |
| 3736 | 3748 |
| 3737 // Otherwise, we are opening a normal web page. | 3749 // Otherwise, we are opening a normal web page. |
| 3738 // | 3750 // |
| 3739 // If our source tab is in an app window, we don't want to open the tab | 3751 // If our source tab is in an app window, we don't want to open the tab |
| 3740 // there. Find a normal browser to open it in. | 3752 // there. Find a normal browser to open it in. |
| 3741 if (extension_app_) { | 3753 if (extension_app_) { |
| 3742 Browser* browser = GetOrCreateTabbedBrowser(profile_); | 3754 Browser* browser = GetOrCreateTabbedBrowser(profile_); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4069 } | 4081 } |
| 4070 | 4082 |
| 4071 bool Browser::IsPinned(TabContents* source) { | 4083 bool Browser::IsPinned(TabContents* source) { |
| 4072 int index = tabstrip_model_.GetIndexOfTabContents(source); | 4084 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 4073 if (index == TabStripModel::kNoTab) { | 4085 if (index == TabStripModel::kNoTab) { |
| 4074 NOTREACHED() << "IsPinned called for tab not in our strip"; | 4086 NOTREACHED() << "IsPinned called for tab not in our strip"; |
| 4075 return false; | 4087 return false; |
| 4076 } | 4088 } |
| 4077 return tabstrip_model_.IsTabPinned(index); | 4089 return tabstrip_model_.IsTabPinned(index); |
| 4078 } | 4090 } |
| OLD | NEW |