blob: 2aa473eb5235b0bf5f3e6fd3624082c3a68910dc [file]
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ACTOR_ACTOR_TAB_DATA_H_
#define CHROME_BROWSER_ACTOR_ACTOR_TAB_DATA_H_
#include <memory>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "components/optimization_guide/proto/features/actions_data.pb.h"
#include "components/tabs/public/tab_interface.h"
#include "ui/base/unowned_user_data/scoped_unowned_user_data.h"
#include "ui/gfx/geometry/point.h"
namespace actor {
namespace ui {
class DomNodeGeometry;
}
// Represents a data that the actor service stores for a tab.
class ActorTabData {
public:
explicit ActorTabData(tabs::TabInterface* tab);
~ActorTabData();
DECLARE_USER_DATA(ActorTabData);
static ActorTabData* From(tabs::TabInterface* tab);
void DidObserveContent(
optimization_guide::proto::AnnotatedPageContent& content);
// Returns last observed page content, nullptr if no observation has been
// made.
const optimization_guide::proto::AnnotatedPageContent*
GetLastObservedPageContent();
const ui::DomNodeGeometry* GetLastObservedDomNodeGeometry();
// Sets the coordinate that was resolved by the renderer during the tool
// validation phase.
void SetLastRendererResolvedTarget(const gfx::Point& point);
// Retrieves the renderer resolved coordinate.
std::optional<gfx::Point> GetLastRendererResolvedTarget();
private:
// Stores the last observed page content for TOCTOU check.
std::optional<optimization_guide::proto::AnnotatedPageContent>
last_observed_page_content_;
std::unique_ptr<ui::DomNodeGeometry> last_observed_dom_node_geometry_;
std::optional<gfx::Point> last_renderer_resolved_target_;
::ui::ScopedUnownedUserData<ActorTabData> scoped_unowned_user_data_;
};
} // namespace actor
#endif // CHROME_BROWSER_ACTOR_ACTOR_TAB_DATA_H_