mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1206302 - Use DOMException
for Push errors. r=mt
--HG-- extra : commitid : 12nCKPtERml extra : rebase_source : 1d59f113235a98ca30653d2c935e0cc2e7bc8931
This commit is contained in:
parent
504eab4598
commit
1a2d174fbf
@ -87,6 +87,9 @@ enum DOM4ErrorTypeCodeMap {
|
||||
BtAuthFailureError = 0,
|
||||
BtRmtDevDownError = 0,
|
||||
BtAuthRejectedError = 0,
|
||||
|
||||
/* Push API errors */
|
||||
PermissionDeniedError = 0,
|
||||
};
|
||||
|
||||
#define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message},
|
||||
|
@ -151,5 +151,11 @@ DOM4_MSG_DEF(InvalidStateError, "A mutation operation was attempted on a file st
|
||||
DOM4_MSG_DEF(AbortError, "A request was aborted, for example through a call to FileHandle.abort.", NS_ERROR_DOM_FILEHANDLE_ABORT_ERR)
|
||||
DOM4_MSG_DEF(QuotaExceededError, "The current file handle exceeded its quota limitations.", NS_ERROR_DOM_FILEHANDLE_QUOTA_ERR)
|
||||
|
||||
/* Push API errors. */
|
||||
DOM4_MSG_DEF(InvalidStateError, "Invalid service worker registration.", NS_ERROR_DOM_PUSH_INVALID_REGISTRATION_ERR)
|
||||
DOM4_MSG_DEF(PermissionDeniedError, "User denied permission to use the Push API.", NS_ERROR_DOM_PUSH_DENIED_ERR)
|
||||
DOM4_MSG_DEF(AbortError, "Error retrieving push subscription.", NS_ERROR_DOM_PUSH_ABORT_ERR)
|
||||
DOM4_MSG_DEF(NetworkError, "Push service unreachable.", NS_ERROR_DOM_PUSH_SERVICE_UNREACHABLE)
|
||||
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_JS_EXCEPTION, "A callback threw an exception")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_DOMEXCEPTION, "A DOMException was thrown")
|
||||
|
@ -68,9 +68,12 @@ Push.prototype = {
|
||||
debug("askPermission");
|
||||
|
||||
return this.createPromise((resolve, reject) => {
|
||||
function permissionDenied() {
|
||||
reject("PermissionDeniedError");
|
||||
}
|
||||
let permissionDenied = () => {
|
||||
reject(new this._window.DOMException(
|
||||
"User denied permission to use the Push API",
|
||||
"PermissionDeniedError"
|
||||
));
|
||||
};
|
||||
|
||||
let permission = Ci.nsIPermissionManager.UNKNOWN_ACTION;
|
||||
try {
|
||||
@ -190,7 +193,10 @@ PushEndpointCallback.prototype = {
|
||||
onPushEndpoint: function(ok, endpoint, keyLen, key) {
|
||||
let {pushManager} = this;
|
||||
if (!Components.isSuccessCode(ok)) {
|
||||
this.reject("AbortError");
|
||||
this.reject(new pushManager._window.DOMException(
|
||||
"Error retrieving push subscription",
|
||||
"AbortError"
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -426,12 +426,13 @@ public:
|
||||
do_CreateInstance("@mozilla.org/push/PushClient;1");
|
||||
if (!client) {
|
||||
callback->OnUnsubscribe(NS_ERROR_FAILURE, false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = mProxy->GetWorkerPrivate()->GetPrincipal();
|
||||
if (NS_WARN_IF(NS_FAILED(client->Unsubscribe(mScope, principal, callback)))) {
|
||||
callback->OnUnsubscribe(NS_ERROR_FAILURE, false);
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -521,7 +522,7 @@ public:
|
||||
promise->MaybeResolve(sub);
|
||||
}
|
||||
} else {
|
||||
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
||||
promise->MaybeReject(NS_ERROR_DOM_PUSH_ABORT_ERR);
|
||||
}
|
||||
|
||||
mProxy->CleanUp(aCx);
|
||||
@ -647,7 +648,7 @@ public:
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
callback->OnPushEndpoint(NS_ERROR_FAILURE, EmptyString(), 0, nullptr);
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -677,7 +678,7 @@ WorkerPushManager::PerformSubscriptionAction(SubscriptionAction aAction, ErrorRe
|
||||
|
||||
RefPtr<PromiseWorkerProxy> proxy = PromiseWorkerProxy::Create(worker, p);
|
||||
if (!proxy) {
|
||||
p->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
||||
p->MaybeReject(NS_ERROR_DOM_PUSH_ABORT_ERR);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,8 @@ http://creativecommons.org/licenses/publicdomain/
|
||||
yield registration.pushManager.subscribe();
|
||||
ok(false, "subscribe() should fail because no permission for push");
|
||||
} catch (error) {
|
||||
ok(true, "subscribe() could not register for push notification");
|
||||
ok(error instanceof DOMException, "Wrong exception type");
|
||||
is(error.name, "PermissionDeniedError", "Wrong exception name");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -926,6 +926,16 @@
|
||||
ERROR(NS_ERROR_DOM_ANIM_NO_TARGET_ERR, FAILURE(2)),
|
||||
#undef MODULE
|
||||
|
||||
/* ======================================================================= */
|
||||
/* 40: NS_ERROR_MODULE_DOM_PUSH */
|
||||
/* ======================================================================= */
|
||||
#define MODULE NS_ERROR_MODULE_DOM_PUSH
|
||||
ERROR(NS_ERROR_DOM_PUSH_INVALID_REGISTRATION_ERR, FAILURE(1)),
|
||||
ERROR(NS_ERROR_DOM_PUSH_DENIED_ERR, FAILURE(2)),
|
||||
ERROR(NS_ERROR_DOM_PUSH_ABORT_ERR, FAILURE(3)),
|
||||
ERROR(NS_ERROR_DOM_PUSH_SERVICE_UNREACHABLE, FAILURE(4)),
|
||||
#undef MODULE
|
||||
|
||||
/* ======================================================================= */
|
||||
/* 51: NS_ERROR_MODULE_GENERAL */
|
||||
/* ======================================================================= */
|
||||
|
@ -77,6 +77,7 @@
|
||||
#define NS_ERROR_MODULE_DOM_BLUETOOTH 37
|
||||
#define NS_ERROR_MODULE_SIGNED_APP 38
|
||||
#define NS_ERROR_MODULE_DOM_ANIM 39
|
||||
#define NS_ERROR_MODULE_DOM_PUSH 40
|
||||
|
||||
/* NS_ERROR_MODULE_GENERAL should be used by modules that do not
|
||||
* care if return code values overlap. Callers of methods that
|
||||
|
Loading…
Reference in New Issue
Block a user