From aaf012c1e2118b2f152111b577a24f04d02382f3 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Wed, 12 Aug 2020 07:53:35 +0000 Subject: [PATCH] Bug 1654803 - Fixing the crash issue in PermissionDelegateHandler::GetPermission(). r=baku At very rare situations, we won't be able to get the top level window context. Perhaps, it's the case that the window has been detached from the dom tree while checking the permission. So, we need to check the top level window context before we really use it. Differential Revision: https://phabricator.services.mozilla.com/D85978 --- extensions/permissions/PermissionDelegateHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/permissions/PermissionDelegateHandler.cpp b/extensions/permissions/PermissionDelegateHandler.cpp index 736b08c4d065..ef5b437b71a2 100644 --- a/extensions/permissions/PermissionDelegateHandler.cpp +++ b/extensions/permissions/PermissionDelegateHandler.cpp @@ -262,7 +262,7 @@ nsresult PermissionDelegateHandler::GetPermission(const nsACString& aType, bc) { RefPtr topWC = bc->GetTopWindowContext(); - if (topWC->IsInProcess()) { + if (topWC && topWC->IsInProcess()) { // If the top-level window context is in the same process, we directly get // the node principal from the top-level document to test the permission. // We cannot check the lists in the window context in this case since the @@ -276,7 +276,7 @@ nsresult PermissionDelegateHandler::GetPermission(const nsACString& aType, if (topDoc) { principal = topDoc->NodePrincipal(); } - } else { + } else if (topWC) { // Get the delegated permissions from the top-level window context. DelegatedPermissionList list = aExactHostMatch ? topWC->GetDelegatedExactHostMatchPermissions()