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

@ -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();
}