diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index b8533b3f7c91bc..a63f8f3dfb79a7 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -137,25 +137,6 @@ steps: - replayio/buildevents#adb8a05: ~ command: "be_cmd metabase-tests -- /home/ubuntu/chromium/src/replay_build_scripts/metabase.sh" - - label: "Trigger Devtools E2E Tests" - key: "devtools-test-suite" - soft_fail: true - depends_on: "build-chromium-linux-x86_64" - agents: - - "runtimeType=chromiumbuild" - - "os=linux" - - "queue=runtime" - plugins: - - thedyrt/skip-checkout#v0.1.1: ~ - - seek-oss/aws-sm#v2.3.1: - region: us-east-2 - env: - GITHUB_AUTH_SECRET: "prod/devtools-github-secret" - BUILDEVENT_APIKEY: honeycomb-api-key - BUILDEVENT_BUILDKITE_API_TOKEN: buildkite-api-token-honeycomb-build-events - - replayio/buildevents#adb8a05: ~ - command: "be_cmd devtools-tests -- /home/ubuntu/chromium/src/replay_build_scripts/devtools-tests.sh" - # wait for all steps above, but also continue if they fail - wait: ~ continue_on_failure: true diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 306559e857eacf..6a4f363ed08a2e 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -2239,7 +2239,7 @@ static_library("browser") { "//components/query_tiles", "//components/reading_list/core", "//components/reading_list/features:flags", - "//components/record_replay/services/auth_token:lib", + "//components/record_replay/services/record_replay:lib", "//components/reduce_accept_language/browser:browser", "//components/renderer_context_menu", "//components/reporting/client:report_queue", diff --git a/chrome/browser/chrome_browser_interface_binders.cc b/chrome/browser/chrome_browser_interface_binders.cc index 91cfaaa9bc3775..4dbbbcd9102c22 100644 --- a/chrome/browser/chrome_browser_interface_binders.cc +++ b/chrome/browser/chrome_browser_interface_binders.cc @@ -71,8 +71,8 @@ #include "components/performance_manager/public/performance_manager.h" #include "components/prefs/pref_service.h" #include "components/reading_list/features/reading_list_switches.h" -#include "components/record_replay/services/auth_token/public/mojom/auth_token.mojom.h" -#include "components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h" +#include "components/record_replay/services/record_replay/public/mojom/record_replay.mojom.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h" #include "components/safe_browsing/buildflags.h" #include "components/security_state/content/content_utils.h" #include "components/security_state/core/security_state.h" @@ -374,9 +374,9 @@ namespace internal { using content::RegisterWebUIControllerInterfaceBinder; -void BindRecordReplayAuthTokenStore( +void BindRecordReplayService( content::RenderFrameHost* frame_host, - mojo::PendingReceiver receiver) { + mojo::PendingReceiver receiver) { // we only bind the receiver if the frame's origin is app.replay.io if (frame_host->GetLastCommittedOrigin().host() != "app.replay.io") { @@ -386,8 +386,8 @@ void BindRecordReplayAuthTokenStore( content::BrowserContext* browser_context = frame_host->GetProcess()->GetBrowserContext(); - auth_token::RecordReplayAuthTokenServiceFactory::GetForBrowserContext(browser_context) - ->BindAuthTokenStore(std::move(receiver)); + record_replay::RecordReplayServiceFactory::GetForBrowserContext(browser_context) + ->BindRecordReplayService(std::move(receiver)); } #if BUILDFLAG(ENABLE_UNHANDLED_TAP) @@ -696,8 +696,8 @@ void PopulateChromeFrameBinders( mojo::BinderMapWithContext* map, content::RenderFrameHost* render_frame_host) { - map->Add( - base::BindRepeating(&BindRecordReplayAuthTokenStore)); + map->Add( + base::BindRepeating(&BindRecordReplayService)); map->Add( base::BindRepeating(&BindImageAnnotator)); diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 621b03d86a86a2..8da024971e35af 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -6,6 +6,7 @@ #include +#include "base/record_replay.h" #include "base/trace_event/trace_event.h" #include "build/branding_buildflags.h" #include "build/build_config.h" @@ -134,6 +135,7 @@ #include "components/prefs/pref_service.h" #include "components/privacy_sandbox/privacy_sandbox_prefs.h" #include "components/proxy_config/pref_proxy_config_tracker_impl.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service.h" #include "components/safe_browsing/content/common/file_type_policies_prefs.h" #include "components/safe_browsing/core/common/safe_browsing_prefs.h" #include "components/search_engines/template_url_prepopulate_data.h" @@ -1559,6 +1561,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, RegisterBrowserViewProfilePrefs(registry); #endif +// Register record-replay prefs dictionary. +record_replay::RegisterProfilePrefs(registry); + #if !BUILDFLAG(IS_ANDROID) registry->RegisterBooleanPref( prefs::kLensRegionSearchEnabled, true, diff --git a/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.cc b/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.cc index 9be4dd96026457..cc06246fa22717 100644 --- a/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.cc +++ b/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.cc @@ -10,6 +10,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/webui_url_constants.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h" #include "ui/views/controls/button/button_controller.h" #include "content/public/browser/web_contents_observer.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -90,6 +92,18 @@ void RecordReplayToolbarButton::ButtonPressed() { } void RecordReplayToolbarButton::StartRecording() { + // TODO: Check for record-replay API key here. + // If it's not set, then we shouldn't have reached this location + // in the logic. + auto* service = GetRecordReplayService(); + fprintf(stderr, "KVKV: RecordReplayToolbarButton::StartRecording(): svc=%p\n", service); + absl::optional token = service->GetReplayUserToken(); + if (!token.has_value()) { + fprintf(stderr, "KVKV: RecordReplayToolbarButton::StartRecording(): no token\n"); + } else { + fprintf(stderr, "KVKV: RecordReplayToolbarButton::StartRecording(): token=%s\n", token.value().c_str()); + } + // Get the current active tab. This provides the URL we'll be recording. TabStripModel* tab_strip_model = browser_->tab_strip_model(); content::WebContents* old_web_contents = tab_strip_model->GetActiveWebContents(); @@ -105,6 +119,7 @@ void RecordReplayToolbarButton::StartRecording() { CHECK(!web_contents_observer_.get()); content::WebContents::CreateParams new_params(browser_context); new_params.record_replay_for_recording = true; + std::unique_ptr new_web_contents( content::WebContents::Create(new_params)); web_contents_ = new_web_contents.get(); @@ -162,6 +177,13 @@ void RecordReplayToolbarButton::RecordingTabDestroyed() { RefreshIconState(); } +record_replay::RecordReplayService* +RecordReplayToolbarButton::GetRecordReplayService() const { + return record_replay::RecordReplayServiceFactory::GetForBrowserContext( + browser_->profile() + ); +} + void RecordReplayToolbarButton::RefreshIconState() { if (web_contents_) { SetVectorIcons(kRecordReplayStopIcon, kRecordReplayStopIcon); @@ -185,4 +207,4 @@ void RecordReplayToolbarButton::EnsurePostRecordingWebContents() { post_recording_web_contents_->GetController().LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); -} \ No newline at end of file +} diff --git a/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.h b/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.h index 53e121b2384eda..7eaa8d4241f186 100644 --- a/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.h +++ b/chrome/browser/ui/views/toolbar/record_replay_toolbar_button.h @@ -9,6 +9,11 @@ #include "content/public/browser/web_contents.h" class Browser; +class Profile; + +namespace record_replay { + class RecordReplayService; +} struct RecordReplayToolbarButtonWebContentsObserver; @@ -31,6 +36,8 @@ class RecordReplayToolbarButton: public ToolbarButton { void RefreshIconState(); void EnsurePostRecordingWebContents(); + record_replay::RecordReplayService* GetRecordReplayService() const; + const raw_ptr browser_; content::WebContents* web_contents_; content::WebContents* post_recording_web_contents_; diff --git a/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.cc b/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.cc index ecb29a82b2e366..d0658586fab98a 100644 --- a/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.cc +++ b/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.cc @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/record_replay_driver.h" #include "chrome/browser/ui/webui/record_replay/record_replay_manager_handler.h" -#include "components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h" #include #include "base/bind.h" @@ -17,82 +16,48 @@ RecordReplayManagerHandler::RecordReplayManagerHandler( Profile* profile, mojo::PendingReceiver receiver) - : profile_(profile), receiver_(this, std::move(receiver)) { -} + : profile_(profile), + service_(record_replay::RecordReplayServiceFactory::GetForBrowserContext(profile_)), + receiver_(this, std::move(receiver)) +{} RecordReplayManagerHandler::~RecordReplayManagerHandler() = default; void RecordReplayManagerHandler::SetManager( mojo::PendingRemote manager) { manager_.Bind(std::move(manager)); + manager_->HandleSignInButtonClicked(); } void RecordReplayManagerHandler::HandleSignInButtonClicked() { - fprintf(stderr, "RecordReplay [RUN-2866] ManagerHandler(%p)::HandleSignInButtonClicked()\n", this); + CHECK(manager_) + << ("RecordReplayManagerHandler::HandleSignInButtonClicked called" + " before manager was set"); manager_->HandleSignInButtonClicked(); - // auth_token::RecordReplayAuthTokenServiceFactory::GetForBrowserContext(profile_)->SetToken(api_key); } void RecordReplayManagerHandler::GetEnv(const std::string& key, GetEnvCallback callback) { - std::move(callback).Run(absl::optional()); + std::move(callback).Run(service_->GetEnv(key)); } void RecordReplayManagerHandler::GetBuildId(GetBuildIdCallback callback) { - std::move(callback).Run(RECORD_REPLAY_BUILD_ID); + std::move(callback).Run(service_->GetBuildId()); } void RecordReplayManagerHandler::GetReplayUserToken(GetReplayUserTokenCallback callback) { - std::move(callback).Run(record_replay_user_token_); + std::move(callback).Run(service_->GetReplayUserToken()); } void RecordReplayManagerHandler::SetReplayUserToken(const absl::optional& token) { - record_replay_user_token_ = token; + service_->SetReplayUserToken(token); } void RecordReplayManagerHandler::GetReplayRefreshToken(GetReplayRefreshTokenCallback callback) { - std::move(callback).Run(record_replay_refresh_token_); + std::move(callback).Run(service_->GetReplayRefreshToken()); } void RecordReplayManagerHandler::SetReplayRefreshToken(const absl::optional& token) { - record_replay_refresh_token_ = token; + service_->SetReplayRefreshToken(token); } void RecordReplayManagerHandler::ShowAuthenticationError(const std::string& message) { - fprintf(stderr, "RecordReplay [RUN-2866] ManagerHandler(%p)::ShowAuthenticationError(%s)\n", this, - message.c_str()); -} - -#if BUILDFLAG(IS_MAC) -static void OpenExternalBrowserMac(const std::string& url_str) { - CFURLRef url = CFURLCreateWithBytes ( - NULL, // allocator - (UInt8*)url_str.c_str(), // URLBytes - url_str.length(), // length - kCFStringEncodingASCII, // encoding - NULL // baseURL - ); - LSOpenCFURLRef(url,0); - CFRelease(url); -} -#endif - -#if BUILDFLAG(IS_LINUX) -static void OpenExternalBrowserLinux(const std::string& url_str) { - std::string cmd = "xdg-open '" + url_str + "'"; - int result = system(cmd.c_str()); - if (result != 0) { - fprintf(stderr, "RecordReplayManagerHandler::OpenExternalBrowserLinux() failed with %d\n", - result); - } + service_->ShowAuthenticationError(message); } -#endif - -#if BUILDFLAG(IS_WIN) -static void OpenExternalBrowserWindows(const std::string& url_str) { - fprintf(stderr, "RecordReplayManagerHandler::OpenExternalBrowserWindows() NOT IMPLEMENTED\n"); -} -#endif void RecordReplayManagerHandler::OpenExternalBrowser(const std::string& url) { -#if BUILDFLAG(IS_MAC) - OpenExternalBrowserMac(url); -#elif BUILDFLAG(IS_LINUX) - OpenExternalBrowserLinux(url); -#elif BUILDFLAG(IS_WIN) - OpenExternalBrowserWindows(url); -#endif + service_->OpenExternalBrowser(url); } diff --git a/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.h b/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.h index 08799bbd079f46..f80fd1431d3f96 100644 --- a/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.h +++ b/chrome/browser/ui/webui/record_replay/record_replay_manager_handler.h @@ -20,6 +20,10 @@ class AutocompleteController; class Profile; +namespace record_replay { + class RecordReplayService; +} + // Implementation of mojo::RecordReplayManagerHandler. StartOmniboxQuery() calls to a // private AutocompleteController. It also listens for updates from the // AutocompleteController to OnResultChanged() and passes those results to @@ -60,6 +64,9 @@ class RecordReplayManagerHandler : public mojom::RecordReplayManagerHandler { // The Profile* handed to us in our constructor. raw_ptr profile_; + // Handle to the component service for record replay. + raw_ptr service_; + mojo::Receiver receiver_; base::WeakPtrFactory weak_factory_{this}; 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 deleted file mode 100644 index 6b529e8299e4bd..00000000000000 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2022 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/record_replay/services/auth_token/public/cpp/auth_token_service.h" -#include "content/public/browser/service_process_host.h" - -namespace auth_token { - -RecordReplayAuthTokenService::RecordReplayAuthTokenService() = default; -RecordReplayAuthTokenService::~RecordReplayAuthTokenService() = default; - -void RecordReplayAuthTokenService::BindAuthTokenStore( - mojo::PendingReceiver store) { - - auth_token_stores_.Add(this, std::move(store)); -} - -void RecordReplayAuthTokenService::SetToken(const std::string& token) { - token_ = token; - NotifyObservers(); -} - -void RecordReplayAuthTokenService::AddObserver(mojo::PendingRemote observer) { - observers_.Add(std::move(observer)); - NotifyObservers(); -} - -void RecordReplayAuthTokenService::NotifyObservers() { - for (auto& observer : observers_) { - observer->OnRecordReplayAuthTokenChanged(token_); - } -} - -} // namespace auth_token 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 deleted file mode 100644 index 1d5b20d9b7e211..00000000000000 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2022 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_H_ -#define COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_H_ - -#include "components/keyed_service/core/keyed_service.h" -#include "components/record_replay/services/auth_token/public/mojom/auth_token.mojom.h" -#include "mojo/public/cpp/bindings/pending_receiver.h" -#include "mojo/public/cpp/bindings/pending_remote.h" -#include "mojo/public/cpp/bindings/receiver.h" -#include "mojo/public/cpp/bindings/receiver_set.h" -#include "mojo/public/cpp/bindings/remote_set.h" - -namespace auth_token { - -class RecordReplayAuthTokenService : public KeyedService, public mojom::RecordReplayAuthTokenStore { - public: - RecordReplayAuthTokenService(); - RecordReplayAuthTokenService(const RecordReplayAuthTokenService&) = delete; - RecordReplayAuthTokenService& operator=(const RecordReplayAuthTokenService&) = delete; - ~RecordReplayAuthTokenService() override; - - void BindAuthTokenStore( - mojo::PendingReceiver store); - - // mojom::RecordReplayAuthTokenStore: - void SetToken(const std::string& token) override; - void AddObserver(mojo::PendingRemote observer) override; - -private: - mojo::ReceiverSet auth_token_stores_; - - std::string token_; - - void NotifyObservers(); - - mojo::RemoteSet observers_; -}; - -} // namespace auth_token - -#endif // COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_H_ diff --git a/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.cc b/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.cc deleted file mode 100644 index ba4d2acdbea692..00000000000000 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2022 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h" - -#include "components/keyed_service/content/browser_context_dependency_manager.h" -#include "content/public/browser/browser_context.h" - -namespace auth_token { - -// static -auth_token::RecordReplayAuthTokenService* -RecordReplayAuthTokenServiceFactory::GetForBrowserContext( - content::BrowserContext* context) { - return static_cast( - GetInstance()->GetServiceForBrowserContext(context, /*create=*/true)); -} - -// static -RecordReplayAuthTokenServiceFactory* RecordReplayAuthTokenServiceFactory::GetInstance() { - static base::NoDestructor instance; - return instance.get(); -} - -RecordReplayAuthTokenServiceFactory::RecordReplayAuthTokenServiceFactory() - : BrowserContextKeyedServiceFactory( - "RecordReplayAuthTokenService", - BrowserContextDependencyManager::GetInstance()) {} - -RecordReplayAuthTokenServiceFactory::~RecordReplayAuthTokenServiceFactory() = default; - -KeyedService* RecordReplayAuthTokenServiceFactory::BuildServiceInstanceFor( - content::BrowserContext* /*context*/) const { - return new auth_token::RecordReplayAuthTokenService(); -} - -// Incognito profiles should use their own instance. -content::BrowserContext* RecordReplayAuthTokenServiceFactory::GetBrowserContextToUse( - content::BrowserContext* context) const { - return context; -} - -} // namespace auth_token diff --git a/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h b/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h deleted file mode 100644 index 8ea1abbe7c1893..00000000000000 --- a/components/record_replay/services/auth_token/public/cpp/auth_token_service_factory.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_FACTORY_H_ -#define COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_FACTORY_H_ - -#include "base/no_destructor.h" -#include "components/keyed_service/content/browser_context_keyed_service_factory.h" -#include "components/record_replay/services/auth_token/public/cpp/auth_token_service.h" - -namespace content { -class BrowserContext; -} - -namespace auth_token { - -class RecordReplayAuthTokenService; - -// Factory to get or create an instance of RecordReplayAuthTokenService for a -// BrowserContext. -class RecordReplayAuthTokenServiceFactory : public BrowserContextKeyedServiceFactory { - public: - static RecordReplayAuthTokenService* GetForBrowserContext( - content::BrowserContext* context); - - private: - friend class base::NoDestructor; - static RecordReplayAuthTokenServiceFactory* GetInstance(); - - RecordReplayAuthTokenServiceFactory(); - ~RecordReplayAuthTokenServiceFactory() override; - - // BrowserContextKeyedServiceFactory: - KeyedService* BuildServiceInstanceFor( - content::BrowserContext* context) const override; - content::BrowserContext* GetBrowserContextToUse( - content::BrowserContext* context) const override; -}; - -} // namespace auth_token - -#endif // COMPONENTS_RECORD_REPLAY_SERVICES_AUTH_TOKEN_PUBLIC_CPP_AUTH_TOKEN_SERVICE_FACTORY_H_ 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 deleted file mode 100644 index 9e07f60bec78d0..00000000000000 --- a/components/record_replay/services/auth_token/public/mojom/auth_token.mojom +++ /dev/null @@ -1,13 +0,0 @@ -module auth_token.mojom; - -// Interface to passing updated token around -interface RecordReplayAuthTokenStore { - SetToken(string token); - - AddObserver(pending_remote observer); - // how do we remove? -}; - -interface RecordReplayAuthTokenStoreObserver { - OnRecordReplayAuthTokenChanged(string token); -}; diff --git a/components/record_replay/services/auth_token/BUILD.gn b/components/record_replay/services/record_replay/BUILD.gn similarity index 56% rename from components/record_replay/services/auth_token/BUILD.gn rename to components/record_replay/services/record_replay/BUILD.gn index c3bbd9f4b2e06d..c683d47e6c269c 100644 --- a/components/record_replay/services/auth_token/BUILD.gn +++ b/components/record_replay/services/record_replay/BUILD.gn @@ -6,10 +6,10 @@ assert(!is_android && !is_ios) source_set("lib") { sources = [ - "public/cpp/auth_token_service.cc", - "public/cpp/auth_token_service.h", - "public/cpp/auth_token_service_factory.cc", - "public/cpp/auth_token_service_factory.h", + "public/cpp/record_replay_service.cc", + "public/cpp/record_replay_service.h", + "public/cpp/record_replay_service_factory.cc", + "public/cpp/record_replay_service_factory.h", ] deps = [ @@ -19,6 +19,6 @@ source_set("lib") { ] public_deps = [ - "//components/record_replay/services/auth_token/public/mojom", + "//components/record_replay/services/record_replay/public/mojom", ] -} \ No newline at end of file +} diff --git a/components/record_replay/services/record_replay/public/cpp/record_replay_service.cc b/components/record_replay/services/record_replay/public/cpp/record_replay_service.cc new file mode 100644 index 00000000000000..94e3daeb3897ab --- /dev/null +++ b/components/record_replay/services/record_replay/public/cpp/record_replay_service.cc @@ -0,0 +1,160 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service.h" + +#include "chrome/browser/profiles/profile.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/scoped_user_pref_update.h" +#include "content/public/browser/service_process_host.h" + +#if BUILDFLAG(IS_MAC) +#include +#include +#endif + +namespace { + const char kRecordReplayPrefsKey[] = "record_replay"; +} + +namespace record_replay { + +void RegisterProfilePrefs(PrefRegistrySimple* registry) { + registry->RegisterDictionaryPref(kRecordReplayPrefsKey); +} + +RecordReplayService::RecordReplayService(Profile* profile) + : profile_(profile) {} +RecordReplayService::~RecordReplayService() = default; + +void RecordReplayService::BindRecordReplayService( + mojo::PendingReceiver store) { + + services_.Add(this, std::move(store)); +} + +void RecordReplayService::SetToken(const std::string& token) { + token_ = token; + // TODO persist the token to browser prefs + NotifyObservers(); +} + +void RecordReplayService::ClearToken() { + token_.clear(); // not sure about this.. should we be sending a null? + NotifyObservers(); +} + +void RecordReplayService::SetUser(const std::string& user) { + // TODO persist the user to browser prefs +} + +void RecordReplayService::ClearUser() { + // TODO clear the user from browser prefs +} + +void RecordReplayService::Login() { +} + +void RecordReplayService::AddObserver(mojo::PendingRemote observer) { + observers_.Add(std::move(observer)); + NotifyObservers(); +} + +absl::optional RecordReplayService::GetEnv(const std::string& key) { + return absl::optional(); +} +std::string RecordReplayService::GetBuildId() { + return "FIXME-BUILD-ID"; +} +absl::optional RecordReplayService::GetReplayUserToken() { + PrefService* prefs = profile_->GetPrefs(); + const std::string* token = + prefs->GetDict(kRecordReplayPrefsKey).FindStringByDottedPath("user_token"); + if (token) { + return absl::optional(*token); + } + return absl::optional(); +} + +void RecordReplayService::SetReplayUserToken(const absl::optional& token) { + ScopedDictPrefUpdate record_replay_prefs(profile_->GetPrefs(), kRecordReplayPrefsKey); + if (token.has_value()) { + record_replay_prefs->SetByDottedPath("user_token", token.value()); + } else { + record_replay_prefs->RemoveByDottedPath("user_token"); + } +} + +absl::optional RecordReplayService::GetReplayRefreshToken() { + PrefService* prefs = profile_->GetPrefs(); + const std::string* token = + prefs->GetDict(kRecordReplayPrefsKey).FindStringByDottedPath("refresh_token"); + if (token) { + return absl::optional(*token); + } + return absl::optional(); +} +void RecordReplayService::SetReplayRefreshToken(const absl::optional& token) { + ScopedDictPrefUpdate record_replay_prefs(profile_->GetPrefs(), kRecordReplayPrefsKey); + if (token.has_value()) { + record_replay_prefs->SetByDottedPath("refresh_token", token.value()); + } else { + record_replay_prefs->Remove("refresh_token"); + } +} +void RecordReplayService::ShowAuthenticationError(const std::string& message) { + fprintf(stderr, "RecordReplay [RUN-2866] ManagerHandler(%p)::ShowAuthenticationError(%s)\n", this, + message.c_str()); +} + +void RecordReplayService::NotifyObservers() { + for (auto& observer : observers_) { + observer->OnRecordReplayAuthTokenChanged(token_); + } +} + +#if BUILDFLAG(IS_MAC) +static void OpenExternalBrowserMac(const std::string& url_str) { + CFURLRef url = CFURLCreateWithBytes ( + NULL, // allocator + (UInt8*)url_str.c_str(), // URLBytes + url_str.length(), // length + kCFStringEncodingASCII, // encoding + NULL // baseURL + ); + LSOpenCFURLRef(url,0); + CFRelease(url); +} +#endif + +#if BUILDFLAG(IS_LINUX) +static void OpenExternalBrowserLinux(const std::string& url_str) { + std::string cmd = "xdg-open '" + url_str + "'"; + int result = system(cmd.c_str()); + if (result != 0) { + fprintf(stderr, "RecordReplayManagerHandler::OpenExternalBrowserLinux() failed with %d\n", + result); + } +} +#endif + +#if BUILDFLAG(IS_WIN) +static void OpenExternalBrowserWindows(const std::string& url_str) { + fprintf(stderr, "RecordReplayManagerHandler::OpenExternalBrowserWindows() NOT IMPLEMENTED\n"); +} +#endif + +void RecordReplayService::OpenExternalBrowser(const std::string& url) { + fprintf(stderr, "RecordReplay [RUN-2866] ManagerHandler(%p)::OpenExternalBrowser(%s)\n", this, + url.c_str()); + #if BUILDFLAG(IS_MAC) + OpenExternalBrowserMac(url); + #elif BUILDFLAG(IS_LINUX) + OpenExternalBrowserLinux(url); + #elif BUILDFLAG(IS_WIN) + OpenExternalBrowserWindows(url); + #endif +} + +} // namespace record_replay diff --git a/components/record_replay/services/record_replay/public/cpp/record_replay_service.h b/components/record_replay/services/record_replay/public/cpp/record_replay_service.h new file mode 100644 index 00000000000000..3ea82b1bd8d4fb --- /dev/null +++ b/components/record_replay/services/record_replay/public/cpp/record_replay_service.h @@ -0,0 +1,68 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_H_ +#define COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_H_ + +#include "components/keyed_service/core/keyed_service.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/record_replay/services/record_replay/public/mojom/record_replay.mojom.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/receiver.h" +#include "mojo/public/cpp/bindings/receiver_set.h" +#include "mojo/public/cpp/bindings/remote_set.h" + +class Profile; + +namespace record_replay { + +// Register preferences dictionary. +void RegisterProfilePrefs(PrefRegistrySimple* registry); + +class RecordReplayService : public KeyedService, public mojom::RecordReplayService { + public: + explicit RecordReplayService(Profile* profile); + RecordReplayService(const RecordReplayService&) = delete; + RecordReplayService& operator=(const RecordReplayService&) = delete; + ~RecordReplayService() override; + + void BindRecordReplayService( + mojo::PendingReceiver store); + + // mojom::RecordReplayService: + 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; + + // interface for RecordReplayManagerHandler + absl::optional GetEnv(const std::string& key); + std::string GetBuildId(); + absl::optional GetReplayUserToken(); + void SetReplayUserToken(const absl::optional& token); + absl::optional GetReplayRefreshToken(); + void SetReplayRefreshToken(const absl::optional& token); + void ShowAuthenticationError(const std::string& message); + void OpenExternalBrowser(const std::string& url); + +private: + raw_ptr profile_; + mojo::ReceiverSet services_; + + std::string token_; + + void NotifyObservers(); + + mojo::RemoteSet observers_; +}; + +} // namespace record_replay + +#endif // COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_H_ diff --git a/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.cc b/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.cc new file mode 100644 index 00000000000000..7dd8be5aa213ea --- /dev/null +++ b/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.cc @@ -0,0 +1,47 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h" + +#include "chrome/browser/profiles/profile.h" +#include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "content/public/browser/browser_context.h" + +namespace record_replay { + +// static +record_replay::RecordReplayService* +RecordReplayServiceFactory::GetForBrowserContext( + content::BrowserContext* context) { + return static_cast( + GetInstance()->GetServiceForBrowserContext(context, /*create=*/true)); +} + +// static +RecordReplayServiceFactory* RecordReplayServiceFactory::GetInstance() { + static base::NoDestructor instance; + return instance.get(); +} + +RecordReplayServiceFactory::RecordReplayServiceFactory() + : BrowserContextKeyedServiceFactory( + "RecordReplayService", + BrowserContextDependencyManager::GetInstance()) {} + +RecordReplayServiceFactory::~RecordReplayServiceFactory() = default; + +KeyedService* RecordReplayServiceFactory::BuildServiceInstanceFor( + content::BrowserContext* context) const { + return new record_replay::RecordReplayService( + Profile::FromBrowserContext(context) + ); +} + +// Incognito profiles should use their own instance. +content::BrowserContext* RecordReplayServiceFactory::GetBrowserContextToUse( + content::BrowserContext* context) const { + return context; +} + +} // namespace record_replay diff --git a/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h b/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h new file mode 100644 index 00000000000000..b92c4e25b29c0f --- /dev/null +++ b/components/record_replay/services/record_replay/public/cpp/record_replay_service_factory.h @@ -0,0 +1,43 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_FACTORY_H_ +#define COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_FACTORY_H_ + +#include "base/no_destructor.h" +#include "components/keyed_service/content/browser_context_keyed_service_factory.h" +#include "components/record_replay/services/record_replay/public/cpp/record_replay_service.h" + +namespace content { +class BrowserContext; +} + +namespace record_replay { + +class RecordReplayService; + +// Factory to get or create an instance of RecordReplayService for a +// BrowserContext. +class RecordReplayServiceFactory : public BrowserContextKeyedServiceFactory { + public: + static RecordReplayService* GetForBrowserContext( + content::BrowserContext* context); + + static RecordReplayServiceFactory* GetInstance(); + private: + friend class base::NoDestructor; + + RecordReplayServiceFactory(); + ~RecordReplayServiceFactory() override; + + // BrowserContextKeyedServiceFactory: + KeyedService* BuildServiceInstanceFor( + content::BrowserContext* context) const override; + content::BrowserContext* GetBrowserContextToUse( + content::BrowserContext* context) const override; +}; + +} // namespace record_replay + +#endif // COMPONENTS_RECORD_REPLAY_SERVICES_RECORD_REPLAY_PUBLIC_CPP_RECORD_REPLAY_SERVICE_FACTORY_H_ diff --git a/components/record_replay/services/auth_token/public/mojom/BUILD.gn b/components/record_replay/services/record_replay/public/mojom/BUILD.gn similarity index 96% rename from components/record_replay/services/auth_token/public/mojom/BUILD.gn rename to components/record_replay/services/record_replay/public/mojom/BUILD.gn index 71527d65cf1af3..927ec90407ca83 100644 --- a/components/record_replay/services/auth_token/public/mojom/BUILD.gn +++ b/components/record_replay/services/record_replay/public/mojom/BUILD.gn @@ -5,7 +5,7 @@ import("//mojo/public/tools/bindings/mojom.gni") mojom("mojom") { - sources = [ "auth_token.mojom" ] + sources = [ "record_replay.mojom" ] # public_deps = [ "//sandbox/policy/mojom" ] diff --git a/components/record_replay/services/record_replay/public/mojom/record_replay.mojom b/components/record_replay/services/record_replay/public/mojom/record_replay.mojom new file mode 100644 index 00000000000000..8482e8cf16f0b2 --- /dev/null +++ b/components/record_replay/services/record_replay/public/mojom/record_replay.mojom @@ -0,0 +1,20 @@ +module record_replay.mojom; + +// Provides access to the browser-side record/replay service. +interface RecordReplayService { + 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? +}; + +interface RecordReplayAuthTokenObserver { + OnRecordReplayAuthTokenChanged(string token); +}; diff --git a/content/browser/browser_interface_binders.cc b/content/browser/browser_interface_binders.cc index 756a4b74ab1f2c..328f1a7576fb5c 100644 --- a/content/browser/browser_interface_binders.cc +++ b/content/browser/browser_interface_binders.cc @@ -13,7 +13,7 @@ #include "build/branding_buildflags.h" #include "build/build_config.h" #include "cc/base/switches.h" -#include "components/record_replay/services/auth_token/public/mojom/auth_token.mojom-blink.h" +#include "components/record_replay/services/record_replay/public/mojom/record_replay.mojom-blink.h" #include "content/browser/aggregation_service/aggregation_service_internals.mojom.h" #include "content/browser/aggregation_service/aggregation_service_internals_ui.h" #include "content/browser/attribution_reporting/attribution_internals.mojom.h" @@ -979,9 +979,9 @@ void PopulateBinderMapWithContext( // by blink. // This avoids renderer kills when no binder is found in the absence of the // production embedder (such as in tests). - map->Add( + map->Add( base::BindRepeating(&EmptyBinderForFrame< - auth_token::mojom::blink::RecordReplayAuthTokenStore>)); + record_replay::mojom::blink::RecordReplayService>)); map->Add(base::BindRepeating( &EmptyBinderForFrame)); map->Add(base::BindRepeating( diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index ea35f5c571d546..e8d679b6146c7a 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -2369,6 +2369,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, bool prerender2_disabled_ = false; bool record_replay_for_recording_ = false; + absl::optional record_replay_api_key_; base::WeakPtrFactory loading_weak_factory_{this}; base::WeakPtrFactory weak_factory_{this}; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index b8135a201b3875..9de19713436697 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -266,6 +266,9 @@ class WebContents : public PageNavigator, // Indicates that the content should be recorded by the Record Replay // framework. bool record_replay_for_recording = false; + + // Specifies the record-replay api key for streaming recording. + absl::optional record_replay_api_key; }; // Creates a new WebContents. diff --git a/replay_build_scripts/upload_build_artifacts.mjs b/replay_build_scripts/upload_build_artifacts.mjs index 250a76f215dfee..21c16999dddabc 100644 --- a/replay_build_scripts/upload_build_artifacts.mjs +++ b/replay_build_scripts/upload_build_artifacts.mjs @@ -237,7 +237,7 @@ async function main(options) { const downloadUris = uploadArchives(buildArchives); uploadToAllBuckets(symbolsArchiveFile, `symbols/${symbolsArchiveFile}`); - fs.unlinkSync(symbolsArchiveFile); + downloadUris.push(`s3://${S3Bucket}/symbols/${symbolsArchiveFile}`); for (const buildArchive of buildArchives) { log(`BuildUploaded https://static.replay.io/downloads/${buildArchive}`); @@ -249,12 +249,20 @@ async function main(options) { downloadUris, platform, buildId, - buildArm ? "arm64" : "x86_64" + buildArm ? "arm64" : "x86_64", + symbolsArchiveFile ); } + fs.unlinkSync(symbolsArchiveFile); } -function buildkiteStuff(downloadUris, platform, buildId, arch) { +function buildkiteStuff( + downloadUris, + platform, + buildId, + arch, + symbolsArchiveFile +) { const markdownDownloadList = downloadUris .map((uri) => uri.replace("s3://recordreplay-website", "https://static.replay.io") @@ -291,6 +299,10 @@ function buildkiteStuff(downloadUris, platform, buildId, arch) { path.join(BUILDKITE_ARTIFACT_DIRECTORY, BUILDKITE_BUILD_ID_ARTIFACT), buildId ); + fs.cpSync( + symbolsArchiveFile, + path.join(BUILDKITE_ARTIFACT_DIRECTORY, symbolsArchiveFile) + ); log( `Wrote build_id to ${BUILDKITE_ARTIFACT_DIRECTORY}/${BUILDKITE_BUILD_ID_ARTIFACT}` @@ -381,7 +393,7 @@ async function buildChromiumSymbols(options) { pdbs ); - log(`ChromiumSymbols Done`); + log(`ChromiumSymbols Done (${archiveFile})})`); return { buildId, symbolsArchiveFile: archiveFile }; } diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn index a659db06cb844a..bfb527d06b17fa 100644 --- a/third_party/blink/public/mojom/BUILD.gn +++ b/third_party/blink/public/mojom/BUILD.gn @@ -249,7 +249,7 @@ mojom("mojom_platform") { ":web_feature_mojo_bindings", "//cc/mojom", "//components/payments/mojom", - "//components/record_replay/services/auth_token/public/mojom", + "//components/record_replay/services/record_replay/public/mojom", "//components/schema_org/common:mojom", "//components/services/filesystem/public/mojom", "//mojo/public/mojom/base", 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..48d97930962663 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 @@ -39,7 +39,6 @@ #include "third_party/blink/renderer/platform/wtf/casting.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "v8/include/v8.h" -#include "components/record_replay/services/auth_token/public/mojom/auth_token.mojom.h" namespace blink { @@ -114,8 +113,6 @@ class LocalWindowProxy final : public WindowProxy { return To(WindowProxy::GetFrame()); } - mojo::Remote auth_token_store_; - 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_interface.cc b/third_party/blink/renderer/bindings/core/v8/record_replay_interface.cc index 627f9ae38b6f24..2c53da3c960405 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 @@ -3372,7 +3372,7 @@ function makeAPIHash(content) { function collectUnresolvedSourceMapResources(mapText, mapURL) { let obj; try { - obj = JSON_parse(mapText); + obj = JSON.parse(mapText); if (typeof obj !== "object" || !obj) { return { sources: [], @@ -3422,7 +3422,7 @@ function collectUnresolvedSourceMapResources(mapText, mapURL) { continue; } - Array_push.call(unresolvedSources, { + unresolvedSources.push({ offset, url: sourceURL, }); @@ -3551,7 +3551,7 @@ function inject(renderer) { const id = ++uidCounter; window.__RECORD_REPLAY_ANNOTATION_HOOK__("react-devtools-hook:v1:" + annotationType, ""); - Array_push.call(window.__REACT_DEVTOOLS_SAVED_RENDERERS__, renderer); + window.__REACT_DEVTOOLS_SAVED_RENDERERS__.push(renderer); return id; } @@ -3670,7 +3670,7 @@ function saveReplayAnnotation(action, state, connectionType, extractedConfig, co const { instanceId } = extractedConfig; - window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON_stringify({ + window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON.stringify({ type: 'action', actionType: action.type, connectionType, @@ -3746,7 +3746,7 @@ function connect(preConfig) { return; }; const init = (state, liftedData) => { - window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON_stringify({ + window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON.stringify({ type: 'init', connectionType: 'generic', instanceId @@ -3774,7 +3774,7 @@ function __REDUX_DEVTOOLS_EXTENSION__(preConfig = {}) { instanceId } = extractedExtensionConfig; function init() { - window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON_stringify({ + window.__RECORD_REPLAY_ANNOTATION_HOOK__('redux-devtools-setup', JSON.stringify({ type: 'init', connectionType: 'redux', instanceId @@ -5818,13 +5818,13 @@ void RecordReplayEventListener::HandleRecordReplayTokenMessage(v8::Local(), "connect")) { LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: connect message received"; - local_frame_->RegisterRecordReplayAuthTokenObserver(); + local_frame_->RecordReplayRegisterAuthTokenObserver(); return; } if (StringEquals(isolate, message_type.As(), "login")) { LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: login message received"; - // [RUN-2863] TODO open external browser to login + local_frame_->RecordReplayLogin(); return; } @@ -5835,13 +5835,13 @@ void RecordReplayEventListener::HandleRecordReplayTokenMessage(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. + local_frame_->RecordReplaySetToken(ToCoreString(message_token.As())); return; } - if (message_token->IsNull()) { + if (message_token->IsNullOrUndefined()) { LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: clear access token message received"; - // [RUN-2863] TODO clear the access token in browser prefs. + local_frame_->RecordReplayClearToken(); return; } @@ -5855,13 +5855,13 @@ void RecordReplayEventListener::HandleRecordReplayMessage(v8::Local 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. + local_frame_->RecordReplaySetUser(ToCoreString(message_user.As())); return; } if (message_user->IsNullOrUndefined()) { LOG(ERROR) << "[RUN-2863] RecordReplayEventListener: clear user message received"; - // [RUN-2863] TODO clear the user in browser prefs. + local_frame_->RecordReplayClearUser(); return; } 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..ce9e5dd9ee7fb9 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 @@ -419,7 +419,7 @@ LocalFrameMojoHandler::LocalFrameMojoHandler(blink::LocalFrame& frame) &LocalFrameMojoHandler::BindFullscreenVideoElementReceiver, WrapWeakPersistent(this))); registry->AddInterface(WTF::BindRepeating( - &LocalFrameMojoHandler::BindRecordReplayAuthTokenStoreObserver, + &LocalFrameMojoHandler::BindRecordReplayAuthTokenObserver, WrapWeakPersistent(this))); } @@ -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_service_); + 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_service_.is_bound()) { return; } auto task_runner = frame_->GetTaskRunner(TaskType::kInternalDefault); frame_->GetBrowserInterfaceBroker().GetInterface( - auth_token_store_.BindNewPipeAndPassReceiver(task_runner)); + record_replay_service_.BindNewPipeAndPassReceiver(task_runner)); +} + +void LocalFrameMojoHandler::RecordReplayRegisterAuthTokenObserver() { + if (record_replay_observer_receiver_.is_bound()) { + return; + } + + RecordReplayEnsureAuthTokenStore(); + auto task_runner = frame_->GetTaskRunner(TaskType::kInternalDefault); + record_replay_service_->AddObserver( + record_replay_observer_receiver_.BindNewPipeAndPassRemote(task_runner)); +} + +void LocalFrameMojoHandler::RecordReplayLogin() { + RecordReplayEnsureAuthTokenStore(); + record_replay_service_->Login(); +} + +void LocalFrameMojoHandler::RecordReplaySetToken(const WTF::String& token) { + RecordReplayEnsureAuthTokenStore(); + record_replay_service_->SetToken(token); +} + +void LocalFrameMojoHandler::RecordReplayClearToken() { + RecordReplayEnsureAuthTokenStore(); + record_replay_service_->ClearToken(); +} + +void LocalFrameMojoHandler::RecordReplaySetUser(const WTF::String& token) { + RecordReplayEnsureAuthTokenStore(); + record_replay_service_->SetUser(token); +} - auth_token_store_->AddObserver( - auth_token_store_observer_receiver_.BindNewPipeAndPassRemote(task_runner)); +void LocalFrameMojoHandler::RecordReplayClearUser() { + RecordReplayEnsureAuthTokenStore(); + record_replay_service_->ClearUser(); } Page* LocalFrameMojoHandler::GetPage() const { @@ -566,13 +599,13 @@ void LocalFrameMojoHandler::BindToHighPriorityReceiver( std::make_unique(frame_)); } -void LocalFrameMojoHandler::BindRecordReplayAuthTokenStoreObserver( +void LocalFrameMojoHandler::BindRecordReplayAuthTokenObserver( mojo::PendingReceiver< - auth_token::mojom::blink::RecordReplayAuthTokenStoreObserver> receiver) { + record_replay::mojom::blink::RecordReplayAuthTokenObserver> receiver) { 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..597890e3cba552 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 @@ -9,7 +9,7 @@ #include "build/build_config.h" #include "components/power_scheduler/power_mode_voter.h" #include "services/device/public/mojom/device_posture_provider.mojom-blink.h" -#include "components/record_replay/services/auth_token/public/mojom/auth_token.mojom-blink.h" +#include "components/record_replay/services/record_replay/public/mojom/record_replay.mojom-blink.h" #include "third_party/blink/public/mojom/frame/back_forward_cache_controller.mojom-blink.h" #include "third_party/blink/public/mojom/frame/frame.mojom-blink.h" #include "third_party/blink/public/mojom/media/fullscreen_video_element.mojom-blink.h" @@ -49,7 +49,7 @@ class LocalFrameMojoHandler public mojom::blink::HighPriorityLocalFrame, public mojom::blink::FullscreenVideoElementHandler, public device::mojom::blink::DevicePostureProviderClient, - public auth_token::mojom::blink::RecordReplayAuthTokenStoreObserver { + public record_replay::mojom::blink::RecordReplayAuthTokenObserver { public: explicit LocalFrameMojoHandler(blink::LocalFrame& frame); void Trace(Visitor* visitor) const; @@ -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; @@ -90,9 +97,9 @@ class LocalFrameMojoHandler void BindFullscreenVideoElementReceiver( mojo::PendingAssociatedReceiver< mojom::blink::FullscreenVideoElementHandler> receiver); - void BindRecordReplayAuthTokenStoreObserver( + void BindRecordReplayAuthTokenObserver( mojo::PendingReceiver< - auth_token::mojom::blink::RecordReplayAuthTokenStoreObserver> receiver); + record_replay::mojom::blink::RecordReplayAuthTokenObserver> receiver); // blink::mojom::LocalFrame overrides: void GetTextSurroundingSelection( @@ -249,7 +256,7 @@ class LocalFrameMojoHandler // DevicePostureServiceClient implementation: void OnPostureChanged(device::mojom::blink::DevicePostureType posture) final; - // RecordReplayAuthTokenStoreObserver implementation: + // RecordReplayAuthTokenObserver implementation: void OnRecordReplayAuthTokenChanged(const WTF::String& token) final; Member frame_; @@ -270,8 +277,8 @@ class LocalFrameMojoHandler HeapMojoAssociatedRemote local_frame_host_remote_{nullptr}; - HeapMojoRemote - auth_token_store_{nullptr}; + HeapMojoRemote + record_replay_service_{nullptr}; // LocalFrameMojoHandler can be reused by multiple ExecutionContext. HeapMojoAssociatedReceiver @@ -288,9 +295,9 @@ class LocalFrameMojoHandler LocalFrameMojoHandler> fullscreen_video_receiver_{this, nullptr}; // 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.