chromium/chrome/browser/background/background_contents_service.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/background/background_contents_service.h"

#include <utility>

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/one_shot_event.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "chrome/browser/apps/platform_apps/app_load_service.h"
#include "chrome/browser/background/background_contents_service_factory.h"
#include "chrome/browser/background/background_contents_service_observer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/notifications/notification_common.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/image_loader.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/icons/extension_icon_set.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "extensions/grit/extensions_browser_resources.h"
#include "ipc/ipc_message.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/notifier_catalogs.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

SiteInstance;
WebContents;
BackgroundInfo;
Extension;
UnloadedExtensionReason;

namespace {

const char kCrashedNotificationPrefix[] =;
const char kNotifierId[] =;
bool g_disable_close_balloon_for_testing =;

void CloseBalloon(const std::string& extension_id, Profile* profile) {}

// Delegate for the app/extension crash notification balloon. Restarts the
// app/extension when the balloon is clicked.
class CrashNotificationDelegate : public message_center::NotificationDelegate {};

void ReloadExtension(const std::string& extension_id, Profile* profile) {}

}  // namespace

// Keys for the information we store about individual BackgroundContents in
// prefs. There is one top-level base::Value::Dict (stored at
// prefs::kRegisteredBackgroundContents). Information about each
// BackgroundContents is stored under that top-level base::Value::Dict, keyed
// by the parent application ID for easy lookup.
//
// kRegisteredBackgroundContents:
//    base::Value::Dict {
//       <appid_1>: { "url": <url1>, "name": <frame_name> },
//       <appid_2>: { "url": <url2>, "name": <frame_name> },
//         ... etc ...
//    }
const char kUrlKey[] =;
const char kFrameNameKey[] =;

// Defines the backoff policy used for attempting to reload extensions.
const net::BackoffEntry::Policy kExtensionReloadBackoffPolicy =;

int BackgroundContentsService::restart_delay_in_ms_ =;  // 3 seconds.

BackgroundContentsService::BackgroundContentsService(Profile* profile)
    :{}

BackgroundContentsService::~BackgroundContentsService() {}

// static
void BackgroundContentsService::
    SetRestartDelayForForceInstalledAppsAndExtensionsForTesting(
        int restart_delay_in_ms) {}

// static
std::string
BackgroundContentsService::GetNotificationDelegateIdForExtensionForTesting(
    const std::string& extension_id) {}

// static
void BackgroundContentsService::DisableCloseBalloonForTesting(
    bool disable_close_balloon_for_testing) {}

void BackgroundContentsService::ShowBalloonForTesting(
    const extensions::Extension* extension) {}

std::vector<BackgroundContents*>
BackgroundContentsService::GetBackgroundContents() const {}

void BackgroundContentsService::StartObserving() {}

void BackgroundContentsService::OnExtensionSystemReady() {}

void BackgroundContentsService::OnExtensionHostRenderProcessGone(
    content::BrowserContext* browser_context,
    extensions::ExtensionHost* extension_host) {}

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

void BackgroundContentsService::OnExtensionUnloaded(
    content::BrowserContext* browser_context,
    const extensions::Extension* extension,
    extensions::UnloadedExtensionReason reason) {}

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

void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
    const Extension* extension) {}

// Loads all background contents whose urls have been stored in prefs.
void BackgroundContentsService::LoadBackgroundContentsFromPrefs() {}

void BackgroundContentsService::SendChangeNotification() {}

void BackgroundContentsService::MaybeClearBackoffEntry(
    const std::string extension_id,
    int expected_failure_count) {}

void BackgroundContentsService::LoadBackgroundContentsForExtension(
    const std::string& extension_id) {}

void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
    const std::string& extension_id,
    const base::Value::Dict& contents) {}

void BackgroundContentsService::LoadBackgroundContentsFromManifests() {}

void BackgroundContentsService::LoadBackgroundContents(
    const GURL& url,
    const std::string& frame_name,
    const std::string& application_id) {}

BackgroundContents* BackgroundContentsService::CreateBackgroundContents(
    scoped_refptr<SiteInstance> site,
    content::RenderFrameHost* opener,
    bool is_new_browsing_instance,
    const std::string& frame_name,
    const std::string& application_id,
    const content::StoragePartitionConfig& partition_config,
    content::SessionStorageNamespace* session_storage_namespace) {}

void BackgroundContentsService::DeleteBackgroundContents(
    BackgroundContents* contents) {}

void BackgroundContentsService::RegisterBackgroundContents(
    BackgroundContents* background_contents) {}

bool BackgroundContentsService::HasRegisteredBackgroundContents(
    const std::string& app_id) {}

void BackgroundContentsService::UnregisterBackgroundContents(
    BackgroundContents* background_contents) {}

void BackgroundContentsService::ShutdownAssociatedBackgroundContents(
    const std::string& appid) {}

void BackgroundContentsService::AddBackgroundContents(
    std::unique_ptr<BackgroundContents> contents,
    const std::string& application_id,
    const std::string& frame_name) {}

// Used by test code and debug checks to verify whether a given
// BackgroundContents is being tracked by this instance.
bool BackgroundContentsService::IsTracked(
    BackgroundContents* background_contents) const {}

void BackgroundContentsService::AddObserver(
    BackgroundContentsServiceObserver* observer) {}

void BackgroundContentsService::RemoveObserver(
    BackgroundContentsServiceObserver* observer) {}

BackgroundContents* BackgroundContentsService::GetAppBackgroundContents(
    const std::string& application_id) {}

const std::string& BackgroundContentsService::GetParentApplicationId(
    BackgroundContents* contents) const {}

void BackgroundContentsService::AddWebContents(
    std::unique_ptr<WebContents> new_contents,
    const GURL& target_url,
    WindowOpenDisposition disposition,
    const blink::mojom::WindowFeatures& window_features,
    bool* was_blocked) {}

void BackgroundContentsService::OnBackgroundContentsNavigated(
    BackgroundContents* contents) {}

void BackgroundContentsService::OnBackgroundContentsTerminated(
    BackgroundContents* contents) {}

void BackgroundContentsService::OnBackgroundContentsClosed(
    BackgroundContents* contents) {}

void BackgroundContentsService::Shutdown() {}

void BackgroundContentsService::HandleExtensionCrashed(
    const extensions::Extension* extension) {}

void BackgroundContentsService::NotificationImageReady(
    const std::string extension_name,
    const std::string extension_id,
    const std::u16string message,
    scoped_refptr<message_center::NotificationDelegate> delegate,
    const gfx::Image& icon) {}

// Show a popup notification balloon with a crash message for a given app/
// extension.
void BackgroundContentsService::ShowBalloon(const Extension* extension) {}

BackgroundContentsService::BackgroundContentsInfo::BackgroundContentsInfo() =
    default;
BackgroundContentsService::BackgroundContentsInfo::~BackgroundContentsInfo() =
    default;