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 #ifndef CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
14 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/id_map.h"
17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h"
20 #include "base/process/process.h"
21 #include "base/strings/string16.h"
22 #include "base/timer/timer.h"
23 #include "build/build_config.h"
24 #include "cc/input/top_controls_state.h"
25 #include "cc/resources/shared_bitmap.h"
26 #include "content/common/content_export.h"
27 #include "content/common/drag_event_source_info.h"
28 #include "content/common/edit_command.h"
29 #include "content/common/frame_message_enums.h"
30 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
31 #include "content/common/navigation_gesture.h"
32 #include "content/common/navigation_params.h"
33 #include "content/common/view_message_enums.h"
34 #include "content/public/common/page_zoom.h"
35 #include "content/public/common/referrer.h"
36 #include "content/public/common/renderer_preferences.h"
37 #include "content/public/common/stop_find_action.h"
38 #include "content/public/common/top_controls_state.h"
39 #include "content/public/common/web_preferences.h"
40 #include "content/public/renderer/render_view.h"
41 #include "content/renderer/mouse_lock_dispatcher.h"
42 #include "content/renderer/render_frame_impl.h"
43 #include "content/renderer/render_widget.h"
44 #include "content/renderer/stats_collection_observer.h"
45 #include "ipc/ipc_platform_file.h"
46 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
47 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
48 #include "third_party/WebKit/public/web/WebAXObject.h"
49 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
50 #include "third_party/WebKit/public/web/WebDataSource.h"
51 #include "third_party/WebKit/public/web/WebElement.h"
52 #include "third_party/WebKit/public/web/WebHistoryItem.h"
53 #include "third_party/WebKit/public/web/WebIconURL.h"
54 #include "third_party/WebKit/public/web/WebInputEvent.h"
55 #include "third_party/WebKit/public/web/WebNavigationType.h"
56 #include "third_party/WebKit/public/web/WebNode.h"
57 #include "third_party/WebKit/public/web/WebPageSerializerClient.h"
58 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
59 #include "third_party/WebKit/public/web/WebViewClient.h"
60 #include "ui/base/window_open_disposition.h"
61 #include "ui/surface/transport_dib.h"
63 #if defined(OS_ANDROID)
64 #include "content/renderer/android/content_detector.h"
65 #include "content/renderer/android/renderer_date_time_picker.h"
66 #include "third_party/WebKit/public/web/WebContentDetectionResult.h"
69 #if defined(COMPILER_MSVC)
70 // RenderViewImpl is a diamond-shaped hierarchy, with WebWidgetClient at the
71 // root. VS warns when we inherit the WebWidgetClient method implementations
72 // from RenderWidget. It's safe to ignore that warning.
73 #pragma warning(disable: 4250)
76 class PepperDeviceTest
;
78 struct PP_NetAddress_Private
;
79 struct FrameMsg_Navigate_Params
;
80 struct ViewMsg_New_Params
;
81 struct ViewMsg_PostMessage_Params
;
82 struct ViewMsg_Resize_Params
;
83 struct ViewMsg_StopFinding_Params
;
90 class WebApplicationCacheHost
;
91 class WebApplicationCacheHostClient
;
92 class WebDOMMessageEvent
;
94 class WebDateTimeChooserCompletion
;
96 class WebGestureEvent
;
99 class WebPeerConnection00Handler
;
100 class WebPeerConnection00HandlerClient
;
102 class WebPeerConnectionHandler
;
103 class WebPeerConnectionHandlerClient
;
104 class WebSpeechRecognizer
;
105 class WebStorageNamespace
;
108 struct WebActiveWheelFlingParameters
;
109 struct WebDateTimeChooserParams
;
110 struct WebFileChooserParams
;
111 struct WebFindOptions
;
112 struct WebMediaPlayerAction
;
113 struct WebPluginAction
;
115 struct WebWindowFeatures
;
117 #if defined(OS_ANDROID)
118 class WebHitTestResult
;
126 class HistoryController
;
128 class MouseLockDispatcher
;
129 class NavigationState
;
131 class PepperPluginInstanceImpl
;
132 class RenderViewImplTest
;
133 class RenderViewObserver
;
134 class RenderViewTest
;
135 class RendererDateTimePicker
;
136 class RendererWebColorChooserImpl
;
137 class SpeechRecognitionDispatcher
;
138 class WebPluginDelegateProxy
;
141 struct FileChooserParams
;
142 struct FileChooserFileInfo
;
143 struct RenderViewImplParams
;
145 #if defined(OS_ANDROID)
146 class WebMediaPlayerProxyAndroid
;
150 // RenderView is an object that manages a WebView object, and provides a
151 // communication interface with an embedding application process.
153 class CONTENT_EXPORT RenderViewImpl
154 : public RenderWidget
,
155 NON_EXPORTED_BASE(public blink::WebViewClient
),
156 NON_EXPORTED_BASE(public blink::WebPageSerializerClient
),
158 public base::SupportsWeakPtr
<RenderViewImpl
> {
160 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
161 // responsible for creating this RenderView. Note that if the original opener
162 // has been closed, |window_was_created_with_opener| will be true and
163 // |opener_id| will be MSG_ROUTING_NONE. When |swapped_out| is true, the
164 // |proxy_routing_id| is specified, so a RenderFrameProxy can be created for
165 // this RenderView's main RenderFrame.
166 static RenderViewImpl
* Create(const ViewMsg_New_Params
& params
,
167 CompositorDependencies
* compositor_deps
,
168 bool was_created_by_renderer
);
170 // Used by content_layouttest_support to hook into the creation of
172 static void InstallCreateHook(
173 RenderViewImpl
* (*create_render_view_impl
)(const ViewMsg_New_Params
&));
175 // Returns the RenderViewImpl containing the given WebView.
176 static RenderViewImpl
* FromWebView(blink::WebView
* webview
);
178 // Returns the RenderViewImpl for the given routing ID.
179 static RenderViewImpl
* FromRoutingID(int routing_id
);
181 static size_t GetRenderViewCount();
183 // May return NULL when the view is closing.
184 blink::WebView
* webview() const;
186 const WebPreferences
& webkit_preferences() const {
187 return webkit_preferences_
;
190 const RendererPreferences
& renderer_preferences() const {
191 return renderer_preferences_
;
194 void set_send_content_state_immediately(bool value
) {
195 send_content_state_immediately_
= value
;
198 MouseLockDispatcher
* mouse_lock_dispatcher() {
199 return mouse_lock_dispatcher_
;
202 HistoryController
* history_controller() {
203 return history_controller_
.get();
206 // Functions to add and remove observers for this object.
207 void AddObserver(RenderViewObserver
* observer
);
208 void RemoveObserver(RenderViewObserver
* observer
);
210 // Returns the StatsCollectionObserver associated with this view, or NULL
211 // if one wasn't created;
212 StatsCollectionObserver
* GetStatsCollectionObserver() {
213 return stats_collection_observer_
.get();
216 // Adds the given file chooser request to the file_chooser_completion_ queue
217 // (see that var for more) and requests the chooser be displayed if there are
218 // no other waiting items in the queue.
220 // Returns true if the chooser was successfully scheduled. False means we
221 // didn't schedule anything.
222 bool ScheduleFileChooser(const FileChooserParams
& params
,
223 blink::WebFileChooserCompletion
* completion
);
225 #if defined(OS_ANDROID)
226 void DismissDateTimeDialog();
229 bool is_loading() const { return frames_in_progress_
!= 0; }
231 void FrameDidStartLoading(blink::WebFrame
* frame
);
232 void FrameDidStopLoading(blink::WebFrame
* frame
);
234 // Plugin-related functions --------------------------------------------------
236 #if defined(ENABLE_PLUGINS)
237 // Get/set the plugin which will be used as to handle document find requests.
238 void set_plugin_find_handler(PepperPluginInstanceImpl
* plugin
) {
239 plugin_find_handler_
= plugin
;
241 PepperPluginInstanceImpl
* plugin_find_handler() {
242 return plugin_find_handler_
;
245 PepperPluginInstanceImpl
* focused_pepper_plugin() {
246 return focused_pepper_plugin_
;
248 PepperPluginInstanceImpl
* pepper_last_mouse_event_target() {
249 return pepper_last_mouse_event_target_
;
251 void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl
* plugin
) {
252 pepper_last_mouse_event_target_
= plugin
;
255 #if defined(OS_MACOSX) || defined(OS_WIN)
256 // Informs the render view that the given plugin has gained or lost focus.
257 void PluginFocusChanged(bool focused
, int plugin_id
);
260 #if defined(OS_MACOSX)
261 // Starts plugin IME.
262 void StartPluginIme();
265 // Indicates that the given instance has been created.
266 void PepperInstanceCreated(PepperPluginInstanceImpl
* instance
);
268 // Indicates that the given instance is being destroyed. This is called from
269 // the destructor, so it's important that the instance is not dereferenced
271 void PepperInstanceDeleted(PepperPluginInstanceImpl
* instance
);
273 // Notification that the given plugin is focused or unfocused.
274 void PepperFocusChanged(PepperPluginInstanceImpl
* instance
, bool focused
);
276 void RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
277 void UnregisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
278 #endif // ENABLE_PLUGINS
280 void TransferActiveWheelFlingAnimation(
281 const blink::WebActiveWheelFlingParameters
& params
);
283 // Returns true if the focused element is editable text from the perspective
284 // of IME support (also used for on-screen keyboard). Works correctly inside
285 // supported PPAPI plug-ins.
286 bool HasIMETextFocus();
288 // Callback for use with GetWindowSnapshot.
289 typedef base::Callback
<void(
290 const gfx::Size
&, const std::vector
<unsigned char>&)>
291 WindowSnapshotCallback
;
293 void GetWindowSnapshot(const WindowSnapshotCallback
& callback
);
295 // Dispatches the current navigation state to the browser. Called on a
296 // periodic timer so we don't send too many messages.
297 void SyncNavigationState();
299 // Returns the length of the session history of this RenderView. Note that
300 // this only coincides with the actual length of the session history if this
301 // RenderView is the currently active RenderView of a WebContents.
302 unsigned GetLocalSessionHistoryLengthForTesting() const;
304 // Invokes OnSetFocus and marks the widget as active depending on the value
305 // of |enable|. This is used for layout tests that need to control the focus
306 // synchronously from the renderer.
307 void SetFocusAndActivateForTesting(bool enable
);
309 // Change the device scale factor and force the compositor to resize.
310 void SetDeviceScaleFactorForTesting(float factor
);
312 // Change the device ICC color profile while running a layout test.
313 void SetDeviceColorProfileForTesting(const std::vector
<char>& color_profile
);
314 void ResetDeviceColorProfileForTesting() override
;
316 // Used to force the size of a window when running layout tests.
317 void ForceResizeForTesting(const gfx::Size
& new_size
);
319 void UseSynchronousResizeModeForTesting(bool enable
);
321 // Control autoresize mode.
322 void EnableAutoResizeForTesting(const gfx::Size
& min_size
,
323 const gfx::Size
& max_size
);
324 void DisableAutoResizeForTesting(const gfx::Size
& new_size
);
326 // IPC::Listener implementation ----------------------------------------------
328 bool OnMessageReceived(const IPC::Message
& msg
) override
;
330 // blink::WebWidgetClient implementation ------------------------------------
332 // Most methods are handled by RenderWidget.
333 virtual void didFocus();
334 virtual void didBlur();
335 virtual void show(blink::WebNavigationPolicy policy
);
336 virtual bool requestPointerLock();
337 virtual void requestPointerUnlock();
338 virtual bool isPointerLocked();
339 virtual void didHandleGestureEvent(const blink::WebGestureEvent
& event
,
340 bool event_cancelled
) override
;
341 virtual void initializeLayerTreeView() override
;
343 // blink::WebViewClient implementation --------------------------------------
345 virtual blink::WebView
* createView(blink::WebLocalFrame
* creator
,
346 const blink::WebURLRequest
& request
,
347 const blink::WebWindowFeatures
& features
,
348 const blink::WebString
& frame_name
,
349 blink::WebNavigationPolicy policy
,
350 bool suppress_opener
);
351 virtual blink::WebWidget
* createPopupMenu(blink::WebPopupType popup_type
);
352 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
353 virtual void printPage(blink::WebLocalFrame
* frame
);
354 virtual bool enumerateChosenDirectory(
355 const blink::WebString
& path
,
356 blink::WebFileChooserCompletion
* chooser_completion
);
357 virtual void saveImageFromDataURL(const blink::WebString
& data_url
);
358 virtual void didCancelCompositionOnSelectionChange();
359 virtual bool handleCurrentKeyboardEvent();
360 virtual bool runFileChooser(
361 const blink::WebFileChooserParams
& params
,
362 blink::WebFileChooserCompletion
* chooser_completion
);
363 void SetValidationMessageDirection(base::string16
* main_text
,
364 blink::WebTextDirection main_text_hint
,
365 base::string16
* sub_text
,
366 blink::WebTextDirection sub_text_hint
);
367 virtual void showValidationMessage(const blink::WebRect
& anchor_in_root_view
,
368 const blink::WebString
& main_text
,
369 blink::WebTextDirection main_text_hint
,
370 const blink::WebString
& sub_text
,
371 blink::WebTextDirection hint
) override
;
372 virtual void hideValidationMessage() override
;
373 virtual void moveValidationMessage(
374 const blink::WebRect
& anchor_in_root_view
) override
;
375 virtual void setStatusText(const blink::WebString
& text
);
376 virtual void setMouseOverURL(const blink::WebURL
& url
);
377 virtual void setKeyboardFocusURL(const blink::WebURL
& url
);
378 virtual void startDragging(blink::WebLocalFrame
* frame
,
379 const blink::WebDragData
& data
,
380 blink::WebDragOperationsMask mask
,
381 const blink::WebImage
& image
,
382 const blink::WebPoint
& imageOffset
);
383 virtual bool acceptsLoadDrops();
384 virtual void focusNext();
385 virtual void focusPrevious();
386 virtual void focusedNodeChanged(const blink::WebNode
& fromNode
,
387 const blink::WebNode
& toNode
);
388 virtual void didUpdateLayout();
389 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
390 virtual bool didTapMultipleTargets(
391 const blink::WebSize
& inner_viewport_offset
,
392 const blink::WebRect
& touch_rect
,
393 const blink::WebVector
<blink::WebRect
>& target_rects
);
395 virtual blink::WebString
acceptLanguages();
396 virtual void navigateBackForwardSoon(int offset
);
397 virtual int historyBackListCount();
398 virtual int historyForwardListCount();
399 virtual blink::WebSpeechRecognizer
* speechRecognizer();
400 virtual void zoomLimitsChanged(double minimum_level
, double maximum_level
);
401 virtual void zoomLevelChanged();
402 virtual void pageScaleFactorChanged();
403 virtual double zoomLevelToZoomFactor(double zoom_level
) const;
404 virtual double zoomFactorToZoomLevel(double factor
) const;
405 virtual void registerProtocolHandler(const blink::WebString
& scheme
,
406 const blink::WebURL
& url
,
407 const blink::WebString
& title
);
408 virtual void unregisterProtocolHandler(const blink::WebString
& scheme
,
409 const blink::WebURL
& url
);
410 virtual blink::WebPageVisibilityState
visibilityState() const;
411 virtual void draggableRegionsChanged();
413 #if defined(OS_ANDROID)
414 virtual void scheduleContentIntent(const blink::WebURL
& intent
);
415 virtual void cancelScheduledContentIntents();
416 virtual blink::WebContentDetectionResult
detectContentAround(
417 const blink::WebHitTestResult
& touch_hit
);
419 // Only used on Android since all other platforms implement
420 // date and time input fields using MULTIPLE_FIELDS_UI
421 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams
&,
422 blink::WebDateTimeChooserCompletion
*);
423 virtual void didScrollWithKeyboard(const blink::WebSize
& delta
);
426 // blink::WebPageSerializerClient implementation ----------------------------
428 virtual void didSerializeDataForFrame(
429 const blink::WebURL
& frame_url
,
430 const blink::WebCString
& data
,
431 PageSerializationStatus status
) override
;
433 // RenderView implementation -------------------------------------------------
435 bool Send(IPC::Message
* message
) override
;
436 RenderFrameImpl
* GetMainRenderFrame() override
;
437 int GetRoutingID() const override
;
438 gfx::Size
GetSize() const override
;
439 WebPreferences
& GetWebkitPreferences() override
;
440 void SetWebkitPreferences(const WebPreferences
& preferences
) override
;
441 blink::WebView
* GetWebView() override
;
442 bool IsEditableNode(const blink::WebNode
& node
) const override
;
443 bool ShouldDisplayScrollbars(int width
, int height
) const override
;
444 int GetEnabledBindings() const override
;
445 bool GetContentStateImmediately() const override
;
446 blink::WebPageVisibilityState
GetVisibilityState() const override
;
447 void DidStartLoading() override
;
448 void DidStopLoading() override
;
449 void Repaint(const gfx::Size
& size
) override
;
450 void SetEditCommandForNextKeyEvent(const std::string
& name
,
451 const std::string
& value
) override
;
452 void ClearEditCommands() override
;
453 SSLStatus
GetSSLStatusOfFrame(blink::WebFrame
* frame
) const override
;
454 const std::string
& GetAcceptLanguages() const override
;
455 #if defined(OS_ANDROID)
456 void UpdateTopControlsState(TopControlsState constraints
,
457 TopControlsState current
,
458 bool animate
) override
;
460 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_
; }
462 // Please do not add your stuff randomly to the end here. If there is an
463 // appropriate section, add it there. If not, there are some random functions
464 // nearer to the top you can add it to.
467 // RenderWidget overrides:
468 void OnClose() override
;
469 void Close() override
;
470 void OnResize(const ViewMsg_Resize_Params
& params
) override
;
471 void DidInitiatePaint() override
;
472 void DidFlushPaint() override
;
473 gfx::Vector2d
GetScrollOffset() override
;
474 void DidHandleKeyEvent() override
;
475 bool WillHandleMouseEvent(const blink::WebMouseEvent
& event
) override
;
476 bool WillHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
477 void DidHandleMouseEvent(const blink::WebMouseEvent
& event
) override
;
478 void DidHandleTouchEvent(const blink::WebTouchEvent
& event
) override
;
479 bool HasTouchEventHandlersAt(const gfx::Point
& point
) const override
;
480 void OnSetFocus(bool enable
) override
;
481 void OnWasHidden() override
;
482 void OnWasShown(bool needs_repainting
,
483 const ui::LatencyInfo
& latency_info
) override
;
484 GURL
GetURLForGraphicsContext3D() override
;
485 void OnImeSetComposition(
486 const base::string16
& text
,
487 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
489 int selection_end
) override
;
490 void OnImeConfirmComposition(const base::string16
& text
,
491 const gfx::Range
& replacement_range
,
492 bool keep_selection
) override
;
493 void SetDeviceScaleFactor(float device_scale_factor
) override
;
494 bool SetDeviceColorProfile(const std::vector
<char>& color_profile
) override
;
495 void OnOrientationChange() override
;
496 ui::TextInputType
GetTextInputType() override
;
497 void GetSelectionBounds(gfx::Rect
* start
, gfx::Rect
* end
) override
;
498 void FocusChangeComplete() override
;
499 void GetCompositionCharacterBounds(
500 std::vector
<gfx::Rect
>* character_bounds
) override
;
501 void GetCompositionRange(gfx::Range
* range
) override
;
502 bool CanComposeInline() override
;
503 void DidCommitCompositorFrame() override
;
504 void DidCompletePageScaleAnimation() override
;
507 explicit RenderViewImpl(const ViewMsg_New_Params
& params
);
509 void Initialize(const ViewMsg_New_Params
& params
,
510 CompositorDependencies
* compositor_deps
,
511 bool was_created_by_renderer
);
512 void SetScreenMetricsEmulationParameters(float device_scale_factor
,
513 const gfx::Point
& root_layer_offset
,
514 float root_layer_scale
) override
;
516 // Do not delete directly. This class is reference counted.
517 virtual ~RenderViewImpl();
521 friend class PepperDeviceTest
;
522 friend class RenderViewImplTest
;
523 friend class RenderViewTest
;
524 friend class RendererAccessibilityTest
;
526 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
527 // utility functions needed in both classes, while we move frame specific
528 // code away from this class.
529 friend class RenderFrameImpl
;
531 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, DecideNavigationPolicyForWebUI
);
532 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
533 DidFailProvisionalLoadWithErrorForError
);
534 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
535 DidFailProvisionalLoadWithErrorForCancellation
);
536 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ImeComposition
);
537 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, InsertCharacters
);
538 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, JSBlockSentAfterPageLoad
);
539 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, LastCommittedUpdateState
);
540 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnHandleKeyboardEvent
);
541 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnImeTypeChanged
);
542 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavStateChanged
);
543 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnSetTextDirection
);
544 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnUpdateWebPreferences
);
545 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
546 SetEditableSelectionAndComposition
);
547 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, StaleNavigationsIgnored
);
548 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
549 DontIgnoreBackAfterNavEntryLimit
);
550 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, UpdateTargetURLWithInvalidURL
);
551 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
552 GetCompositionCharacterBoundsTest
);
553 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavigationHttpPost
);
554 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
555 DecideNavigationPolicyHandlesAllTopLevel
);
556 #if defined(OS_MACOSX)
557 FRIEND_TEST_ALL_PREFIXES(RenderViewTest
, MacTestCmdUp
);
559 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SetHistoryLengthAndOffset
);
560 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ZoomLimit
);
561 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, NavigateFrame
);
562 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, BasicRenderFrame
);
563 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, TextInputTypeWithPepper
);
564 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
565 MessageOrderInDidChangeSelection
);
566 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SendCandidateWindowEvents
);
567 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, Suppresses
);
568 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, DoesNotSuppress
);
570 typedef std::map
<GURL
, double> HostZoomLevels
;
578 // Old WebFrameClient implementations ----------------------------------------
580 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
581 // WebFrameClient. However, many implementations of WebFrameClient methods
582 // still live here and are called from RenderFrameImpl. These implementations
583 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
585 void didCreateDataSource(blink::WebLocalFrame
* frame
,
586 blink::WebDataSource
* datasource
);
587 void didChangeIcon(blink::WebLocalFrame
*, blink::WebIconURL::Type
);
588 void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
589 void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
591 static bool IsReload(FrameMsg_Navigate_Type::Value navigation_type
);
593 static Referrer
GetReferrerFromRequest(
594 blink::WebFrame
* frame
,
595 const blink::WebURLRequest
& request
);
597 static WindowOpenDisposition
NavigationPolicyToDisposition(
598 blink::WebNavigationPolicy policy
);
600 void UpdateSessionHistory(blink::WebFrame
* frame
);
601 void SendUpdateState(HistoryEntry
* entry
);
603 // Sends a message and runs a nested message loop.
604 bool SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
);
606 // IPC message handlers ------------------------------------------------------
608 // The documentation for these functions should be in
609 // content/common/*_messages.h for the message that the function is handling.
610 void OnExecuteEditCommand(const std::string
& name
, const std::string
& value
);
611 void OnMoveCaret(const gfx::Point
& point
);
612 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
613 void OnSetEditCommandsForNextKeyEvent(const EditCommands
& edit_commands
);
614 void OnAllowBindings(int enabled_bindings_flags
);
615 void OnAllowScriptToClose(bool script_can_close
);
616 void OnCancelDownload(int32 download_id
);
617 void OnClearFocusedElement();
619 void OnShowContextMenu(ui::MenuSourceType source_type
,
620 const gfx::Point
& location
);
621 void OnCopyImageAt(int x
, int y
);
622 void OnSaveImageAt(int x
, int y
);
623 void OnDeterminePageLanguage();
624 void OnDisableScrollbarsForSmallWindows(
625 const gfx::Size
& disable_scrollbars_size_limit
);
626 void OnDragSourceEnded(const gfx::Point
& client_point
,
627 const gfx::Point
& screen_point
,
628 blink::WebDragOperation drag_operation
);
629 void OnDragSourceSystemDragEnded();
630 void OnDragTargetDrop(const gfx::Point
& client_pt
,
631 const gfx::Point
& screen_pt
,
633 void OnDragTargetDragEnter(const DropData
& drop_data
,
634 const gfx::Point
& client_pt
,
635 const gfx::Point
& screen_pt
,
636 blink::WebDragOperationsMask operations_allowed
,
638 void OnDragTargetDragLeave();
639 void OnDragTargetDragOver(const gfx::Point
& client_pt
,
640 const gfx::Point
& screen_pt
,
641 blink::WebDragOperationsMask operations_allowed
,
643 void OnEnablePreferredSizeChangedMode();
644 void OnEnableAutoResize(const gfx::Size
& min_size
, const gfx::Size
& max_size
);
645 void OnDisableAutoResize(const gfx::Size
& new_size
);
646 void OnEnumerateDirectoryResponse(int id
,
647 const std::vector
<base::FilePath
>& paths
);
648 void OnFileChooserResponse(
649 const std::vector
<content::FileChooserFileInfo
>& files
);
650 void OnFind(int request_id
,
651 const base::string16
&,
652 const blink::WebFindOptions
&);
653 void OnGetAllSavableResourceLinksForCurrentPage(const GURL
& page_url
);
654 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
655 const std::vector
<GURL
>& links
,
656 const std::vector
<base::FilePath
>& local_paths
,
657 const base::FilePath
& local_directory_name
);
658 void OnMediaPlayerActionAt(const gfx::Point
& location
,
659 const blink::WebMediaPlayerAction
& action
);
660 void OnPluginActionAt(const gfx::Point
& location
,
661 const blink::WebPluginAction
& action
);
662 void OnMoveOrResizeStarted();
663 void OnPostMessageEvent(const ViewMsg_PostMessage_Params
& params
);
664 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId
& id
);
665 void OnResetPageEncodingToDefault();
666 void OnSetActive(bool active
);
667 void OnSetBackgroundOpaque(bool opaque
);
668 void OnExitFullscreen();
669 void OnSetHistoryOffsetAndLength(int history_offset
, int history_length
);
670 void OnSetInitialFocus(bool reverse
);
671 void OnSetPageEncoding(const std::string
& encoding_name
);
672 void OnSetRendererPrefs(const RendererPreferences
& renderer_prefs
);
673 void OnSetWebUIProperty(const std::string
& name
, const std::string
& value
);
674 void OnSetZoomLevelForLoadingURL(const GURL
& url
, double zoom_level
);
675 void OnSetZoomLevelForView(bool uses_temporary_zoom_level
, double level
);
676 void OnStopFinding(StopFindAction action
);
677 void OnSuppressDialogsUntilSwapOut();
678 void OnThemeChanged();
679 void OnUpdateTargetURLAck();
680 void OnUpdateWebPreferences(const WebPreferences
& prefs
);
681 void OnResetPageScale();
682 void OnZoom(PageZoom zoom
);
683 void OnEnableViewSourceMode();
684 void OnWindowSnapshotCompleted(const int snapshot_id
,
685 const gfx::Size
& size
, const std::vector
<unsigned char>& png
);
686 void OnForceRedraw(int request_id
);
687 void OnSelectWordAroundCaret();
688 #if defined(OS_ANDROID)
689 void OnActivateNearestFindResult(int request_id
, float x
, float y
);
690 void OnFindMatchRects(int current_version
);
691 void OnUndoScrollFocusedEditableNodeIntoRect();
692 void OnUpdateTopControlsState(bool enable_hiding
,
695 void OnExtractSmartClipData(const gfx::Rect
& rect
);
696 #elif defined(OS_MACOSX)
697 void OnGetRenderedText();
698 void OnPluginImeCompositionCompleted(const base::string16
& text
,
700 void OnSetInLiveResize(bool in_live_resize
);
701 void OnSetWindowVisibility(bool visible
);
702 void OnWindowFrameChanged(const gfx::Rect
& window_frame
,
703 const gfx::Rect
& view_frame
);
706 // Adding a new message handler? Please add it in alphabetical order above
707 // and put it in the same position in the .cc file.
709 // Misc private functions ----------------------------------------------------
710 // Check whether the preferred size has changed.
711 void CheckPreferredSize();
713 // Gets the currently focused element, if any.
714 blink::WebElement
GetFocusedElement() const;
716 // Called to get the WebPlugin to handle find requests in the document.
717 // Returns NULL if there is no such WebPlugin.
718 blink::WebPlugin
* GetWebPluginForFind();
720 // If we initiated a navigation, this function will populate |document_state|
721 // with the navigation information saved in OnNavigate().
722 void PopulateDocumentStateFromPending(DocumentState
* document_state
);
724 // Returns a new NavigationState populated with the navigation information
725 // saved in OnNavigate().
726 NavigationState
* CreateNavigationStateFromPending();
728 #if defined(OS_ANDROID)
729 // Launch an Android content intent with the given URL.
730 void LaunchAndroidContentIntent(const GURL
& intent_url
, size_t request_id
);
733 // Sends a reply to the current find operation handling if it was a
734 // synchronous find request.
735 void SendFindReply(int request_id
,
738 const blink::WebRect
& selection_rect
,
739 bool final_status_update
);
741 // Starts nav_state_sync_timer_ if it isn't already running.
742 void StartNavStateSyncTimerIfNecessary();
744 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
745 void UpdateFontRenderingFromRendererPrefs();
747 void UpdateFontRenderingFromRendererPrefs() {}
750 // Update the target url and tell the browser that the target URL has changed.
751 // If |url| is empty, show |fallback_url|.
752 void UpdateTargetURL(const GURL
& url
, const GURL
& fallback_url
);
754 // Tells the browser what the new list of favicons for the webpage is.
755 void SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
);
757 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
759 void DidStopLoadingIcons();
761 // Coordinate conversion -----------------------------------------------------
763 gfx::RectF
ClientRectToPhysicalWindowRect(const gfx::RectF
& rect
) const;
765 // RenderFrameImpl accessible state ------------------------------------------
766 // The following section is the set of methods that RenderFrameImpl needs
767 // to access RenderViewImpl state. The set of state variables are page-level
768 // specific, so they don't belong in RenderFrameImpl and should remain in
770 ObserverList
<RenderViewObserver
>& observers() {
774 // TODO(nasko): Remove this method when we move to frame proxy objects, since
775 // the concept of swapped out will be eliminated.
776 void set_is_swapped_out(bool swapped_out
) {
777 is_swapped_out_
= swapped_out
;
780 NavigationGesture
navigation_gesture() {
781 return navigation_gesture_
;
783 void set_navigation_gesture(NavigationGesture gesture
) {
784 navigation_gesture_
= gesture
;
787 // ---------------------------------------------------------------------------
788 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
789 // it in the same order in the .cc file as it was in the header.
790 // ---------------------------------------------------------------------------
792 // Settings ------------------------------------------------------------------
794 WebPreferences webkit_preferences_
;
795 RendererPreferences renderer_preferences_
;
797 HostZoomLevels host_zoom_levels_
;
799 // Whether content state (such as form state, scroll position and page
800 // contents) should be sent to the browser immediately. This is normally
801 // false, but set to true by some tests.
802 bool send_content_state_immediately_
;
804 // Bitwise-ORed set of extra bindings that have been enabled. See
805 // BindingsPolicy for details.
806 int enabled_bindings_
;
808 // If true, we send IPC messages when |preferred_size_| changes.
809 bool send_preferred_size_changes_
;
811 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
812 // scroll bars on windows smaller than this size. Used for windows that the
813 // browser resizes to the size of the content, such as browser action popups.
814 // If a render view is set to the minimum size of its content, webkit may add
815 // scroll bars. This makes sense for fixed sized windows, but it does not
816 // make sense when the size of the view was chosen to fit the content.
817 // This setting ensures that no scroll bars are drawn. The size limit exists
818 // because if the view grows beyond a size known to the browser, scroll bars
820 gfx::Size disable_scrollbars_size_limit_
;
822 // Loading state -------------------------------------------------------------
824 // The gesture that initiated the current navigation.
825 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
826 NavigationGesture navigation_gesture_
;
829 bool opened_by_user_gesture_
;
831 // Whether this RenderView was created by a frame that was suppressing its
832 // opener. If so, we may want to load pages in a separate process. See
833 // decidePolicyForNavigation for details.
834 bool opener_suppressed_
;
836 // Whether we must stop creating nested message loops for modal dialogs until
837 // OnSwapOut is called. This is necessary because modal dialogs have a
838 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
839 bool suppress_dialogs_until_swap_out_
;
841 // Holds state pertaining to a navigation that we initiated. This is held by
842 // the WebDataSource::ExtraData attribute. We use pending_navigation_state_
843 // as a temporary holder for the state until the WebDataSource corresponding
844 // to the new navigation is created. See DidCreateDataSource.
845 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
846 scoped_ptr
<NavigationParams
> pending_navigation_params_
;
848 // Timer used to delay the updating of nav state (see SyncNavigationState).
849 base::OneShotTimer
<RenderViewImpl
> nav_state_sync_timer_
;
851 // Page IDs ------------------------------------------------------------------
852 // See documentation in RenderView.
855 // The next available page ID to use for this RenderView. These IDs are
856 // specific to a given RenderView and the frames within it.
859 // The offset of the current item in the history list.
860 int history_list_offset_
;
862 // The RenderView's current impression of the history length. This includes
863 // any items that have committed in this process, but because of cross-process
864 // navigations, the history may have some entries that were committed in other
865 // processes. We won't know about them until the next navigation in this
867 int history_list_length_
;
869 // Counter to track how many frames have sent start notifications but not stop
870 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
872 int frames_in_progress_
;
874 // UI state ------------------------------------------------------------------
876 // The state of our target_url transmissions. When we receive a request to
877 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
878 // comes back - if a new request comes in before the ACK, we store the new
879 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
880 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
881 // revert to TARGET_INFLIGHT.
883 // We don't need a queue of URLs to send, as only the latest is useful.
886 TARGET_INFLIGHT
, // We have a request in-flight, waiting for an ACK
887 TARGET_PENDING
// INFLIGHT + we have a URL waiting to be sent
888 } target_url_status_
;
890 // The URL we show the user in the status bar. We use this to determine if we
891 // want to send a new one (we do not need to send duplicates). It will be
892 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
896 // The URL the user's mouse is hovering over.
897 GURL mouse_over_url_
;
899 // The URL that has keyboard focus.
902 // The next target URL we want to send to the browser.
903 GURL pending_target_url_
;
905 // Indicates whether this view overrides url-based zoom settings.
906 bool uses_temporary_zoom_level_
;
908 #if defined(OS_ANDROID)
909 // Cache the old top controls state constraints. Used when updating
910 // current value only without altering the constraints.
911 TopControlsState top_controls_constraints_
;
914 // View ----------------------------------------------------------------------
916 // Cache the preferred size of the page in order to prevent sending the IPC
917 // when layout() recomputes but doesn't actually change sizes.
918 gfx::Size preferred_size_
;
920 // Used to delay determining the preferred size (to avoid intermediate
921 // states for the sizes).
922 base::OneShotTimer
<RenderViewImpl
> check_preferred_size_timer_
;
924 // Bookkeeping to suppress redundant scroll and focus requests for an already
925 // scrolled and focused editable node.
926 bool has_scrolled_focused_editable_node_into_rect_
;
927 gfx::Rect rect_for_scrolled_focused_editable_node_
;
929 // Helper objects ------------------------------------------------------------
931 scoped_ptr
<RenderFrameImpl
> main_render_frame_
;
933 // The next group of objects all implement RenderViewObserver, so are deleted
934 // along with the RenderView automatically. This is why we just store
937 // The speech recognition dispatcher attached to this view, lazily
939 SpeechRecognitionDispatcher
* speech_recognition_dispatcher_
;
941 DevToolsAgent
* devtools_agent_
;
943 // Mouse Lock dispatcher attached to this view.
944 MouseLockDispatcher
* mouse_lock_dispatcher_
;
946 scoped_ptr
<HistoryController
> history_controller_
;
948 #if defined(OS_ANDROID)
949 // Android Specific ---------------------------------------------------------
951 // Expected id of the next content intent launched. Used to prevent scheduled
952 // intents to be launched if aborted.
953 size_t expected_content_intent_id_
;
955 // List of click-based content detectors.
956 typedef std::vector
< linked_ptr
<ContentDetector
> > ContentDetectorList
;
957 ContentDetectorList content_detectors_
;
959 // A date/time picker object for date and time related input elements.
960 scoped_ptr
<RendererDateTimePicker
> date_time_picker_client_
;
963 // Plugins -------------------------------------------------------------------
965 // All the currently active plugin delegates for this RenderView; kept so
966 // that we can enumerate them to send updates about things like window
967 // location or tab focus and visibily. These are non-owning references.
968 std::set
<WebPluginDelegateProxy
*> plugin_delegates_
;
971 // The ID of the focused NPAPI plug-in.
972 int focused_plugin_id_
;
975 #if defined(ENABLE_PLUGINS)
976 PepperPluginInstanceImpl
* plugin_find_handler_
;
978 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
979 PepperPluginSet active_pepper_instances_
;
981 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
982 // is focused and sends the IPCs which use these to the correct frame. Until
983 // then, we must store these on RenderView as that's the one place that knows
984 // about all the RenderFrames for a page.
986 // Whether or not the focus is on a PPAPI plugin
987 PepperPluginInstanceImpl
* focused_pepper_plugin_
;
989 // The plugin instance that received the last mouse event. It is set to NULL
990 // if the last mouse event went to elements other than Pepper plugins.
991 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
992 // the RenderFrameImpl to NULL it out when it destructs.
993 PepperPluginInstanceImpl
* pepper_last_mouse_event_target_
;
996 // Misc ----------------------------------------------------------------------
998 // The current and pending file chooser completion objects. If the queue is
999 // nonempty, the first item represents the currently running file chooser
1000 // callback, and the remaining elements are the other file chooser completion
1001 // still waiting to be run (in order).
1002 struct PendingFileChooser
;
1003 std::deque
< linked_ptr
<PendingFileChooser
> > file_chooser_completions_
;
1005 // The current directory enumeration callback
1006 std::map
<int, blink::WebFileChooserCompletion
*> enumeration_completions_
;
1007 int enumeration_completion_id_
;
1009 // The SessionStorage namespace that we're assigned to has an ID, and that ID
1010 // is passed to us upon creation. WebKit asks for this ID upon first use and
1011 // uses it whenever asking the browser process to allocate new storage areas.
1012 int64 session_storage_namespace_id_
;
1014 // Stores edit commands associated to the next key event.
1015 // Shall be cleared as soon as the next key event is processed.
1016 EditCommands edit_commands_
;
1018 // All the registered observers. We expect this list to be small, so vector
1020 ObserverList
<RenderViewObserver
> observers_
;
1022 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1023 scoped_ptr
<MouseLockDispatcher::LockTarget
> webwidget_mouse_lock_target_
;
1025 // State associated with the GetWindowSnapshot function.
1026 int next_snapshot_id_
;
1027 typedef std::map
<int, WindowSnapshotCallback
> PendingSnapshotMap
;
1028 PendingSnapshotMap pending_snapshots_
;
1030 // This field stores drag/drop related info for the event that is currently
1031 // being handled. If the current event results in starting a drag/drop
1032 // session, this info is sent to the browser along with other drag/drop info.
1033 DragEventSourceInfo possible_drag_event_info_
;
1035 // NOTE: stats_collection_observer_ should be the last members because their
1036 // constructors call the AddObservers method of RenderViewImpl.
1037 scoped_ptr
<StatsCollectionObserver
> stats_collection_observer_
;
1039 typedef std::map
<cc::SharedBitmapId
, cc::SharedBitmap
*> BitmapMap
;
1040 BitmapMap disambiguation_bitmaps_
;
1042 bool page_scale_factor_is_one_
;
1044 // ---------------------------------------------------------------------------
1045 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1046 // sections rather than throwing it randomly at the end. If you're adding a
1047 // bunch of stuff, you should probably create a helper class and put your
1048 // data and methods on that to avoid bloating RenderView more. You can
1049 // use the Observer interface to filter IPC messages and receive frame change
1051 // ---------------------------------------------------------------------------
1053 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl
);
1056 } // namespace content
1058 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_