chromium/chrome/browser/extensions/api/extension_action/extension_action_api.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"

#include <stddef.h>

#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/common/color_parser.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/prefs_helper.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/api/extension_action/action_info.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/image_util.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "url/origin.h"

WebContents;

namespace extensions {

namespace {

// Errors.
const char kNoExtensionActionError[] =;
const char kNoTabError[] =;
const char kOpenPopupError[] =;
const char kFailedToOpenPopupGenericError[] =;
constexpr char kNoActiveWindowFound[] =;
constexpr char kNoActivePopup[] =;
constexpr char kOpenPopupInactiveWindow[] =;

bool g_report_error_for_invisible_icon =;

// Returns the browser that was last active in the given `profile`, optionally
// also checking the incognito profile.
Browser* FindLastActiveBrowserWindow(Profile* profile,
                                     bool check_incognito_profile) {}

// Returns true if the color values provided could be parsed into a color
// object out param.
bool ParseColor(const base::Value& color_value, SkColor& color) {}

// Returns true if the given `extension` has an active popup on the active tab
// of `browser`.
bool HasPopupOnActiveTab(Browser* browser,
                         content::BrowserContext* browser_context,
                         const Extension& extension) {}

// Attempts to open `extension`'s popup in the given `browser`. Returns true on
// success; otherwise, populates `error` and returns false.
bool OpenPopupInBrowser(Browser& browser,
                        const Extension& extension,
                        std::string* error,
                        ShowPopupCallback callback) {}

}  // namespace

//
// ExtensionActionAPI::Observer
//

void ExtensionActionAPI::Observer::OnExtensionActionUpdated(
    ExtensionAction* extension_action,
    content::WebContents* web_contents,
    content::BrowserContext* browser_context) {}

void ExtensionActionAPI::Observer::OnExtensionActionAPIShuttingDown() {}

ExtensionActionAPI::Observer::~Observer() {}

//
// ExtensionActionAPI
//

static base::LazyInstance<BrowserContextKeyedAPIFactory<ExtensionActionAPI>>::
    DestructorAtExit g_extension_action_api_factory =;

ExtensionActionAPI::ExtensionActionAPI(content::BrowserContext* context)
    :{}

ExtensionActionAPI::~ExtensionActionAPI() {}

// static
BrowserContextKeyedAPIFactory<ExtensionActionAPI>*
ExtensionActionAPI::GetFactoryInstance() {}

// static
ExtensionActionAPI* ExtensionActionAPI::Get(content::BrowserContext* context) {}

void ExtensionActionAPI::AddObserver(Observer* observer) {}

void ExtensionActionAPI::RemoveObserver(Observer* observer) {}

void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action,
                                      content::WebContents* web_contents,
                                      content::BrowserContext* context) {}

void ExtensionActionAPI::DispatchExtensionActionClicked(
    const ExtensionAction& extension_action,
    WebContents* web_contents,
    const Extension* extension) {}

void ExtensionActionAPI::ClearAllValuesForTab(
    content::WebContents* web_contents) {}

ExtensionPrefs* ExtensionActionAPI::GetExtensionPrefs() {}

void ExtensionActionAPI::DispatchEventToExtension(
    content::BrowserContext* context,
    const ExtensionId& extension_id,
    events::HistogramValue histogram_value,
    const std::string& event_name,
    base::Value::List event_args) {}

void ExtensionActionAPI::Shutdown() {}

void ExtensionActionAPI::OnActionPinnedStateChanged(
    const ExtensionId& extension_id,
    bool is_pinned) {}

//
// ExtensionActionFunction
//

ExtensionActionFunction::ExtensionActionFunction()
    :{}

ExtensionActionFunction::~ExtensionActionFunction() {}

ExtensionFunction::ResponseAction ExtensionActionFunction::Run() {}

bool ExtensionActionFunction::ExtractDataFromArguments() {}

void ExtensionActionFunction::NotifyChange() {}

void ExtensionActionFunction::SetVisible(bool visible) {}

ExtensionFunction::ResponseAction
ExtensionActionShowFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionHideFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ActionIsEnabledFunction::RunExtensionAction() {}

// static
void ExtensionActionSetIconFunction::SetReportErrorForInvisibleIconForTesting(
    bool value) {}

ExtensionFunction::ResponseAction
ExtensionActionSetIconFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionSetTitleFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionSetPopupFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionSetBadgeTextFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ActionSetBadgeTextColorFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionGetTitleFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionGetPopupFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionGetBadgeTextFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() {}

ExtensionFunction::ResponseAction
ActionGetBadgeTextColorFunction::RunExtensionAction() {}

ActionGetUserSettingsFunction::ActionGetUserSettingsFunction() = default;
ActionGetUserSettingsFunction::~ActionGetUserSettingsFunction() = default;

ExtensionFunction::ResponseAction ActionGetUserSettingsFunction::Run() {}

ActionOpenPopupFunction::ActionOpenPopupFunction() = default;
ActionOpenPopupFunction::~ActionOpenPopupFunction() = default;

ExtensionFunction::ResponseAction ActionOpenPopupFunction::Run() {}

void ActionOpenPopupFunction::OnShowPopupComplete(ExtensionHost* popup_host) {}

BrowserActionOpenPopupFunction::BrowserActionOpenPopupFunction() = default;
BrowserActionOpenPopupFunction::~BrowserActionOpenPopupFunction() = default;

ExtensionFunction::ResponseAction BrowserActionOpenPopupFunction::Run() {}

void BrowserActionOpenPopupFunction::OnBrowserContextShutdown() {}

void BrowserActionOpenPopupFunction::OpenPopupTimedOut() {}

void BrowserActionOpenPopupFunction::OnExtensionHostCompletedFirstLoad(
    content::BrowserContext* browser_context,
    ExtensionHost* host) {}

}  // namespace extensions