#include "chrome/browser/extensions/extension_tab_util.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include "base/containers/fixed_flat_set.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/types/expected_macros.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/tab_groups/tab_groups_util.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/browser_extension_window_controller.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_utils.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/extensions/api/tabs.h"
#include "chrome/common/url_constants.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/url_formatter/url_fixer.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
#include "extensions/common/manifest_handlers/options_page_info.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permissions_data.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
NavigationEntry;
WebContents;
APIPermissionID;
namespace extensions {
namespace {
enum class NavigationScheme { … };
ExtensionBrowserWindow* ExtensionWindowFromBrowser(const Browser* browser) { … }
Browser* CreateBrowser(Profile* profile, bool user_gesture) { … }
Browser* CreateAndShowBrowser(Profile* profile,
bool user_gesture,
std::string* error) { … }
int GetTabIdForExtensions(const WebContents* web_contents) { … }
bool IsFileUrl(const GURL& url) { … }
ExtensionTabUtil::ScrubTabBehaviorType GetScrubTabBehaviorImpl(
const Extension* extension,
mojom::ContextType context,
const GURL& url,
int tab_id) { … }
bool HasValidMainFrameProcess(content::WebContents* contents) { … }
void RecordNavigationScheme(const GURL& url,
const Extension& extension,
content::BrowserContext* browser_context) { … }
}
ExtensionTabUtil::OpenTabParams::OpenTabParams() = default;
ExtensionTabUtil::OpenTabParams::~OpenTabParams() = default;
base::expected<base::Value::Dict, std::string> ExtensionTabUtil::OpenTab(
ExtensionFunction* function,
const OpenTabParams& params,
bool user_gesture) { … }
Browser* ExtensionTabUtil::GetBrowserFromWindowID(
const ChromeExtensionFunctionDetails& details,
int window_id,
std::string* error) { … }
Browser* ExtensionTabUtil::GetBrowserInProfileWithId(
Profile* profile,
int window_id,
bool also_match_incognito_profile,
std::string* error_message) { … }
int ExtensionTabUtil::GetWindowId(const Browser* browser) { … }
int ExtensionTabUtil::GetWindowIdOfTabStripModel(
const TabStripModel* tab_strip_model) { … }
int ExtensionTabUtil::GetTabId(const WebContents* web_contents) { … }
int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { … }
std::string ExtensionTabUtil::GetBrowserWindowTypeText(const Browser& browser) { … }
api::tabs::Tab ExtensionTabUtil::CreateTabObject(
WebContents* contents,
ScrubTabBehavior scrub_tab_behavior,
const Extension* extension,
TabStripModel* tab_strip,
int tab_index) { … }
base::Value::List ExtensionTabUtil::CreateTabList(const Browser* browser,
const Extension* extension,
mojom::ContextType context) { … }
base::Value::Dict ExtensionTabUtil::CreateWindowValueForExtension(
const Browser& browser,
const Extension* extension,
ExtensionBrowserWindow::PopulateTabBehavior populate_tab_behavior,
mojom::ContextType context) { … }
api::tabs::MutedInfo ExtensionTabUtil::CreateMutedInfo(
content::WebContents* contents) { … }
ExtensionTabUtil::ScrubTabBehavior ExtensionTabUtil::GetScrubTabBehavior(
const Extension* extension,
mojom::ContextType context,
content::WebContents* contents) { … }
ExtensionTabUtil::ScrubTabBehavior ExtensionTabUtil::GetScrubTabBehavior(
const Extension* extension,
mojom::ContextType context,
const GURL& url) { … }
void ExtensionTabUtil::ScrubTabForExtension(
const Extension* extension,
content::WebContents* contents,
api::tabs::Tab* tab,
ScrubTabBehavior scrub_tab_behavior) { … }
bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
TabStripModel** tab_strip_model,
int* tab_index) { … }
bool ExtensionTabUtil::GetDefaultTab(Browser* browser,
WebContents** contents,
int* tab_id) { … }
bool ExtensionTabUtil::GetTabById(int tab_id,
content::BrowserContext* browser_context,
bool include_incognito,
Browser** browser,
TabStripModel** tab_strip,
WebContents** contents,
int* tab_index) { … }
bool ExtensionTabUtil::GetTabById(int tab_id,
content::BrowserContext* browser_context,
bool include_incognito,
WebContents** contents) { … }
std::vector<content::WebContents*>
ExtensionTabUtil::GetAllActiveWebContentsForContext(
content::BrowserContext* browser_context,
bool include_incognito) { … }
bool ExtensionTabUtil::IsWebContentsInContext(
content::WebContents* web_contents,
content::BrowserContext* browser_context,
bool include_incognito) { … }
GURL ExtensionTabUtil::ResolvePossiblyRelativeURL(const std::string& url_string,
const Extension* extension) { … }
bool ExtensionTabUtil::IsKillURL(const GURL& url) { … }
base::expected<GURL, std::string> ExtensionTabUtil::PrepareURLForNavigation(
const std::string& url_string,
const Extension* extension,
content::BrowserContext* browser_context) { … }
void ExtensionTabUtil::CreateTab(
std::unique_ptr<WebContents> web_contents,
const std::string& extension_id,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& window_features,
bool user_gesture) { … }
void ExtensionTabUtil::ForEachTab(
base::RepeatingCallback<void(WebContents*)> callback) { … }
WindowController* ExtensionTabUtil::GetWindowControllerOfTab(
const WebContents* web_contents) { … }
bool ExtensionTabUtil::OpenOptionsPageFromAPI(
const Extension* extension,
content::BrowserContext* browser_context) { … }
bool ExtensionTabUtil::OpenOptionsPage(const Extension* extension,
Browser* browser) { … }
bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { … }
api::tabs::TabStatus ExtensionTabUtil::GetLoadingStatus(WebContents* contents) { … }
void ExtensionTabUtil::ClearBackForwardCache() { … }
bool ExtensionTabUtil::IsTabStripEditable() { … }
TabStripModel* ExtensionTabUtil::GetEditableTabStripModel(Browser* browser) { … }
bool ExtensionTabUtil::TabIsInSavedTabGroup(content::WebContents* contents,
TabStripModel* tab_strip_model) { … }
}