OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include "app/animation.h" | 7 #include "app/animation.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/idle_timer.h" | 10 #include "base/idle_timer.h" |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 transition, false, instance); | 573 transition, false, instance); |
574 tabstrip_model_.AddTabContents(contents, index, force_index, | 574 tabstrip_model_.AddTabContents(contents, index, force_index, |
575 transition, foreground); | 575 transition, foreground); |
576 // By default, content believes it is not hidden. When adding contents | 576 // By default, content believes it is not hidden. When adding contents |
577 // in the background, tell it that it's hidden. | 577 // in the background, tell it that it's hidden. |
578 if (!foreground) | 578 if (!foreground) |
579 contents->WasHidden(); | 579 contents->WasHidden(); |
580 } else { | 580 } else { |
581 // We're in an app window or a popup window. Find an existing browser to | 581 // We're in an app window or a popup window. Find an existing browser to |
582 // open this URL in, creating one if none exists. | 582 // open this URL in, creating one if none exists. |
583 Browser* b = GetOrCreateTabbedBrowser(); | 583 Browser* b = GetOrCreateTabbedBrowser(profile_); |
584 contents = b->AddTabWithURL(url, referrer, transition, foreground, index, | 584 contents = b->AddTabWithURL(url, referrer, transition, foreground, index, |
585 force_index, instance); | 585 force_index, instance); |
586 b->window()->Show(); | 586 b->window()->Show(); |
587 } | 587 } |
588 return contents; | 588 return contents; |
589 } | 589 } |
590 | 590 |
591 // TODO(brettw) this should be just AddTab and it should take a TabContents. | 591 // TODO(brettw) this should be just AddTab and it should take a TabContents. |
592 TabContents* Browser::AddTabWithNavigationController( | 592 TabContents* Browser::AddTabWithNavigationController( |
593 NavigationController* ctrl, PageTransition::Type type) { | 593 NavigationController* ctrl, PageTransition::Type type) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 void Browser::CloseWindow() { | 825 void Browser::CloseWindow() { |
826 UserMetrics::RecordAction(L"CloseWindow", profile_); | 826 UserMetrics::RecordAction(L"CloseWindow", profile_); |
827 window_->Close(); | 827 window_->Close(); |
828 } | 828 } |
829 | 829 |
830 void Browser::NewTab() { | 830 void Browser::NewTab() { |
831 UserMetrics::RecordAction(L"NewTab", profile_); | 831 UserMetrics::RecordAction(L"NewTab", profile_); |
832 if (type() == TYPE_NORMAL) { | 832 if (type() == TYPE_NORMAL) { |
833 AddBlankTab(true); | 833 AddBlankTab(true); |
834 } else { | 834 } else { |
835 Browser* b = GetOrCreateTabbedBrowser(); | 835 Browser* b = GetOrCreateTabbedBrowser(profile_); |
836 b->AddBlankTab(true); | 836 b->AddBlankTab(true); |
837 b->window()->Show(); | 837 b->window()->Show(); |
838 // The call to AddBlankTab above did not set the focus to the tab as its | 838 // The call to AddBlankTab above did not set the focus to the tab as its |
839 // window was not active, so we have to do it explicitly. | 839 // window was not active, so we have to do it explicitly. |
840 // See http://crbug.com/6380. | 840 // See http://crbug.com/6380. |
841 b->GetSelectedTabContents()->view()->RestoreFocus(); | 841 b->GetSelectedTabContents()->view()->RestoreFocus(); |
842 } | 842 } |
843 } | 843 } |
844 | 844 |
845 void Browser::CloseTab() { | 845 void Browser::CloseTab() { |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 bool user_gesture) { | 1772 bool user_gesture) { |
1773 DCHECK(disposition != SAVE_TO_DISK); // No code for this yet | 1773 DCHECK(disposition != SAVE_TO_DISK); // No code for this yet |
1774 DCHECK(disposition != CURRENT_TAB); // Can't create a new contents for the | 1774 DCHECK(disposition != CURRENT_TAB); // Can't create a new contents for the |
1775 // current tab. | 1775 // current tab. |
1776 | 1776 |
1777 // If this is an application we can only have one tab so we need to process | 1777 // If this is an application we can only have one tab so we need to process |
1778 // this in tabbed browser window. | 1778 // this in tabbed browser window. |
1779 if (tabstrip_model_.count() > 0 && | 1779 if (tabstrip_model_.count() > 0 && |
1780 disposition != NEW_WINDOW && disposition != NEW_POPUP && | 1780 disposition != NEW_WINDOW && disposition != NEW_POPUP && |
1781 type_ != TYPE_NORMAL) { | 1781 type_ != TYPE_NORMAL) { |
1782 Browser* b = GetOrCreateTabbedBrowser(); | 1782 Browser* b = GetOrCreateTabbedBrowser(profile_); |
1783 DCHECK(b); | 1783 DCHECK(b); |
1784 PageTransition::Type transition = PageTransition::LINK; | 1784 PageTransition::Type transition = PageTransition::LINK; |
1785 // If we were called from an "installed webapp" we want to emulate the code | 1785 // If we were called from an "installed webapp" we want to emulate the code |
1786 // that is run from browser_init.cc for links from external applications. | 1786 // that is run from browser_init.cc for links from external applications. |
1787 // This means we need to open the tab with the START PAGE transition. | 1787 // This means we need to open the tab with the START PAGE transition. |
1788 // AddNewContents doesn't support this but the TabStripModel's | 1788 // AddNewContents doesn't support this but the TabStripModel's |
1789 // AddTabContents method does. | 1789 // AddTabContents method does. |
1790 if (type_ & TYPE_APP) | 1790 if (type_ & TYPE_APP) |
1791 transition = PageTransition::START_PAGE; | 1791 transition = PageTransition::START_PAGE; |
1792 b->tabstrip_model()->AddTabContents(new_contents, -1, false, transition, | 1792 b->tabstrip_model()->AddTabContents(new_contents, -1, false, transition, |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2578 window_->ConfirmBrowserCloseWithPendingDownloads(); | 2578 window_->ConfirmBrowserCloseWithPendingDownloads(); |
2579 | 2579 |
2580 // Return false so the browser does not close. We'll close if the user | 2580 // Return false so the browser does not close. We'll close if the user |
2581 // confirms in the dialog. | 2581 // confirms in the dialog. |
2582 return false; | 2582 return false; |
2583 } | 2583 } |
2584 | 2584 |
2585 /////////////////////////////////////////////////////////////////////////////// | 2585 /////////////////////////////////////////////////////////////////////////////// |
2586 // Browser, Assorted utility functions (private): | 2586 // Browser, Assorted utility functions (private): |
2587 | 2587 |
2588 Browser* Browser::GetOrCreateTabbedBrowser() { | 2588 // static |
| 2589 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
2589 Browser* browser = BrowserList::FindBrowserWithType( | 2590 Browser* browser = BrowserList::FindBrowserWithType( |
2590 profile_, TYPE_NORMAL); | 2591 profile, TYPE_NORMAL); |
2591 if (!browser) | 2592 if (!browser) |
2592 browser = Browser::Create(profile_); | 2593 browser = Browser::Create(profile); |
2593 return browser; | 2594 return browser; |
2594 } | 2595 } |
2595 | 2596 |
2596 void Browser::OpenURLAtIndex(TabContents* source, | 2597 void Browser::OpenURLAtIndex(TabContents* source, |
2597 const GURL& url, | 2598 const GURL& url, |
2598 const GURL& referrer, | 2599 const GURL& referrer, |
2599 WindowOpenDisposition disposition, | 2600 WindowOpenDisposition disposition, |
2600 PageTransition::Type transition, | 2601 PageTransition::Type transition, |
2601 int index, | 2602 int index, |
2602 bool force_index) { | 2603 bool force_index) { |
(...skipping 27 matching lines...) Expand all Loading... |
2630 // only have one tab so a new tab always goes into a tabbed browser window. | 2631 // only have one tab so a new tab always goes into a tabbed browser window. |
2631 if (disposition != NEW_WINDOW && type_ != TYPE_NORMAL) { | 2632 if (disposition != NEW_WINDOW && type_ != TYPE_NORMAL) { |
2632 // If the disposition is OFF_THE_RECORD we don't want to create a new | 2633 // If the disposition is OFF_THE_RECORD we don't want to create a new |
2633 // browser that will itself create another OTR browser. This will result in | 2634 // browser that will itself create another OTR browser. This will result in |
2634 // a browser leak (and crash below because no tab is created or selected). | 2635 // a browser leak (and crash below because no tab is created or selected). |
2635 if (disposition == OFF_THE_RECORD) { | 2636 if (disposition == OFF_THE_RECORD) { |
2636 OpenURLOffTheRecord(profile_, url); | 2637 OpenURLOffTheRecord(profile_, url); |
2637 return; | 2638 return; |
2638 } | 2639 } |
2639 | 2640 |
2640 Browser* b = GetOrCreateTabbedBrowser(); | 2641 Browser* b = GetOrCreateTabbedBrowser(profile_); |
2641 DCHECK(b); | 2642 DCHECK(b); |
2642 | 2643 |
2643 // If we have just created a new browser window, make sure we select the | 2644 // If we have just created a new browser window, make sure we select the |
2644 // tab. | 2645 // tab. |
2645 if (b->tab_count() == 0 && disposition == NEW_BACKGROUND_TAB) | 2646 if (b->tab_count() == 0 && disposition == NEW_BACKGROUND_TAB) |
2646 disposition = NEW_FOREGROUND_TAB; | 2647 disposition = NEW_FOREGROUND_TAB; |
2647 | 2648 |
2648 b->OpenURL(url, referrer, disposition, transition); | 2649 b->OpenURL(url, referrer, disposition, transition); |
2649 b->window()->Show(); | 2650 b->window()->Show(); |
2650 return; | 2651 return; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2776 /////////////////////////////////////////////////////////////////////////////// | 2777 /////////////////////////////////////////////////////////////////////////////// |
2777 // BrowserToolbarModel (private): | 2778 // BrowserToolbarModel (private): |
2778 | 2779 |
2779 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2780 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
2780 // This |current_tab| can be NULL during the initialization of the | 2781 // This |current_tab| can be NULL during the initialization of the |
2781 // toolbar during window creation (i.e. before any tabs have been added | 2782 // toolbar during window creation (i.e. before any tabs have been added |
2782 // to the window). | 2783 // to the window). |
2783 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2784 TabContents* current_tab = browser_->GetSelectedTabContents(); |
2784 return current_tab ? ¤t_tab->controller() : NULL; | 2785 return current_tab ? ¤t_tab->controller() : NULL; |
2785 } | 2786 } |
OLD | NEW |