Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/extensions/extension_tab_util.cc

Issue 10535077: TabContentsWrapper -> TabContents, part 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/net/url_fixer_upper.h" 8 #include "chrome/browser/net/url_fixer_upper.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 10 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_manifest_constants.h" 17 #include "chrome/common/extensions/extension_manifest_constants.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/favicon_status.h" 19 #include "content/public/browser/favicon_status.h"
20 #include "content/public/browser/navigation_entry.h" 20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
23 23
24 namespace keys = extensions::tabs_constants; 24 namespace keys = extensions::tabs_constants;
25 namespace errors = extension_manifest_errors; 25 namespace errors = extension_manifest_errors;
26 26
27 using content::NavigationEntry; 27 using content::NavigationEntry;
28 using content::WebContents; 28 using content::WebContents;
29 29
30 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 30 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
31 return browser->session_id().id(); 31 return browser->session_id().id();
32 } 32 }
33 33
34 int ExtensionTabUtil::GetWindowIdOfTabStripModel( 34 int ExtensionTabUtil::GetWindowIdOfTabStripModel(
35 const TabStripModel* tab_strip_model) { 35 const TabStripModel* tab_strip_model) {
36 for (BrowserList::const_iterator it = BrowserList::begin(); 36 for (BrowserList::const_iterator it = BrowserList::begin();
37 it != BrowserList::end(); ++it) { 37 it != BrowserList::end(); ++it) {
38 if ((*it)->tab_strip_model() == tab_strip_model) 38 if ((*it)->tab_strip_model() == tab_strip_model)
39 return GetWindowId(*it); 39 return GetWindowId(*it);
40 } 40 }
41 return -1; 41 return -1;
42 } 42 }
43 43
44 // TODO(sky): this function should really take a TabContentsWrapper. 44 // TODO(sky): this function should really take a TabContents.
45 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { 45 int ExtensionTabUtil::GetTabId(const WebContents* web_contents) {
46 const TabContentsWrapper* tab = 46 const TabContents* tab = TabContents::FromWebContents(web_contents);
47 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
48 return tab ? tab->restore_tab_helper()->session_id().id() : -1; 47 return tab ? tab->restore_tab_helper()->session_id().id() : -1;
49 } 48 }
50 49
51 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { 50 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) {
52 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; 51 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete;
53 } 52 }
54 53
55 // TODO(sky): this function should really take a TabContentsWrapper. 54 // TODO(sky): this function should really take a TabContents.
56 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { 55 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) {
57 const TabContentsWrapper* tab = 56 const TabContents* tab = TabContents::FromWebContents(web_contents);
58 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
59 return tab ? tab->restore_tab_helper()->window_id().id() : -1; 57 return tab ? tab->restore_tab_helper()->window_id().id() : -1;
60 } 58 }
61 59
62 DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents) { 60 DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents) {
63 // Find the tab strip and index of this guy. 61 // Find the tab strip and index of this guy.
64 TabStripModel* tab_strip = NULL; 62 TabStripModel* tab_strip = NULL;
65 int tab_index; 63 int tab_index;
66 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) 64 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index))
67 return ExtensionTabUtil::CreateTabValue(contents, tab_strip, tab_index); 65 return ExtensionTabUtil::CreateTabValue(contents, tab_strip, tab_index);
68 66
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 *tab_strip_model = tab_strip; 145 *tab_strip_model = tab_strip;
148 *tab_index = index; 146 *tab_index = index;
149 return true; 147 return true;
150 } 148 }
151 } 149 }
152 150
153 return false; 151 return false;
154 } 152 }
155 153
156 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, 154 bool ExtensionTabUtil::GetDefaultTab(Browser* browser,
157 TabContentsWrapper** contents, 155 TabContents** contents,
158 int* tab_id) { 156 int* tab_id) {
159 DCHECK(browser); 157 DCHECK(browser);
160 DCHECK(contents); 158 DCHECK(contents);
161 159
162 *contents = browser->GetSelectedTabContentsWrapper(); 160 *contents = browser->GetActiveTabContents();
163 if (*contents) { 161 if (*contents) {
164 if (tab_id) 162 if (tab_id)
165 *tab_id = ExtensionTabUtil::GetTabId((*contents)->web_contents()); 163 *tab_id = ExtensionTabUtil::GetTabId((*contents)->web_contents());
166 return true; 164 return true;
167 } 165 }
168 166
169 return false; 167 return false;
170 } 168 }
171 169
172 bool ExtensionTabUtil::GetTabById(int tab_id, 170 bool ExtensionTabUtil::GetTabById(int tab_id,
173 Profile* profile, 171 Profile* profile,
174 bool include_incognito, 172 bool include_incognito,
175 Browser** browser, 173 Browser** browser,
176 TabStripModel** tab_strip, 174 TabStripModel** tab_strip,
177 TabContentsWrapper** contents, 175 TabContents** contents,
178 int* tab_index) { 176 int* tab_index) {
179 Profile* incognito_profile = 177 Profile* incognito_profile =
180 include_incognito && profile->HasOffTheRecordProfile() ? 178 include_incognito && profile->HasOffTheRecordProfile() ?
181 profile->GetOffTheRecordProfile() : NULL; 179 profile->GetOffTheRecordProfile() : NULL;
182 for (BrowserList::const_iterator iter = BrowserList::begin(); 180 for (BrowserList::const_iterator iter = BrowserList::begin();
183 iter != BrowserList::end(); ++iter) { 181 iter != BrowserList::end(); ++iter) {
184 Browser* target_browser = *iter; 182 Browser* target_browser = *iter;
185 if (target_browser->profile() == profile || 183 if (target_browser->profile() == profile ||
186 target_browser->profile() == incognito_profile) { 184 target_browser->profile() == incognito_profile) {
187 TabStripModel* target_tab_strip = target_browser->tab_strip_model(); 185 TabStripModel* target_tab_strip = target_browser->tab_strip_model();
188 for (int i = 0; i < target_tab_strip->count(); ++i) { 186 for (int i = 0; i < target_tab_strip->count(); ++i) {
189 TabContentsWrapper* target_contents = 187 TabContents* target_contents = target_tab_strip->GetTabContentsAt(i);
190 target_tab_strip->GetTabContentsAt(i);
191 if (target_contents->restore_tab_helper()->session_id().id() == 188 if (target_contents->restore_tab_helper()->session_id().id() ==
192 tab_id) { 189 tab_id) {
193 if (browser) 190 if (browser)
194 *browser = target_browser; 191 *browser = target_browser;
195 if (tab_strip) 192 if (tab_strip)
196 *tab_strip = target_tab_strip; 193 *tab_strip = target_tab_strip;
197 if (contents) 194 if (contents)
198 *contents = target_contents; 195 *contents = target_contents;
199 if (tab_index) 196 if (tab_index)
200 *tab_index = i; 197 *tab_index = i;
(...skipping 15 matching lines...) Expand all
216 } 213 }
217 214
218 bool ExtensionTabUtil::IsCrashURL(const GURL& url) { 215 bool ExtensionTabUtil::IsCrashURL(const GURL& url) {
219 // Check a fixed-up URL, to normalize the scheme and parse hosts correctly. 216 // Check a fixed-up URL, to normalize the scheme and parse hosts correctly.
220 GURL fixed_url = 217 GURL fixed_url =
221 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string()); 218 URLFixerUpper::FixupURL(url.possibly_invalid_spec(), std::string());
222 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) && 219 return (fixed_url.SchemeIs(chrome::kChromeUIScheme) &&
223 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost || 220 (fixed_url.host() == chrome::kChromeUIBrowserCrashHost ||
224 fixed_url.host() == chrome::kChromeUICrashHost)); 221 fixed_url.host() == chrome::kChromeUICrashHost));
225 } 222 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.h ('k') | chrome/browser/extensions/extension_toolbar_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698