#ifndef CHROME_BROWSER_GLIC_WIDGET_GLIC_WINDOW_CONTROLLER_H_
#define CHROME_BROWSER_GLIC_WIDGET_GLIC_WINDOW_CONTROLLER_H_
#include <optional>
#include <vector>
#include "base/callback_list.h"
#include "base/functional/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/scoped_observation.h"
#include "base/scoped_observation_traits.h"
#include "chrome/browser/glic/host/glic.mojom.h"
#include "chrome/browser/glic/host/glic_web_client_access.h"
#include "chrome/browser/glic/host/host.h"
#include "chrome/browser/glic/public/glic_enabling.h"
#include "chrome/browser/glic/public/glic_instance.h"
#include "chrome/browser/glic/widget/local_hotkey_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/gfx/native_ui_types.h"
#include "ui/views/widget/widget.h"
class Browser;
namespace content {
class RenderFrameHost;
}
namespace gfx {
class Point;
}
namespace tabs {
class TabInterface;
}
namespace glic {
DECLARE_CUSTOM_ELEMENT_EVENT_TYPE(kGlicWidgetAttached);
class GlicWidget;
class GlicKeyedService;
enum class AttachChangeReason;
class GlicWindowController {
public:
using StateObserver = PanelStateObserver;
using PanelStateContext = ::glic::PanelStateContext;
GlicWindowController(const GlicWindowController&) = delete;
GlicWindowController& operator=(const GlicWindowController&) = delete;
GlicWindowController() = default;
virtual ~GlicWindowController() = default;
virtual HostManager& host_manager() = 0;
virtual std::vector<GlicInstance*> GetInstances() = 0;
virtual GlicInstance* GetInstanceForTab(
const tabs::TabInterface* tab) const = 0;
virtual void Toggle(BrowserWindowInterface* bwi,
bool prevent_close,
mojom::InvocationSource source,
std::optional<std::string> prompt_suggestion) = 0;
virtual void ShowAfterSignIn(base::WeakPtr<Browser> browser) = 0;
virtual void Shutdown() = 0;
virtual void Close() = 0;
virtual void CloseInstanceWithFrame(
content::RenderFrameHost* render_frame_host) = 0;
virtual void CloseAndShutdownInstanceWithFrame(
content::RenderFrameHost* render_frame_host) = 0;
virtual bool IsDetached() const = 0;
virtual bool IsPanelShowingForBrowser(
const BrowserWindowInterface& bwi) const = 0;
using WindowActivationChangedCallback =
base::RepeatingCallback<void(bool active)>;
virtual base::CallbackListSubscription AddWindowActivationChangedCallback(
WindowActivationChangedCallback callback) = 0;
virtual base::CallbackListSubscription AddGlobalShowHideCallback(
base::RepeatingClosure callback) = 0;
virtual void Preload() = 0;
virtual void Reload(content::RenderFrameHost* render_frame_host) = 0;
virtual GlicWidget* GetGlicWidget() const = 0;
virtual Browser* attached_browser() = 0;
enum class State {
kClosed,
kWaitingForGlicToLoad,
kOpen,
kDetaching,
kWaitingForSidePanelToShow,
};
virtual State state() const = 0;
virtual Profile* profile() = 0;
virtual gfx::Rect GetInitialBounds(Browser* browser) = 0;
virtual void ShowDetachedForTesting() = 0;
virtual void SetPreviousPositionForTesting(gfx::Point position) = 0;
using ActiveInstanceChangedCallback =
base::RepeatingCallback<void(GlicInstance* new_instance)>;
virtual base::CallbackListSubscription
AddActiveInstanceChangedCallbackAndNotifyImmediately(
ActiveInstanceChangedCallback callback) = 0;
virtual GlicInstance* GetActiveInstance() = 0;
static bool AlwaysDetached() {
return base::FeatureList::IsEnabled(features::kGlicDetached) &&
!GlicEnabling::IsMultiInstanceEnabled();
}
virtual void AddGlobalStateObserver(PanelStateObserver* observer) = 0;
virtual void RemoveGlobalStateObserver(PanelStateObserver* observer) = 0;
};
class GlicWindowControllerInterface : public GlicWindowController,
public GlicInstance {
public:
virtual base::WeakPtr<GlicWindowControllerInterface> GetWeakPtr() = 0;
virtual bool IsWarmed() const = 0;
virtual void SidePanelShown(BrowserWindowInterface* browser) = 0;
virtual std::unique_ptr<views::View> CreateViewForSidePanel(
tabs::TabInterface& tab) = 0;
virtual void MaybeSetWidgetCanResize() = 0;
};
}
namespace base {
template <>
struct ScopedObservationTraits<glic::GlicWindowController,
glic::PanelStateObserver> {
static void AddObserver(glic::GlicWindowController* source,
glic::PanelStateObserver* observer) {
source->AddGlobalStateObserver(observer);
}
static void RemoveObserver(glic::GlicWindowController* source,
glic::PanelStateObserver* observer) {
source->RemoveGlobalStateObserver(observer);
}
};
}
#endif