#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include <stddef.h>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/guest_view/browser/guest_view_event.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/guest_view/common/guest_view_constants.h"
#include "components/input/native_web_keyboard_event.h"
#include "components/permissions/permission_util.h"
#include "components/web_cache/browser/web_cache_manager.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/child_process_security_policy.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/permission_result.h"
#include "content/public/browser/render_frame_host.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/render_widget_host_view.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/storage_partition_config.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/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/stop_find_action.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h"
#include "extensions/browser/api/web_request/extension_web_request_event_router.h"
#include "extensions/browser/bad_message.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/guest_view/web_view/web_view_constants.h"
#include "extensions/browser/guest_view/web_view/web_view_content_script_manager.h"
#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
#include "extensions/browser/guest_view/web_view/web_view_permission_types.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/url_loader_factory_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "ipc/ipc_message_macros.h"
#include "net/base/net_errors.h"
#include "net/cookies/canonical_cookie.h"
#include "services/network/public/mojom/clear_data_filter.mojom.h"
#include "third_party/blink/public/common/logging/logging_utils.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "url/url_constants.h"
UserMetricsAction;
GlobalRequestID;
RenderFrameHost;
RenderProcessHost;
StoragePartition;
WebContents;
GuestViewBase;
GuestViewEvent;
GuestViewManager;
ZoomController;
namespace extensions {
namespace {
constexpr char kAttributeAllowTransparency[] = …;
constexpr char kAttributeAllowScaling[] = …;
constexpr char kAttributeName[] = …;
constexpr char kAttributeSrc[] = …;
constexpr char kAPINamespace[] = …;
constexpr char kInitialZoomFactor[] = …;
constexpr char kParameterUserAgentOverride[] = …;
constexpr char kInternalBaseURLForDataURL[] = …;
constexpr char kInternalCurrentEntryIndex[] = …;
constexpr char kInternalEntryCount[] = …;
constexpr char kInternalProcessId[] = …;
constexpr char kInternalVisibleUrl[] = …;
uint32_t GetStoragePartitionRemovalMask(uint32_t web_view_removal_mask) { … }
std::string WindowOpenDispositionToString(
WindowOpenDisposition window_open_disposition) { … }
static std::string TerminationStatusToString(base::TerminationStatus status) { … }
std::string GetStoragePartitionIdFromPartitionConfig(
const content::StoragePartitionConfig& storage_partition_config) { … }
void ParsePartitionParam(const base::Value::Dict& create_params,
std::string* storage_partition_id,
bool* persist_storage) { … }
double ConvertZoomLevelToZoomFactor(double zoom_level) { … }
WebViewKey;
WebViewKeyToIDMap;
static base::LazyInstance<WebViewKeyToIDMap>::DestructorAtExit
web_view_key_to_id_map = …;
bool IsInWebViewMainFrame(content::NavigationHandle* navigation_handle) { … }
}
WebViewGuest::NewWindowInfo::NewWindowInfo(const GURL& url,
const std::string& name)
: … { … }
WebViewGuest::NewWindowInfo::NewWindowInfo(const WebViewGuest::NewWindowInfo&) =
default;
WebViewGuest::NewWindowInfo::~NewWindowInfo() = default;
void WebViewGuest::CleanUp(content::BrowserContext* browser_context,
int embedder_process_id,
int view_instance_id) { … }
std::unique_ptr<GuestViewBase> WebViewGuest::Create(
content::RenderFrameHost* owner_rfh) { … }
std::string WebViewGuest::GetPartitionID(
RenderProcessHost* render_process_host) { … }
const char WebViewGuest::Type[] = …;
const guest_view::GuestViewHistogramValue WebViewGuest::HistogramValue = …;
int WebViewGuest::GetOrGenerateRulesRegistryID(int embedder_process_id,
int webview_instance_id) { … }
void WebViewGuest::CreateWebContents(std::unique_ptr<GuestViewBase> owned_this,
const base::Value::Dict& create_params,
WebContentsCreatedCallback callback) { … }
void WebViewGuest::CreateWebContentsWithStoragePartition(
std::unique_ptr<GuestViewBase> owned_this,
const base::Value::Dict& create_params,
WebContentsCreatedCallback callback,
std::optional<content::StoragePartitionConfig> partition_config) { … }
void WebViewGuest::DidAttachToEmbedder() { … }
void WebViewGuest::DidInitialize(const base::Value::Dict& create_params) { … }
void WebViewGuest::MaybeRecreateGuestContents(
content::RenderFrameHost* outer_contents_frame) { … }
void WebViewGuest::ClearCodeCache(base::Time remove_since,
uint32_t removal_mask,
base::OnceClosure callback) { … }
void WebViewGuest::ClearDataInternal(base::Time remove_since,
uint32_t removal_mask,
base::OnceClosure callback) { … }
void WebViewGuest::GuestViewDidStopLoading() { … }
void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { … }
bool WebViewGuest::ZoomPropagatesFromEmbedderToGuest() const { … }
const char* WebViewGuest::GetAPINamespace() const { … }
int WebViewGuest::GetTaskPrefix() const { … }
void WebViewGuest::WebContentsDestroyed() { … }
void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
const gfx::Size& new_size) { … }
bool WebViewGuest::IsAutoSizeSupported() const { … }
void WebViewGuest::GuestZoomChanged(double old_zoom_level,
double new_zoom_level) { … }
void WebViewGuest::CloseContents(WebContents* source) { … }
void WebViewGuest::FindReply(WebContents* source,
int request_id,
int number_of_matches,
const gfx::Rect& selection_rect,
int active_match_ordinal,
bool final_update) { … }
double WebViewGuest::GetZoom() const { … }
ZoomController::ZoomMode WebViewGuest::GetZoomMode() { … }
bool WebViewGuest::HandleContextMenu(
content::RenderFrameHost& render_frame_host,
const content::ContextMenuParams& params) { … }
bool WebViewGuest::HandleKeyboardEvent(
WebContents* source,
const input::NativeWebKeyboardEvent& event) { … }
bool WebViewGuest::PreHandleGestureEvent(WebContents* source,
const blink::WebGestureEvent& event) { … }
void WebViewGuest::LoadAbort(bool is_top_level,
const GURL& url,
int error_code) { … }
void WebViewGuest::CreateNewGuestWebViewWindow(
const content::OpenURLParams& params) { … }
void WebViewGuest::NewGuestWebViewCallback(
const content::OpenURLParams& params,
std::unique_ptr<GuestViewBase> guest) { … }
void WebViewGuest::RendererResponsive(
WebContents* source,
content::RenderWidgetHost* render_widget_host) { … }
void WebViewGuest::RendererUnresponsive(
WebContents* source,
content::RenderWidgetHost* render_widget_host,
base::RepeatingClosure hang_monitor_restarter) { … }
void WebViewGuest::StartFind(
const std::u16string& search_text,
blink::mojom::FindOptionsPtr options,
scoped_refptr<WebViewInternalFindFunction> find_function) { … }
void WebViewGuest::StopFinding(content::StopFindAction action) { … }
bool WebViewGuest::Go(int relative_index) { … }
void WebViewGuest::Reload() { … }
void WebViewGuest::SetUserAgentOverride(
const std::string& user_agent_override) { … }
void WebViewGuest::Stop() { … }
void WebViewGuest::Terminate() { … }
bool WebViewGuest::ClearData(base::Time remove_since,
uint32_t removal_mask,
base::OnceClosure callback) { … }
WebViewGuest::WebViewGuest(content::RenderFrameHost* owner_rfh)
: … { … }
WebViewGuest::~WebViewGuest() { … }
void WebViewGuest::DidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
void WebViewGuest::LoadProgressChanged(double progress) { … }
void WebViewGuest::DocumentOnLoadCompletedInPrimaryMainFrame() { … }
void WebViewGuest::DidStartNavigation(
content::NavigationHandle* navigation_handle) { … }
void WebViewGuest::DidRedirectNavigation(
content::NavigationHandle* navigation_handle) { … }
void WebViewGuest::PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) { … }
void WebViewGuest::UserAgentOverrideSet(
const blink::UserAgentOverride& ua_override) { … }
void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host,
const std::string& name) { … }
void WebViewGuest::OnAudioStateChanged(bool audible) { … }
void WebViewGuest::OnDidAddMessageToConsole(
content::RenderFrameHost* source_frame,
blink::mojom::ConsoleMessageLevel log_level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id,
const std::optional<std::u16string>& untrusted_stack_trace) { … }
void WebViewGuest::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) { … }
void WebViewGuest::RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) { … }
void WebViewGuest::RenderFrameHostChanged(content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) { … }
void WebViewGuest::ReportFrameNameChange(const std::string& name) { … }
void WebViewGuest::PushWebViewStateToIOThread(
content::RenderFrameHost* guest_host) { … }
void WebViewGuest::RequestMediaAccessPermission(
WebContents* source,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { … }
bool WebViewGuest::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const url::Origin& security_origin,
blink::mojom::MediaStreamType type) { … }
void WebViewGuest::CanDownload(const GURL& url,
const std::string& request_method,
base::OnceCallback<void(bool)> callback) { … }
void WebViewGuest::OnOwnerAudioMutedStateUpdated(bool muted) { … }
void WebViewGuest::SignalWhenReady(base::OnceClosure callback) { … }
void WebViewGuest::WillAttachToEmbedder() { … }
bool WebViewGuest::RequiresSslInterstitials() const { … }
bool WebViewGuest::IsPermissionRequestable(ContentSettingsType type) const { … }
std::optional<content::PermissionResult> WebViewGuest::OverridePermissionResult(
ContentSettingsType type) const { … }
content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager(
WebContents* source) { … }
void WebViewGuest::NavigateGuest(
const std::string& src,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback,
bool force_navigation) { … }
bool WebViewGuest::HandleKeyboardShortcuts(
const input::NativeWebKeyboardEvent& event) { … }
void WebViewGuest::ApplyAttributes(const base::Value::Dict& params) { … }
void WebViewGuest::ShowContextMenu(int request_id) { … }
void WebViewGuest::SetName(const std::string& name) { … }
void WebViewGuest::SetSpatialNavigationEnabled(bool enabled) { … }
bool WebViewGuest::IsSpatialNavigationEnabled() const { … }
void WebViewGuest::SetZoom(double zoom_factor) { … }
void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { … }
void WebViewGuest::SetAllowTransparency(bool allow) { … }
void WebViewGuest::SetAudioMuted(bool mute) { … }
bool WebViewGuest::IsAudioMuted() { … }
void WebViewGuest::SetTransparency(
content::RenderFrameHost* render_frame_host) { … }
void WebViewGuest::SetAllowScaling(bool allow) { … }
bool WebViewGuest::ShouldResumeRequestsForCreatedWindow() { … }
content::WebContents* WebViewGuest::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) { … }
WebContents* WebViewGuest::OpenURLFromTab(
WebContents* source,
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback) { … }
void WebViewGuest::WebContentsCreated(WebContents* source_contents,
int opener_render_process_id,
int opener_render_frame_id,
const std::string& frame_name,
const GURL& target_url,
WebContents* new_contents) { … }
void WebViewGuest::EnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) { … }
void WebViewGuest::ExitFullscreenModeForTab(WebContents* web_contents) { … }
bool WebViewGuest::IsFullscreenForTabOrPending(
const WebContents* web_contents) { … }
void WebViewGuest::RequestPointerLock(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) { … }
void WebViewGuest::LoadURLWithParams(
const GURL& url,
const content::Referrer& referrer,
ui::PageTransition transition_type,
base::OnceCallback<void(content::NavigationHandle&)>
navigation_handle_callback,
bool force_navigation) { … }
void WebViewGuest::RequestNewWindowPermission(
WindowOpenDisposition disposition,
const gfx::Rect& initial_bounds,
std::unique_ptr<WebViewGuest> new_guest) { … }
GURL WebViewGuest::ResolveURL(const std::string& src) { … }
void WebViewGuest::OnWebViewNewWindowResponse(int new_window_instance_id,
bool allow,
const std::string& user_input) { … }
void WebViewGuest::OnFullscreenPermissionDecided(
bool allowed,
const std::string& user_input) { … }
bool WebViewGuest::GuestMadeEmbedderFullscreen() const { … }
void WebViewGuest::SetFullscreenState(bool is_fullscreen) { … }
}