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/extensions/extension_tab_util.h" | 5 #include "chrome/browser/extensions/extension_tab_util.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 7 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
8 #include "chrome/browser/extensions/tab_helper.h" | 8 #include "chrome/browser/extensions/tab_helper.h" |
9 #include "chrome/browser/extensions/window_controller.h" | 9 #include "chrome/browser/extensions/window_controller.h" |
10 #include "chrome/browser/net/url_fixer_upper.h" | 10 #include "chrome/browser/net/url_fixer_upper.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sessions/session_id.h" | 12 #include "chrome/browser/sessions/session_id.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_iterator.h" |
16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
20 #include "chrome/common/extensions/extension_manifest_constants.h" | 20 #include "chrome/common/extensions/extension_manifest_constants.h" |
21 #include "chrome/common/extensions/permissions/api_permission.h" | 21 #include "chrome/common/extensions/permissions/api_permission.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "content/public/browser/favicon_status.h" | 23 #include "content/public/browser/favicon_status.h" |
24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
27 | 27 |
28 namespace keys = extensions::tabs_constants; | 28 namespace keys = extensions::tabs_constants; |
29 namespace tabs = extensions::api::tabs; | 29 namespace tabs = extensions::api::tabs; |
30 | 30 |
31 using content::NavigationEntry; | 31 using content::NavigationEntry; |
32 using content::WebContents; | 32 using content::WebContents; |
33 using extensions::APIPermission; | 33 using extensions::APIPermission; |
34 using extensions::Extension; | 34 using extensions::Extension; |
35 | 35 |
36 int ExtensionTabUtil::GetWindowId(const Browser* browser) { | 36 int ExtensionTabUtil::GetWindowId(const Browser* browser) { |
37 return browser->session_id().id(); | 37 return browser->session_id().id(); |
38 } | 38 } |
39 | 39 |
40 int ExtensionTabUtil::GetWindowIdOfTabStripModel( | 40 int ExtensionTabUtil::GetWindowIdOfTabStripModel( |
41 const TabStripModel* tab_strip_model) { | 41 const TabStripModel* tab_strip_model) { |
42 for (BrowserList::const_iterator it = BrowserList::begin(); | 42 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
43 it != BrowserList::end(); ++it) { | 43 if (it->tab_strip_model() == tab_strip_model) |
44 if ((*it)->tab_strip_model() == tab_strip_model) | |
45 return GetWindowId(*it); | 44 return GetWindowId(*it); |
46 } | 45 } |
47 return -1; | 46 return -1; |
48 } | 47 } |
49 | 48 |
50 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { | 49 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { |
51 return SessionID::IdForTab(web_contents); | 50 return SessionID::IdForTab(web_contents); |
52 } | 51 } |
53 | 52 |
54 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { | 53 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 151 } |
153 } | 152 } |
154 | 153 |
155 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, | 154 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, |
156 TabStripModel** tab_strip_model, | 155 TabStripModel** tab_strip_model, |
157 int* tab_index) { | 156 int* tab_index) { |
158 DCHECK(web_contents); | 157 DCHECK(web_contents); |
159 DCHECK(tab_strip_model); | 158 DCHECK(tab_strip_model); |
160 DCHECK(tab_index); | 159 DCHECK(tab_index); |
161 | 160 |
162 for (BrowserList::const_iterator it = BrowserList::begin(); | 161 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
163 it != BrowserList::end(); ++it) { | 162 TabStripModel* tab_strip = it->tab_strip_model(); |
164 TabStripModel* tab_strip = (*it)->tab_strip_model(); | |
165 int index = tab_strip->GetIndexOfWebContents(web_contents); | 163 int index = tab_strip->GetIndexOfWebContents(web_contents); |
166 if (index != -1) { | 164 if (index != -1) { |
167 *tab_strip_model = tab_strip; | 165 *tab_strip_model = tab_strip; |
168 *tab_index = index; | 166 *tab_index = index; |
169 return true; | 167 return true; |
170 } | 168 } |
171 } | 169 } |
172 | 170 |
173 return false; | 171 return false; |
174 } | 172 } |
(...skipping 17 matching lines...) Expand all Loading... |
192 bool ExtensionTabUtil::GetTabById(int tab_id, | 190 bool ExtensionTabUtil::GetTabById(int tab_id, |
193 Profile* profile, | 191 Profile* profile, |
194 bool include_incognito, | 192 bool include_incognito, |
195 Browser** browser, | 193 Browser** browser, |
196 TabStripModel** tab_strip, | 194 TabStripModel** tab_strip, |
197 WebContents** contents, | 195 WebContents** contents, |
198 int* tab_index) { | 196 int* tab_index) { |
199 Profile* incognito_profile = | 197 Profile* incognito_profile = |
200 include_incognito && profile->HasOffTheRecordProfile() ? | 198 include_incognito && profile->HasOffTheRecordProfile() ? |
201 profile->GetOffTheRecordProfile() : NULL; | 199 profile->GetOffTheRecordProfile() : NULL; |
202 for (BrowserList::const_iterator iter = BrowserList::begin(); | 200 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
203 iter != BrowserList::end(); ++iter) { | 201 Browser* target_browser = *it; |
204 Browser* target_browser = *iter; | |
205 if (target_browser->profile() == profile || | 202 if (target_browser->profile() == profile || |
206 target_browser->profile() == incognito_profile) { | 203 target_browser->profile() == incognito_profile) { |
207 TabStripModel* target_tab_strip = target_browser->tab_strip_model(); | 204 TabStripModel* target_tab_strip = target_browser->tab_strip_model(); |
208 for (int i = 0; i < target_tab_strip->count(); ++i) { | 205 for (int i = 0; i < target_tab_strip->count(); ++i) { |
209 WebContents* target_contents = target_tab_strip->GetWebContentsAt(i); | 206 WebContents* target_contents = target_tab_strip->GetWebContentsAt(i); |
210 if (SessionID::IdForTab(target_contents) == tab_id) { | 207 if (SessionID::IdForTab(target_contents) == tab_id) { |
211 if (browser) | 208 if (browser) |
212 *browser = target_browser; | 209 *browser = target_browser; |
213 if (tab_strip) | 210 if (tab_strip) |
214 *tab_strip = target_tab_strip; | 211 *tab_strip = target_tab_strip; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 281 |
285 // static | 282 // static |
286 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( | 283 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( |
287 const WebContents* web_contents) { | 284 const WebContents* web_contents) { |
288 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 285 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
289 if (browser != NULL) | 286 if (browser != NULL) |
290 return browser->extension_window_controller(); | 287 return browser->extension_window_controller(); |
291 | 288 |
292 return NULL; | 289 return NULL; |
293 } | 290 } |
OLD | NEW |