fix: ensure webcontents is destroyed before its associated browser context.

This commit is contained in:
deepak1556 2018-10-09 02:59:58 +05:30 committed by Jeremy Apthorp
parent a71755e1b6
commit 363aafc25b
4 changed files with 34 additions and 3 deletions

View file

@ -72,7 +72,7 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
bool in_memory,
const base::DictionaryValue& options)
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
base::SequencedTaskRunnerHandle::Get()),
base::ThreadTaskRunnerHandle::Get()),
in_memory_pref_store_(nullptr),
storage_policy_(new SpecialStoragePolicy),
in_memory_(in_memory),

View file

@ -205,8 +205,19 @@ void CommonWebContentsDelegate::SetOwnerWindow(
void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
if (async) {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
web_contents_.release());
// Browser context should be destroyed only after the WebContents,
// 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 {
web_contents_.reset();
}

View file

@ -477,3 +477,10 @@ patches:
Pass RenderProcessHost through to PlatformNotificationService.
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.

View 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
}