#include "extensions/browser/app_window/app_window.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/task_runner.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/app_window/app_delegate.h"
#include "extensions/browser/app_window/app_web_contents_helper.h"
#include "extensions/browser/app_window/app_window_client.h"
#include "extensions/browser/app_window/app_window_geometry_cache.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/browser/app_window/size_constraints.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/suggest_permission_util.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/icons_handler.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/page/draggable_region.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/size.h"
#if !BUILDFLAG(IS_MAC)
#include "components/prefs/pref_service.h"
#include "extensions/browser/pref_names.h"
#endif
ConsoleMessageLevel;
BrowserContext;
WebContents;
WebContentsModalDialogHost;
WebContentsModalDialogManager;
namespace extensions {
namespace {
const int kDefaultWidth = …;
const int kDefaultHeight = …;
void SetConstraintProperty(const std::string& name,
int value,
base::Value::Dict* bounds_properties) { … }
void SetBoundsProperties(const gfx::Rect& bounds,
const gfx::Size& min_size,
const gfx::Size& max_size,
const std::string& bounds_name,
base::Value::Dict* window_properties) { … }
gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints,
const gfx::Size& content_constraints,
const gfx::Insets& frame_insets,
const gfx::RoundedCornersF& window_radii,
bool is_minimum_size_constraint) { … }
gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints,
const gfx::Size& content_constraints,
const gfx::Insets& frame_insets) { … }
}
const int AppWindow::BoundsSpecification::kUnspecifiedPosition = …;
AppWindow::BoundsSpecification::BoundsSpecification()
: … { … }
AppWindow::BoundsSpecification::~BoundsSpecification() = default;
void AppWindow::BoundsSpecification::ResetBounds() { … }
AppWindow::CreateParams::CreateParams()
: … { … }
AppWindow::CreateParams::CreateParams(const CreateParams& other) = default;
AppWindow::CreateParams::~CreateParams() = default;
gfx::Rect AppWindow::CreateParams::GetInitialWindowBounds(
const gfx::Insets& frame_insets,
const gfx::RoundedCornersF& window_radii) const { … }
gfx::Size AppWindow::CreateParams::GetContentMinimumSize(
const gfx::Insets& frame_insets) const { … }
gfx::Size AppWindow::CreateParams::GetContentMaximumSize(
const gfx::Insets& frame_insets) const { … }
gfx::Size AppWindow::CreateParams::GetWindowMinimumSize(
const gfx::Insets& frame_insets,
const gfx::RoundedCornersF& window_radii) const { … }
gfx::Size AppWindow::CreateParams::GetWindowMaximumSize(
const gfx::Insets& frame_insets,
const gfx::RoundedCornersF& window_radii) const { … }
AppWindow::AppWindow(BrowserContext* context,
std::unique_ptr<AppDelegate> app_delegate,
const Extension* extension)
: … { … }
void AppWindow::Init(const GURL& url,
std::unique_ptr<AppWindowContents> app_window_contents,
content::RenderFrameHost* creator_frame,
const CreateParams& params) { … }
AppWindow::~AppWindow() { … }
void AppWindow::RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { … }
bool AppWindow::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type) { … }
WebContents* AppWindow::OpenURLFromTab(
WebContents* source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
content::WebContents* AppWindow::AddNewContents(
WebContents* source,
std::unique_ptr<WebContents> new_contents,
const GURL& target_url,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& window_features,
bool user_gesture,
bool* was_blocked) { … }
content::KeyboardEventProcessingResult AppWindow::PreHandleKeyboardEvent(
content::WebContents* source,
const input::NativeWebKeyboardEvent& event) { … }
bool AppWindow::HandleKeyboardEvent(
WebContents* source,
const input::NativeWebKeyboardEvent& event) { … }
void AppWindow::RequestPointerLock(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) { … }
bool AppWindow::PreHandleGestureEvent(WebContents* source,
const blink::WebGestureEvent& event) { … }
bool AppWindow::TakeFocus(WebContents* source, bool reverse) { … }
content::PictureInPictureResult AppWindow::EnterPictureInPicture(
content::WebContents* web_contents) { … }
void AppWindow::ExitPictureInPicture() { … }
bool AppWindow::ShouldShowStaleContentOnEviction(content::WebContents* source) { … }
void AppWindow::RenderFrameCreated(content::RenderFrameHost* frame_host) { … }
void AppWindow::AddOnDidFinishFirstNavigationCallback(
DidFinishFirstNavigationCallback callback) { … }
void AppWindow::OnDidFinishFirstNavigation() { … }
void AppWindow::OnNativeClose() { … }
void AppWindow::OnNativeWindowChanged() { … }
void AppWindow::OnNativeWindowActivated() { … }
content::WebContents* AppWindow::web_contents() const { … }
const Extension* AppWindow::GetExtension() const { … }
NativeAppWindow* AppWindow::GetBaseWindow() { … }
gfx::NativeWindow AppWindow::GetNativeWindow() { … }
gfx::Rect AppWindow::GetClientBounds() const { … }
std::u16string AppWindow::GetTitle() const { … }
void AppWindow::SetAppIconUrl(const GURL& url) { … }
void AppWindow::UpdateShape(std::unique_ptr<ShapeRects> rects) { … }
void AppWindow::DraggableRegionsChanged(
const std::vector<blink::mojom::DraggableRegionPtr>& regions,
content::WebContents* contents) { … }
void AppWindow::UpdateAppIcon(const gfx::Image& image) { … }
void AppWindow::SetFullscreen(FullscreenType type, bool enable) { … }
bool AppWindow::IsFullscreen() const { … }
bool AppWindow::IsForcedFullscreen() const { … }
bool AppWindow::IsHtmlApiFullscreen() const { … }
bool AppWindow::IsOsFullscreen() const { … }
void AppWindow::Fullscreen() { … }
void AppWindow::Maximize() { … }
void AppWindow::Minimize() { … }
void AppWindow::Restore() { … }
void AppWindow::OSFullscreen() { … }
void AppWindow::ForcedFullscreen() { … }
void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size) { … }
void AppWindow::Show(ShowType show_type) { … }
void AppWindow::Hide() { … }
void AppWindow::SetAlwaysOnTop(bool always_on_top) { … }
bool AppWindow::IsAlwaysOnTop() const { … }
void AppWindow::RestoreAlwaysOnTop() { … }
void AppWindow::GetSerializedState(base::Value::Dict* properties) const { … }
void AppWindow::StartAppIconDownload() { … }
void AppWindow::DidDownloadFavicon(
int id,
int http_status_code,
const GURL& image_url,
const std::vector<SkBitmap>& bitmaps,
const std::vector<gfx::Size>& original_bitmap_sizes) { … }
void AppWindow::SetNativeWindowFullscreen() { … }
bool AppWindow::IntersectsWithTaskbar() const { … }
void AppWindow::UpdateNativeAlwaysOnTop() { … }
void AppWindow::ActivateContents(WebContents* contents) { … }
void AppWindow::CloseContents(WebContents* contents) { … }
bool AppWindow::ShouldSuppressDialogs(WebContents* source) { … }
void AppWindow::RunFileChooser(
content::RenderFrameHost* render_frame_host,
scoped_refptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) { … }
void AppWindow::SetContentsBounds(WebContents* source,
const gfx::Rect& bounds) { … }
void AppWindow::NavigationStateChanged(content::WebContents* source,
content::InvalidateTypes changed_flags) { … }
void AppWindow::EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) { … }
void AppWindow::ExitFullscreenModeForTab(content::WebContents* source) { … }
void AppWindow::AppWindowReady() { … }
void AppWindow::ToggleFullscreenModeForTab(content::WebContents* source,
bool enter_fullscreen) { … }
bool AppWindow::IsFullscreenForTabOrPending(
const content::WebContents* source) { … }
blink::mojom::DisplayMode AppWindow::GetDisplayMode(
const content::WebContents* source) { … }
WindowController* AppWindow::GetExtensionWindowController() const { … }
content::WebContents* AppWindow::GetAssociatedWebContents() const { … }
void AppWindow::OnExtensionUnloaded(BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
void AppWindow::SetWebContentsBlocked(content::WebContents* web_contents,
bool blocked) { … }
bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) { … }
WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() { … }
void AppWindow::SaveWindowPosition() { … }
void AppWindow::AdjustBoundsToBeVisibleOnScreen(
const gfx::Rect& cached_bounds,
const gfx::Rect& cached_screen_bounds,
const gfx::Rect& current_screen_bounds,
const gfx::Size& minimum_size,
gfx::Rect* bounds) const { … }
AppWindow::CreateParams AppWindow::LoadDefaults(CreateParams params) const { … }
SkRegion* AppWindow::RawDraggableRegionsToSkRegion(
const std::vector<blink::mojom::DraggableRegionPtr>& regions) { … }
}