2015-06-16 09:23:29 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_session.h"
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2019-08-26 16:47:32 +00:00
|
|
|
#include <algorithm>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2020-02-10 22:08:53 +00:00
|
|
|
#include <set>
|
2015-06-24 03:59:11 +00:00
|
|
|
#include <string>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2015-07-13 22:13:17 +00:00
|
|
|
#include <vector>
|
2015-06-24 03:59:11 +00:00
|
|
|
|
2019-12-19 13:53:49 +00:00
|
|
|
#include "base/command_line.h"
|
2024-04-01 16:09:01 +00:00
|
|
|
#include "base/containers/fixed_flat_map.h"
|
2023-03-20 14:34:49 +00:00
|
|
|
#include "base/files/file_enumerator.h"
|
2015-07-26 08:30:02 +00:00
|
|
|
#include "base/files/file_path.h"
|
2023-03-20 14:34:49 +00:00
|
|
|
#include "base/files/file_util.h"
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-02-26 00:39:17 +00:00
|
|
|
#include "base/scoped_observation.h"
|
2015-07-02 14:12:18 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2021-05-04 03:13:46 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2023-06-13 18:45:48 +00:00
|
|
|
#include "base/uuid.h"
|
2018-01-02 12:03:46 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2020-09-23 20:22:10 +00:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2015-07-26 08:30:02 +00:00
|
|
|
#include "chrome/common/pref_names.h"
|
2018-04-10 15:58:49 +00:00
|
|
|
#include "components/download/public/common/download_danger_type.h"
|
2019-08-29 03:27:20 +00:00
|
|
|
#include "components/download/public/common/download_url_parameters.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "components/prefs/pref_service.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/prefs/value_map_pref_store.h"
|
|
|
|
#include "components/proxy_config/proxy_config_dictionary.h"
|
|
|
|
#include "components/proxy_config/proxy_config_pref_names.h"
|
2020-10-27 06:50:06 +00:00
|
|
|
#include "components/proxy_config/proxy_prefs.h"
|
2022-03-15 20:34:53 +00:00
|
|
|
#include "content/browser/code_cache/generated_code_cache_context.h" // nogncheck
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2015-06-25 08:43:01 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2024-04-01 16:09:01 +00:00
|
|
|
#include "content/public/browser/browsing_data_filter_builder.h"
|
2024-02-26 00:39:17 +00:00
|
|
|
#include "content/public/browser/browsing_data_remover.h"
|
2018-04-10 15:29:26 +00:00
|
|
|
#include "content/public/browser/download_item_utils.h"
|
2016-11-18 10:43:43 +00:00
|
|
|
#include "content/public/browser/download_manager_delegate.h"
|
2019-05-29 23:43:06 +00:00
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2015-06-25 08:43:01 +00:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2020-05-19 17:18:12 +00:00
|
|
|
#include "gin/arguments.h"
|
2024-04-01 16:09:01 +00:00
|
|
|
#include "gin/converter.h"
|
2019-09-18 19:58:00 +00:00
|
|
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
|
|
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
2019-04-20 17:20:37 +00:00
|
|
|
#include "net/base/completion_repeating_callback.h"
|
2015-06-24 03:59:11 +00:00
|
|
|
#include "net/base/load_flags.h"
|
2022-10-17 14:22:24 +00:00
|
|
|
#include "net/base/network_anonymization_key.h"
|
2016-05-23 05:29:55 +00:00
|
|
|
#include "net/http/http_auth_handler_factory.h"
|
|
|
|
#include "net/http/http_auth_preferences.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "net/http/http_cache.h"
|
2020-06-04 11:05:37 +00:00
|
|
|
#include "net/http/http_util.h"
|
2019-06-28 22:22:23 +00:00
|
|
|
#include "services/network/network_service.h"
|
2019-04-23 21:39:21 +00:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2023-03-10 16:07:42 +00:00
|
|
|
#include "services/network/public/mojom/clear_data_filter.mojom.h"
|
2020-05-19 17:18:12 +00:00
|
|
|
#include "shell/browser/api/electron_api_app.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_cookies.h"
|
|
|
|
#include "shell/browser/api/electron_api_data_pipe_holder.h"
|
|
|
|
#include "shell/browser/api/electron_api_download_item.h"
|
|
|
|
#include "shell/browser/api/electron_api_net_log.h"
|
|
|
|
#include "shell/browser/api/electron_api_protocol.h"
|
2020-02-20 23:19:06 +00:00
|
|
|
#include "shell/browser/api/electron_api_service_worker_context.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_frame_main.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_request.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
|
|
#include "shell/browser/electron_permission_manager.h"
|
2020-06-22 16:35:24 +00:00
|
|
|
#include "shell/browser/javascript_environment.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/media/media_device_id_salt.h"
|
2019-08-07 15:04:09 +00:00
|
|
|
#include "shell/browser/net/cert_verifier_client.h"
|
2023-04-05 14:06:14 +00:00
|
|
|
#include "shell/browser/net/resolve_host_function.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/session_preferences.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
|
|
|
#include "shell/common/gin_converters/content_converter.h"
|
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "shell/common/gin_converters/media_converter.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_converters/net_converter.h"
|
2023-05-30 16:35:25 +00:00
|
|
|
#include "shell/common/gin_converters/usb_protected_classes_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2024-02-26 00:39:17 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
#include "shell/common/options_switches.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/common/process_util.h"
|
2022-07-13 21:26:16 +00:00
|
|
|
#include "third_party/blink/public/common/storage_key/storage_key.h"
|
2022-08-22 21:15:32 +00:00
|
|
|
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
|
2016-06-22 06:57:51 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2024-04-01 16:09:01 +00:00
|
|
|
#include "url/origin.h"
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-01-13 22:56:28 +00:00
|
|
|
#include "extensions/browser/extension_registry.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_system.h"
|
2020-01-13 22:56:28 +00:00
|
|
|
#include "shell/common/gin_converters/extension_converter.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2019-11-30 22:17:46 +00:00
|
|
|
#include "chrome/browser/spellchecker/spellcheck_factory.h" // nogncheck
|
|
|
|
#include "chrome/browser/spellchecker/spellcheck_service.h" // nogncheck
|
2019-10-31 20:11:51 +00:00
|
|
|
#include "components/spellcheck/browser/pref_names.h"
|
|
|
|
#include "components/spellcheck/common/spellcheck_common.h"
|
2019-11-26 21:16:43 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|
|
|
|
#include "components/spellcheck/browser/spellcheck_platform.h"
|
|
|
|
#include "components/spellcheck/common/spellcheck_features.h"
|
|
|
|
#endif
|
2019-10-31 20:11:51 +00:00
|
|
|
#endif
|
|
|
|
|
2015-07-02 14:12:18 +00:00
|
|
|
using content::BrowserThread;
|
2024-04-01 16:09:01 +00:00
|
|
|
using content::BrowsingDataFilterBuilder;
|
|
|
|
using content::BrowsingDataRemover;
|
2015-07-02 14:12:18 +00:00
|
|
|
using content::StoragePartition;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-07-13 22:13:17 +00:00
|
|
|
struct ClearStorageDataOptions {
|
2022-07-13 21:26:16 +00:00
|
|
|
blink::StorageKey storage_key;
|
2016-03-08 04:40:10 +00:00
|
|
|
uint32_t storage_types = StoragePartition::REMOVE_DATA_MASK_ALL;
|
|
|
|
uint32_t quota_types = StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL;
|
2015-07-13 22:13:17 +00:00
|
|
|
};
|
2015-07-02 14:12:18 +00:00
|
|
|
|
2016-03-08 04:40:10 +00:00
|
|
|
uint32_t GetStorageMask(const std::vector<std::string>& storage_types) {
|
2024-04-01 16:09:01 +00:00
|
|
|
static constexpr auto Lookup =
|
|
|
|
base::MakeFixedFlatMap<std::string_view, uint32_t>(
|
|
|
|
{{"cookies", StoragePartition::REMOVE_DATA_MASK_COOKIES},
|
|
|
|
{"filesystem", StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS},
|
|
|
|
{"indexdb", StoragePartition::REMOVE_DATA_MASK_INDEXEDDB},
|
|
|
|
{"localstorage", StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE},
|
|
|
|
{"shadercache", StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE},
|
|
|
|
{"serviceworkers",
|
|
|
|
StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS},
|
|
|
|
{"cachestorage", StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE}});
|
|
|
|
|
2016-03-08 04:40:10 +00:00
|
|
|
uint32_t storage_mask = 0;
|
2015-07-13 22:13:17 +00:00
|
|
|
for (const auto& it : storage_types) {
|
2015-12-07 11:56:23 +00:00
|
|
|
auto type = base::ToLowerASCII(it);
|
2024-04-01 16:09:01 +00:00
|
|
|
if (Lookup.contains(type))
|
|
|
|
storage_mask |= Lookup.at(type);
|
2015-07-02 14:12:18 +00:00
|
|
|
}
|
|
|
|
return storage_mask;
|
|
|
|
}
|
|
|
|
|
2016-03-08 04:40:10 +00:00
|
|
|
uint32_t GetQuotaMask(const std::vector<std::string>& quota_types) {
|
|
|
|
uint32_t quota_mask = 0;
|
2015-07-13 22:13:17 +00:00
|
|
|
for (const auto& it : quota_types) {
|
2015-12-07 11:56:23 +00:00
|
|
|
auto type = base::ToLowerASCII(it);
|
2015-07-13 22:13:17 +00:00
|
|
|
if (type == "temporary")
|
2015-07-02 14:12:18 +00:00
|
|
|
quota_mask |= StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY;
|
2015-07-13 22:13:17 +00:00
|
|
|
else if (type == "syncable")
|
|
|
|
quota_mask |= StoragePartition::QUOTA_MANAGED_STORAGE_MASK_SYNCABLE;
|
2015-07-02 14:12:18 +00:00
|
|
|
}
|
|
|
|
return quota_mask;
|
|
|
|
}
|
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
constexpr BrowsingDataRemover::DataType kClearDataTypeAll = ~0ULL;
|
|
|
|
constexpr BrowsingDataRemover::OriginType kClearOriginTypeAll =
|
|
|
|
BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
|
|
|
|
BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB;
|
|
|
|
|
|
|
|
constexpr auto kDataTypeLookup =
|
|
|
|
base::MakeFixedFlatMap<std::string_view, BrowsingDataRemover::DataType>({
|
|
|
|
{"backgroundFetch", BrowsingDataRemover::DATA_TYPE_BACKGROUND_FETCH},
|
|
|
|
{"cache", BrowsingDataRemover::DATA_TYPE_CACHE |
|
|
|
|
BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE},
|
|
|
|
{"cookies", BrowsingDataRemover::DATA_TYPE_COOKIES},
|
|
|
|
{"downloads", BrowsingDataRemover::DATA_TYPE_DOWNLOADS},
|
|
|
|
{"fileSystems", BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS},
|
|
|
|
{"indexedDB", BrowsingDataRemover::DATA_TYPE_INDEXED_DB},
|
|
|
|
{"localStorage", BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE},
|
|
|
|
{"serviceWorkers", BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS},
|
|
|
|
});
|
|
|
|
|
|
|
|
BrowsingDataRemover::DataType GetDataTypeMask(
|
|
|
|
const std::vector<std::string>& data_types) {
|
|
|
|
BrowsingDataRemover::DataType mask = 0u;
|
|
|
|
for (const auto& type : data_types) {
|
|
|
|
if (kDataTypeLookup.contains(type)) {
|
|
|
|
mask |= kDataTypeLookup.at(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> GetDataTypesFromMask(
|
|
|
|
BrowsingDataRemover::DataType mask) {
|
|
|
|
std::vector<std::string> results;
|
|
|
|
for (const auto [type, flag] : kDataTypeLookup) {
|
|
|
|
if (mask & flag) {
|
|
|
|
results.emplace_back(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
2024-02-26 00:39:17 +00:00
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
// Represents a task to clear browsing data for the `clearData` API method.
|
|
|
|
//
|
|
|
|
// This type manages its own lifetime, deleting itself once the task finishes
|
|
|
|
// completely.
|
|
|
|
class ClearDataTask {
|
2024-02-26 00:39:17 +00:00
|
|
|
public:
|
2024-04-01 16:09:01 +00:00
|
|
|
// Starts running a task. This function will return before the task is
|
|
|
|
// finished, but will resolve or reject the |promise| when it finishes.
|
|
|
|
static void Run(
|
|
|
|
BrowsingDataRemover* remover,
|
|
|
|
gin_helper::Promise<void> promise,
|
|
|
|
BrowsingDataRemover::DataType data_type_mask,
|
|
|
|
std::vector<url::Origin> origins,
|
|
|
|
BrowsingDataFilterBuilder::Mode filter_mode,
|
|
|
|
BrowsingDataFilterBuilder::OriginMatchingMode origin_matching_mode) {
|
|
|
|
std::shared_ptr<ClearDataTask> task(new ClearDataTask(std::move(promise)));
|
|
|
|
|
|
|
|
// This method counts as an operation. This is important so we can call
|
|
|
|
// `OnOperationFinished` at the end of this method as a fallback if all the
|
|
|
|
// other operations finished while this method was still executing
|
|
|
|
task->operations_running_ = 1;
|
|
|
|
|
|
|
|
// Cookies are scoped more broadly than other types of data, so if we are
|
|
|
|
// filtering then we need to do it at the registrable domain level
|
|
|
|
if (!origins.empty() &&
|
|
|
|
data_type_mask & BrowsingDataRemover::DATA_TYPE_COOKIES) {
|
|
|
|
data_type_mask &= ~BrowsingDataRemover::DATA_TYPE_COOKIES;
|
|
|
|
|
|
|
|
auto cookies_filter_builder =
|
|
|
|
BrowsingDataFilterBuilder::Create(filter_mode);
|
|
|
|
|
|
|
|
for (const url::Origin& origin : origins) {
|
|
|
|
std::string domain = GetDomainAndRegistry(
|
|
|
|
origin,
|
|
|
|
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
|
|
|
|
if (domain.empty()) {
|
|
|
|
domain = origin.host();
|
|
|
|
}
|
|
|
|
cookies_filter_builder->AddRegisterableDomain(domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
StartOperation(task, remover, BrowsingDataRemover::DATA_TYPE_COOKIES,
|
|
|
|
std::move(cookies_filter_builder));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If cookies aren't the only data type and weren't handled above, then we
|
|
|
|
// can start an operation that is scoped to origins
|
|
|
|
if (data_type_mask) {
|
|
|
|
auto filter_builder =
|
|
|
|
BrowsingDataFilterBuilder::Create(filter_mode, origin_matching_mode);
|
|
|
|
|
|
|
|
for (auto const& origin : origins) {
|
|
|
|
filter_builder->AddOrigin(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
StartOperation(task, remover, data_type_mask, std::move(filter_builder));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This static method counts as an operation.
|
|
|
|
task->OnOperationFinished(std::nullopt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// An individiual |content::BrowsingDataRemover::Remove...| operation as part
|
|
|
|
// of a full |ClearDataTask|. This class manages its own lifetime, cleaning
|
|
|
|
// itself up after the operation completes and notifies the task of the
|
|
|
|
// result.
|
2024-05-29 18:07:02 +00:00
|
|
|
class ClearDataOperation : private BrowsingDataRemover::Observer {
|
2024-04-01 16:09:01 +00:00
|
|
|
public:
|
|
|
|
static void Run(std::shared_ptr<ClearDataTask> task,
|
|
|
|
BrowsingDataRemover* remover,
|
|
|
|
BrowsingDataRemover::DataType data_type_mask,
|
|
|
|
std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
|
|
|
|
auto* operation = new ClearDataOperation(task, remover);
|
|
|
|
|
|
|
|
remover->RemoveWithFilterAndReply(base::Time::Min(), base::Time::Max(),
|
|
|
|
data_type_mask, kClearOriginTypeAll,
|
|
|
|
std::move(filter_builder), operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BrowsingDataRemover::Observer:
|
|
|
|
void OnBrowsingDataRemoverDone(
|
|
|
|
BrowsingDataRemover::DataType failed_data_types) override {
|
|
|
|
task_->OnOperationFinished(failed_data_types);
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClearDataOperation(std::shared_ptr<ClearDataTask> task,
|
|
|
|
BrowsingDataRemover* remover)
|
|
|
|
: task_(task) {
|
|
|
|
observation_.Observe(remover);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ClearDataTask> task_;
|
|
|
|
base::ScopedObservation<BrowsingDataRemover, BrowsingDataRemover::Observer>
|
|
|
|
observation_{this};
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit ClearDataTask(gin_helper::Promise<void> promise)
|
|
|
|
: promise_(std::move(promise)) {}
|
|
|
|
|
|
|
|
static void StartOperation(
|
|
|
|
std::shared_ptr<ClearDataTask> task,
|
|
|
|
BrowsingDataRemover* remover,
|
|
|
|
BrowsingDataRemover::DataType data_type_mask,
|
|
|
|
std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
|
|
|
|
// Track this operation
|
|
|
|
task->operations_running_ += 1;
|
|
|
|
|
|
|
|
ClearDataOperation::Run(task, remover, data_type_mask,
|
|
|
|
std::move(filter_builder));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnOperationFinished(
|
|
|
|
std::optional<BrowsingDataRemover::DataType> failed_data_types) {
|
|
|
|
DCHECK_GT(operations_running_, 0);
|
|
|
|
operations_running_ -= 1;
|
|
|
|
|
|
|
|
if (failed_data_types.has_value()) {
|
|
|
|
failed_data_types_ |= failed_data_types.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the last operation, then the task is finished
|
|
|
|
if (operations_running_ == 0) {
|
|
|
|
OnTaskFinished();
|
|
|
|
}
|
2024-02-26 00:39:17 +00:00
|
|
|
}
|
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
void OnTaskFinished() {
|
|
|
|
if (failed_data_types_ == 0ULL) {
|
2024-02-26 00:39:17 +00:00
|
|
|
promise_.Resolve();
|
|
|
|
} else {
|
2024-04-01 16:09:01 +00:00
|
|
|
v8::Isolate* isolate = promise_.isolate();
|
|
|
|
|
|
|
|
v8::Local<v8::Value> failed_data_types_array =
|
|
|
|
gin::ConvertToV8(isolate, GetDataTypesFromMask(failed_data_types_));
|
|
|
|
|
|
|
|
// Create a rich error object with extra detail about what data types
|
|
|
|
// failed
|
|
|
|
auto error = v8::Exception::Error(
|
|
|
|
gin::StringToV8(isolate, "Failed to clear data"));
|
|
|
|
error.As<v8::Object>()
|
|
|
|
->Set(promise_.GetContext(),
|
|
|
|
gin::StringToV8(isolate, "failedDataTypes"),
|
|
|
|
failed_data_types_array)
|
|
|
|
.Check();
|
|
|
|
|
|
|
|
promise_.Reject(error);
|
2024-02-26 00:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
int operations_running_ = 0;
|
|
|
|
BrowsingDataRemover::DataType failed_data_types_ = 0ULL;
|
2024-02-26 00:39:17 +00:00
|
|
|
gin_helper::Promise<void> promise_;
|
|
|
|
};
|
|
|
|
|
2022-10-17 14:22:24 +00:00
|
|
|
base::Value::Dict createProxyConfig(ProxyPrefs::ProxyMode proxy_mode,
|
|
|
|
std::string const& pac_url,
|
|
|
|
std::string const& proxy_server,
|
|
|
|
std::string const& bypass_list) {
|
|
|
|
if (proxy_mode == ProxyPrefs::MODE_DIRECT) {
|
|
|
|
return ProxyConfigDictionary::CreateDirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proxy_mode == ProxyPrefs::MODE_SYSTEM) {
|
|
|
|
return ProxyConfigDictionary::CreateSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proxy_mode == ProxyPrefs::MODE_AUTO_DETECT) {
|
|
|
|
return ProxyConfigDictionary::CreateAutoDetect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proxy_mode == ProxyPrefs::MODE_PAC_SCRIPT) {
|
|
|
|
const bool pac_mandatory = true;
|
|
|
|
return ProxyConfigDictionary::CreatePacScript(pac_url, pac_mandatory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ProxyConfigDictionary::CreateFixedServers(proxy_server, bypass_list);
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:12:18 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
namespace gin {
|
2015-07-13 22:13:17 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2015-07-13 22:13:17 +00:00
|
|
|
struct Converter<ClearStorageDataOptions> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
ClearStorageDataOptions* out) {
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Dictionary options;
|
2015-07-13 22:13:17 +00:00
|
|
|
if (!ConvertFromV8(isolate, val, &options))
|
|
|
|
return false;
|
2022-07-13 21:26:16 +00:00
|
|
|
if (GURL storage_origin; options.Get("origin", &storage_origin))
|
2023-03-10 16:07:42 +00:00
|
|
|
out->storage_key = blink::StorageKey::CreateFirstParty(
|
|
|
|
url::Origin::Create(storage_origin));
|
2015-07-13 22:13:17 +00:00
|
|
|
std::vector<std::string> types;
|
|
|
|
if (options.Get("storages", &types))
|
|
|
|
out->storage_types = GetStorageMask(types);
|
|
|
|
if (options.Get("quotas", &types))
|
|
|
|
out->quota_types = GetQuotaMask(types);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-23 20:22:10 +00:00
|
|
|
bool SSLProtocolVersionFromString(const std::string& version_str,
|
|
|
|
network::mojom::SSLVersion* version) {
|
|
|
|
if (version_str == switches::kSSLVersionTLSv12) {
|
|
|
|
*version = network::mojom::SSLVersion::kTLS12;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (version_str == switches::kSSLVersionTLSv13) {
|
|
|
|
*version = network::mojom::SSLVersion::kTLS13;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-21 18:03:59 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<uint16_t> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
uint16_t* out) {
|
|
|
|
auto maybe = val->IntegerValue(isolate->GetCurrentContext());
|
|
|
|
if (maybe.IsNothing())
|
|
|
|
return false;
|
|
|
|
*out = maybe.FromJust();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-23 20:22:10 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<network::mojom::SSLConfigPtr> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
network::mojom::SSLConfigPtr* out) {
|
|
|
|
gin_helper::Dictionary options;
|
|
|
|
if (!ConvertFromV8(isolate, val, &options))
|
|
|
|
return false;
|
|
|
|
*out = network::mojom::SSLConfig::New();
|
|
|
|
std::string version_min_str;
|
|
|
|
if (options.Get("minVersion", &version_min_str)) {
|
|
|
|
if (!SSLProtocolVersionFromString(version_min_str, &(*out)->version_min))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string version_max_str;
|
|
|
|
if (options.Get("maxVersion", &version_max_str)) {
|
|
|
|
if (!SSLProtocolVersionFromString(version_max_str,
|
|
|
|
&(*out)->version_max) ||
|
|
|
|
(*out)->version_max < network::mojom::SSLVersion::kTLS12)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-21 18:03:59 +00:00
|
|
|
if (options.Has("disabledCipherSuites") &&
|
|
|
|
!options.Get("disabledCipherSuites", &(*out)->disabled_cipher_suites)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::sort((*out)->disabled_cipher_suites.begin(),
|
|
|
|
(*out)->disabled_cipher_suites.end());
|
|
|
|
|
|
|
|
// TODO(nornagon): also support other SSLConfig properties?
|
2020-09-23 20:22:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
} // namespace gin
|
2015-07-13 22:13:17 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2015-06-16 09:23:29 +00:00
|
|
|
|
2015-06-24 03:59:11 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-07-12 12:01:49 +00:00
|
|
|
const char kPersistPrefix[] = "persist:";
|
|
|
|
|
2016-11-18 10:43:43 +00:00
|
|
|
void DownloadIdCallback(content::DownloadManager* download_manager,
|
|
|
|
const base::FilePath& path,
|
|
|
|
const std::vector<GURL>& url_chain,
|
|
|
|
const std::string& mime_type,
|
|
|
|
int64_t offset,
|
|
|
|
int64_t length,
|
|
|
|
const std::string& last_modified,
|
|
|
|
const std::string& etag,
|
|
|
|
const base::Time& start_time,
|
|
|
|
uint32_t id) {
|
2016-11-24 15:16:39 +00:00
|
|
|
download_manager->CreateDownloadItem(
|
2023-06-13 18:45:48 +00:00
|
|
|
base::Uuid::GenerateRandomV4().AsLowercaseString(), id, path, path,
|
|
|
|
url_chain, GURL(),
|
2022-02-25 18:17:35 +00:00
|
|
|
content::StoragePartitionConfig::CreateDefault(
|
|
|
|
download_manager->GetBrowserContext()),
|
2024-01-10 22:23:35 +00:00
|
|
|
GURL(), GURL(), std::nullopt, mime_type, mime_type, start_time,
|
2022-02-25 18:17:35 +00:00
|
|
|
base::Time(), etag, last_modified, offset, length, std::string(),
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem::INTERRUPTED,
|
2018-04-10 15:58:49 +00:00
|
|
|
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
|
2018-04-10 16:08:50 +00:00
|
|
|
download::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false, base::Time(),
|
2023-01-06 02:35:34 +00:00
|
|
|
false, std::vector<download::DownloadItem::ReceivedSlice>());
|
2016-11-18 10:43:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2020-02-10 22:08:53 +00:00
|
|
|
class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
|
|
|
|
private:
|
|
|
|
std::unique_ptr<gin_helper::Promise<std::set<std::string>>> promise_;
|
|
|
|
base::WeakPtr<SpellcheckService> spellcheck_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DictionaryObserver(gin_helper::Promise<std::set<std::string>> promise,
|
|
|
|
base::WeakPtr<SpellcheckService> spellcheck)
|
|
|
|
: spellcheck_(spellcheck) {
|
|
|
|
promise_ = std::make_unique<gin_helper::Promise<std::set<std::string>>>(
|
|
|
|
std::move(promise));
|
|
|
|
if (spellcheck_)
|
|
|
|
spellcheck_->GetCustomDictionary()->AddObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~DictionaryObserver() {
|
|
|
|
if (spellcheck_)
|
|
|
|
spellcheck_->GetCustomDictionary()->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnCustomDictionaryLoaded() override {
|
|
|
|
if (spellcheck_) {
|
|
|
|
promise_->Resolve(spellcheck_->GetCustomDictionary()->GetWords());
|
|
|
|
} else {
|
|
|
|
promise_->RejectWithErrorMessage(
|
|
|
|
"Spellcheck in unexpected state: failed to load custom dictionary.");
|
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnCustomDictionaryChanged(
|
|
|
|
const SpellcheckCustomDictionary::Change& dictionary_change) override {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
};
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2020-02-10 22:08:53 +00:00
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
struct UserDataLink : base::SupportsUserData::Data {
|
2024-07-08 10:55:48 +00:00
|
|
|
explicit UserDataLink(base::WeakPtr<Session> session_in)
|
|
|
|
: session{std::move(session_in)} {}
|
2020-05-19 17:18:12 +00:00
|
|
|
|
2024-07-08 10:55:48 +00:00
|
|
|
base::WeakPtr<Session> session;
|
2020-05-19 17:18:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const void* kElectronApiSessionKey = &kElectronApiSessionKey;
|
|
|
|
|
2015-06-24 03:59:11 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::WrapperInfo Session::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
2021-03-29 10:45:08 +00:00
|
|
|
: isolate_(isolate),
|
|
|
|
network_emulation_token_(base::UnguessableToken::Create()),
|
2024-07-02 21:53:36 +00:00
|
|
|
browser_context_{
|
|
|
|
raw_ref<ElectronBrowserContext>::from_ptr(browser_context)} {
|
2016-09-21 23:24:03 +00:00
|
|
|
// Observe DownloadManager to get download notifications.
|
2021-05-19 23:15:47 +00:00
|
|
|
browser_context->GetDownloadManager()->AddObserver(this);
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2023-06-09 16:20:43 +00:00
|
|
|
SessionPreferences::CreateForBrowserContext(browser_context);
|
2017-12-05 06:59:15 +00:00
|
|
|
|
2019-11-07 23:35:12 +00:00
|
|
|
protocol_.Reset(isolate, Protocol::Create(isolate, browser_context).ToV8());
|
|
|
|
|
2024-07-08 10:55:48 +00:00
|
|
|
browser_context->SetUserData(
|
|
|
|
kElectronApiSessionKey,
|
|
|
|
std::make_unique<UserDataLink>(weak_factory_.GetWeakPtr()));
|
2020-03-05 19:58:19 +00:00
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2024-07-02 21:53:36 +00:00
|
|
|
if (auto* service =
|
|
|
|
SpellcheckServiceFactory::GetForContext(browser_context)) {
|
2020-03-05 19:58:19 +00:00
|
|
|
service->SetHunspellObserver(this);
|
|
|
|
}
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif
|
2020-09-23 19:29:08 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context)->AddObserver(this);
|
|
|
|
#endif
|
2015-06-16 09:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Session::~Session() {
|
2021-05-19 23:15:47 +00:00
|
|
|
browser_context()->GetDownloadManager()->RemoveObserver(this);
|
2020-03-05 19:58:19 +00:00
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2024-07-02 21:53:36 +00:00
|
|
|
if (auto* service =
|
|
|
|
SpellcheckServiceFactory::GetForContext(browser_context())) {
|
2020-03-05 19:58:19 +00:00
|
|
|
service->SetHunspellObserver(nullptr);
|
|
|
|
}
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif
|
2020-09-23 19:29:08 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
extensions::ExtensionRegistry::Get(browser_context())->RemoveObserver(this);
|
|
|
|
#endif
|
2015-08-30 18:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
2018-04-10 15:29:26 +00:00
|
|
|
download::DownloadItem* item) {
|
2016-04-27 14:59:39 +00:00
|
|
|
if (item->IsSavePackageDownload())
|
2015-10-14 04:41:31 +00:00
|
|
|
return;
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2021-03-29 10:45:08 +00:00
|
|
|
v8::HandleScope handle_scope(isolate_);
|
|
|
|
auto handle = DownloadItem::FromOrCreate(isolate_, item);
|
2018-04-10 15:29:26 +00:00
|
|
|
if (item->GetState() == download::DownloadItem::INTERRUPTED)
|
2016-11-18 10:43:43 +00:00
|
|
|
handle->SetSavePath(item->GetTargetFilePath());
|
2018-04-10 15:29:26 +00:00
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::DownloadItemUtils::GetWebContents(item);
|
|
|
|
bool prevent_default = Emit("will-download", handle, web_contents);
|
2015-08-30 18:52:01 +00:00
|
|
|
if (prevent_default) {
|
|
|
|
item->Cancel(true);
|
|
|
|
item->Remove();
|
|
|
|
}
|
2015-06-16 09:23:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2020-03-05 19:58:19 +00:00
|
|
|
void Session::OnHunspellDictionaryInitialized(const std::string& language) {
|
|
|
|
Emit("spellcheck-dictionary-initialized", language);
|
|
|
|
}
|
|
|
|
void Session::OnHunspellDictionaryDownloadBegin(const std::string& language) {
|
|
|
|
Emit("spellcheck-dictionary-download-begin", language);
|
|
|
|
}
|
|
|
|
void Session::OnHunspellDictionaryDownloadSuccess(const std::string& language) {
|
|
|
|
Emit("spellcheck-dictionary-download-success", language);
|
|
|
|
}
|
|
|
|
void Session::OnHunspellDictionaryDownloadFailure(const std::string& language) {
|
|
|
|
Emit("spellcheck-dictionary-download-failure", language);
|
|
|
|
}
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif
|
2020-03-05 19:58:19 +00:00
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> Session::ResolveProxy(gin::Arguments* args) {
|
2019-03-08 20:51:12 +00:00
|
|
|
v8::Isolate* isolate = args->isolate();
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<std::string> promise(isolate);
|
2019-03-08 20:51:12 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
GURL url;
|
|
|
|
args->GetNext(&url);
|
|
|
|
|
|
|
|
browser_context_->GetResolveProxyHelper()->ResolveProxy(
|
2019-11-01 06:10:32 +00:00
|
|
|
url, base::BindOnce(gin_helper::Promise<std::string>::ResolvePromise,
|
2019-05-01 20:45:08 +00:00
|
|
|
std::move(promise)));
|
2019-03-08 20:51:12 +00:00
|
|
|
|
|
|
|
return handle;
|
2015-06-24 03:59:11 +00:00
|
|
|
}
|
|
|
|
|
2023-04-05 14:06:14 +00:00
|
|
|
v8::Local<v8::Promise> Session::ResolveHost(
|
|
|
|
std::string host,
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<network::mojom::ResolveHostParametersPtr> params) {
|
2023-04-05 14:06:14 +00:00
|
|
|
gin_helper::Promise<gin_helper::Dictionary> promise(isolate_);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
auto fn = base::MakeRefCounted<ResolveHostFunction>(
|
2024-07-02 21:53:36 +00:00
|
|
|
browser_context(), std::move(host),
|
2023-04-05 14:06:14 +00:00
|
|
|
params ? std::move(params.value()) : nullptr,
|
|
|
|
base::BindOnce(
|
|
|
|
[](gin_helper::Promise<gin_helper::Dictionary> promise,
|
2024-01-10 22:23:35 +00:00
|
|
|
int64_t net_error, const std::optional<net::AddressList>& addrs) {
|
2023-04-05 14:06:14 +00:00
|
|
|
if (net_error < 0) {
|
|
|
|
promise.RejectWithErrorMessage(net::ErrorToString(net_error));
|
|
|
|
} else {
|
|
|
|
DCHECK(addrs.has_value() && !addrs->empty());
|
|
|
|
|
|
|
|
v8::HandleScope handle_scope(promise.isolate());
|
2023-10-10 10:45:44 +00:00
|
|
|
auto dict =
|
|
|
|
gin_helper::Dictionary::CreateEmpty(promise.isolate());
|
2023-04-05 14:06:14 +00:00
|
|
|
dict.Set("endpoints", addrs->endpoints());
|
|
|
|
promise.Resolve(dict);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
std::move(promise)));
|
|
|
|
|
|
|
|
fn->Run();
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-04-30 22:09:17 +00:00
|
|
|
v8::Local<v8::Promise> Session::GetCacheSize() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<int64_t> promise(isolate_);
|
2019-04-30 22:09:17 +00:00
|
|
|
auto handle = promise.GetHandle();
|
2019-03-08 22:42:03 +00:00
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2019-04-30 22:09:17 +00:00
|
|
|
->GetNetworkContext()
|
2019-08-23 00:03:28 +00:00
|
|
|
->ComputeHttpCacheSize(
|
|
|
|
base::Time(), base::Time::Max(),
|
|
|
|
base::BindOnce(
|
2019-11-01 06:10:32 +00:00
|
|
|
[](gin_helper::Promise<int64_t> promise, bool is_upper_bound,
|
2019-08-23 00:03:28 +00:00
|
|
|
int64_t size_or_error) {
|
|
|
|
if (size_or_error < 0) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
net::ErrorToString(size_or_error));
|
|
|
|
} else {
|
|
|
|
promise.Resolve(size_or_error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
std::move(promise)));
|
2019-04-30 22:09:17 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> Session::ClearCache() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate_);
|
2019-04-30 22:09:17 +00:00
|
|
|
auto handle = promise.GetHandle();
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2019-04-30 22:09:17 +00:00
|
|
|
->GetNetworkContext()
|
|
|
|
->ClearHttpCache(base::Time(), base::Time::Max(), nullptr,
|
2019-11-01 06:10:32 +00:00
|
|
|
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
2019-04-30 22:09:17 +00:00
|
|
|
std::move(promise)));
|
2019-03-08 22:42:03 +00:00
|
|
|
|
|
|
|
return handle;
|
2015-07-02 14:12:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> Session::ClearStorageData(gin::Arguments* args) {
|
2019-03-08 17:02:30 +00:00
|
|
|
v8::Isolate* isolate = args->isolate();
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-03-08 17:02:30 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
2015-07-13 22:13:17 +00:00
|
|
|
ClearStorageDataOptions options;
|
|
|
|
args->GetNext(&options);
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
auto* storage_partition = browser_context()->GetStoragePartition(nullptr);
|
2016-12-03 11:14:33 +00:00
|
|
|
if (options.storage_types & StoragePartition::REMOVE_DATA_MASK_COOKIES) {
|
|
|
|
// Reset media device id salt when cookies are cleared.
|
|
|
|
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
|
2018-10-19 18:51:43 +00:00
|
|
|
MediaDeviceIDSalt::Reset(browser_context()->prefs());
|
2016-12-03 11:14:33 +00:00
|
|
|
}
|
2019-03-08 17:02:30 +00:00
|
|
|
|
|
|
|
storage_partition->ClearData(
|
2022-07-13 21:26:16 +00:00
|
|
|
options.storage_types, options.quota_types, options.storage_key,
|
|
|
|
base::Time(), base::Time::Max(),
|
2019-11-01 06:10:32 +00:00
|
|
|
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
2019-08-23 00:03:28 +00:00
|
|
|
std::move(promise)));
|
2019-03-08 17:02:30 +00:00
|
|
|
return handle;
|
2015-07-02 14:12:18 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 15:28:12 +00:00
|
|
|
void Session::FlushStorageData() {
|
2021-05-04 03:13:46 +00:00
|
|
|
auto* storage_partition = browser_context()->GetStoragePartition(nullptr);
|
2016-01-12 15:28:12 +00:00
|
|
|
storage_partition->Flush();
|
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> Session::SetProxy(gin::Arguments* args) {
|
2019-03-08 20:51:12 +00:00
|
|
|
v8::Isolate* isolate = args->isolate();
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-03-08 20:51:12 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Dictionary options;
|
2019-03-08 20:51:12 +00:00
|
|
|
args->GetNext(&options);
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
if (!browser_context_->in_memory_pref_store()) {
|
2019-03-08 20:51:12 +00:00
|
|
|
promise.Resolve();
|
|
|
|
return handle;
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 06:50:06 +00:00
|
|
|
std::string mode, proxy_rules, bypass_list, pac_url;
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
options.Get("pacScript", &pac_url);
|
|
|
|
options.Get("proxyRules", &proxy_rules);
|
|
|
|
options.Get("proxyBypassRules", &bypass_list);
|
|
|
|
|
2020-10-27 06:50:06 +00:00
|
|
|
ProxyPrefs::ProxyMode proxy_mode = ProxyPrefs::MODE_FIXED_SERVERS;
|
|
|
|
if (!options.Get("mode", &mode)) {
|
|
|
|
// pacScript takes precedence over proxyRules.
|
|
|
|
if (!pac_url.empty()) {
|
|
|
|
proxy_mode = ProxyPrefs::MODE_PAC_SCRIPT;
|
|
|
|
} else {
|
|
|
|
proxy_mode = ProxyPrefs::MODE_FIXED_SERVERS;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ProxyPrefs::StringToProxyMode(mode, &proxy_mode)) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"Invalid mode, must be one of direct, auto_detect, pac_script, "
|
|
|
|
"fixed_servers or system");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_context_->in_memory_pref_store()->SetValue(
|
2022-10-17 14:22:24 +00:00
|
|
|
proxy_config::prefs::kProxy,
|
|
|
|
base::Value{
|
|
|
|
createProxyConfig(proxy_mode, pac_url, proxy_rules, bypass_list)},
|
2020-10-27 06:50:06 +00:00
|
|
|
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
2019-11-01 06:10:32 +00:00
|
|
|
FROM_HERE, base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
2019-08-23 00:03:28 +00:00
|
|
|
std::move(promise)));
|
2019-03-08 20:51:12 +00:00
|
|
|
|
|
|
|
return handle;
|
2015-07-16 14:36:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 06:50:06 +00:00
|
|
|
v8::Local<v8::Promise> Session::ForceReloadProxyConfig() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate_);
|
2020-10-27 06:50:06 +00:00
|
|
|
auto handle = promise.GetHandle();
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2020-10-27 06:50:06 +00:00
|
|
|
->GetNetworkContext()
|
|
|
|
->ForceReloadProxyConfig(base::BindOnce(
|
|
|
|
gin_helper::Promise<void>::ResolvePromise, std::move(promise)));
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2015-07-30 02:38:04 +00:00
|
|
|
void Session::SetDownloadPath(const base::FilePath& path) {
|
2018-04-18 01:55:30 +00:00
|
|
|
browser_context_->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
|
|
|
|
path);
|
2015-07-26 08:30:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void Session::EnableNetworkEmulation(const gin_helper::Dictionary& options) {
|
2018-10-02 18:08:10 +00:00
|
|
|
auto conditions = network::mojom::NetworkConditions::New();
|
|
|
|
|
|
|
|
options.Get("offline", &conditions->offline);
|
|
|
|
options.Get("downloadThroughput", &conditions->download_throughput);
|
|
|
|
options.Get("uploadThroughput", &conditions->upload_throughput);
|
|
|
|
double latency = 0.0;
|
|
|
|
if (options.Get("latency", &latency) && latency) {
|
2021-11-24 08:45:59 +00:00
|
|
|
conditions->latency = base::Milliseconds(latency);
|
2015-09-27 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 20:21:53 +00:00
|
|
|
auto* network_context =
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()->GetNetworkContext();
|
2018-10-02 18:08:10 +00:00
|
|
|
network_context->SetNetworkConditions(network_emulation_token_,
|
|
|
|
std::move(conditions));
|
2015-09-27 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::DisableNetworkEmulation() {
|
2020-08-17 20:21:53 +00:00
|
|
|
auto* network_context =
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()->GetNetworkContext();
|
2018-10-02 18:08:10 +00:00
|
|
|
network_context->SetNetworkConditions(
|
|
|
|
network_emulation_token_, network::mojom::NetworkConditions::New());
|
2015-09-27 13:19:52 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 03:45:15 +00:00
|
|
|
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2019-08-07 15:04:09 +00:00
|
|
|
CertVerifierClient::CertVerifyProc proc;
|
2019-10-25 13:03:28 +00:00
|
|
|
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &proc))) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError("Must pass null or function");
|
2015-11-18 03:17:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::PendingRemote<network::mojom::CertVerifierClient>
|
|
|
|
cert_verifier_client_remote;
|
2019-08-02 23:56:46 +00:00
|
|
|
if (proc) {
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::MakeSelfOwnedReceiver(
|
|
|
|
std::make_unique<CertVerifierClient>(proc),
|
|
|
|
cert_verifier_client_remote.InitWithNewPipeAndPassReceiver());
|
2019-06-28 22:22:23 +00:00
|
|
|
}
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2019-08-02 23:56:46 +00:00
|
|
|
->GetNetworkContext()
|
2019-09-18 19:58:00 +00:00
|
|
|
->SetCertVerifierClient(std::move(cert_verifier_client_remote));
|
2015-11-18 03:17:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 21:35:34 +00:00
|
|
|
void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2020-02-04 20:19:40 +00:00
|
|
|
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
2019-05-03 21:20:43 +00:00
|
|
|
browser_context()->GetPermissionControllerDelegate());
|
|
|
|
if (val->IsNull()) {
|
|
|
|
permission_manager->SetPermissionRequestHandler(
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronPermissionManager::RequestHandler());
|
2019-05-03 21:20:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-02-04 20:19:40 +00:00
|
|
|
auto handler = std::make_unique<ElectronPermissionManager::RequestHandler>();
|
2019-10-25 13:03:28 +00:00
|
|
|
if (!gin::ConvertFromV8(args->isolate(), val, handler.get())) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError("Must pass null or function");
|
2016-01-31 21:35:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-03 18:30:48 +00:00
|
|
|
permission_manager->SetPermissionRequestHandler(base::BindRepeating(
|
2020-02-04 20:19:40 +00:00
|
|
|
[](ElectronPermissionManager::RequestHandler* handler,
|
2019-06-13 18:11:43 +00:00
|
|
|
content::WebContents* web_contents,
|
2022-05-17 16:48:40 +00:00
|
|
|
blink::PermissionType permission_type,
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronPermissionManager::StatusCallback callback,
|
2019-06-13 18:11:43 +00:00
|
|
|
const base::Value& details) {
|
2023-05-18 21:01:44 +00:00
|
|
|
handler->Run(web_contents, permission_type, std::move(callback),
|
2019-05-03 21:20:43 +00:00
|
|
|
details);
|
2019-05-03 18:30:48 +00:00
|
|
|
},
|
2019-05-03 21:20:43 +00:00
|
|
|
base::Owned(std::move(handler))));
|
2016-01-31 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 14:05:08 +00:00
|
|
|
void Session::SetPermissionCheckHandler(v8::Local<v8::Value> val,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronPermissionManager::CheckHandler handler;
|
2019-10-25 13:03:28 +00:00
|
|
|
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError("Must pass null or function");
|
2018-08-28 14:05:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-02-04 20:19:40 +00:00
|
|
|
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
2018-10-02 21:53:10 +00:00
|
|
|
browser_context()->GetPermissionControllerDelegate());
|
2018-08-28 14:05:08 +00:00
|
|
|
permission_manager->SetPermissionCheckHandler(handler);
|
|
|
|
}
|
|
|
|
|
2022-08-22 21:15:32 +00:00
|
|
|
void Session::SetDisplayMediaRequestHandler(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val) {
|
|
|
|
if (val->IsNull()) {
|
|
|
|
browser_context_->SetDisplayMediaRequestHandler(
|
|
|
|
DisplayMediaRequestHandler());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DisplayMediaRequestHandler handler;
|
|
|
|
if (!gin::ConvertFromV8(isolate, val, &handler)) {
|
|
|
|
gin_helper::ErrorThrower(isolate).ThrowTypeError(
|
|
|
|
"Display media request handler must be null or a function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
browser_context_->SetDisplayMediaRequestHandler(handler);
|
|
|
|
}
|
|
|
|
|
2021-09-23 11:00:11 +00:00
|
|
|
void Session::SetDevicePermissionHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args) {
|
|
|
|
ElectronPermissionManager::DeviceCheckHandler handler;
|
|
|
|
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) {
|
|
|
|
args->ThrowTypeError("Must pass null or function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
|
|
|
browser_context()->GetPermissionControllerDelegate());
|
|
|
|
permission_manager->SetDevicePermissionHandler(handler);
|
|
|
|
}
|
|
|
|
|
2023-05-30 16:35:25 +00:00
|
|
|
void Session::SetUSBProtectedClassesHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args) {
|
|
|
|
ElectronPermissionManager::ProtectedUSBHandler handler;
|
|
|
|
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) {
|
|
|
|
args->ThrowTypeError("Must pass null or function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
|
|
|
browser_context()->GetPermissionControllerDelegate());
|
|
|
|
permission_manager->SetProtectedUSBHandler(handler);
|
|
|
|
}
|
|
|
|
|
2022-09-26 14:19:58 +00:00
|
|
|
void Session::SetBluetoothPairingHandler(v8::Local<v8::Value> val,
|
|
|
|
gin::Arguments* args) {
|
|
|
|
ElectronPermissionManager::BluetoothPairingHandler handler;
|
|
|
|
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) {
|
|
|
|
args->ThrowTypeError("Must pass null or function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto* permission_manager = static_cast<ElectronPermissionManager*>(
|
|
|
|
browser_context()->GetPermissionControllerDelegate());
|
|
|
|
permission_manager->SetBluetoothPairingHandler(handler);
|
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
v8::Local<v8::Promise> Session::ClearHostResolverCache(gin::Arguments* args) {
|
2019-03-08 18:26:17 +00:00
|
|
|
v8::Isolate* isolate = args->isolate();
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-03-08 18:26:17 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2016-02-01 13:33:23 +00:00
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2019-04-25 17:51:48 +00:00
|
|
|
->GetNetworkContext()
|
2019-05-03 21:30:25 +00:00
|
|
|
->ClearHostCache(nullptr,
|
2019-11-01 06:10:32 +00:00
|
|
|
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
2019-05-03 21:30:25 +00:00
|
|
|
std::move(promise)));
|
2019-04-25 17:51:48 +00:00
|
|
|
|
2019-03-08 18:26:17 +00:00
|
|
|
return handle;
|
2016-02-01 13:33:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 21:30:25 +00:00
|
|
|
v8::Local<v8::Promise> Session::ClearAuthCache() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate_);
|
2019-03-09 02:41:42 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2019-05-03 21:30:25 +00:00
|
|
|
->GetNetworkContext()
|
2019-08-23 00:03:28 +00:00
|
|
|
->ClearHttpAuthCache(
|
2020-09-21 08:00:36 +00:00
|
|
|
base::Time(), base::Time::Max(),
|
2023-10-24 15:24:20 +00:00
|
|
|
nullptr /*mojom::ClearDataFilterPtr*/,
|
2019-11-01 06:10:32 +00:00
|
|
|
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
2019-08-23 00:03:28 +00:00
|
|
|
std::move(promise)));
|
2016-11-30 16:35:15 +00:00
|
|
|
|
2019-03-09 02:41:42 +00:00
|
|
|
return handle;
|
2016-11-30 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 05:29:55 +00:00
|
|
|
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
|
2020-06-02 19:58:00 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2019-08-07 15:04:09 +00:00
|
|
|
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
|
|
|
|
network::mojom::HttpAuthDynamicParams::New();
|
|
|
|
auth_dynamic_params->server_allowlist = domains;
|
2019-12-19 13:53:49 +00:00
|
|
|
auth_dynamic_params->enable_negotiate_port =
|
2020-06-02 19:58:00 +00:00
|
|
|
command_line->HasSwitch(electron::switches::kEnableAuthNegotiatePort);
|
|
|
|
auth_dynamic_params->ntlm_v2_enabled =
|
|
|
|
!command_line->HasSwitch(electron::switches::kDisableNTLMv2);
|
2019-08-07 15:04:09 +00:00
|
|
|
content::GetNetworkService()->ConfigureHttpAuthPrefs(
|
|
|
|
std::move(auth_dynamic_params));
|
2016-05-23 05:29:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
void Session::SetUserAgent(const std::string& user_agent,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2019-08-29 06:50:14 +00:00
|
|
|
browser_context_->SetUserAgent(user_agent);
|
2020-08-17 20:21:53 +00:00
|
|
|
auto* network_context =
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()->GetNetworkContext();
|
2020-06-04 11:05:37 +00:00
|
|
|
network_context->SetUserAgent(user_agent);
|
|
|
|
|
|
|
|
std::string accept_lang;
|
|
|
|
if (args->GetNext(&accept_lang)) {
|
|
|
|
network_context->SetAcceptLanguage(
|
|
|
|
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang));
|
|
|
|
}
|
2016-06-22 06:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Session::GetUserAgent() {
|
|
|
|
return browser_context_->GetUserAgent();
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:22:10 +00:00
|
|
|
void Session::SetSSLConfig(network::mojom::SSLConfigPtr config) {
|
|
|
|
browser_context_->SetSSLConfig(std::move(config));
|
|
|
|
}
|
|
|
|
|
2020-03-11 07:02:22 +00:00
|
|
|
bool Session::IsPersistent() {
|
|
|
|
return !browser_context_->IsOffTheRecord();
|
|
|
|
}
|
|
|
|
|
2019-03-14 15:11:01 +00:00
|
|
|
v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
|
|
|
|
const std::string& uuid) {
|
2019-09-03 22:54:14 +00:00
|
|
|
gin::Handle<DataPipeHolder> holder = DataPipeHolder::From(isolate, uuid);
|
|
|
|
if (holder.IsEmpty()) {
|
2019-11-01 06:10:32 +00:00
|
|
|
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
2019-09-03 22:54:14 +00:00
|
|
|
promise.RejectWithErrorMessage("Could not get blob data handle");
|
|
|
|
return promise.GetHandle();
|
|
|
|
}
|
2016-08-23 05:57:43 +00:00
|
|
|
|
2019-09-03 22:54:14 +00:00
|
|
|
return holder->ReadAll(isolate);
|
2016-08-23 00:39:06 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 13:31:28 +00:00
|
|
|
void Session::DownloadURL(const GURL& url, gin::Arguments* args) {
|
|
|
|
std::map<std::string, std::string> headers;
|
|
|
|
gin_helper::Dictionary options;
|
|
|
|
if (args->GetNext(&options)) {
|
|
|
|
if (options.Has("headers") && !options.Get("headers", &headers)) {
|
|
|
|
args->ThrowTypeError("Invalid value for headers - must be an object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:27:20 +00:00
|
|
|
auto download_params = std::make_unique<download::DownloadUrlParameters>(
|
2020-03-11 11:15:07 +00:00
|
|
|
url, MISSING_TRAFFIC_ANNOTATION);
|
2023-06-21 13:31:28 +00:00
|
|
|
|
|
|
|
for (const auto& [name, value] : headers) {
|
|
|
|
download_params->add_request_header(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* download_manager = browser_context()->GetDownloadManager();
|
2019-08-29 03:27:20 +00:00
|
|
|
download_manager->DownloadUrl(std::move(download_params));
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void Session::CreateInterruptedDownload(const gin_helper::Dictionary& options) {
|
2016-11-18 10:43:43 +00:00
|
|
|
int64_t offset = 0, length = 0;
|
2023-11-01 14:02:12 +00:00
|
|
|
double start_time = base::Time::Now().InSecondsFSinceUnixEpoch();
|
2016-11-18 10:43:43 +00:00
|
|
|
std::string mime_type, last_modified, etag;
|
|
|
|
base::FilePath path;
|
|
|
|
std::vector<GURL> url_chain;
|
|
|
|
options.Get("path", &path);
|
|
|
|
options.Get("urlChain", &url_chain);
|
|
|
|
options.Get("mimeType", &mime_type);
|
|
|
|
options.Get("offset", &offset);
|
|
|
|
options.Get("length", &length);
|
|
|
|
options.Get("lastModified", &last_modified);
|
|
|
|
options.Get("eTag", &etag);
|
|
|
|
options.Get("startTime", &start_time);
|
2016-12-07 07:28:53 +00:00
|
|
|
if (path.empty() || url_chain.empty() || length == 0) {
|
2021-03-29 10:45:08 +00:00
|
|
|
isolate_->ThrowException(v8::Exception::Error(gin::StringToV8(
|
|
|
|
isolate_, "Must pass non-empty path, urlChain and length.")));
|
2016-11-18 10:43:43 +00:00
|
|
|
return;
|
2016-12-07 07:28:53 +00:00
|
|
|
}
|
|
|
|
if (offset >= length) {
|
2021-03-29 10:45:08 +00:00
|
|
|
isolate_->ThrowException(v8::Exception::Error(gin::StringToV8(
|
|
|
|
isolate_, "Must pass an offset value less than length.")));
|
2016-12-07 07:28:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-19 23:15:47 +00:00
|
|
|
auto* download_manager = browser_context()->GetDownloadManager();
|
2020-04-03 00:22:46 +00:00
|
|
|
download_manager->GetNextId(base::BindRepeating(
|
2016-11-18 10:43:43 +00:00
|
|
|
&DownloadIdCallback, download_manager, path, url_chain, mime_type, offset,
|
2023-11-01 14:02:12 +00:00
|
|
|
length, last_modified, etag,
|
|
|
|
base::Time::FromSecondsSinceUnixEpoch(start_time)));
|
2016-11-18 10:43:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
void Session::SetPreloads(const std::vector<base::FilePath>& preloads) {
|
2017-12-05 06:59:15 +00:00
|
|
|
auto* prefs = SessionPreferences::FromBrowserContext(browser_context());
|
|
|
|
DCHECK(prefs);
|
|
|
|
prefs->set_preloads(preloads);
|
2017-09-16 15:05:49 +00:00
|
|
|
}
|
2017-12-05 02:50:06 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
std::vector<base::FilePath> Session::GetPreloads() const {
|
2017-12-05 06:59:15 +00:00
|
|
|
auto* prefs = SessionPreferences::FromBrowserContext(browser_context());
|
|
|
|
DCHECK(prefs);
|
|
|
|
return prefs->preloads();
|
2017-09-16 15:05:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-01-13 22:56:28 +00:00
|
|
|
v8::Local<v8::Promise> Session::LoadExtension(
|
2021-02-01 22:41:08 +00:00
|
|
|
const base::FilePath& extension_path,
|
|
|
|
gin::Arguments* args) {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<const extensions::Extension*> promise(isolate_);
|
2020-01-13 22:56:28 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2020-08-21 03:47:10 +00:00
|
|
|
|
|
|
|
if (!extension_path.IsAbsolute()) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"The path to the extension in 'loadExtension' must be absolute");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:28:03 +00:00
|
|
|
if (browser_context()->IsOffTheRecord()) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"Extensions cannot be loaded in a temporary session");
|
|
|
|
return handle;
|
|
|
|
}
|
2020-01-13 22:56:28 +00:00
|
|
|
|
2021-02-01 22:41:08 +00:00
|
|
|
int load_flags = extensions::Extension::FOLLOW_SYMLINKS_ANYWHERE;
|
|
|
|
gin_helper::Dictionary options;
|
|
|
|
if (args->GetNext(&options)) {
|
|
|
|
bool allowFileAccess = false;
|
|
|
|
options.Get("allowFileAccess", &allowFileAccess);
|
|
|
|
if (allowFileAccess)
|
|
|
|
load_flags |= extensions::Extension::ALLOW_FILE_ACCESS;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
|
2020-01-13 22:56:28 +00:00
|
|
|
extensions::ExtensionSystem::Get(browser_context()));
|
2020-01-21 17:43:18 +00:00
|
|
|
extension_system->LoadExtension(
|
2021-02-01 22:41:08 +00:00
|
|
|
extension_path, load_flags,
|
2020-01-21 17:43:18 +00:00
|
|
|
base::BindOnce(
|
|
|
|
[](gin_helper::Promise<const extensions::Extension*> promise,
|
2020-02-03 22:01:10 +00:00
|
|
|
const extensions::Extension* extension,
|
|
|
|
const std::string& error_msg) {
|
2020-01-21 17:43:18 +00:00
|
|
|
if (extension) {
|
2020-02-03 22:01:10 +00:00
|
|
|
if (!error_msg.empty()) {
|
|
|
|
node::Environment* env =
|
2021-03-29 10:45:08 +00:00
|
|
|
node::Environment::GetCurrent(promise.isolate());
|
2020-02-03 22:01:10 +00:00
|
|
|
EmitWarning(env, error_msg, "ExtensionLoadWarning");
|
|
|
|
}
|
2020-01-21 17:43:18 +00:00
|
|
|
promise.Resolve(extension);
|
|
|
|
} else {
|
2020-02-03 22:01:10 +00:00
|
|
|
promise.RejectWithErrorMessage(error_msg);
|
2020-01-21 17:43:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
std::move(promise)));
|
2020-01-13 22:56:28 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::RemoveExtension(const std::string& extension_id) {
|
2020-02-03 22:01:10 +00:00
|
|
|
auto* extension_system = static_cast<extensions::ElectronExtensionSystem*>(
|
2019-07-24 23:01:08 +00:00
|
|
|
extensions::ExtensionSystem::Get(browser_context()));
|
2020-01-13 22:56:28 +00:00
|
|
|
extension_system->RemoveExtension(extension_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> Session::GetExtension(const std::string& extension_id) {
|
|
|
|
auto* registry = extensions::ExtensionRegistry::Get(browser_context());
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
registry->GetInstalledExtension(extension_id);
|
|
|
|
if (extension) {
|
2021-03-29 10:45:08 +00:00
|
|
|
return gin::ConvertToV8(isolate_, extension);
|
2020-01-13 22:56:28 +00:00
|
|
|
} else {
|
2021-03-29 10:45:08 +00:00
|
|
|
return v8::Null(isolate_);
|
2020-01-13 22:56:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> Session::GetAllExtensions() {
|
|
|
|
auto* registry = extensions::ExtensionRegistry::Get(browser_context());
|
2023-03-10 16:07:42 +00:00
|
|
|
const extensions::ExtensionSet extensions =
|
|
|
|
registry->GenerateInstalledExtensionsSet();
|
2020-01-13 22:56:28 +00:00
|
|
|
std::vector<const extensions::Extension*> extensions_vector;
|
2023-03-10 16:07:42 +00:00
|
|
|
for (const auto& extension : extensions) {
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
if (extension->location() !=
|
2021-05-19 23:08:24 +00:00
|
|
|
extensions::mojom::ManifestLocation::kComponent)
|
2020-02-13 00:39:12 +00:00
|
|
|
extensions_vector.emplace_back(extension.get());
|
2020-01-13 22:56:28 +00:00
|
|
|
}
|
2021-03-29 10:45:08 +00:00
|
|
|
return gin::ConvertToV8(isolate_, extensions_vector);
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
2020-09-23 19:29:08 +00:00
|
|
|
|
|
|
|
void Session::OnExtensionLoaded(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension) {
|
|
|
|
Emit("extension-loaded", extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::OnExtensionUnloaded(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension,
|
|
|
|
extensions::UnloadedExtensionReason reason) {
|
|
|
|
Emit("extension-unloaded", extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::OnExtensionReady(content::BrowserContext* browser_context,
|
|
|
|
const extensions::Extension* extension) {
|
|
|
|
Emit("extension-ready", extension);
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-16 09:23:29 +00:00
|
|
|
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
|
|
|
|
if (cookies_.IsEmpty()) {
|
2016-09-21 23:24:03 +00:00
|
|
|
auto handle = Cookies::Create(isolate, browser_context());
|
2015-06-16 09:23:29 +00:00
|
|
|
cookies_.Reset(isolate, handle.ToV8());
|
|
|
|
}
|
2020-03-26 17:34:32 +00:00
|
|
|
return cookies_.Get(isolate);
|
2015-06-16 09:23:29 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 14:31:27 +00:00
|
|
|
v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
|
2020-03-26 17:34:32 +00:00
|
|
|
return protocol_.Get(isolate);
|
2016-06-08 14:31:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 23:19:06 +00:00
|
|
|
v8::Local<v8::Value> Session::ServiceWorkerContext(v8::Isolate* isolate) {
|
|
|
|
if (service_worker_context_.IsEmpty()) {
|
|
|
|
v8::Local<v8::Value> handle;
|
|
|
|
handle = ServiceWorkerContext::Create(isolate, browser_context()).ToV8();
|
|
|
|
service_worker_context_.Reset(isolate, handle);
|
|
|
|
}
|
2020-03-26 17:34:32 +00:00
|
|
|
return service_worker_context_.Get(isolate);
|
2020-02-20 23:19:06 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 04:52:22 +00:00
|
|
|
v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
|
|
|
|
if (web_request_.IsEmpty()) {
|
2019-10-24 00:51:06 +00:00
|
|
|
auto handle = WebRequest::Create(isolate, browser_context());
|
2019-08-11 04:24:51 +00:00
|
|
|
web_request_.Reset(isolate, handle.ToV8());
|
2015-12-01 04:52:22 +00:00
|
|
|
}
|
2020-03-26 17:34:32 +00:00
|
|
|
return web_request_.Get(isolate);
|
2015-12-01 04:52:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
v8::Local<v8::Value> Session::NetLog(v8::Isolate* isolate) {
|
|
|
|
if (net_log_.IsEmpty()) {
|
2020-03-26 17:34:32 +00:00
|
|
|
auto handle = NetLog::Create(isolate, browser_context());
|
2018-10-04 18:08:56 +00:00
|
|
|
net_log_.Reset(isolate, handle.ToV8());
|
|
|
|
}
|
2020-03-26 17:34:32 +00:00
|
|
|
return net_log_.Get(isolate);
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 20:21:53 +00:00
|
|
|
static void StartPreconnectOnUI(ElectronBrowserContext* browser_context,
|
|
|
|
const GURL& url,
|
|
|
|
int num_sockets_to_preconnect) {
|
2021-09-06 07:33:10 +00:00
|
|
|
url::Origin origin = url::Origin::Create(url);
|
2019-08-26 16:47:32 +00:00
|
|
|
std::vector<predictors::PreconnectRequest> requests = {
|
2019-12-11 00:22:35 +00:00
|
|
|
{url::Origin::Create(url), num_sockets_to_preconnect,
|
2023-03-10 16:07:42 +00:00
|
|
|
net::NetworkAnonymizationKey::CreateSameSite(
|
|
|
|
net::SchemefulSite(origin))}};
|
2019-08-26 16:47:32 +00:00
|
|
|
browser_context->GetPreconnectManager()->Start(url, requests);
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void Session::Preconnect(const gin_helper::Dictionary& options,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2019-08-26 16:47:32 +00:00
|
|
|
GURL url;
|
|
|
|
if (!options.Get("url", &url) || !url.is_valid()) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError(
|
|
|
|
"Must pass non-empty valid url to session.preconnect.");
|
2019-08-26 16:47:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int num_sockets_to_preconnect = 1;
|
|
|
|
if (options.Get("numSockets", &num_sockets_to_preconnect)) {
|
|
|
|
const int kMinSocketsToPreconnect = 1;
|
|
|
|
const int kMaxSocketsToPreconnect = 6;
|
|
|
|
if (num_sockets_to_preconnect < kMinSocketsToPreconnect ||
|
|
|
|
num_sockets_to_preconnect > kMaxSocketsToPreconnect) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError(
|
2019-08-26 16:47:32 +00:00
|
|
|
base::StringPrintf("numSocketsToPreconnect is outside range [%d,%d]",
|
|
|
|
kMinSocketsToPreconnect, kMaxSocketsToPreconnect));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_GT(num_sockets_to_preconnect, 0);
|
2022-05-17 16:48:40 +00:00
|
|
|
content::GetUIThreadTaskRunner({})->PostTask(
|
|
|
|
FROM_HERE,
|
2024-07-02 21:53:36 +00:00
|
|
|
base::BindOnce(&StartPreconnectOnUI, base::Unretained(browser_context()),
|
2019-08-26 16:47:32 +00:00
|
|
|
url, num_sockets_to_preconnect));
|
|
|
|
}
|
|
|
|
|
2020-10-08 16:45:36 +00:00
|
|
|
v8::Local<v8::Promise> Session::CloseAllConnections() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate_);
|
2020-10-08 16:45:36 +00:00
|
|
|
auto handle = promise.GetHandle();
|
|
|
|
|
2021-05-04 03:13:46 +00:00
|
|
|
browser_context_->GetDefaultStoragePartition()
|
2020-10-08 16:45:36 +00:00
|
|
|
->GetNetworkContext()
|
|
|
|
->CloseAllConnections(base::BindOnce(
|
|
|
|
gin_helper::Promise<void>::ResolvePromise, std::move(promise)));
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:54:28 +00:00
|
|
|
v8::Local<v8::Value> Session::GetPath(v8::Isolate* isolate) {
|
|
|
|
if (browser_context_->IsOffTheRecord()) {
|
|
|
|
return v8::Null(isolate);
|
|
|
|
}
|
|
|
|
return gin::ConvertToV8(isolate, browser_context_->GetPath());
|
|
|
|
}
|
|
|
|
|
2022-03-15 20:34:53 +00:00
|
|
|
void Session::SetCodeCachePath(gin::Arguments* args) {
|
|
|
|
base::FilePath code_cache_path;
|
|
|
|
auto* storage_partition = browser_context_->GetDefaultStoragePartition();
|
|
|
|
auto* code_cache_context = storage_partition->GetGeneratedCodeCacheContext();
|
|
|
|
if (code_cache_context) {
|
|
|
|
if (!args->GetNext(&code_cache_path) || !code_cache_path.IsAbsolute()) {
|
|
|
|
args->ThrowTypeError(
|
|
|
|
"Absolute path must be provided to store code cache.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
code_cache_context->Initialize(
|
|
|
|
code_cache_path, 0 /* allows disk_cache to choose the size */);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> Session::ClearCodeCaches(
|
|
|
|
const gin_helper::Dictionary& options) {
|
|
|
|
auto* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
gin_helper::Promise<void> promise(isolate);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
std::set<GURL> url_list;
|
|
|
|
base::RepeatingCallback<bool(const GURL&)> url_matcher = base::NullCallback();
|
|
|
|
if (options.Get("urls", &url_list) && !url_list.empty()) {
|
|
|
|
url_matcher = base::BindRepeating(
|
|
|
|
[](const std::set<GURL>& url_list, const GURL& url) {
|
|
|
|
return base::Contains(url_list, url);
|
|
|
|
},
|
|
|
|
url_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_context_->GetDefaultStoragePartition()->ClearCodeCaches(
|
|
|
|
base::Time(), base::Time::Max(), url_matcher,
|
|
|
|
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
|
|
|
std::move(promise)));
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
v8::Local<v8::Value> Session::ClearData(gin_helper::ErrorThrower thrower,
|
|
|
|
gin::Arguments* args) {
|
2024-02-26 00:39:17 +00:00
|
|
|
auto* isolate = JavascriptEnvironment::GetIsolate();
|
2024-04-01 16:09:01 +00:00
|
|
|
|
|
|
|
BrowsingDataRemover::DataType data_type_mask = kClearDataTypeAll;
|
|
|
|
std::vector<url::Origin> origins;
|
|
|
|
BrowsingDataFilterBuilder::OriginMatchingMode origin_matching_mode =
|
|
|
|
BrowsingDataFilterBuilder::OriginMatchingMode::kThirdPartiesIncluded;
|
|
|
|
BrowsingDataFilterBuilder::Mode filter_mode =
|
|
|
|
BrowsingDataFilterBuilder::Mode::kPreserve;
|
|
|
|
|
|
|
|
if (gin_helper::Dictionary options; args->GetNext(&options)) {
|
|
|
|
if (std::vector<std::string> data_types;
|
|
|
|
options.Get("dataTypes", &data_types)) {
|
|
|
|
data_type_mask = GetDataTypeMask(data_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bool avoid_closing_connections;
|
|
|
|
options.Get("avoidClosingConnections", &avoid_closing_connections) &&
|
|
|
|
avoid_closing_connections) {
|
|
|
|
data_type_mask |=
|
|
|
|
BrowsingDataRemover::DATA_TYPE_AVOID_CLOSING_CONNECTIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GURL> origin_urls;
|
|
|
|
{
|
|
|
|
bool has_origins_key = options.Get("origins", &origin_urls);
|
|
|
|
std::vector<GURL> exclude_origin_urls;
|
|
|
|
bool has_exclude_origins_key =
|
|
|
|
options.Get("excludeOrigins", &exclude_origin_urls);
|
|
|
|
|
|
|
|
if (has_origins_key && has_exclude_origins_key) {
|
|
|
|
thrower.ThrowError(
|
|
|
|
"Cannot provide both 'origins' and 'excludeOrigins'");
|
|
|
|
return v8::Undefined(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_origins_key) {
|
|
|
|
filter_mode = BrowsingDataFilterBuilder::Mode::kDelete;
|
|
|
|
} else if (has_exclude_origins_key) {
|
|
|
|
origin_urls = std::move(exclude_origin_urls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!origin_urls.empty()) {
|
|
|
|
origins.reserve(origin_urls.size());
|
|
|
|
for (const GURL& origin_url : origin_urls) {
|
|
|
|
auto origin = url::Origin::Create(origin_url);
|
|
|
|
|
|
|
|
// Opaque origins cannot be used with this API
|
|
|
|
if (origin.opaque()) {
|
|
|
|
thrower.ThrowError(
|
|
|
|
base::StringPrintf("Invalid origin: '%s'",
|
|
|
|
origin_url.possibly_invalid_spec().c_str()));
|
|
|
|
return v8::Undefined(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
origins.push_back(std::move(origin));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::string origin_matching_mode_string;
|
|
|
|
options.Get("originMatchingMode", &origin_matching_mode_string)) {
|
|
|
|
if (origin_matching_mode_string == "third-parties-included") {
|
|
|
|
origin_matching_mode = BrowsingDataFilterBuilder::OriginMatchingMode::
|
|
|
|
kThirdPartiesIncluded;
|
|
|
|
} else if (origin_matching_mode_string == "origin-in-all-contexts") {
|
|
|
|
origin_matching_mode =
|
|
|
|
BrowsingDataFilterBuilder::OriginMatchingMode::kOriginInAllContexts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-26 00:39:17 +00:00
|
|
|
gin_helper::Promise<void> promise(isolate);
|
|
|
|
v8::Local<v8::Promise> promise_handle = promise.GetHandle();
|
|
|
|
|
2024-04-01 16:09:01 +00:00
|
|
|
BrowsingDataRemover* remover = browser_context_->GetBrowsingDataRemover();
|
|
|
|
ClearDataTask::Run(remover, std::move(promise), data_type_mask,
|
|
|
|
std::move(origins), filter_mode, origin_matching_mode);
|
2024-02-26 00:39:17 +00:00
|
|
|
|
|
|
|
return promise_handle;
|
|
|
|
}
|
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
base::Value Session::GetSpellCheckerLanguages() {
|
|
|
|
return browser_context_->prefs()
|
2022-09-07 07:46:37 +00:00
|
|
|
->GetValue(spellcheck::prefs::kSpellCheckDictionaries)
|
|
|
|
.Clone();
|
2019-10-31 20:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::SetSpellCheckerLanguages(
|
|
|
|
gin_helper::ErrorThrower thrower,
|
|
|
|
const std::vector<std::string>& languages) {
|
2022-09-14 22:10:16 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2022-06-22 08:14:35 +00:00
|
|
|
base::Value::List language_codes;
|
2019-10-31 20:11:51 +00:00
|
|
|
for (const std::string& lang : languages) {
|
|
|
|
std::string code = spellcheck::GetCorrespondingSpellCheckLanguage(lang);
|
|
|
|
if (code.empty()) {
|
|
|
|
thrower.ThrowError("Invalid language code provided: \"" + lang +
|
|
|
|
"\" is not a valid language code");
|
|
|
|
return;
|
|
|
|
}
|
2021-10-06 02:21:00 +00:00
|
|
|
language_codes.Append(code);
|
2019-10-31 20:11:51 +00:00
|
|
|
}
|
|
|
|
browser_context_->prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
|
2022-06-22 08:14:35 +00:00
|
|
|
base::Value(std::move(language_codes)));
|
2020-10-23 07:34:19 +00:00
|
|
|
// Enable spellcheck if > 0 languages, disable if no languages set
|
|
|
|
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
|
|
|
|
!languages.empty());
|
2022-09-14 22:10:16 +00:00
|
|
|
#endif
|
2019-10-31 20:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
|
|
|
|
const GURL& url) {
|
2022-09-14 22:10:16 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2019-10-31 20:11:51 +00:00
|
|
|
if (!url.is_valid()) {
|
|
|
|
thrower.ThrowError(
|
|
|
|
"The URL you provided to setSpellCheckerDictionaryDownloadURL is not a "
|
|
|
|
"valid URL");
|
|
|
|
return;
|
|
|
|
}
|
2020-02-25 22:57:28 +00:00
|
|
|
SpellcheckHunspellDictionary::SetBaseDownloadURL(url);
|
2022-09-14 22:10:16 +00:00
|
|
|
#endif
|
2019-10-31 20:11:51 +00:00
|
|
|
}
|
2019-11-26 21:16:43 +00:00
|
|
|
|
2020-02-10 22:08:53 +00:00
|
|
|
v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
|
2021-03-29 10:45:08 +00:00
|
|
|
gin_helper::Promise<std::set<std::string>> promise(isolate_);
|
2020-02-10 22:08:53 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
SpellcheckService* spellcheck =
|
2024-07-02 21:53:36 +00:00
|
|
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
2020-02-10 22:08:53 +00:00
|
|
|
|
2020-10-22 17:53:42 +00:00
|
|
|
if (!spellcheck) {
|
2020-02-10 22:08:53 +00:00
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"Spellcheck in unexpected state: failed to load custom dictionary.");
|
2020-10-22 17:53:42 +00:00
|
|
|
return handle;
|
|
|
|
}
|
2020-02-10 22:08:53 +00:00
|
|
|
|
|
|
|
if (spellcheck->GetCustomDictionary()->IsLoaded()) {
|
|
|
|
promise.Resolve(spellcheck->GetCustomDictionary()->GetWords());
|
|
|
|
} else {
|
|
|
|
new DictionaryObserver(std::move(promise), spellcheck->GetWeakPtr());
|
|
|
|
// Dictionary loads by default asynchronously,
|
|
|
|
// call the load function anyways just to be sure.
|
|
|
|
spellcheck->GetCustomDictionary()->Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-11-26 21:16:43 +00:00
|
|
|
bool Session::AddWordToSpellCheckerDictionary(const std::string& word) {
|
2020-03-10 07:45:43 +00:00
|
|
|
// don't let in-memory sessions add spellchecker words
|
|
|
|
// because files will persist unintentionally
|
|
|
|
bool is_in_memory = browser_context_->IsOffTheRecord();
|
|
|
|
if (is_in_memory)
|
|
|
|
return false;
|
|
|
|
|
2020-02-06 07:05:30 +00:00
|
|
|
SpellcheckService* service =
|
2024-07-02 21:53:36 +00:00
|
|
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
2020-02-06 07:05:30 +00:00
|
|
|
if (!service)
|
|
|
|
return false;
|
|
|
|
|
2019-11-26 21:16:43 +00:00
|
|
|
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|
|
|
|
if (spellcheck::UseBrowserSpellChecker()) {
|
2020-02-06 07:05:30 +00:00
|
|
|
spellcheck_platform::AddWord(service->platform_spell_checker(),
|
|
|
|
base::UTF8ToUTF16(word));
|
2019-11-26 21:16:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-02-06 07:05:30 +00:00
|
|
|
return service->GetCustomDictionary()->AddWord(word);
|
2019-11-26 21:16:43 +00:00
|
|
|
}
|
2020-02-10 22:07:25 +00:00
|
|
|
|
|
|
|
bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) {
|
2020-03-10 07:45:43 +00:00
|
|
|
// don't let in-memory sessions remove spellchecker words
|
|
|
|
// because files will persist unintentionally
|
|
|
|
bool is_in_memory = browser_context_->IsOffTheRecord();
|
|
|
|
if (is_in_memory)
|
|
|
|
return false;
|
|
|
|
|
2020-02-10 22:07:25 +00:00
|
|
|
SpellcheckService* service =
|
2024-07-02 21:53:36 +00:00
|
|
|
SpellcheckServiceFactory::GetForContext(browser_context());
|
2020-02-10 22:07:25 +00:00
|
|
|
if (!service)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|
|
|
|
if (spellcheck::UseBrowserSpellChecker()) {
|
|
|
|
spellcheck_platform::RemoveWord(service->platform_spell_checker(),
|
|
|
|
base::UTF8ToUTF16(word));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return service->GetCustomDictionary()->RemoveWord(word);
|
|
|
|
}
|
2020-11-11 15:29:18 +00:00
|
|
|
|
|
|
|
void Session::SetSpellCheckerEnabled(bool b) {
|
|
|
|
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
|
|
|
|
b);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::IsSpellCheckerEnabled() const {
|
|
|
|
return browser_context_->prefs()->GetBoolean(
|
|
|
|
spellcheck::prefs::kSpellCheckEnable);
|
|
|
|
}
|
|
|
|
|
2020-03-10 09:39:40 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2019-10-31 20:11:51 +00:00
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
// static
|
|
|
|
Session* Session::FromBrowserContext(content::BrowserContext* context) {
|
2020-10-26 18:56:31 +00:00
|
|
|
auto* data =
|
2020-05-19 17:18:12 +00:00
|
|
|
static_cast<UserDataLink*>(context->GetUserData(kElectronApiSessionKey));
|
2024-07-08 10:55:48 +00:00
|
|
|
return data ? data->session.get() : nullptr;
|
2020-05-19 17:18:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 09:23:29 +00:00
|
|
|
// static
|
2020-02-04 20:19:40 +00:00
|
|
|
gin::Handle<Session> Session::CreateFrom(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
ElectronBrowserContext* browser_context) {
|
2020-05-19 17:18:12 +00:00
|
|
|
Session* existing = FromBrowserContext(browser_context);
|
2015-06-24 07:37:04 +00:00
|
|
|
if (existing)
|
2020-05-19 17:18:12 +00:00
|
|
|
return gin::CreateHandle(isolate, existing);
|
2015-06-24 07:37:04 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
auto handle =
|
2019-10-25 13:03:28 +00:00
|
|
|
gin::CreateHandle(isolate, new Session(isolate, browser_context));
|
2016-08-01 11:11:17 +00:00
|
|
|
|
|
|
|
// The Sessions should never be garbage collected, since the common pattern is
|
|
|
|
// to use partition strings, instead of using the Session object directly.
|
2020-05-19 17:18:12 +00:00
|
|
|
handle->Pin(isolate);
|
|
|
|
|
2023-02-13 21:39:18 +00:00
|
|
|
App::Get()->EmitWithoutEvent("session-created", handle);
|
2016-08-01 11:11:17 +00:00
|
|
|
|
2015-09-01 10:02:14 +00:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2015-09-05 14:39:48 +00:00
|
|
|
// static
|
2019-10-30 05:30:59 +00:00
|
|
|
gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
|
|
|
|
const std::string& partition,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict options) {
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext* browser_context;
|
2016-07-12 12:01:49 +00:00
|
|
|
if (partition.empty()) {
|
2020-02-04 20:19:40 +00:00
|
|
|
browser_context =
|
|
|
|
ElectronBrowserContext::From("", false, std::move(options));
|
2024-04-24 02:13:59 +00:00
|
|
|
} else if (partition.starts_with(kPersistPrefix)) {
|
2016-07-12 12:01:49 +00:00
|
|
|
std::string name = partition.substr(8);
|
2020-02-04 20:19:40 +00:00
|
|
|
browser_context =
|
|
|
|
ElectronBrowserContext::From(name, false, std::move(options));
|
2016-07-12 12:01:49 +00:00
|
|
|
} else {
|
2019-10-30 05:30:59 +00:00
|
|
|
browser_context =
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::From(partition, true, std::move(options));
|
2016-07-12 12:01:49 +00:00
|
|
|
}
|
2020-08-17 20:21:53 +00:00
|
|
|
return CreateFrom(isolate, browser_context);
|
2015-09-05 14:39:48 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
// static
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<gin::Handle<Session>> Session::FromPath(
|
2023-03-20 14:34:49 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const base::FilePath& path,
|
|
|
|
base::Value::Dict options) {
|
|
|
|
ElectronBrowserContext* browser_context;
|
|
|
|
|
|
|
|
if (path.empty()) {
|
|
|
|
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
|
|
|
promise.RejectWithErrorMessage("An empty path was specified");
|
2024-01-10 22:23:35 +00:00
|
|
|
return std::nullopt;
|
2023-03-20 14:34:49 +00:00
|
|
|
}
|
|
|
|
if (!path.IsAbsolute()) {
|
|
|
|
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
|
|
|
promise.RejectWithErrorMessage("An absolute path was not provided");
|
2024-01-10 22:23:35 +00:00
|
|
|
return std::nullopt;
|
2023-03-20 14:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
browser_context =
|
|
|
|
ElectronBrowserContext::FromPath(std::move(path), std::move(options));
|
|
|
|
|
|
|
|
return CreateFrom(isolate, browser_context);
|
|
|
|
}
|
|
|
|
|
2023-02-20 20:57:38 +00:00
|
|
|
// static
|
|
|
|
gin::Handle<Session> Session::New() {
|
|
|
|
gin_helper::ErrorThrower(JavascriptEnvironment::GetIsolate())
|
|
|
|
.ThrowError("Session objects cannot be created with 'new'");
|
|
|
|
return gin::Handle<Session>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::FillObjectTemplate(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::ObjectTemplate> templ) {
|
2023-07-10 09:49:20 +00:00
|
|
|
gin::ObjectTemplateBuilder(isolate, GetClassName(), templ)
|
2023-04-05 14:06:14 +00:00
|
|
|
.SetMethod("resolveHost", &Session::ResolveHost)
|
2015-12-03 08:04:46 +00:00
|
|
|
.SetMethod("resolveProxy", &Session::ResolveProxy)
|
2019-04-30 22:09:17 +00:00
|
|
|
.SetMethod("getCacheSize", &Session::GetCacheSize)
|
|
|
|
.SetMethod("clearCache", &Session::ClearCache)
|
2015-12-03 08:04:46 +00:00
|
|
|
.SetMethod("clearStorageData", &Session::ClearStorageData)
|
2016-01-12 15:28:12 +00:00
|
|
|
.SetMethod("flushStorageData", &Session::FlushStorageData)
|
2015-12-03 08:04:46 +00:00
|
|
|
.SetMethod("setProxy", &Session::SetProxy)
|
2020-10-27 06:50:06 +00:00
|
|
|
.SetMethod("forceReloadProxyConfig", &Session::ForceReloadProxyConfig)
|
2015-12-03 08:04:46 +00:00
|
|
|
.SetMethod("setDownloadPath", &Session::SetDownloadPath)
|
|
|
|
.SetMethod("enableNetworkEmulation", &Session::EnableNetworkEmulation)
|
|
|
|
.SetMethod("disableNetworkEmulation", &Session::DisableNetworkEmulation)
|
2018-05-23 20:51:28 +00:00
|
|
|
.SetMethod("setCertificateVerifyProc", &Session::SetCertVerifyProc)
|
2016-01-31 21:35:34 +00:00
|
|
|
.SetMethod("setPermissionRequestHandler",
|
|
|
|
&Session::SetPermissionRequestHandler)
|
2018-08-28 14:05:08 +00:00
|
|
|
.SetMethod("setPermissionCheckHandler",
|
|
|
|
&Session::SetPermissionCheckHandler)
|
2022-08-22 21:15:32 +00:00
|
|
|
.SetMethod("setDisplayMediaRequestHandler",
|
|
|
|
&Session::SetDisplayMediaRequestHandler)
|
2021-09-23 11:00:11 +00:00
|
|
|
.SetMethod("setDevicePermissionHandler",
|
|
|
|
&Session::SetDevicePermissionHandler)
|
2023-05-30 16:35:25 +00:00
|
|
|
.SetMethod("setUSBProtectedClassesHandler",
|
|
|
|
&Session::SetUSBProtectedClassesHandler)
|
2022-09-26 14:19:58 +00:00
|
|
|
.SetMethod("setBluetoothPairingHandler",
|
|
|
|
&Session::SetBluetoothPairingHandler)
|
2016-02-01 13:33:23 +00:00
|
|
|
.SetMethod("clearHostResolverCache", &Session::ClearHostResolverCache)
|
2016-11-30 16:35:15 +00:00
|
|
|
.SetMethod("clearAuthCache", &Session::ClearAuthCache)
|
2016-05-23 05:29:55 +00:00
|
|
|
.SetMethod("allowNTLMCredentialsForDomains",
|
|
|
|
&Session::AllowNTLMCredentialsForDomains)
|
2020-03-11 07:02:22 +00:00
|
|
|
.SetMethod("isPersistent", &Session::IsPersistent)
|
2016-06-22 06:57:51 +00:00
|
|
|
.SetMethod("setUserAgent", &Session::SetUserAgent)
|
|
|
|
.SetMethod("getUserAgent", &Session::GetUserAgent)
|
2020-09-23 20:22:10 +00:00
|
|
|
.SetMethod("setSSLConfig", &Session::SetSSLConfig)
|
2016-08-23 05:57:43 +00:00
|
|
|
.SetMethod("getBlobData", &Session::GetBlobData)
|
2019-08-29 03:27:20 +00:00
|
|
|
.SetMethod("downloadURL", &Session::DownloadURL)
|
2016-11-18 10:43:43 +00:00
|
|
|
.SetMethod("createInterruptedDownload",
|
|
|
|
&Session::CreateInterruptedDownload)
|
2017-12-05 06:59:15 +00:00
|
|
|
.SetMethod("setPreloads", &Session::SetPreloads)
|
2017-09-16 15:05:49 +00:00
|
|
|
.SetMethod("getPreloads", &Session::GetPreloads)
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-01-13 22:56:28 +00:00
|
|
|
.SetMethod("loadExtension", &Session::LoadExtension)
|
|
|
|
.SetMethod("removeExtension", &Session::RemoveExtension)
|
|
|
|
.SetMethod("getExtension", &Session::GetExtension)
|
|
|
|
.SetMethod("getAllExtensions", &Session::GetAllExtensions)
|
2019-10-31 20:11:51 +00:00
|
|
|
#endif
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
.SetMethod("getSpellCheckerLanguages", &Session::GetSpellCheckerLanguages)
|
|
|
|
.SetMethod("setSpellCheckerLanguages", &Session::SetSpellCheckerLanguages)
|
|
|
|
.SetProperty("availableSpellCheckerLanguages",
|
|
|
|
&spellcheck::SpellCheckLanguages)
|
|
|
|
.SetMethod("setSpellCheckerDictionaryDownloadURL",
|
|
|
|
&SetSpellCheckerDictionaryDownloadURL)
|
2020-02-10 22:08:53 +00:00
|
|
|
.SetMethod("listWordsInSpellCheckerDictionary",
|
|
|
|
&Session::ListWordsInSpellCheckerDictionary)
|
2019-11-26 21:16:43 +00:00
|
|
|
.SetMethod("addWordToSpellCheckerDictionary",
|
|
|
|
&Session::AddWordToSpellCheckerDictionary)
|
2020-02-10 22:07:25 +00:00
|
|
|
.SetMethod("removeWordFromSpellCheckerDictionary",
|
|
|
|
&Session::RemoveWordFromSpellCheckerDictionary)
|
2020-11-11 15:29:18 +00:00
|
|
|
.SetMethod("setSpellCheckerEnabled", &Session::SetSpellCheckerEnabled)
|
|
|
|
.SetMethod("isSpellCheckerEnabled", &Session::IsSpellCheckerEnabled)
|
|
|
|
.SetProperty("spellCheckerEnabled", &Session::IsSpellCheckerEnabled,
|
|
|
|
&Session::SetSpellCheckerEnabled)
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2019-08-26 16:47:32 +00:00
|
|
|
.SetMethod("preconnect", &Session::Preconnect)
|
2020-10-08 16:45:36 +00:00
|
|
|
.SetMethod("closeAllConnections", &Session::CloseAllConnections)
|
2021-04-27 16:54:28 +00:00
|
|
|
.SetMethod("getStoragePath", &Session::GetPath)
|
2022-03-15 20:34:53 +00:00
|
|
|
.SetMethod("setCodeCachePath", &Session::SetCodeCachePath)
|
|
|
|
.SetMethod("clearCodeCaches", &Session::ClearCodeCaches)
|
2024-02-26 00:39:17 +00:00
|
|
|
.SetMethod("clearData", &Session::ClearData)
|
2015-12-01 04:52:22 +00:00
|
|
|
.SetProperty("cookies", &Session::Cookies)
|
2018-10-04 18:08:56 +00:00
|
|
|
.SetProperty("netLog", &Session::NetLog)
|
2016-06-08 14:31:27 +00:00
|
|
|
.SetProperty("protocol", &Session::Protocol)
|
2020-02-20 23:19:06 +00:00
|
|
|
.SetProperty("serviceWorkers", &Session::ServiceWorkerContext)
|
2021-04-27 16:54:28 +00:00
|
|
|
.SetProperty("webRequest", &Session::WebRequest)
|
2023-02-20 20:57:38 +00:00
|
|
|
.SetProperty("storagePath", &Session::GetPath)
|
|
|
|
.Build();
|
2015-12-03 08:04:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
const char* Session::GetTypeName() {
|
2023-07-10 09:49:20 +00:00
|
|
|
return GetClassName();
|
2020-05-19 17:18:12 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2015-09-01 10:02:14 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
using electron::api::Session;
|
2016-08-02 11:38:35 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
2020-05-19 17:18:12 +00:00
|
|
|
gin::Arguments* args) {
|
2019-06-19 21:23:04 +00:00
|
|
|
if (!electron::Browser::Get()->is_ready()) {
|
2020-05-19 17:18:12 +00:00
|
|
|
args->ThrowTypeError("Session can only be received when app is ready");
|
2016-07-12 11:21:59 +00:00
|
|
|
return v8::Null(args->isolate());
|
|
|
|
}
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict options;
|
2016-07-12 12:53:19 +00:00
|
|
|
args->GetNext(&options);
|
2019-10-30 05:30:59 +00:00
|
|
|
return Session::FromPartition(args->isolate(), partition, std::move(options))
|
|
|
|
.ToV8();
|
2016-07-12 11:21:59 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:34:49 +00:00
|
|
|
v8::Local<v8::Value> FromPath(const base::FilePath& path,
|
|
|
|
gin::Arguments* args) {
|
|
|
|
if (!electron::Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowTypeError("Session can only be received when app is ready");
|
|
|
|
return v8::Null(args->isolate());
|
|
|
|
}
|
|
|
|
base::Value::Dict options;
|
|
|
|
args->GetNext(&options);
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<gin::Handle<Session>> session_handle =
|
2023-03-20 14:34:49 +00:00
|
|
|
Session::FromPath(args->isolate(), path, std::move(options));
|
|
|
|
|
|
|
|
if (session_handle)
|
|
|
|
return session_handle.value().ToV8();
|
|
|
|
else
|
|
|
|
return v8::Null(args->isolate());
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2015-09-01 10:02:14 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2023-02-20 20:57:38 +00:00
|
|
|
dict.Set("Session", Session::GetConstructor(context));
|
2016-07-12 11:21:59 +00:00
|
|
|
dict.SetMethod("fromPartition", &FromPartition);
|
2023-03-20 14:34:49 +00:00
|
|
|
dict.SetMethod("fromPath", &FromPath);
|
2015-09-01 10:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-02-09 01:31:38 +00:00
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_session, Initialize)
|