Commit a3ddd692 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[WebPush] Add a warning that non-VAPID keys will be deprecated.

Bug: 979235
Change-Id: I7f9ddf6c80f0e13707beec1f8827357cf2b21daf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1680469
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673296}
parent 64d16994
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/frame.h" #include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/modules/push_messaging/push_error.h" #include "third_party/blink/renderer/modules/push_messaging/push_error.h"
#include "third_party/blink/renderer/modules/push_messaging/push_messaging_bridge.h" #include "third_party/blink/renderer/modules/push_messaging/push_messaging_bridge.h"
#include "third_party/blink/renderer/modules/push_messaging/push_messaging_client.h" #include "third_party/blink/renderer/modules/push_messaging/push_messaging_client.h"
...@@ -66,6 +67,16 @@ ScriptPromise PushManager::subscribe( ...@@ -66,6 +67,16 @@ ScriptPromise PushManager::subscribe(
if (exception_state.HadException()) if (exception_state.HadException())
return ScriptPromise(); return ScriptPromise();
if (!options->IsApplicationServerKeyVapid()) {
ExecutionContext::From(script_state)
->AddConsoleMessage(ConsoleMessage::Create(
mojom::ConsoleMessageSource::kJavaScript,
mojom::ConsoleMessageLevel::kWarning,
"The provided application server key is not a VAPID key. Only "
"VAPID keys will be supported in the future. For more information "
"check https://crbug.com/979235."));
}
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
......
...@@ -98,6 +98,13 @@ PushSubscriptionOptions::PushSubscriptionOptions( ...@@ -98,6 +98,13 @@ PushSubscriptionOptions::PushSubscriptionOptions(
application_server_key.data(), application_server_key.data(),
SafeCast<unsigned>(application_server_key.size()))) {} SafeCast<unsigned>(application_server_key.size()))) {}
bool PushSubscriptionOptions::IsApplicationServerKeyVapid() const {
if (!application_server_key_)
return false;
return application_server_key_->ByteLength() == 65 &&
static_cast<uint8_t*>(application_server_key_->Data())[0] == 0x04;
}
void PushSubscriptionOptions::Trace(blink::Visitor* visitor) { void PushSubscriptionOptions::Trace(blink::Visitor* visitor) {
visitor->Trace(application_server_key_); visitor->Trace(application_server_key_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
......
...@@ -44,6 +44,9 @@ class PushSubscriptionOptions final : public ScriptWrappable { ...@@ -44,6 +44,9 @@ class PushSubscriptionOptions final : public ScriptWrappable {
return application_server_key_; return application_server_key_;
} }
// Whether the application server key follows the VAPID protocol.
bool IsApplicationServerKeyVapid() const;
void Trace(blink::Visitor* visitor) override; void Trace(blink::Visitor* visitor) override;
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment