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