fix: browser contexts live forever (#24964)
This commit is contained in:
parent
befbbc27d8
commit
bac2f46ba9
11 changed files with 68 additions and 73 deletions
|
@ -276,7 +276,7 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
|||
|
||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||
SpellcheckService* service =
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
||||
if (service) {
|
||||
service->SetHunspellObserver(this);
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ Session::~Session() {
|
|||
|
||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||
SpellcheckService* service =
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
||||
if (service) {
|
||||
service->SetHunspellObserver(nullptr);
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ v8::Local<v8::Promise> Session::GetCacheSize() {
|
|||
gin_helper::Promise<int64_t> promise(isolate);
|
||||
auto handle = promise.GetHandle();
|
||||
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext()
|
||||
->ComputeHttpCacheSize(
|
||||
base::Time(), base::Time::Max(),
|
||||
|
@ -375,7 +375,7 @@ v8::Local<v8::Promise> Session::ClearCache() {
|
|||
gin_helper::Promise<void> promise(isolate);
|
||||
auto handle = promise.GetHandle();
|
||||
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext()
|
||||
->ClearHttpCache(base::Time(), base::Time::Max(), nullptr,
|
||||
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
||||
|
@ -471,17 +471,17 @@ void Session::EnableNetworkEmulation(const gin_helper::Dictionary& options) {
|
|||
conditions->latency = base::TimeDelta::FromMillisecondsD(latency);
|
||||
}
|
||||
|
||||
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
|
||||
browser_context_.get())
|
||||
->GetNetworkContext();
|
||||
auto* network_context =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext();
|
||||
network_context->SetNetworkConditions(network_emulation_token_,
|
||||
std::move(conditions));
|
||||
}
|
||||
|
||||
void Session::DisableNetworkEmulation() {
|
||||
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
|
||||
browser_context_.get())
|
||||
->GetNetworkContext();
|
||||
auto* network_context =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext();
|
||||
network_context->SetNetworkConditions(
|
||||
network_emulation_token_, network::mojom::NetworkConditions::New());
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
|||
std::make_unique<CertVerifierClient>(proc),
|
||||
cert_verifier_client_remote.InitWithNewPipeAndPassReceiver());
|
||||
}
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext()
|
||||
->SetCertVerifierClient(std::move(cert_verifier_client_remote));
|
||||
|
||||
|
@ -553,7 +553,7 @@ v8::Local<v8::Promise> Session::ClearHostResolverCache(gin::Arguments* args) {
|
|||
gin_helper::Promise<void> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext()
|
||||
->ClearHostCache(nullptr,
|
||||
base::BindOnce(gin_helper::Promise<void>::ResolvePromise,
|
||||
|
@ -567,7 +567,7 @@ v8::Local<v8::Promise> Session::ClearAuthCache() {
|
|||
gin_helper::Promise<void> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext()
|
||||
->ClearHttpAuthCache(
|
||||
base::Time(),
|
||||
|
@ -593,9 +593,9 @@ void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
|
|||
void Session::SetUserAgent(const std::string& user_agent,
|
||||
gin::Arguments* args) {
|
||||
browser_context_->SetUserAgent(user_agent);
|
||||
auto* network_context = content::BrowserContext::GetDefaultStoragePartition(
|
||||
browser_context_.get())
|
||||
->GetNetworkContext();
|
||||
auto* network_context =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetNetworkContext();
|
||||
network_context->SetUserAgent(user_agent);
|
||||
|
||||
std::string accept_lang;
|
||||
|
@ -781,10 +781,9 @@ v8::Local<v8::Value> Session::NetLog(v8::Isolate* isolate) {
|
|||
return net_log_.Get(isolate);
|
||||
}
|
||||
|
||||
static void StartPreconnectOnUI(
|
||||
scoped_refptr<ElectronBrowserContext> browser_context,
|
||||
const GURL& url,
|
||||
int num_sockets_to_preconnect) {
|
||||
static void StartPreconnectOnUI(ElectronBrowserContext* browser_context,
|
||||
const GURL& url,
|
||||
int num_sockets_to_preconnect) {
|
||||
std::vector<predictors::PreconnectRequest> requests = {
|
||||
{url::Origin::Create(url), num_sockets_to_preconnect,
|
||||
net::NetworkIsolationKey()}};
|
||||
|
@ -815,7 +814,7 @@ void Session::Preconnect(const gin_helper::Dictionary& options,
|
|||
DCHECK_GT(num_sockets_to_preconnect, 0);
|
||||
base::PostTask(
|
||||
FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(&StartPreconnectOnUI, base::RetainedRef(browser_context_),
|
||||
base::BindOnce(&StartPreconnectOnUI, base::Unretained(browser_context_),
|
||||
url, num_sockets_to_preconnect));
|
||||
}
|
||||
|
||||
|
@ -860,7 +859,7 @@ v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
|
|||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
SpellcheckService* spellcheck =
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
||||
|
||||
if (!spellcheck)
|
||||
promise.RejectWithErrorMessage(
|
||||
|
@ -886,7 +885,7 @@ bool Session::AddWordToSpellCheckerDictionary(const std::string& word) {
|
|||
return false;
|
||||
|
||||
SpellcheckService* service =
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
||||
if (!service)
|
||||
return false;
|
||||
|
||||
|
@ -907,7 +906,7 @@ bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) {
|
|||
return false;
|
||||
|
||||
SpellcheckService* service =
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||
SpellcheckServiceFactory::GetForContext(browser_context_);
|
||||
if (!service)
|
||||
return false;
|
||||
|
||||
|
@ -953,7 +952,7 @@ gin::Handle<Session> Session::CreateFrom(
|
|||
gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
|
||||
const std::string& partition,
|
||||
base::DictionaryValue options) {
|
||||
scoped_refptr<ElectronBrowserContext> browser_context;
|
||||
ElectronBrowserContext* browser_context;
|
||||
if (partition.empty()) {
|
||||
browser_context =
|
||||
ElectronBrowserContext::From("", false, std::move(options));
|
||||
|
@ -966,7 +965,7 @@ gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
|
|||
browser_context =
|
||||
ElectronBrowserContext::From(partition, true, std::move(options));
|
||||
}
|
||||
return CreateFrom(isolate, browser_context.get());
|
||||
return CreateFrom(isolate, browser_context);
|
||||
}
|
||||
|
||||
gin::ObjectTemplateBuilder Session::GetObjectTemplateBuilder(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue