mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1139425 - Service Worker Client id should return a DOMString uuid. r=baku
This commit is contained in:
parent
346c28a446
commit
5cb6d620a6
@ -12844,6 +12844,35 @@ nsIDocument::CreateHTMLElement(nsIAtom* aTag)
|
||||
return element.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIDocument::GetId(nsAString& aId)
|
||||
{
|
||||
if (mId.IsEmpty()) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIUUIDGenerator> uuidgen = do_GetService("@mozilla.org/uuid-generator;1", &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsID id;
|
||||
rv = uuidgen->GenerateUUIDInPlace(&id);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Build a string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format
|
||||
char buffer[NSID_LENGTH];
|
||||
id.ToProvidedString(buffer);
|
||||
NS_ConvertASCIItoUTF16 uuid(buffer);
|
||||
|
||||
// Remove {} and the null terminator
|
||||
mId.Assign(Substring(uuid, 1, NSID_LENGTH - 3));
|
||||
}
|
||||
|
||||
aId = mId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData)
|
||||
{
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "nsILoadGroup.h" // for member (in nsCOMPtr)
|
||||
#include "nsINode.h" // for base class
|
||||
#include "nsIScriptGlobalObject.h" // for member (in nsCOMPtr)
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
#include "nsPIDOMWindow.h" // for use in inline functions
|
||||
#include "nsPropertyTable.h" // for member
|
||||
#include "nsTHashtable.h" // for member
|
||||
@ -747,6 +749,8 @@ public:
|
||||
return mAnonymousContents;
|
||||
}
|
||||
|
||||
nsresult GetId(nsAString& aId);
|
||||
|
||||
protected:
|
||||
virtual Element *GetRootElementInternal() const = 0;
|
||||
|
||||
@ -2798,6 +2802,7 @@ protected:
|
||||
nsCOMPtr<nsIChannel> mChannel;
|
||||
private:
|
||||
nsCString mContentType;
|
||||
nsString mId;
|
||||
protected:
|
||||
|
||||
// The document's security info
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
[Exposed=ServiceWorker]
|
||||
interface Client {
|
||||
readonly attribute DOMString id;
|
||||
readonly attribute USVString url;
|
||||
|
||||
[Throws]
|
||||
|
@ -31,8 +31,13 @@ ServiceWorkerClientInfo::ServiceWorkerClientInfo(nsIDocument* aDoc)
|
||||
MOZ_ASSERT(aDoc);
|
||||
MOZ_ASSERT(aDoc->GetWindow());
|
||||
|
||||
nsresult rv = aDoc->GetId(mClientId);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to get the UUID of the document.");
|
||||
}
|
||||
|
||||
nsRefPtr<nsGlobalWindow> outerWindow = static_cast<nsGlobalWindow*>(aDoc->GetWindow());
|
||||
mClientId = outerWindow->WindowID();
|
||||
mWindowId = outerWindow->WindowID();
|
||||
aDoc->GetURL(mUrl);
|
||||
mVisibilityState = aDoc->VisibilityState();
|
||||
|
||||
@ -61,15 +66,15 @@ namespace {
|
||||
|
||||
class ServiceWorkerClientPostMessageRunnable MOZ_FINAL : public nsRunnable
|
||||
{
|
||||
uint64_t mId;
|
||||
uint64_t mWindowId;
|
||||
JSAutoStructuredCloneBuffer mBuffer;
|
||||
nsTArray<nsCOMPtr<nsISupports>> mClonedObjects;
|
||||
|
||||
public:
|
||||
ServiceWorkerClientPostMessageRunnable(uint64_t aId,
|
||||
ServiceWorkerClientPostMessageRunnable(uint64_t aWindowId,
|
||||
JSAutoStructuredCloneBuffer&& aData,
|
||||
nsTArray<nsCOMPtr<nsISupports>>& aClonedObjects)
|
||||
: mId(aId),
|
||||
: mWindowId(aWindowId),
|
||||
mBuffer(Move(aData))
|
||||
{
|
||||
mClonedObjects.SwapElements(aClonedObjects);
|
||||
@ -79,7 +84,7 @@ public:
|
||||
Run()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
nsGlobalWindow* window = nsGlobalWindow::GetOuterWindowWithId(mId);
|
||||
nsGlobalWindow* window = nsGlobalWindow::GetOuterWindowWithId(mWindowId);
|
||||
if (!window) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -182,7 +187,7 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
||||
}
|
||||
|
||||
nsRefPtr<ServiceWorkerClientPostMessageRunnable> runnable =
|
||||
new ServiceWorkerClientPostMessageRunnable(mId, Move(buffer), clonedObjects);
|
||||
new ServiceWorkerClientPostMessageRunnable(mWindowId, Move(buffer), clonedObjects);
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
|
@ -31,7 +31,8 @@ public:
|
||||
explicit ServiceWorkerClientInfo(nsIDocument* aDoc);
|
||||
|
||||
private:
|
||||
uint64_t mClientId;
|
||||
nsString mClientId;
|
||||
uint64_t mWindowId;
|
||||
nsString mUrl;
|
||||
|
||||
// Window Clients
|
||||
@ -51,6 +52,7 @@ public:
|
||||
const ServiceWorkerClientInfo& aClientInfo)
|
||||
: mOwner(aOwner),
|
||||
mId(aClientInfo.mClientId),
|
||||
mWindowId(aClientInfo.mWindowId),
|
||||
mUrl(aClientInfo.mUrl)
|
||||
{
|
||||
MOZ_ASSERT(aOwner);
|
||||
@ -62,6 +64,11 @@ public:
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
void GetId(nsString& aRetval) const
|
||||
{
|
||||
aRetval = mId;
|
||||
}
|
||||
|
||||
void
|
||||
GetUrl(nsAString& aUrl) const
|
||||
{
|
||||
@ -81,7 +88,8 @@ protected:
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
uint64_t mId;
|
||||
nsString mId;
|
||||
uint64_t mWindowId;
|
||||
nsString mUrl;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user