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)
76 struct PP_NetAddress_Private
;
77 struct ViewMsg_New_Params
;
78 struct ViewMsg_Resize_Params
;
79 struct ViewMsg_StopFinding_Params
;
86 class WebApplicationCacheHost
;
87 class WebApplicationCacheHostClient
;
88 class WebDOMMessageEvent
;
90 class WebDateTimeChooserCompletion
;
92 class WebGestureEvent
;
95 class WebPeerConnection00Handler
;
96 class WebPeerConnection00HandlerClient
;
98 class WebPeerConnectionHandler
;
99 class WebPeerConnectionHandlerClient
;
100 class WebSpeechRecognizer
;
101 class WebStorageNamespace
;
104 struct WebActiveWheelFlingParameters
;
105 struct WebDateTimeChooserParams
;
106 struct WebFileChooserParams
;
107 struct WebFindOptions
;
108 struct WebMediaPlayerAction
;
109 struct WebPluginAction
;
111 struct WebWindowFeatures
;
113 #if defined(OS_ANDROID)
114 class WebHitTestResult
;
120 class HistoryController
;
122 class MouseLockDispatcher
;
124 class PepperPluginInstanceImpl
;
125 class RenderViewImplTest
;
126 class RenderViewObserver
;
127 class RenderViewTest
;
128 class RendererDateTimePicker
;
129 class RendererWebColorChooserImpl
;
130 class SpeechRecognitionDispatcher
;
131 class WebPluginDelegateProxy
;
134 struct FileChooserParams
;
135 struct FileChooserFileInfo
;
136 struct RenderViewImplParams
;
138 #if defined(OS_ANDROID)
139 class WebMediaPlayerProxyAndroid
;
143 // RenderView is an object that manages a WebView object, and provides a
144 // communication interface with an embedding application process.
146 // DEPRECATED: RenderViewImpl is being removed as part of the SiteIsolation
147 // project. New code should be added to RenderFrameImpl instead.
149 // For context, please see https://crbug.com/467770 and
150 // http://www.chromium.org/developers/design-documents/site-isolation.
151 class CONTENT_EXPORT RenderViewImpl
152 : public RenderWidget
,
153 NON_EXPORTED_BASE(public blink::WebViewClient
),
154 NON_EXPORTED_BASE(public blink::WebPageSerializerClient
),
156 public base::SupportsWeakPtr
<RenderViewImpl
> {
158 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
159 // responsible for creating this RenderView. Note that if the original opener
160 // has been closed, |window_was_created_with_opener| will be true and
161 // |opener_id| will be MSG_ROUTING_NONE. When |swapped_out| is true, the
162 // |proxy_routing_id| is specified, so a RenderFrameProxy can be created for
163 // this RenderView's main RenderFrame.
164 static RenderViewImpl
* Create(CompositorDependencies
* compositor_deps
,
165 const ViewMsg_New_Params
& params
,
166 bool was_created_by_renderer
);
168 // Used by content_layouttest_support to hook into the creation of
170 static void InstallCreateHook(RenderViewImpl
* (*create_render_view_impl
)(
171 CompositorDependencies
* compositor_deps
,
172 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 // Synchronously sends the current navigation state to the browser.
286 void SendUpdateState();
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 onMouseDown(const blink::WebNode
& mouse_down_node
) override
;
332 virtual void initializeLayerTreeView() override
;
334 // blink::WebViewClient implementation --------------------------------------
336 virtual blink::WebView
* createView(blink::WebLocalFrame
* creator
,
337 const blink::WebURLRequest
& request
,
338 const blink::WebWindowFeatures
& features
,
339 const blink::WebString
& frame_name
,
340 blink::WebNavigationPolicy policy
,
341 bool suppress_opener
);
342 virtual blink::WebWidget
* createPopupMenu(blink::WebPopupType popup_type
);
343 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
344 virtual void printPage(blink::WebLocalFrame
* frame
);
345 virtual bool enumerateChosenDirectory(
346 const blink::WebString
& path
,
347 blink::WebFileChooserCompletion
* chooser_completion
);
348 virtual void saveImageFromDataURL(const blink::WebString
& data_url
);
349 virtual void didCancelCompositionOnSelectionChange();
350 virtual bool handleCurrentKeyboardEvent();
351 virtual bool runFileChooser(
352 const blink::WebFileChooserParams
& params
,
353 blink::WebFileChooserCompletion
* chooser_completion
);
354 void SetValidationMessageDirection(base::string16
* main_text
,
355 blink::WebTextDirection main_text_hint
,
356 base::string16
* sub_text
,
357 blink::WebTextDirection sub_text_hint
);
358 virtual void showValidationMessage(const blink::WebRect
& anchor_in_root_view
,
359 const blink::WebString
& main_text
,
360 blink::WebTextDirection main_text_hint
,
361 const blink::WebString
& sub_text
,
362 blink::WebTextDirection hint
) override
;
363 virtual void hideValidationMessage() override
;
364 virtual void moveValidationMessage(
365 const blink::WebRect
& anchor_in_root_view
) override
;
366 virtual void setStatusText(const blink::WebString
& text
);
367 virtual void setMouseOverURL(const blink::WebURL
& url
);
368 virtual void setKeyboardFocusURL(const blink::WebURL
& url
);
369 virtual void startDragging(blink::WebLocalFrame
* frame
,
370 const blink::WebDragData
& data
,
371 blink::WebDragOperationsMask mask
,
372 const blink::WebImage
& image
,
373 const blink::WebPoint
& imageOffset
);
374 virtual bool acceptsLoadDrops();
375 virtual void focusNext();
376 virtual void focusPrevious();
377 virtual void focusedNodeChanged(const blink::WebNode
& fromNode
,
378 const blink::WebNode
& toNode
);
379 virtual void didUpdateLayout();
380 #if defined(OS_ANDROID) || defined(USE_AURA)
381 virtual bool didTapMultipleTargets(
382 const blink::WebSize
& inner_viewport_offset
,
383 const blink::WebRect
& touch_rect
,
384 const blink::WebVector
<blink::WebRect
>& target_rects
);
386 virtual blink::WebString
acceptLanguages();
387 virtual void navigateBackForwardSoon(int offset
);
388 virtual int historyBackListCount();
389 virtual int historyForwardListCount();
390 virtual blink::WebSpeechRecognizer
* speechRecognizer();
391 virtual void zoomLimitsChanged(double minimum_level
, double maximum_level
);
392 virtual void zoomLevelChanged();
393 virtual void pageScaleFactorChanged();
394 virtual double zoomLevelToZoomFactor(double zoom_level
) const;
395 virtual double zoomFactorToZoomLevel(double factor
) const;
396 virtual blink::WebPageVisibilityState
visibilityState() const;
397 virtual void draggableRegionsChanged();
399 #if defined(OS_ANDROID)
400 virtual void scheduleContentIntent(const blink::WebURL
& intent
);
401 virtual void cancelScheduledContentIntents();
402 virtual blink::WebContentDetectionResult
detectContentAround(
403 const blink::WebHitTestResult
& touch_hit
);
405 // Only used on Android since all other platforms implement
406 // date and time input fields using MULTIPLE_FIELDS_UI
407 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams
&,
408 blink::WebDateTimeChooserCompletion
*);
409 virtual void didScrollWithKeyboard(const blink::WebSize
& delta
);
412 // blink::WebPageSerializerClient implementation ----------------------------
414 virtual void didSerializeDataForFrame(
415 const blink::WebURL
& frame_url
,
416 const blink::WebCString
& data
,
417 PageSerializationStatus status
) override
;
419 // RenderView implementation -------------------------------------------------
421 bool Send(IPC::Message
* message
) override
;
422 RenderFrameImpl
* GetMainRenderFrame() override
;
423 int GetRoutingID() const override
;
424 gfx::Size
GetSize() const override
;
425 WebPreferences
& GetWebkitPreferences() override
;
426 void SetWebkitPreferences(const WebPreferences
& preferences
) override
;
427 blink::WebView
* GetWebView() override
;
428 bool IsEditableNode(const blink::WebNode
& node
) const override
;
429 bool ShouldDisplayScrollbars(int width
, int height
) const override
;
430 int GetEnabledBindings() const override
;
431 bool GetContentStateImmediately() const override
;
432 blink::WebPageVisibilityState
GetVisibilityState() const override
;
433 void DidStartLoading() override
;
434 void DidStopLoading() override
;
435 void Repaint(const gfx::Size
& size
) override
;
436 void SetEditCommandForNextKeyEvent(const std::string
& name
,
437 const std::string
& value
) override
;
438 void ClearEditCommands() override
;
439 SSLStatus
GetSSLStatusOfFrame(blink::WebFrame
* frame
) const override
;
440 const std::string
& GetAcceptLanguages() const override
;
441 #if defined(OS_ANDROID)
442 void UpdateTopControlsState(TopControlsState constraints
,
443 TopControlsState current
,
444 bool animate
) override
;
446 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_
; }
448 // Please do not add your stuff randomly to the end here. If there is an
449 // appropriate section, add it there. If not, there are some random functions
450 // nearer to the top you can add it to.
453 // RenderWidget overrides:
454 void Close() override
;
455 void OnResize(const ViewMsg_Resize_Params
& params
) override
;
456 void DidInitiatePaint() override
;
457 void DidFlushPaint() override
;
458 gfx::Vector2d
GetScrollOffset() override
;
459 void DidHandleKeyEvent() override
;
460 bool WillHandleMouseEvent(const blink::WebMouseEvent
& event
) override
;
461 bool WillHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
462 bool HasTouchEventHandlersAt(const gfx::Point
& point
) const override
;
463 void OnSetFocus(bool enable
) override
;
464 void OnWasHidden() override
;
465 void OnWasShown(bool needs_repainting
,
466 const ui::LatencyInfo
& latency_info
) override
;
467 GURL
GetURLForGraphicsContext3D() override
;
468 void OnImeSetComposition(
469 const base::string16
& text
,
470 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
472 int selection_end
) override
;
473 void OnImeConfirmComposition(const base::string16
& text
,
474 const gfx::Range
& replacement_range
,
475 bool keep_selection
) override
;
476 void SetDeviceScaleFactor(float device_scale_factor
) override
;
477 bool SetDeviceColorProfile(const std::vector
<char>& color_profile
) override
;
478 void OnOrientationChange() override
;
479 ui::TextInputType
GetTextInputType() override
;
480 void GetSelectionBounds(gfx::Rect
* start
, gfx::Rect
* end
) override
;
481 void FocusChangeComplete() override
;
482 void GetCompositionCharacterBounds(
483 std::vector
<gfx::Rect
>* character_bounds
) override
;
484 void GetCompositionRange(gfx::Range
* range
) override
;
485 bool CanComposeInline() override
;
486 void DidCommitCompositorFrame() override
;
487 void DidCompletePageScaleAnimation() override
;
490 RenderViewImpl(CompositorDependencies
* compositor_deps
,
491 const ViewMsg_New_Params
& params
);
493 void Initialize(const ViewMsg_New_Params
& params
,
494 bool was_created_by_renderer
);
495 void SetScreenMetricsEmulationParameters(
497 const blink::WebDeviceEmulationParams
& params
) override
;
499 // Do not delete directly. This class is reference counted.
500 virtual ~RenderViewImpl();
504 friend class DevToolsAgentTest
;
505 friend class RenderViewImplTest
;
506 friend class RenderViewTest
;
507 friend class RendererAccessibilityTest
;
509 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
510 // utility functions needed in both classes, while we move frame specific
511 // code away from this class.
512 friend class RenderFrameImpl
;
514 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameMessageAfterDetach
);
515 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, DecideNavigationPolicyForWebUI
);
516 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
517 DidFailProvisionalLoadWithErrorForError
);
518 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
519 DidFailProvisionalLoadWithErrorForCancellation
);
520 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ImeComposition
);
521 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, InsertCharacters
);
522 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, JSBlockSentAfterPageLoad
);
523 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, LastCommittedUpdateState
);
524 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnHandleKeyboardEvent
);
525 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnImeTypeChanged
);
526 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavStateChanged
);
527 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnSetTextDirection
);
528 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnUpdateWebPreferences
);
529 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
530 SetEditableSelectionAndComposition
);
531 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, StaleNavigationsIgnored
);
532 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
533 DontIgnoreBackAfterNavEntryLimit
);
534 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, UpdateTargetURLWithInvalidURL
);
535 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
536 GetCompositionCharacterBoundsTest
);
537 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OnNavigationHttpPost
);
538 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ScreenMetricsEmulation
);
539 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
540 DecideNavigationPolicyHandlesAllTopLevel
);
541 #if defined(OS_MACOSX)
542 FRIEND_TEST_ALL_PREFIXES(RenderViewTest
, MacTestCmdUp
);
544 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SetHistoryLengthAndOffset
);
545 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ZoomLimit
);
546 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, NavigateFrame
);
547 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, BasicRenderFrame
);
548 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, TextInputTypeWithPepper
);
549 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
550 MessageOrderInDidChangeSelection
);
551 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SendCandidateWindowEvents
);
552 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, RenderFrameClearedAfterClose
);
553 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, Suppresses
);
554 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest
, DoesNotSuppress
);
556 typedef std::map
<GURL
, double> HostZoomLevels
;
564 // Old WebFrameClient implementations ----------------------------------------
566 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
567 // WebFrameClient. However, many implementations of WebFrameClient methods
568 // still live here and are called from RenderFrameImpl. These implementations
569 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
571 void didChangeIcon(blink::WebLocalFrame
*, blink::WebIconURL::Type
);
572 void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
573 void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
575 static Referrer
GetReferrerFromRequest(
576 blink::WebFrame
* frame
,
577 const blink::WebURLRequest
& request
);
579 static WindowOpenDisposition
NavigationPolicyToDisposition(
580 blink::WebNavigationPolicy policy
);
582 void ApplyWebPreferencesInternal(const WebPreferences
& prefs
,
583 blink::WebView
* web_view
,
584 CompositorDependencies
* compositor_deps
);
586 // Sends a message and runs a nested message loop.
587 bool SendAndRunNestedMessageLoop(IPC::SyncMessage
* message
);
589 // IPC message handlers ------------------------------------------------------
591 // The documentation for these functions should be in
592 // content/common/*_messages.h for the message that the function is handling.
593 void OnExecuteEditCommand(const std::string
& name
, const std::string
& value
);
594 void OnMoveCaret(const gfx::Point
& point
);
595 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect
& rect
);
596 void OnSetEditCommandsForNextKeyEvent(const EditCommands
& edit_commands
);
597 void OnAllowBindings(int enabled_bindings_flags
);
598 void OnAllowScriptToClose(bool script_can_close
);
599 void OnCancelDownload(int32 download_id
);
600 void OnClearFocusedElement();
604 void OnShowContextMenu(ui::MenuSourceType source_type
,
605 const gfx::Point
& location
);
606 void OnCopyImageAt(int x
, int y
);
607 void OnSaveImageAt(int x
, int y
);
608 void OnDeterminePageLanguage();
609 void OnDisableScrollbarsForSmallWindows(
610 const gfx::Size
& disable_scrollbars_size_limit
);
611 void OnDragSourceEnded(const gfx::Point
& client_point
,
612 const gfx::Point
& screen_point
,
613 blink::WebDragOperation drag_operation
);
614 void OnDragSourceSystemDragEnded();
615 void OnDragTargetDrop(const gfx::Point
& client_pt
,
616 const gfx::Point
& screen_pt
,
618 void OnDragTargetDragEnter(const DropData
& drop_data
,
619 const gfx::Point
& client_pt
,
620 const gfx::Point
& screen_pt
,
621 blink::WebDragOperationsMask operations_allowed
,
623 void OnDragTargetDragLeave();
624 void OnDragTargetDragOver(const gfx::Point
& client_pt
,
625 const gfx::Point
& screen_pt
,
626 blink::WebDragOperationsMask operations_allowed
,
628 void OnEnablePreferredSizeChangedMode();
629 void OnEnableAutoResize(const gfx::Size
& min_size
, const gfx::Size
& max_size
);
630 void OnDisableAutoResize(const gfx::Size
& new_size
);
631 void OnEnumerateDirectoryResponse(int id
,
632 const std::vector
<base::FilePath
>& paths
);
633 void OnFileChooserResponse(
634 const std::vector
<content::FileChooserFileInfo
>& files
);
635 void OnFind(int request_id
,
636 const base::string16
&,
637 const blink::WebFindOptions
&);
638 void OnGetAllSavableResourceLinksForCurrentPage(const GURL
& page_url
);
639 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
640 const std::vector
<GURL
>& links
,
641 const std::vector
<base::FilePath
>& local_paths
,
642 const base::FilePath
& local_directory_name
);
643 void OnMediaPlayerActionAt(const gfx::Point
& location
,
644 const blink::WebMediaPlayerAction
& action
);
645 void OnPluginActionAt(const gfx::Point
& location
,
646 const blink::WebPluginAction
& action
);
647 void OnMoveOrResizeStarted();
648 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId
& id
);
649 void OnResetPageEncodingToDefault();
650 void OnSetActive(bool active
);
651 void OnSetBackgroundOpaque(bool opaque
);
652 void OnExitFullscreen();
653 void OnSetHistoryOffsetAndLength(int history_offset
, int history_length
);
654 void OnSetInitialFocus(bool reverse
);
655 void OnSetPageEncoding(const std::string
& encoding_name
);
656 void OnSetRendererPrefs(const RendererPreferences
& renderer_prefs
);
657 void OnSetWebUIProperty(const std::string
& name
, const std::string
& value
);
658 void OnSetZoomLevelForLoadingURL(const GURL
& url
, double zoom_level
);
659 void OnSetZoomLevelForView(bool uses_temporary_zoom_level
, double level
);
660 void OnStopFinding(StopFindAction action
);
661 void OnSuppressDialogsUntilSwapOut();
662 void OnThemeChanged();
663 void OnUpdateTargetURLAck();
664 void OnUpdateWebPreferences(const WebPreferences
& prefs
);
665 void OnResetPageScale();
666 void OnZoom(PageZoom zoom
);
667 void OnEnableViewSourceMode();
668 void OnForceRedraw(int request_id
);
669 void OnSelectWordAroundCaret();
670 #if defined(OS_ANDROID)
671 void OnActivateNearestFindResult(int request_id
, float x
, float y
);
672 void OnFindMatchRects(int current_version
);
673 void OnUndoScrollFocusedEditableNodeIntoRect();
674 void OnUpdateTopControlsState(bool enable_hiding
,
677 void OnExtractSmartClipData(const gfx::Rect
& rect
);
678 #elif defined(OS_MACOSX)
679 void OnGetRenderedText();
680 void OnPluginImeCompositionCompleted(const base::string16
& text
,
682 void OnSetInLiveResize(bool in_live_resize
);
683 void OnSetWindowVisibility(bool visible
);
684 void OnWindowFrameChanged(const gfx::Rect
& window_frame
,
685 const gfx::Rect
& view_frame
);
688 // Adding a new message handler? Please add it in alphabetical order above
689 // and put it in the same position in the .cc file.
691 // Misc private functions ----------------------------------------------------
692 // Check whether the preferred size has changed.
693 void CheckPreferredSize();
695 // Gets the currently focused element, if any.
696 blink::WebElement
GetFocusedElement() const;
698 // Called to get the WebPlugin to handle find requests in the document.
699 // Returns NULL if there is no such WebPlugin.
700 blink::WebPlugin
* GetWebPluginForFind();
702 #if defined(OS_ANDROID)
703 // Launch an Android content intent with the given URL.
704 void LaunchAndroidContentIntent(const GURL
& intent_url
, size_t request_id
);
707 // Sends a reply to the current find operation handling if it was a
708 // synchronous find request.
709 void SendFindReply(int request_id
,
712 const blink::WebRect
& selection_rect
,
713 bool final_status_update
);
715 // Starts nav_state_sync_timer_ if it isn't already running.
716 void StartNavStateSyncTimerIfNecessary();
718 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
719 void UpdateFontRenderingFromRendererPrefs();
721 void UpdateFontRenderingFromRendererPrefs() {}
724 // Update the target url and tell the browser that the target URL has changed.
725 // If |url| is empty, show |fallback_url|.
726 void UpdateTargetURL(const GURL
& url
, const GURL
& fallback_url
);
728 // Tells the browser what the new list of favicons for the webpage is.
729 void SendUpdateFaviconURL(const std::vector
<FaviconURL
>& urls
);
731 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
733 void DidStopLoadingIcons();
735 // Coordinate conversion -----------------------------------------------------
737 gfx::RectF
ClientRectToPhysicalWindowRect(const gfx::RectF
& rect
) const;
739 // RenderFrameImpl accessible state ------------------------------------------
740 // The following section is the set of methods that RenderFrameImpl needs
741 // to access RenderViewImpl state. The set of state variables are page-level
742 // specific, so they don't belong in RenderFrameImpl and should remain in
744 base::ObserverList
<RenderViewObserver
>& observers() { return observers_
; }
746 // TODO(nasko): Remove this method when we move to frame proxy objects, since
747 // the concept of swapped out will be eliminated.
748 void set_is_swapped_out(bool swapped_out
) {
749 is_swapped_out_
= swapped_out
;
752 NavigationGesture
navigation_gesture() {
753 return navigation_gesture_
;
755 void set_navigation_gesture(NavigationGesture gesture
) {
756 navigation_gesture_
= gesture
;
759 // Platform specific theme preferences if any are updated here.
761 void UpdateThemePrefs();
763 void UpdateThemePrefs() {}
766 // ---------------------------------------------------------------------------
767 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
768 // it in the same order in the .cc file as it was in the header.
769 // ---------------------------------------------------------------------------
771 // Settings ------------------------------------------------------------------
773 WebPreferences webkit_preferences_
;
774 RendererPreferences renderer_preferences_
;
776 HostZoomLevels host_zoom_levels_
;
778 // Whether content state (such as form state, scroll position and page
779 // contents) should be sent to the browser immediately. This is normally
780 // false, but set to true by some tests.
781 bool send_content_state_immediately_
;
783 // Bitwise-ORed set of extra bindings that have been enabled. See
784 // BindingsPolicy for details.
785 int enabled_bindings_
;
787 // If true, we send IPC messages when |preferred_size_| changes.
788 bool send_preferred_size_changes_
;
790 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
791 // scroll bars on windows smaller than this size. Used for windows that the
792 // browser resizes to the size of the content, such as browser action popups.
793 // If a render view is set to the minimum size of its content, webkit may add
794 // scroll bars. This makes sense for fixed sized windows, but it does not
795 // make sense when the size of the view was chosen to fit the content.
796 // This setting ensures that no scroll bars are drawn. The size limit exists
797 // because if the view grows beyond a size known to the browser, scroll bars
799 gfx::Size disable_scrollbars_size_limit_
;
801 // Loading state -------------------------------------------------------------
803 // The gesture that initiated the current navigation.
804 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
805 NavigationGesture navigation_gesture_
;
808 bool opened_by_user_gesture_
;
810 // Whether this RenderView was created by a frame that was suppressing its
811 // opener. If so, we may want to load pages in a separate process. See
812 // decidePolicyForNavigation for details.
813 bool opener_suppressed_
;
815 // Whether we must stop creating nested message loops for modal dialogs until
816 // OnSwapOut is called. This is necessary because modal dialogs have a
817 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
818 bool suppress_dialogs_until_swap_out_
;
820 // Timer used to delay the updating of nav state (see
821 // StartNavStateSyncTimerIfNecessary).
822 base::OneShotTimer
<RenderViewImpl
> nav_state_sync_timer_
;
824 // Page IDs ------------------------------------------------------------------
825 // See documentation in RenderView.
828 // The next available page ID to use for this RenderView. These IDs are
829 // specific to a given RenderView and the frames within it.
832 // The offset of the current item in the history list.
833 int history_list_offset_
;
835 // The RenderView's current impression of the history length. This includes
836 // any items that have committed in this process, but because of cross-process
837 // navigations, the history may have some entries that were committed in other
838 // processes. We won't know about them until the next navigation in this
840 int history_list_length_
;
842 // Counter to track how many frames have sent start notifications but not stop
843 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
845 int frames_in_progress_
;
847 // UI state ------------------------------------------------------------------
849 // The state of our target_url transmissions. When we receive a request to
850 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
851 // comes back - if a new request comes in before the ACK, we store the new
852 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
853 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
854 // revert to TARGET_INFLIGHT.
856 // We don't need a queue of URLs to send, as only the latest is useful.
859 TARGET_INFLIGHT
, // We have a request in-flight, waiting for an ACK
860 TARGET_PENDING
// INFLIGHT + we have a URL waiting to be sent
861 } target_url_status_
;
863 // The URL we show the user in the status bar. We use this to determine if we
864 // want to send a new one (we do not need to send duplicates). It will be
865 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
869 // The URL the user's mouse is hovering over.
870 GURL mouse_over_url_
;
872 // The URL that has keyboard focus.
875 // The next target URL we want to send to the browser.
876 GURL pending_target_url_
;
878 // Indicates whether this view overrides url-based zoom settings.
879 bool uses_temporary_zoom_level_
;
881 #if defined(OS_ANDROID)
882 // Cache the old top controls state constraints. Used when updating
883 // current value only without altering the constraints.
884 TopControlsState top_controls_constraints_
;
887 // View ----------------------------------------------------------------------
889 // Cache the preferred size of the page in order to prevent sending the IPC
890 // when layout() recomputes but doesn't actually change sizes.
891 gfx::Size preferred_size_
;
893 // Used to delay determining the preferred size (to avoid intermediate
894 // states for the sizes).
895 base::OneShotTimer
<RenderViewImpl
> check_preferred_size_timer_
;
897 // Bookkeeping to suppress redundant scroll and focus requests for an already
898 // scrolled and focused editable node.
899 bool has_scrolled_focused_editable_node_into_rect_
;
900 gfx::Rect rect_for_scrolled_focused_editable_node_
;
902 // Helper objects ------------------------------------------------------------
904 RenderFrameImpl
* main_render_frame_
;
906 // The next group of objects all implement RenderViewObserver, so are deleted
907 // along with the RenderView automatically. This is why we just store
910 // The speech recognition dispatcher attached to this view, lazily
912 SpeechRecognitionDispatcher
* speech_recognition_dispatcher_
;
914 // Mouse Lock dispatcher attached to this view.
915 MouseLockDispatcher
* mouse_lock_dispatcher_
;
917 scoped_ptr
<HistoryController
> history_controller_
;
919 #if defined(OS_ANDROID)
920 // Android Specific ---------------------------------------------------------
922 // Expected id of the next content intent launched. Used to prevent scheduled
923 // intents to be launched if aborted.
924 size_t expected_content_intent_id_
;
926 // List of click-based content detectors.
927 typedef std::vector
< linked_ptr
<ContentDetector
> > ContentDetectorList
;
928 ContentDetectorList content_detectors_
;
930 // A date/time picker object for date and time related input elements.
931 scoped_ptr
<RendererDateTimePicker
> date_time_picker_client_
;
934 // Plugins -------------------------------------------------------------------
936 // All the currently active plugin delegates for this RenderView; kept so
937 // that we can enumerate them to send updates about things like window
938 // location or tab focus and visibily. These are non-owning references.
939 std::set
<WebPluginDelegateProxy
*> plugin_delegates_
;
942 // The ID of the focused NPAPI plugin.
943 int focused_plugin_id_
;
946 #if defined(ENABLE_PLUGINS)
947 PepperPluginInstanceImpl
* plugin_find_handler_
;
949 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
950 PepperPluginSet active_pepper_instances_
;
952 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
953 // is focused and sends the IPCs which use these to the correct frame. Until
954 // then, we must store these on RenderView as that's the one place that knows
955 // about all the RenderFrames for a page.
957 // Whether or not the focus is on a PPAPI plugin
958 PepperPluginInstanceImpl
* focused_pepper_plugin_
;
960 // The plugin instance that received the last mouse event. It is set to NULL
961 // if the last mouse event went to elements other than Pepper plugins.
962 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
963 // the RenderFrameImpl to NULL it out when it destructs.
964 PepperPluginInstanceImpl
* pepper_last_mouse_event_target_
;
967 // Misc ----------------------------------------------------------------------
969 // The current and pending file chooser completion objects. If the queue is
970 // nonempty, the first item represents the currently running file chooser
971 // callback, and the remaining elements are the other file chooser completion
972 // still waiting to be run (in order).
973 struct PendingFileChooser
;
974 std::deque
< linked_ptr
<PendingFileChooser
> > file_chooser_completions_
;
976 // The current directory enumeration callback
977 std::map
<int, blink::WebFileChooserCompletion
*> enumeration_completions_
;
978 int enumeration_completion_id_
;
980 // The SessionStorage namespace that we're assigned to has an ID, and that ID
981 // is passed to us upon creation. WebKit asks for this ID upon first use and
982 // uses it whenever asking the browser process to allocate new storage areas.
983 int64 session_storage_namespace_id_
;
985 // Stores edit commands associated to the next key event.
986 // Shall be cleared as soon as the next key event is processed.
987 EditCommands edit_commands_
;
989 // All the registered observers. We expect this list to be small, so vector
991 base::ObserverList
<RenderViewObserver
> observers_
;
993 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
994 scoped_ptr
<MouseLockDispatcher::LockTarget
> webwidget_mouse_lock_target_
;
996 // This field stores drag/drop related info for the event that is currently
997 // being handled. If the current event results in starting a drag/drop
998 // session, this info is sent to the browser along with other drag/drop info.
999 DragEventSourceInfo possible_drag_event_info_
;
1001 // NOTE: stats_collection_observer_ should be the last members because their
1002 // constructors call the AddObservers method of RenderViewImpl.
1003 scoped_ptr
<StatsCollectionObserver
> stats_collection_observer_
;
1005 typedef std::map
<cc::SharedBitmapId
, cc::SharedBitmap
*> BitmapMap
;
1006 BitmapMap disambiguation_bitmaps_
;
1008 bool page_scale_factor_is_one_
;
1010 // ---------------------------------------------------------------------------
1011 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1012 // sections rather than throwing it randomly at the end. If you're adding a
1013 // bunch of stuff, you should probably create a helper class and put your
1014 // data and methods on that to avoid bloating RenderView more. You can
1015 // use the Observer interface to filter IPC messages and receive frame change
1017 // ---------------------------------------------------------------------------
1019 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl
);
1022 } // namespace content
1024 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_