| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return true; | 243 return true; |
| 244 | 244 |
| 245 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually | 245 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually |
| 246 // view-source: of a chrome:// URL. | 246 // view-source: of a chrome:// URL. |
| 247 if (entry->virtual_url().SchemeIs(chrome::kViewSourceScheme)) | 247 if (entry->virtual_url().SchemeIs(chrome::kViewSourceScheme)) |
| 248 return entry->url().SchemeIs(chrome::kChromeUIScheme); | 248 return entry->url().SchemeIs(chrome::kChromeUIScheme); |
| 249 | 249 |
| 250 return false; | 250 return false; |
| 251 } | 251 } |
| 252 | 252 |
| 253 // Get the launch URL for a given extension, with optional override/fallback. |
| 254 // |override_url|, if non-empty, will be preferred over the extension's |
| 255 // launch url. |
| 256 GURL UrlForExtension(const Extension* extension, const GURL& override_url) { |
| 257 if (!extension) |
| 258 return override_url; |
| 259 |
| 260 GURL url; |
| 261 if (!override_url.is_empty()) { |
| 262 DCHECK(extension->web_extent().MatchesURL(override_url)); |
| 263 url = override_url; |
| 264 } else { |
| 265 url = extension->GetFullLaunchURL(); |
| 266 } |
| 267 |
| 268 // For extensions lacking launch urls, determine a reasonable fallback. |
| 269 if (!url.is_valid()) { |
| 270 url = extension->options_url(); |
| 271 if (!url.is_valid()) { |
| 272 url = GURL(std::string(chrome::kChromeUISettingsURL) + |
| 273 chrome::kExtensionsSubPage); |
| 274 } |
| 275 } |
| 276 |
| 277 return url; |
| 278 } |
| 279 |
| 253 } // namespace | 280 } // namespace |
| 254 | 281 |
| 255 //////////////////////////////////////////////////////////////////////////////// | 282 //////////////////////////////////////////////////////////////////////////////// |
| 256 // Browser, CreateParams: | 283 // Browser, CreateParams: |
| 257 | 284 |
| 258 Browser::CreateParams::CreateParams(Type type, Profile* profile) | 285 Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 259 : type(type), | 286 : type(type), |
| 260 profile(profile) { | 287 profile(profile) { |
| 261 } | 288 } |
| 262 | 289 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 profile->GetOffTheRecordProfile()); | 603 profile->GetOffTheRecordProfile()); |
| 577 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); | 604 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
| 578 browser->window()->Show(); | 605 browser->window()->Show(); |
| 579 } | 606 } |
| 580 | 607 |
| 581 // static | 608 // static |
| 582 TabContents* Browser::OpenApplication( | 609 TabContents* Browser::OpenApplication( |
| 583 Profile* profile, | 610 Profile* profile, |
| 584 const Extension* extension, | 611 const Extension* extension, |
| 585 extension_misc::LaunchContainer container, | 612 extension_misc::LaunchContainer container, |
| 613 const GURL& override_url, |
| 586 WindowOpenDisposition disposition) { | 614 WindowOpenDisposition disposition) { |
| 587 #if defined(USE_AURA) | 615 #if defined(USE_AURA) |
| 588 // On aura we're experimenting with making all apps open in windows. | 616 // On aura we're experimenting with making all apps open in windows. |
| 589 container = extension_misc::LAUNCH_WINDOW; | 617 container = extension_misc::LAUNCH_WINDOW; |
| 590 #endif | 618 #endif |
| 591 TabContents* tab = NULL; | 619 TabContents* tab = NULL; |
| 592 ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); | 620 ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); |
| 593 prefs->SetActiveBit(extension->id(), true); | 621 prefs->SetActiveBit(extension->id(), true); |
| 594 | 622 |
| 595 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); | 623 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); |
| 596 | 624 |
| 597 switch (container) { | 625 switch (container) { |
| 598 case extension_misc::LAUNCH_WINDOW: | 626 case extension_misc::LAUNCH_WINDOW: |
| 599 case extension_misc::LAUNCH_PANEL: | 627 case extension_misc::LAUNCH_PANEL: |
| 600 tab = Browser::OpenApplicationWindow(profile, extension, container, | 628 tab = Browser::OpenApplicationWindow(profile, extension, container, |
| 601 GURL(), NULL); | 629 override_url, NULL); |
| 602 break; | 630 break; |
| 603 case extension_misc::LAUNCH_TAB: { | 631 case extension_misc::LAUNCH_TAB: { |
| 604 tab = Browser::OpenApplicationTab(profile, extension, disposition); | 632 tab = Browser::OpenApplicationTab(profile, extension, override_url, |
| 633 disposition); |
| 605 break; | 634 break; |
| 606 } | 635 } |
| 607 default: | 636 default: |
| 608 NOTREACHED(); | 637 NOTREACHED(); |
| 609 break; | 638 break; |
| 610 } | 639 } |
| 611 return tab; | 640 return tab; |
| 612 } | 641 } |
| 613 | 642 |
| 614 // static | 643 // static |
| 615 TabContents* Browser::OpenApplicationWindow( | 644 TabContents* Browser::OpenApplicationWindow( |
| 616 Profile* profile, | 645 Profile* profile, |
| 617 const Extension* extension, | 646 const Extension* extension, |
| 618 extension_misc::LaunchContainer container, | 647 extension_misc::LaunchContainer container, |
| 619 const GURL& url_input, | 648 const GURL& url_input, |
| 620 Browser** app_browser) { | 649 Browser** app_browser) { |
| 621 GURL url; | 650 DCHECK(!url_input.is_empty() || extension); |
| 622 if (!url_input.is_empty()) { | 651 GURL url = UrlForExtension(extension, url_input); |
| 623 if (extension) | |
| 624 DCHECK(extension->web_extent().MatchesURL(url_input)); | |
| 625 url = url_input; | |
| 626 } else { | |
| 627 DCHECK(extension); // Empty url and no extension. Nothing to open. | |
| 628 url = extension->GetFullLaunchURL(); | |
| 629 } | |
| 630 | 652 |
| 631 std::string app_name; | 653 std::string app_name; |
| 632 if (extension) | 654 app_name = extension ? |
| 633 app_name = | 655 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
| 634 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 656 web_app::GenerateApplicationNameFromURL(url); |
| 635 else | |
| 636 app_name = web_app::GenerateApplicationNameFromURL(url); | |
| 637 | 657 |
| 638 Type type = extension && (container == extension_misc::LAUNCH_PANEL) ? | 658 Type type = extension && (container == extension_misc::LAUNCH_PANEL) ? |
| 639 TYPE_PANEL : TYPE_POPUP; | 659 TYPE_PANEL : TYPE_POPUP; |
| 640 | 660 |
| 641 gfx::Rect window_bounds; | 661 gfx::Rect window_bounds; |
| 642 if (extension) { | 662 if (extension) { |
| 643 window_bounds.set_width(extension->launch_width()); | 663 window_bounds.set_width(extension->launch_width()); |
| 644 window_bounds.set_height(extension->launch_height()); | 664 window_bounds.set_height(extension->launch_height()); |
| 645 } | 665 } |
| 646 | 666 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 705 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 686 // pending web app action. | 706 // pending web app action. |
| 687 app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 707 app_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 688 } | 708 } |
| 689 return tab; | 709 return tab; |
| 690 } | 710 } |
| 691 | 711 |
| 692 // static | 712 // static |
| 693 TabContents* Browser::OpenApplicationTab(Profile* profile, | 713 TabContents* Browser::OpenApplicationTab(Profile* profile, |
| 694 const Extension* extension, | 714 const Extension* extension, |
| 715 const GURL& override_url, |
| 695 WindowOpenDisposition disposition) { | 716 WindowOpenDisposition disposition) { |
| 696 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); | 717 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); |
| 697 TabContents* contents = NULL; | 718 TabContents* contents = NULL; |
| 698 if (!browser) { | 719 if (!browser) { |
| 699 // No browser for this profile, need to open a new one. | 720 // No browser for this profile, need to open a new one. |
| 700 browser = Browser::Create(profile); | 721 browser = Browser::Create(profile); |
| 701 browser->window()->Show(); | 722 browser->window()->Show(); |
| 702 // There's no current tab in this browser window, so add a new one. | 723 // There's no current tab in this browser window, so add a new one. |
| 703 disposition = NEW_FOREGROUND_TAB; | 724 disposition = NEW_FOREGROUND_TAB; |
| 704 } | 725 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 718 UMA_HISTOGRAM_ENUMERATION( | 739 UMA_HISTOGRAM_ENUMERATION( |
| 719 base::FieldTrial::MakeName("Extensions.AppTabLaunchType", | 740 base::FieldTrial::MakeName("Extensions.AppTabLaunchType", |
| 720 kDefaultAppsTrial_Name), | 741 kDefaultAppsTrial_Name), |
| 721 launch_type, 100); | 742 launch_type, 100); |
| 722 } | 743 } |
| 723 | 744 |
| 724 int add_type = TabStripModel::ADD_ACTIVE; | 745 int add_type = TabStripModel::ADD_ACTIVE; |
| 725 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) | 746 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
| 726 add_type |= TabStripModel::ADD_PINNED; | 747 add_type |= TabStripModel::ADD_PINNED; |
| 727 | 748 |
| 728 // For extensions lacking launch urls, determine a reasonable fallback. | 749 GURL extension_url = UrlForExtension(extension, override_url); |
| 729 GURL extension_url = extension->GetFullLaunchURL(); | |
| 730 if (!extension_url.is_valid()) { | |
| 731 extension_url = extension->options_url(); | |
| 732 if (!extension_url.is_valid()) | |
| 733 extension_url = GURL(std::string(chrome::kChromeUISettingsURL) + | |
| 734 chrome::kExtensionsSubPage); | |
| 735 } | |
| 736 | |
| 737 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all | 750 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all |
| 738 // cases. | 751 // cases. |
| 739 browser::NavigateParams params(browser, extension_url, | 752 browser::NavigateParams params(browser, extension_url, |
| 740 content::PAGE_TRANSITION_START_PAGE); | 753 content::PAGE_TRANSITION_START_PAGE); |
| 741 params.tabstrip_add_types = add_type; | 754 params.tabstrip_add_types = add_type; |
| 742 params.disposition = disposition; | 755 params.disposition = disposition; |
| 743 | 756 |
| 744 if (disposition == CURRENT_TAB) { | 757 if (disposition == CURRENT_TAB) { |
| 745 TabContents* existing_tab = browser->GetSelectedTabContents(); | 758 TabContents* existing_tab = browser->GetSelectedTabContents(); |
| 746 TabStripModel* model = browser->tabstrip_model(); | 759 TabStripModel* model = browser->tabstrip_model(); |
| 747 int tab_index = model->GetWrapperIndex(existing_tab); | 760 int tab_index = model->GetWrapperIndex(existing_tab); |
| 748 | 761 |
| 749 existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), | 762 existing_tab->OpenURL(extension_url, existing_tab->GetURL(), |
| 750 disposition, content::PAGE_TRANSITION_LINK); | 763 disposition, content::PAGE_TRANSITION_LINK); |
| 751 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { | 764 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { |
| 752 model->SetTabPinned(tab_index, true); | 765 model->SetTabPinned(tab_index, true); |
| 753 tab_index = model->GetWrapperIndex(existing_tab); | 766 tab_index = model->GetWrapperIndex(existing_tab); |
| 754 } | 767 } |
| 755 if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) | 768 if (params.tabstrip_add_types & TabStripModel::ADD_ACTIVE) |
| 756 model->ActivateTabAt(tab_index, true); | 769 model->ActivateTabAt(tab_index, true); |
| 757 | 770 |
| 758 contents = existing_tab; | 771 contents = existing_tab; |
| 759 } else { | 772 } else { |
| 760 browser::Navigate(¶ms); | 773 browser::Navigate(¶ms); |
| 761 contents = params.target_contents->tab_contents(); | 774 contents = params.target_contents->tab_contents(); |
| 762 } | 775 } |
| 763 | 776 |
| 764 // TODO(skerner): If we are already in full screen mode, and the user | 777 // TODO(skerner): If we are already in full screen mode, and the user |
| 765 // set the app to open as a regular or pinned tab, what should happen? | 778 // set the app to open as a regular or pinned tab, what should happen? |
| 766 // Today we open the tab, but stay in full screen mode. Should we leave | 779 // Today we open the tab, but stay in full screen mode. Should we leave |
| 767 // full screen mode in this case? | 780 // full screen mode in this case? |
| 768 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && | 781 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
| 769 !browser->window()->IsFullscreen()) | 782 !browser->window()->IsFullscreen()) { |
| 770 browser->ToggleFullscreenMode(false); | 783 browser->ToggleFullscreenMode(false); |
| 784 } |
| 771 | 785 |
| 772 return contents; | 786 return contents; |
| 773 } | 787 } |
| 774 | 788 |
| 775 // static | 789 // static |
| 776 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 790 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 777 Browser* browser = Browser::Create(profile); | 791 Browser* browser = Browser::Create(profile); |
| 778 browser->OpenBookmarkManager(); | 792 browser->OpenBookmarkManager(); |
| 779 browser->window()->Show(); | 793 browser->window()->Show(); |
| 780 } | 794 } |
| (...skipping 4727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5508 } | 5522 } |
| 5509 | 5523 |
| 5510 void Browser::UpdateFullscreenExitBubbleContent() { | 5524 void Browser::UpdateFullscreenExitBubbleContent() { |
| 5511 GURL url; | 5525 GURL url; |
| 5512 if (fullscreened_tab_) | 5526 if (fullscreened_tab_) |
| 5513 url = fullscreened_tab_->tab_contents()->GetURL(); | 5527 url = fullscreened_tab_->tab_contents()->GetURL(); |
| 5514 | 5528 |
| 5515 window_->UpdateFullscreenExitBubbleContent( | 5529 window_->UpdateFullscreenExitBubbleContent( |
| 5516 url, GetFullscreenExitBubbleType()); | 5530 url, GetFullscreenExitBubbleType()); |
| 5517 } | 5531 } |
| OLD | NEW |