зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1550569 part 2. Stop using [array] in nsIPushService. r=dragana
Differential Revision: https://phabricator.services.mozilla.com/D30551 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
dbeea27f14
Коммит
767491f74e
|
@ -24,9 +24,7 @@ interface nsIPushSubscription : nsISupports
|
|||
bool quotaApplies();
|
||||
bool isExpired();
|
||||
|
||||
void getKey(in AString name,
|
||||
[optional] out uint32_t keyLen,
|
||||
[array, size_is(keyLen), retval] out uint8_t key);
|
||||
Array<uint8_t> getKey(in AString name);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -105,8 +103,7 @@ interface nsIPushService : nsISupports
|
|||
* message delivery requests, as described in draft-thomson-webpush-vapid.
|
||||
*/
|
||||
void subscribeWithKey(in AString scope, in nsIPrincipal principal,
|
||||
in uint32_t keyLength,
|
||||
[const, array, size_is(keyLength)] in uint8_t key,
|
||||
in Array<uint8_t> key,
|
||||
in nsIPushSubscriptionCallback callback);
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,8 +96,7 @@ Push.prototype = {
|
|||
return;
|
||||
}
|
||||
PushService.subscribeWithKey(this._scope, this._principal,
|
||||
keyView.byteLength, keyView,
|
||||
callback);
|
||||
keyView, callback);
|
||||
})
|
||||
);
|
||||
},
|
||||
|
@ -240,14 +239,13 @@ PushSubscriptionCallback.prototype = {
|
|||
},
|
||||
|
||||
_getKey(subscription, name) {
|
||||
let outKeyLen = {};
|
||||
let rawKey = Cu.cloneInto(subscription.getKey(name, outKeyLen),
|
||||
let rawKey = Cu.cloneInto(subscription.getKey(name),
|
||||
this.pushManager._window);
|
||||
if (!outKeyLen.value) {
|
||||
if (!rawKey.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let key = new this.pushManager._window.ArrayBuffer(outKeyLen.value);
|
||||
let key = new this.pushManager._window.ArrayBuffer(rawKey.length);
|
||||
let keyView = new this.pushManager._window.Uint8Array(key);
|
||||
keyView.set(rawKey);
|
||||
return key;
|
||||
|
|
|
@ -141,10 +141,10 @@ Object.assign(PushServiceParent.prototype, {
|
|||
// nsIPushService methods
|
||||
|
||||
subscribe(scope, principal, callback) {
|
||||
this.subscribeWithKey(scope, principal, 0, null, callback);
|
||||
this.subscribeWithKey(scope, principal, [], callback);
|
||||
},
|
||||
|
||||
subscribeWithKey(scope, principal, keyLen, key, callback) {
|
||||
subscribeWithKey(scope, principal, key, callback) {
|
||||
this._handleRequest("Push:Register", principal, {
|
||||
scope,
|
||||
appServerKey: key,
|
||||
|
@ -348,10 +348,10 @@ Object.assign(PushServiceContent.prototype, {
|
|||
// nsIPushService methods
|
||||
|
||||
subscribe(scope, principal, callback) {
|
||||
this.subscribeWithKey(scope, principal, 0, null, callback);
|
||||
this.subscribeWithKey(scope, principal, [], callback);
|
||||
},
|
||||
|
||||
subscribeWithKey(scope, principal, keyLen, key, callback) {
|
||||
subscribeWithKey(scope, principal, key, callback) {
|
||||
let requestID = this._addRequest(callback);
|
||||
this._mm.sendAsyncMessage("Push:Register", {
|
||||
scope,
|
||||
|
@ -529,29 +529,25 @@ PushSubscription.prototype = {
|
|||
* callers receive the key buffer as a return value, while C++ callers
|
||||
* receive the key size and buffer as out parameters.
|
||||
*/
|
||||
getKey(name, outKeyLen) {
|
||||
getKey(name) {
|
||||
switch (name) {
|
||||
case "p256dh":
|
||||
return this._getRawKey(this._props.p256dhKey, outKeyLen);
|
||||
return this._getRawKey(this._props.p256dhKey);
|
||||
|
||||
case "auth":
|
||||
return this._getRawKey(this._props.authenticationSecret, outKeyLen);
|
||||
return this._getRawKey(this._props.authenticationSecret);
|
||||
|
||||
case "appServer":
|
||||
return this._getRawKey(this._props.appServerKey, outKeyLen);
|
||||
return this._getRawKey(this._props.appServerKey);
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
},
|
||||
|
||||
_getRawKey(key, outKeyLen) {
|
||||
_getRawKey(key) {
|
||||
if (!key) {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
let rawKey = new Uint8Array(key);
|
||||
if (outKeyLen) {
|
||||
outKeyLen.value = rawKey.length;
|
||||
}
|
||||
return rawKey;
|
||||
return new Uint8Array(key);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -61,38 +61,6 @@ nsresult GetPermissionState(nsIPrincipal* aPrincipal,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// A helper class that frees an `nsIPushSubscription` key buffer when it
|
||||
// goes out of scope.
|
||||
class MOZ_RAII AutoFreeKeyBuffer final {
|
||||
uint8_t** mKeyBuffer;
|
||||
|
||||
public:
|
||||
explicit AutoFreeKeyBuffer(uint8_t** aKeyBuffer) : mKeyBuffer(aKeyBuffer) {
|
||||
MOZ_ASSERT(mKeyBuffer);
|
||||
}
|
||||
|
||||
~AutoFreeKeyBuffer() { free(*mKeyBuffer); }
|
||||
};
|
||||
|
||||
// Copies a subscription key buffer into an array.
|
||||
nsresult CopySubscriptionKeyToArray(nsIPushSubscription* aSubscription,
|
||||
const nsAString& aKeyName,
|
||||
nsTArray<uint8_t>& aKey) {
|
||||
uint8_t* keyBuffer = nullptr;
|
||||
AutoFreeKeyBuffer autoFree(&keyBuffer);
|
||||
|
||||
uint32_t keyLen;
|
||||
nsresult rv = aSubscription->GetKey(aKeyName, &keyLen, &keyBuffer);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
if (!aKey.SetCapacity(keyLen, fallible) ||
|
||||
!aKey.InsertElementsAt(0, keyBuffer, keyLen, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult GetSubscriptionParams(nsIPushSubscription* aSubscription,
|
||||
nsAString& aEndpoint,
|
||||
nsTArray<uint8_t>& aRawP256dhKey,
|
||||
|
@ -107,18 +75,15 @@ nsresult GetSubscriptionParams(nsIPushSubscription* aSubscription,
|
|||
return rv;
|
||||
}
|
||||
|
||||
rv = CopySubscriptionKeyToArray(aSubscription, NS_LITERAL_STRING("p256dh"),
|
||||
aRawP256dhKey);
|
||||
rv = aSubscription->GetKey(NS_LITERAL_STRING("p256dh"), aRawP256dhKey);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
rv = CopySubscriptionKeyToArray(aSubscription, NS_LITERAL_STRING("auth"),
|
||||
aAuthSecret);
|
||||
rv = aSubscription->GetKey(NS_LITERAL_STRING("auth"), aAuthSecret);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
rv = CopySubscriptionKeyToArray(aSubscription, NS_LITERAL_STRING("appServer"),
|
||||
aAppServerKey);
|
||||
rv = aSubscription->GetKey(NS_LITERAL_STRING("appServer"), aAppServerKey);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -290,9 +255,8 @@ class GetSubscriptionRunnable final : public Runnable {
|
|||
if (mAppServerKey.IsEmpty()) {
|
||||
rv = service->Subscribe(mScope, principal, callback);
|
||||
} else {
|
||||
rv =
|
||||
service->SubscribeWithKey(mScope, principal, mAppServerKey.Length(),
|
||||
mAppServerKey.Elements(), callback);
|
||||
rv = service->SubscribeWithKey(mScope, principal, mAppServerKey,
|
||||
callback);
|
||||
}
|
||||
} else {
|
||||
MOZ_ASSERT(mAction == PushManager::GetSubscriptionAction);
|
||||
|
|
|
@ -1021,7 +1021,8 @@ var PushService = {
|
|||
console.debug("register()", aPageRecord);
|
||||
|
||||
let keyPromise;
|
||||
if (aPageRecord.appServerKey) {
|
||||
if (aPageRecord.appServerKey &&
|
||||
aPageRecord.appServerKey.length != 0) {
|
||||
let keyView = new Uint8Array(aPageRecord.appServerKey);
|
||||
keyPromise = PushCrypto.validateAppServerKey(keyView)
|
||||
.catch(error => {
|
||||
|
|
|
@ -64,7 +64,6 @@ add_test(function test_subscribeWithKey_error() {
|
|||
PushServiceComponent.subscribeWithKey(
|
||||
"https://example.com/sub-key/invalid",
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
invalidKey.length,
|
||||
invalidKey,
|
||||
(result, subscription) => {
|
||||
ok(!Components.isSuccessCode(result), "Expected error creating subscription with invalid key");
|
||||
|
@ -84,7 +83,6 @@ add_test(function test_subscribeWithKey_success() {
|
|||
PushServiceComponent.subscribeWithKey(
|
||||
"https://example.com/sub-key/ok",
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
key.length,
|
||||
key,
|
||||
(result, subscription) => {
|
||||
ok(Components.isSuccessCode(result), "Error creating subscription with key");
|
||||
|
@ -105,7 +103,6 @@ add_test(function test_subscribeWithKey_conflict() {
|
|||
PushServiceComponent.subscribeWithKey(
|
||||
"https://example.com/sub-key/ok",
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
differentKey.length,
|
||||
differentKey,
|
||||
(result, subscription) => {
|
||||
ok(!Components.isSuccessCode(result), "Expected error creating subscription with conflicting key");
|
||||
|
|
Загрузка…
Ссылка в новой задаче