mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Delete Alloy bootstrap (fixes #3685)
This commit is contained in:
@@ -1,486 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_context.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "cef/libcef/browser/alloy/alloy_download_manager_delegate.h"
|
||||
#include "cef/libcef/browser/extensions/extension_system.h"
|
||||
#include "cef/libcef/browser/prefs/browser_prefs.h"
|
||||
#include "cef/libcef/browser/ssl_host_state_delegate.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/cef_switches.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "chrome/browser/font_family_cache.h"
|
||||
#include "chrome/browser/permissions/permission_manager_factory.h"
|
||||
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
|
||||
#include "chrome/browser/profiles/profile_key.h"
|
||||
#include "chrome/browser/reduce_accept_language/reduce_accept_language_factory.h"
|
||||
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/guest_view/browser/guest_view_manager.h"
|
||||
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
||||
#include "components/keyed_service/core/simple_dependency_manager.h"
|
||||
#include "components/keyed_service/core/simple_key_map.h"
|
||||
#include "components/permissions/permission_manager.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
||||
#include "components/user_prefs/user_prefs.h"
|
||||
#include "components/visitedlink/browser/visitedlink_event_listener.h"
|
||||
#include "components/visitedlink/browser/visitedlink_writer.h"
|
||||
#include "components/zoom/zoom_event_manager.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "content/public/browser/resource_context.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "extensions/browser/extension_protocols.h"
|
||||
#include "extensions/browser/process_manager.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "net/proxy_resolution/proxy_config_service.h"
|
||||
#include "services/network/public/mojom/cors_origin_pattern.mojom.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
// Creates and manages VisitedLinkEventListener objects for each
|
||||
// AlloyBrowserContext sharing the same VisitedLinkWriter.
|
||||
class CefVisitedLinkListener : public visitedlink::VisitedLinkWriter::Listener {
|
||||
public:
|
||||
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
|
||||
|
||||
CefVisitedLinkListener(const CefVisitedLinkListener&) = delete;
|
||||
CefVisitedLinkListener& operator=(const CefVisitedLinkListener&) = delete;
|
||||
|
||||
void CreateListenerForContext(content::BrowserContext* context) {
|
||||
CEF_REQUIRE_UIT();
|
||||
auto listener =
|
||||
std::make_unique<visitedlink::VisitedLinkEventListener>(context);
|
||||
listener_map_.insert(std::make_pair(context, std::move(listener)));
|
||||
}
|
||||
|
||||
void RemoveListenerForContext(content::BrowserContext* context) {
|
||||
CEF_REQUIRE_UIT();
|
||||
ListenerMap::iterator it = listener_map_.find(context);
|
||||
DCHECK(it != listener_map_.end());
|
||||
listener_map_.erase(it);
|
||||
}
|
||||
|
||||
// visitedlink::VisitedLinkWriter::Listener methods.
|
||||
|
||||
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
|
||||
CEF_REQUIRE_UIT();
|
||||
ListenerMap::iterator it = listener_map_.begin();
|
||||
for (; it != listener_map_.end(); ++it) {
|
||||
it->second->NewTable(table_region);
|
||||
}
|
||||
}
|
||||
|
||||
void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override {
|
||||
CEF_REQUIRE_UIT();
|
||||
ListenerMap::iterator it = listener_map_.begin();
|
||||
for (; it != listener_map_.end(); ++it) {
|
||||
it->second->Add(fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
void Reset(bool invalidate_hashes) override {
|
||||
CEF_REQUIRE_UIT();
|
||||
ListenerMap::iterator it = listener_map_.begin();
|
||||
for (; it != listener_map_.end(); ++it) {
|
||||
it->second->Reset(invalidate_hashes);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Map of AlloyBrowserContext to the associated VisitedLinkEventListener.
|
||||
using ListenerMap =
|
||||
std::map<const content::BrowserContext*,
|
||||
std::unique_ptr<visitedlink::VisitedLinkEventListener>>;
|
||||
ListenerMap listener_map_;
|
||||
};
|
||||
|
||||
AlloyBrowserContext::AlloyBrowserContext(
|
||||
const CefRequestContextSettings& settings)
|
||||
: CefBrowserContext(settings) {}
|
||||
|
||||
AlloyBrowserContext::~AlloyBrowserContext() = default;
|
||||
|
||||
bool AlloyBrowserContext::IsInitialized() const {
|
||||
CEF_REQUIRE_UIT();
|
||||
return !!key_;
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::StoreOrTriggerInitCallback(
|
||||
base::OnceClosure callback) {
|
||||
CEF_REQUIRE_UIT();
|
||||
// Initialization is always synchronous.
|
||||
std::move(callback).Run();
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::Initialize() {
|
||||
CefBrowserContext::Initialize();
|
||||
|
||||
key_ = std::make_unique<ProfileKey>(cache_path_);
|
||||
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
|
||||
|
||||
// Initialize the PrefService object.
|
||||
pref_service_ = browser_prefs::CreatePrefService(
|
||||
this, cache_path_, !!settings_.persist_user_preferences);
|
||||
|
||||
// This must be called before creating any services to avoid hitting
|
||||
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
|
||||
// multiple browser contexts (due to pointer address reuse).
|
||||
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
|
||||
this);
|
||||
|
||||
const bool extensions_enabled = extensions::ExtensionsEnabled();
|
||||
if (extensions_enabled) {
|
||||
// Create the custom ExtensionSystem first because other KeyedServices
|
||||
// depend on it.
|
||||
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
|
||||
extensions::ExtensionSystem::Get(this));
|
||||
extension_system_->InitForRegularProfile(true);
|
||||
|
||||
// Make sure the ProcessManager is created so that it receives extension
|
||||
// load notifications. This is necessary for the proper initialization of
|
||||
// background/event pages.
|
||||
extensions::ProcessManager::Get(this);
|
||||
}
|
||||
|
||||
// Initialize visited links management.
|
||||
base::FilePath visited_link_path;
|
||||
if (!cache_path_.empty()) {
|
||||
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
|
||||
}
|
||||
visitedlink_listener_ = new CefVisitedLinkListener;
|
||||
visitedlink_master_ = std::make_unique<visitedlink::VisitedLinkWriter>(
|
||||
visitedlink_listener_, this, !visited_link_path.empty(), false,
|
||||
visited_link_path, 0);
|
||||
visitedlink_listener_->CreateListenerForContext(this);
|
||||
visitedlink_master_->Init();
|
||||
|
||||
// Initialize proxy configuration tracker.
|
||||
pref_proxy_config_tracker_ = std::make_unique<PrefProxyConfigTrackerImpl>(
|
||||
GetPrefs(), content::GetIOThreadTaskRunner({}));
|
||||
|
||||
// Spell checking support and possibly other subsystems retrieve the
|
||||
// PrefService associated with a BrowserContext via UserPrefs::Get().
|
||||
PrefService* pref_service = GetPrefs();
|
||||
DCHECK(pref_service);
|
||||
user_prefs::UserPrefs::Set(this, pref_service);
|
||||
key_->SetPrefs(pref_service);
|
||||
|
||||
if (extensions_enabled) {
|
||||
extension_system_->Init();
|
||||
}
|
||||
|
||||
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::Shutdown() {
|
||||
CefBrowserContext::Shutdown();
|
||||
|
||||
// Send notifications to clean up objects associated with this Profile.
|
||||
MaybeSendDestroyedNotification();
|
||||
|
||||
ChromePluginServiceFilter::GetInstance()->UnregisterProfile(this);
|
||||
|
||||
// Clear this reference before the associated KeyedServiceFactory is destroyed
|
||||
// by PerformInterlockedTwoPhaseShutdown().
|
||||
extension_system_ = nullptr;
|
||||
|
||||
// Remove any BrowserContextKeyedServiceFactory associations. This must be
|
||||
// called before the ProxyService owned by AlloyBrowserContext is destroyed.
|
||||
// The SimpleDependencyManager should always be passed after the
|
||||
// BrowserContextDependencyManager. This is because the KeyedService instances
|
||||
// in the BrowserContextDependencyManager's dependency graph can depend on the
|
||||
// ones in the SimpleDependencyManager's graph.
|
||||
DependencyManager::PerformInterlockedTwoPhaseShutdown(
|
||||
BrowserContextDependencyManager::GetInstance(), this,
|
||||
SimpleDependencyManager::GetInstance(), key_.get());
|
||||
|
||||
key_.reset();
|
||||
SimpleKeyMap::GetInstance()->Dissociate(this);
|
||||
|
||||
// Shuts down the storage partitions associated with this browser context.
|
||||
// This must be called before the browser context is actually destroyed
|
||||
// and before a clean-up task for its corresponding IO thread residents
|
||||
// (e.g. ResourceContext) is posted, so that the classes that hung on
|
||||
// StoragePartition can have time to do necessary cleanups on IO thread.
|
||||
ShutdownStoragePartitions();
|
||||
|
||||
visitedlink_listener_->RemoveListenerForContext(this);
|
||||
|
||||
// The FontFamilyCache references the ProxyService so delete it before the
|
||||
// ProxyService is deleted.
|
||||
SetUserData(&kFontFamilyCacheKey, nullptr);
|
||||
|
||||
pref_proxy_config_tracker_->DetachFromPrefService();
|
||||
|
||||
// Delete the download manager delegate here because otherwise we'll crash
|
||||
// when it's accessed from the content::BrowserContext destructor.
|
||||
if (download_manager_delegate_) {
|
||||
download_manager_delegate_.reset(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::RemoveCefRequestContext(
|
||||
CefRequestContextImpl* context) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extension_system()->OnRequestContextDeleted(context);
|
||||
}
|
||||
|
||||
// May result in |this| being deleted.
|
||||
CefBrowserContext::RemoveCefRequestContext(context);
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::LoadExtension(
|
||||
const CefString& root_directory,
|
||||
CefRefPtr<CefDictionaryValue> manifest,
|
||||
CefRefPtr<CefExtensionHandler> handler,
|
||||
CefRefPtr<CefRequestContext> loader_context) {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
if (handler) {
|
||||
handler->OnExtensionLoadFailed(ERR_ABORTED);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (manifest && manifest->GetSize() > 0) {
|
||||
CefDictionaryValueImpl* value_impl =
|
||||
static_cast<CefDictionaryValueImpl*>(manifest.get());
|
||||
auto value = value_impl->CopyValue();
|
||||
extension_system()->LoadExtension(std::move(value.GetDict()),
|
||||
root_directory, false /* builtin */,
|
||||
loader_context, handler);
|
||||
} else {
|
||||
extension_system()->LoadExtension(root_directory, false /* builtin */,
|
||||
loader_context, handler);
|
||||
}
|
||||
}
|
||||
|
||||
bool AlloyBrowserContext::GetExtensions(std::vector<CefString>& extension_ids) {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
extensions::CefExtensionSystem::ExtensionMap extension_map =
|
||||
extension_system()->GetExtensions();
|
||||
extensions::CefExtensionSystem::ExtensionMap::const_iterator it =
|
||||
extension_map.begin();
|
||||
for (; it != extension_map.end(); ++it) {
|
||||
extension_ids.push_back(it->second->GetIdentifier());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefExtension> AlloyBrowserContext::GetExtension(
|
||||
const CefString& extension_id) {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return extension_system()->GetExtension(extension_id);
|
||||
}
|
||||
|
||||
bool AlloyBrowserContext::UnloadExtension(const CefString& extension_id) {
|
||||
DCHECK(extensions::ExtensionsEnabled());
|
||||
return extension_system()->UnloadExtension(extension_id);
|
||||
}
|
||||
|
||||
content::ClientHintsControllerDelegate*
|
||||
AlloyBrowserContext::GetClientHintsControllerDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ChromeZoomLevelPrefs* AlloyBrowserContext::GetZoomLevelPrefs() {
|
||||
return static_cast<ChromeZoomLevelPrefs*>(
|
||||
GetStoragePartition(nullptr)->GetZoomLevelDelegate());
|
||||
}
|
||||
|
||||
scoped_refptr<network::SharedURLLoaderFactory>
|
||||
AlloyBrowserContext::GetURLLoaderFactory() {
|
||||
return GetDefaultStoragePartition()->GetURLLoaderFactoryForBrowserProcess();
|
||||
}
|
||||
|
||||
base::FilePath AlloyBrowserContext::GetPath() {
|
||||
return cache_path_;
|
||||
}
|
||||
|
||||
base::FilePath AlloyBrowserContext::GetPath() const {
|
||||
return cache_path_;
|
||||
}
|
||||
|
||||
std::unique_ptr<content::ZoomLevelDelegate>
|
||||
AlloyBrowserContext::CreateZoomLevelDelegate(
|
||||
const base::FilePath& partition_path) {
|
||||
if (cache_path_.empty()) {
|
||||
return std::unique_ptr<content::ZoomLevelDelegate>();
|
||||
}
|
||||
|
||||
return base::WrapUnique(new ChromeZoomLevelPrefs(
|
||||
GetPrefs(), cache_path_, partition_path,
|
||||
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
|
||||
}
|
||||
|
||||
content::DownloadManagerDelegate*
|
||||
AlloyBrowserContext::GetDownloadManagerDelegate() {
|
||||
if (!download_manager_delegate_) {
|
||||
download_manager_delegate_ =
|
||||
std::make_unique<AlloyDownloadManagerDelegate>(GetDownloadManager());
|
||||
}
|
||||
return download_manager_delegate_.get();
|
||||
}
|
||||
|
||||
content::BrowserPluginGuestManager* AlloyBrowserContext::GetGuestManager() {
|
||||
if (!extensions::ExtensionsEnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
return guest_view::GuestViewManager::FromBrowserContext(this);
|
||||
}
|
||||
|
||||
storage::SpecialStoragePolicy* AlloyBrowserContext::GetSpecialStoragePolicy() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::PlatformNotificationService*
|
||||
AlloyBrowserContext::GetPlatformNotificationService() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::PushMessagingService* AlloyBrowserContext::GetPushMessagingService() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::StorageNotificationService*
|
||||
AlloyBrowserContext::GetStorageNotificationService() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::SSLHostStateDelegate* AlloyBrowserContext::GetSSLHostStateDelegate() {
|
||||
if (!ssl_host_state_delegate_) {
|
||||
ssl_host_state_delegate_ = std::make_unique<CefSSLHostStateDelegate>();
|
||||
}
|
||||
return ssl_host_state_delegate_.get();
|
||||
}
|
||||
|
||||
content::PermissionControllerDelegate*
|
||||
AlloyBrowserContext::GetPermissionControllerDelegate() {
|
||||
return PermissionManagerFactory::GetForProfile(this);
|
||||
}
|
||||
|
||||
content::BackgroundFetchDelegate*
|
||||
AlloyBrowserContext::GetBackgroundFetchDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::BackgroundSyncController*
|
||||
AlloyBrowserContext::GetBackgroundSyncController() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::BrowsingDataRemoverDelegate*
|
||||
AlloyBrowserContext::GetBrowsingDataRemoverDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::ReduceAcceptLanguageControllerDelegate*
|
||||
AlloyBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
|
||||
return ReduceAcceptLanguageFactory::GetForProfile(this);
|
||||
}
|
||||
|
||||
PrefService* AlloyBrowserContext::GetPrefs() {
|
||||
return pref_service_.get();
|
||||
}
|
||||
|
||||
const PrefService* AlloyBrowserContext::GetPrefs() const {
|
||||
return pref_service_.get();
|
||||
}
|
||||
|
||||
ProfileKey* AlloyBrowserContext::GetProfileKey() const {
|
||||
DCHECK(key_);
|
||||
return key_.get();
|
||||
}
|
||||
|
||||
policy::SchemaRegistryService*
|
||||
AlloyBrowserContext::GetPolicySchemaRegistryService() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
policy::UserCloudPolicyManager*
|
||||
AlloyBrowserContext::GetUserCloudPolicyManager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
policy::ProfileCloudPolicyManager*
|
||||
AlloyBrowserContext::GetProfileCloudPolicyManager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
policy::CloudPolicyManager* AlloyBrowserContext::GetCloudPolicyManager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
policy::ProfilePolicyConnector*
|
||||
AlloyBrowserContext::GetProfilePolicyConnector() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const policy::ProfilePolicyConnector*
|
||||
AlloyBrowserContext::GetProfilePolicyConnector() const {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AlloyBrowserContext::IsNewProfile() const {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::RebuildTable(
|
||||
const scoped_refptr<URLEnumerator>& enumerator) {
|
||||
// Called when visited links will not or cannot be loaded from disk.
|
||||
enumerator->OnComplete(true);
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::BuildVisitedLinkTable(
|
||||
const scoped_refptr<VisitedLinkEnumerator>& enumerator) {
|
||||
// Called when visited links will not or cannot be loaded from disk.
|
||||
enumerator->OnVisitedLinkComplete(true);
|
||||
}
|
||||
|
||||
DownloadPrefs* AlloyBrowserContext::GetDownloadPrefs() {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (!download_prefs_) {
|
||||
download_prefs_ = std::make_unique<DownloadPrefs>(this);
|
||||
}
|
||||
return download_prefs_.get();
|
||||
}
|
||||
|
||||
void AlloyBrowserContext::AddVisitedURLs(
|
||||
const GURL& url,
|
||||
const std::vector<GURL>& redirect_chain,
|
||||
ui::PageTransition /*transition*/) {
|
||||
if (!redirect_chain.empty()) {
|
||||
visitedlink_master_->AddURLs(redirect_chain);
|
||||
} else {
|
||||
visitedlink_master_->AddURL(url);
|
||||
}
|
||||
}
|
@@ -1,148 +0,0 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_
|
||||
#pragma once
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "cef/include/cef_request_context_handler.h"
|
||||
#include "cef/libcef/browser/alloy/chrome_profile_alloy.h"
|
||||
#include "cef/libcef/browser/browser_context.h"
|
||||
#include "cef/libcef/browser/request_context_handler_map.h"
|
||||
#include "chrome/browser/download/download_prefs.h"
|
||||
#include "components/proxy_config/pref_proxy_config_tracker.h"
|
||||
#include "components/visitedlink/browser/visitedlink_delegate.h"
|
||||
|
||||
class AlloyDownloadManagerDelegate;
|
||||
class CefSSLHostStateDelegate;
|
||||
class CefVisitedLinkListener;
|
||||
class PrefService;
|
||||
|
||||
namespace extensions {
|
||||
class CefExtensionSystem;
|
||||
}
|
||||
|
||||
namespace visitedlink {
|
||||
class VisitedLinkWriter;
|
||||
}
|
||||
|
||||
// See CefBrowserContext documentation for usage. Only accessed on the UI thread
|
||||
// unless otherwise indicated. ChromeProfileAlloy must be the first listed base
|
||||
// class to avoid issues when casting between void* and content::BrowserContext*
|
||||
// in Chromium code.
|
||||
class AlloyBrowserContext : public ChromeProfileAlloy,
|
||||
public CefBrowserContext,
|
||||
public visitedlink::VisitedLinkDelegate {
|
||||
public:
|
||||
explicit AlloyBrowserContext(const CefRequestContextSettings& settings);
|
||||
|
||||
AlloyBrowserContext(const AlloyBrowserContext&) = delete;
|
||||
AlloyBrowserContext& operator=(const AlloyBrowserContext&) = delete;
|
||||
|
||||
// CefBrowserContext overrides.
|
||||
content::BrowserContext* AsBrowserContext() override { return this; }
|
||||
Profile* AsProfile() override { return this; }
|
||||
bool IsInitialized() const override;
|
||||
void StoreOrTriggerInitCallback(base::OnceClosure callback) override;
|
||||
void Initialize() override;
|
||||
void Shutdown() override;
|
||||
void RemoveCefRequestContext(CefRequestContextImpl* context) override;
|
||||
void LoadExtension(const CefString& root_directory,
|
||||
CefRefPtr<CefDictionaryValue> manifest,
|
||||
CefRefPtr<CefExtensionHandler> handler,
|
||||
CefRefPtr<CefRequestContext> loader_context) override;
|
||||
bool GetExtensions(std::vector<CefString>& extension_ids) override;
|
||||
CefRefPtr<CefExtension> GetExtension(const CefString& extension_id) override;
|
||||
bool UnloadExtension(const CefString& extension_id) override;
|
||||
void AddVisitedURLs(const GURL& url,
|
||||
const std::vector<GURL>& redirect_chain,
|
||||
ui::PageTransition transition) override;
|
||||
|
||||
// content::BrowserContext overrides.
|
||||
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
|
||||
override;
|
||||
base::FilePath GetPath() override;
|
||||
base::FilePath GetPath() const override;
|
||||
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
||||
const base::FilePath& partition_path) override;
|
||||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
||||
content::BrowserPluginGuestManager* GetGuestManager() override;
|
||||
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
|
||||
content::PlatformNotificationService* GetPlatformNotificationService()
|
||||
override;
|
||||
content::PushMessagingService* GetPushMessagingService() override;
|
||||
content::StorageNotificationService* GetStorageNotificationService() override;
|
||||
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
|
||||
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
|
||||
override;
|
||||
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
|
||||
content::BackgroundSyncController* GetBackgroundSyncController() override;
|
||||
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
|
||||
override;
|
||||
content::ReduceAcceptLanguageControllerDelegate*
|
||||
GetReduceAcceptLanguageControllerDelegate() override;
|
||||
|
||||
// Profile overrides.
|
||||
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
|
||||
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
|
||||
PrefService* GetPrefs() override;
|
||||
bool AllowsBrowserWindows() const override { return false; }
|
||||
const PrefService* GetPrefs() const override;
|
||||
ProfileKey* GetProfileKey() const override;
|
||||
policy::SchemaRegistryService* GetPolicySchemaRegistryService() override;
|
||||
policy::UserCloudPolicyManager* GetUserCloudPolicyManager() override;
|
||||
policy::ProfileCloudPolicyManager* GetProfileCloudPolicyManager() override;
|
||||
policy::CloudPolicyManager* GetCloudPolicyManager() override;
|
||||
policy::ProfilePolicyConnector* GetProfilePolicyConnector() override;
|
||||
const policy::ProfilePolicyConnector* GetProfilePolicyConnector()
|
||||
const override;
|
||||
bool IsNewProfile() const override;
|
||||
|
||||
// Values checked in ProfileNetworkContextService::CreateNetworkContextParams
|
||||
// when creating the NetworkContext.
|
||||
bool ShouldRestoreOldSessionCookies() override {
|
||||
return ShouldPersistSessionCookies();
|
||||
}
|
||||
bool ShouldPersistSessionCookies() const override {
|
||||
return !!settings_.persist_session_cookies;
|
||||
}
|
||||
|
||||
// visitedlink::VisitedLinkDelegate methods.
|
||||
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
|
||||
void BuildVisitedLinkTable(
|
||||
const scoped_refptr<VisitedLinkEnumerator>& enumerator) override;
|
||||
|
||||
// Manages extensions.
|
||||
extensions::CefExtensionSystem* extension_system() const {
|
||||
return extension_system_;
|
||||
}
|
||||
|
||||
// Called from DownloadPrefs::FromBrowserContext via
|
||||
// alloy::GetDownloadPrefsFromBrowserContext.
|
||||
DownloadPrefs* GetDownloadPrefs();
|
||||
|
||||
private:
|
||||
~AlloyBrowserContext() override;
|
||||
|
||||
std::unique_ptr<PrefService> pref_service_;
|
||||
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
|
||||
|
||||
std::unique_ptr<AlloyDownloadManagerDelegate> download_manager_delegate_;
|
||||
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
|
||||
std::unique_ptr<visitedlink::VisitedLinkWriter> visitedlink_master_;
|
||||
// |visitedlink_listener_| is owned by visitedlink_master_.
|
||||
raw_ptr<CefVisitedLinkListener> visitedlink_listener_ = nullptr;
|
||||
|
||||
// Owned by the KeyedService system.
|
||||
raw_ptr<extensions::CefExtensionSystem> extension_system_ = nullptr;
|
||||
|
||||
// The key to index KeyedService instances created by
|
||||
// SimpleKeyedServiceFactory.
|
||||
std::unique_ptr<ProfileKey> key_;
|
||||
|
||||
std::unique_ptr<DownloadPrefs> download_prefs_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_
|
@@ -31,7 +31,6 @@
|
||||
#include "cef/libcef/common/net/url_util.h"
|
||||
#include "cef/libcef/common/request_impl.h"
|
||||
#include "cef/libcef/common/values_impl.h"
|
||||
#include "cef/libcef/features/runtime.h"
|
||||
#include "chrome/browser/file_select_helper.h"
|
||||
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
|
||||
#include "components/input/native_web_keyboard_event.h"
|
||||
@@ -52,10 +51,6 @@
|
||||
#include "net/base/net_errors.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
#include "extensions/common/extension.h"
|
||||
#endif
|
||||
|
||||
using content::KeyboardEventProcessingResult;
|
||||
|
||||
namespace {
|
||||
@@ -77,15 +72,9 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
|
||||
// Expect runtime style to match.
|
||||
CHECK(platform_delegate->IsAlloyStyle());
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
const bool is_devtools_popup = !!create_params.devtools_opener;
|
||||
#else
|
||||
const bool is_devtools_popup = false;
|
||||
#endif
|
||||
|
||||
scoped_refptr<CefBrowserInfo> info =
|
||||
CefBrowserInfoManager::GetInstance()->CreateBrowserInfo(
|
||||
is_devtools_popup, platform_delegate->IsWindowless(),
|
||||
/*is_devtools_popup=*/false, platform_delegate->IsWindowless(),
|
||||
platform_delegate->IsPrintPreviewSupported(),
|
||||
create_params.extra_info);
|
||||
|
||||
@@ -98,47 +87,18 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::Create(
|
||||
auto request_context_impl =
|
||||
static_cast<CefRequestContextImpl*>(create_params.request_context.get());
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
CefRefPtr<CefExtension> cef_extension;
|
||||
if (create_params.extension) {
|
||||
auto cef_browser_context = request_context_impl->GetBrowserContext();
|
||||
cef_extension =
|
||||
cef_browser_context->GetExtension(create_params.extension->id());
|
||||
CHECK(cef_extension);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
auto platform_delegate_ptr = platform_delegate.get();
|
||||
#endif
|
||||
|
||||
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
|
||||
create_params.settings, create_params.client, web_contents,
|
||||
own_web_contents, info,
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
FromBaseChecked(create_params.devtools_opener),
|
||||
#else
|
||||
/*opener=*/nullptr,
|
||||
#endif
|
||||
is_devtools_popup, request_context_impl, std::move(platform_delegate)
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
cef_extension
|
||||
#endif
|
||||
);
|
||||
CefRefPtr<AlloyBrowserHostImpl> browser =
|
||||
CreateInternal(create_params.settings, create_params.client, web_contents,
|
||||
own_web_contents, info,
|
||||
/*opener=*/nullptr, /*is_devtools_popup=*/false,
|
||||
request_context_impl, std::move(platform_delegate));
|
||||
if (!browser) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GURL url = url_util::MakeGURL(create_params.url, /*fixup=*/true);
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (create_params.extension) {
|
||||
platform_delegate_ptr->CreateExtensionHost(
|
||||
create_params.extension, url, create_params.extension_host_type);
|
||||
} else
|
||||
#endif
|
||||
if (!url.is_empty()) {
|
||||
if (!url.is_empty()) {
|
||||
content::OpenURLParams params(url, content::Referrer(),
|
||||
WindowOpenDisposition::CURRENT_TAB,
|
||||
CefFrameHostImpl::kPageTransitionExplicit,
|
||||
@@ -159,12 +119,7 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
||||
CefRefPtr<AlloyBrowserHostImpl> opener,
|
||||
bool is_devtools_popup,
|
||||
CefRefPtr<CefRequestContextImpl> request_context,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
CefRefPtr<CefExtension> extension
|
||||
#endif
|
||||
) {
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(web_contents);
|
||||
DCHECK(browser_info);
|
||||
@@ -195,12 +150,7 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
||||
|
||||
CefRefPtr<AlloyBrowserHostImpl> browser = new AlloyBrowserHostImpl(
|
||||
settings, client, web_contents, browser_info, opener, request_context,
|
||||
std::move(platform_delegate)
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
extension
|
||||
#endif
|
||||
);
|
||||
std::move(platform_delegate));
|
||||
browser->InitializeBrowser();
|
||||
|
||||
if (!browser->CreateHostWindow()) {
|
||||
@@ -213,7 +163,7 @@ CefRefPtr<AlloyBrowserHostImpl> AlloyBrowserHostImpl::CreateInternal(
|
||||
if (opener && opener->platform_delegate_) {
|
||||
// 1. Notify the opener browser's platform delegate. With Views this will
|
||||
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
|
||||
// Do this first for consistency with the Chrome runtime.
|
||||
// Do this first for consistency with Chrome style.
|
||||
opener->platform_delegate_->PopupBrowserCreated(
|
||||
browser->platform_delegate(), browser.get(), is_devtools_popup);
|
||||
}
|
||||
@@ -383,16 +333,6 @@ void AlloyBrowserHostImpl::SetAutoResizeEnabled(bool enabled,
|
||||
}
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
CefRefPtr<CefExtension> AlloyBrowserHostImpl::GetExtension() {
|
||||
return extension_;
|
||||
}
|
||||
|
||||
bool AlloyBrowserHostImpl::IsBackgroundHost() {
|
||||
return is_background_host_;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool AlloyBrowserHostImpl::CanExecuteChromeCommand(int command_id) {
|
||||
return false;
|
||||
}
|
||||
@@ -640,14 +580,6 @@ bool AlloyBrowserHostImpl::MaybeAllowNavigation(
|
||||
return true;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
extensions::ExtensionHost* AlloyBrowserHostImpl::GetExtensionHost() const {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(platform_delegate_);
|
||||
return platform_delegate_->GetExtensionHost();
|
||||
}
|
||||
#endif
|
||||
|
||||
void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
|
||||
if (!CEF_CURRENTLY_ON_UIT()) {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::OnSetFocus,
|
||||
@@ -958,14 +890,6 @@ content::WebContents* AlloyBrowserHostImpl::OpenURLFromTab(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool AlloyBrowserHostImpl::ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
bool is_main_frame_navigation) {
|
||||
return platform_delegate_->ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
is_main_frame_navigation);
|
||||
}
|
||||
#endif
|
||||
|
||||
void AlloyBrowserHostImpl::AddNewContents(
|
||||
content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
@@ -1106,14 +1030,6 @@ bool AlloyBrowserHostImpl::HandleKeyboardEvent(
|
||||
return false;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool AlloyBrowserHostImpl::PreHandleGestureEvent(
|
||||
content::WebContents* source,
|
||||
const blink::WebGestureEvent& event) {
|
||||
return platform_delegate_->PreHandleGestureEvent(source, event);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool AlloyBrowserHostImpl::CanDragEnter(content::WebContents* source,
|
||||
const content::DropData& data,
|
||||
blink::DragOperationsMask mask) {
|
||||
@@ -1186,12 +1102,8 @@ void AlloyBrowserHostImpl::WebContentsCreated(
|
||||
// However, we need to install observers/delegates here.
|
||||
CefRefPtr<AlloyBrowserHostImpl> browser = CreateInternal(
|
||||
settings, client, new_contents, /*own_web_contents=*/false, info, opener,
|
||||
/*is_devtools_popup=*/false, request_context, std::move(platform_delegate)
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
/*extension=*/nullptr
|
||||
#endif
|
||||
);
|
||||
/*is_devtools_popup=*/false, request_context,
|
||||
std::move(platform_delegate));
|
||||
}
|
||||
|
||||
void AlloyBrowserHostImpl::RendererUnresponsive(
|
||||
@@ -1275,13 +1187,6 @@ bool AlloyBrowserHostImpl::CheckMediaAccessPermission(
|
||||
security_origin, type);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool AlloyBrowserHostImpl::IsNeverComposited(
|
||||
content::WebContents* web_contents) {
|
||||
return platform_delegate_->IsNeverComposited(web_contents);
|
||||
}
|
||||
#endif
|
||||
|
||||
content::PictureInPictureResult AlloyBrowserHostImpl::EnterPictureInPicture(
|
||||
content::WebContents* web_contents) {
|
||||
if (!IsPictureInPictureSupported()) {
|
||||
@@ -1299,12 +1204,7 @@ void AlloyBrowserHostImpl::ExitPictureInPicture() {
|
||||
|
||||
bool AlloyBrowserHostImpl::IsBackForwardCacheSupported(
|
||||
content::WebContents& web_contents) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
return true;
|
||||
#else
|
||||
// Disabled with Alloy bootstrap due to issue #3237.
|
||||
return cef::IsChromeRuntimeEnabled();
|
||||
#endif
|
||||
}
|
||||
|
||||
content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported(
|
||||
@@ -1438,12 +1338,7 @@ AlloyBrowserHostImpl::AlloyBrowserHostImpl(
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
CefRefPtr<AlloyBrowserHostImpl> opener,
|
||||
CefRefPtr<CefRequestContextImpl> request_context,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
CefRefPtr<CefExtension> extension
|
||||
#endif
|
||||
)
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate)
|
||||
: CefBrowserHostBase(settings,
|
||||
client,
|
||||
std::move(platform_delegate),
|
||||
@@ -1451,12 +1346,7 @@ AlloyBrowserHostImpl::AlloyBrowserHostImpl(
|
||||
request_context),
|
||||
content::WebContentsObserver(web_contents),
|
||||
opener_(kNullWindowHandle),
|
||||
is_windowless_(platform_delegate_->IsWindowless())
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
extension_(extension)
|
||||
#endif
|
||||
{
|
||||
is_windowless_(platform_delegate_->IsWindowless()) {
|
||||
contents_delegate_->ObserveWebContents(web_contents);
|
||||
|
||||
if (opener.get() && !is_views_hosted_) {
|
||||
|
@@ -24,16 +24,12 @@
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
#include "extensions/common/mojom/view_type.mojom-forward.h"
|
||||
#endif
|
||||
|
||||
class CefAudioCapturer;
|
||||
class CefBrowserInfo;
|
||||
class SiteInstance;
|
||||
|
||||
// CefBrowser implementation for the alloy runtime. Method calls are delegated
|
||||
// to the CefPlatformDelegate or the WebContents as appropriate. All methods are
|
||||
// CefBrowser implementation for Alloy style. Method calls are delegated to the
|
||||
// CefPlatformDelegate or the WebContents as appropriate. All methods are
|
||||
// thread-safe unless otherwise indicated.
|
||||
//
|
||||
// WebContentsDelegate: Interface for handling WebContents delegations. There is
|
||||
@@ -124,10 +120,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
void SetAutoResizeEnabled(bool enabled,
|
||||
const CefSize& min_size,
|
||||
const CefSize& max_size) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
CefRefPtr<CefExtension> GetExtension() override;
|
||||
bool IsBackgroundHost() override;
|
||||
#endif
|
||||
bool CanExecuteChromeCommand(int command_id) override;
|
||||
void ExecuteChromeCommand(int command_id,
|
||||
cef_window_open_disposition_t disposition) override;
|
||||
@@ -169,11 +161,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
void UpdateDragOperation(ui::mojom::DragOperation operation,
|
||||
bool document_is_handling_drag);
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Accessors that must be called on the UI thread.
|
||||
extensions::ExtensionHost* GetExtensionHost() const;
|
||||
#endif
|
||||
|
||||
void OnSetFocus(cef_focus_source_t source) override;
|
||||
|
||||
bool ShowContextMenu(const content::ContextMenuParams& params);
|
||||
@@ -192,10 +179,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
const content::OpenURLParams& params,
|
||||
base::OnceCallback<void(content::NavigationHandle&)>
|
||||
navigation_handle_callback) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
bool is_main_frame_navigation) override;
|
||||
#endif
|
||||
void AddNewContents(content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
const GURL& target_url,
|
||||
@@ -225,10 +208,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
const input::NativeWebKeyboardEvent& event) override;
|
||||
bool HandleKeyboardEvent(content::WebContents* source,
|
||||
const input::NativeWebKeyboardEvent& event) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool PreHandleGestureEvent(content::WebContents* source,
|
||||
const blink::WebGestureEvent& event) override;
|
||||
#endif
|
||||
bool CanDragEnter(content::WebContents* source,
|
||||
const content::DropData& data,
|
||||
blink::DragOperationsMask operations_allowed) override;
|
||||
@@ -282,9 +261,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
|
||||
const url::Origin& security_origin,
|
||||
blink::mojom::MediaStreamType type) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool IsNeverComposited(content::WebContents* web_contents) override;
|
||||
#endif
|
||||
content::PictureInPictureResult EnterPictureInPicture(
|
||||
content::WebContents* web_contents) override;
|
||||
void ExitPictureInPicture() override;
|
||||
@@ -318,12 +294,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
CefRefPtr<AlloyBrowserHostImpl> opener,
|
||||
bool is_devtools_popup,
|
||||
CefRefPtr<CefRequestContextImpl> request_context,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
CefRefPtr<CefExtension> extension
|
||||
#endif
|
||||
);
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate);
|
||||
|
||||
AlloyBrowserHostImpl(
|
||||
const CefBrowserSettings& settings,
|
||||
@@ -332,12 +303,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
CefRefPtr<AlloyBrowserHostImpl> opener,
|
||||
CefRefPtr<CefRequestContextImpl> request_context,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
,
|
||||
CefRefPtr<CefExtension> extension
|
||||
#endif
|
||||
);
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate);
|
||||
|
||||
// Give the platform delegate an opportunity to create the host window.
|
||||
bool CreateHostWindow();
|
||||
@@ -348,10 +314,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
|
||||
CefWindowHandle opener_;
|
||||
const bool is_windowless_;
|
||||
CefWindowHandle host_window_handle_ = kNullWindowHandle;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
CefRefPtr<CefExtension> extension_;
|
||||
bool is_background_host_ = false;
|
||||
#endif
|
||||
|
||||
// Represents the current browser destruction state. Only accessed on the UI
|
||||
// thread.
|
||||
|
@@ -1,426 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_main.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_manager_delegate.h"
|
||||
#include "cef/libcef/browser/alloy/dialogs/alloy_constrained_window_views_client.h"
|
||||
#include "cef/libcef/browser/browser_context.h"
|
||||
#include "cef/libcef/browser/browser_context_keyed_service_factories.h"
|
||||
#include "cef/libcef/browser/context.h"
|
||||
#include "cef/libcef/browser/extensions/extension_system_factory.h"
|
||||
#include "cef/libcef/browser/file_dialog_runner.h"
|
||||
#include "cef/libcef/browser/net/chrome_scheme_handler.h"
|
||||
#include "cef/libcef/browser/permission_prompt.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
#include "cef/libcef/common/command_line_impl.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "cef/libcef/common/net/net_resource_provider.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/chrome_process_singleton.h"
|
||||
#include "chrome/browser/media/router/chrome_media_router_factory.h"
|
||||
#include "chrome/browser/net/system_network_context_manager.h"
|
||||
#include "chrome/browser/ui/color/chrome_color_mixers.h"
|
||||
#include "chrome/browser/ui/javascript_dialogs/chrome_javascript_app_modal_dialog_view_factory.h"
|
||||
#include "chrome/browser/ui/ui_features.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "components/color/color_mixers.h"
|
||||
#include "components/constrained_window/constrained_window_views.h"
|
||||
#include "content/public/browser/gpu_data_manager.h"
|
||||
#include "content/public/browser/network_service_instance.h"
|
||||
#include "content/public/common/result_codes.h"
|
||||
#include "extensions/browser/extensions_browser_client.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "third_party/widevine/cdm/buildflags.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/color/color_provider_manager.h"
|
||||
#include "ui/native_theme/native_theme.h"
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#include "components/password_manager/core/browser/password_manager_switches.h"
|
||||
#include "ui/base/ozone_buildflags.h"
|
||||
#if defined(USE_AURA) && BUILDFLAG(IS_OZONE_X11)
|
||||
#include "ui/events/devices/x11/touch_factory_x11.h"
|
||||
#endif
|
||||
#if defined(USE_DBUS)
|
||||
#include "chrome/browser/ui/views/dark_mode_manager_linux.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_AURA)
|
||||
#include "ui/aura/env.h"
|
||||
#include "ui/views/widget/desktop_aura/desktop_screen.h"
|
||||
#include "ui/wm/core/wm_state.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include "base/enterprise_util.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "chrome/browser/chrome_browser_main_win.h"
|
||||
#include "chrome/browser/win/parental_controls.h"
|
||||
#endif
|
||||
#endif // defined(USE_AURA)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "chrome/browser/ui/views/chrome_layout_provider.h"
|
||||
#include "chrome/browser/ui/views/chrome_views_delegate.h"
|
||||
#else
|
||||
#include "ui/views/test/desktop_test_views_delegate.h"
|
||||
#endif
|
||||
|
||||
#if defined(USE_AURA) && BUILDFLAG(IS_LINUX)
|
||||
#include "ui/base/ime/init/input_method_initializer.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
#include "components/os_crypt/sync/os_crypt.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#include "base/path_service.h"
|
||||
#include "cef/libcef/browser/printing/print_dialog_linux.h"
|
||||
#include "chrome/browser/themes/theme_service_aura_linux.h"
|
||||
#include "chrome/browser/ui/views/theme_profile_key.h"
|
||||
#include "chrome/grit/branded_strings.h"
|
||||
#include "components/os_crypt/sync/key_storage_config_linux.h"
|
||||
#include "ui/base/cursor/cursor_factory.h"
|
||||
#include "ui/base/ime/input_method.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/linux/linux_ui.h"
|
||||
#include "ui/linux/linux_ui_delegate.h"
|
||||
#include "ui/linux/linux_ui_factory.h"
|
||||
#include "ui/linux/linux_ui_getter.h"
|
||||
#include "ui/ozone/public/ozone_platform.h"
|
||||
#endif // BUILDFLAG(IS_LINUX)
|
||||
|
||||
#if BUILDFLAG(ENABLE_MEDIA_FOUNDATION_WIDEVINE_CDM)
|
||||
#include "chrome/browser/component_updater/media_foundation_widevine_cdm_component_installer.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
|
||||
#include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
|
||||
class LinuxUiGetterImpl : public ui::LinuxUiGetter {
|
||||
public:
|
||||
LinuxUiGetterImpl() = default;
|
||||
~LinuxUiGetterImpl() override = default;
|
||||
ui::LinuxUiTheme* GetForWindow(aura::Window* window) override {
|
||||
return window ? GetForProfile(GetThemeProfileForWindow(window)) : nullptr;
|
||||
}
|
||||
ui::LinuxUiTheme* GetForProfile(Profile* profile) override {
|
||||
return ui::GetLinuxUiTheme(
|
||||
ThemeServiceAuraLinux::GetSystemThemeForProfile(profile));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BUILDFLAG(IS_LINUX)
|
||||
|
||||
void ProcessSingletonNotificationCallbackImpl(
|
||||
base::CommandLine command_line,
|
||||
const base::FilePath& current_directory) {
|
||||
// Drop the request if the browser process is already shutting down.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if (auto app = CefAppManager::Get()->GetApplication()) {
|
||||
if (auto handler = app->GetBrowserProcessHandler()) {
|
||||
CefRefPtr<CefCommandLineImpl> commandLinePtr(
|
||||
new CefCommandLineImpl(command_line));
|
||||
handled = handler->OnAlreadyRunningAppRelaunch(commandLinePtr.get(),
|
||||
current_directory.value());
|
||||
std::ignore = commandLinePtr->Detach(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
LOG(WARNING) << "Unhandled app relaunch; implement "
|
||||
"CefBrowserProcessHandler::OnAlreadyRunningAppRelaunch.";
|
||||
}
|
||||
}
|
||||
|
||||
// Based on ChromeBrowserMainParts::ProcessSingletonNotificationCallback.
|
||||
bool ProcessSingletonNotificationCallback(
|
||||
base::CommandLine command_line,
|
||||
const base::FilePath& current_directory) {
|
||||
// Drop the request if the browser process is already shutting down.
|
||||
// Note that we're going to post an async task below. Even if the browser
|
||||
// process isn't shutting down right now, it could be by the time the task
|
||||
// starts running. So, an additional check needs to happen when it starts.
|
||||
// But regardless of any future check, there is no reason to post the task
|
||||
// now if we know we're already shutting down.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// In order to handle this request on Windows, there is platform specific
|
||||
// code in browser_finder.cc that requires making outbound COM calls to
|
||||
// cross-apartment shell objects (via IVirtualDesktopManager). That is not
|
||||
// allowed within a SendMessage handler, which this function is a part of.
|
||||
// So, we post a task to asynchronously finish the command line processing.
|
||||
return base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ProcessSingletonNotificationCallbackImpl,
|
||||
std::move(command_line), current_directory));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AlloyBrowserMainParts::AlloyBrowserMainParts() = default;
|
||||
|
||||
AlloyBrowserMainParts::~AlloyBrowserMainParts() {
|
||||
constrained_window::SetConstrainedWindowViewsClient(nullptr);
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::ToolkitInitialized() {
|
||||
SetConstrainedWindowViewsClient(
|
||||
CreateAlloyConstrainedWindowViewsClient(nullptr));
|
||||
#if defined(USE_AURA)
|
||||
CHECK(aura::Env::GetInstance());
|
||||
|
||||
wm_state_ = std::make_unique<wm::WMState>();
|
||||
#endif // defined(USE_AURA)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
views_delegate_ = std::make_unique<ChromeViewsDelegate>();
|
||||
layout_provider_ = ChromeLayoutProvider::CreateLayoutProvider();
|
||||
#else
|
||||
views_delegate_ = std::make_unique<views::DesktopTestViewsDelegate>();
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
// Based on chrome_browser_main_extra_parts_views_linux.cc
|
||||
// |linux_ui| will be nullptr with multi-threaded-message-loop. See
|
||||
// CefUiThread::InitializeBrowserRunner.
|
||||
if (auto linux_ui = ui::GetDefaultLinuxUi()) {
|
||||
linux_ui_getter_ = std::make_unique<LinuxUiGetterImpl>();
|
||||
ui::LinuxUi::SetInstance(linux_ui);
|
||||
|
||||
// Cursor theme changes are tracked by LinuxUI (via a CursorThemeManager
|
||||
// implementation). Start observing them once it's initialized.
|
||||
ui::CursorFactory::GetInstance()->ObserveThemeChanges();
|
||||
}
|
||||
|
||||
#if defined(USE_DBUS)
|
||||
if (!ui::NativeTheme::IsForcedDarkMode() &&
|
||||
!ui::NativeTheme::IsForcedLightMode()) {
|
||||
dark_mode_manager_ = std::make_unique<ui::DarkModeManagerLinux>();
|
||||
}
|
||||
#endif
|
||||
|
||||
auto printing_delegate = new CefPrintingContextLinuxDelegate();
|
||||
auto default_delegate =
|
||||
ui::PrintingContextLinuxDelegate::SetInstance(printing_delegate);
|
||||
printing_delegate->SetDefaultDelegate(default_delegate);
|
||||
#endif // BUILDFLAG(IS_LINUX)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
if (base::FeatureList::IsEnabled(features::kViewsJSAppModalDialog)) {
|
||||
InstallChromeJavaScriptAppModalDialogViewFactory();
|
||||
} else {
|
||||
InstallChromeJavaScriptAppModalDialogViewCocoaFactory();
|
||||
}
|
||||
#else
|
||||
InstallChromeJavaScriptAppModalDialogViewFactory();
|
||||
#endif
|
||||
|
||||
// On GTK that builds the native theme that, in turn, adds the GTK core color
|
||||
// mixer; core mixers should all be added before we add chrome mixers.
|
||||
ui::ColorProviderManager::Get().AppendColorProviderInitializer(
|
||||
base::BindRepeating(color::AddComponentsColorMixers));
|
||||
ui::ColorProviderManager::Get().AppendColorProviderInitializer(
|
||||
base::BindRepeating(AddChromeColorMixers));
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::PreCreateMainMessageLoop() {
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
#if defined(USE_AURA) && BUILDFLAG(IS_OZONE_X11)
|
||||
ui::TouchFactory::SetTouchDeviceListFromCommandLine();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// Initialize the OSCrypt.
|
||||
PrefService* local_state = g_browser_process->local_state();
|
||||
DCHECK(local_state);
|
||||
bool os_crypt_init = OSCrypt::Init(local_state);
|
||||
DCHECK(os_crypt_init);
|
||||
|
||||
// installer_util references strings that are normally compiled into
|
||||
// setup.exe. In Chrome, these strings are in the locale files.
|
||||
ChromeBrowserMainPartsWin::SetupInstallerUtilStrings();
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
media_router::ChromeMediaRouterFactory::DoPlatformInit();
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::PostCreateMainMessageLoop() {
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
||||
// Set up crypt config. This needs to be done before anything starts the
|
||||
// network service, as the raw encryption key needs to be shared with the
|
||||
// network service for encrypted cookie storage.
|
||||
// Based on ChromeBrowserMainPartsLinux::PostCreateMainMessageLoop.
|
||||
std::unique_ptr<os_crypt::Config> config =
|
||||
std::make_unique<os_crypt::Config>();
|
||||
// Forward to os_crypt the flag to use a specific password store.
|
||||
config->store =
|
||||
command_line->GetSwitchValueASCII(password_manager::kPasswordStore);
|
||||
// Forward the product name
|
||||
config->product_name = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME);
|
||||
// OSCrypt can be disabled in a special settings file.
|
||||
config->should_use_preference =
|
||||
command_line->HasSwitch(password_manager::kEnableEncryptionSelection);
|
||||
base::PathService::Get(chrome::DIR_USER_DATA, &config->user_data_path);
|
||||
DCHECK(!config->user_data_path.empty());
|
||||
OSCrypt::SetConfig(std::move(config));
|
||||
#endif // BUILDFLAG(IS_LINUX)
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
base::SetExtraNoExecuteAllowedPath(chrome::DIR_USER_DATA);
|
||||
#endif
|
||||
}
|
||||
|
||||
int AlloyBrowserMainParts::PreCreateThreads() {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
PlatformInitialize();
|
||||
#endif
|
||||
|
||||
net::NetModule::SetResourceProvider(&NetResourceProvider);
|
||||
|
||||
// Initialize these objects before IO access restrictions are applied and
|
||||
// before the IO thread is started.
|
||||
content::GpuDataManager::GetInstance();
|
||||
SystemNetworkContextManager::CreateInstance(g_browser_process->local_state());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::PostCreateThreads() {
|
||||
ChromeProcessSingleton::GetInstance()->StartWatching();
|
||||
}
|
||||
|
||||
int AlloyBrowserMainParts::PreMainMessageLoopRun() {
|
||||
#if defined(USE_AURA)
|
||||
screen_ = views::CreateDesktopScreen();
|
||||
#endif
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
screen_ = std::make_unique<display::ScopedNativeScreen>();
|
||||
#endif
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
// This should be set in ChromeBrowserProcessAlloy::Initialize.
|
||||
DCHECK(extensions::ExtensionsBrowserClient::Get());
|
||||
// Initialize extension global objects before creating the global
|
||||
// BrowserContext.
|
||||
extensions::CefExtensionSystemFactory::GetInstance();
|
||||
}
|
||||
|
||||
// Register additional KeyedService factories here. See
|
||||
// ChromeBrowserMainExtraPartsProfiles for details.
|
||||
cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
||||
|
||||
background_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
||||
{base::TaskPriority::BEST_EFFORT,
|
||||
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
||||
user_visible_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
||||
{base::TaskPriority::USER_VISIBLE,
|
||||
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
||||
user_blocking_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
||||
{base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
||||
|
||||
CefRequestContextSettings settings;
|
||||
CefContext::Get()->PopulateGlobalRequestContextSettings(&settings);
|
||||
|
||||
// Create the global RequestContext.
|
||||
global_request_context_ =
|
||||
CefRequestContextImpl::CreateGlobalRequestContext(settings);
|
||||
auto browser_context =
|
||||
global_request_context_->GetBrowserContext()->AsBrowserContext();
|
||||
|
||||
CefDevToolsManagerDelegate::StartHttpHandler(browser_context);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// Windows parental controls calls can be slow, so we do an early init here
|
||||
// that calculates this value off of the UI thread.
|
||||
InitializeWinParentalControls();
|
||||
|
||||
// These methods may call LoadLibrary and could trigger
|
||||
// AssertBlockingAllowed() failures if executed at a later time on the UI
|
||||
// thread.
|
||||
base::IsManagedDevice();
|
||||
base::IsEnterpriseDevice();
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
scheme::RegisterWebUIControllerFactory();
|
||||
file_dialog_runner::RegisterFactory();
|
||||
permission_prompt::RegisterCreateCallback();
|
||||
|
||||
// Initialize theme configuration (high contrast, dark mode, etc).
|
||||
ui::NativeTheme::GetInstanceForNativeUi();
|
||||
|
||||
#if BUILDFLAG(ENABLE_MEDIA_FOUNDATION_WIDEVINE_CDM) || \
|
||||
BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
if (!command_line->HasSwitch(switches::kDisableComponentUpdate)) {
|
||||
auto* const cus = g_browser_process->component_updater();
|
||||
|
||||
#if BUILDFLAG(ENABLE_MEDIA_FOUNDATION_WIDEVINE_CDM)
|
||||
RegisterMediaFoundationWidevineCdmComponent(cus);
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
|
||||
RegisterWidevineCdmComponent(cus);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allow ProcessSingleton to process messages.
|
||||
// This is done here instead of just relying on the main message loop's start
|
||||
// to avoid rendezvous in RunLoops that may precede MainMessageLoopRun.
|
||||
ChromeProcessSingleton::GetInstance()->Unlock(
|
||||
base::BindRepeating(&ProcessSingletonNotificationCallback));
|
||||
|
||||
return content::RESULT_CODE_NORMAL_EXIT;
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::PostMainMessageLoopRun() {
|
||||
// NOTE: Destroy objects in reverse order of creation.
|
||||
CefDevToolsManagerDelegate::StopHttpHandler();
|
||||
|
||||
ChromeProcessSingleton::GetInstance()->Cleanup();
|
||||
|
||||
// There should be no additional references to the global CefRequestContext
|
||||
// during shutdown. Did you forget to release a CefBrowser reference?
|
||||
DCHECK(global_request_context_->HasOneRef());
|
||||
global_request_context_ = nullptr;
|
||||
}
|
||||
|
||||
void AlloyBrowserMainParts::PostDestroyThreads() {
|
||||
views_delegate_.reset();
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
layout_provider_.reset();
|
||||
#endif
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cef/libcef/browser/request_context_impl.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/browser/browser_main_parts.h"
|
||||
#include "ui/display/screen.h"
|
||||
|
||||
#if defined(USE_AURA)
|
||||
namespace wm {
|
||||
class WMState;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace views {
|
||||
class ViewsDelegate;
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
class LayoutProvider;
|
||||
#endif
|
||||
} // namespace views
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
namespace ui {
|
||||
class LinuxUiGetter;
|
||||
#if defined(USE_DBUS)
|
||||
class DarkModeManagerLinux;
|
||||
#endif
|
||||
} // namespace ui
|
||||
#endif
|
||||
|
||||
class CefDevToolsDelegate;
|
||||
|
||||
class AlloyBrowserMainParts : public content::BrowserMainParts {
|
||||
public:
|
||||
AlloyBrowserMainParts();
|
||||
|
||||
AlloyBrowserMainParts(const AlloyBrowserMainParts&) = delete;
|
||||
AlloyBrowserMainParts& operator=(const AlloyBrowserMainParts&) = delete;
|
||||
|
||||
~AlloyBrowserMainParts() override;
|
||||
|
||||
void ToolkitInitialized() override;
|
||||
void PreCreateMainMessageLoop() override;
|
||||
void PostCreateMainMessageLoop() override;
|
||||
int PreCreateThreads() override;
|
||||
void PostCreateThreads() override;
|
||||
int PreMainMessageLoopRun() override;
|
||||
void PostMainMessageLoopRun() override;
|
||||
void PostDestroyThreads() override;
|
||||
|
||||
CefRefPtr<CefRequestContextImpl> request_context() const {
|
||||
return global_request_context_;
|
||||
}
|
||||
CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_; }
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const {
|
||||
return background_task_runner_;
|
||||
}
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner() const {
|
||||
return user_visible_task_runner_;
|
||||
}
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner()
|
||||
const {
|
||||
return user_blocking_task_runner_;
|
||||
}
|
||||
|
||||
private:
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
void PlatformInitialize();
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
CefRefPtr<CefRequestContextImpl> global_request_context_;
|
||||
raw_ptr<CefDevToolsDelegate> devtools_delegate_ = nullptr; // Deletes itself.
|
||||
|
||||
// Blocking task runners exposed via CefTaskRunner. For consistency with
|
||||
// previous named thread behavior always execute all pending tasks before
|
||||
// shutdown (e.g. to make sure critical data is saved to disk).
|
||||
// |background_task_runner_| is also passed to SQLitePersistentCookieStore.
|
||||
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner_;
|
||||
|
||||
#if defined(USE_AURA)
|
||||
std::unique_ptr<display::Screen> screen_;
|
||||
std::unique_ptr<wm::WMState> wm_state_;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<views::ViewsDelegate> views_delegate_;
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
std::unique_ptr<display::ScopedNativeScreen> screen_;
|
||||
std::unique_ptr<views::LayoutProvider> layout_provider_;
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
std::unique_ptr<ui::LinuxUiGetter> linux_ui_getter_;
|
||||
#if defined(USE_DBUS)
|
||||
std::unique_ptr<ui::DarkModeManagerLinux> dark_mode_manager_;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_MAIN_H_
|
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_main.h"
|
||||
|
||||
#include <Objbase.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <commctrl.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
||||
void AlloyBrowserMainParts::PlatformInitialize() {
|
||||
HRESULT res;
|
||||
|
||||
// Initialize common controls.
|
||||
res = CoInitialize(nullptr);
|
||||
DCHECK(SUCCEEDED(res));
|
||||
INITCOMMONCONTROLSEX InitCtrlEx;
|
||||
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
InitCtrlEx.dwICC = ICC_STANDARD_CLASSES;
|
||||
InitCommonControlsEx(&InitCtrlEx);
|
||||
|
||||
// Start COM stuff.
|
||||
res = OleInitialize(nullptr);
|
||||
DCHECK(SUCCEEDED(res));
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,287 +0,0 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_CONTENT_BROWSER_CLIENT_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_CONTENT_BROWSER_CLIENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cef/include/cef_request_context_handler.h"
|
||||
#include "cef/libcef/browser/request_context_impl.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
class AlloyBrowserMainParts;
|
||||
class CefDevToolsDelegate;
|
||||
|
||||
namespace content {
|
||||
class SiteInstance;
|
||||
} // namespace content
|
||||
|
||||
namespace extensions {
|
||||
class Extension;
|
||||
}
|
||||
|
||||
class AlloyContentBrowserClient : public content::ContentBrowserClient {
|
||||
public:
|
||||
AlloyContentBrowserClient();
|
||||
~AlloyContentBrowserClient() override;
|
||||
|
||||
void CleanupOnUIThread();
|
||||
|
||||
// ContentBrowserClient implementation.
|
||||
std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts(
|
||||
bool is_integration_test) override;
|
||||
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
|
||||
bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
|
||||
const GURL& site_url) override;
|
||||
bool ShouldUseSpareRenderProcessHost(content::BrowserContext* browser_context,
|
||||
const GURL& site_url) override;
|
||||
bool DoesSiteRequireDedicatedProcess(content::BrowserContext* browser_context,
|
||||
const GURL& effective_site_url) override;
|
||||
bool ShouldTreatURLSchemeAsFirstPartyWhenTopLevel(
|
||||
std::string_view scheme,
|
||||
bool is_embedded_origin_secure) override;
|
||||
bool ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel(
|
||||
std::string_view scheme,
|
||||
bool is_embedded_origin_secure) override;
|
||||
void OverrideURLLoaderFactoryParams(
|
||||
content::BrowserContext* browser_context,
|
||||
const url::Origin& origin,
|
||||
bool is_for_isolated_world,
|
||||
network::mojom::URLLoaderFactoryParams* factory_params) override;
|
||||
void GetAdditionalWebUISchemes(
|
||||
std::vector<std::string>* additional_schemes) override;
|
||||
void GetAdditionalViewSourceSchemes(
|
||||
std::vector<std::string>* additional_schemes) override;
|
||||
std::unique_ptr<ui::SelectFilePolicy> CreateSelectFilePolicy(
|
||||
content::WebContents* web_contents) override;
|
||||
void GetAdditionalAllowedSchemesForFileSystem(
|
||||
std::vector<std::string>* additional_allowed_schemes) override;
|
||||
bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) override;
|
||||
bool IsHandledURL(const GURL& url) override;
|
||||
void SiteInstanceGotProcessAndSite(
|
||||
content::SiteInstance* site_instance) override;
|
||||
void BindHostReceiverForRenderer(
|
||||
content::RenderProcessHost* render_process_host,
|
||||
mojo::GenericPendingReceiver receiver) override;
|
||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
|
||||
int child_process_id) override;
|
||||
std::string GetApplicationLocale() override;
|
||||
scoped_refptr<network::SharedURLLoaderFactory>
|
||||
GetSystemSharedURLLoaderFactory() override;
|
||||
network::mojom::NetworkContext* GetSystemNetworkContext() override;
|
||||
content::MediaObserver* GetMediaObserver() override;
|
||||
content::SpeechRecognitionManagerDelegate*
|
||||
CreateSpeechRecognitionManagerDelegate() override;
|
||||
content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings(
|
||||
content::BrowserContext* context) override;
|
||||
void AllowCertificateError(
|
||||
content::WebContents* web_contents,
|
||||
int cert_error,
|
||||
const net::SSLInfo& ssl_info,
|
||||
const GURL& request_url,
|
||||
bool is_main_frame_request,
|
||||
bool strict_enforcement,
|
||||
base::OnceCallback<void(content::CertificateRequestResultType)> callback)
|
||||
override;
|
||||
base::OnceClosure SelectClientCertificate(
|
||||
content::BrowserContext* browser_context,
|
||||
content::WebContents* web_contents,
|
||||
net::SSLCertRequestInfo* cert_request_info,
|
||||
net::ClientCertIdentityList client_certs,
|
||||
std::unique_ptr<content::ClientCertificateDelegate> delegate) override;
|
||||
bool CanCreateWindow(content::RenderFrameHost* opener,
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
const url::Origin& source_origin,
|
||||
content::mojom::WindowContainerType container_type,
|
||||
const GURL& target_url,
|
||||
const content::Referrer& referrer,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
bool* no_javascript_access) override;
|
||||
void OverrideWebkitPrefs(content::WebContents* web_contents,
|
||||
blink::web_pref::WebPreferences* prefs) override;
|
||||
bool OverrideWebPreferencesAfterNavigation(
|
||||
content::WebContents* web_contents,
|
||||
blink::web_pref::WebPreferences* prefs) override;
|
||||
void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override;
|
||||
std::string GetDefaultDownloadName() override;
|
||||
std::unique_ptr<content::DevToolsManagerDelegate>
|
||||
CreateDevToolsManagerDelegate() override;
|
||||
void ExposeInterfacesToRenderer(
|
||||
service_manager::BinderRegistry* registry,
|
||||
blink::AssociatedInterfaceRegistry* associated_registry,
|
||||
content::RenderProcessHost* render_process_host) override;
|
||||
void RegisterAssociatedInterfaceBindersForServiceWorker(
|
||||
const content::ServiceWorkerVersionBaseInfo& service_worker_version_info,
|
||||
blink::AssociatedInterfaceRegistry& associated_registry) override;
|
||||
void RegisterAssociatedInterfaceBindersForRenderFrameHost(
|
||||
content::RenderFrameHost& render_frame_host,
|
||||
blink::AssociatedInterfaceRegistry& associated_registry) override;
|
||||
std::vector<std::unique_ptr<content::NavigationThrottle>>
|
||||
CreateThrottlesForNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
|
||||
CreateURLLoaderThrottles(
|
||||
const network::ResourceRequest& request,
|
||||
content::BrowserContext* browser_context,
|
||||
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
|
||||
content::NavigationUIData* navigation_ui_data,
|
||||
int frame_tree_node_id,
|
||||
std::optional<int64_t> navigation_id) override;
|
||||
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
|
||||
CreateURLLoaderThrottlesForKeepAlive(
|
||||
const network::ResourceRequest& request,
|
||||
content::BrowserContext* browser_context,
|
||||
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
|
||||
int frame_tree_node_id) override;
|
||||
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
|
||||
WillCreateURLLoaderRequestInterceptors(
|
||||
content::NavigationUIData* navigation_ui_data,
|
||||
int frame_tree_node_id,
|
||||
int64_t navigation_id,
|
||||
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner)
|
||||
override;
|
||||
|
||||
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
|
||||
void GetAdditionalMappedFilesForChildProcess(
|
||||
const base::CommandLine& command_line,
|
||||
int child_process_id,
|
||||
content::PosixFileDescriptorInfo* mappings) override;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
|
||||
content::BrowserContext* browser_context) override;
|
||||
std::unique_ptr<content::LoginDelegate> CreateLoginDelegate(
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
content::WebContents* web_contents,
|
||||
content::BrowserContext* browser_context,
|
||||
const content::GlobalRequestID& request_id,
|
||||
bool is_request_for_main_frame,
|
||||
const GURL& url,
|
||||
scoped_refptr<net::HttpResponseHeaders> response_headers,
|
||||
bool first_auth_attempt,
|
||||
LoginAuthRequiredCallback auth_required_callback) override;
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory>
|
||||
CreateNonNetworkNavigationURLLoaderFactory(const std::string& scheme,
|
||||
int frame_tree_node_id) override;
|
||||
void RegisterNonNetworkSubresourceURLLoaderFactories(
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
const std::optional<url::Origin>& request_initiator_origin,
|
||||
NonNetworkURLLoaderFactoryMap* factories) override;
|
||||
void WillCreateURLLoaderFactory(
|
||||
content::BrowserContext* browser_context,
|
||||
content::RenderFrameHost* frame,
|
||||
int render_process_id,
|
||||
URLLoaderFactoryType type,
|
||||
const url::Origin& request_initiator,
|
||||
const net::IsolationInfo& isolation_info,
|
||||
std::optional<int64_t> navigation_id,
|
||||
ukm::SourceIdObj ukm_source_id,
|
||||
network::URLLoaderFactoryBuilder& factory_builder,
|
||||
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
|
||||
header_client,
|
||||
bool* bypass_redirect_checks,
|
||||
bool* disable_secure_dns,
|
||||
network::mojom::URLLoaderFactoryOverridePtr* factory_override,
|
||||
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner)
|
||||
override;
|
||||
void OnNetworkServiceCreated(
|
||||
network::mojom::NetworkService* network_service) override;
|
||||
bool ConfigureNetworkContextParams(
|
||||
content::BrowserContext* context,
|
||||
bool in_memory,
|
||||
const base::FilePath& relative_partition_path,
|
||||
network::mojom::NetworkContextParams* network_context_params,
|
||||
cert_verifier::mojom::CertVerifierCreationParams*
|
||||
cert_verifier_creation_params) override;
|
||||
std::vector<base::FilePath> GetNetworkContextsParentDirectory() override;
|
||||
bool HandleExternalProtocol(
|
||||
const GURL& url,
|
||||
content::WebContents::Getter web_contents_getter,
|
||||
int frame_tree_node_id,
|
||||
content::NavigationUIData* navigation_data,
|
||||
bool is_primary_main_frame,
|
||||
bool is_in_fenced_frame_tree,
|
||||
network::mojom::WebSandboxFlags sandbox_flags,
|
||||
ui::PageTransition page_transition,
|
||||
bool has_user_gesture,
|
||||
const std::optional<url::Origin>& initiating_origin,
|
||||
content::RenderFrameHost* initiator_document,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory)
|
||||
override;
|
||||
bool HandleExternalProtocol(
|
||||
content::WebContents::Getter web_contents_getter,
|
||||
int frame_tree_node_id,
|
||||
content::NavigationUIData* navigation_data,
|
||||
bool is_primary_main_frame,
|
||||
bool is_in_fenced_frame_tree,
|
||||
network::mojom::WebSandboxFlags sandbox_flags,
|
||||
const network::ResourceRequest& request,
|
||||
const std::optional<url::Origin>& initiating_origin,
|
||||
content::RenderFrameHost* initiator_document,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory)
|
||||
override;
|
||||
std::unique_ptr<content::VideoOverlayWindow>
|
||||
CreateWindowForVideoPictureInPicture(
|
||||
content::VideoPictureInPictureWindowController* controller) override;
|
||||
void RegisterBrowserInterfaceBindersForFrame(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) override;
|
||||
void RegisterBrowserInterfaceBindersForServiceWorker(
|
||||
content::BrowserContext* browser_context,
|
||||
const content::ServiceWorkerVersionBaseInfo& service_worker_version_info,
|
||||
mojo::BinderMapWithContext<const content::ServiceWorkerVersionBaseInfo&>*
|
||||
map) override;
|
||||
base::FilePath GetSandboxedStorageServiceDataDirectory() override;
|
||||
base::FilePath GetShaderDiskCacheDirectory() override;
|
||||
base::FilePath GetGrShaderDiskCacheDirectory() override;
|
||||
base::FilePath GetGraphiteDawnDiskCacheDirectory() override;
|
||||
base::FilePath GetNetLogDefaultDirectory() override;
|
||||
base::FilePath GetFirstPartySetsDirectory() override;
|
||||
std::optional<base::FilePath> GetLocalTracesDirectory() override;
|
||||
std::string GetProduct() override;
|
||||
std::string GetChromeProduct() override;
|
||||
std::string GetUserAgent() override;
|
||||
std::unique_ptr<content::WebContentsViewDelegate> GetWebContentsViewDelegate(
|
||||
content::WebContents* web_contents) override;
|
||||
blink::UserAgentMetadata GetUserAgentMetadata() override;
|
||||
base::flat_set<std::string> GetPluginMimeTypesWithExternalHandlers(
|
||||
content::BrowserContext* browser_context) override;
|
||||
void GetMediaDeviceIDSalt(
|
||||
content::RenderFrameHost* rfh,
|
||||
const net::SiteForCookies& site_for_cookies,
|
||||
const blink::StorageKey& storage_key,
|
||||
base::OnceCallback<void(bool, const std::string&)> callback) override;
|
||||
void OnWebContentsCreated(content::WebContents* web_contents) override;
|
||||
bool IsFindInPageDisabledForOrigin(const url::Origin& origin) override;
|
||||
|
||||
CefRefPtr<CefRequestContextImpl> request_context() const;
|
||||
CefDevToolsDelegate* devtools_delegate() const;
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner() const;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner() const;
|
||||
|
||||
private:
|
||||
// Returns the extension or app associated with |site_instance| or NULL.
|
||||
const extensions::Extension* GetExtension(
|
||||
content::SiteInstance* site_instance);
|
||||
|
||||
raw_ptr<AlloyBrowserMainParts> browser_main_parts_ = nullptr;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_CONTENT_BROWSER_CLIENT_H_
|
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_download_manager_delegate.h"
|
||||
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "components/download/public/common/download_item.h"
|
||||
|
||||
AlloyDownloadManagerDelegate::AlloyDownloadManagerDelegate(
|
||||
content::DownloadManager* manager)
|
||||
: CefDownloadManagerDelegateImpl(manager, /*alloy_bootstrap=*/true) {}
|
||||
|
||||
void AlloyDownloadManagerDelegate::GetNextId(
|
||||
content::DownloadIdCallback callback) {
|
||||
static uint32_t next_id = download::DownloadItem::kInvalidId + 1;
|
||||
std::move(callback).Run(next_id++);
|
||||
}
|
||||
|
||||
std::string AlloyDownloadManagerDelegate::ApplicationClientIdForFileScanning() {
|
||||
return std::string(chrome::kApplicationClientIDStringForAVScanning);
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_MANAGER_DELEGATE_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_MANAGER_DELEGATE_H_
|
||||
#pragma once
|
||||
|
||||
#include "cef/libcef/browser/download_manager_delegate_impl.h"
|
||||
|
||||
// Specialization for the Alloy bootstrap.
|
||||
class AlloyDownloadManagerDelegate : public CefDownloadManagerDelegateImpl {
|
||||
public:
|
||||
explicit AlloyDownloadManagerDelegate(content::DownloadManager* manager);
|
||||
|
||||
AlloyDownloadManagerDelegate(const AlloyDownloadManagerDelegate&) = delete;
|
||||
AlloyDownloadManagerDelegate& operator=(const AlloyDownloadManagerDelegate&) =
|
||||
delete;
|
||||
|
||||
private:
|
||||
// DownloadManagerDelegate methods.
|
||||
void GetNextId(content::DownloadIdCallback callback) override;
|
||||
std::string ApplicationClientIdForFileScanning() override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_MANAGER_DELEGATE_H_
|
@@ -1,18 +0,0 @@
|
||||
// Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_download_util.h"
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_context.h"
|
||||
|
||||
namespace alloy {
|
||||
|
||||
DownloadPrefs* GetDownloadPrefsFromBrowserContext(
|
||||
content::BrowserContext* context) {
|
||||
// This function is only called with Alloy bootstrap, so the static_cast is
|
||||
// safe.
|
||||
return static_cast<AlloyBrowserContext*>(context)->GetDownloadPrefs();
|
||||
}
|
||||
|
||||
} // namespace alloy
|
@@ -1,25 +0,0 @@
|
||||
// Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_UTIL_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include "cef/libcef/features/features.h"
|
||||
|
||||
class DownloadPrefs;
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
} // namespace content
|
||||
|
||||
namespace alloy {
|
||||
|
||||
// Called from DownloadPrefs::FromBrowserContext.
|
||||
DownloadPrefs* GetDownloadPrefsFromBrowserContext(
|
||||
content::BrowserContext* context);
|
||||
|
||||
} // namespace alloy
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_DOWNLOAD_UTIL_H_
|
@@ -1,21 +0,0 @@
|
||||
// Copyright 2022 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_web_contents_view_delegate.h"
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
AlloyWebContentsViewDelegate::AlloyWebContentsViewDelegate(
|
||||
content::WebContents* web_contents)
|
||||
: web_contents_(web_contents) {}
|
||||
|
||||
void AlloyWebContentsViewDelegate::ShowContextMenu(
|
||||
content::RenderFrameHost& render_frame_host,
|
||||
const content::ContextMenuParams& params) {
|
||||
if (auto browser =
|
||||
AlloyBrowserHostImpl::GetBrowserForContents(web_contents_)) {
|
||||
browser->ShowContextMenu(params);
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
// Copyright 2022 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_WEB_CONTENTS_VIEW_DELEGATE_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_WEB_CONTENTS_VIEW_DELEGATE_H_
|
||||
#pragma once
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "cef/include/internal/cef_ptr.h"
|
||||
#include "content/public/browser/web_contents_view_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
class AlloyWebContentsViewDelegate : public content::WebContentsViewDelegate {
|
||||
public:
|
||||
explicit AlloyWebContentsViewDelegate(content::WebContents* web_contents);
|
||||
|
||||
AlloyWebContentsViewDelegate(const AlloyWebContentsViewDelegate&) = delete;
|
||||
AlloyWebContentsViewDelegate& operator=(const AlloyWebContentsViewDelegate&) =
|
||||
delete;
|
||||
|
||||
// WebContentsViewDelegate methods:
|
||||
void ShowContextMenu(content::RenderFrameHost& render_frame_host,
|
||||
const content::ContextMenuParams& params) override;
|
||||
|
||||
private:
|
||||
const raw_ptr<content::WebContents> web_contents_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_WEB_CONTENTS_VIEW_DELEGATE_H_
|
@@ -8,13 +8,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "cef/libcef/browser/extensions/extension_background_host.h"
|
||||
#include "cef/libcef/browser/extensions/extension_system.h"
|
||||
#include "cef/libcef/browser/extensions/extension_view_host.h"
|
||||
#include "cef/libcef/browser/extensions/extension_web_contents_observer.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "cef/libcef/common/net/url_util.h"
|
||||
#include "cef/libcef/features/features.h"
|
||||
#include "chrome/browser/task_manager/web_contents_tags.h"
|
||||
#include "chrome/browser/ui/tab_helpers.h"
|
||||
#include "components/find_in_page/find_tab_helper.h"
|
||||
@@ -26,34 +20,10 @@
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
#include "cef/libcef/browser/alloy/dialogs/alloy_javascript_dialog_manager_delegate.h"
|
||||
#include "cef/libcef/features/runtime_checks.h"
|
||||
#include "chrome/browser/printing/printing_init.h"
|
||||
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||
#include "components/javascript_dialogs/tab_modal_dialog_manager.h"
|
||||
#include "components/permissions/permission_request_manager.h"
|
||||
#include "components/zoom/zoom_controller.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
namespace {
|
||||
|
||||
const char kAttachedHelpersUserDataKey[] = "CefAttachedHelpers";
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
const extensions::Extension* GetExtensionForUrl(
|
||||
content::BrowserContext* browser_context,
|
||||
const GURL& url) {
|
||||
auto* registry = extensions::ExtensionRegistry::Get(browser_context);
|
||||
if (!registry) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string extension_id = url.host();
|
||||
return registry->enabled_extensions().GetByID(extension_id);
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
} // namespace
|
||||
|
||||
CefBrowserPlatformDelegateAlloy::CefBrowserPlatformDelegateAlloy()
|
||||
@@ -73,38 +43,7 @@ content::WebContents* CefBrowserPlatformDelegateAlloy::CreateWebContents(
|
||||
CefRequestContextImpl::GetBrowserContext(create_params.request_context);
|
||||
CHECK(browser_context);
|
||||
|
||||
scoped_refptr<content::SiteInstance> site_instance;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (extensions::ExtensionsEnabled() && !create_params.url.empty()) {
|
||||
GURL gurl = url_util::MakeGURL(create_params.url, /*fixup=*/true);
|
||||
if (!create_params.extension) {
|
||||
// We might be loading an extension app view where the extension URL is
|
||||
// provided by the client.
|
||||
create_params.extension = GetExtensionForUrl(browser_context, gurl);
|
||||
}
|
||||
if (create_params.extension) {
|
||||
if (create_params.extension_host_type ==
|
||||
extensions::mojom::ViewType::kInvalid) {
|
||||
// Default to popup behavior.
|
||||
create_params.extension_host_type =
|
||||
extensions::mojom::ViewType::kExtensionPopup;
|
||||
}
|
||||
|
||||
// Extension resources will fail to load if we don't use a SiteInstance
|
||||
// associated with the extension.
|
||||
// (AlloyContentBrowserClient::SiteInstanceGotProcessAndSite won't find
|
||||
// the extension to register with InfoMap, and AllowExtensionResourceLoad
|
||||
// in ExtensionProtocolHandler::MaybeCreateJob will return false resulting
|
||||
// in ERR_BLOCKED_BY_CLIENT).
|
||||
site_instance = extensions::ProcessManager::Get(browser_context)
|
||||
->GetSiteInstanceForURL(gurl);
|
||||
DCHECK(site_instance);
|
||||
}
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
content::WebContents::CreateParams wc_create_params(browser_context,
|
||||
site_instance);
|
||||
content::WebContents::CreateParams wc_create_params(browser_context, nullptr);
|
||||
|
||||
if (IsWindowless()) {
|
||||
// Create the OSR view for the WebContents.
|
||||
@@ -154,28 +93,8 @@ void CefBrowserPlatformDelegateAlloy::AddNewContents(
|
||||
->SetOwnedWebContents(new_contents.release());
|
||||
return;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
if (extension_host_) {
|
||||
extension_host_->AddNewContents(source, std::move(new_contents), target_url,
|
||||
disposition, window_features, user_gesture,
|
||||
was_blocked);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool CefBrowserPlatformDelegateAlloy::
|
||||
ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
bool is_main_frame_navigation) {
|
||||
if (extension_host_) {
|
||||
return extension_host_->ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
is_main_frame_navigation);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::RenderViewReady() {
|
||||
ConfigureAutoResize();
|
||||
}
|
||||
@@ -200,55 +119,9 @@ void CefBrowserPlatformDelegateAlloy::BrowserCreated(
|
||||
std::make_unique<AlloyWebContentsDialogHelper>(web_contents_, this);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
void CefBrowserPlatformDelegateAlloy::CreateExtensionHost(
|
||||
const extensions::Extension* extension,
|
||||
const GURL& url,
|
||||
extensions::mojom::ViewType host_type) {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
DCHECK(primary_);
|
||||
|
||||
// Should get WebContentsCreated and BrowserCreated calls first.
|
||||
DCHECK(web_contents_);
|
||||
DCHECK(browser_);
|
||||
DCHECK(!extension_host_);
|
||||
|
||||
auto alloy_browser = AlloyBrowserHostImpl::FromBaseChecked(browser_.get());
|
||||
|
||||
if (host_type == extensions::mojom::ViewType::kExtensionPopup) {
|
||||
// Create an extension host that we own.
|
||||
extension_host_ = new extensions::CefExtensionViewHost(
|
||||
alloy_browser.get(), extension, web_contents_, url, host_type);
|
||||
// Trigger load of the extension URL.
|
||||
extension_host_->CreateRendererSoon();
|
||||
} else if (host_type ==
|
||||
extensions::mojom::ViewType::kExtensionBackgroundPage) {
|
||||
is_background_host_ = true;
|
||||
alloy_browser->is_background_host_ = true;
|
||||
// Create an extension host that will be owned by ProcessManager.
|
||||
extension_host_ = new extensions::CefExtensionBackgroundHost(
|
||||
alloy_browser.get(),
|
||||
base::BindOnce(&CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted,
|
||||
weak_ptr_factory_.GetWeakPtr()),
|
||||
extension, web_contents_, url, host_type);
|
||||
// Load will be triggered by ProcessManager::CreateBackgroundHost.
|
||||
} else {
|
||||
DCHECK(false) << " Unsupported extension host type: " << host_type;
|
||||
}
|
||||
}
|
||||
|
||||
extensions::ExtensionHost* CefBrowserPlatformDelegateAlloy::GetExtensionHost()
|
||||
const {
|
||||
return extension_host_;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::BrowserDestroyed(
|
||||
CefBrowserHostBase* browser) {
|
||||
if (primary_) {
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
DestroyExtensionHost();
|
||||
#endif
|
||||
owned_web_contents_.reset();
|
||||
}
|
||||
|
||||
@@ -290,25 +163,6 @@ void CefBrowserPlatformDelegateAlloy::NotifyMoveOrResizeStarted() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool CefBrowserPlatformDelegateAlloy::PreHandleGestureEvent(
|
||||
content::WebContents* source,
|
||||
const blink::WebGestureEvent& event) {
|
||||
if (extension_host_) {
|
||||
return extension_host_->PreHandleGestureEvent(source, event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateAlloy::IsNeverComposited(
|
||||
content::WebContents* web_contents) {
|
||||
if (extension_host_) {
|
||||
return extension_host_->IsNeverComposited(web_contents);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::SetAutoResizeEnabled(
|
||||
bool enabled,
|
||||
const CefSize& min_size,
|
||||
@@ -404,34 +258,6 @@ void CefBrowserPlatformDelegateAlloy::SetOwnedWebContents(
|
||||
owned_web_contents_.reset(owned_contents);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
void CefBrowserPlatformDelegateAlloy::DestroyExtensionHost() {
|
||||
if (!extension_host_) {
|
||||
return;
|
||||
}
|
||||
if (extension_host_->extension_host_type() ==
|
||||
extensions::mojom::ViewType::kExtensionBackgroundPage) {
|
||||
DCHECK(is_background_host_);
|
||||
// Close notification for background pages arrives via CloseContents.
|
||||
// The extension host will be deleted by
|
||||
// ProcessManager::CloseBackgroundHost and OnExtensionHostDeleted will be
|
||||
// called to notify us.
|
||||
extension_host_->Close();
|
||||
} else {
|
||||
DCHECK(!is_background_host_);
|
||||
// We own the extension host and must delete it.
|
||||
delete extension_host_;
|
||||
extension_host_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::OnExtensionHostDeleted() {
|
||||
DCHECK(is_background_host_);
|
||||
DCHECK(extension_host_);
|
||||
extension_host_ = nullptr;
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
|
||||
void CefBrowserPlatformDelegateAlloy::AttachHelpers(
|
||||
content::WebContents* web_contents) {
|
||||
// If already attached, nothing to be done.
|
||||
@@ -445,36 +271,20 @@ void CefBrowserPlatformDelegateAlloy::AttachHelpers(
|
||||
web_contents->SetUserData(&kAttachedHelpersUserDataKey,
|
||||
std::make_unique<base::SupportsUserData::Data>());
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Create all the helpers.
|
||||
if (cef::IsAlloyRuntimeEnabled()) {
|
||||
find_in_page::FindTabHelper::CreateForWebContents(web_contents);
|
||||
permissions::PermissionRequestManager::CreateForWebContents(web_contents);
|
||||
PrefsTabHelper::CreateForWebContents(web_contents);
|
||||
printing::InitializePrintingForWebContents(web_contents);
|
||||
zoom::ZoomController::CreateForWebContents(web_contents);
|
||||
|
||||
javascript_dialogs::TabModalDialogManager::CreateForWebContents(
|
||||
web_contents, CreateAlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
||||
web_contents));
|
||||
} else
|
||||
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
{
|
||||
if (IsWindowless()) {
|
||||
// Logic from ChromeContentBrowserClientCef::GetWebContentsViewDelegate
|
||||
// which is not called for windowless browsers. Needs to be done before
|
||||
// calling AttachTabHelpers.
|
||||
if (auto* registry =
|
||||
performance_manager::PerformanceManagerRegistry::GetInstance()) {
|
||||
registry->MaybeCreatePageNodeForWebContents(web_contents);
|
||||
}
|
||||
if (IsWindowless()) {
|
||||
// Logic from ChromeContentBrowserClientCef::GetWebContentsViewDelegate
|
||||
// which is not called for windowless browsers. Needs to be done before
|
||||
// calling AttachTabHelpers.
|
||||
if (auto* registry =
|
||||
performance_manager::PerformanceManagerRegistry::GetInstance()) {
|
||||
registry->MaybeCreatePageNodeForWebContents(web_contents);
|
||||
}
|
||||
|
||||
// Adopt the WebContents now, so all observers are in place, as the network
|
||||
// requests for its initial navigation will start immediately
|
||||
TabHelpers::AttachTabHelpers(web_contents);
|
||||
|
||||
// Make the tab show up in the task manager.
|
||||
task_manager::WebContentsTags::CreateForTabContents(web_contents);
|
||||
}
|
||||
|
||||
// Adopt the WebContents now, so all observers are in place, as the network
|
||||
// requests for its initial navigation will start immediately
|
||||
TabHelpers::AttachTabHelpers(web_contents);
|
||||
|
||||
// Make the tab show up in the task manager.
|
||||
task_manager::WebContentsTags::CreateForTabContents(web_contents);
|
||||
}
|
||||
|
@@ -33,29 +33,14 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
|
||||
const blink::mojom::WindowFeatures& window_features,
|
||||
bool user_gesture,
|
||||
bool* was_blocked) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool ShouldAllowRendererInitiatedCrossProcessNavigation(
|
||||
bool is_main_frame_navigation) override;
|
||||
#endif
|
||||
void RenderViewReady() override;
|
||||
void BrowserCreated(CefBrowserHostBase* browser) override;
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
void CreateExtensionHost(const extensions::Extension* extension,
|
||||
const GURL& url,
|
||||
extensions::mojom::ViewType host_type) override;
|
||||
extensions::ExtensionHost* GetExtensionHost() const override;
|
||||
#endif
|
||||
void BrowserDestroyed(CefBrowserHostBase* browser) override;
|
||||
web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
|
||||
const override;
|
||||
void SendCaptureLostEvent() override;
|
||||
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC))
|
||||
void NotifyMoveOrResizeStarted() override;
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
bool PreHandleGestureEvent(content::WebContents* source,
|
||||
const blink::WebGestureEvent& event) override;
|
||||
bool IsNeverComposited(content::WebContents* web_contents) override;
|
||||
#endif
|
||||
bool IsAlloyStyle() const override { return true; }
|
||||
void SetAutoResizeEnabled(bool enabled,
|
||||
@@ -89,11 +74,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
|
||||
private:
|
||||
void SetOwnedWebContents(content::WebContents* owned_contents);
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
void DestroyExtensionHost();
|
||||
void OnExtensionHostDeleted();
|
||||
#endif
|
||||
|
||||
void ConfigureAutoResize();
|
||||
|
||||
// Attach all the associated helpers that are needed for the WebContents. It
|
||||
@@ -113,12 +93,6 @@ class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate {
|
||||
// matches, the find selection rectangle, etc.
|
||||
find_in_page::FindNotificationDetails last_search_result_;
|
||||
|
||||
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
|
||||
// Used when the browser is hosting an extension.
|
||||
raw_ptr<extensions::ExtensionHost> extension_host_ = nullptr;
|
||||
bool is_background_host_ = false;
|
||||
#endif
|
||||
|
||||
// Used with auto-resize.
|
||||
bool auto_resize_enabled_ = false;
|
||||
gfx::Size auto_resize_min_;
|
||||
|
@@ -1,468 +0,0 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
||||
// Portions (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/chrome_browser_process_alloy.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/path_service.h"
|
||||
#include "cef/libcef/browser/alloy/chrome_profile_manager_alloy.h"
|
||||
#include "cef/libcef/browser/browser_context.h"
|
||||
#include "cef/libcef/browser/context.h"
|
||||
#include "cef/libcef/browser/extensions/extensions_browser_client.h"
|
||||
#include "cef/libcef/browser/prefs/browser_prefs.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/cef_switches.h"
|
||||
#include "cef/libcef/common/extensions/extensions_client.h"
|
||||
#include "cef/libcef/common/extensions/extensions_util.h"
|
||||
#include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
|
||||
#include "chrome/browser/net/system_network_context_manager.h"
|
||||
#include "chrome/browser/permissions/chrome_permissions_client.h"
|
||||
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
|
||||
#include "chrome/browser/printing/background_printing_manager.h"
|
||||
#include "chrome/browser/printing/print_job_manager.h"
|
||||
#include "chrome/browser/printing/print_preview_dialog_controller.h"
|
||||
#include "chrome/browser/ui/prefs/pref_watcher.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "components/component_updater/component_updater_service.h"
|
||||
#include "components/component_updater/timer_update_scheduler.h"
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "components/os_crypt/async/browser/os_crypt_async.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/browser/startup_helper.h"
|
||||
#include "content/public/browser/network_service_instance.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "net/log/net_log_capture_mode.h"
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include "components/os_crypt/async/browser/dpapi_key_provider.h"
|
||||
#endif
|
||||
|
||||
ChromeBrowserProcessAlloy::ChromeBrowserProcessAlloy() : locale_("en-US") {}
|
||||
|
||||
ChromeBrowserProcessAlloy::~ChromeBrowserProcessAlloy() {
|
||||
DCHECK((!initialized_ && !context_initialized_) || shutdown_);
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
extensions::ExtensionsBrowserClient::Set(nullptr);
|
||||
extensions_browser_client_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::Initialize() {
|
||||
DCHECK(!initialized_);
|
||||
DCHECK(!context_initialized_);
|
||||
DCHECK(!shutdown_);
|
||||
DCHECK(!field_trial_list_);
|
||||
|
||||
// Initialize this early before any code tries to check feature flags.
|
||||
field_trial_list_ = content::SetUpFieldTrialsAndFeatureList();
|
||||
|
||||
if (extensions::ExtensionsEnabled()) {
|
||||
// Initialize extension global objects before creating the global
|
||||
// BrowserContext.
|
||||
extensions_client_ = std::make_unique<extensions::CefExtensionsClient>();
|
||||
extensions::ExtensionsClient::Set(extensions_client_.get());
|
||||
extensions_browser_client_ =
|
||||
std::make_unique<extensions::CefExtensionsBrowserClient>();
|
||||
extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
|
||||
}
|
||||
|
||||
// Make sure permissions client has been set.
|
||||
ChromePermissionsClient::GetInstance();
|
||||
|
||||
initialized_ = true;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::OnContextInitialized() {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(initialized_);
|
||||
DCHECK(!context_initialized_);
|
||||
DCHECK(!shutdown_);
|
||||
|
||||
// OSCryptAsync provider configuration. If empty, this delegates all
|
||||
// encryption operations to OSCrypt.
|
||||
std::vector<std::pair<size_t, std::unique_ptr<os_crypt_async::KeyProvider>>>
|
||||
providers;
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// The DPAPI key provider requires OSCrypt::Init to have already been called
|
||||
// to initialize the key storage. This happens in
|
||||
// AlloyBrowserMainParts::PreCreateMainMessageLoop.
|
||||
providers.emplace_back(std::make_pair(
|
||||
/*precedence=*/10u,
|
||||
std::make_unique<os_crypt_async::DPAPIKeyProvider>(local_state())));
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
os_crypt_async_ =
|
||||
std::make_unique<os_crypt_async::OSCryptAsync>(std::move(providers));
|
||||
|
||||
// Trigger async initialization of OSCrypt key providers.
|
||||
std::ignore = os_crypt_async_->GetInstance(base::DoNothing());
|
||||
|
||||
// Must be created after the NotificationService.
|
||||
print_job_manager_ = std::make_unique<printing::PrintJobManager>();
|
||||
profile_manager_ = std::make_unique<ChromeProfileManagerAlloy>();
|
||||
event_router_forwarder_ = new extensions::EventRouterForwarder();
|
||||
context_initialized_ = true;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(initialized_);
|
||||
DCHECK(context_initialized_);
|
||||
DCHECK(!shutdown_);
|
||||
|
||||
// Wait for the pending print jobs to finish. Don't do this later, since
|
||||
// this might cause a nested message loop to run, and we don't want pending
|
||||
// tasks to run once teardown has started.
|
||||
print_job_manager_->Shutdown();
|
||||
print_job_manager_.reset(nullptr);
|
||||
print_preview_dialog_controller_ = nullptr;
|
||||
|
||||
profile_manager_.reset();
|
||||
event_router_forwarder_ = nullptr;
|
||||
|
||||
if (SystemNetworkContextManager::GetInstance()) {
|
||||
SystemNetworkContextManager::DeleteInstance();
|
||||
}
|
||||
|
||||
// Release any references held by objects associated with a Profile. The
|
||||
// Profile will be deleted later.
|
||||
for (const auto& browser_context : CefBrowserContext::GetAll()) {
|
||||
// Release any references to |local_state_|.
|
||||
auto profile = browser_context->AsProfile();
|
||||
PrefWatcher* pref_watcher = PrefWatcher::Get(profile);
|
||||
if (pref_watcher) {
|
||||
pref_watcher->Shutdown();
|
||||
}
|
||||
|
||||
// Unregister observers for |background_printing_manager_|.
|
||||
if (background_printing_manager_) {
|
||||
background_printing_manager_->DeletePreviewContentsForBrowserContext(
|
||||
profile);
|
||||
}
|
||||
}
|
||||
|
||||
os_crypt_async_.reset();
|
||||
local_state_.reset();
|
||||
browser_policy_connector_.reset();
|
||||
background_printing_manager_.reset();
|
||||
field_trial_list_.reset();
|
||||
component_updater_.reset();
|
||||
|
||||
shutdown_ = true;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::EndSession() {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::FlushLocalStateAndReply(
|
||||
base::OnceClosure reply) {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
metrics_services_manager::MetricsServicesManager*
|
||||
ChromeBrowserProcessAlloy::GetMetricsServicesManager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
metrics::MetricsService* ChromeBrowserProcessAlloy::metrics_service() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SystemNetworkContextManager*
|
||||
ChromeBrowserProcessAlloy::system_network_context_manager() {
|
||||
DCHECK(SystemNetworkContextManager::GetInstance());
|
||||
return SystemNetworkContextManager::GetInstance();
|
||||
}
|
||||
|
||||
network::NetworkQualityTracker*
|
||||
ChromeBrowserProcessAlloy::network_quality_tracker() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
embedder_support::OriginTrialsSettingsStorage*
|
||||
ChromeBrowserProcessAlloy::GetOriginTrialsSettingsStorage() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ProfileManager* ChromeBrowserProcessAlloy::profile_manager() {
|
||||
DCHECK(context_initialized_);
|
||||
return profile_manager_.get();
|
||||
}
|
||||
|
||||
PrefService* ChromeBrowserProcessAlloy::local_state() {
|
||||
DCHECK(initialized_);
|
||||
if (!local_state_) {
|
||||
base::FilePath user_data_path;
|
||||
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_path);
|
||||
DCHECK(!user_data_path.empty());
|
||||
|
||||
// Used for very early NetworkService initialization.
|
||||
// Always persist preferences for this PrefService if possible because it
|
||||
// contains the cookie encryption key on Windows.
|
||||
local_state_ =
|
||||
browser_prefs::CreatePrefService(nullptr /* profile */, user_data_path,
|
||||
true /* persist_user_preferences */);
|
||||
}
|
||||
return local_state_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<network::SharedURLLoaderFactory>
|
||||
ChromeBrowserProcessAlloy::shared_url_loader_factory() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
variations::VariationsService* ChromeBrowserProcessAlloy::variations_service() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BrowserProcessPlatformPart* ChromeBrowserProcessAlloy::platform_part() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extensions::EventRouterForwarder*
|
||||
ChromeBrowserProcessAlloy::extension_event_router_forwarder() {
|
||||
DCHECK(context_initialized_);
|
||||
return event_router_forwarder_.get();
|
||||
}
|
||||
|
||||
NotificationUIManager* ChromeBrowserProcessAlloy::notification_ui_manager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NotificationPlatformBridge*
|
||||
ChromeBrowserProcessAlloy::notification_platform_bridge() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
policy::ChromeBrowserPolicyConnector*
|
||||
ChromeBrowserProcessAlloy::browser_policy_connector() {
|
||||
if (!browser_policy_connector_) {
|
||||
browser_policy_connector_ =
|
||||
std::make_unique<policy::ChromeBrowserPolicyConnector>();
|
||||
}
|
||||
return browser_policy_connector_.get();
|
||||
}
|
||||
|
||||
policy::PolicyService* ChromeBrowserProcessAlloy::policy_service() {
|
||||
return browser_policy_connector()->GetPolicyService();
|
||||
}
|
||||
|
||||
IconManager* ChromeBrowserProcessAlloy::icon_manager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GpuModeManager* ChromeBrowserProcessAlloy::gpu_mode_manager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::CreateDevToolsProtocolHandler() {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::CreateDevToolsAutoOpener() {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
bool ChromeBrowserProcessAlloy::IsShuttingDown() {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
printing::PrintJobManager* ChromeBrowserProcessAlloy::print_job_manager() {
|
||||
DCHECK(context_initialized_);
|
||||
return print_job_manager_.get();
|
||||
}
|
||||
|
||||
printing::PrintPreviewDialogController*
|
||||
ChromeBrowserProcessAlloy::print_preview_dialog_controller() {
|
||||
if (!print_preview_dialog_controller_) {
|
||||
print_preview_dialog_controller_ =
|
||||
std::make_unique<printing::PrintPreviewDialogController>();
|
||||
}
|
||||
return print_preview_dialog_controller_.get();
|
||||
}
|
||||
|
||||
printing::BackgroundPrintingManager*
|
||||
ChromeBrowserProcessAlloy::background_printing_manager() {
|
||||
if (!background_printing_manager_.get()) {
|
||||
background_printing_manager_ =
|
||||
std::make_unique<printing::BackgroundPrintingManager>();
|
||||
}
|
||||
return background_printing_manager_.get();
|
||||
}
|
||||
|
||||
IntranetRedirectDetector*
|
||||
ChromeBrowserProcessAlloy::intranet_redirect_detector() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::string& ChromeBrowserProcessAlloy::GetApplicationLocale() {
|
||||
DCHECK(!locale_.empty());
|
||||
return locale_;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::SetApplicationLocale(
|
||||
const std::string& locale) {
|
||||
locale_ = locale;
|
||||
}
|
||||
|
||||
DownloadStatusUpdater* ChromeBrowserProcessAlloy::download_status_updater() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DownloadRequestLimiter* ChromeBrowserProcessAlloy::download_request_limiter() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
|
||||
BackgroundModeManager* ChromeBrowserProcessAlloy::background_mode_manager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::set_background_mode_manager_for_test(
|
||||
std::unique_ptr<BackgroundModeManager> manager) {
|
||||
DCHECK(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
StatusTray* ChromeBrowserProcessAlloy::status_tray() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
safe_browsing::SafeBrowsingService*
|
||||
ChromeBrowserProcessAlloy::safe_browsing_service() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
subresource_filter::RulesetService*
|
||||
ChromeBrowserProcessAlloy::subresource_filter_ruleset_service() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
subresource_filter::RulesetService*
|
||||
ChromeBrowserProcessAlloy::fingerprinting_protection_ruleset_service() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StartupData* ChromeBrowserProcessAlloy::startup_data() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
void ChromeBrowserProcessAlloy::StartAutoupdateTimer() {}
|
||||
#endif
|
||||
|
||||
component_updater::ComponentUpdateService*
|
||||
ChromeBrowserProcessAlloy::component_updater() {
|
||||
if (component_updater_) {
|
||||
return component_updater_.get();
|
||||
}
|
||||
|
||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<component_updater::UpdateScheduler> scheduler =
|
||||
std::make_unique<component_updater::TimerUpdateScheduler>();
|
||||
|
||||
component_updater_ = component_updater::ComponentUpdateServiceFactory(
|
||||
component_updater::MakeChromeComponentUpdaterConfigurator(
|
||||
base::CommandLine::ForCurrentProcess(),
|
||||
g_browser_process->local_state()),
|
||||
std::move(scheduler), /*brand=*/std::string());
|
||||
|
||||
return component_updater_.get();
|
||||
}
|
||||
|
||||
MediaFileSystemRegistry*
|
||||
ChromeBrowserProcessAlloy::media_file_system_registry() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WebRtcLogUploader* ChromeBrowserProcessAlloy::webrtc_log_uploader() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
network_time::NetworkTimeTracker*
|
||||
ChromeBrowserProcessAlloy::network_time_tracker() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gcm::GCMDriver* ChromeBrowserProcessAlloy::gcm_driver() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
resource_coordinator::TabManager* ChromeBrowserProcessAlloy::GetTabManager() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
resource_coordinator::ResourceCoordinatorParts*
|
||||
ChromeBrowserProcessAlloy::resource_coordinator_parts() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
os_crypt_async::OSCryptAsync* ChromeBrowserProcessAlloy::os_crypt_async() {
|
||||
DCHECK(os_crypt_async_);
|
||||
return os_crypt_async_.get();
|
||||
}
|
||||
|
||||
void ChromeBrowserProcessAlloy::set_additional_os_crypt_async_provider_for_test(
|
||||
size_t precedence,
|
||||
std::unique_ptr<os_crypt_async::KeyProvider> provider) {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
BuildState* ChromeBrowserProcessAlloy::GetBuildState() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SerialPolicyAllowedPorts*
|
||||
ChromeBrowserProcessAlloy::serial_policy_allowed_ports() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HidSystemTrayIcon* ChromeBrowserProcessAlloy::hid_system_tray_icon() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UsbSystemTrayIcon* ChromeBrowserProcessAlloy::usb_system_tray_icon() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
@@ -1,149 +0,0 @@
|
||||
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
|
||||
// Portions (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file provides a stub implementation of Chrome's BrowserProcess object
|
||||
// for use as an interop layer between CEF and files that live in chrome/.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_CHROME_BROWSER_PROCESS_ALLOY_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_CHROME_BROWSER_PROCESS_ALLOY_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/metrics/field_trial.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/extensions/event_router_forwarder.h"
|
||||
#include "media/media_buildflags.h"
|
||||
|
||||
namespace extensions {
|
||||
class ExtensionsBrowserClient;
|
||||
class ExtensionsClient;
|
||||
} // namespace extensions
|
||||
|
||||
class ChromeProfileManagerAlloy;
|
||||
|
||||
class BackgroundModeManager {
|
||||
public:
|
||||
BackgroundModeManager();
|
||||
|
||||
BackgroundModeManager(const BackgroundModeManager&) = delete;
|
||||
BackgroundModeManager& operator=(const BackgroundModeManager&) = delete;
|
||||
|
||||
virtual ~BackgroundModeManager();
|
||||
};
|
||||
|
||||
class ChromeBrowserProcessAlloy : public BrowserProcess {
|
||||
public:
|
||||
ChromeBrowserProcessAlloy();
|
||||
|
||||
ChromeBrowserProcessAlloy(const ChromeBrowserProcessAlloy&) = delete;
|
||||
ChromeBrowserProcessAlloy& operator=(const ChromeBrowserProcessAlloy&) =
|
||||
delete;
|
||||
|
||||
~ChromeBrowserProcessAlloy() override;
|
||||
|
||||
void Initialize();
|
||||
void OnContextInitialized();
|
||||
void CleanupOnUIThread();
|
||||
|
||||
// BrowserProcess implementation.
|
||||
void EndSession() override;
|
||||
void FlushLocalStateAndReply(base::OnceClosure reply) override;
|
||||
metrics_services_manager::MetricsServicesManager* GetMetricsServicesManager()
|
||||
override;
|
||||
metrics::MetricsService* metrics_service() override;
|
||||
SystemNetworkContextManager* system_network_context_manager() override;
|
||||
network::NetworkQualityTracker* network_quality_tracker() override;
|
||||
embedder_support::OriginTrialsSettingsStorage*
|
||||
GetOriginTrialsSettingsStorage() override;
|
||||
ProfileManager* profile_manager() override;
|
||||
PrefService* local_state() override;
|
||||
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory()
|
||||
override;
|
||||
variations::VariationsService* variations_service() override;
|
||||
BrowserProcessPlatformPart* platform_part() override;
|
||||
extensions::EventRouterForwarder* extension_event_router_forwarder() override;
|
||||
NotificationUIManager* notification_ui_manager() override;
|
||||
NotificationPlatformBridge* notification_platform_bridge() override;
|
||||
policy::ChromeBrowserPolicyConnector* browser_policy_connector() override;
|
||||
policy::PolicyService* policy_service() override;
|
||||
IconManager* icon_manager() override;
|
||||
GpuModeManager* gpu_mode_manager() override;
|
||||
void CreateDevToolsProtocolHandler() override;
|
||||
void CreateDevToolsAutoOpener() override;
|
||||
bool IsShuttingDown() override;
|
||||
printing::PrintJobManager* print_job_manager() override;
|
||||
printing::PrintPreviewDialogController* print_preview_dialog_controller()
|
||||
override;
|
||||
printing::BackgroundPrintingManager* background_printing_manager() override;
|
||||
IntranetRedirectDetector* intranet_redirect_detector() override;
|
||||
const std::string& GetApplicationLocale() override;
|
||||
void SetApplicationLocale(const std::string& locale) override;
|
||||
DownloadStatusUpdater* download_status_updater() override;
|
||||
DownloadRequestLimiter* download_request_limiter() override;
|
||||
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
|
||||
BackgroundModeManager* background_mode_manager() override;
|
||||
void set_background_mode_manager_for_test(
|
||||
std::unique_ptr<BackgroundModeManager> manager) override;
|
||||
#endif
|
||||
StatusTray* status_tray() override;
|
||||
safe_browsing::SafeBrowsingService* safe_browsing_service() override;
|
||||
subresource_filter::RulesetService* subresource_filter_ruleset_service()
|
||||
override;
|
||||
subresource_filter::RulesetService*
|
||||
fingerprinting_protection_ruleset_service() override;
|
||||
StartupData* startup_data() override;
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
void StartAutoupdateTimer() override;
|
||||
#endif
|
||||
|
||||
component_updater::ComponentUpdateService* component_updater() override;
|
||||
MediaFileSystemRegistry* media_file_system_registry() override;
|
||||
WebRtcLogUploader* webrtc_log_uploader() override;
|
||||
network_time::NetworkTimeTracker* network_time_tracker() override;
|
||||
gcm::GCMDriver* gcm_driver() override;
|
||||
resource_coordinator::TabManager* GetTabManager() override;
|
||||
resource_coordinator::ResourceCoordinatorParts* resource_coordinator_parts()
|
||||
override;
|
||||
os_crypt_async::OSCryptAsync* os_crypt_async() override;
|
||||
void set_additional_os_crypt_async_provider_for_test(
|
||||
size_t precedence,
|
||||
std::unique_ptr<os_crypt_async::KeyProvider> provider) override;
|
||||
BuildState* GetBuildState() override;
|
||||
SerialPolicyAllowedPorts* serial_policy_allowed_ports() override;
|
||||
HidSystemTrayIcon* hid_system_tray_icon() override;
|
||||
UsbSystemTrayIcon* usb_system_tray_icon() override;
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
bool context_initialized_ = false;
|
||||
bool shutdown_ = false;
|
||||
|
||||
std::unique_ptr<extensions::ExtensionsClient> extensions_client_;
|
||||
std::unique_ptr<extensions::ExtensionsBrowserClient>
|
||||
extensions_browser_client_;
|
||||
|
||||
std::string locale_;
|
||||
std::unique_ptr<printing::PrintJobManager> print_job_manager_;
|
||||
std::unique_ptr<ChromeProfileManagerAlloy> profile_manager_;
|
||||
scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_;
|
||||
std::unique_ptr<printing::PrintPreviewDialogController>
|
||||
print_preview_dialog_controller_;
|
||||
std::unique_ptr<printing::BackgroundPrintingManager>
|
||||
background_printing_manager_;
|
||||
std::unique_ptr<PrefService> local_state_;
|
||||
|
||||
// Must be destroyed after |local_state_|.
|
||||
std::unique_ptr<policy::ChromeBrowserPolicyConnector>
|
||||
browser_policy_connector_;
|
||||
std::unique_ptr<base::FieldTrialList> field_trial_list_;
|
||||
|
||||
std::unique_ptr<component_updater::ComponentUpdateService> component_updater_;
|
||||
|
||||
std::unique_ptr<os_crypt_async::OSCryptAsync> os_crypt_async_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_CHROME_BROWSER_PROCESS_ALLOY_H_
|
@@ -1,156 +0,0 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/chrome_profile_alloy.h"
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "components/profile_metrics/browser_profile_type.h"
|
||||
#include "components/variations/variations_client.h"
|
||||
#include "components/variations/variations_ids_provider.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class CefVariationsClient : public variations::VariationsClient {
|
||||
public:
|
||||
explicit CefVariationsClient(content::BrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {}
|
||||
|
||||
~CefVariationsClient() override = default;
|
||||
|
||||
bool IsOffTheRecord() const override {
|
||||
return browser_context_->IsOffTheRecord();
|
||||
}
|
||||
|
||||
variations::mojom::VariationsHeadersPtr GetVariationsHeaders()
|
||||
const override {
|
||||
return variations::VariationsIdsProvider::GetInstance()
|
||||
->GetClientDataHeaders(false /* is_signed_in */);
|
||||
}
|
||||
|
||||
private:
|
||||
raw_ptr<content::BrowserContext> browser_context_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ChromeProfileAlloy::ChromeProfileAlloy() : Profile(nullptr) {
|
||||
// Alloy contexts are never flagged as off-the-record. It causes problems
|
||||
// for the extension system.
|
||||
DCHECK(!IsOffTheRecord());
|
||||
|
||||
profile_metrics::SetBrowserProfileType(
|
||||
this, profile_metrics::BrowserProfileType::kRegular);
|
||||
}
|
||||
|
||||
ChromeProfileAlloy::~ChromeProfileAlloy() = default;
|
||||
|
||||
variations::VariationsClient* ChromeProfileAlloy::GetVariationsClient() {
|
||||
if (!variations_client_) {
|
||||
variations_client_ = std::make_unique<CefVariationsClient>(this);
|
||||
}
|
||||
return variations_client_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<base::SequencedTaskRunner> ChromeProfileAlloy::GetIOTaskRunner() {
|
||||
DCHECK(false);
|
||||
return scoped_refptr<base::SequencedTaskRunner>();
|
||||
}
|
||||
|
||||
std::string ChromeProfileAlloy::GetProfileUserName() const {
|
||||
DCHECK(false);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Profile* ChromeProfileAlloy::GetOffTheRecordProfile(
|
||||
const Profile::OTRProfileID& otr_profile_id,
|
||||
bool create_if_needed) {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<Profile*> ChromeProfileAlloy::GetAllOffTheRecordProfiles() {
|
||||
return {};
|
||||
}
|
||||
|
||||
void ChromeProfileAlloy::DestroyOffTheRecordProfile(Profile* otr_profile) {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::HasOffTheRecordProfile(
|
||||
const Profile::OTRProfileID& otr_profile_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::HasAnyOffTheRecordProfile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
Profile* ChromeProfileAlloy::GetOriginalProfile() {
|
||||
return this;
|
||||
}
|
||||
|
||||
const Profile* ChromeProfileAlloy::GetOriginalProfile() const {
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::IsChild() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExtensionSpecialStoragePolicy*
|
||||
ChromeProfileAlloy::GetExtensionSpecialStoragePolicy() {
|
||||
DCHECK(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::IsSameOrParent(Profile* profile) {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
base::Time ChromeProfileAlloy::GetStartTime() const {
|
||||
DCHECK(false);
|
||||
return base::Time();
|
||||
}
|
||||
|
||||
base::FilePath ChromeProfileAlloy::last_selected_directory() {
|
||||
return last_selected_directory_;
|
||||
}
|
||||
|
||||
void ChromeProfileAlloy::set_last_selected_directory(
|
||||
const base::FilePath& path) {
|
||||
last_selected_directory_ = path;
|
||||
}
|
||||
|
||||
GURL ChromeProfileAlloy::GetHomePage() {
|
||||
DCHECK(false);
|
||||
return GURL();
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::WasCreatedByVersionOrLater(
|
||||
const std::string& version) {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
base::Time ChromeProfileAlloy::GetCreationTime() const {
|
||||
DCHECK(false);
|
||||
return base::Time();
|
||||
}
|
||||
|
||||
void ChromeProfileAlloy::SetCreationTimeForTesting(base::Time creation_time) {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
void ChromeProfileAlloy::RecordPrimaryMainFrameNavigation() {
|
||||
DCHECK(false);
|
||||
}
|
||||
|
||||
bool ChromeProfileAlloy::IsSignedIn() {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This class gathers state related to a single user profile.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_ALLOY_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_ALLOY_H_
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
|
||||
// This file provides a stub implementation of Chrome's Profile object for use
|
||||
// as an interop layer between CEF and files that live in chrome/.
|
||||
|
||||
class ChromeProfileAlloy : public Profile {
|
||||
public:
|
||||
ChromeProfileAlloy();
|
||||
|
||||
ChromeProfileAlloy(const ChromeProfileAlloy&) = delete;
|
||||
ChromeProfileAlloy& operator=(const ChromeProfileAlloy&) = delete;
|
||||
|
||||
~ChromeProfileAlloy() override;
|
||||
|
||||
protected:
|
||||
// Profile methods.
|
||||
variations::VariationsClient* GetVariationsClient() override;
|
||||
scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
|
||||
std::string GetProfileUserName() const override;
|
||||
Profile* GetOffTheRecordProfile(const Profile::OTRProfileID& otr_profile_id,
|
||||
bool create_if_needed) override;
|
||||
std::vector<Profile*> GetAllOffTheRecordProfiles() override;
|
||||
void DestroyOffTheRecordProfile(Profile* otr_profile) override;
|
||||
bool HasOffTheRecordProfile(
|
||||
const Profile::OTRProfileID& otr_profile_id) override;
|
||||
bool HasAnyOffTheRecordProfile() override;
|
||||
Profile* GetOriginalProfile() override;
|
||||
const Profile* GetOriginalProfile() const override;
|
||||
bool IsChild() const override;
|
||||
ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() override;
|
||||
bool IsSameOrParent(Profile* profile) override;
|
||||
base::Time GetStartTime() const override;
|
||||
base::FilePath last_selected_directory() override;
|
||||
void set_last_selected_directory(const base::FilePath& path) override;
|
||||
GURL GetHomePage() override;
|
||||
bool WasCreatedByVersionOrLater(const std::string& version) override;
|
||||
base::Time GetCreationTime() const override;
|
||||
void SetCreationTimeForTesting(base::Time creation_time) override;
|
||||
void RecordPrimaryMainFrameNavigation() override;
|
||||
bool IsSignedIn() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<variations::VariationsClient> variations_client_;
|
||||
base::FilePath last_selected_directory_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_ALLOY_H_
|
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) 2016 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/chrome_profile_manager_alloy.h"
|
||||
|
||||
#include "cef/libcef/browser/browser_context.h"
|
||||
#include "cef/libcef/browser/request_context_impl.h"
|
||||
#include "cef/libcef/common/app_manager.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Return the active browser context. This is primarily called from Chrome code
|
||||
// that handles WebUI views and wishes to associate the view's data with a
|
||||
// particular context (profile). Chrome stores multiple profiles in sub-
|
||||
// directories of |user_data_dir| and then uses ProfileManager to track which
|
||||
// profile (sub-directory name) was last active.
|
||||
//
|
||||
// TODO(cef): To most closely match Chrome behavior this should return the
|
||||
// context for the currently active browser (e.g. the browser with input focus).
|
||||
// Return the main context for now since we don't currently have a good way to
|
||||
// determine that.
|
||||
CefBrowserContext* GetActiveBrowserContext() {
|
||||
auto request_context = static_cast<CefRequestContextImpl*>(
|
||||
CefAppManager::Get()->GetGlobalRequestContext().get());
|
||||
return request_context->GetBrowserContext();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChromeProfileManagerAlloy::ChromeProfileManagerAlloy()
|
||||
: ProfileManager(base::FilePath()) {}
|
||||
|
||||
ChromeProfileManagerAlloy::~ChromeProfileManagerAlloy() = default;
|
||||
|
||||
Profile* ChromeProfileManagerAlloy::GetProfile(
|
||||
const base::FilePath& profile_dir) {
|
||||
CefBrowserContext* browser_context =
|
||||
CefBrowserContext::FromCachePath(profile_dir);
|
||||
if (!browser_context) {
|
||||
// ProfileManager makes assumptions about profile directory paths that do
|
||||
// not match CEF usage. For example, the default Chrome profile name is
|
||||
// "Default" so it will append that sub-directory name to an empty
|
||||
// |user_data_dir| value and then call this method. Use the active context
|
||||
// in cases such as this where we don't understand what ProfileManager is
|
||||
// asking for.
|
||||
browser_context = GetActiveBrowserContext();
|
||||
}
|
||||
return browser_context->AsProfile();
|
||||
}
|
||||
|
||||
bool ChromeProfileManagerAlloy::IsValidProfile(const void* profile) {
|
||||
if (!profile) {
|
||||
return false;
|
||||
}
|
||||
return !!CefBrowserContext::FromBrowserContext(
|
||||
static_cast<const content::BrowserContext*>(profile));
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2016 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This file provides a stub implementation of Chrome's ProfileManager object
|
||||
// for use as an interop layer between CEF and files that live in chrome/.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_MANAGER_ALLOY_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_MANAGER_ALLOY_H_
|
||||
|
||||
#include "chrome/browser/profiles/profile_manager.h"
|
||||
|
||||
class ChromeProfileManagerAlloy : public ProfileManager {
|
||||
public:
|
||||
ChromeProfileManagerAlloy();
|
||||
|
||||
ChromeProfileManagerAlloy(const ChromeProfileManagerAlloy&) = delete;
|
||||
ChromeProfileManagerAlloy& operator=(const ChromeProfileManagerAlloy&) =
|
||||
delete;
|
||||
|
||||
~ChromeProfileManagerAlloy() override;
|
||||
|
||||
Profile* GetProfile(const base::FilePath& profile_dir) override;
|
||||
bool IsValidProfile(const void* profile) override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_CHROME_PROFILE_MANAGER_ALLOY_H_
|
@@ -1,46 +0,0 @@
|
||||
// Copyright 2024 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/devtools/alloy_devtools_window_runner.h"
|
||||
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_frontend.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
|
||||
void AlloyDevToolsWindowRunner::ShowDevTools(
|
||||
CefBrowserHostBase* opener,
|
||||
std::unique_ptr<CefShowDevToolsParams> params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (devtools_frontend_) {
|
||||
if (!params->inspect_element_at_.IsEmpty()) {
|
||||
devtools_frontend_->InspectElementAt(params->inspect_element_at_.x,
|
||||
params->inspect_element_at_.y);
|
||||
}
|
||||
devtools_frontend_->Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
auto alloy_browser = AlloyBrowserHostImpl::FromBaseChecked(opener);
|
||||
devtools_frontend_ = CefDevToolsFrontend::Show(
|
||||
alloy_browser.get(), params->window_info_, params->client_,
|
||||
params->settings_, params->inspect_element_at_,
|
||||
base::BindOnce(&AlloyDevToolsWindowRunner::OnFrontEndDestroyed,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void AlloyDevToolsWindowRunner::CloseDevTools() {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (devtools_frontend_) {
|
||||
devtools_frontend_->Close();
|
||||
}
|
||||
}
|
||||
|
||||
bool AlloyDevToolsWindowRunner::HasDevTools() {
|
||||
CEF_REQUIRE_UIT();
|
||||
return !!devtools_frontend_;
|
||||
}
|
||||
|
||||
void AlloyDevToolsWindowRunner::OnFrontEndDestroyed() {
|
||||
CEF_REQUIRE_UIT();
|
||||
devtools_frontend_ = nullptr;
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
// Copyright 2024 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_ALLOY_DEVTOOLS_WINDOW_RUNNER_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_ALLOY_DEVTOOLS_WINDOW_RUNNER_H_
|
||||
#pragma once
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "cef/libcef/browser/devtools/devtools_window_runner.h"
|
||||
|
||||
class CefDevToolsFrontend;
|
||||
|
||||
// Creates and runs a DevTools window instance. Only accessed on the UI thread.
|
||||
class AlloyDevToolsWindowRunner : public CefDevToolsWindowRunner {
|
||||
public:
|
||||
AlloyDevToolsWindowRunner() = default;
|
||||
|
||||
AlloyDevToolsWindowRunner(const AlloyDevToolsWindowRunner&) = delete;
|
||||
AlloyDevToolsWindowRunner& operator=(const AlloyDevToolsWindowRunner&) =
|
||||
delete;
|
||||
|
||||
// CefDevToolsWindowRunner methods:
|
||||
void ShowDevTools(CefBrowserHostBase* opener,
|
||||
std::unique_ptr<CefShowDevToolsParams> params) override;
|
||||
void CloseDevTools() override;
|
||||
bool HasDevTools() override;
|
||||
|
||||
private:
|
||||
void OnFrontEndDestroyed();
|
||||
|
||||
// CefDevToolsFrontend will delete itself when the frontend WebContents is
|
||||
// destroyed.
|
||||
raw_ptr<CefDevToolsFrontend> devtools_frontend_ = nullptr;
|
||||
|
||||
base::WeakPtrFactory<AlloyDevToolsWindowRunner> weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_ALLOY_DEVTOOLS_WINDOW_RUNNER_H_
|
@@ -1,206 +0,0 @@
|
||||
// Copyright 2019 The Chromium Embedded Framework Authors. Portions copyright
|
||||
// 2013 The Chromium Authors. All rights reserved. Use of this source code is
|
||||
// governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_file_manager.h"
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/hash/md5.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/json/values_util.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "base/values.h"
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/scoped_user_pref_update.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace {
|
||||
|
||||
base::LazyInstance<base::FilePath>::Leaky g_last_save_path =
|
||||
LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
void WriteToFile(const base::FilePath& path, const std::string& content) {
|
||||
DCHECK(!path.empty());
|
||||
base::WriteFile(path, content.c_str(), content.length());
|
||||
}
|
||||
|
||||
void AppendToFile(const base::FilePath& path, const std::string& content) {
|
||||
DCHECK(!path.empty());
|
||||
base::AppendToFile(path, std::string_view(content));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefDevToolsFileManager::CefDevToolsFileManager(
|
||||
AlloyBrowserHostImpl* browser_impl,
|
||||
PrefService* prefs)
|
||||
: browser_impl_(browser_impl),
|
||||
prefs_(prefs),
|
||||
file_task_runner_(
|
||||
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})),
|
||||
weak_factory_(this) {}
|
||||
|
||||
void CefDevToolsFileManager::SaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as) {
|
||||
Save(url, content, save_as,
|
||||
base::BindOnce(&CefDevToolsFileManager::FileSavedAs,
|
||||
weak_factory_.GetWeakPtr(), url),
|
||||
base::BindOnce(&CefDevToolsFileManager::CanceledFileSaveAs,
|
||||
weak_factory_.GetWeakPtr(), url));
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::AppendToFile(const std::string& url,
|
||||
const std::string& content) {
|
||||
Append(url, content,
|
||||
base::BindOnce(&CefDevToolsFileManager::AppendedTo,
|
||||
weak_factory_.GetWeakPtr(), url));
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::Save(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as,
|
||||
SaveCallback saveCallback,
|
||||
CancelCallback cancelCallback) {
|
||||
auto it = saved_files_.find(url);
|
||||
if (it != saved_files_.end() && !save_as) {
|
||||
SaveAsFileSelected(url, content, std::move(saveCallback), it->second);
|
||||
return;
|
||||
}
|
||||
|
||||
const base::Value::Dict& file_map =
|
||||
prefs_->GetDict(prefs::kDevToolsEditedFiles);
|
||||
base::FilePath initial_path;
|
||||
|
||||
if (const base::Value* path_value = file_map.Find(base::MD5String(url))) {
|
||||
std::optional<base::FilePath> path = base::ValueToFilePath(*path_value);
|
||||
if (path) {
|
||||
initial_path = std::move(*path);
|
||||
}
|
||||
}
|
||||
|
||||
if (initial_path.empty()) {
|
||||
GURL gurl(url);
|
||||
std::string suggested_file_name =
|
||||
gurl.is_valid() ? gurl.ExtractFileName() : url;
|
||||
|
||||
if (suggested_file_name.length() > 64) {
|
||||
suggested_file_name = suggested_file_name.substr(0, 64);
|
||||
}
|
||||
|
||||
if (!g_last_save_path.Pointer()->empty()) {
|
||||
initial_path = g_last_save_path.Pointer()->DirName().AppendASCII(
|
||||
suggested_file_name);
|
||||
} else {
|
||||
// Use the temp directory. It may be an empty value.
|
||||
base::PathService::Get(base::DIR_TEMP, &initial_path);
|
||||
initial_path = initial_path.AppendASCII(suggested_file_name);
|
||||
}
|
||||
}
|
||||
|
||||
blink::mojom::FileChooserParams params;
|
||||
params.mode = blink::mojom::FileChooserParams::Mode::kSave;
|
||||
if (!initial_path.empty()) {
|
||||
params.default_file_name = initial_path;
|
||||
if (!initial_path.Extension().empty()) {
|
||||
params.accept_types.push_back(CefString(initial_path.Extension()));
|
||||
}
|
||||
}
|
||||
|
||||
browser_impl_->RunFileChooserForBrowser(
|
||||
params,
|
||||
base::BindOnce(&CefDevToolsFileManager::SaveAsDialogDismissed,
|
||||
weak_factory_.GetWeakPtr(), url, content,
|
||||
std::move(saveCallback), std::move(cancelCallback)));
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::SaveAsDialogDismissed(
|
||||
const std::string& url,
|
||||
const std::string& content,
|
||||
SaveCallback saveCallback,
|
||||
CancelCallback cancelCallback,
|
||||
const std::vector<base::FilePath>& file_paths) {
|
||||
if (file_paths.size() == 1) {
|
||||
SaveAsFileSelected(url, content, std::move(saveCallback), file_paths[0]);
|
||||
} else {
|
||||
std::move(cancelCallback).Run();
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::SaveAsFileSelected(const std::string& url,
|
||||
const std::string& content,
|
||||
SaveCallback callback,
|
||||
const base::FilePath& path) {
|
||||
*g_last_save_path.Pointer() = path;
|
||||
saved_files_[url] = path;
|
||||
|
||||
ScopedDictPrefUpdate update(prefs_, prefs::kDevToolsEditedFiles);
|
||||
update->Set(base::MD5String(url), base::FilePathToValue(path));
|
||||
std::string file_system_path = path.AsUTF8Unsafe();
|
||||
std::move(callback).Run(file_system_path);
|
||||
file_task_runner_->PostTask(FROM_HERE,
|
||||
base::BindOnce(&::WriteToFile, path, content));
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::FileSavedAs(const std::string& url,
|
||||
const std::string& file_system_path) {
|
||||
base::Value url_value(url);
|
||||
base::Value file_system_path_value(file_system_path);
|
||||
CallClientFunction("DevToolsAPI.savedURL", &url_value,
|
||||
&file_system_path_value, nullptr);
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::CanceledFileSaveAs(const std::string& url) {
|
||||
base::Value url_value(url);
|
||||
CallClientFunction("DevToolsAPI.canceledSaveURL", &url_value, nullptr,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::Append(const std::string& url,
|
||||
const std::string& content,
|
||||
AppendCallback callback) {
|
||||
auto it = saved_files_.find(url);
|
||||
if (it == saved_files_.end()) {
|
||||
return;
|
||||
}
|
||||
std::move(callback).Run();
|
||||
file_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&::AppendToFile, it->second, content));
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::AppendedTo(const std::string& url) {
|
||||
base::Value url_value(url);
|
||||
CallClientFunction("DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CefDevToolsFileManager::CallClientFunction(
|
||||
const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3) {
|
||||
std::string javascript = function_name + "(";
|
||||
if (arg1) {
|
||||
std::string json;
|
||||
base::JSONWriter::Write(*arg1, &json);
|
||||
javascript.append(json);
|
||||
if (arg2) {
|
||||
base::JSONWriter::Write(*arg2, &json);
|
||||
javascript.append(", ").append(json);
|
||||
if (arg3) {
|
||||
base::JSONWriter::Write(*arg3, &json);
|
||||
javascript.append(", ").append(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
javascript.append(");");
|
||||
browser_impl_->web_contents()->GetPrimaryMainFrame()->ExecuteJavaScript(
|
||||
base::UTF8ToUTF16(javascript), base::NullCallback());
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
// Copyright 2019 The Chromium Embedded Framework Authors. Portions copyright
|
||||
// 2013 The Chromium Authors. All rights reserved. Use of this source code is
|
||||
// governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
class SequencedTaskRunner;
|
||||
class Value;
|
||||
} // namespace base
|
||||
|
||||
class AlloyBrowserHostImpl;
|
||||
class PrefService;
|
||||
|
||||
// File management helper for DevTools.
|
||||
// Based on chrome/browser/devtools/devtools_ui_bindings.cc and
|
||||
// chrome/browser/devtools/devtools_file_helper.cc.
|
||||
class CefDevToolsFileManager {
|
||||
public:
|
||||
CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl,
|
||||
PrefService* prefs);
|
||||
|
||||
CefDevToolsFileManager(const CefDevToolsFileManager&) = delete;
|
||||
CefDevToolsFileManager& operator=(const CefDevToolsFileManager&) = delete;
|
||||
|
||||
void SaveToFile(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as);
|
||||
void AppendToFile(const std::string& url, const std::string& content);
|
||||
|
||||
private:
|
||||
// SaveToFile implementation:
|
||||
using SaveCallback = base::OnceCallback<void(const std::string&)>;
|
||||
using CancelCallback = base::OnceCallback<void()>;
|
||||
void Save(const std::string& url,
|
||||
const std::string& content,
|
||||
bool save_as,
|
||||
SaveCallback saveCallback,
|
||||
CancelCallback cancelCallback);
|
||||
void SaveAsDialogDismissed(const std::string& url,
|
||||
const std::string& content,
|
||||
SaveCallback saveCallback,
|
||||
CancelCallback cancelCallback,
|
||||
const std::vector<base::FilePath>& file_paths);
|
||||
void SaveAsFileSelected(const std::string& url,
|
||||
const std::string& content,
|
||||
SaveCallback callback,
|
||||
const base::FilePath& path);
|
||||
void FileSavedAs(const std::string& url, const std::string& file_system_path);
|
||||
void CanceledFileSaveAs(const std::string& url);
|
||||
|
||||
// AppendToFile implementation:
|
||||
using AppendCallback = base::OnceCallback<void(void)>;
|
||||
void Append(const std::string& url,
|
||||
const std::string& content,
|
||||
AppendCallback callback);
|
||||
void AppendedTo(const std::string& url);
|
||||
|
||||
void CallClientFunction(const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3);
|
||||
|
||||
// Guaranteed to outlive this object.
|
||||
raw_ptr<AlloyBrowserHostImpl> browser_impl_;
|
||||
raw_ptr<PrefService> prefs_;
|
||||
|
||||
using PathsMap = std::map<std::string, base::FilePath>;
|
||||
PathsMap saved_files_;
|
||||
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
|
||||
base::WeakPtrFactory<CefDevToolsFileManager> weak_factory_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FILE_MANAGER_H_
|
@@ -1,673 +0,0 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_frontend.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/json/string_escape.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/raw_ptr.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/uuid.h"
|
||||
#include "base/values.h"
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_manager_delegate.h"
|
||||
#include "cef/libcef/browser/browser_context.h"
|
||||
#include "cef/libcef/browser/net/devtools_scheme_handler.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/cef_switches.h"
|
||||
#include "cef/libcef/common/task_runner_manager.h"
|
||||
#include "cef/libcef/features/runtime_checks.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/scoped_user_pref_update.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/file_url_loader.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/shared_cors_origin_access_list.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/url_utils.h"
|
||||
#include "ipc/ipc_channel.h"
|
||||
#include "net/base/completion_once_callback.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/traffic_annotation/network_traffic_annotation.h"
|
||||
#include "services/network/public/cpp/simple_url_loader.h"
|
||||
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
|
||||
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||
#include "storage/browser/file_system/native_file_util.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include <windows.h>
|
||||
#elif BUILDFLAG(IS_POSIX)
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// This constant should be in sync with the constant in
|
||||
// chrome/browser/devtools/devtools_ui_bindings.cc.
|
||||
constexpr size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4;
|
||||
|
||||
constexpr int kMaxLogLineLength = 1024;
|
||||
|
||||
static std::string GetFrontendURL() {
|
||||
return base::StringPrintf("%s://%s/devtools_app.html",
|
||||
content::kChromeDevToolsScheme,
|
||||
scheme::kChromeDevToolsHost);
|
||||
}
|
||||
|
||||
base::Value::Dict BuildObjectForResponse(const net::HttpResponseHeaders* rh,
|
||||
bool success,
|
||||
int net_error) {
|
||||
base::Value::Dict response;
|
||||
int responseCode = 200;
|
||||
if (rh) {
|
||||
responseCode = rh->response_code();
|
||||
} else if (!success) {
|
||||
// In case of no headers, assume file:// URL and failed to load
|
||||
responseCode = 404;
|
||||
}
|
||||
response.Set("statusCode", responseCode);
|
||||
response.Set("netError", net_error);
|
||||
response.Set("netErrorName", net::ErrorToString(net_error));
|
||||
|
||||
base::Value::Dict headers;
|
||||
size_t iterator = 0;
|
||||
std::string name;
|
||||
std::string value;
|
||||
// TODO(caseq): this probably needs to handle duplicate header names
|
||||
// correctly by folding them.
|
||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) {
|
||||
headers.Set(name, value);
|
||||
}
|
||||
|
||||
response.Set("headers", std::move(headers));
|
||||
return response;
|
||||
}
|
||||
|
||||
void WriteTimestamp(std::stringstream& stream) {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
SYSTEMTIME local_time;
|
||||
GetLocalTime(&local_time);
|
||||
stream << std::setfill('0') << std::setw(2) << local_time.wMonth
|
||||
<< std::setw(2) << local_time.wDay << '/' << std::setw(2)
|
||||
<< local_time.wHour << std::setw(2) << local_time.wMinute
|
||||
<< std::setw(2) << local_time.wSecond << '.' << std::setw(3)
|
||||
<< local_time.wMilliseconds;
|
||||
#elif BUILDFLAG(IS_POSIX)
|
||||
timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
time_t t = tv.tv_sec;
|
||||
struct tm local_time;
|
||||
localtime_r(&t, &local_time);
|
||||
struct tm* tm_time = &local_time;
|
||||
stream << std::setfill('0') << std::setw(2) << 1 + tm_time->tm_mon
|
||||
<< std::setw(2) << tm_time->tm_mday << '/' << std::setw(2)
|
||||
<< tm_time->tm_hour << std::setw(2) << tm_time->tm_min << std::setw(2)
|
||||
<< tm_time->tm_sec << '.' << std::setw(6) << tv.tv_usec;
|
||||
#else
|
||||
#error Unsupported platform
|
||||
#endif
|
||||
}
|
||||
|
||||
void LogProtocolMessage(const base::FilePath& log_file,
|
||||
ProtocolMessageType type,
|
||||
std::string to_log) {
|
||||
// Track if logging has failed, in which case we don't keep trying.
|
||||
static bool log_error = false;
|
||||
if (log_error) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (storage::NativeFileUtil::EnsureFileExists(log_file, nullptr) !=
|
||||
base::File::FILE_OK) {
|
||||
LOG(ERROR) << "Failed to create file " << log_file.value();
|
||||
log_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string type_label;
|
||||
switch (type) {
|
||||
case ProtocolMessageType::METHOD:
|
||||
type_label = "METHOD";
|
||||
break;
|
||||
case ProtocolMessageType::RESULT:
|
||||
type_label = "RESULT";
|
||||
break;
|
||||
case ProtocolMessageType::EVENT:
|
||||
type_label = "EVENT";
|
||||
break;
|
||||
}
|
||||
|
||||
std::stringstream stream;
|
||||
WriteTimestamp(stream);
|
||||
stream << ": " << type_label << ": " << to_log << "\n";
|
||||
const std::string& str = stream.str();
|
||||
if (!base::AppendToFile(log_file, std::string_view(str))) {
|
||||
LOG(ERROR) << "Failed to write file " << log_file.value();
|
||||
log_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class CefDevToolsFrontend::NetworkResourceLoader
|
||||
: public network::SimpleURLLoaderStreamConsumer {
|
||||
public:
|
||||
NetworkResourceLoader(int stream_id,
|
||||
CefDevToolsFrontend* bindings,
|
||||
std::unique_ptr<network::SimpleURLLoader> loader,
|
||||
network::mojom::URLLoaderFactory* url_loader_factory,
|
||||
int request_id)
|
||||
: stream_id_(stream_id),
|
||||
bindings_(bindings),
|
||||
loader_(std::move(loader)),
|
||||
request_id_(request_id) {
|
||||
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
||||
&NetworkResourceLoader::OnResponseStarted, base::Unretained(this)));
|
||||
loader_->DownloadAsStream(url_loader_factory, this);
|
||||
}
|
||||
|
||||
NetworkResourceLoader(const NetworkResourceLoader&) = delete;
|
||||
NetworkResourceLoader& operator=(const NetworkResourceLoader&) = delete;
|
||||
|
||||
private:
|
||||
void OnResponseStarted(const GURL& final_url,
|
||||
const network::mojom::URLResponseHead& response_head) {
|
||||
response_headers_ = response_head.headers;
|
||||
}
|
||||
|
||||
void OnDataReceived(std::string_view chunk,
|
||||
base::OnceClosure resume) override {
|
||||
base::Value chunkValue;
|
||||
|
||||
bool encoded = !base::IsStringUTF8(chunk);
|
||||
if (encoded) {
|
||||
chunkValue = base::Value(base::Base64Encode(chunk));
|
||||
} else {
|
||||
chunkValue = base::Value(chunk);
|
||||
}
|
||||
base::Value id(stream_id_);
|
||||
base::Value encodedValue(encoded);
|
||||
|
||||
bindings_->CallClientFunction("DevToolsAPI", "streamWrite", std::move(id),
|
||||
std::move(chunkValue),
|
||||
std::move(encodedValue));
|
||||
std::move(resume).Run();
|
||||
}
|
||||
|
||||
void OnComplete(bool success) override {
|
||||
auto response = BuildObjectForResponse(response_headers_.get(), success,
|
||||
loader_->NetError());
|
||||
bindings_->SendMessageAck(request_id_, std::move(response));
|
||||
|
||||
bindings_->loaders_.erase(bindings_->loaders_.find(this));
|
||||
}
|
||||
|
||||
void OnRetry(base::OnceClosure start_retry) override { DCHECK(false); }
|
||||
|
||||
const int stream_id_;
|
||||
const raw_ptr<CefDevToolsFrontend> bindings_;
|
||||
std::unique_ptr<network::SimpleURLLoader> loader_;
|
||||
int request_id_;
|
||||
scoped_refptr<net::HttpResponseHeaders> response_headers_;
|
||||
};
|
||||
|
||||
// static
|
||||
CefDevToolsFrontend* CefDevToolsFrontend::Show(
|
||||
AlloyBrowserHostImpl* inspected_browser,
|
||||
const CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefBrowserSettings& settings,
|
||||
const CefPoint& inspect_element_at,
|
||||
base::OnceClosure frontend_destroyed_callback) {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
|
||||
CefBrowserSettings new_settings = settings;
|
||||
if (!windowInfo.windowless_rendering_enabled &&
|
||||
CefColorGetA(new_settings.background_color) != SK_AlphaOPAQUE) {
|
||||
// Use white as the default background color for windowed DevTools instead
|
||||
// of the CefSettings.background_color value.
|
||||
new_settings.background_color = SK_ColorWHITE;
|
||||
}
|
||||
|
||||
CefBrowserCreateParams create_params;
|
||||
create_params.MaybeSetWindowInfo(windowInfo, /*allow_alloy_style=*/true,
|
||||
/*allow_chrome_style=*/false);
|
||||
|
||||
if (inspected_browser->is_views_hosted()) {
|
||||
create_params.popup_with_views_hosted_opener = true;
|
||||
}
|
||||
create_params.popup_with_alloy_style_opener = true;
|
||||
|
||||
create_params.client = client;
|
||||
create_params.settings = new_settings;
|
||||
create_params.devtools_opener = inspected_browser;
|
||||
create_params.request_context = inspected_browser->GetRequestContext();
|
||||
create_params.extra_info = inspected_browser->browser_info()->extra_info();
|
||||
|
||||
CefRefPtr<AlloyBrowserHostImpl> frontend_browser =
|
||||
AlloyBrowserHostImpl::Create(create_params);
|
||||
|
||||
content::WebContents* inspected_contents = inspected_browser->web_contents();
|
||||
|
||||
// CefDevToolsFrontend will delete itself when the frontend WebContents is
|
||||
// destroyed.
|
||||
CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend(
|
||||
frontend_browser.get(), inspected_contents, inspect_element_at,
|
||||
std::move(frontend_destroyed_callback));
|
||||
|
||||
// Need to load the URL after creating the DevTools objects.
|
||||
frontend_browser->GetMainFrame()->LoadURL(GetFrontendURL());
|
||||
|
||||
return devtools_frontend;
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::Activate() {
|
||||
frontend_browser_->ActivateContents(web_contents());
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::Focus() {
|
||||
frontend_browser_->SetFocus(true);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::InspectElementAt(int x, int y) {
|
||||
if (inspect_element_at_.x != x || inspect_element_at_.y != y) {
|
||||
inspect_element_at_.Set(x, y);
|
||||
}
|
||||
if (agent_host_) {
|
||||
agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(), x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::Close() {
|
||||
CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::CloseBrowser,
|
||||
frontend_browser_.get(), true));
|
||||
}
|
||||
|
||||
CefDevToolsFrontend::CefDevToolsFrontend(
|
||||
AlloyBrowserHostImpl* frontend_browser,
|
||||
content::WebContents* inspected_contents,
|
||||
const CefPoint& inspect_element_at,
|
||||
base::OnceClosure frontend_destroyed_callback)
|
||||
: content::WebContentsObserver(frontend_browser->web_contents()),
|
||||
frontend_browser_(frontend_browser),
|
||||
inspected_contents_(inspected_contents),
|
||||
inspect_element_at_(inspect_element_at),
|
||||
frontend_destroyed_callback_(std::move(frontend_destroyed_callback)),
|
||||
file_manager_(frontend_browser, GetPrefs()),
|
||||
protocol_log_file_(
|
||||
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
||||
switches::kDevToolsProtocolLogFile)),
|
||||
weak_factory_(this) {
|
||||
DCHECK(!frontend_destroyed_callback_.is_null());
|
||||
}
|
||||
|
||||
CefDevToolsFrontend::~CefDevToolsFrontend() = default;
|
||||
|
||||
void CefDevToolsFrontend::ReadyToCommitNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
content::RenderFrameHost* frame = navigation_handle->GetRenderFrameHost();
|
||||
if (navigation_handle->IsInMainFrame()) {
|
||||
frontend_host_ = content::DevToolsFrontendHost::Create(
|
||||
frame, base::BindRepeating(
|
||||
&CefDevToolsFrontend::HandleMessageFromDevToolsFrontend,
|
||||
base::Unretained(this)));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string origin =
|
||||
navigation_handle->GetURL().DeprecatedGetOriginAsURL().spec();
|
||||
auto it = extensions_api_.find(origin);
|
||||
if (it == extensions_api_.end()) {
|
||||
return;
|
||||
}
|
||||
std::string script = base::StringPrintf(
|
||||
"%s(\"%s\")", it->second.c_str(),
|
||||
base::Uuid::GenerateRandomV4().AsLowercaseString().c_str());
|
||||
content::DevToolsFrontendHost::SetupExtensionsAPI(frame, script);
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::PrimaryMainDocumentElementAvailable() {
|
||||
// Don't call AttachClient multiple times for the same DevToolsAgentHost.
|
||||
// Otherwise it will call AgentHostClosed which closes the DevTools window.
|
||||
// This may happen in cases where the DevTools content fails to load.
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host =
|
||||
content::DevToolsAgentHost::GetOrCreateFor(inspected_contents_);
|
||||
if (agent_host != agent_host_) {
|
||||
if (agent_host_) {
|
||||
agent_host_->DetachClient(this);
|
||||
}
|
||||
agent_host_ = agent_host;
|
||||
agent_host_->AttachClient(this);
|
||||
if (!inspect_element_at_.IsEmpty()) {
|
||||
agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(),
|
||||
inspect_element_at_.x, inspect_element_at_.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::WebContentsDestroyed() {
|
||||
if (agent_host_) {
|
||||
agent_host_->DetachClient(this);
|
||||
agent_host_ = nullptr;
|
||||
}
|
||||
std::move(frontend_destroyed_callback_).Run();
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
||||
base::Value::Dict message) {
|
||||
const std::string* method = message.FindString("method");
|
||||
if (!method) {
|
||||
return;
|
||||
}
|
||||
|
||||
int request_id = message.FindInt("id").value_or(0);
|
||||
base::Value::List* params_value = message.FindList("params");
|
||||
|
||||
// Since we've received message by value, we can take the list.
|
||||
base::Value::List params;
|
||||
if (params_value) {
|
||||
params = std::move(*params_value);
|
||||
}
|
||||
|
||||
if (*method == "dispatchProtocolMessage") {
|
||||
if (params.size() < 1) {
|
||||
return;
|
||||
}
|
||||
const std::string* protocol_message = params[0].GetIfString();
|
||||
if (!agent_host_ || !protocol_message) {
|
||||
return;
|
||||
}
|
||||
if (ProtocolLoggingEnabled()) {
|
||||
LogProtocolMessage(ProtocolMessageType::METHOD, *protocol_message);
|
||||
}
|
||||
agent_host_->DispatchProtocolMessage(
|
||||
this, base::as_bytes(base::make_span(*protocol_message)));
|
||||
} else if (*method == "loadCompleted") {
|
||||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
|
||||
u"DevToolsAPI.setUseSoftMenu(true);", base::NullCallback());
|
||||
} else if (*method == "loadNetworkResource") {
|
||||
if (params.size() < 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(pfeldman): handle some of the embedder messages in content.
|
||||
const std::string* url = params[0].GetIfString();
|
||||
const std::string* headers = params[1].GetIfString();
|
||||
std::optional<const int> stream_id = params[2].GetIfInt();
|
||||
if (!url || !headers || !stream_id.has_value()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GURL gurl(*url);
|
||||
if (!gurl.is_valid()) {
|
||||
base::Value::Dict response;
|
||||
response.Set("statusCode", 404);
|
||||
response.Set("urlValid", false);
|
||||
SendMessageAck(request_id, std::move(response));
|
||||
return;
|
||||
}
|
||||
|
||||
net::NetworkTrafficAnnotationTag traffic_annotation =
|
||||
net::DefineNetworkTrafficAnnotation(
|
||||
"devtools_handle_front_end_messages", R"(
|
||||
semantics {
|
||||
sender: "Developer Tools"
|
||||
description:
|
||||
"When user opens Developer Tools, the browser may fetch "
|
||||
"additional resources from the network to enrich the debugging "
|
||||
"experience (e.g. source map resources)."
|
||||
trigger: "User opens Developer Tools to debug a web page."
|
||||
data: "Any resources requested by Developer Tools."
|
||||
destination: OTHER
|
||||
}
|
||||
policy {
|
||||
cookies_allowed: YES
|
||||
cookies_store: "user"
|
||||
setting:
|
||||
"It's not possible to disable this feature from settings."
|
||||
chrome_policy {
|
||||
DeveloperToolsAvailability {
|
||||
policy_options {mode: MANDATORY}
|
||||
DeveloperToolsAvailability: 2
|
||||
}
|
||||
}
|
||||
})");
|
||||
|
||||
// Based on DevToolsUIBindings::LoadNetworkResource.
|
||||
auto resource_request = std::make_unique<network::ResourceRequest>();
|
||||
resource_request->url = gurl;
|
||||
// TODO(caseq): this preserves behavior of URLFetcher-based
|
||||
// implementation. We really need to pass proper first party origin from
|
||||
// the front-end.
|
||||
resource_request->site_for_cookies = net::SiteForCookies::FromUrl(gurl);
|
||||
resource_request->headers.AddHeadersFromString(*headers);
|
||||
|
||||
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
|
||||
if (gurl.SchemeIsFile()) {
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote =
|
||||
content::CreateFileURLLoaderFactory(
|
||||
base::FilePath() /* profile_path */,
|
||||
nullptr /* shared_cors_origin_access_list */);
|
||||
url_loader_factory = network::SharedURLLoaderFactory::Create(
|
||||
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
|
||||
std::move(pending_remote)));
|
||||
} else if (content::HasWebUIScheme(gurl)) {
|
||||
base::Value::Dict response;
|
||||
response.Set("statusCode", 403);
|
||||
SendMessageAck(request_id, std::move(response));
|
||||
return;
|
||||
} else {
|
||||
auto* partition =
|
||||
inspected_contents_->GetPrimaryMainFrame()->GetStoragePartition();
|
||||
url_loader_factory = partition->GetURLLoaderFactoryForBrowserProcess();
|
||||
}
|
||||
|
||||
auto simple_url_loader = network::SimpleURLLoader::Create(
|
||||
std::move(resource_request), traffic_annotation);
|
||||
auto resource_loader = std::make_unique<NetworkResourceLoader>(
|
||||
*stream_id, this, std::move(simple_url_loader),
|
||||
url_loader_factory.get(), request_id);
|
||||
loaders_.insert(std::move(resource_loader));
|
||||
return;
|
||||
} else if (*method == "getHostConfig") {
|
||||
SendMessageAck(request_id, {});
|
||||
return;
|
||||
} else if (*method == "getPreferences") {
|
||||
SendMessageAck(request_id,
|
||||
GetPrefs()->GetDict(prefs::kDevToolsPreferences).Clone());
|
||||
return;
|
||||
} else if (*method == "setPreference") {
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* name = params[0].GetIfString();
|
||||
|
||||
// We're just setting params[1] as a value anyways, so just make sure it's
|
||||
// the type we want, but don't worry about getting it.
|
||||
if (!name || !params[1].is_string()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScopedDictPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
|
||||
update->Set(*name, std::move(params[1]));
|
||||
} else if (*method == "removePreference") {
|
||||
const std::string* name = params[0].GetIfString();
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
ScopedDictPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences);
|
||||
update->Remove(*name);
|
||||
} else if (*method == "requestFileSystems") {
|
||||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests(
|
||||
u"DevToolsAPI.fileSystemsLoaded([]);", base::NullCallback());
|
||||
} else if (*method == "reattach") {
|
||||
if (!agent_host_) {
|
||||
return;
|
||||
}
|
||||
agent_host_->DetachClient(this);
|
||||
agent_host_->AttachClient(this);
|
||||
} else if (*method == "registerExtensionsAPI") {
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* origin = params[0].GetIfString();
|
||||
const std::string* script = params[1].GetIfString();
|
||||
if (!origin || !script) {
|
||||
return;
|
||||
}
|
||||
extensions_api_[*origin + "/"] = *script;
|
||||
} else if (*method == "save") {
|
||||
if (params.size() < 3) {
|
||||
return;
|
||||
}
|
||||
const std::string* url = params[0].GetIfString();
|
||||
const std::string* content = params[1].GetIfString();
|
||||
std::optional<bool> save_as = params[2].GetIfBool();
|
||||
if (!url || !content || !save_as.has_value()) {
|
||||
return;
|
||||
}
|
||||
file_manager_.SaveToFile(*url, *content, *save_as);
|
||||
} else if (*method == "append") {
|
||||
if (params.size() < 2) {
|
||||
return;
|
||||
}
|
||||
const std::string* url = params[0].GetIfString();
|
||||
const std::string* content = params[1].GetIfString();
|
||||
if (!url || !content) {
|
||||
return;
|
||||
}
|
||||
file_manager_.AppendToFile(*url, *content);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (request_id) {
|
||||
SendMessageAck(request_id, base::Value::Dict());
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::DispatchProtocolMessage(
|
||||
content::DevToolsAgentHost* agent_host,
|
||||
base::span<const uint8_t> message) {
|
||||
if (!frontend_browser_->GetWebContents() ||
|
||||
frontend_browser_->GetWebContents()->IsBeingDestroyed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view str_message(reinterpret_cast<const char*>(message.data()),
|
||||
message.size());
|
||||
if (ProtocolLoggingEnabled()) {
|
||||
// Quick check to avoid parsing the JSON object. Events begin with a
|
||||
// "method" value whereas method results begin with an "id" value.
|
||||
LogProtocolMessage(base::StartsWith(str_message, "{\"method\":")
|
||||
? ProtocolMessageType::EVENT
|
||||
: ProtocolMessageType::RESULT,
|
||||
str_message);
|
||||
}
|
||||
|
||||
if (str_message.length() < kMaxMessageChunkSize) {
|
||||
CallClientFunction("DevToolsAPI", "dispatchMessage",
|
||||
base::Value(std::string(str_message)));
|
||||
} else {
|
||||
size_t total_size = str_message.length();
|
||||
for (size_t pos = 0; pos < str_message.length();
|
||||
pos += kMaxMessageChunkSize) {
|
||||
std::string_view str_message_chunk =
|
||||
str_message.substr(pos, kMaxMessageChunkSize);
|
||||
|
||||
CallClientFunction(
|
||||
"DevToolsAPI", "dispatchMessageChunk",
|
||||
base::Value(std::string(str_message_chunk)),
|
||||
base::Value(base::NumberToString(pos ? 0 : total_size)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::CallClientFunction(
|
||||
const std::string& object_name,
|
||||
const std::string& method_name,
|
||||
base::Value arg1,
|
||||
base::Value arg2,
|
||||
base::Value arg3,
|
||||
base::OnceCallback<void(base::Value)> cb) {
|
||||
std::string javascript;
|
||||
|
||||
web_contents()->GetPrimaryMainFrame()->AllowInjectingJavaScript();
|
||||
|
||||
base::Value::List arguments;
|
||||
if (!arg1.is_none()) {
|
||||
arguments.Append(std::move(arg1));
|
||||
if (!arg2.is_none()) {
|
||||
arguments.Append(std::move(arg2));
|
||||
if (!arg3.is_none()) {
|
||||
arguments.Append(std::move(arg3));
|
||||
}
|
||||
}
|
||||
}
|
||||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptMethod(
|
||||
base::ASCIIToUTF16(object_name), base::ASCIIToUTF16(method_name),
|
||||
std::move(arguments), std::move(cb));
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::SendMessageAck(int request_id,
|
||||
base::Value::Dict arg) {
|
||||
CallClientFunction("DevToolsAPI", "embedderMessageAck",
|
||||
base::Value(request_id), base::Value(std::move(arg)));
|
||||
}
|
||||
|
||||
bool CefDevToolsFrontend::ProtocolLoggingEnabled() const {
|
||||
return !protocol_log_file_.empty();
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::LogProtocolMessage(ProtocolMessageType type,
|
||||
const std::string_view& message) {
|
||||
DCHECK(ProtocolLoggingEnabled());
|
||||
|
||||
std::string to_log(message.substr(0, kMaxLogLineLength));
|
||||
|
||||
// Execute in an ordered context that allows blocking.
|
||||
auto task_runner = CefTaskRunnerManager::Get()->GetBackgroundTaskRunner();
|
||||
task_runner->PostTask(
|
||||
FROM_HERE, base::BindOnce(::LogProtocolMessage, protocol_log_file_, type,
|
||||
std::move(to_log)));
|
||||
}
|
||||
|
||||
void CefDevToolsFrontend::AgentHostClosed(
|
||||
content::DevToolsAgentHost* agent_host) {
|
||||
DCHECK(agent_host == agent_host_.get());
|
||||
agent_host_ = nullptr;
|
||||
Close();
|
||||
}
|
||||
|
||||
PrefService* CefDevToolsFrontend::GetPrefs() const {
|
||||
return CefBrowserContext::FromBrowserContext(
|
||||
frontend_browser_->web_contents()->GetBrowserContext())
|
||||
->AsProfile()
|
||||
->GetPrefs();
|
||||
}
|
@@ -1,114 +0,0 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FRONTEND_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FRONTEND_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/values.h"
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_file_manager.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_frontend_host.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
namespace base {
|
||||
class Value;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
class NavigationHandle;
|
||||
class RenderViewHost;
|
||||
class WebContents;
|
||||
} // namespace content
|
||||
|
||||
class PrefService;
|
||||
|
||||
enum class ProtocolMessageType {
|
||||
METHOD,
|
||||
RESULT,
|
||||
EVENT,
|
||||
};
|
||||
|
||||
class CefDevToolsFrontend : public content::WebContentsObserver,
|
||||
public content::DevToolsAgentHostClient {
|
||||
public:
|
||||
CefDevToolsFrontend(const CefDevToolsFrontend&) = delete;
|
||||
CefDevToolsFrontend& operator=(const CefDevToolsFrontend&) = delete;
|
||||
|
||||
static CefDevToolsFrontend* Show(
|
||||
AlloyBrowserHostImpl* inspected_browser,
|
||||
const CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient> client,
|
||||
const CefBrowserSettings& settings,
|
||||
const CefPoint& inspect_element_at,
|
||||
base::OnceClosure frontend_destroyed_callback);
|
||||
|
||||
void Activate();
|
||||
void Focus();
|
||||
void InspectElementAt(int x, int y);
|
||||
void Close();
|
||||
|
||||
void CallClientFunction(
|
||||
const std::string& object_name,
|
||||
const std::string& method_name,
|
||||
const base::Value arg1 = {},
|
||||
const base::Value arg2 = {},
|
||||
const base::Value arg3 = {},
|
||||
base::OnceCallback<void(base::Value)> cb = base::NullCallback());
|
||||
|
||||
private:
|
||||
CefDevToolsFrontend(AlloyBrowserHostImpl* frontend_browser,
|
||||
content::WebContents* inspected_contents,
|
||||
const CefPoint& inspect_element_at,
|
||||
base::OnceClosure destroyed_callback);
|
||||
~CefDevToolsFrontend() override;
|
||||
|
||||
// content::DevToolsAgentHostClient implementation.
|
||||
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
|
||||
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
||||
base::span<const uint8_t> message) override;
|
||||
void HandleMessageFromDevToolsFrontend(base::Value::Dict message);
|
||||
|
||||
private:
|
||||
// WebContentsObserver overrides
|
||||
void ReadyToCommitNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
void PrimaryMainDocumentElementAvailable() override;
|
||||
void WebContentsDestroyed() override;
|
||||
|
||||
void SendMessageAck(int request_id, base::Value::Dict arg);
|
||||
|
||||
bool ProtocolLoggingEnabled() const;
|
||||
void LogProtocolMessage(ProtocolMessageType type,
|
||||
const std::string_view& message);
|
||||
|
||||
PrefService* GetPrefs() const;
|
||||
|
||||
CefRefPtr<AlloyBrowserHostImpl> frontend_browser_;
|
||||
raw_ptr<content::WebContents> inspected_contents_;
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
CefPoint inspect_element_at_;
|
||||
base::OnceClosure frontend_destroyed_callback_;
|
||||
std::unique_ptr<content::DevToolsFrontendHost> frontend_host_;
|
||||
|
||||
class NetworkResourceLoader;
|
||||
std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
|
||||
loaders_;
|
||||
|
||||
using ExtensionsAPIs = std::map<std::string, std::string>;
|
||||
ExtensionsAPIs extensions_api_;
|
||||
CefDevToolsFileManager file_manager_;
|
||||
|
||||
const base::FilePath protocol_log_file_;
|
||||
|
||||
base::WeakPtrFactory<CefDevToolsFrontend> weak_factory_;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_FRONTEND_H_
|
@@ -1,148 +0,0 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/devtools/devtools_manager_delegate.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/atomicops.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cef/grit/cef_resources.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/devtools_frontend_host.h"
|
||||
#include "content/public/browser/devtools_socket_factory.h"
|
||||
#include "content/public/browser/favicon_status.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/log/net_log_source.h"
|
||||
#include "net/socket/tcp_server_socket.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const int kBackLog = 10;
|
||||
|
||||
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
||||
public:
|
||||
TCPServerSocketFactory(const std::string& address, uint16_t port)
|
||||
: address_(address), port_(port) {}
|
||||
|
||||
TCPServerSocketFactory(const TCPServerSocketFactory&) = delete;
|
||||
TCPServerSocketFactory& operator=(const TCPServerSocketFactory&) = delete;
|
||||
|
||||
private:
|
||||
// content::DevToolsSocketFactory.
|
||||
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
|
||||
std::unique_ptr<net::ServerSocket> socket(
|
||||
new net::TCPServerSocket(nullptr, net::NetLogSource()));
|
||||
if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) !=
|
||||
net::OK) {
|
||||
return std::unique_ptr<net::ServerSocket>();
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<net::ServerSocket> CreateForTethering(
|
||||
std::string* out_name) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string address_;
|
||||
uint16_t port_;
|
||||
};
|
||||
|
||||
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
// See if the user specified a port on the command line. Specifying 0 will
|
||||
// result in the selection of an ephemeral port and the port number will be
|
||||
// printed as part of the WebSocket endpoint URL to stderr. If a cache
|
||||
// directory path is provided the port will also be written to the
|
||||
// <cache-dir>/DevToolsActivePort file.
|
||||
//
|
||||
// It's not allowed to bind ports between 0 and 1024 exclusive because
|
||||
// they're normally restricted to root on Posix-based systems.
|
||||
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
|
||||
int port = 0;
|
||||
std::string port_str =
|
||||
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
||||
|
||||
if (base::StringToInt(port_str, &port) &&
|
||||
(0 == port || (port >= 1024 && port < 65535))) {
|
||||
return std::unique_ptr<content::DevToolsSocketFactory>(
|
||||
new TCPServerSocketFactory("127.0.0.1", port));
|
||||
} else {
|
||||
DLOG(WARNING) << "Invalid http debugger port number '" << port_str << "'";
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// CefDevToolsManagerDelegate ----------------------------------------------
|
||||
|
||||
// static
|
||||
void CefDevToolsManagerDelegate::StartHttpHandler(
|
||||
content::BrowserContext* browser_context) {
|
||||
std::unique_ptr<content::DevToolsSocketFactory> socket_factory =
|
||||
CreateSocketFactory();
|
||||
if (!socket_factory) {
|
||||
return;
|
||||
}
|
||||
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
||||
std::move(socket_factory), browser_context->GetPath(), base::FilePath());
|
||||
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
if (command_line.HasSwitch(switches::kRemoteDebuggingPipe)) {
|
||||
content::DevToolsAgentHost::StartRemoteDebuggingPipeHandler(
|
||||
base::OnceClosure());
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void CefDevToolsManagerDelegate::StopHttpHandler() {
|
||||
// This is a no-op if the server was never started.
|
||||
content::DevToolsAgentHost::StopRemoteDebuggingServer();
|
||||
}
|
||||
|
||||
CefDevToolsManagerDelegate::CefDevToolsManagerDelegate() = default;
|
||||
|
||||
CefDevToolsManagerDelegate::~CefDevToolsManagerDelegate() = default;
|
||||
|
||||
scoped_refptr<content::DevToolsAgentHost>
|
||||
CefDevToolsManagerDelegate::CreateNewTarget(
|
||||
const GURL& url,
|
||||
content::DevToolsManagerDelegate::TargetType target_type) {
|
||||
// This is reached when the user selects "Open link in new tab" from the
|
||||
// DevTools interface.
|
||||
// TODO(cef): Consider exposing new API to support this.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string CefDevToolsManagerDelegate::GetDiscoveryPageHTML() {
|
||||
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
||||
IDR_CEF_DEVTOOLS_DISCOVERY_PAGE);
|
||||
}
|
||||
|
||||
bool CefDevToolsManagerDelegate::HasBundledFrontendResources() {
|
||||
return true;
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
// Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_MANAGER_DELEGATE_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_MANAGER_DELEGATE_H_
|
||||
|
||||
#include "content/public/browser/devtools_manager_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
}
|
||||
|
||||
class CefDevToolsManagerDelegate : public content::DevToolsManagerDelegate {
|
||||
public:
|
||||
static void StartHttpHandler(content::BrowserContext* browser_context);
|
||||
static void StopHttpHandler();
|
||||
|
||||
CefDevToolsManagerDelegate();
|
||||
|
||||
CefDevToolsManagerDelegate(const CefDevToolsManagerDelegate&) = delete;
|
||||
CefDevToolsManagerDelegate& operator=(const CefDevToolsManagerDelegate&) =
|
||||
delete;
|
||||
|
||||
~CefDevToolsManagerDelegate() override;
|
||||
|
||||
// DevToolsManagerDelegate implementation.
|
||||
scoped_refptr<content::DevToolsAgentHost> CreateNewTarget(
|
||||
const GURL& url,
|
||||
content::DevToolsManagerDelegate::TargetType target_type) override;
|
||||
std::string GetDiscoveryPageHTML() override;
|
||||
bool HasBundledFrontendResources() override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_DEVTOOLS_DEVTOOLS_MANAGER_DELEGATE_H_
|
@@ -1,57 +0,0 @@
|
||||
// Copyright 2022 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright 2020 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cef/libcef/browser/alloy/dialogs/alloy_javascript_dialog_manager_delegate.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "cef/libcef/browser/browser_host_base.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class AlloyJavaScriptTabModalDialogManagerDelegateDesktop
|
||||
: public JavaScriptTabModalDialogManagerDelegateDesktop {
|
||||
public:
|
||||
explicit AlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
||||
content::WebContents* web_contents)
|
||||
: JavaScriptTabModalDialogManagerDelegateDesktop(web_contents),
|
||||
web_contents_(web_contents) {}
|
||||
|
||||
AlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
||||
const AlloyJavaScriptTabModalDialogManagerDelegateDesktop&) = delete;
|
||||
AlloyJavaScriptTabModalDialogManagerDelegateDesktop& operator=(
|
||||
const AlloyJavaScriptTabModalDialogManagerDelegateDesktop&) = delete;
|
||||
|
||||
// javascript_dialogs::TabModalDialogManagerDelegate methods:
|
||||
void WillRunDialog() override {}
|
||||
|
||||
void DidCloseDialog() override {}
|
||||
|
||||
void SetTabNeedsAttention(bool attention) override {}
|
||||
|
||||
bool IsWebContentsForemost() override {
|
||||
if (auto browser =
|
||||
CefBrowserHostBase::GetBrowserForContents(web_contents_)) {
|
||||
return browser->IsVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsApp() override { return false; }
|
||||
|
||||
private:
|
||||
// The WebContents for the tab over which the dialog will be modal. This may
|
||||
// be different from the WebContents that requested the dialog, such as with
|
||||
// Chrome app <webview>s.
|
||||
raw_ptr<content::WebContents> web_contents_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<JavaScriptTabModalDialogManagerDelegateDesktop>
|
||||
CreateAlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
||||
content::WebContents* web_contents) {
|
||||
return std::make_unique<AlloyJavaScriptTabModalDialogManagerDelegateDesktop>(
|
||||
web_contents);
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
// Copyright 2022 The Chromium Embedded Framework Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_ALLOY_DIALOGS_ALLOY_JAVASCRIPT_DIALOG_MANAGER_DELEGATE_H_
|
||||
#define CEF_LIBCEF_BROWSER_ALLOY_DIALOGS_ALLOY_JAVASCRIPT_DIALOG_MANAGER_DELEGATE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "chrome/browser/ui/javascript_dialogs/javascript_tab_modal_dialog_manager_delegate_desktop.h"
|
||||
|
||||
// Creates a JavaScriptTabModalDialogManagerDelegateDesktop for the Chrome
|
||||
// environment.
|
||||
std::unique_ptr<JavaScriptTabModalDialogManagerDelegateDesktop>
|
||||
CreateAlloyJavaScriptTabModalDialogManagerDelegateDesktop(
|
||||
content::WebContents* web_contents);
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_ALLOY_DIALOGS_ALLOY_JAVASCRIPT_DIALOG_MANAGER_DELEGATE_H_
|
Reference in New Issue
Block a user