2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-09-14 05:39:57 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
2016-07-14 03:44:00 +03:00
|
|
|
#include "PresentationRequest.h"
|
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2016-08-17 11:15:32 +03:00
|
|
|
#include "AvailabilityCollection.h"
|
2016-08-02 20:11:00 +03:00
|
|
|
#include "ControllerConnectionCollection.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "Presentation.h"
|
|
|
|
#include "PresentationAvailability.h"
|
|
|
|
#include "PresentationCallbacks.h"
|
|
|
|
#include "PresentationLog.h"
|
|
|
|
#include "PresentationTransportBuilderConstructor.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2016-08-11 00:01:00 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-10-31 10:49:32 +03:00
|
|
|
#include "mozilla/dom/Navigator.h"
|
2015-10-12 05:36:31 +03:00
|
|
|
#include "mozilla/dom/PresentationConnectionAvailableEvent.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/dom/PresentationRequestBinding.h"
|
2015-09-14 05:39:57 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2016-08-11 00:01:00 +03:00
|
|
|
#include "nsContentSecurityManager.h"
|
2015-09-14 05:39:57 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2016-10-31 10:49:32 +03:00
|
|
|
#include "nsGlobalWindow.h"
|
2015-09-14 05:39:57 +03:00
|
|
|
#include "nsIPresentationService.h"
|
2016-08-03 10:35:36 +03:00
|
|
|
#include "nsIURI.h"
|
2015-09-14 05:39:57 +03:00
|
|
|
#include "nsIUUIDGenerator.h"
|
2016-08-03 10:35:36 +03:00
|
|
|
#include "nsNetUtil.h"
|
2016-07-14 03:44:00 +03:00
|
|
|
#include "nsSandboxFlags.h"
|
2015-09-14 05:39:57 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2020-08-09 17:53:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-09-14 05:39:57 +03:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(PresentationRequest, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PresentationRequest, DOMEventTargetHelper)
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PresentationRequest)
|
2015-09-14 05:39:57 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
2016-08-03 10:35:36 +03:00
|
|
|
static nsresult GetAbsoluteURL(const nsAString& aUrl, nsIURI* aBaseUri,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument, nsAString& aAbsoluteUrl) {
|
2016-08-03 10:35:36 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-06-18 14:37:50 +03:00
|
|
|
nsresult rv;
|
|
|
|
if (aDocument) {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), aUrl,
|
|
|
|
aDocument->GetDocumentCharacterSet(), aBaseUri);
|
|
|
|
} else {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), aUrl, nullptr, aBaseUri);
|
|
|
|
}
|
2016-08-03 10:35:36 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
|
2020-09-02 12:54:37 +03:00
|
|
|
CopyUTF8toUTF16(spec, aAbsoluteUrl);
|
2016-08-03 10:35:36 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<PresentationRequest> PresentationRequest::Constructor(
|
|
|
|
const GlobalObject& aGlobal, const nsAString& aUrl, ErrorResult& aRv) {
|
2016-09-05 02:17:00 +03:00
|
|
|
Sequence<nsString> urls;
|
2020-04-24 17:34:15 +03:00
|
|
|
if (!urls.AppendElement(aUrl, fallible)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
return Constructor(aGlobal, urls, aRv);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<PresentationRequest> PresentationRequest::Constructor(
|
|
|
|
const GlobalObject& aGlobal, const Sequence<nsString>& aUrls,
|
|
|
|
ErrorResult& aRv) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
2015-09-14 05:39:57 +03:00
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-09-05 02:17:00 +03:00
|
|
|
if (aUrls.IsEmpty()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2015-09-14 05:39:57 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-03 10:35:36 +03:00
|
|
|
// Resolve relative URL to absolute URL
|
|
|
|
nsCOMPtr<nsIURI> baseUri = window->GetDocBaseURI();
|
2016-09-05 02:17:00 +03:00
|
|
|
nsTArray<nsString> urls;
|
|
|
|
for (const auto& url : aUrls) {
|
|
|
|
nsAutoString absoluteUrl;
|
|
|
|
nsresult rv =
|
|
|
|
GetAbsoluteURL(url, baseUri, window->GetExtantDoc(), absoluteUrl);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-08-03 10:35:36 +03:00
|
|
|
|
2016-09-05 02:17:00 +03:00
|
|
|
urls.AppendElement(absoluteUrl);
|
2016-08-03 10:35:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PresentationRequest> request =
|
2018-05-30 22:15:35 +03:00
|
|
|
new PresentationRequest(window, std::move(urls));
|
2015-09-14 05:39:57 +03:00
|
|
|
return NS_WARN_IF(!request->Init()) ? nullptr : request.forget();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
PresentationRequest::PresentationRequest(nsPIDOMWindowInner* aWindow,
|
2016-09-05 02:17:00 +03:00
|
|
|
nsTArray<nsString>&& aUrls)
|
2015-09-14 05:39:57 +03:00
|
|
|
: DOMEventTargetHelper(aWindow), mUrls(std::move(aUrls)) {}
|
|
|
|
|
2020-03-09 18:14:19 +03:00
|
|
|
PresentationRequest::~PresentationRequest() = default;
|
2015-09-14 05:39:57 +03:00
|
|
|
|
|
|
|
bool PresentationRequest::Init() { return true; }
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* PresentationRequest::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return PresentationRequest_Binding::Wrap(aCx, this, aGivenProto);
|
2015-09-14 05:39:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> PresentationRequest::Start(ErrorResult& aRv) {
|
2017-09-22 07:35:46 +03:00
|
|
|
return StartWithDevice(VoidString(), aRv);
|
2016-01-13 14:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise> PresentationRequest::StartWithDevice(
|
|
|
|
const nsAString& aDeviceId, ErrorResult& aRv) {
|
2015-09-14 05:39:57 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (NS_WARN_IF(!global)) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the origin.
|
|
|
|
nsAutoString origin;
|
|
|
|
nsresult rv = nsContentUtils::GetUTFOrigin(global->PrincipalOrNull(), origin);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc = GetOwner()->GetExtantDoc();
|
2016-07-14 03:44:00 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2015-09-14 05:39:57 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:38:30 +03:00
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-11 00:01:00 +03:00
|
|
|
if (IsProhibitMixedSecurityContexts(doc) && !IsAllURLAuthenticated()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-07-14 03:44:00 +03:00
|
|
|
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
RefPtr<Navigator> navigator =
|
|
|
|
nsGlobalWindowInner::Cast(GetOwner())->Navigator();
|
2016-10-31 10:49:32 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Presentation> presentation = navigator->GetPresentation(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (presentation->IsStartSessionUnsettled()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-09-14 05:39:57 +03:00
|
|
|
// Generate a session ID.
|
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1");
|
|
|
|
if (NS_WARN_IF(!uuidgen)) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsID uuid;
|
|
|
|
uuidgen->GenerateUUIDInPlace(&uuid);
|
|
|
|
char buffer[NSID_LENGTH];
|
|
|
|
uuid.ToProvidedString(buffer);
|
|
|
|
nsAutoString id;
|
2020-08-07 10:49:47 +03:00
|
|
|
CopyASCIItoUTF16(Span(buffer, NSID_LENGTH - 1), id);
|
2015-09-14 05:39:57 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
|
|
if (NS_WARN_IF(!service)) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-10-31 10:49:32 +03:00
|
|
|
presentation->SetStartSessionUnsettled(true);
|
|
|
|
|
2016-08-31 15:56:17 +03:00
|
|
|
// Get xul:browser element in parent process or nsWindowRoot object in child
|
|
|
|
// process. If it's in child process, the corresponding xul:browser element
|
|
|
|
// will be obtained at PresentationRequestParent::DoRequest in its parent
|
|
|
|
// process.
|
2018-04-20 07:49:30 +03:00
|
|
|
nsCOMPtr<EventTarget> handler = GetOwner()->GetChromeEventHandler();
|
2016-10-04 09:27:05 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
|
2015-09-14 05:39:57 +03:00
|
|
|
nsCOMPtr<nsIPresentationServiceCallback> callback =
|
2016-09-05 02:17:00 +03:00
|
|
|
new PresentationRequesterCallback(this, id, promise);
|
2016-09-16 15:59:00 +03:00
|
|
|
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
|
|
|
|
PresentationTransportBuilderConstructor::Create();
|
|
|
|
rv = service->StartSession(mUrls, id, origin, aDeviceId,
|
|
|
|
GetOwner()->WindowID(), handler, principal,
|
|
|
|
callback, constructor);
|
2015-09-14 05:39:57 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
2016-10-31 10:49:32 +03:00
|
|
|
NotifyPromiseSettled();
|
2015-09-14 05:39:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:11:00 +03:00
|
|
|
already_AddRefed<Promise> PresentationRequest::Reconnect(
|
|
|
|
const nsAString& aPresentationId, ErrorResult& aRv) {
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (NS_WARN_IF(!global)) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc = GetOwner()->GetExtantDoc();
|
2016-08-02 20:11:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:38:30 +03:00
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-11 00:01:00 +03:00
|
|
|
if (IsProhibitMixedSecurityContexts(doc) && !IsAllURLAuthenticated()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:11:00 +03:00
|
|
|
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString presentationId = nsString(aPresentationId);
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<nsString, RefPtr<Promise>>(
|
|
|
|
"dom::PresentationRequest::FindOrCreatePresentationConnection", this,
|
|
|
|
&PresentationRequest::FindOrCreatePresentationConnection, presentationId,
|
|
|
|
promise);
|
2016-08-02 20:11:00 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(r)))) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresentationRequest::FindOrCreatePresentationConnection(
|
|
|
|
const nsAString& aPresentationId, Promise* aPromise) {
|
|
|
|
MOZ_ASSERT(aPromise);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!GetOwner())) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PresentationConnection> connection =
|
|
|
|
ControllerConnectionCollection::GetSingleton()->FindConnection(
|
|
|
|
GetOwner()->WindowID(), aPresentationId,
|
|
|
|
nsIPresentationService::ROLE_CONTROLLER);
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
nsAutoString url;
|
|
|
|
connection->GetUrl(url);
|
2016-09-05 02:17:00 +03:00
|
|
|
if (mUrls.Contains(url)) {
|
2016-08-02 20:11:00 +03:00
|
|
|
switch (connection->State()) {
|
|
|
|
case PresentationConnectionState::Closed:
|
|
|
|
// We found the matched connection.
|
|
|
|
break;
|
|
|
|
case PresentationConnectionState::Connecting:
|
|
|
|
case PresentationConnectionState::Connected:
|
|
|
|
aPromise->MaybeResolve(connection);
|
|
|
|
return;
|
|
|
|
case PresentationConnectionState::Terminated:
|
|
|
|
// A terminated connection cannot be reused.
|
|
|
|
connection = nullptr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown presentation session state.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
connection = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationService> service =
|
|
|
|
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
|
|
|
if (NS_WARN_IF(!service)) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationServiceCallback> callback =
|
|
|
|
new PresentationReconnectCallback(this, aPresentationId, aPromise,
|
|
|
|
connection);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-05 02:17:00 +03:00
|
|
|
nsresult rv = service->ReconnectSession(
|
2016-08-02 20:11:00 +03:00
|
|
|
mUrls, aPresentationId, nsIPresentationService::ROLE_CONTROLLER,
|
|
|
|
callback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 05:39:57 +03:00
|
|
|
already_AddRefed<Promise> PresentationRequest::GetAvailability(
|
|
|
|
ErrorResult& aRv) {
|
2016-09-05 02:17:00 +03:00
|
|
|
PRES_DEBUG("%s\n", __func__);
|
2015-09-14 05:39:57 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (NS_WARN_IF(!global)) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc = GetOwner()->GetExtantDoc();
|
2016-07-14 03:44:00 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2015-09-14 05:39:57 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:38:30 +03:00
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-11 00:01:00 +03:00
|
|
|
if (IsProhibitMixedSecurityContexts(doc) && !IsAllURLAuthenticated()) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-07-14 03:44:00 +03:00
|
|
|
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:15:32 +03:00
|
|
|
FindOrCreatePresentationAvailability(promise);
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresentationRequest::FindOrCreatePresentationAvailability(
|
|
|
|
RefPtr<Promise>& aPromise) {
|
|
|
|
MOZ_ASSERT(aPromise);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!GetOwner())) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AvailabilityCollection* collection = AvailabilityCollection::GetSingleton();
|
|
|
|
if (NS_WARN_IF(!collection)) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-31 05:31:15 +03:00
|
|
|
|
|
|
|
RefPtr<PresentationAvailability> availability =
|
2016-09-05 02:17:00 +03:00
|
|
|
collection->Find(GetOwner()->WindowID(), mUrls);
|
2016-08-31 05:31:15 +03:00
|
|
|
|
|
|
|
if (!availability) {
|
2016-09-05 02:17:00 +03:00
|
|
|
availability =
|
|
|
|
PresentationAvailability::Create(GetOwner(), mUrls, aPromise);
|
2016-08-17 11:15:32 +03:00
|
|
|
} else {
|
2016-09-05 02:17:00 +03:00
|
|
|
PRES_DEBUG(">resolve with same object\n");
|
2016-08-17 11:15:32 +03:00
|
|
|
|
|
|
|
// Fetching cached available devices is asynchronous in our implementation,
|
|
|
|
// we need to ensure the promise is resolved in order.
|
|
|
|
if (availability->IsCachedValueReady()) {
|
|
|
|
aPromise->MaybeResolve(availability);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
availability->EnqueuePromise(aPromise);
|
2016-08-31 05:31:15 +03:00
|
|
|
}
|
|
|
|
|
2016-08-17 11:15:32 +03:00
|
|
|
if (!availability) {
|
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-14 05:39:57 +03:00
|
|
|
}
|
2015-09-10 11:29:08 +03:00
|
|
|
|
2015-10-12 05:36:31 +03:00
|
|
|
nsresult PresentationRequest::DispatchConnectionAvailableEvent(
|
|
|
|
PresentationConnection* aConnection) {
|
2017-08-09 12:38:30 +03:00
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-12 05:36:31 +03:00
|
|
|
PresentationConnectionAvailableEventInit init;
|
|
|
|
init.mConnection = aConnection;
|
2015-09-10 11:29:08 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PresentationConnectionAvailableEvent> event =
|
2015-10-12 05:36:31 +03:00
|
|
|
PresentationConnectionAvailableEvent::Constructor(
|
|
|
|
this, u"connectionavailable"_ns, init);
|
2015-09-10 11:29:08 +03:00
|
|
|
if (NS_WARN_IF(!event)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
2015-09-10 11:29:08 +03:00
|
|
|
new AsyncEventDispatcher(this, event);
|
|
|
|
return asyncDispatcher->PostDOMEvent();
|
|
|
|
}
|
2016-08-11 00:01:00 +03:00
|
|
|
|
2016-10-31 10:49:32 +03:00
|
|
|
void PresentationRequest::NotifyPromiseSettled() {
|
|
|
|
PRES_DEBUG("%s\n", __func__);
|
|
|
|
|
|
|
|
if (!GetOwner()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
RefPtr<Navigator> navigator =
|
|
|
|
nsGlobalWindowInner::Cast(GetOwner())->Navigator();
|
2016-10-31 10:49:32 +03:00
|
|
|
if (!navigator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-14 05:40:03 +03:00
|
|
|
ErrorResult rv;
|
2016-10-31 10:49:32 +03:00
|
|
|
RefPtr<Presentation> presentation = navigator->GetPresentation(rv);
|
|
|
|
|
|
|
|
if (presentation) {
|
|
|
|
presentation->SetStartSessionUnsettled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
bool PresentationRequest::IsProhibitMixedSecurityContexts(Document* aDocument) {
|
2016-08-11 00:01:00 +03:00
|
|
|
MOZ_ASSERT(aDocument);
|
|
|
|
|
|
|
|
if (nsContentUtils::IsChromeDoc(aDocument)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc = aDocument;
|
2016-08-11 00:01:00 +03:00
|
|
|
while (doc && !nsContentUtils::IsChromeDoc(doc)) {
|
|
|
|
if (nsContentUtils::HttpsStateIsModern(doc)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-26 19:48:31 +03:00
|
|
|
doc = doc->GetInProcessParentDocument();
|
2016-08-11 00:01:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PresentationRequest::IsPrioriAuthenticatedURL(const nsAString& aUrl) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(uri), aUrl))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString scheme;
|
|
|
|
nsresult rv = uri->GetScheme(scheme);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scheme.EqualsLiteral("data")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString uriSpec;
|
|
|
|
rv = uri->GetSpec(uriSpec);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uriSpec.EqualsLiteral("about:blank") ||
|
|
|
|
uriSpec.EqualsLiteral("about:srcdoc")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes attrs;
|
2016-08-11 00:01:00 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
2019-07-08 19:37:45 +03:00
|
|
|
BasePrincipal::CreateContentPrincipal(uri, attrs);
|
2016-08-11 00:01:00 +03:00
|
|
|
if (NS_WARN_IF(!principal)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:01:54 +03:00
|
|
|
return principal->GetIsOriginPotentiallyTrustworthy();
|
2016-08-11 00:01:00 +03:00
|
|
|
}
|
2016-09-05 02:17:00 +03:00
|
|
|
|
|
|
|
bool PresentationRequest::IsAllURLAuthenticated() {
|
|
|
|
for (const auto& url : mUrls) {
|
|
|
|
if (!IsPrioriAuthenticatedURL(url)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-09 17:53:57 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|