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/renderer/render_view_impl.h"
10 #include "base/auto_reset.h"
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/command_line.h"
14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h"
16 #include "base/debug/trace_event.h"
17 #include "base/files/file_path.h"
18 #include "base/i18n/rtl.h"
19 #include "base/json/json_writer.h"
20 #include "base/lazy_instance.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/message_loop/message_loop_proxy.h"
23 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h"
25 #include "base/path_service.h"
26 #include "base/process/kill.h"
27 #include "base/process/process.h"
28 #include "base/strings/string_number_conversions.h"
29 #include "base/strings/string_piece.h"
30 #include "base/strings/string_split.h"
31 #include "base/strings/string_util.h"
32 #include "base/strings/sys_string_conversions.h"
33 #include "base/strings/utf_string_conversions.h"
34 #include "base/time/time.h"
35 #include "cc/base/switches.h"
36 #include "content/child/appcache/appcache_dispatcher.h"
37 #include "content/child/appcache/web_application_cache_host_impl.h"
38 #include "content/child/child_shared_bitmap_manager.h"
39 #include "content/child/child_thread.h"
40 #include "content/child/npapi/webplugin_delegate_impl.h"
41 #include "content/child/request_extra_data.h"
42 #include "content/child/webmessageportchannel_impl.h"
43 #include "content/common/database_messages.h"
44 #include "content/common/dom_storage/dom_storage_types.h"
45 #include "content/common/drag_messages.h"
46 #include "content/common/frame_messages.h"
47 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
48 #include "content/common/input_messages.h"
49 #include "content/common/pepper_messages.h"
50 #include "content/common/socket_stream_handle_data.h"
51 #include "content/common/ssl_status_serialization.h"
52 #include "content/common/view_messages.h"
53 #include "content/public/common/bindings_policy.h"
54 #include "content/public/common/content_client.h"
55 #include "content/public/common/content_constants.h"
56 #include "content/public/common/content_switches.h"
57 #include "content/public/common/drop_data.h"
58 #include "content/public/common/favicon_url.h"
59 #include "content/public/common/file_chooser_params.h"
60 #include "content/public/common/page_zoom.h"
61 #include "content/public/common/ssl_status.h"
62 #include "content/public/common/three_d_api_types.h"
63 #include "content/public/common/url_constants.h"
64 #include "content/public/common/url_utils.h"
65 #include "content/public/common/web_preferences.h"
66 #include "content/public/renderer/content_renderer_client.h"
67 #include "content/public/renderer/document_state.h"
68 #include "content/public/renderer/navigation_state.h"
69 #include "content/public/renderer/render_view_observer.h"
70 #include "content/public/renderer/render_view_visitor.h"
71 #include "content/renderer/accessibility/renderer_accessibility.h"
72 #include "content/renderer/accessibility/renderer_accessibility_complete.h"
73 #include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
74 #include "content/renderer/browser_plugin/browser_plugin.h"
75 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
76 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
77 #include "content/renderer/devtools/devtools_agent.h"
78 #include "content/renderer/disambiguation_popup_helper.h"
79 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
80 #include "content/renderer/drop_data_builder.h"
81 #include "content/renderer/gpu/render_widget_compositor.h"
82 #include "content/renderer/history_controller.h"
83 #include "content/renderer/history_serialization.h"
84 #include "content/renderer/idle_user_detector.h"
85 #include "content/renderer/ime_event_guard.h"
86 #include "content/renderer/input/input_handler_manager.h"
87 #include "content/renderer/internal_document_state_data.h"
88 #include "content/renderer/media/audio_device_factory.h"
89 #include "content/renderer/media/video_capture_impl_manager.h"
90 #include "content/renderer/memory_benchmarking_extension.h"
91 #include "content/renderer/mhtml_generator.h"
92 #include "content/renderer/net_info_helper.h"
93 #include "content/renderer/render_frame_impl.h"
94 #include "content/renderer/render_frame_proxy.h"
95 #include "content/renderer/render_process.h"
96 #include "content/renderer/render_thread_impl.h"
97 #include "content/renderer/render_view_impl_params.h"
98 #include "content/renderer/render_view_mouse_lock_dispatcher.h"
99 #include "content/renderer/render_widget_fullscreen_pepper.h"
100 #include "content/renderer/renderer_webapplicationcachehost_impl.h"
101 #include "content/renderer/resizing_mode_selector.h"
102 #include "content/renderer/savable_resources.h"
103 #include "content/renderer/skia_benchmarking_extension.h"
104 #include "content/renderer/speech_recognition_dispatcher.h"
105 #include "content/renderer/stats_collection_controller.h"
106 #include "content/renderer/stats_collection_observer.h"
107 #include "content/renderer/text_input_client_observer.h"
108 #include "content/renderer/v8_value_converter_impl.h"
109 #include "content/renderer/web_ui_extension.h"
110 #include "content/renderer/web_ui_extension_data.h"
111 #include "content/renderer/web_ui_mojo.h"
112 #include "content/renderer/websharedworker_proxy.h"
113 #include "media/audio/audio_output_device.h"
114 #include "media/base/filter_collection.h"
115 #include "media/base/media_switches.h"
116 #include "media/filters/audio_renderer_impl.h"
117 #include "media/filters/gpu_video_accelerator_factories.h"
118 #include "net/base/data_url.h"
119 #include "net/base/escape.h"
120 #include "net/base/net_errors.h"
121 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
122 #include "net/http/http_util.h"
123 #include "third_party/WebKit/public/platform/WebCString.h"
124 #include "third_party/WebKit/public/platform/WebConnectionType.h"
125 #include "third_party/WebKit/public/platform/WebDragData.h"
126 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
127 #include "third_party/WebKit/public/platform/WebImage.h"
128 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
129 #include "third_party/WebKit/public/platform/WebPoint.h"
130 #include "third_party/WebKit/public/platform/WebRect.h"
131 #include "third_party/WebKit/public/platform/WebSize.h"
132 #include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
133 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
134 #include "third_party/WebKit/public/platform/WebString.h"
135 #include "third_party/WebKit/public/platform/WebURL.h"
136 #include "third_party/WebKit/public/platform/WebURLError.h"
137 #include "third_party/WebKit/public/platform/WebURLRequest.h"
138 #include "third_party/WebKit/public/platform/WebURLResponse.h"
139 #include "third_party/WebKit/public/platform/WebVector.h"
140 #include "third_party/WebKit/public/web/WebAXObject.h"
141 #include "third_party/WebKit/public/web/WebColorName.h"
142 #include "third_party/WebKit/public/web/WebColorSuggestion.h"
143 #include "third_party/WebKit/public/web/WebDOMEvent.h"
144 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
145 #include "third_party/WebKit/public/web/WebDataSource.h"
146 #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
147 #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
148 #include "third_party/WebKit/public/web/WebDevToolsAgent.h"
149 #include "third_party/WebKit/public/web/WebDocument.h"
150 #include "third_party/WebKit/public/web/WebElement.h"
151 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
152 #include "third_party/WebKit/public/web/WebFindOptions.h"
153 #include "third_party/WebKit/public/web/WebFormControlElement.h"
154 #include "third_party/WebKit/public/web/WebFormElement.h"
155 #include "third_party/WebKit/public/web/WebFrame.h"
156 #include "third_party/WebKit/public/web/WebGlyphCache.h"
157 #include "third_party/WebKit/public/web/WebHistoryItem.h"
158 #include "third_party/WebKit/public/web/WebHitTestResult.h"
159 #include "third_party/WebKit/public/web/WebInputElement.h"
160 #include "third_party/WebKit/public/web/WebInputEvent.h"
161 #include "third_party/WebKit/public/web/WebKit.h"
162 #include "third_party/WebKit/public/web/WebLocalFrame.h"
163 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
164 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
165 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
166 #include "third_party/WebKit/public/web/WebNodeList.h"
167 #include "third_party/WebKit/public/web/WebPageSerializer.h"
168 #include "third_party/WebKit/public/web/WebPlugin.h"
169 #include "third_party/WebKit/public/web/WebPluginAction.h"
170 #include "third_party/WebKit/public/web/WebPluginContainer.h"
171 #include "third_party/WebKit/public/web/WebPluginDocument.h"
172 #include "third_party/WebKit/public/web/WebRange.h"
173 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
174 #include "third_party/WebKit/public/web/WebScriptSource.h"
175 #include "third_party/WebKit/public/web/WebSearchableFormData.h"
176 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
177 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
178 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
179 #include "third_party/WebKit/public/web/WebSettings.h"
180 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
181 #include "third_party/WebKit/public/web/WebView.h"
182 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
183 #include "third_party/WebKit/public/web/default/WebRenderTheme.h"
184 #include "third_party/icu/source/common/unicode/uchar.h"
185 #include "third_party/icu/source/common/unicode/uscript.h"
186 #include "ui/base/clipboard/clipboard.h"
187 #include "ui/base/ui_base_switches_util.h"
188 #include "ui/events/latency_info.h"
189 #include "ui/gfx/native_widget_types.h"
190 #include "ui/gfx/point.h"
191 #include "ui/gfx/rect.h"
192 #include "ui/gfx/rect_conversions.h"
193 #include "ui/gfx/size_conversions.h"
194 #include "ui/shell_dialogs/selected_file_info.h"
195 #include "v8/include/v8.h"
197 #if defined(OS_ANDROID)
198 #include <cpu-features.h>
200 #include "content/renderer/android/address_detector.h"
201 #include "content/renderer/android/content_detector.h"
202 #include "content/renderer/android/email_detector.h"
203 #include "content/renderer/android/phone_number_detector.h"
204 #include "net/android/network_library.h"
205 #include "skia/ext/platform_canvas.h"
206 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
207 #include "third_party/WebKit/public/platform/WebFloatRect.h"
208 #include "ui/gfx/rect_f.h"
210 #elif defined(OS_WIN)
211 // TODO(port): these files are currently Windows only because they concern:
213 #include "ui/native_theme/native_theme_win.h"
214 #elif defined(USE_X11)
215 #include "ui/native_theme/native_theme.h"
216 #elif defined(OS_MACOSX)
217 #include "skia/ext/skia_utils_mac.h"
220 #if defined(ENABLE_PLUGINS)
221 #include "content/renderer/npapi/webplugin_delegate_proxy.h"
222 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
223 #include "content/renderer/pepper/pepper_plugin_registry.h"
226 #if defined(ENABLE_WEBRTC)
227 #include "content/renderer/media/rtc_peer_connection_handler.h"
228 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
231 using blink::WebAXObject
;
232 using blink::WebApplicationCacheHost
;
233 using blink::WebApplicationCacheHostClient
;
234 using blink::WebCString
;
235 using blink::WebColor
;
236 using blink::WebColorName
;
237 using blink::WebConsoleMessage
;
238 using blink::WebData
;
239 using blink::WebDataSource
;
240 using blink::WebDocument
;
241 using blink::WebDOMEvent
;
242 using blink::WebDOMMessageEvent
;
243 using blink::WebDragData
;
244 using blink::WebDragOperation
;
245 using blink::WebDragOperationsMask
;
246 using blink::WebElement
;
247 using blink::WebFileChooserCompletion
;
248 using blink::WebFindOptions
;
249 using blink::WebFormControlElement
;
250 using blink::WebFormElement
;
251 using blink::WebFrame
;
252 using blink::WebGestureEvent
;
253 using blink::WebHistoryItem
;
254 using blink::WebHTTPBody
;
255 using blink::WebIconURL
;
256 using blink::WebImage
;
257 using blink::WebInputElement
;
258 using blink::WebInputEvent
;
259 using blink::WebLocalFrame
;
260 using blink::WebMediaPlayerAction
;
261 using blink::WebMouseEvent
;
262 using blink::WebNavigationPolicy
;
263 using blink::WebNavigationType
;
264 using blink::WebNode
;
265 using blink::WebPageSerializer
;
266 using blink::WebPageSerializerClient
;
267 using blink::WebPeerConnection00Handler
;
268 using blink::WebPeerConnection00HandlerClient
;
269 using blink::WebPeerConnectionHandler
;
270 using blink::WebPeerConnectionHandlerClient
;
271 using blink::WebPluginAction
;
272 using blink::WebPluginContainer
;
273 using blink::WebPluginDocument
;
274 using blink::WebPoint
;
275 using blink::WebRange
;
276 using blink::WebRect
;
277 using blink::WebReferrerPolicy
;
278 using blink::WebScriptSource
;
279 using blink::WebSearchableFormData
;
280 using blink::WebSecurityOrigin
;
281 using blink::WebSecurityPolicy
;
282 using blink::WebSerializedScriptValue
;
283 using blink::WebSettings
;
284 using blink::WebSize
;
285 using blink::WebSocketStreamHandle
;
286 using blink::WebStorageNamespace
;
287 using blink::WebStorageQuotaCallbacks
;
288 using blink::WebStorageQuotaError
;
289 using blink::WebStorageQuotaType
;
290 using blink::WebString
;
291 using blink::WebTextAffinity
;
292 using blink::WebTextDirection
;
293 using blink::WebTouchEvent
;
295 using blink::WebURLError
;
296 using blink::WebURLRequest
;
297 using blink::WebURLResponse
;
298 using blink::WebUserGestureIndicator
;
299 using blink::WebVector
;
300 using blink::WebView
;
301 using blink::WebWidget
;
302 using blink::WebWindowFeatures
;
303 using blink::WebNetworkStateNotifier
;
304 using blink::WebRuntimeFeatures
;
306 using base::TimeDelta
;
308 #if defined(OS_ANDROID)
309 using blink::WebContentDetectionResult
;
310 using blink::WebFloatPoint
;
311 using blink::WebFloatRect
;
312 using blink::WebHitTestResult
;
317 //-----------------------------------------------------------------------------
319 typedef std::map
<blink::WebView
*, RenderViewImpl
*> ViewMap
;
320 static base::LazyInstance
<ViewMap
> g_view_map
= LAZY_INSTANCE_INITIALIZER
;
321 typedef std::map
<int32
, RenderViewImpl
*> RoutingIDViewMap
;
322 static base::LazyInstance
<RoutingIDViewMap
> g_routing_id_view_map
=
323 LAZY_INSTANCE_INITIALIZER
;
325 // Time, in seconds, we delay before sending content state changes (such as form
326 // state and scroll position) to the browser. We delay sending changes to avoid
327 // spamming the browser.
328 // To avoid having tab/session restore require sending a message to get the
329 // current content state during tab closing we use a shorter timeout for the
330 // foreground renderer. This means there is a small window of time from which
331 // content state is modified and not sent to session restore, but this is
332 // better than having to wake up all renderers during shutdown.
333 const int kDelaySecondsForContentStateSyncHidden
= 5;
334 const int kDelaySecondsForContentStateSync
= 1;
336 #if defined(OS_ANDROID)
337 // Delay between tapping in content and launching the associated android intent.
338 // Used to allow users see what has been recognized as content.
339 const size_t kContentIntentDelayMilliseconds
= 700;
342 static RenderViewImpl
* (*g_create_render_view_impl
)(RenderViewImplParams
*) =
346 bool RenderViewImpl::IsReload(const FrameMsg_Navigate_Params
& params
) {
348 params
.navigation_type
== FrameMsg_Navigate_Type::RELOAD
||
349 params
.navigation_type
== FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE
||
350 params
.navigation_type
==
351 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL
;
355 Referrer
RenderViewImpl::GetReferrerFromRequest(
357 const WebURLRequest
& request
) {
358 return Referrer(GURL(request
.httpHeaderField(WebString::fromUTF8("Referer"))),
359 request
.referrerPolicy());
363 WindowOpenDisposition
RenderViewImpl::NavigationPolicyToDisposition(
364 WebNavigationPolicy policy
) {
366 case blink::WebNavigationPolicyIgnore
:
367 return IGNORE_ACTION
;
368 case blink::WebNavigationPolicyDownload
:
370 case blink::WebNavigationPolicyCurrentTab
:
372 case blink::WebNavigationPolicyNewBackgroundTab
:
373 return NEW_BACKGROUND_TAB
;
374 case blink::WebNavigationPolicyNewForegroundTab
:
375 return NEW_FOREGROUND_TAB
;
376 case blink::WebNavigationPolicyNewWindow
:
378 case blink::WebNavigationPolicyNewPopup
:
381 NOTREACHED() << "Unexpected WebNavigationPolicy";
382 return IGNORE_ACTION
;
386 // Returns true if the device scale is high enough that losing subpixel
387 // antialiasing won't have a noticeable effect on text quality.
388 static bool DeviceScaleEnsuresTextQuality(float device_scale_factor
) {
389 #if defined(OS_ANDROID)
390 // On Android, we never have subpixel antialiasing.
393 return device_scale_factor
> 1.5f
;
398 static bool PreferCompositingToLCDText(float device_scale_factor
) {
399 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
400 if (command_line
.HasSwitch(switches::kDisablePreferCompositingToLCDText
))
402 if (command_line
.HasSwitch(switches::kEnablePreferCompositingToLCDText
))
404 if (RenderThreadImpl::current() &&
405 !RenderThreadImpl::current()->is_lcd_text_enabled())
407 return DeviceScaleEnsuresTextQuality(device_scale_factor
);
410 static bool ShouldUseTransitionCompositing(float device_scale_factor
) {
411 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
413 if (command_line
.HasSwitch(switches::kDisableCompositingForTransition
))
416 if (command_line
.HasSwitch(switches::kEnableCompositingForTransition
))
419 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
420 // of excessive layer promotion caused by overlap has been addressed.
421 // http://crbug.com/178119.
425 static FaviconURL::IconType
ToFaviconType(blink::WebIconURL::Type type
) {
427 case blink::WebIconURL::TypeFavicon
:
428 return FaviconURL::FAVICON
;
429 case blink::WebIconURL::TypeTouch
:
430 return FaviconURL::TOUCH_ICON
;
431 case blink::WebIconURL::TypeTouchPrecomposed
:
432 return FaviconURL::TOUCH_PRECOMPOSED_ICON
;
433 case blink::WebIconURL::TypeInvalid
:
434 return FaviconURL::INVALID_ICON
;
436 return FaviconURL::INVALID_ICON
;
439 static void ConvertToFaviconSizes(
440 const blink::WebVector
<blink::WebSize
>& web_sizes
,
441 std::vector
<gfx::Size
>* sizes
) {
442 DCHECK(sizes
->empty());
443 sizes
->reserve(web_sizes
.size());
444 for (size_t i
= 0; i
< web_sizes
.size(); ++i
)
445 sizes
->push_back(gfx::Size(web_sizes
[i
]));
448 ///////////////////////////////////////////////////////////////////////////////
450 struct RenderViewImpl::PendingFileChooser
{
451 PendingFileChooser(const FileChooserParams
& p
, WebFileChooserCompletion
* c
)
455 FileChooserParams params
;
456 WebFileChooserCompletion
* completion
; // MAY BE NULL to skip callback.
461 class WebWidgetLockTarget
: public MouseLockDispatcher::LockTarget
{
463 explicit WebWidgetLockTarget(blink::WebWidget
* webwidget
)
464 : webwidget_(webwidget
) {}
466 virtual void OnLockMouseACK(bool succeeded
) OVERRIDE
{
468 webwidget_
->didAcquirePointerLock();
470 webwidget_
->didNotAcquirePointerLock();
473 virtual void OnMouseLockLost() OVERRIDE
{
474 webwidget_
->didLosePointerLock();
477 virtual bool HandleMouseLockedInputEvent(
478 const blink::WebMouseEvent
&event
) OVERRIDE
{
479 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
484 blink::WebWidget
* webwidget_
;
487 bool TouchEnabled() {
488 // Based on the definition of chrome::kEnableTouchIcon.
489 #if defined(OS_ANDROID)
496 WebDragData
DropDataToWebDragData(const DropData
& drop_data
) {
497 std::vector
<WebDragData::Item
> item_list
;
499 // These fields are currently unused when dragging into WebKit.
500 DCHECK(drop_data
.download_metadata
.empty());
501 DCHECK(drop_data
.file_contents
.empty());
502 DCHECK(drop_data
.file_description_filename
.empty());
504 if (!drop_data
.text
.is_null()) {
505 WebDragData::Item item
;
506 item
.storageType
= WebDragData::Item::StorageTypeString
;
507 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeText
);
508 item
.stringData
= drop_data
.text
.string();
509 item_list
.push_back(item
);
512 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
513 // meaningful to write an empty URL to the clipboard?
514 if (!drop_data
.url
.is_empty()) {
515 WebDragData::Item item
;
516 item
.storageType
= WebDragData::Item::StorageTypeString
;
517 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList
);
518 item
.stringData
= WebString::fromUTF8(drop_data
.url
.spec());
519 item
.title
= drop_data
.url_title
;
520 item_list
.push_back(item
);
523 if (!drop_data
.html
.is_null()) {
524 WebDragData::Item item
;
525 item
.storageType
= WebDragData::Item::StorageTypeString
;
526 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML
);
527 item
.stringData
= drop_data
.html
.string();
528 item
.baseURL
= drop_data
.html_base_url
;
529 item_list
.push_back(item
);
532 for (std::vector
<ui::FileInfo
>::const_iterator it
=
533 drop_data
.filenames
.begin();
534 it
!= drop_data
.filenames
.end();
536 WebDragData::Item item
;
537 item
.storageType
= WebDragData::Item::StorageTypeFilename
;
538 item
.filenameData
= it
->path
.AsUTF16Unsafe();
539 item
.displayNameData
= it
->display_name
.AsUTF16Unsafe();
540 item_list
.push_back(item
);
543 for (std::vector
<DropData::FileSystemFileInfo
>::const_iterator it
=
544 drop_data
.file_system_files
.begin();
545 it
!= drop_data
.file_system_files
.end();
547 WebDragData::Item item
;
548 item
.storageType
= WebDragData::Item::StorageTypeFileSystemFile
;
549 item
.fileSystemURL
= it
->url
;
550 item
.fileSystemFileSize
= it
->size
;
551 item_list
.push_back(item
);
554 for (std::map
<base::string16
, base::string16
>::const_iterator it
=
555 drop_data
.custom_data
.begin();
556 it
!= drop_data
.custom_data
.end();
558 WebDragData::Item item
;
559 item
.storageType
= WebDragData::Item::StorageTypeString
;
560 item
.stringType
= it
->first
;
561 item
.stringData
= it
->second
;
562 item_list
.push_back(item
);
567 result
.setItems(item_list
);
568 result
.setFilesystemId(drop_data
.filesystem_id
);
572 typedef void (*SetFontFamilyWrapper
)(blink::WebSettings
*,
573 const base::string16
&,
576 void SetStandardFontFamilyWrapper(WebSettings
* settings
,
577 const base::string16
& font
,
578 UScriptCode script
) {
579 settings
->setStandardFontFamily(font
, script
);
582 void SetFixedFontFamilyWrapper(WebSettings
* settings
,
583 const base::string16
& font
,
584 UScriptCode script
) {
585 settings
->setFixedFontFamily(font
, script
);
588 void SetSerifFontFamilyWrapper(WebSettings
* settings
,
589 const base::string16
& font
,
590 UScriptCode script
) {
591 settings
->setSerifFontFamily(font
, script
);
594 void SetSansSerifFontFamilyWrapper(WebSettings
* settings
,
595 const base::string16
& font
,
596 UScriptCode script
) {
597 settings
->setSansSerifFontFamily(font
, script
);
600 void SetCursiveFontFamilyWrapper(WebSettings
* settings
,
601 const base::string16
& font
,
602 UScriptCode script
) {
603 settings
->setCursiveFontFamily(font
, script
);
606 void SetFantasyFontFamilyWrapper(WebSettings
* settings
,
607 const base::string16
& font
,
608 UScriptCode script
) {
609 settings
->setFantasyFontFamily(font
, script
);
612 void SetPictographFontFamilyWrapper(WebSettings
* settings
,
613 const base::string16
& font
,
614 UScriptCode script
) {
615 settings
->setPictographFontFamily(font
, script
);
618 // If |scriptCode| is a member of a family of "similar" script codes, returns
619 // the script code in that family that is used by WebKit for font selection
620 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
621 // considered equivalent for the purposes of font selection. WebKit uses the
622 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
623 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
624 // uses different scripts than the ones in Chrome pref names because the version
625 // of ICU included on certain ports does not have some of the newer scripts. If
626 // |scriptCode| is not a member of such a family, returns |scriptCode|.
627 UScriptCode
GetScriptForWebSettings(UScriptCode scriptCode
) {
628 switch (scriptCode
) {
629 case USCRIPT_HIRAGANA
:
630 case USCRIPT_KATAKANA
:
631 case USCRIPT_JAPANESE
:
632 return USCRIPT_KATAKANA_OR_HIRAGANA
;
634 return USCRIPT_HANGUL
;
640 void ApplyFontsFromMap(const ScriptFontFamilyMap
& map
,
641 SetFontFamilyWrapper setter
,
642 WebSettings
* settings
) {
643 for (ScriptFontFamilyMap::const_iterator it
= map
.begin(); it
!= map
.end();
645 int32 script
= u_getPropertyValueEnum(UCHAR_SCRIPT
, (it
->first
).c_str());
646 if (script
>= 0 && script
< USCRIPT_CODE_LIMIT
) {
647 UScriptCode code
= static_cast<UScriptCode
>(script
);
648 (*setter
)(settings
, it
->second
, GetScriptForWebSettings(code
));
655 RenderViewImpl::RenderViewImpl(RenderViewImplParams
* params
)
656 : RenderWidget(blink::WebPopupTypeNone
,
660 params
->never_visible
),
661 webkit_preferences_(params
->webkit_prefs
),
662 send_content_state_immediately_(false),
663 enabled_bindings_(0),
664 send_preferred_size_changes_(false),
665 navigation_gesture_(NavigationGestureUnknown
),
666 opened_by_user_gesture_(true),
667 opener_suppressed_(false),
668 suppress_dialogs_until_swap_out_(false),
670 last_page_id_sent_to_browser_(-1),
671 next_page_id_(params
->next_page_id
),
672 history_list_offset_(-1),
673 history_list_length_(0),
674 frames_in_progress_(0),
675 target_url_status_(TARGET_NONE
),
676 uses_temporary_zoom_level_(false),
677 #if defined(OS_ANDROID)
678 top_controls_constraints_(cc::BOTH
),
680 has_scrolled_focused_editable_node_into_rect_(false),
681 speech_recognition_dispatcher_(NULL
),
682 browser_plugin_manager_(NULL
),
683 devtools_agent_(NULL
),
684 mouse_lock_dispatcher_(NULL
),
685 #if defined(OS_ANDROID)
686 expected_content_intent_id_(0),
689 focused_plugin_id_(-1),
691 #if defined(ENABLE_PLUGINS)
692 plugin_find_handler_(NULL
),
693 focused_pepper_plugin_(NULL
),
694 pepper_last_mouse_event_target_(NULL
),
696 enumeration_completion_id_(0),
697 session_storage_namespace_id_(params
->session_storage_namespace_id
),
698 next_snapshot_id_(0) {
701 void RenderViewImpl::Initialize(RenderViewImplParams
* params
) {
702 routing_id_
= params
->routing_id
;
703 surface_id_
= params
->surface_id
;
704 if (params
->opener_id
!= MSG_ROUTING_NONE
&& params
->is_renderer_created
)
705 opener_id_
= params
->opener_id
;
707 // Ensure we start with a valid next_page_id_ from the browser.
708 DCHECK_GE(next_page_id_
, 0);
710 main_render_frame_
.reset(RenderFrameImpl::Create(
711 this, params
->main_frame_routing_id
));
712 // The main frame WebLocalFrame object is closed by
713 // RenderFrameImpl::frameDetached().
714 WebLocalFrame
* web_frame
= WebLocalFrame::create(main_render_frame_
.get());
715 main_render_frame_
->SetWebFrame(web_frame
);
717 webwidget_
= WebView::create(this);
718 webwidget_mouse_lock_target_
.reset(new WebWidgetLockTarget(webwidget_
));
720 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
722 if (command_line
.HasSwitch(switches::kStatsCollectionController
))
723 stats_collection_observer_
.reset(new StatsCollectionObserver(this));
725 #if defined(OS_ANDROID)
726 const std::string region_code
=
727 command_line
.HasSwitch(switches::kNetworkCountryIso
)
728 ? command_line
.GetSwitchValueASCII(switches::kNetworkCountryIso
)
729 : net::android::GetTelephonyNetworkOperator();
730 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
731 new AddressDetector()));
732 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
733 new PhoneNumberDetector(region_code
)));
734 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
735 new EmailDetector()));
738 RenderThread::Get()->AddRoute(routing_id_
, this);
739 // Take a reference on behalf of the RenderThread. This will be balanced
740 // when we receive ViewMsg_ClosePage.
742 if (RenderThreadImpl::current()) {
743 RenderThreadImpl::current()->WidgetCreated();
745 RenderThreadImpl::current()->WidgetHidden();
748 // If this is a popup, we must wait for the CreatingNew_ACK message before
749 // completing initialization. Otherwise, we can finish it now.
750 if (opener_id_
== MSG_ROUTING_NONE
) {
755 g_view_map
.Get().insert(std::make_pair(webview(), this));
756 g_routing_id_view_map
.Get().insert(std::make_pair(routing_id_
, this));
757 webview()->setDeviceScaleFactor(device_scale_factor_
);
758 webview()->settings()->setPreferCompositingToLCDTextEnabled(
759 PreferCompositingToLCDText(device_scale_factor_
));
760 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
761 ShouldUseTransitionCompositing(device_scale_factor_
));
763 ApplyWebPreferences(webkit_preferences_
, webview());
765 webview()->settings()->setAllowConnectingInsecureWebSocket(
766 command_line
.HasSwitch(switches::kAllowInsecureWebSocketFromHttpsOrigin
));
768 RenderFrameProxy
* proxy
= NULL
;
769 if (params
->proxy_routing_id
!= MSG_ROUTING_NONE
) {
770 CHECK(params
->swapped_out
);
771 proxy
= RenderFrameProxy::CreateProxyToReplaceFrame(
772 main_render_frame_
.get(), params
->proxy_routing_id
);
773 main_render_frame_
->set_render_frame_proxy(proxy
);
776 // In --site-per-process, just use the WebRemoteFrame as the main frame.
777 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess
) &&
779 webview()->setMainFrame(proxy
->web_frame());
781 webview()->setMainFrame(main_render_frame_
->GetWebFrame());
783 main_render_frame_
->Initialize();
785 if (switches::IsTouchDragDropEnabled())
786 webview()->settings()->setTouchDragDropEnabled(true);
788 if (switches::IsTouchEditingEnabled())
789 webview()->settings()->setTouchEditingEnabled(true);
791 if (!params
->frame_name
.empty())
792 webview()->mainFrame()->setName(params
->frame_name
);
794 // TODO(davidben): Move this state from Blink into content.
795 if (params
->window_was_created_with_opener
)
796 webview()->setOpenedByDOM();
798 OnSetRendererPrefs(params
->renderer_prefs
);
800 new MHTMLGenerator(this);
801 #if defined(OS_MACOSX)
802 new TextInputClientObserver(this);
803 #endif // defined(OS_MACOSX)
805 // The next group of objects all implement RenderViewObserver, so are deleted
806 // along with the RenderView automatically.
807 devtools_agent_
= new DevToolsAgent(this);
808 if (RenderWidgetCompositor
* rwc
= compositor()) {
809 webview()->devToolsAgent()->setLayerTreeId(rwc
->GetLayerTreeId());
811 mouse_lock_dispatcher_
= new RenderViewMouseLockDispatcher(this);
813 history_controller_
.reset(new HistoryController(this));
815 new IdleUserDetector(this);
817 if (command_line
.HasSwitch(switches::kDomAutomationController
))
818 enabled_bindings_
|= BINDINGS_POLICY_DOM_AUTOMATION
;
819 if (command_line
.HasSwitch(switches::kStatsCollectionController
))
820 enabled_bindings_
|= BINDINGS_POLICY_STATS_COLLECTION
;
822 ProcessViewLayoutFlags(command_line
);
824 GetContentClient()->renderer()->RenderViewCreated(this);
826 // If we have an opener_id but we weren't created by a renderer, then
827 // it's the browser asking us to set our opener to another RenderView.
828 if (params
->opener_id
!= MSG_ROUTING_NONE
&& !params
->is_renderer_created
) {
829 RenderViewImpl
* opener_view
= FromRoutingID(params
->opener_id
);
831 webview()->mainFrame()->setOpener(opener_view
->webview()->mainFrame());
834 // If we are initially swapped out, navigate to kSwappedOutURL.
835 // This ensures we are in a unique origin that others cannot script.
836 if (is_swapped_out_
&& webview()->mainFrame()->isWebLocalFrame())
837 NavigateToSwappedOutURL(webview()->mainFrame());
840 RenderViewImpl::~RenderViewImpl() {
841 for (BitmapMap::iterator it
= disambiguation_bitmaps_
.begin();
842 it
!= disambiguation_bitmaps_
.end();
845 history_page_ids_
.clear();
847 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_
);
849 // If file chooser is still waiting for answer, dispatch empty answer.
850 while (!file_chooser_completions_
.empty()) {
851 if (file_chooser_completions_
.front()->completion
) {
852 file_chooser_completions_
.front()->completion
->didChooseFile(
853 WebVector
<WebString
>());
855 file_chooser_completions_
.pop_front();
858 #if defined(OS_ANDROID)
859 // The date/time picker client is both a scoped_ptr member of this class and
860 // a RenderViewObserver. Reset it to prevent double deletion.
861 date_time_picker_client_
.reset();
865 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
866 ViewMap
* views
= g_view_map
.Pointer();
867 for (ViewMap::iterator it
= views
->begin(); it
!= views
->end(); ++it
)
868 DCHECK_NE(this, it
->second
) << "Failed to call Close?";
869 RoutingIDViewMap
* routing_id_views
= g_routing_id_view_map
.Pointer();
870 for (RoutingIDViewMap::iterator it
= routing_id_views
->begin();
871 it
!= routing_id_views
->end(); ++it
)
872 DCHECK_NE(this, it
->second
) << "Failed to call Close?";
875 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, RenderViewGone());
876 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, OnDestruct());
880 RenderViewImpl
* RenderViewImpl::FromWebView(WebView
* webview
) {
881 ViewMap
* views
= g_view_map
.Pointer();
882 ViewMap::iterator it
= views
->find(webview
);
883 return it
== views
->end() ? NULL
: it
->second
;
887 RenderView
* RenderView::FromWebView(blink::WebView
* webview
) {
888 return RenderViewImpl::FromWebView(webview
);
892 RenderViewImpl
* RenderViewImpl::FromRoutingID(int32 routing_id
) {
893 RoutingIDViewMap
* views
= g_routing_id_view_map
.Pointer();
894 RoutingIDViewMap::iterator it
= views
->find(routing_id
);
895 return it
== views
->end() ? NULL
: it
->second
;
899 RenderView
* RenderView::FromRoutingID(int routing_id
) {
900 return RenderViewImpl::FromRoutingID(routing_id
);
904 size_t RenderViewImpl::GetRenderViewCount() {
905 return g_view_map
.Get().size();
909 void RenderView::ForEach(RenderViewVisitor
* visitor
) {
910 ViewMap
* views
= g_view_map
.Pointer();
911 for (ViewMap::iterator it
= views
->begin(); it
!= views
->end(); ++it
) {
912 if (!visitor
->Visit(it
->second
))
918 void RenderView::ApplyWebPreferences(const WebPreferences
& prefs
,
920 WebSettings
* settings
= web_view
->settings();
921 ApplyFontsFromMap(prefs
.standard_font_family_map
,
922 SetStandardFontFamilyWrapper
, settings
);
923 ApplyFontsFromMap(prefs
.fixed_font_family_map
,
924 SetFixedFontFamilyWrapper
, settings
);
925 ApplyFontsFromMap(prefs
.serif_font_family_map
,
926 SetSerifFontFamilyWrapper
, settings
);
927 ApplyFontsFromMap(prefs
.sans_serif_font_family_map
,
928 SetSansSerifFontFamilyWrapper
, settings
);
929 ApplyFontsFromMap(prefs
.cursive_font_family_map
,
930 SetCursiveFontFamilyWrapper
, settings
);
931 ApplyFontsFromMap(prefs
.fantasy_font_family_map
,
932 SetFantasyFontFamilyWrapper
, settings
);
933 ApplyFontsFromMap(prefs
.pictograph_font_family_map
,
934 SetPictographFontFamilyWrapper
, settings
);
935 settings
->setDefaultFontSize(prefs
.default_font_size
);
936 settings
->setDefaultFixedFontSize(prefs
.default_fixed_font_size
);
937 settings
->setMinimumFontSize(prefs
.minimum_font_size
);
938 settings
->setMinimumLogicalFontSize(prefs
.minimum_logical_font_size
);
939 settings
->setDefaultTextEncodingName(
940 base::ASCIIToUTF16(prefs
.default_encoding
));
941 settings
->setJavaScriptEnabled(prefs
.javascript_enabled
);
942 settings
->setWebSecurityEnabled(prefs
.web_security_enabled
);
943 settings
->setJavaScriptCanOpenWindowsAutomatically(
944 prefs
.javascript_can_open_windows_automatically
);
945 settings
->setLoadsImagesAutomatically(prefs
.loads_images_automatically
);
946 settings
->setImagesEnabled(prefs
.images_enabled
);
947 settings
->setPluginsEnabled(prefs
.plugins_enabled
);
948 settings
->setDOMPasteAllowed(prefs
.dom_paste_enabled
);
949 settings
->setShrinksStandaloneImagesToFit(
950 prefs
.shrinks_standalone_images_to_fit
);
951 settings
->setUsesEncodingDetector(prefs
.uses_universal_detector
);
952 settings
->setTextAreasAreResizable(prefs
.text_areas_are_resizable
);
953 settings
->setAllowScriptsToCloseWindows(prefs
.allow_scripts_to_close_windows
);
954 settings
->setDownloadableBinaryFontsEnabled(prefs
.remote_fonts_enabled
);
955 settings
->setJavaScriptCanAccessClipboard(
956 prefs
.javascript_can_access_clipboard
);
957 WebRuntimeFeatures::enableXSLT(prefs
.xslt_enabled
);
958 settings
->setXSSAuditorEnabled(prefs
.xss_auditor_enabled
);
959 settings
->setDNSPrefetchingEnabled(prefs
.dns_prefetching_enabled
);
960 settings
->setLocalStorageEnabled(prefs
.local_storage_enabled
);
961 settings
->setSyncXHRInDocumentsEnabled(prefs
.sync_xhr_in_documents_enabled
);
962 WebRuntimeFeatures::enableDatabase(prefs
.databases_enabled
);
963 settings
->setOfflineWebApplicationCacheEnabled(
964 prefs
.application_cache_enabled
);
965 settings
->setCaretBrowsingEnabled(prefs
.caret_browsing_enabled
);
966 settings
->setHyperlinkAuditingEnabled(prefs
.hyperlink_auditing_enabled
);
967 settings
->setCookieEnabled(prefs
.cookie_enabled
);
968 settings
->setNavigateOnDragDrop(prefs
.navigate_on_drag_drop
);
970 settings
->setJavaEnabled(prefs
.java_enabled
);
972 // By default, allow_universal_access_from_file_urls is set to false and thus
973 // we mitigate attacks from local HTML files by not granting file:// URLs
974 // universal access. Only test shell will enable this.
975 settings
->setAllowUniversalAccessFromFileURLs(
976 prefs
.allow_universal_access_from_file_urls
);
977 settings
->setAllowFileAccessFromFileURLs(
978 prefs
.allow_file_access_from_file_urls
);
980 // Enable the web audio API if requested on the command line.
981 settings
->setWebAudioEnabled(prefs
.webaudio_enabled
);
983 // Enable experimental WebGL support if requested on command line
984 // and support is compiled in.
985 settings
->setExperimentalWebGLEnabled(prefs
.experimental_webgl_enabled
);
987 // Disable GL multisampling if requested on command line.
988 settings
->setOpenGLMultisamplingEnabled(prefs
.gl_multisampling_enabled
);
990 // Enable WebGL errors to the JS console if requested.
991 settings
->setWebGLErrorsToConsoleEnabled(
992 prefs
.webgl_errors_to_console_enabled
);
994 // Uses the mock theme engine for scrollbars.
995 settings
->setMockScrollbarsEnabled(prefs
.mock_scrollbars_enabled
);
997 settings
->setLayerSquashingEnabled(prefs
.layer_squashing_enabled
);
999 // Enable gpu-accelerated 2d canvas if requested on the command line.
1000 settings
->setAccelerated2dCanvasEnabled(prefs
.accelerated_2d_canvas_enabled
);
1002 settings
->setMinimumAccelerated2dCanvasSize(
1003 prefs
.minimum_accelerated_2d_canvas_size
);
1005 // Disable antialiasing for 2d canvas if requested on the command line.
1006 settings
->setAntialiased2dCanvasEnabled(
1007 !prefs
.antialiased_2d_canvas_disabled
);
1009 // Set MSAA sample count for 2d canvas if requested on the command line (or
1010 // default value if not).
1011 settings
->setAccelerated2dCanvasMSAASampleCount(
1012 prefs
.accelerated_2d_canvas_msaa_sample_count
);
1014 // Enable deferred filter rendering if requested on the command line.
1015 settings
->setDeferredFiltersEnabled(prefs
.deferred_filters_enabled
);
1017 // Enable container culling if requested on the command line.
1018 settings
->setContainerCullingEnabled(prefs
.container_culling_enabled
);
1020 settings
->setAsynchronousSpellCheckingEnabled(
1021 prefs
.asynchronous_spell_checking_enabled
);
1022 settings
->setUnifiedTextCheckerEnabled(prefs
.unified_textchecker_enabled
);
1024 // Tabs to link is not part of the settings. WebCore calls
1025 // ChromeClient::tabsToLinks which is part of the glue code.
1026 web_view
->setTabsToLinks(prefs
.tabs_to_links
);
1028 settings
->setAllowDisplayOfInsecureContent(
1029 prefs
.allow_displaying_insecure_content
);
1030 settings
->setAllowRunningOfInsecureContent(
1031 prefs
.allow_running_insecure_content
);
1032 settings
->setPasswordEchoEnabled(prefs
.password_echo_enabled
);
1033 settings
->setShouldPrintBackgrounds(prefs
.should_print_backgrounds
);
1034 settings
->setShouldClearDocumentBackground(
1035 prefs
.should_clear_document_background
);
1036 settings
->setEnableScrollAnimator(prefs
.enable_scroll_animator
);
1038 settings
->setRegionBasedColumnsEnabled(prefs
.region_based_columns_enabled
);
1040 WebRuntimeFeatures::enableTouch(prefs
.touch_enabled
);
1041 settings
->setMaxTouchPoints(prefs
.pointer_events_max_touch_points
);
1042 settings
->setDeviceSupportsTouch(prefs
.device_supports_touch
);
1043 settings
->setDeviceSupportsMouse(prefs
.device_supports_mouse
);
1044 settings
->setEnableTouchAdjustment(prefs
.touch_adjustment_enabled
);
1046 settings
->setDeferredImageDecodingEnabled(
1047 prefs
.deferred_image_decoding_enabled
);
1048 settings
->setShouldRespectImageOrientation(
1049 prefs
.should_respect_image_orientation
);
1051 settings
->setUnsafePluginPastingEnabled(false);
1052 settings
->setEditingBehavior(
1053 static_cast<WebSettings::EditingBehavior
>(prefs
.editing_behavior
));
1055 settings
->setSupportsMultipleWindows(prefs
.supports_multiple_windows
);
1057 settings
->setViewportEnabled(prefs
.viewport_enabled
);
1058 settings
->setLoadWithOverviewMode(prefs
.initialize_at_minimum_page_scale
);
1059 settings
->setViewportMetaEnabled(prefs
.viewport_meta_enabled
);
1060 settings
->setMainFrameResizesAreOrientationChanges(
1061 prefs
.main_frame_resizes_are_orientation_changes
);
1063 settings
->setSmartInsertDeleteEnabled(prefs
.smart_insert_delete_enabled
);
1065 settings
->setSpatialNavigationEnabled(prefs
.spatial_navigation_enabled
);
1067 settings
->setSelectionIncludesAltImageText(true);
1069 settings
->setV8CacheOptions(
1070 static_cast<WebSettings::V8CacheOptions
>(prefs
.v8_cache_options
));
1072 #if defined(OS_ANDROID)
1073 settings
->setAllowCustomScrollbarInMainFrame(false);
1074 settings
->setTextAutosizingEnabled(prefs
.text_autosizing_enabled
);
1075 settings
->setAccessibilityFontScaleFactor(prefs
.font_scale_factor
);
1076 settings
->setDeviceScaleAdjustment(prefs
.device_scale_adjustment
);
1077 settings
->setDisallowFullscreenForNonMediaElements(
1078 prefs
.disallow_fullscreen_for_non_media_elements
);
1079 settings
->setFullscreenSupported(prefs
.fullscreen_supported
);
1080 web_view
->setIgnoreViewportTagScaleLimits(prefs
.force_enable_zoom
);
1081 settings
->setAutoZoomFocusedNodeToLegibleScale(true);
1082 settings
->setDoubleTapToZoomEnabled(prefs
.double_tap_to_zoom_enabled
);
1083 settings
->setMediaControlsOverlayPlayButtonEnabled(true);
1084 settings
->setMediaPlaybackRequiresUserGesture(
1085 prefs
.user_gesture_required_for_media_playback
);
1086 settings
->setDefaultVideoPosterURL(
1087 base::ASCIIToUTF16(prefs
.default_video_poster_url
.spec()));
1088 settings
->setSupportDeprecatedTargetDensityDPI(
1089 prefs
.support_deprecated_target_density_dpi
);
1090 settings
->setUseLegacyBackgroundSizeShorthandBehavior(
1091 prefs
.use_legacy_background_size_shorthand_behavior
);
1092 settings
->setWideViewportQuirkEnabled(prefs
.wide_viewport_quirk
);
1093 settings
->setUseWideViewport(prefs
.use_wide_viewport
);
1094 settings
->setForceZeroLayoutHeight(prefs
.force_zero_layout_height
);
1095 settings
->setViewportMetaLayoutSizeQuirk(
1096 prefs
.viewport_meta_layout_size_quirk
);
1097 settings
->setViewportMetaMergeContentQuirk(
1098 prefs
.viewport_meta_merge_content_quirk
);
1099 settings
->setViewportMetaNonUserScalableQuirk(
1100 prefs
.viewport_meta_non_user_scalable_quirk
);
1101 settings
->setViewportMetaZeroValuesQuirk(
1102 prefs
.viewport_meta_zero_values_quirk
);
1103 settings
->setClobberUserAgentInitialScaleQuirk(
1104 prefs
.clobber_user_agent_initial_scale_quirk
);
1105 settings
->setIgnoreMainFrameOverflowHiddenQuirk(
1106 prefs
.ignore_main_frame_overflow_hidden_quirk
);
1107 settings
->setReportScreenSizeInPhysicalPixelsQuirk(
1108 prefs
.report_screen_size_in_physical_pixels_quirk
);
1109 settings
->setMainFrameClipsContent(false);
1110 settings
->setShrinksStandaloneImagesToFit(false);
1111 settings
->setShrinksViewportContentToFit(true);
1114 WebNetworkStateNotifier::setOnLine(prefs
.is_online
);
1115 WebNetworkStateNotifier::setWebConnectionType(
1116 NetConnectionTypeToWebConnectionType(prefs
.connection_type
));
1117 settings
->setPinchVirtualViewportEnabled(
1118 prefs
.pinch_virtual_viewport_enabled
);
1120 settings
->setPinchOverlayScrollbarThickness(
1121 prefs
.pinch_overlay_scrollbar_thickness
);
1122 settings
->setUseSolidColorScrollbars(prefs
.use_solid_color_scrollbars
);
1126 RenderViewImpl
* RenderViewImpl::Create(
1128 bool window_was_created_with_opener
,
1129 const RendererPreferences
& renderer_prefs
,
1130 const WebPreferences
& webkit_prefs
,
1132 int32 main_frame_routing_id
,
1134 int64 session_storage_namespace_id
,
1135 const base::string16
& frame_name
,
1136 bool is_renderer_created
,
1138 int32 proxy_routing_id
,
1142 const blink::WebScreenInfo
& screen_info
) {
1143 DCHECK(routing_id
!= MSG_ROUTING_NONE
);
1144 RenderViewImplParams
params(opener_id
,
1145 window_was_created_with_opener
,
1149 main_frame_routing_id
,
1151 session_storage_namespace_id
,
1153 is_renderer_created
,
1160 RenderViewImpl
* render_view
= NULL
;
1161 if (g_create_render_view_impl
)
1162 render_view
= g_create_render_view_impl(¶ms
);
1164 render_view
= new RenderViewImpl(¶ms
);
1166 render_view
->Initialize(¶ms
);
1171 void RenderViewImpl::InstallCreateHook(
1172 RenderViewImpl
* (*create_render_view_impl
)(RenderViewImplParams
*)) {
1173 CHECK(!g_create_render_view_impl
);
1174 g_create_render_view_impl
= create_render_view_impl
;
1177 void RenderViewImpl::AddObserver(RenderViewObserver
* observer
) {
1178 observers_
.AddObserver(observer
);
1181 void RenderViewImpl::RemoveObserver(RenderViewObserver
* observer
) {
1182 observer
->RenderViewGone();
1183 observers_
.RemoveObserver(observer
);
1186 blink::WebView
* RenderViewImpl::webview() const {
1187 return static_cast<blink::WebView
*>(webwidget());
1190 #if defined(ENABLE_PLUGINS)
1191 void RenderViewImpl::PepperInstanceCreated(
1192 PepperPluginInstanceImpl
* instance
) {
1193 active_pepper_instances_
.insert(instance
);
1196 void RenderViewImpl::PepperInstanceDeleted(
1197 PepperPluginInstanceImpl
* instance
) {
1198 active_pepper_instances_
.erase(instance
);
1200 if (pepper_last_mouse_event_target_
== instance
)
1201 pepper_last_mouse_event_target_
= NULL
;
1202 if (focused_pepper_plugin_
== instance
)
1203 PepperFocusChanged(instance
, false);
1206 void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl
* instance
,
1209 focused_pepper_plugin_
= instance
;
1210 else if (focused_pepper_plugin_
== instance
)
1211 focused_pepper_plugin_
= NULL
;
1213 UpdateTextInputState(NO_SHOW_IME
, FROM_NON_IME
);
1214 UpdateSelectionBounds();
1217 void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
) {
1218 plugin_delegates_
.insert(delegate
);
1219 // If the renderer is visible, set initial visibility and focus state.
1221 #if defined(OS_MACOSX)
1222 delegate
->SetContainerVisibility(true);
1223 if (webview() && webview()->isActive())
1224 delegate
->SetWindowFocus(true);
1227 // Plugins start assuming the content has focus (so that they work in
1228 // environments where RenderView isn't hosting them), so we always have to
1229 // set the initial state. See webplugin_delegate_impl.h for details.
1230 delegate
->SetContentAreaFocus(has_focus());
1233 void RenderViewImpl::UnregisterPluginDelegate(
1234 WebPluginDelegateProxy
* delegate
) {
1235 plugin_delegates_
.erase(delegate
);
1239 void RenderViewImpl::PluginFocusChanged(bool focused
, int plugin_id
) {
1241 focused_plugin_id_
= plugin_id
;
1243 focused_plugin_id_
= -1;
1247 #if defined(OS_MACOSX)
1248 void RenderViewImpl::PluginFocusChanged(bool focused
, int plugin_id
) {
1249 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused
, plugin_id
));
1252 void RenderViewImpl::OnGetRenderedText() {
1255 // Get rendered text from WebLocalFrame.
1256 // TODO: Currently IPC truncates any data that has a
1257 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1258 // send back using multiple IPC. See http://crbug.com/393444.
1259 static const size_t kMaximumMessageSize
= 8 * 1024 * 1024;
1260 std::string text
= webview()->mainFrame()->contentAsText(
1261 kMaximumMessageSize
).utf8();
1263 Send(new ViewMsg_GetRenderedTextCompleted(routing_id(), text
));
1266 void RenderViewImpl::StartPluginIme() {
1267 IPC::Message
* msg
= new ViewHostMsg_StartPluginIme(routing_id());
1268 // This message can be sent during event-handling, and needs to be delivered
1269 // within that context.
1270 msg
->set_unblock(true);
1273 #endif // defined(OS_MACOSX)
1275 #endif // ENABLE_PLUGINS
1277 void RenderViewImpl::TransferActiveWheelFlingAnimation(
1278 const blink::WebActiveWheelFlingParameters
& params
) {
1280 webview()->transferActiveWheelFlingAnimation(params
);
1283 bool RenderViewImpl::HasIMETextFocus() {
1284 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE
;
1287 bool RenderViewImpl::OnMessageReceived(const IPC::Message
& message
) {
1288 WebFrame
* main_frame
= webview() ? webview()->mainFrame() : NULL
;
1289 if (main_frame
&& main_frame
->isWebLocalFrame())
1290 GetContentClient()->SetActiveURL(main_frame
->document().url());
1292 ObserverListBase
<RenderViewObserver
>::Iterator
it(observers_
);
1293 RenderViewObserver
* observer
;
1294 while ((observer
= it
.GetNext()) != NULL
)
1295 if (observer
->OnMessageReceived(message
))
1298 bool handled
= true;
1299 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl
, message
)
1300 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand
, OnExecuteEditCommand
)
1301 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret
, OnMoveCaret
)
1302 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect
,
1303 OnScrollFocusedEditableNodeIntoRect
)
1304 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent
,
1305 OnSetEditCommandsForNextKeyEvent
)
1306 IPC_MESSAGE_HANDLER(ViewMsg_Stop
, OnStop
)
1307 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt
, OnCopyImageAt
)
1308 IPC_MESSAGE_HANDLER(ViewMsg_SaveImageAt
, OnSaveImageAt
)
1309 IPC_MESSAGE_HANDLER(ViewMsg_Find
, OnFind
)
1310 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding
, OnStopFinding
)
1311 IPC_MESSAGE_HANDLER(ViewMsg_Zoom
, OnZoom
)
1312 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL
,
1313 OnSetZoomLevelForLoadingURL
)
1314 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView
,
1315 OnSetZoomLevelForView
)
1316 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding
, OnSetPageEncoding
)
1317 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault
,
1318 OnResetPageEncodingToDefault
)
1319 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent
, OnPostMessageEvent
)
1320 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter
, OnDragTargetDragEnter
)
1321 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver
, OnDragTargetDragOver
)
1322 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave
, OnDragTargetDragLeave
)
1323 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop
, OnDragTargetDrop
)
1324 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded
, OnDragSourceEnded
)
1325 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded
,
1326 OnDragSourceSystemDragEnded
)
1327 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings
, OnAllowBindings
)
1328 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus
, OnSetInitialFocus
)
1329 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK
, OnUpdateTargetURLAck
)
1330 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences
, OnUpdateWebPreferences
)
1331 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse
,
1332 OnEnumerateDirectoryResponse
)
1333 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse
, OnFileChooserResponse
)
1334 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut
,
1335 OnSuppressDialogsUntilSwapOut
)
1336 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage
, OnClosePage
)
1337 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged
, OnThemeChanged
)
1338 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted
, OnMoveOrResizeStarted
)
1339 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement
, OnClearFocusedElement
)
1340 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque
, OnSetBackgroundOpaque
)
1341 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode
,
1342 OnEnablePreferredSizeChangedMode
)
1343 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize
, OnEnableAutoResize
)
1344 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize
, OnDisableAutoResize
)
1345 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows
,
1346 OnDisableScrollbarsForSmallWindows
)
1347 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs
, OnSetRendererPrefs
)
1348 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt
, OnMediaPlayerActionAt
)
1349 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt
, OnPluginActionAt
)
1350 IPC_MESSAGE_HANDLER(ViewMsg_SetActive
, OnSetActive
)
1351 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage
,
1352 OnGetAllSavableResourceLinksForCurrentPage
)
1353 IPC_MESSAGE_HANDLER(
1354 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks
,
1355 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks
)
1356 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu
, OnShowContextMenu
)
1357 // TODO(viettrungluu): Move to a separate message filter.
1358 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune
,
1359 OnSetHistoryLengthAndPrune
)
1360 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode
, OnEnableViewSourceMode
)
1361 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap
,
1362 OnReleaseDisambiguationPopupBitmap
)
1363 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted
,
1364 OnWindowSnapshotCompleted
)
1365 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw
, OnForceRedraw
)
1366 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret
, OnSelectWordAroundCaret
)
1367 #if defined(OS_ANDROID)
1368 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult
,
1369 OnActivateNearestFindResult
)
1370 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects
, OnFindMatchRects
)
1371 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState
,
1372 OnUpdateTopControlsState
)
1373 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData
, OnExtractSmartClipData
)
1374 #elif defined(OS_MACOSX)
1375 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText
,
1377 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted
,
1378 OnPluginImeCompositionCompleted
)
1379 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize
, OnSetInLiveResize
)
1380 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility
, OnSetWindowVisibility
)
1381 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged
, OnWindowFrameChanged
)
1383 // Adding a new message? Add platform independent ones first, then put the
1384 // platform specific ones at the end.
1386 // Have the super handle all other messages.
1387 IPC_MESSAGE_UNHANDLED(handled
= RenderWidget::OnMessageReceived(message
))
1388 IPC_END_MESSAGE_MAP()
1393 void RenderViewImpl::OnSelectWordAroundCaret() {
1397 handling_input_event_
= true;
1398 webview()->focusedFrame()->selectWordAroundCaret();
1399 handling_input_event_
= false;
1402 bool RenderViewImpl::IsBackForwardToStaleEntry(
1403 const FrameMsg_Navigate_Params
& params
,
1405 // Make sure this isn't a back/forward to an entry we have already cropped
1406 // or replaced from our history, before the browser knew about it. If so,
1407 // a new navigation has committed in the mean time, and we can ignore this.
1408 bool is_back_forward
= !is_reload
&& params
.page_state
.IsValid();
1410 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1411 // restoring from a previous session. We'll update our state in OnNavigate.
1412 if (!is_back_forward
|| history_list_length_
<= 0)
1415 DCHECK_EQ(static_cast<int>(history_page_ids_
.size()), history_list_length_
);
1417 // Check for whether the forward history has been cropped due to a recent
1418 // navigation the browser didn't know about.
1419 if (params
.pending_history_list_offset
>= history_list_length_
)
1422 // Check for whether this entry has been replaced with a new one.
1423 int expected_page_id
=
1424 history_page_ids_
[params
.pending_history_list_offset
];
1425 if (expected_page_id
> 0 && params
.page_id
!= expected_page_id
) {
1426 if (params
.page_id
< expected_page_id
)
1429 // Otherwise we've removed an earlier entry and should have shifted all
1430 // entries left. For now, it's ok to lazily update the list.
1431 // TODO(creis): Notify all live renderers when we remove entries from
1432 // the front of the list, so that we don't hit this case.
1433 history_page_ids_
[params
.pending_history_list_offset
] = params
.page_id
;
1439 // Stop loading the current page.
1440 void RenderViewImpl::OnStop() {
1442 webview()->mainFrame()->stopLoading();
1443 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, OnStop());
1444 main_render_frame_
->OnStop();
1447 void RenderViewImpl::OnCopyImageAt(int x
, int y
) {
1448 webview()->copyImageAt(WebPoint(x
, y
));
1451 void RenderViewImpl::OnSaveImageAt(int x
, int y
) {
1452 webview()->saveImageAt(WebPoint(x
, y
));
1455 void RenderViewImpl::OnUpdateTargetURLAck() {
1456 // Check if there is a targeturl waiting to be sent.
1457 if (target_url_status_
== TARGET_PENDING
) {
1458 Send(new ViewHostMsg_UpdateTargetURL(routing_id_
, page_id_
,
1459 pending_target_url_
));
1462 target_url_status_
= TARGET_NONE
;
1465 void RenderViewImpl::OnExecuteEditCommand(const std::string
& name
,
1466 const std::string
& value
) {
1467 if (!webview() || !webview()->focusedFrame())
1470 webview()->focusedFrame()->executeCommand(
1471 WebString::fromUTF8(name
), WebString::fromUTF8(value
));
1474 void RenderViewImpl::OnMoveCaret(const gfx::Point
& point
) {
1478 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_
));
1480 webview()->focusedFrame()->moveCaretSelection(point
);
1483 void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1484 const gfx::Rect
& rect
) {
1485 if (has_scrolled_focused_editable_node_into_rect_
&&
1486 rect
== rect_for_scrolled_focused_editable_node_
) {
1490 blink::WebElement element
= GetFocusedElement();
1491 if (!element
.isNull() && IsEditableNode(element
)) {
1492 rect_for_scrolled_focused_editable_node_
= rect
;
1493 has_scrolled_focused_editable_node_into_rect_
= true;
1494 webview()->scrollFocusedNodeIntoRect(rect
);
1498 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1499 const EditCommands
& edit_commands
) {
1500 edit_commands_
= edit_commands
;
1503 void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length
,
1504 int32 minimum_page_id
) {
1505 DCHECK_GE(history_length
, 0);
1506 DCHECK(history_list_offset_
== history_list_length_
- 1);
1507 DCHECK_GE(minimum_page_id
, -1);
1509 // Generate the new list.
1510 std::vector
<int32
> new_history_page_ids(history_length
, -1);
1511 for (size_t i
= 0; i
< history_page_ids_
.size(); ++i
) {
1512 if (minimum_page_id
>= 0 && history_page_ids_
[i
] < minimum_page_id
)
1514 new_history_page_ids
.push_back(history_page_ids_
[i
]);
1516 new_history_page_ids
.swap(history_page_ids_
);
1519 history_list_length_
= history_page_ids_
.size();
1520 history_list_offset_
= history_list_length_
- 1;
1524 void RenderViewImpl::OnSetInitialFocus(bool reverse
) {
1527 webview()->setInitialFocus(reverse
);
1530 #if defined(OS_MACOSX)
1531 void RenderViewImpl::OnSetInLiveResize(bool in_live_resize
) {
1535 webview()->willStartLiveResize();
1537 webview()->willEndLiveResize();
1541 ///////////////////////////////////////////////////////////////////////////////
1543 // Sends the current history state to the browser so it will be saved before we
1544 // navigate to a new page.
1545 void RenderViewImpl::UpdateSessionHistory(WebFrame
* frame
) {
1546 // If we have a valid page ID at this point, then it corresponds to the page
1547 // we are navigating away from. Otherwise, this is the first navigation, so
1548 // there is no past session history to record.
1551 SendUpdateState(history_controller_
->GetCurrentEntry());
1554 void RenderViewImpl::SendUpdateState(HistoryEntry
* entry
) {
1558 // Don't send state updates for kSwappedOutURL.
1559 if (entry
->root().urlString() == WebString::fromUTF8(kSwappedOutURL
))
1562 Send(new ViewHostMsg_UpdateState(
1563 routing_id_
, page_id_
, HistoryEntryToPageState(entry
)));
1566 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
) {
1567 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1568 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1569 // it is particularly important that we do not call willEnterModalLoop as
1570 // that would defer resource loads for the dialog itself.
1571 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1572 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
1574 message
->EnableMessagePumping(); // Runs a nested message loop.
1575 return Send(message
);
1578 void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback
& callback
) {
1579 int id
= next_snapshot_id_
++;
1580 pending_snapshots_
.insert(std::make_pair(id
, callback
));
1581 ui::LatencyInfo latency_info
;
1582 latency_info
.AddLatencyNumber(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT
,
1585 scoped_ptr
<cc::SwapPromiseMonitor
> latency_info_swap_promise_monitor
;
1586 if (RenderWidgetCompositor
* rwc
= compositor()) {
1587 latency_info_swap_promise_monitor
=
1588 rwc
->CreateLatencyInfoSwapPromiseMonitor(&latency_info
).Pass();
1590 ScheduleCompositeWithForcedRedraw();
1593 void RenderViewImpl::OnForceRedraw(int id
) {
1594 ui::LatencyInfo latency_info
;
1596 latency_info
.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT
,
1600 scoped_ptr
<cc::SwapPromiseMonitor
> latency_info_swap_promise_monitor
;
1601 if (RenderWidgetCompositor
* rwc
= compositor()) {
1602 latency_info_swap_promise_monitor
=
1603 rwc
->CreateLatencyInfoSwapPromiseMonitor(&latency_info
).Pass();
1605 ScheduleCompositeWithForcedRedraw();
1608 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id
,
1609 const gfx::Size
& size
, const std::vector
<unsigned char>& png
) {
1611 // Any pending snapshots with a lower ID than the one received are considered
1612 // to be implicitly complete, and returned the same snapshot data.
1613 PendingSnapshotMap::iterator it
= pending_snapshots_
.begin();
1614 while(it
!= pending_snapshots_
.end()) {
1615 if (it
->first
<= snapshot_id
) {
1616 it
->second
.Run(size
, png
);
1617 pending_snapshots_
.erase(it
++);
1624 // blink::WebViewClient ------------------------------------------------------
1626 WebView
* RenderViewImpl::createView(WebLocalFrame
* creator
,
1627 const WebURLRequest
& request
,
1628 const WebWindowFeatures
& features
,
1629 const WebString
& frame_name
,
1630 WebNavigationPolicy policy
,
1631 bool suppress_opener
) {
1632 ViewHostMsg_CreateWindow_Params params
;
1633 params
.opener_id
= routing_id_
;
1634 params
.user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
1635 if (GetContentClient()->renderer()->AllowPopup())
1636 params
.user_gesture
= true;
1637 params
.window_container_type
= WindowFeaturesToContainerType(features
);
1638 params
.session_storage_namespace_id
= session_storage_namespace_id_
;
1639 if (frame_name
!= "_blank")
1640 params
.frame_name
= frame_name
;
1641 params
.opener_render_frame_id
=
1642 RenderFrameImpl::FromWebFrame(creator
)->GetRoutingID();
1643 params
.opener_url
= creator
->document().url();
1644 params
.opener_top_level_frame_url
= creator
->top()->document().url();
1645 GURL
security_url(creator
->document().securityOrigin().toString());
1646 if (!security_url
.is_valid())
1647 security_url
= GURL();
1648 params
.opener_security_origin
= security_url
;
1649 params
.opener_suppressed
= suppress_opener
;
1650 params
.disposition
= NavigationPolicyToDisposition(policy
);
1651 if (!request
.isNull()) {
1652 params
.target_url
= request
.url();
1653 params
.referrer
= GetReferrerFromRequest(creator
, request
);
1655 params
.features
= features
;
1657 for (size_t i
= 0; i
< features
.additionalFeatures
.size(); ++i
)
1658 params
.additional_features
.push_back(features
.additionalFeatures
[i
]);
1660 int32 routing_id
= MSG_ROUTING_NONE
;
1661 int32 main_frame_routing_id
= MSG_ROUTING_NONE
;
1662 int32 surface_id
= 0;
1663 int64 cloned_session_storage_namespace_id
= 0;
1665 RenderThread::Get()->Send(
1666 new ViewHostMsg_CreateWindow(params
,
1668 &main_frame_routing_id
,
1670 &cloned_session_storage_namespace_id
));
1671 if (routing_id
== MSG_ROUTING_NONE
)
1674 WebUserGestureIndicator::consumeUserGesture();
1676 // While this view may be a background extension page, it can spawn a visible
1677 // render view. So we just assume that the new one is not another background
1678 // page instead of passing on our own value.
1679 // TODO(vangelis): Can we tell if the new view will be a background page?
1680 bool never_visible
= false;
1682 // The initial hidden state for the RenderViewImpl here has to match what the
1683 // browser will eventually decide for the given disposition. Since we have to
1684 // return from this call synchronously, we just have to make our best guess
1685 // and rely on the browser sending a WasHidden / WasShown message if it
1687 RenderViewImpl
* view
= RenderViewImpl::Create(
1689 true, // window_was_created_with_opener
1690 renderer_preferences_
,
1691 webkit_preferences_
,
1693 main_frame_routing_id
,
1695 cloned_session_storage_namespace_id
,
1696 base::string16(), // WebCore will take care of setting the correct name.
1697 true, // is_renderer_created
1698 false, // swapped_out
1699 MSG_ROUTING_NONE
, // proxy_routing_id
1700 params
.disposition
== NEW_BACKGROUND_TAB
, // hidden
1704 view
->opened_by_user_gesture_
= params
.user_gesture
;
1706 // Record whether the creator frame is trying to suppress the opener field.
1707 view
->opener_suppressed_
= params
.opener_suppressed
;
1709 return view
->webview();
1712 WebWidget
* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type
) {
1713 RenderWidget
* widget
=
1714 RenderWidget::Create(routing_id_
, popup_type
, screen_info_
);
1717 if (screen_metrics_emulator_
) {
1718 widget
->SetPopupOriginAdjustmentsForEmulation(
1719 screen_metrics_emulator_
.get());
1721 return widget
->webwidget();
1724 WebStorageNamespace
* RenderViewImpl::createSessionStorageNamespace() {
1725 CHECK(session_storage_namespace_id_
!= kInvalidSessionStorageNamespaceId
);
1726 return new WebStorageNamespaceImpl(session_storage_namespace_id_
);
1729 void RenderViewImpl::printPage(WebLocalFrame
* frame
) {
1730 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
,
1731 PrintPage(frame
, handling_input_event_
));
1734 bool RenderViewImpl::enumerateChosenDirectory(
1735 const WebString
& path
,
1736 WebFileChooserCompletion
* chooser_completion
) {
1737 int id
= enumeration_completion_id_
++;
1738 enumeration_completions_
[id
] = chooser_completion
;
1739 return Send(new ViewHostMsg_EnumerateDirectory(
1742 base::FilePath::FromUTF16Unsafe(path
)));
1745 void RenderViewImpl::FrameDidStartLoading(WebFrame
* frame
) {
1746 DCHECK_GE(frames_in_progress_
, 0);
1747 if (frames_in_progress_
== 0)
1748 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidStartLoading());
1749 frames_in_progress_
++;
1752 void RenderViewImpl::FrameDidStopLoading(WebFrame
* frame
) {
1753 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1754 // calls DidStopLoading() without a matching DidStartLoading().
1755 if (frames_in_progress_
== 0)
1757 frames_in_progress_
--;
1758 if (frames_in_progress_
== 0) {
1759 DidStopLoadingIcons();
1760 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidStopLoading());
1764 void RenderViewImpl::didCancelCompositionOnSelectionChange() {
1765 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1768 bool RenderViewImpl::handleCurrentKeyboardEvent() {
1769 if (edit_commands_
.empty())
1772 WebFrame
* frame
= webview()->focusedFrame();
1776 EditCommands::iterator it
= edit_commands_
.begin();
1777 EditCommands::iterator end
= edit_commands_
.end();
1779 bool did_execute_command
= false;
1780 for (; it
!= end
; ++it
) {
1781 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1782 // key (but it's the exception). Once one edit command is not executed, it
1783 // seems safest to not execute the rest.
1784 if (!frame
->executeCommand(WebString::fromUTF8(it
->name
),
1785 WebString::fromUTF8(it
->value
),
1786 GetFocusedElement()))
1788 did_execute_command
= true;
1791 return did_execute_command
;
1794 bool RenderViewImpl::runFileChooser(
1795 const blink::WebFileChooserParams
& params
,
1796 WebFileChooserCompletion
* chooser_completion
) {
1797 // Do not open the file dialog in a hidden RenderView.
1800 FileChooserParams ipc_params
;
1801 if (params
.directory
)
1802 ipc_params
.mode
= FileChooserParams::UploadFolder
;
1803 else if (params
.multiSelect
)
1804 ipc_params
.mode
= FileChooserParams::OpenMultiple
;
1805 else if (params
.saveAs
)
1806 ipc_params
.mode
= FileChooserParams::Save
;
1808 ipc_params
.mode
= FileChooserParams::Open
;
1809 ipc_params
.title
= params
.title
;
1810 ipc_params
.default_file_name
=
1811 base::FilePath::FromUTF16Unsafe(params
.initialValue
);
1812 ipc_params
.accept_types
.reserve(params
.acceptTypes
.size());
1813 for (size_t i
= 0; i
< params
.acceptTypes
.size(); ++i
)
1814 ipc_params
.accept_types
.push_back(params
.acceptTypes
[i
]);
1815 #if defined(OS_ANDROID)
1816 ipc_params
.capture
= params
.useMediaCapture
;
1819 return ScheduleFileChooser(ipc_params
, chooser_completion
);
1822 void RenderViewImpl::showValidationMessage(
1823 const blink::WebRect
& anchor_in_root_view
,
1824 const blink::WebString
& main_text
,
1825 const blink::WebString
& sub_text
,
1826 blink::WebTextDirection hint
) {
1827 base::string16 wrapped_main_text
= main_text
;
1828 base::string16 wrapped_sub_text
= sub_text
;
1829 if (hint
== blink::WebTextDirectionLeftToRight
) {
1831 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text
);
1832 if (!wrapped_sub_text
.empty()) {
1834 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text
);
1836 } else if (hint
== blink::WebTextDirectionRightToLeft
1837 && !base::i18n::IsRTL()) {
1838 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text
);
1839 if (!wrapped_sub_text
.empty()) {
1840 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text
);
1843 Send(new ViewHostMsg_ShowValidationMessage(
1844 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view
),
1845 wrapped_main_text
, wrapped_sub_text
));
1848 void RenderViewImpl::hideValidationMessage() {
1849 Send(new ViewHostMsg_HideValidationMessage(routing_id()));
1852 void RenderViewImpl::moveValidationMessage(
1853 const blink::WebRect
& anchor_in_root_view
) {
1854 Send(new ViewHostMsg_MoveValidationMessage(
1855 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view
)));
1858 void RenderViewImpl::setStatusText(const WebString
& text
) {
1861 void RenderViewImpl::UpdateTargetURL(const GURL
& url
,
1862 const GURL
& fallback_url
) {
1863 GURL latest_url
= url
.is_empty() ? fallback_url
: url
;
1864 if (latest_url
== target_url_
)
1867 // Tell the browser to display a destination link.
1868 if (target_url_status_
== TARGET_INFLIGHT
||
1869 target_url_status_
== TARGET_PENDING
) {
1870 // If we have a request in-flight, save the URL to be sent when we
1871 // receive an ACK to the in-flight request. We can happily overwrite
1872 // any existing pending sends.
1873 pending_target_url_
= latest_url
;
1874 target_url_status_
= TARGET_PENDING
;
1876 // URLs larger than |MaxURLChars()| cannot be sent through IPC -
1877 // see |ParamTraits<GURL>|.
1878 if (latest_url
.possibly_invalid_spec().size() > GetMaxURLChars())
1879 latest_url
= GURL();
1880 Send(new ViewHostMsg_UpdateTargetURL(routing_id_
, page_id_
, latest_url
));
1881 target_url_
= latest_url
;
1882 target_url_status_
= TARGET_INFLIGHT
;
1886 gfx::RectF
RenderViewImpl::ClientRectToPhysicalWindowRect(
1887 const gfx::RectF
& rect
) const {
1888 gfx::RectF window_rect
= rect
;
1889 window_rect
.Scale(device_scale_factor_
* webview()->pageScaleFactor());
1893 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
1894 // No need to update state if no page has committed yet.
1899 if (send_content_state_immediately_
)
1901 else if (is_hidden())
1902 delay
= kDelaySecondsForContentStateSyncHidden
;
1904 delay
= kDelaySecondsForContentStateSync
;
1906 if (nav_state_sync_timer_
.IsRunning()) {
1907 // The timer is already running. If the delay of the timer maches the amount
1908 // we want to delay by, then return. Otherwise stop the timer so that it
1909 // gets started with the right delay.
1910 if (nav_state_sync_timer_
.GetCurrentDelay().InSeconds() == delay
)
1912 nav_state_sync_timer_
.Stop();
1915 nav_state_sync_timer_
.Start(FROM_HERE
, TimeDelta::FromSeconds(delay
), this,
1916 &RenderViewImpl::SyncNavigationState
);
1919 void RenderViewImpl::setMouseOverURL(const WebURL
& url
) {
1920 mouse_over_url_
= GURL(url
);
1921 UpdateTargetURL(mouse_over_url_
, focus_url_
);
1924 void RenderViewImpl::setKeyboardFocusURL(const WebURL
& url
) {
1925 focus_url_
= GURL(url
);
1926 UpdateTargetURL(focus_url_
, mouse_over_url_
);
1929 void RenderViewImpl::startDragging(WebLocalFrame
* frame
,
1930 const WebDragData
& data
,
1931 WebDragOperationsMask mask
,
1932 const WebImage
& image
,
1933 const WebPoint
& webImageOffset
) {
1934 DropData
drop_data(DropDataBuilder::Build(data
));
1935 drop_data
.referrer_policy
= frame
->document().referrerPolicy();
1936 gfx::Vector2d
imageOffset(webImageOffset
.x
, webImageOffset
.y
);
1937 Send(new DragHostMsg_StartDragging(routing_id_
,
1940 image
.getSkBitmap(),
1942 possible_drag_event_info_
));
1945 bool RenderViewImpl::acceptsLoadDrops() {
1946 return renderer_preferences_
.can_accept_load_drops
;
1949 void RenderViewImpl::focusNext() {
1950 Send(new ViewHostMsg_TakeFocus(routing_id_
, false));
1953 void RenderViewImpl::focusPrevious() {
1954 Send(new ViewHostMsg_TakeFocus(routing_id_
, true));
1957 void RenderViewImpl::focusedNodeChanged(const WebNode
& node
) {
1958 has_scrolled_focused_editable_node_into_rect_
= false;
1960 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_
, IsEditableNode(node
)));
1962 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, FocusedNodeChanged(node
));
1964 // TODO(dmazzoni): this should be part of RenderFrameObserver.
1965 main_render_frame()->FocusedNodeChanged(node
);
1968 void RenderViewImpl::didUpdateLayout() {
1969 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidUpdateLayout());
1971 // We don't always want to set up a timer, only if we've been put in that
1972 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1974 if (!send_preferred_size_changes_
|| !webview())
1977 if (check_preferred_size_timer_
.IsRunning())
1979 check_preferred_size_timer_
.Start(FROM_HERE
,
1980 TimeDelta::FromMilliseconds(0), this,
1981 &RenderViewImpl::CheckPreferredSize
);
1984 void RenderViewImpl::navigateBackForwardSoon(int offset
) {
1985 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_
, offset
));
1988 int RenderViewImpl::historyBackListCount() {
1989 return history_list_offset_
< 0 ? 0 : history_list_offset_
;
1992 int RenderViewImpl::historyForwardListCount() {
1993 return history_list_length_
- historyBackListCount() - 1;
1996 void RenderViewImpl::postAccessibilityEvent(
1997 const WebAXObject
& obj
, blink::WebAXEvent event
) {
1998 main_render_frame()->HandleWebAccessibilityEvent(obj
, event
);
2001 // blink::WebWidgetClient ----------------------------------------------------
2003 void RenderViewImpl::didFocus() {
2004 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2005 // we won't have to test for user gesture anymore and we can
2006 // move that code back to render_widget.cc
2007 if (WebUserGestureIndicator::isProcessingUserGesture() &&
2008 !RenderThreadImpl::current()->layout_test_mode()) {
2009 Send(new ViewHostMsg_Focus(routing_id_
));
2013 void RenderViewImpl::didBlur() {
2014 // TODO(jcivelli): see TODO above in didFocus().
2015 if (WebUserGestureIndicator::isProcessingUserGesture() &&
2016 !RenderThreadImpl::current()->layout_test_mode()) {
2017 Send(new ViewHostMsg_Blur(routing_id_
));
2021 // We are supposed to get a single call to Show for a newly created RenderView
2022 // that was created via RenderViewImpl::CreateWebView. So, we wait until this
2023 // point to dispatch the ShowView message.
2025 // This method provides us with the information about how to display the newly
2026 // created RenderView (i.e., as a blocked popup or as a new tab).
2028 void RenderViewImpl::show(WebNavigationPolicy policy
) {
2030 // When supports_multiple_windows is disabled, popups are reusing
2031 // the same view. In some scenarios, this makes WebKit to call show() twice.
2032 if (webkit_preferences_
.supports_multiple_windows
)
2033 NOTREACHED() << "received extraneous Show call";
2038 DCHECK(opener_id_
!= MSG_ROUTING_NONE
);
2040 // Force new windows to a popup if they were not opened with a user gesture.
2041 if (!opened_by_user_gesture_
) {
2042 // We exempt background tabs for compat with older versions of Chrome.
2043 // TODO(darin): This seems bogus. These should have a user gesture, so
2044 // we probably don't need this check.
2045 if (policy
!= blink::WebNavigationPolicyNewBackgroundTab
)
2046 policy
= blink::WebNavigationPolicyNewPopup
;
2049 // NOTE: initial_pos_ may still have its default values at this point, but
2050 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2051 // browser process will impose a default position otherwise.
2052 Send(new ViewHostMsg_ShowView(opener_id_
, routing_id_
,
2053 NavigationPolicyToDisposition(policy
), initial_pos_
,
2054 opened_by_user_gesture_
));
2055 SetPendingWindowRect(initial_pos_
);
2058 void RenderViewImpl::runModal() {
2059 DCHECK(did_show_
) << "should already have shown the view";
2061 // Don't allow further dialogs if we are waiting to swap out, since the
2062 // PageGroupLoadDeferrer in our stack prevents it.
2063 if (suppress_dialogs_until_swap_out_
)
2066 // We must keep WebKit's shared timer running in this case in order to allow
2067 // showModalDialog to function properly.
2069 // TODO(darin): WebKit should really be smarter about suppressing events and
2070 // timers so that we do not need to manage the shared timer in such a heavy
2073 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2074 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
2076 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2077 routing_id_
, opener_id_
));
2080 bool RenderViewImpl::enterFullScreen() {
2081 Send(new ViewHostMsg_ToggleFullscreen(routing_id_
, true));
2085 void RenderViewImpl::exitFullScreen() {
2086 Send(new ViewHostMsg_ToggleFullscreen(routing_id_
, false));
2089 bool RenderViewImpl::requestPointerLock() {
2090 return mouse_lock_dispatcher_
->LockMouse(webwidget_mouse_lock_target_
.get());
2093 void RenderViewImpl::requestPointerUnlock() {
2094 mouse_lock_dispatcher_
->UnlockMouse(webwidget_mouse_lock_target_
.get());
2097 bool RenderViewImpl::isPointerLocked() {
2098 return mouse_lock_dispatcher_
->IsMouseLockedTo(
2099 webwidget_mouse_lock_target_
.get());
2102 void RenderViewImpl::didHandleGestureEvent(
2103 const WebGestureEvent
& event
,
2104 bool event_cancelled
) {
2105 RenderWidget::didHandleGestureEvent(event
, event_cancelled
);
2107 if (!event_cancelled
) {
2109 RenderViewObserver
, observers_
, DidHandleGestureEvent(event
));
2112 if (event
.type
!= blink::WebGestureEvent::GestureTap
)
2115 // TODO(estade): hit test the event against focused node to make sure
2116 // the tap actually hit the focused node.
2117 blink::WebTextInputType text_input_type
=
2118 GetWebView()->textInputInfo().type
;
2120 Send(new ViewHostMsg_FocusedNodeTouched(
2121 routing_id(), text_input_type
!= blink::WebTextInputTypeNone
));
2124 void RenderViewImpl::initializeLayerTreeView() {
2125 RenderWidget::initializeLayerTreeView();
2126 RenderWidgetCompositor
* rwc
= compositor();
2129 if (webview() && webview()->devToolsAgent())
2130 webview()->devToolsAgent()->setLayerTreeId(rwc
->GetLayerTreeId());
2132 #if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
2133 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
2134 // render_thread may be NULL in tests.
2135 InputHandlerManager
* input_handler_manager
=
2136 render_thread
? render_thread
->input_handler_manager() : NULL
;
2137 if (input_handler_manager
) {
2138 input_handler_manager
->AddInputHandler(
2139 routing_id_
, rwc
->GetInputHandler(), AsWeakPtr());
2144 // blink::WebFrameClient -----------------------------------------------------
2146 void RenderViewImpl::Repaint(const gfx::Size
& size
) {
2150 void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string
& name
,
2151 const std::string
& value
) {
2152 EditCommands edit_commands
;
2153 edit_commands
.push_back(EditCommand(name
, value
));
2154 OnSetEditCommandsForNextKeyEvent(edit_commands
);
2157 void RenderViewImpl::ClearEditCommands() {
2158 edit_commands_
.clear();
2161 SSLStatus
RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame
* frame
) const {
2162 std::string security_info
;
2163 if (frame
&& frame
->dataSource())
2164 security_info
= frame
->dataSource()->response().securityInfo();
2166 SSLStatus ssl_status
;
2167 DeserializeSecurityInfo(security_info
,
2168 &ssl_status
.cert_id
,
2169 &ssl_status
.cert_status
,
2170 &ssl_status
.security_bits
,
2171 &ssl_status
.connection_status
,
2172 &ssl_status
.signed_certificate_timestamp_ids
);
2176 const std::string
& RenderViewImpl::GetAcceptLanguages() const {
2177 return renderer_preferences_
.accept_languages
;
2180 void RenderViewImpl::didCreateDataSource(WebLocalFrame
* frame
,
2181 WebDataSource
* ds
) {
2182 bool content_initiated
= !pending_navigation_params_
.get();
2184 // Make sure any previous redirect URLs end up in our new data source.
2185 if (pending_navigation_params_
.get()) {
2186 for (std::vector
<GURL
>::const_iterator i
=
2187 pending_navigation_params_
->redirects
.begin();
2188 i
!= pending_navigation_params_
->redirects
.end(); ++i
) {
2189 ds
->appendRedirect(*i
);
2193 DocumentState
* document_state
= DocumentState::FromDataSource(ds
);
2194 if (!document_state
) {
2195 document_state
= new DocumentState
;
2196 ds
->setExtraData(document_state
);
2197 if (!content_initiated
)
2198 PopulateDocumentStateFromPending(document_state
);
2201 // Carry over the user agent override flag, if it exists.
2202 if (content_initiated
&& webview() && webview()->mainFrame() &&
2203 webview()->mainFrame()->isWebLocalFrame() &&
2204 webview()->mainFrame()->dataSource()) {
2205 DocumentState
* old_document_state
=
2206 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2207 if (old_document_state
) {
2208 InternalDocumentStateData
* internal_data
=
2209 InternalDocumentStateData::FromDocumentState(document_state
);
2210 InternalDocumentStateData
* old_internal_data
=
2211 InternalDocumentStateData::FromDocumentState(old_document_state
);
2212 internal_data
->set_is_overriding_user_agent(
2213 old_internal_data
->is_overriding_user_agent());
2217 // The rest of RenderView assumes that a WebDataSource will always have a
2218 // non-null NavigationState.
2219 if (content_initiated
) {
2220 document_state
->set_navigation_state(
2221 NavigationState::CreateContentInitiated());
2223 document_state
->set_navigation_state(CreateNavigationStateFromPending());
2224 pending_navigation_params_
.reset();
2227 // DocumentState::referred_by_prefetcher_ is true if we are
2228 // navigating from a page that used prefetching using a link on that
2229 // page. We are early enough in the request process here that we
2230 // can still see the DocumentState of the previous page and set
2231 // this value appropriately.
2232 // TODO(gavinp): catch the important case of navigation in a new
2233 // renderer process.
2235 if (WebFrame
* old_frame
= webview()->mainFrame()) {
2236 const WebURLRequest
& original_request
= ds
->originalRequest();
2237 const GURL
referrer(
2238 original_request
.httpHeaderField(WebString::fromUTF8("Referer")));
2239 if (!referrer
.is_empty() && old_frame
->isWebLocalFrame() &&
2240 DocumentState::FromDataSource(old_frame
->dataSource())
2241 ->was_prefetcher()) {
2242 for (; old_frame
; old_frame
= old_frame
->traverseNext(false)) {
2243 WebDataSource
* old_frame_ds
= old_frame
->dataSource();
2244 if (old_frame_ds
&& referrer
== GURL(old_frame_ds
->request().url())) {
2245 document_state
->set_was_referred_by_prefetcher(true);
2253 if (content_initiated
) {
2254 const WebURLRequest
& request
= ds
->request();
2255 switch (request
.cachePolicy()) {
2256 case WebURLRequest::UseProtocolCachePolicy
: // normal load.
2257 document_state
->set_load_type(DocumentState::LINK_LOAD_NORMAL
);
2259 case WebURLRequest::ReloadIgnoringCacheData
: // reload.
2260 case WebURLRequest::ReloadBypassingCache
: // end-to-end reload.
2261 document_state
->set_load_type(DocumentState::LINK_LOAD_RELOAD
);
2263 case WebURLRequest::ReturnCacheDataElseLoad
: // allow stale data.
2264 document_state
->set_load_type(
2265 DocumentState::LINK_LOAD_CACHE_STALE_OK
);
2267 case WebURLRequest::ReturnCacheDataDontLoad
: // Don't re-post.
2268 document_state
->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY
);
2276 RenderViewObserver
, observers_
, DidCreateDataSource(frame
, ds
));
2279 void RenderViewImpl::PopulateDocumentStateFromPending(
2280 DocumentState
* document_state
) {
2281 const FrameMsg_Navigate_Params
& params
= *pending_navigation_params_
.get();
2282 document_state
->set_request_time(params
.request_time
);
2284 InternalDocumentStateData
* internal_data
=
2285 InternalDocumentStateData::FromDocumentState(document_state
);
2287 if (!params
.url
.SchemeIs(url::kJavaScriptScheme
) &&
2288 params
.navigation_type
== FrameMsg_Navigate_Type::RESTORE
) {
2289 // We're doing a load of a page that was restored from the last session. By
2290 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2291 // can result in stale data for pages that are set to expire. We explicitly
2292 // override that by setting the policy here so that as necessary we load
2293 // from the network.
2295 // TODO(davidben): Remove this in favor of passing a cache policy to the
2296 // loadHistoryItem call in OnNavigate. That requires not overloading
2297 // UseProtocolCachePolicy to mean both "normal load" and "determine cache
2298 // policy based on load type, etc".
2299 internal_data
->set_cache_policy_override(
2300 WebURLRequest::UseProtocolCachePolicy
);
2303 if (IsReload(params
))
2304 document_state
->set_load_type(DocumentState::RELOAD
);
2305 else if (params
.page_state
.IsValid())
2306 document_state
->set_load_type(DocumentState::HISTORY_LOAD
);
2308 document_state
->set_load_type(DocumentState::NORMAL_LOAD
);
2310 internal_data
->set_is_overriding_user_agent(params
.is_overriding_user_agent
);
2311 internal_data
->set_must_reset_scroll_and_scale_state(
2312 params
.navigation_type
==
2313 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL
);
2314 document_state
->set_can_load_local_resources(params
.can_load_local_resources
);
2317 NavigationState
* RenderViewImpl::CreateNavigationStateFromPending() {
2318 const FrameMsg_Navigate_Params
& params
= *pending_navigation_params_
.get();
2319 NavigationState
* navigation_state
= NULL
;
2321 // A navigation resulting from loading a javascript URL should not be treated
2322 // as a browser initiated event. Instead, we want it to look as if the page
2323 // initiated any load resulting from JS execution.
2324 if (!params
.url
.SchemeIs(url::kJavaScriptScheme
)) {
2325 navigation_state
= NavigationState::CreateBrowserInitiated(
2327 params
.pending_history_list_offset
,
2328 params
.should_clear_history_list
,
2330 navigation_state
->set_should_replace_current_entry(
2331 params
.should_replace_current_entry
);
2332 navigation_state
->set_transferred_request_child_id(
2333 params
.transferred_request_child_id
);
2334 navigation_state
->set_transferred_request_request_id(
2335 params
.transferred_request_request_id
);
2336 navigation_state
->set_allow_download(params
.allow_download
);
2337 navigation_state
->set_extra_headers(params
.extra_headers
);
2339 navigation_state
= NavigationState::CreateContentInitiated();
2341 return navigation_state
;
2344 void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine
& command_line
) {
2345 bool enable_viewport
=
2346 command_line
.HasSwitch(switches::kEnableViewport
) ||
2347 command_line
.HasSwitch(switches::kEnableViewportMeta
);
2349 // If viewport tag is enabled, then the WebKit side will take care
2350 // of setting the fixed layout size and page scale limits.
2351 if (enable_viewport
)
2354 // When navigating to a new page, reset the page scale factor to be 1.0.
2355 webview()->setInitialPageScaleOverride(1.f
);
2357 float maxPageScaleFactor
=
2358 command_line
.HasSwitch(switches::kEnablePinch
) ? 4.f
: 1.f
;
2359 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor
);
2362 void RenderViewImpl::didClearWindowObject(WebLocalFrame
* frame
) {
2364 RenderViewObserver
, observers_
, DidClearWindowObject(frame
));
2366 if (enabled_bindings_
& BINDINGS_POLICY_WEB_UI
)
2367 WebUIExtension::Install(frame
);
2369 if (enabled_bindings_
& BINDINGS_POLICY_STATS_COLLECTION
)
2370 StatsCollectionController::Install(frame
);
2372 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
2374 if (command_line
.HasSwitch(switches::kEnableSkiaBenchmarking
))
2375 SkiaBenchmarking::Install(frame
);
2377 if (command_line
.HasSwitch(switches::kEnableMemoryBenchmarking
))
2378 MemoryBenchmarkingExtension::Install(frame
);
2381 void RenderViewImpl::didChangeIcon(WebLocalFrame
* frame
,
2382 WebIconURL::Type icon_type
) {
2383 if (frame
->parent())
2386 if (!TouchEnabled() && icon_type
!= WebIconURL::TypeFavicon
)
2389 WebVector
<WebIconURL
> icon_urls
= frame
->iconURLs(icon_type
);
2390 std::vector
<FaviconURL
> urls
;
2391 for (size_t i
= 0; i
< icon_urls
.size(); i
++) {
2392 std::vector
<gfx::Size
> sizes
;
2393 ConvertToFaviconSizes(icon_urls
[i
].sizes(), &sizes
);
2394 urls
.push_back(FaviconURL(
2395 icon_urls
[i
].iconURL(), ToFaviconType(icon_urls
[i
].iconType()), sizes
));
2397 SendUpdateFaviconURL(urls
);
2400 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame
* frame
) {
2401 StartNavStateSyncTimerIfNecessary();
2404 void RenderViewImpl::CheckPreferredSize() {
2405 // We don't always want to send the change messages over IPC, only if we've
2406 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2408 if (!send_preferred_size_changes_
|| !webview())
2411 gfx::Size size
= webview()->contentsPreferredMinimumSize();
2413 // In the presence of zoom, these sizes are still reported as if unzoomed,
2414 // so we need to adjust.
2415 double zoom_factor
= ZoomLevelToZoomFactor(webview()->zoomLevel());
2416 size
.set_width(static_cast<int>(size
.width() * zoom_factor
));
2417 size
.set_height(static_cast<int>(size
.height() * zoom_factor
));
2419 if (size
== preferred_size_
)
2422 preferred_size_
= size
;
2423 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_
,
2427 BrowserPluginManager
* RenderViewImpl::GetBrowserPluginManager() {
2428 if (!browser_plugin_manager_
.get())
2429 browser_plugin_manager_
= BrowserPluginManager::Create(this);
2430 return browser_plugin_manager_
.get();
2433 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame
* frame
) {
2434 StartNavStateSyncTimerIfNecessary();
2437 RenderViewObserver
, observers_
, DidChangeScrollOffset(frame
));
2440 void RenderViewImpl::SendFindReply(int request_id
,
2443 const WebRect
& selection_rect
,
2444 bool final_status_update
) {
2445 Send(new ViewHostMsg_Find_Reply(routing_id_
,
2450 final_status_update
));
2453 blink::WebString
RenderViewImpl::acceptLanguages() {
2454 return WebString::fromUTF8(renderer_preferences_
.accept_languages
);
2457 // blink::WebPageSerializerClient implementation ------------------------------
2459 void RenderViewImpl::didSerializeDataForFrame(
2460 const WebURL
& frame_url
,
2461 const WebCString
& data
,
2462 WebPageSerializerClient::PageSerializationStatus status
) {
2463 Send(new ViewHostMsg_SendSerializedHtmlData(
2467 static_cast<int32
>(status
)));
2470 // RenderView implementation ---------------------------------------------------
2472 bool RenderViewImpl::Send(IPC::Message
* message
) {
2473 return RenderWidget::Send(message
);
2476 RenderFrame
* RenderViewImpl::GetMainRenderFrame() {
2477 return main_render_frame_
.get();
2480 int RenderViewImpl::GetRoutingID() const {
2484 gfx::Size
RenderViewImpl::GetSize() const {
2488 WebPreferences
& RenderViewImpl::GetWebkitPreferences() {
2489 return webkit_preferences_
;
2492 void RenderViewImpl::SetWebkitPreferences(const WebPreferences
& preferences
) {
2493 OnUpdateWebPreferences(preferences
);
2496 blink::WebView
* RenderViewImpl::GetWebView() {
2500 blink::WebElement
RenderViewImpl::GetFocusedElement() const {
2502 return WebElement();
2503 WebFrame
* focused_frame
= webview()->focusedFrame();
2504 if (focused_frame
) {
2505 WebDocument doc
= focused_frame
->document();
2507 return doc
.focusedElement();
2510 return WebElement();
2513 bool RenderViewImpl::IsEditableNode(const WebNode
& node
) const {
2517 if (node
.isContentEditable())
2520 if (node
.isElementNode()) {
2521 const WebElement
& element
= node
.toConst
<WebElement
>();
2522 if (element
.isTextFormControlElement())
2525 // Also return true if it has an ARIA role of 'textbox'.
2526 for (unsigned i
= 0; i
< element
.attributeCount(); ++i
) {
2527 if (LowerCaseEqualsASCII(element
.attributeLocalName(i
), "role")) {
2528 if (LowerCaseEqualsASCII(element
.attributeValue(i
), "textbox"))
2538 bool RenderViewImpl::NodeContainsPoint(const WebNode
& node
,
2539 const gfx::Point
& point
) const {
2540 blink::WebHitTestResult hit_test
=
2541 webview()->hitTestResultAt(WebPoint(point
.x(), point
.y()));
2542 return node
.containsIncludingShadowDOM(hit_test
.node());
2545 bool RenderViewImpl::ShouldDisplayScrollbars(int width
, int height
) const {
2546 return (!send_preferred_size_changes_
||
2547 (disable_scrollbars_size_limit_
.width() <= width
||
2548 disable_scrollbars_size_limit_
.height() <= height
));
2551 int RenderViewImpl::GetEnabledBindings() const {
2552 return enabled_bindings_
;
2555 bool RenderViewImpl::GetContentStateImmediately() const {
2556 return send_content_state_immediately_
;
2559 blink::WebPageVisibilityState
RenderViewImpl::GetVisibilityState() const {
2560 return visibilityState();
2563 void RenderViewImpl::DidStartLoading() {
2564 main_render_frame_
->didStartLoading(true);
2567 void RenderViewImpl::DidStopLoading() {
2568 main_render_frame_
->didStopLoading();
2571 void RenderViewImpl::SyncNavigationState() {
2574 SendUpdateState(history_controller_
->GetCurrentEntry());
2577 blink::WebPlugin
* RenderViewImpl::GetWebPluginForFind() {
2581 WebFrame
* main_frame
= webview()->mainFrame();
2582 if (main_frame
->isWebLocalFrame() &&
2583 main_frame
->document().isPluginDocument())
2584 return webview()->mainFrame()->document().to
<WebPluginDocument
>().plugin();
2586 #if defined(ENABLE_PLUGINS)
2587 if (plugin_find_handler_
)
2588 return plugin_find_handler_
->container()->plugin();
2594 void RenderViewImpl::OnFind(int request_id
,
2595 const base::string16
& search_text
,
2596 const WebFindOptions
& options
) {
2597 WebFrame
* main_frame
= webview()->mainFrame();
2598 blink::WebPlugin
* plugin
= GetWebPluginForFind();
2599 // Check if the plugin still exists in the document.
2601 if (options
.findNext
) {
2602 // Just navigate back/forward.
2603 plugin
->selectFindResult(options
.forward
);
2605 if (!plugin
->startFind(
2606 search_text
, options
.matchCase
, request_id
)) {
2607 // Send "no results".
2608 SendFindReply(request_id
, 0, 0, gfx::Rect(), true);
2614 WebFrame
* frame_after_main
= main_frame
->traverseNext(true);
2615 WebFrame
* focused_frame
= webview()->focusedFrame();
2616 WebFrame
* search_frame
= focused_frame
; // start searching focused frame.
2618 bool multi_frame
= (frame_after_main
!= main_frame
);
2620 // If we have multiple frames, we don't want to wrap the search within the
2621 // frame, so we check here if we only have main_frame in the chain.
2622 bool wrap_within_frame
= !multi_frame
;
2624 WebRect selection_rect
;
2625 bool result
= false;
2627 // If something is selected when we start searching it means we cannot just
2628 // increment the current match ordinal; we need to re-generate it.
2629 WebRange current_selection
= focused_frame
->selectionRange();
2632 result
= search_frame
->find(
2633 request_id
, search_text
, options
, wrap_within_frame
, &selection_rect
);
2636 // don't leave text selected as you move to the next frame.
2637 search_frame
->executeCommand(WebString::fromUTF8("Unselect"),
2638 GetFocusedElement());
2640 // Find the next frame, but skip the invisible ones.
2642 // What is the next frame to search? (we might be going backwards). Note
2643 // that we specify wrap=true so that search_frame never becomes NULL.
2644 search_frame
= options
.forward
?
2645 search_frame
->traverseNext(true) :
2646 search_frame
->traversePrevious(true);
2647 } while (!search_frame
->hasVisibleContent() &&
2648 search_frame
!= focused_frame
);
2650 // Make sure selection doesn't affect the search operation in new frame.
2651 search_frame
->executeCommand(WebString::fromUTF8("Unselect"),
2652 GetFocusedElement());
2654 // If we have multiple frames and we have wrapped back around to the
2655 // focused frame, we need to search it once more allowing wrap within
2656 // the frame, otherwise it will report 'no match' if the focused frame has
2657 // reported matches, but no frames after the focused_frame contain a
2658 // match for the search word(s).
2659 if (multi_frame
&& search_frame
== focused_frame
) {
2660 result
= search_frame
->find(
2661 request_id
, search_text
, options
, true, // Force wrapping.
2666 webview()->setFocusedFrame(search_frame
);
2667 } while (!result
&& search_frame
!= focused_frame
);
2669 if (options
.findNext
&& current_selection
.isNull()) {
2670 // Force the main_frame to report the actual count.
2671 main_frame
->increaseMatchCount(0, request_id
);
2673 // If nothing is found, set result to "0 of 0", otherwise, set it to
2674 // "-1 of 1" to indicate that we found at least one item, but we don't know
2675 // yet what is active.
2676 int ordinal
= result
? -1 : 0; // -1 here means, we might know more later.
2677 int match_count
= result
? 1 : 0; // 1 here means possibly more coming.
2679 // If we find no matches then this will be our last status update.
2680 // Otherwise the scoping effort will send more results.
2681 bool final_status_update
= !result
;
2683 SendFindReply(request_id
, match_count
, ordinal
, selection_rect
,
2684 final_status_update
);
2686 // Scoping effort begins, starting with the mainframe.
2687 search_frame
= main_frame
;
2689 main_frame
->resetMatchCount();
2692 // Cancel all old scoping requests before starting a new one.
2693 search_frame
->cancelPendingScopingEffort();
2695 // We don't start another scoping effort unless at least one match has
2698 // Start new scoping request. If the scoping function determines that it
2699 // needs to scope, it will defer until later.
2700 search_frame
->scopeStringMatches(request_id
,
2703 true); // reset the tickmarks
2706 // Iterate to the next frame. The frame will not necessarily scope, for
2707 // example if it is not visible.
2708 search_frame
= search_frame
->traverseNext(true);
2709 } while (search_frame
!= main_frame
);
2713 void RenderViewImpl::OnStopFinding(StopFindAction action
) {
2714 WebView
* view
= webview();
2718 blink::WebPlugin
* plugin
= GetWebPluginForFind();
2724 bool clear_selection
= action
== STOP_FIND_ACTION_CLEAR_SELECTION
;
2725 if (clear_selection
) {
2726 view
->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
2727 GetFocusedElement());
2730 WebFrame
* frame
= view
->mainFrame();
2732 frame
->stopFinding(clear_selection
);
2733 frame
= frame
->traverseNext(false);
2736 if (action
== STOP_FIND_ACTION_ACTIVATE_SELECTION
) {
2737 WebFrame
* focused_frame
= view
->focusedFrame();
2738 if (focused_frame
) {
2739 WebDocument doc
= focused_frame
->document();
2740 if (!doc
.isNull()) {
2741 WebElement element
= doc
.focusedElement();
2742 if (!element
.isNull())
2743 element
.simulateClick();
2749 #if defined(OS_ANDROID)
2750 void RenderViewImpl::OnActivateNearestFindResult(int request_id
,
2755 WebFrame
* main_frame
= webview()->mainFrame();
2756 WebRect selection_rect
;
2757 int ordinal
= main_frame
->selectNearestFindMatch(WebFloatPoint(x
, y
),
2759 if (ordinal
== -1) {
2760 // Something went wrong, so send a no-op reply (force the main_frame to
2761 // report the current match count) in case the host is waiting for a
2762 // response due to rate-limiting).
2763 main_frame
->increaseMatchCount(0, request_id
);
2767 SendFindReply(request_id
,
2768 -1 /* number_of_matches */,
2771 true /* final_update */);
2774 void RenderViewImpl::OnFindMatchRects(int current_version
) {
2778 WebFrame
* main_frame
= webview()->mainFrame();
2779 std::vector
<gfx::RectF
> match_rects
;
2781 int rects_version
= main_frame
->findMatchMarkersVersion();
2782 if (current_version
!= rects_version
) {
2783 WebVector
<WebFloatRect
> web_match_rects
;
2784 main_frame
->findMatchRects(web_match_rects
);
2785 match_rects
.reserve(web_match_rects
.size());
2786 for (size_t i
= 0; i
< web_match_rects
.size(); ++i
)
2787 match_rects
.push_back(gfx::RectF(web_match_rects
[i
]));
2790 gfx::RectF active_rect
= main_frame
->activeFindMatchRect();
2791 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_
,
2798 void RenderViewImpl::OnZoom(PageZoom zoom
) {
2799 if (!webview()) // Not sure if this can happen, but no harm in being safe.
2802 webview()->hidePopups();
2804 double old_zoom_level
= webview()->zoomLevel();
2806 if (zoom
== PAGE_ZOOM_RESET
) {
2808 } else if (static_cast<int>(old_zoom_level
) == old_zoom_level
) {
2809 // Previous zoom level is a whole number, so just increment/decrement.
2810 zoom_level
= old_zoom_level
+ zoom
;
2812 // Either the user hit the zoom factor limit and thus the zoom level is now
2813 // not a whole number, or a plugin changed it to a custom value. We want
2814 // to go to the next whole number so that the user can always get back to
2815 // 100% with the keyboard/menu.
2816 if ((old_zoom_level
> 1 && zoom
> 0) ||
2817 (old_zoom_level
< 1 && zoom
< 0)) {
2818 zoom_level
= static_cast<int>(old_zoom_level
+ zoom
);
2820 // We're going towards 100%, so first go to the next whole number.
2821 zoom_level
= static_cast<int>(old_zoom_level
);
2824 webview()->setZoomLevel(zoom_level
);
2828 void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL
& url
,
2829 double zoom_level
) {
2830 #if !defined(OS_ANDROID)
2831 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
2832 // for legacy WebView text scaling emulation. Thus, the code that resets
2833 // the zoom level from this map will be effectively resetting text zoom level.
2834 host_zoom_levels_
[url
] = zoom_level
;
2838 void RenderViewImpl::OnSetZoomLevelForView(bool uses_temporary_zoom_level
,
2840 uses_temporary_zoom_level_
= uses_temporary_zoom_level
;
2842 webview()->hidePopups();
2843 webview()->setZoomLevel(level
);
2846 void RenderViewImpl::OnSetPageEncoding(const std::string
& encoding_name
) {
2847 webview()->setPageEncoding(WebString::fromUTF8(encoding_name
));
2850 void RenderViewImpl::OnResetPageEncodingToDefault() {
2851 WebString no_encoding
;
2852 webview()->setPageEncoding(no_encoding
);
2855 void RenderViewImpl::OnPostMessageEvent(
2856 const ViewMsg_PostMessage_Params
& params
) {
2857 // TODO(nasko): Support sending to subframes.
2858 WebFrame
* frame
= webview()->mainFrame();
2860 // Find the source frame if it exists.
2861 WebFrame
* source_frame
= NULL
;
2862 if (params
.source_routing_id
!= MSG_ROUTING_NONE
) {
2863 RenderViewImpl
* source_view
= FromRoutingID(params
.source_routing_id
);
2865 source_frame
= source_view
->webview()->mainFrame();
2868 // If the message contained MessagePorts, create the corresponding endpoints.
2869 DCHECK_EQ(params
.message_port_ids
.size(), params
.new_routing_ids
.size());
2870 blink::WebMessagePortChannelArray
channels(params
.message_port_ids
.size());
2872 i
< params
.message_port_ids
.size() && i
< params
.new_routing_ids
.size();
2875 new WebMessagePortChannelImpl(params
.new_routing_ids
[i
],
2876 params
.message_port_ids
[i
],
2877 base::MessageLoopProxy::current().get());
2880 WebSerializedScriptValue serialized_script_value
;
2881 if (params
.is_data_raw_string
) {
2882 v8::HandleScope
handle_scope(blink::mainThreadIsolate());
2883 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
2884 v8::Context::Scope
context_scope(context
);
2885 V8ValueConverterImpl converter
;
2886 converter
.SetDateAllowed(true);
2887 converter
.SetRegExpAllowed(true);
2888 scoped_ptr
<base::Value
> value(new base::StringValue(params
.data
));
2889 v8::Handle
<v8::Value
> result_value
= converter
.ToV8Value(value
.get(),
2891 serialized_script_value
= WebSerializedScriptValue::serialize(result_value
);
2893 serialized_script_value
= WebSerializedScriptValue::fromString(params
.data
);
2896 // Create an event with the message. The final parameter to initMessageEvent
2897 // is the last event ID, which is not used with postMessage.
2898 WebDOMEvent event
= frame
->document().createEvent("MessageEvent");
2899 WebDOMMessageEvent msg_event
= event
.to
<WebDOMMessageEvent
>();
2900 msg_event
.initMessageEvent("message",
2901 // |canBubble| and |cancellable| are always false
2903 serialized_script_value
,
2904 params
.source_origin
, source_frame
, "", channels
);
2906 // We must pass in the target_origin to do the security check on this side,
2907 // since it may have changed since the original postMessage call was made.
2908 WebSecurityOrigin target_origin
;
2909 if (!params
.target_origin
.empty()) {
2911 WebSecurityOrigin::createFromString(WebString(params
.target_origin
));
2913 frame
->dispatchMessageEventWithOriginCheck(target_origin
, msg_event
);
2916 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags
) {
2917 if ((enabled_bindings_flags
& BINDINGS_POLICY_WEB_UI
) &&
2918 !(enabled_bindings_
& BINDINGS_POLICY_WEB_UI
)) {
2919 // WebUIExtensionData deletes itself when we're destroyed.
2920 new WebUIExtensionData(this);
2921 // WebUIMojo deletes itself when we're destroyed.
2922 new WebUIMojo(this);
2925 enabled_bindings_
|= enabled_bindings_flags
;
2927 // Keep track of the total bindings accumulated in this process.
2928 RenderProcess::current()->AddBindings(enabled_bindings_flags
);
2931 void RenderViewImpl::OnDragTargetDragEnter(const DropData
& drop_data
,
2932 const gfx::Point
& client_point
,
2933 const gfx::Point
& screen_point
,
2934 WebDragOperationsMask ops
,
2935 int key_modifiers
) {
2936 WebDragOperation operation
= webview()->dragTargetDragEnter(
2937 DropDataToWebDragData(drop_data
),
2943 Send(new DragHostMsg_UpdateDragCursor(routing_id_
, operation
));
2946 void RenderViewImpl::OnDragTargetDragOver(const gfx::Point
& client_point
,
2947 const gfx::Point
& screen_point
,
2948 WebDragOperationsMask ops
,
2949 int key_modifiers
) {
2950 WebDragOperation operation
= webview()->dragTargetDragOver(
2956 Send(new DragHostMsg_UpdateDragCursor(routing_id_
, operation
));
2959 void RenderViewImpl::OnDragTargetDragLeave() {
2960 webview()->dragTargetDragLeave();
2963 void RenderViewImpl::OnDragTargetDrop(const gfx::Point
& client_point
,
2964 const gfx::Point
& screen_point
,
2965 int key_modifiers
) {
2966 webview()->dragTargetDrop(client_point
, screen_point
, key_modifiers
);
2968 Send(new DragHostMsg_TargetDrop_ACK(routing_id_
));
2971 void RenderViewImpl::OnDragSourceEnded(const gfx::Point
& client_point
,
2972 const gfx::Point
& screen_point
,
2973 WebDragOperation op
) {
2974 webview()->dragSourceEndedAt(client_point
, screen_point
, op
);
2977 void RenderViewImpl::OnDragSourceSystemDragEnded() {
2978 webview()->dragSourceSystemDragEnded();
2981 void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences
& prefs
) {
2982 webkit_preferences_
= prefs
;
2983 ApplyWebPreferences(webkit_preferences_
, webview());
2986 void RenderViewImpl::OnEnumerateDirectoryResponse(
2988 const std::vector
<base::FilePath
>& paths
) {
2989 if (!enumeration_completions_
[id
])
2992 WebVector
<WebString
> ws_file_names(paths
.size());
2993 for (size_t i
= 0; i
< paths
.size(); ++i
)
2994 ws_file_names
[i
] = paths
[i
].AsUTF16Unsafe();
2996 enumeration_completions_
[id
]->didChooseFile(ws_file_names
);
2997 enumeration_completions_
.erase(id
);
3000 void RenderViewImpl::OnFileChooserResponse(
3001 const std::vector
<ui::SelectedFileInfo
>& files
) {
3002 // This could happen if we navigated to a different page before the user
3003 // closed the chooser.
3004 if (file_chooser_completions_
.empty())
3007 // Convert Chrome's SelectedFileInfo list to WebKit's.
3008 WebVector
<WebFileChooserCompletion::SelectedFileInfo
> selected_files(
3010 for (size_t i
= 0; i
< files
.size(); ++i
) {
3011 WebFileChooserCompletion::SelectedFileInfo selected_file
;
3012 selected_file
.path
= files
[i
].local_path
.AsUTF16Unsafe();
3013 selected_file
.displayName
=
3014 base::FilePath(files
[i
].display_name
).AsUTF16Unsafe();
3015 selected_files
[i
] = selected_file
;
3018 if (file_chooser_completions_
.front()->completion
)
3019 file_chooser_completions_
.front()->completion
->didChooseFile(
3021 file_chooser_completions_
.pop_front();
3023 // If there are more pending file chooser requests, schedule one now.
3024 if (!file_chooser_completions_
.empty()) {
3025 Send(new ViewHostMsg_RunFileChooser(routing_id_
,
3026 file_chooser_completions_
.front()->params
));
3030 void RenderViewImpl::OnEnableAutoResize(const gfx::Size
& min_size
,
3031 const gfx::Size
& max_size
) {
3032 DCHECK(disable_scrollbars_size_limit_
.IsEmpty());
3035 auto_resize_mode_
= true;
3036 webview()->enableAutoResizeMode(min_size
, max_size
);
3039 void RenderViewImpl::OnDisableAutoResize(const gfx::Size
& new_size
) {
3040 DCHECK(disable_scrollbars_size_limit_
.IsEmpty());
3043 auto_resize_mode_
= false;
3044 webview()->disableAutoResizeMode();
3046 if (!new_size
.IsEmpty()) {
3048 physical_backing_size_
,
3049 top_controls_layout_height_
,
3050 visible_viewport_size_
,
3057 void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
3058 if (send_preferred_size_changes_
)
3060 send_preferred_size_changes_
= true;
3062 // Start off with an initial preferred size notification (in case
3063 // |didUpdateLayout| was already called).
3067 void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
3068 const gfx::Size
& disable_scrollbar_size_limit
) {
3069 disable_scrollbars_size_limit_
= disable_scrollbar_size_limit
;
3072 void RenderViewImpl::OnSetRendererPrefs(
3073 const RendererPreferences
& renderer_prefs
) {
3074 double old_zoom_level
= renderer_preferences_
.default_zoom_level
;
3075 std::string old_accept_languages
= renderer_preferences_
.accept_languages
;
3077 renderer_preferences_
= renderer_prefs
;
3078 UpdateFontRenderingFromRendererPrefs();
3080 #if defined(USE_DEFAULT_RENDER_THEME)
3081 if (renderer_prefs
.use_custom_colors
) {
3082 WebColorName name
= blink::WebColorWebkitFocusRingColor
;
3083 blink::setNamedColors(&name
, &renderer_prefs
.focus_ring_color
, 1);
3084 blink::setCaretBlinkInterval(renderer_prefs
.caret_blink_interval
);
3087 webview()->setSelectionColors(
3088 renderer_prefs
.active_selection_bg_color
,
3089 renderer_prefs
.active_selection_fg_color
,
3090 renderer_prefs
.inactive_selection_bg_color
,
3091 renderer_prefs
.inactive_selection_fg_color
);
3092 webview()->themeChanged();
3095 #endif // defined(USE_DEFAULT_RENDER_THEME)
3097 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3098 RenderThreadImpl::current()->SetFlingCurveParameters(
3099 renderer_prefs
.touchpad_fling_profile
,
3100 renderer_prefs
.touchscreen_fling_profile
);
3102 // If the zoom level for this page matches the old zoom default, and this
3103 // is not a plugin, update the zoom level to match the new default.
3104 if (webview() && webview()->mainFrame()->isWebLocalFrame() &&
3105 !webview()->mainFrame()->document().isPluginDocument() &&
3106 !ZoomValuesEqual(old_zoom_level
,
3107 renderer_preferences_
.default_zoom_level
) &&
3108 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level
)) {
3109 webview()->setZoomLevel(renderer_preferences_
.default_zoom_level
);
3114 old_accept_languages
!= renderer_preferences_
.accept_languages
) {
3115 webview()->acceptLanguagesChanged();
3119 void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point
& location
,
3120 const WebMediaPlayerAction
& action
) {
3122 webview()->performMediaPlayerAction(action
, location
);
3125 void RenderViewImpl::OnOrientationChange() {
3126 // TODO(mlamouri): consumers of that event should be using DisplayObserver.
3127 FOR_EACH_OBSERVER(RenderViewObserver
,
3129 OrientationChangeEvent());
3131 webview()->mainFrame()->sendOrientationChangeEvent();
3134 void RenderViewImpl::OnPluginActionAt(const gfx::Point
& location
,
3135 const WebPluginAction
& action
) {
3137 webview()->performPluginAction(action
, location
);
3140 void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
3141 const GURL
& page_url
) {
3142 // Prepare list to storage all savable resource links.
3143 std::vector
<GURL
> resources_list
;
3144 std::vector
<GURL
> referrer_urls_list
;
3145 std::vector
<blink::WebReferrerPolicy
> referrer_policies_list
;
3146 std::vector
<GURL
> frames_list
;
3147 SavableResourcesResult
result(&resources_list
,
3148 &referrer_urls_list
,
3149 &referrer_policies_list
,
3152 // webkit/ doesn't know about Referrer.
3153 if (!GetAllSavableResourceLinksForCurrentPage(
3157 const_cast<const char**>(GetSavableSchemes()))) {
3158 // If something is wrong when collecting all savable resource links,
3159 // send empty list to embedder(browser) to tell it failed.
3160 referrer_urls_list
.clear();
3161 referrer_policies_list
.clear();
3162 resources_list
.clear();
3163 frames_list
.clear();
3166 std::vector
<Referrer
> referrers_list
;
3167 CHECK_EQ(referrer_urls_list
.size(), referrer_policies_list
.size());
3168 for (unsigned i
= 0; i
< referrer_urls_list
.size(); ++i
) {
3169 referrers_list
.push_back(
3170 Referrer(referrer_urls_list
[i
], referrer_policies_list
[i
]));
3173 // Send result of all savable resource links to embedder.
3174 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3180 void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3181 const std::vector
<GURL
>& links
,
3182 const std::vector
<base::FilePath
>& local_paths
,
3183 const base::FilePath
& local_directory_name
) {
3185 // Convert std::vector of GURLs to WebVector<WebURL>
3186 WebVector
<WebURL
> weburl_links(links
);
3188 // Convert std::vector of base::FilePath to WebVector<WebString>
3189 WebVector
<WebString
> webstring_paths(local_paths
.size());
3190 for (size_t i
= 0; i
< local_paths
.size(); i
++)
3191 webstring_paths
[i
] = local_paths
[i
].AsUTF16Unsafe();
3193 WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(),
3198 local_directory_name
.AsUTF16Unsafe());
3201 void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
3202 // Don't show any more dialogs until we finish OnSwapOut.
3203 suppress_dialogs_until_swap_out_
= true;
3206 void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame
* frame
) {
3207 // We use loadRequest instead of loadHTMLString because the former commits
3208 // synchronously. Otherwise a new navigation can interrupt the navigation
3209 // to kSwappedOutURL. If that happens to be to the page we had been
3210 // showing, then WebKit will never send a commit and we'll be left spinning.
3211 // TODO(creis): Until we move this to RenderFrame, we may call this from a
3212 // swapped out RenderFrame while our own is_swapped_out_ is false.
3213 RenderFrameImpl
* rf
= RenderFrameImpl::FromWebFrame(frame
);
3214 CHECK(is_swapped_out_
|| rf
->is_swapped_out());
3215 GURL
swappedOutURL(kSwappedOutURL
);
3216 WebURLRequest
request(swappedOutURL
);
3217 if (frame
->isWebLocalFrame())
3218 frame
->loadRequest(request
);
3221 void RenderViewImpl::OnClosePage() {
3222 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, ClosePage());
3223 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3224 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3225 // in the onunload handler from appearing. For now, we're bypassing that and
3226 // calling the FrameLoader's CloseURL method directly. This should be
3227 // revisited to avoid having two ways to close a page. Having a single way
3228 // to close that can run onunload is also useful for fixing
3229 // http://b/issue?id=753080.
3230 webview()->mainFrame()->dispatchUnloadEvent();
3232 Send(new ViewHostMsg_ClosePage_ACK(routing_id_
));
3235 void RenderViewImpl::OnThemeChanged() {
3236 #if defined(USE_AURA)
3237 // Aura doesn't care if we switch themes.
3238 #elif defined(OS_WIN)
3239 ui::NativeThemeWin::instance()->CloseHandles();
3241 webview()->themeChanged();
3242 #else // defined(OS_WIN)
3243 // TODO(port): we don't support theming on non-Windows platforms yet
3248 void RenderViewImpl::OnMoveOrResizeStarted() {
3250 webview()->hidePopups();
3253 void RenderViewImpl::OnResize(const ViewMsg_Resize_Params
& params
) {
3254 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
3256 webview()->hidePopups();
3257 if (send_preferred_size_changes_
) {
3258 webview()->mainFrame()->setCanHaveScrollbars(
3259 ShouldDisplayScrollbars(params
.new_size
.width(),
3260 params
.new_size
.height()));
3264 gfx::Size old_visible_viewport_size
= visible_viewport_size_
;
3266 RenderWidget::OnResize(params
);
3268 if (old_visible_viewport_size
!= visible_viewport_size_
)
3269 has_scrolled_focused_editable_node_into_rect_
= false;
3271 FOR_EACH_OBSERVER(RenderViewObserver
,
3276 void RenderViewImpl::DidInitiatePaint() {
3277 #if defined(ENABLE_PLUGINS)
3278 // Notify all instances that we painted. The same caveats apply as for
3279 // ViewFlushedPaint regarding instances closing themselves, so we take
3280 // similar precautions.
3281 PepperPluginSet plugins
= active_pepper_instances_
;
3282 for (PepperPluginSet::iterator i
= plugins
.begin(); i
!= plugins
.end(); ++i
) {
3283 if (active_pepper_instances_
.find(*i
) != active_pepper_instances_
.end())
3284 (*i
)->ViewInitiatedPaint();
3289 void RenderViewImpl::DidFlushPaint() {
3290 #if defined(ENABLE_PLUGINS)
3291 // Notify all instances that we flushed. This will call into the plugin, and
3292 // we it may ask to close itself as a result. This will, in turn, modify our
3293 // set, possibly invalidating the iterator. So we iterate on a copy that
3294 // won't change out from under us.
3295 PepperPluginSet plugins
= active_pepper_instances_
;
3296 for (PepperPluginSet::iterator i
= plugins
.begin(); i
!= plugins
.end(); ++i
) {
3297 // The copy above makes sure our iterator is never invalid if some plugins
3298 // are destroyed. But some plugin may decide to close all of its views in
3299 // response to a paint in one of them, so we need to make sure each one is
3300 // still "current" before using it.
3302 // It's possible that a plugin was destroyed, but another one was created
3303 // with the same address. In this case, we'll call ViewFlushedPaint on that
3304 // new plugin. But that's OK for this particular case since we're just
3305 // notifying all of our instances that the view flushed, and the new one is
3306 // one of our instances.
3308 // What about the case where a new one is created in a callback at a new
3309 // address and we don't issue the callback? We're still OK since this
3310 // callback is used for flush callbacks and we could not have possibly
3311 // started a new paint for the new plugin while processing a previous paint
3312 // for an existing one.
3313 if (active_pepper_instances_
.find(*i
) != active_pepper_instances_
.end())
3314 (*i
)->ViewFlushedPaint();
3318 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
3319 // See crbug.com/112921.
3323 WebFrame
* main_frame
= webview()->mainFrame();
3324 for (WebFrame
* frame
= main_frame
; frame
;
3325 frame
= frame
->traverseNext(false)) {
3326 if (frame
->isWebLocalFrame())
3330 // If we have a provisional frame we are between the start and commit stages
3331 // of loading and we don't want to save stats.
3332 if (!main_frame
->provisionalDataSource()) {
3333 WebDataSource
* ds
= main_frame
->dataSource();
3334 DocumentState
* document_state
= DocumentState::FromDataSource(ds
);
3336 // TODO(jar): The following code should all be inside a method, probably in
3338 Time now
= Time::Now();
3339 if (document_state
->first_paint_time().is_null()) {
3340 document_state
->set_first_paint_time(now
);
3342 if (document_state
->first_paint_after_load_time().is_null() &&
3343 !document_state
->finish_load_time().is_null()) {
3344 document_state
->set_first_paint_after_load_time(now
);
3349 gfx::Vector2d
RenderViewImpl::GetScrollOffset() {
3350 WebFrame
* main_frame
= webview()->mainFrame();
3351 for (WebFrame
* frame
= main_frame
; frame
;
3352 frame
= frame
->traverseNext(false)) {
3353 // TODO(nasko): This is a hack for the case in which the top-level
3354 // frame is being rendered in another process. It will not
3355 // behave correctly for out of process iframes.
3356 if (frame
->isWebLocalFrame()) {
3362 WebSize scroll_offset
= main_frame
->scrollOffset();
3363 return gfx::Vector2d(scroll_offset
.width
, scroll_offset
.height
);
3366 void RenderViewImpl::OnClearFocusedElement() {
3368 webview()->clearFocusedElement();
3371 void RenderViewImpl::OnSetBackgroundOpaque(bool opaque
) {
3373 webview()->setIsTransparent(!opaque
);
3375 compositor_
->setHasTransparentBackground(!opaque
);
3378 void RenderViewImpl::OnSetActive(bool active
) {
3380 webview()->setIsActive(active
);
3382 #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
3383 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3384 for (plugin_it
= plugin_delegates_
.begin();
3385 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3386 (*plugin_it
)->SetWindowFocus(active
);
3391 #if defined(OS_MACOSX)
3392 void RenderViewImpl::OnSetWindowVisibility(bool visible
) {
3393 #if defined(ENABLE_PLUGINS)
3394 // Inform plugins that their container has changed visibility.
3395 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3396 for (plugin_it
= plugin_delegates_
.begin();
3397 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3398 (*plugin_it
)->SetContainerVisibility(visible
);
3403 void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect
& window_frame
,
3404 const gfx::Rect
& view_frame
) {
3405 #if defined(ENABLE_PLUGINS)
3406 // Inform plugins that their window's frame has changed.
3407 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3408 for (plugin_it
= plugin_delegates_
.begin();
3409 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3410 (*plugin_it
)->WindowFrameChanged(window_frame
, view_frame
);
3415 void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16
& text
,
3417 // WebPluginDelegateProxy is responsible for figuring out if this event
3418 // applies to it or not, so inform all the delegates.
3419 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3420 for (plugin_it
= plugin_delegates_
.begin();
3421 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3422 (*plugin_it
)->ImeCompositionCompleted(text
, plugin_id
);
3427 void RenderViewImpl::OnClose() {
3429 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_
));
3430 RenderWidget::OnClose();
3433 void RenderViewImpl::Close() {
3434 // We need to grab a pointer to the doomed WebView before we destroy it.
3435 WebView
* doomed
= webview();
3436 RenderWidget::Close();
3437 g_view_map
.Get().erase(doomed
);
3438 g_routing_id_view_map
.Get().erase(routing_id_
);
3439 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_
));
3442 void RenderViewImpl::DidHandleKeyEvent() {
3443 ClearEditCommands();
3446 bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent
& event
) {
3447 possible_drag_event_info_
.event_source
=
3448 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE
;
3449 possible_drag_event_info_
.event_location
=
3450 gfx::Point(event
.globalX
, event
.globalY
);
3452 #if defined(ENABLE_PLUGINS)
3453 // This method is called for every mouse event that the render view receives.
3454 // And then the mouse event is forwarded to WebKit, which dispatches it to the
3455 // event target. Potentially a Pepper plugin will receive the event.
3456 // In order to tell whether a plugin gets the last mouse event and which it
3457 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
3458 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
3459 // |pepper_last_mouse_event_target_|.
3460 pepper_last_mouse_event_target_
= NULL
;
3463 // If the mouse is locked, only the current owner of the mouse lock can
3464 // process mouse events.
3465 return mouse_lock_dispatcher_
->WillHandleMouseEvent(event
);
3468 bool RenderViewImpl::WillHandleGestureEvent(
3469 const blink::WebGestureEvent
& event
) {
3470 possible_drag_event_info_
.event_source
=
3471 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH
;
3472 possible_drag_event_info_
.event_location
=
3473 gfx::Point(event
.globalX
, event
.globalY
);
3477 void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent
& event
) {
3478 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidHandleMouseEvent(event
));
3481 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent
& event
) {
3482 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidHandleTouchEvent(event
));
3485 bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point
& point
) const {
3488 return webview()->hasTouchEventHandlersAt(point
);
3491 void RenderViewImpl::OnWasHidden() {
3492 RenderWidget::OnWasHidden();
3494 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3495 RenderThreadImpl::current()->video_capture_impl_manager()->
3496 SuspendDevices(true);
3497 if (speech_recognition_dispatcher_
)
3498 speech_recognition_dispatcher_
->AbortAllRecognitions();
3502 webview()->setVisibilityState(visibilityState(), false);
3504 #if defined(ENABLE_PLUGINS)
3505 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3506 i
!= active_pepper_instances_
.end(); ++i
)
3507 (*i
)->PageVisibilityChanged(false);
3509 #if defined(OS_MACOSX)
3510 // Inform NPAPI plugins that their container is no longer visible.
3511 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3512 for (plugin_it
= plugin_delegates_
.begin();
3513 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3514 (*plugin_it
)->SetContainerVisibility(false);
3517 #endif // ENABLE_PLUGINS
3520 void RenderViewImpl::OnWasShown(bool needs_repainting
,
3521 const ui::LatencyInfo
& latency_info
) {
3522 RenderWidget::OnWasShown(needs_repainting
, latency_info
);
3524 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3525 RenderThreadImpl::current()->video_capture_impl_manager()->
3526 SuspendDevices(false);
3530 webview()->setVisibilityState(visibilityState(), false);
3532 #if defined(ENABLE_PLUGINS)
3533 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3534 i
!= active_pepper_instances_
.end(); ++i
)
3535 (*i
)->PageVisibilityChanged(true);
3537 #if defined(OS_MACOSX)
3538 // Inform NPAPI plugins that their container is now visible.
3539 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3540 for (plugin_it
= plugin_delegates_
.begin();
3541 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3542 (*plugin_it
)->SetContainerVisibility(true);
3545 #endif // ENABLE_PLUGINS
3548 GURL
RenderViewImpl::GetURLForGraphicsContext3D() {
3550 if (webview()->mainFrame()->isWebLocalFrame())
3551 return GURL(webview()->mainFrame()->document().url());
3553 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
3556 void RenderViewImpl::OnSetFocus(bool enable
) {
3557 RenderWidget::OnSetFocus(enable
);
3559 #if defined(ENABLE_PLUGINS)
3560 if (webview() && webview()->isActive()) {
3561 // Notify all NPAPI plugins.
3562 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3563 for (plugin_it
= plugin_delegates_
.begin();
3564 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3565 #if defined(OS_MACOSX)
3566 // RenderWidget's call to setFocus can cause the underlying webview's
3567 // activation state to change just like a call to setIsActive.
3569 (*plugin_it
)->SetWindowFocus(true);
3571 (*plugin_it
)->SetContentAreaFocus(enable
);
3574 // Notify all Pepper plugins.
3575 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3576 i
!= active_pepper_instances_
.end(); ++i
)
3577 (*i
)->SetContentAreaFocus(enable
);
3579 // Notify all BrowserPlugins of the RenderView's focus state.
3580 if (browser_plugin_manager_
.get())
3581 browser_plugin_manager_
->UpdateFocusState();
3584 void RenderViewImpl::OnImeSetComposition(
3585 const base::string16
& text
,
3586 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
3587 int selection_start
,
3588 int selection_end
) {
3589 #if defined(ENABLE_PLUGINS)
3590 if (focused_pepper_plugin_
) {
3591 focused_pepper_plugin_
->render_frame()->OnImeSetComposition(
3592 text
, underlines
, selection_start
, selection_end
);
3597 // When a plug-in has focus, we create platform-specific IME data used by
3598 // our IME emulator and send it directly to the focused plug-in, i.e. we
3599 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
3600 // instance ID is the same one as the specified ID.)
3601 if (focused_plugin_id_
>= 0) {
3602 std::vector
<int> clauses
;
3603 std::vector
<int> target
;
3604 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
3605 clauses
.push_back(underlines
[i
].startOffset
);
3606 clauses
.push_back(underlines
[i
].endOffset
);
3607 if (underlines
[i
].thick
) {
3609 target
.push_back(underlines
[i
].startOffset
);
3610 target
.push_back(underlines
[i
].endOffset
);
3613 std::set
<WebPluginDelegateProxy
*>::iterator it
;
3614 for (it
= plugin_delegates_
.begin(); it
!= plugin_delegates_
.end(); ++it
) {
3615 (*it
)->ImeCompositionUpdated(text
, clauses
, target
, selection_end
,
3616 focused_plugin_id_
);
3621 #endif // ENABLE_PLUGINS
3622 RenderWidget::OnImeSetComposition(text
,
3628 void RenderViewImpl::OnImeConfirmComposition(
3629 const base::string16
& text
,
3630 const gfx::Range
& replacement_range
,
3631 bool keep_selection
) {
3632 #if defined(ENABLE_PLUGINS)
3633 if (focused_pepper_plugin_
) {
3634 focused_pepper_plugin_
->render_frame()->OnImeConfirmComposition(
3635 text
, replacement_range
, keep_selection
);
3639 // Same as OnImeSetComposition(), we send the text from IMEs directly to
3640 // plug-ins. When we send IME text directly to plug-ins, we should not send
3641 // it to WebKit to prevent WebKit from controlling IMEs.
3642 // TODO(thakis): Honor |replacement_range| for plugins?
3643 if (focused_plugin_id_
>= 0) {
3644 std::set
<WebPluginDelegateProxy
*>::iterator it
;
3645 for (it
= plugin_delegates_
.begin();
3646 it
!= plugin_delegates_
.end(); ++it
) {
3647 (*it
)->ImeCompositionCompleted(text
, focused_plugin_id_
);
3652 #endif // ENABLE_PLUGINS
3653 if (replacement_range
.IsValid() && webview()) {
3654 // Select the text in |replacement_range|, it will then be replaced by
3655 // text added by the call to RenderWidget::OnImeConfirmComposition().
3656 if (WebLocalFrame
* frame
= webview()->focusedFrame()->toWebLocalFrame()) {
3657 WebRange webrange
= WebRange::fromDocumentRange(
3658 frame
, replacement_range
.start(), replacement_range
.length());
3659 if (!webrange
.isNull())
3660 frame
->selectRange(webrange
);
3663 RenderWidget::OnImeConfirmComposition(text
,
3668 void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor
) {
3669 RenderWidget::SetDeviceScaleFactor(device_scale_factor
);
3671 webview()->setDeviceScaleFactor(device_scale_factor
);
3672 webview()->settings()->setPreferCompositingToLCDTextEnabled(
3673 PreferCompositingToLCDText(device_scale_factor_
));
3674 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
3675 ShouldUseTransitionCompositing(device_scale_factor_
));
3677 if (auto_resize_mode_
)
3678 AutoResizeCompositor();
3680 if (browser_plugin_manager_
.get())
3681 browser_plugin_manager_
->UpdateDeviceScaleFactor(device_scale_factor_
);
3684 bool RenderViewImpl::SetDeviceColorProfile(
3685 const std::vector
<char>& profile
) {
3686 bool changed
= RenderWidget::SetDeviceColorProfile(profile
);
3687 if (changed
&& webview()) {
3688 // TODO(noel): notify the webview() of the color profile change so it
3689 // can update and repaint all color profiled page elements.
3694 ui::TextInputType
RenderViewImpl::GetTextInputType() {
3695 #if defined(ENABLE_PLUGINS)
3696 if (focused_pepper_plugin_
)
3697 return focused_pepper_plugin_
->text_input_type();
3699 return RenderWidget::GetTextInputType();
3702 void RenderViewImpl::GetSelectionBounds(gfx::Rect
* start
, gfx::Rect
* end
) {
3703 #if defined(ENABLE_PLUGINS)
3704 if (focused_pepper_plugin_
) {
3705 // TODO(kinaba) http://crbug.com/101101
3706 // Current Pepper IME API does not handle selection bounds. So we simply
3707 // use the caret position as an empty range for now. It will be updated
3708 // after Pepper API equips features related to surrounding text retrieval.
3709 gfx::Rect caret
= focused_pepper_plugin_
->GetCaretBounds();
3715 RenderWidget::GetSelectionBounds(start
, end
);
3718 #if defined(OS_MACOSX) || defined(USE_AURA)
3719 void RenderViewImpl::GetCompositionCharacterBounds(
3720 std::vector
<gfx::Rect
>* bounds
) {
3724 #if defined(ENABLE_PLUGINS)
3725 if (focused_pepper_plugin_
) {
3732 size_t start_offset
= 0;
3733 size_t character_count
= 0;
3734 if (!webview()->compositionRange(&start_offset
, &character_count
))
3736 if (character_count
== 0)
3739 blink::WebFrame
* frame
= webview()->focusedFrame();
3743 bounds
->reserve(character_count
);
3744 blink::WebRect webrect
;
3745 for (size_t i
= 0; i
< character_count
; ++i
) {
3746 if (!frame
->firstRectForCharacterRange(start_offset
+ i
, 1, webrect
)) {
3747 DLOG(ERROR
) << "Could not retrieve character rectangle at " << i
;
3751 bounds
->push_back(webrect
);
3755 void RenderViewImpl::GetCompositionRange(gfx::Range
* range
) {
3756 #if defined(ENABLE_PLUGINS)
3757 if (focused_pepper_plugin_
) {
3761 RenderWidget::GetCompositionRange(range
);
3765 bool RenderViewImpl::CanComposeInline() {
3766 #if defined(ENABLE_PLUGINS)
3767 if (focused_pepper_plugin_
)
3768 return focused_pepper_plugin_
->IsPluginAcceptingCompositionEvents();
3773 void RenderViewImpl::InstrumentWillBeginFrame(int frame_id
) {
3776 if (!webview()->devToolsAgent())
3778 webview()->devToolsAgent()->didBeginFrame(frame_id
);
3781 void RenderViewImpl::InstrumentDidBeginFrame() {
3784 if (!webview()->devToolsAgent())
3786 // TODO(jamesr/caseq): Decide if this needs to be renamed.
3787 webview()->devToolsAgent()->didComposite();
3790 void RenderViewImpl::InstrumentDidCancelFrame() {
3793 if (!webview()->devToolsAgent())
3795 webview()->devToolsAgent()->didCancelFrame();
3798 void RenderViewImpl::InstrumentWillComposite() {
3801 if (!webview()->devToolsAgent())
3803 webview()->devToolsAgent()->willComposite();
3806 void RenderViewImpl::SetScreenMetricsEmulationParameters(
3807 float device_scale_factor
,
3808 const gfx::Point
& root_layer_offset
,
3809 float root_layer_scale
) {
3810 if (webview() && compositor()) {
3811 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor
);
3812 webview()->setRootLayerTransform(
3813 blink::WebSize(root_layer_offset
.x(), root_layer_offset
.y()),
3818 bool RenderViewImpl::ScheduleFileChooser(
3819 const FileChooserParams
& params
,
3820 WebFileChooserCompletion
* completion
) {
3821 static const size_t kMaximumPendingFileChooseRequests
= 4;
3822 if (file_chooser_completions_
.size() > kMaximumPendingFileChooseRequests
) {
3823 // This sanity check prevents too many file choose requests from getting
3824 // queued which could DoS the user. Getting these is most likely a
3825 // programming error (there are many ways to DoS the user so it's not
3826 // considered a "real" security check), either in JS requesting many file
3827 // choosers to pop up, or in a plugin.
3829 // TODO(brettw) we might possibly want to require a user gesture to open
3830 // a file picker, which will address this issue in a better way.
3834 file_chooser_completions_
.push_back(linked_ptr
<PendingFileChooser
>(
3835 new PendingFileChooser(params
, completion
)));
3836 if (file_chooser_completions_
.size() == 1) {
3837 // Actually show the browse dialog when this is the first request.
3838 Send(new ViewHostMsg_RunFileChooser(routing_id_
, params
));
3843 blink::WebSpeechRecognizer
* RenderViewImpl::speechRecognizer() {
3844 if (!speech_recognition_dispatcher_
)
3845 speech_recognition_dispatcher_
= new SpeechRecognitionDispatcher(this);
3846 return speech_recognition_dispatcher_
;
3849 void RenderViewImpl::zoomLimitsChanged(double minimum_level
,
3850 double maximum_level
) {
3851 int minimum_percent
= static_cast<int>(
3852 ZoomLevelToZoomFactor(minimum_level
) * 100);
3853 int maximum_percent
= static_cast<int>(
3854 ZoomLevelToZoomFactor(maximum_level
) * 100);
3856 Send(new ViewHostMsg_UpdateZoomLimits(
3857 routing_id_
, minimum_percent
, maximum_percent
));
3860 void RenderViewImpl::zoomLevelChanged() {
3861 double zoom_level
= webview()->zoomLevel();
3863 // Do not send empty URLs to the browser when we are just setting the default
3864 // zoom level (from RendererPreferences) before the first navigation.
3865 if (!webview()->mainFrame()->document().url().isEmpty()) {
3866 // Tell the browser which url got zoomed so it can update the menu and the
3867 // saved values if necessary
3868 Send(new ViewHostMsg_DidZoomURL(
3869 routing_id_
, zoom_level
,
3870 GURL(webview()->mainFrame()->document().url())));
3874 double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level
) const {
3875 return ZoomLevelToZoomFactor(zoom_level
);
3878 double RenderViewImpl::zoomFactorToZoomLevel(double factor
) const {
3879 return ZoomFactorToZoomLevel(factor
);
3882 // TODO(sanjoy.pal): Remove once blink patch lands. http://crbug.com/406236.
3883 void RenderViewImpl::registerProtocolHandler(const WebString
& scheme
,
3884 const WebURL
& base_url
,
3886 const WebString
& title
) {
3887 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3888 GURL
base(base_url
);
3889 GURL absolute_url
= base
.Resolve(base::UTF16ToUTF8(url
.string()));
3890 if (base
.GetOrigin() != absolute_url
.GetOrigin()) {
3893 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_
,
3894 base::UTF16ToUTF8(scheme
),
3900 void RenderViewImpl::unregisterProtocolHandler(const WebString
& scheme
,
3901 const WebURL
& base_url
,
3902 const WebURL
& url
) {
3903 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3904 GURL
base(base_url
);
3905 GURL absolute_url
= base
.Resolve(base::UTF16ToUTF8(url
.string()));
3906 if (base
.GetOrigin() != absolute_url
.GetOrigin())
3908 Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_
,
3909 base::UTF16ToUTF8(scheme
),
3914 void RenderViewImpl::registerProtocolHandler(const WebString
& scheme
,
3916 const WebString
& title
) {
3917 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3918 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_
,
3919 base::UTF16ToUTF8(scheme
),
3925 void RenderViewImpl::unregisterProtocolHandler(const WebString
& scheme
,
3926 const WebURL
& url
) {
3927 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3928 Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_
,
3929 base::UTF16ToUTF8(scheme
),
3934 blink::WebPageVisibilityState
RenderViewImpl::visibilityState() const {
3935 blink::WebPageVisibilityState current_state
= is_hidden() ?
3936 blink::WebPageVisibilityStateHidden
:
3937 blink::WebPageVisibilityStateVisible
;
3938 blink::WebPageVisibilityState override_state
= current_state
;
3939 // TODO(jam): move this method to WebFrameClient.
3940 if (GetContentClient()->renderer()->
3941 ShouldOverridePageVisibilityState(main_render_frame_
.get(),
3943 return override_state
;
3944 return current_state
;
3947 blink::WebPushClient
* RenderViewImpl::webPushClient() {
3948 // TODO(mvanouwerkerk): Remove this method once the Push API code in Blink
3949 // has also switched over to Frame.
3950 return main_render_frame_
->pushClient();
3953 void RenderViewImpl::draggableRegionsChanged() {
3957 DraggableRegionsChanged(webview()->mainFrame()));
3960 #if defined(OS_ANDROID)
3961 WebContentDetectionResult
RenderViewImpl::detectContentAround(
3962 const WebHitTestResult
& touch_hit
) {
3963 DCHECK(!touch_hit
.isNull());
3964 DCHECK(!touch_hit
.node().isNull());
3965 DCHECK(touch_hit
.node().isTextNode());
3967 // Process the position with all the registered content detectors until
3968 // a match is found. Priority is provided by their relative order.
3969 for (ContentDetectorList::const_iterator it
= content_detectors_
.begin();
3970 it
!= content_detectors_
.end(); ++it
) {
3971 ContentDetector::Result content
= (*it
)->FindTappedContent(touch_hit
);
3972 if (content
.valid
) {
3973 return WebContentDetectionResult(content
.content_boundaries
,
3974 base::UTF8ToUTF16(content
.text
), content
.intent_url
);
3977 return WebContentDetectionResult();
3980 void RenderViewImpl::scheduleContentIntent(const WebURL
& intent
) {
3981 // Introduce a short delay so that the user can notice the content.
3982 base::MessageLoop::current()->PostDelayedTask(
3984 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent
,
3987 expected_content_intent_id_
),
3988 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds
));
3991 void RenderViewImpl::cancelScheduledContentIntents() {
3992 ++expected_content_intent_id_
;
3995 void RenderViewImpl::LaunchAndroidContentIntent(const GURL
& intent
,
3996 size_t request_id
) {
3997 if (request_id
!= expected_content_intent_id_
)
4000 // Remove the content highlighting if any.
4001 scheduleComposite();
4003 if (!intent
.is_empty())
4004 Send(new ViewHostMsg_StartContentIntent(routing_id_
, intent
));
4007 bool RenderViewImpl::openDateTimeChooser(
4008 const blink::WebDateTimeChooserParams
& params
,
4009 blink::WebDateTimeChooserCompletion
* completion
) {
4010 // JavaScript may try to open a date time chooser while one is already open.
4011 if (date_time_picker_client_
)
4013 date_time_picker_client_
.reset(
4014 new RendererDateTimePicker(this, params
, completion
));
4015 return date_time_picker_client_
->Open();
4018 void RenderViewImpl::DismissDateTimeDialog() {
4019 DCHECK(date_time_picker_client_
);
4020 date_time_picker_client_
.reset(NULL
);
4023 #endif // defined(OS_ANDROID)
4025 void RenderViewImpl::OnShowContextMenu(
4026 ui::MenuSourceType source_type
, const gfx::Point
& location
) {
4027 context_menu_source_type_
= source_type
;
4028 has_host_context_menu_location_
= true;
4029 host_context_menu_location_
= location
;
4031 webview()->showContextMenu();
4032 has_host_context_menu_location_
= false;
4035 void RenderViewImpl::OnEnableViewSourceMode() {
4038 WebFrame
* main_frame
= webview()->mainFrame();
4041 main_frame
->enableViewSourceMode(true);
4044 #if defined(OS_ANDROID)
4045 bool RenderViewImpl::didTapMultipleTargets(
4046 const blink::WebGestureEvent
& event
,
4047 const WebVector
<WebRect
>& target_rects
) {
4048 // Never show a disambiguation popup when accessibility is enabled,
4049 // as this interferes with "touch exploration".
4050 AccessibilityMode accessibility_mode
=
4051 main_render_frame()->accessibility_mode();
4052 bool matches_accessibility_mode_complete
=
4053 (accessibility_mode
& AccessibilityModeComplete
) ==
4054 AccessibilityModeComplete
;
4055 if (matches_accessibility_mode_complete
)
4058 gfx::Rect
finger_rect(
4059 event
.x
- event
.data
.tap
.width
/ 2, event
.y
- event
.data
.tap
.height
/ 2,
4060 event
.data
.tap
.width
, event
.data
.tap
.height
);
4061 gfx::Rect zoom_rect
;
4062 float new_total_scale
=
4063 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
4064 finger_rect
, target_rects
, GetSize(),
4065 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
4066 device_scale_factor_
* webview()->pageScaleFactor(), &zoom_rect
);
4067 if (!new_total_scale
)
4070 bool handled
= false;
4071 switch (renderer_preferences_
.tap_multiple_targets_strategy
) {
4072 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM
:
4073 handled
= webview()->zoomToMultipleTargetsRect(zoom_rect
);
4075 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP
: {
4076 gfx::Size canvas_size
=
4077 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect
.size(), new_total_scale
));
4078 cc::SharedBitmapManager
* manager
=
4079 RenderThreadImpl::current()->shared_bitmap_manager();
4080 scoped_ptr
<cc::SharedBitmap
> shared_bitmap
=
4081 manager
->AllocateSharedBitmap(canvas_size
);
4084 SkImageInfo info
= SkImageInfo::MakeN32Premul(canvas_size
.width(),
4085 canvas_size
.height());
4086 bitmap
.installPixels(info
, shared_bitmap
->pixels(), info
.minRowBytes());
4087 SkCanvas
canvas(bitmap
);
4089 // TODO(trchen): Cleanup the device scale factor mess.
4090 // device scale will be applied in WebKit
4091 // --> zoom_rect doesn't include device scale,
4092 // but WebKit will still draw on zoom_rect * device_scale_factor_
4093 canvas
.scale(new_total_scale
/ device_scale_factor_
,
4094 new_total_scale
/ device_scale_factor_
);
4095 canvas
.translate(-zoom_rect
.x() * device_scale_factor_
,
4096 -zoom_rect
.y() * device_scale_factor_
);
4098 DCHECK(webwidget_
->isAcceleratedCompositingActive());
4099 // TODO(aelias): The disambiguation popup should be composited so we
4100 // don't have to call this method.
4101 webwidget_
->paintCompositedDeprecated(&canvas
, zoom_rect
);
4104 gfx::Rect physical_window_zoom_rect
= gfx::ToEnclosingRect(
4105 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect
)));
4106 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_
,
4107 physical_window_zoom_rect
,
4109 shared_bitmap
->id()));
4110 cc::SharedBitmapId id
= shared_bitmap
->id();
4111 disambiguation_bitmaps_
[id
] = shared_bitmap
.release();
4115 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE
:
4124 unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
4125 return history_list_length_
;
4128 void RenderViewImpl::SetFocusAndActivateForTesting(bool enable
) {
4142 void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor
) {
4143 ViewMsg_Resize_Params params
;
4144 params
.screen_info
= screen_info_
;
4145 params
.screen_info
.deviceScaleFactor
= factor
;
4146 params
.new_size
= size();
4147 params
.physical_backing_size
=
4148 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor
));
4149 params
.top_controls_layout_height
= 0.f
;
4150 params
.resizer_rect
= WebRect();
4151 params
.is_fullscreen
= is_fullscreen();
4155 void RenderViewImpl::SetDeviceColorProfileForTesting(
4156 const std::vector
<char>& color_profile
) {
4157 SetDeviceColorProfile(color_profile
);
4160 void RenderViewImpl::ForceResizeForTesting(const gfx::Size
& new_size
) {
4161 gfx::Rect
new_position(rootWindowRect().x
,
4165 ResizeSynchronously(new_position
);
4168 void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable
) {
4169 resizing_mode_selector_
->set_is_synchronous_mode(enable
);
4172 void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size
& min_size
,
4173 const gfx::Size
& max_size
) {
4174 OnEnableAutoResize(min_size
, max_size
);
4177 void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size
& new_size
) {
4178 OnDisableAutoResize(new_size
);
4181 void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
4182 const cc::SharedBitmapId
& id
) {
4183 BitmapMap::iterator it
= disambiguation_bitmaps_
.find(id
);
4184 DCHECK(it
!= disambiguation_bitmaps_
.end());
4186 disambiguation_bitmaps_
.erase(it
);
4189 void RenderViewImpl::DidCommitCompositorFrame() {
4190 RenderWidget::DidCommitCompositorFrame();
4191 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidCommitCompositorFrame());
4194 void RenderViewImpl::SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
) {
4196 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_
, urls
));
4199 void RenderViewImpl::DidStopLoadingIcons() {
4200 int icon_types
= WebIconURL::TypeFavicon
;
4202 icon_types
|= WebIconURL::TypeTouchPrecomposed
| WebIconURL::TypeTouch
;
4204 WebVector
<WebIconURL
> icon_urls
=
4205 webview()->mainFrame()->iconURLs(icon_types
);
4207 std::vector
<FaviconURL
> urls
;
4208 for (size_t i
= 0; i
< icon_urls
.size(); i
++) {
4209 WebURL url
= icon_urls
[i
].iconURL();
4210 std::vector
<gfx::Size
> sizes
;
4211 ConvertToFaviconSizes(icon_urls
[i
].sizes(), &sizes
);
4214 FaviconURL(url
, ToFaviconType(icon_urls
[i
].iconType()), sizes
));
4216 SendUpdateFaviconURL(urls
);
4219 } // namespace content