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 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2085 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: | 2085 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
2086 | 2086 |
2087 void Browser::ExecuteCommand(int id) { | 2087 void Browser::ExecuteCommand(int id) { |
2088 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 2088 ExecuteCommandWithDisposition(id, CURRENT_TAB); |
2089 } | 2089 } |
2090 | 2090 |
2091 /////////////////////////////////////////////////////////////////////////////// | 2091 /////////////////////////////////////////////////////////////////////////////// |
2092 // Browser, TabStripModelDelegate implementation: | 2092 // Browser, TabStripModelDelegate implementation: |
2093 | 2093 |
2094 TabContents* Browser::AddBlankTab(bool foreground) { | 2094 TabContents* Browser::AddBlankTab(bool foreground) { |
| 2095 // To make a more "launchy" experience, try to reuse an existing NTP if there |
| 2096 // is one. |
| 2097 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2098 switches::kEnableExtensionApps)) { |
| 2099 for (int i = tabstrip_model_.count() - 1; i >= 0; --i) { |
| 2100 TabContents* contents = tabstrip_model_.GetTabContentsAt(i); |
| 2101 if (StartsWithASCII(contents->GetURL().spec(), |
| 2102 chrome::kChromeUINewTabURL, true)) { |
| 2103 if (foreground) |
| 2104 SelectTabContentsAt(i, true); |
| 2105 |
| 2106 return contents; |
| 2107 } |
| 2108 } |
| 2109 } |
| 2110 |
2095 return AddBlankTabAt(-1, foreground); | 2111 return AddBlankTabAt(-1, foreground); |
2096 } | 2112 } |
2097 | 2113 |
2098 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { | 2114 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { |
2099 // Time new tab page creation time. We keep track of the timing data in | 2115 // Time new tab page creation time. We keep track of the timing data in |
2100 // TabContents, but we want to include the time it takes to create the | 2116 // TabContents, but we want to include the time it takes to create the |
2101 // TabContents object too. | 2117 // TabContents object too. |
2102 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); | 2118 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
2103 TabContents* tab_contents = AddTabWithURL( | 2119 TabContents* tab_contents = AddTabWithURL( |
2104 GURL(chrome::kChromeUINewTabURL), GURL(), PageTransition::TYPED, index, | 2120 GURL(chrome::kChromeUINewTabURL), GURL(), PageTransition::TYPED, index, |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3852 if (TabHasUnloadListener(contents)) { | 3868 if (TabHasUnloadListener(contents)) { |
3853 // If the page has unload listeners, then we tell the renderer to fire | 3869 // If the page has unload listeners, then we tell the renderer to fire |
3854 // them. Once they have fired, we'll get a message back saying whether | 3870 // them. Once they have fired, we'll get a message back saying whether |
3855 // to proceed closing the page or not, which sends us back to this method | 3871 // to proceed closing the page or not, which sends us back to this method |
3856 // with the HasUnloadListener bit cleared. | 3872 // with the HasUnloadListener bit cleared. |
3857 contents->render_view_host()->FirePageBeforeUnload(false); | 3873 contents->render_view_host()->FirePageBeforeUnload(false); |
3858 return true; | 3874 return true; |
3859 } | 3875 } |
3860 return false; | 3876 return false; |
3861 } | 3877 } |
OLD | NEW |