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

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

Issue 11824004: Do not pass URLs in onUpdated events to extensions unless they have the (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Revised to address review comments Created 7 years, 11 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
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/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
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 // Only add privacy-sensitive data if the requesting extension has the tabs 67 DictionaryValue *result = CreateTabValue(contents, tab_strip, tab_index);
68 // permission. 68 ScrubTabValueForExtension(contents, extension, result);
69 bool has_permission = extension && extension->HasAPIPermissionForTab( 69 return result;
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);
75 } 70 }
76 71
77 ListValue* ExtensionTabUtil::CreateTabList( 72 ListValue* ExtensionTabUtil::CreateTabList(
78 const Browser* browser, 73 const Browser* browser,
79 const Extension* extension) { 74 const Extension* extension) {
80 ListValue* tab_list = new ListValue(); 75 ListValue* tab_list = new ListValue();
81 TabStripModel* tab_strip = browser->tab_strip_model(); 76 TabStripModel* tab_strip = browser->tab_strip_model();
82 for (int i = 0; i < tab_strip->count(); ++i) { 77 for (int i = 0; i < tab_strip->count(); ++i) {
83 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i), 78 tab_list->Append(CreateTabValue(tab_strip->GetWebContentsAt(i),
84 tab_strip, 79 tab_strip,
85 i, 80 i,
86 extension)); 81 extension));
87 } 82 }
88 83
89 return tab_list; 84 return tab_list;
90 } 85 }
91 86
92 DictionaryValue* ExtensionTabUtil::CreateTabValue( 87 DictionaryValue* ExtensionTabUtil::CreateTabValue(
93 const WebContents* contents, 88 const WebContents* contents,
94 TabStripModel* tab_strip, 89 TabStripModel* tab_strip,
95 int tab_index, 90 int tab_index) {
96 IncludePrivacySensitiveFields include_privacy_sensitive_fields) {
97 if (!tab_strip) 91 if (!tab_strip)
98 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); 92 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index);
99 93
100 DictionaryValue* result = new DictionaryValue(); 94 DictionaryValue* result = new DictionaryValue();
101 bool is_loading = contents->IsLoading(); 95 bool is_loading = contents->IsLoading();
102 result->SetInteger(keys::kIdKey, GetTabId(contents)); 96 result->SetInteger(keys::kIdKey, GetTabId(contents));
103 result->SetInteger(keys::kIndexKey, tab_index); 97 result->SetInteger(keys::kIndexKey, tab_index);
104 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); 98 result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents));
105 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); 99 result->SetString(keys::kStatusKey, GetTabStatusText(is_loading));
106 result->SetBoolean(keys::kActiveKey, 100 result->SetBoolean(keys::kActiveKey,
107 tab_strip && tab_index == tab_strip->active_index()); 101 tab_strip && tab_index == tab_strip->active_index());
108 result->SetBoolean(keys::kSelectedKey, 102 result->SetBoolean(keys::kSelectedKey,
109 tab_strip && tab_index == tab_strip->active_index()); 103 tab_strip && tab_index == tab_strip->active_index());
110 result->SetBoolean(keys::kHighlightedKey, 104 result->SetBoolean(keys::kHighlightedKey,
111 tab_strip && tab_strip->IsTabSelected(tab_index)); 105 tab_strip && tab_strip->IsTabSelected(tab_index));
112 result->SetBoolean(keys::kPinnedKey, 106 result->SetBoolean(keys::kPinnedKey,
113 tab_strip && tab_strip->IsTabPinned(tab_index)); 107 tab_strip && tab_strip->IsTabPinned(tab_index));
114 result->SetBoolean(keys::kIncognitoKey, 108 result->SetBoolean(keys::kIncognitoKey,
115 contents->GetBrowserContext()->IsOffTheRecord()); 109 contents->GetBrowserContext()->IsOffTheRecord());
116 110
117 if (include_privacy_sensitive_fields == INCLUDE_PRIVACY_SENSITIVE_FIELDS) { 111 // Privacy-sensitive fields: these should be stripped off by
118 result->SetString(keys::kUrlKey, contents->GetURL().spec()); 112 // ScrubTabValueForExtension if the extension should not see them.
119 result->SetString(keys::kTitleKey, contents->GetTitle()); 113 result->SetString(keys::kUrlKey, contents->GetURL().spec());
120 if (!is_loading) { 114 result->SetString(keys::kTitleKey, contents->GetTitle());
121 NavigationEntry* entry = contents->GetController().GetActiveEntry(); 115 if (!is_loading) {
122 if (entry && entry->GetFavicon().valid) 116 NavigationEntry* entry = contents->GetController().GetActiveEntry();
123 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); 117 if (entry && entry->GetFavicon().valid)
124 } 118 result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec());
125 } 119 }
126 120
127 if (tab_strip) { 121 if (tab_strip) {
128 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); 122 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index);
129 if (opener) 123 if (opener)
130 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener)); 124 result->SetInteger(keys::kOpenerTabIdKey, GetTabId(opener));
131 } 125 }
132 126
133 return result; 127 return result;
134 } 128 }
135 129
130 DictionaryValue* ExtensionTabUtil::ScrubTabValueForExtension(
131 const WebContents* contents,
132 const Extension* extension,
133 DictionaryValue* tab_info) {
134 bool has_permission = extension && extension->HasAPIPermissionForTab(
135 GetTabId(contents), APIPermission::kTab);
136
137 if (!has_permission) {
138 tab_info->Remove(keys::kUrlKey, NULL);
139 tab_info->Remove(keys::kTitleKey, NULL);
140 tab_info->Remove(keys::kFaviconUrlKey, NULL);
141 }
142
143 return tab_info;
not at google - send to devlin 2013/01/09 02:04:29 returning something here is unnecessary
mvrable 2013/01/09 19:25:35 Done.
144 }
145
136 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 146 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
137 TabStripModel** tab_strip_model, 147 TabStripModel** tab_strip_model,
138 int* tab_index) { 148 int* tab_index) {
139 DCHECK(web_contents); 149 DCHECK(web_contents);
140 DCHECK(tab_strip_model); 150 DCHECK(tab_strip_model);
141 DCHECK(tab_index); 151 DCHECK(tab_index);
142 152
143 for (BrowserList::const_iterator it = BrowserList::begin(); 153 for (BrowserList::const_iterator it = BrowserList::begin();
144 it != BrowserList::end(); ++it) { 154 it != BrowserList::end(); ++it) {
145 TabStripModel* tab_strip = (*it)->tab_strip_model(); 155 TabStripModel* tab_strip = (*it)->tab_strip_model();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 277
268 // static 278 // static
269 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( 279 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
270 const WebContents* web_contents) { 280 const WebContents* web_contents) {
271 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 281 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
272 if (browser != NULL) 282 if (browser != NULL)
273 return browser->extension_window_controller(); 283 return browser->extension_window_controller();
274 284
275 return NULL; 285 return NULL;
276 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698