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

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: Update test 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 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
136 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 143 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
137 TabStripModel** tab_strip_model, 144 TabStripModel** tab_strip_model,
138 int* tab_index) { 145 int* tab_index) {
139 DCHECK(web_contents); 146 DCHECK(web_contents);
140 DCHECK(tab_strip_model); 147 DCHECK(tab_strip_model);
141 DCHECK(tab_index); 148 DCHECK(tab_index);
142 149
143 for (BrowserList::const_iterator it = BrowserList::begin(); 150 for (BrowserList::const_iterator it = BrowserList::begin();
144 it != BrowserList::end(); ++it) { 151 it != BrowserList::end(); ++it) {
145 TabStripModel* tab_strip = (*it)->tab_strip_model(); 152 TabStripModel* tab_strip = (*it)->tab_strip_model();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 272
266 // static 273 // static
267 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab( 274 extensions::WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
268 const WebContents* web_contents) { 275 const WebContents* web_contents) {
269 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 276 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
270 if (browser != NULL) 277 if (browser != NULL)
271 return browser->extension_window_controller(); 278 return browser->extension_window_controller();
272 279
273 return NULL; 280 return NULL;
274 } 281 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tab_util.h ('k') | chrome/browser/extensions/extension_tab_util_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698