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/gfx/geometry/rect.h"
61 #include "ui/gfx/geometry/rect_f.h"
62 #include "ui/surface/transport_dib.h"
64 #if defined(OS_ANDROID)
65 #include "content/renderer/android/content_detector.h"
66 #include "content/renderer/android/renderer_date_time_picker.h"
67 #include "third_party/WebKit/public/web/WebContentDetectionResult.h"
70 #if defined(COMPILER_MSVC)
71 // RenderViewImpl is a diamond-shaped hierarchy, with WebWidgetClient at the
72 // root. VS warns when we inherit the WebWidgetClient method implementations
73 // from RenderWidget. It's safe to ignore that warning.
74 #pragma warning(disable: 4250)
78 struct PP_NetAddress_Private
;
79 struct ViewMsg_New_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 // DEPRECATED: RenderViewImpl is being removed as part of the SiteIsolation
149 // project. New code should be added to RenderFrameImpl instead.
151 // For context, please see https://crbug.com/467770 and
152 // http://www.chromium.org/developers/design-documents/site-isolation.
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(CompositorDependencies
* compositor_deps
,
167 const ViewMsg_New_Params
& params
,
168 bool was_created_by_renderer
);
170 // Used by content_layouttest_support to hook into the creation of
172 static void InstallCreateHook(RenderViewImpl
* (*create_render_view_impl
)(
173 CompositorDependencies
* compositor_deps
,
174 const ViewMsg_New_Params
&));
176 // Returns the RenderViewImpl containing the given WebView.
177 static RenderViewImpl
* FromWebView(blink::WebView
* webview
);
179 // Returns the RenderViewImpl for the given routing ID.
180 static RenderViewImpl
* FromRoutingID(int routing_id
);
182 // May return NULL when the view is closing.
183 blink::WebView
* webview() const;
185 const WebPreferences
& webkit_preferences() const {
186 return webkit_preferences_
;
189 const RendererPreferences
& renderer_preferences() const {
190 return renderer_preferences_
;
193 void set_send_content_state_immediately(bool value
) {
194 send_content_state_immediately_
= value
;
197 MouseLockDispatcher
* mouse_lock_dispatcher() {
198 return mouse_lock_dispatcher_
;
201 HistoryController
* history_controller() {
202 return history_controller_
.get();
205 // Functions to add and remove observers for this object.
206 void AddObserver(RenderViewObserver
* observer
);
207 void RemoveObserver(RenderViewObserver
* observer
);
209 // Returns the StatsCollectionObserver associated with this view, or NULL
210 // if one wasn't created;
211 StatsCollectionObserver
* GetStatsCollectionObserver() {
212 return stats_collection_observer_
.get();
215 // Adds the given file chooser request to the file_chooser_completion_ queue
216 // (see that var for more) and requests the chooser be displayed if there are
217 // no other waiting items in the queue.
219 // Returns true if the chooser was successfully scheduled. False means we
220 // didn't schedule anything.
221 bool ScheduleFileChooser(const FileChooserParams
& params
,
222 blink::WebFileChooserCompletion
* completion
);
224 #if defined(OS_ANDROID)
225 void DismissDateTimeDialog();
228 bool is_loading() const { return frames_in_progress_
!= 0; }
230 void FrameDidStartLoading(blink::WebFrame
* frame
);
231 void FrameDidStopLoading(blink::WebFrame
* frame
);
233 // Sets the zoom level and notifies observers. Doesn't call zoomLevelChanged,
234 // as that is only for changes that aren't initiated by the client.
235 void SetZoomLevel(double zoom_level
);
237 // Plugin-related functions --------------------------------------------------
239 #if defined(ENABLE_PLUGINS)
240 // Get/set the plugin which will be used as to handle document find requests.
241 void set_plugin_find_handler(PepperPluginInstanceImpl
* plugin
) {
242 plugin_find_handler_
= plugin
;
244 PepperPluginInstanceImpl
* plugin_find_handler() {
245 return plugin_find_handler_
;
248 PepperPluginInstanceImpl
* focused_pepper_plugin() {
249 return focused_pepper_plugin_
;
251 PepperPluginInstanceImpl
* pepper_last_mouse_event_target() {
252 return pepper_last_mouse_event_target_
;
254 void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl
* plugin
) {
255 pepper_last_mouse_event_target_
= plugin
;
258 #if defined(OS_MACOSX) || defined(OS_WIN)
259 // Informs the render view that the given plugin has gained or lost focus.
260 void PluginFocusChanged(bool focused
, int plugin_id
);
263 #if defined(OS_MACOSX)
264 // Starts plugin IME.
265 void StartPluginIme();
268 // Indicates that the given instance has been created.
269 void PepperInstanceCreated(PepperPluginInstanceImpl
* instance
);
271 // Indicates that the given instance is being destroyed. This is called from
272 // the destructor, so it's important that the instance is not dereferenced
274 void PepperInstanceDeleted(PepperPluginInstanceImpl
* instance
);
276 // Notification that the given plugin is focused or unfocused.
277 void PepperFocusChanged(PepperPluginInstanceImpl
* instance
, bool focused
);
279 void RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
280 void UnregisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
281 #endif // ENABLE_PLUGINS
283 void TransferActiveWheelFlingAnimation(
284 const blink::WebActiveWheelFlingParameters
& params
);
286 // Returns true if the focused element is editable text from the perspective
287 // of IME support (also used for on-screen keyboard). Works correctly inside
288 // supported PPAPI plugins.
289 bool HasIMETextFocus();
291 // Synchronously sends the current navigation state to the browser.
292 void SendUpdateState();
294 // Returns the length of the session history of this RenderView. Note that
295 // this only coincides with the actual length of the session history if this
296 // RenderView is the currently active RenderView of a WebContents.
297 unsigned GetLocalSessionHistoryLengthForTesting() const;
299 // Invokes OnSetFocus and marks the widget as active depending on the value
300 // of |enable|. This is used for layout tests that need to control the focus
301 // synchronously from the renderer.
302 void SetFocusAndActivateForTesting(bool enable
);
304 // Change the device scale factor and force the compositor to resize.
305 void SetDeviceScaleFactorForTesting(float factor
);
307 // Change the device ICC color profile while running a layout test.
308 void SetDeviceColorProfileForTesting(const std::vector
<char>& color_profile
);
309 void ResetDeviceColorProfileForTesting() override
;
311 // Used to force the size of a window when running layout tests.
312 void ForceResizeForTesting(const gfx::Size
& new_size
);
314 void UseSynchronousResizeModeForTesting(bool enable
);
316 // Control autoresize mode.
317 void EnableAutoResizeForTesting(const gfx::Size
& min_size
,
318 const gfx::Size
& max_size
);
319 void DisableAutoResizeForTesting(const gfx::Size
& new_size
);
321 // IPC::Listener implementation ----------------------------------------------
323 bool OnMessageReceived(const IPC::Message
& msg
) override
;
325 // blink::WebWidgetClient implementation ------------------------------------
327 // Most methods are handled by RenderWidget.
328 virtual void didFocus();
329 virtual void didBlur();
330 virtual void show(blink::WebNavigationPolicy policy
);
331 virtual bool requestPointerLock();
332 virtual void requestPointerUnlock();
333 virtual bool isPointerLocked();
334 virtual void didHandleGestureEvent(const blink::WebGestureEvent
& event
,
335 bool event_cancelled
) override
;
336 virtual void onMouseDown(const blink::WebNode
& mouse_down_node
) override
;
338 virtual void initializeLayerTreeView() override
;
340 // blink::WebViewClient implementation --------------------------------------
342 virtual blink::WebView
* createView(blink::WebLocalFrame
* creator
,
343 const blink::WebURLRequest
& request
,
344 const blink::WebWindowFeatures
& features
,
345 const blink::WebString
& frame_name
,
346 blink::WebNavigationPolicy policy
,
347 bool suppress_opener
);
348 virtual blink::WebWidget
* createPopupMenu(blink::WebPopupType popup_type
);
349 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
350 virtual void printPage(blink::WebLocalFrame
* frame
);
351 virtual bool enumerateChosenDirectory(
352 const blink::WebString
& path
,
353 blink::WebFileChooserCompletion
* chooser_completion
);
354 virtual void saveImageFromDataURL(const blink::WebString
& data_url
);
355 virtual void didCancelCompositionOnSelectionChange();
356 virtual bool handleCurrentKeyboardEvent();
357 virtual bool runFileChooser(
358 const blink::WebFileChooserParams
& params
,
359 blink::WebFileChooserCompletion
* chooser_completion
);
360 void SetValidationMessageDirection(base::string16
* main_text
,
361 blink::WebTextDirection main_text_hint
,
362 base::string16
* sub_text
,
363 blink::WebTextDirection sub_text_hint
);
364 virtual void showValidationMessage(const blink::WebRect
& anchor_in_root_view
,
365 const blink::WebString
& main_text
,
366 blink::WebTextDirection main_text_hint
,
367 const blink::WebString
& sub_text
,
368 blink::WebTextDirection hint
) override
;
369 virtual void hideValidationMessage() override
;
370 virtual void moveValidationMessage(
371 const blink::WebRect
& anchor_in_root_view
) override
;
372 virtual void setStatusText(const blink::WebString
& text
);
373 virtual void setMouseOverURL(const blink::WebURL
& url
);
374 virtual void setKeyboardFocusURL(const blink::WebURL
& url
);
375 virtual void startDragging(blink::WebLocalFrame
* frame
,
376 const blink::WebDragData
& data
,
377 blink::WebDragOperationsMask mask
,
378 const blink::WebImage
& image
,
379 const blink::WebPoint
& imageOffset
);
380 virtual bool acceptsLoadDrops();
381 virtual void focusNext();
382 virtual void focusPrevious();
383 virtual void focusedNodeChanged(const blink::WebNode
& fromNode
,
384 const blink::WebNode
& toNode
);
385 virtual void didUpdateLayout();
386 #if defined(OS_ANDROID) || defined(USE_AURA)
387 virtual bool didTapMultipleTargets(
388 const blink::WebSize
& inner_viewport_offset
,
389 const blink::WebRect
& touch_rect
,
390 const blink::WebVector
<blink::WebRect
>& target_rects
);
392 virtual blink::WebString
acceptLanguages();
393 virtual void navigateBackForwardSoon(int offset
);
394 virtual int historyBackListCount();
395 virtual int historyForwardListCount();
396 virtual blink::WebSpeechRecognizer
* speechRecognizer();
397 virtual void zoomLimitsChanged(double minimum_level
, double maximum_level
);
398 virtual void zoomLevelChanged();
399 virtual void pageScaleFactorChanged();
400 virtual double zoomLevelToZoomFactor(double zoom_level
) const;
401 virtual double zoomFactorToZoomLevel(double factor
) const;
402 virtual blink::WebPageVisibilityState
visibilityState() const;
403 virtual void draggableRegionsChanged();
405 #if defined(OS_ANDROID)
406 virtual void scheduleContentIntent(const blink::WebURL
& intent
);
407 virtual void cancelScheduledContentIntents();
408 virtual blink::WebContentDetectionResult
detectContentAround(
409 const blink::WebHitTestResult
& touch_hit
);
411 // Only used on Android since all other platforms implement
412 // date and time input fields using MULTIPLE_FIELDS_UI
413 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams
&,
414 blink::WebDateTimeChooserCompletion
*);
415 virtual void didScrollWithKeyboard(const blink::WebSize
& delta
);
418 // blink::WebPageSerializerClient implementation ----------------------------
420 virtual void didSerializeDataForFrame(
421 const blink::WebURL
& frame_url
,
422 const blink::WebCString
& data
,
423 PageSerializationStatus status
) override
;
425 // RenderView implementation -------------------------------------------------
427 bool Send(IPC::Message
* message
) override
;
428 RenderFrameImpl
* GetMainRenderFrame() override
;
429 int GetRoutingID() const override
;
430 gfx::Size
GetSize() const override
;
431 WebPreferences
& GetWebkitPreferences() override
;
432 void SetWebkitPreferences(const WebPreferences
& preferences
) override
;
433 blink::WebView
* GetWebView() override
;
434 bool IsEditableNode(const blink::WebNode
& node
) const override
;
435 bool ShouldDisplayScrollbars(int width
, int height
) const override
;
436 int GetEnabledBindings() const override
;
437 bool GetContentStateImmediately() const override
;
438 blink::WebPageVisibilityState
GetVisibilityState() const override
;
439 void DidStartLoading() override
;
440 void DidStopLoading() override
;
441 void Repaint(const gfx::Size
& size
) override
;
442 void SetEditCommandForNextKeyEvent(const std::string
& name
,
443 const std::string
& value
) override
;
444 void ClearEditCommands() override
;
445 SSLStatus
GetSSLStatusOfFrame(blink::WebFrame
* frame
) const override
;
446 const std::string
& GetAcceptLanguages() const override
;
447 #if defined(OS_ANDROID)
448 void UpdateTopControlsState(TopControlsState constraints
,
449 TopControlsState current
,
450 bool animate
) override
;
452 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_
; }
454 // Please do not add your stuff randomly to the end here. If there is an
455 // appropriate section, add it there. If not, there are some random functions
456 // nearer to the top you can add it to.
459 // RenderWidget overrides:
460 void Close() override
;
461 void OnResize(const ViewMsg_Resize_Params
& params
) override
;
462 void DidInitiatePaint() override
;
463 void DidFlushPaint() override
;
464 gfx::Vector2d
GetScrollOffset() override
;
465 void DidHandleKeyEvent() override
;
466 bool WillHandleMouseEvent(const blink::WebMouseEvent
& event
) override
;
467 bool WillHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
468 bool HasTouchEventHandlersAt(const gfx::Point
& point
) const override
;
469 void OnSetFocus(bool enable
) override
;
470 void OnWasHidden() override
;
471 void OnWasShown(bool needs_repainting
,
472 const ui::LatencyInfo
& latency_info
) override
;
473 GURL
GetURLForGraphicsContext3D() override
;
474 void OnImeSetComposition(
475 const base::string16
& text
,
476 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
478 int selection_end
) override
;
479 void OnImeConfirmComposition(const base::string16
& text
,
480 const gfx::Range
& replacement_range
,
481 bool keep_selection
) override
;
482 void SetDeviceScaleFactor(float device_scale_factor
) override
;
483 bool SetDeviceColorProfile(const std::vector
<char>& color_profile
) override
;
484 void OnOrientationChange() override
;
485 ui::TextInputType
GetTextInputType() override
;
486 void GetSelectionBounds(gfx::Rect
* start
, gfx::Rect
* end
) override
;
487 void FocusChangeComplete() override
;
488 void GetCompositionCharacterBounds(
489 std::vector
<gfx::Rect
>* character_bounds
) override
;
490 void GetCompositionRange(gfx::Range
* range
) override
;
491 bool CanComposeInline() override
;
492 void DidCommitCompositorFrame() override
;
493 void DidCompletePageScaleAnimation() override
;
494 #if defined(OS_ANDROID)
495 bool DoesRecordFullLayer() const override
;
499 RenderViewImpl(CompositorDependencies
* compositor_deps
,
500 const ViewMsg_New_Params
& params
);
502 void Initialize(const ViewMsg_New_Params
& params
,
503 bool was_created_by_renderer
);
504 void SetScreenMetricsEmulationParameters(
506 const blink::WebDeviceEmulationParams
& params
) override
;
508 // Do not delete directly. This class is reference counted.
509 virtual ~RenderViewImpl();
513 friend class DevToolsAgentTest
;
514 friend class RenderViewImplTest
;
515 friend class RenderViewTest
;
516 friend class RendererAccessibilityTest
;
518 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
519 // utility functions needed in both classes, while we move frame specific
520 // code away from this class.
521 friend class RenderFrameImpl
;
523 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameMessageAfterDetach
);
524 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, DecideNavigationPolicyForWebUI
);
525 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
526 DidFailProvisionalLoadWithErrorForError
);
527 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
528 DidFailProvisionalLoadWithErrorForCancellation
);
529 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ImeComposition
);
530 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, InsertCharacters
);
531 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, JSBlockSentAfterPageLoad
);
532 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, LastCommittedUpdateState
);
533 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnHandleKeyboardEvent
);
534 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnImeTypeChanged
);
535 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavStateChanged
);
536 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnSetTextDirection
);
537 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnUpdateWebPreferences
);
538 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
539 SetEditableSelectionAndComposition
);
540 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, StaleNavigationsIgnored
);
541 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
542 DontIgnoreBackAfterNavEntryLimit
);
543 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, UpdateTargetURLWithInvalidURL
);
544 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
545 GetCompositionCharacterBoundsTest
);
546 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavigationHttpPost
);
547 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ScreenMetricsEmulation
);
548 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
549 DecideNavigationPolicyHandlesAllTopLevel
);
550 #if defined(OS_MACOSX)
551 FRIEND_TEST_ALL_PREFIXES(RenderViewTest
, MacTestCmdUp
);
553 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SetHistoryLengthAndOffset
);
554 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ZoomLimit
);
555 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, NavigateFrame
);
556 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, BasicRenderFrame
);
557 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, TextInputTypeWithPepper
);
558 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
559 MessageOrderInDidChangeSelection
);
560 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SendCandidateWindowEvents
);
561 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameClearedAfterClose
);
562 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, PaintAfterSwapOut
);
563 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, Suppresses
);
564 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, DoesNotSuppress
);
566 typedef std::map
<GURL
, double> HostZoomLevels
;
574 // Old WebFrameClient implementations ----------------------------------------
576 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
577 // WebFrameClient. However, many implementations of WebFrameClient methods
578 // still live here and are called from RenderFrameImpl. These implementations
579 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
581 void didChangeIcon(blink::WebLocalFrame
*, blink::WebIconURL::Type
);
582 void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
583 void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
585 static Referrer
GetReferrerFromRequest(
586 blink::WebFrame
* frame
,
587 const blink::WebURLRequest
& request
);
589 static WindowOpenDisposition
NavigationPolicyToDisposition(
590 blink::WebNavigationPolicy policy
);
592 void ApplyWebPreferencesInternal(const WebPreferences
& prefs
,
593 blink::WebView
* web_view
,
594 CompositorDependencies
* compositor_deps
);
596 // Sends a message and runs a nested message loop.
597 bool SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
);
599 // IPC message handlers ------------------------------------------------------
601 // The documentation for these functions should be in
602 // content/common/*_messages.h for the message that the function is handling.
603 void OnExecuteEditCommand(const std::string
& name
, const std::string
& value
);
604 void OnMoveCaret(const gfx::Point
& point
);
605 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
606 void OnSetEditCommandsForNextKeyEvent(const EditCommands
& edit_commands
);
607 void OnAllowBindings(int enabled_bindings_flags
);
608 void OnAllowScriptToClose(bool script_can_close
);
609 void OnCancelDownload(int32 download_id
);
610 void OnClearFocusedElement();
614 void OnShowContextMenu(ui::MenuSourceType source_type
,
615 const gfx::Point
& location
);
616 void OnCopyImageAt(int x
, int y
);
617 void OnSaveImageAt(int x
, int y
);
618 void OnDeterminePageLanguage();
619 void OnDisableScrollbarsForSmallWindows(
620 const gfx::Size
& disable_scrollbars_size_limit
);
621 void OnDragSourceEnded(const gfx::Point
& client_point
,
622 const gfx::Point
& screen_point
,
623 blink::WebDragOperation drag_operation
);
624 void OnDragSourceSystemDragEnded();
625 void OnDragTargetDrop(const gfx::Point
& client_pt
,
626 const gfx::Point
& screen_pt
,
628 void OnDragTargetDragEnter(const DropData
& drop_data
,
629 const gfx::Point
& client_pt
,
630 const gfx::Point
& screen_pt
,
631 blink::WebDragOperationsMask operations_allowed
,
633 void OnDragTargetDragLeave();
634 void OnDragTargetDragOver(const gfx::Point
& client_pt
,
635 const gfx::Point
& screen_pt
,
636 blink::WebDragOperationsMask operations_allowed
,
638 void OnEnablePreferredSizeChangedMode();
639 void OnEnableAutoResize(const gfx::Size
& min_size
, const gfx::Size
& max_size
);
640 void OnDisableAutoResize(const gfx::Size
& new_size
);
641 void OnEnumerateDirectoryResponse(int id
,
642 const std::vector
<base::FilePath
>& paths
);
643 void OnFileChooserResponse(
644 const std::vector
<content::FileChooserFileInfo
>& files
);
645 void OnFind(int request_id
,
646 const base::string16
&,
647 const blink::WebFindOptions
&);
648 void OnGetAllSavableResourceLinksForCurrentPage(const GURL
& page_url
);
649 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
650 const std::vector
<GURL
>& links
,
651 const std::vector
<base::FilePath
>& local_paths
,
652 const base::FilePath
& local_directory_name
);
653 void OnMediaPlayerActionAt(const gfx::Point
& location
,
654 const blink::WebMediaPlayerAction
& action
);
655 void OnPluginActionAt(const gfx::Point
& location
,
656 const blink::WebPluginAction
& action
);
657 void OnMoveOrResizeStarted();
658 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId
& id
);
659 void OnResetPageEncodingToDefault();
660 void OnSetActive(bool active
);
661 void OnSetBackgroundOpaque(bool opaque
);
662 void OnExitFullscreen();
663 void OnSetHistoryOffsetAndLength(int history_offset
, int history_length
);
664 void OnSetInitialFocus(bool reverse
);
665 void OnSetPageEncoding(const std::string
& encoding_name
);
666 void OnSetRendererPrefs(const RendererPreferences
& renderer_prefs
);
667 void OnSetWebUIProperty(const std::string
& name
, const std::string
& value
);
668 void OnSetZoomLevelForLoadingURL(const GURL
& url
, double zoom_level
);
669 void OnSetZoomLevelForView(bool uses_temporary_zoom_level
, double level
);
670 void OnStopFinding(StopFindAction action
);
671 void OnSuppressDialogsUntilSwapOut();
672 void OnThemeChanged();
673 void OnUpdateTargetURLAck();
674 void OnUpdateWebPreferences(const WebPreferences
& prefs
);
675 void OnResetPageScale();
676 void OnZoom(PageZoom zoom
);
677 void OnEnableViewSourceMode();
678 void OnForceRedraw(int request_id
);
679 void OnSelectWordAroundCaret();
680 #if defined(OS_ANDROID)
681 void OnActivateNearestFindResult(int request_id
, float x
, float y
);
682 void OnFindMatchRects(int current_version
);
683 void OnUndoScrollFocusedEditableNodeIntoRect();
684 void OnUpdateTopControlsState(bool enable_hiding
,
687 void OnExtractSmartClipData(const gfx::Rect
& rect
);
688 #elif defined(OS_MACOSX)
689 void OnGetRenderedText();
690 void OnPluginImeCompositionCompleted(const base::string16
& text
,
692 void OnSetInLiveResize(bool in_live_resize
);
693 void OnSetWindowVisibility(bool visible
);
694 void OnWindowFrameChanged(const gfx::Rect
& window_frame
,
695 const gfx::Rect
& view_frame
);
698 // Adding a new message handler? Please add it in alphabetical order above
699 // and put it in the same position in the .cc file.
701 // Misc private functions ----------------------------------------------------
702 // Check whether the preferred size has changed.
703 void CheckPreferredSize();
705 // Gets the currently focused element, if any.
706 blink::WebElement
GetFocusedElement() const;
708 // Called to get the WebPlugin to handle find requests in the document.
709 // Returns NULL if there is no such WebPlugin.
710 blink::WebPlugin
* GetWebPluginForFind();
712 #if defined(OS_ANDROID)
713 // Launch an Android content intent with the given URL.
714 void LaunchAndroidContentIntent(const GURL
& intent_url
, size_t request_id
);
717 // Sends a reply to the current find operation handling if it was a
718 // synchronous find request.
719 void SendFindReply(int request_id
,
722 const blink::WebRect
& selection_rect
,
723 bool final_status_update
);
725 // Starts nav_state_sync_timer_ if it isn't already running.
726 void StartNavStateSyncTimerIfNecessary();
728 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
729 void UpdateFontRenderingFromRendererPrefs();
731 void UpdateFontRenderingFromRendererPrefs() {}
734 // Update the target url and tell the browser that the target URL has changed.
735 // If |url| is empty, show |fallback_url|.
736 void UpdateTargetURL(const GURL
& url
, const GURL
& fallback_url
);
738 // Tells the browser what the new list of favicons for the webpage is.
739 void SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
);
741 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
743 void DidStopLoadingIcons();
745 // Coordinate conversion -----------------------------------------------------
747 gfx::RectF
ClientRectToPhysicalWindowRect(const gfx::RectF
& rect
) const;
749 // RenderFrameImpl accessible state ------------------------------------------
750 // The following section is the set of methods that RenderFrameImpl needs
751 // to access RenderViewImpl state. The set of state variables are page-level
752 // specific, so they don't belong in RenderFrameImpl and should remain in
754 base::ObserverList
<RenderViewObserver
>& observers() { return observers_
; }
756 // TODO(nasko): Remove this method when we move to frame proxy objects, since
757 // the concept of swapped out will be eliminated.
758 void set_is_swapped_out(bool swapped_out
) {
759 is_swapped_out_
= swapped_out
;
762 NavigationGesture
navigation_gesture() {
763 return navigation_gesture_
;
765 void set_navigation_gesture(NavigationGesture gesture
) {
766 navigation_gesture_
= gesture
;
769 // Platform specific theme preferences if any are updated here.
771 void UpdateThemePrefs();
773 void UpdateThemePrefs() {}
776 // ---------------------------------------------------------------------------
777 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
778 // it in the same order in the .cc file as it was in the header.
779 // ---------------------------------------------------------------------------
781 // Settings ------------------------------------------------------------------
783 WebPreferences webkit_preferences_
;
784 RendererPreferences renderer_preferences_
;
786 HostZoomLevels host_zoom_levels_
;
788 // Whether content state (such as form state, scroll position and page
789 // contents) should be sent to the browser immediately. This is normally
790 // false, but set to true by some tests.
791 bool send_content_state_immediately_
;
793 // Bitwise-ORed set of extra bindings that have been enabled. See
794 // BindingsPolicy for details.
795 int enabled_bindings_
;
797 // If true, we send IPC messages when |preferred_size_| changes.
798 bool send_preferred_size_changes_
;
800 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
801 // scroll bars on windows smaller than this size. Used for windows that the
802 // browser resizes to the size of the content, such as browser action popups.
803 // If a render view is set to the minimum size of its content, webkit may add
804 // scroll bars. This makes sense for fixed sized windows, but it does not
805 // make sense when the size of the view was chosen to fit the content.
806 // This setting ensures that no scroll bars are drawn. The size limit exists
807 // because if the view grows beyond a size known to the browser, scroll bars
809 gfx::Size disable_scrollbars_size_limit_
;
811 // Loading state -------------------------------------------------------------
813 // The gesture that initiated the current navigation.
814 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
815 NavigationGesture navigation_gesture_
;
818 bool opened_by_user_gesture_
;
820 // Whether this RenderView was created by a frame that was suppressing its
821 // opener. If so, we may want to load pages in a separate process. See
822 // decidePolicyForNavigation for details.
823 bool opener_suppressed_
;
825 // Whether we must stop creating nested message loops for modal dialogs until
826 // OnSwapOut is called. This is necessary because modal dialogs have a
827 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
828 bool suppress_dialogs_until_swap_out_
;
830 // Timer used to delay the updating of nav state (see
831 // StartNavStateSyncTimerIfNecessary).
832 base::OneShotTimer
<RenderViewImpl
> nav_state_sync_timer_
;
834 // Page IDs ------------------------------------------------------------------
835 // See documentation in RenderView.
838 // The next available page ID to use for this RenderView. These IDs are
839 // specific to a given RenderView and the frames within it.
842 // The offset of the current item in the history list.
843 int history_list_offset_
;
845 // The RenderView's current impression of the history length. This includes
846 // any items that have committed in this process, but because of cross-process
847 // navigations, the history may have some entries that were committed in other
848 // processes. We won't know about them until the next navigation in this
850 int history_list_length_
;
852 // Counter to track how many frames have sent start notifications but not stop
853 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
855 int frames_in_progress_
;
857 // UI state ------------------------------------------------------------------
859 // The state of our target_url transmissions. When we receive a request to
860 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
861 // comes back - if a new request comes in before the ACK, we store the new
862 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
863 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
864 // revert to TARGET_INFLIGHT.
866 // We don't need a queue of URLs to send, as only the latest is useful.
869 TARGET_INFLIGHT
, // We have a request in-flight, waiting for an ACK
870 TARGET_PENDING
// INFLIGHT + we have a URL waiting to be sent
871 } target_url_status_
;
873 // The URL we show the user in the status bar. We use this to determine if we
874 // want to send a new one (we do not need to send duplicates). It will be
875 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
879 // The URL the user's mouse is hovering over.
880 GURL mouse_over_url_
;
882 // The URL that has keyboard focus.
885 // The next target URL we want to send to the browser.
886 GURL pending_target_url_
;
888 // Indicates whether this view overrides url-based zoom settings.
889 bool uses_temporary_zoom_level_
;
891 #if defined(OS_ANDROID)
892 // Cache the old top controls state constraints. Used when updating
893 // current value only without altering the constraints.
894 TopControlsState top_controls_constraints_
;
897 // View ----------------------------------------------------------------------
899 // Cache the preferred size of the page in order to prevent sending the IPC
900 // when layout() recomputes but doesn't actually change sizes.
901 gfx::Size preferred_size_
;
903 // Used to delay determining the preferred size (to avoid intermediate
904 // states for the sizes).
905 base::OneShotTimer
<RenderViewImpl
> check_preferred_size_timer_
;
907 // Bookkeeping to suppress redundant scroll and focus requests for an already
908 // scrolled and focused editable node.
909 bool has_scrolled_focused_editable_node_into_rect_
;
910 gfx::Rect rect_for_scrolled_focused_editable_node_
;
912 // Helper objects ------------------------------------------------------------
914 RenderFrameImpl
* main_render_frame_
;
916 // The next group of objects all implement RenderViewObserver, so are deleted
917 // along with the RenderView automatically. This is why we just store
920 // The speech recognition dispatcher attached to this view, lazily
922 SpeechRecognitionDispatcher
* speech_recognition_dispatcher_
;
924 // Mouse Lock dispatcher attached to this view.
925 MouseLockDispatcher
* mouse_lock_dispatcher_
;
927 scoped_ptr
<HistoryController
> history_controller_
;
929 #if defined(OS_ANDROID)
930 // Android Specific ---------------------------------------------------------
932 // Expected id of the next content intent launched. Used to prevent scheduled
933 // intents to be launched if aborted.
934 size_t expected_content_intent_id_
;
936 // List of click-based content detectors.
937 typedef std::vector
< linked_ptr
<ContentDetector
> > ContentDetectorList
;
938 ContentDetectorList content_detectors_
;
940 // A date/time picker object for date and time related input elements.
941 scoped_ptr
<RendererDateTimePicker
> date_time_picker_client_
;
944 // Plugins -------------------------------------------------------------------
946 // All the currently active plugin delegates for this RenderView; kept so
947 // that we can enumerate them to send updates about things like window
948 // location or tab focus and visibily. These are non-owning references.
949 std::set
<WebPluginDelegateProxy
*> plugin_delegates_
;
952 // The ID of the focused NPAPI plugin.
953 int focused_plugin_id_
;
956 #if defined(ENABLE_PLUGINS)
957 PepperPluginInstanceImpl
* plugin_find_handler_
;
959 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
960 PepperPluginSet active_pepper_instances_
;
962 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
963 // is focused and sends the IPCs which use these to the correct frame. Until
964 // then, we must store these on RenderView as that's the one place that knows
965 // about all the RenderFrames for a page.
967 // Whether or not the focus is on a PPAPI plugin
968 PepperPluginInstanceImpl
* focused_pepper_plugin_
;
970 // The plugin instance that received the last mouse event. It is set to NULL
971 // if the last mouse event went to elements other than Pepper plugins.
972 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
973 // the RenderFrameImpl to NULL it out when it destructs.
974 PepperPluginInstanceImpl
* pepper_last_mouse_event_target_
;
977 // Misc ----------------------------------------------------------------------
979 // The current and pending file chooser completion objects. If the queue is
980 // nonempty, the first item represents the currently running file chooser
981 // callback, and the remaining elements are the other file chooser completion
982 // still waiting to be run (in order).
983 struct PendingFileChooser
;
984 std::deque
< linked_ptr
<PendingFileChooser
> > file_chooser_completions_
;
986 // The current directory enumeration callback
987 std::map
<int, blink::WebFileChooserCompletion
*> enumeration_completions_
;
988 int enumeration_completion_id_
;
990 // The SessionStorage namespace that we're assigned to has an ID, and that ID
991 // is passed to us upon creation. WebKit asks for this ID upon first use and
992 // uses it whenever asking the browser process to allocate new storage areas.
993 int64 session_storage_namespace_id_
;
995 // Stores edit commands associated to the next key event.
996 // Shall be cleared as soon as the next key event is processed.
997 EditCommands edit_commands_
;
999 // All the registered observers. We expect this list to be small, so vector
1001 base::ObserverList
<RenderViewObserver
> observers_
;
1003 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1004 scoped_ptr
<MouseLockDispatcher::LockTarget
> webwidget_mouse_lock_target_
;
1006 // This field stores drag/drop related info for the event that is currently
1007 // being handled. If the current event results in starting a drag/drop
1008 // session, this info is sent to the browser along with other drag/drop info.
1009 DragEventSourceInfo possible_drag_event_info_
;
1011 // NOTE: stats_collection_observer_ should be the last members because their
1012 // constructors call the AddObservers method of RenderViewImpl.
1013 scoped_ptr
<StatsCollectionObserver
> stats_collection_observer_
;
1015 typedef std::map
<cc::SharedBitmapId
, cc::SharedBitmap
*> BitmapMap
;
1016 BitmapMap disambiguation_bitmaps_
;
1018 bool page_scale_factor_is_one_
;
1020 // ---------------------------------------------------------------------------
1021 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1022 // sections rather than throwing it randomly at the end. If you're adding a
1023 // bunch of stuff, you should probably create a helper class and put your
1024 // data and methods on that to avoid bloating RenderView more. You can
1025 // use the Observer interface to filter IPC messages and receive frame change
1027 // ---------------------------------------------------------------------------
1029 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl
);
1032 } // namespace content
1034 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_