Commit 6cdde421 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate PushMessagingClient to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I666b8ade1cd0ea9043df7978a01eb4537fbbc713
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109396
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755291}
parent 3424a65a
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h" #include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/modules/manifest/manifest_manager.h" #include "third_party/blink/renderer/modules/manifest/manifest_manager.h"
#include "third_party/blink/renderer/modules/push_messaging/push_error.h" #include "third_party/blink/renderer/modules/push_messaging/push_error.h"
...@@ -30,7 +31,8 @@ namespace blink { ...@@ -30,7 +31,8 @@ namespace blink {
const char PushMessagingClient::kSupplementName[] = "PushMessagingClient"; const char PushMessagingClient::kSupplementName[] = "PushMessagingClient";
PushMessagingClient::PushMessagingClient(LocalFrame& frame) PushMessagingClient::PushMessagingClient(LocalFrame& frame)
: Supplement<LocalFrame>(frame) { : Supplement<LocalFrame>(frame),
push_messaging_manager_(frame.DomWindow()) {
// This class will be instantiated for every page load (rather than on push // This class will be instantiated for every page load (rather than on push
// messaging use), so there's nothing to be done in this constructor. // messaging use), so there's nothing to be done in this constructor.
} }
...@@ -42,7 +44,7 @@ PushMessagingClient* PushMessagingClient::From(LocalFrame* frame) { ...@@ -42,7 +44,7 @@ PushMessagingClient* PushMessagingClient::From(LocalFrame* frame) {
} }
mojom::blink::PushMessaging* PushMessagingClient::GetPushMessagingRemote() { mojom::blink::PushMessaging* PushMessagingClient::GetPushMessagingRemote() {
if (!push_messaging_manager_) { if (!push_messaging_manager_.is_bound()) {
GetSupplementable()->GetBrowserInterfaceBroker().GetInterface( GetSupplementable()->GetBrowserInterfaceBroker().GetInterface(
push_messaging_manager_.BindNewPipeAndPassReceiver( push_messaging_manager_.BindNewPipeAndPassReceiver(
GetSupplementable()->GetTaskRunner(TaskType::kMiscPlatformAPI))); GetSupplementable()->GetTaskRunner(TaskType::kMiscPlatformAPI)));
...@@ -76,6 +78,11 @@ void PushMessagingClient::Subscribe( ...@@ -76,6 +78,11 @@ void PushMessagingClient::Subscribe(
} }
} }
void PushMessagingClient::Trace(Visitor* visitor) {
Supplement<LocalFrame>::Trace(visitor);
visitor->Trace(push_messaging_manager_);
}
void PushMessagingClient::DidGetManifest( void PushMessagingClient::DidGetManifest(
ServiceWorkerRegistration* service_worker_registration, ServiceWorkerRegistration* service_worker_registration,
mojom::blink::PushSubscriptionOptionsPtr options, mojom::blink::PushSubscriptionOptionsPtr options,
......
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-blink-forward.h" #include "third_party/blink/public/mojom/manifest/manifest.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/push_messaging/push_messaging.mojom-blink.h" #include "third_party/blink/public/mojom/push_messaging/push_messaging.mojom-blink.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/modules/push_messaging/push_subscription_callbacks.h" #include "third_party/blink/renderer/modules/push_messaging/push_subscription_callbacks.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
namespace blink { namespace blink {
...@@ -42,6 +43,7 @@ class PushMessagingClient final : public GarbageCollected<PushMessagingClient>, ...@@ -42,6 +43,7 @@ class PushMessagingClient final : public GarbageCollected<PushMessagingClient>,
PushSubscriptionOptions* options, PushSubscriptionOptions* options,
bool user_gesture, bool user_gesture,
std::unique_ptr<PushSubscriptionCallbacks> callbacks); std::unique_ptr<PushSubscriptionCallbacks> callbacks);
void Trace(Visitor*) override;
private: private:
// Returns an initialized PushMessaging service. A connection will be // Returns an initialized PushMessaging service. A connection will be
...@@ -65,7 +67,9 @@ class PushMessagingClient final : public GarbageCollected<PushMessagingClient>, ...@@ -65,7 +67,9 @@ class PushMessagingClient final : public GarbageCollected<PushMessagingClient>,
mojom::blink::PushRegistrationStatus status, mojom::blink::PushRegistrationStatus status,
mojom::blink::PushSubscriptionPtr subscription); mojom::blink::PushSubscriptionPtr subscription);
mojo::Remote<mojom::blink::PushMessaging> push_messaging_manager_; HeapMojoRemote<mojom::blink::PushMessaging,
HeapMojoWrapperMode::kWithoutContextObserver>
push_messaging_manager_;
DISALLOW_COPY_AND_ASSIGN(PushMessagingClient); DISALLOW_COPY_AND_ASSIGN(PushMessagingClient);
}; };
......
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