#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include <stddef.h>
#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/escape.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/types/expected.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/api/tab_groups/tab_groups_constants.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/api/tabs/windows_util.h"
#include "chrome/browser/extensions/browser_extension_window_controller.h"
#include "chrome/browser/extensions/extension_browser_window.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/extensions/window_controller_list.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service.h"
#include "chrome/browser/safe_browsing/extension_telemetry/tabs_api_signal.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.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/recently_audible_helper.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_user_gesture_details.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/common/extensions/api/tabs.h"
#include "chrome/common/extensions/api/windows.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/common/language_detection_details.h"
#include "components/webapps/common/web_app_id.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_zoom_request_client.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/file_reader.h"
#include "extensions/browser/script_executor.h"
#include "extensions/common/api/extension_types.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/default_locale_handler.h"
#include "extensions/common/message_bundle.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/host_id.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/user_script.h"
#include "skia/ext/image_operations.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/ozone_buildflags.h"
#include "ui/base/ui_base_types.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/rect.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/chromeos/window_pin_util.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "content/public/browser/devtools_agent_host.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_buffer.h"
#endif
BrowserThread;
NavigationController;
NavigationEntry;
OpenURLParams;
Referrer;
WebContents;
TabModel;
ZoomController;
namespace extensions {
windows;
tabs;
InjectDetails;
namespace {
template <typename T>
class ApiParameterExtractor { … };
bool GetBrowserFromWindowID(const ChromeExtensionFunctionDetails& details,
int window_id,
Browser** browser,
std::string* error) { … }
bool GetBrowserFromWindowID(ExtensionFunction* function,
int window_id,
Browser** browser,
std::string* error) { … }
bool GetTabById(int tab_id,
content::BrowserContext* context,
bool include_incognito,
Browser** browser,
TabStripModel** tab_strip,
content::WebContents** contents,
int* tab_index,
std::string* error_message) { … }
content::WebContents* GetTabsAPIDefaultWebContents(ExtensionFunction* function,
int tab_id,
std::string* error) { … }
bool MatchesBool(const std::optional<bool>& boolean, bool value) { … }
ui::WindowShowState ConvertToWindowShowState(windows::WindowState state) { … }
bool IsValidStateForWindowsCreateFunction(
const windows::Create::Params::CreateData* create_data) { … }
bool ExtensionHasLockedFullscreenPermission(const Extension* extension) { … }
api::tabs::Tab CreateTabObjectHelper(WebContents* contents,
const Extension* extension,
mojom::ContextType context,
TabStripModel* tab_strip,
int tab_index) { … }
int MoveTabToWindow(ExtensionFunction* function,
int tab_id,
Browser* target_browser,
int new_index,
std::string* error) { … }
void SetLockedFullscreenState(Browser* browser, bool pinned) { … }
bool WindowBoundsIntersectDisplays(const gfx::Rect& bounds) { … }
void NotifyExtensionTelemetry(Profile* profile,
const Extension* extension,
safe_browsing::TabsApiInfo::ApiMethod api_method,
const std::string& current_url,
const std::string& new_url,
const std::optional<StackTrace>& js_callstack) { … }
}
void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode,
api::tabs::ZoomSettings* zoom_settings) { … }
ExtensionFunction::ResponseAction WindowsGetFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsGetCurrentFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsGetLastFocusedFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsGetAllFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsCreateFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsUpdateFunction::Run() { … }
ExtensionFunction::ResponseAction WindowsRemoveFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetSelectedFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetAllInWindowFunction::Run() { … }
ExtensionFunction::ResponseAction TabsQueryFunction::Run() { … }
ExtensionFunction::ResponseAction TabsCreateFunction::Run() { … }
ExtensionFunction::ResponseAction TabsDuplicateFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetCurrentFunction::Run() { … }
ExtensionFunction::ResponseAction TabsHighlightFunction::Run() { … }
bool TabsHighlightFunction::HighlightTab(TabStripModel* tabstrip,
ui::ListSelectionModel* selection,
std::optional<size_t>* active_index,
int index,
std::string* error) { … }
TabsUpdateFunction::TabsUpdateFunction() : … { … }
ExtensionFunction::ResponseAction TabsUpdateFunction::Run() { … }
bool TabsUpdateFunction::UpdateURL(const std::string& url_string,
int tab_id,
std::string* error) { … }
ExtensionFunction::ResponseValue TabsUpdateFunction::GetResult() { … }
ExtensionFunction::ResponseAction TabsMoveFunction::Run() { … }
bool TabsMoveFunction::MoveTab(int tab_id,
int* new_index,
base::Value::List& tab_values,
const std::optional<int>& window_id,
std::string* error) { … }
ExtensionFunction::ResponseAction TabsReloadFunction::Run() { … }
TabsRemoveFunction::TabsRemoveFunction() = default;
TabsRemoveFunction::~TabsRemoveFunction() = default;
ExtensionFunction::ResponseAction TabsRemoveFunction::Run() { … }
bool TabsRemoveFunction::RemoveTab(int tab_id, std::string* error) { … }
void TabsRemoveFunction::TabDestroyed() { … }
class TabsRemoveFunction::WebContentsDestroyedObserver
: public content::WebContentsObserver { … };
ExtensionFunction::ResponseAction TabsGroupFunction::Run() { … }
ExtensionFunction::ResponseAction TabsUngroupFunction::Run() { … }
bool TabsUngroupFunction::UngroupTab(int tab_id, std::string* error) { … }
bool TabsCaptureVisibleTabFunction::disable_throttling_for_test_ = …;
TabsCaptureVisibleTabFunction::TabsCaptureVisibleTabFunction()
: … { … }
WebContentsCaptureClient::ScreenshotAccess
TabsCaptureVisibleTabFunction::GetScreenshotAccess(
content::WebContents* web_contents) const { … }
bool TabsCaptureVisibleTabFunction::ClientAllowsTransparency() { … }
WebContents* TabsCaptureVisibleTabFunction::GetWebContentsForID(
int window_id,
std::string* error) { … }
ExtensionFunction::ResponseAction TabsCaptureVisibleTabFunction::Run() { … }
void TabsCaptureVisibleTabFunction::GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const { … }
bool TabsCaptureVisibleTabFunction::ShouldSkipQuotaLimiting() const { … }
void TabsCaptureVisibleTabFunction::OnCaptureSuccess(const SkBitmap& bitmap) { … }
void TabsCaptureVisibleTabFunction::EncodeBitmapOnWorkerThread(
scoped_refptr<base::TaskRunner> reply_task_runner,
const SkBitmap& bitmap) { … }
void TabsCaptureVisibleTabFunction::OnBitmapEncodedOnUIThread(
bool success,
std::string base64_result) { … }
void TabsCaptureVisibleTabFunction::OnCaptureFailure(CaptureResult result) { … }
std::string TabsCaptureVisibleTabFunction::CaptureResultToErrorMessage(
CaptureResult result) { … }
void TabsCaptureVisibleTabFunction::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
ExtensionFunction::ResponseAction TabsDetectLanguageFunction::Run() { … }
void TabsDetectLanguageFunction::NavigationEntryCommitted(
const content::LoadCommittedDetails& load_details) { … }
void TabsDetectLanguageFunction::WebContentsDestroyed() { … }
void TabsDetectLanguageFunction::OnLanguageDetermined(
const translate::LanguageDetectionDetails& details) { … }
void TabsDetectLanguageFunction::RespondWithLanguage(
const std::string& language) { … }
ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
: … { … }
ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() { … }
ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() { … }
bool ExecuteCodeInTabFunction::ShouldInsertCSS() const { … }
bool ExecuteCodeInTabFunction::ShouldRemoveCSS() const { … }
bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage(std::string* error) { … }
ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor(
std::string* error) { … }
bool ExecuteCodeInTabFunction::IsWebView() const { … }
const GURL& ExecuteCodeInTabFunction::GetWebViewSrc() const { … }
bool TabsInsertCSSFunction::ShouldInsertCSS() const { … }
bool TabsRemoveCSSFunction::ShouldRemoveCSS() const { … }
ExtensionFunction::ResponseAction TabsSetZoomFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetZoomFunction::Run() { … }
ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() { … }
ExtensionFunction::ResponseAction TabsDiscardFunction::Run() { … }
TabsDiscardFunction::TabsDiscardFunction() { … }
TabsDiscardFunction::~TabsDiscardFunction() { … }
ExtensionFunction::ResponseAction TabsGoForwardFunction::Run() { … }
ExtensionFunction::ResponseAction TabsGoBackFunction::Run() { … }
}