mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
c08eaf90ca
- Bug 1142761 - Move CallSetter into ScriptedIndirectProxyHandler so it will eventually be deleted along with its only remaining caller. (a5a0b3f6b) - Bug 1143810 - Remove some XPConnect JSClass::setProperty hooks that are not needed anymore. (4eda6a60b) - Bug 1142195 - Remove some unused class declarations in the DOM Cache code (afd802623) - Bug 1145345 - Account for a greater variety of rounding errors when comparing coordinates (6a41f34f3) - Bug 1145787 - Put a misplaced assertion into its proper place. (7f760a66d) - Bug 1146059 - Remove Response.finalURL. (230d9fa50) - Bug 1134324 - Set CORS mode and credentials on Fetch event Request. r=michal (772fcac8f) - Bug 1136200 - Verify request type is not no-cors if response is opaque (396c9bfb4) - Bug 1144249 - fix fetch no-cors mode. r=bkelly (af9656291) - Bug 1144876 - Stop spamming stderr with a warning every time that we encounter a document that is not controlled by a service worker; (0a5c5fbfd) - Bug 1117172 part 1. Allow passing an optional aGivenProto to binding Wrap methods. (8aea85046) - Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv (13146be83) - Bug 1117172 part 3. Change the wrappercached WrapObject methods to al low passing in aGivenProto. r=peterv (1621ef48d) - Bug 1146293 - Fix coding style break (intent and line length) caused by Bug 1117172 and Bug 1145631. (0822709f1) - Bug 1121298 - Part 1: refactor MozNDEFRecord cstor. (6e57a37ec) - Bug 1121298 - Part 2: Add Constructor(uri) for MozNDEFRecord. (46f921bcf) - Bug 1121298 - Part 3. add getAsURI. (e67cad94b) - Bug 1138886 - Structured Clone for MozNDEFRecord. (With adaptations of Bug 1117172 part 3) (b83b7f684) - Bug 1143504 - Disconnect the Cache object from its actor when it gets cycle collected. (dae58dcdd)
219 lines
5.3 KiB
C++
219 lines
5.3 KiB
C++
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
/* 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 "SharedWorker.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/dom/SharedWorkerBinding.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsIClassInfoImpl.h"
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "MessagePort.h"
|
|
#include "RuntimeService.h"
|
|
#include "WorkerPrivate.h"
|
|
|
|
using mozilla::dom::Optional;
|
|
using mozilla::dom::Sequence;
|
|
using namespace mozilla;
|
|
|
|
USING_WORKERS_NAMESPACE
|
|
|
|
SharedWorker::SharedWorker(nsPIDOMWindow* aWindow,
|
|
WorkerPrivate* aWorkerPrivate)
|
|
: DOMEventTargetHelper(aWindow), mWorkerPrivate(aWorkerPrivate),
|
|
mSuspended(false)
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
mSerial = aWorkerPrivate->NextMessagePortSerial();
|
|
|
|
mMessagePort = new MessagePort(aWindow, this, mSerial);
|
|
}
|
|
|
|
SharedWorker::~SharedWorker()
|
|
{
|
|
AssertIsOnMainThread();
|
|
Close();
|
|
MOZ_ASSERT(!mWorkerPrivate);
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<SharedWorker>
|
|
SharedWorker::Constructor(const GlobalObject& aGlobal, JSContext* aCx,
|
|
const nsAString& aScriptURL,
|
|
const mozilla::dom::Optional<nsAString>& aName,
|
|
ErrorResult& aRv)
|
|
{
|
|
AssertIsOnMainThread();
|
|
|
|
RuntimeService* rts = RuntimeService::GetOrCreateService();
|
|
if (!rts) {
|
|
aRv = NS_ERROR_NOT_AVAILABLE;
|
|
return nullptr;
|
|
}
|
|
|
|
nsCString name;
|
|
if (aName.WasPassed()) {
|
|
name = NS_ConvertUTF16toUTF8(aName.Value());
|
|
}
|
|
|
|
nsRefPtr<SharedWorker> sharedWorker;
|
|
nsresult rv = rts->CreateSharedWorker(aGlobal, aScriptURL, name,
|
|
getter_AddRefs(sharedWorker));
|
|
if (NS_FAILED(rv)) {
|
|
aRv = rv;
|
|
return nullptr;
|
|
}
|
|
|
|
return sharedWorker.forget();
|
|
}
|
|
|
|
already_AddRefed<mozilla::dom::workers::MessagePort>
|
|
SharedWorker::Port()
|
|
{
|
|
AssertIsOnMainThread();
|
|
|
|
nsRefPtr<MessagePort> messagePort = mMessagePort;
|
|
return messagePort.forget();
|
|
}
|
|
|
|
void
|
|
SharedWorker::Suspend()
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(!IsSuspended());
|
|
|
|
mSuspended = true;
|
|
}
|
|
|
|
void
|
|
SharedWorker::Resume()
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(IsSuspended());
|
|
|
|
mSuspended = false;
|
|
|
|
if (!mSuspendedEvents.IsEmpty()) {
|
|
nsTArray<nsCOMPtr<nsIDOMEvent>> events;
|
|
mSuspendedEvents.SwapElements(events);
|
|
|
|
for (uint32_t index = 0; index < events.Length(); index++) {
|
|
nsCOMPtr<nsIDOMEvent>& event = events[index];
|
|
MOZ_ASSERT(event);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
if (NS_SUCCEEDED(event->GetTarget(getter_AddRefs(target)))) {
|
|
bool ignored;
|
|
if (NS_FAILED(target->DispatchEvent(event, &ignored))) {
|
|
NS_WARNING("Failed to dispatch event!");
|
|
}
|
|
} else {
|
|
NS_WARNING("Failed to get target!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
SharedWorker::QueueEvent(nsIDOMEvent* aEvent)
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(aEvent);
|
|
MOZ_ASSERT(IsSuspended());
|
|
|
|
mSuspendedEvents.AppendElement(aEvent);
|
|
}
|
|
|
|
void
|
|
SharedWorker::Close()
|
|
{
|
|
AssertIsOnMainThread();
|
|
|
|
if (mMessagePort) {
|
|
mMessagePort->Close();
|
|
}
|
|
|
|
if (mWorkerPrivate) {
|
|
AutoSafeJSContext cx;
|
|
NoteDeadWorker(cx);
|
|
}
|
|
}
|
|
|
|
void
|
|
SharedWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
const Optional<Sequence<JS::Value>>& aTransferable,
|
|
ErrorResult& aRv)
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
MOZ_ASSERT(mMessagePort);
|
|
|
|
mWorkerPrivate->PostMessageToMessagePort(aCx, mMessagePort->Serial(),
|
|
aMessage, aTransferable, aRv);
|
|
}
|
|
|
|
void
|
|
SharedWorker::NoteDeadWorker(JSContext* aCx)
|
|
{
|
|
AssertIsOnMainThread();
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mWorkerPrivate->UnregisterSharedWorker(aCx, this);
|
|
mWorkerPrivate = nullptr;
|
|
}
|
|
|
|
NS_IMPL_ADDREF_INHERITED(SharedWorker, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(SharedWorker, DOMEventTargetHelper)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SharedWorker)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SharedWorker)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SharedWorker,
|
|
DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessagePort)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedEvents)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SharedWorker,
|
|
DOMEventTargetHelper)
|
|
tmp->Close();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessagePort)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedEvents)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
JSObject*
|
|
SharedWorker::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
AssertIsOnMainThread();
|
|
|
|
return SharedWorkerBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
nsresult
|
|
SharedWorker::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|
{
|
|
AssertIsOnMainThread();
|
|
|
|
nsIDOMEvent*& event = aVisitor.mDOMEvent;
|
|
|
|
if (IsSuspended() && event) {
|
|
QueueEvent(event);
|
|
|
|
aVisitor.mCanHandle = false;
|
|
aVisitor.mParentTarget = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
return DOMEventTargetHelper::PreHandleEvent(aVisitor);
|
|
}
|