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

Unified Diff: chrome/browser/extensions/extension_tab_util.cc

Issue 10829186: Tabs API is usable without tabs permission. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ETU now SetString()'s for empty values Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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 8d49ea784c1a8bd5e518707962b2292fc018e2c4..6b4ee44dc5545a2d9c2456c5843a67662d04b6dc 100644
--- a/chrome/browser/extensions/extension_tab_util.cc
+++ b/chrome/browser/extensions/extension_tab_util.cc
@@ -20,6 +20,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"
@@ -58,38 +59,50 @@ 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) {
+ CHECK(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 +112,43 @@ 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.
+ bool has_permission = false;
+ if (tab_index >= 0) {
+ has_permission = extension->HasAPIPermissionForTab(
+ tab_index, extensions::APIPermission::kTab);
+ } else {
+ has_permission = extension->HasAPIPermission(
+ extensions::APIPermission::kTab);
+ }
+
+ if (has_permission) {
+ result->SetString(keys::kUrlKey, contents->GetURL().spec());
+ result->SetString(keys::kTitleKey, contents->GetTitle());
+ if (!is_loading) {
+ NavigationEntry* entry = contents->GetController().GetActiveEntry();
+ if (entry && entry->GetFavicon().valid)
+ result->SetString(keys::kFaviconUrlKey, entry->GetFavicon().url.spec());
+ }
+ } else {
+ result->SetString(keys::kUrlKey, std::string());
+ result->SetString(keys::kTitleKey, std::string());
+ if (!is_loading) {
+ NavigationEntry* entry = contents->GetController().GetActiveEntry();
+ if (entry && entry->GetFavicon().valid)
+ result->SetString(keys::kFaviconUrlKey, std::string());
+ }
+ }
+
if (tab_strip) {
content::NavigationController* opener =
tab_strip->GetOpenerOfTabContentsAt(tab_index);
if (opener) {
result->SetInteger(keys::kOpenerTabIdKey,
- ExtensionTabUtil::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());
+ GetTabId(opener->GetWebContents()));
}
}
@@ -125,8 +157,9 @@ 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;
}
@@ -161,7 +194,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;
}
« 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