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/process/kill.h"
26 #include "base/process/process.h"
27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/string_piece.h"
29 #include "base/strings/string_split.h"
30 #include "base/strings/string_util.h"
31 #include "base/strings/sys_string_conversions.h"
32 #include "base/strings/utf_string_conversions.h"
33 #include "base/time/time.h"
34 #include "cc/base/switches.h"
35 #include "content/child/appcache/appcache_dispatcher.h"
36 #include "content/child/appcache/web_application_cache_host_impl.h"
37 #include "content/child/child_shared_bitmap_manager.h"
38 #include "content/child/child_thread.h"
39 #include "content/child/npapi/webplugin_delegate_impl.h"
40 #include "content/child/request_extra_data.h"
41 #include "content/child/webmessageportchannel_impl.h"
42 #include "content/common/content_constants_internal.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/ssl_status_serialization.h"
51 #include "content/common/view_messages.h"
52 #include "content/public/common/bindings_policy.h"
53 #include "content/public/common/content_client.h"
54 #include "content/public/common/content_constants.h"
55 #include "content/public/common/content_switches.h"
56 #include "content/public/common/drop_data.h"
57 #include "content/public/common/favicon_url.h"
58 #include "content/public/common/file_chooser_file_info.h"
59 #include "content/public/common/file_chooser_params.h"
60 #include "content/public/common/page_state.h"
61 #include "content/public/common/page_zoom.h"
62 #include "content/public/common/ssl_status.h"
63 #include "content/public/common/three_d_api_types.h"
64 #include "content/public/common/url_constants.h"
65 #include "content/public/common/url_utils.h"
66 #include "content/public/common/web_preferences.h"
67 #include "content/public/renderer/content_renderer_client.h"
68 #include "content/public/renderer/document_state.h"
69 #include "content/public/renderer/navigation_state.h"
70 #include "content/public/renderer/render_view_observer.h"
71 #include "content/public/renderer/render_view_visitor.h"
72 #include "content/renderer/browser_plugin/browser_plugin.h"
73 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
74 #include "content/renderer/devtools/devtools_agent.h"
75 #include "content/renderer/disambiguation_popup_helper.h"
76 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
77 #include "content/renderer/drop_data_builder.h"
78 #include "content/renderer/gpu/gpu_benchmarking_extension.h"
79 #include "content/renderer/gpu/render_widget_compositor.h"
80 #include "content/renderer/history_controller.h"
81 #include "content/renderer/history_serialization.h"
82 #include "content/renderer/idle_user_detector.h"
83 #include "content/renderer/ime_event_guard.h"
84 #include "content/renderer/input/input_handler_manager.h"
85 #include "content/renderer/internal_document_state_data.h"
86 #include "content/renderer/media/audio_device_factory.h"
87 #include "content/renderer/media/video_capture_impl_manager.h"
88 #include "content/renderer/memory_benchmarking_extension.h"
89 #include "content/renderer/mhtml_generator.h"
90 #include "content/renderer/net_info_helper.h"
91 #include "content/renderer/render_frame_impl.h"
92 #include "content/renderer/render_frame_proxy.h"
93 #include "content/renderer/render_process.h"
94 #include "content/renderer/render_thread_impl.h"
95 #include "content/renderer/render_view_impl_params.h"
96 #include "content/renderer/render_view_mouse_lock_dispatcher.h"
97 #include "content/renderer/render_widget_fullscreen_pepper.h"
98 #include "content/renderer/renderer_webapplicationcachehost_impl.h"
99 #include "content/renderer/resizing_mode_selector.h"
100 #include "content/renderer/savable_resources.h"
101 #include "content/renderer/skia_benchmarking_extension.h"
102 #include "content/renderer/speech_recognition_dispatcher.h"
103 #include "content/renderer/stats_collection_controller.h"
104 #include "content/renderer/stats_collection_observer.h"
105 #include "content/renderer/text_input_client_observer.h"
106 #include "content/renderer/v8_value_converter_impl.h"
107 #include "content/renderer/web_ui_extension.h"
108 #include "content/renderer/web_ui_extension_data.h"
109 #include "content/renderer/web_ui_mojo.h"
110 #include "content/renderer/websharedworker_proxy.h"
111 #include "media/audio/audio_output_device.h"
112 #include "media/base/media_switches.h"
113 #include "media/filters/audio_renderer_impl.h"
114 #include "media/filters/gpu_video_accelerator_factories.h"
115 #include "net/base/data_url.h"
116 #include "net/base/escape.h"
117 #include "net/base/net_errors.h"
118 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
119 #include "net/http/http_util.h"
120 #include "skia/ext/platform_canvas.h"
121 #include "third_party/WebKit/public/platform/WebCString.h"
122 #include "third_party/WebKit/public/platform/WebConnectionType.h"
123 #include "third_party/WebKit/public/platform/WebDragData.h"
124 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
125 #include "third_party/WebKit/public/platform/WebImage.h"
126 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
127 #include "third_party/WebKit/public/platform/WebPoint.h"
128 #include "third_party/WebKit/public/platform/WebRect.h"
129 #include "third_party/WebKit/public/platform/WebSize.h"
130 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
131 #include "third_party/WebKit/public/platform/WebString.h"
132 #include "third_party/WebKit/public/platform/WebURL.h"
133 #include "third_party/WebKit/public/platform/WebURLError.h"
134 #include "third_party/WebKit/public/platform/WebURLRequest.h"
135 #include "third_party/WebKit/public/platform/WebURLResponse.h"
136 #include "third_party/WebKit/public/platform/WebVector.h"
137 #include "third_party/WebKit/public/web/WebAXObject.h"
138 #include "third_party/WebKit/public/web/WebColorName.h"
139 #include "third_party/WebKit/public/web/WebColorSuggestion.h"
140 #include "third_party/WebKit/public/web/WebDOMEvent.h"
141 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
142 #include "third_party/WebKit/public/web/WebDataSource.h"
143 #include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
144 #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
145 #include "third_party/WebKit/public/web/WebDevToolsAgent.h"
146 #include "third_party/WebKit/public/web/WebDocument.h"
147 #include "third_party/WebKit/public/web/WebElement.h"
148 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
149 #include "third_party/WebKit/public/web/WebFindOptions.h"
150 #include "third_party/WebKit/public/web/WebFormControlElement.h"
151 #include "third_party/WebKit/public/web/WebFormElement.h"
152 #include "third_party/WebKit/public/web/WebFrame.h"
153 #include "third_party/WebKit/public/web/WebGlyphCache.h"
154 #include "third_party/WebKit/public/web/WebHistoryItem.h"
155 #include "third_party/WebKit/public/web/WebHitTestResult.h"
156 #include "third_party/WebKit/public/web/WebInputElement.h"
157 #include "third_party/WebKit/public/web/WebInputEvent.h"
158 #include "third_party/WebKit/public/web/WebKit.h"
159 #include "third_party/WebKit/public/web/WebLocalFrame.h"
160 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
161 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
162 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
163 #include "third_party/WebKit/public/web/WebNodeList.h"
164 #include "third_party/WebKit/public/web/WebPageSerializer.h"
165 #include "third_party/WebKit/public/web/WebPlugin.h"
166 #include "third_party/WebKit/public/web/WebPluginAction.h"
167 #include "third_party/WebKit/public/web/WebPluginContainer.h"
168 #include "third_party/WebKit/public/web/WebPluginDocument.h"
169 #include "third_party/WebKit/public/web/WebRange.h"
170 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
171 #include "third_party/WebKit/public/web/WebScriptSource.h"
172 #include "third_party/WebKit/public/web/WebSearchableFormData.h"
173 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
174 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
175 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
176 #include "third_party/WebKit/public/web/WebSettings.h"
177 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
178 #include "third_party/WebKit/public/web/WebView.h"
179 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
180 #include "third_party/WebKit/public/web/default/WebRenderTheme.h"
181 #include "third_party/icu/source/common/unicode/uchar.h"
182 #include "third_party/icu/source/common/unicode/uscript.h"
183 #include "ui/base/clipboard/clipboard.h"
184 #include "ui/base/ui_base_switches_util.h"
185 #include "ui/events/latency_info.h"
186 #include "ui/gfx/native_widget_types.h"
187 #include "ui/gfx/point.h"
188 #include "ui/gfx/rect.h"
189 #include "ui/gfx/rect_conversions.h"
190 #include "ui/gfx/size_conversions.h"
191 #include "v8/include/v8.h"
193 #if defined(OS_ANDROID)
194 #include <cpu-features.h>
196 #include "content/renderer/android/address_detector.h"
197 #include "content/renderer/android/content_detector.h"
198 #include "content/renderer/android/email_detector.h"
199 #include "content/renderer/android/phone_number_detector.h"
200 #include "net/android/network_library.h"
201 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
202 #include "third_party/WebKit/public/platform/WebFloatRect.h"
203 #include "ui/gfx/rect_f.h"
205 #elif defined(OS_WIN)
206 // TODO(port): these files are currently Windows only because they concern:
208 #include "ui/native_theme/native_theme_win.h"
209 #elif defined(USE_X11)
210 #include "ui/native_theme/native_theme.h"
211 #elif defined(OS_MACOSX)
212 #include "skia/ext/skia_utils_mac.h"
215 #if defined(ENABLE_PLUGINS)
216 #include "content/renderer/npapi/webplugin_delegate_proxy.h"
217 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
218 #include "content/renderer/pepper/pepper_plugin_registry.h"
221 #if defined(ENABLE_WEBRTC)
222 #include "content/renderer/media/rtc_peer_connection_handler.h"
223 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
226 using blink::WebAXObject
;
227 using blink::WebApplicationCacheHost
;
228 using blink::WebApplicationCacheHostClient
;
229 using blink::WebCString
;
230 using blink::WebColor
;
231 using blink::WebColorName
;
232 using blink::WebConsoleMessage
;
233 using blink::WebData
;
234 using blink::WebDataSource
;
235 using blink::WebDocument
;
236 using blink::WebDOMEvent
;
237 using blink::WebDOMMessageEvent
;
238 using blink::WebDragData
;
239 using blink::WebDragOperation
;
240 using blink::WebDragOperationsMask
;
241 using blink::WebElement
;
242 using blink::WebFileChooserCompletion
;
243 using blink::WebFindOptions
;
244 using blink::WebFormControlElement
;
245 using blink::WebFormElement
;
246 using blink::WebFrame
;
247 using blink::WebGestureEvent
;
248 using blink::WebHistoryItem
;
249 using blink::WebHTTPBody
;
250 using blink::WebIconURL
;
251 using blink::WebImage
;
252 using blink::WebInputElement
;
253 using blink::WebInputEvent
;
254 using blink::WebLocalFrame
;
255 using blink::WebMediaPlayerAction
;
256 using blink::WebMouseEvent
;
257 using blink::WebNavigationPolicy
;
258 using blink::WebNavigationType
;
259 using blink::WebNode
;
260 using blink::WebPageSerializer
;
261 using blink::WebPageSerializerClient
;
262 using blink::WebPeerConnection00Handler
;
263 using blink::WebPeerConnection00HandlerClient
;
264 using blink::WebPeerConnectionHandler
;
265 using blink::WebPeerConnectionHandlerClient
;
266 using blink::WebPluginAction
;
267 using blink::WebPluginContainer
;
268 using blink::WebPluginDocument
;
269 using blink::WebPoint
;
270 using blink::WebRange
;
271 using blink::WebRect
;
272 using blink::WebReferrerPolicy
;
273 using blink::WebScriptSource
;
274 using blink::WebSearchableFormData
;
275 using blink::WebSecurityOrigin
;
276 using blink::WebSecurityPolicy
;
277 using blink::WebSerializedScriptValue
;
278 using blink::WebSettings
;
279 using blink::WebSize
;
280 using blink::WebStorageNamespace
;
281 using blink::WebStorageQuotaCallbacks
;
282 using blink::WebStorageQuotaError
;
283 using blink::WebStorageQuotaType
;
284 using blink::WebString
;
285 using blink::WebTextAffinity
;
286 using blink::WebTextDirection
;
287 using blink::WebTouchEvent
;
289 using blink::WebURLError
;
290 using blink::WebURLRequest
;
291 using blink::WebURLResponse
;
292 using blink::WebUserGestureIndicator
;
293 using blink::WebVector
;
294 using blink::WebView
;
295 using blink::WebWidget
;
296 using blink::WebWindowFeatures
;
297 using blink::WebNetworkStateNotifier
;
298 using blink::WebRuntimeFeatures
;
300 using base::TimeDelta
;
302 #if defined(OS_ANDROID)
303 using blink::WebContentDetectionResult
;
304 using blink::WebFloatPoint
;
305 using blink::WebFloatRect
;
306 using blink::WebHitTestResult
;
311 //-----------------------------------------------------------------------------
313 typedef std::map
<blink::WebView
*, RenderViewImpl
*> ViewMap
;
314 static base::LazyInstance
<ViewMap
> g_view_map
= LAZY_INSTANCE_INITIALIZER
;
315 typedef std::map
<int32
, RenderViewImpl
*> RoutingIDViewMap
;
316 static base::LazyInstance
<RoutingIDViewMap
> g_routing_id_view_map
=
317 LAZY_INSTANCE_INITIALIZER
;
319 // Time, in seconds, we delay before sending content state changes (such as form
320 // state and scroll position) to the browser. We delay sending changes to avoid
321 // spamming the browser.
322 // To avoid having tab/session restore require sending a message to get the
323 // current content state during tab closing we use a shorter timeout for the
324 // foreground renderer. This means there is a small window of time from which
325 // content state is modified and not sent to session restore, but this is
326 // better than having to wake up all renderers during shutdown.
327 const int kDelaySecondsForContentStateSyncHidden
= 5;
328 const int kDelaySecondsForContentStateSync
= 1;
330 #if defined(OS_ANDROID)
331 // Delay between tapping in content and launching the associated android intent.
332 // Used to allow users see what has been recognized as content.
333 const size_t kContentIntentDelayMilliseconds
= 700;
336 static RenderViewImpl
* (*g_create_render_view_impl
)(RenderViewImplParams
*) =
340 bool RenderViewImpl::IsReload(FrameMsg_Navigate_Type::Value navigation_type
) {
341 return navigation_type
== FrameMsg_Navigate_Type::RELOAD
||
342 navigation_type
== FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE
||
343 navigation_type
== FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL
;
347 Referrer
RenderViewImpl::GetReferrerFromRequest(
349 const WebURLRequest
& request
) {
350 return Referrer(GURL(request
.httpHeaderField(WebString::fromUTF8("Referer"))),
351 request
.referrerPolicy());
355 WindowOpenDisposition
RenderViewImpl::NavigationPolicyToDisposition(
356 WebNavigationPolicy policy
) {
358 case blink::WebNavigationPolicyIgnore
:
359 return IGNORE_ACTION
;
360 case blink::WebNavigationPolicyDownload
:
362 case blink::WebNavigationPolicyCurrentTab
:
364 case blink::WebNavigationPolicyNewBackgroundTab
:
365 return NEW_BACKGROUND_TAB
;
366 case blink::WebNavigationPolicyNewForegroundTab
:
367 return NEW_FOREGROUND_TAB
;
368 case blink::WebNavigationPolicyNewWindow
:
370 case blink::WebNavigationPolicyNewPopup
:
373 NOTREACHED() << "Unexpected WebNavigationPolicy";
374 return IGNORE_ACTION
;
378 // Returns true if the device scale is high enough that losing subpixel
379 // antialiasing won't have a noticeable effect on text quality.
380 static bool DeviceScaleEnsuresTextQuality(float device_scale_factor
) {
381 #if defined(OS_ANDROID)
382 // On Android, we never have subpixel antialiasing.
385 return device_scale_factor
> 1.5f
;
390 static bool PreferCompositingToLCDText(float device_scale_factor
) {
391 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
392 if (command_line
.HasSwitch(switches::kDisablePreferCompositingToLCDText
))
394 if (command_line
.HasSwitch(switches::kEnablePreferCompositingToLCDText
))
396 if (RenderThreadImpl::current() &&
397 !RenderThreadImpl::current()->is_lcd_text_enabled())
399 return DeviceScaleEnsuresTextQuality(device_scale_factor
);
402 static bool ShouldUseTransitionCompositing(float device_scale_factor
) {
403 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
405 if (command_line
.HasSwitch(switches::kDisableCompositingForTransition
))
408 if (command_line
.HasSwitch(switches::kEnableCompositingForTransition
))
411 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
412 // of excessive layer promotion caused by overlap has been addressed.
413 // http://crbug.com/178119.
417 static FaviconURL::IconType
ToFaviconType(blink::WebIconURL::Type type
) {
419 case blink::WebIconURL::TypeFavicon
:
420 return FaviconURL::FAVICON
;
421 case blink::WebIconURL::TypeTouch
:
422 return FaviconURL::TOUCH_ICON
;
423 case blink::WebIconURL::TypeTouchPrecomposed
:
424 return FaviconURL::TOUCH_PRECOMPOSED_ICON
;
425 case blink::WebIconURL::TypeInvalid
:
426 return FaviconURL::INVALID_ICON
;
428 return FaviconURL::INVALID_ICON
;
431 static void ConvertToFaviconSizes(
432 const blink::WebVector
<blink::WebSize
>& web_sizes
,
433 std::vector
<gfx::Size
>* sizes
) {
434 DCHECK(sizes
->empty());
435 sizes
->reserve(web_sizes
.size());
436 for (size_t i
= 0; i
< web_sizes
.size(); ++i
)
437 sizes
->push_back(gfx::Size(web_sizes
[i
]));
440 ///////////////////////////////////////////////////////////////////////////////
442 struct RenderViewImpl::PendingFileChooser
{
443 PendingFileChooser(const FileChooserParams
& p
, WebFileChooserCompletion
* c
)
447 FileChooserParams params
;
448 WebFileChooserCompletion
* completion
; // MAY BE NULL to skip callback.
453 class WebWidgetLockTarget
: public MouseLockDispatcher::LockTarget
{
455 explicit WebWidgetLockTarget(blink::WebWidget
* webwidget
)
456 : webwidget_(webwidget
) {}
458 void OnLockMouseACK(bool succeeded
) override
{
460 webwidget_
->didAcquirePointerLock();
462 webwidget_
->didNotAcquirePointerLock();
465 void OnMouseLockLost() override
{ webwidget_
->didLosePointerLock(); }
467 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent
& event
) override
{
468 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
473 blink::WebWidget
* webwidget_
;
476 bool TouchEnabled() {
477 // Based on the definition of chrome::kEnableTouchIcon.
478 #if defined(OS_ANDROID)
485 WebDragData
DropDataToWebDragData(const DropData
& drop_data
) {
486 std::vector
<WebDragData::Item
> item_list
;
488 // These fields are currently unused when dragging into WebKit.
489 DCHECK(drop_data
.download_metadata
.empty());
490 DCHECK(drop_data
.file_contents
.empty());
491 DCHECK(drop_data
.file_description_filename
.empty());
493 if (!drop_data
.text
.is_null()) {
494 WebDragData::Item item
;
495 item
.storageType
= WebDragData::Item::StorageTypeString
;
496 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeText
);
497 item
.stringData
= drop_data
.text
.string();
498 item_list
.push_back(item
);
501 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
502 // meaningful to write an empty URL to the clipboard?
503 if (!drop_data
.url
.is_empty()) {
504 WebDragData::Item item
;
505 item
.storageType
= WebDragData::Item::StorageTypeString
;
506 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList
);
507 item
.stringData
= WebString::fromUTF8(drop_data
.url
.spec());
508 item
.title
= drop_data
.url_title
;
509 item_list
.push_back(item
);
512 if (!drop_data
.html
.is_null()) {
513 WebDragData::Item item
;
514 item
.storageType
= WebDragData::Item::StorageTypeString
;
515 item
.stringType
= WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML
);
516 item
.stringData
= drop_data
.html
.string();
517 item
.baseURL
= drop_data
.html_base_url
;
518 item_list
.push_back(item
);
521 for (std::vector
<ui::FileInfo
>::const_iterator it
=
522 drop_data
.filenames
.begin();
523 it
!= drop_data
.filenames
.end();
525 WebDragData::Item item
;
526 item
.storageType
= WebDragData::Item::StorageTypeFilename
;
527 item
.filenameData
= it
->path
.AsUTF16Unsafe();
528 item
.displayNameData
= it
->display_name
.AsUTF16Unsafe();
529 item_list
.push_back(item
);
532 for (std::vector
<DropData::FileSystemFileInfo
>::const_iterator it
=
533 drop_data
.file_system_files
.begin();
534 it
!= drop_data
.file_system_files
.end();
536 WebDragData::Item item
;
537 item
.storageType
= WebDragData::Item::StorageTypeFileSystemFile
;
538 item
.fileSystemURL
= it
->url
;
539 item
.fileSystemFileSize
= it
->size
;
540 item_list
.push_back(item
);
543 for (std::map
<base::string16
, base::string16
>::const_iterator it
=
544 drop_data
.custom_data
.begin();
545 it
!= drop_data
.custom_data
.end();
547 WebDragData::Item item
;
548 item
.storageType
= WebDragData::Item::StorageTypeString
;
549 item
.stringType
= it
->first
;
550 item
.stringData
= it
->second
;
551 item_list
.push_back(item
);
556 result
.setItems(item_list
);
557 result
.setFilesystemId(drop_data
.filesystem_id
);
561 typedef void (*SetFontFamilyWrapper
)(blink::WebSettings
*,
562 const base::string16
&,
565 void SetStandardFontFamilyWrapper(WebSettings
* settings
,
566 const base::string16
& font
,
567 UScriptCode script
) {
568 settings
->setStandardFontFamily(font
, script
);
571 void SetFixedFontFamilyWrapper(WebSettings
* settings
,
572 const base::string16
& font
,
573 UScriptCode script
) {
574 settings
->setFixedFontFamily(font
, script
);
577 void SetSerifFontFamilyWrapper(WebSettings
* settings
,
578 const base::string16
& font
,
579 UScriptCode script
) {
580 settings
->setSerifFontFamily(font
, script
);
583 void SetSansSerifFontFamilyWrapper(WebSettings
* settings
,
584 const base::string16
& font
,
585 UScriptCode script
) {
586 settings
->setSansSerifFontFamily(font
, script
);
589 void SetCursiveFontFamilyWrapper(WebSettings
* settings
,
590 const base::string16
& font
,
591 UScriptCode script
) {
592 settings
->setCursiveFontFamily(font
, script
);
595 void SetFantasyFontFamilyWrapper(WebSettings
* settings
,
596 const base::string16
& font
,
597 UScriptCode script
) {
598 settings
->setFantasyFontFamily(font
, script
);
601 void SetPictographFontFamilyWrapper(WebSettings
* settings
,
602 const base::string16
& font
,
603 UScriptCode script
) {
604 settings
->setPictographFontFamily(font
, script
);
607 // If |scriptCode| is a member of a family of "similar" script codes, returns
608 // the script code in that family that is used by WebKit for font selection
609 // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
610 // considered equivalent for the purposes of font selection. WebKit uses the
611 // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
612 // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
613 // uses different scripts than the ones in Chrome pref names because the version
614 // of ICU included on certain ports does not have some of the newer scripts. If
615 // |scriptCode| is not a member of such a family, returns |scriptCode|.
616 UScriptCode
GetScriptForWebSettings(UScriptCode scriptCode
) {
617 switch (scriptCode
) {
618 case USCRIPT_HIRAGANA
:
619 case USCRIPT_KATAKANA
:
620 case USCRIPT_JAPANESE
:
621 return USCRIPT_KATAKANA_OR_HIRAGANA
;
623 return USCRIPT_HANGUL
;
629 void ApplyFontsFromMap(const ScriptFontFamilyMap
& map
,
630 SetFontFamilyWrapper setter
,
631 WebSettings
* settings
) {
632 for (ScriptFontFamilyMap::const_iterator it
= map
.begin(); it
!= map
.end();
634 int32 script
= u_getPropertyValueEnum(UCHAR_SCRIPT
, (it
->first
).c_str());
635 if (script
>= 0 && script
< USCRIPT_CODE_LIMIT
) {
636 UScriptCode code
= static_cast<UScriptCode
>(script
);
637 (*setter
)(settings
, it
->second
, GetScriptForWebSettings(code
));
644 RenderViewImpl::RenderViewImpl(RenderViewImplParams
* params
)
645 : RenderWidget(blink::WebPopupTypeNone
,
649 params
->never_visible
),
650 webkit_preferences_(params
->webkit_prefs
),
651 send_content_state_immediately_(false),
652 enabled_bindings_(0),
653 send_preferred_size_changes_(false),
654 navigation_gesture_(NavigationGestureUnknown
),
655 opened_by_user_gesture_(true),
656 opener_suppressed_(false),
657 suppress_dialogs_until_swap_out_(false),
659 last_page_id_sent_to_browser_(-1),
660 next_page_id_(params
->next_page_id
),
661 history_list_offset_(-1),
662 history_list_length_(0),
663 frames_in_progress_(0),
664 target_url_status_(TARGET_NONE
),
665 uses_temporary_zoom_level_(false),
666 #if defined(OS_ANDROID)
667 top_controls_constraints_(cc::BOTH
),
669 has_scrolled_focused_editable_node_into_rect_(false),
670 speech_recognition_dispatcher_(NULL
),
671 browser_plugin_manager_(NULL
),
672 devtools_agent_(NULL
),
673 mouse_lock_dispatcher_(NULL
),
674 #if defined(OS_ANDROID)
675 expected_content_intent_id_(0),
678 focused_plugin_id_(-1),
680 #if defined(ENABLE_PLUGINS)
681 plugin_find_handler_(NULL
),
682 focused_pepper_plugin_(NULL
),
683 pepper_last_mouse_event_target_(NULL
),
685 enumeration_completion_id_(0),
686 session_storage_namespace_id_(params
->session_storage_namespace_id
),
687 next_snapshot_id_(0) {
690 void RenderViewImpl::Initialize(RenderViewImplParams
* params
) {
691 routing_id_
= params
->routing_id
;
692 surface_id_
= params
->surface_id
;
693 if (params
->opener_id
!= MSG_ROUTING_NONE
&& params
->is_renderer_created
)
694 opener_id_
= params
->opener_id
;
696 // Ensure we start with a valid next_page_id_ from the browser.
697 DCHECK_GE(next_page_id_
, 0);
699 main_render_frame_
.reset(RenderFrameImpl::Create(
700 this, params
->main_frame_routing_id
));
701 // The main frame WebLocalFrame object is closed by
702 // RenderFrameImpl::frameDetached().
703 WebLocalFrame
* web_frame
= WebLocalFrame::create(main_render_frame_
.get());
704 main_render_frame_
->SetWebFrame(web_frame
);
706 webwidget_
= WebView::create(this);
707 webwidget_mouse_lock_target_
.reset(new WebWidgetLockTarget(webwidget_
));
709 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
711 if (command_line
.HasSwitch(switches::kStatsCollectionController
))
712 stats_collection_observer_
.reset(new StatsCollectionObserver(this));
714 #if defined(OS_ANDROID)
715 const std::string region_code
=
716 command_line
.HasSwitch(switches::kNetworkCountryIso
)
717 ? command_line
.GetSwitchValueASCII(switches::kNetworkCountryIso
)
718 : net::android::GetTelephonyNetworkCountryIso();
719 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
720 new AddressDetector()));
721 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
722 new PhoneNumberDetector(region_code
)));
723 content_detectors_
.push_back(linked_ptr
<ContentDetector
>(
724 new EmailDetector()));
727 RenderThread::Get()->AddRoute(routing_id_
, this);
728 // Take a reference on behalf of the RenderThread. This will be balanced
729 // when we receive ViewMsg_ClosePage.
731 if (RenderThreadImpl::current()) {
732 RenderThreadImpl::current()->WidgetCreated();
734 RenderThreadImpl::current()->WidgetHidden();
737 // If this is a popup, we must wait for the CreatingNew_ACK message before
738 // completing initialization. Otherwise, we can finish it now.
739 if (opener_id_
== MSG_ROUTING_NONE
) {
744 g_view_map
.Get().insert(std::make_pair(webview(), this));
745 g_routing_id_view_map
.Get().insert(std::make_pair(routing_id_
, this));
746 webview()->setDeviceScaleFactor(device_scale_factor_
);
747 webview()->settings()->setPreferCompositingToLCDTextEnabled(
748 PreferCompositingToLCDText(device_scale_factor_
));
749 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
750 ShouldUseTransitionCompositing(device_scale_factor_
));
751 webview()->settings()->setThreadedScrollingEnabled(
752 !command_line
.HasSwitch(switches::kDisableThreadedScrolling
));
753 webview()->settings()->setRootLayerScrolls(
754 command_line
.HasSwitch(switches::kRootLayerScrolls
));
756 ApplyWebPreferences(webkit_preferences_
, webview());
758 webview()->settings()->setAllowConnectingInsecureWebSocket(
759 command_line
.HasSwitch(switches::kAllowInsecureWebSocketFromHttpsOrigin
));
761 RenderFrameProxy
* proxy
= NULL
;
762 if (params
->proxy_routing_id
!= MSG_ROUTING_NONE
) {
763 CHECK(params
->swapped_out
);
764 proxy
= RenderFrameProxy::CreateProxyToReplaceFrame(
765 main_render_frame_
.get(), params
->proxy_routing_id
);
766 main_render_frame_
->set_render_frame_proxy(proxy
);
769 // In --site-per-process, just use the WebRemoteFrame as the main frame.
770 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess
) &&
772 webview()->setMainFrame(proxy
->web_frame());
774 webview()->setMainFrame(main_render_frame_
->GetWebFrame());
776 main_render_frame_
->Initialize();
778 if (switches::IsTouchDragDropEnabled())
779 webview()->settings()->setTouchDragDropEnabled(true);
781 if (switches::IsTouchEditingEnabled())
782 webview()->settings()->setTouchEditingEnabled(true);
784 if (!params
->frame_name
.empty())
785 webview()->mainFrame()->setName(params
->frame_name
);
787 // TODO(davidben): Move this state from Blink into content.
788 if (params
->window_was_created_with_opener
)
789 webview()->setOpenedByDOM();
791 OnSetRendererPrefs(params
->renderer_prefs
);
793 new MHTMLGenerator(this);
794 #if defined(OS_MACOSX)
795 new TextInputClientObserver(this);
796 #endif // defined(OS_MACOSX)
798 // The next group of objects all implement RenderViewObserver, so are deleted
799 // along with the RenderView automatically.
800 devtools_agent_
= new DevToolsAgent(this);
801 if (RenderWidgetCompositor
* rwc
= compositor()) {
802 webview()->devToolsAgent()->setLayerTreeId(rwc
->GetLayerTreeId());
804 mouse_lock_dispatcher_
= new RenderViewMouseLockDispatcher(this);
806 history_controller_
.reset(new HistoryController(this));
808 new IdleUserDetector(this);
810 if (command_line
.HasSwitch(switches::kDomAutomationController
))
811 enabled_bindings_
|= BINDINGS_POLICY_DOM_AUTOMATION
;
812 if (command_line
.HasSwitch(switches::kStatsCollectionController
))
813 enabled_bindings_
|= BINDINGS_POLICY_STATS_COLLECTION
;
815 ProcessViewLayoutFlags(command_line
);
817 GetContentClient()->renderer()->RenderViewCreated(this);
819 // If we have an opener_id but we weren't created by a renderer, then
820 // it's the browser asking us to set our opener to another RenderView.
821 if (params
->opener_id
!= MSG_ROUTING_NONE
&& !params
->is_renderer_created
) {
822 RenderViewImpl
* opener_view
= FromRoutingID(params
->opener_id
);
824 webview()->mainFrame()->setOpener(opener_view
->webview()->mainFrame());
827 // If we are initially swapped out, navigate to kSwappedOutURL.
828 // This ensures we are in a unique origin that others cannot script.
829 if (is_swapped_out_
&& webview()->mainFrame()->isWebLocalFrame())
830 NavigateToSwappedOutURL(webview()->mainFrame());
833 RenderViewImpl::~RenderViewImpl() {
834 for (BitmapMap::iterator it
= disambiguation_bitmaps_
.begin();
835 it
!= disambiguation_bitmaps_
.end();
838 history_page_ids_
.clear();
840 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_
);
842 // If file chooser is still waiting for answer, dispatch empty answer.
843 while (!file_chooser_completions_
.empty()) {
844 if (file_chooser_completions_
.front()->completion
) {
845 file_chooser_completions_
.front()->completion
->didChooseFile(
846 WebVector
<WebString
>());
848 file_chooser_completions_
.pop_front();
851 #if defined(OS_ANDROID)
852 // The date/time picker client is both a scoped_ptr member of this class and
853 // a RenderViewObserver. Reset it to prevent double deletion.
854 date_time_picker_client_
.reset();
858 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
859 ViewMap
* views
= g_view_map
.Pointer();
860 for (ViewMap::iterator it
= views
->begin(); it
!= views
->end(); ++it
)
861 DCHECK_NE(this, it
->second
) << "Failed to call Close?";
862 RoutingIDViewMap
* routing_id_views
= g_routing_id_view_map
.Pointer();
863 for (RoutingIDViewMap::iterator it
= routing_id_views
->begin();
864 it
!= routing_id_views
->end(); ++it
)
865 DCHECK_NE(this, it
->second
) << "Failed to call Close?";
868 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, RenderViewGone());
869 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, OnDestruct());
873 RenderViewImpl
* RenderViewImpl::FromWebView(WebView
* webview
) {
874 ViewMap
* views
= g_view_map
.Pointer();
875 ViewMap::iterator it
= views
->find(webview
);
876 return it
== views
->end() ? NULL
: it
->second
;
880 RenderView
* RenderView::FromWebView(blink::WebView
* webview
) {
881 return RenderViewImpl::FromWebView(webview
);
885 RenderViewImpl
* RenderViewImpl::FromRoutingID(int32 routing_id
) {
886 RoutingIDViewMap
* views
= g_routing_id_view_map
.Pointer();
887 RoutingIDViewMap::iterator it
= views
->find(routing_id
);
888 return it
== views
->end() ? NULL
: it
->second
;
892 RenderView
* RenderView::FromRoutingID(int routing_id
) {
893 return RenderViewImpl::FromRoutingID(routing_id
);
897 size_t RenderViewImpl::GetRenderViewCount() {
898 return g_view_map
.Get().size();
902 void RenderView::ForEach(RenderViewVisitor
* visitor
) {
903 ViewMap
* views
= g_view_map
.Pointer();
904 for (ViewMap::iterator it
= views
->begin(); it
!= views
->end(); ++it
) {
905 if (!visitor
->Visit(it
->second
))
911 void RenderView::ApplyWebPreferences(const WebPreferences
& prefs
,
913 WebSettings
* settings
= web_view
->settings();
914 ApplyFontsFromMap(prefs
.standard_font_family_map
,
915 SetStandardFontFamilyWrapper
, settings
);
916 ApplyFontsFromMap(prefs
.fixed_font_family_map
,
917 SetFixedFontFamilyWrapper
, settings
);
918 ApplyFontsFromMap(prefs
.serif_font_family_map
,
919 SetSerifFontFamilyWrapper
, settings
);
920 ApplyFontsFromMap(prefs
.sans_serif_font_family_map
,
921 SetSansSerifFontFamilyWrapper
, settings
);
922 ApplyFontsFromMap(prefs
.cursive_font_family_map
,
923 SetCursiveFontFamilyWrapper
, settings
);
924 ApplyFontsFromMap(prefs
.fantasy_font_family_map
,
925 SetFantasyFontFamilyWrapper
, settings
);
926 ApplyFontsFromMap(prefs
.pictograph_font_family_map
,
927 SetPictographFontFamilyWrapper
, settings
);
928 settings
->setDefaultFontSize(prefs
.default_font_size
);
929 settings
->setDefaultFixedFontSize(prefs
.default_fixed_font_size
);
930 settings
->setMinimumFontSize(prefs
.minimum_font_size
);
931 settings
->setMinimumLogicalFontSize(prefs
.minimum_logical_font_size
);
932 settings
->setDefaultTextEncodingName(
933 base::ASCIIToUTF16(prefs
.default_encoding
));
934 settings
->setJavaScriptEnabled(prefs
.javascript_enabled
);
935 settings
->setWebSecurityEnabled(prefs
.web_security_enabled
);
936 settings
->setJavaScriptCanOpenWindowsAutomatically(
937 prefs
.javascript_can_open_windows_automatically
);
938 settings
->setLoadsImagesAutomatically(prefs
.loads_images_automatically
);
939 settings
->setImagesEnabled(prefs
.images_enabled
);
940 settings
->setPluginsEnabled(prefs
.plugins_enabled
);
941 settings
->setDOMPasteAllowed(prefs
.dom_paste_enabled
);
942 settings
->setShrinksStandaloneImagesToFit(
943 prefs
.shrinks_standalone_images_to_fit
);
944 settings
->setUsesEncodingDetector(prefs
.uses_universal_detector
);
945 settings
->setTextAreasAreResizable(prefs
.text_areas_are_resizable
);
946 settings
->setAllowScriptsToCloseWindows(prefs
.allow_scripts_to_close_windows
);
947 settings
->setDownloadableBinaryFontsEnabled(prefs
.remote_fonts_enabled
);
948 settings
->setJavaScriptCanAccessClipboard(
949 prefs
.javascript_can_access_clipboard
);
950 WebRuntimeFeatures::enableXSLT(prefs
.xslt_enabled
);
951 WebRuntimeFeatures::enableSlimmingPaint(prefs
.slimming_paint_enabled
);
952 settings
->setXSSAuditorEnabled(prefs
.xss_auditor_enabled
);
953 settings
->setDNSPrefetchingEnabled(prefs
.dns_prefetching_enabled
);
954 settings
->setLocalStorageEnabled(prefs
.local_storage_enabled
);
955 settings
->setSyncXHRInDocumentsEnabled(prefs
.sync_xhr_in_documents_enabled
);
956 WebRuntimeFeatures::enableDatabase(prefs
.databases_enabled
);
957 settings
->setOfflineWebApplicationCacheEnabled(
958 prefs
.application_cache_enabled
);
959 settings
->setCaretBrowsingEnabled(prefs
.caret_browsing_enabled
);
960 settings
->setHyperlinkAuditingEnabled(prefs
.hyperlink_auditing_enabled
);
961 settings
->setCookieEnabled(prefs
.cookie_enabled
);
962 settings
->setNavigateOnDragDrop(prefs
.navigate_on_drag_drop
);
964 settings
->setJavaEnabled(prefs
.java_enabled
);
966 // By default, allow_universal_access_from_file_urls is set to false and thus
967 // we mitigate attacks from local HTML files by not granting file:// URLs
968 // universal access. Only test shell will enable this.
969 settings
->setAllowUniversalAccessFromFileURLs(
970 prefs
.allow_universal_access_from_file_urls
);
971 settings
->setAllowFileAccessFromFileURLs(
972 prefs
.allow_file_access_from_file_urls
);
974 // Enable the web audio API if requested on the command line.
975 settings
->setWebAudioEnabled(prefs
.webaudio_enabled
);
977 // Enable experimental WebGL support if requested on command line
978 // and support is compiled in.
979 settings
->setExperimentalWebGLEnabled(prefs
.experimental_webgl_enabled
);
981 // Disable GL multisampling if requested on command line.
982 settings
->setOpenGLMultisamplingEnabled(prefs
.gl_multisampling_enabled
);
984 // Enable WebGL errors to the JS console if requested.
985 settings
->setWebGLErrorsToConsoleEnabled(
986 prefs
.webgl_errors_to_console_enabled
);
988 // Uses the mock theme engine for scrollbars.
989 settings
->setMockScrollbarsEnabled(prefs
.mock_scrollbars_enabled
);
991 settings
->setLayerSquashingEnabled(prefs
.layer_squashing_enabled
);
993 // Enable gpu-accelerated 2d canvas if requested on the command line.
994 settings
->setAccelerated2dCanvasEnabled(prefs
.accelerated_2d_canvas_enabled
);
996 settings
->setMinimumAccelerated2dCanvasSize(
997 prefs
.minimum_accelerated_2d_canvas_size
);
999 // Disable antialiasing for 2d canvas if requested on the command line.
1000 settings
->setAntialiased2dCanvasEnabled(
1001 !prefs
.antialiased_2d_canvas_disabled
);
1003 // Enabled antialiasing of clips for 2d canvas if requested on the command
1005 settings
->setAntialiasedClips2dCanvasEnabled(
1006 prefs
.antialiased_clips_2d_canvas_enabled
);
1008 // Set MSAA sample count for 2d canvas if requested on the command line (or
1009 // default value if not).
1010 settings
->setAccelerated2dCanvasMSAASampleCount(
1011 prefs
.accelerated_2d_canvas_msaa_sample_count
);
1013 // Enable container culling if requested on the command line.
1014 settings
->setContainerCullingEnabled(prefs
.container_culling_enabled
);
1016 WebRuntimeFeatures::enableTextBlobs(prefs
.text_blobs_enabled
);
1018 settings
->setAsynchronousSpellCheckingEnabled(
1019 prefs
.asynchronous_spell_checking_enabled
);
1020 settings
->setUnifiedTextCheckerEnabled(prefs
.unified_textchecker_enabled
);
1022 // Tabs to link is not part of the settings. WebCore calls
1023 // ChromeClient::tabsToLinks which is part of the glue code.
1024 web_view
->setTabsToLinks(prefs
.tabs_to_links
);
1026 settings
->setAllowDisplayOfInsecureContent(
1027 prefs
.allow_displaying_insecure_content
);
1028 settings
->setAllowRunningOfInsecureContent(
1029 prefs
.allow_running_insecure_content
);
1030 settings
->setPasswordEchoEnabled(prefs
.password_echo_enabled
);
1031 settings
->setShouldPrintBackgrounds(prefs
.should_print_backgrounds
);
1032 settings
->setShouldClearDocumentBackground(
1033 prefs
.should_clear_document_background
);
1034 settings
->setEnableScrollAnimator(prefs
.enable_scroll_animator
);
1036 settings
->setRegionBasedColumnsEnabled(prefs
.region_based_columns_enabled
);
1038 WebRuntimeFeatures::enableTouch(prefs
.touch_enabled
);
1039 settings
->setMaxTouchPoints(prefs
.pointer_events_max_touch_points
);
1040 settings
->setDeviceSupportsTouch(prefs
.device_supports_touch
);
1041 settings
->setDeviceSupportsMouse(prefs
.device_supports_mouse
);
1042 settings
->setEnableTouchAdjustment(prefs
.touch_adjustment_enabled
);
1044 settings
->setDeferredImageDecodingEnabled(
1045 prefs
.deferred_image_decoding_enabled
);
1046 WebRuntimeFeatures::enableImageColorProfiles(
1047 prefs
.image_color_profiles_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 settings
->setV8ScriptStreamingEnabled(prefs
.v8_script_streaming_enabled
);
1073 settings
->setV8ScriptStreamingMode(
1074 static_cast<WebSettings::V8ScriptStreamingMode
>(
1075 prefs
.v8_script_streaming_mode
));
1077 #if defined(OS_ANDROID)
1078 settings
->setAllowCustomScrollbarInMainFrame(false);
1079 settings
->setTextAutosizingEnabled(prefs
.text_autosizing_enabled
);
1080 settings
->setAccessibilityFontScaleFactor(prefs
.font_scale_factor
);
1081 settings
->setDeviceScaleAdjustment(prefs
.device_scale_adjustment
);
1082 settings
->setFullscreenSupported(prefs
.fullscreen_supported
);
1083 web_view
->setIgnoreViewportTagScaleLimits(prefs
.force_enable_zoom
);
1084 settings
->setAutoZoomFocusedNodeToLegibleScale(true);
1085 settings
->setDoubleTapToZoomEnabled(prefs
.double_tap_to_zoom_enabled
);
1086 settings
->setMediaControlsOverlayPlayButtonEnabled(true);
1087 settings
->setMediaPlaybackRequiresUserGesture(
1088 prefs
.user_gesture_required_for_media_playback
);
1089 settings
->setDefaultVideoPosterURL(
1090 base::ASCIIToUTF16(prefs
.default_video_poster_url
.spec()));
1091 settings
->setSupportDeprecatedTargetDensityDPI(
1092 prefs
.support_deprecated_target_density_dpi
);
1093 settings
->setUseLegacyBackgroundSizeShorthandBehavior(
1094 prefs
.use_legacy_background_size_shorthand_behavior
);
1095 settings
->setWideViewportQuirkEnabled(prefs
.wide_viewport_quirk
);
1096 settings
->setUseWideViewport(prefs
.use_wide_viewport
);
1097 settings
->setForceZeroLayoutHeight(prefs
.force_zero_layout_height
);
1098 settings
->setViewportMetaLayoutSizeQuirk(
1099 prefs
.viewport_meta_layout_size_quirk
);
1100 settings
->setViewportMetaMergeContentQuirk(
1101 prefs
.viewport_meta_merge_content_quirk
);
1102 settings
->setViewportMetaNonUserScalableQuirk(
1103 prefs
.viewport_meta_non_user_scalable_quirk
);
1104 settings
->setViewportMetaZeroValuesQuirk(
1105 prefs
.viewport_meta_zero_values_quirk
);
1106 settings
->setClobberUserAgentInitialScaleQuirk(
1107 prefs
.clobber_user_agent_initial_scale_quirk
);
1108 settings
->setIgnoreMainFrameOverflowHiddenQuirk(
1109 prefs
.ignore_main_frame_overflow_hidden_quirk
);
1110 settings
->setReportScreenSizeInPhysicalPixelsQuirk(
1111 prefs
.report_screen_size_in_physical_pixels_quirk
);
1112 settings
->setMainFrameClipsContent(false);
1113 settings
->setShrinksStandaloneImagesToFit(false);
1114 settings
->setShrinksViewportContentToFit(true);
1117 WebNetworkStateNotifier::setOnLine(prefs
.is_online
);
1118 WebNetworkStateNotifier::setWebConnectionType(
1119 NetConnectionTypeToWebConnectionType(prefs
.connection_type
));
1120 settings
->setPinchVirtualViewportEnabled(
1121 prefs
.pinch_virtual_viewport_enabled
);
1123 settings
->setPinchOverlayScrollbarThickness(
1124 prefs
.pinch_overlay_scrollbar_thickness
);
1125 settings
->setUseSolidColorScrollbars(prefs
.use_solid_color_scrollbars
);
1129 RenderViewImpl
* RenderViewImpl::Create(
1131 bool window_was_created_with_opener
,
1132 const RendererPreferences
& renderer_prefs
,
1133 const WebPreferences
& webkit_prefs
,
1135 int32 main_frame_routing_id
,
1137 int64 session_storage_namespace_id
,
1138 const base::string16
& frame_name
,
1139 bool is_renderer_created
,
1141 int32 proxy_routing_id
,
1145 const blink::WebScreenInfo
& screen_info
) {
1146 DCHECK(routing_id
!= MSG_ROUTING_NONE
);
1147 RenderViewImplParams
params(opener_id
,
1148 window_was_created_with_opener
,
1152 main_frame_routing_id
,
1154 session_storage_namespace_id
,
1156 is_renderer_created
,
1163 RenderViewImpl
* render_view
= NULL
;
1164 if (g_create_render_view_impl
)
1165 render_view
= g_create_render_view_impl(¶ms
);
1167 render_view
= new RenderViewImpl(¶ms
);
1169 render_view
->Initialize(¶ms
);
1174 void RenderViewImpl::InstallCreateHook(
1175 RenderViewImpl
* (*create_render_view_impl
)(RenderViewImplParams
*)) {
1176 CHECK(!g_create_render_view_impl
);
1177 g_create_render_view_impl
= create_render_view_impl
;
1180 void RenderViewImpl::AddObserver(RenderViewObserver
* observer
) {
1181 observers_
.AddObserver(observer
);
1184 void RenderViewImpl::RemoveObserver(RenderViewObserver
* observer
) {
1185 observer
->RenderViewGone();
1186 observers_
.RemoveObserver(observer
);
1189 blink::WebView
* RenderViewImpl::webview() const {
1190 return static_cast<blink::WebView
*>(webwidget());
1193 #if defined(ENABLE_PLUGINS)
1194 void RenderViewImpl::PepperInstanceCreated(
1195 PepperPluginInstanceImpl
* instance
) {
1196 active_pepper_instances_
.insert(instance
);
1199 void RenderViewImpl::PepperInstanceDeleted(
1200 PepperPluginInstanceImpl
* instance
) {
1201 active_pepper_instances_
.erase(instance
);
1203 if (pepper_last_mouse_event_target_
== instance
)
1204 pepper_last_mouse_event_target_
= NULL
;
1205 if (focused_pepper_plugin_
== instance
)
1206 PepperFocusChanged(instance
, false);
1209 void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl
* instance
,
1212 focused_pepper_plugin_
= instance
;
1213 else if (focused_pepper_plugin_
== instance
)
1214 focused_pepper_plugin_
= NULL
;
1216 UpdateTextInputType();
1217 UpdateSelectionBounds();
1220 void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
) {
1221 plugin_delegates_
.insert(delegate
);
1222 // If the renderer is visible, set initial visibility and focus state.
1224 #if defined(OS_MACOSX)
1225 delegate
->SetContainerVisibility(true);
1226 if (webview() && webview()->isActive())
1227 delegate
->SetWindowFocus(true);
1230 // Plugins start assuming the content has focus (so that they work in
1231 // environments where RenderView isn't hosting them), so we always have to
1232 // set the initial state. See webplugin_delegate_impl.h for details.
1233 delegate
->SetContentAreaFocus(has_focus());
1236 void RenderViewImpl::UnregisterPluginDelegate(
1237 WebPluginDelegateProxy
* delegate
) {
1238 plugin_delegates_
.erase(delegate
);
1242 void RenderViewImpl::PluginFocusChanged(bool focused
, int plugin_id
) {
1244 focused_plugin_id_
= plugin_id
;
1246 focused_plugin_id_
= -1;
1250 #if defined(OS_MACOSX)
1251 void RenderViewImpl::PluginFocusChanged(bool focused
, int plugin_id
) {
1252 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused
, plugin_id
));
1255 void RenderViewImpl::OnGetRenderedText() {
1258 // Get rendered text from WebLocalFrame.
1259 // TODO: Currently IPC truncates any data that has a
1260 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1261 // send back using multiple IPC. See http://crbug.com/393444.
1262 static const size_t kMaximumMessageSize
= 8 * 1024 * 1024;
1263 std::string text
= webview()->mainFrame()->contentAsText(
1264 kMaximumMessageSize
).utf8();
1266 Send(new ViewMsg_GetRenderedTextCompleted(routing_id(), text
));
1269 void RenderViewImpl::StartPluginIme() {
1270 IPC::Message
* msg
= new ViewHostMsg_StartPluginIme(routing_id());
1271 // This message can be sent during event-handling, and needs to be delivered
1272 // within that context.
1273 msg
->set_unblock(true);
1276 #endif // defined(OS_MACOSX)
1278 #endif // ENABLE_PLUGINS
1280 void RenderViewImpl::TransferActiveWheelFlingAnimation(
1281 const blink::WebActiveWheelFlingParameters
& params
) {
1283 webview()->transferActiveWheelFlingAnimation(params
);
1286 bool RenderViewImpl::HasIMETextFocus() {
1287 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE
;
1290 bool RenderViewImpl::OnMessageReceived(const IPC::Message
& message
) {
1291 WebFrame
* main_frame
= webview() ? webview()->mainFrame() : NULL
;
1292 if (main_frame
&& main_frame
->isWebLocalFrame())
1293 GetContentClient()->SetActiveURL(main_frame
->document().url());
1295 ObserverListBase
<RenderViewObserver
>::Iterator
it(observers_
);
1296 RenderViewObserver
* observer
;
1297 while ((observer
= it
.GetNext()) != NULL
)
1298 if (observer
->OnMessageReceived(message
))
1301 bool handled
= true;
1302 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl
, message
)
1303 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand
, OnExecuteEditCommand
)
1304 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret
, OnMoveCaret
)
1305 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect
,
1306 OnScrollFocusedEditableNodeIntoRect
)
1307 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent
,
1308 OnSetEditCommandsForNextKeyEvent
)
1309 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt
, OnCopyImageAt
)
1310 IPC_MESSAGE_HANDLER(ViewMsg_SaveImageAt
, OnSaveImageAt
)
1311 IPC_MESSAGE_HANDLER(ViewMsg_Find
, OnFind
)
1312 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding
, OnStopFinding
)
1313 IPC_MESSAGE_HANDLER(ViewMsg_Zoom
, OnZoom
)
1314 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL
,
1315 OnSetZoomLevelForLoadingURL
)
1316 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView
,
1317 OnSetZoomLevelForView
)
1318 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding
, OnSetPageEncoding
)
1319 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault
,
1320 OnResetPageEncodingToDefault
)
1321 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent
, OnPostMessageEvent
)
1322 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter
, OnDragTargetDragEnter
)
1323 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver
, OnDragTargetDragOver
)
1324 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave
, OnDragTargetDragLeave
)
1325 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop
, OnDragTargetDrop
)
1326 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded
, OnDragSourceEnded
)
1327 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded
,
1328 OnDragSourceSystemDragEnded
)
1329 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings
, OnAllowBindings
)
1330 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus
, OnSetInitialFocus
)
1331 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK
, OnUpdateTargetURLAck
)
1332 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences
, OnUpdateWebPreferences
)
1333 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse
,
1334 OnEnumerateDirectoryResponse
)
1335 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse
, OnFileChooserResponse
)
1336 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut
,
1337 OnSuppressDialogsUntilSwapOut
)
1338 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage
, OnClosePage
)
1339 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged
, OnThemeChanged
)
1340 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted
, OnMoveOrResizeStarted
)
1341 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement
, OnClearFocusedElement
)
1342 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque
, OnSetBackgroundOpaque
)
1343 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode
,
1344 OnEnablePreferredSizeChangedMode
)
1345 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize
, OnEnableAutoResize
)
1346 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize
, OnDisableAutoResize
)
1347 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows
,
1348 OnDisableScrollbarsForSmallWindows
)
1349 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs
, OnSetRendererPrefs
)
1350 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt
, OnMediaPlayerActionAt
)
1351 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt
, OnPluginActionAt
)
1352 IPC_MESSAGE_HANDLER(ViewMsg_SetActive
, OnSetActive
)
1353 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage
,
1354 OnGetAllSavableResourceLinksForCurrentPage
)
1355 IPC_MESSAGE_HANDLER(
1356 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks
,
1357 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks
)
1358 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu
, OnShowContextMenu
)
1359 // TODO(viettrungluu): Move to a separate message filter.
1360 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune
,
1361 OnSetHistoryLengthAndPrune
)
1362 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode
, OnEnableViewSourceMode
)
1363 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap
,
1364 OnReleaseDisambiguationPopupBitmap
)
1365 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted
,
1366 OnWindowSnapshotCompleted
)
1367 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw
, OnForceRedraw
)
1368 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret
, OnSelectWordAroundCaret
)
1369 #if defined(OS_ANDROID)
1370 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult
,
1371 OnActivateNearestFindResult
)
1372 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects
, OnFindMatchRects
)
1373 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState
,
1374 OnUpdateTopControlsState
)
1375 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData
, OnExtractSmartClipData
)
1376 #elif defined(OS_MACOSX)
1377 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText
,
1379 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted
,
1380 OnPluginImeCompositionCompleted
)
1381 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize
, OnSetInLiveResize
)
1382 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility
, OnSetWindowVisibility
)
1383 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged
, OnWindowFrameChanged
)
1385 // Adding a new message? Add platform independent ones first, then put the
1386 // platform specific ones at the end.
1388 // Have the super handle all other messages.
1389 IPC_MESSAGE_UNHANDLED(handled
= RenderWidget::OnMessageReceived(message
))
1390 IPC_END_MESSAGE_MAP()
1395 void RenderViewImpl::OnSelectWordAroundCaret() {
1399 handling_input_event_
= true;
1400 webview()->focusedFrame()->selectWordAroundCaret();
1401 handling_input_event_
= false;
1404 bool RenderViewImpl::IsBackForwardToStaleEntry(const PageState
& state
,
1405 int pending_history_list_offset
,
1408 // Make sure this isn't a back/forward to an entry we have already cropped
1409 // or replaced from our history, before the browser knew about it. If so,
1410 // a new navigation has committed in the mean time, and we can ignore this.
1411 bool is_back_forward
= !is_reload
&& state
.IsValid();
1413 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1414 // restoring from a previous session. We'll update our state in OnNavigate.
1415 if (!is_back_forward
|| history_list_length_
<= 0)
1418 DCHECK_EQ(static_cast<int>(history_page_ids_
.size()), history_list_length_
);
1420 // Check for whether the forward history has been cropped due to a recent
1421 // navigation the browser didn't know about.
1422 if (pending_history_list_offset
>= history_list_length_
)
1425 // Check for whether this entry has been replaced with a new one.
1426 int expected_page_id
=
1427 history_page_ids_
[pending_history_list_offset
];
1428 if (expected_page_id
> 0 && page_id
!= expected_page_id
) {
1429 if (page_id
< expected_page_id
)
1432 // Otherwise we've removed an earlier entry and should have shifted all
1433 // entries left. For now, it's ok to lazily update the list.
1434 // TODO(creis): Notify all live renderers when we remove entries from
1435 // the front of the list, so that we don't hit this case.
1436 history_page_ids_
[pending_history_list_offset
] = page_id
;
1442 void RenderViewImpl::OnCopyImageAt(int x
, int y
) {
1443 webview()->copyImageAt(WebPoint(x
, y
));
1446 void RenderViewImpl::OnSaveImageAt(int x
, int y
) {
1447 webview()->saveImageAt(WebPoint(x
, y
));
1450 void RenderViewImpl::OnUpdateTargetURLAck() {
1451 // Check if there is a targeturl waiting to be sent.
1452 if (target_url_status_
== TARGET_PENDING
)
1453 Send(new ViewHostMsg_UpdateTargetURL(routing_id_
, pending_target_url_
));
1455 target_url_status_
= TARGET_NONE
;
1458 void RenderViewImpl::OnExecuteEditCommand(const std::string
& name
,
1459 const std::string
& value
) {
1460 if (!webview() || !webview()->focusedFrame())
1463 webview()->focusedFrame()->executeCommand(
1464 WebString::fromUTF8(name
), WebString::fromUTF8(value
));
1467 void RenderViewImpl::OnMoveCaret(const gfx::Point
& point
) {
1471 Send(new InputHostMsg_MoveCaret_ACK(routing_id_
));
1473 webview()->focusedFrame()->moveCaretSelection(point
);
1476 void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1477 const gfx::Rect
& rect
) {
1478 if (has_scrolled_focused_editable_node_into_rect_
&&
1479 rect
== rect_for_scrolled_focused_editable_node_
) {
1483 blink::WebElement element
= GetFocusedElement();
1484 if (!element
.isNull() && IsEditableNode(element
)) {
1485 rect_for_scrolled_focused_editable_node_
= rect
;
1486 has_scrolled_focused_editable_node_into_rect_
= true;
1487 webview()->scrollFocusedNodeIntoRect(rect
);
1491 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1492 const EditCommands
& edit_commands
) {
1493 edit_commands_
= edit_commands
;
1496 void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length
,
1497 int32 minimum_page_id
) {
1498 DCHECK_GE(history_length
, 0);
1499 DCHECK(history_list_offset_
== history_list_length_
- 1);
1500 DCHECK_GE(minimum_page_id
, -1);
1502 // Generate the new list.
1503 std::vector
<int32
> new_history_page_ids(history_length
, -1);
1504 for (size_t i
= 0; i
< history_page_ids_
.size(); ++i
) {
1505 if (minimum_page_id
>= 0 && history_page_ids_
[i
] < minimum_page_id
)
1507 new_history_page_ids
.push_back(history_page_ids_
[i
]);
1509 new_history_page_ids
.swap(history_page_ids_
);
1512 history_list_length_
= history_page_ids_
.size();
1513 history_list_offset_
= history_list_length_
- 1;
1517 void RenderViewImpl::OnSetInitialFocus(bool reverse
) {
1520 webview()->setInitialFocus(reverse
);
1523 #if defined(OS_MACOSX)
1524 void RenderViewImpl::OnSetInLiveResize(bool in_live_resize
) {
1528 webview()->willStartLiveResize();
1530 webview()->willEndLiveResize();
1534 ///////////////////////////////////////////////////////////////////////////////
1536 // Sends the current history state to the browser so it will be saved before we
1537 // navigate to a new page.
1538 void RenderViewImpl::UpdateSessionHistory(WebFrame
* frame
) {
1539 // If we have a valid page ID at this point, then it corresponds to the page
1540 // we are navigating away from. Otherwise, this is the first navigation, so
1541 // there is no past session history to record.
1544 SendUpdateState(history_controller_
->GetCurrentEntry());
1547 void RenderViewImpl::SendUpdateState(HistoryEntry
* entry
) {
1551 // Don't send state updates for kSwappedOutURL.
1552 if (entry
->root().urlString() == WebString::fromUTF8(kSwappedOutURL
))
1555 Send(new ViewHostMsg_UpdateState(
1556 routing_id_
, page_id_
, HistoryEntryToPageState(entry
)));
1559 bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
) {
1560 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1561 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1562 // it is particularly important that we do not call willEnterModalLoop as
1563 // that would defer resource loads for the dialog itself.
1564 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1565 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
1567 message
->EnableMessagePumping(); // Runs a nested message loop.
1568 return Send(message
);
1571 void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback
& callback
) {
1572 int id
= next_snapshot_id_
++;
1573 pending_snapshots_
.insert(std::make_pair(id
, callback
));
1574 ui::LatencyInfo latency_info
;
1575 latency_info
.AddLatencyNumber(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT
,
1578 scoped_ptr
<cc::SwapPromiseMonitor
> latency_info_swap_promise_monitor
;
1579 if (RenderWidgetCompositor
* rwc
= compositor()) {
1580 latency_info_swap_promise_monitor
=
1581 rwc
->CreateLatencyInfoSwapPromiseMonitor(&latency_info
).Pass();
1583 ScheduleCompositeWithForcedRedraw();
1586 void RenderViewImpl::OnForceRedraw(int id
) {
1587 ui::LatencyInfo latency_info
;
1589 latency_info
.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT
,
1593 scoped_ptr
<cc::SwapPromiseMonitor
> latency_info_swap_promise_monitor
;
1594 if (RenderWidgetCompositor
* rwc
= compositor()) {
1595 latency_info_swap_promise_monitor
=
1596 rwc
->CreateLatencyInfoSwapPromiseMonitor(&latency_info
).Pass();
1598 ScheduleCompositeWithForcedRedraw();
1601 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id
,
1602 const gfx::Size
& size
, const std::vector
<unsigned char>& png
) {
1604 // Any pending snapshots with a lower ID than the one received are considered
1605 // to be implicitly complete, and returned the same snapshot data.
1606 PendingSnapshotMap::iterator it
= pending_snapshots_
.begin();
1607 while(it
!= pending_snapshots_
.end()) {
1608 if (it
->first
<= snapshot_id
) {
1609 it
->second
.Run(size
, png
);
1610 pending_snapshots_
.erase(it
++);
1617 // blink::WebViewClient ------------------------------------------------------
1619 WebView
* RenderViewImpl::createView(WebLocalFrame
* creator
,
1620 const WebURLRequest
& request
,
1621 const WebWindowFeatures
& features
,
1622 const WebString
& frame_name
,
1623 WebNavigationPolicy policy
,
1624 bool suppress_opener
) {
1625 ViewHostMsg_CreateWindow_Params params
;
1626 params
.opener_id
= routing_id_
;
1627 params
.user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
1628 if (GetContentClient()->renderer()->AllowPopup())
1629 params
.user_gesture
= true;
1630 params
.window_container_type
= WindowFeaturesToContainerType(features
);
1631 params
.session_storage_namespace_id
= session_storage_namespace_id_
;
1632 if (frame_name
!= "_blank")
1633 params
.frame_name
= frame_name
;
1634 params
.opener_render_frame_id
=
1635 RenderFrameImpl::FromWebFrame(creator
)->GetRoutingID();
1636 params
.opener_url
= creator
->document().url();
1637 params
.opener_top_level_frame_url
= creator
->top()->document().url();
1638 GURL
security_url(creator
->document().securityOrigin().toString());
1639 if (!security_url
.is_valid())
1640 security_url
= GURL();
1641 params
.opener_security_origin
= security_url
;
1642 params
.opener_suppressed
= suppress_opener
;
1643 params
.disposition
= NavigationPolicyToDisposition(policy
);
1644 if (!request
.isNull()) {
1645 params
.target_url
= request
.url();
1646 params
.referrer
= GetReferrerFromRequest(creator
, request
);
1648 params
.features
= features
;
1650 for (size_t i
= 0; i
< features
.additionalFeatures
.size(); ++i
)
1651 params
.additional_features
.push_back(features
.additionalFeatures
[i
]);
1653 int32 routing_id
= MSG_ROUTING_NONE
;
1654 int32 main_frame_routing_id
= MSG_ROUTING_NONE
;
1655 int32 surface_id
= 0;
1656 int64 cloned_session_storage_namespace_id
= 0;
1658 RenderThread::Get()->Send(
1659 new ViewHostMsg_CreateWindow(params
,
1661 &main_frame_routing_id
,
1663 &cloned_session_storage_namespace_id
));
1664 if (routing_id
== MSG_ROUTING_NONE
)
1667 WebUserGestureIndicator::consumeUserGesture();
1669 // While this view may be a background extension page, it can spawn a visible
1670 // render view. So we just assume that the new one is not another background
1671 // page instead of passing on our own value.
1672 // TODO(vangelis): Can we tell if the new view will be a background page?
1673 bool never_visible
= false;
1675 // The initial hidden state for the RenderViewImpl here has to match what the
1676 // browser will eventually decide for the given disposition. Since we have to
1677 // return from this call synchronously, we just have to make our best guess
1678 // and rely on the browser sending a WasHidden / WasShown message if it
1680 RenderViewImpl
* view
= RenderViewImpl::Create(
1682 true, // window_was_created_with_opener
1683 renderer_preferences_
,
1684 webkit_preferences_
,
1686 main_frame_routing_id
,
1688 cloned_session_storage_namespace_id
,
1689 base::string16(), // WebCore will take care of setting the correct name.
1690 true, // is_renderer_created
1691 false, // swapped_out
1692 MSG_ROUTING_NONE
, // proxy_routing_id
1693 params
.disposition
== NEW_BACKGROUND_TAB
, // hidden
1697 view
->opened_by_user_gesture_
= params
.user_gesture
;
1699 // Record whether the creator frame is trying to suppress the opener field.
1700 view
->opener_suppressed_
= params
.opener_suppressed
;
1702 return view
->webview();
1705 WebWidget
* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type
) {
1706 RenderWidget
* widget
=
1707 RenderWidget::Create(routing_id_
, popup_type
, screen_info_
);
1710 if (screen_metrics_emulator_
) {
1711 widget
->SetPopupOriginAdjustmentsForEmulation(
1712 screen_metrics_emulator_
.get());
1714 return widget
->webwidget();
1717 WebStorageNamespace
* RenderViewImpl::createSessionStorageNamespace() {
1718 CHECK(session_storage_namespace_id_
!= kInvalidSessionStorageNamespaceId
);
1719 return new WebStorageNamespaceImpl(session_storage_namespace_id_
);
1722 void RenderViewImpl::printPage(WebLocalFrame
* frame
) {
1723 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
,
1724 PrintPage(frame
, handling_input_event_
));
1727 void RenderViewImpl::saveImageFromDataURL(const blink::WebString
& data_url
) {
1728 // Note: We should basically send GURL but we use size-limited string instead
1729 // in order to send a larger data url to save a image for <canvas> or <img>.
1730 if (data_url
.length() < kMaxLengthOfDataURLString
)
1731 Send(new ViewHostMsg_SaveImageFromDataURL(routing_id_
, data_url
.utf8()));
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 ipc_params
.need_local_path
= params
.needLocalPath
;
1816 #if defined(OS_ANDROID)
1817 ipc_params
.capture
= params
.useMediaCapture
;
1820 return ScheduleFileChooser(ipc_params
, chooser_completion
);
1823 void RenderViewImpl::SetValidationMessageDirection(
1824 base::string16
* wrapped_main_text
,
1825 blink::WebTextDirection main_text_hint
,
1826 base::string16
* wrapped_sub_text
,
1827 blink::WebTextDirection sub_text_hint
) {
1828 if (main_text_hint
== blink::WebTextDirectionLeftToRight
) {
1829 *wrapped_main_text
=
1830 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text
);
1831 } else if (main_text_hint
== blink::WebTextDirectionRightToLeft
&&
1832 !base::i18n::IsRTL()) {
1833 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text
);
1836 if (!wrapped_sub_text
->empty()) {
1837 if (sub_text_hint
== blink::WebTextDirectionLeftToRight
) {
1839 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text
);
1840 } else if (sub_text_hint
== blink::WebTextDirectionRightToLeft
) {
1841 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text
);
1846 void RenderViewImpl::showValidationMessage(
1847 const blink::WebRect
& anchor_in_root_view
,
1848 const blink::WebString
& main_text
,
1849 blink::WebTextDirection main_text_hint
,
1850 const blink::WebString
& sub_text
,
1851 blink::WebTextDirection sub_text_hint
) {
1852 base::string16 wrapped_main_text
= main_text
;
1853 base::string16 wrapped_sub_text
= sub_text
;
1855 SetValidationMessageDirection(
1856 &wrapped_main_text
, main_text_hint
, &wrapped_sub_text
, sub_text_hint
);
1858 Send(new ViewHostMsg_ShowValidationMessage(
1859 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view
),
1860 wrapped_main_text
, wrapped_sub_text
));
1863 void RenderViewImpl::hideValidationMessage() {
1864 Send(new ViewHostMsg_HideValidationMessage(routing_id()));
1867 void RenderViewImpl::moveValidationMessage(
1868 const blink::WebRect
& anchor_in_root_view
) {
1869 Send(new ViewHostMsg_MoveValidationMessage(
1870 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view
)));
1873 void RenderViewImpl::setStatusText(const WebString
& text
) {
1876 void RenderViewImpl::UpdateTargetURL(const GURL
& url
,
1877 const GURL
& fallback_url
) {
1878 GURL latest_url
= url
.is_empty() ? fallback_url
: url
;
1879 if (latest_url
== target_url_
)
1882 // Tell the browser to display a destination link.
1883 if (target_url_status_
== TARGET_INFLIGHT
||
1884 target_url_status_
== TARGET_PENDING
) {
1885 // If we have a request in-flight, save the URL to be sent when we
1886 // receive an ACK to the in-flight request. We can happily overwrite
1887 // any existing pending sends.
1888 pending_target_url_
= latest_url
;
1889 target_url_status_
= TARGET_PENDING
;
1891 // URLs larger than |MaxURLChars()| cannot be sent through IPC -
1892 // see |ParamTraits<GURL>|.
1893 if (latest_url
.possibly_invalid_spec().size() > GetMaxURLChars())
1894 latest_url
= GURL();
1895 Send(new ViewHostMsg_UpdateTargetURL(routing_id_
, latest_url
));
1896 target_url_
= latest_url
;
1897 target_url_status_
= TARGET_INFLIGHT
;
1901 gfx::RectF
RenderViewImpl::ClientRectToPhysicalWindowRect(
1902 const gfx::RectF
& rect
) const {
1903 gfx::RectF window_rect
= rect
;
1904 window_rect
.Scale(device_scale_factor_
* webview()->pageScaleFactor());
1908 void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
1909 // No need to update state if no page has committed yet.
1914 if (send_content_state_immediately_
)
1916 else if (is_hidden())
1917 delay
= kDelaySecondsForContentStateSyncHidden
;
1919 delay
= kDelaySecondsForContentStateSync
;
1921 if (nav_state_sync_timer_
.IsRunning()) {
1922 // The timer is already running. If the delay of the timer maches the amount
1923 // we want to delay by, then return. Otherwise stop the timer so that it
1924 // gets started with the right delay.
1925 if (nav_state_sync_timer_
.GetCurrentDelay().InSeconds() == delay
)
1927 nav_state_sync_timer_
.Stop();
1930 nav_state_sync_timer_
.Start(FROM_HERE
, TimeDelta::FromSeconds(delay
), this,
1931 &RenderViewImpl::SyncNavigationState
);
1934 void RenderViewImpl::setMouseOverURL(const WebURL
& url
) {
1935 mouse_over_url_
= GURL(url
);
1936 UpdateTargetURL(mouse_over_url_
, focus_url_
);
1939 void RenderViewImpl::setKeyboardFocusURL(const WebURL
& url
) {
1940 focus_url_
= GURL(url
);
1941 UpdateTargetURL(focus_url_
, mouse_over_url_
);
1944 void RenderViewImpl::startDragging(WebLocalFrame
* frame
,
1945 const WebDragData
& data
,
1946 WebDragOperationsMask mask
,
1947 const WebImage
& image
,
1948 const WebPoint
& webImageOffset
) {
1949 DropData
drop_data(DropDataBuilder::Build(data
));
1950 drop_data
.referrer_policy
= frame
->document().referrerPolicy();
1951 gfx::Vector2d
imageOffset(webImageOffset
.x
, webImageOffset
.y
);
1952 Send(new DragHostMsg_StartDragging(routing_id_
,
1955 image
.getSkBitmap(),
1957 possible_drag_event_info_
));
1960 bool RenderViewImpl::acceptsLoadDrops() {
1961 return renderer_preferences_
.can_accept_load_drops
;
1964 void RenderViewImpl::focusNext() {
1965 Send(new ViewHostMsg_TakeFocus(routing_id_
, false));
1968 void RenderViewImpl::focusPrevious() {
1969 Send(new ViewHostMsg_TakeFocus(routing_id_
, true));
1972 void RenderViewImpl::focusedNodeChanged(const WebNode
& node
) {
1973 has_scrolled_focused_editable_node_into_rect_
= false;
1975 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_
, IsEditableNode(node
)));
1977 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, FocusedNodeChanged(node
));
1979 // TODO(dmazzoni): this should be part of RenderFrameObserver.
1980 GetMainRenderFrame()->FocusedNodeChanged(node
);
1983 void RenderViewImpl::didUpdateLayout() {
1984 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidUpdateLayout());
1986 // We don't always want to set up a timer, only if we've been put in that
1987 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1989 if (!send_preferred_size_changes_
|| !webview())
1992 if (check_preferred_size_timer_
.IsRunning())
1994 check_preferred_size_timer_
.Start(FROM_HERE
,
1995 TimeDelta::FromMilliseconds(0), this,
1996 &RenderViewImpl::CheckPreferredSize
);
1999 void RenderViewImpl::navigateBackForwardSoon(int offset
) {
2000 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_
, offset
));
2003 int RenderViewImpl::historyBackListCount() {
2004 return history_list_offset_
< 0 ? 0 : history_list_offset_
;
2007 int RenderViewImpl::historyForwardListCount() {
2008 return history_list_length_
- historyBackListCount() - 1;
2011 // blink::WebWidgetClient ----------------------------------------------------
2013 void RenderViewImpl::didFocus() {
2014 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2015 // we won't have to test for user gesture anymore and we can
2016 // move that code back to render_widget.cc
2017 if (WebUserGestureIndicator::isProcessingUserGesture() &&
2018 !RenderThreadImpl::current()->layout_test_mode()) {
2019 Send(new ViewHostMsg_Focus(routing_id_
));
2023 void RenderViewImpl::didBlur() {
2024 // TODO(jcivelli): see TODO above in didFocus().
2025 if (WebUserGestureIndicator::isProcessingUserGesture() &&
2026 !RenderThreadImpl::current()->layout_test_mode()) {
2027 Send(new ViewHostMsg_Blur(routing_id_
));
2031 // We are supposed to get a single call to Show for a newly created RenderView
2032 // that was created via RenderViewImpl::CreateWebView. So, we wait until this
2033 // point to dispatch the ShowView message.
2035 // This method provides us with the information about how to display the newly
2036 // created RenderView (i.e., as a blocked popup or as a new tab).
2038 void RenderViewImpl::show(WebNavigationPolicy policy
) {
2040 // When supports_multiple_windows is disabled, popups are reusing
2041 // the same view. In some scenarios, this makes WebKit to call show() twice.
2042 if (webkit_preferences_
.supports_multiple_windows
)
2043 NOTREACHED() << "received extraneous Show call";
2048 DCHECK(opener_id_
!= MSG_ROUTING_NONE
);
2050 // NOTE: initial_pos_ may still have its default values at this point, but
2051 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2052 // browser process will impose a default position otherwise.
2053 Send(new ViewHostMsg_ShowView(opener_id_
, routing_id_
,
2054 NavigationPolicyToDisposition(policy
), initial_pos_
,
2055 opened_by_user_gesture_
));
2056 SetPendingWindowRect(initial_pos_
);
2059 void RenderViewImpl::runModal() {
2060 DCHECK(did_show_
) << "should already have shown the view";
2062 // Don't allow further dialogs if we are waiting to swap out, since the
2063 // PageGroupLoadDeferrer in our stack prevents it.
2064 if (suppress_dialogs_until_swap_out_
)
2067 // We must keep WebKit's shared timer running in this case in order to allow
2068 // showModalDialog to function properly.
2070 // TODO(darin): WebKit should really be smarter about suppressing events and
2071 // timers so that we do not need to manage the shared timer in such a heavy
2074 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2075 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
2077 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2078 routing_id_
, opener_id_
));
2081 bool RenderViewImpl::enterFullScreen() {
2082 Send(new ViewHostMsg_ToggleFullscreen(routing_id_
, true));
2086 void RenderViewImpl::exitFullScreen() {
2087 Send(new ViewHostMsg_ToggleFullscreen(routing_id_
, false));
2090 bool RenderViewImpl::requestPointerLock() {
2091 return mouse_lock_dispatcher_
->LockMouse(webwidget_mouse_lock_target_
.get());
2094 void RenderViewImpl::requestPointerUnlock() {
2095 mouse_lock_dispatcher_
->UnlockMouse(webwidget_mouse_lock_target_
.get());
2098 bool RenderViewImpl::isPointerLocked() {
2099 return mouse_lock_dispatcher_
->IsMouseLockedTo(
2100 webwidget_mouse_lock_target_
.get());
2103 void RenderViewImpl::didHandleGestureEvent(
2104 const WebGestureEvent
& event
,
2105 bool event_cancelled
) {
2106 RenderWidget::didHandleGestureEvent(event
, event_cancelled
);
2108 if (!event_cancelled
) {
2110 RenderViewObserver
, observers_
, DidHandleGestureEvent(event
));
2113 // TODO(ananta): Piggyback off existing IPCs to communicate this information,
2116 if (event
.type
!= blink::WebGestureEvent::GestureTap
)
2119 // TODO(estade): hit test the event against focused node to make sure
2120 // the tap actually hit the focused node.
2121 blink::WebTextInputType text_input_type
=
2122 GetWebView()->textInputInfo().type
;
2124 Send(new ViewHostMsg_FocusedNodeTouched(
2125 routing_id(), text_input_type
!= blink::WebTextInputTypeNone
));
2129 void RenderViewImpl::initializeLayerTreeView() {
2130 RenderWidget::initializeLayerTreeView();
2131 RenderWidgetCompositor
* rwc
= compositor();
2134 if (webview() && webview()->devToolsAgent())
2135 webview()->devToolsAgent()->setLayerTreeId(rwc
->GetLayerTreeId());
2137 bool use_threaded_event_handling
= true;
2138 #if defined(OS_MACOSX) && !defined(OS_IOS)
2139 // Development flag because many events are still unhandled on Mac.
2140 // http://crbug.com/138003
2141 use_threaded_event_handling
= CommandLine::ForCurrentProcess()->HasSwitch(
2142 switches::kEnableThreadedEventHandlingMac
);
2144 if (use_threaded_event_handling
) {
2145 RenderThreadImpl
* render_thread
= RenderThreadImpl::current();
2146 // render_thread may be NULL in tests.
2147 InputHandlerManager
* input_handler_manager
=
2148 render_thread
? render_thread
->input_handler_manager() : NULL
;
2149 if (input_handler_manager
) {
2150 input_handler_manager
->AddInputHandler(
2151 routing_id_
, rwc
->GetInputHandler(), AsWeakPtr());
2156 // blink::WebFrameClient -----------------------------------------------------
2158 void RenderViewImpl::Repaint(const gfx::Size
& size
) {
2162 void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string
& name
,
2163 const std::string
& value
) {
2164 EditCommands edit_commands
;
2165 edit_commands
.push_back(EditCommand(name
, value
));
2166 OnSetEditCommandsForNextKeyEvent(edit_commands
);
2169 void RenderViewImpl::ClearEditCommands() {
2170 edit_commands_
.clear();
2173 SSLStatus
RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame
* frame
) const {
2174 std::string security_info
;
2175 if (frame
&& frame
->dataSource())
2176 security_info
= frame
->dataSource()->response().securityInfo();
2178 SSLStatus ssl_status
;
2179 DeserializeSecurityInfo(security_info
,
2180 &ssl_status
.cert_id
,
2181 &ssl_status
.cert_status
,
2182 &ssl_status
.security_bits
,
2183 &ssl_status
.connection_status
,
2184 &ssl_status
.signed_certificate_timestamp_ids
);
2188 const std::string
& RenderViewImpl::GetAcceptLanguages() const {
2189 return renderer_preferences_
.accept_languages
;
2192 void RenderViewImpl::didCreateDataSource(WebLocalFrame
* frame
,
2193 WebDataSource
* ds
) {
2194 bool content_initiated
= !pending_navigation_params_
.get();
2196 // Make sure any previous redirect URLs end up in our new data source.
2197 if (pending_navigation_params_
.get()) {
2198 for (std::vector
<GURL
>::const_iterator i
=
2199 pending_navigation_params_
->redirects
.begin();
2200 i
!= pending_navigation_params_
->redirects
.end(); ++i
) {
2201 ds
->appendRedirect(*i
);
2205 DocumentState
* document_state
= DocumentState::FromDataSource(ds
);
2206 if (!document_state
) {
2207 document_state
= new DocumentState
;
2208 ds
->setExtraData(document_state
);
2209 if (!content_initiated
)
2210 PopulateDocumentStateFromPending(document_state
);
2213 // Carry over the user agent override flag, if it exists.
2214 if (content_initiated
&& webview() && webview()->mainFrame() &&
2215 webview()->mainFrame()->isWebLocalFrame() &&
2216 webview()->mainFrame()->dataSource()) {
2217 DocumentState
* old_document_state
=
2218 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2219 if (old_document_state
) {
2220 InternalDocumentStateData
* internal_data
=
2221 InternalDocumentStateData::FromDocumentState(document_state
);
2222 InternalDocumentStateData
* old_internal_data
=
2223 InternalDocumentStateData::FromDocumentState(old_document_state
);
2224 internal_data
->set_is_overriding_user_agent(
2225 old_internal_data
->is_overriding_user_agent());
2229 // The rest of RenderView assumes that a WebDataSource will always have a
2230 // non-null NavigationState.
2231 if (content_initiated
) {
2232 document_state
->set_navigation_state(
2233 NavigationState::CreateContentInitiated());
2235 document_state
->set_navigation_state(CreateNavigationStateFromPending());
2236 pending_navigation_params_
.reset();
2239 // DocumentState::referred_by_prefetcher_ is true if we are
2240 // navigating from a page that used prefetching using a link on that
2241 // page. We are early enough in the request process here that we
2242 // can still see the DocumentState of the previous page and set
2243 // this value appropriately.
2244 // TODO(gavinp): catch the important case of navigation in a new
2245 // renderer process.
2247 if (WebFrame
* old_frame
= webview()->mainFrame()) {
2248 const WebURLRequest
& original_request
= ds
->originalRequest();
2249 const GURL
referrer(
2250 original_request
.httpHeaderField(WebString::fromUTF8("Referer")));
2251 if (!referrer
.is_empty() && old_frame
->isWebLocalFrame() &&
2252 DocumentState::FromDataSource(old_frame
->dataSource())
2253 ->was_prefetcher()) {
2254 for (; old_frame
; old_frame
= old_frame
->traverseNext(false)) {
2255 WebDataSource
* old_frame_ds
= old_frame
->dataSource();
2256 if (old_frame_ds
&& referrer
== GURL(old_frame_ds
->request().url())) {
2257 document_state
->set_was_referred_by_prefetcher(true);
2265 if (content_initiated
) {
2266 const WebURLRequest
& request
= ds
->request();
2267 switch (request
.cachePolicy()) {
2268 case WebURLRequest::UseProtocolCachePolicy
: // normal load.
2269 document_state
->set_load_type(DocumentState::LINK_LOAD_NORMAL
);
2271 case WebURLRequest::ReloadIgnoringCacheData
: // reload.
2272 case WebURLRequest::ReloadBypassingCache
: // end-to-end reload.
2273 document_state
->set_load_type(DocumentState::LINK_LOAD_RELOAD
);
2275 case WebURLRequest::ReturnCacheDataElseLoad
: // allow stale data.
2276 document_state
->set_load_type(
2277 DocumentState::LINK_LOAD_CACHE_STALE_OK
);
2279 case WebURLRequest::ReturnCacheDataDontLoad
: // Don't re-post.
2280 document_state
->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY
);
2288 RenderViewObserver
, observers_
, DidCreateDataSource(frame
, ds
));
2291 void RenderViewImpl::PopulateDocumentStateFromPending(
2292 DocumentState
* document_state
) {
2293 const FrameMsg_Navigate_Params
& params
= *pending_navigation_params_
.get();
2294 document_state
->set_request_time(params
.request_time
);
2296 InternalDocumentStateData
* internal_data
=
2297 InternalDocumentStateData::FromDocumentState(document_state
);
2299 if (!params
.common_params
.url
.SchemeIs(url::kJavaScriptScheme
) &&
2300 params
.common_params
.navigation_type
== FrameMsg_Navigate_Type::RESTORE
) {
2301 // We're doing a load of a page that was restored from the last session. By
2302 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2303 // can result in stale data for pages that are set to expire. We explicitly
2304 // override that by setting the policy here so that as necessary we load
2305 // from the network.
2307 // TODO(davidben): Remove this in favor of passing a cache policy to the
2308 // loadHistoryItem call in OnNavigate. That requires not overloading
2309 // UseProtocolCachePolicy to mean both "normal load" and "determine cache
2310 // policy based on load type, etc".
2311 internal_data
->set_cache_policy_override(
2312 WebURLRequest::UseProtocolCachePolicy
);
2315 if (IsReload(params
.common_params
.navigation_type
))
2316 document_state
->set_load_type(DocumentState::RELOAD
);
2317 else if (params
.commit_params
.page_state
.IsValid())
2318 document_state
->set_load_type(DocumentState::HISTORY_LOAD
);
2320 document_state
->set_load_type(DocumentState::NORMAL_LOAD
);
2322 internal_data
->set_is_overriding_user_agent(
2323 params
.commit_params
.is_overriding_user_agent
);
2324 internal_data
->set_must_reset_scroll_and_scale_state(
2325 params
.common_params
.navigation_type
==
2326 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL
);
2327 document_state
->set_can_load_local_resources(params
.can_load_local_resources
);
2330 NavigationState
* RenderViewImpl::CreateNavigationStateFromPending() {
2331 const FrameMsg_Navigate_Params
& params
= *pending_navigation_params_
.get();
2332 NavigationState
* navigation_state
= NULL
;
2334 // A navigation resulting from loading a javascript URL should not be treated
2335 // as a browser initiated event. Instead, we want it to look as if the page
2336 // initiated any load resulting from JS execution.
2337 if (!params
.common_params
.url
.SchemeIs(url::kJavaScriptScheme
)) {
2338 navigation_state
= NavigationState::CreateBrowserInitiated(
2340 params
.pending_history_list_offset
,
2341 params
.should_clear_history_list
,
2342 params
.common_params
.transition
);
2343 navigation_state
->set_should_replace_current_entry(
2344 params
.should_replace_current_entry
);
2345 navigation_state
->set_transferred_request_child_id(
2346 params
.transferred_request_child_id
);
2347 navigation_state
->set_transferred_request_request_id(
2348 params
.transferred_request_request_id
);
2349 navigation_state
->set_allow_download(params
.common_params
.allow_download
);
2350 navigation_state
->set_extra_headers(params
.request_params
.extra_headers
);
2352 navigation_state
= NavigationState::CreateContentInitiated();
2354 return navigation_state
;
2357 void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine
& command_line
) {
2358 bool enable_viewport
=
2359 command_line
.HasSwitch(switches::kEnableViewport
) ||
2360 command_line
.HasSwitch(switches::kEnableViewportMeta
);
2362 // If viewport tag is enabled, then the WebKit side will take care
2363 // of setting the fixed layout size and page scale limits.
2364 if (enable_viewport
)
2367 // When navigating to a new page, reset the page scale factor to be 1.0.
2368 webview()->setInitialPageScaleOverride(1.f
);
2370 float maxPageScaleFactor
=
2371 command_line
.HasSwitch(switches::kEnablePinch
) ? 4.f
: 1.f
;
2372 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor
);
2375 void RenderViewImpl::didClearWindowObject(WebLocalFrame
* frame
) {
2377 RenderViewObserver
, observers_
, DidClearWindowObject(frame
));
2379 if (enabled_bindings_
& BINDINGS_POLICY_WEB_UI
)
2380 WebUIExtension::Install(frame
);
2382 if (enabled_bindings_
& BINDINGS_POLICY_STATS_COLLECTION
)
2383 StatsCollectionController::Install(frame
);
2385 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
2387 if (command_line
.HasSwitch(switches::kEnableSkiaBenchmarking
))
2388 SkiaBenchmarking::Install(frame
);
2390 if (command_line
.HasSwitch(cc::switches::kEnableGpuBenchmarking
))
2391 GpuBenchmarking::Install(frame
);
2393 if (command_line
.HasSwitch(switches::kEnableMemoryBenchmarking
))
2394 MemoryBenchmarkingExtension::Install(frame
);
2397 void RenderViewImpl::didChangeIcon(WebLocalFrame
* frame
,
2398 WebIconURL::Type icon_type
) {
2399 if (frame
->parent())
2402 if (!TouchEnabled() && icon_type
!= WebIconURL::TypeFavicon
)
2405 WebVector
<WebIconURL
> icon_urls
= frame
->iconURLs(icon_type
);
2406 std::vector
<FaviconURL
> urls
;
2407 for (size_t i
= 0; i
< icon_urls
.size(); i
++) {
2408 std::vector
<gfx::Size
> sizes
;
2409 ConvertToFaviconSizes(icon_urls
[i
].sizes(), &sizes
);
2410 urls
.push_back(FaviconURL(
2411 icon_urls
[i
].iconURL(), ToFaviconType(icon_urls
[i
].iconType()), sizes
));
2413 SendUpdateFaviconURL(urls
);
2416 void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame
* frame
) {
2417 StartNavStateSyncTimerIfNecessary();
2420 void RenderViewImpl::CheckPreferredSize() {
2421 // We don't always want to send the change messages over IPC, only if we've
2422 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2424 if (!send_preferred_size_changes_
|| !webview())
2427 gfx::Size size
= webview()->contentsPreferredMinimumSize();
2429 // In the presence of zoom, these sizes are still reported as if unzoomed,
2430 // so we need to adjust.
2431 double zoom_factor
= ZoomLevelToZoomFactor(webview()->zoomLevel());
2432 size
.set_width(static_cast<int>(size
.width() * zoom_factor
));
2433 size
.set_height(static_cast<int>(size
.height() * zoom_factor
));
2435 if (size
== preferred_size_
)
2438 preferred_size_
= size
;
2439 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_
,
2443 BrowserPluginManager
* RenderViewImpl::GetBrowserPluginManager() {
2444 if (!browser_plugin_manager_
.get())
2445 browser_plugin_manager_
= BrowserPluginManager::Create(this);
2446 return browser_plugin_manager_
.get();
2449 void RenderViewImpl::didChangeScrollOffset(WebLocalFrame
* frame
) {
2450 StartNavStateSyncTimerIfNecessary();
2453 RenderViewObserver
, observers_
, DidChangeScrollOffset(frame
));
2456 void RenderViewImpl::SendFindReply(int request_id
,
2459 const WebRect
& selection_rect
,
2460 bool final_status_update
) {
2461 Send(new ViewHostMsg_Find_Reply(routing_id_
,
2466 final_status_update
));
2469 blink::WebString
RenderViewImpl::acceptLanguages() {
2470 return WebString::fromUTF8(renderer_preferences_
.accept_languages
);
2473 // blink::WebPageSerializerClient implementation ------------------------------
2475 void RenderViewImpl::didSerializeDataForFrame(
2476 const WebURL
& frame_url
,
2477 const WebCString
& data
,
2478 WebPageSerializerClient::PageSerializationStatus status
) {
2479 Send(new ViewHostMsg_SendSerializedHtmlData(
2483 static_cast<int32
>(status
)));
2486 // RenderView implementation ---------------------------------------------------
2488 bool RenderViewImpl::Send(IPC::Message
* message
) {
2489 return RenderWidget::Send(message
);
2492 RenderFrameImpl
* RenderViewImpl::GetMainRenderFrame() {
2493 return main_render_frame_
.get();
2496 int RenderViewImpl::GetRoutingID() const {
2500 gfx::Size
RenderViewImpl::GetSize() const {
2504 WebPreferences
& RenderViewImpl::GetWebkitPreferences() {
2505 return webkit_preferences_
;
2508 void RenderViewImpl::SetWebkitPreferences(const WebPreferences
& preferences
) {
2509 OnUpdateWebPreferences(preferences
);
2512 blink::WebView
* RenderViewImpl::GetWebView() {
2516 blink::WebElement
RenderViewImpl::GetFocusedElement() const {
2518 return WebElement();
2519 WebFrame
* focused_frame
= webview()->focusedFrame();
2520 if (focused_frame
) {
2521 WebDocument doc
= focused_frame
->document();
2523 return doc
.focusedElement();
2526 return WebElement();
2529 bool RenderViewImpl::IsEditableNode(const WebNode
& node
) const {
2533 if (node
.isContentEditable())
2536 if (node
.isElementNode()) {
2537 const WebElement
& element
= node
.toConst
<WebElement
>();
2538 if (element
.isTextFormControlElement()) {
2539 if (!(element
.hasAttribute("readonly") ||
2540 element
.hasAttribute("disabled")))
2544 // Also return true if it has an ARIA role of 'textbox'.
2545 for (unsigned i
= 0; i
< element
.attributeCount(); ++i
) {
2546 if (LowerCaseEqualsASCII(element
.attributeLocalName(i
), "role")) {
2547 if (LowerCaseEqualsASCII(element
.attributeValue(i
), "textbox"))
2557 bool RenderViewImpl::NodeContainsPoint(const WebNode
& node
,
2558 const gfx::Point
& point
) const {
2559 blink::WebHitTestResult hit_test
=
2560 webview()->hitTestResultAt(WebPoint(point
.x(), point
.y()));
2561 return node
.containsIncludingShadowDOM(hit_test
.node());
2564 bool RenderViewImpl::ShouldDisplayScrollbars(int width
, int height
) const {
2565 return (!send_preferred_size_changes_
||
2566 (disable_scrollbars_size_limit_
.width() <= width
||
2567 disable_scrollbars_size_limit_
.height() <= height
));
2570 int RenderViewImpl::GetEnabledBindings() const {
2571 return enabled_bindings_
;
2574 bool RenderViewImpl::GetContentStateImmediately() const {
2575 return send_content_state_immediately_
;
2578 blink::WebPageVisibilityState
RenderViewImpl::GetVisibilityState() const {
2579 return visibilityState();
2582 void RenderViewImpl::DidStartLoading() {
2583 main_render_frame_
->didStartLoading(true);
2586 void RenderViewImpl::DidStopLoading() {
2587 main_render_frame_
->didStopLoading();
2590 void RenderViewImpl::SyncNavigationState() {
2593 SendUpdateState(history_controller_
->GetCurrentEntry());
2596 blink::WebPlugin
* RenderViewImpl::GetWebPluginForFind() {
2600 WebFrame
* main_frame
= webview()->mainFrame();
2601 if (main_frame
->isWebLocalFrame() &&
2602 main_frame
->document().isPluginDocument())
2603 return webview()->mainFrame()->document().to
<WebPluginDocument
>().plugin();
2605 #if defined(ENABLE_PLUGINS)
2606 if (plugin_find_handler_
)
2607 return plugin_find_handler_
->container()->plugin();
2613 void RenderViewImpl::OnFind(int request_id
,
2614 const base::string16
& search_text
,
2615 const WebFindOptions
& options
) {
2616 WebFrame
* main_frame
= webview()->mainFrame();
2617 blink::WebPlugin
* plugin
= GetWebPluginForFind();
2618 // Check if the plugin still exists in the document.
2620 if (options
.findNext
) {
2621 // Just navigate back/forward.
2622 plugin
->selectFindResult(options
.forward
);
2624 if (!plugin
->startFind(
2625 search_text
, options
.matchCase
, request_id
)) {
2626 // Send "no results".
2627 SendFindReply(request_id
, 0, 0, gfx::Rect(), true);
2633 WebFrame
* frame_after_main
= main_frame
->traverseNext(true);
2634 WebFrame
* focused_frame
= webview()->focusedFrame();
2635 WebFrame
* search_frame
= focused_frame
; // start searching focused frame.
2637 bool multi_frame
= (frame_after_main
!= main_frame
);
2639 // If we have multiple frames, we don't want to wrap the search within the
2640 // frame, so we check here if we only have main_frame in the chain.
2641 bool wrap_within_frame
= !multi_frame
;
2643 WebRect selection_rect
;
2644 bool result
= false;
2646 // If something is selected when we start searching it means we cannot just
2647 // increment the current match ordinal; we need to re-generate it.
2648 WebRange current_selection
= focused_frame
->selectionRange();
2651 result
= search_frame
->find(
2652 request_id
, search_text
, options
, wrap_within_frame
, &selection_rect
);
2655 // don't leave text selected as you move to the next frame.
2656 search_frame
->executeCommand(WebString::fromUTF8("Unselect"),
2657 GetFocusedElement());
2659 // Find the next frame, but skip the invisible ones.
2661 // What is the next frame to search? (we might be going backwards). Note
2662 // that we specify wrap=true so that search_frame never becomes NULL.
2663 search_frame
= options
.forward
?
2664 search_frame
->traverseNext(true) :
2665 search_frame
->traversePrevious(true);
2666 } while (!search_frame
->hasVisibleContent() &&
2667 search_frame
!= focused_frame
);
2669 // Make sure selection doesn't affect the search operation in new frame.
2670 search_frame
->executeCommand(WebString::fromUTF8("Unselect"),
2671 GetFocusedElement());
2673 // If we have multiple frames and we have wrapped back around to the
2674 // focused frame, we need to search it once more allowing wrap within
2675 // the frame, otherwise it will report 'no match' if the focused frame has
2676 // reported matches, but no frames after the focused_frame contain a
2677 // match for the search word(s).
2678 if (multi_frame
&& search_frame
== focused_frame
) {
2679 result
= search_frame
->find(
2680 request_id
, search_text
, options
, true, // Force wrapping.
2685 webview()->setFocusedFrame(search_frame
);
2686 } while (!result
&& search_frame
!= focused_frame
);
2688 if (options
.findNext
&& current_selection
.isNull()) {
2689 // Force the main_frame to report the actual count.
2690 main_frame
->increaseMatchCount(0, request_id
);
2692 // If nothing is found, set result to "0 of 0", otherwise, set it to
2693 // "-1 of 1" to indicate that we found at least one item, but we don't know
2694 // yet what is active.
2695 int ordinal
= result
? -1 : 0; // -1 here means, we might know more later.
2696 int match_count
= result
? 1 : 0; // 1 here means possibly more coming.
2698 // If we find no matches then this will be our last status update.
2699 // Otherwise the scoping effort will send more results.
2700 bool final_status_update
= !result
;
2702 SendFindReply(request_id
, match_count
, ordinal
, selection_rect
,
2703 final_status_update
);
2705 // Scoping effort begins, starting with the mainframe.
2706 search_frame
= main_frame
;
2708 main_frame
->resetMatchCount();
2711 // Cancel all old scoping requests before starting a new one.
2712 search_frame
->cancelPendingScopingEffort();
2714 // We don't start another scoping effort unless at least one match has
2717 // Start new scoping request. If the scoping function determines that it
2718 // needs to scope, it will defer until later.
2719 search_frame
->scopeStringMatches(request_id
,
2722 true); // reset the tickmarks
2725 // Iterate to the next frame. The frame will not necessarily scope, for
2726 // example if it is not visible.
2727 search_frame
= search_frame
->traverseNext(true);
2728 } while (search_frame
!= main_frame
);
2732 void RenderViewImpl::OnStopFinding(StopFindAction action
) {
2733 WebView
* view
= webview();
2737 blink::WebPlugin
* plugin
= GetWebPluginForFind();
2743 bool clear_selection
= action
== STOP_FIND_ACTION_CLEAR_SELECTION
;
2744 if (clear_selection
) {
2745 view
->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
2746 GetFocusedElement());
2749 WebFrame
* frame
= view
->mainFrame();
2751 frame
->stopFinding(clear_selection
);
2752 frame
= frame
->traverseNext(false);
2755 if (action
== STOP_FIND_ACTION_ACTIVATE_SELECTION
) {
2756 WebFrame
* focused_frame
= view
->focusedFrame();
2757 if (focused_frame
) {
2758 WebDocument doc
= focused_frame
->document();
2759 if (!doc
.isNull()) {
2760 WebElement element
= doc
.focusedElement();
2761 if (!element
.isNull())
2762 element
.simulateClick();
2768 #if defined(OS_ANDROID)
2769 void RenderViewImpl::OnActivateNearestFindResult(int request_id
,
2774 WebFrame
* main_frame
= webview()->mainFrame();
2775 WebRect selection_rect
;
2776 int ordinal
= main_frame
->selectNearestFindMatch(WebFloatPoint(x
, y
),
2778 if (ordinal
== -1) {
2779 // Something went wrong, so send a no-op reply (force the main_frame to
2780 // report the current match count) in case the host is waiting for a
2781 // response due to rate-limiting).
2782 main_frame
->increaseMatchCount(0, request_id
);
2786 SendFindReply(request_id
,
2787 -1 /* number_of_matches */,
2790 true /* final_update */);
2793 void RenderViewImpl::OnFindMatchRects(int current_version
) {
2797 WebFrame
* main_frame
= webview()->mainFrame();
2798 std::vector
<gfx::RectF
> match_rects
;
2800 int rects_version
= main_frame
->findMatchMarkersVersion();
2801 if (current_version
!= rects_version
) {
2802 WebVector
<WebFloatRect
> web_match_rects
;
2803 main_frame
->findMatchRects(web_match_rects
);
2804 match_rects
.reserve(web_match_rects
.size());
2805 for (size_t i
= 0; i
< web_match_rects
.size(); ++i
)
2806 match_rects
.push_back(gfx::RectF(web_match_rects
[i
]));
2809 gfx::RectF active_rect
= main_frame
->activeFindMatchRect();
2810 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_
,
2817 void RenderViewImpl::OnZoom(PageZoom zoom
) {
2818 if (!webview()) // Not sure if this can happen, but no harm in being safe.
2821 webview()->hidePopups();
2823 double old_zoom_level
= webview()->zoomLevel();
2825 if (zoom
== PAGE_ZOOM_RESET
) {
2827 } else if (static_cast<int>(old_zoom_level
) == old_zoom_level
) {
2828 // Previous zoom level is a whole number, so just increment/decrement.
2829 zoom_level
= old_zoom_level
+ zoom
;
2831 // Either the user hit the zoom factor limit and thus the zoom level is now
2832 // not a whole number, or a plugin changed it to a custom value. We want
2833 // to go to the next whole number so that the user can always get back to
2834 // 100% with the keyboard/menu.
2835 if ((old_zoom_level
> 1 && zoom
> 0) ||
2836 (old_zoom_level
< 1 && zoom
< 0)) {
2837 zoom_level
= static_cast<int>(old_zoom_level
+ zoom
);
2839 // We're going towards 100%, so first go to the next whole number.
2840 zoom_level
= static_cast<int>(old_zoom_level
);
2843 webview()->setZoomLevel(zoom_level
);
2847 void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL
& url
,
2848 double zoom_level
) {
2849 #if !defined(OS_ANDROID)
2850 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
2851 // for legacy WebView text scaling emulation. Thus, the code that resets
2852 // the zoom level from this map will be effectively resetting text zoom level.
2853 host_zoom_levels_
[url
] = zoom_level
;
2857 void RenderViewImpl::OnSetZoomLevelForView(bool uses_temporary_zoom_level
,
2859 uses_temporary_zoom_level_
= uses_temporary_zoom_level
;
2861 webview()->hidePopups();
2862 webview()->setZoomLevel(level
);
2865 void RenderViewImpl::OnSetPageEncoding(const std::string
& encoding_name
) {
2866 webview()->setPageEncoding(WebString::fromUTF8(encoding_name
));
2869 void RenderViewImpl::OnResetPageEncodingToDefault() {
2870 WebString no_encoding
;
2871 webview()->setPageEncoding(no_encoding
);
2874 void RenderViewImpl::OnPostMessageEvent(
2875 const ViewMsg_PostMessage_Params
& params
) {
2876 // TODO(nasko): Support sending to subframes.
2877 WebFrame
* frame
= webview()->mainFrame();
2879 // Find the source frame if it exists.
2880 WebFrame
* source_frame
= NULL
;
2881 if (params
.source_routing_id
!= MSG_ROUTING_NONE
) {
2882 RenderViewImpl
* source_view
= FromRoutingID(params
.source_routing_id
);
2884 source_frame
= source_view
->webview()->mainFrame();
2887 // If the message contained MessagePorts, create the corresponding endpoints.
2888 DCHECK_EQ(params
.message_port_ids
.size(), params
.new_routing_ids
.size());
2889 blink::WebMessagePortChannelArray
channels(params
.message_port_ids
.size());
2891 i
< params
.message_port_ids
.size() && i
< params
.new_routing_ids
.size();
2894 new WebMessagePortChannelImpl(params
.new_routing_ids
[i
],
2895 params
.message_port_ids
[i
],
2896 base::MessageLoopProxy::current().get());
2899 WebSerializedScriptValue serialized_script_value
;
2900 if (params
.is_data_raw_string
) {
2901 v8::HandleScope
handle_scope(blink::mainThreadIsolate());
2902 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
2903 v8::Context::Scope
context_scope(context
);
2904 V8ValueConverterImpl converter
;
2905 converter
.SetDateAllowed(true);
2906 converter
.SetRegExpAllowed(true);
2907 scoped_ptr
<base::Value
> value(new base::StringValue(params
.data
));
2908 v8::Handle
<v8::Value
> result_value
= converter
.ToV8Value(value
.get(),
2910 serialized_script_value
= WebSerializedScriptValue::serialize(result_value
);
2912 serialized_script_value
= WebSerializedScriptValue::fromString(params
.data
);
2915 // Create an event with the message. The final parameter to initMessageEvent
2916 // is the last event ID, which is not used with postMessage.
2917 WebDOMEvent event
= frame
->document().createEvent("MessageEvent");
2918 WebDOMMessageEvent msg_event
= event
.to
<WebDOMMessageEvent
>();
2919 msg_event
.initMessageEvent("message",
2920 // |canBubble| and |cancellable| are always false
2922 serialized_script_value
,
2923 params
.source_origin
, source_frame
, "", channels
);
2925 // We must pass in the target_origin to do the security check on this side,
2926 // since it may have changed since the original postMessage call was made.
2927 WebSecurityOrigin target_origin
;
2928 if (!params
.target_origin
.empty()) {
2930 WebSecurityOrigin::createFromString(WebString(params
.target_origin
));
2932 frame
->dispatchMessageEventWithOriginCheck(target_origin
, msg_event
);
2935 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags
) {
2936 if ((enabled_bindings_flags
& BINDINGS_POLICY_WEB_UI
) &&
2937 !(enabled_bindings_
& BINDINGS_POLICY_WEB_UI
)) {
2938 // WebUIExtensionData deletes itself when we're destroyed.
2939 new WebUIExtensionData(this);
2940 // WebUIMojo deletes itself when we're destroyed.
2941 new WebUIMojo(this);
2944 enabled_bindings_
|= enabled_bindings_flags
;
2946 // Keep track of the total bindings accumulated in this process.
2947 RenderProcess::current()->AddBindings(enabled_bindings_flags
);
2950 void RenderViewImpl::OnDragTargetDragEnter(const DropData
& drop_data
,
2951 const gfx::Point
& client_point
,
2952 const gfx::Point
& screen_point
,
2953 WebDragOperationsMask ops
,
2954 int key_modifiers
) {
2955 WebDragOperation operation
= webview()->dragTargetDragEnter(
2956 DropDataToWebDragData(drop_data
),
2962 Send(new DragHostMsg_UpdateDragCursor(routing_id_
, operation
));
2965 void RenderViewImpl::OnDragTargetDragOver(const gfx::Point
& client_point
,
2966 const gfx::Point
& screen_point
,
2967 WebDragOperationsMask ops
,
2968 int key_modifiers
) {
2969 WebDragOperation operation
= webview()->dragTargetDragOver(
2975 Send(new DragHostMsg_UpdateDragCursor(routing_id_
, operation
));
2978 void RenderViewImpl::OnDragTargetDragLeave() {
2979 webview()->dragTargetDragLeave();
2982 void RenderViewImpl::OnDragTargetDrop(const gfx::Point
& client_point
,
2983 const gfx::Point
& screen_point
,
2984 int key_modifiers
) {
2985 webview()->dragTargetDrop(client_point
, screen_point
, key_modifiers
);
2987 Send(new DragHostMsg_TargetDrop_ACK(routing_id_
));
2990 void RenderViewImpl::OnDragSourceEnded(const gfx::Point
& client_point
,
2991 const gfx::Point
& screen_point
,
2992 WebDragOperation op
) {
2993 webview()->dragSourceEndedAt(client_point
, screen_point
, op
);
2996 void RenderViewImpl::OnDragSourceSystemDragEnded() {
2997 webview()->dragSourceSystemDragEnded();
3000 void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences
& prefs
) {
3001 webkit_preferences_
= prefs
;
3002 ApplyWebPreferences(webkit_preferences_
, webview());
3005 void RenderViewImpl::OnEnumerateDirectoryResponse(
3007 const std::vector
<base::FilePath
>& paths
) {
3008 if (!enumeration_completions_
[id
])
3011 WebVector
<WebString
> ws_file_names(paths
.size());
3012 for (size_t i
= 0; i
< paths
.size(); ++i
)
3013 ws_file_names
[i
] = paths
[i
].AsUTF16Unsafe();
3015 enumeration_completions_
[id
]->didChooseFile(ws_file_names
);
3016 enumeration_completions_
.erase(id
);
3019 void RenderViewImpl::OnFileChooserResponse(
3020 const std::vector
<content::FileChooserFileInfo
>& files
) {
3021 // This could happen if we navigated to a different page before the user
3022 // closed the chooser.
3023 if (file_chooser_completions_
.empty())
3026 // Convert Chrome's SelectedFileInfo list to WebKit's.
3027 WebVector
<WebFileChooserCompletion::SelectedFileInfo
> selected_files(
3029 for (size_t i
= 0; i
< files
.size(); ++i
) {
3030 WebFileChooserCompletion::SelectedFileInfo selected_file
;
3031 selected_file
.path
= files
[i
].file_path
.AsUTF16Unsafe();
3032 selected_file
.displayName
=
3033 base::FilePath(files
[i
].display_name
).AsUTF16Unsafe();
3034 if (files
[i
].file_system_url
.is_valid()) {
3035 selected_file
.fileSystemURL
= files
[i
].file_system_url
;
3036 selected_file
.length
= files
[i
].length
;
3037 selected_file
.modificationTime
= files
[i
].modification_time
.ToDoubleT();
3038 selected_file
.isDirectory
= files
[i
].is_directory
;
3040 selected_files
[i
] = selected_file
;
3043 if (file_chooser_completions_
.front()->completion
)
3044 file_chooser_completions_
.front()->completion
->didChooseFile(
3046 file_chooser_completions_
.pop_front();
3048 // If there are more pending file chooser requests, schedule one now.
3049 if (!file_chooser_completions_
.empty()) {
3050 Send(new ViewHostMsg_RunFileChooser(routing_id_
,
3051 file_chooser_completions_
.front()->params
));
3055 void RenderViewImpl::OnEnableAutoResize(const gfx::Size
& min_size
,
3056 const gfx::Size
& max_size
) {
3057 DCHECK(disable_scrollbars_size_limit_
.IsEmpty());
3060 auto_resize_mode_
= true;
3061 webview()->enableAutoResizeMode(min_size
, max_size
);
3064 void RenderViewImpl::OnDisableAutoResize(const gfx::Size
& new_size
) {
3065 DCHECK(disable_scrollbars_size_limit_
.IsEmpty());
3068 auto_resize_mode_
= false;
3069 webview()->disableAutoResizeMode();
3071 if (!new_size
.IsEmpty()) {
3073 physical_backing_size_
,
3074 top_controls_layout_height_
,
3075 visible_viewport_size_
,
3082 void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
3083 if (send_preferred_size_changes_
)
3085 send_preferred_size_changes_
= true;
3087 // Start off with an initial preferred size notification (in case
3088 // |didUpdateLayout| was already called).
3092 void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
3093 const gfx::Size
& disable_scrollbar_size_limit
) {
3094 disable_scrollbars_size_limit_
= disable_scrollbar_size_limit
;
3097 void RenderViewImpl::OnSetRendererPrefs(
3098 const RendererPreferences
& renderer_prefs
) {
3099 double old_zoom_level
= renderer_preferences_
.default_zoom_level
;
3100 std::string old_accept_languages
= renderer_preferences_
.accept_languages
;
3102 renderer_preferences_
= renderer_prefs
;
3103 UpdateFontRenderingFromRendererPrefs();
3105 #if defined(USE_DEFAULT_RENDER_THEME)
3106 if (renderer_prefs
.use_custom_colors
) {
3107 WebColorName name
= blink::WebColorWebkitFocusRingColor
;
3108 blink::setNamedColors(&name
, &renderer_prefs
.focus_ring_color
, 1);
3109 blink::setCaretBlinkInterval(renderer_prefs
.caret_blink_interval
);
3112 webview()->setSelectionColors(
3113 renderer_prefs
.active_selection_bg_color
,
3114 renderer_prefs
.active_selection_fg_color
,
3115 renderer_prefs
.inactive_selection_bg_color
,
3116 renderer_prefs
.inactive_selection_fg_color
);
3117 webview()->themeChanged();
3120 #endif // defined(USE_DEFAULT_RENDER_THEME)
3122 // If the zoom level for this page matches the old zoom default, and this
3123 // is not a plugin, update the zoom level to match the new default.
3124 if (webview() && webview()->mainFrame()->isWebLocalFrame() &&
3125 !webview()->mainFrame()->document().isPluginDocument() &&
3126 !ZoomValuesEqual(old_zoom_level
,
3127 renderer_preferences_
.default_zoom_level
) &&
3128 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level
)) {
3129 webview()->setZoomLevel(renderer_preferences_
.default_zoom_level
);
3134 old_accept_languages
!= renderer_preferences_
.accept_languages
) {
3135 webview()->acceptLanguagesChanged();
3139 void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point
& location
,
3140 const WebMediaPlayerAction
& action
) {
3142 webview()->performMediaPlayerAction(action
, location
);
3145 void RenderViewImpl::OnOrientationChange() {
3146 // TODO(mlamouri): consumers of that event should be using DisplayObserver.
3147 FOR_EACH_OBSERVER(RenderViewObserver
,
3149 OrientationChangeEvent());
3151 webview()->mainFrame()->toWebLocalFrame()->sendOrientationChangeEvent();
3154 void RenderViewImpl::OnPluginActionAt(const gfx::Point
& location
,
3155 const WebPluginAction
& action
) {
3157 webview()->performPluginAction(action
, location
);
3160 void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
3161 const GURL
& page_url
) {
3162 // Prepare list to storage all savable resource links.
3163 std::vector
<GURL
> resources_list
;
3164 std::vector
<GURL
> referrer_urls_list
;
3165 std::vector
<blink::WebReferrerPolicy
> referrer_policies_list
;
3166 std::vector
<GURL
> frames_list
;
3167 SavableResourcesResult
result(&resources_list
,
3168 &referrer_urls_list
,
3169 &referrer_policies_list
,
3172 // webkit/ doesn't know about Referrer.
3173 if (!GetAllSavableResourceLinksForCurrentPage(
3177 const_cast<const char**>(GetSavableSchemes()))) {
3178 // If something is wrong when collecting all savable resource links,
3179 // send empty list to embedder(browser) to tell it failed.
3180 referrer_urls_list
.clear();
3181 referrer_policies_list
.clear();
3182 resources_list
.clear();
3183 frames_list
.clear();
3186 std::vector
<Referrer
> referrers_list
;
3187 CHECK_EQ(referrer_urls_list
.size(), referrer_policies_list
.size());
3188 for (unsigned i
= 0; i
< referrer_urls_list
.size(); ++i
) {
3189 referrers_list
.push_back(
3190 Referrer(referrer_urls_list
[i
], referrer_policies_list
[i
]));
3193 // Send result of all savable resource links to embedder.
3194 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3200 void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3201 const std::vector
<GURL
>& links
,
3202 const std::vector
<base::FilePath
>& local_paths
,
3203 const base::FilePath
& local_directory_name
) {
3205 // Convert std::vector of GURLs to WebVector<WebURL>
3206 WebVector
<WebURL
> weburl_links(links
);
3208 // Convert std::vector of base::FilePath to WebVector<WebString>
3209 WebVector
<WebString
> webstring_paths(local_paths
.size());
3210 for (size_t i
= 0; i
< local_paths
.size(); i
++)
3211 webstring_paths
[i
] = local_paths
[i
].AsUTF16Unsafe();
3213 WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(),
3218 local_directory_name
.AsUTF16Unsafe());
3221 void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
3222 // Don't show any more dialogs until we finish OnSwapOut.
3223 suppress_dialogs_until_swap_out_
= true;
3226 void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame
* frame
) {
3227 // We use loadRequest instead of loadHTMLString because the former commits
3228 // synchronously. Otherwise a new navigation can interrupt the navigation
3229 // to kSwappedOutURL. If that happens to be to the page we had been
3230 // showing, then WebKit will never send a commit and we'll be left spinning.
3231 // TODO(creis): Until we move this to RenderFrame, we may call this from a
3232 // swapped out RenderFrame while our own is_swapped_out_ is false.
3233 RenderFrameImpl
* rf
= RenderFrameImpl::FromWebFrame(frame
);
3234 CHECK(is_swapped_out_
|| rf
->is_swapped_out());
3235 GURL
swappedOutURL(kSwappedOutURL
);
3236 WebURLRequest
request(swappedOutURL
);
3237 if (frame
->isWebLocalFrame())
3238 frame
->loadRequest(request
);
3241 void RenderViewImpl::OnClosePage() {
3242 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, ClosePage());
3243 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3244 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3245 // in the onunload handler from appearing. For now, we're bypassing that and
3246 // calling the FrameLoader's CloseURL method directly. This should be
3247 // revisited to avoid having two ways to close a page. Having a single way
3248 // to close that can run onunload is also useful for fixing
3249 // http://b/issue?id=753080.
3250 webview()->mainFrame()->dispatchUnloadEvent();
3252 Send(new ViewHostMsg_ClosePage_ACK(routing_id_
));
3255 void RenderViewImpl::OnThemeChanged() {
3256 #if defined(USE_AURA)
3257 // Aura doesn't care if we switch themes.
3258 #elif defined(OS_WIN)
3259 ui::NativeThemeWin::instance()->CloseHandles();
3261 webview()->themeChanged();
3262 #else // defined(OS_WIN)
3263 // TODO(port): we don't support theming on non-Windows platforms yet
3268 void RenderViewImpl::OnMoveOrResizeStarted() {
3270 webview()->hidePopups();
3273 void RenderViewImpl::OnResize(const ViewMsg_Resize_Params
& params
) {
3274 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
3276 webview()->hidePopups();
3277 if (send_preferred_size_changes_
) {
3278 webview()->mainFrame()->setCanHaveScrollbars(
3279 ShouldDisplayScrollbars(params
.new_size
.width(),
3280 params
.new_size
.height()));
3284 gfx::Size old_visible_viewport_size
= visible_viewport_size_
;
3286 RenderWidget::OnResize(params
);
3288 if (old_visible_viewport_size
!= visible_viewport_size_
)
3289 has_scrolled_focused_editable_node_into_rect_
= false;
3291 FOR_EACH_OBSERVER(RenderViewObserver
,
3296 void RenderViewImpl::DidInitiatePaint() {
3297 #if defined(ENABLE_PLUGINS)
3298 // Notify all instances that we painted. The same caveats apply as for
3299 // ViewFlushedPaint regarding instances closing themselves, so we take
3300 // similar precautions.
3301 PepperPluginSet plugins
= active_pepper_instances_
;
3302 for (PepperPluginSet::iterator i
= plugins
.begin(); i
!= plugins
.end(); ++i
) {
3303 if (active_pepper_instances_
.find(*i
) != active_pepper_instances_
.end())
3304 (*i
)->ViewInitiatedPaint();
3309 void RenderViewImpl::DidFlushPaint() {
3310 #if defined(ENABLE_PLUGINS)
3311 // Notify all instances that we flushed. This will call into the plugin, and
3312 // we it may ask to close itself as a result. This will, in turn, modify our
3313 // set, possibly invalidating the iterator. So we iterate on a copy that
3314 // won't change out from under us.
3315 PepperPluginSet plugins
= active_pepper_instances_
;
3316 for (PepperPluginSet::iterator i
= plugins
.begin(); i
!= plugins
.end(); ++i
) {
3317 // The copy above makes sure our iterator is never invalid if some plugins
3318 // are destroyed. But some plugin may decide to close all of its views in
3319 // response to a paint in one of them, so we need to make sure each one is
3320 // still "current" before using it.
3322 // It's possible that a plugin was destroyed, but another one was created
3323 // with the same address. In this case, we'll call ViewFlushedPaint on that
3324 // new plugin. But that's OK for this particular case since we're just
3325 // notifying all of our instances that the view flushed, and the new one is
3326 // one of our instances.
3328 // What about the case where a new one is created in a callback at a new
3329 // address and we don't issue the callback? We're still OK since this
3330 // callback is used for flush callbacks and we could not have possibly
3331 // started a new paint for the new plugin while processing a previous paint
3332 // for an existing one.
3333 if (active_pepper_instances_
.find(*i
) != active_pepper_instances_
.end())
3334 (*i
)->ViewFlushedPaint();
3338 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
3339 // See crbug.com/112921.
3343 WebFrame
* main_frame
= webview()->mainFrame();
3344 for (WebFrame
* frame
= main_frame
; frame
;
3345 frame
= frame
->traverseNext(false)) {
3346 // TODO(nasko): This is a hack for the case in which the top-level
3347 // frame is being rendered in another process. It will not
3348 // behave correctly for out of process iframes.
3349 if (frame
->isWebLocalFrame()) {
3355 // If we have a provisional frame we are between the start and commit stages
3356 // of loading and we don't want to save stats.
3357 if (!main_frame
->provisionalDataSource()) {
3358 WebDataSource
* ds
= main_frame
->dataSource();
3359 DocumentState
* document_state
= DocumentState::FromDataSource(ds
);
3361 // TODO(jar): The following code should all be inside a method, probably in
3363 Time now
= Time::Now();
3364 if (document_state
->first_paint_time().is_null()) {
3365 document_state
->set_first_paint_time(now
);
3367 if (document_state
->first_paint_after_load_time().is_null() &&
3368 !document_state
->finish_load_time().is_null()) {
3369 document_state
->set_first_paint_after_load_time(now
);
3374 gfx::Vector2d
RenderViewImpl::GetScrollOffset() {
3375 WebFrame
* main_frame
= webview()->mainFrame();
3376 for (WebFrame
* frame
= main_frame
; frame
;
3377 frame
= frame
->traverseNext(false)) {
3378 // TODO(nasko): This is a hack for the case in which the top-level
3379 // frame is being rendered in another process. It will not
3380 // behave correctly for out of process iframes.
3381 if (frame
->isWebLocalFrame()) {
3387 WebSize scroll_offset
= main_frame
->scrollOffset();
3388 return gfx::Vector2d(scroll_offset
.width
, scroll_offset
.height
);
3391 void RenderViewImpl::OnClearFocusedElement() {
3393 webview()->clearFocusedElement();
3396 void RenderViewImpl::OnSetBackgroundOpaque(bool opaque
) {
3398 webview()->setIsTransparent(!opaque
);
3400 compositor_
->setHasTransparentBackground(!opaque
);
3403 void RenderViewImpl::OnSetActive(bool active
) {
3405 webview()->setIsActive(active
);
3407 #if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
3408 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3409 for (plugin_it
= plugin_delegates_
.begin();
3410 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3411 (*plugin_it
)->SetWindowFocus(active
);
3416 #if defined(OS_MACOSX)
3417 void RenderViewImpl::OnSetWindowVisibility(bool visible
) {
3418 #if defined(ENABLE_PLUGINS)
3419 // Inform plugins that their container has changed visibility.
3420 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3421 for (plugin_it
= plugin_delegates_
.begin();
3422 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3423 (*plugin_it
)->SetContainerVisibility(visible
);
3428 void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect
& window_frame
,
3429 const gfx::Rect
& view_frame
) {
3430 #if defined(ENABLE_PLUGINS)
3431 // Inform plugins that their window's frame has changed.
3432 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3433 for (plugin_it
= plugin_delegates_
.begin();
3434 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3435 (*plugin_it
)->WindowFrameChanged(window_frame
, view_frame
);
3440 void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16
& text
,
3442 // WebPluginDelegateProxy is responsible for figuring out if this event
3443 // applies to it or not, so inform all the delegates.
3444 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3445 for (plugin_it
= plugin_delegates_
.begin();
3446 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3447 (*plugin_it
)->ImeCompositionCompleted(text
, plugin_id
);
3452 void RenderViewImpl::OnClose() {
3454 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_
));
3455 RenderWidget::OnClose();
3458 void RenderViewImpl::Close() {
3459 // We need to grab a pointer to the doomed WebView before we destroy it.
3460 WebView
* doomed
= webview();
3461 RenderWidget::Close();
3462 g_view_map
.Get().erase(doomed
);
3463 g_routing_id_view_map
.Get().erase(routing_id_
);
3464 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_
));
3467 void RenderViewImpl::DidHandleKeyEvent() {
3468 ClearEditCommands();
3471 bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent
& event
) {
3472 possible_drag_event_info_
.event_source
=
3473 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE
;
3474 possible_drag_event_info_
.event_location
=
3475 gfx::Point(event
.globalX
, event
.globalY
);
3477 #if defined(ENABLE_PLUGINS)
3478 // This method is called for every mouse event that the render view receives.
3479 // And then the mouse event is forwarded to WebKit, which dispatches it to the
3480 // event target. Potentially a Pepper plugin will receive the event.
3481 // In order to tell whether a plugin gets the last mouse event and which it
3482 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
3483 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
3484 // |pepper_last_mouse_event_target_|.
3485 pepper_last_mouse_event_target_
= NULL
;
3488 // If the mouse is locked, only the current owner of the mouse lock can
3489 // process mouse events.
3490 return mouse_lock_dispatcher_
->WillHandleMouseEvent(event
);
3493 bool RenderViewImpl::WillHandleGestureEvent(
3494 const blink::WebGestureEvent
& event
) {
3495 possible_drag_event_info_
.event_source
=
3496 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH
;
3497 possible_drag_event_info_
.event_location
=
3498 gfx::Point(event
.globalX
, event
.globalY
);
3502 void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent
& event
) {
3503 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidHandleMouseEvent(event
));
3506 void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent
& event
) {
3507 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidHandleTouchEvent(event
));
3510 bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point
& point
) const {
3513 return webview()->hasTouchEventHandlersAt(point
);
3516 void RenderViewImpl::OnWasHidden() {
3517 RenderWidget::OnWasHidden();
3519 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3520 RenderThreadImpl::current()->video_capture_impl_manager()->
3521 SuspendDevices(true);
3522 if (speech_recognition_dispatcher_
)
3523 speech_recognition_dispatcher_
->AbortAllRecognitions();
3527 webview()->setVisibilityState(visibilityState(), false);
3529 #if defined(ENABLE_PLUGINS)
3530 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3531 i
!= active_pepper_instances_
.end(); ++i
)
3532 (*i
)->PageVisibilityChanged(false);
3534 #if defined(OS_MACOSX)
3535 // Inform NPAPI plugins that their container is no longer visible.
3536 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3537 for (plugin_it
= plugin_delegates_
.begin();
3538 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3539 (*plugin_it
)->SetContainerVisibility(false);
3542 #endif // ENABLE_PLUGINS
3545 void RenderViewImpl::OnWasShown(bool needs_repainting
,
3546 const ui::LatencyInfo
& latency_info
) {
3547 RenderWidget::OnWasShown(needs_repainting
, latency_info
);
3549 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3550 RenderThreadImpl::current()->video_capture_impl_manager()->
3551 SuspendDevices(false);
3555 webview()->setVisibilityState(visibilityState(), false);
3557 #if defined(ENABLE_PLUGINS)
3558 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3559 i
!= active_pepper_instances_
.end(); ++i
)
3560 (*i
)->PageVisibilityChanged(true);
3562 #if defined(OS_MACOSX)
3563 // Inform NPAPI plugins that their container is now visible.
3564 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3565 for (plugin_it
= plugin_delegates_
.begin();
3566 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3567 (*plugin_it
)->SetContainerVisibility(true);
3570 #endif // ENABLE_PLUGINS
3573 GURL
RenderViewImpl::GetURLForGraphicsContext3D() {
3575 if (webview()->mainFrame()->isWebLocalFrame())
3576 return GURL(webview()->mainFrame()->document().url());
3578 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
3581 void RenderViewImpl::OnSetFocus(bool enable
) {
3582 RenderWidget::OnSetFocus(enable
);
3584 #if defined(ENABLE_PLUGINS)
3585 if (webview() && webview()->isActive()) {
3586 // Notify all NPAPI plugins.
3587 std::set
<WebPluginDelegateProxy
*>::iterator plugin_it
;
3588 for (plugin_it
= plugin_delegates_
.begin();
3589 plugin_it
!= plugin_delegates_
.end(); ++plugin_it
) {
3590 #if defined(OS_MACOSX)
3591 // RenderWidget's call to setFocus can cause the underlying webview's
3592 // activation state to change just like a call to setIsActive.
3594 (*plugin_it
)->SetWindowFocus(true);
3596 (*plugin_it
)->SetContentAreaFocus(enable
);
3599 // Notify all Pepper plugins.
3600 for (PepperPluginSet::iterator i
= active_pepper_instances_
.begin();
3601 i
!= active_pepper_instances_
.end(); ++i
)
3602 (*i
)->SetContentAreaFocus(enable
);
3604 // Notify all BrowserPlugins of the RenderView's focus state.
3605 if (browser_plugin_manager_
.get())
3606 browser_plugin_manager_
->UpdateFocusState();
3609 void RenderViewImpl::OnImeSetComposition(
3610 const base::string16
& text
,
3611 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
3612 int selection_start
,
3613 int selection_end
) {
3614 #if defined(ENABLE_PLUGINS)
3615 if (focused_pepper_plugin_
) {
3616 focused_pepper_plugin_
->render_frame()->OnImeSetComposition(
3617 text
, underlines
, selection_start
, selection_end
);
3622 // When a plug-in has focus, we create platform-specific IME data used by
3623 // our IME emulator and send it directly to the focused plug-in, i.e. we
3624 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
3625 // instance ID is the same one as the specified ID.)
3626 if (focused_plugin_id_
>= 0) {
3627 std::vector
<int> clauses
;
3628 std::vector
<int> target
;
3629 for (size_t i
= 0; i
< underlines
.size(); ++i
) {
3630 clauses
.push_back(underlines
[i
].startOffset
);
3631 clauses
.push_back(underlines
[i
].endOffset
);
3632 if (underlines
[i
].thick
) {
3634 target
.push_back(underlines
[i
].startOffset
);
3635 target
.push_back(underlines
[i
].endOffset
);
3638 std::set
<WebPluginDelegateProxy
*>::iterator it
;
3639 for (it
= plugin_delegates_
.begin(); it
!= plugin_delegates_
.end(); ++it
) {
3640 (*it
)->ImeCompositionUpdated(text
, clauses
, target
, selection_end
,
3641 focused_plugin_id_
);
3646 #endif // ENABLE_PLUGINS
3647 RenderWidget::OnImeSetComposition(text
,
3653 void RenderViewImpl::OnImeConfirmComposition(
3654 const base::string16
& text
,
3655 const gfx::Range
& replacement_range
,
3656 bool keep_selection
) {
3657 #if defined(ENABLE_PLUGINS)
3658 if (focused_pepper_plugin_
) {
3659 focused_pepper_plugin_
->render_frame()->OnImeConfirmComposition(
3660 text
, replacement_range
, keep_selection
);
3664 // Same as OnImeSetComposition(), we send the text from IMEs directly to
3665 // plug-ins. When we send IME text directly to plug-ins, we should not send
3666 // it to WebKit to prevent WebKit from controlling IMEs.
3667 // TODO(thakis): Honor |replacement_range| for plugins?
3668 if (focused_plugin_id_
>= 0) {
3669 std::set
<WebPluginDelegateProxy
*>::iterator it
;
3670 for (it
= plugin_delegates_
.begin();
3671 it
!= plugin_delegates_
.end(); ++it
) {
3672 (*it
)->ImeCompositionCompleted(text
, focused_plugin_id_
);
3677 #endif // ENABLE_PLUGINS
3678 if (replacement_range
.IsValid() && webview()) {
3679 // Select the text in |replacement_range|, it will then be replaced by
3680 // text added by the call to RenderWidget::OnImeConfirmComposition().
3681 if (WebLocalFrame
* frame
= webview()->focusedFrame()->toWebLocalFrame()) {
3682 WebRange webrange
= WebRange::fromDocumentRange(
3683 frame
, replacement_range
.start(), replacement_range
.length());
3684 if (!webrange
.isNull())
3685 frame
->selectRange(webrange
);
3688 RenderWidget::OnImeConfirmComposition(text
,
3693 void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor
) {
3694 RenderWidget::SetDeviceScaleFactor(device_scale_factor
);
3696 webview()->setDeviceScaleFactor(device_scale_factor
);
3697 webview()->settings()->setPreferCompositingToLCDTextEnabled(
3698 PreferCompositingToLCDText(device_scale_factor_
));
3699 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
3700 ShouldUseTransitionCompositing(device_scale_factor_
));
3702 if (auto_resize_mode_
)
3703 AutoResizeCompositor();
3705 if (browser_plugin_manager_
.get())
3706 browser_plugin_manager_
->UpdateDeviceScaleFactor();
3709 bool RenderViewImpl::SetDeviceColorProfile(
3710 const std::vector
<char>& profile
) {
3711 bool changed
= RenderWidget::SetDeviceColorProfile(profile
);
3712 if (changed
&& webview()) {
3713 WebVector
<char> colorProfile
= profile
;
3714 webview()->setDeviceColorProfile(colorProfile
);
3719 void RenderViewImpl::ResetDeviceColorProfileForTesting() {
3720 RenderWidget::ResetDeviceColorProfileForTesting();
3722 webview()->resetDeviceColorProfile();
3725 ui::TextInputType
RenderViewImpl::GetTextInputType() {
3726 #if defined(ENABLE_PLUGINS)
3727 if (focused_pepper_plugin_
)
3728 return focused_pepper_plugin_
->text_input_type();
3730 return RenderWidget::GetTextInputType();
3733 void RenderViewImpl::GetSelectionBounds(gfx::Rect
* start
, gfx::Rect
* end
) {
3734 #if defined(ENABLE_PLUGINS)
3735 if (focused_pepper_plugin_
) {
3736 // TODO(kinaba) http://crbug.com/101101
3737 // Current Pepper IME API does not handle selection bounds. So we simply
3738 // use the caret position as an empty range for now. It will be updated
3739 // after Pepper API equips features related to surrounding text retrieval.
3740 gfx::Rect caret
= focused_pepper_plugin_
->GetCaretBounds();
3746 RenderWidget::GetSelectionBounds(start
, end
);
3749 #if defined(OS_MACOSX) || defined(USE_AURA) || defined(OS_ANDROID)
3750 void RenderViewImpl::GetCompositionCharacterBounds(
3751 std::vector
<gfx::Rect
>* bounds
) {
3755 #if defined(ENABLE_PLUGINS)
3756 if (focused_pepper_plugin_
) {
3763 size_t start_offset
= 0;
3764 size_t character_count
= 0;
3765 if (!webview()->compositionRange(&start_offset
, &character_count
))
3767 if (character_count
== 0)
3770 blink::WebFrame
* frame
= webview()->focusedFrame();
3774 bounds
->reserve(character_count
);
3775 blink::WebRect webrect
;
3776 for (size_t i
= 0; i
< character_count
; ++i
) {
3777 if (!frame
->firstRectForCharacterRange(start_offset
+ i
, 1, webrect
)) {
3778 DLOG(ERROR
) << "Could not retrieve character rectangle at " << i
;
3782 bounds
->push_back(webrect
);
3786 void RenderViewImpl::GetCompositionRange(gfx::Range
* range
) {
3787 #if defined(ENABLE_PLUGINS)
3788 if (focused_pepper_plugin_
) {
3792 RenderWidget::GetCompositionRange(range
);
3796 bool RenderViewImpl::CanComposeInline() {
3797 #if defined(ENABLE_PLUGINS)
3798 if (focused_pepper_plugin_
)
3799 return focused_pepper_plugin_
->IsPluginAcceptingCompositionEvents();
3804 void RenderViewImpl::InstrumentWillBeginFrame(int frame_id
) {
3807 if (!webview()->devToolsAgent())
3809 webview()->devToolsAgent()->didBeginFrame(frame_id
);
3812 void RenderViewImpl::InstrumentDidBeginFrame() {
3815 if (!webview()->devToolsAgent())
3817 // TODO(jamesr/caseq): Decide if this needs to be renamed.
3818 webview()->devToolsAgent()->didComposite();
3821 void RenderViewImpl::InstrumentDidCancelFrame() {
3824 if (!webview()->devToolsAgent())
3826 webview()->devToolsAgent()->didCancelFrame();
3829 void RenderViewImpl::InstrumentWillComposite() {
3832 if (!webview()->devToolsAgent())
3834 webview()->devToolsAgent()->willComposite();
3837 void RenderViewImpl::SetScreenMetricsEmulationParameters(
3838 float device_scale_factor
,
3839 const gfx::Point
& root_layer_offset
,
3840 float root_layer_scale
) {
3841 if (webview() && compositor()) {
3842 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor
);
3843 webview()->setRootLayerTransform(
3844 blink::WebSize(root_layer_offset
.x(), root_layer_offset
.y()),
3849 bool RenderViewImpl::ScheduleFileChooser(
3850 const FileChooserParams
& params
,
3851 WebFileChooserCompletion
* completion
) {
3852 static const size_t kMaximumPendingFileChooseRequests
= 4;
3853 if (file_chooser_completions_
.size() > kMaximumPendingFileChooseRequests
) {
3854 // This sanity check prevents too many file choose requests from getting
3855 // queued which could DoS the user. Getting these is most likely a
3856 // programming error (there are many ways to DoS the user so it's not
3857 // considered a "real" security check), either in JS requesting many file
3858 // choosers to pop up, or in a plugin.
3860 // TODO(brettw) we might possibly want to require a user gesture to open
3861 // a file picker, which will address this issue in a better way.
3865 file_chooser_completions_
.push_back(linked_ptr
<PendingFileChooser
>(
3866 new PendingFileChooser(params
, completion
)));
3867 if (file_chooser_completions_
.size() == 1) {
3868 // Actually show the browse dialog when this is the first request.
3869 Send(new ViewHostMsg_RunFileChooser(routing_id_
, params
));
3874 blink::WebSpeechRecognizer
* RenderViewImpl::speechRecognizer() {
3875 if (!speech_recognition_dispatcher_
)
3876 speech_recognition_dispatcher_
= new SpeechRecognitionDispatcher(this);
3877 return speech_recognition_dispatcher_
;
3880 void RenderViewImpl::zoomLimitsChanged(double minimum_level
,
3881 double maximum_level
) {
3882 int minimum_percent
= static_cast<int>(
3883 ZoomLevelToZoomFactor(minimum_level
) * 100);
3884 int maximum_percent
= static_cast<int>(
3885 ZoomLevelToZoomFactor(maximum_level
) * 100);
3887 Send(new ViewHostMsg_UpdateZoomLimits(
3888 routing_id_
, minimum_percent
, maximum_percent
));
3891 void RenderViewImpl::zoomLevelChanged() {
3892 double zoom_level
= webview()->zoomLevel();
3894 // Do not send empty URLs to the browser when we are just setting the default
3895 // zoom level (from RendererPreferences) before the first navigation.
3896 if (!webview()->mainFrame()->document().url().isEmpty()) {
3897 // Tell the browser which url got zoomed so it can update the menu and the
3898 // saved values if necessary
3899 Send(new ViewHostMsg_DidZoomURL(
3900 routing_id_
, zoom_level
,
3901 GURL(webview()->mainFrame()->document().url())));
3905 double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level
) const {
3906 return ZoomLevelToZoomFactor(zoom_level
);
3909 double RenderViewImpl::zoomFactorToZoomLevel(double factor
) const {
3910 return ZoomFactorToZoomLevel(factor
);
3913 void RenderViewImpl::registerProtocolHandler(const WebString
& scheme
,
3915 const WebString
& title
) {
3916 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3917 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_
,
3918 base::UTF16ToUTF8(scheme
),
3924 void RenderViewImpl::unregisterProtocolHandler(const WebString
& scheme
,
3925 const WebURL
& url
) {
3926 bool user_gesture
= WebUserGestureIndicator::isProcessingUserGesture();
3927 Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_
,
3928 base::UTF16ToUTF8(scheme
),
3933 blink::WebPageVisibilityState
RenderViewImpl::visibilityState() const {
3934 blink::WebPageVisibilityState current_state
= is_hidden() ?
3935 blink::WebPageVisibilityStateHidden
:
3936 blink::WebPageVisibilityStateVisible
;
3937 blink::WebPageVisibilityState override_state
= current_state
;
3938 // TODO(jam): move this method to WebFrameClient.
3939 if (GetContentClient()->renderer()->
3940 ShouldOverridePageVisibilityState(main_render_frame_
.get(),
3942 return override_state
;
3943 return current_state
;
3946 blink::WebPushClient
* RenderViewImpl::webPushClient() {
3947 // TODO(mvanouwerkerk): Remove this method once the Push API code in Blink
3948 // has also switched over to Frame.
3949 return main_render_frame_
->pushClient();
3952 void RenderViewImpl::draggableRegionsChanged() {
3956 DraggableRegionsChanged(webview()->mainFrame()));
3959 #if defined(OS_ANDROID)
3960 WebContentDetectionResult
RenderViewImpl::detectContentAround(
3961 const WebHitTestResult
& touch_hit
) {
3962 DCHECK(!touch_hit
.isNull());
3963 DCHECK(!touch_hit
.node().isNull());
3964 DCHECK(touch_hit
.node().isTextNode());
3966 // Process the position with all the registered content detectors until
3967 // a match is found. Priority is provided by their relative order.
3968 for (ContentDetectorList::const_iterator it
= content_detectors_
.begin();
3969 it
!= content_detectors_
.end(); ++it
) {
3970 ContentDetector::Result content
= (*it
)->FindTappedContent(touch_hit
);
3971 if (content
.valid
) {
3972 return WebContentDetectionResult(content
.content_boundaries
,
3973 base::UTF8ToUTF16(content
.text
), content
.intent_url
);
3976 return WebContentDetectionResult();
3979 void RenderViewImpl::scheduleContentIntent(const WebURL
& intent
) {
3980 // Introduce a short delay so that the user can notice the content.
3981 base::MessageLoop::current()->PostDelayedTask(
3983 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent
,
3986 expected_content_intent_id_
),
3987 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds
));
3990 void RenderViewImpl::cancelScheduledContentIntents() {
3991 ++expected_content_intent_id_
;
3994 void RenderViewImpl::LaunchAndroidContentIntent(const GURL
& intent
,
3995 size_t request_id
) {
3996 if (request_id
!= expected_content_intent_id_
)
3999 // Remove the content highlighting if any.
4000 scheduleComposite();
4002 if (!intent
.is_empty())
4003 Send(new ViewHostMsg_StartContentIntent(routing_id_
, intent
));
4006 bool RenderViewImpl::openDateTimeChooser(
4007 const blink::WebDateTimeChooserParams
& params
,
4008 blink::WebDateTimeChooserCompletion
* completion
) {
4009 // JavaScript may try to open a date time chooser while one is already open.
4010 if (date_time_picker_client_
)
4012 date_time_picker_client_
.reset(
4013 new RendererDateTimePicker(this, params
, completion
));
4014 return date_time_picker_client_
->Open();
4017 void RenderViewImpl::DismissDateTimeDialog() {
4018 DCHECK(date_time_picker_client_
);
4019 date_time_picker_client_
.reset(NULL
);
4022 #endif // defined(OS_ANDROID)
4024 void RenderViewImpl::OnShowContextMenu(
4025 ui::MenuSourceType source_type
, const gfx::Point
& location
) {
4026 context_menu_source_type_
= source_type
;
4027 has_host_context_menu_location_
= true;
4028 host_context_menu_location_
= location
;
4030 webview()->showContextMenu();
4031 has_host_context_menu_location_
= false;
4034 void RenderViewImpl::OnEnableViewSourceMode() {
4037 WebFrame
* main_frame
= webview()->mainFrame();
4040 main_frame
->enableViewSourceMode(true);
4043 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
4044 bool RenderViewImpl::didTapMultipleTargets(
4045 const WebSize
& inner_viewport_offset
,
4046 const WebRect
& touch_rect
,
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 GetMainRenderFrame()->accessibility_mode();
4052 bool matches_accessibility_mode_complete
=
4053 (accessibility_mode
& AccessibilityModeComplete
) ==
4054 AccessibilityModeComplete
;
4055 if (matches_accessibility_mode_complete
)
4058 // The touch_rect, target_rects and zoom_rect are in the outer viewport
4060 gfx::Rect zoom_rect
;
4061 float new_total_scale
=
4062 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
4063 touch_rect
, target_rects
, GetSize(),
4064 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
4065 device_scale_factor_
* webview()->pageScaleFactor(), &zoom_rect
);
4066 if (!new_total_scale
)
4069 bool handled
= false;
4070 switch (renderer_preferences_
.tap_multiple_targets_strategy
) {
4071 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM
:
4072 handled
= webview()->zoomToMultipleTargetsRect(zoom_rect
);
4074 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP
: {
4075 gfx::Size canvas_size
=
4076 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect
.size(), new_total_scale
));
4077 cc::SharedBitmapManager
* manager
=
4078 RenderThreadImpl::current()->shared_bitmap_manager();
4079 scoped_ptr
<cc::SharedBitmap
> shared_bitmap
=
4080 manager
->AllocateSharedBitmap(canvas_size
);
4083 SkImageInfo info
= SkImageInfo::MakeN32Premul(canvas_size
.width(),
4084 canvas_size
.height());
4085 bitmap
.installPixels(info
, shared_bitmap
->pixels(), info
.minRowBytes());
4086 SkCanvas
canvas(bitmap
);
4088 // TODO(trchen): Cleanup the device scale factor mess.
4089 // device scale will be applied in WebKit
4090 // --> zoom_rect doesn't include device scale,
4091 // but WebKit will still draw on zoom_rect * device_scale_factor_
4092 canvas
.scale(new_total_scale
/ device_scale_factor_
,
4093 new_total_scale
/ device_scale_factor_
);
4094 canvas
.translate(-zoom_rect
.x() * device_scale_factor_
,
4095 -zoom_rect
.y() * device_scale_factor_
);
4097 DCHECK(webwidget_
->isAcceleratedCompositingActive());
4098 // TODO(aelias): The disambiguation popup should be composited so we
4099 // don't have to call this method.
4100 webwidget_
->paintCompositedDeprecated(&canvas
, zoom_rect
);
4103 gfx::Rect zoom_rect_in_screen
=
4104 zoom_rect
- gfx::Vector2d(inner_viewport_offset
.width
,
4105 inner_viewport_offset
.height
);
4107 gfx::Rect physical_window_zoom_rect
= gfx::ToEnclosingRect(
4108 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen
)));
4110 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_
,
4111 physical_window_zoom_rect
,
4113 shared_bitmap
->id()));
4114 cc::SharedBitmapId id
= shared_bitmap
->id();
4115 disambiguation_bitmaps_
[id
] = shared_bitmap
.release();
4119 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE
:
4126 #endif // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
4128 unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
4129 return history_list_length_
;
4132 void RenderViewImpl::SetFocusAndActivateForTesting(bool enable
) {
4146 void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor
) {
4147 ViewMsg_Resize_Params params
;
4148 params
.screen_info
= screen_info_
;
4149 params
.screen_info
.deviceScaleFactor
= factor
;
4150 params
.new_size
= size();
4151 params
.visible_viewport_size
= visible_viewport_size_
;
4152 params
.physical_backing_size
=
4153 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor
));
4154 params
.top_controls_layout_height
= 0.f
;
4155 params
.resizer_rect
= WebRect();
4156 params
.is_fullscreen
= is_fullscreen();
4160 void RenderViewImpl::SetDeviceColorProfileForTesting(
4161 const std::vector
<char>& color_profile
) {
4162 SetDeviceColorProfile(color_profile
);
4165 void RenderViewImpl::ForceResizeForTesting(const gfx::Size
& new_size
) {
4166 gfx::Rect
new_position(rootWindowRect().x
,
4170 ResizeSynchronously(new_position
, new_size
);
4173 void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable
) {
4174 resizing_mode_selector_
->set_is_synchronous_mode(enable
);
4177 void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size
& min_size
,
4178 const gfx::Size
& max_size
) {
4179 OnEnableAutoResize(min_size
, max_size
);
4182 void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size
& new_size
) {
4183 OnDisableAutoResize(new_size
);
4186 void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
4187 const cc::SharedBitmapId
& id
) {
4188 BitmapMap::iterator it
= disambiguation_bitmaps_
.find(id
);
4189 DCHECK(it
!= disambiguation_bitmaps_
.end());
4191 disambiguation_bitmaps_
.erase(it
);
4194 void RenderViewImpl::DidCommitCompositorFrame() {
4195 RenderWidget::DidCommitCompositorFrame();
4196 FOR_EACH_OBSERVER(RenderViewObserver
, observers_
, DidCommitCompositorFrame());
4199 void RenderViewImpl::SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
) {
4201 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_
, urls
));
4204 void RenderViewImpl::DidStopLoadingIcons() {
4205 int icon_types
= WebIconURL::TypeFavicon
;
4207 icon_types
|= WebIconURL::TypeTouchPrecomposed
| WebIconURL::TypeTouch
;
4209 // Favicons matter only for the top-level frame. If it is a WebRemoteFrame,
4210 // just return early.
4211 if (webview()->mainFrame()->isWebRemoteFrame())
4214 WebVector
<WebIconURL
> icon_urls
=
4215 webview()->mainFrame()->iconURLs(icon_types
);
4217 std::vector
<FaviconURL
> urls
;
4218 for (size_t i
= 0; i
< icon_urls
.size(); i
++) {
4219 WebURL url
= icon_urls
[i
].iconURL();
4220 std::vector
<gfx::Size
> sizes
;
4221 ConvertToFaviconSizes(icon_urls
[i
].sizes(), &sizes
);
4224 FaviconURL(url
, ToFaviconType(icon_urls
[i
].iconType()), sizes
));
4226 SendUpdateFaviconURL(urls
);
4229 } // namespace content