#include "chrome/browser/ui/apps/chrome_app_delegate.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/apps/platform_apps/audio_focus_web_contents_observer.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/file_system_access/file_system_access_permission_request_manager.h"
#include "chrome/browser/lifetime/termination_notification.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/media_stream_request.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "extensions/common/constants.h"
#include "extensions/common/mojom/app_window.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "printing/buildflags/buildflags.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_tab_helper.h"
#endif
#if BUILDFLAG(ENABLE_PRINTING)
#include "chrome/browser/printing/printing_init.h"
#endif
namespace {
int kAppWindowFirstShowTimeoutSeconds = …;
bool disable_external_open_for_testing_ = …;
content::WebContents* OpenURLFromTabInternal(
content::BrowserContext* context,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
void OpenURLAfterCheckIsDefaultBrowser(
std::unique_ptr<content::WebContents> source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback,
shell_integration::DefaultWebClientState state) { … }
}
void ChromeAppDelegate::RelinquishKeepAliveAfterTimeout(
const base::WeakPtr<ChromeAppDelegate>& chrome_app_delegate) { … }
class ChromeAppDelegate::NewWindowContentsDelegate
: public content::WebContentsDelegate { … };
content::WebContents*
ChromeAppDelegate::NewWindowContentsDelegate::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
ChromeAppDelegate::ChromeAppDelegate(Profile* profile, bool keep_alive)
: … { … }
ChromeAppDelegate::~ChromeAppDelegate() { … }
void ChromeAppDelegate::DisableExternalOpenForTesting() { … }
void ChromeAppDelegate::InitWebContents(content::WebContents* web_contents) { … }
void ChromeAppDelegate::RenderFrameCreated(
content::RenderFrameHost* frame_host) { … }
void ChromeAppDelegate::ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size) { … }
content::WebContents* ChromeAppDelegate::OpenURLFromTab(
content::BrowserContext* context,
content::WebContents* source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
void ChromeAppDelegate::AddNewContents(
content::BrowserContext* context,
std::unique_ptr<content::WebContents> new_contents,
const GURL& target_url,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& window_features,
bool user_gesture) { … }
void ChromeAppDelegate::RunFileChooser(
content::RenderFrameHost* render_frame_host,
scoped_refptr<content::FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) { … }
void ChromeAppDelegate::RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const extensions::Extension* extension) { … }
bool ChromeAppDelegate::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type,
const extensions::Extension* extension) { … }
int ChromeAppDelegate::PreferredIconSize() const { … }
void ChromeAppDelegate::SetWebContentsBlocked(
content::WebContents* web_contents,
bool blocked) { … }
bool ChromeAppDelegate::IsWebContentsVisible(
content::WebContents* web_contents) { … }
void ChromeAppDelegate::SetTerminatingCallback(base::OnceClosure callback) { … }
void ChromeAppDelegate::OnHide() { … }
void ChromeAppDelegate::OnShow() { … }
bool ChromeAppDelegate::TakeFocus(content::WebContents* web_contents,
bool reverse) { … }
content::PictureInPictureResult ChromeAppDelegate::EnterPictureInPicture(
content::WebContents* web_contents) { … }
void ChromeAppDelegate::ExitPictureInPicture() { … }
void ChromeAppDelegate::OnAppTerminating() { … }