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 chrome::NavigateParams params(browser, | 27 chrome::NavigateParams params(browser, |
28 url.is_empty() ? GURL(chrome::kChromeUINewTabURL) : url, | 28 url.is_empty() ? GURL(chrome::kChromeUINewTabURL) : url, |
29 ui::PAGE_TRANSITION_TYPED); | 29 ui::PAGE_TRANSITION_TYPED); |
30 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 30 params.disposition = foreground ? WindowOpenDisposition::NEW_FOREGROUND_TAB |
| 31 : WindowOpenDisposition::NEW_BACKGROUND_TAB; |
31 params.tabstrip_index = idx; | 32 params.tabstrip_index = idx; |
32 chrome::Navigate(¶ms); | 33 chrome::Navigate(¶ms); |
33 CoreTabHelper* core_tab_helper = | 34 CoreTabHelper* core_tab_helper = |
34 CoreTabHelper::FromWebContents(params.target_contents); | 35 CoreTabHelper::FromWebContents(params.target_contents); |
35 core_tab_helper->set_new_tab_start_time(new_tab_start_time); | 36 core_tab_helper->set_new_tab_start_time(new_tab_start_time); |
36 } | 37 } |
37 | 38 |
38 content::WebContents* AddSelectedTabWithURL( | 39 content::WebContents* AddSelectedTabWithURL( |
39 Browser* browser, | 40 Browser* browser, |
40 const GURL& url, | 41 const GURL& url, |
41 ui::PageTransition transition) { | 42 ui::PageTransition transition) { |
42 NavigateParams params(browser, url, transition); | 43 NavigateParams params(browser, url, transition); |
43 params.disposition = NEW_FOREGROUND_TAB; | 44 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
44 Navigate(¶ms); | 45 Navigate(¶ms); |
45 return params.target_contents; | 46 return params.target_contents; |
46 } | 47 } |
47 | 48 |
48 void AddWebContents(Browser* browser, | 49 void AddWebContents(Browser* browser, |
49 content::WebContents* source_contents, | 50 content::WebContents* source_contents, |
50 content::WebContents* new_contents, | 51 content::WebContents* new_contents, |
51 WindowOpenDisposition disposition, | 52 WindowOpenDisposition disposition, |
52 const gfx::Rect& initial_rect, | 53 const gfx::Rect& initial_rect, |
53 bool user_gesture, | 54 bool user_gesture, |
54 bool* was_blocked) { | 55 bool* was_blocked) { |
55 // No code for this yet. | 56 // No code for this yet. |
56 DCHECK(disposition != SAVE_TO_DISK); | 57 DCHECK(disposition != WindowOpenDisposition::SAVE_TO_DISK); |
57 // Can't create a new contents for the current tab - invalid case. | 58 // Can't create a new contents for the current tab - invalid case. |
58 DCHECK(disposition != CURRENT_TAB); | 59 DCHECK(disposition != WindowOpenDisposition::CURRENT_TAB); |
59 | 60 |
60 NavigateParams params(browser, new_contents); | 61 NavigateParams params(browser, new_contents); |
61 params.source_contents = source_contents; | 62 params.source_contents = source_contents; |
62 params.disposition = disposition; | 63 params.disposition = disposition; |
63 params.window_bounds = initial_rect; | 64 params.window_bounds = initial_rect; |
64 params.window_action = NavigateParams::SHOW_WINDOW; | 65 params.window_action = NavigateParams::SHOW_WINDOW; |
65 // At this point, we're already beyond the popup blocker. Even if the popup | 66 // At this point, we're already beyond the popup blocker. Even if the popup |
66 // was created without a user gesture, we have to set |user_gesture| to true, | 67 // was created without a user gesture, we have to set |user_gesture| to true, |
67 // so it gets correctly focused. | 68 // so it gets correctly focused. |
68 params.user_gesture = true; | 69 params.user_gesture = true; |
69 Navigate(¶ms); | 70 Navigate(¶ms); |
70 } | 71 } |
71 | 72 |
72 void CloseWebContents(Browser* browser, | 73 void CloseWebContents(Browser* browser, |
73 content::WebContents* contents, | 74 content::WebContents* contents, |
74 bool add_to_history) { | 75 bool add_to_history) { |
75 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 76 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
76 if (index == TabStripModel::kNoTab) { | 77 if (index == TabStripModel::kNoTab) { |
77 NOTREACHED() << "CloseWebContents called for tab not in our strip"; | 78 NOTREACHED() << "CloseWebContents called for tab not in our strip"; |
78 return; | 79 return; |
79 } | 80 } |
80 | 81 |
81 browser->tab_strip_model()->CloseWebContentsAt( | 82 browser->tab_strip_model()->CloseWebContentsAt( |
82 index, | 83 index, |
83 add_to_history ? TabStripModel::CLOSE_CREATE_HISTORICAL_TAB | 84 add_to_history ? TabStripModel::CLOSE_CREATE_HISTORICAL_TAB |
84 : TabStripModel::CLOSE_NONE); | 85 : TabStripModel::CLOSE_NONE); |
85 } | 86 } |
86 | 87 |
87 } // namespace chrome | 88 } // namespace chrome |
OLD | NEW |