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...) 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(), &browser); | 534 GURL()); |
535 break; | 535 break; |
536 case Extension::LAUNCH_TAB: { | 536 case Extension::LAUNCH_TAB: { |
537 tab = Browser::OpenApplicationTab(profile, extension, &browser); | 537 tab = Browser::OpenApplicationTab(profile, extension); |
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(); |
545 if (browser && extension && extension->launch_fullscreen()) | 546 if (browser && extension && extension->launch_fullscreen()) |
546 browser->window()->SetFullscreen(true); | 547 browser->window()->SetFullscreen(true); |
547 } | 548 } |
548 return tab; | 549 return tab; |
549 } | 550 } |
550 | 551 |
551 // static | 552 // static |
552 TabContents* Browser::OpenApplicationWindow( | 553 TabContents* Browser::OpenApplicationWindow( |
553 Profile* profile, | 554 Profile* profile, |
554 Extension* extension, | 555 Extension* extension, |
555 Extension::LaunchContainer container, | 556 Extension::LaunchContainer container, |
556 const GURL& url_input, | 557 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* local_browser = Browser::CreateForApp(app_name, extension, profile, | 573 Browser* browser = Browser::CreateForApp(app_name, extension, profile, |
574 as_panel); | 574 as_panel); |
575 TabContents* tab_contents = local_browser->AddTabWithURL( | 575 TabContents* tab_contents = 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 local_browser->window()->Show(); | 581 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 local_browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 594 browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
595 } | 595 } |
596 | 596 |
597 if (browser) | |
598 *browser = local_browser; | |
599 | |
600 return tab_contents; | 597 return tab_contents; |
601 } | 598 } |
602 | 599 |
603 // static | 600 // static |
604 TabContents* Browser::OpenApplicationWindow(Profile* profile, | 601 TabContents* Browser::OpenApplicationWindow(Profile* profile, |
605 GURL& url, Browser** browser) { | 602 GURL& url) { |
606 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url, | 603 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url); |
607 browser); | |
608 } | 604 } |
609 | 605 |
610 // static | 606 // static |
611 TabContents* Browser::OpenApplicationTab(Profile* profile, | 607 TabContents* Browser::OpenApplicationTab(Profile* profile, |
612 Extension* extension, | 608 Extension* extension) { |
613 Browser** browser) { | 609 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
614 Browser* local_browser = BrowserList::GetLastActiveWithProfile(profile); | 610 if (!browser || browser->type() != Browser::TYPE_NORMAL) |
615 if (!local_browser || local_browser->type() != Browser::TYPE_NORMAL) | |
616 return NULL; | 611 return NULL; |
617 | 612 |
618 // TODO(erikkay): This doesn't seem like the right transition in all cases. | 613 // TODO(erikkay): This doesn't seem like the right transition in all cases. |
619 PageTransition::Type transition = PageTransition::START_PAGE; | 614 PageTransition::Type transition = PageTransition::START_PAGE; |
620 GURL url = extension->GetFullLaunchURL(); | 615 GURL url = extension->GetFullLaunchURL(); |
621 TabContents* tab_contents = | 616 TabContents* tab_contents = |
622 local_browser->CreateTabContentsForURL(url, GURL(), profile, | 617 browser->CreateTabContentsForURL(url, GURL(), profile, |
623 transition, false, NULL); | 618 transition, false, NULL); |
624 tab_contents->SetExtensionApp(extension); | 619 tab_contents->SetExtensionApp(extension); |
625 local_browser->AddTab(tab_contents, transition); | 620 browser->AddTab(tab_contents, transition); |
626 | |
627 if (browser) | |
628 *browser = local_browser; | |
629 | |
630 return tab_contents; | 621 return tab_contents; |
631 } | 622 } |
632 | 623 |
633 // static | 624 // static |
634 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 625 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
635 Browser* browser = Browser::Create(profile); | 626 Browser* browser = Browser::Create(profile); |
636 browser->ShowBookmarkManagerTab(); | 627 browser->ShowBookmarkManagerTab(); |
637 browser->window()->Show(); | 628 browser->window()->Show(); |
638 } | 629 } |
639 | 630 |
(...skipping 1736 matching lines...) Loading... |
2376 TabCloseableStateWatcher* watcher = | 2367 TabCloseableStateWatcher* watcher = |
2377 g_browser_process->tab_closeable_state_watcher(); | 2368 g_browser_process->tab_closeable_state_watcher(); |
2378 return !watcher || watcher->CanCloseTab(this); | 2369 return !watcher || watcher->CanCloseTab(this); |
2379 } | 2370 } |
2380 | 2371 |
2381 void Browser::ToggleUseVerticalTabs() { | 2372 void Browser::ToggleUseVerticalTabs() { |
2382 use_vertical_tabs_.SetValue(!UseVerticalTabs()); | 2373 use_vertical_tabs_.SetValue(!UseVerticalTabs()); |
2383 UseVerticalTabsChanged(); | 2374 UseVerticalTabsChanged(); |
2384 } | 2375 } |
2385 | 2376 |
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 | |
2393 /////////////////////////////////////////////////////////////////////////////// | 2377 /////////////////////////////////////////////////////////////////////////////// |
2394 // Browser, TabStripModelObserver implementation: | 2378 // Browser, TabStripModelObserver implementation: |
2395 | 2379 |
2396 void Browser::TabInsertedAt(TabContents* contents, | 2380 void Browser::TabInsertedAt(TabContents* contents, |
2397 int index, | 2381 int index, |
2398 bool foreground) { | 2382 bool foreground) { |
2399 contents->set_delegate(this); | 2383 contents->set_delegate(this); |
2400 contents->controller().SetWindowID(session_id()); | 2384 contents->controller().SetWindowID(session_id()); |
2401 | 2385 |
2402 SyncHistoryWithTabs(index); | 2386 SyncHistoryWithTabs(index); |
(...skipping 531 matching lines...) Loading... |
2934 break; | 2918 break; |
2935 } | 2919 } |
2936 default: | 2920 default: |
2937 NOTREACHED(); | 2921 NOTREACHED(); |
2938 break; | 2922 break; |
2939 } | 2923 } |
2940 | 2924 |
2941 pending_web_app_action_ = NONE; | 2925 pending_web_app_action_ = NONE; |
2942 } | 2926 } |
2943 | 2927 |
| 2928 Browser* Browser::GetBrowser() { |
| 2929 return this; |
| 2930 } |
| 2931 |
2944 void Browser::ContentTypeChanged(TabContents* source) { | 2932 void Browser::ContentTypeChanged(TabContents* source) { |
2945 if (source == GetSelectedTabContents()) | 2933 if (source == GetSelectedTabContents()) |
2946 UpdateZoomCommandsForTabState(); | 2934 UpdateZoomCommandsForTabState(); |
2947 } | 2935 } |
2948 | 2936 |
2949 /////////////////////////////////////////////////////////////////////////////// | 2937 /////////////////////////////////////////////////////////////////////////////// |
2950 // Browser, SelectFileDialog::Listener implementation: | 2938 // Browser, SelectFileDialog::Listener implementation: |
2951 | 2939 |
2952 void Browser::FileSelected(const FilePath& path, int index, void* params) { | 2940 void Browser::FileSelected(const FilePath& path, int index, void* params) { |
2953 profile_->set_last_selected_directory(path.DirName()); | 2941 profile_->set_last_selected_directory(path.DirName()); |
(...skipping 780 matching lines...) Loading... |
3734 (*iter)->window()->Show(); | 3722 (*iter)->window()->Show(); |
3735 return true; | 3723 return true; |
3736 } | 3724 } |
3737 } | 3725 } |
3738 | 3726 |
3739 // If the extension wants to be opened in a window, but there is no | 3727 // If the extension wants to be opened in a window, but there is no |
3740 // existing window, create one, then open the URL there. | 3728 // existing window, create one, then open the URL there. |
3741 if (destination_extension->launch_container() == | 3729 if (destination_extension->launch_container() == |
3742 Extension::LAUNCH_WINDOW) { | 3730 Extension::LAUNCH_WINDOW) { |
3743 Browser::OpenApplicationWindow(profile_, destination_extension, | 3731 Browser::OpenApplicationWindow(profile_, destination_extension, |
3744 Extension::LAUNCH_WINDOW, url, NULL); | 3732 Extension::LAUNCH_WINDOW, url); |
3745 return true; | 3733 return true; |
3746 } | 3734 } |
3747 } | 3735 } |
3748 | 3736 |
3749 // Otherwise, we are opening a normal web page. | 3737 // Otherwise, we are opening a normal web page. |
3750 // | 3738 // |
3751 // If our source tab is in an app window, we don't want to open the tab | 3739 // If our source tab is in an app window, we don't want to open the tab |
3752 // there. Find a normal browser to open it in. | 3740 // there. Find a normal browser to open it in. |
3753 if (extension_app_) { | 3741 if (extension_app_) { |
3754 Browser* browser = GetOrCreateTabbedBrowser(profile_); | 3742 Browser* browser = GetOrCreateTabbedBrowser(profile_); |
(...skipping 326 matching lines...) Loading... |
4081 } | 4069 } |
4082 | 4070 |
4083 bool Browser::IsPinned(TabContents* source) { | 4071 bool Browser::IsPinned(TabContents* source) { |
4084 int index = tabstrip_model_.GetIndexOfTabContents(source); | 4072 int index = tabstrip_model_.GetIndexOfTabContents(source); |
4085 if (index == TabStripModel::kNoTab) { | 4073 if (index == TabStripModel::kNoTab) { |
4086 NOTREACHED() << "IsPinned called for tab not in our strip"; | 4074 NOTREACHED() << "IsPinned called for tab not in our strip"; |
4087 return false; | 4075 return false; |
4088 } | 4076 } |
4089 return tabstrip_model_.IsTabPinned(index); | 4077 return tabstrip_model_.IsTabPinned(index); |
4090 } | 4078 } |
OLD | NEW |