This source file includes following definitions.
- WebTextDirectionToChromeTextDirection
- DismissVirtualKeyboardTask
- IsRVHStateActive
- FromID
- From
- FromID
- weak_factory_
- GetDelegate
- GetSiteInstance
- CreateRenderView
- IsRenderViewLive
- SyncRendererPrefs
- GetWebkitPrefs
- Navigate
- NavigateToURL
- SetNavigationsSuspended
- CancelSuspendedNavigations
- SuppressDialogsUntilSwapOut
- OnSwappedOut
- WasSwappedOut
- SetPendingShutdown
- ClosePage
- ClosePageIgnoringUnloadEvents
- HasPendingCrossSiteRequest
- SetHasPendingCrossSiteRequest
- ActivateNearestFindResult
- RequestFindMatchRects
- DisableFullscreenEncryptedMediaPlayback
- SetWebUIHandle
- DragTargetDragEnter
- DragTargetDragOver
- DragTargetDragLeave
- DragTargetDrop
- DesktopNotificationPermissionRequestDone
- DesktopNotificationPostDisplay
- DesktopNotificationPostError
- DesktopNotificationPostClose
- DesktopNotificationPostClick
- JavaScriptDialogClosed
- DragSourceEndedAt
- DragSourceSystemDragEnded
- GetMainFrame
- AllowBindings
- GetEnabledBindings
- SetWebUIProperty
- GotFocus
- LostCapture
- LostMouseLock
- SetInitialFocus
- FilesSelectedInChooser
- DirectoryEnumerationFinished
- LoadStateChanged
- SuddenTerminationAllowed
- OnMessageReceived
- Init
- Shutdown
- IsRenderView
- CreateNewWindow
- CreateNewWidget
- CreateNewFullscreenWidget
- OnShowView
- OnShowWidget
- OnShowFullscreenWidget
- OnRunModal
- OnRenderViewReady
- OnRenderProcessGone
- OnUpdateState
- OnUpdateTitle
- OnUpdateEncoding
- OnUpdateTargetURL
- OnUpdateInspectorSetting
- OnClose
- OnRequestMove
- OnDidChangeLoadProgress
- OnDidDisownOpener
- OnDocumentAvailableInMainFrame
- OnDocumentOnLoadCompletedInMainFrame
- OnToggleFullscreen
- OnDidContentsPreferredSizeChange
- OnRenderAutoResized
- OnDidChangeScrollOffset
- OnDidChangeScrollbarsForMainFrame
- OnDidChangeScrollOffsetPinningForMainFrame
- OnDidChangeNumWheelEvents
- OnSelectionRootBoundsChanged
- OnRouteCloseEvent
- OnRouteMessageEvent
- OnRunJavaScriptMessage
- OnRunBeforeUnloadConfirm
- OnStartDragging
- OnUpdateDragCursor
- OnTargetDropACK
- OnTakeFocus
- OnFocusedNodeChanged
- OnUserGesture
- OnClosePageACK
- NotifyRendererUnresponsive
- NotifyRendererResponsive
- RequestToLockMouse
- IsFullscreen
- OnFocus
- OnBlur
- GetRootWindowResizerRect
- ForwardMouseEvent
- OnPointerEventActivate
- ForwardKeyboardEvent
- DidSelectPopupMenuItems
- DidCancelPopupMenu
- DidSelectPopupMenuItem
- DidCancelPopupMenu
- SendOrientationChangeEvent
- ToggleSpeechInput
- IsWaitingForUnloadACK
- ExitFullscreen
- GetWebkitPreferences
- DisownOpener
- SetAccessibilityCallbackForTesting
- UpdateWebkitPreferences
- GetAudioOutputControllers
- ClearFocusedElement
- Zoom
- DisableScrollbarsForThreshold
- EnablePreferredSizeMode
- EnableAutoResize
- DisableAutoResize
- CopyImageAt
- ExecuteMediaPlayerActionAtLocation
- ExecutePluginActionAtLocation
- NotifyMoveOrResizeStarted
- OnAccessibilityEvents
- OnAccessibilityLocationChanges
- OnDidZoomURL
- OnRequestDesktopNotificationPermission
- OnShowDesktopNotification
- OnCancelDesktopNotification
- OnRunFileChooser
- OnDidAccessInitialDocument
- OnFocusedNodeTouched
- OnShowPopup
- OnHidePopup
- SetState
- CanAccessFilesOfPageState
- AttachToFrameTree
#include "content/browser/renderer_host/render_view_host_impl.h"
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/i18n/rtl.h"
#include "base/json/json_reader.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "base/time/time.h"
#include "base/values.h"
#include "cc/base/switches.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/cross_site_request_manager.h"
#include "content/browser/dom_storage/session_storage_namespace_impl.h"
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/gpu/gpu_surface_tracker.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/input/timeout_monitor.h"
#include "content/browser/renderer_host/media/audio_renderer_host.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/common/accessibility_messages.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/content_switches_internal.h"
#include "content/common/desktop_notification_messages.h"
#include "content/common/drag_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/input_messages.h"
#include "content/common/inter_process_time_ticks_converter.h"
#include "content/common/speech_recognition_messages.h"
#include "content/common/swapped_out_messages.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_view_host_delegate_view.h"
#include "content/port/browser/render_widget_host_view_port.h"
#include "content/public/browser/ax_event_notification_details.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/drop_data.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
#include "net/url_request/url_request_context_getter.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/ax_tree.h"
#include "ui/base/touch/touch_device.h"
#include "ui/base/touch/touch_enabled.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "webkit/browser/fileapi/isolated_context.h"
#if defined(OS_MACOSX)
#include "content/browser/renderer_host/popup_menu_helper_mac.h"
#elif defined(OS_ANDROID)
#include "content/browser/media/android/browser_media_player_manager.h"
#elif defined(OS_WIN)
#include "base/win/win_util.h"
#endif
using base::TimeDelta;
using blink::WebConsoleMessage;
using blink::WebDragOperation;
using blink::WebDragOperationNone;
using blink::WebDragOperationsMask;
using blink::WebInputEvent;
using blink::WebMediaPlayerAction;
using blink::WebPluginAction;
namespace content {
namespace {
base::i18n::TextDirection WebTextDirectionToChromeTextDirection(
blink::WebTextDirection dir) {
switch (dir) {
case blink::WebTextDirectionLeftToRight:
return base::i18n::LEFT_TO_RIGHT;
case blink::WebTextDirectionRightToLeft:
return base::i18n::RIGHT_TO_LEFT;
default:
NOTREACHED();
return base::i18n::UNKNOWN_DIRECTION;
}
}
#if defined(OS_WIN)
const int kVirtualKeyboardDisplayWaitTimeoutMs = 100;
const int kMaxVirtualKeyboardDisplayRetries = 5;
void DismissVirtualKeyboardTask() {
static int virtual_keyboard_display_retries = 0;
if (!base::win::DismissVirtualKeyboard()) {
if (virtual_keyboard_display_retries < kMaxVirtualKeyboardDisplayRetries) {
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)),
TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs));
++virtual_keyboard_display_retries;
} else {
virtual_keyboard_display_retries = 0;
}
}
}
#endif
}
const int RenderViewHostImpl::kUnloadTimeoutMS = 1000;
bool RenderViewHostImpl::IsRVHStateActive(RenderViewHostImplState rvh_state) {
if (rvh_state == STATE_DEFAULT ||
rvh_state == STATE_WAITING_FOR_UNLOAD_ACK ||
rvh_state == STATE_WAITING_FOR_COMMIT ||
rvh_state == STATE_WAITING_FOR_CLOSE)
return true;
return false;
}
RenderViewHost* RenderViewHost::FromID(int render_process_id,
int render_view_id) {
return RenderViewHostImpl::FromID(render_process_id, render_view_id);
}
RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) {
DCHECK(rwh->IsRenderView());
return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh));
}
RenderViewHostImpl* RenderViewHostImpl::FromID(int render_process_id,
int render_view_id) {
RenderWidgetHost* widget =
RenderWidgetHost::FromID(render_process_id, render_view_id);
if (!widget || !widget->IsRenderView())
return NULL;
return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget));
}
RenderViewHostImpl::RenderViewHostImpl(
SiteInstance* instance,
RenderViewHostDelegate* delegate,
RenderWidgetHostDelegate* widget_delegate,
int routing_id,
int main_frame_routing_id,
bool swapped_out,
bool hidden)
: RenderWidgetHostImpl(widget_delegate,
instance->GetProcess(),
routing_id,
hidden),
frames_ref_count_(0),
delegate_(delegate),
instance_(static_cast<SiteInstanceImpl*>(instance)),
waiting_for_drag_context_response_(false),
enabled_bindings_(0),
navigations_suspended_(false),
has_accessed_initial_document_(false),
main_frame_routing_id_(main_frame_routing_id),
run_modal_reply_msg_(NULL),
run_modal_opener_id_(MSG_ROUTING_NONE),
is_waiting_for_beforeunload_ack_(false),
unload_ack_is_for_cross_site_transition_(false),
are_javascript_messages_suppressed_(false),
sudden_termination_allowed_(false),
render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING),
virtual_keyboard_requested_(false),
weak_factory_(this) {
DCHECK(instance_.get());
CHECK(delegate_);
GetProcess()->EnableSendQueue();
if (swapped_out) {
rvh_state_ = STATE_SWAPPED_OUT;
} else {
rvh_state_ = STATE_DEFAULT;
instance_->increment_active_view_count();
}
if (ResourceDispatcherHostImpl::Get()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated,
base::Unretained(ResourceDispatcherHostImpl::Get()),
GetProcess()->GetID(), GetRoutingID()));
}
#if defined(OS_ANDROID)
media_player_manager_.reset(BrowserMediaPlayerManager::Create(this));
#endif
unload_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
&RenderViewHostImpl::OnSwappedOut, weak_factory_.GetWeakPtr(), true)));
}
RenderViewHostImpl::~RenderViewHostImpl() {
if (ResourceDispatcherHostImpl::Get()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
base::Unretained(ResourceDispatcherHostImpl::Get()),
GetProcess()->GetID(), GetRoutingID()));
}
delegate_->RenderViewDeleted(this);
CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
GetProcess()->GetID(), GetRoutingID(), false);
if (IsRVHStateActive(rvh_state_))
instance_->decrement_active_view_count();
}
RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const {
return delegate_;
}
SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
return instance_.get();
}
bool RenderViewHostImpl::CreateRenderView(
const base::string16& frame_name,
int opener_route_id,
int32 max_page_id) {
TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
DCHECK(!IsRenderViewLive()) << "Creating view twice";
if (!GetProcess()->Init())
return false;
DCHECK(GetProcess()->HasConnection());
DCHECK(GetProcess()->GetBrowserContext());
renderer_initialized_ = true;
GpuSurfaceTracker::Get()->SetSurfaceHandle(
surface_id(), GetCompositingSurface());
int32 next_page_id = 1;
if (max_page_id > -1)
next_page_id = max_page_id + 1;
ViewMsg_New_Params params;
params.renderer_preferences =
delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
params.web_preferences = delegate_->GetWebkitPrefs();
params.view_id = GetRoutingID();
params.main_frame_routing_id = main_frame_routing_id_;
params.surface_id = surface_id();
params.session_storage_namespace_id =
delegate_->GetSessionStorageNamespace(instance_)->id();
params.frame_name = frame_name;
params.opener_route_id = opener_route_id;
params.swapped_out = !IsRVHStateActive(rvh_state_);
params.hidden = is_hidden();
params.next_page_id = next_page_id;
GetWebScreenInfo(¶ms.screen_info);
params.accessibility_mode = accessibility_mode();
Send(new ViewMsg_New(params));
if (GetProcess()->IsGuest())
DCHECK_EQ(0, enabled_bindings_);
Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_));
delegate_->RenderViewCreated(this);
return true;
}
bool RenderViewHostImpl::IsRenderViewLive() const {
return GetProcess()->HasConnection() && renderer_initialized_;
}
void RenderViewHostImpl::SyncRendererPrefs() {
Send(new ViewMsg_SetRendererPrefs(GetRoutingID(),
delegate_->GetRendererPrefs(
GetProcess()->GetBrowserContext())));
}
WebPreferences RenderViewHostImpl::GetWebkitPrefs(const GURL& url) {
TRACE_EVENT0("browser", "RenderViewHostImpl::GetWebkitPrefs");
WebPreferences prefs;
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
prefs.javascript_enabled =
!command_line.HasSwitch(switches::kDisableJavaScript);
prefs.web_security_enabled =
!command_line.HasSwitch(switches::kDisableWebSecurity);
prefs.plugins_enabled =
!command_line.HasSwitch(switches::kDisablePlugins);
prefs.java_enabled =
!command_line.HasSwitch(switches::kDisableJava);
prefs.remote_fonts_enabled =
!command_line.HasSwitch(switches::kDisableRemoteFonts);
prefs.xslt_enabled =
!command_line.HasSwitch(switches::kDisableXSLT);
prefs.xss_auditor_enabled =
!command_line.HasSwitch(switches::kDisableXSSAuditor);
prefs.application_cache_enabled =
!command_line.HasSwitch(switches::kDisableApplicationCache);
prefs.local_storage_enabled =
!command_line.HasSwitch(switches::kDisableLocalStorage);
prefs.databases_enabled =
!command_line.HasSwitch(switches::kDisableDatabases);
#if defined(OS_ANDROID)
prefs.webaudio_enabled =
!command_line.HasSwitch(switches::kDisableWebAudio);
#endif
prefs.experimental_webgl_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisable3DAPIs) &&
!command_line.HasSwitch(switches::kDisableExperimentalWebGL);
prefs.pepper_3d_enabled =
!command_line.HasSwitch(switches::kDisablePepper3d);
prefs.flash_3d_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisableFlash3d);
prefs.flash_stage3d_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisableFlashStage3d);
prefs.flash_stage3d_baseline_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisableFlashStage3d);
prefs.gl_multisampling_enabled =
!command_line.HasSwitch(switches::kDisableGLMultisampling);
prefs.privileged_webgl_extensions_enabled =
command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
prefs.site_specific_quirks_enabled =
!command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
prefs.allow_file_access_from_file_urls =
command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
prefs.layer_squashing_enabled = false;
if (command_line.HasSwitch(switches::kEnableLayerSquashing))
prefs.layer_squashing_enabled = true;
if (command_line.HasSwitch(switches::kDisableLayerSquashing))
prefs.layer_squashing_enabled = false;
prefs.show_paint_rects =
command_line.HasSwitch(switches::kShowPaintRects);
prefs.accelerated_compositing_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
prefs.force_compositing_mode = content::IsForceCompositingModeEnabled();
prefs.accelerated_2d_canvas_enabled =
GpuProcessHost::gpu_enabled() &&
!command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
prefs.antialiased_2d_canvas_disabled =
command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
prefs.accelerated_2d_canvas_msaa_sample_count =
atoi(command_line.GetSwitchValueASCII(
switches::kAcceleratedCanvas2dMSAASampleCount).c_str());
prefs.deferred_filters_enabled =
command_line.HasSwitch(switches::kEnableDeferredFilters);
prefs.accelerated_compositing_for_3d_transforms_enabled =
prefs.accelerated_compositing_for_animation_enabled =
!command_line.HasSwitch(switches::kDisableAcceleratedLayers);
prefs.accelerated_compositing_for_plugins_enabled = true;
prefs.accelerated_compositing_for_video_enabled =
!command_line.HasSwitch(switches::kDisableAcceleratedVideo);
prefs.lazy_layout_enabled =
command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures);
prefs.region_based_columns_enabled =
command_line.HasSwitch(switches::kEnableRegionBasedColumns);
prefs.threaded_html_parser =
!command_line.HasSwitch(switches::kDisableThreadedHTMLParser);
prefs.experimental_websocket_enabled =
command_line.HasSwitch(switches::kEnableExperimentalWebSocket);
if (command_line.HasSwitch(cc::switches::kEnablePinchVirtualViewport)) {
prefs.pinch_virtual_viewport_enabled = true;
prefs.pinch_overlay_scrollbar_thickness = 10;
}
prefs.use_solid_color_scrollbars = ui::IsOverlayScrollbarEnabled();
#if defined(OS_ANDROID)
prefs.user_gesture_required_for_media_playback = !command_line.HasSwitch(
switches::kDisableGestureRequirementForMediaPlayback);
#endif
prefs.touch_enabled = ui::AreTouchEventsEnabled();
prefs.device_supports_touch = prefs.touch_enabled &&
ui::IsTouchDevicePresent();
#if defined(OS_ANDROID)
prefs.device_supports_mouse = false;
#endif
prefs.pointer_events_max_touch_points = ui::MaxTouchPoints();
prefs.touch_adjustment_enabled =
!command_line.HasSwitch(switches::kDisableTouchAdjustment);
prefs.compositor_touch_hit_testing =
!command_line.HasSwitch(
cc::switches::kDisableCompositorTouchHitTesting) &&
!command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths);
#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
bool default_enable_scroll_animator = true;
#else
bool default_enable_scroll_animator = false;
#endif
prefs.enable_scroll_animator = default_enable_scroll_animator;
if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
prefs.enable_scroll_animator = true;
if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
prefs.enable_scroll_animator = false;
prefs.visual_word_movement_enabled =
command_line.HasSwitch(switches::kEnableVisualWordMovement);
GpuDataManagerImpl::GetInstance()->UpdateRendererWebPrefs(&prefs);
if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
GetProcess()->GetID())) {
prefs.loads_images_automatically = true;
prefs.javascript_enabled = true;
}
prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
switches::kDisableFixedPositionCreatesStackingContext);
prefs.gesture_tap_highlight_enabled = !command_line.HasSwitch(
switches::kDisableGestureTapHighlight);
prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
prefs.viewport_meta_enabled =
command_line.HasSwitch(switches::kEnableViewportMeta);
prefs.viewport_enabled =
command_line.HasSwitch(switches::kEnableViewport) ||
prefs.viewport_meta_enabled;
prefs.main_frame_resizes_are_orientation_changes =
command_line.HasSwitch(switches::kMainFrameResizesAreOrientationChanges);
prefs.deferred_image_decoding_enabled =
command_line.HasSwitch(switches::kEnableDeferredImageDecoding) ||
content::IsImplSidePaintingEnabled();
prefs.spatial_navigation_enabled = command_line.HasSwitch(
switches::kEnableSpatialNavigation);
GetContentClient()->browser()->OverrideWebkitPrefs(this, url, &prefs);
bool guest_compositing_enabled = !command_line.HasSwitch(
switches::kDisableBrowserPluginCompositing);
if (GetProcess()->IsGuest() && !guest_compositing_enabled) {
prefs.force_compositing_mode = false;
prefs.accelerated_compositing_enabled = false;
}
return prefs;
}
void RenderViewHostImpl::Navigate(const FrameMsg_Navigate_Params& params) {
TRACE_EVENT0("renderer_host", "RenderViewHostImpl::Navigate");
delegate_->GetFrameTree()->GetMainFrame()->Navigate(params);
}
void RenderViewHostImpl::NavigateToURL(const GURL& url) {
delegate_->GetFrameTree()->GetMainFrame()->NavigateToURL(url);
}
void RenderViewHostImpl::SetNavigationsSuspended(
bool suspend,
const base::TimeTicks& proceed_time) {
DCHECK(navigations_suspended_ != suspend);
navigations_suspended_ = suspend;
if (!suspend && suspended_nav_params_) {
SetState(STATE_DEFAULT);
DCHECK(!proceed_time.is_null());
suspended_nav_params_->browser_navigation_start = proceed_time;
Send(new FrameMsg_Navigate(
main_frame_routing_id_, *suspended_nav_params_.get()));
suspended_nav_params_.reset();
}
}
void RenderViewHostImpl::CancelSuspendedNavigations() {
if (suspended_nav_params_)
suspended_nav_params_.reset();
navigations_suspended_ = false;
}
void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
}
void RenderViewHostImpl::OnSwappedOut(bool timed_out) {
if (!IsWaitingForUnloadACK())
return;
unload_event_monitor_timeout_->Stop();
if (timed_out) {
base::ProcessHandle process_handle = GetProcess()->GetHandle();
int views = 0;
scoped_ptr<RenderWidgetHostIterator> widgets(
RenderWidgetHost::GetRenderWidgetHosts());
while (RenderWidgetHost* widget = widgets->GetNextHost()) {
if (widget->GetProcess()->GetID() == GetProcess()->GetID())
++views;
}
if (!RenderProcessHost::run_renderer_in_process() &&
process_handle && views <= 1) {
if (SuddenTerminationAllowed()) {
UMA_HISTOGRAM_PERCENTAGE(
"BrowserRenderProcessHost.ChildKillsUnresponsive", 1);
}
}
}
switch (rvh_state_) {
case STATE_WAITING_FOR_UNLOAD_ACK:
SetState(STATE_WAITING_FOR_COMMIT);
break;
case STATE_PENDING_SWAP_OUT:
SetState(STATE_SWAPPED_OUT);
break;
case STATE_PENDING_SHUTDOWN:
DCHECK(!pending_shutdown_on_swap_out_.is_null());
pending_shutdown_on_swap_out_.Run();
break;
default:
NOTREACHED();
}
}
void RenderViewHostImpl::WasSwappedOut(
const base::Closure& pending_delete_on_swap_out) {
Send(new ViewMsg_WasSwappedOut(GetRoutingID()));
if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) {
SetState(STATE_PENDING_SWAP_OUT);
if (!instance_->active_view_count())
SetPendingShutdown(pending_delete_on_swap_out);
} else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) {
SetState(STATE_SWAPPED_OUT);
} else if (rvh_state_ == STATE_DEFAULT) {
DCHECK(!IsRenderViewLive());
SetState(STATE_SWAPPED_OUT);
} else {
NOTREACHED();
}
}
void RenderViewHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) {
pending_shutdown_on_swap_out_ = on_swap_out;
SetState(STATE_PENDING_SHUTDOWN);
}
void RenderViewHostImpl::ClosePage() {
SetState(STATE_WAITING_FOR_CLOSE);
StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
if (IsRenderViewLive()) {
increment_in_flight_event_count();
NotificationService::current()->Notify(
NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
Source<RenderViewHost>(this),
NotificationService::NoDetails());
Send(new ViewMsg_ClosePage(GetRoutingID()));
} else {
ClosePageIgnoringUnloadEvents();
}
}
void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() {
StopHangMonitorTimeout();
is_waiting_for_beforeunload_ack_ = false;
sudden_termination_allowed_ = true;
delegate_->Close(this);
}
bool RenderViewHostImpl::HasPendingCrossSiteRequest() {
return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest(
GetProcess()->GetID(), GetRoutingID());
}
void RenderViewHostImpl::SetHasPendingCrossSiteRequest(
bool has_pending_request) {
CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
GetProcess()->GetID(), GetRoutingID(), has_pending_request);
}
#if defined(OS_ANDROID)
void RenderViewHostImpl::ActivateNearestFindResult(int request_id,
float x,
float y) {
Send(new InputMsg_ActivateNearestFindResult(GetRoutingID(),
request_id, x, y));
}
void RenderViewHostImpl::RequestFindMatchRects(int current_version) {
Send(new ViewMsg_FindMatchRects(GetRoutingID(), current_version));
}
void RenderViewHostImpl::DisableFullscreenEncryptedMediaPlayback() {
media_player_manager_->DisableFullscreenEncryptedMediaPlayback();
}
#endif
#if defined(USE_MOJO)
void RenderViewHostImpl::SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) {
if (GetProcess()->IsGuest()) {
NOTREACHED() << "Never grant bindings to a guest process.";
return;
}
if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) == 0) {
NOTREACHED() << "You must grant bindings before setting the handle";
return;
}
DCHECK(renderer_initialized_);
RenderProcessHostImpl* process =
static_cast<RenderProcessHostImpl*>(GetProcess());
process->SetWebUIHandle(GetRoutingID(), handle.Pass());
}
#endif
void RenderViewHostImpl::DragTargetDragEnter(
const DropData& drop_data,
const gfx::Point& client_pt,
const gfx::Point& screen_pt,
WebDragOperationsMask operations_allowed,
int key_modifiers) {
const int renderer_id = GetProcess()->GetID();
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
DropData filtered_data(drop_data);
GetProcess()->FilterURL(true, &filtered_data.url);
if (drop_data.did_originate_from_renderer) {
filtered_data.filenames.clear();
}
fileapi::IsolatedContext::FileInfoSet files;
for (std::vector<ui::FileInfo>::iterator iter(
filtered_data.filenames.begin());
iter != filtered_data.filenames.end();
++iter) {
if (iter->display_name.empty()) {
std::string name;
files.AddPath(iter->path, &name);
iter->display_name = base::FilePath::FromUTF8Unsafe(name);
} else {
files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe());
}
policy->GrantRequestSpecificFileURL(renderer_id,
net::FilePathToFileURL(iter->path));
if (!policy->CanReadFile(renderer_id, iter->path))
policy->GrantReadFile(renderer_id, iter->path);
}
fileapi::IsolatedContext* isolated_context =
fileapi::IsolatedContext::GetInstance();
DCHECK(isolated_context);
std::string filesystem_id = isolated_context->RegisterDraggedFileSystem(
files);
if (!filesystem_id.empty()) {
policy->GrantReadFileSystem(renderer_id, filesystem_id);
}
filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id);
Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt,
screen_pt, operations_allowed,
key_modifiers));
}
void RenderViewHostImpl::DragTargetDragOver(
const gfx::Point& client_pt,
const gfx::Point& screen_pt,
WebDragOperationsMask operations_allowed,
int key_modifiers) {
Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt,
operations_allowed, key_modifiers));
}
void RenderViewHostImpl::DragTargetDragLeave() {
Send(new DragMsg_TargetDragLeave(GetRoutingID()));
}
void RenderViewHostImpl::DragTargetDrop(
const gfx::Point& client_pt,
const gfx::Point& screen_pt,
int key_modifiers) {
Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt,
key_modifiers));
}
void RenderViewHostImpl::DesktopNotificationPermissionRequestDone(
int callback_context) {
Send(new DesktopNotificationMsg_PermissionRequestDone(
GetRoutingID(), callback_context));
}
void RenderViewHostImpl::DesktopNotificationPostDisplay(int callback_context) {
Send(new DesktopNotificationMsg_PostDisplay(GetRoutingID(),
callback_context));
}
void RenderViewHostImpl::DesktopNotificationPostError(
int notification_id,
const base::string16& message) {
Send(new DesktopNotificationMsg_PostError(
GetRoutingID(), notification_id, message));
}
void RenderViewHostImpl::DesktopNotificationPostClose(int notification_id,
bool by_user) {
Send(new DesktopNotificationMsg_PostClose(
GetRoutingID(), notification_id, by_user));
}
void RenderViewHostImpl::DesktopNotificationPostClick(int notification_id) {
Send(new DesktopNotificationMsg_PostClick(GetRoutingID(), notification_id));
}
void RenderViewHostImpl::JavaScriptDialogClosed(
IPC::Message* reply_msg,
bool success,
const base::string16& user_input) {
GetProcess()->SetIgnoreInputEvents(false);
bool is_waiting = is_waiting_for_beforeunload_ack_ || IsWaitingForUnloadACK();
if (is_waiting) {
StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
success ? kUnloadTimeoutMS : hung_renderer_delay_ms_));
}
ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg,
success, user_input);
Send(reply_msg);
if (is_waiting && are_javascript_messages_suppressed_)
delegate_->RendererUnresponsive(
this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK());
}
void RenderViewHostImpl::DragSourceEndedAt(
int client_x, int client_y, int screen_x, int screen_y,
WebDragOperation operation) {
Send(new DragMsg_SourceEnded(GetRoutingID(),
gfx::Point(client_x, client_y),
gfx::Point(screen_x, screen_y),
operation));
}
void RenderViewHostImpl::DragSourceSystemDragEnded() {
Send(new DragMsg_SourceSystemDragEnded(GetRoutingID()));
}
RenderFrameHost* RenderViewHostImpl::GetMainFrame() {
return RenderFrameHost::FromID(GetProcess()->GetID(), main_frame_routing_id_);
}
void RenderViewHostImpl::AllowBindings(int bindings_flags) {
if (GetProcess()->IsGuest()) {
NOTREACHED() << "Never grant bindings to a guest process.";
return;
}
if (bindings_flags & BINDINGS_POLICY_WEB_UI &&
GetProcess()->HasConnection() &&
!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
GetProcess()->GetID())) {
RenderProcessHostImpl* process =
static_cast<RenderProcessHostImpl*>(GetProcess());
if (process->GetActiveViewCount() > 1)
return;
}
if (bindings_flags & BINDINGS_POLICY_WEB_UI) {
ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings(
GetProcess()->GetID());
}
enabled_bindings_ |= bindings_flags;
if (renderer_initialized_)
Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_));
}
int RenderViewHostImpl::GetEnabledBindings() const {
return enabled_bindings_;
}
void RenderViewHostImpl::SetWebUIProperty(const std::string& name,
const std::string& value) {
if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI) {
Send(new ViewMsg_SetWebUIProperty(GetRoutingID(), name, value));
} else {
RecordAction(
base::UserMetricsAction("BindingsMismatchTerminate_RVH_WebUI"));
base::KillProcess(
GetProcess()->GetHandle(), content::RESULT_CODE_KILLED, false);
}
}
void RenderViewHostImpl::GotFocus() {
RenderWidgetHostImpl::GotFocus();
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (view)
view->GotFocus();
}
void RenderViewHostImpl::LostCapture() {
RenderWidgetHostImpl::LostCapture();
delegate_->LostCapture();
}
void RenderViewHostImpl::LostMouseLock() {
RenderWidgetHostImpl::LostMouseLock();
delegate_->LostMouseLock();
}
void RenderViewHostImpl::SetInitialFocus(bool reverse) {
Send(new ViewMsg_SetInitialFocus(GetRoutingID(), reverse));
}
void RenderViewHostImpl::FilesSelectedInChooser(
const std::vector<ui::SelectedFileInfo>& files,
FileChooserParams::Mode permissions) {
for (size_t i = 0; i < files.size(); ++i) {
const ui::SelectedFileInfo& file = files[i];
if (permissions == FileChooserParams::Save) {
ChildProcessSecurityPolicyImpl::GetInstance()->GrantCreateReadWriteFile(
GetProcess()->GetID(), file.local_path);
} else {
ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
GetProcess()->GetID(), file.local_path);
}
}
Send(new ViewMsg_RunFileChooserResponse(GetRoutingID(), files));
}
void RenderViewHostImpl::DirectoryEnumerationFinished(
int request_id,
const std::vector<base::FilePath>& files) {
for (std::vector<base::FilePath>::const_iterator file = files.begin();
file != files.end(); ++file) {
ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
GetProcess()->GetID(), *file);
}
Send(new ViewMsg_EnumerateDirectoryResponse(GetRoutingID(),
request_id,
files));
}
void RenderViewHostImpl::LoadStateChanged(
const GURL& url,
const net::LoadStateWithParam& load_state,
uint64 upload_position,
uint64 upload_size) {
delegate_->LoadStateChanged(url, load_state, upload_position, upload_size);
}
bool RenderViewHostImpl::SuddenTerminationAllowed() const {
return sudden_termination_allowed_ ||
GetProcess()->SuddenTerminationAllowed();
}
bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) {
if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this))
return true;
if (IsSwappedOut()) {
if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) {
if (msg.is_sync()) {
IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
reply->set_reply_error();
Send(reply);
}
return true;
}
}
if (delegate_->OnMessageReceived(this, msg))
return true;
bool handled = true;
bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(RenderViewHostImpl, msg, msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowFullscreenWidget,
OnShowFullscreenWidget)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunModal, OnRunModal)
IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady)
IPC_MESSAGE_HANDLER(ViewHostMsg_RenderProcessGone, OnRenderProcessGone)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState, OnUpdateState)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTitle, OnUpdateTitle)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateEncoding, OnUpdateEncoding)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnUpdateTargetURL)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateInspectorSetting,
OnUpdateInspectorSetting)
IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose)
IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeLoadProgress,
OnDidChangeLoadProgress)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisownOpener, OnDidDisownOpener)
IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame,
OnDocumentAvailableInMainFrame)
IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame,
OnDocumentOnLoadCompletedInMainFrame)
IPC_MESSAGE_HANDLER(ViewHostMsg_ToggleFullscreen, OnToggleFullscreen)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange,
OnDidContentsPreferredSizeChange)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffset,
OnDidChangeScrollOffset)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollbarsForMainFrame,
OnDidChangeScrollbarsForMainFrame)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame,
OnDidChangeScrollOffsetPinningForMainFrame)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumWheelEvents,
OnDidChangeNumWheelEvents)
IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent,
OnRouteCloseEvent)
IPC_MESSAGE_HANDLER(ViewHostMsg_RouteMessageEvent, OnRouteMessageEvent)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage,
OnRunJavaScriptMessage)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm,
OnRunBeforeUnloadConfirm)
IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnStartDragging)
IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor)
IPC_MESSAGE_HANDLER(DragHostMsg_TargetDrop_ACK, OnTargetDropACK)
IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK)
#if defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionRootBoundsChanged,
OnSelectionRootBoundsChanged)
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL)
IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission,
OnRequestDesktopNotificationPermission)
IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show,
OnShowDesktopNotification)
IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel,
OnCancelDesktopNotification)
#if defined(OS_MACOSX) || defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup)
IPC_MESSAGE_HANDLER(ViewHostMsg_HidePopup, OnHidePopup)
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidAccessInitialDocument,
OnDidAccessInitialDocument)
IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents)
IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges,
OnAccessibilityLocationChanges)
IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched, OnFocusedNodeTouched)
IPC_MESSAGE_UNHANDLED(
handled = RenderWidgetHostImpl::OnMessageReceived(msg))
IPC_END_MESSAGE_MAP_EX()
if (!msg_is_ok) {
RecordAction(base::UserMetricsAction("BadMessageTerminate_RVH"));
GetProcess()->ReceivedBadMessage();
}
return handled;
}
void RenderViewHostImpl::Init() {
RenderWidgetHostImpl::Init();
}
void RenderViewHostImpl::Shutdown() {
if (run_modal_reply_msg_) {
Send(run_modal_reply_msg_);
run_modal_reply_msg_ = NULL;
RenderViewHostImpl* opener =
RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_);
if (opener) {
opener->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
hung_renderer_delay_ms_));
opener->increment_in_flight_event_count();
}
run_modal_opener_id_ = MSG_ROUTING_NONE;
}
RenderWidgetHostImpl::Shutdown();
}
bool RenderViewHostImpl::IsRenderView() const {
return true;
}
void RenderViewHostImpl::CreateNewWindow(
int route_id,
int main_frame_route_id,
const ViewHostMsg_CreateWindow_Params& params,
SessionStorageNamespace* session_storage_namespace) {
ViewHostMsg_CreateWindow_Params validated_params(params);
GetProcess()->FilterURL(false, &validated_params.target_url);
GetProcess()->FilterURL(false, &validated_params.opener_url);
GetProcess()->FilterURL(true, &validated_params.opener_security_origin);
delegate_->CreateNewWindow(
GetProcess()->GetID(), route_id, main_frame_route_id, validated_params,
session_storage_namespace);
}
void RenderViewHostImpl::CreateNewWidget(int route_id,
blink::WebPopupType popup_type) {
delegate_->CreateNewWidget(GetProcess()->GetID(), route_id, popup_type);
}
void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id) {
delegate_->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id);
}
void RenderViewHostImpl::OnShowView(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
if (IsRVHStateActive(rvh_state_)) {
delegate_->ShowCreatedWindow(
route_id, disposition, initial_pos, user_gesture);
}
Send(new ViewMsg_Move_ACK(route_id));
}
void RenderViewHostImpl::OnShowWidget(int route_id,
const gfx::Rect& initial_pos) {
if (IsRVHStateActive(rvh_state_))
delegate_->ShowCreatedWidget(route_id, initial_pos);
Send(new ViewMsg_Move_ACK(route_id));
}
void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) {
if (IsRVHStateActive(rvh_state_))
delegate_->ShowCreatedFullscreenWidget(route_id);
Send(new ViewMsg_Move_ACK(route_id));
}
void RenderViewHostImpl::OnRunModal(int opener_id, IPC::Message* reply_msg) {
DCHECK(!run_modal_reply_msg_);
run_modal_reply_msg_ = reply_msg;
run_modal_opener_id_ = opener_id;
RecordAction(base::UserMetricsAction("ShowModalDialog"));
RenderViewHostImpl* opener =
RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_);
if (opener) {
opener->StopHangMonitorTimeout();
opener->decrement_in_flight_event_count();
}
}
void RenderViewHostImpl::OnRenderViewReady() {
render_view_termination_status_ = base::TERMINATION_STATUS_STILL_RUNNING;
SendScreenRects();
WasResized();
delegate_->RenderViewReady(this);
}
void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) {
render_view_termination_status_ =
static_cast<base::TerminationStatus>(status);
delegate_->GetFrameTree()->RenderProcessGone(this);
RendererExited(render_view_termination_status_, exit_code);
delegate_->RenderViewTerminated(this,
static_cast<base::TerminationStatus>(status),
exit_code);
}
void RenderViewHostImpl::OnUpdateState(int32 page_id, const PageState& state) {
if (!CanAccessFilesOfPageState(state)) {
GetProcess()->ReceivedBadMessage();
return;
}
delegate_->UpdateState(this, page_id, state);
}
void RenderViewHostImpl::OnUpdateTitle(
int32 page_id,
const base::string16& title,
blink::WebTextDirection title_direction) {
if (title.length() > kMaxTitleChars) {
NOTREACHED() << "Renderer sent too many characters in title.";
return;
}
delegate_->UpdateTitle(this, page_id, title,
WebTextDirectionToChromeTextDirection(
title_direction));
}
void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) {
delegate_->UpdateEncoding(this, encoding_name);
}
void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) {
if (IsRVHStateActive(rvh_state_))
delegate_->UpdateTargetURL(page_id, url);
Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID()));
}
void RenderViewHostImpl::OnUpdateInspectorSetting(
const std::string& key, const std::string& value) {
GetContentClient()->browser()->UpdateInspectorSetting(
this, key, value);
}
void RenderViewHostImpl::OnClose() {
ClosePageIgnoringUnloadEvents();
}
void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) {
if (IsRVHStateActive(rvh_state_))
delegate_->RequestMove(pos);
Send(new ViewMsg_Move_ACK(GetRoutingID()));
}
void RenderViewHostImpl::OnDidChangeLoadProgress(double load_progress) {
delegate_->DidChangeLoadProgress(load_progress);
}
void RenderViewHostImpl::OnDidDisownOpener() {
delegate_->DidDisownOpener(this);
}
void RenderViewHostImpl::OnDocumentAvailableInMainFrame() {
delegate_->DocumentAvailableInMainFrame(this);
}
void RenderViewHostImpl::OnDocumentOnLoadCompletedInMainFrame(
int32 page_id) {
delegate_->DocumentOnLoadCompletedInMainFrame(this, page_id);
}
void RenderViewHostImpl::OnToggleFullscreen(bool enter_fullscreen) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
delegate_->ToggleFullscreenMode(enter_fullscreen);
WasResized();
}
void RenderViewHostImpl::OnDidContentsPreferredSizeChange(
const gfx::Size& new_size) {
delegate_->UpdatePreferredSize(new_size);
}
void RenderViewHostImpl::OnRenderAutoResized(const gfx::Size& new_size) {
delegate_->ResizeDueToAutoResize(new_size);
}
void RenderViewHostImpl::OnDidChangeScrollOffset() {
if (view_)
view_->ScrollOffsetChanged();
}
void RenderViewHostImpl::OnDidChangeScrollbarsForMainFrame(
bool has_horizontal_scrollbar, bool has_vertical_scrollbar) {
if (view_)
view_->SetHasHorizontalScrollbar(has_horizontal_scrollbar);
}
void RenderViewHostImpl::OnDidChangeScrollOffsetPinningForMainFrame(
bool is_pinned_to_left, bool is_pinned_to_right) {
if (view_)
view_->SetScrollOffsetPinning(is_pinned_to_left, is_pinned_to_right);
}
void RenderViewHostImpl::OnDidChangeNumWheelEvents(int count) {
}
#if defined(OS_ANDROID)
void RenderViewHostImpl::OnSelectionRootBoundsChanged(
const gfx::Rect& bounds) {
if (view_) {
view_->SelectionRootBoundsChanged(bounds);
}
}
#endif
void RenderViewHostImpl::OnRouteCloseEvent() {
delegate_->RouteCloseEvent(this);
}
void RenderViewHostImpl::OnRouteMessageEvent(
const ViewMsg_PostMessage_Params& params) {
delegate_->RouteMessageEvent(this, params);
}
void RenderViewHostImpl::OnRunJavaScriptMessage(
const base::string16& message,
const base::string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType type,
IPC::Message* reply_msg) {
GetProcess()->SetIgnoreInputEvents(true);
StopHangMonitorTimeout();
delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url,
type, reply_msg,
&are_javascript_messages_suppressed_);
}
void RenderViewHostImpl::OnRunBeforeUnloadConfirm(const GURL& frame_url,
const base::string16& message,
bool is_reload,
IPC::Message* reply_msg) {
GetProcess()->SetIgnoreInputEvents(true);
StopHangMonitorTimeout();
delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg);
}
void RenderViewHostImpl::OnStartDragging(
const DropData& drop_data,
WebDragOperationsMask drag_operations_mask,
const SkBitmap& bitmap,
const gfx::Vector2d& bitmap_offset_in_dip,
const DragEventSourceInfo& event_info) {
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (!view)
return;
DropData filtered_data(drop_data);
RenderProcessHost* process = GetProcess();
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
if (!filtered_data.url.SchemeIs(kJavaScriptScheme))
process->FilterURL(true, &filtered_data.url);
process->FilterURL(false, &filtered_data.html_base_url);
filtered_data.filenames.clear();
for (std::vector<ui::FileInfo>::const_iterator it =
drop_data.filenames.begin();
it != drop_data.filenames.end();
++it) {
if (policy->CanReadFile(GetProcess()->GetID(), it->path))
filtered_data.filenames.push_back(*it);
}
float scale = ui::GetImageScale(GetScaleFactorForView(GetView()));
gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale));
view->StartDragging(filtered_data, drag_operations_mask, image,
bitmap_offset_in_dip, event_info);
}
void RenderViewHostImpl::OnUpdateDragCursor(WebDragOperation current_op) {
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (view)
view->UpdateDragCursor(current_op);
}
void RenderViewHostImpl::OnTargetDropACK() {
NotificationService::current()->Notify(
NOTIFICATION_RENDER_VIEW_HOST_DID_RECEIVE_DRAG_TARGET_DROP_ACK,
Source<RenderViewHost>(this),
NotificationService::NoDetails());
}
void RenderViewHostImpl::OnTakeFocus(bool reverse) {
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (view)
view->TakeFocus(reverse);
}
void RenderViewHostImpl::OnFocusedNodeChanged(bool is_editable_node) {
if (view_)
view_->FocusedNodeChanged(is_editable_node);
#if defined(OS_WIN)
if (!is_editable_node && virtual_keyboard_requested_) {
virtual_keyboard_requested_ = false;
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)),
TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs));
}
#endif
NotificationService::current()->Notify(
NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
Source<RenderViewHost>(this),
Details<const bool>(&is_editable_node));
}
void RenderViewHostImpl::OnUserGesture() {
delegate_->OnUserGesture();
}
void RenderViewHostImpl::OnClosePageACK() {
decrement_in_flight_event_count();
ClosePageIgnoringUnloadEvents();
}
void RenderViewHostImpl::NotifyRendererUnresponsive() {
delegate_->RendererUnresponsive(
this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK());
}
void RenderViewHostImpl::NotifyRendererResponsive() {
delegate_->RendererResponsive(this);
}
void RenderViewHostImpl::RequestToLockMouse(bool user_gesture,
bool last_unlocked_by_target) {
delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target);
}
bool RenderViewHostImpl::IsFullscreen() const {
return delegate_->IsFullscreenForCurrentTab();
}
void RenderViewHostImpl::OnFocus() {
delegate_->Activate();
}
void RenderViewHostImpl::OnBlur() {
delegate_->Deactivate();
}
gfx::Rect RenderViewHostImpl::GetRootWindowResizerRect() const {
return delegate_->GetRootWindowResizerRect();
}
void RenderViewHostImpl::ForwardMouseEvent(
const blink::WebMouseEvent& mouse_event) {
blink::WebMouseEvent event_copy(mouse_event);
RenderWidgetHostImpl::ForwardMouseEvent(event_copy);
switch (event_copy.type) {
case WebInputEvent::MouseMove:
delegate_->HandleMouseMove();
break;
case WebInputEvent::MouseLeave:
delegate_->HandleMouseLeave();
break;
case WebInputEvent::MouseDown:
delegate_->HandleMouseDown();
break;
case WebInputEvent::MouseWheel:
if (ignore_input_events())
delegate_->OnIgnoredUIEvent();
break;
case WebInputEvent::MouseUp:
delegate_->HandleMouseUp();
default:
break;
}
}
void RenderViewHostImpl::OnPointerEventActivate() {
delegate_->HandlePointerActivate();
}
void RenderViewHostImpl::ForwardKeyboardEvent(
const NativeWebKeyboardEvent& key_event) {
if (ignore_input_events()) {
if (key_event.type == WebInputEvent::RawKeyDown)
delegate_->OnIgnoredUIEvent();
return;
}
RenderWidgetHostImpl::ForwardKeyboardEvent(key_event);
}
#if defined(OS_ANDROID)
void RenderViewHostImpl::DidSelectPopupMenuItems(
const std::vector<int>& selected_indices) {
Send(new ViewMsg_SelectPopupMenuItems(GetRoutingID(), false,
selected_indices));
}
void RenderViewHostImpl::DidCancelPopupMenu() {
Send(new ViewMsg_SelectPopupMenuItems(GetRoutingID(), true,
std::vector<int>()));
}
#endif
#if defined(OS_MACOSX)
void RenderViewHostImpl::DidSelectPopupMenuItem(int selected_index) {
Send(new ViewMsg_SelectPopupMenuItem(GetRoutingID(), selected_index));
}
void RenderViewHostImpl::DidCancelPopupMenu() {
Send(new ViewMsg_SelectPopupMenuItem(GetRoutingID(), -1));
}
#endif
void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) {
Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation));
}
void RenderViewHostImpl::ToggleSpeechInput() {
Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID()));
}
bool RenderViewHostImpl::IsWaitingForUnloadACK() const {
return rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK ||
rvh_state_ == STATE_WAITING_FOR_CLOSE ||
rvh_state_ == STATE_PENDING_SHUTDOWN ||
rvh_state_ == STATE_PENDING_SWAP_OUT;
}
void RenderViewHostImpl::ExitFullscreen() {
RejectMouseLockOrUnlockIfNecessary();
OnToggleFullscreen(false);
}
WebPreferences RenderViewHostImpl::GetWebkitPreferences() {
return delegate_->GetWebkitPrefs();
}
void RenderViewHostImpl::DisownOpener() {
DCHECK(IsSwappedOut());
Send(new ViewMsg_DisownOpener(GetRoutingID()));
}
void RenderViewHostImpl::SetAccessibilityCallbackForTesting(
const base::Callback<void(ui::AXEvent)>& callback) {
accessibility_testing_callback_ = callback;
}
void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) {
Send(new ViewMsg_UpdateWebPreferences(GetRoutingID(), prefs));
}
void RenderViewHostImpl::GetAudioOutputControllers(
const GetAudioOutputControllersCallback& callback) const {
AudioRendererHost* audio_host =
static_cast<RenderProcessHostImpl*>(GetProcess())->audio_renderer_host();
audio_host->GetOutputControllers(GetRoutingID(), callback);
}
void RenderViewHostImpl::ClearFocusedElement() {
Send(new ViewMsg_ClearFocusedElement(GetRoutingID()));
}
void RenderViewHostImpl::Zoom(PageZoom zoom) {
Send(new ViewMsg_Zoom(GetRoutingID(), zoom));
}
void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) {
Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size));
}
void RenderViewHostImpl::EnablePreferredSizeMode() {
Send(new ViewMsg_EnablePreferredSizeChangedMode(GetRoutingID()));
}
void RenderViewHostImpl::EnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) {
SetShouldAutoResize(true);
Send(new ViewMsg_EnableAutoResize(GetRoutingID(), min_size, max_size));
}
void RenderViewHostImpl::DisableAutoResize(const gfx::Size& new_size) {
SetShouldAutoResize(false);
Send(new ViewMsg_DisableAutoResize(GetRoutingID(), new_size));
}
void RenderViewHostImpl::CopyImageAt(int x, int y) {
Send(new ViewMsg_CopyImageAt(GetRoutingID(), x, y));
}
void RenderViewHostImpl::ExecuteMediaPlayerActionAtLocation(
const gfx::Point& location, const blink::WebMediaPlayerAction& action) {
Send(new ViewMsg_MediaPlayerActionAt(GetRoutingID(), location, action));
}
void RenderViewHostImpl::ExecutePluginActionAtLocation(
const gfx::Point& location, const blink::WebPluginAction& action) {
Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action));
}
void RenderViewHostImpl::NotifyMoveOrResizeStarted() {
Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID()));
}
void RenderViewHostImpl::OnAccessibilityEvents(
const std::vector<AccessibilityHostMsg_EventParams>& params) {
if ((accessibility_mode() != AccessibilityModeOff) && view_ &&
IsRVHStateActive(rvh_state_)) {
if (accessibility_mode() & AccessibilityModeFlagPlatform) {
view_->CreateBrowserAccessibilityManagerIfNeeded();
BrowserAccessibilityManager* manager =
view_->GetBrowserAccessibilityManager();
if (manager)
manager->OnAccessibilityEvents(params);
}
std::vector<AXEventNotificationDetails> details;
for (unsigned int i = 0; i < params.size(); ++i) {
const AccessibilityHostMsg_EventParams& param = params[i];
AXEventNotificationDetails detail(param.update.nodes,
param.event_type,
param.id,
GetProcess()->GetID(),
GetRoutingID());
details.push_back(detail);
}
delegate_->AccessibilityEventReceived(details);
}
Send(new AccessibilityMsg_Events_ACK(GetRoutingID()));
if (accessibility_testing_callback_.is_null())
return;
for (unsigned i = 0; i < params.size(); i++) {
const AccessibilityHostMsg_EventParams& param = params[i];
if (static_cast<int>(param.event_type) < 0)
continue;
if (!ax_tree_)
ax_tree_.reset(new ui::AXTree(param.update));
else
CHECK(ax_tree_->Unserialize(param.update)) << ax_tree_->error();
accessibility_testing_callback_.Run(param.event_type);
}
}
void RenderViewHostImpl::OnAccessibilityLocationChanges(
const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
if (view_ && IsRVHStateActive(rvh_state_)) {
if (accessibility_mode() & AccessibilityModeFlagPlatform) {
view_->CreateBrowserAccessibilityManagerIfNeeded();
BrowserAccessibilityManager* manager =
view_->GetBrowserAccessibilityManager();
if (manager)
manager->OnLocationChanges(params);
}
}
}
void RenderViewHostImpl::OnDidZoomURL(double zoom_level,
bool remember,
const GURL& url) {
HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
HostZoomMap::GetForBrowserContext(GetProcess()->GetBrowserContext()));
if (remember) {
host_zoom_map->
SetZoomLevelForHost(net::GetHostOrSpecFromURL(url), zoom_level);
} else {
host_zoom_map->SetTemporaryZoomLevel(
GetProcess()->GetID(), GetRoutingID(), zoom_level);
}
}
void RenderViewHostImpl::OnRequestDesktopNotificationPermission(
const GURL& source_origin, int callback_context) {
GetContentClient()->browser()->RequestDesktopNotificationPermission(
source_origin, callback_context, GetProcess()->GetID(), GetRoutingID());
}
void RenderViewHostImpl::OnShowDesktopNotification(
const ShowDesktopNotificationHostMsgParams& params) {
GetContentClient()->browser()->ShowDesktopNotification(
params, GetProcess()->GetID(), GetRoutingID(), false);
}
void RenderViewHostImpl::OnCancelDesktopNotification(int notification_id) {
GetContentClient()->browser()->CancelDesktopNotification(
GetProcess()->GetID(), GetRoutingID(), notification_id);
}
void RenderViewHostImpl::OnRunFileChooser(const FileChooserParams& params) {
delegate_->RunFileChooser(this, params);
}
void RenderViewHostImpl::OnDidAccessInitialDocument() {
has_accessed_initial_document_ = true;
delegate_->DidAccessInitialDocument();
}
void RenderViewHostImpl::OnFocusedNodeTouched(bool editable) {
#if defined(OS_WIN)
if (editable) {
virtual_keyboard_requested_ = base::win::DisplayVirtualKeyboard();
} else {
virtual_keyboard_requested_ = false;
base::win::DismissVirtualKeyboard();
}
#endif
}
#if defined(OS_MACOSX) || defined(OS_ANDROID)
void RenderViewHostImpl::OnShowPopup(
const ViewHostMsg_ShowPopup_Params& params) {
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (view) {
view->ShowPopupMenu(params.bounds,
params.item_height,
params.item_font_size,
params.selected_item,
params.popup_items,
params.right_aligned,
params.allow_multiple_selection);
}
}
void RenderViewHostImpl::OnHidePopup() {
RenderViewHostDelegateView* view = delegate_->GetDelegateView();
if (view)
view->HidePopupMenu();
}
#endif
void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) {
if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state))
instance_->increment_active_view_count();
else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state))
instance_->decrement_active_view_count();
if (rvh_state == STATE_DEFAULT ||
rvh_state == STATE_SWAPPED_OUT ||
rvh_state_ == STATE_DEFAULT ||
rvh_state_ == STATE_SWAPPED_OUT) {
is_waiting_for_beforeunload_ack_ = false;
}
rvh_state_ = rvh_state;
}
bool RenderViewHostImpl::CanAccessFilesOfPageState(
const PageState& state) const {
ChildProcessSecurityPolicyImpl* policy =
ChildProcessSecurityPolicyImpl::GetInstance();
const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
file != file_paths.end(); ++file) {
if (!policy->CanReadFile(GetProcess()->GetID(), *file))
return false;
}
return true;
}
void RenderViewHostImpl::AttachToFrameTree() {
FrameTree* frame_tree = delegate_->GetFrameTree();
frame_tree->ResetForMainFrameSwap();
}
}