OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/idle_timer.h" | 6 #include "base/idle_timer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 : type_(type), | 156 : type_(type), |
157 profile_(profile), | 157 profile_(profile), |
158 window_(NULL), | 158 window_(NULL), |
159 tabstrip_model_(this, profile), | 159 tabstrip_model_(this, profile), |
160 command_updater_(this), | 160 command_updater_(this), |
161 toolbar_model_(this), | 161 toolbar_model_(this), |
162 chrome_updater_factory_(this), | 162 chrome_updater_factory_(this), |
163 is_attempting_to_close_browser_(false), | 163 is_attempting_to_close_browser_(false), |
164 override_maximized_(false), | 164 override_maximized_(false), |
165 method_factory_(this), | 165 method_factory_(this), |
166 idle_task_(new BrowserIdleTimer) { | 166 idle_task_(new BrowserIdleTimer), |
167 open_new_windows_in_default_browser_(false) { | |
167 tabstrip_model_.AddObserver(this); | 168 tabstrip_model_.AddObserver(this); |
168 | 169 |
169 NotificationService::current()->AddObserver( | 170 NotificationService::current()->AddObserver( |
170 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); | 171 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); |
171 | 172 |
172 InitCommandState(); | 173 InitCommandState(); |
173 BrowserList::AddBrowser(this); | 174 BrowserList::AddBrowser(this); |
174 | 175 |
175 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
176 // TODO(port): turn this back on when prefs are fleshed out. This asserts | 177 // TODO(port): turn this back on when prefs are fleshed out. This asserts |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 case IDC_NEW_WINDOW: NewWindow(); break; | 1103 case IDC_NEW_WINDOW: NewWindow(); break; |
1103 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; | 1104 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; |
1104 case IDC_NEW_WINDOW_PROFILE_0: | 1105 case IDC_NEW_WINDOW_PROFILE_0: |
1105 case IDC_NEW_WINDOW_PROFILE_1: | 1106 case IDC_NEW_WINDOW_PROFILE_1: |
1106 case IDC_NEW_WINDOW_PROFILE_2: | 1107 case IDC_NEW_WINDOW_PROFILE_2: |
1107 case IDC_NEW_WINDOW_PROFILE_3: | 1108 case IDC_NEW_WINDOW_PROFILE_3: |
1108 case IDC_NEW_WINDOW_PROFILE_4: | 1109 case IDC_NEW_WINDOW_PROFILE_4: |
1109 case IDC_NEW_WINDOW_PROFILE_5: | 1110 case IDC_NEW_WINDOW_PROFILE_5: |
1110 case IDC_NEW_WINDOW_PROFILE_6: | 1111 case IDC_NEW_WINDOW_PROFILE_6: |
1111 case IDC_NEW_WINDOW_PROFILE_7: | 1112 case IDC_NEW_WINDOW_PROFILE_7: |
1112 case IDC_NEW_WINDOW_PROFILE_8: | 1113 case IDC_NEW_WINDOW_PROFILE_8: |
1113 NewProfileWindowByIndex(id - IDC_NEW_WINDOW_PROFILE_0); break; | 1114 NewProfileWindowByIndex(id - IDC_NEW_WINDOW_PROFILE_0); break; |
1114 case IDC_CLOSE_WINDOW: CloseWindow(); break; | 1115 case IDC_CLOSE_WINDOW: CloseWindow(); break; |
1115 case IDC_NEW_TAB: NewTab(); break; | 1116 case IDC_NEW_TAB: NewTab(); break; |
1116 case IDC_CLOSE_TAB: CloseTab(); break; | 1117 case IDC_CLOSE_TAB: CloseTab(); break; |
1117 case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; | 1118 case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; |
1118 case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; | 1119 case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; |
1119 case IDC_SELECT_TAB_0: | 1120 case IDC_SELECT_TAB_0: |
1120 case IDC_SELECT_TAB_1: | 1121 case IDC_SELECT_TAB_1: |
1121 case IDC_SELECT_TAB_2: | 1122 case IDC_SELECT_TAB_2: |
1122 case IDC_SELECT_TAB_3: | 1123 case IDC_SELECT_TAB_3: |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1642 } | 1643 } |
1643 | 1644 |
1644 void Browser::AddNewContents(TabContents* source, | 1645 void Browser::AddNewContents(TabContents* source, |
1645 TabContents* new_contents, | 1646 TabContents* new_contents, |
1646 WindowOpenDisposition disposition, | 1647 WindowOpenDisposition disposition, |
1647 const gfx::Rect& initial_pos, | 1648 const gfx::Rect& initial_pos, |
1648 bool user_gesture) { | 1649 bool user_gesture) { |
1649 DCHECK(disposition != SAVE_TO_DISK); // No code for this yet | 1650 DCHECK(disposition != SAVE_TO_DISK); // No code for this yet |
1650 | 1651 |
1651 // If this is an application we can only have one tab so we need to process | 1652 // If this is an application we can only have one tab so we need to process |
1652 // this in tabbed browser window. | 1653 // this in tabbed browser window. The new window will act as an intermediary |
1653 if (tabstrip_model_.count() > 0 && | 1654 // to launch urls in the default browser. |
1655 if (tabstrip_model_.count() > 0 && // A launched application has count of 1. | |
1654 disposition != NEW_WINDOW && disposition != NEW_POPUP && | 1656 disposition != NEW_WINDOW && disposition != NEW_POPUP && |
1655 type_ != TYPE_NORMAL) { | 1657 type_ != TYPE_NORMAL) { |
1656 Browser* b = GetOrCreateTabbedBrowser(); | 1658 Browser* b = GetOrCreateTabbedBrowser(); |
1657 DCHECK(b); | 1659 DCHECK(b); |
1660 b->set_open_new_windows_in_default_browser(true); | |
Mark Larson
2009/01/23 07:02:33
When does this get unset?
| |
1658 PageTransition::Type transition = PageTransition::LINK; | 1661 PageTransition::Type transition = PageTransition::LINK; |
1659 // If we were called from an "installed webapp" we want to emulate the code | 1662 // If we were called from an "installed webapp" we want to emulate the code |
1660 // that is run from browser_init.cc for links from external applications. | 1663 // that is run from browser_init.cc for links from external applications. |
1661 // This means we need to open the tab with the START PAGE transition. | 1664 // This means we need to open the tab with the START PAGE transition. |
1662 // AddNewContents doesn't support this but the TabStripModel's | 1665 // AddNewContents doesn't support this but the TabStripModel's |
1663 // AddTabContents method does. | 1666 // AddTabContents method does. |
1664 if (type_ == TYPE_APP) | 1667 if (type_ == TYPE_APP) |
1665 transition = PageTransition::START_PAGE; | 1668 transition = PageTransition::START_PAGE; |
1666 b->tabstrip_model()->AddTabContents(new_contents, -1, transition, true); | 1669 b->tabstrip_model()->AddTabContents(new_contents, -1, transition, true); |
1667 b->window()->Show(); | 1670 |
1671 // All new windows from an "installed webapp" which must have their own | |
1672 // tabs will be launched in the default browser. At this moment the | |
1673 // url is inaccessbile and so we do not show the window until the url is | |
1674 // reported to the TabConentsDelegate. | |
1675 if (type_ != TYPE_APP) | |
1676 b->window()->Show(); | |
1668 return; | 1677 return; |
1669 } | 1678 } |
1670 | 1679 |
1671 if (disposition == NEW_POPUP) { | 1680 if (disposition == NEW_POPUP) { |
1672 BuildPopupWindow(source, new_contents, initial_pos); | 1681 BuildPopupWindow(source, new_contents, initial_pos); |
1673 } else if (disposition == NEW_WINDOW) { | 1682 } else if (disposition == NEW_WINDOW) { |
1674 Browser* browser = Browser::Create(profile_); | 1683 Browser* browser = Browser::Create(profile_); |
1675 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, | 1684 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, |
1676 initial_pos, user_gesture); | 1685 initial_pos, user_gesture); |
1677 browser->window()->Show(); | 1686 browser->window()->Show(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1767 } | 1776 } |
1768 | 1777 |
1769 void Browser::ContentsZoomChange(bool zoom_in) { | 1778 void Browser::ContentsZoomChange(bool zoom_in) { |
1770 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); | 1779 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
1771 } | 1780 } |
1772 | 1781 |
1773 bool Browser::IsApplication() const { | 1782 bool Browser::IsApplication() const { |
1774 return type_ == TYPE_APP; | 1783 return type_ == TYPE_APP; |
1775 } | 1784 } |
1776 | 1785 |
1786 bool Browser::ShouldOpenURLInDefaultBrowser() const { | |
1787 return open_new_windows_in_default_browser_; | |
1788 } | |
1789 | |
1777 void Browser::ConvertContentsToApplication(TabContents* contents) { | 1790 void Browser::ConvertContentsToApplication(TabContents* contents) { |
1778 WebContents* web_contents = contents->AsWebContents(); | 1791 WebContents* web_contents = contents->AsWebContents(); |
1779 if (!web_contents || !web_contents->web_app()) { | 1792 if (!web_contents || !web_contents->web_app()) { |
1780 NOTREACHED(); | 1793 NOTREACHED(); |
1781 return; | 1794 return; |
1782 } | 1795 } |
1783 | 1796 |
1784 int index = tabstrip_model_.GetIndexOfTabContents(contents); | 1797 int index = tabstrip_model_.GetIndexOfTabContents(contents); |
1785 if (index < 0) | 1798 if (index < 0) |
1786 return; | 1799 return; |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2413 std::wstring window_pref(prefs::kBrowserWindowPlacement); | 2426 std::wstring window_pref(prefs::kBrowserWindowPlacement); |
2414 window_pref.append(L"_"); | 2427 window_pref.append(L"_"); |
2415 window_pref.append(app_name); | 2428 window_pref.append(app_name); |
2416 PrefService* prefs = g_browser_process->local_state(); | 2429 PrefService* prefs = g_browser_process->local_state(); |
2417 DCHECK(prefs); | 2430 DCHECK(prefs); |
2418 | 2431 |
2419 prefs->RegisterDictionaryPref(window_pref.c_str()); | 2432 prefs->RegisterDictionaryPref(window_pref.c_str()); |
2420 } | 2433 } |
2421 | 2434 |
2422 #endif // OS_WIN | 2435 #endif // OS_WIN |
2436 | |
OLD | NEW |