Bug 1339844 P1 Implement the Client.type attribute. r=asuth

This commit is contained in:
Ben Kelly 2017-02-15 15:12:37 -05:00
parent 902c3acb7b
commit 76b97762b7
3 changed files with 26 additions and 2 deletions

View File

@ -4,16 +4,23 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
* https://w3c.github.io/ServiceWorker/#client-interface
*
*/
[Exposed=ServiceWorker]
interface Client {
readonly attribute USVString url;
// Remove frameType in bug 1290936
readonly attribute FrameType frameType;
readonly attribute ClientType type;
readonly attribute DOMString id;
// Implement reserved in bug 1264177
// readonly attribute boolean reserved;
[Throws]
void postMessage(any message, optional sequence<object> transfer = []);
};
@ -23,6 +30,9 @@ interface WindowClient : Client {
readonly attribute VisibilityState visibilityState;
readonly attribute boolean focused;
// Implement ancestorOrigins in bug 1264180
// [SameObject] readonly attribute FrozenArray<USVString> ancestorOrigins;
[Throws, NewObject]
Promise<WindowClient> focus();
@ -30,6 +40,7 @@ interface WindowClient : Client {
Promise<WindowClient> navigate(USVString url);
};
// Remove FrameType in bug 1290936
enum FrameType {
"auxiliary",
"top-level",

View File

@ -34,7 +34,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerClient)
NS_INTERFACE_MAP_END
ServiceWorkerClientInfo::ServiceWorkerClientInfo(nsIDocument* aDoc)
: mWindowId(0)
: mType(ClientType::Window)
, mWindowId(0)
, mFrameType(FrameType::None)
{
MOZ_ASSERT(aDoc);
@ -82,6 +83,12 @@ ServiceWorkerClient::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProt
return ClientBinding::Wrap(aCx, this, aGivenProto);
}
ClientType
ServiceWorkerClient::Type() const
{
return mType;
}
namespace {
class ServiceWorkerClientPostMessageRunnable final

View File

@ -39,6 +39,7 @@ public:
}
private:
const mozilla::dom::ClientType mType;
nsString mClientId;
uint64_t mWindowId;
nsString mUrl;
@ -59,6 +60,7 @@ public:
ServiceWorkerClient(nsISupports* aOwner,
const ServiceWorkerClientInfo& aClientInfo)
: mOwner(aOwner)
, mType(aClientInfo.mType)
, mId(aClientInfo.mClientId)
, mUrl(aClientInfo.mUrl)
, mWindowId(aClientInfo.mWindowId)
@ -90,6 +92,9 @@ public:
return mFrameType;
}
mozilla::dom::ClientType
Type() const;
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
@ -102,6 +107,7 @@ protected:
private:
nsCOMPtr<nsISupports> mOwner;
const ClientType mType;
nsString mId;
nsString mUrl;