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