[Extensions] Require a scrub tab behavior for CreateTabObject
CreateTabObject() creates an object to pass to an extension representing
a given tab. Depending on whether the tab has permission to see the
user's tabs or the specific tab, this may include URL, title, and
favicon (but shouldn't if the extension doesn't have that permission).
There were multiple CreateTabObject() methods in ExtensionTabUtil(), and
it was easy to get them mixed up. Combine these methods so that all
require an explicit argument specifying scrubbing behavior. Also fix an
instance in tabs.discard where the scrubbing behavior was incorrect.
Bug: 809253
Change-Id: I1ed77fd0323dc261de3214db2e405db2e95cb9ae
Reviewed-on: https://chromium-review.googlesource.com/902928
Commit-Queue: Devlin <[email protected]>
Reviewed-by: Karan Bhatia <[email protected]>
Cr-Commit-Position: refs/heads/master@{#535564}
diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc
index 43b2715..26486ea 100644
--- a/chrome/browser/extensions/extension_tab_util.cc
+++ b/chrome/browser/extensions/extension_tab_util.cc
@@ -265,8 +265,8 @@
// Return data about the newly created tab.
return ExtensionTabUtil::CreateTabObject(navigate_params.target_contents,
- tab_strip, new_index,
- function->extension())
+ kScrubTab, function->extension(),
+ tab_strip, new_index)
->ToValue()
.release();
}
@@ -334,32 +334,8 @@
// static
std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject(
WebContents* contents,
- TabStripModel* tab_strip,
- int tab_index,
- const Extension* extension) {
- std::unique_ptr<api::tabs::Tab> result =
- CreateTabObject(contents, tab_strip, tab_index);
- ScrubTabForExtension(extension, contents, result.get());
- return result;
-}
-
-std::unique_ptr<base::ListValue> ExtensionTabUtil::CreateTabList(
- const Browser* browser,
- const Extension* extension) {
- std::unique_ptr<base::ListValue> tab_list(new base::ListValue());
- TabStripModel* tab_strip = browser->tab_strip_model();
- for (int i = 0; i < tab_strip->count(); ++i) {
- tab_list->Append(
- CreateTabObject(tab_strip->GetWebContentsAt(i), tab_strip, i, extension)
- ->ToValue());
- }
-
- return tab_list;
-}
-
-// static
-std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject(
- content::WebContents* contents,
+ ScrubTabBehavior scrub_tab_behavior,
+ const Extension* extension,
TabStripModel* tab_strip,
int tab_index) {
if (!tab_strip)
@@ -402,9 +378,25 @@
}
}
+ if (scrub_tab_behavior == kScrubTab)
+ ScrubTabForExtension(extension, contents, tab_object.get());
return tab_object;
}
+std::unique_ptr<base::ListValue> ExtensionTabUtil::CreateTabList(
+ const Browser* browser,
+ const Extension* extension) {
+ std::unique_ptr<base::ListValue> tab_list(new base::ListValue());
+ TabStripModel* tab_strip = browser->tab_strip_model();
+ for (int i = 0; i < tab_strip->count(); ++i) {
+ tab_list->Append(CreateTabObject(tab_strip->GetWebContentsAt(i), kScrubTab,
+ extension, tab_strip, i)
+ ->ToValue());
+ }
+
+ return tab_list;
+}
+
// static
std::unique_ptr<base::DictionaryValue>
ExtensionTabUtil::CreateWindowValueForExtension(