#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_bounds_cache.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_occlusion_tracker.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "content/public/browser/document_picture_in_picture_window_controller.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/picture_in_picture_window_controller.h"
#include "content/public/browser/video_picture_in_picture_window_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/url_constants.h"
#include "extensions/buildflags/buildflags.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/resize_utils.h"
#include "ui/gfx/geometry/size.h"
#if !BUILDFLAG(IS_ANDROID)
#include "base/metrics/histogram_functions.h"
#include "base/numerics/checked_math.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/browser/picture_in_picture/auto_picture_in_picture_tab_helper.h"
#include "media/base/media_switches.h"
#include "net/base/url_util.h"
#include "third_party/blink/public/common/features.h"
#include "ui/views/view.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#endif
namespace {
constexpr double kInitialAspectRatio = …;
constexpr gfx::Size kMinWindowSize(240, 52);
constexpr double kMaxWindowSizeRatio = …;
#if !BUILDFLAG(IS_ANDROID)
bool ShouldFocusPictureInPictureWindow(const NavigateParams& params) { … }
#endif
}
class PictureInPictureWindowManager::VideoWebContentsObserver final
: public content::WebContentsObserver { … };
#if !BUILDFLAG(IS_ANDROID)
class PictureInPictureWindowManager::DocumentWebContentsObserver final
: public content::WebContentsObserver { … };
#endif
PictureInPictureWindowManager* PictureInPictureWindowManager::GetInstance() { … }
void PictureInPictureWindowManager::EnterPictureInPictureWithController(
content::PictureInPictureWindowController* pip_window_controller) { … }
#if !BUILDFLAG(IS_ANDROID)
void PictureInPictureWindowManager::EnterDocumentPictureInPicture(
content::WebContents* parent_web_contents,
content::WebContents* child_web_contents) { … }
#endif
content::PictureInPictureResult
PictureInPictureWindowManager::EnterVideoPictureInPicture(
content::WebContents* web_contents) { … }
bool PictureInPictureWindowManager::ExitPictureInPictureViaWindowUi(
UiBehavior behavior) { … }
bool PictureInPictureWindowManager::ExitPictureInPicture() { … }
void PictureInPictureWindowManager::ExitPictureInPictureSoon() { … }
void PictureInPictureWindowManager::FocusInitiator() { … }
content::WebContents* PictureInPictureWindowManager::GetWebContents() const { … }
content::WebContents* PictureInPictureWindowManager::GetChildWebContents()
const { … }
bool PictureInPictureWindowManager::IsChildWebContents(
content::WebContents* wc) { … }
std::optional<gfx::Rect>
PictureInPictureWindowManager::GetPictureInPictureWindowBounds() const { … }
gfx::Rect PictureInPictureWindowManager::CalculateOuterWindowBounds(
const blink::mojom::PictureInPictureWindowOptions& pip_options,
const display::Display& display,
const gfx::Size& minimum_outer_window_size,
const gfx::Size& excluded_margin) { … }
gfx::Rect
PictureInPictureWindowManager::CalculateInitialPictureInPictureWindowBounds(
const blink::mojom::PictureInPictureWindowOptions& pip_options,
const display::Display& display) { … }
void PictureInPictureWindowManager::UpdateCachedBounds(
const gfx::Rect& most_recent_bounds) { … }
gfx::Size PictureInPictureWindowManager::GetMinimumInnerWindowSize() { … }
gfx::Size PictureInPictureWindowManager::GetMaximumWindowSize(
const display::Display& display) { … }
void PictureInPictureWindowManager::SetWindowParams(NavigateParams& params) { … }
bool PictureInPictureWindowManager::IsSupportedForDocumentPictureInPicture(
const GURL& url) { … }
void PictureInPictureWindowManager::CreateWindowInternal(
content::WebContents* web_contents) { … }
void PictureInPictureWindowManager::CloseWindowInternal() { … }
#if !BUILDFLAG(IS_ANDROID)
void PictureInPictureWindowManager::DocumentWebContentsDestroyed() { … }
std::unique_ptr<AutoPipSettingOverlayView>
PictureInPictureWindowManager::GetOverlayView(
const gfx::Rect& browser_view_overridden_bounds,
views::View* anchor_view,
views::BubbleBorder::Arrow arrow) { … }
PictureInPictureOcclusionTracker*
PictureInPictureWindowManager::GetOcclusionTracker() { … }
void PictureInPictureWindowManager::CreateOcclusionTrackerIfNecessary() { … }
void PictureInPictureWindowManager::OnFileDialogOpened() { … }
void PictureInPictureWindowManager::OnFileDialogClosed() { … }
void PictureInPictureWindowManager::
RecordDocumentPictureInPictureRequestedSizeMetrics(
const blink::mojom::PictureInPictureWindowOptions& pip_options,
const display::Display& display) { … }
void PictureInPictureWindowManager::RecordFileDialogOpenMetric(
FileDialogOpenState state) { … }
#endif
void PictureInPictureWindowManager::NotifyObserversOnEnterPictureInPicture() { … }
PictureInPictureWindowManager::PictureInPictureWindowManager() = default;
PictureInPictureWindowManager::~PictureInPictureWindowManager() = default;