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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { | 58 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
59 return SessionID::IdForWindowContainingTab(web_contents); | 59 return SessionID::IdForWindowContainingTab(web_contents); |
60 } | 60 } |
61 | 61 |
62 DictionaryValue* ExtensionTabUtil::CreateTabValue( | 62 DictionaryValue* ExtensionTabUtil::CreateTabValue( |
63 const WebContents* contents, | 63 const WebContents* contents, |
64 TabStripModel* tab_strip, | 64 TabStripModel* tab_strip, |
65 int tab_index, | 65 int tab_index, |
66 const Extension* extension) { | 66 const Extension* extension) { |
67 DictionaryValue *result = CreateTabValue(contents, tab_strip, tab_index); | 67 // Only add privacy-sensitive data if the requesting extension has the tabs |
68 ScrubTabValueForExtension(contents, extension, result); | 68 // permission. |
69 return result; | 69 bool has_permission = extension && extension->HasAPIPermissionForTab( |
| 70 GetTabId(contents), APIPermission::kTab); |
| 71 |
| 72 return CreateTabValue(contents, tab_strip, tab_index, |
| 73 has_permission ? INCLUDE_PRIVACY_SENSITIVE_FIELDS : |
| 74 OMIT_PRIVACY_SENSITIVE_FIELDS); |
70 } | 75 } |
71 | 76 |
72 ListValue* ExtensionTabUtil::CreateTabList( | 77 ListValue* ExtensionTabUtil::CreateTabList( |
73 const Browser* browser, | 78 const Browser* browser, |
74 const Extension* extension) { | 79 const Extension* extension) { |
75 ListValue* tab_list = new ListValue(); | 80 ListValue* tab_list = new ListValue(); |
76 TabStripModel* tab_strip = browser->tab_strip_model(); | 81 TabStripModel* tab_strip = browser->tab_strip_model(); |
77 for (int i = 0; i < tab_strip->count(); ++i) { | 82 for (int i = 0; i < tab_strip->count(); ++i) { |
78 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i), | 83 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i), |
79 tab_strip, | 84 tab_strip, |
80 i, | 85 i, |
81 extension)); | 86 extension)); |
82 } | 87 } |
83 | 88 |
84 return tab_list; | 89 return tab_list; |
85 } | 90 } |
86 | 91 |
87 DictionaryValue* ExtensionTabUtil::CreateTabValue( | 92 DictionaryValue* ExtensionTabUtil::CreateTabValue( |
88 const WebContents* contents, | 93 const WebContents* contents, |
89 TabStripModel* tab_strip, | 94 TabStripModel* tab_strip, |
90 int tab_index) { | 95 int tab_index, |
| 96 IncludePrivacySensitiveFields include_privacy_sensitive_fields) { |
91 if (!tab_strip) | 97 if (!tab_strip) |
92 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); | 98 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
93 | 99 |
94 DictionaryValue* result = new DictionaryValue(); | 100 DictionaryValue* result = new DictionaryValue(); |
95 bool is_loading = contents->IsLoading(); | 101 bool is_loading = contents->IsLoading(); |
96 result->SetInteger(keys::kIdKey, GetTabId(contents)); | 102 result->SetInteger(keys::kIdKey, GetTabId(contents)); |
97 result->SetInteger(keys::kIndexKey, tab_index); | 103 result->SetInteger(keys::kIndexKey, tab_index); |
98 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); | 104 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); |
99 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); | 105 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
100 result->SetBoolean(keys::kActiveKey, | 106 result->SetBoolean(keys::kActiveKey, |
101 tab_strip && tab_index == tab_strip->active_index()); | 107 tab_strip && tab_index == tab_strip->active_index()); |
102 result->SetBoolean(keys::kSelectedKey, | 108 result->SetBoolean(keys::kSelectedKey, |
103 tab_strip && tab_index == tab_strip->active_index()); | 109 tab_strip && tab_index == tab_strip->active_index()); |
104 result->SetBoolean(keys::kHighlightedKey, | 110 result->SetBoolean(keys::kHighlightedKey, |
105 tab_strip && tab_strip->IsTabSelected(tab_index)); | 111 tab_strip && tab_strip->IsTabSelected(tab_index)); |
106 result->SetBoolean(keys::kPinnedKey, | 112 result->SetBoolean(keys::kPinnedKey, |
107 tab_strip && tab_strip->IsTabPinned(tab_index)); | 113 tab_strip && tab_strip->IsTabPinned(tab_index)); |
108 result->SetBoolean(keys::kIncognitoKey, | 114 result->SetBoolean(keys::kIncognitoKey, |
109 contents->GetBrowserContext()->IsOffTheRecord()); | 115 contents->GetBrowserContext()->IsOffTheRecord()); |
110 | 116 |
111 // Privacy-sensitive fields: these should be stripped off by | 117 if (include_privacy_sensitive_fields == INCLUDE_PRIVACY_SENSITIVE_FIELDS) { |
112 // ScrubTabValueForExtension if the extension should not see them. | 118 result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
113 result->SetString(keys::kUrlKey, contents->GetURL().spec()); | 119 result->SetString(keys::kTitleKey, contents->GetTitle()); |
114 result->SetString(keys::kTitleKey, contents->GetTitle()); | 120 if (!is_loading) { |
115 if (!is_loading) { | 121 NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
116 NavigationEntry* entry = contents->GetController().GetActiveEntry(); | 122 if (entry && entry->GetFavicon().valid) |
117 if (entry && entry->GetFavicon().valid) | 123 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); |
118 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); | 124 } |
119 } | 125 } |
120 | 126 |
121 if (tab_strip) { | 127 if (tab_strip) { |
122 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); | 128 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
123 if (opener) | 129 if (opener) |
124 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); | 130 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); |
125 } | 131 } |
126 | 132 |
127 return result; | 133 return result; |
128 } | 134 } |
129 | 135 |
130 void ExtensionTabUtil::ScrubTabValueForExtension(const WebContents* contents, | |
131 const Extension* extension, | |
132 DictionaryValue* tab_info) { | |
133 bool has_permission = extension && extension->HasAPIPermissionForTab( | |
134 GetTabId(contents), APIPermission::kTab); | |
135 | |
136 if (!has_permission) { | |
137 tab_info->Remove(keys::kUrlKey, NULL); | |
138 tab_info->Remove(keys::kTitleKey, NULL); | |
139 tab_info->Remove(keys::kFaviconUrlKey, NULL); | |
140 } | |
141 } | |
142 | |
143 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, | 136 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, |
144 TabStripModel** tab_strip_model, | 137 TabStripModel** tab_strip_model, |
145 int* tab_index) { | 138 int* tab_index) { |
146 DCHECK(web_contents); | 139 DCHECK(web_contents); |
147 DCHECK(tab_strip_model); | 140 DCHECK(tab_strip_model); |
148 DCHECK(tab_index); | 141 DCHECK(tab_index); |
149 | 142 |
150 for (BrowserList::const_iterator it = BrowserList::begin(); | 143 for (BrowserList::const_iterator it = BrowserList::begin(); |
151 it != BrowserList::end(); ++it) { | 144 it != BrowserList::end(); ++it) { |
152 TabStripModel* tab_strip = (*it)->tab_strip_model(); | 145 TabStripModel* tab_strip = (*it)->tab_strip_model(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 265 |
273 // static | 266 // static |
274 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( | 267 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( |
275 const WebContents* web_contents) { | 268 const WebContents* web_contents) { |
276 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 269 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
277 if (browser != NULL) | 270 if (browser != NULL) |
278 return browser->extension_window_controller(); | 271 return browser->extension_window_controller(); |
279 | 272 |
280 return NULL; | 273 return NULL; |
281 } | 274 } |
OLD | NEW |