Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_tabstrip.h" | 5 #include "chrome/browser/ui/browser_tabstrip.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "chrome/browser/ui/browser_navigator_params.h" | 11 #include "chrome/browser/ui/browser_navigator_params.h" |
| 12 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 12 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 | 19 |
| 20 namespace chrome { | 20 namespace chrome { |
| 21 | 21 |
| 22 void AddTabAt(Browser* browser, const GURL& url, int idx, bool foreground) { | 22 void AddTabAt(Browser* browser, const GURL& url, int idx, bool foreground) { |
| 23 // Time new tab page creation time. We keep track of the timing data in | 23 // Time new tab page creation time. We keep track of the timing data in |
| 24 // WebContents, but we want to include the time it takes to create the | 24 // WebContents, but we want to include the time it takes to create the |
| 25 // WebContents object too. | 25 // WebContents object too. |
| 26 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); | 26 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
| 27 bool show_ntp = url.is_empty(); | |
| 27 chrome::NavigateParams params(browser, | 28 chrome::NavigateParams params(browser, |
| 28 url.is_empty() ? GURL(chrome::kChromeUINewTabURL) : url, | 29 show_ntp ? GURL(chrome::kChromeUINewTabURL) : url, |
| 29 ui::PAGE_TRANSITION_TYPED); | 30 show_ntp ? ui::PAGE_TRANSITION_AUTO_TOPLEVEL : ui::PAGE_TRANSITION_TYPED); |
| 30 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 31 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 31 params.tabstrip_index = idx; | 32 params.tabstrip_index = idx; |
| 33 // Explicitly ensure new tabs will return to the previous focused tabs when | |
|
msw
2016/02/02 01:57:46
nit: "Ensure the previously active tab regains foc
| |
| 34 // closed. | |
| 35 if (show_ntp) | |
|
msw
2016/02/02 01:57:46
Why is this only applied if |show_ntp| is true? (d
| |
| 36 params.tabstrip_add_types |= TabStripModel::ADD_INHERIT_GROUP; | |
| 37 | |
| 32 chrome::Navigate(¶ms); | 38 chrome::Navigate(¶ms); |
| 33 CoreTabHelper* core_tab_helper = | 39 CoreTabHelper* core_tab_helper = |
| 34 CoreTabHelper::FromWebContents(params.target_contents); | 40 CoreTabHelper::FromWebContents(params.target_contents); |
| 35 core_tab_helper->set_new_tab_start_time(new_tab_start_time); | 41 core_tab_helper->set_new_tab_start_time(new_tab_start_time); |
| 36 } | 42 } |
| 37 | 43 |
| 38 content::WebContents* AddSelectedTabWithURL( | 44 content::WebContents* AddSelectedTabWithURL( |
| 39 Browser* browser, | 45 Browser* browser, |
| 40 const GURL& url, | 46 const GURL& url, |
| 41 ui::PageTransition transition) { | 47 ui::PageTransition transition) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 return; | 84 return; |
| 79 } | 85 } |
| 80 | 86 |
| 81 browser->tab_strip_model()->CloseWebContentsAt( | 87 browser->tab_strip_model()->CloseWebContentsAt( |
| 82 index, | 88 index, |
| 83 add_to_history ? TabStripModel::CLOSE_CREATE_HISTORICAL_TAB | 89 add_to_history ? TabStripModel::CLOSE_CREATE_HISTORICAL_TAB |
| 84 : TabStripModel::CLOSE_NONE); | 90 : TabStripModel::CLOSE_NONE); |
| 85 } | 91 } |
| 86 | 92 |
| 87 } // namespace chrome | 93 } // namespace chrome |
| OLD | NEW |