Chromium Code Reviews| Index: chrome/browser/extensions/extension_tab_util.cc |
| diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc |
| index 55d9c4ceb1e8b99c6e27e5ff4e6d809b3557f0cd..6be3275fce61f21bcb6e8861cc46a9b64b99d4df 100644 |
| --- a/chrome/browser/extensions/extension_tab_util.cc |
| +++ b/chrome/browser/extensions/extension_tab_util.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/extensions/extension_tab_util.h" |
| #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| +#include "chrome/browser/extensions/event_names.h" |
| #include "chrome/browser/extensions/tab_helper.h" |
| #include "chrome/browser/extensions/window_controller.h" |
| #include "chrome/browser/net/url_fixer_upper.h" |
| @@ -20,6 +21,7 @@ |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/extensions/extension.h" |
| #include "chrome/common/extensions/extension_manifest_constants.h" |
| +#include "chrome/common/extensions/permissions/api_permission.h" |
| #include "chrome/common/url_constants.h" |
| #include "content/public/browser/favicon_status.h" |
| #include "content/public/browser/navigation_entry.h" |
| @@ -31,6 +33,16 @@ namespace keys = extensions::tabs_constants; |
| using content::NavigationEntry; |
| using content::WebContents; |
| +namespace { |
| + |
| +void StripTabOfSensitiveData(DictionaryValue* tab) { |
| + tab->SetString(keys::kUrlKey, std::string()); |
| + tab->SetString(keys::kTitleKey, std::string()); |
| + tab->SetString(keys::kFaviconUrlKey, std::string()); |
| +} |
| + |
| +} |
| + |
| int ExtensionTabUtil::GetWindowId(const Browser* browser) { |
| return browser->session_id().id(); |
| } |
| @@ -58,38 +70,49 @@ int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
| TabContents::FromWebContents(web_contents)); |
| } |
| -DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents) { |
| +DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| + const WebContents* contents, |
| + const extensions::Extension* extension) { |
| // Find the tab strip and index of this guy. |
| TabStripModel* tab_strip = NULL; |
| int tab_index; |
| - if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) |
| - return ExtensionTabUtil::CreateTabValue(contents, tab_strip, tab_index); |
| + if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { |
| + return ExtensionTabUtil::CreateTabValue(contents, |
| + tab_strip, |
| + tab_index, |
| + extension); |
| + } |
| // Couldn't find it. This can happen if the tab is being dragged. |
| - return ExtensionTabUtil::CreateTabValue(contents, NULL, -1); |
| + return ExtensionTabUtil::CreateTabValue(contents, NULL, -1, extension); |
| } |
| -ListValue* ExtensionTabUtil::CreateTabList(const Browser* browser) { |
| +ListValue* ExtensionTabUtil::CreateTabList( |
| + const Browser* browser, |
| + const extensions::Extension* extension) { |
| ListValue* tab_list = new ListValue(); |
| TabStripModel* tab_strip = browser->tab_strip_model(); |
| for (int i = 0; i < tab_strip->count(); ++i) { |
| - tab_list->Append(ExtensionTabUtil::CreateTabValue( |
| - tab_strip->GetTabContentsAt(i)->web_contents(), tab_strip, i)); |
| + tab_list->Append(CreateTabValue( |
| + tab_strip->GetTabContentsAt(i)->web_contents(), |
| + tab_strip, |
| + i, |
| + extension)); |
| } |
| return tab_list; |
| } |
| -DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, |
| - TabStripModel* tab_strip, |
| - int tab_index) { |
| +DictionaryValue* ExtensionTabUtil::CreateTabValue( |
| + const WebContents* contents, |
| + TabStripModel* tab_strip, |
| + int tab_index, |
| + const extensions::Extension* extension) { |
| DictionaryValue* result = new DictionaryValue(); |
| bool is_loading = contents->IsLoading(); |
| - result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); |
| + result->SetInteger(keys::kIdKey, GetTabId(contents)); |
| result->SetInteger(keys::kIndexKey, tab_index); |
| - result->SetInteger(keys::kWindowIdKey, |
| - ExtensionTabUtil::GetWindowIdOfTab(contents)); |
| - result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| + result->SetInteger(keys::kWindowIdKey, GetWindowIdOfTab(contents)); |
| result->SetString(keys::kStatusKey, GetTabStatusText(is_loading)); |
| result->SetBoolean(keys::kActiveKey, |
| tab_strip && tab_index == tab_strip->active_index()); |
| @@ -99,24 +122,40 @@ DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, |
| tab_strip && tab_strip->IsTabSelected(tab_index)); |
| result->SetBoolean(keys::kPinnedKey, |
| tab_strip && tab_strip->IsTabPinned(tab_index)); |
| - result->SetString(keys::kTitleKey, contents->GetTitle()); |
| result->SetBoolean(keys::kIncognitoKey, |
| contents->GetBrowserContext()->IsOffTheRecord()); |
| + // If we have an extension without permissions, we don't add sensitive data. |
| + if (extension && !extension->HasAPIPermissionForTab( |
| + tab_index, extensions::APIPermission::kTab)) { |
| + result->SetString(keys::kUrlKey, std::string()); |
|
Aaron Boodman
2012/08/23 17:47:29
There's no reason to set these keys at all is ther
chebert
2012/08/29 21:51:58
Done.
|
| + result->SetString(keys::kTitleKey, std::string()); |
| + } else { |
| + result->SetString(keys::kUrlKey, contents->GetURL().spec()); |
| + result->SetString(keys::kTitleKey, contents->GetTitle()); |
| + } |
| + |
| if (tab_strip) { |
| content::NavigationController* opener = |
| tab_strip->GetOpenerOfTabContentsAt(tab_index); |
| if (opener) { |
| result->SetInteger(keys::kOpenerTabIdKey, |
| - ExtensionTabUtil::GetTabId(opener->GetWebContents())); |
| + GetTabId(opener->GetWebContents())); |
| } |
| } |
| if (!is_loading) { |
| NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
| if (entry) { |
| - if (entry->GetFavicon().valid) |
| - result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec()); |
| + if (entry->GetFavicon().valid) { |
|
Aaron Boodman
2012/08/23 17:47:29
Can you rejigger things so that here is just one c
chebert
2012/08/29 21:51:58
Rejiggered.
|
| + if (extension && !extension->HasAPIPermissionForTab( |
| + tab_index, extensions::APIPermission::kTab)) { |
| + result->SetString(keys::kFaviconUrlKey, std::string()); |
| + } else { |
| + result->SetString(keys::kFaviconUrlKey, |
| + entry->GetFavicon().url.spec()); |
| + } |
| + } |
| } |
| } |
| @@ -125,12 +164,32 @@ DictionaryValue* ExtensionTabUtil::CreateTabValue(const WebContents* contents, |
| DictionaryValue* ExtensionTabUtil::CreateTabValueActive( |
| const WebContents* contents, |
| - bool active) { |
| - DictionaryValue* result = ExtensionTabUtil::CreateTabValue(contents); |
| + bool active, |
| + const extensions::Extension* extension) { |
| + DictionaryValue* result = CreateTabValue(contents, extension); |
| result->SetBoolean(keys::kSelectedKey, active); |
| return result; |
| } |
| +void ExtensionTabUtil::MaybeStripEventArgsOfSensitiveData( |
| + const std::string& event_name, |
| + const extensions::Extension* extension, |
| + base::ListValue* event_args) { |
| + int arg = 0; |
| + if (event_name == extensions::event_names::kOnTabUpdated) |
| + arg = 2; |
| + else if (event_name == extensions::event_names::kOnTabUpdated) |
| + arg = 0; |
| + else |
| + return; |
| + |
| + if (!extension->HasAPIPermission(extensions::APIPermission::kTab)) { |
| + DictionaryValue* tab; |
| + event_args->GetDictionary(arg, &tab); |
| + StripTabOfSensitiveData(tab); |
| + } |
| +} |
| + |
| bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, |
| TabStripModel** tab_strip_model, |
| int* tab_index) { |
| @@ -161,7 +220,7 @@ bool ExtensionTabUtil::GetDefaultTab(Browser* browser, |
| *contents = chrome::GetActiveTabContents(browser); |
| if (*contents) { |
| if (tab_id) |
| - *tab_id = ExtensionTabUtil::GetTabId((*contents)->web_contents()); |
| + *tab_id = GetTabId((*contents)->web_contents()); |
| return true; |
| } |