fix: ensure webcontents is destroyed before its associated browser context.
This commit is contained in:
parent
a71755e1b6
commit
363aafc25b
4 changed files with 34 additions and 3 deletions
|
@ -72,7 +72,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||||
bool in_memory,
|
bool in_memory,
|
||||||
const base::DictionaryValue& options)
|
const base::DictionaryValue& options)
|
||||||
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
|
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
|
||||||
base::SequencedTaskRunnerHandle::Get()),
|
base::ThreadTaskRunnerHandle::Get()),
|
||||||
in_memory_pref_store_(nullptr),
|
in_memory_pref_store_(nullptr),
|
||||||
storage_policy_(new SpecialStoragePolicy),
|
storage_policy_(new SpecialStoragePolicy),
|
||||||
in_memory_(in_memory),
|
in_memory_(in_memory),
|
||||||
|
|
|
@ -205,8 +205,19 @@ void CommonWebContentsDelegate::SetOwnerWindow(
|
||||||
|
|
||||||
void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
|
void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
|
||||||
if (async) {
|
if (async) {
|
||||||
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
|
// Browser context should be destroyed only after the WebContents,
|
||||||
web_contents_.release());
|
// this is guaranteed in the sync mode by the order of declaration,
|
||||||
|
// in the async version we maintain a reference until the WebContents
|
||||||
|
// is destroyed.
|
||||||
|
// //electron/patches/common/chromium/content_browser_main_loop.patch
|
||||||
|
// is required to get the right quit closure for the main message loop.
|
||||||
|
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::BindOnce([](scoped_refptr<AtomBrowserContext> browser_context,
|
||||||
|
std::unique_ptr<brightray::InspectableWebContents>
|
||||||
|
web_contents) { web_contents.reset(); },
|
||||||
|
base::RetainedRef(browser_context_),
|
||||||
|
std::move(web_contents_)));
|
||||||
} else {
|
} else {
|
||||||
web_contents_.reset();
|
web_contents_.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -477,3 +477,10 @@ patches:
|
||||||
Pass RenderProcessHost through to PlatformNotificationService.
|
Pass RenderProcessHost through to PlatformNotificationService.
|
||||||
|
|
||||||
This is so Electron can identify which renderer a notification came from.
|
This is so Electron can identify which renderer a notification came from.
|
||||||
|
-
|
||||||
|
author: deepak1556 <hop2deep@gmail.com>
|
||||||
|
file: content_browser_main_loop.patch
|
||||||
|
description: |
|
||||||
|
Pass idle quit closure for main message loop, so that pending tasks are
|
||||||
|
run before shutdown. This is required to cleanup WebContents asynchronously
|
||||||
|
in atom::CommonWebContentsDelegate::ResetManageWebContents.
|
||||||
|
|
13
patches/common/chromium/content_browser_main_loop.patch
Normal file
13
patches/common/chromium/content_browser_main_loop.patch
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
|
||||||
|
index eb942391306e..9111cf18b7fc 100644
|
||||||
|
--- a/content/browser/browser_main_loop.cc
|
||||||
|
+++ b/content/browser/browser_main_loop.cc
|
||||||
|
@@ -1571,7 +1571,7 @@ void BrowserMainLoop::MainMessageLoopRun() {
|
||||||
|
}
|
||||||
|
|
||||||
|
base::RunLoop run_loop;
|
||||||
|
- parts_->PreDefaultMainMessageLoopRun(run_loop.QuitClosure());
|
||||||
|
+ parts_->PreDefaultMainMessageLoopRun(run_loop.QuitWhenIdleClosure());
|
||||||
|
run_loop.Run();
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue