#ifndef FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_CONTROLLER_IMPL_H_
#define FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_CONTROLLER_IMPL_H_
#include <fuchsia/web/cpp/fidl.h>
#include <lib/fidl/cpp/binding_set.h>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/favicon/core/favicon_driver_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "fuchsia_web/webengine/web_engine_export.h"
#include "net/base/net_errors.h"
namespace content {
class NavigationEntry;
class NavigationHandle;
class WebContents;
}
class NavigationControllerImpl final
: public fuchsia::web::NavigationController,
public content::WebContentsObserver,
public favicon::FaviconDriverObserver {
public:
static const void* const kAbortedRequestKey;
NavigationControllerImpl(content::WebContents* web_contents,
void* parent_for_trace_flow);
NavigationControllerImpl(const NavigationControllerImpl&) = delete;
NavigationControllerImpl& operator=(const NavigationControllerImpl&) = delete;
~NavigationControllerImpl() override;
void AddBinding(
fidl::InterfaceRequest<fuchsia::web::NavigationController> controller);
void SetEventListener(
fidl::InterfaceHandle<fuchsia::web::NavigationEventListener> listener,
fuchsia::web::NavigationEventListenerFlags flags);
private:
fuchsia::web::NavigationState GetVisibleNavigationState() const;
void OnNavigationEntryChanged();
void MaybeSendNavigationEvent();
void LoadUrl(std::string url,
fuchsia::web::LoadUrlParams params,
LoadUrlCallback callback) override;
void GoBack() override;
void GoForward() override;
void Stop() override;
void Reload(fuchsia::web::ReloadType type) override;
void TitleWasSet(content::NavigationEntry*) override;
void PrimaryMainDocumentElementAvailable() override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
void PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) override;
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
NotificationIconType notification_icon_type,
const GURL& icon_url,
bool icon_url_changed,
const gfx::Image& image) override;
const raw_ptr<void> parent_for_trace_flow_;
const raw_ptr<content::WebContents> web_contents_;
fidl::BindingSet<fuchsia::web::NavigationController> controller_bindings_;
fuchsia::web::NavigationEventListenerPtr navigation_listener_;
fuchsia::web::NavigationState previous_navigation_state_;
fuchsia::web::NavigationState pending_navigation_event_;
bool waiting_for_navigation_event_ack_ = false;
bool is_main_document_loaded_ = false;
raw_ptr<content::NavigationHandle> active_navigation_ = nullptr;
bool uncommitted_load_error_ = false;
net::Error last_error_code_ = net::OK;
bool send_favicon_ = false;
base::WeakPtrFactory<NavigationControllerImpl> weak_factory_;
};
WEB_ENGINE_EXPORT void DiffNavigationEntriesForTest(
const fuchsia::web::NavigationState& old_entry,
const fuchsia::web::NavigationState& new_entry,
fuchsia::web::NavigationState* difference);
#endif