#include "extensions/browser/process_manager.h"
#include <memory>
#include <unordered_set>
#include <vector>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/one_shot_event.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/uuid.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.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_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/service_worker_external_request_result.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.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_delegate.h"
#include "extensions/browser/process_manager_factory.h"
#include "extensions/browser/process_manager_observer.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/browser/view_type_utils.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/incognito_info.h"
#include "extensions/common/mojom/renderer.mojom.h"
#include "extensions/common/mojom/view_type.mojom.h"
BrowserContext;
namespace extensions {
namespace {
base::TimeDelta g_event_page_idle_time = …;
unsigned g_event_page_suspending_time_msec = …;
ExtensionId GetExtensionID(content::RenderFrameHost* render_frame_host) { … }
bool IsFrameInExtensionHost(ExtensionHost* extension_host,
content::RenderFrameHost* render_frame_host) { … }
class IncognitoProcessManager : public ProcessManager { … };
static void CreateBackgroundHostForExtensionLoad(
ProcessManager* manager, const Extension* extension) { … }
void PropagateExtensionWakeResult(
base::OnceCallback<void(bool)> callback,
std::unique_ptr<LazyContextTaskQueue::ContextInfo> context_info) { … }
}
struct ProcessManager::BackgroundPageData { … };
struct ProcessManager::ExtensionRenderFrameData { … };
ProcessManager* ProcessManager::Get(BrowserContext* context) { … }
ProcessManager* ProcessManager::Create(BrowserContext* context) { … }
ProcessManager* ProcessManager::CreateForTesting(
BrowserContext* context,
ExtensionRegistry* extension_registry) { … }
ProcessManager* ProcessManager::CreateIncognitoForTesting(
BrowserContext* incognito_context,
BrowserContext* original_context,
ExtensionRegistry* extension_registry) { … }
ProcessManager::ProcessManager(BrowserContext* context,
BrowserContext* original_context,
ExtensionRegistry* extension_registry)
: … { … }
ProcessManager::~ProcessManager() { … }
void ProcessManager::Shutdown() { … }
void ProcessManager::RegisterRenderFrameHost(
content::WebContents* web_contents,
content::RenderFrameHost* render_frame_host,
const Extension* extension) { … }
void ProcessManager::UnregisterRenderFrameHost(
content::RenderFrameHost* render_frame_host) { … }
scoped_refptr<content::SiteInstance> ProcessManager::GetSiteInstanceForURL(
const GURL& url) { … }
const ProcessManager::FrameSet ProcessManager::GetAllFrames() const { … }
ProcessManager::FrameSet ProcessManager::GetRenderFrameHostsForExtension(
const ExtensionId& extension_id) { … }
bool ProcessManager::IsRenderFrameHostRegistered(
content::RenderFrameHost* render_frame_host) { … }
void ProcessManager::AddObserver(ProcessManagerObserver* observer) { … }
void ProcessManager::RemoveObserver(ProcessManagerObserver* observer) { … }
bool ProcessManager::CreateBackgroundHost(const Extension* extension,
const GURL& url) { … }
void ProcessManager::MaybeCreateStartupBackgroundHosts() { … }
ExtensionHost* ProcessManager::GetBackgroundHostForExtension(
const ExtensionId& extension_id) { … }
ExtensionHost* ProcessManager::GetBackgroundHostForRenderFrameHost(
content::RenderFrameHost* render_frame_host) { … }
bool ProcessManager::IsEventPageSuspended(const ExtensionId& extension_id) { … }
bool ProcessManager::WakeEventPage(const ExtensionId& extension_id,
base::OnceCallback<void(bool)> callback) { … }
bool ProcessManager::IsBackgroundHostClosing(const ExtensionId& extension_id) { … }
const Extension* ProcessManager::GetExtensionForRenderFrameHost(
content::RenderFrameHost* render_frame_host) { … }
const Extension* ProcessManager::GetExtensionForWebContents(
content::WebContents* web_contents) { … }
int ProcessManager::GetLazyKeepaliveCount(const Extension* extension) { … }
void ProcessManager::IncrementLazyKeepaliveCount(
const Extension* extension,
Activity::Type activity_type,
const std::string& extra_data) { … }
void ProcessManager::DecrementLazyKeepaliveCount(
const Extension* extension,
Activity::Type activity_type,
const std::string& extra_data) { … }
void ProcessManager::NotifyExtensionProcessTerminated(
const Extension* extension) { … }
ProcessManager::ActivitiesMultiset ProcessManager::GetLazyKeepaliveActivities(
const Extension* extension) { … }
void ProcessManager::OnShouldSuspendAck(const ExtensionId& extension_id,
uint64_t sequence_id) { … }
void ProcessManager::OnSuspendAck(const ExtensionId& extension_id) { … }
void ProcessManager::NetworkRequestStarted(
content::RenderFrameHost* render_frame_host,
uint64_t request_id) { … }
void ProcessManager::NetworkRequestDone(
content::RenderFrameHost* render_frame_host,
uint64_t request_id) { … }
void ProcessManager::CancelSuspend(const Extension* extension) { … }
void ProcessManager::CloseBackgroundHosts() { … }
void ProcessManager::SetEventPageIdleTimeForTesting(unsigned idle_time_msec) { … }
void ProcessManager::SetEventPageSuspendingTimeForTesting(
unsigned suspending_time_msec) { … }
void ProcessManager::OnExtensionLoaded(BrowserContext* browser_context,
const Extension* extension) { … }
void ProcessManager::OnExtensionUnloaded(BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
void ProcessManager::CreateStartupBackgroundHosts() { … }
void ProcessManager::OnBackgroundHostCreated(ExtensionHost* host) { … }
void ProcessManager::CloseBackgroundHost(ExtensionHost* host) { … }
void ProcessManager::AcquireLazyKeepaliveCountForFrame(
content::RenderFrameHost* render_frame_host) { … }
void ProcessManager::ReleaseLazyKeepaliveCountForFrame(
content::RenderFrameHost* render_frame_host) { … }
base::Uuid ProcessManager::IncrementServiceWorkerKeepaliveCount(
const WorkerId& worker_id,
content::ServiceWorkerExternalRequestTimeoutType timeout_type,
Activity::Type activity_type,
const std::string& extra_data) { … }
void ProcessManager::DecrementLazyKeepaliveCount(
const ExtensionId& extension_id,
Activity::Type activity_type,
const std::string& extra_data) { … }
void ProcessManager::DecrementServiceWorkerKeepaliveCount(
const WorkerId& worker_id,
const base::Uuid& request_uuid,
Activity::Type activity_type,
const std::string& extra_data) { … }
void ProcessManager::OnLazyBackgroundPageIdle(const ExtensionId& extension_id,
uint64_t sequence_id) { … }
void ProcessManager::OnLazyBackgroundPageActive(
const ExtensionId& extension_id) { … }
void ProcessManager::CloseLazyBackgroundPageNow(const ExtensionId& extension_id,
uint64_t sequence_id) { … }
const Extension* ProcessManager::GetExtensionForAgentHost(
content::DevToolsAgentHost* agent_host) { … }
void ProcessManager::DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) { … }
void ProcessManager::DevToolsAgentHostDetached(
content::DevToolsAgentHost* agent_host) { … }
void ProcessManager::UnregisterExtension(const ExtensionId& extension_id) { … }
void ProcessManager::StartTrackingServiceWorkerRunningInstance(
const WorkerId& worker_id) { … }
void ProcessManager::RenderProcessExited(
content::RenderProcessHost* host,
const content::ChildProcessTerminationInfo& info) { … }
void ProcessManager::OnExtensionHostDestroyed(ExtensionHost* host) { … }
void ProcessManager::HandleCloseExtensionHost(ExtensionHost* host) { … }
void ProcessManager::StopTrackingServiceWorkerRunningInstance(
const WorkerId& worker_id) { … }
void ProcessManager::StopTrackingServiceWorkerRunningInstance(
const ExtensionId& extension_id,
int64_t worker_version_id) { … }
bool ProcessManager::HasServiceWorker(const WorkerId& worker_id) const { … }
std::vector<WorkerId> ProcessManager::GetServiceWorkersForExtension(
const ExtensionId& extension_id) const { … }
base::Uuid ProcessManager::GetContextIdForWorker(
const WorkerId& worker_id) const { … }
std::vector<ProcessManager::ServiceWorkerKeepaliveData>
ProcessManager::GetServiceWorkerKeepaliveDataForRecords(
const ExtensionId& extension_id) const { … }
std::vector<WorkerId> ProcessManager::GetAllWorkersIdsForTesting() { … }
void ProcessManager::ClearBackgroundPageData(const ExtensionId& extension_id) { … }
IncognitoProcessManager::IncognitoProcessManager(
BrowserContext* incognito_context,
BrowserContext* original_context,
ExtensionRegistry* extension_registry)
: … { … }
bool IncognitoProcessManager::CreateBackgroundHost(const Extension* extension,
const GURL& url) { … }
scoped_refptr<content::SiteInstance>
IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { … }
}