| 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // static | 440 // static |
| 441 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 441 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
| 442 Profile* off_the_record_profile = profile->GetOffTheRecordProfile(); | 442 Profile* off_the_record_profile = profile->GetOffTheRecordProfile(); |
| 443 Browser* browser = BrowserList::FindBrowserWithType( | 443 Browser* browser = BrowserList::FindBrowserWithType( |
| 444 off_the_record_profile, TYPE_NORMAL, false); | 444 off_the_record_profile, TYPE_NORMAL, false); |
| 445 if (!browser) | 445 if (!browser) |
| 446 browser = Browser::Create(off_the_record_profile); | 446 browser = Browser::Create(off_the_record_profile); |
| 447 // TODO(eroman): should we have referrer here? | 447 // TODO(eroman): should we have referrer here? |
| 448 browser->AddTabWithURL( | 448 browser->AddTabWithURL( |
| 449 url, GURL(), PageTransition::LINK, -1, TabStripModel::ADD_SELECTED, NULL, | 449 url, GURL(), PageTransition::LINK, -1, TabStripModel::ADD_SELECTED, NULL, |
| 450 std::string()); | 450 std::string(), &browser); |
| 451 browser->window()->Show(); | 451 browser->window()->Show(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 // static | 454 // static |
| 455 Browser* Browser::FindAppWindowOrPanel(Profile* profile, | 455 Browser* Browser::FindAppWindowOrPanel(Profile* profile, |
| 456 Extension* extension_app) { | 456 Extension* extension_app) { |
| 457 // Test the focused browser first. | 457 // Test the focused browser first. |
| 458 Browser* browser = BrowserList::GetLastActive(); | 458 Browser* browser = BrowserList::GetLastActive(); |
| 459 if (browser && BrowserHostsExtensionApp(browser, profile, extension_app)) | 459 if (browser && BrowserHostsExtensionApp(browser, profile, extension_app)) |
| 460 return browser; | 460 return browser; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 browser->SelectTabContentsAt(tab_idx, false); | 530 browser->SelectTabContentsAt(tab_idx, false); |
| 531 return tab; | 531 return tab; |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 // The app is not yet open. Load it. | 535 // The app is not yet open. Load it. |
| 536 switch (container) { | 536 switch (container) { |
| 537 case Extension::LAUNCH_WINDOW: | 537 case Extension::LAUNCH_WINDOW: |
| 538 case Extension::LAUNCH_PANEL: | 538 case Extension::LAUNCH_PANEL: |
| 539 tab = Browser::OpenApplicationWindow(profile, extension, container, | 539 tab = Browser::OpenApplicationWindow(profile, extension, container, |
| 540 GURL()); | 540 GURL(), &browser); |
| 541 break; | 541 break; |
| 542 case Extension::LAUNCH_TAB: { | 542 case Extension::LAUNCH_TAB: { |
| 543 tab = Browser::OpenApplicationTab(profile, extension); | 543 tab = Browser::OpenApplicationTab(profile, extension, &browser); |
| 544 break; | 544 break; |
| 545 } | 545 } |
| 546 default: | 546 default: |
| 547 NOTREACHED(); | 547 NOTREACHED(); |
| 548 break; | 548 break; |
| 549 } | 549 } |
| 550 if (tab) { | 550 if (tab) { |
| 551 Browser* browser = tab->delegate()->GetBrowser(); | |
| 552 if (browser && extension && extension->launch_fullscreen()) | 551 if (browser && extension && extension->launch_fullscreen()) |
| 553 browser->window()->SetFullscreen(true); | 552 browser->window()->SetFullscreen(true); |
| 554 } | 553 } |
| 555 return tab; | 554 return tab; |
| 556 } | 555 } |
| 557 | 556 |
| 558 // static | 557 // static |
| 559 TabContents* Browser::OpenApplicationWindow( | 558 TabContents* Browser::OpenApplicationWindow( |
| 560 Profile* profile, | 559 Profile* profile, |
| 561 Extension* extension, | 560 Extension* extension, |
| 562 Extension::LaunchContainer container, | 561 Extension::LaunchContainer container, |
| 563 const GURL& url_input) { | 562 const GURL& url_input, |
| 563 Browser** browser) { |
| 564 GURL url; | 564 GURL url; |
| 565 if (!url_input.is_empty()) { | 565 if (!url_input.is_empty()) { |
| 566 if (extension) | 566 if (extension) |
| 567 DCHECK(extension->web_extent().ContainsURL(url_input)); | 567 DCHECK(extension->web_extent().ContainsURL(url_input)); |
| 568 url = url_input; | 568 url = url_input; |
| 569 } else { | 569 } else { |
| 570 DCHECK(extension); | 570 DCHECK(extension); |
| 571 url = extension->GetFullLaunchURL(); | 571 url = extension->GetFullLaunchURL(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 // TODO(erikkay) this can't be correct for extensions | 574 // TODO(erikkay) this can't be correct for extensions |
| 575 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 575 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
| 576 RegisterAppPrefs(app_name); | 576 RegisterAppPrefs(app_name); |
| 577 | 577 |
| 578 bool as_panel = extension && (container == Extension::LAUNCH_PANEL); | 578 bool as_panel = extension && (container == Extension::LAUNCH_PANEL); |
| 579 Browser* browser = Browser::CreateForApp(app_name, extension, profile, | 579 Browser* local_browser = Browser::CreateForApp(app_name, extension, profile, |
| 580 as_panel); | 580 as_panel); |
| 581 TabContents* tab_contents = browser->AddTabWithURL( | 581 TabContents* tab_contents = local_browser->AddTabWithURL( |
| 582 url, GURL(), PageTransition::START_PAGE, -1, TabStripModel::ADD_SELECTED, | 582 url, GURL(), PageTransition::START_PAGE, -1, TabStripModel::ADD_SELECTED, |
| 583 NULL, std::string()); | 583 NULL, std::string(), &local_browser); |
| 584 | 584 |
| 585 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 585 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 586 tab_contents->render_view_host()->SyncRendererPrefs(); | 586 tab_contents->render_view_host()->SyncRendererPrefs(); |
| 587 browser->window()->Show(); | 587 local_browser->window()->Show(); |
| 588 | 588 |
| 589 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 589 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 590 // focus explicitly. | 590 // focus explicitly. |
| 591 tab_contents->view()->SetInitialFocus(); | 591 tab_contents->view()->SetInitialFocus(); |
| 592 | 592 |
| 593 if (!as_panel) { | 593 if (!as_panel) { |
| 594 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked | 594 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 595 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | 595 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 596 // the web app info is available, TabContents notifies Browser via | 596 // the web app info is available, TabContents notifies Browser via |
| 597 // OnDidGetApplicationInfo, which calls | 597 // OnDidGetApplicationInfo, which calls |
| 598 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 598 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 599 // pending web app action. | 599 // pending web app action. |
| 600 browser->pending_web_app_action_ = UPDATE_SHORTCUT; | 600 local_browser->pending_web_app_action_ = UPDATE_SHORTCUT; |
| 601 } | 601 } |
| 602 | 602 |
| 603 if (browser) |
| 604 *browser = local_browser; |
| 605 |
| 603 return tab_contents; | 606 return tab_contents; |
| 604 } | 607 } |
| 605 | 608 |
| 606 // static | 609 // static |
| 607 TabContents* Browser::OpenApplicationWindow(Profile* profile, | 610 TabContents* Browser::OpenApplicationWindow(Profile* profile, |
| 608 GURL& url) { | 611 GURL& url, Browser** browser) { |
| 609 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url); | 612 return OpenApplicationWindow(profile, NULL, Extension::LAUNCH_WINDOW, url, |
| 613 browser); |
| 610 } | 614 } |
| 611 | 615 |
| 612 // static | 616 // static |
| 613 TabContents* Browser::OpenApplicationTab(Profile* profile, | 617 TabContents* Browser::OpenApplicationTab(Profile* profile, |
| 614 Extension* extension) { | 618 Extension* extension, |
| 615 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 619 Browser** browser) { |
| 616 if (!browser || browser->type() != Browser::TYPE_NORMAL) | 620 Browser* local_browser = BrowserList::GetLastActiveWithProfile(profile); |
| 621 if (!local_browser || local_browser->type() != Browser::TYPE_NORMAL) |
| 617 return NULL; | 622 return NULL; |
| 618 | 623 |
| 619 // TODO(erikkay): This doesn't seem like the right transition in all cases. | 624 // TODO(erikkay): This doesn't seem like the right transition in all cases. |
| 620 PageTransition::Type transition = PageTransition::START_PAGE; | 625 PageTransition::Type transition = PageTransition::START_PAGE; |
| 621 GURL url = extension->GetFullLaunchURL(); | 626 GURL url = extension->GetFullLaunchURL(); |
| 622 TabContents* tab_contents = | 627 TabContents* tab_contents = |
| 623 browser->CreateTabContentsForURL(url, GURL(), profile, | 628 local_browser->CreateTabContentsForURL(url, GURL(), profile, |
| 624 transition, false, NULL); | 629 transition, false, NULL); |
| 625 tab_contents->SetExtensionApp(extension); | 630 tab_contents->SetExtensionApp(extension); |
| 626 browser->AddTab(tab_contents, transition); | 631 local_browser->AddTab(tab_contents, transition); |
| 632 |
| 633 if (browser) |
| 634 *browser = local_browser; |
| 635 |
| 627 return tab_contents; | 636 return tab_contents; |
| 628 } | 637 } |
| 629 | 638 |
| 630 // static | 639 // static |
| 631 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 640 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 632 Browser* browser = Browser::Create(profile); | 641 Browser* browser = Browser::Create(profile); |
| 633 browser->ShowBookmarkManagerTab(); | 642 browser->ShowBookmarkManagerTab(); |
| 634 browser->window()->Show(); | 643 browser->window()->Show(); |
| 635 } | 644 } |
| 636 | 645 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 return (tabstrip_model_.insertion_policy() == TabStripModel::INSERT_AFTER) ? | 879 return (tabstrip_model_.insertion_policy() == TabStripModel::INSERT_AFTER) ? |
| 871 tab_count() : relative_index; | 880 tab_count() : relative_index; |
| 872 } | 881 } |
| 873 | 882 |
| 874 TabContents* Browser::AddTabWithURL(const GURL& url, | 883 TabContents* Browser::AddTabWithURL(const GURL& url, |
| 875 const GURL& referrer, | 884 const GURL& referrer, |
| 876 PageTransition::Type transition, | 885 PageTransition::Type transition, |
| 877 int index, | 886 int index, |
| 878 int add_types, | 887 int add_types, |
| 879 SiteInstance* instance, | 888 SiteInstance* instance, |
| 880 const std::string& extension_app_id) { | 889 const std::string& extension_app_id, |
| 890 Browser** browser_used) { |
| 881 TabContents* contents = NULL; | 891 TabContents* contents = NULL; |
| 882 if (CanSupportWindowFeature(FEATURE_TABSTRIP) || tabstrip_model()->empty()) { | 892 if (CanSupportWindowFeature(FEATURE_TABSTRIP) || tabstrip_model()->empty()) { |
| 883 GURL url_to_load = url; | 893 GURL url_to_load = url; |
| 884 if (url_to_load.is_empty()) | 894 if (url_to_load.is_empty()) |
| 885 url_to_load = GetHomePage(); | 895 url_to_load = GetHomePage(); |
| 886 contents = CreateTabContentsForURL(url_to_load, referrer, profile_, | 896 contents = CreateTabContentsForURL(url_to_load, referrer, profile_, |
| 887 transition, false, instance); | 897 transition, false, instance); |
| 888 contents->SetExtensionAppById(extension_app_id); | 898 contents->SetExtensionAppById(extension_app_id); |
| 889 tabstrip_model_.AddTabContents(contents, index, transition, add_types); | 899 tabstrip_model_.AddTabContents(contents, index, transition, add_types); |
| 890 // TODO(sky): figure out why this is needed. Without it we seem to get | 900 // TODO(sky): figure out why this is needed. Without it we seem to get |
| 891 // failures in startup tests. | 901 // failures in startup tests. |
| 892 // By default, content believes it is not hidden. When adding contents | 902 // By default, content believes it is not hidden. When adding contents |
| 893 // in the background, tell it that it's hidden. | 903 // in the background, tell it that it's hidden. |
| 894 if ((add_types & TabStripModel::ADD_SELECTED) == 0) { | 904 if ((add_types & TabStripModel::ADD_SELECTED) == 0) { |
| 895 // TabStripModel::AddTabContents invokes HideContents if not foreground. | 905 // TabStripModel::AddTabContents invokes HideContents if not foreground. |
| 896 contents->WasHidden(); | 906 contents->WasHidden(); |
| 897 } | 907 } |
| 908 |
| 909 if (browser_used) |
| 910 *browser_used = this; |
| 898 } else { | 911 } else { |
| 899 // We're in an app window or a popup window. Find an existing browser to | 912 // We're in an app window or a popup window. Find an existing browser to |
| 900 // open this URL in, creating one if none exists. | 913 // open this URL in, creating one if none exists. |
| 901 Browser* b = BrowserList::FindBrowserWithFeature(profile_, | 914 Browser* b = BrowserList::FindBrowserWithFeature(profile_, |
| 902 FEATURE_TABSTRIP); | 915 FEATURE_TABSTRIP); |
| 903 if (!b) | 916 if (!b) |
| 904 b = Browser::Create(profile_); | 917 b = Browser::Create(profile_); |
| 905 contents = b->AddTabWithURL(url, referrer, transition, index, add_types, | 918 contents = b->AddTabWithURL(url, referrer, transition, index, add_types, |
| 906 instance, extension_app_id); | 919 instance, extension_app_id, &b); |
| 907 b->window()->Show(); | 920 b->window()->Show(); |
| 921 |
| 922 if (browser_used) |
| 923 *browser_used = b; |
| 908 } | 924 } |
| 909 return contents; | 925 return contents; |
| 910 } | 926 } |
| 911 | 927 |
| 912 TabContents* Browser::AddTab(TabContents* tab_contents, | 928 TabContents* Browser::AddTab(TabContents* tab_contents, |
| 913 PageTransition::Type type) { | 929 PageTransition::Type type) { |
| 914 tabstrip_model_.AddTabContents( | 930 tabstrip_model_.AddTabContents( |
| 915 tab_contents, -1, type, TabStripModel::ADD_SELECTED); | 931 tab_contents, -1, type, TabStripModel::ADD_SELECTED); |
| 916 return tab_contents; | 932 return tab_contents; |
| 917 } | 933 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); | 1041 TabContents* tc = tabstrip_model_.GetTabContentsAt(i); |
| 1026 if (CompareURLsIgnoreRef(tc->GetURL(), url) || | 1042 if (CompareURLsIgnoreRef(tc->GetURL(), url) || |
| 1027 CompareURLsIgnoreRef(tc->GetURL(), rewritten_url)) { | 1043 CompareURLsIgnoreRef(tc->GetURL(), rewritten_url)) { |
| 1028 tabstrip_model_.SelectTabContentsAt(i, false); | 1044 tabstrip_model_.SelectTabContentsAt(i, false); |
| 1029 return; | 1045 return; |
| 1030 } | 1046 } |
| 1031 } | 1047 } |
| 1032 | 1048 |
| 1033 // Otherwise, just create a new tab. | 1049 // Otherwise, just create a new tab. |
| 1034 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, -1, | 1050 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, -1, |
| 1035 TabStripModel::ADD_SELECTED, NULL, std::string()); | 1051 TabStripModel::ADD_SELECTED, NULL, std::string(), NULL); |
| 1036 } | 1052 } |
| 1037 | 1053 |
| 1038 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { | 1054 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| 1039 #if !defined(OS_MACOSX) | 1055 #if !defined(OS_MACOSX) |
| 1040 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; | 1056 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; |
| 1041 #else | 1057 #else |
| 1042 const bool show_main_ui = (type() == TYPE_NORMAL); | 1058 const bool show_main_ui = (type() == TYPE_NORMAL); |
| 1043 #endif | 1059 #endif |
| 1044 | 1060 |
| 1045 bool main_not_fullscreen_or_popup = | 1061 bool main_not_fullscreen_or_popup = |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 } | 1846 } |
| 1831 | 1847 |
| 1832 void Browser::OpenUpdateChromeDialog() { | 1848 void Browser::OpenUpdateChromeDialog() { |
| 1833 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); | 1849 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); |
| 1834 window_->ShowUpdateChromeDialog(); | 1850 window_->ShowUpdateChromeDialog(); |
| 1835 } | 1851 } |
| 1836 | 1852 |
| 1837 void Browser::OpenHelpTab() { | 1853 void Browser::OpenHelpTab() { |
| 1838 GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kHelpContentUrl)); | 1854 GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kHelpContentUrl)); |
| 1839 AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, -1, | 1855 AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, -1, |
| 1840 TabStripModel::ADD_SELECTED, NULL, std::string()); | 1856 TabStripModel::ADD_SELECTED, NULL, std::string(), NULL); |
| 1841 } | 1857 } |
| 1842 | 1858 |
| 1843 void Browser::OpenThemeGalleryTabAndActivate() { | 1859 void Browser::OpenThemeGalleryTabAndActivate() { |
| 1844 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), | 1860 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 1845 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1861 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 1846 window_->Activate(); | 1862 window_->Activate(); |
| 1847 } | 1863 } |
| 1848 | 1864 |
| 1849 void Browser::OpenPrivacyDashboardTabAndActivate() { | 1865 void Browser::OpenPrivacyDashboardTabAndActivate() { |
| 1850 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_PRIVACY_DASHBOARD_URL)), | 1866 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_PRIVACY_DASHBOARD_URL)), |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2182 } | 2198 } |
| 2183 | 2199 |
| 2184 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { | 2200 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { |
| 2185 // Time new tab page creation time. We keep track of the timing data in | 2201 // Time new tab page creation time. We keep track of the timing data in |
| 2186 // TabContents, but we want to include the time it takes to create the | 2202 // TabContents, but we want to include the time it takes to create the |
| 2187 // TabContents object too. | 2203 // TabContents object too. |
| 2188 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); | 2204 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
| 2189 TabContents* tab_contents = AddTabWithURL( | 2205 TabContents* tab_contents = AddTabWithURL( |
| 2190 GURL(chrome::kChromeUINewTabURL), GURL(), PageTransition::TYPED, index, | 2206 GURL(chrome::kChromeUINewTabURL), GURL(), PageTransition::TYPED, index, |
| 2191 foreground ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE, NULL, | 2207 foreground ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE, NULL, |
| 2192 std::string()); | 2208 std::string(), NULL); |
| 2193 tab_contents->set_new_tab_start_time(new_tab_start_time); | 2209 tab_contents->set_new_tab_start_time(new_tab_start_time); |
| 2194 return tab_contents; | 2210 return tab_contents; |
| 2195 } | 2211 } |
| 2196 | 2212 |
| 2197 Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, | 2213 Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, |
| 2198 const gfx::Rect& window_bounds, | 2214 const gfx::Rect& window_bounds, |
| 2199 const DockInfo& dock_info, | 2215 const DockInfo& dock_info, |
| 2200 bool maximize) { | 2216 bool maximize) { |
| 2201 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); | 2217 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
| 2202 | 2218 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 TabCloseableStateWatcher* watcher = | 2388 TabCloseableStateWatcher* watcher = |
| 2373 g_browser_process->tab_closeable_state_watcher(); | 2389 g_browser_process->tab_closeable_state_watcher(); |
| 2374 return !watcher || watcher->CanCloseTab(this); | 2390 return !watcher || watcher->CanCloseTab(this); |
| 2375 } | 2391 } |
| 2376 | 2392 |
| 2377 void Browser::ToggleUseVerticalTabs() { | 2393 void Browser::ToggleUseVerticalTabs() { |
| 2378 use_vertical_tabs_.SetValue(!UseVerticalTabs()); | 2394 use_vertical_tabs_.SetValue(!UseVerticalTabs()); |
| 2379 UseVerticalTabsChanged(); | 2395 UseVerticalTabsChanged(); |
| 2380 } | 2396 } |
| 2381 | 2397 |
| 2398 bool Browser::LargeIconsPermitted() const { |
| 2399 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 2400 // for those windows, we already have a big icon in the top-left outside any |
| 2401 // tab. Having big tab icons too looks kinda redonk. |
| 2402 return TYPE_EXTENSION_APP != type(); |
| 2403 } |
| 2404 |
| 2382 /////////////////////////////////////////////////////////////////////////////// | 2405 /////////////////////////////////////////////////////////////////////////////// |
| 2383 // Browser, TabStripModelObserver implementation: | 2406 // Browser, TabStripModelObserver implementation: |
| 2384 | 2407 |
| 2385 void Browser::TabInsertedAt(TabContents* contents, | 2408 void Browser::TabInsertedAt(TabContents* contents, |
| 2386 int index, | 2409 int index, |
| 2387 bool foreground) { | 2410 bool foreground) { |
| 2388 contents->set_delegate(this); | 2411 contents->set_delegate(this); |
| 2389 contents->controller().SetWindowID(session_id()); | 2412 contents->controller().SetWindowID(session_id()); |
| 2390 | 2413 |
| 2391 SyncHistoryWithTabs(index); | 2414 SyncHistoryWithTabs(index); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2937 break; | 2960 break; |
| 2938 } | 2961 } |
| 2939 default: | 2962 default: |
| 2940 NOTREACHED(); | 2963 NOTREACHED(); |
| 2941 break; | 2964 break; |
| 2942 } | 2965 } |
| 2943 | 2966 |
| 2944 pending_web_app_action_ = NONE; | 2967 pending_web_app_action_ = NONE; |
| 2945 } | 2968 } |
| 2946 | 2969 |
| 2947 Browser* Browser::GetBrowser() { | |
| 2948 return this; | |
| 2949 } | |
| 2950 | |
| 2951 void Browser::ContentTypeChanged(TabContents* source) { | 2970 void Browser::ContentTypeChanged(TabContents* source) { |
| 2952 if (source == GetSelectedTabContents()) | 2971 if (source == GetSelectedTabContents()) |
| 2953 UpdateZoomCommandsForTabState(); | 2972 UpdateZoomCommandsForTabState(); |
| 2954 } | 2973 } |
| 2955 | 2974 |
| 2956 void Browser::CommitMatchPreview(TabContents* source) { | 2975 void Browser::CommitMatchPreview(TabContents* source) { |
| 2957 int index = tabstrip_model_.GetIndexOfTabContents(source); | 2976 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 2958 DCHECK_NE(-1, index); | 2977 DCHECK_NE(-1, index); |
| 2959 TabContents* preview_contents = | 2978 TabContents* preview_contents = |
| 2960 source->match_preview()->ReleasePreviewContents(); | 2979 source->match_preview()->ReleasePreviewContents(); |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3751 (*iter)->window()->Show(); | 3770 (*iter)->window()->Show(); |
| 3752 return true; | 3771 return true; |
| 3753 } | 3772 } |
| 3754 } | 3773 } |
| 3755 | 3774 |
| 3756 // If the extension wants to be opened in a window, but there is no | 3775 // If the extension wants to be opened in a window, but there is no |
| 3757 // existing window, create one, then open the URL there. | 3776 // existing window, create one, then open the URL there. |
| 3758 if (destination_extension->launch_container() == | 3777 if (destination_extension->launch_container() == |
| 3759 Extension::LAUNCH_WINDOW) { | 3778 Extension::LAUNCH_WINDOW) { |
| 3760 Browser::OpenApplicationWindow(profile_, destination_extension, | 3779 Browser::OpenApplicationWindow(profile_, destination_extension, |
| 3761 Extension::LAUNCH_WINDOW, url); | 3780 Extension::LAUNCH_WINDOW, url, NULL); |
| 3762 return true; | 3781 return true; |
| 3763 } | 3782 } |
| 3764 } | 3783 } |
| 3765 | 3784 |
| 3766 // Otherwise, we are opening a normal web page. | 3785 // Otherwise, we are opening a normal web page. |
| 3767 // | 3786 // |
| 3768 // If our source tab is in an app window, we don't want to open the tab | 3787 // If our source tab is in an app window, we don't want to open the tab |
| 3769 // there. Find a normal browser to open it in. | 3788 // there. Find a normal browser to open it in. |
| 3770 if (extension_app_) { | 3789 if (extension_app_) { |
| 3771 Browser* browser = GetOrCreateTabbedBrowser(profile_); | 3790 Browser* browser = GetOrCreateTabbedBrowser(profile_); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3905 if (profile_->IsOffTheRecord() && disposition == OFF_THE_RECORD) | 3924 if (profile_->IsOffTheRecord() && disposition == OFF_THE_RECORD) |
| 3906 disposition = NEW_FOREGROUND_TAB; | 3925 disposition = NEW_FOREGROUND_TAB; |
| 3907 | 3926 |
| 3908 if (disposition == SINGLETON_TAB) { | 3927 if (disposition == SINGLETON_TAB) { |
| 3909 ShowSingletonTab(url); | 3928 ShowSingletonTab(url); |
| 3910 return; | 3929 return; |
| 3911 } else if (disposition == NEW_WINDOW) { | 3930 } else if (disposition == NEW_WINDOW) { |
| 3912 Browser* browser = Browser::Create(profile_); | 3931 Browser* browser = Browser::Create(profile_); |
| 3913 new_contents = browser->AddTabWithURL( | 3932 new_contents = browser->AddTabWithURL( |
| 3914 url, referrer, transition, index, | 3933 url, referrer, transition, index, |
| 3915 TabStripModel::ADD_SELECTED | add_types, instance, std::string()); | 3934 TabStripModel::ADD_SELECTED | add_types, instance, std::string(), |
| 3935 &browser); |
| 3916 browser->window()->Show(); | 3936 browser->window()->Show(); |
| 3917 } else if ((disposition == CURRENT_TAB) && current_tab) { | 3937 } else if ((disposition == CURRENT_TAB) && current_tab) { |
| 3918 tabstrip_model_.TabNavigating(current_tab, transition); | 3938 tabstrip_model_.TabNavigating(current_tab, transition); |
| 3919 | 3939 |
| 3920 bool user_initiated = (PageTransition::StripQualifier(transition) == | 3940 bool user_initiated = (PageTransition::StripQualifier(transition) == |
| 3921 PageTransition::AUTO_BOOKMARK); | 3941 PageTransition::AUTO_BOOKMARK); |
| 3922 | 3942 |
| 3923 if (user_initiated && source_tab_was_frontmost && | 3943 if (user_initiated && source_tab_was_frontmost && |
| 3924 window_->GetLocationBar()) { | 3944 window_->GetLocationBar()) { |
| 3925 // Forcibly reset the location bar if the url is going to change in the | 3945 // Forcibly reset the location bar if the url is going to change in the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3940 // the throbber will show the default favicon for a split second when | 3960 // the throbber will show the default favicon for a split second when |
| 3941 // navigating away from the new tab page. | 3961 // navigating away from the new tab page. |
| 3942 ScheduleUIUpdate(current_tab, TabContents::INVALIDATE_URL); | 3962 ScheduleUIUpdate(current_tab, TabContents::INVALIDATE_URL); |
| 3943 } else if (disposition == OFF_THE_RECORD) { | 3963 } else if (disposition == OFF_THE_RECORD) { |
| 3944 OpenURLOffTheRecord(profile_, url); | 3964 OpenURLOffTheRecord(profile_, url); |
| 3945 return; | 3965 return; |
| 3946 } else if (disposition != SUPPRESS_OPEN) { | 3966 } else if (disposition != SUPPRESS_OPEN) { |
| 3947 if (disposition != NEW_BACKGROUND_TAB) | 3967 if (disposition != NEW_BACKGROUND_TAB) |
| 3948 add_types |= TabStripModel::ADD_SELECTED; | 3968 add_types |= TabStripModel::ADD_SELECTED; |
| 3949 new_contents = AddTabWithURL(url, referrer, transition, index, add_types, | 3969 new_contents = AddTabWithURL(url, referrer, transition, index, add_types, |
| 3950 instance, std::string()); | 3970 instance, std::string(), NULL); |
| 3951 } | 3971 } |
| 3952 | 3972 |
| 3953 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost && | 3973 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost && |
| 3954 new_contents) { | 3974 new_contents) { |
| 3955 // Give the focus to the newly navigated tab, if the source tab was | 3975 // Give the focus to the newly navigated tab, if the source tab was |
| 3956 // front-most. | 3976 // front-most. |
| 3957 new_contents->Focus(); | 3977 new_contents->Focus(); |
| 3958 } | 3978 } |
| 3959 } | 3979 } |
| 3960 | 3980 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4098 } | 4118 } |
| 4099 | 4119 |
| 4100 bool Browser::IsPinned(TabContents* source) { | 4120 bool Browser::IsPinned(TabContents* source) { |
| 4101 int index = tabstrip_model_.GetIndexOfTabContents(source); | 4121 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 4102 if (index == TabStripModel::kNoTab) { | 4122 if (index == TabStripModel::kNoTab) { |
| 4103 NOTREACHED() << "IsPinned called for tab not in our strip"; | 4123 NOTREACHED() << "IsPinned called for tab not in our strip"; |
| 4104 return false; | 4124 return false; |
| 4105 } | 4125 } |
| 4106 return tabstrip_model_.IsTabPinned(index); | 4126 return tabstrip_model_.IsTabPinned(index); |
| 4107 } | 4127 } |
| OLD | NEW |