#include "content/shell/browser/shell.h"
#include <stddef.h>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/custom_handlers/protocol_handler.h"
#include "components/custom_handlers/protocol_handler_registry.h"
#include "components/custom_handlers/simple_protocol_handler_registry_factory.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/document_picture_in_picture_window_controller.h"
#include "content/public/browser/file_select_listener.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/picture_in_picture_window_controller.h"
#include "content/public/browser/presentation_receiver_flags.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/renderer_preferences_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/shell/app/resource.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_devtools_frontend.h"
#include "content/shell/browser/shell_javascript_dialog_manager.h"
#include "content/shell/common/shell_switches.h"
#include "media/media_buildflags.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
#include "third_party/blink/public/mojom/choosers/file_chooser.mojom-forward.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
namespace content {
namespace {
base::OnceClosure& GetMainMessageLoopQuitClosure() { … }
constexpr int kDefaultTestWindowWidthDip = …;
constexpr int kDefaultTestWindowHeightDip = …;
ShellPlatformDelegate* g_platform;
}
std::vector<Shell*> Shell::windows_;
base::OnceCallback<void(Shell*)> Shell::shell_created_callback_;
Shell::Shell(std::unique_ptr<WebContents> web_contents,
bool should_set_delegate)
: … { … }
Shell::~Shell() { … }
Shell* Shell::CreateShell(std::unique_ptr<WebContents> web_contents,
const gfx::Size& initial_size,
bool should_set_delegate) { … }
void Shell::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) { … }
void Shell::QuitMainMessageLoopForTesting() { … }
void Shell::SetShellCreatedCallback(
base::OnceCallback<void(Shell*)> shell_created_callback) { … }
bool Shell::ShouldHideToolbar() { … }
Shell* Shell::FromWebContents(WebContents* web_contents) { … }
void Shell::Initialize(std::unique_ptr<ShellPlatformDelegate> platform) { … }
void Shell::Shutdown() { … }
gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) { … }
Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
const GURL& url,
const scoped_refptr<SiteInstance>& site_instance,
const gfx::Size& initial_size) { … }
void Shell::RenderFrameCreated(RenderFrameHost* frame_host) { … }
void Shell::LoadURL(const GURL& url) { … }
void Shell::LoadURLForFrame(const GURL& url,
const std::string& frame_name,
ui::PageTransition transition_type) { … }
void Shell::LoadDataWithBaseURL(const GURL& url,
const std::string& data,
const GURL& base_url) { … }
#if BUILDFLAG(IS_ANDROID)
void Shell::LoadDataAsStringWithBaseURL(const GURL& url,
const std::string& data,
const GURL& base_url) {
bool load_as_string = true;
LoadDataWithBaseURLInternal(url, data, base_url, load_as_string);
}
#endif
void Shell::LoadDataWithBaseURLInternal(const GURL& url,
const std::string& data,
const GURL& base_url,
bool load_as_string) { … }
WebContents* Shell::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) { … }
void Shell::GoBackOrForward(int offset) { … }
void Shell::Reload() { … }
void Shell::ReloadBypassingCache() { … }
void Shell::Stop() { … }
void Shell::UpdateNavigationControls(bool should_show_loading_ui) { … }
void Shell::ShowDevTools() { … }
void Shell::CloseDevTools() { … }
void Shell::ResizeWebContentForTests(const gfx::Size& content_size) { … }
gfx::NativeView Shell::GetContentView() { … }
#if !BUILDFLAG(IS_ANDROID)
gfx::NativeWindow Shell::window() { … }
#endif
#if BUILDFLAG(IS_MAC)
void Shell::ActionPerformed(int control) {
switch (control) {
case IDC_NAV_BACK:
GoBackOrForward(-1);
break;
case IDC_NAV_FORWARD:
GoBackOrForward(1);
break;
case IDC_NAV_RELOAD:
Reload();
break;
case IDC_NAV_STOP:
Stop();
break;
}
}
void Shell::URLEntered(const std::string& url_string) {
if (!url_string.empty()) {
GURL url(url_string);
if (!url.has_scheme())
url = GURL("http://" + url_string);
LoadURL(url);
}
}
#endif
WebContents* Shell::OpenURLFromTab(
WebContents* source,
const OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
void Shell::LoadingStateChanged(WebContents* source,
bool should_show_loading_ui) { … }
#if BUILDFLAG(IS_ANDROID)
void Shell::SetOverlayMode(bool use_overlay_mode) {
g_platform->SetOverlayMode(this, use_overlay_mode);
}
#endif
void Shell::EnterFullscreenModeForTab(
RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) { … }
void Shell::ExitFullscreenModeForTab(WebContents* web_contents) { … }
void Shell::ToggleFullscreenModeForTab(WebContents* web_contents,
bool enter_fullscreen) { … }
bool Shell::IsFullscreenForTabOrPending(const WebContents* web_contents) { … }
blink::mojom::DisplayMode Shell::GetDisplayMode(
const WebContents* web_contents) { … }
#if !BUILDFLAG(IS_ANDROID)
void Shell::RegisterProtocolHandler(RenderFrameHost* requesting_frame,
const std::string& protocol,
const GURL& url,
bool user_gesture) { … }
#endif
void Shell::RequestPointerLock(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) { … }
void Shell::Close() { … }
void Shell::CloseContents(WebContents* source) { … }
bool Shell::CanOverscrollContent() { … }
void Shell::NavigationStateChanged(WebContents* source,
InvalidateTypes changed_flags) { … }
JavaScriptDialogManager* Shell::GetJavaScriptDialogManager(
WebContents* source) { … }
#if BUILDFLAG(IS_MAC)
void Shell::PrimaryPageChanged(Page& page) {
g_platform->DidNavigatePrimaryMainFramePostCommit(
this, WebContents::FromRenderFrameHost(&page.GetMainDocument()));
}
bool Shell::HandleKeyboardEvent(WebContents* source,
const input::NativeWebKeyboardEvent& event) {
return g_platform->HandleKeyboardEvent(this, source, event);
}
#endif
bool Shell::DidAddMessageToConsole(WebContents* source,
blink::mojom::ConsoleMessageLevel log_level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id) { … }
void Shell::RendererUnresponsive(
WebContents* source,
RenderWidgetHost* render_widget_host,
base::RepeatingClosure hang_monitor_restarter) { … }
void Shell::ActivateContents(WebContents* contents) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
std::unique_ptr<ColorChooser> Shell::OpenColorChooser(
WebContents* web_contents,
SkColor color,
const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions) {
return g_platform->OpenColorChooser(web_contents, color, suggestions);
}
#endif
void Shell::RunFileChooser(RenderFrameHost* render_frame_host,
scoped_refptr<FileSelectListener> listener,
const blink::mojom::FileChooserParams& params) { … }
void Shell::EnumerateDirectory(WebContents* web_contents,
scoped_refptr<FileSelectListener> listener,
const base::FilePath& path) { … }
bool Shell::IsBackForwardCacheSupported(WebContents& web_contents) { … }
PreloadingEligibility Shell::IsPrerender2Supported(WebContents& web_contents) { … }
namespace {
class PendingCallback : public base::RefCounted<PendingCallback> { … };
}
bool Shell::ShouldAllowRunningInsecureContent(WebContents* web_contents,
bool allowed_per_prefs,
const url::Origin& origin,
const GURL& resource_url) { … }
PictureInPictureResult Shell::EnterPictureInPicture(WebContents* web_contents) { … }
bool Shell::ShouldResumeRequestsForCreatedWindow() { … }
void Shell::SetContentsBounds(WebContents* source, const gfx::Rect& bounds) { … }
gfx::Size Shell::GetShellDefaultSize() { … }
#if BUILDFLAG(IS_ANDROID)
void Shell::LoadProgressChanged(double progress) {
g_platform->LoadProgressChanged(this, progress);
}
#endif
void Shell::TitleWasSet(NavigationEntry* entry) { … }
}