From fb9487935b36981be5687e508120f3523e414c94 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 6 Feb 2024 18:49:45 -0700 Subject: [PATCH] Reapply "[RUN-2863] finish devtools plumbing (#1032)" (#1078) This reverts commit 971ced236c16717cdd1c5452654586797b38b8db. --- .../public/cpp/auth_token_service.cc | 17 ++ .../public/cpp/auth_token_service.h | 7 + .../auth_token/public/mojom/auth_token.mojom | 7 + .../blink/renderer/bindings/bindings.gni | 6 +- .../bindings/core/v8/local_window_proxy.cc | 7 +- .../bindings/core/v8/local_window_proxy.h | 6 +- .../record_replay_devtools_event_listener.cc | 168 ++++++++++++++++++ .../record_replay_devtools_event_listener.h | 37 ++++ .../core/v8/record_replay_interface.cc | 147 --------------- .../core/v8/record_replay_interface.h | 22 --- .../blink/renderer/core/frame/local_frame.cc | 26 ++- .../blink/renderer/core/frame/local_frame.h | 9 +- .../core/frame/local_frame_mojo_handler.cc | 49 ++++- .../core/frame/local_frame_mojo_handler.h | 13 +- 14 files changed, 329 insertions(+), 192 deletions(-) create mode 100644 third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.cc create mode 100644 third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h diff --git a/components/record_replay/services/auth_token/public/cpp/auth_token_service.cc b/components/record_replay/services/auth_token/public/cpp/auth_token_service.cc index 6b529e8299e4bd..80dbf6f642c13c 100644 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service.cc +++ b/components/record_replay/services/auth_token/public/cpp/auth_token_service.cc @@ -18,9 +18,26 @@ void RecordReplayAuthTokenService::BindAuthTokenStore( void RecordReplayAuthTokenService::SetToken(const std::string& token) { token_ = token; + // TODO persist the token to browser prefs NotifyObservers(); } +void RecordReplayAuthTokenService::ClearToken() { + token_.clear(); // not sure about this.. should we be sending a null? + NotifyObservers(); +} + +void RecordReplayAuthTokenService::SetUser(const std::string& user) { + // TODO persist the user to browser prefs +} + +void RecordReplayAuthTokenService::ClearUser() { + // TODO clear the user from browser prefs +} + +void RecordReplayAuthTokenService::Login() { +} + void RecordReplayAuthTokenService::AddObserver(mojo::PendingRemote observer) { observers_.Add(std::move(observer)); NotifyObservers(); diff --git a/components/record_replay/services/auth_token/public/cpp/auth_token_service.h b/components/record_replay/services/auth_token/public/cpp/auth_token_service.h index 1d5b20d9b7e211..df2994fb7f888f 100644 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service.h +++ b/components/record_replay/services/auth_token/public/cpp/auth_token_service.h @@ -27,6 +27,13 @@ class RecordReplayAuthTokenService : public KeyedService, public mojom::RecordRe // mojom::RecordReplayAuthTokenStore: void SetToken(const std::string& token) override; + void ClearToken() override; + + void SetUser(const std::string& user) override; + void ClearUser() override; + + void Login() override; + void AddObserver(mojo::PendingRemote observer) override; private: diff --git a/components/record_replay/services/auth_token/public/mojom/auth_token.mojom b/components/record_replay/services/auth_token/public/mojom/auth_token.mojom index 9e07f60bec78d0..250ed808fb2f38 100644 --- a/components/record_replay/services/auth_token/public/mojom/auth_token.mojom +++ b/components/record_replay/services/auth_token/public/mojom/auth_token.mojom @@ -3,6 +3,13 @@ module auth_token.mojom; // Interface to passing updated token around interface RecordReplayAuthTokenStore { SetToken(string token); + ClearToken(); + + SetUser (string user); + ClearUser(); + + // Opens an external browser to log the user in + Login(); AddObserver(pending_remote observer); // how do we remove? diff --git a/third_party/blink/renderer/bindings/bindings.gni b/third_party/blink/renderer/bindings/bindings.gni index 086333a6fa9434..45a08504d1c486 100644 --- a/third_party/blink/renderer/bindings/bindings.gni +++ b/third_party/blink/renderer/bindings/bindings.gni @@ -68,10 +68,12 @@ blink_core_sources_bindings = "core/v8/observable_array_exotic_object_impl.h", "core/v8/profiler_trace_builder.cc", "core/v8/profiler_trace_builder.h", - "core/v8/record_replay_interface.cc", - "core/v8/record_replay_interface.h", + "core/v8/record_replay_devtools_event_listener.cc", + "core/v8/record_replay_devtools_event_listener.h", "core/v8/record_replay_events.cc", "core/v8/record_replay_events.h", + "core/v8/record_replay_interface.cc", + "core/v8/record_replay_interface.h", "core/v8/record_replay_network.cc", "core/v8/record_replay_network.h", "core/v8/referrer_script_info.cc", diff --git a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc index aba73fd0c3e1ad..606808538f972a 100644 --- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc +++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc @@ -37,6 +37,7 @@ #include "base/metrics/single_sample_metrics.h" #include "third_party/blink/renderer/bindings/core/v8/isolated_world_csp.h" #include "third_party/blink/renderer/bindings/core/v8/script_controller.h" +#include "third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h" #include "third_party/blink/renderer/bindings/core/v8/record_replay_interface.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" @@ -268,17 +269,17 @@ void LocalWindowProxy::Initialize() { // Add an event listener for the dispatched custom event the devtools uses to register // its listener. Do this outside the recording. - SetupRecordReplayEventListener(); + SetupRecordReplayDevtoolsEventListener(); if (World().IsMainWorld()) { GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld(); } } -void LocalWindowProxy::SetupRecordReplayEventListener() { +void LocalWindowProxy::SetupRecordReplayDevtoolsEventListener() { LocalFrame* localFrame = GetFrame(); - record_replay_listener_ = RecordReplayEventListener::Create(GetIsolate(), localFrame); + record_replay_listener_ = RecordReplayDevtoolsEventListener::Create(GetIsolate(), localFrame); bool added = localFrame->DomWindow()->addEventListener("WebChannelMessageToChrome", record_replay_listener_.Get()); diff --git a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.h b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.h index d1d7e1e4dc6e51..f00cd819c9248f 100644 --- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.h +++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.h @@ -46,7 +46,7 @@ namespace blink { class HTMLDocument; class ScriptState; class SecurityOrigin; -class RecordReplayEventListener; +class RecordReplayDevtoolsEventListener; // Subclass of WindowProxy that only handles LocalFrame. class LocalWindowProxy final : public WindowProxy { @@ -73,7 +73,7 @@ class LocalWindowProxy final : public WindowProxy { v8::Context::AbortScriptExecutionCallback callback); private: - void SetupRecordReplayEventListener(); + void SetupRecordReplayDevtoolsEventListener(); // LocalWindowProxy overrides: bool IsLocal() const override { return true; } @@ -116,7 +116,7 @@ class LocalWindowProxy final : public WindowProxy { mojo::Remote auth_token_store_; - Member record_replay_listener_; + Member record_replay_listener_; Member script_state_; bool context_was_created_from_snapshot_ = false; }; diff --git a/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.cc b/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.cc new file mode 100644 index 00000000000000..6ac6ff25957a8e --- /dev/null +++ b/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.cc @@ -0,0 +1,168 @@ +// Copyright 2021 Record Replay Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/core/dom/events/custom_event.h" +#include "third_party/blink/renderer/core/execution_context/execution_context.h" + +namespace blink { + +static v8::Local ToV8String(v8::Isolate* isolate, const char* value) { + return v8::String::NewFromUtf8(isolate, value, + v8::NewStringType::kInternalized).ToLocalChecked(); +} +static const std::string V8ToString(v8::Isolate* isolate, v8::Local str) { + v8::String::Utf8Value s(isolate, str); + return *s; +} + +static bool GetStringProperty(v8::Local context, v8::Local obj, const char* name, v8::Local* out) { + v8::Isolate* isolate = context->GetIsolate(); + v8::Local v8Name = ToV8String(isolate, name); + v8::Local v8Value = obj->Get(context, v8Name).ToLocalChecked(); + + return v8Value->ToString(context).ToLocal(out); +} + +static bool GetObjectProperty(v8::Local context, v8::Local obj, const char* name, v8::Local* out) { + v8::Isolate* isolate = context->GetIsolate(); + v8::Local v8Name = ToV8String(isolate, name); + v8::Local v8Value = obj->Get(context, v8Name).ToLocalChecked(); + + return v8Value->ToObject(context).ToLocal(out); +} + +static bool StringEquals(v8::Isolate* isolate, v8::Local str1, const char* str2) { + return str1->StringEquals(ToV8String(isolate, str2)); +} + + +void RecordReplayDevtoolsEventListener::Invoke(ExecutionContext* context, Event* event) { + v8::Isolate* isolate = context->GetIsolate(); + v8::Local v8_context = isolate->GetCurrentContext(); + ScriptState* scriptState = ScriptState::Current(isolate); + CustomEvent* customEvent = To(event); + + if (!customEvent) { + return; + } + + v8::Local detail = customEvent->detail(scriptState).V8Value(); + v8::Local detail_json; + if (!detail->ToString(v8_context).ToLocal(&detail_json)) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: detail is not a string"; + return; + } + + // for debugging: + // LOG(ERROR) << "RecordReplayDevtoolsEventListener: detail = " << V8ToString(isolate, detail_json); + + // detail is a JSON stringified object with one of the following forms: + + // { "id": "record-replay-token", "message": { "type": "connect" } } => register auth token observer + // { "id": "record-replay-token", "message": { "type": "login" } } => open external browser to login + // { "id": "record-replay-token", "message": { "token": } } => set access token if string. clear if null (or undefined?) + // { "id": "record-replay", "message": { "user": } } => set user if string. clear if null (or undefined?) + + v8::Local detail_obj; + if (!v8::JSON::Parse(v8_context, detail_json).ToLocalChecked()->ToObject(v8_context).ToLocal(&detail_obj)) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: detail is not a JSON object"; + return; + } + + // always pull out the id and message properties, and early out if id isn't a string or message isn't an object + v8::Local id_str; + if (!GetStringProperty(v8_context, detail_obj, "id", &id_str)) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: id is not an string"; + return; + } + + v8::Local message_obj; + if (!GetObjectProperty(v8_context, detail_obj, "message", &message_obj)) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: message is not an object"; + return; + } + + + if (StringEquals(isolate, id_str, "record-replay-token")) { + HandleRecordReplayTokenMessage(v8_context, message_obj); + } else if (StringEquals(isolate, id_str, "record-replay")) { + HandleRecordReplayMessage(v8_context, message_obj); + } else { + LOG(ERROR) << "[RUN-2863] Unknown event id: " << V8ToString(isolate, id_str); + } +} + +void RecordReplayDevtoolsEventListener::HandleRecordReplayTokenMessage(v8::Local context, v8::Local message) { + v8::Isolate* isolate = context->GetIsolate(); + + // cases here: + // { "id": "record-replay-token", "message": { "type": "connect" } } => register auth token observer + // { "id": "record-replay-token", "message": { "type": "login" } } => open external browser to login + // { "id": "record-replay-token", "message": { "token": } } => set access token if string. clear if null (or undefined?) + + // first check if there's a type property to handle the first two cases above. + v8::Local message_type = message->Get(context, ToV8String(isolate, "type")).ToLocalChecked(); + if (message_type->IsString()) { + // message is either `{ type: "connect" }` or `{ type: "login" }`, with neither payload carrying additional info. + if (StringEquals(isolate, message_type.As(), "connect")) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: connect message received"; + local_frame_->RecordReplayRegisterAuthTokenObserver(); + return; + } + + if (StringEquals(isolate, message_type.As(), "login")) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: login message received"; + local_frame_->RecordReplayLogin(); + return; + } + + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: unknown record-replay-token message type: " << V8ToString(isolate, message_type); + } + + // if we're here, we should only be in the `{ token: ... }` case from the list above. + v8::Local message_token = message->Get(context, ToV8String(isolate, "token")).ToLocalChecked(); + if (message_token->IsString()) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: set access token message received, token = " << V8ToString(isolate, message_token); + local_frame_->RecordReplaySetToken(ToCoreString(message_token.As())); + return; + } + + if (message_token->IsNullOrUndefined()) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: clear access token message received"; + local_frame_->RecordReplayClearToken(); + return; + } + + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: unknown record-replay-token message"; +} + +void RecordReplayDevtoolsEventListener::HandleRecordReplayMessage(v8::Local context, v8::Local message) { + v8::Isolate* isolate = context->GetIsolate(); + + // the only message handled here is `{ user: }` + v8::Local message_user = message->Get(context, ToV8String(isolate, "user")).ToLocalChecked(); + if (message_user->IsString()) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: set user message received, user = " << V8ToString(isolate, message_user); + local_frame_->RecordReplaySetUser(ToCoreString(message_user.As())); + return; + } + + if (message_user->IsNullOrUndefined()) { + LOG(ERROR) << "[RUN-2863] RecordReplayDevtoolsEventListener: clear user message received"; + local_frame_->RecordReplayClearUser(); + return; + } + + LOG(ERROR) << "[RUN-2863] Unknown record-replay message type"; + return; +} + +void RecordReplayDevtoolsEventListener::Trace(Visitor* visitor) const { + visitor->Trace(local_frame_); + EventListener::Trace(visitor); +} + +} // namespace blink \ No newline at end of file diff --git a/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h b/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h new file mode 100644 index 00000000000000..1e83f745c83014 --- /dev/null +++ b/third_party/blink/renderer/bindings/core/v8/record_replay_devtools_event_listener.h @@ -0,0 +1,37 @@ +// Copyright 2021 Record Replay Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_DEVTOOLS_EVENT_LISTENER_H_ +#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_DEVTOOLS_EVENT_LISTENER_H_ + +#include "third_party/blink/renderer/core/dom/events/native_event_listener.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" +#include "v8/include/v8.h" + +namespace blink { + +class RecordReplayDevtoolsEventListener : public NativeEventListener { + public: + RecordReplayDevtoolsEventListener(v8::Isolate* isolate, LocalFrame* localFrame) + : local_frame_(localFrame) {} + + void Invoke(ExecutionContext*, Event*) override; + + void Trace(Visitor*) const override; + + static RecordReplayDevtoolsEventListener* Create(v8::Isolate* isolate, + LocalFrame* localFrame) { + return MakeGarbageCollected(isolate, localFrame); + } + + private: + Member local_frame_; + + void HandleRecordReplayTokenMessage(v8::Local context, v8::Local message); + void HandleRecordReplayMessage(v8::Local context, v8::Local message); +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_DEVTOOLS_EVENT_LISTENER_H_ diff --git a/third_party/blink/renderer/bindings/core/v8/record_replay_interface.cc b/third_party/blink/renderer/bindings/core/v8/record_replay_interface.cc index 7dcf77d0ae7d8e..633458d91ff46e 100644 --- a/third_party/blink/renderer/bindings/core/v8/record_replay_interface.cc +++ b/third_party/blink/renderer/bindings/core/v8/record_replay_interface.cc @@ -22,7 +22,6 @@ #include "third_party/blink/renderer/bindings/core/v8/v8_node.h" #include "third_party/blink/renderer/core/css/css_style_declaration.h" #include "third_party/blink/renderer/core/dom/dom_node_ids.h" -#include "third_party/blink/renderer/core/dom/events/custom_event.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/inspector/inspected_frames.h" @@ -2747,150 +2746,4 @@ static void GetCurrentError(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(rv); } -bool GetStringProperty(v8::Local context, v8::Local obj, const char* name, v8::Local* out) { - v8::Isolate* isolate = context->GetIsolate(); - v8::Local v8Name = ToV8String(isolate, name); - v8::Local v8Value = obj->Get(context, v8Name).ToLocalChecked(); - - return v8Value->ToString(context).ToLocal(out); -} - -bool GetObjectProperty(v8::Local context, v8::Local obj, const char* name, v8::Local* out) { - v8::Isolate* isolate = context->GetIsolate(); - v8::Local v8Name = ToV8String(isolate, name); - v8::Local v8Value = obj->Get(context, v8Name).ToLocalChecked(); - - return v8Value->ToObject(context).ToLocal(out); -} - -bool StringEquals(v8::Isolate* isolate, v8::Local str1, const char* str2) { - return str1->StringEquals(ToV8String(isolate, str2)); -} - -void RecordReplayEventListener::Invoke(ExecutionContext* context, Event* event) { - v8::Isolate* isolate = context->GetIsolate(); - v8::Local v8_context = isolate->GetCurrentContext(); - ScriptState* scriptState = ScriptState::Current(isolate); - CustomEvent* customEvent = To(event); - - if (!customEvent) { - return; - } - - v8::Local detail = customEvent->detail(scriptState).V8Value(); - v8::Local detail_json; - if (!detail->ToString(v8_context).ToLocal(&detail_json)) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: detail is not a string"; - return; - } - - // for debugging: - // LOG(ERROR) << "RecordReplayEventListener: detail = " << V8ToString(isolate, detail_json); - - // detail is a JSON stringified object with one of the following forms: - - // { "id": "record-replay-token", "message": { "type": "connect" } } => register auth token observer - // { "id": "record-replay-token", "message": { "type": "login" } } => open external browser to login - // { "id": "record-replay-token", "message": { "token": } } => set access token if string. clear if null (or undefined?) - // { "id": "record-replay", "message": { "user": } } => set user if string. clear if null (or undefined?) - - v8::Local detail_obj; - if (!v8::JSON::Parse(v8_context, detail_json).ToLocalChecked()->ToObject(v8_context).ToLocal(&detail_obj)) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: detail is not a JSON object"; - return; - } - - // always pull out the id and message properties, and early out if id isn't a string or message isn't an object - v8::Local id_str; - if (!GetStringProperty(v8_context, detail_obj, "id", &id_str)) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: id is not an string"; - return; - } - - v8::Local message_obj; - if (!GetObjectProperty(v8_context, detail_obj, "message", &message_obj)) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: message is not an object"; - return; - } - - - if (StringEquals(isolate, id_str, "record-replay-token")) { - HandleRecordReplayTokenMessage(v8_context, message_obj); - } else if (StringEquals(isolate, id_str, "record-replay")) { - HandleRecordReplayMessage(v8_context, message_obj); - } else { - LOG(ERROR) << "[RUN-2863] Unknown event id: " << V8ToString(isolate, id_str); - } -} - -void RecordReplayEventListener::HandleRecordReplayTokenMessage(v8::Local context, v8::Local message) { - v8::Isolate* isolate = context->GetIsolate(); - - // cases here: - // { "id": "record-replay-token", "message": { "type": "connect" } } => register auth token observer - // { "id": "record-replay-token", "message": { "type": "login" } } => open external browser to login - // { "id": "record-replay-token", "message": { "token": } } => set access token if string. clear if null (or undefined?) - - // first check if there's a type property to handle the first two cases above. - v8::Local message_type = message->Get(context, ToV8String(isolate, "type")).ToLocalChecked(); - if (message_type->IsString()) { - // message is either `{ type: "connect" }` or `{ type: "login" }`, with neither payload carrying additional info. - if (StringEquals(isolate, message_type.As(), "connect")) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: connect message received"; - local_frame_->RegisterRecordReplayAuthTokenObserver(); - return; - } - - if (StringEquals(isolate, message_type.As(), "login")) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: login message received"; - // [RUN-2863] TODO open external browser to login - return; - } - - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: unknown record-replay-token message type: " << V8ToString(isolate, message_type); - } - - // if we're here, we should only be in the `{ token: ... }` case from the list above. - v8::Local message_token = message->Get(context, ToV8String(isolate, "token")).ToLocalChecked(); - if (message_token->IsString()) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: set access token message received, token = " << V8ToString(isolate, message_token); - // [RUN-2863] TODO set the access token in browser prefs. - return; - } - - if (message_token->IsNull()) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: clear access token message received"; - // [RUN-2863] TODO clear the access token in browser prefs. - return; - } - - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: unknown record-replay-token message"; -} - -void RecordReplayEventListener::HandleRecordReplayMessage(v8::Local context, v8::Local message) { - v8::Isolate* isolate = context->GetIsolate(); - - // the only message handled here is `{ user: }` - v8::Local message_user = message->Get(context, ToV8String(isolate, "user")).ToLocalChecked(); - if (message_user->IsString()) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: set user message received, user = " << V8ToString(isolate, message_user); - // [RUN-2863] TODO set the user in browser prefs. - return; - } - - if (message_user->IsNullOrUndefined()) { - LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: clear user message received"; - // [RUN-2863] TODO clear the user in browser prefs. - return; - } - - LOG(ERROR) << "[RUN-2863] Unknown record-replay message type"; - return; -} - -void RecordReplayEventListener::Trace(Visitor* visitor) const { - visitor->Trace(local_frame_); - EventListener::Trace(visitor); -} - } // namespace blink diff --git a/third_party/blink/renderer/bindings/core/v8/record_replay_interface.h b/third_party/blink/renderer/bindings/core/v8/record_replay_interface.h index 329d29b7e7cb5f..a092681e4c84e5 100644 --- a/third_party/blink/renderer/bindings/core/v8/record_replay_interface.h +++ b/third_party/blink/renderer/bindings/core/v8/record_replay_interface.h @@ -5,7 +5,6 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_INTERFACE_H_ #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_INTERFACE_H_ -#include "third_party/blink/renderer/core/dom/events/native_event_listener.h" #include "third_party/blink/renderer/core/events/error_event.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "base/values.h" @@ -46,27 +45,6 @@ void RecordReplayClearContexts(const char* reason, LocalFrame* frame); void RecordReplayRegisterV8Inspector(v8_inspector::V8Inspector* inspector, v8::Isolate* isolate); -class RecordReplayEventListener : public NativeEventListener { - public: - RecordReplayEventListener(v8::Isolate* isolate, LocalFrame* localFrame) - : local_frame_(localFrame) {} - - void Invoke(ExecutionContext*, Event*) override; - - void Trace(Visitor*) const override; - - static RecordReplayEventListener* Create(v8::Isolate* isolate, - LocalFrame* localFrame) { - return MakeGarbageCollected(isolate, localFrame); - } - - private: - Member local_frame_; - - void HandleRecordReplayTokenMessage(v8::Local context, v8::Local message); - void HandleRecordReplayMessage(v8::Local context, v8::Local message); -}; - } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_RECORD_REPLAY_INTERFACE_H_ diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/blink/renderer/core/frame/local_frame.cc index 09a3fa4fd35f33..4bad10f8196fa0 100644 --- a/third_party/blink/renderer/core/frame/local_frame.cc +++ b/third_party/blink/renderer/core/frame/local_frame.cc @@ -3318,8 +3318,30 @@ bool LocalFrame::HasBlockingReasonsHelper( return false; } -void LocalFrame::RegisterRecordReplayAuthTokenObserver() { - mojo_handler_->RegisterRecordReplayAuthTokenObserver(); +// delegate all the recordreplay calls to the mojo handler +void LocalFrame::RecordReplayRegisterAuthTokenObserver() { + mojo_handler_->RecordReplayRegisterAuthTokenObserver(); +} + +void LocalFrame::RecordReplayLogin() { + mojo_handler_->RecordReplayLogin(); + +} + +void LocalFrame::RecordReplaySetToken(const WTF::String& token) { + mojo_handler_->RecordReplaySetToken(token); +} + +void LocalFrame::RecordReplayClearToken() { + mojo_handler_->RecordReplayClearToken(); +} + +void LocalFrame::RecordReplaySetUser(const WTF::String& user) { + mojo_handler_->RecordReplaySetUser(user); +} + +void LocalFrame::RecordReplayClearUser() { + mojo_handler_->RecordReplayClearUser(); } } // namespace blink diff --git a/third_party/blink/renderer/core/frame/local_frame.h b/third_party/blink/renderer/core/frame/local_frame.h index bd9f8589222f40..e6d40469c8a7b8 100644 --- a/third_party/blink/renderer/core/frame/local_frame.h +++ b/third_party/blink/renderer/core/frame/local_frame.h @@ -805,8 +805,13 @@ class CORE_EXPORT LocalFrame final absl::optional GetFrameOverlayColorForTesting() const; - void RegisterRecordReplayAuthTokenObserver(); - + void RecordReplayRegisterAuthTokenObserver(); + void RecordReplayLogin(); + void RecordReplaySetToken(const WTF::String& token); + void RecordReplayClearToken(); + void RecordReplaySetUser(const WTF::String& user); + void RecordReplayClearUser(); + private: friend class FrameNavigationDisabler; // LocalFrameMojoHandler is a part of LocalFrame. diff --git a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc index 805f7937fb1272..ed662381000bd4 100644 --- a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc +++ b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc @@ -437,8 +437,8 @@ void LocalFrameMojoHandler::Trace(Visitor* visitor) const { visitor->Trace(high_priority_frame_receiver_); visitor->Trace(fullscreen_video_receiver_); visitor->Trace(device_posture_receiver_); - visitor->Trace(auth_token_store_); - visitor->Trace(auth_token_store_observer_receiver_); + visitor->Trace(record_replay_auth_token_store_); + visitor->Trace(record_replay_observer_receiver_); } void LocalFrameMojoHandler::WasAttachedAsLocalMainFrame() { @@ -507,17 +507,50 @@ LocalFrameMojoHandler::GetDevicePosture() { return current_device_posture_; } -void LocalFrameMojoHandler::RegisterRecordReplayAuthTokenObserver() { - if (auth_token_store_.is_bound()) { +void LocalFrameMojoHandler::RecordReplayEnsureAuthTokenStore() { + if (record_replay_auth_token_store_.is_bound()) { return; } auto task_runner = frame_->GetTaskRunner(TaskType::kInternalDefault); frame_->GetBrowserInterfaceBroker().GetInterface( - auth_token_store_.BindNewPipeAndPassReceiver(task_runner)); + record_replay_auth_token_store_.BindNewPipeAndPassReceiver(task_runner)); +} + +void LocalFrameMojoHandler::RecordReplayRegisterAuthTokenObserver() { + if (record_replay_observer_receiver_.is_bound()) { + return; + } + + RecordReplayEnsureAuthTokenStore(); + auto task_runner = frame_->GetTaskRunner(TaskType::kInternalDefault); + record_replay_auth_token_store_->AddObserver( + record_replay_observer_receiver_.BindNewPipeAndPassRemote(task_runner)); +} + +void LocalFrameMojoHandler::RecordReplayLogin() { + RecordReplayEnsureAuthTokenStore(); + record_replay_auth_token_store_->Login(); +} + +void LocalFrameMojoHandler::RecordReplaySetToken(const WTF::String& token) { + RecordReplayEnsureAuthTokenStore(); + record_replay_auth_token_store_->SetToken(token); +} + +void LocalFrameMojoHandler::RecordReplayClearToken() { + RecordReplayEnsureAuthTokenStore(); + record_replay_auth_token_store_->ClearToken(); +} + +void LocalFrameMojoHandler::RecordReplaySetUser(const WTF::String& token) { + RecordReplayEnsureAuthTokenStore(); + record_replay_auth_token_store_->SetUser(token); +} - auth_token_store_->AddObserver( - auth_token_store_observer_receiver_.BindNewPipeAndPassRemote(task_runner)); +void LocalFrameMojoHandler::RecordReplayClearUser() { + RecordReplayEnsureAuthTokenStore(); + record_replay_auth_token_store_->ClearUser(); } Page* LocalFrameMojoHandler::GetPage() const { @@ -572,7 +605,7 @@ void LocalFrameMojoHandler::BindRecordReplayAuthTokenStoreObserver( if (frame_->IsDetached()) return; - auth_token_store_observer_receiver_.Bind( + record_replay_observer_receiver_.Bind( std::move(receiver), frame_->GetTaskRunner(TaskType::kInternalDefault)); } diff --git a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.h b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.h index 9004b7d7537e0a..34183d32f6ea49 100644 --- a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.h +++ b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.h @@ -75,7 +75,14 @@ class LocalFrameMojoHandler device::mojom::blink::DevicePostureType GetDevicePosture(); - void RegisterRecordReplayAuthTokenObserver(); + void RecordReplayEnsureAuthTokenStore(); + void RecordReplayRegisterAuthTokenObserver(); + void RecordReplayLogin(); + void RecordReplaySetToken(const WTF::String& token); + void RecordReplayClearToken(); + void RecordReplaySetUser(const WTF::String& user); + void RecordReplayClearUser(); + private: Page* GetPage() const; LocalDOMWindow* DomWindow() const; @@ -271,7 +278,7 @@ class LocalFrameMojoHandler local_frame_host_remote_{nullptr}; HeapMojoRemote - auth_token_store_{nullptr}; + record_replay_auth_token_store_{nullptr}; // LocalFrameMojoHandler can be reused by multiple ExecutionContext. HeapMojoAssociatedReceiver @@ -290,7 +297,7 @@ class LocalFrameMojoHandler // LocalFrameMojoHandler can be reused by multiple ExecutionContext. HeapMojoReceiver - auth_token_store_observer_receiver_{this, nullptr}; + record_replay_observer_receiver_{this, nullptr}; // LocalFrameMojoHandler can be reused by multiple ExecutionContext.