зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1268758 - Part1: Implement allow-presentation sandboxing flag, r=smaug
This commit is contained in:
Родитель
d4556d9101
Коммит
baf1057b0d
|
@ -23,3 +23,5 @@ SANDBOX_KEYWORD("allow-popups", allowpopups, SANDBOXED_AUXILIARY_NAVIGATION)
|
|||
SANDBOX_KEYWORD("allow-modals", allowmodals, SANDBOXED_MODALS)
|
||||
SANDBOX_KEYWORD("allow-popups-to-escape-sandbox", allowpopupstoescapesandbox,
|
||||
SANDBOX_PROPAGATES_TO_AUXILIARY_BROWSING_CONTEXTS)
|
||||
SANDBOX_KEYWORD("allow-presentation", allowpresentation,
|
||||
SANDBOXED_PRESENTATION)
|
||||
|
|
|
@ -84,6 +84,7 @@ GK_ATOM(alloworientationlock,"allow-orientation-lock")
|
|||
GK_ATOM(allowpointerlock,"allow-pointer-lock")
|
||||
GK_ATOM(allowpopupstoescapesandbox,"allow-popups-to-escape-sandbox")
|
||||
GK_ATOM(allowpopups,"allow-popups")
|
||||
GK_ATOM(allowpresentation,"allow-presentation")
|
||||
GK_ATOM(allowsameorigin,"allow-same-origin")
|
||||
GK_ATOM(allowscripts,"allow-scripts")
|
||||
GK_ATOM(allowtopnavigation,"allow-top-navigation")
|
||||
|
|
|
@ -108,5 +108,10 @@ const unsigned long SANDBOX_PROPAGATES_TO_AUXILIARY_BROWSING_CONTEXTS = 0x1000;
|
|||
*/
|
||||
const unsigned long SANDBOXED_ORIENTATION_LOCK = 0x2000;
|
||||
|
||||
const unsigned long SANDBOX_ALL_FLAGS = 0x3FFF;
|
||||
/**
|
||||
* This flag disables the Presentation API.
|
||||
*/
|
||||
const unsigned long SANDBOXED_PRESENTATION = 0x4000;
|
||||
|
||||
const unsigned long SANDBOX_ALL_FLAGS = 0x7FFF;
|
||||
#endif
|
||||
|
|
|
@ -4,15 +4,18 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Presentation.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mozilla/dom/PresentationBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIPresentationService.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "Presentation.h"
|
||||
#include "PresentationReceiver.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
@ -57,6 +60,15 @@ Presentation::SetDefaultRequest(PresentationRequest* aRequest)
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = GetOwner() ? GetOwner()->GetExtantDoc() : nullptr;
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
mDefaultRequest = aRequest;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "PresentationRequest.h"
|
||||
|
||||
#include "mozilla/dom/PresentationRequestBinding.h"
|
||||
#include "mozilla/dom/PresentationConnectionAvailableEvent.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
@ -11,10 +13,10 @@
|
|||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIPresentationService.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "PresentationAvailability.h"
|
||||
#include "PresentationCallbacks.h"
|
||||
#include "PresentationRequest.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -102,11 +104,22 @@ PresentationRequest::StartWithDevice(const nsAString& aDeviceId,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
||||
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Generate a session ID.
|
||||
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||
do_GetService("@mozilla.org/uuid-generator;1");
|
||||
|
@ -148,11 +161,22 @@ PresentationRequest::GetAvailability(ErrorResult& aRv)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
||||
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
promise->MaybeResolve(mAvailability);
|
||||
return promise.forget();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче