1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "base/callback.h"
13 #include "base/command_line.h"
14 #include "base/debug/trace_event.h"
15 #include "base/i18n/rtl.h"
16 #include "base/json/json_reader.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/metrics/histogram.h"
19 #include "base/stl_util.h"
20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/sys_info.h"
23 #include "base/time/time.h"
24 #include "base/values.h"
25 #include "cc/base/switches.h"
26 #include "content/browser/accessibility/browser_accessibility_manager.h"
27 #include "content/browser/child_process_security_policy_impl.h"
28 #include "content/browser/cross_site_request_manager.h"
29 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
30 #include "content/browser/frame_host/frame_tree.h"
31 #include "content/browser/gpu/compositor_util.h"
32 #include "content/browser/gpu/gpu_data_manager_impl.h"
33 #include "content/browser/gpu/gpu_process_host.h"
34 #include "content/browser/gpu/gpu_surface_tracker.h"
35 #include "content/browser/host_zoom_map_impl.h"
36 #include "content/browser/loader/resource_dispatcher_host_impl.h"
37 #include "content/browser/renderer_host/dip_util.h"
38 #include "content/browser/renderer_host/input/timeout_monitor.h"
39 #include "content/browser/renderer_host/media/audio_renderer_host.h"
40 #include "content/browser/renderer_host/render_process_host_impl.h"
41 #include "content/browser/renderer_host/render_view_host_delegate.h"
42 #include "content/common/accessibility_messages.h"
43 #include "content/common/browser_plugin/browser_plugin_messages.h"
44 #include "content/common/content_switches_internal.h"
45 #include "content/common/desktop_notification_messages.h"
46 #include "content/common/drag_messages.h"
47 #include "content/common/frame_messages.h"
48 #include "content/common/input_messages.h"
49 #include "content/common/inter_process_time_ticks_converter.h"
50 #include "content/common/speech_recognition_messages.h"
51 #include "content/common/swapped_out_messages.h"
52 #include "content/common/view_messages.h"
53 #include "content/port/browser/render_view_host_delegate_view.h"
54 #include "content/port/browser/render_widget_host_view_port.h"
55 #include "content/public/browser/ax_event_notification_details.h"
56 #include "content/public/browser/browser_accessibility_state.h"
57 #include "content/public/browser/browser_context.h"
58 #include "content/public/browser/browser_message_filter.h"
59 #include "content/public/browser/content_browser_client.h"
60 #include "content/public/browser/native_web_keyboard_event.h"
61 #include "content/public/browser/notification_details.h"
62 #include "content/public/browser/notification_service.h"
63 #include "content/public/browser/notification_types.h"
64 #include "content/public/browser/render_frame_host.h"
65 #include "content/public/browser/render_widget_host_iterator.h"
66 #include "content/public/browser/user_metrics.h"
67 #include "content/public/common/bindings_policy.h"
68 #include "content/public/common/content_constants.h"
69 #include "content/public/common/content_switches.h"
70 #include "content/public/common/context_menu_params.h"
71 #include "content/public/common/drop_data.h"
72 #include "content/public/common/result_codes.h"
73 #include "content/public/common/url_constants.h"
74 #include "content/public/common/url_utils.h"
75 #include "net/base/net_util.h"
76 #include "net/base/network_change_notifier.h"
77 #include "net/url_request/url_request_context_getter.h"
78 #include "third_party/skia/include/core/SkBitmap.h"
79 #include "ui/accessibility/ax_tree.h"
80 #include "ui/base/touch/touch_device.h"
81 #include "ui/base/touch/touch_enabled.h"
82 #include "ui/base/ui_base_switches.h"
83 #include "ui/gfx/image/image_skia.h"
84 #include "ui/gfx/native_widget_types.h"
85 #include "ui/native_theme/native_theme_switches.h"
86 #include "ui/shell_dialogs/selected_file_info.h"
87 #include "webkit/browser/fileapi/isolated_context.h"
89 #if defined(OS_MACOSX)
90 #include "content/browser/renderer_host/popup_menu_helper_mac.h"
91 #elif defined(OS_ANDROID)
92 #include "content/browser/media/android/browser_media_player_manager.h"
94 #include "base/win/win_util.h"
97 using base::TimeDelta
;
98 using blink::WebConsoleMessage
;
99 using blink::WebDragOperation
;
100 using blink::WebDragOperationNone
;
101 using blink::WebDragOperationsMask
;
102 using blink::WebInputEvent
;
103 using blink::WebMediaPlayerAction
;
104 using blink::WebPluginAction
;
109 // Translate a WebKit text direction into a base::i18n one.
110 base::i18n::TextDirection
WebTextDirectionToChromeTextDirection(
111 blink::WebTextDirection dir
) {
113 case blink::WebTextDirectionLeftToRight
:
114 return base::i18n::LEFT_TO_RIGHT
;
115 case blink::WebTextDirectionRightToLeft
:
116 return base::i18n::RIGHT_TO_LEFT
;
119 return base::i18n::UNKNOWN_DIRECTION
;
125 const int kVirtualKeyboardDisplayWaitTimeoutMs
= 100;
126 const int kMaxVirtualKeyboardDisplayRetries
= 5;
128 void DismissVirtualKeyboardTask() {
129 static int virtual_keyboard_display_retries
= 0;
130 // If the virtual keyboard is not yet visible, then we execute the task again
131 // waiting for it to show up.
132 if (!base::win::DismissVirtualKeyboard()) {
133 if (virtual_keyboard_display_retries
< kMaxVirtualKeyboardDisplayRetries
) {
134 BrowserThread::PostDelayedTask(
135 BrowserThread::UI
, FROM_HERE
,
136 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask
)),
137 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs
));
138 ++virtual_keyboard_display_retries
;
140 virtual_keyboard_display_retries
= 0;
149 const int RenderViewHostImpl::kUnloadTimeoutMS
= 1000;
151 ///////////////////////////////////////////////////////////////////////////////
152 // RenderViewHost, public:
155 bool RenderViewHostImpl::IsRVHStateActive(RenderViewHostImplState rvh_state
) {
156 if (rvh_state
== STATE_DEFAULT
||
157 rvh_state
== STATE_WAITING_FOR_UNLOAD_ACK
||
158 rvh_state
== STATE_WAITING_FOR_COMMIT
||
159 rvh_state
== STATE_WAITING_FOR_CLOSE
)
165 RenderViewHost
* RenderViewHost::FromID(int render_process_id
,
166 int render_view_id
) {
167 return RenderViewHostImpl::FromID(render_process_id
, render_view_id
);
171 RenderViewHost
* RenderViewHost::From(RenderWidgetHost
* rwh
) {
172 DCHECK(rwh
->IsRenderView());
173 return static_cast<RenderViewHostImpl
*>(RenderWidgetHostImpl::From(rwh
));
176 ///////////////////////////////////////////////////////////////////////////////
177 // RenderViewHostImpl, public:
180 RenderViewHostImpl
* RenderViewHostImpl::FromID(int render_process_id
,
181 int render_view_id
) {
182 RenderWidgetHost
* widget
=
183 RenderWidgetHost::FromID(render_process_id
, render_view_id
);
184 if (!widget
|| !widget
->IsRenderView())
186 return static_cast<RenderViewHostImpl
*>(RenderWidgetHostImpl::From(widget
));
189 RenderViewHostImpl::RenderViewHostImpl(
190 SiteInstance
* instance
,
191 RenderViewHostDelegate
* delegate
,
192 RenderWidgetHostDelegate
* widget_delegate
,
194 int main_frame_routing_id
,
197 : RenderWidgetHostImpl(widget_delegate
,
198 instance
->GetProcess(),
201 frames_ref_count_(0),
203 instance_(static_cast<SiteInstanceImpl
*>(instance
)),
204 waiting_for_drag_context_response_(false),
205 enabled_bindings_(0),
206 navigations_suspended_(false),
207 has_accessed_initial_document_(false),
208 main_frame_routing_id_(main_frame_routing_id
),
209 run_modal_reply_msg_(NULL
),
210 run_modal_opener_id_(MSG_ROUTING_NONE
),
211 is_waiting_for_beforeunload_ack_(false),
212 unload_ack_is_for_cross_site_transition_(false),
213 are_javascript_messages_suppressed_(false),
214 sudden_termination_allowed_(false),
215 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING
),
216 virtual_keyboard_requested_(false),
217 weak_factory_(this) {
218 DCHECK(instance_
.get());
219 CHECK(delegate_
); // http://crbug.com/82827
221 GetProcess()->EnableSendQueue();
224 rvh_state_
= STATE_SWAPPED_OUT
;
226 rvh_state_
= STATE_DEFAULT
;
227 instance_
->increment_active_view_count();
230 if (ResourceDispatcherHostImpl::Get()) {
231 BrowserThread::PostTask(
232 BrowserThread::IO
, FROM_HERE
,
233 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated
,
234 base::Unretained(ResourceDispatcherHostImpl::Get()),
235 GetProcess()->GetID(), GetRoutingID()));
238 #if defined(OS_ANDROID)
239 media_player_manager_
.reset(BrowserMediaPlayerManager::Create(this));
242 unload_event_monitor_timeout_
.reset(new TimeoutMonitor(base::Bind(
243 &RenderViewHostImpl::OnSwappedOut
, weak_factory_
.GetWeakPtr(), true)));
246 RenderViewHostImpl::~RenderViewHostImpl() {
247 if (ResourceDispatcherHostImpl::Get()) {
248 BrowserThread::PostTask(
249 BrowserThread::IO
, FROM_HERE
,
250 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted
,
251 base::Unretained(ResourceDispatcherHostImpl::Get()),
252 GetProcess()->GetID(), GetRoutingID()));
255 delegate_
->RenderViewDeleted(this);
257 // Be sure to clean up any leftover state from cross-site requests.
258 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
259 GetProcess()->GetID(), GetRoutingID(), false);
261 // If this was swapped out, it already decremented the active view
262 // count of the SiteInstance it belongs to.
263 if (IsRVHStateActive(rvh_state_
))
264 instance_
->decrement_active_view_count();
267 RenderViewHostDelegate
* RenderViewHostImpl::GetDelegate() const {
271 SiteInstance
* RenderViewHostImpl::GetSiteInstance() const {
272 return instance_
.get();
275 bool RenderViewHostImpl::CreateRenderView(
276 const base::string16
& frame_name
,
279 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
280 DCHECK(!IsRenderViewLive()) << "Creating view twice";
282 // The process may (if we're sharing a process with another host that already
283 // initialized it) or may not (we have our own process or the old process
284 // crashed) have been initialized. Calling Init multiple times will be
285 // ignored, so this is safe.
286 if (!GetProcess()->Init())
288 DCHECK(GetProcess()->HasConnection());
289 DCHECK(GetProcess()->GetBrowserContext());
291 renderer_initialized_
= true;
293 GpuSurfaceTracker::Get()->SetSurfaceHandle(
294 surface_id(), GetCompositingSurface());
296 // Ensure the RenderView starts with a next_page_id larger than any existing
297 // page ID it might be asked to render.
298 int32 next_page_id
= 1;
299 if (max_page_id
> -1)
300 next_page_id
= max_page_id
+ 1;
302 ViewMsg_New_Params params
;
303 params
.renderer_preferences
=
304 delegate_
->GetRendererPrefs(GetProcess()->GetBrowserContext());
305 params
.web_preferences
= delegate_
->GetWebkitPrefs();
306 params
.view_id
= GetRoutingID();
307 params
.main_frame_routing_id
= main_frame_routing_id_
;
308 params
.surface_id
= surface_id();
309 params
.session_storage_namespace_id
=
310 delegate_
->GetSessionStorageNamespace(instance_
)->id();
311 params
.frame_name
= frame_name
;
312 // Ensure the RenderView sets its opener correctly.
313 params
.opener_route_id
= opener_route_id
;
314 params
.swapped_out
= !IsRVHStateActive(rvh_state_
);
315 params
.hidden
= is_hidden();
316 params
.next_page_id
= next_page_id
;
317 GetWebScreenInfo(¶ms
.screen_info
);
318 params
.accessibility_mode
= accessibility_mode();
320 Send(new ViewMsg_New(params
));
322 // If it's enabled, tell the renderer to set up the Javascript bindings for
323 // sending messages back to the browser.
324 if (GetProcess()->IsGuest())
325 DCHECK_EQ(0, enabled_bindings_
);
326 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_
));
327 // Let our delegate know that we created a RenderView.
328 delegate_
->RenderViewCreated(this);
333 bool RenderViewHostImpl::IsRenderViewLive() const {
334 return GetProcess()->HasConnection() && renderer_initialized_
;
337 void RenderViewHostImpl::SyncRendererPrefs() {
338 Send(new ViewMsg_SetRendererPrefs(GetRoutingID(),
339 delegate_
->GetRendererPrefs(
340 GetProcess()->GetBrowserContext())));
343 WebPreferences
RenderViewHostImpl::GetWebkitPrefs(const GURL
& url
) {
344 TRACE_EVENT0("browser", "RenderViewHostImpl::GetWebkitPrefs");
345 WebPreferences prefs
;
347 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
349 prefs
.javascript_enabled
=
350 !command_line
.HasSwitch(switches::kDisableJavaScript
);
351 prefs
.web_security_enabled
=
352 !command_line
.HasSwitch(switches::kDisableWebSecurity
);
353 prefs
.plugins_enabled
=
354 !command_line
.HasSwitch(switches::kDisablePlugins
);
356 !command_line
.HasSwitch(switches::kDisableJava
);
358 prefs
.remote_fonts_enabled
=
359 !command_line
.HasSwitch(switches::kDisableRemoteFonts
);
361 !command_line
.HasSwitch(switches::kDisableXSLT
);
362 prefs
.xss_auditor_enabled
=
363 !command_line
.HasSwitch(switches::kDisableXSSAuditor
);
364 prefs
.application_cache_enabled
=
365 !command_line
.HasSwitch(switches::kDisableApplicationCache
);
367 prefs
.local_storage_enabled
=
368 !command_line
.HasSwitch(switches::kDisableLocalStorage
);
369 prefs
.databases_enabled
=
370 !command_line
.HasSwitch(switches::kDisableDatabases
);
371 #if defined(OS_ANDROID) && defined(ARCH_CPU_X86)
372 prefs
.webaudio_enabled
=
373 command_line
.HasSwitch(switches::kEnableWebAudio
);
375 prefs
.webaudio_enabled
=
376 !command_line
.HasSwitch(switches::kDisableWebAudio
);
379 prefs
.experimental_webgl_enabled
=
380 GpuProcessHost::gpu_enabled() &&
381 !command_line
.HasSwitch(switches::kDisable3DAPIs
) &&
382 !command_line
.HasSwitch(switches::kDisableExperimentalWebGL
);
384 prefs
.pepper_3d_enabled
=
385 !command_line
.HasSwitch(switches::kDisablePepper3d
);
387 prefs
.flash_3d_enabled
=
388 GpuProcessHost::gpu_enabled() &&
389 !command_line
.HasSwitch(switches::kDisableFlash3d
);
390 prefs
.flash_stage3d_enabled
=
391 GpuProcessHost::gpu_enabled() &&
392 !command_line
.HasSwitch(switches::kDisableFlashStage3d
);
393 prefs
.flash_stage3d_baseline_enabled
=
394 GpuProcessHost::gpu_enabled() &&
395 !command_line
.HasSwitch(switches::kDisableFlashStage3d
);
397 prefs
.gl_multisampling_enabled
=
398 !command_line
.HasSwitch(switches::kDisableGLMultisampling
);
399 prefs
.privileged_webgl_extensions_enabled
=
400 command_line
.HasSwitch(switches::kEnablePrivilegedWebGLExtensions
);
401 prefs
.site_specific_quirks_enabled
=
402 !command_line
.HasSwitch(switches::kDisableSiteSpecificQuirks
);
403 prefs
.allow_file_access_from_file_urls
=
404 command_line
.HasSwitch(switches::kAllowFileAccessFromFiles
);
406 prefs
.layer_squashing_enabled
= false;
407 if (command_line
.HasSwitch(switches::kEnableLayerSquashing
))
408 prefs
.layer_squashing_enabled
= true;
409 if (command_line
.HasSwitch(switches::kDisableLayerSquashing
))
410 prefs
.layer_squashing_enabled
= false;
412 prefs
.show_paint_rects
=
413 command_line
.HasSwitch(switches::kShowPaintRects
);
414 prefs
.accelerated_compositing_enabled
=
415 GpuProcessHost::gpu_enabled() &&
416 !command_line
.HasSwitch(switches::kDisableAcceleratedCompositing
);
417 prefs
.force_compositing_mode
=
418 content::IsForceCompositingModeEnabled() &&
419 !command_line
.HasSwitch(switches::kDisableForceCompositingMode
);
420 prefs
.accelerated_2d_canvas_enabled
=
421 GpuProcessHost::gpu_enabled() &&
422 !command_line
.HasSwitch(switches::kDisableAccelerated2dCanvas
);
423 prefs
.antialiased_2d_canvas_disabled
=
424 command_line
.HasSwitch(switches::kDisable2dCanvasAntialiasing
);
425 prefs
.accelerated_2d_canvas_msaa_sample_count
=
426 atoi(command_line
.GetSwitchValueASCII(
427 switches::kAcceleratedCanvas2dMSAASampleCount
).c_str());
428 prefs
.deferred_filters_enabled
=
429 command_line
.HasSwitch(switches::kEnableDeferredFilters
);
430 prefs
.accelerated_compositing_for_3d_transforms_enabled
=
431 prefs
.accelerated_compositing_for_animation_enabled
=
432 !command_line
.HasSwitch(switches::kDisableAcceleratedLayers
);
433 prefs
.accelerated_compositing_for_plugins_enabled
= true;
434 prefs
.accelerated_compositing_for_video_enabled
=
435 !command_line
.HasSwitch(switches::kDisableAcceleratedVideo
);
436 prefs
.lazy_layout_enabled
=
437 command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
);
438 prefs
.region_based_columns_enabled
=
439 command_line
.HasSwitch(switches::kEnableRegionBasedColumns
);
440 prefs
.threaded_html_parser
=
441 !command_line
.HasSwitch(switches::kDisableThreadedHTMLParser
);
442 prefs
.experimental_websocket_enabled
=
443 command_line
.HasSwitch(switches::kEnableExperimentalWebSocket
);
444 if (command_line
.HasSwitch(cc::switches::kEnablePinchVirtualViewport
)) {
445 prefs
.pinch_virtual_viewport_enabled
= true;
446 prefs
.pinch_overlay_scrollbar_thickness
= 10;
448 prefs
.use_solid_color_scrollbars
= ui::IsOverlayScrollbarEnabled();
450 #if defined(OS_ANDROID)
451 prefs
.user_gesture_required_for_media_playback
= !command_line
.HasSwitch(
452 switches::kDisableGestureRequirementForMediaPlayback
);
453 prefs
.user_gesture_required_for_media_fullscreen
= !command_line
.HasSwitch(
454 switches::kDisableGestureRequirementForMediaFullscreen
);
457 prefs
.touch_enabled
= ui::AreTouchEventsEnabled();
458 prefs
.device_supports_touch
= prefs
.touch_enabled
&&
459 ui::IsTouchDevicePresent();
460 #if defined(OS_ANDROID)
461 prefs
.device_supports_mouse
= false;
464 prefs
.pointer_events_max_touch_points
= ui::MaxTouchPoints();
466 prefs
.touch_adjustment_enabled
=
467 !command_line
.HasSwitch(switches::kDisableTouchAdjustment
);
468 prefs
.compositor_touch_hit_testing
=
469 !command_line
.HasSwitch(
470 cc::switches::kDisableCompositorTouchHitTesting
) &&
471 !command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
);
474 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
475 bool default_enable_scroll_animator
= true;
477 bool default_enable_scroll_animator
= false;
479 prefs
.enable_scroll_animator
= default_enable_scroll_animator
;
480 if (command_line
.HasSwitch(switches::kEnableSmoothScrolling
))
481 prefs
.enable_scroll_animator
= true;
482 if (command_line
.HasSwitch(switches::kDisableSmoothScrolling
))
483 prefs
.enable_scroll_animator
= false;
485 prefs
.visual_word_movement_enabled
=
486 command_line
.HasSwitch(switches::kEnableVisualWordMovement
);
488 // Certain GPU features might have been blacklisted.
489 GpuDataManagerImpl::GetInstance()->UpdateRendererWebPrefs(&prefs
);
491 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
492 GetProcess()->GetID())) {
493 prefs
.loads_images_automatically
= true;
494 prefs
.javascript_enabled
= true;
497 prefs
.is_online
= !net::NetworkChangeNotifier::IsOffline();
499 prefs
.fixed_position_creates_stacking_context
= !command_line
.HasSwitch(
500 switches::kDisableFixedPositionCreatesStackingContext
);
502 prefs
.gesture_tap_highlight_enabled
= !command_line
.HasSwitch(
503 switches::kDisableGestureTapHighlight
);
505 prefs
.number_of_cpu_cores
= base::SysInfo::NumberOfProcessors();
507 prefs
.viewport_meta_enabled
=
508 command_line
.HasSwitch(switches::kEnableViewportMeta
);
510 prefs
.viewport_enabled
=
511 command_line
.HasSwitch(switches::kEnableViewport
) ||
512 prefs
.viewport_meta_enabled
;
514 prefs
.main_frame_resizes_are_orientation_changes
=
515 command_line
.HasSwitch(switches::kMainFrameResizesAreOrientationChanges
);
517 prefs
.deferred_image_decoding_enabled
=
518 command_line
.HasSwitch(switches::kEnableDeferredImageDecoding
) ||
519 content::IsImplSidePaintingEnabled();
521 prefs
.spatial_navigation_enabled
= command_line
.HasSwitch(
522 switches::kEnableSpatialNavigation
);
524 GetContentClient()->browser()->OverrideWebkitPrefs(this, url
, &prefs
);
526 // Disable compositing in guests until we have compositing path implemented
528 bool guest_compositing_enabled
= !command_line
.HasSwitch(
529 switches::kDisableBrowserPluginCompositing
);
530 if (GetProcess()->IsGuest() && !guest_compositing_enabled
) {
531 prefs
.force_compositing_mode
= false;
532 prefs
.accelerated_compositing_enabled
= false;
538 void RenderViewHostImpl::Navigate(const FrameMsg_Navigate_Params
& params
) {
539 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::Navigate");
540 delegate_
->GetFrameTree()->GetMainFrame()->Navigate(params
);
543 void RenderViewHostImpl::NavigateToURL(const GURL
& url
) {
544 delegate_
->GetFrameTree()->GetMainFrame()->NavigateToURL(url
);
547 void RenderViewHostImpl::SetNavigationsSuspended(
549 const base::TimeTicks
& proceed_time
) {
550 // This should only be called to toggle the state.
551 DCHECK(navigations_suspended_
!= suspend
);
553 navigations_suspended_
= suspend
;
554 if (!suspend
&& suspended_nav_params_
) {
555 // There's navigation message params waiting to be sent. Now that we're not
556 // suspended anymore, resume navigation by sending them. If we were swapped
557 // out, we should also stop filtering out the IPC messages now.
558 SetState(STATE_DEFAULT
);
560 DCHECK(!proceed_time
.is_null());
561 suspended_nav_params_
->browser_navigation_start
= proceed_time
;
562 Send(new FrameMsg_Navigate(
563 main_frame_routing_id_
, *suspended_nav_params_
.get()));
564 suspended_nav_params_
.reset();
568 void RenderViewHostImpl::CancelSuspendedNavigations() {
569 // Clear any state if a pending navigation is canceled or pre-empted.
570 if (suspended_nav_params_
)
571 suspended_nav_params_
.reset();
572 navigations_suspended_
= false;
575 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
576 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
579 void RenderViewHostImpl::SwapOut() {
580 SetState(STATE_WAITING_FOR_UNLOAD_ACK
);
581 unload_event_monitor_timeout_
->Start(
582 base::TimeDelta::FromMilliseconds(kUnloadTimeoutMS
));
584 if (IsRenderViewLive()) {
585 Send(new ViewMsg_SwapOut(GetRoutingID()));
587 delegate_
->SwappedOut(this);
590 void RenderViewHostImpl::OnSwapOutACK() {
594 void RenderViewHostImpl::OnSwappedOut(bool timed_out
) {
595 // Ignore spurious swap out ack.
596 if (!IsWaitingForUnloadACK())
598 unload_event_monitor_timeout_
->Stop();
600 base::ProcessHandle process_handle
= GetProcess()->GetHandle();
603 // Count the number of active widget hosts for the process, which
604 // is equivalent to views using the process as of this writing.
605 scoped_ptr
<RenderWidgetHostIterator
> widgets(
606 RenderWidgetHost::GetRenderWidgetHosts());
607 while (RenderWidgetHost
* widget
= widgets
->GetNextHost()) {
608 if (widget
->GetProcess()->GetID() == GetProcess()->GetID())
612 if (!RenderProcessHost::run_renderer_in_process() &&
613 process_handle
&& views
<= 1) {
614 // The process can safely be terminated, only if WebContents sets
615 // SuddenTerminationAllowed, which indicates that the timer has expired.
616 // This is not the case if we load data URLs or about:blank. The reason
617 // is that those have no network requests and this code is hit without
618 // setting the unresponsiveness timer. This allows a corner case where a
619 // navigation to a data URL will leave a process running, if the
620 // beforeunload handler completes fine, but the unload handler hangs.
621 // At this time, the complexity to solve this edge case is not worthwhile.
622 if (SuddenTerminationAllowed()) {
623 // We should kill the process, but for now, just log the data so we can
624 // diagnose the kill rate and investigate if separate timer is needed.
625 // http://crbug.com/104346.
627 // Log a histogram point to help us diagnose how many of those kills
628 // we have performed. 1 is the enum value for RendererType Normal for
630 UMA_HISTOGRAM_PERCENTAGE(
631 "BrowserRenderProcessHost.ChildKillsUnresponsive", 1);
636 switch (rvh_state_
) {
637 case STATE_WAITING_FOR_UNLOAD_ACK
:
638 SetState(STATE_WAITING_FOR_COMMIT
);
640 case STATE_PENDING_SWAP_OUT
:
641 SetState(STATE_SWAPPED_OUT
);
643 case STATE_PENDING_SHUTDOWN
:
644 DCHECK(!pending_shutdown_on_swap_out_
.is_null());
645 pending_shutdown_on_swap_out_
.Run();
652 void RenderViewHostImpl::WasSwappedOut(
653 const base::Closure
& pending_delete_on_swap_out
) {
654 Send(new ViewMsg_WasSwappedOut(GetRoutingID()));
655 if (rvh_state_
== STATE_WAITING_FOR_UNLOAD_ACK
) {
656 SetState(STATE_PENDING_SWAP_OUT
);
657 if (!instance_
->active_view_count())
658 SetPendingShutdown(pending_delete_on_swap_out
);
659 } else if (rvh_state_
== STATE_WAITING_FOR_COMMIT
) {
660 SetState(STATE_SWAPPED_OUT
);
661 } else if (rvh_state_
== STATE_DEFAULT
) {
662 // When the RenderView is not live, the RenderFrameHostManager will call
663 // CommitPending directly, without calling SwapOut on the old RVH. This will
664 // cause WasSwappedOut to be called directly on the live old RVH.
665 DCHECK(!IsRenderViewLive());
666 SetState(STATE_SWAPPED_OUT
);
672 void RenderViewHostImpl::SetPendingShutdown(const base::Closure
& on_swap_out
) {
673 pending_shutdown_on_swap_out_
= on_swap_out
;
674 SetState(STATE_PENDING_SHUTDOWN
);
677 void RenderViewHostImpl::ClosePage() {
678 SetState(STATE_WAITING_FOR_CLOSE
);
679 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS
));
681 if (IsRenderViewLive()) {
682 // Since we are sending an IPC message to the renderer, increase the event
683 // count to prevent the hang monitor timeout from being stopped by input
684 // event acknowledgements.
685 increment_in_flight_event_count();
687 // TODO(creis): Should this be moved to Shutdown? It may not be called for
688 // RenderViewHosts that have been swapped out.
689 NotificationService::current()->Notify(
690 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW
,
691 Source
<RenderViewHost
>(this),
692 NotificationService::NoDetails());
694 Send(new ViewMsg_ClosePage(GetRoutingID()));
696 // This RenderViewHost doesn't have a live renderer, so just skip the unload
697 // event and close the page.
698 ClosePageIgnoringUnloadEvents();
702 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() {
703 StopHangMonitorTimeout();
704 is_waiting_for_beforeunload_ack_
= false;
706 sudden_termination_allowed_
= true;
707 delegate_
->Close(this);
710 bool RenderViewHostImpl::HasPendingCrossSiteRequest() {
711 return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest(
712 GetProcess()->GetID(), GetRoutingID());
715 void RenderViewHostImpl::SetHasPendingCrossSiteRequest(
716 bool has_pending_request
) {
717 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
718 GetProcess()->GetID(), GetRoutingID(), has_pending_request
);
721 #if defined(OS_ANDROID)
722 void RenderViewHostImpl::ActivateNearestFindResult(int request_id
,
725 Send(new InputMsg_ActivateNearestFindResult(GetRoutingID(),
729 void RenderViewHostImpl::RequestFindMatchRects(int current_version
) {
730 Send(new ViewMsg_FindMatchRects(GetRoutingID(), current_version
));
733 void RenderViewHostImpl::DisableFullscreenEncryptedMediaPlayback() {
734 media_player_manager_
->DisableFullscreenEncryptedMediaPlayback();
738 void RenderViewHostImpl::DragTargetDragEnter(
739 const DropData
& drop_data
,
740 const gfx::Point
& client_pt
,
741 const gfx::Point
& screen_pt
,
742 WebDragOperationsMask operations_allowed
,
744 const int renderer_id
= GetProcess()->GetID();
745 ChildProcessSecurityPolicyImpl
* policy
=
746 ChildProcessSecurityPolicyImpl::GetInstance();
748 // The URL could have been cobbled together from any highlighted text string,
749 // and can't be interpreted as a capability.
750 DropData
filtered_data(drop_data
);
751 GetProcess()->FilterURL(true, &filtered_data
.url
);
753 // The filenames vector, on the other hand, does represent a capability to
754 // access the given files.
755 fileapi::IsolatedContext::FileInfoSet files
;
756 for (std::vector
<DropData::FileInfo
>::iterator
iter(
757 filtered_data
.filenames
.begin());
758 iter
!= filtered_data
.filenames
.end(); ++iter
) {
759 // A dragged file may wind up as the value of an input element, or it
760 // may be used as the target of a navigation instead. We don't know
761 // which will happen at this point, so generously grant both access
762 // and request permissions to the specific file to cover both cases.
763 // We do not give it the permission to request all file:// URLs.
764 base::FilePath path
=
765 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(iter
->path
));
767 // Make sure we have the same display_name as the one we register.
768 if (iter
->display_name
.empty()) {
770 files
.AddPath(path
, &name
);
771 iter
->display_name
= base::UTF8ToUTF16(name
);
773 files
.AddPathWithName(path
, base::UTF16ToUTF8(iter
->display_name
));
776 policy
->GrantRequestSpecificFileURL(renderer_id
,
777 net::FilePathToFileURL(path
));
779 // If the renderer already has permission to read these paths, we don't need
780 // to re-grant them. This prevents problems with DnD for files in the CrOS
781 // file manager--the file manager already had read/write access to those
782 // directories, but dragging a file would cause the read/write access to be
783 // overwritten with read-only access, making them impossible to delete or
784 // rename until the renderer was killed.
785 if (!policy
->CanReadFile(renderer_id
, path
))
786 policy
->GrantReadFile(renderer_id
, path
);
789 fileapi::IsolatedContext
* isolated_context
=
790 fileapi::IsolatedContext::GetInstance();
791 DCHECK(isolated_context
);
792 std::string filesystem_id
= isolated_context
->RegisterDraggedFileSystem(
794 if (!filesystem_id
.empty()) {
795 // Grant the permission iff the ID is valid.
796 policy
->GrantReadFileSystem(renderer_id
, filesystem_id
);
798 filtered_data
.filesystem_id
= base::UTF8ToUTF16(filesystem_id
);
800 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data
, client_pt
,
801 screen_pt
, operations_allowed
,
805 void RenderViewHostImpl::DragTargetDragOver(
806 const gfx::Point
& client_pt
,
807 const gfx::Point
& screen_pt
,
808 WebDragOperationsMask operations_allowed
,
810 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt
, screen_pt
,
811 operations_allowed
, key_modifiers
));
814 void RenderViewHostImpl::DragTargetDragLeave() {
815 Send(new DragMsg_TargetDragLeave(GetRoutingID()));
818 void RenderViewHostImpl::DragTargetDrop(
819 const gfx::Point
& client_pt
,
820 const gfx::Point
& screen_pt
,
822 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt
, screen_pt
,
826 void RenderViewHostImpl::DesktopNotificationPermissionRequestDone(
827 int callback_context
) {
828 Send(new DesktopNotificationMsg_PermissionRequestDone(
829 GetRoutingID(), callback_context
));
832 void RenderViewHostImpl::DesktopNotificationPostDisplay(int callback_context
) {
833 Send(new DesktopNotificationMsg_PostDisplay(GetRoutingID(),
837 void RenderViewHostImpl::DesktopNotificationPostError(
839 const base::string16
& message
) {
840 Send(new DesktopNotificationMsg_PostError(
841 GetRoutingID(), notification_id
, message
));
844 void RenderViewHostImpl::DesktopNotificationPostClose(int notification_id
,
846 Send(new DesktopNotificationMsg_PostClose(
847 GetRoutingID(), notification_id
, by_user
));
850 void RenderViewHostImpl::DesktopNotificationPostClick(int notification_id
) {
851 Send(new DesktopNotificationMsg_PostClick(GetRoutingID(), notification_id
));
854 void RenderViewHostImpl::ExecuteJavascriptInWebFrame(
855 const base::string16
& frame_xpath
,
856 const base::string16
& jscript
) {
857 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath
, jscript
,
861 void RenderViewHostImpl::ExecuteJavascriptInWebFrameCallbackResult(
862 const base::string16
& frame_xpath
,
863 const base::string16
& jscript
,
864 const JavascriptResultCallback
& callback
) {
865 static int next_id
= 1;
867 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath
, jscript
,
869 javascript_callbacks_
.insert(std::make_pair(key
, callback
));
872 void RenderViewHostImpl::JavaScriptDialogClosed(
873 IPC::Message
* reply_msg
,
875 const base::string16
& user_input
) {
876 GetProcess()->SetIgnoreInputEvents(false);
877 bool is_waiting
= is_waiting_for_beforeunload_ack_
|| IsWaitingForUnloadACK();
879 // If we are executing as part of (before)unload event handling, we don't
880 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to
881 // leave the current page. In this case, use the regular timeout value used
882 // during the (before)unload handling.
884 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
885 success
? kUnloadTimeoutMS
: hung_renderer_delay_ms_
));
888 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg
,
889 success
, user_input
);
892 // If we are waiting for an unload or beforeunload ack and the user has
893 // suppressed messages, kill the tab immediately; a page that's spamming
894 // alerts in onbeforeunload is presumably malicious, so there's no point in
895 // continuing to run its script and dragging out the process.
896 // This must be done after sending the reply since RenderView can't close
897 // correctly while waiting for a response.
898 if (is_waiting
&& are_javascript_messages_suppressed_
)
899 delegate_
->RendererUnresponsive(
900 this, is_waiting_for_beforeunload_ack_
, IsWaitingForUnloadACK());
903 void RenderViewHostImpl::DragSourceEndedAt(
904 int client_x
, int client_y
, int screen_x
, int screen_y
,
905 WebDragOperation operation
) {
906 Send(new DragMsg_SourceEndedOrMoved(
908 gfx::Point(client_x
, client_y
),
909 gfx::Point(screen_x
, screen_y
),
913 void RenderViewHostImpl::DragSourceMovedTo(
914 int client_x
, int client_y
, int screen_x
, int screen_y
) {
915 Send(new DragMsg_SourceEndedOrMoved(
917 gfx::Point(client_x
, client_y
),
918 gfx::Point(screen_x
, screen_y
),
919 false, WebDragOperationNone
));
922 void RenderViewHostImpl::DragSourceSystemDragEnded() {
923 Send(new DragMsg_SourceSystemDragEnded(GetRoutingID()));
926 RenderFrameHost
* RenderViewHostImpl::GetMainFrame() {
927 return RenderFrameHost::FromID(GetProcess()->GetID(), main_frame_routing_id_
);
930 void RenderViewHostImpl::AllowBindings(int bindings_flags
) {
931 // Never grant any bindings to browser plugin guests.
932 if (GetProcess()->IsGuest()) {
933 NOTREACHED() << "Never grant bindings to a guest process.";
937 // Ensure we aren't granting WebUI bindings to a process that has already
938 // been used for non-privileged views.
939 if (bindings_flags
& BINDINGS_POLICY_WEB_UI
&&
940 GetProcess()->HasConnection() &&
941 !ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
942 GetProcess()->GetID())) {
943 // This process has no bindings yet. Make sure it does not have more
944 // than this single active view.
945 RenderProcessHostImpl
* process
=
946 static_cast<RenderProcessHostImpl
*>(GetProcess());
947 if (process
->GetActiveViewCount() > 1)
951 if (bindings_flags
& BINDINGS_POLICY_WEB_UI
) {
952 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings(
953 GetProcess()->GetID());
956 enabled_bindings_
|= bindings_flags
;
957 if (renderer_initialized_
)
958 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_
));
961 int RenderViewHostImpl::GetEnabledBindings() const {
962 return enabled_bindings_
;
965 void RenderViewHostImpl::SetWebUIProperty(const std::string
& name
,
966 const std::string
& value
) {
967 // This is a sanity check before telling the renderer to enable the property.
968 // It could lie and send the corresponding IPC messages anyway, but we will
969 // not act on them if enabled_bindings_ doesn't agree. If we get here without
970 // WebUI bindings, kill the renderer process.
971 if (enabled_bindings_
& BINDINGS_POLICY_WEB_UI
) {
972 Send(new ViewMsg_SetWebUIProperty(GetRoutingID(), name
, value
));
975 base::UserMetricsAction("BindingsMismatchTerminate_RVH_WebUI"));
977 GetProcess()->GetHandle(), content::RESULT_CODE_KILLED
, false);
981 void RenderViewHostImpl::GotFocus() {
982 RenderWidgetHostImpl::GotFocus(); // Notifies the renderer it got focus.
984 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
989 void RenderViewHostImpl::LostCapture() {
990 RenderWidgetHostImpl::LostCapture();
991 delegate_
->LostCapture();
994 void RenderViewHostImpl::LostMouseLock() {
995 RenderWidgetHostImpl::LostMouseLock();
996 delegate_
->LostMouseLock();
999 void RenderViewHostImpl::SetInitialFocus(bool reverse
) {
1000 Send(new ViewMsg_SetInitialFocus(GetRoutingID(), reverse
));
1003 void RenderViewHostImpl::FilesSelectedInChooser(
1004 const std::vector
<ui::SelectedFileInfo
>& files
,
1005 FileChooserParams::Mode permissions
) {
1006 // Grant the security access requested to the given files.
1007 for (size_t i
= 0; i
< files
.size(); ++i
) {
1008 const ui::SelectedFileInfo
& file
= files
[i
];
1009 if (permissions
== FileChooserParams::Save
) {
1010 ChildProcessSecurityPolicyImpl::GetInstance()->GrantCreateReadWriteFile(
1011 GetProcess()->GetID(), file
.local_path
);
1013 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
1014 GetProcess()->GetID(), file
.local_path
);
1017 Send(new ViewMsg_RunFileChooserResponse(GetRoutingID(), files
));
1020 void RenderViewHostImpl::DirectoryEnumerationFinished(
1022 const std::vector
<base::FilePath
>& files
) {
1023 // Grant the security access requested to the given files.
1024 for (std::vector
<base::FilePath
>::const_iterator file
= files
.begin();
1025 file
!= files
.end(); ++file
) {
1026 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
1027 GetProcess()->GetID(), *file
);
1029 Send(new ViewMsg_EnumerateDirectoryResponse(GetRoutingID(),
1034 void RenderViewHostImpl::LoadStateChanged(
1036 const net::LoadStateWithParam
& load_state
,
1037 uint64 upload_position
,
1038 uint64 upload_size
) {
1039 delegate_
->LoadStateChanged(url
, load_state
, upload_position
, upload_size
);
1042 bool RenderViewHostImpl::SuddenTerminationAllowed() const {
1043 return sudden_termination_allowed_
||
1044 GetProcess()->SuddenTerminationAllowed();
1047 ///////////////////////////////////////////////////////////////////////////////
1048 // RenderViewHostImpl, IPC message handlers:
1050 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message
& msg
) {
1051 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg
, this))
1054 // Filter out most IPC messages if this renderer is swapped out.
1055 // We still want to handle certain ACKs to keep our state consistent.
1056 if (IsSwappedOut()) {
1057 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg
)) {
1058 // If this is a synchronous message and we decided not to handle it,
1059 // we must send an error reply, or else the renderer will be stuck
1060 // and won't respond to future requests.
1061 if (msg
.is_sync()) {
1062 IPC::Message
* reply
= IPC::SyncMessage::GenerateReply(&msg
);
1063 reply
->set_reply_error();
1066 // Don't continue looking for someone to handle it.
1071 if (delegate_
->OnMessageReceived(this, msg
))
1074 bool handled
= true;
1075 bool msg_is_ok
= true;
1076 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewHostImpl
, msg
, msg_is_ok
)
1077 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView
, OnShowView
)
1078 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget
, OnShowWidget
)
1079 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowFullscreenWidget
,
1080 OnShowFullscreenWidget
)
1081 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunModal
, OnRunModal
)
1082 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady
, OnRenderViewReady
)
1083 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderProcessGone
, OnRenderProcessGone
)
1084 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState
, OnUpdateState
)
1085 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTitle
, OnUpdateTitle
)
1086 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateEncoding
, OnUpdateEncoding
)
1087 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL
, OnUpdateTargetURL
)
1088 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateInspectorSetting
,
1089 OnUpdateInspectorSetting
)
1090 IPC_MESSAGE_HANDLER(ViewHostMsg_Close
, OnClose
)
1091 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove
, OnRequestMove
)
1092 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeLoadProgress
,
1093 OnDidChangeLoadProgress
)
1094 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisownOpener
, OnDidDisownOpener
)
1095 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame
,
1096 OnDocumentAvailableInMainFrame
)
1097 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame
,
1098 OnDocumentOnLoadCompletedInMainFrame
)
1099 IPC_MESSAGE_HANDLER(ViewHostMsg_ToggleFullscreen
, OnToggleFullscreen
)
1100 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange
,
1101 OnDidContentsPreferredSizeChange
)
1102 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffset
,
1103 OnDidChangeScrollOffset
)
1104 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollbarsForMainFrame
,
1105 OnDidChangeScrollbarsForMainFrame
)
1106 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame
,
1107 OnDidChangeScrollOffsetPinningForMainFrame
)
1108 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumWheelEvents
,
1109 OnDidChangeNumWheelEvents
)
1110 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent
,
1112 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteMessageEvent
, OnRouteMessageEvent
)
1113 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage
,
1114 OnRunJavaScriptMessage
)
1115 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm
,
1116 OnRunBeforeUnloadConfirm
)
1117 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging
, OnStartDragging
)
1118 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor
, OnUpdateDragCursor
)
1119 IPC_MESSAGE_HANDLER(DragHostMsg_TargetDrop_ACK
, OnTargetDropACK
)
1120 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus
, OnTakeFocus
)
1121 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged
, OnFocusedNodeChanged
)
1122 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole
, OnAddMessageToConsole
)
1123 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK
, OnClosePageACK
)
1124 IPC_MESSAGE_HANDLER(ViewHostMsg_SwapOut_ACK
, OnSwapOutACK
)
1125 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged
, OnSelectionChanged
)
1126 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged
,
1127 OnSelectionBoundsChanged
)
1128 #if defined(OS_ANDROID)
1129 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionRootBoundsChanged
,
1130 OnSelectionRootBoundsChanged
)
1132 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse
, OnScriptEvalResponse
)
1133 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL
, OnDidZoomURL
)
1134 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission
,
1135 OnRequestDesktopNotificationPermission
)
1136 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show
,
1137 OnShowDesktopNotification
)
1138 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel
,
1139 OnCancelDesktopNotification
)
1140 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1141 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup
, OnShowPopup
)
1143 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser
, OnRunFileChooser
)
1144 IPC_MESSAGE_HANDLER(ViewHostMsg_DidAccessInitialDocument
,
1145 OnDidAccessInitialDocument
)
1146 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events
, OnAccessibilityEvents
)
1147 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges
,
1148 OnAccessibilityLocationChanges
)
1149 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched
, OnFocusedNodeTouched
)
1150 // Have the super handle all other messages.
1151 IPC_MESSAGE_UNHANDLED(
1152 handled
= RenderWidgetHostImpl::OnMessageReceived(msg
))
1153 IPC_END_MESSAGE_MAP_EX()
1156 // The message had a handler, but its de-serialization failed.
1157 // Kill the renderer.
1158 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVH"));
1159 GetProcess()->ReceivedBadMessage();
1165 void RenderViewHostImpl::Init() {
1166 RenderWidgetHostImpl::Init();
1169 void RenderViewHostImpl::Shutdown() {
1170 // If we are being run modally (see RunModal), then we need to cleanup.
1171 if (run_modal_reply_msg_
) {
1172 Send(run_modal_reply_msg_
);
1173 run_modal_reply_msg_
= NULL
;
1174 RenderViewHostImpl
* opener
=
1175 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_
);
1177 opener
->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
1178 hung_renderer_delay_ms_
));
1179 // Balance out the decrement when we got created.
1180 opener
->increment_in_flight_event_count();
1182 run_modal_opener_id_
= MSG_ROUTING_NONE
;
1185 RenderWidgetHostImpl::Shutdown();
1188 bool RenderViewHostImpl::IsRenderView() const {
1192 void RenderViewHostImpl::CreateNewWindow(
1194 int main_frame_route_id
,
1195 const ViewHostMsg_CreateWindow_Params
& params
,
1196 SessionStorageNamespace
* session_storage_namespace
) {
1197 ViewHostMsg_CreateWindow_Params
validated_params(params
);
1198 GetProcess()->FilterURL(false, &validated_params
.target_url
);
1199 GetProcess()->FilterURL(false, &validated_params
.opener_url
);
1200 GetProcess()->FilterURL(true, &validated_params
.opener_security_origin
);
1202 delegate_
->CreateNewWindow(
1203 GetProcess()->GetID(), route_id
, main_frame_route_id
, validated_params
,
1204 session_storage_namespace
);
1207 void RenderViewHostImpl::CreateNewWidget(int route_id
,
1208 blink::WebPopupType popup_type
) {
1209 delegate_
->CreateNewWidget(GetProcess()->GetID(), route_id
, popup_type
);
1212 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id
) {
1213 delegate_
->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id
);
1216 void RenderViewHostImpl::OnShowView(int route_id
,
1217 WindowOpenDisposition disposition
,
1218 const gfx::Rect
& initial_pos
,
1219 bool user_gesture
) {
1220 if (IsRVHStateActive(rvh_state_
)) {
1221 delegate_
->ShowCreatedWindow(
1222 route_id
, disposition
, initial_pos
, user_gesture
);
1224 Send(new ViewMsg_Move_ACK(route_id
));
1227 void RenderViewHostImpl::OnShowWidget(int route_id
,
1228 const gfx::Rect
& initial_pos
) {
1229 if (IsRVHStateActive(rvh_state_
))
1230 delegate_
->ShowCreatedWidget(route_id
, initial_pos
);
1231 Send(new ViewMsg_Move_ACK(route_id
));
1234 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id
) {
1235 if (IsRVHStateActive(rvh_state_
))
1236 delegate_
->ShowCreatedFullscreenWidget(route_id
);
1237 Send(new ViewMsg_Move_ACK(route_id
));
1240 void RenderViewHostImpl::OnRunModal(int opener_id
, IPC::Message
* reply_msg
) {
1241 DCHECK(!run_modal_reply_msg_
);
1242 run_modal_reply_msg_
= reply_msg
;
1243 run_modal_opener_id_
= opener_id
;
1245 RecordAction(base::UserMetricsAction("ShowModalDialog"));
1247 RenderViewHostImpl
* opener
=
1248 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_
);
1250 opener
->StopHangMonitorTimeout();
1251 // The ack for the mouse down won't come until the dialog closes, so fake it
1252 // so that we don't get a timeout.
1253 opener
->decrement_in_flight_event_count();
1256 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in
1257 // an app-modal fashion.
1260 void RenderViewHostImpl::OnRenderViewReady() {
1261 render_view_termination_status_
= base::TERMINATION_STATUS_STILL_RUNNING
;
1264 delegate_
->RenderViewReady(this);
1267 void RenderViewHostImpl::OnRenderProcessGone(int status
, int exit_code
) {
1268 // Keep the termination status so we can get at it later when we
1269 // need to know why it died.
1270 render_view_termination_status_
=
1271 static_cast<base::TerminationStatus
>(status
);
1273 // Reset frame tree state associated with this process.
1274 delegate_
->GetFrameTree()->RenderProcessGone(this);
1276 // Our base class RenderWidgetHost needs to reset some stuff.
1277 RendererExited(render_view_termination_status_
, exit_code
);
1279 delegate_
->RenderViewTerminated(this,
1280 static_cast<base::TerminationStatus
>(status
),
1284 void RenderViewHostImpl::OnUpdateState(int32 page_id
, const PageState
& state
) {
1285 // Without this check, the renderer can trick the browser into using
1286 // filenames it can't access in a future session restore.
1287 if (!CanAccessFilesOfPageState(state
)) {
1288 GetProcess()->ReceivedBadMessage();
1292 delegate_
->UpdateState(this, page_id
, state
);
1295 void RenderViewHostImpl::OnUpdateTitle(
1297 const base::string16
& title
,
1298 blink::WebTextDirection title_direction
) {
1299 if (title
.length() > kMaxTitleChars
) {
1300 NOTREACHED() << "Renderer sent too many characters in title.";
1304 delegate_
->UpdateTitle(this, page_id
, title
,
1305 WebTextDirectionToChromeTextDirection(
1309 void RenderViewHostImpl::OnUpdateEncoding(const std::string
& encoding_name
) {
1310 delegate_
->UpdateEncoding(this, encoding_name
);
1313 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id
, const GURL
& url
) {
1314 if (IsRVHStateActive(rvh_state_
))
1315 delegate_
->UpdateTargetURL(page_id
, url
);
1317 // Send a notification back to the renderer that we are ready to
1318 // receive more target urls.
1319 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID()));
1322 void RenderViewHostImpl::OnUpdateInspectorSetting(
1323 const std::string
& key
, const std::string
& value
) {
1324 GetContentClient()->browser()->UpdateInspectorSetting(
1328 void RenderViewHostImpl::OnClose() {
1329 // If the renderer is telling us to close, it has already run the unload
1330 // events, and we can take the fast path.
1331 ClosePageIgnoringUnloadEvents();
1334 void RenderViewHostImpl::OnRequestMove(const gfx::Rect
& pos
) {
1335 if (IsRVHStateActive(rvh_state_
))
1336 delegate_
->RequestMove(pos
);
1337 Send(new ViewMsg_Move_ACK(GetRoutingID()));
1340 void RenderViewHostImpl::OnDidChangeLoadProgress(double load_progress
) {
1341 delegate_
->DidChangeLoadProgress(load_progress
);
1344 void RenderViewHostImpl::OnDidDisownOpener() {
1345 delegate_
->DidDisownOpener(this);
1348 void RenderViewHostImpl::OnDocumentAvailableInMainFrame() {
1349 delegate_
->DocumentAvailableInMainFrame(this);
1352 void RenderViewHostImpl::OnDocumentOnLoadCompletedInMainFrame(
1354 delegate_
->DocumentOnLoadCompletedInMainFrame(this, page_id
);
1357 void RenderViewHostImpl::OnToggleFullscreen(bool enter_fullscreen
) {
1358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
1359 delegate_
->ToggleFullscreenMode(enter_fullscreen
);
1360 // We need to notify the contents that its fullscreen state has changed. This
1361 // is done as part of the resize message.
1365 void RenderViewHostImpl::OnDidContentsPreferredSizeChange(
1366 const gfx::Size
& new_size
) {
1367 delegate_
->UpdatePreferredSize(new_size
);
1370 void RenderViewHostImpl::OnRenderAutoResized(const gfx::Size
& new_size
) {
1371 delegate_
->ResizeDueToAutoResize(new_size
);
1374 void RenderViewHostImpl::OnDidChangeScrollOffset() {
1376 view_
->ScrollOffsetChanged();
1379 void RenderViewHostImpl::OnDidChangeScrollbarsForMainFrame(
1380 bool has_horizontal_scrollbar
, bool has_vertical_scrollbar
) {
1382 view_
->SetHasHorizontalScrollbar(has_horizontal_scrollbar
);
1385 void RenderViewHostImpl::OnDidChangeScrollOffsetPinningForMainFrame(
1386 bool is_pinned_to_left
, bool is_pinned_to_right
) {
1388 view_
->SetScrollOffsetPinning(is_pinned_to_left
, is_pinned_to_right
);
1391 void RenderViewHostImpl::OnDidChangeNumWheelEvents(int count
) {
1394 void RenderViewHostImpl::OnSelectionChanged(const base::string16
& text
,
1396 const gfx::Range
& range
) {
1398 view_
->SelectionChanged(text
, offset
, range
);
1401 void RenderViewHostImpl::OnSelectionBoundsChanged(
1402 const ViewHostMsg_SelectionBounds_Params
& params
) {
1404 view_
->SelectionBoundsChanged(params
);
1408 #if defined(OS_ANDROID)
1409 void RenderViewHostImpl::OnSelectionRootBoundsChanged(
1410 const gfx::Rect
& bounds
) {
1412 view_
->SelectionRootBoundsChanged(bounds
);
1417 void RenderViewHostImpl::OnRouteCloseEvent() {
1418 // Have the delegate route this to the active RenderViewHost.
1419 delegate_
->RouteCloseEvent(this);
1422 void RenderViewHostImpl::OnRouteMessageEvent(
1423 const ViewMsg_PostMessage_Params
& params
) {
1424 // Give to the delegate to route to the active RenderViewHost.
1425 delegate_
->RouteMessageEvent(this, params
);
1428 void RenderViewHostImpl::OnRunJavaScriptMessage(
1429 const base::string16
& message
,
1430 const base::string16
& default_prompt
,
1431 const GURL
& frame_url
,
1432 JavaScriptMessageType type
,
1433 IPC::Message
* reply_msg
) {
1434 // While a JS message dialog is showing, tabs in the same process shouldn't
1435 // process input events.
1436 GetProcess()->SetIgnoreInputEvents(true);
1437 StopHangMonitorTimeout();
1438 delegate_
->RunJavaScriptMessage(this, message
, default_prompt
, frame_url
,
1440 &are_javascript_messages_suppressed_
);
1443 void RenderViewHostImpl::OnRunBeforeUnloadConfirm(const GURL
& frame_url
,
1444 const base::string16
& message
,
1446 IPC::Message
* reply_msg
) {
1447 // While a JS before unload dialog is showing, tabs in the same process
1448 // shouldn't process input events.
1449 GetProcess()->SetIgnoreInputEvents(true);
1450 StopHangMonitorTimeout();
1451 delegate_
->RunBeforeUnloadConfirm(this, message
, is_reload
, reply_msg
);
1454 void RenderViewHostImpl::OnStartDragging(
1455 const DropData
& drop_data
,
1456 WebDragOperationsMask drag_operations_mask
,
1457 const SkBitmap
& bitmap
,
1458 const gfx::Vector2d
& bitmap_offset_in_dip
,
1459 const DragEventSourceInfo
& event_info
) {
1460 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1464 DropData
filtered_data(drop_data
);
1465 RenderProcessHost
* process
= GetProcess();
1466 ChildProcessSecurityPolicyImpl
* policy
=
1467 ChildProcessSecurityPolicyImpl::GetInstance();
1469 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar.
1470 if (!filtered_data
.url
.SchemeIs(kJavaScriptScheme
))
1471 process
->FilterURL(true, &filtered_data
.url
);
1472 process
->FilterURL(false, &filtered_data
.html_base_url
);
1473 // Filter out any paths that the renderer didn't have access to. This prevents
1474 // the following attack on a malicious renderer:
1475 // 1. StartDragging IPC sent with renderer-specified filesystem paths that it
1476 // doesn't have read permissions for.
1477 // 2. We initiate a native DnD operation.
1478 // 3. DnD operation immediately ends since mouse is not held down. DnD events
1479 // still fire though, which causes read permissions to be granted to the
1480 // renderer for any file paths in the drop.
1481 filtered_data
.filenames
.clear();
1482 for (std::vector
<DropData::FileInfo
>::const_iterator it
=
1483 drop_data
.filenames
.begin();
1484 it
!= drop_data
.filenames
.end(); ++it
) {
1485 base::FilePath
path(
1486 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(it
->path
)));
1487 if (policy
->CanReadFile(GetProcess()->GetID(), path
))
1488 filtered_data
.filenames
.push_back(*it
);
1490 float scale
= ui::GetImageScale(GetScaleFactorForView(GetView()));
1491 gfx::ImageSkia
image(gfx::ImageSkiaRep(bitmap
, scale
));
1492 view
->StartDragging(filtered_data
, drag_operations_mask
, image
,
1493 bitmap_offset_in_dip
, event_info
);
1496 void RenderViewHostImpl::OnUpdateDragCursor(WebDragOperation current_op
) {
1497 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1499 view
->UpdateDragCursor(current_op
);
1502 void RenderViewHostImpl::OnTargetDropACK() {
1503 NotificationService::current()->Notify(
1504 NOTIFICATION_RENDER_VIEW_HOST_DID_RECEIVE_DRAG_TARGET_DROP_ACK
,
1505 Source
<RenderViewHost
>(this),
1506 NotificationService::NoDetails());
1509 void RenderViewHostImpl::OnTakeFocus(bool reverse
) {
1510 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1512 view
->TakeFocus(reverse
);
1515 void RenderViewHostImpl::OnFocusedNodeChanged(bool is_editable_node
) {
1517 view_
->FocusedNodeChanged(is_editable_node
);
1519 if (!is_editable_node
&& virtual_keyboard_requested_
) {
1520 virtual_keyboard_requested_
= false;
1521 BrowserThread::PostDelayedTask(
1522 BrowserThread::UI
, FROM_HERE
,
1523 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask
)),
1524 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs
));
1527 NotificationService::current()->Notify(
1528 NOTIFICATION_FOCUS_CHANGED_IN_PAGE
,
1529 Source
<RenderViewHost
>(this),
1530 Details
<const bool>(&is_editable_node
));
1533 void RenderViewHostImpl::OnAddMessageToConsole(
1535 const base::string16
& message
,
1537 const base::string16
& source_id
) {
1538 if (delegate_
->AddMessageToConsole(level
, message
, line_no
, source_id
))
1541 // Pass through log level only on WebUI pages to limit console spew.
1542 int32 resolved_level
= HasWebUIScheme(delegate_
->GetURL()) ? level
: 0;
1544 if (resolved_level
>= ::logging::GetMinLogLevel()) {
1545 logging::LogMessage("CONSOLE", line_no
, resolved_level
).stream() << "\"" <<
1546 message
<< "\", source: " << source_id
<< " (" << line_no
<< ")";
1550 void RenderViewHostImpl::OnUserGesture() {
1551 delegate_
->OnUserGesture();
1554 void RenderViewHostImpl::OnClosePageACK() {
1555 decrement_in_flight_event_count();
1556 ClosePageIgnoringUnloadEvents();
1559 void RenderViewHostImpl::NotifyRendererUnresponsive() {
1560 delegate_
->RendererUnresponsive(
1561 this, is_waiting_for_beforeunload_ack_
, IsWaitingForUnloadACK());
1564 void RenderViewHostImpl::NotifyRendererResponsive() {
1565 delegate_
->RendererResponsive(this);
1568 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture
,
1569 bool last_unlocked_by_target
) {
1570 delegate_
->RequestToLockMouse(user_gesture
, last_unlocked_by_target
);
1573 bool RenderViewHostImpl::IsFullscreen() const {
1574 return delegate_
->IsFullscreenForCurrentTab();
1577 void RenderViewHostImpl::OnFocus() {
1578 // Note: We allow focus and blur from swapped out RenderViewHosts, even when
1579 // the active RenderViewHost is in a different BrowsingInstance (e.g., WebUI).
1580 delegate_
->Activate();
1583 void RenderViewHostImpl::OnBlur() {
1584 delegate_
->Deactivate();
1587 gfx::Rect
RenderViewHostImpl::GetRootWindowResizerRect() const {
1588 return delegate_
->GetRootWindowResizerRect();
1591 void RenderViewHostImpl::ForwardMouseEvent(
1592 const blink::WebMouseEvent
& mouse_event
) {
1594 // We make a copy of the mouse event because
1595 // RenderWidgetHost::ForwardMouseEvent will delete |mouse_event|.
1596 blink::WebMouseEvent
event_copy(mouse_event
);
1597 RenderWidgetHostImpl::ForwardMouseEvent(event_copy
);
1599 switch (event_copy
.type
) {
1600 case WebInputEvent::MouseMove
:
1601 delegate_
->HandleMouseMove();
1603 case WebInputEvent::MouseLeave
:
1604 delegate_
->HandleMouseLeave();
1606 case WebInputEvent::MouseDown
:
1607 delegate_
->HandleMouseDown();
1609 case WebInputEvent::MouseWheel
:
1610 if (ignore_input_events())
1611 delegate_
->OnIgnoredUIEvent();
1613 case WebInputEvent::MouseUp
:
1614 delegate_
->HandleMouseUp();
1616 // For now, we don't care about the rest.
1621 void RenderViewHostImpl::OnPointerEventActivate() {
1622 delegate_
->HandlePointerActivate();
1625 void RenderViewHostImpl::ForwardKeyboardEvent(
1626 const NativeWebKeyboardEvent
& key_event
) {
1627 if (ignore_input_events()) {
1628 if (key_event
.type
== WebInputEvent::RawKeyDown
)
1629 delegate_
->OnIgnoredUIEvent();
1632 RenderWidgetHostImpl::ForwardKeyboardEvent(key_event
);
1635 #if defined(OS_ANDROID)
1636 void RenderViewHostImpl::DidSelectPopupMenuItems(
1637 const std::vector
<int>& selected_indices
) {
1638 Send(new ViewMsg_SelectPopupMenuItems(GetRoutingID(), false,
1642 void RenderViewHostImpl::DidCancelPopupMenu() {
1643 Send(new ViewMsg_SelectPopupMenuItems(GetRoutingID(), true,
1644 std::vector
<int>()));
1648 #if defined(OS_MACOSX)
1649 void RenderViewHostImpl::DidSelectPopupMenuItem(int selected_index
) {
1650 Send(new ViewMsg_SelectPopupMenuItem(GetRoutingID(), selected_index
));
1653 void RenderViewHostImpl::DidCancelPopupMenu() {
1654 Send(new ViewMsg_SelectPopupMenuItem(GetRoutingID(), -1));
1658 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation
) {
1659 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation
));
1662 void RenderViewHostImpl::ToggleSpeechInput() {
1663 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID()));
1666 bool RenderViewHostImpl::IsWaitingForUnloadACK() const {
1667 return rvh_state_
== STATE_WAITING_FOR_UNLOAD_ACK
||
1668 rvh_state_
== STATE_WAITING_FOR_CLOSE
||
1669 rvh_state_
== STATE_PENDING_SHUTDOWN
||
1670 rvh_state_
== STATE_PENDING_SWAP_OUT
;
1673 void RenderViewHostImpl::ExitFullscreen() {
1674 RejectMouseLockOrUnlockIfNecessary();
1675 // Notify delegate_ and renderer of fullscreen state change.
1676 OnToggleFullscreen(false);
1679 WebPreferences
RenderViewHostImpl::GetWebkitPreferences() {
1680 return delegate_
->GetWebkitPrefs();
1683 void RenderViewHostImpl::DisownOpener() {
1684 // This should only be called when swapped out.
1685 DCHECK(IsSwappedOut());
1687 Send(new ViewMsg_DisownOpener(GetRoutingID()));
1690 void RenderViewHostImpl::SetAccessibilityCallbackForTesting(
1691 const base::Callback
<void(ui::AXEvent
)>& callback
) {
1692 accessibility_testing_callback_
= callback
;
1695 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences
& prefs
) {
1696 Send(new ViewMsg_UpdateWebPreferences(GetRoutingID(), prefs
));
1699 void RenderViewHostImpl::GetAudioOutputControllers(
1700 const GetAudioOutputControllersCallback
& callback
) const {
1701 AudioRendererHost
* audio_host
=
1702 static_cast<RenderProcessHostImpl
*>(GetProcess())->audio_renderer_host();
1703 audio_host
->GetOutputControllers(GetRoutingID(), callback
);
1706 void RenderViewHostImpl::ClearFocusedElement() {
1707 Send(new ViewMsg_ClearFocusedElement(GetRoutingID()));
1710 void RenderViewHostImpl::Zoom(PageZoom zoom
) {
1711 Send(new ViewMsg_Zoom(GetRoutingID(), zoom
));
1714 void RenderViewHostImpl::ReloadFrame() {
1715 Send(new ViewMsg_ReloadFrame(GetRoutingID()));
1718 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size
& size
) {
1719 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size
));
1722 void RenderViewHostImpl::EnablePreferredSizeMode() {
1723 Send(new ViewMsg_EnablePreferredSizeChangedMode(GetRoutingID()));
1726 void RenderViewHostImpl::EnableAutoResize(const gfx::Size
& min_size
,
1727 const gfx::Size
& max_size
) {
1728 SetShouldAutoResize(true);
1729 Send(new ViewMsg_EnableAutoResize(GetRoutingID(), min_size
, max_size
));
1732 void RenderViewHostImpl::DisableAutoResize(const gfx::Size
& new_size
) {
1733 SetShouldAutoResize(false);
1734 Send(new ViewMsg_DisableAutoResize(GetRoutingID(), new_size
));
1737 void RenderViewHostImpl::CopyImageAt(int x
, int y
) {
1738 Send(new ViewMsg_CopyImageAt(GetRoutingID(), x
, y
));
1741 void RenderViewHostImpl::ExecuteMediaPlayerActionAtLocation(
1742 const gfx::Point
& location
, const blink::WebMediaPlayerAction
& action
) {
1743 Send(new ViewMsg_MediaPlayerActionAt(GetRoutingID(), location
, action
));
1746 void RenderViewHostImpl::ExecutePluginActionAtLocation(
1747 const gfx::Point
& location
, const blink::WebPluginAction
& action
) {
1748 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location
, action
));
1751 void RenderViewHostImpl::NotifyMoveOrResizeStarted() {
1752 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID()));
1755 void RenderViewHostImpl::OnAccessibilityEvents(
1756 const std::vector
<AccessibilityHostMsg_EventParams
>& params
) {
1757 if ((accessibility_mode() & AccessibilityModeFlagPlatform
) && view_
&&
1758 IsRVHStateActive(rvh_state_
)) {
1759 view_
->CreateBrowserAccessibilityManagerIfNeeded();
1760 BrowserAccessibilityManager
* manager
=
1761 view_
->GetBrowserAccessibilityManager();
1763 manager
->OnAccessibilityEvents(params
);
1765 // TODO(aboxhall, dtseng): Only send notification when accessibility mode
1766 // extension enabled.
1767 std::vector
<AXEventNotificationDetails
> details
;
1768 for (unsigned int i
= 0; i
< params
.size(); ++i
) {
1769 const AccessibilityHostMsg_EventParams
& param
= params
[i
];
1770 AXEventNotificationDetails
detail(
1771 param
.nodes
, param
.event_type
, param
.id
, GetRoutingID());
1772 details
.push_back(detail
);
1775 delegate_
->AccessibilityEventReceived(details
);
1778 // Always send an ACK or the renderer can be in a bad state.
1779 Send(new AccessibilityMsg_Events_ACK(GetRoutingID()));
1781 // The rest of this code is just for testing; bail out if we're not
1783 if (accessibility_testing_callback_
.is_null())
1786 for (unsigned i
= 0; i
< params
.size(); i
++) {
1787 const AccessibilityHostMsg_EventParams
& param
= params
[i
];
1788 if (static_cast<int>(param
.event_type
) < 0)
1790 ui::AXTreeUpdate update
;
1791 update
.nodes
= param
.nodes
;
1793 ax_tree_
.reset(new ui::AXTree(update
));
1795 CHECK(ax_tree_
->Unserialize(update
)) << ax_tree_
->error();
1796 accessibility_testing_callback_
.Run(param
.event_type
);
1800 void RenderViewHostImpl::OnAccessibilityLocationChanges(
1801 const std::vector
<AccessibilityHostMsg_LocationChangeParams
>& params
) {
1802 if (view_
&& IsRVHStateActive(rvh_state_
)) {
1803 view_
->CreateBrowserAccessibilityManagerIfNeeded();
1804 BrowserAccessibilityManager
* manager
=
1805 view_
->GetBrowserAccessibilityManager();
1807 manager
->OnLocationChanges(params
);
1811 void RenderViewHostImpl::OnScriptEvalResponse(int id
,
1812 const base::ListValue
& result
) {
1813 const base::Value
* result_value
;
1814 if (!result
.Get(0, &result_value
)) {
1815 // Programming error or rogue renderer.
1816 NOTREACHED() << "Got bad arguments for OnScriptEvalResponse";
1820 std::map
<int, JavascriptResultCallback
>::iterator it
=
1821 javascript_callbacks_
.find(id
);
1822 if (it
!= javascript_callbacks_
.end()) {
1823 // ExecuteJavascriptInWebFrameCallbackResult was used; do callback.
1824 it
->second
.Run(result_value
);
1825 javascript_callbacks_
.erase(it
);
1827 NOTREACHED() << "Received script response for unknown request";
1831 void RenderViewHostImpl::OnDidZoomURL(double zoom_level
,
1834 HostZoomMapImpl
* host_zoom_map
= static_cast<HostZoomMapImpl
*>(
1835 HostZoomMap::GetForBrowserContext(GetProcess()->GetBrowserContext()));
1838 SetZoomLevelForHost(net::GetHostOrSpecFromURL(url
), zoom_level
);
1840 host_zoom_map
->SetTemporaryZoomLevel(
1841 GetProcess()->GetID(), GetRoutingID(), zoom_level
);
1845 void RenderViewHostImpl::OnRequestDesktopNotificationPermission(
1846 const GURL
& source_origin
, int callback_context
) {
1847 GetContentClient()->browser()->RequestDesktopNotificationPermission(
1848 source_origin
, callback_context
, GetProcess()->GetID(), GetRoutingID());
1851 void RenderViewHostImpl::OnShowDesktopNotification(
1852 const ShowDesktopNotificationHostMsgParams
& params
) {
1853 GetContentClient()->browser()->ShowDesktopNotification(
1854 params
, GetProcess()->GetID(), GetRoutingID(), false);
1857 void RenderViewHostImpl::OnCancelDesktopNotification(int notification_id
) {
1858 GetContentClient()->browser()->CancelDesktopNotification(
1859 GetProcess()->GetID(), GetRoutingID(), notification_id
);
1862 void RenderViewHostImpl::OnRunFileChooser(const FileChooserParams
& params
) {
1863 delegate_
->RunFileChooser(this, params
);
1866 void RenderViewHostImpl::OnDidAccessInitialDocument() {
1867 has_accessed_initial_document_
= true;
1868 delegate_
->DidAccessInitialDocument();
1871 void RenderViewHostImpl::OnFocusedNodeTouched(bool editable
) {
1874 virtual_keyboard_requested_
= base::win::DisplayVirtualKeyboard();
1876 virtual_keyboard_requested_
= false;
1877 base::win::DismissVirtualKeyboard();
1882 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1883 void RenderViewHostImpl::OnShowPopup(
1884 const ViewHostMsg_ShowPopup_Params
& params
) {
1885 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1887 view
->ShowPopupMenu(params
.bounds
,
1889 params
.item_font_size
,
1890 params
.selected_item
,
1892 params
.right_aligned
,
1893 params
.allow_multiple_selection
);
1898 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state
) {
1899 // We update the number of RenderViews in a SiteInstance when the
1900 // swapped out status of this RenderView gets flipped to/from live.
1901 if (!IsRVHStateActive(rvh_state_
) && IsRVHStateActive(rvh_state
))
1902 instance_
->increment_active_view_count();
1903 else if (IsRVHStateActive(rvh_state_
) && !IsRVHStateActive(rvh_state
))
1904 instance_
->decrement_active_view_count();
1906 // Whenever we change the RVH state to and from live or swapped out state, we
1907 // should not be waiting for beforeunload or unload acks. We clear them here
1908 // to be safe, since they can cause navigations to be ignored in OnNavigate.
1909 if (rvh_state
== STATE_DEFAULT
||
1910 rvh_state
== STATE_SWAPPED_OUT
||
1911 rvh_state_
== STATE_DEFAULT
||
1912 rvh_state_
== STATE_SWAPPED_OUT
) {
1913 is_waiting_for_beforeunload_ack_
= false;
1915 rvh_state_
= rvh_state
;
1919 bool RenderViewHostImpl::CanAccessFilesOfPageState(
1920 const PageState
& state
) const {
1921 ChildProcessSecurityPolicyImpl
* policy
=
1922 ChildProcessSecurityPolicyImpl::GetInstance();
1924 const std::vector
<base::FilePath
>& file_paths
= state
.GetReferencedFiles();
1925 for (std::vector
<base::FilePath
>::const_iterator file
= file_paths
.begin();
1926 file
!= file_paths
.end(); ++file
) {
1927 if (!policy
->CanReadFile(GetProcess()->GetID(), *file
))
1933 void RenderViewHostImpl::AttachToFrameTree() {
1934 FrameTree
* frame_tree
= delegate_
->GetFrameTree();
1936 frame_tree
->ResetForMainFrameSwap();
1939 } // namespace content