#ifndef WEBLAYER_SHELL_BROWSER_SHELL_H_
#define WEBLAYER_SHELL_BROWSER_SHELL_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"
#include "weblayer/public/download_delegate.h"
#include "weblayer/public/navigation_observer.h"
#include "weblayer/public/tab_observer.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/scoped_java_ref.h"
#elif defined(USE_AURA)
namespace views {
class Widget;
class ViewsDelegate;
}
#if !BUILDFLAG(IS_CHROMEOS)
namespace display {
class Screen;
}
namespace wm {
class WMState;
}
#endif
#endif
class GURL;
namespace weblayer {
class Browser;
class Profile;
class Tab;
class Shell : public TabObserver,
public NavigationObserver,
public DownloadDelegate {
public:
~Shell() override;
void LoadURL(const GURL& url);
void GoBackOrForward(int offset);
void Reload();
void ReloadBypassingCache();
void Stop();
void Close();
static void Initialize();
#if BUILDFLAG(IS_ANDROID)
static Shell* CreateNewWindow(const GURL& url, const gfx::Size& initial_size);
#else
static Shell* CreateNewWindow(Profile* web_profile,
const GURL& url,
const gfx::Size& initial_size);
#endif
static std::vector<Shell*>& windows() { return windows_; }
static void CloseAllWindows();
static void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);
Tab* tab();
Browser* browser();
gfx::NativeWindow window() { return window_; }
static gfx::Size GetShellDefaultSize();
private:
enum UIControl { BACK_BUTTON, FORWARD_BUTTON, STOP_BUTTON };
static Shell* CreateNewWindowWithBrowser(std::unique_ptr<Browser> browser,
const GURL& url,
const gfx::Size& initial_size);
explicit Shell(std::unique_ptr<Browser> browser);
void DisplayedUrlChanged(const GURL& url) override;
void LoadStateChanged(bool is_loading, bool should_show_loading_ui) override;
void LoadProgressChanged(double progress) override;
bool InterceptDownload(const GURL& url,
const std::string& user_agent,
const std::string& content_disposition,
const std::string& mime_type,
int64_t content_length) override;
void AllowDownload(Tab* tab,
const GURL& url,
const std::string& request_method,
absl::optional<url::Origin> request_initiator,
AllowDownloadCallback callback) override;
static Shell* CreateShell(std::unique_ptr<Browser> browser,
const gfx::Size& initial_size);
static void PlatformInitialize(const gfx::Size& default_window_size);
static void PlatformExit();
static gfx::Size AdjustWindowSize(const gfx::Size& initial_size);
void PlatformCleanUp();
void PlatformCreateWindow(int width, int height);
void PlatformSetContents();
void PlatformResizeSubViews();
void PlatformEnableUIControl(UIControl control, bool is_enabled);
void PlatformSetAddressBarURL(const GURL& url);
void PlatformSetLoadProgress(double progress);
void PlatformSetTitle(const std::u16string& title);
std::unique_ptr<Browser> browser_;
gfx::NativeWindow window_;
gfx::Size content_size_;
#if BUILDFLAG(IS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> java_object_;
#elif defined(USE_AURA)
static wm::WMState* wm_state_;
static display::Screen* screen_;
#if defined(TOOLKIT_VIEWS)
static views::ViewsDelegate* views_delegate_;
raw_ptr<views::Widget> window_widget_;
#endif
#endif
static std::vector<Shell*> windows_;
};
}
#endif