Provide and use a simpler version of ExtensionTabUtil::GetTabById.
14 out of 24 usages of ExtensionTabUtil::GetTabById didn't require
|browser|, |tab_strip| and |tab_index| and specified nullptr for
them. Provide a simpler version without these params and update
callers to use the simplified version.
Bug: None
Test: No visible changes expected, internal only cleanup.
Change-Id: I3cbdeee148c335b49c058b9498be097f43043c8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717458
Reviewed-by: Devlin <[email protected]>
Commit-Queue: Istiaque Ahmed <[email protected]>
Cr-Commit-Position: refs/heads/master@{#681201}
diff --git a/chrome/browser/extensions/api/automation_internal/chrome_automation_internal_api_delegate.cc b/chrome/browser/extensions/api/automation_internal/chrome_automation_internal_api_delegate.cc
index b33da9f..ea3db0a 100644
--- a/chrome/browser/extensions/api/automation_internal/chrome_automation_internal_api_delegate.cc
+++ b/chrome/browser/extensions/api/automation_internal/chrome_automation_internal_api_delegate.cc
@@ -56,11 +56,8 @@
content::WebContents** contents,
std::string* error_msg) {
*error_msg = tabs_constants::kTabNotFoundError;
- return ExtensionTabUtil::GetTabById(
- tab_id, browser_context, include_incognito,
- nullptr, /* browser out param */
- nullptr, /* tab strip out param */
- contents, nullptr /* tab_index out param */);
+ return ExtensionTabUtil::GetTabById(tab_id, browser_context,
+ include_incognito, contents);
}
int ChromeAutomationInternalApiDelegate::GetTabId(
diff --git a/chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc b/chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc
index 40acfb60..da020fe3 100644
--- a/chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc
+++ b/chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc
@@ -216,9 +216,7 @@
content::WebContents* web_contents = nullptr;
if (!ExtensionTabUtil::GetTabById(params->options.tab_id, browser_context(),
true /* include incognito windows */,
- nullptr /* out_browser */,
- nullptr /* out_tab_strip */, &web_contents,
- nullptr /* out_tab_index */)) {
+ &web_contents)) {
return RespondNow(Error("cannot find specified tab"));
}
diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc
index e5cd5ab18..9b092996 100644
--- a/chrome/browser/extensions/api/debugger/debugger_api.cc
+++ b/chrome/browser/extensions/api/debugger/debugger_api.cc
@@ -421,10 +421,10 @@
bool DebuggerFunction::InitAgentHost() {
if (debuggee_.tab_id) {
- WebContents* web_contents = NULL;
+ WebContents* web_contents = nullptr;
bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id, GetProfile(),
include_incognito_information(),
- NULL, NULL, &web_contents, NULL);
+ &web_contents);
if (result && web_contents) {
// TODO(rdevlin.cronin) This should definitely be GetLastCommittedURL().
GURL url = web_contents->GetVisibleURL();
diff --git a/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc b/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc
index 13b8da3..9b97e1b 100644
--- a/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc
+++ b/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc
@@ -83,7 +83,7 @@
}
if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(),
- true, NULL, NULL, &web_contents, NULL)) {
+ true, &web_contents)) {
error_ = kDesktopCaptureApiInvalidTabIdError;
return false;
}
diff --git a/chrome/browser/extensions/api/extension_action/extension_action_api.cc b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
index ef0c3b6b..84a7a97 100644
--- a/chrome/browser/extensions/api/extension_action/extension_action_api.cc
+++ b/chrome/browser/extensions/api/extension_action/extension_action_api.cc
@@ -283,8 +283,7 @@
// Find the WebContents that contains this tab id if one is required.
if (tab_id_ != ExtensionAction::kDefaultTabId) {
ExtensionTabUtil::GetTabById(tab_id_, browser_context(),
- include_incognito_information(), nullptr,
- nullptr, &contents_, nullptr);
+ include_incognito_information(), &contents_);
if (!contents_)
return RespondNow(Error(kNoTabError, base::NumberToString(tab_id_)));
} else {
diff --git a/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc b/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
index b19df51e..ff4cc1c 100644
--- a/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
+++ b/chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc
@@ -98,8 +98,7 @@
int tab_id) {
content::WebContents* contents = nullptr;
if (!ExtensionTabUtil::GetTabById(tab_id, browser_context,
- /*incognito_enabled=*/true, nullptr,
- nullptr, &contents, nullptr)) {
+ /*incognito_enabled=*/true, &contents)) {
return nullptr;
}
return contents;
diff --git a/chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_api.cc b/chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_api.cc
index 9ad16e7d..579d813 100644
--- a/chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_api.cc
+++ b/chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_api.cc
@@ -46,8 +46,8 @@
content::WebContents* contents = nullptr;
if (!ExtensionTabUtil::GetTabById(params->tab_id, browser_context(),
- include_incognito_information(), nullptr,
- nullptr, &contents, nullptr)) {
+ include_incognito_information(),
+ &contents)) {
return RespondNow(Error(
base::StringPrintf("Could not find tab with id %d.", params->tab_id)));
}
diff --git a/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc b/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
index cbeaa34..0fdb361b 100644
--- a/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
+++ b/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
@@ -412,8 +412,8 @@
content::WebContents* target_contents = nullptr;
if (params->options && params->options->target_tab_id) {
if (!ExtensionTabUtil::GetTabById(*(params->options->target_tab_id),
- browser_context(), true, nullptr, nullptr,
- &target_contents, nullptr)) {
+ browser_context(), true,
+ &target_contents)) {
return RespondNow(Error(kInvalidTabIdError));
}
} else {
@@ -447,8 +447,8 @@
GURL origin;
if (params->options && params->options->consumer_tab_id) {
if (!ExtensionTabUtil::GetTabById(*(params->options->consumer_tab_id),
- browser_context(), true, nullptr, nullptr,
- &consumer_contents, nullptr)) {
+ browser_context(), true,
+ &consumer_contents)) {
return RespondNow(Error(kInvalidTabIdError));
}
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
index 7677465a..c4d8763b 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
@@ -271,7 +271,7 @@
// now.
if (ExtensionTabUtil::GetTabById(ExtensionTabUtil::GetTabId(web_contents()),
web_contents()->GetBrowserContext(), false,
- nullptr, nullptr, nullptr, nullptr)) {
+ nullptr)) {
DispatchCachedOnBeforeNavigate();
}
}
@@ -500,8 +500,8 @@
content::WebContents* web_contents;
if (!ExtensionTabUtil::GetTabById(tab_id, browser_context(),
- include_incognito_information(), nullptr,
- nullptr, &web_contents, nullptr) ||
+ include_incognito_information(),
+ &web_contents) ||
!web_contents) {
return RespondNow(OneArgument(std::make_unique<base::Value>()));
}
@@ -540,8 +540,8 @@
content::WebContents* web_contents;
if (!ExtensionTabUtil::GetTabById(tab_id, browser_context(),
- include_incognito_information(), nullptr,
- nullptr, &web_contents, nullptr) ||
+ include_incognito_information(),
+ &web_contents) ||
!web_contents) {
return RespondNow(OneArgument(std::make_unique<base::Value>()));
}
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
index ce5b7603..88a9423 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
@@ -202,7 +202,7 @@
DCHECK(ExtensionTabUtil::GetTabById(
ExtensionTabUtil::GetTabId(target_web_contents),
Profile::FromBrowserContext(target_web_contents->GetBrowserContext()),
- false, NULL, NULL, NULL, NULL));
+ false, nullptr));
web_navigation::OnCreatedNavigationTarget::Details details;
details.source_tab_id = ExtensionTabUtil::GetTabId(web_contents);
diff --git a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc
index 3896f0b..c79032d 100644
--- a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc
+++ b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.cc
@@ -150,8 +150,7 @@
int tab_id = *request.tab_id;
content::WebContents* contents = nullptr;
- if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, nullptr,
- nullptr, &contents, nullptr)) {
+ if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, &contents)) {
SetError(extensions::ErrorUtils::FormatErrorMessage(
extensions::tabs_constants::kTabNotFoundError,
base::NumberToString(tab_id)));
diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc
index eb78de66..d508ef4 100644
--- a/chrome/browser/extensions/extension_tab_util.cc
+++ b/chrome/browser/extensions/extension_tab_util.cc
@@ -578,6 +578,7 @@
return false;
}
+// static
bool ExtensionTabUtil::GetTabById(int tab_id,
content::BrowserContext* browser_context,
bool include_incognito,
@@ -615,6 +616,15 @@
return false;
}
+// static
+bool ExtensionTabUtil::GetTabById(int tab_id,
+ content::BrowserContext* browser_context,
+ bool include_incognito,
+ WebContents** contents) {
+ return GetTabById(tab_id, browser_context, include_incognito, nullptr,
+ nullptr, contents, nullptr);
+}
+
GURL ExtensionTabUtil::ResolvePossiblyRelativeURL(const std::string& url_string,
const Extension* extension) {
GURL url = GURL(url_string);
diff --git a/chrome/browser/extensions/extension_tab_util.h b/chrome/browser/extensions/extension_tab_util.h
index 8d51f78..f255bc7c 100644
--- a/chrome/browser/extensions/extension_tab_util.h
+++ b/chrome/browser/extensions/extension_tab_util.h
@@ -160,6 +160,10 @@
TabStripModel** tab_strip,
content::WebContents** contents,
int* tab_index);
+ static bool GetTabById(int tab_id,
+ content::BrowserContext* browser_context,
+ bool include_incognito,
+ content::WebContents** contents);
// Takes |url_string| and returns a GURL which is either valid and absolute
// or invalid. If |url_string| is not directly interpretable as a valid (it is