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/field_trial.h"
19 #include "base/metrics/histogram.h"
20 #include "base/stl_util.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/sys_info.h"
24 #include "base/time/time.h"
25 #include "base/values.h"
26 #include "cc/base/switches.h"
27 #include "content/browser/child_process_security_policy_impl.h"
28 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
29 #include "content/browser/frame_host/frame_tree.h"
30 #include "content/browser/gpu/compositor_util.h"
31 #include "content/browser/gpu/gpu_data_manager_impl.h"
32 #include "content/browser/gpu/gpu_process_host.h"
33 #include "content/browser/gpu/gpu_surface_tracker.h"
34 #include "content/browser/host_zoom_map_impl.h"
35 #include "content/browser/loader/resource_dispatcher_host_impl.h"
36 #include "content/browser/renderer_host/dip_util.h"
37 #include "content/browser/renderer_host/media/audio_renderer_host.h"
38 #include "content/browser/renderer_host/render_process_host_impl.h"
39 #include "content/browser/renderer_host/render_view_host_delegate.h"
40 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
41 #include "content/browser/renderer_host/render_widget_host_view_base.h"
42 #include "content/common/browser_plugin/browser_plugin_messages.h"
43 #include "content/common/content_switches_internal.h"
44 #include "content/common/drag_messages.h"
45 #include "content/common/frame_messages.h"
46 #include "content/common/input_messages.h"
47 #include "content/common/inter_process_time_ticks_converter.h"
48 #include "content/common/speech_recognition_messages.h"
49 #include "content/common/swapped_out_messages.h"
50 #include "content/common/view_messages.h"
51 #include "content/public/browser/ax_event_notification_details.h"
52 #include "content/public/browser/browser_accessibility_state.h"
53 #include "content/public/browser/browser_context.h"
54 #include "content/public/browser/browser_message_filter.h"
55 #include "content/public/browser/content_browser_client.h"
56 #include "content/public/browser/native_web_keyboard_event.h"
57 #include "content/public/browser/notification_details.h"
58 #include "content/public/browser/notification_service.h"
59 #include "content/public/browser/notification_types.h"
60 #include "content/public/browser/render_frame_host.h"
61 #include "content/public/browser/render_widget_host_iterator.h"
62 #include "content/public/browser/storage_partition.h"
63 #include "content/public/browser/user_metrics.h"
64 #include "content/public/common/bindings_policy.h"
65 #include "content/public/common/content_constants.h"
66 #include "content/public/common/content_switches.h"
67 #include "content/public/common/context_menu_params.h"
68 #include "content/public/common/drop_data.h"
69 #include "content/public/common/file_chooser_file_info.h"
70 #include "content/public/common/file_chooser_params.h"
71 #include "content/public/common/result_codes.h"
72 #include "content/public/common/url_utils.h"
73 #include "net/base/filename_util.h"
74 #include "net/base/net_util.h"
75 #include "net/base/network_change_notifier.h"
76 #include "net/url_request/url_request_context_getter.h"
77 #include "storage/browser/fileapi/isolated_context.h"
78 #include "third_party/skia/include/core/SkBitmap.h"
79 #include "ui/base/touch/touch_device.h"
80 #include "ui/base/touch/touch_enabled.h"
81 #include "ui/base/ui_base_switches.h"
82 #include "ui/gfx/image/image_skia.h"
83 #include "ui/gfx/native_widget_types.h"
84 #include "ui/native_theme/native_theme_switches.h"
85 #include "url/url_constants.h"
88 #include "base/win/win_util.h"
91 #if defined(ENABLE_BROWSER_CDMS)
92 #include "content/browser/media/media_web_contents_observer.h"
95 using base::TimeDelta
;
96 using blink::WebConsoleMessage
;
97 using blink::WebDragOperation
;
98 using blink::WebDragOperationNone
;
99 using blink::WebDragOperationsMask
;
100 using blink::WebInputEvent
;
101 using blink::WebMediaPlayerAction
;
102 using blink::WebPluginAction
;
109 const int kVirtualKeyboardDisplayWaitTimeoutMs
= 100;
110 const int kMaxVirtualKeyboardDisplayRetries
= 5;
112 void DismissVirtualKeyboardTask() {
113 static int virtual_keyboard_display_retries
= 0;
114 // If the virtual keyboard is not yet visible, then we execute the task again
115 // waiting for it to show up.
116 if (!base::win::DismissVirtualKeyboard()) {
117 if (virtual_keyboard_display_retries
< kMaxVirtualKeyboardDisplayRetries
) {
118 BrowserThread::PostDelayedTask(
119 BrowserThread::UI
, FROM_HERE
,
120 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask
)),
121 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs
));
122 ++virtual_keyboard_display_retries
;
124 virtual_keyboard_display_retries
= 0;
133 const int64
RenderViewHostImpl::kUnloadTimeoutMS
= 1000;
135 ///////////////////////////////////////////////////////////////////////////////
136 // RenderViewHost, public:
139 RenderViewHost
* RenderViewHost::FromID(int render_process_id
,
140 int render_view_id
) {
141 return RenderViewHostImpl::FromID(render_process_id
, render_view_id
);
145 RenderViewHost
* RenderViewHost::From(RenderWidgetHost
* rwh
) {
146 DCHECK(rwh
->IsRenderView());
147 return static_cast<RenderViewHostImpl
*>(RenderWidgetHostImpl::From(rwh
));
150 ///////////////////////////////////////////////////////////////////////////////
151 // RenderViewHostImpl, public:
154 RenderViewHostImpl
* RenderViewHostImpl::FromID(int render_process_id
,
155 int render_view_id
) {
156 RenderWidgetHost
* widget
=
157 RenderWidgetHost::FromID(render_process_id
, render_view_id
);
158 if (!widget
|| !widget
->IsRenderView())
160 return static_cast<RenderViewHostImpl
*>(RenderWidgetHostImpl::From(widget
));
163 RenderViewHostImpl::RenderViewHostImpl(
164 SiteInstance
* instance
,
165 RenderViewHostDelegate
* delegate
,
166 RenderWidgetHostDelegate
* widget_delegate
,
168 int main_frame_routing_id
,
171 bool has_initialized_audio_host
)
172 : RenderWidgetHostImpl(widget_delegate
,
173 instance
->GetProcess(),
176 frames_ref_count_(0),
178 instance_(static_cast<SiteInstanceImpl
*>(instance
)),
179 waiting_for_drag_context_response_(false),
180 enabled_bindings_(0),
182 is_active_(!swapped_out
),
183 is_swapped_out_(swapped_out
),
184 main_frame_routing_id_(main_frame_routing_id
),
185 run_modal_reply_msg_(NULL
),
186 run_modal_opener_id_(MSG_ROUTING_NONE
),
187 is_waiting_for_close_ack_(false),
188 sudden_termination_allowed_(false),
189 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING
),
190 virtual_keyboard_requested_(false),
191 is_focused_element_editable_(false),
192 updating_web_preferences_(false),
193 weak_factory_(this) {
194 DCHECK(instance_
.get());
195 CHECK(delegate_
); // http://crbug.com/82827
197 GetProcess()->EnableSendQueue();
199 if (ResourceDispatcherHostImpl::Get()) {
200 bool has_active_audio
= false;
201 if (has_initialized_audio_host
) {
202 scoped_refptr
<AudioRendererHost
> arh
=
203 static_cast<RenderProcessHostImpl
*>(GetProcess())
204 ->audio_renderer_host();
206 has_active_audio
= arh
->RenderViewHasActiveAudio(GetRoutingID());
208 BrowserThread::PostTask(
211 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated
,
212 base::Unretained(ResourceDispatcherHostImpl::Get()),
213 GetProcess()->GetID(),
218 #if defined(ENABLE_BROWSER_CDMS)
219 media_web_contents_observer_
.reset(new MediaWebContentsObserver(this));
223 RenderViewHostImpl::~RenderViewHostImpl() {
224 if (ResourceDispatcherHostImpl::Get()) {
225 BrowserThread::PostTask(
226 BrowserThread::IO
, FROM_HERE
,
227 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted
,
228 base::Unretained(ResourceDispatcherHostImpl::Get()),
229 GetProcess()->GetID(), GetRoutingID()));
232 delegate_
->RenderViewDeleted(this);
235 RenderViewHostDelegate
* RenderViewHostImpl::GetDelegate() const {
239 SiteInstanceImpl
* RenderViewHostImpl::GetSiteInstance() const {
240 return instance_
.get();
243 bool RenderViewHostImpl::CreateRenderView(
244 const base::string16
& frame_name
,
248 bool window_was_created_with_opener
) {
249 TRACE_EVENT0("renderer_host,navigation",
250 "RenderViewHostImpl::CreateRenderView");
251 DCHECK(!IsRenderViewLive()) << "Creating view twice";
253 // The process may (if we're sharing a process with another host that already
254 // initialized it) or may not (we have our own process or the old process
255 // crashed) have been initialized. Calling Init multiple times will be
256 // ignored, so this is safe.
257 if (!GetProcess()->Init())
259 DCHECK(GetProcess()->HasConnection());
260 DCHECK(GetProcess()->GetBrowserContext());
262 renderer_initialized_
= true;
264 GpuSurfaceTracker::Get()->SetSurfaceHandle(
265 surface_id(), GetCompositingSurface());
267 // Ensure the RenderView starts with a next_page_id larger than any existing
268 // page ID it might be asked to render.
269 int32 next_page_id
= 1;
270 if (max_page_id
> -1)
271 next_page_id
= max_page_id
+ 1;
273 ViewMsg_New_Params params
;
274 params
.renderer_preferences
=
275 delegate_
->GetRendererPrefs(GetProcess()->GetBrowserContext());
276 params
.web_preferences
= GetWebkitPreferences();
277 params
.view_id
= GetRoutingID();
278 params
.main_frame_routing_id
= main_frame_routing_id_
;
279 params
.surface_id
= surface_id();
280 params
.session_storage_namespace_id
=
281 delegate_
->GetSessionStorageNamespace(instance_
.get())->id();
282 params
.frame_name
= frame_name
;
283 // Ensure the RenderView sets its opener correctly.
284 params
.opener_route_id
= opener_route_id
;
285 params
.swapped_out
= !is_active_
;
286 params
.proxy_routing_id
= proxy_route_id
;
287 params
.hidden
= is_hidden();
288 params
.never_visible
= delegate_
->IsNeverVisible();
289 params
.window_was_created_with_opener
= window_was_created_with_opener
;
290 params
.next_page_id
= next_page_id
;
291 GetWebScreenInfo(¶ms
.screen_info
);
293 Send(new ViewMsg_New(params
));
295 // If it's enabled, tell the renderer to set up the Javascript bindings for
296 // sending messages back to the browser.
297 if (GetProcess()->IsIsolatedGuest())
298 DCHECK_EQ(0, enabled_bindings_
);
299 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_
));
300 // Let our delegate know that we created a RenderView.
301 delegate_
->RenderViewCreated(this);
306 bool RenderViewHostImpl::IsRenderViewLive() const {
307 return GetProcess()->HasConnection() && renderer_initialized_
;
310 void RenderViewHostImpl::SyncRendererPrefs() {
311 Send(new ViewMsg_SetRendererPrefs(GetRoutingID(),
312 delegate_
->GetRendererPrefs(
313 GetProcess()->GetBrowserContext())));
316 WebPreferences
RenderViewHostImpl::ComputeWebkitPrefs(const GURL
& url
) {
317 TRACE_EVENT0("browser", "RenderViewHostImpl::GetWebkitPrefs");
318 WebPreferences prefs
;
320 const base::CommandLine
& command_line
=
321 *base::CommandLine::ForCurrentProcess();
323 prefs
.javascript_enabled
=
324 !command_line
.HasSwitch(switches::kDisableJavaScript
);
325 prefs
.web_security_enabled
=
326 !command_line
.HasSwitch(switches::kDisableWebSecurity
);
327 prefs
.plugins_enabled
=
328 !command_line
.HasSwitch(switches::kDisablePlugins
);
330 !command_line
.HasSwitch(switches::kDisableJava
);
332 prefs
.remote_fonts_enabled
=
333 !command_line
.HasSwitch(switches::kDisableRemoteFonts
);
335 !command_line
.HasSwitch(switches::kDisableXSLT
);
336 prefs
.xss_auditor_enabled
=
337 !command_line
.HasSwitch(switches::kDisableXSSAuditor
);
338 prefs
.application_cache_enabled
=
339 !command_line
.HasSwitch(switches::kDisableApplicationCache
);
341 prefs
.local_storage_enabled
=
342 !command_line
.HasSwitch(switches::kDisableLocalStorage
);
343 prefs
.databases_enabled
=
344 !command_line
.HasSwitch(switches::kDisableDatabases
);
345 #if defined(OS_ANDROID)
346 // WebAudio is enabled by default on x86 and ARM.
347 prefs
.webaudio_enabled
=
348 !command_line
.HasSwitch(switches::kDisableWebAudio
);
351 prefs
.experimental_webgl_enabled
=
352 GpuProcessHost::gpu_enabled() &&
353 !command_line
.HasSwitch(switches::kDisable3DAPIs
) &&
354 !command_line
.HasSwitch(switches::kDisableExperimentalWebGL
);
356 prefs
.pepper_3d_enabled
=
357 !command_line
.HasSwitch(switches::kDisablePepper3d
);
359 prefs
.flash_3d_enabled
=
360 GpuProcessHost::gpu_enabled() &&
361 !command_line
.HasSwitch(switches::kDisableFlash3d
);
362 prefs
.flash_stage3d_enabled
=
363 GpuProcessHost::gpu_enabled() &&
364 !command_line
.HasSwitch(switches::kDisableFlashStage3d
);
365 prefs
.flash_stage3d_baseline_enabled
=
366 GpuProcessHost::gpu_enabled() &&
367 !command_line
.HasSwitch(switches::kDisableFlashStage3d
);
369 prefs
.allow_file_access_from_file_urls
=
370 command_line
.HasSwitch(switches::kAllowFileAccessFromFiles
);
372 prefs
.layer_squashing_enabled
= true;
373 if (command_line
.HasSwitch(switches::kEnableLayerSquashing
))
374 prefs
.layer_squashing_enabled
= true;
375 if (command_line
.HasSwitch(switches::kDisableLayerSquashing
))
376 prefs
.layer_squashing_enabled
= false;
378 prefs
.accelerated_2d_canvas_enabled
=
379 GpuProcessHost::gpu_enabled() &&
380 !command_line
.HasSwitch(switches::kDisableAccelerated2dCanvas
);
381 prefs
.antialiased_2d_canvas_disabled
=
382 command_line
.HasSwitch(switches::kDisable2dCanvasAntialiasing
);
383 prefs
.antialiased_clips_2d_canvas_enabled
=
384 command_line
.HasSwitch(switches::kEnable2dCanvasClipAntialiasing
);
385 prefs
.accelerated_2d_canvas_msaa_sample_count
=
386 atoi(command_line
.GetSwitchValueASCII(
387 switches::kAcceleratedCanvas2dMSAASampleCount
).c_str());
388 prefs
.container_culling_enabled
=
389 command_line
.HasSwitch(switches::kEnableContainerCulling
);
390 prefs
.text_blobs_enabled
=
391 command_line
.HasSwitch(switches::kEnableTextBlobs
);
392 prefs
.region_based_columns_enabled
=
393 command_line
.HasSwitch(switches::kEnableRegionBasedColumns
);
395 if (IsPinchVirtualViewportEnabled()) {
396 prefs
.pinch_virtual_viewport_enabled
= true;
397 prefs
.pinch_overlay_scrollbar_thickness
= 10;
399 prefs
.use_solid_color_scrollbars
= ui::IsOverlayScrollbarEnabled();
401 #if defined(OS_ANDROID)
402 prefs
.user_gesture_required_for_media_playback
= !command_line
.HasSwitch(
403 switches::kDisableGestureRequirementForMediaPlayback
);
406 prefs
.touch_enabled
= ui::AreTouchEventsEnabled();
407 prefs
.device_supports_touch
= prefs
.touch_enabled
&&
408 ui::IsTouchDevicePresent();
409 #if defined(OS_ANDROID)
410 prefs
.device_supports_mouse
= false;
413 prefs
.pointer_events_max_touch_points
= ui::MaxTouchPoints();
415 prefs
.touch_adjustment_enabled
=
416 !command_line
.HasSwitch(switches::kDisableTouchAdjustment
);
418 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
419 bool default_enable_scroll_animator
= true;
421 bool default_enable_scroll_animator
= false;
423 prefs
.enable_scroll_animator
= default_enable_scroll_animator
;
424 if (command_line
.HasSwitch(switches::kEnableSmoothScrolling
))
425 prefs
.enable_scroll_animator
= true;
426 if (command_line
.HasSwitch(switches::kDisableSmoothScrolling
))
427 prefs
.enable_scroll_animator
= false;
429 // Certain GPU features might have been blacklisted.
430 GpuDataManagerImpl::GetInstance()->UpdateRendererWebPrefs(&prefs
);
432 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
433 GetProcess()->GetID())) {
434 prefs
.loads_images_automatically
= true;
435 prefs
.javascript_enabled
= true;
438 prefs
.connection_type
= net::NetworkChangeNotifier::GetConnectionType();
440 prefs
.connection_type
!= net::NetworkChangeNotifier::CONNECTION_NONE
;
442 prefs
.number_of_cpu_cores
= base::SysInfo::NumberOfProcessors();
444 prefs
.viewport_meta_enabled
=
445 command_line
.HasSwitch(switches::kEnableViewportMeta
);
447 prefs
.viewport_enabled
=
448 command_line
.HasSwitch(switches::kEnableViewport
) ||
449 prefs
.viewport_meta_enabled
;
451 prefs
.main_frame_resizes_are_orientation_changes
=
452 command_line
.HasSwitch(switches::kMainFrameResizesAreOrientationChanges
);
454 prefs
.deferred_image_decoding_enabled
=
455 command_line
.HasSwitch(switches::kEnableDeferredImageDecoding
) ||
456 content::IsImplSidePaintingEnabled();
458 prefs
.spatial_navigation_enabled
= command_line
.HasSwitch(
459 switches::kEnableSpatialNavigation
);
461 if (command_line
.HasSwitch(switches::kV8CacheOptions
)) {
462 const std::string v8_cache_options
=
463 command_line
.GetSwitchValueASCII(switches::kV8CacheOptions
);
464 if (v8_cache_options
== "parse") {
465 prefs
.v8_cache_options
= V8_CACHE_OPTIONS_PARSE
;
466 } else if (v8_cache_options
== "code") {
467 prefs
.v8_cache_options
= V8_CACHE_OPTIONS_CODE
;
469 prefs
.v8_cache_options
= V8_CACHE_OPTIONS_OFF
;
473 prefs
.v8_script_streaming_enabled
=
474 command_line
.HasSwitch(switches::kEnableV8ScriptStreaming
) ||
475 base::FieldTrialList::FindFullName("V8ScriptStreaming") == "Enabled";
477 GetContentClient()->browser()->OverrideWebkitPrefs(this, url
, &prefs
);
481 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
482 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
485 void RenderViewHostImpl::ClosePage() {
486 is_waiting_for_close_ack_
= true;
487 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS
));
489 if (IsRenderViewLive()) {
490 // Since we are sending an IPC message to the renderer, increase the event
491 // count to prevent the hang monitor timeout from being stopped by input
492 // event acknowledgements.
493 increment_in_flight_event_count();
495 // TODO(creis): Should this be moved to Shutdown? It may not be called for
496 // RenderViewHosts that have been swapped out.
497 NotificationService::current()->Notify(
498 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW
,
499 Source
<RenderViewHost
>(this),
500 NotificationService::NoDetails());
502 Send(new ViewMsg_ClosePage(GetRoutingID()));
504 // This RenderViewHost doesn't have a live renderer, so just skip the unload
505 // event and close the page.
506 ClosePageIgnoringUnloadEvents();
510 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() {
511 StopHangMonitorTimeout();
512 is_waiting_for_close_ack_
= false;
514 sudden_termination_allowed_
= true;
515 delegate_
->Close(this);
518 #if defined(OS_ANDROID)
519 void RenderViewHostImpl::ActivateNearestFindResult(int request_id
,
522 Send(new InputMsg_ActivateNearestFindResult(GetRoutingID(),
526 void RenderViewHostImpl::RequestFindMatchRects(int current_version
) {
527 Send(new ViewMsg_FindMatchRects(GetRoutingID(), current_version
));
531 void RenderViewHostImpl::DragTargetDragEnter(
532 const DropData
& drop_data
,
533 const gfx::Point
& client_pt
,
534 const gfx::Point
& screen_pt
,
535 WebDragOperationsMask operations_allowed
,
537 const int renderer_id
= GetProcess()->GetID();
538 ChildProcessSecurityPolicyImpl
* policy
=
539 ChildProcessSecurityPolicyImpl::GetInstance();
541 // The URL could have been cobbled together from any highlighted text string,
542 // and can't be interpreted as a capability.
543 DropData
filtered_data(drop_data
);
544 GetProcess()->FilterURL(true, &filtered_data
.url
);
545 if (drop_data
.did_originate_from_renderer
) {
546 filtered_data
.filenames
.clear();
549 // The filenames vector, on the other hand, does represent a capability to
550 // access the given files.
551 storage::IsolatedContext::FileInfoSet files
;
552 for (std::vector
<ui::FileInfo
>::iterator
iter(
553 filtered_data
.filenames
.begin());
554 iter
!= filtered_data
.filenames
.end();
556 // A dragged file may wind up as the value of an input element, or it
557 // may be used as the target of a navigation instead. We don't know
558 // which will happen at this point, so generously grant both access
559 // and request permissions to the specific file to cover both cases.
560 // We do not give it the permission to request all file:// URLs.
562 // Make sure we have the same display_name as the one we register.
563 if (iter
->display_name
.empty()) {
565 files
.AddPath(iter
->path
, &name
);
566 iter
->display_name
= base::FilePath::FromUTF8Unsafe(name
);
568 files
.AddPathWithName(iter
->path
, iter
->display_name
.AsUTF8Unsafe());
571 policy
->GrantRequestSpecificFileURL(renderer_id
,
572 net::FilePathToFileURL(iter
->path
));
574 // If the renderer already has permission to read these paths, we don't need
575 // to re-grant them. This prevents problems with DnD for files in the CrOS
576 // file manager--the file manager already had read/write access to those
577 // directories, but dragging a file would cause the read/write access to be
578 // overwritten with read-only access, making them impossible to delete or
579 // rename until the renderer was killed.
580 if (!policy
->CanReadFile(renderer_id
, iter
->path
))
581 policy
->GrantReadFile(renderer_id
, iter
->path
);
584 storage::IsolatedContext
* isolated_context
=
585 storage::IsolatedContext::GetInstance();
586 DCHECK(isolated_context
);
587 std::string filesystem_id
= isolated_context
->RegisterDraggedFileSystem(
589 if (!filesystem_id
.empty()) {
590 // Grant the permission iff the ID is valid.
591 policy
->GrantReadFileSystem(renderer_id
, filesystem_id
);
593 filtered_data
.filesystem_id
= base::UTF8ToUTF16(filesystem_id
);
595 storage::FileSystemContext
* file_system_context
=
596 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
598 ->GetFileSystemContext();
599 for (size_t i
= 0; i
< filtered_data
.file_system_files
.size(); ++i
) {
600 storage::FileSystemURL file_system_url
=
601 file_system_context
->CrackURL(filtered_data
.file_system_files
[i
].url
);
603 std::string register_name
;
604 std::string filesystem_id
= isolated_context
->RegisterFileSystemForPath(
605 file_system_url
.type(), file_system_url
.filesystem_id(),
606 file_system_url
.path(), ®ister_name
);
607 policy
->GrantReadFileSystem(renderer_id
, filesystem_id
);
609 // Note: We are using the origin URL provided by the sender here. It may be
610 // different from the receiver's.
611 filtered_data
.file_system_files
[i
].url
=
612 GURL(storage::GetIsolatedFileSystemRootURIString(
613 file_system_url
.origin(), filesystem_id
, std::string())
614 .append(register_name
));
617 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data
, client_pt
,
618 screen_pt
, operations_allowed
,
622 void RenderViewHostImpl::DragTargetDragOver(
623 const gfx::Point
& client_pt
,
624 const gfx::Point
& screen_pt
,
625 WebDragOperationsMask operations_allowed
,
627 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt
, screen_pt
,
628 operations_allowed
, key_modifiers
));
631 void RenderViewHostImpl::DragTargetDragLeave() {
632 Send(new DragMsg_TargetDragLeave(GetRoutingID()));
635 void RenderViewHostImpl::DragTargetDrop(
636 const gfx::Point
& client_pt
,
637 const gfx::Point
& screen_pt
,
639 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt
, screen_pt
,
643 void RenderViewHostImpl::DragSourceEndedAt(
644 int client_x
, int client_y
, int screen_x
, int screen_y
,
645 WebDragOperation operation
) {
646 Send(new DragMsg_SourceEnded(GetRoutingID(),
647 gfx::Point(client_x
, client_y
),
648 gfx::Point(screen_x
, screen_y
),
652 void RenderViewHostImpl::DragSourceSystemDragEnded() {
653 Send(new DragMsg_SourceSystemDragEnded(GetRoutingID()));
656 RenderFrameHost
* RenderViewHostImpl::GetMainFrame() {
657 return RenderFrameHost::FromID(GetProcess()->GetID(), main_frame_routing_id_
);
660 void RenderViewHostImpl::AllowBindings(int bindings_flags
) {
661 // Never grant any bindings to browser plugin guests.
662 if (GetProcess()->IsIsolatedGuest()) {
663 NOTREACHED() << "Never grant bindings to a guest process.";
667 // Ensure we aren't granting WebUI bindings to a process that has already
668 // been used for non-privileged views.
669 if (bindings_flags
& BINDINGS_POLICY_WEB_UI
&&
670 GetProcess()->HasConnection() &&
671 !ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
672 GetProcess()->GetID())) {
673 // This process has no bindings yet. Make sure it does not have more
674 // than this single active view.
675 RenderProcessHostImpl
* process
=
676 static_cast<RenderProcessHostImpl
*>(GetProcess());
677 // --single-process only has one renderer.
678 if (process
->GetActiveViewCount() > 1 &&
679 !base::CommandLine::ForCurrentProcess()->HasSwitch(
680 switches::kSingleProcess
))
684 if (bindings_flags
& BINDINGS_POLICY_WEB_UI
) {
685 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings(
686 GetProcess()->GetID());
689 enabled_bindings_
|= bindings_flags
;
690 if (renderer_initialized_
)
691 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_
));
694 int RenderViewHostImpl::GetEnabledBindings() const {
695 return enabled_bindings_
;
698 void RenderViewHostImpl::SetWebUIProperty(const std::string
& name
,
699 const std::string
& value
) {
700 // This is a sanity check before telling the renderer to enable the property.
701 // It could lie and send the corresponding IPC messages anyway, but we will
702 // not act on them if enabled_bindings_ doesn't agree. If we get here without
703 // WebUI bindings, kill the renderer process.
704 if (enabled_bindings_
& BINDINGS_POLICY_WEB_UI
) {
705 Send(new ViewMsg_SetWebUIProperty(GetRoutingID(), name
, value
));
708 base::UserMetricsAction("BindingsMismatchTerminate_RVH_WebUI"));
710 GetProcess()->GetHandle(), content::RESULT_CODE_KILLED
, false);
714 void RenderViewHostImpl::GotFocus() {
715 RenderWidgetHostImpl::GotFocus(); // Notifies the renderer it got focus.
717 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
722 void RenderViewHostImpl::LostCapture() {
723 RenderWidgetHostImpl::LostCapture();
724 delegate_
->LostCapture();
727 void RenderViewHostImpl::LostMouseLock() {
728 RenderWidgetHostImpl::LostMouseLock();
729 delegate_
->LostMouseLock();
732 void RenderViewHostImpl::SetInitialFocus(bool reverse
) {
733 Send(new ViewMsg_SetInitialFocus(GetRoutingID(), reverse
));
736 void RenderViewHostImpl::FilesSelectedInChooser(
737 const std::vector
<content::FileChooserFileInfo
>& files
,
738 FileChooserParams::Mode permissions
) {
739 storage::FileSystemContext
* const file_system_context
=
740 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
742 ->GetFileSystemContext();
743 // Grant the security access requested to the given files.
744 for (size_t i
= 0; i
< files
.size(); ++i
) {
745 const content::FileChooserFileInfo
& file
= files
[i
];
746 if (permissions
== FileChooserParams::Save
) {
747 ChildProcessSecurityPolicyImpl::GetInstance()->GrantCreateReadWriteFile(
748 GetProcess()->GetID(), file
.file_path
);
750 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
751 GetProcess()->GetID(), file
.file_path
);
753 if (file
.file_system_url
.is_valid()) {
754 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFileSystem(
755 GetProcess()->GetID(),
756 file_system_context
->CrackURL(file
.file_system_url
)
757 .mount_filesystem_id());
760 Send(new ViewMsg_RunFileChooserResponse(GetRoutingID(), files
));
763 void RenderViewHostImpl::DirectoryEnumerationFinished(
765 const std::vector
<base::FilePath
>& files
) {
766 // Grant the security access requested to the given files.
767 for (std::vector
<base::FilePath
>::const_iterator file
= files
.begin();
768 file
!= files
.end(); ++file
) {
769 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
770 GetProcess()->GetID(), *file
);
772 Send(new ViewMsg_EnumerateDirectoryResponse(GetRoutingID(),
777 void RenderViewHostImpl::SetIsLoading(bool is_loading
) {
778 if (ResourceDispatcherHostImpl::Get()) {
779 BrowserThread::PostTask(
782 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading
,
783 base::Unretained(ResourceDispatcherHostImpl::Get()),
784 GetProcess()->GetID(),
788 RenderWidgetHostImpl::SetIsLoading(is_loading
);
791 void RenderViewHostImpl::LoadStateChanged(
793 const net::LoadStateWithParam
& load_state
,
794 uint64 upload_position
,
795 uint64 upload_size
) {
796 delegate_
->LoadStateChanged(url
, load_state
, upload_position
, upload_size
);
799 bool RenderViewHostImpl::SuddenTerminationAllowed() const {
800 return sudden_termination_allowed_
||
801 GetProcess()->SuddenTerminationAllowed();
804 ///////////////////////////////////////////////////////////////////////////////
805 // RenderViewHostImpl, IPC message handlers:
807 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message
& msg
) {
808 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg
, this))
811 // Filter out most IPC messages if this renderer is swapped out.
812 // We still want to handle certain ACKs to keep our state consistent.
813 if (is_swapped_out_
) {
814 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg
)) {
815 // If this is a synchronous message and we decided not to handle it,
816 // we must send an error reply, or else the renderer will be stuck
817 // and won't respond to future requests.
819 IPC::Message
* reply
= IPC::SyncMessage::GenerateReply(&msg
);
820 reply
->set_reply_error();
823 // Don't continue looking for someone to handle it.
828 if (delegate_
->OnMessageReceived(this, msg
))
832 IPC_BEGIN_MESSAGE_MAP(RenderViewHostImpl
, msg
)
833 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView
, OnShowView
)
834 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget
, OnShowWidget
)
835 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowFullscreenWidget
,
836 OnShowFullscreenWidget
)
837 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunModal
, OnRunModal
)
838 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady
, OnRenderViewReady
)
839 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderProcessGone
, OnRenderProcessGone
)
840 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState
, OnUpdateState
)
841 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL
, OnUpdateTargetURL
)
842 IPC_MESSAGE_HANDLER(ViewHostMsg_Close
, OnClose
)
843 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove
, OnRequestMove
)
844 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame
,
845 OnDocumentAvailableInMainFrame
)
846 IPC_MESSAGE_HANDLER(ViewHostMsg_ToggleFullscreen
, OnToggleFullscreen
)
847 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange
,
848 OnDidContentsPreferredSizeChange
)
849 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent
,
851 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteMessageEvent
, OnRouteMessageEvent
)
852 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging
, OnStartDragging
)
853 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor
, OnUpdateDragCursor
)
854 IPC_MESSAGE_HANDLER(DragHostMsg_TargetDrop_ACK
, OnTargetDropACK
)
855 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus
, OnTakeFocus
)
856 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged
, OnFocusedNodeChanged
)
857 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK
, OnClosePageACK
)
858 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL
, OnDidZoomURL
)
859 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser
, OnRunFileChooser
)
860 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeTouched
, OnFocusedNodeTouched
)
861 // Have the super handle all other messages.
862 IPC_MESSAGE_UNHANDLED(
863 handled
= RenderWidgetHostImpl::OnMessageReceived(msg
))
864 IPC_END_MESSAGE_MAP()
869 void RenderViewHostImpl::Init() {
870 RenderWidgetHostImpl::Init();
873 void RenderViewHostImpl::Shutdown() {
874 // If we are being run modally (see RunModal), then we need to cleanup.
875 if (run_modal_reply_msg_
) {
876 Send(run_modal_reply_msg_
);
877 run_modal_reply_msg_
= NULL
;
878 RenderViewHostImpl
* opener
=
879 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_
);
881 opener
->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
882 hung_renderer_delay_ms_
));
883 // Balance out the decrement when we got created.
884 opener
->increment_in_flight_event_count();
886 run_modal_opener_id_
= MSG_ROUTING_NONE
;
889 // We can't release the SessionStorageNamespace until our peer
890 // in the renderer has wound down.
891 if (GetProcess()->HasConnection()) {
892 RenderProcessHostImpl::ReleaseOnCloseACK(
894 delegate_
->GetSessionStorageNamespaceMap(),
898 RenderWidgetHostImpl::Shutdown();
901 void RenderViewHostImpl::WasHidden() {
902 if (ResourceDispatcherHostImpl::Get()) {
903 BrowserThread::PostTask(
904 BrowserThread::IO
, FROM_HERE
,
905 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostWasHidden
,
906 base::Unretained(ResourceDispatcherHostImpl::Get()),
907 GetProcess()->GetID(), GetRoutingID()));
910 RenderWidgetHostImpl::WasHidden();
913 void RenderViewHostImpl::WasShown(const ui::LatencyInfo
& latency_info
) {
914 if (ResourceDispatcherHostImpl::Get()) {
915 BrowserThread::PostTask(
916 BrowserThread::IO
, FROM_HERE
,
917 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostWasShown
,
918 base::Unretained(ResourceDispatcherHostImpl::Get()),
919 GetProcess()->GetID(), GetRoutingID()));
922 RenderWidgetHostImpl::WasShown(latency_info
);
925 bool RenderViewHostImpl::IsRenderView() const {
929 void RenderViewHostImpl::CreateNewWindow(
931 int main_frame_route_id
,
932 const ViewHostMsg_CreateWindow_Params
& params
,
933 SessionStorageNamespace
* session_storage_namespace
) {
934 ViewHostMsg_CreateWindow_Params
validated_params(params
);
935 GetProcess()->FilterURL(false, &validated_params
.target_url
);
936 GetProcess()->FilterURL(false, &validated_params
.opener_url
);
937 GetProcess()->FilterURL(true, &validated_params
.opener_security_origin
);
939 delegate_
->CreateNewWindow(
940 GetProcess()->GetID(), route_id
, main_frame_route_id
, validated_params
,
941 session_storage_namespace
);
944 void RenderViewHostImpl::CreateNewWidget(int route_id
,
945 blink::WebPopupType popup_type
) {
946 delegate_
->CreateNewWidget(GetProcess()->GetID(), route_id
, popup_type
);
949 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id
) {
950 delegate_
->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id
);
953 void RenderViewHostImpl::OnShowView(int route_id
,
954 WindowOpenDisposition disposition
,
955 const gfx::Rect
& initial_pos
,
958 delegate_
->ShowCreatedWindow(
959 route_id
, disposition
, initial_pos
, user_gesture
);
961 Send(new ViewMsg_Move_ACK(route_id
));
964 void RenderViewHostImpl::OnShowWidget(int route_id
,
965 const gfx::Rect
& initial_pos
) {
967 delegate_
->ShowCreatedWidget(route_id
, initial_pos
);
968 Send(new ViewMsg_Move_ACK(route_id
));
971 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id
) {
973 delegate_
->ShowCreatedFullscreenWidget(route_id
);
974 Send(new ViewMsg_Move_ACK(route_id
));
977 void RenderViewHostImpl::OnRunModal(int opener_id
, IPC::Message
* reply_msg
) {
978 DCHECK(!run_modal_reply_msg_
);
979 run_modal_reply_msg_
= reply_msg
;
980 run_modal_opener_id_
= opener_id
;
982 RecordAction(base::UserMetricsAction("ShowModalDialog"));
984 RenderViewHostImpl
* opener
=
985 RenderViewHostImpl::FromID(GetProcess()->GetID(), run_modal_opener_id_
);
987 opener
->StopHangMonitorTimeout();
988 // The ack for the mouse down won't come until the dialog closes, so fake it
989 // so that we don't get a timeout.
990 opener
->decrement_in_flight_event_count();
993 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in
994 // an app-modal fashion.
997 void RenderViewHostImpl::OnRenderViewReady() {
998 render_view_termination_status_
= base::TERMINATION_STATUS_STILL_RUNNING
;
1001 delegate_
->RenderViewReady(this);
1004 void RenderViewHostImpl::OnRenderProcessGone(int status
, int exit_code
) {
1005 // Keep the termination status so we can get at it later when we
1006 // need to know why it died.
1007 render_view_termination_status_
=
1008 static_cast<base::TerminationStatus
>(status
);
1010 // Reset frame tree state associated with this process. This must happen
1011 // before RenderViewTerminated because observers expect the subframes of any
1012 // affected frames to be cleared first.
1013 delegate_
->GetFrameTree()->RenderProcessGone(this);
1015 // Our base class RenderWidgetHost needs to reset some stuff.
1016 RendererExited(render_view_termination_status_
, exit_code
);
1018 delegate_
->RenderViewTerminated(this,
1019 static_cast<base::TerminationStatus
>(status
),
1023 void RenderViewHostImpl::OnUpdateState(int32 page_id
, const PageState
& state
) {
1024 // Without this check, the renderer can trick the browser into using
1025 // filenames it can't access in a future session restore.
1026 if (!CanAccessFilesOfPageState(state
)) {
1027 GetProcess()->ReceivedBadMessage();
1031 delegate_
->UpdateState(this, page_id
, state
);
1034 void RenderViewHostImpl::OnUpdateTargetURL(const GURL
& url
) {
1036 delegate_
->UpdateTargetURL(url
);
1038 // Send a notification back to the renderer that we are ready to
1039 // receive more target urls.
1040 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID()));
1043 void RenderViewHostImpl::OnClose() {
1044 // If the renderer is telling us to close, it has already run the unload
1045 // events, and we can take the fast path.
1046 ClosePageIgnoringUnloadEvents();
1049 void RenderViewHostImpl::OnRequestMove(const gfx::Rect
& pos
) {
1051 delegate_
->RequestMove(pos
);
1052 Send(new ViewMsg_Move_ACK(GetRoutingID()));
1055 void RenderViewHostImpl::OnDocumentAvailableInMainFrame(
1056 bool uses_temporary_zoom_level
) {
1057 delegate_
->DocumentAvailableInMainFrame(this);
1059 if (!uses_temporary_zoom_level
)
1062 HostZoomMapImpl
* host_zoom_map
=
1063 static_cast<HostZoomMapImpl
*>(HostZoomMap::GetDefaultForBrowserContext(
1064 GetProcess()->GetBrowserContext()));
1065 host_zoom_map
->SetTemporaryZoomLevel(GetProcess()->GetID(),
1067 host_zoom_map
->GetDefaultZoomLevel());
1070 void RenderViewHostImpl::OnToggleFullscreen(bool enter_fullscreen
) {
1071 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
1072 delegate_
->ToggleFullscreenMode(enter_fullscreen
);
1073 // We need to notify the contents that its fullscreen state has changed. This
1074 // is done as part of the resize message.
1078 void RenderViewHostImpl::OnDidContentsPreferredSizeChange(
1079 const gfx::Size
& new_size
) {
1080 delegate_
->UpdatePreferredSize(new_size
);
1083 void RenderViewHostImpl::OnRenderAutoResized(const gfx::Size
& new_size
) {
1084 delegate_
->ResizeDueToAutoResize(new_size
);
1087 void RenderViewHostImpl::OnRouteCloseEvent() {
1088 // Have the delegate route this to the active RenderViewHost.
1089 delegate_
->RouteCloseEvent(this);
1092 void RenderViewHostImpl::OnRouteMessageEvent(
1093 const ViewMsg_PostMessage_Params
& params
) {
1094 // Give to the delegate to route to the active RenderViewHost.
1095 delegate_
->RouteMessageEvent(this, params
);
1098 void RenderViewHostImpl::OnStartDragging(
1099 const DropData
& drop_data
,
1100 WebDragOperationsMask drag_operations_mask
,
1101 const SkBitmap
& bitmap
,
1102 const gfx::Vector2d
& bitmap_offset_in_dip
,
1103 const DragEventSourceInfo
& event_info
) {
1104 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1108 DropData
filtered_data(drop_data
);
1109 RenderProcessHost
* process
= GetProcess();
1110 ChildProcessSecurityPolicyImpl
* policy
=
1111 ChildProcessSecurityPolicyImpl::GetInstance();
1113 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar.
1114 if (!filtered_data
.url
.SchemeIs(url::kJavaScriptScheme
))
1115 process
->FilterURL(true, &filtered_data
.url
);
1116 process
->FilterURL(false, &filtered_data
.html_base_url
);
1117 // Filter out any paths that the renderer didn't have access to. This prevents
1118 // the following attack on a malicious renderer:
1119 // 1. StartDragging IPC sent with renderer-specified filesystem paths that it
1120 // doesn't have read permissions for.
1121 // 2. We initiate a native DnD operation.
1122 // 3. DnD operation immediately ends since mouse is not held down. DnD events
1123 // still fire though, which causes read permissions to be granted to the
1124 // renderer for any file paths in the drop.
1125 filtered_data
.filenames
.clear();
1126 for (std::vector
<ui::FileInfo
>::const_iterator it
=
1127 drop_data
.filenames
.begin();
1128 it
!= drop_data
.filenames
.end();
1130 if (policy
->CanReadFile(GetProcess()->GetID(), it
->path
))
1131 filtered_data
.filenames
.push_back(*it
);
1134 storage::FileSystemContext
* file_system_context
=
1135 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
1137 ->GetFileSystemContext();
1138 filtered_data
.file_system_files
.clear();
1139 for (size_t i
= 0; i
< drop_data
.file_system_files
.size(); ++i
) {
1140 storage::FileSystemURL file_system_url
=
1141 file_system_context
->CrackURL(drop_data
.file_system_files
[i
].url
);
1142 if (policy
->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url
))
1143 filtered_data
.file_system_files
.push_back(drop_data
.file_system_files
[i
]);
1146 float scale
= GetScaleFactorForView(GetView());
1147 gfx::ImageSkia
image(gfx::ImageSkiaRep(bitmap
, scale
));
1148 view
->StartDragging(filtered_data
, drag_operations_mask
, image
,
1149 bitmap_offset_in_dip
, event_info
);
1152 void RenderViewHostImpl::OnUpdateDragCursor(WebDragOperation current_op
) {
1153 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1155 view
->UpdateDragCursor(current_op
);
1158 void RenderViewHostImpl::OnTargetDropACK() {
1159 NotificationService::current()->Notify(
1160 NOTIFICATION_RENDER_VIEW_HOST_DID_RECEIVE_DRAG_TARGET_DROP_ACK
,
1161 Source
<RenderViewHost
>(this),
1162 NotificationService::NoDetails());
1165 void RenderViewHostImpl::OnTakeFocus(bool reverse
) {
1166 RenderViewHostDelegateView
* view
= delegate_
->GetDelegateView();
1168 view
->TakeFocus(reverse
);
1171 void RenderViewHostImpl::OnFocusedNodeChanged(bool is_editable_node
) {
1172 is_focused_element_editable_
= is_editable_node
;
1174 view_
->FocusedNodeChanged(is_editable_node
);
1176 if (!is_editable_node
&& virtual_keyboard_requested_
) {
1177 virtual_keyboard_requested_
= false;
1178 BrowserThread::PostDelayedTask(
1179 BrowserThread::UI
, FROM_HERE
,
1180 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask
)),
1181 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs
));
1184 NotificationService::current()->Notify(
1185 NOTIFICATION_FOCUS_CHANGED_IN_PAGE
,
1186 Source
<RenderViewHost
>(this),
1187 Details
<const bool>(&is_editable_node
));
1190 void RenderViewHostImpl::OnUserGesture() {
1191 delegate_
->OnUserGesture();
1194 void RenderViewHostImpl::OnClosePageACK() {
1195 decrement_in_flight_event_count();
1196 ClosePageIgnoringUnloadEvents();
1199 void RenderViewHostImpl::NotifyRendererUnresponsive() {
1200 delegate_
->RendererUnresponsive(this);
1203 void RenderViewHostImpl::NotifyRendererResponsive() {
1204 delegate_
->RendererResponsive(this);
1207 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture
,
1208 bool last_unlocked_by_target
) {
1209 delegate_
->RequestToLockMouse(user_gesture
, last_unlocked_by_target
);
1212 bool RenderViewHostImpl::IsFullscreen() const {
1213 return delegate_
->IsFullscreenForCurrentTab();
1216 void RenderViewHostImpl::OnFocus() {
1217 // Note: We allow focus and blur from swapped out RenderViewHosts, even when
1218 // the active RenderViewHost is in a different BrowsingInstance (e.g., WebUI).
1219 delegate_
->Activate();
1222 void RenderViewHostImpl::OnBlur() {
1223 delegate_
->Deactivate();
1226 gfx::Rect
RenderViewHostImpl::GetRootWindowResizerRect() const {
1227 return delegate_
->GetRootWindowResizerRect();
1230 void RenderViewHostImpl::ForwardMouseEvent(
1231 const blink::WebMouseEvent
& mouse_event
) {
1233 // We make a copy of the mouse event because
1234 // RenderWidgetHost::ForwardMouseEvent will delete |mouse_event|.
1235 blink::WebMouseEvent
event_copy(mouse_event
);
1236 RenderWidgetHostImpl::ForwardMouseEvent(event_copy
);
1238 switch (event_copy
.type
) {
1239 case WebInputEvent::MouseMove
:
1240 delegate_
->HandleMouseMove();
1242 case WebInputEvent::MouseLeave
:
1243 delegate_
->HandleMouseLeave();
1245 case WebInputEvent::MouseDown
:
1246 delegate_
->HandleMouseDown();
1248 case WebInputEvent::MouseWheel
:
1249 if (ignore_input_events())
1250 delegate_
->OnIgnoredUIEvent();
1252 case WebInputEvent::MouseUp
:
1253 delegate_
->HandleMouseUp();
1255 // For now, we don't care about the rest.
1260 void RenderViewHostImpl::OnPointerEventActivate() {
1261 delegate_
->HandlePointerActivate();
1264 void RenderViewHostImpl::ForwardKeyboardEvent(
1265 const NativeWebKeyboardEvent
& key_event
) {
1266 if (ignore_input_events()) {
1267 if (key_event
.type
== WebInputEvent::RawKeyDown
)
1268 delegate_
->OnIgnoredUIEvent();
1271 RenderWidgetHostImpl::ForwardKeyboardEvent(key_event
);
1274 void RenderViewHostImpl::OnTextSurroundingSelectionResponse(
1275 const base::string16
& content
,
1276 size_t start_offset
,
1277 size_t end_offset
) {
1280 view_
->OnTextSurroundingSelectionResponse(content
, start_offset
, end_offset
);
1283 void RenderViewHostImpl::ExitFullscreen() {
1284 RejectMouseLockOrUnlockIfNecessary();
1285 // Notify delegate_ and renderer of fullscreen state change.
1286 OnToggleFullscreen(false);
1289 WebPreferences
RenderViewHostImpl::GetWebkitPreferences() {
1290 if (!web_preferences_
.get()) {
1291 OnWebkitPreferencesChanged();
1293 return *web_preferences_
;
1296 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences
& prefs
) {
1297 web_preferences_
.reset(new WebPreferences(prefs
));
1298 Send(new ViewMsg_UpdateWebPreferences(GetRoutingID(), prefs
));
1301 void RenderViewHostImpl::OnWebkitPreferencesChanged() {
1302 // This is defensive code to avoid infinite loops due to code run inside
1303 // UpdateWebkitPreferences() accidentally updating more preferences and thus
1304 // calling back into this code. See crbug.com/398751 for one past example.
1305 if (updating_web_preferences_
)
1307 updating_web_preferences_
= true;
1308 UpdateWebkitPreferences(delegate_
->ComputeWebkitPrefs());
1309 updating_web_preferences_
= false;
1312 void RenderViewHostImpl::GetAudioOutputControllers(
1313 const GetAudioOutputControllersCallback
& callback
) const {
1314 scoped_refptr
<AudioRendererHost
> audio_host
=
1315 static_cast<RenderProcessHostImpl
*>(GetProcess())->audio_renderer_host();
1316 audio_host
->GetOutputControllers(GetRoutingID(), callback
);
1319 void RenderViewHostImpl::ClearFocusedElement() {
1320 is_focused_element_editable_
= false;
1321 Send(new ViewMsg_ClearFocusedElement(GetRoutingID()));
1324 bool RenderViewHostImpl::IsFocusedElementEditable() {
1325 return is_focused_element_editable_
;
1328 void RenderViewHostImpl::Zoom(PageZoom zoom
) {
1329 Send(new ViewMsg_Zoom(GetRoutingID(), zoom
));
1332 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size
& size
) {
1333 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size
));
1336 void RenderViewHostImpl::EnablePreferredSizeMode() {
1337 Send(new ViewMsg_EnablePreferredSizeChangedMode(GetRoutingID()));
1340 void RenderViewHostImpl::EnableAutoResize(const gfx::Size
& min_size
,
1341 const gfx::Size
& max_size
) {
1342 SetShouldAutoResize(true);
1343 Send(new ViewMsg_EnableAutoResize(GetRoutingID(), min_size
, max_size
));
1346 void RenderViewHostImpl::DisableAutoResize(const gfx::Size
& new_size
) {
1347 SetShouldAutoResize(false);
1348 Send(new ViewMsg_DisableAutoResize(GetRoutingID(), new_size
));
1349 if (!new_size
.IsEmpty())
1350 GetView()->SetSize(new_size
);
1353 void RenderViewHostImpl::CopyImageAt(int x
, int y
) {
1354 Send(new ViewMsg_CopyImageAt(GetRoutingID(), x
, y
));
1357 void RenderViewHostImpl::SaveImageAt(int x
, int y
) {
1358 Send(new ViewMsg_SaveImageAt(GetRoutingID(), x
, y
));
1361 void RenderViewHostImpl::ExecuteMediaPlayerActionAtLocation(
1362 const gfx::Point
& location
, const blink::WebMediaPlayerAction
& action
) {
1363 Send(new ViewMsg_MediaPlayerActionAt(GetRoutingID(), location
, action
));
1366 void RenderViewHostImpl::ExecutePluginActionAtLocation(
1367 const gfx::Point
& location
, const blink::WebPluginAction
& action
) {
1368 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location
, action
));
1371 void RenderViewHostImpl::NotifyMoveOrResizeStarted() {
1372 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID()));
1375 void RenderViewHostImpl::OnDidZoomURL(double zoom_level
,
1377 HostZoomMapImpl
* host_zoom_map
=
1378 static_cast<HostZoomMapImpl
*>(HostZoomMap::GetDefaultForBrowserContext(
1379 GetProcess()->GetBrowserContext()));
1381 host_zoom_map
->SetZoomLevelForView(GetProcess()->GetID(),
1384 net::GetHostOrSpecFromURL(url
));
1387 void RenderViewHostImpl::OnRunFileChooser(const FileChooserParams
& params
) {
1388 delegate_
->RunFileChooser(this, params
);
1391 void RenderViewHostImpl::OnFocusedNodeTouched(bool editable
) {
1394 virtual_keyboard_requested_
= base::win::DisplayVirtualKeyboard();
1396 virtual_keyboard_requested_
= false;
1397 base::win::DismissVirtualKeyboard();
1402 bool RenderViewHostImpl::CanAccessFilesOfPageState(
1403 const PageState
& state
) const {
1404 ChildProcessSecurityPolicyImpl
* policy
=
1405 ChildProcessSecurityPolicyImpl::GetInstance();
1407 const std::vector
<base::FilePath
>& file_paths
= state
.GetReferencedFiles();
1408 for (std::vector
<base::FilePath
>::const_iterator file
= file_paths
.begin();
1409 file
!= file_paths
.end(); ++file
) {
1410 if (!policy
->CanReadFile(GetProcess()->GetID(), *file
))
1416 void RenderViewHostImpl::AttachToFrameTree() {
1417 FrameTree
* frame_tree
= delegate_
->GetFrameTree();
1419 frame_tree
->ResetForMainFrameSwap();
1422 void RenderViewHostImpl::SelectWordAroundCaret() {
1423 Send(new ViewMsg_SelectWordAroundCaret(GetRoutingID()));
1426 } // namespace content