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_Resize_Params
;
80 struct ViewMsg_StopFinding_Params
;
87 class WebApplicationCacheHost
;
88 class WebApplicationCacheHostClient
;
89 class WebDOMMessageEvent
;
91 class WebDateTimeChooserCompletion
;
93 class WebGestureEvent
;
96 class WebPeerConnection00Handler
;
97 class WebPeerConnection00HandlerClient
;
99 class WebPeerConnectionHandler
;
100 class WebPeerConnectionHandlerClient
;
101 class WebSpeechRecognizer
;
102 class WebStorageNamespace
;
105 struct WebActiveWheelFlingParameters
;
106 struct WebDateTimeChooserParams
;
107 struct WebFileChooserParams
;
108 struct WebFindOptions
;
109 struct WebMediaPlayerAction
;
110 struct WebPluginAction
;
112 struct WebWindowFeatures
;
114 #if defined(OS_ANDROID)
115 class WebHitTestResult
;
121 class HistoryController
;
123 class MouseLockDispatcher
;
125 class PepperPluginInstanceImpl
;
126 class RenderViewImplTest
;
127 class RenderViewObserver
;
128 class RenderViewTest
;
129 class RendererDateTimePicker
;
130 class RendererWebColorChooserImpl
;
131 class SpeechRecognitionDispatcher
;
132 class WebPluginDelegateProxy
;
135 struct FileChooserParams
;
136 struct FileChooserFileInfo
;
137 struct RenderViewImplParams
;
139 #if defined(OS_ANDROID)
140 class WebMediaPlayerProxyAndroid
;
144 // RenderView is an object that manages a WebView object, and provides a
145 // communication interface with an embedding application process.
147 // DEPRECATED: RenderViewImpl is being removed as part of the SiteIsolation
148 // project. New code should be added to RenderFrameImpl instead.
150 // For context, please see https://crbug.com/467770 and
151 // http://www.chromium.org/developers/design-documents/site-isolation.
152 class CONTENT_EXPORT RenderViewImpl
153 : public RenderWidget
,
154 NON_EXPORTED_BASE(public blink::WebViewClient
),
155 NON_EXPORTED_BASE(public blink::WebPageSerializerClient
),
157 public base::SupportsWeakPtr
<RenderViewImpl
> {
159 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
160 // responsible for creating this RenderView. Note that if the original opener
161 // has been closed, |window_was_created_with_opener| will be true and
162 // |opener_id| will be MSG_ROUTING_NONE. When |swapped_out| is true, the
163 // |proxy_routing_id| is specified, so a RenderFrameProxy can be created for
164 // this RenderView's main RenderFrame.
165 static RenderViewImpl
* Create(const ViewMsg_New_Params
& params
,
166 CompositorDependencies
* compositor_deps
,
167 bool was_created_by_renderer
);
169 // Used by content_layouttest_support to hook into the creation of
171 static void InstallCreateHook(
172 RenderViewImpl
* (*create_render_view_impl
)(const ViewMsg_New_Params
&));
174 // Returns the RenderViewImpl containing the given WebView.
175 static RenderViewImpl
* FromWebView(blink::WebView
* webview
);
177 // Returns the RenderViewImpl for the given routing ID.
178 static RenderViewImpl
* FromRoutingID(int routing_id
);
180 // May return NULL when the view is closing.
181 blink::WebView
* webview() const;
183 const WebPreferences
& webkit_preferences() const {
184 return webkit_preferences_
;
187 const RendererPreferences
& renderer_preferences() const {
188 return renderer_preferences_
;
191 void set_send_content_state_immediately(bool value
) {
192 send_content_state_immediately_
= value
;
195 MouseLockDispatcher
* mouse_lock_dispatcher() {
196 return mouse_lock_dispatcher_
;
199 HistoryController
* history_controller() {
200 return history_controller_
.get();
203 // Functions to add and remove observers for this object.
204 void AddObserver(RenderViewObserver
* observer
);
205 void RemoveObserver(RenderViewObserver
* observer
);
207 // Returns the StatsCollectionObserver associated with this view, or NULL
208 // if one wasn't created;
209 StatsCollectionObserver
* GetStatsCollectionObserver() {
210 return stats_collection_observer_
.get();
213 // Adds the given file chooser request to the file_chooser_completion_ queue
214 // (see that var for more) and requests the chooser be displayed if there are
215 // no other waiting items in the queue.
217 // Returns true if the chooser was successfully scheduled. False means we
218 // didn't schedule anything.
219 bool ScheduleFileChooser(const FileChooserParams
& params
,
220 blink::WebFileChooserCompletion
* completion
);
222 #if defined(OS_ANDROID)
223 void DismissDateTimeDialog();
226 bool is_loading() const { return frames_in_progress_
!= 0; }
228 void FrameDidStartLoading(blink::WebFrame
* frame
);
229 void FrameDidStopLoading(blink::WebFrame
* frame
);
231 // Plugin-related functions --------------------------------------------------
233 #if defined(ENABLE_PLUGINS)
234 // Get/set the plugin which will be used as to handle document find requests.
235 void set_plugin_find_handler(PepperPluginInstanceImpl
* plugin
) {
236 plugin_find_handler_
= plugin
;
238 PepperPluginInstanceImpl
* plugin_find_handler() {
239 return plugin_find_handler_
;
242 PepperPluginInstanceImpl
* focused_pepper_plugin() {
243 return focused_pepper_plugin_
;
245 PepperPluginInstanceImpl
* pepper_last_mouse_event_target() {
246 return pepper_last_mouse_event_target_
;
248 void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl
* plugin
) {
249 pepper_last_mouse_event_target_
= plugin
;
252 #if defined(OS_MACOSX) || defined(OS_WIN)
253 // Informs the render view that the given plugin has gained or lost focus.
254 void PluginFocusChanged(bool focused
, int plugin_id
);
257 #if defined(OS_MACOSX)
258 // Starts plugin IME.
259 void StartPluginIme();
262 // Indicates that the given instance has been created.
263 void PepperInstanceCreated(PepperPluginInstanceImpl
* instance
);
265 // Indicates that the given instance is being destroyed. This is called from
266 // the destructor, so it's important that the instance is not dereferenced
268 void PepperInstanceDeleted(PepperPluginInstanceImpl
* instance
);
270 // Notification that the given plugin is focused or unfocused.
271 void PepperFocusChanged(PepperPluginInstanceImpl
* instance
, bool focused
);
273 void RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
274 void UnregisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
275 #endif // ENABLE_PLUGINS
277 void TransferActiveWheelFlingAnimation(
278 const blink::WebActiveWheelFlingParameters
& params
);
280 // Returns true if the focused element is editable text from the perspective
281 // of IME support (also used for on-screen keyboard). Works correctly inside
282 // supported PPAPI plugins.
283 bool HasIMETextFocus();
285 // Dispatches the current navigation state to the browser. Called on a
286 // periodic timer so we don't send too many messages.
287 void SyncNavigationState();
289 // Returns the length of the session history of this RenderView. Note that
290 // this only coincides with the actual length of the session history if this
291 // RenderView is the currently active RenderView of a WebContents.
292 unsigned GetLocalSessionHistoryLengthForTesting() const;
294 // Invokes OnSetFocus and marks the widget as active depending on the value
295 // of |enable|. This is used for layout tests that need to control the focus
296 // synchronously from the renderer.
297 void SetFocusAndActivateForTesting(bool enable
);
299 // Change the device scale factor and force the compositor to resize.
300 void SetDeviceScaleFactorForTesting(float factor
);
302 // Change the device ICC color profile while running a layout test.
303 void SetDeviceColorProfileForTesting(const std::vector
<char>& color_profile
);
304 void ResetDeviceColorProfileForTesting() override
;
306 // Used to force the size of a window when running layout tests.
307 void ForceResizeForTesting(const gfx::Size
& new_size
);
309 void UseSynchronousResizeModeForTesting(bool enable
);
311 // Control autoresize mode.
312 void EnableAutoResizeForTesting(const gfx::Size
& min_size
,
313 const gfx::Size
& max_size
);
314 void DisableAutoResizeForTesting(const gfx::Size
& new_size
);
316 // IPC::Listener implementation ----------------------------------------------
318 bool OnMessageReceived(const IPC::Message
& msg
) override
;
320 // blink::WebWidgetClient implementation ------------------------------------
322 // Most methods are handled by RenderWidget.
323 virtual void didFocus();
324 virtual void didBlur();
325 virtual void show(blink::WebNavigationPolicy policy
);
326 virtual bool requestPointerLock();
327 virtual void requestPointerUnlock();
328 virtual bool isPointerLocked();
329 virtual void didHandleGestureEvent(const blink::WebGestureEvent
& event
,
330 bool event_cancelled
) override
;
331 virtual void initializeLayerTreeView() override
;
333 // blink::WebViewClient implementation --------------------------------------
335 virtual blink::WebView
* createView(blink::WebLocalFrame
* creator
,
336 const blink::WebURLRequest
& request
,
337 const blink::WebWindowFeatures
& features
,
338 const blink::WebString
& frame_name
,
339 blink::WebNavigationPolicy policy
,
340 bool suppress_opener
);
341 virtual blink::WebWidget
* createPopupMenu(blink::WebPopupType popup_type
);
342 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
343 virtual void printPage(blink::WebLocalFrame
* frame
);
344 virtual bool enumerateChosenDirectory(
345 const blink::WebString
& path
,
346 blink::WebFileChooserCompletion
* chooser_completion
);
347 virtual void saveImageFromDataURL(const blink::WebString
& data_url
);
348 virtual void didCancelCompositionOnSelectionChange();
349 virtual bool handleCurrentKeyboardEvent();
350 virtual bool runFileChooser(
351 const blink::WebFileChooserParams
& params
,
352 blink::WebFileChooserCompletion
* chooser_completion
);
353 void SetValidationMessageDirection(base::string16
* main_text
,
354 blink::WebTextDirection main_text_hint
,
355 base::string16
* sub_text
,
356 blink::WebTextDirection sub_text_hint
);
357 virtual void showValidationMessage(const blink::WebRect
& anchor_in_root_view
,
358 const blink::WebString
& main_text
,
359 blink::WebTextDirection main_text_hint
,
360 const blink::WebString
& sub_text
,
361 blink::WebTextDirection hint
) override
;
362 virtual void hideValidationMessage() override
;
363 virtual void moveValidationMessage(
364 const blink::WebRect
& anchor_in_root_view
) override
;
365 virtual void setStatusText(const blink::WebString
& text
);
366 virtual void setMouseOverURL(const blink::WebURL
& url
);
367 virtual void setKeyboardFocusURL(const blink::WebURL
& url
);
368 virtual void startDragging(blink::WebLocalFrame
* frame
,
369 const blink::WebDragData
& data
,
370 blink::WebDragOperationsMask mask
,
371 const blink::WebImage
& image
,
372 const blink::WebPoint
& imageOffset
);
373 virtual bool acceptsLoadDrops();
374 virtual void focusNext();
375 virtual void focusPrevious();
376 virtual void focusedNodeChanged(const blink::WebNode
& fromNode
,
377 const blink::WebNode
& toNode
);
378 virtual void didUpdateLayout();
379 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
380 virtual bool didTapMultipleTargets(
381 const blink::WebSize
& inner_viewport_offset
,
382 const blink::WebRect
& touch_rect
,
383 const blink::WebVector
<blink::WebRect
>& target_rects
);
385 virtual blink::WebString
acceptLanguages();
386 virtual void navigateBackForwardSoon(int offset
);
387 virtual int historyBackListCount();
388 virtual int historyForwardListCount();
389 virtual blink::WebSpeechRecognizer
* speechRecognizer();
390 virtual void zoomLimitsChanged(double minimum_level
, double maximum_level
);
391 virtual void zoomLevelChanged();
392 virtual void pageScaleFactorChanged();
393 virtual double zoomLevelToZoomFactor(double zoom_level
) const;
394 virtual double zoomFactorToZoomLevel(double factor
) const;
395 virtual void registerProtocolHandler(const blink::WebString
& scheme
,
396 const blink::WebURL
& url
,
397 const blink::WebString
& title
);
398 virtual void unregisterProtocolHandler(const blink::WebString
& scheme
,
399 const blink::WebURL
& url
);
400 virtual blink::WebPageVisibilityState
visibilityState() const;
401 virtual void draggableRegionsChanged();
403 #if defined(OS_ANDROID)
404 virtual void scheduleContentIntent(const blink::WebURL
& intent
);
405 virtual void cancelScheduledContentIntents();
406 virtual blink::WebContentDetectionResult
detectContentAround(
407 const blink::WebHitTestResult
& touch_hit
);
409 // Only used on Android since all other platforms implement
410 // date and time input fields using MULTIPLE_FIELDS_UI
411 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams
&,
412 blink::WebDateTimeChooserCompletion
*);
413 virtual void didScrollWithKeyboard(const blink::WebSize
& delta
);
416 // blink::WebPageSerializerClient implementation ----------------------------
418 virtual void didSerializeDataForFrame(
419 const blink::WebURL
& frame_url
,
420 const blink::WebCString
& data
,
421 PageSerializationStatus status
) override
;
423 // RenderView implementation -------------------------------------------------
425 bool Send(IPC::Message
* message
) override
;
426 RenderFrameImpl
* GetMainRenderFrame() override
;
427 int GetRoutingID() const override
;
428 gfx::Size
GetSize() const override
;
429 WebPreferences
& GetWebkitPreferences() override
;
430 void SetWebkitPreferences(const WebPreferences
& preferences
) override
;
431 blink::WebView
* GetWebView() override
;
432 bool IsEditableNode(const blink::WebNode
& node
) const override
;
433 bool ShouldDisplayScrollbars(int width
, int height
) const override
;
434 int GetEnabledBindings() const override
;
435 bool GetContentStateImmediately() const override
;
436 blink::WebPageVisibilityState
GetVisibilityState() const override
;
437 void DidStartLoading() override
;
438 void DidStopLoading() override
;
439 void Repaint(const gfx::Size
& size
) override
;
440 void SetEditCommandForNextKeyEvent(const std::string
& name
,
441 const std::string
& value
) override
;
442 void ClearEditCommands() override
;
443 SSLStatus
GetSSLStatusOfFrame(blink::WebFrame
* frame
) const override
;
444 const std::string
& GetAcceptLanguages() const override
;
445 #if defined(OS_ANDROID)
446 void UpdateTopControlsState(TopControlsState constraints
,
447 TopControlsState current
,
448 bool animate
) override
;
450 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_
; }
452 // Please do not add your stuff randomly to the end here. If there is an
453 // appropriate section, add it there. If not, there are some random functions
454 // nearer to the top you can add it to.
457 // RenderWidget overrides:
458 void Close() override
;
459 void OnResize(const ViewMsg_Resize_Params
& params
) override
;
460 void DidInitiatePaint() override
;
461 void DidFlushPaint() override
;
462 gfx::Vector2d
GetScrollOffset() override
;
463 void DidHandleKeyEvent() override
;
464 bool WillHandleMouseEvent(const blink::WebMouseEvent
& event
) override
;
465 bool WillHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
466 void DidHandleMouseEvent(const blink::WebMouseEvent
& 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 DevToolsAgentTest
;
510 friend class PepperDeviceTest
;
511 friend class RenderViewImplTest
;
512 friend class RenderViewTest
;
513 friend class RendererAccessibilityTest
;
515 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
516 // utility functions needed in both classes, while we move frame specific
517 // code away from this class.
518 friend class RenderFrameImpl
;
520 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameMessageAfterDetach
);
521 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, DecideNavigationPolicyForWebUI
);
522 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
523 DidFailProvisionalLoadWithErrorForError
);
524 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
525 DidFailProvisionalLoadWithErrorForCancellation
);
526 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ImeComposition
);
527 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, InsertCharacters
);
528 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, JSBlockSentAfterPageLoad
);
529 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, LastCommittedUpdateState
);
530 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnHandleKeyboardEvent
);
531 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnImeTypeChanged
);
532 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavStateChanged
);
533 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnSetTextDirection
);
534 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnUpdateWebPreferences
);
535 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
536 SetEditableSelectionAndComposition
);
537 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, StaleNavigationsIgnored
);
538 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
539 DontIgnoreBackAfterNavEntryLimit
);
540 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, UpdateTargetURLWithInvalidURL
);
541 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
542 GetCompositionCharacterBoundsTest
);
543 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavigationHttpPost
);
544 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ScreenMetricsEmulation
);
545 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
546 DecideNavigationPolicyHandlesAllTopLevel
);
547 #if defined(OS_MACOSX)
548 FRIEND_TEST_ALL_PREFIXES(RenderViewTest
, MacTestCmdUp
);
550 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SetHistoryLengthAndOffset
);
551 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ZoomLimit
);
552 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, NavigateFrame
);
553 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, BasicRenderFrame
);
554 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, TextInputTypeWithPepper
);
555 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
556 MessageOrderInDidChangeSelection
);
557 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SendCandidateWindowEvents
);
558 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameClearedAfterClose
);
559 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, Suppresses
);
560 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, DoesNotSuppress
);
562 typedef std::map
<GURL
, double> HostZoomLevels
;
570 // Old WebFrameClient implementations ----------------------------------------
572 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
573 // WebFrameClient. However, many implementations of WebFrameClient methods
574 // still live here and are called from RenderFrameImpl. These implementations
575 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
577 void didChangeIcon(blink::WebLocalFrame
*, blink::WebIconURL::Type
);
578 void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
579 void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
581 static Referrer
GetReferrerFromRequest(
582 blink::WebFrame
* frame
,
583 const blink::WebURLRequest
& request
);
585 static WindowOpenDisposition
NavigationPolicyToDisposition(
586 blink::WebNavigationPolicy policy
);
588 void UpdateSessionHistory(blink::WebFrame
* frame
);
589 void SendUpdateState(HistoryEntry
* entry
);
591 // Sends a message and runs a nested message loop.
592 bool SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
);
594 // IPC message handlers ------------------------------------------------------
596 // The documentation for these functions should be in
597 // content/common/*_messages.h for the message that the function is handling.
598 void OnExecuteEditCommand(const std::string
& name
, const std::string
& value
);
599 void OnMoveCaret(const gfx::Point
& point
);
600 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
601 void OnSetEditCommandsForNextKeyEvent(const EditCommands
& edit_commands
);
602 void OnAllowBindings(int enabled_bindings_flags
);
603 void OnAllowScriptToClose(bool script_can_close
);
604 void OnCancelDownload(int32 download_id
);
605 void OnClearFocusedElement();
609 void OnShowContextMenu(ui::MenuSourceType source_type
,
610 const gfx::Point
& location
);
611 void OnCopyImageAt(int x
, int y
);
612 void OnSaveImageAt(int x
, int y
);
613 void OnDeterminePageLanguage();
614 void OnDisableScrollbarsForSmallWindows(
615 const gfx::Size
& disable_scrollbars_size_limit
);
616 void OnDragSourceEnded(const gfx::Point
& client_point
,
617 const gfx::Point
& screen_point
,
618 blink::WebDragOperation drag_operation
);
619 void OnDragSourceSystemDragEnded();
620 void OnDragTargetDrop(const gfx::Point
& client_pt
,
621 const gfx::Point
& screen_pt
,
623 void OnDragTargetDragEnter(const DropData
& drop_data
,
624 const gfx::Point
& client_pt
,
625 const gfx::Point
& screen_pt
,
626 blink::WebDragOperationsMask operations_allowed
,
628 void OnDragTargetDragLeave();
629 void OnDragTargetDragOver(const gfx::Point
& client_pt
,
630 const gfx::Point
& screen_pt
,
631 blink::WebDragOperationsMask operations_allowed
,
633 void OnEnablePreferredSizeChangedMode();
634 void OnEnableAutoResize(const gfx::Size
& min_size
, const gfx::Size
& max_size
);
635 void OnDisableAutoResize(const gfx::Size
& new_size
);
636 void OnEnumerateDirectoryResponse(int id
,
637 const std::vector
<base::FilePath
>& paths
);
638 void OnFileChooserResponse(
639 const std::vector
<content::FileChooserFileInfo
>& files
);
640 void OnFind(int request_id
,
641 const base::string16
&,
642 const blink::WebFindOptions
&);
643 void OnGetAllSavableResourceLinksForCurrentPage(const GURL
& page_url
);
644 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
645 const std::vector
<GURL
>& links
,
646 const std::vector
<base::FilePath
>& local_paths
,
647 const base::FilePath
& local_directory_name
);
648 void OnMediaPlayerActionAt(const gfx::Point
& location
,
649 const blink::WebMediaPlayerAction
& action
);
650 void OnPluginActionAt(const gfx::Point
& location
,
651 const blink::WebPluginAction
& action
);
652 void OnMoveOrResizeStarted();
653 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId
& id
);
654 void OnResetPageEncodingToDefault();
655 void OnSetActive(bool active
);
656 void OnSetBackgroundOpaque(bool opaque
);
657 void OnExitFullscreen();
658 void OnSetHistoryOffsetAndLength(int history_offset
, int history_length
);
659 void OnSetInitialFocus(bool reverse
);
660 void OnSetPageEncoding(const std::string
& encoding_name
);
661 void OnSetRendererPrefs(const RendererPreferences
& renderer_prefs
);
662 void OnSetWebUIProperty(const std::string
& name
, const std::string
& value
);
663 void OnSetZoomLevelForLoadingURL(const GURL
& url
, double zoom_level
);
664 void OnSetZoomLevelForView(bool uses_temporary_zoom_level
, double level
);
665 void OnStopFinding(StopFindAction action
);
666 void OnSuppressDialogsUntilSwapOut();
667 void OnThemeChanged();
668 void OnUpdateTargetURLAck();
669 void OnUpdateWebPreferences(const WebPreferences
& prefs
);
670 void OnResetPageScale();
671 void OnZoom(PageZoom zoom
);
672 void OnEnableViewSourceMode();
673 void OnForceRedraw(int request_id
);
674 void OnSelectWordAroundCaret();
675 #if defined(OS_ANDROID)
676 void OnActivateNearestFindResult(int request_id
, float x
, float y
);
677 void OnFindMatchRects(int current_version
);
678 void OnUndoScrollFocusedEditableNodeIntoRect();
679 void OnUpdateTopControlsState(bool enable_hiding
,
682 void OnExtractSmartClipData(const gfx::Rect
& rect
);
683 #elif defined(OS_MACOSX)
684 void OnGetRenderedText();
685 void OnPluginImeCompositionCompleted(const base::string16
& text
,
687 void OnSetInLiveResize(bool in_live_resize
);
688 void OnSetWindowVisibility(bool visible
);
689 void OnWindowFrameChanged(const gfx::Rect
& window_frame
,
690 const gfx::Rect
& view_frame
);
693 // Adding a new message handler? Please add it in alphabetical order above
694 // and put it in the same position in the .cc file.
696 // Misc private functions ----------------------------------------------------
697 // Check whether the preferred size has changed.
698 void CheckPreferredSize();
700 // Gets the currently focused element, if any.
701 blink::WebElement
GetFocusedElement() const;
703 // Called to get the WebPlugin to handle find requests in the document.
704 // Returns NULL if there is no such WebPlugin.
705 blink::WebPlugin
* GetWebPluginForFind();
707 #if defined(OS_ANDROID)
708 // Launch an Android content intent with the given URL.
709 void LaunchAndroidContentIntent(const GURL
& intent_url
, size_t request_id
);
712 // Sends a reply to the current find operation handling if it was a
713 // synchronous find request.
714 void SendFindReply(int request_id
,
717 const blink::WebRect
& selection_rect
,
718 bool final_status_update
);
720 // Starts nav_state_sync_timer_ if it isn't already running.
721 void StartNavStateSyncTimerIfNecessary();
723 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
724 void UpdateFontRenderingFromRendererPrefs();
726 void UpdateFontRenderingFromRendererPrefs() {}
729 // Update the target url and tell the browser that the target URL has changed.
730 // If |url| is empty, show |fallback_url|.
731 void UpdateTargetURL(const GURL
& url
, const GURL
& fallback_url
);
733 // Tells the browser what the new list of favicons for the webpage is.
734 void SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
);
736 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
738 void DidStopLoadingIcons();
740 // Coordinate conversion -----------------------------------------------------
742 gfx::RectF
ClientRectToPhysicalWindowRect(const gfx::RectF
& rect
) const;
744 // RenderFrameImpl accessible state ------------------------------------------
745 // The following section is the set of methods that RenderFrameImpl needs
746 // to access RenderViewImpl state. The set of state variables are page-level
747 // specific, so they don't belong in RenderFrameImpl and should remain in
749 base::ObserverList
<RenderViewObserver
>& observers() { return observers_
; }
751 // TODO(nasko): Remove this method when we move to frame proxy objects, since
752 // the concept of swapped out will be eliminated.
753 void set_is_swapped_out(bool swapped_out
) {
754 is_swapped_out_
= swapped_out
;
757 NavigationGesture
navigation_gesture() {
758 return navigation_gesture_
;
760 void set_navigation_gesture(NavigationGesture gesture
) {
761 navigation_gesture_
= gesture
;
764 // Platform specific theme preferences if any are updated here.
766 void UpdateThemePrefs();
768 void UpdateThemePrefs() {}
771 // ---------------------------------------------------------------------------
772 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
773 // it in the same order in the .cc file as it was in the header.
774 // ---------------------------------------------------------------------------
776 // Settings ------------------------------------------------------------------
778 WebPreferences webkit_preferences_
;
779 RendererPreferences renderer_preferences_
;
781 HostZoomLevels host_zoom_levels_
;
783 // Whether content state (such as form state, scroll position and page
784 // contents) should be sent to the browser immediately. This is normally
785 // false, but set to true by some tests.
786 bool send_content_state_immediately_
;
788 // Bitwise-ORed set of extra bindings that have been enabled. See
789 // BindingsPolicy for details.
790 int enabled_bindings_
;
792 // If true, we send IPC messages when |preferred_size_| changes.
793 bool send_preferred_size_changes_
;
795 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
796 // scroll bars on windows smaller than this size. Used for windows that the
797 // browser resizes to the size of the content, such as browser action popups.
798 // If a render view is set to the minimum size of its content, webkit may add
799 // scroll bars. This makes sense for fixed sized windows, but it does not
800 // make sense when the size of the view was chosen to fit the content.
801 // This setting ensures that no scroll bars are drawn. The size limit exists
802 // because if the view grows beyond a size known to the browser, scroll bars
804 gfx::Size disable_scrollbars_size_limit_
;
806 // Loading state -------------------------------------------------------------
808 // The gesture that initiated the current navigation.
809 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
810 NavigationGesture navigation_gesture_
;
813 bool opened_by_user_gesture_
;
815 // Whether this RenderView was created by a frame that was suppressing its
816 // opener. If so, we may want to load pages in a separate process. See
817 // decidePolicyForNavigation for details.
818 bool opener_suppressed_
;
820 // Whether we must stop creating nested message loops for modal dialogs until
821 // OnSwapOut is called. This is necessary because modal dialogs have a
822 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
823 bool suppress_dialogs_until_swap_out_
;
825 // Timer used to delay the updating of nav state (see SyncNavigationState).
826 base::OneShotTimer
<RenderViewImpl
> nav_state_sync_timer_
;
828 // Page IDs ------------------------------------------------------------------
829 // See documentation in RenderView.
832 // The next available page ID to use for this RenderView. These IDs are
833 // specific to a given RenderView and the frames within it.
836 // The offset of the current item in the history list.
837 int history_list_offset_
;
839 // The RenderView's current impression of the history length. This includes
840 // any items that have committed in this process, but because of cross-process
841 // navigations, the history may have some entries that were committed in other
842 // processes. We won't know about them until the next navigation in this
844 int history_list_length_
;
846 // Counter to track how many frames have sent start notifications but not stop
847 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
849 int frames_in_progress_
;
851 // UI state ------------------------------------------------------------------
853 // The state of our target_url transmissions. When we receive a request to
854 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
855 // comes back - if a new request comes in before the ACK, we store the new
856 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
857 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
858 // revert to TARGET_INFLIGHT.
860 // We don't need a queue of URLs to send, as only the latest is useful.
863 TARGET_INFLIGHT
, // We have a request in-flight, waiting for an ACK
864 TARGET_PENDING
// INFLIGHT + we have a URL waiting to be sent
865 } target_url_status_
;
867 // The URL we show the user in the status bar. We use this to determine if we
868 // want to send a new one (we do not need to send duplicates). It will be
869 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
873 // The URL the user's mouse is hovering over.
874 GURL mouse_over_url_
;
876 // The URL that has keyboard focus.
879 // The next target URL we want to send to the browser.
880 GURL pending_target_url_
;
882 // Indicates whether this view overrides url-based zoom settings.
883 bool uses_temporary_zoom_level_
;
885 #if defined(OS_ANDROID)
886 // Cache the old top controls state constraints. Used when updating
887 // current value only without altering the constraints.
888 TopControlsState top_controls_constraints_
;
891 // View ----------------------------------------------------------------------
893 // Cache the preferred size of the page in order to prevent sending the IPC
894 // when layout() recomputes but doesn't actually change sizes.
895 gfx::Size preferred_size_
;
897 // Used to delay determining the preferred size (to avoid intermediate
898 // states for the sizes).
899 base::OneShotTimer
<RenderViewImpl
> check_preferred_size_timer_
;
901 // Bookkeeping to suppress redundant scroll and focus requests for an already
902 // scrolled and focused editable node.
903 bool has_scrolled_focused_editable_node_into_rect_
;
904 gfx::Rect rect_for_scrolled_focused_editable_node_
;
906 // Helper objects ------------------------------------------------------------
908 RenderFrameImpl
* main_render_frame_
;
910 // The next group of objects all implement RenderViewObserver, so are deleted
911 // along with the RenderView automatically. This is why we just store
914 // The speech recognition dispatcher attached to this view, lazily
916 SpeechRecognitionDispatcher
* speech_recognition_dispatcher_
;
918 // Mouse Lock dispatcher attached to this view.
919 MouseLockDispatcher
* mouse_lock_dispatcher_
;
921 scoped_ptr
<HistoryController
> history_controller_
;
923 #if defined(OS_ANDROID)
924 // Android Specific ---------------------------------------------------------
926 // Expected id of the next content intent launched. Used to prevent scheduled
927 // intents to be launched if aborted.
928 size_t expected_content_intent_id_
;
930 // List of click-based content detectors.
931 typedef std::vector
< linked_ptr
<ContentDetector
> > ContentDetectorList
;
932 ContentDetectorList content_detectors_
;
934 // A date/time picker object for date and time related input elements.
935 scoped_ptr
<RendererDateTimePicker
> date_time_picker_client_
;
938 // Plugins -------------------------------------------------------------------
940 // All the currently active plugin delegates for this RenderView; kept so
941 // that we can enumerate them to send updates about things like window
942 // location or tab focus and visibily. These are non-owning references.
943 std::set
<WebPluginDelegateProxy
*> plugin_delegates_
;
946 // The ID of the focused NPAPI plugin.
947 int focused_plugin_id_
;
950 #if defined(ENABLE_PLUGINS)
951 PepperPluginInstanceImpl
* plugin_find_handler_
;
953 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
954 PepperPluginSet active_pepper_instances_
;
956 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
957 // is focused and sends the IPCs which use these to the correct frame. Until
958 // then, we must store these on RenderView as that's the one place that knows
959 // about all the RenderFrames for a page.
961 // Whether or not the focus is on a PPAPI plugin
962 PepperPluginInstanceImpl
* focused_pepper_plugin_
;
964 // The plugin instance that received the last mouse event. It is set to NULL
965 // if the last mouse event went to elements other than Pepper plugins.
966 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
967 // the RenderFrameImpl to NULL it out when it destructs.
968 PepperPluginInstanceImpl
* pepper_last_mouse_event_target_
;
971 // Misc ----------------------------------------------------------------------
973 // The current and pending file chooser completion objects. If the queue is
974 // nonempty, the first item represents the currently running file chooser
975 // callback, and the remaining elements are the other file chooser completion
976 // still waiting to be run (in order).
977 struct PendingFileChooser
;
978 std::deque
< linked_ptr
<PendingFileChooser
> > file_chooser_completions_
;
980 // The current directory enumeration callback
981 std::map
<int, blink::WebFileChooserCompletion
*> enumeration_completions_
;
982 int enumeration_completion_id_
;
984 // The SessionStorage namespace that we're assigned to has an ID, and that ID
985 // is passed to us upon creation. WebKit asks for this ID upon first use and
986 // uses it whenever asking the browser process to allocate new storage areas.
987 int64 session_storage_namespace_id_
;
989 // Stores edit commands associated to the next key event.
990 // Shall be cleared as soon as the next key event is processed.
991 EditCommands edit_commands_
;
993 // All the registered observers. We expect this list to be small, so vector
995 base::ObserverList
<RenderViewObserver
> observers_
;
997 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
998 scoped_ptr
<MouseLockDispatcher::LockTarget
> webwidget_mouse_lock_target_
;
1000 // This field stores drag/drop related info for the event that is currently
1001 // being handled. If the current event results in starting a drag/drop
1002 // session, this info is sent to the browser along with other drag/drop info.
1003 DragEventSourceInfo possible_drag_event_info_
;
1005 // NOTE: stats_collection_observer_ should be the last members because their
1006 // constructors call the AddObservers method of RenderViewImpl.
1007 scoped_ptr
<StatsCollectionObserver
> stats_collection_observer_
;
1009 typedef std::map
<cc::SharedBitmapId
, cc::SharedBitmap
*> BitmapMap
;
1010 BitmapMap disambiguation_bitmaps_
;
1012 bool page_scale_factor_is_one_
;
1014 // ---------------------------------------------------------------------------
1015 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1016 // sections rather than throwing it randomly at the end. If you're adding a
1017 // bunch of stuff, you should probably create a helper class and put your
1018 // data and methods on that to avoid bloating RenderView more. You can
1019 // use the Observer interface to filter IPC messages and receive frame change
1021 // ---------------------------------------------------------------------------
1023 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl
);
1026 } // namespace content
1028 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_