Skip to content

Commit

Permalink
[WebPush] Add a warning that non-VAPID keys will be deprecated.
Browse files Browse the repository at this point in the history
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: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673296}
  • Loading branch information
rayankans authored and Commit Bot committed Jun 28, 2019
1 parent 64d1699 commit a3ddd69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions third_party/blink/renderer/modules/push_messaging/push_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#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/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_messaging_bridge.h"
#include "third_party/blink/renderer/modules/push_messaging/push_messaging_client.h"
Expand Down Expand Up @@ -66,6 +67,16 @@ ScriptPromise PushManager::subscribe(
if (exception_state.HadException())
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);
ScriptPromise promise = resolver->Promise();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ PushSubscriptionOptions::PushSubscriptionOptions(
application_server_key.data(),
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) {
visitor->Trace(application_server_key_);
ScriptWrappable::Trace(visitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class PushSubscriptionOptions final : public ScriptWrappable {
return application_server_key_;
}

// Whether the application server key follows the VAPID protocol.
bool IsApplicationServerKeyVapid() const;

void Trace(blink::Visitor* visitor) override;

private:
Expand Down

0 comments on commit a3ddd69

Please sign in to comment.