mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
/* 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/. */
|
|
|
|
#include "mozilla/dom/PresentationBinding.h"
|
|
#include "mozilla/dom/Promise.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsIPresentationDeviceManager.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "Presentation.h"
|
|
#include "PresentationSession.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Presentation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Presentation, DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSession)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Presentation, DOMEventTargetHelper)
|
|
tmp->Shutdown();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSession)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Presentation, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(Presentation, DOMEventTargetHelper)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Presentation)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
/* static */ already_AddRefed<Presentation>
|
|
Presentation::Create(nsPIDOMWindow* aWindow)
|
|
{
|
|
nsRefPtr<Presentation> presentation = new Presentation(aWindow);
|
|
return NS_WARN_IF(!presentation->Init()) ? nullptr : presentation.forget();
|
|
}
|
|
|
|
Presentation::Presentation(nsPIDOMWindow* aWindow)
|
|
: DOMEventTargetHelper(aWindow)
|
|
, mAvailable(false)
|
|
{
|
|
}
|
|
|
|
Presentation::~Presentation()
|
|
{
|
|
Shutdown();
|
|
}
|
|
|
|
bool
|
|
Presentation::Init()
|
|
{
|
|
// TODO: Register listener for |mAvailable| changes.
|
|
|
|
return true;
|
|
}
|
|
|
|
void Presentation::Shutdown()
|
|
{
|
|
mSession = nullptr;
|
|
|
|
// TODO: Unregister listener for |mAvailable| changes.
|
|
}
|
|
|
|
/* virtual */ JSObject*
|
|
Presentation::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return PresentationBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
already_AddRefed<Promise>
|
|
Presentation::StartSession(const nsAString& aUrl,
|
|
const Optional<nsAString>& aId,
|
|
ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
if (NS_WARN_IF(!global)) {
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
return nullptr;
|
|
}
|
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return nullptr;
|
|
}
|
|
|
|
// TODO: Resolve/reject the promise.
|
|
|
|
return promise.forget();
|
|
}
|
|
|
|
already_AddRefed<PresentationSession>
|
|
Presentation::GetSession() const
|
|
{
|
|
nsRefPtr<PresentationSession> session = mSession;
|
|
return session.forget();
|
|
}
|
|
|
|
bool
|
|
Presentation::CachedAvailable() const
|
|
{
|
|
return mAvailable;
|
|
}
|