Always send the full tab object in ExtensionAction click event.

Along the way, decompose a few swiss army knife functions to
simplify and generalize code.

BUG=149020

Review URL: https://codereview.chromium.org/10909256

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157082 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc
index 09d20e03..416a07b 100644
--- a/chrome/browser/extensions/extension_tab_util.cc
+++ b/chrome/browser/extensions/extension_tab_util.cc
@@ -62,19 +62,17 @@
 
 DictionaryValue* ExtensionTabUtil::CreateTabValue(
     const WebContents* contents,
+    TabStripModel* tab_strip,
+    int tab_index,
     const 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,
-                                            extension);
-  }
+  // Only add privacy-sensitive data if the requesting extension has the tabs
+  // permission.
+  bool has_permission = extension && extension->HasAPIPermissionForTab(
+      GetTabId(contents), APIPermission::kTab);
 
-  // Couldn't find it.  This can happen if the tab is being dragged.
-  return ExtensionTabUtil::CreateTabValue(contents, NULL, -1, extension);
+  return CreateTabValue(contents, tab_strip, tab_index,
+                        has_permission ? INCLUDE_PRIVACY_SENSITIVE_FIELDS :
+                            OMIT_PRIVACY_SENSITIVE_FIELDS);
 }
 
 ListValue* ExtensionTabUtil::CreateTabList(
@@ -97,7 +95,10 @@
     const WebContents* contents,
     TabStripModel* tab_strip,
     int tab_index,
-    const Extension* extension) {
+    IncludePrivacySensitiveFields include_privacy_sensitive_fields) {
+  if (!tab_strip)
+    ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index);
+
   DictionaryValue* result = new DictionaryValue();
   bool is_loading = contents->IsLoading();
   result->SetInteger(keys::kIdKey, GetTabId(contents));
@@ -115,24 +116,7 @@
   result->SetBoolean(keys::kIncognitoKey,
                      contents->GetBrowserContext()->IsOffTheRecord());
 
-  // Only add privacy-sensitive data if the requesting extension has the tabs
-  // permission.
-  bool has_permission = false;
-  if (extension) {
-    if (tab_index >= 0) {
-      has_permission =
-          extension->HasAPIPermissionForTab(
-              tab_index, APIPermission::kTab) ||
-          extension->HasAPIPermissionForTab(
-              tab_index, APIPermission::kWebNavigation);
-    } else {
-      has_permission =
-          extension->HasAPIPermission(APIPermission::kTab) ||
-          extension->HasAPIPermission(APIPermission::kWebNavigation);
-    }
-  }
-
-  if (has_permission) {
+  if (include_privacy_sensitive_fields == INCLUDE_PRIVACY_SENSITIVE_FIELDS) {
     result->SetString(keys::kUrlKey, contents->GetURL().spec());
     result->SetString(keys::kTitleKey, contents->GetTitle());
     if (!is_loading) {
@@ -154,15 +138,6 @@
   return result;
 }
 
-DictionaryValue* ExtensionTabUtil::CreateTabValueActive(
-    const WebContents* contents,
-    bool active,
-    const extensions::Extension* extension) {
-  DictionaryValue* result = CreateTabValue(contents, extension);
-  result->SetBoolean(keys::kSelectedKey, active);
-  return result;
-}
-
 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
                                         TabStripModel** tab_strip_model,
                                         int* tab_index) {