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
;
123 class HistoryController
;
125 class MouseLockDispatcher
;
127 class PepperPluginInstanceImpl
;
128 class RenderViewImplTest
;
129 class RenderViewObserver
;
130 class RenderViewTest
;
131 class RendererDateTimePicker
;
132 class RendererWebColorChooserImpl
;
133 class SpeechRecognitionDispatcher
;
134 class WebPluginDelegateProxy
;
137 struct FileChooserParams
;
138 struct FileChooserFileInfo
;
139 struct RenderViewImplParams
;
141 #if defined(OS_ANDROID)
142 class WebMediaPlayerProxyAndroid
;
146 // RenderView is an object that manages a WebView object, and provides a
147 // communication interface with an embedding application process.
149 class CONTENT_EXPORT RenderViewImpl
150 : public RenderWidget
,
151 NON_EXPORTED_BASE(public blink::WebViewClient
),
152 NON_EXPORTED_BASE(public blink::WebPageSerializerClient
),
154 public base::SupportsWeakPtr
<RenderViewImpl
> {
156 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
157 // responsible for creating this RenderView. Note that if the original opener
158 // has been closed, |window_was_created_with_opener| will be true and
159 // |opener_id| will be MSG_ROUTING_NONE. When |swapped_out| is true, the
160 // |proxy_routing_id| is specified, so a RenderFrameProxy can be created for
161 // this RenderView's main RenderFrame.
162 static RenderViewImpl
* Create(const ViewMsg_New_Params
& params
,
163 CompositorDependencies
* compositor_deps
,
164 bool was_created_by_renderer
);
166 // Used by content_layouttest_support to hook into the creation of
168 static void InstallCreateHook(
169 RenderViewImpl
* (*create_render_view_impl
)(const ViewMsg_New_Params
&));
171 // Returns the RenderViewImpl containing the given WebView.
172 static RenderViewImpl
* FromWebView(blink::WebView
* webview
);
174 // Returns the RenderViewImpl for the given routing ID.
175 static RenderViewImpl
* FromRoutingID(int routing_id
);
177 static size_t GetRenderViewCount();
179 // May return NULL when the view is closing.
180 blink::WebView
* webview() const;
182 const WebPreferences
& webkit_preferences() const {
183 return webkit_preferences_
;
186 const RendererPreferences
& renderer_preferences() const {
187 return renderer_preferences_
;
190 void set_send_content_state_immediately(bool value
) {
191 send_content_state_immediately_
= value
;
194 MouseLockDispatcher
* mouse_lock_dispatcher() {
195 return mouse_lock_dispatcher_
;
198 HistoryController
* history_controller() {
199 return history_controller_
.get();
202 // Functions to add and remove observers for this object.
203 void AddObserver(RenderViewObserver
* observer
);
204 void RemoveObserver(RenderViewObserver
* observer
);
206 // Returns the StatsCollectionObserver associated with this view, or NULL
207 // if one wasn't created;
208 StatsCollectionObserver
* GetStatsCollectionObserver() {
209 return stats_collection_observer_
.get();
212 // Adds the given file chooser request to the file_chooser_completion_ queue
213 // (see that var for more) and requests the chooser be displayed if there are
214 // no other waiting items in the queue.
216 // Returns true if the chooser was successfully scheduled. False means we
217 // didn't schedule anything.
218 bool ScheduleFileChooser(const FileChooserParams
& params
,
219 blink::WebFileChooserCompletion
* completion
);
221 #if defined(OS_ANDROID)
222 void DismissDateTimeDialog();
225 bool is_loading() const { return frames_in_progress_
!= 0; }
227 void FrameDidStartLoading(blink::WebFrame
* frame
);
228 void FrameDidStopLoading(blink::WebFrame
* frame
);
230 // Plugin-related functions --------------------------------------------------
232 #if defined(ENABLE_PLUGINS)
233 // Get/set the plugin which will be used as to handle document find requests.
234 void set_plugin_find_handler(PepperPluginInstanceImpl
* plugin
) {
235 plugin_find_handler_
= plugin
;
237 PepperPluginInstanceImpl
* plugin_find_handler() {
238 return plugin_find_handler_
;
241 PepperPluginInstanceImpl
* focused_pepper_plugin() {
242 return focused_pepper_plugin_
;
244 PepperPluginInstanceImpl
* pepper_last_mouse_event_target() {
245 return pepper_last_mouse_event_target_
;
247 void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl
* plugin
) {
248 pepper_last_mouse_event_target_
= plugin
;
251 #if defined(OS_MACOSX) || defined(OS_WIN)
252 // Informs the render view that the given plugin has gained or lost focus.
253 void PluginFocusChanged(bool focused
, int plugin_id
);
256 #if defined(OS_MACOSX)
257 // Starts plugin IME.
258 void StartPluginIme();
261 // Indicates that the given instance has been created.
262 void PepperInstanceCreated(PepperPluginInstanceImpl
* instance
);
264 // Indicates that the given instance is being destroyed. This is called from
265 // the destructor, so it's important that the instance is not dereferenced
267 void PepperInstanceDeleted(PepperPluginInstanceImpl
* instance
);
269 // Notification that the given plugin is focused or unfocused.
270 void PepperFocusChanged(PepperPluginInstanceImpl
* instance
, bool focused
);
272 void RegisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
273 void UnregisterPluginDelegate(WebPluginDelegateProxy
* delegate
);
274 #endif // ENABLE_PLUGINS
276 void TransferActiveWheelFlingAnimation(
277 const blink::WebActiveWheelFlingParameters
& params
);
279 // Returns true if the focused element is editable text from the perspective
280 // of IME support (also used for on-screen keyboard). Works correctly inside
281 // supported PPAPI plugins.
282 bool HasIMETextFocus();
284 // Dispatches the current navigation state to the browser. Called on a
285 // periodic timer so we don't send too many messages.
286 void SyncNavigationState();
288 // Returns the length of the session history of this RenderView. Note that
289 // this only coincides with the actual length of the session history if this
290 // RenderView is the currently active RenderView of a WebContents.
291 unsigned GetLocalSessionHistoryLengthForTesting() const;
293 // Invokes OnSetFocus and marks the widget as active depending on the value
294 // of |enable|. This is used for layout tests that need to control the focus
295 // synchronously from the renderer.
296 void SetFocusAndActivateForTesting(bool enable
);
298 // Change the device scale factor and force the compositor to resize.
299 void SetDeviceScaleFactorForTesting(float factor
);
301 // Change the device ICC color profile while running a layout test.
302 void SetDeviceColorProfileForTesting(const std::vector
<char>& color_profile
);
303 void ResetDeviceColorProfileForTesting() override
;
305 // Used to force the size of a window when running layout tests.
306 void ForceResizeForTesting(const gfx::Size
& new_size
);
308 void UseSynchronousResizeModeForTesting(bool enable
);
310 // Control autoresize mode.
311 void EnableAutoResizeForTesting(const gfx::Size
& min_size
,
312 const gfx::Size
& max_size
);
313 void DisableAutoResizeForTesting(const gfx::Size
& new_size
);
315 // IPC::Listener implementation ----------------------------------------------
317 bool OnMessageReceived(const IPC::Message
& msg
) override
;
319 // blink::WebWidgetClient implementation ------------------------------------
321 // Most methods are handled by RenderWidget.
322 virtual void didFocus();
323 virtual void didBlur();
324 virtual void show(blink::WebNavigationPolicy policy
);
325 virtual bool requestPointerLock();
326 virtual void requestPointerUnlock();
327 virtual bool isPointerLocked();
328 virtual void didHandleGestureEvent(const blink::WebGestureEvent
& event
,
329 bool event_cancelled
) override
;
330 virtual void initializeLayerTreeView() override
;
332 // blink::WebViewClient implementation --------------------------------------
334 virtual blink::WebView
* createView(blink::WebLocalFrame
* creator
,
335 const blink::WebURLRequest
& request
,
336 const blink::WebWindowFeatures
& features
,
337 const blink::WebString
& frame_name
,
338 blink::WebNavigationPolicy policy
,
339 bool suppress_opener
);
340 virtual blink::WebWidget
* createPopupMenu(blink::WebPopupType popup_type
);
341 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
342 virtual void printPage(blink::WebLocalFrame
* frame
);
343 virtual bool enumerateChosenDirectory(
344 const blink::WebString
& path
,
345 blink::WebFileChooserCompletion
* chooser_completion
);
346 virtual void saveImageFromDataURL(const blink::WebString
& data_url
);
347 virtual void didCancelCompositionOnSelectionChange();
348 virtual bool handleCurrentKeyboardEvent();
349 virtual bool runFileChooser(
350 const blink::WebFileChooserParams
& params
,
351 blink::WebFileChooserCompletion
* chooser_completion
);
352 void SetValidationMessageDirection(base::string16
* main_text
,
353 blink::WebTextDirection main_text_hint
,
354 base::string16
* sub_text
,
355 blink::WebTextDirection sub_text_hint
);
356 virtual void showValidationMessage(const blink::WebRect
& anchor_in_root_view
,
357 const blink::WebString
& main_text
,
358 blink::WebTextDirection main_text_hint
,
359 const blink::WebString
& sub_text
,
360 blink::WebTextDirection hint
) override
;
361 virtual void hideValidationMessage() override
;
362 virtual void moveValidationMessage(
363 const blink::WebRect
& anchor_in_root_view
) override
;
364 virtual void setStatusText(const blink::WebString
& text
);
365 virtual void setMouseOverURL(const blink::WebURL
& url
);
366 virtual void setKeyboardFocusURL(const blink::WebURL
& url
);
367 virtual void startDragging(blink::WebLocalFrame
* frame
,
368 const blink::WebDragData
& data
,
369 blink::WebDragOperationsMask mask
,
370 const blink::WebImage
& image
,
371 const blink::WebPoint
& imageOffset
);
372 virtual bool acceptsLoadDrops();
373 virtual void focusNext();
374 virtual void focusPrevious();
375 virtual void focusedNodeChanged(const blink::WebNode
& fromNode
,
376 const blink::WebNode
& toNode
);
377 virtual void didUpdateLayout();
378 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
379 virtual bool didTapMultipleTargets(
380 const blink::WebSize
& inner_viewport_offset
,
381 const blink::WebRect
& touch_rect
,
382 const blink::WebVector
<blink::WebRect
>& target_rects
);
384 virtual blink::WebString
acceptLanguages();
385 virtual void navigateBackForwardSoon(int offset
);
386 virtual int historyBackListCount();
387 virtual int historyForwardListCount();
388 virtual blink::WebSpeechRecognizer
* speechRecognizer();
389 virtual void zoomLimitsChanged(double minimum_level
, double maximum_level
);
390 virtual void zoomLevelChanged();
391 virtual void pageScaleFactorChanged();
392 virtual double zoomLevelToZoomFactor(double zoom_level
) const;
393 virtual double zoomFactorToZoomLevel(double factor
) const;
394 virtual void registerProtocolHandler(const blink::WebString
& scheme
,
395 const blink::WebURL
& url
,
396 const blink::WebString
& title
);
397 virtual void unregisterProtocolHandler(const blink::WebString
& scheme
,
398 const blink::WebURL
& url
);
399 virtual blink::WebPageVisibilityState
visibilityState() const;
400 virtual void draggableRegionsChanged();
402 #if defined(OS_ANDROID)
403 virtual void scheduleContentIntent(const blink::WebURL
& intent
);
404 virtual void cancelScheduledContentIntents();
405 virtual blink::WebContentDetectionResult
detectContentAround(
406 const blink::WebHitTestResult
& touch_hit
);
408 // Only used on Android since all other platforms implement
409 // date and time input fields using MULTIPLE_FIELDS_UI
410 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams
&,
411 blink::WebDateTimeChooserCompletion
*);
412 virtual void didScrollWithKeyboard(const blink::WebSize
& delta
);
415 // blink::WebPageSerializerClient implementation ----------------------------
417 virtual void didSerializeDataForFrame(
418 const blink::WebURL
& frame_url
,
419 const blink::WebCString
& data
,
420 PageSerializationStatus status
) override
;
422 // RenderView implementation -------------------------------------------------
424 bool Send(IPC::Message
* message
) override
;
425 RenderFrameImpl
* GetMainRenderFrame() override
;
426 int GetRoutingID() const override
;
427 gfx::Size
GetSize() const override
;
428 WebPreferences
& GetWebkitPreferences() override
;
429 void SetWebkitPreferences(const WebPreferences
& preferences
) override
;
430 blink::WebView
* GetWebView() override
;
431 bool IsEditableNode(const blink::WebNode
& node
) const override
;
432 bool ShouldDisplayScrollbars(int width
, int height
) const override
;
433 int GetEnabledBindings() const override
;
434 bool GetContentStateImmediately() const override
;
435 blink::WebPageVisibilityState
GetVisibilityState() const override
;
436 void DidStartLoading() override
;
437 void DidStopLoading() override
;
438 void Repaint(const gfx::Size
& size
) override
;
439 void SetEditCommandForNextKeyEvent(const std::string
& name
,
440 const std::string
& value
) override
;
441 void ClearEditCommands() override
;
442 SSLStatus
GetSSLStatusOfFrame(blink::WebFrame
* frame
) const override
;
443 const std::string
& GetAcceptLanguages() const override
;
444 #if defined(OS_ANDROID)
445 void UpdateTopControlsState(TopControlsState constraints
,
446 TopControlsState current
,
447 bool animate
) override
;
449 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_
; }
451 // Please do not add your stuff randomly to the end here. If there is an
452 // appropriate section, add it there. If not, there are some random functions
453 // nearer to the top you can add it to.
456 // RenderWidget overrides:
457 void OnClose() override
;
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 void DidHandleTouchEvent(const blink::WebTouchEvent
& 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
;
496 explicit RenderViewImpl(const ViewMsg_New_Params
& params
);
498 void Initialize(const ViewMsg_New_Params
& params
,
499 CompositorDependencies
* compositor_deps
,
500 bool was_created_by_renderer
);
501 void SetScreenMetricsEmulationParameters(
503 const blink::WebDeviceEmulationParams
& params
) override
;
505 // Do not delete directly. This class is reference counted.
506 virtual ~RenderViewImpl();
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(SuppressErrorPageTest
, Suppresses
);
559 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, DoesNotSuppress
);
561 typedef std::map
<GURL
, double> HostZoomLevels
;
569 // Old WebFrameClient implementations ----------------------------------------
571 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
572 // WebFrameClient. However, many implementations of WebFrameClient methods
573 // still live here and are called from RenderFrameImpl. These implementations
574 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
576 void didChangeIcon(blink::WebLocalFrame
*, blink::WebIconURL::Type
);
577 void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
578 void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
580 static Referrer
GetReferrerFromRequest(
581 blink::WebFrame
* frame
,
582 const blink::WebURLRequest
& request
);
584 static WindowOpenDisposition
NavigationPolicyToDisposition(
585 blink::WebNavigationPolicy policy
);
587 void UpdateSessionHistory(blink::WebFrame
* frame
);
588 void SendUpdateState(HistoryEntry
* entry
);
590 // Sends a message and runs a nested message loop.
591 bool SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
);
593 // IPC message handlers ------------------------------------------------------
595 // The documentation for these functions should be in
596 // content/common/*_messages.h for the message that the function is handling.
597 void OnExecuteEditCommand(const std::string
& name
, const std::string
& value
);
598 void OnMoveCaret(const gfx::Point
& point
);
599 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
600 void OnSetEditCommandsForNextKeyEvent(const EditCommands
& edit_commands
);
601 void OnAllowBindings(int enabled_bindings_flags
);
602 void OnAllowScriptToClose(bool script_can_close
);
603 void OnCancelDownload(int32 download_id
);
604 void OnClearFocusedElement();
606 void OnShowContextMenu(ui::MenuSourceType source_type
,
607 const gfx::Point
& location
);
608 void OnCopyImageAt(int x
, int y
);
609 void OnSaveImageAt(int x
, int y
);
610 void OnDeterminePageLanguage();
611 void OnDisableScrollbarsForSmallWindows(
612 const gfx::Size
& disable_scrollbars_size_limit
);
613 void OnDragSourceEnded(const gfx::Point
& client_point
,
614 const gfx::Point
& screen_point
,
615 blink::WebDragOperation drag_operation
);
616 void OnDragSourceSystemDragEnded();
617 void OnDragTargetDrop(const gfx::Point
& client_pt
,
618 const gfx::Point
& screen_pt
,
620 void OnDragTargetDragEnter(const DropData
& drop_data
,
621 const gfx::Point
& client_pt
,
622 const gfx::Point
& screen_pt
,
623 blink::WebDragOperationsMask operations_allowed
,
625 void OnDragTargetDragLeave();
626 void OnDragTargetDragOver(const gfx::Point
& client_pt
,
627 const gfx::Point
& screen_pt
,
628 blink::WebDragOperationsMask operations_allowed
,
630 void OnEnablePreferredSizeChangedMode();
631 void OnEnableAutoResize(const gfx::Size
& min_size
, const gfx::Size
& max_size
);
632 void OnDisableAutoResize(const gfx::Size
& new_size
);
633 void OnEnumerateDirectoryResponse(int id
,
634 const std::vector
<base::FilePath
>& paths
);
635 void OnFileChooserResponse(
636 const std::vector
<content::FileChooserFileInfo
>& files
);
637 void OnFind(int request_id
,
638 const base::string16
&,
639 const blink::WebFindOptions
&);
640 void OnGetAllSavableResourceLinksForCurrentPage(const GURL
& page_url
);
641 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
642 const std::vector
<GURL
>& links
,
643 const std::vector
<base::FilePath
>& local_paths
,
644 const base::FilePath
& local_directory_name
);
645 void OnMediaPlayerActionAt(const gfx::Point
& location
,
646 const blink::WebMediaPlayerAction
& action
);
647 void OnPluginActionAt(const gfx::Point
& location
,
648 const blink::WebPluginAction
& action
);
649 void OnMoveOrResizeStarted();
650 void OnPostMessageEvent(const ViewMsg_PostMessage_Params
& params
);
651 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId
& id
);
652 void OnResetPageEncodingToDefault();
653 void OnSetActive(bool active
);
654 void OnSetBackgroundOpaque(bool opaque
);
655 void OnExitFullscreen();
656 void OnSetHistoryOffsetAndLength(int history_offset
, int history_length
);
657 void OnSetInitialFocus(bool reverse
);
658 void OnSetPageEncoding(const std::string
& encoding_name
);
659 void OnSetRendererPrefs(const RendererPreferences
& renderer_prefs
);
660 void OnSetWebUIProperty(const std::string
& name
, const std::string
& value
);
661 void OnSetZoomLevelForLoadingURL(const GURL
& url
, double zoom_level
);
662 void OnSetZoomLevelForView(bool uses_temporary_zoom_level
, double level
);
663 void OnStopFinding(StopFindAction action
);
664 void OnSuppressDialogsUntilSwapOut();
665 void OnThemeChanged();
666 void OnUpdateTargetURLAck();
667 void OnUpdateWebPreferences(const WebPreferences
& prefs
);
668 void OnResetPageScale();
669 void OnZoom(PageZoom zoom
);
670 void OnEnableViewSourceMode();
671 void OnForceRedraw(int request_id
);
672 void OnSelectWordAroundCaret();
673 #if defined(OS_ANDROID)
674 void OnActivateNearestFindResult(int request_id
, float x
, float y
);
675 void OnFindMatchRects(int current_version
);
676 void OnUndoScrollFocusedEditableNodeIntoRect();
677 void OnUpdateTopControlsState(bool enable_hiding
,
680 void OnExtractSmartClipData(const gfx::Rect
& rect
);
681 #elif defined(OS_MACOSX)
682 void OnGetRenderedText();
683 void OnPluginImeCompositionCompleted(const base::string16
& text
,
685 void OnSetInLiveResize(bool in_live_resize
);
686 void OnSetWindowVisibility(bool visible
);
687 void OnWindowFrameChanged(const gfx::Rect
& window_frame
,
688 const gfx::Rect
& view_frame
);
691 // Adding a new message handler? Please add it in alphabetical order above
692 // and put it in the same position in the .cc file.
694 // Misc private functions ----------------------------------------------------
695 // Check whether the preferred size has changed.
696 void CheckPreferredSize();
698 // Gets the currently focused element, if any.
699 blink::WebElement
GetFocusedElement() const;
701 // Called to get the WebPlugin to handle find requests in the document.
702 // Returns NULL if there is no such WebPlugin.
703 blink::WebPlugin
* GetWebPluginForFind();
705 #if defined(OS_ANDROID)
706 // Launch an Android content intent with the given URL.
707 void LaunchAndroidContentIntent(const GURL
& intent_url
, size_t request_id
);
710 // Sends a reply to the current find operation handling if it was a
711 // synchronous find request.
712 void SendFindReply(int request_id
,
715 const blink::WebRect
& selection_rect
,
716 bool final_status_update
);
718 // Starts nav_state_sync_timer_ if it isn't already running.
719 void StartNavStateSyncTimerIfNecessary();
721 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
722 void UpdateFontRenderingFromRendererPrefs();
724 void UpdateFontRenderingFromRendererPrefs() {}
727 // Update the target url and tell the browser that the target URL has changed.
728 // If |url| is empty, show |fallback_url|.
729 void UpdateTargetURL(const GURL
& url
, const GURL
& fallback_url
);
731 // Tells the browser what the new list of favicons for the webpage is.
732 void SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
);
734 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
736 void DidStopLoadingIcons();
738 // Coordinate conversion -----------------------------------------------------
740 gfx::RectF
ClientRectToPhysicalWindowRect(const gfx::RectF
& rect
) const;
742 // RenderFrameImpl accessible state ------------------------------------------
743 // The following section is the set of methods that RenderFrameImpl needs
744 // to access RenderViewImpl state. The set of state variables are page-level
745 // specific, so they don't belong in RenderFrameImpl and should remain in
747 ObserverList
<RenderViewObserver
>& 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 // ---------------------------------------------------------------------------
765 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
766 // it in the same order in the .cc file as it was in the header.
767 // ---------------------------------------------------------------------------
769 // Settings ------------------------------------------------------------------
771 WebPreferences webkit_preferences_
;
772 RendererPreferences renderer_preferences_
;
774 HostZoomLevels host_zoom_levels_
;
776 // Whether content state (such as form state, scroll position and page
777 // contents) should be sent to the browser immediately. This is normally
778 // false, but set to true by some tests.
779 bool send_content_state_immediately_
;
781 // Bitwise-ORed set of extra bindings that have been enabled. See
782 // BindingsPolicy for details.
783 int enabled_bindings_
;
785 // If true, we send IPC messages when |preferred_size_| changes.
786 bool send_preferred_size_changes_
;
788 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
789 // scroll bars on windows smaller than this size. Used for windows that the
790 // browser resizes to the size of the content, such as browser action popups.
791 // If a render view is set to the minimum size of its content, webkit may add
792 // scroll bars. This makes sense for fixed sized windows, but it does not
793 // make sense when the size of the view was chosen to fit the content.
794 // This setting ensures that no scroll bars are drawn. The size limit exists
795 // because if the view grows beyond a size known to the browser, scroll bars
797 gfx::Size disable_scrollbars_size_limit_
;
799 // Loading state -------------------------------------------------------------
801 // The gesture that initiated the current navigation.
802 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
803 NavigationGesture navigation_gesture_
;
806 bool opened_by_user_gesture_
;
808 // Whether this RenderView was created by a frame that was suppressing its
809 // opener. If so, we may want to load pages in a separate process. See
810 // decidePolicyForNavigation for details.
811 bool opener_suppressed_
;
813 // Whether we must stop creating nested message loops for modal dialogs until
814 // OnSwapOut is called. This is necessary because modal dialogs have a
815 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
816 bool suppress_dialogs_until_swap_out_
;
818 // Timer used to delay the updating of nav state (see SyncNavigationState).
819 base::OneShotTimer
<RenderViewImpl
> nav_state_sync_timer_
;
821 // Page IDs ------------------------------------------------------------------
822 // See documentation in RenderView.
825 // The next available page ID to use for this RenderView. These IDs are
826 // specific to a given RenderView and the frames within it.
829 // The offset of the current item in the history list.
830 int history_list_offset_
;
832 // The RenderView's current impression of the history length. This includes
833 // any items that have committed in this process, but because of cross-process
834 // navigations, the history may have some entries that were committed in other
835 // processes. We won't know about them until the next navigation in this
837 int history_list_length_
;
839 // Counter to track how many frames have sent start notifications but not stop
840 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
842 int frames_in_progress_
;
844 // UI state ------------------------------------------------------------------
846 // The state of our target_url transmissions. When we receive a request to
847 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
848 // comes back - if a new request comes in before the ACK, we store the new
849 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
850 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
851 // revert to TARGET_INFLIGHT.
853 // We don't need a queue of URLs to send, as only the latest is useful.
856 TARGET_INFLIGHT
, // We have a request in-flight, waiting for an ACK
857 TARGET_PENDING
// INFLIGHT + we have a URL waiting to be sent
858 } target_url_status_
;
860 // The URL we show the user in the status bar. We use this to determine if we
861 // want to send a new one (we do not need to send duplicates). It will be
862 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
866 // The URL the user's mouse is hovering over.
867 GURL mouse_over_url_
;
869 // The URL that has keyboard focus.
872 // The next target URL we want to send to the browser.
873 GURL pending_target_url_
;
875 // Indicates whether this view overrides url-based zoom settings.
876 bool uses_temporary_zoom_level_
;
878 #if defined(OS_ANDROID)
879 // Cache the old top controls state constraints. Used when updating
880 // current value only without altering the constraints.
881 TopControlsState top_controls_constraints_
;
884 // View ----------------------------------------------------------------------
886 // Cache the preferred size of the page in order to prevent sending the IPC
887 // when layout() recomputes but doesn't actually change sizes.
888 gfx::Size preferred_size_
;
890 // Used to delay determining the preferred size (to avoid intermediate
891 // states for the sizes).
892 base::OneShotTimer
<RenderViewImpl
> check_preferred_size_timer_
;
894 // Bookkeeping to suppress redundant scroll and focus requests for an already
895 // scrolled and focused editable node.
896 bool has_scrolled_focused_editable_node_into_rect_
;
897 gfx::Rect rect_for_scrolled_focused_editable_node_
;
899 // Helper objects ------------------------------------------------------------
901 scoped_ptr
<RenderFrameImpl
> main_render_frame_
;
903 // The next group of objects all implement RenderViewObserver, so are deleted
904 // along with the RenderView automatically. This is why we just store
907 // The speech recognition dispatcher attached to this view, lazily
909 SpeechRecognitionDispatcher
* speech_recognition_dispatcher_
;
911 DevToolsAgent
* devtools_agent_
;
913 // Mouse Lock dispatcher attached to this view.
914 MouseLockDispatcher
* mouse_lock_dispatcher_
;
916 scoped_ptr
<HistoryController
> history_controller_
;
918 #if defined(OS_ANDROID)
919 // Android Specific ---------------------------------------------------------
921 // Expected id of the next content intent launched. Used to prevent scheduled
922 // intents to be launched if aborted.
923 size_t expected_content_intent_id_
;
925 // List of click-based content detectors.
926 typedef std::vector
< linked_ptr
<ContentDetector
> > ContentDetectorList
;
927 ContentDetectorList content_detectors_
;
929 // A date/time picker object for date and time related input elements.
930 scoped_ptr
<RendererDateTimePicker
> date_time_picker_client_
;
933 // Plugins -------------------------------------------------------------------
935 // All the currently active plugin delegates for this RenderView; kept so
936 // that we can enumerate them to send updates about things like window
937 // location or tab focus and visibily. These are non-owning references.
938 std::set
<WebPluginDelegateProxy
*> plugin_delegates_
;
941 // The ID of the focused NPAPI plugin.
942 int focused_plugin_id_
;
945 #if defined(ENABLE_PLUGINS)
946 PepperPluginInstanceImpl
* plugin_find_handler_
;
948 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
949 PepperPluginSet active_pepper_instances_
;
951 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
952 // is focused and sends the IPCs which use these to the correct frame. Until
953 // then, we must store these on RenderView as that's the one place that knows
954 // about all the RenderFrames for a page.
956 // Whether or not the focus is on a PPAPI plugin
957 PepperPluginInstanceImpl
* focused_pepper_plugin_
;
959 // The plugin instance that received the last mouse event. It is set to NULL
960 // if the last mouse event went to elements other than Pepper plugins.
961 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
962 // the RenderFrameImpl to NULL it out when it destructs.
963 PepperPluginInstanceImpl
* pepper_last_mouse_event_target_
;
966 // Misc ----------------------------------------------------------------------
968 // The current and pending file chooser completion objects. If the queue is
969 // nonempty, the first item represents the currently running file chooser
970 // callback, and the remaining elements are the other file chooser completion
971 // still waiting to be run (in order).
972 struct PendingFileChooser
;
973 std::deque
< linked_ptr
<PendingFileChooser
> > file_chooser_completions_
;
975 // The current directory enumeration callback
976 std::map
<int, blink::WebFileChooserCompletion
*> enumeration_completions_
;
977 int enumeration_completion_id_
;
979 // The SessionStorage namespace that we're assigned to has an ID, and that ID
980 // is passed to us upon creation. WebKit asks for this ID upon first use and
981 // uses it whenever asking the browser process to allocate new storage areas.
982 int64 session_storage_namespace_id_
;
984 // Stores edit commands associated to the next key event.
985 // Shall be cleared as soon as the next key event is processed.
986 EditCommands edit_commands_
;
988 // All the registered observers. We expect this list to be small, so vector
990 ObserverList
<RenderViewObserver
> observers_
;
992 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
993 scoped_ptr
<MouseLockDispatcher::LockTarget
> webwidget_mouse_lock_target_
;
995 // This field stores drag/drop related info for the event that is currently
996 // being handled. If the current event results in starting a drag/drop
997 // session, this info is sent to the browser along with other drag/drop info.
998 DragEventSourceInfo possible_drag_event_info_
;
1000 // NOTE: stats_collection_observer_ should be the last members because their
1001 // constructors call the AddObservers method of RenderViewImpl.
1002 scoped_ptr
<StatsCollectionObserver
> stats_collection_observer_
;
1004 typedef std::map
<cc::SharedBitmapId
, cc::SharedBitmap
*> BitmapMap
;
1005 BitmapMap disambiguation_bitmaps_
;
1007 bool page_scale_factor_is_one_
;
1009 // ---------------------------------------------------------------------------
1010 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1011 // sections rather than throwing it randomly at the end. If you're adding a
1012 // bunch of stuff, you should probably create a helper class and put your
1013 // data and methods on that to avoid bloating RenderView more. You can
1014 // use the Observer interface to filter IPC messages and receive frame change
1016 // ---------------------------------------------------------------------------
1018 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl
);
1021 } // namespace content
1023 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_