chromium/extensions/browser/api/runtime/runtime_api.cc

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

#include "extensions/browser/api/runtime/runtime_api.h"

#include <memory>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/notreached.h"
#include "base/one_shot_event.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/values.h"
#include "base/version.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/child_process_security_policy.h"
#include "extensions/browser/api/runtime/runtime_api_delegate.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/events/lazy_event_dispatch_util.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/lazy_context_id.h"
#include "extensions/browser/lazy_context_task_queue.h"
#include "extensions/browser/process_manager_factory.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/api/runtime.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/manifest_handlers/shared_module_info.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "storage/browser/file_system/isolated_context.h"
#include "url/gurl.h"

BrowserContext;

namespace extensions {

runtime;

namespace {

const char kNoBackgroundPageError[] =;
const char kPageLoadError[] =;
const char kFailedToCreateOptionsPage[] =;
const char kInstallId[] =;
const char kInstallReason[] =;
const char kInstallReasonChromeUpdate[] =;
const char kInstallReasonUpdate[] =;
const char kInstallReasonInstall[] =;
const char kInstallReasonSharedModuleUpdate[] =;
const char kInstallPreviousVersion[] =;
const char kInvalidUrlError[] =;
const char kPlatformInfoUnavailable[] =;

const char kUpdatesDisabledError[] =;

// A preference key storing the url loaded when an extension is uninstalled.
const char kUninstallUrl[] =;

// The name of the directory to be returned by getPackageDirectoryEntry. This
// particular value does not matter to user code, but is chosen for consistency
// with the equivalent Pepper API.
const char kPackageDirectoryPath[] =;

// Preference key for storing the last successful restart due to a call to
// chrome.runtime.restartAfterDelay().
constexpr char kPrefLastRestartAfterDelayTime[] =;
// Preference key for storing whether the most recent restart was due to a
// successful call to chrome.runtime.restartAfterDelay().
constexpr char kPrefLastRestartWasDueToDelayedRestartApi[] =;

// Error and status messages strings for the restartAfterDelay() API.
constexpr char kErrorInvalidArgument[] =;
constexpr char kErrorOnlyKioskModeAllowed[] =;
constexpr char kErrorOnlyFirstExtensionAllowed[] =;
constexpr char kErrorInvalidStatus[] =;
constexpr char kErrorRequestedTooSoon[] =;

constexpr int kMinDurationBetweenSuccessiveRestartsHours =;

// This is used for unit tests, so that we can test the restartAfterDelay
// API without a kiosk app.
bool allow_non_kiosk_apps_restart_api_for_test =;

void DispatchOnStartupEventImpl(
    BrowserContext* browser_context,
    const ExtensionId& extension_id,
    bool first_call,
    std::unique_ptr<LazyContextTaskQueue::ContextInfo> context_info) {}

std::string GetUninstallURL(ExtensionPrefs* prefs,
                            const ExtensionId& extension_id) {}

// Returns true if the given `context` matches the `filter`.
bool ExtensionContextMatchesFilter(
    const api::runtime::ExtensionContext& context,
    const api::runtime::ContextFilter& filter) {}

}  // namespace

///////////////////////////////////////////////////////////////////////////////

static base::LazyInstance<
    BrowserContextKeyedAPIFactory<RuntimeAPI>>::DestructorAtExit g_factory =;

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

constexpr int RuntimeAPI::kFastReloadCount;
constexpr int RuntimeAPI::kUnpackedFastReloadCount;

// static
void RuntimeAPI::RegisterPrefs(PrefRegistrySimple* registry) {}

template <>
void BrowserContextKeyedAPIFactory<RuntimeAPI>::DeclareFactoryDependencies() {}

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

RuntimeAPI::~RuntimeAPI() = default;

void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
                                   const Extension* extension) {}

void RuntimeAPI::OnExtensionUninstalled(
    content::BrowserContext* browser_context,
    const Extension* extension,
    UninstallReason reason) {}

void RuntimeAPI::Shutdown() {}

void RuntimeAPI::OnAppUpdateAvailable(const Extension* extension) {}

void RuntimeAPI::OnChromeUpdateAvailable() {}

void RuntimeAPI::OnBackgroundHostStartup(const Extension* extension) {}

void RuntimeAPI::ReloadExtension(const ExtensionId& extension_id) {}

bool RuntimeAPI::CheckForUpdates(
    const ExtensionId& extension_id,
    RuntimeAPIDelegate::UpdateCheckCallback callback) {}

void RuntimeAPI::OpenURL(const GURL& update_url) {}

bool RuntimeAPI::GetPlatformInfo(runtime::PlatformInfo* info) {}

bool RuntimeAPI::RestartDevice(std::string* error_message) {}

RuntimeAPI::RestartAfterDelayStatus RuntimeAPI::RestartDeviceAfterDelay(
    const ExtensionId& extension_id,
    int seconds_from_now) {}

bool RuntimeAPI::OpenOptionsPage(const Extension* extension,
                                 content::BrowserContext* browser_context) {}

void RuntimeAPI::MaybeCancelRunningDelayedRestartTimer() {}

void RuntimeAPI::OnExtensionsReady() {}

RuntimeAPI::RestartAfterDelayStatus RuntimeAPI::ScheduleDelayedRestart(
    const base::Time& now,
    int seconds_from_now) {}

void RuntimeAPI::OnDelayedRestartTimerTimeout() {}

void RuntimeAPI::AllowNonKioskAppsInRestartAfterDelayForTesting() {}

///////////////////////////////////////////////////////////////////////////////

// static
void RuntimeEventRouter::DispatchOnStartupEvent(
    content::BrowserContext* context,
    const ExtensionId& extension_id) {}

// static
void RuntimeEventRouter::DispatchOnInstalledEvent(
    void* context_id,
    const ExtensionId& extension_id,
    const base::Version& old_version,
    bool chrome_updated) {}

// static
void RuntimeEventRouter::DispatchOnUpdateAvailableEvent(
    content::BrowserContext* context,
    const ExtensionId& extension_id,
    const base::Value::Dict* manifest) {}

// static
void RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent(
    content::BrowserContext* context) {}

// static
void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
    content::BrowserContext* context,
    const std::string& app_id,
    api::runtime::OnRestartRequiredReason reason) {}

// static
void RuntimeEventRouter::OnExtensionUninstalled(
    content::BrowserContext* context,
    const ExtensionId& extension_id,
    UninstallReason reason) {}

void RuntimeAPI::OnExtensionInstalledAndLoaded(
    content::BrowserContext* browser_context,
    const Extension* extension,
    const base::Version& previous_version) {}

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

void RuntimeGetBackgroundPageFunction::OnPageLoaded(
    std::unique_ptr<LazyContextTaskQueue::ContextInfo> context_info) {}

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

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

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

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

void RuntimeRequestUpdateCheckFunction::CheckComplete(
    const RuntimeAPIDelegate::UpdateCheckResult& result) {}

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

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

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

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

RuntimeGetContextsFunction::RuntimeGetContextsFunction() = default;
RuntimeGetContextsFunction::~RuntimeGetContextsFunction() = default;

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

std::optional<api::runtime::ExtensionContext>
RuntimeGetContextsFunction::GetWorkerContext() {}

std::vector<api::runtime::ExtensionContext>
RuntimeGetContextsFunction::GetFrameContexts() {}

}  // namespace extensions