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