Add non-native file support to the ViewMsg_RunFileChooserResponse message.
[chromium-blink-merge.git] / content / renderer / render_view_impl.h
blobec6d730553f59d3f830abeb6a4b961c412153954
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/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/WebPageVisibilityState.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_PostMessage_Params;
81 struct ViewMsg_StopFinding_Params;
83 namespace base {
84 class CommandLine;
87 namespace blink {
88 class WebApplicationCacheHost;
89 class WebApplicationCacheHostClient;
90 class WebDOMMessageEvent;
91 class WebDataSource;
92 class WebDateTimeChooserCompletion;
93 class WebDragData;
94 class WebGestureEvent;
95 class WebIconURL;
96 class WebImage;
97 class WebPeerConnection00Handler;
98 class WebPeerConnection00HandlerClient;
99 class WebMouseEvent;
100 class WebPeerConnectionHandler;
101 class WebPeerConnectionHandlerClient;
102 class WebSocketStreamHandle;
103 class WebSpeechRecognizer;
104 class WebStorageNamespace;
105 class WebTouchEvent;
106 class WebURLRequest;
107 struct WebActiveWheelFlingParameters;
108 struct WebDateTimeChooserParams;
109 struct WebFileChooserParams;
110 struct WebFindOptions;
111 struct WebMediaPlayerAction;
112 struct WebPluginAction;
113 struct WebPoint;
114 struct WebWindowFeatures;
116 #if defined(OS_ANDROID)
117 class WebHitTestResult;
118 #endif
119 } // namespace blink
121 namespace content {
123 class BrowserPluginManager;
124 class DevToolsAgent;
125 class DocumentState;
126 class HistoryController;
127 class HistoryEntry;
128 class ImageResourceFetcher;
129 class MouseLockDispatcher;
130 class NavigationState;
131 class PageState;
132 class PepperPluginInstanceImpl;
133 class RenderViewImplTest;
134 class RenderViewObserver;
135 class RenderViewTest;
136 class RendererDateTimePicker;
137 class RendererWebColorChooserImpl;
138 class SpeechRecognitionDispatcher;
139 class WebPluginDelegateProxy;
140 struct DropData;
141 struct FaviconURL;
142 struct FileChooserParams;
143 struct FileChooserFileInfo;
144 struct RenderViewImplParams;
146 #if defined(OS_ANDROID)
147 class WebMediaPlayerProxyAndroid;
148 #endif
151 // RenderView is an object that manages a WebView object, and provides a
152 // communication interface with an embedding application process.
154 class CONTENT_EXPORT RenderViewImpl
155 : public RenderWidget,
156 NON_EXPORTED_BASE(public blink::WebViewClient),
157 NON_EXPORTED_BASE(public blink::WebPageSerializerClient),
158 public RenderView,
159 public base::SupportsWeakPtr<RenderViewImpl> {
160 public:
161 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
162 // responsible for creating this RenderView. Note that if the original opener
163 // has been closed, |window_was_created_with_opener| will be true and
164 // |opener_id| will be MSG_ROUTING_NONE. When |swapped_out| is true, the
165 // |proxy_routing_id| is specified, so a RenderFrameProxy can be created for
166 // this RenderView's main RenderFrame.
167 static RenderViewImpl* Create(int32 opener_id,
168 bool window_was_created_with_opener,
169 const RendererPreferences& renderer_prefs,
170 const WebPreferences& webkit_prefs,
171 int32 routing_id,
172 int32 main_frame_routing_id,
173 int32 surface_id,
174 int64 session_storage_namespace_id,
175 const base::string16& frame_name,
176 bool is_renderer_created,
177 bool swapped_out,
178 int32 proxy_routing_id,
179 bool hidden,
180 bool never_visible,
181 int32 next_page_id,
182 const blink::WebScreenInfo& screen_info);
184 // Used by content_layouttest_support to hook into the creation of
185 // RenderViewImpls.
186 static void InstallCreateHook(
187 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*));
189 // Returns the RenderViewImpl containing the given WebView.
190 static RenderViewImpl* FromWebView(blink::WebView* webview);
192 // Returns the RenderViewImpl for the given routing ID.
193 static RenderViewImpl* FromRoutingID(int routing_id);
195 static size_t GetRenderViewCount();
197 // May return NULL when the view is closing.
198 blink::WebView* webview() const;
200 int history_list_offset() const { return history_list_offset_; }
202 const WebPreferences& webkit_preferences() const {
203 return webkit_preferences_;
206 const RendererPreferences& renderer_preferences() const {
207 return renderer_preferences_;
210 void set_send_content_state_immediately(bool value) {
211 send_content_state_immediately_ = value;
214 MouseLockDispatcher* mouse_lock_dispatcher() {
215 return mouse_lock_dispatcher_;
218 HistoryController* history_controller() {
219 return history_controller_.get();
222 // Lazily initialize this view's BrowserPluginManager and return it.
223 BrowserPluginManager* GetBrowserPluginManager();
225 // Functions to add and remove observers for this object.
226 void AddObserver(RenderViewObserver* observer);
227 void RemoveObserver(RenderViewObserver* observer);
229 // Returns the StatsCollectionObserver associated with this view, or NULL
230 // if one wasn't created;
231 StatsCollectionObserver* GetStatsCollectionObserver() {
232 return stats_collection_observer_.get();
235 // Adds the given file chooser request to the file_chooser_completion_ queue
236 // (see that var for more) and requests the chooser be displayed if there are
237 // no other waiting items in the queue.
239 // Returns true if the chooser was successfully scheduled. False means we
240 // didn't schedule anything.
241 bool ScheduleFileChooser(const FileChooserParams& params,
242 blink::WebFileChooserCompletion* completion);
244 #if defined(OS_ANDROID)
245 void DismissDateTimeDialog();
246 #endif
248 bool is_loading() const { return frames_in_progress_ != 0; }
250 void FrameDidStartLoading(blink::WebFrame* frame);
251 void FrameDidStopLoading(blink::WebFrame* frame);
253 // Plugin-related functions --------------------------------------------------
255 #if defined(ENABLE_PLUGINS)
256 // Get/set the plugin which will be used as to handle document find requests.
257 void set_plugin_find_handler(PepperPluginInstanceImpl* plugin) {
258 plugin_find_handler_ = plugin;
260 PepperPluginInstanceImpl* plugin_find_handler() {
261 return plugin_find_handler_;
264 PepperPluginInstanceImpl* focused_pepper_plugin() {
265 return focused_pepper_plugin_;
267 PepperPluginInstanceImpl* pepper_last_mouse_event_target() {
268 return pepper_last_mouse_event_target_;
270 void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl* plugin) {
271 pepper_last_mouse_event_target_ = plugin;
274 #if defined(OS_MACOSX) || defined(OS_WIN)
275 // Informs the render view that the given plugin has gained or lost focus.
276 void PluginFocusChanged(bool focused, int plugin_id);
277 #endif
279 #if defined(OS_MACOSX)
280 // Starts plugin IME.
281 void StartPluginIme();
282 #endif
284 // Indicates that the given instance has been created.
285 void PepperInstanceCreated(PepperPluginInstanceImpl* instance);
287 // Indicates that the given instance is being destroyed. This is called from
288 // the destructor, so it's important that the instance is not dereferenced
289 // from this call.
290 void PepperInstanceDeleted(PepperPluginInstanceImpl* instance);
292 // Notification that the given plugin is focused or unfocused.
293 void PepperFocusChanged(PepperPluginInstanceImpl* instance, bool focused);
295 void RegisterPluginDelegate(WebPluginDelegateProxy* delegate);
296 void UnregisterPluginDelegate(WebPluginDelegateProxy* delegate);
297 #endif // ENABLE_PLUGINS
299 void TransferActiveWheelFlingAnimation(
300 const blink::WebActiveWheelFlingParameters& params);
302 // Returns true if the focused element is editable text from the perspective
303 // of IME support (also used for on-screen keyboard). Works correctly inside
304 // supported PPAPI plug-ins.
305 bool HasIMETextFocus();
307 // Callback for use with GetWindowSnapshot.
308 typedef base::Callback<void(
309 const gfx::Size&, const std::vector<unsigned char>&)>
310 WindowSnapshotCallback;
312 void GetWindowSnapshot(const WindowSnapshotCallback& callback);
314 // Dispatches the current navigation state to the browser. Called on a
315 // periodic timer so we don't send too many messages.
316 void SyncNavigationState();
318 // Returns the length of the session history of this RenderView. Note that
319 // this only coincides with the actual length of the session history if this
320 // RenderView is the currently active RenderView of a WebContents.
321 unsigned GetLocalSessionHistoryLengthForTesting() const;
323 // Invokes OnSetFocus and marks the widget as active depending on the value
324 // of |enable|. This is used for layout tests that need to control the focus
325 // synchronously from the renderer.
326 void SetFocusAndActivateForTesting(bool enable);
328 // Change the device scale factor and force the compositor to resize.
329 void SetDeviceScaleFactorForTesting(float factor);
331 // Change the device ICC color profile while running a layout test.
332 void SetDeviceColorProfileForTesting(const std::vector<char>& color_profile);
333 virtual void ResetDeviceColorProfileForTesting() override;
335 // Used to force the size of a window when running layout tests.
336 void ForceResizeForTesting(const gfx::Size& new_size);
338 void UseSynchronousResizeModeForTesting(bool enable);
340 // Control autoresize mode.
341 void EnableAutoResizeForTesting(const gfx::Size& min_size,
342 const gfx::Size& max_size);
343 void DisableAutoResizeForTesting(const gfx::Size& new_size);
345 // IPC::Listener implementation ----------------------------------------------
347 virtual bool OnMessageReceived(const IPC::Message& msg) override;
349 // blink::WebWidgetClient implementation ------------------------------------
351 // Most methods are handled by RenderWidget.
352 virtual void didFocus();
353 virtual void didBlur();
354 virtual void show(blink::WebNavigationPolicy policy);
355 virtual void runModal();
356 virtual bool enterFullScreen();
357 virtual void exitFullScreen();
358 virtual bool requestPointerLock();
359 virtual void requestPointerUnlock();
360 virtual bool isPointerLocked();
361 virtual void didHandleGestureEvent(const blink::WebGestureEvent& event,
362 bool event_cancelled) override;
363 virtual void initializeLayerTreeView() override;
365 // blink::WebViewClient implementation --------------------------------------
367 virtual blink::WebView* createView(blink::WebLocalFrame* creator,
368 const blink::WebURLRequest& request,
369 const blink::WebWindowFeatures& features,
370 const blink::WebString& frame_name,
371 blink::WebNavigationPolicy policy,
372 bool suppress_opener);
373 virtual blink::WebWidget* createPopupMenu(blink::WebPopupType popup_type);
374 virtual blink::WebStorageNamespace* createSessionStorageNamespace();
375 virtual void printPage(blink::WebLocalFrame* frame);
376 virtual bool enumerateChosenDirectory(
377 const blink::WebString& path,
378 blink::WebFileChooserCompletion* chooser_completion);
379 virtual void saveImageFromDataURL(const blink::WebString& data_url);
380 virtual void didCancelCompositionOnSelectionChange();
381 virtual bool handleCurrentKeyboardEvent();
382 virtual bool runFileChooser(
383 const blink::WebFileChooserParams& params,
384 blink::WebFileChooserCompletion* chooser_completion);
385 void SetValidationMessageDirection(base::string16* main_text,
386 blink::WebTextDirection main_text_hint,
387 base::string16* sub_text,
388 blink::WebTextDirection sub_text_hint);
389 virtual void showValidationMessage(const blink::WebRect& anchor_in_root_view,
390 const blink::WebString& main_text,
391 blink::WebTextDirection main_text_hint,
392 const blink::WebString& sub_text,
393 blink::WebTextDirection hint) override;
394 virtual void hideValidationMessage() override;
395 virtual void moveValidationMessage(
396 const blink::WebRect& anchor_in_root_view) override;
397 virtual void setStatusText(const blink::WebString& text);
398 virtual void setMouseOverURL(const blink::WebURL& url);
399 virtual void setKeyboardFocusURL(const blink::WebURL& url);
400 virtual void startDragging(blink::WebLocalFrame* frame,
401 const blink::WebDragData& data,
402 blink::WebDragOperationsMask mask,
403 const blink::WebImage& image,
404 const blink::WebPoint& imageOffset);
405 virtual bool acceptsLoadDrops();
406 virtual void focusNext();
407 virtual void focusPrevious();
408 virtual void focusedNodeChanged(const blink::WebNode& node);
409 virtual void didUpdateLayout();
410 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
411 virtual bool didTapMultipleTargets(
412 const blink::WebSize& inner_viewport_offset,
413 const blink::WebRect& touch_rect,
414 const blink::WebVector<blink::WebRect>& target_rects);
415 #endif
416 virtual blink::WebString acceptLanguages();
417 virtual void navigateBackForwardSoon(int offset);
418 virtual int historyBackListCount();
419 virtual int historyForwardListCount();
420 virtual blink::WebSpeechRecognizer* speechRecognizer();
421 virtual void zoomLimitsChanged(double minimum_level, double maximum_level);
422 virtual void zoomLevelChanged();
423 virtual double zoomLevelToZoomFactor(double zoom_level) const;
424 virtual double zoomFactorToZoomLevel(double factor) const;
425 virtual void registerProtocolHandler(const blink::WebString& scheme,
426 const blink::WebURL& url,
427 const blink::WebString& title);
428 virtual void unregisterProtocolHandler(const blink::WebString& scheme,
429 const blink::WebURL& url);
430 virtual blink::WebPageVisibilityState visibilityState() const;
431 virtual blink::WebPushClient* webPushClient();
432 virtual void draggableRegionsChanged();
434 #if defined(OS_ANDROID)
435 virtual void scheduleContentIntent(const blink::WebURL& intent);
436 virtual void cancelScheduledContentIntents();
437 virtual blink::WebContentDetectionResult detectContentAround(
438 const blink::WebHitTestResult& touch_hit);
440 // Only used on Android since all other platforms implement
441 // date and time input fields using MULTIPLE_FIELDS_UI
442 virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams&,
443 blink::WebDateTimeChooserCompletion*);
444 virtual void didScrollWithKeyboard(const blink::WebSize& delta);
445 #endif
447 // blink::WebPageSerializerClient implementation ----------------------------
449 virtual void didSerializeDataForFrame(
450 const blink::WebURL& frame_url,
451 const blink::WebCString& data,
452 PageSerializationStatus status) override;
454 // RenderView implementation -------------------------------------------------
456 virtual bool Send(IPC::Message* message) override;
457 virtual RenderFrameImpl* GetMainRenderFrame() override;
458 virtual int GetRoutingID() const override;
459 virtual gfx::Size GetSize() const override;
460 virtual WebPreferences& GetWebkitPreferences() override;
461 virtual void SetWebkitPreferences(const WebPreferences& preferences) override;
462 virtual blink::WebView* GetWebView() override;
463 virtual blink::WebElement GetFocusedElement() const override;
464 virtual bool IsEditableNode(const blink::WebNode& node) const override;
465 virtual bool NodeContainsPoint(const blink::WebNode& node,
466 const gfx::Point& point) const override;
467 virtual bool ShouldDisplayScrollbars(int width, int height) const override;
468 virtual int GetEnabledBindings() const override;
469 virtual bool GetContentStateImmediately() const override;
470 virtual blink::WebPageVisibilityState GetVisibilityState() const override;
471 virtual void DidStartLoading() override;
472 virtual void DidStopLoading() override;
473 virtual void Repaint(const gfx::Size& size) override;
474 virtual void SetEditCommandForNextKeyEvent(const std::string& name,
475 const std::string& value) override;
476 virtual void ClearEditCommands() override;
477 virtual SSLStatus GetSSLStatusOfFrame(blink::WebFrame* frame) const override;
478 virtual const std::string& GetAcceptLanguages() const override;
479 #if defined(OS_ANDROID)
480 virtual void UpdateTopControlsState(TopControlsState constraints,
481 TopControlsState current,
482 bool animate) override;
483 #endif
484 bool uses_temporary_zoom_level() const { return uses_temporary_zoom_level_; }
486 // Please do not add your stuff randomly to the end here. If there is an
487 // appropriate section, add it there. If not, there are some random functions
488 // nearer to the top you can add it to.
490 // Cannot use std::set unfortunately since linked_ptr<> does not support
491 // operator<.
492 typedef std::vector<linked_ptr<ImageResourceFetcher> >
493 ImageResourceFetcherList;
495 protected:
496 // RenderWidget overrides:
497 virtual void OnClose() override;
498 virtual void Close() override;
499 virtual void OnResize(const ViewMsg_Resize_Params& params) override;
500 virtual void DidInitiatePaint() override;
501 virtual void DidFlushPaint() override;
502 virtual gfx::Vector2d GetScrollOffset() override;
503 virtual void DidHandleKeyEvent() override;
504 virtual bool WillHandleMouseEvent(
505 const blink::WebMouseEvent& event) override;
506 virtual bool WillHandleGestureEvent(
507 const blink::WebGestureEvent& event) override;
508 virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) override;
509 virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) override;
510 virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const override;
511 virtual void OnSetFocus(bool enable) override;
512 virtual void OnWasHidden() override;
513 virtual void OnWasShown(bool needs_repainting,
514 const ui::LatencyInfo& latency_info) override;
515 virtual GURL GetURLForGraphicsContext3D() override;
516 virtual void OnImeSetComposition(
517 const base::string16& text,
518 const std::vector<blink::WebCompositionUnderline>& underlines,
519 int selection_start,
520 int selection_end) override;
521 virtual void OnImeConfirmComposition(const base::string16& text,
522 const gfx::Range& replacement_range,
523 bool keep_selection) override;
524 virtual void SetDeviceScaleFactor(float device_scale_factor) override;
525 virtual bool SetDeviceColorProfile(
526 const std::vector<char>& color_profile) override;
527 virtual void OnOrientationChange() override;
528 virtual ui::TextInputType GetTextInputType() override;
529 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) override;
530 #if defined(OS_MACOSX) || defined(USE_AURA)
531 virtual void GetCompositionCharacterBounds(
532 std::vector<gfx::Rect>* character_bounds) override;
533 virtual void GetCompositionRange(gfx::Range* range) override;
534 #endif
535 virtual bool CanComposeInline() override;
536 virtual void DidCommitCompositorFrame() override;
537 virtual void InstrumentWillBeginFrame(int frame_id) override;
538 virtual void InstrumentDidBeginFrame() override;
539 virtual void InstrumentDidCancelFrame() override;
540 virtual void InstrumentWillComposite() override;
542 protected:
543 explicit RenderViewImpl(RenderViewImplParams* params);
545 void Initialize(RenderViewImplParams* params);
546 virtual void SetScreenMetricsEmulationParameters(
547 float device_scale_factor,
548 const gfx::Point& root_layer_offset,
549 float root_layer_scale) override;
551 // Do not delete directly. This class is reference counted.
552 virtual ~RenderViewImpl();
554 private:
555 // For unit tests.
556 friend class PepperDeviceTest;
557 friend class RenderViewImplTest;
558 friend class RenderViewTest;
559 friend class RendererAccessibilityTest;
561 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
562 // utility functions needed in both classes, while we move frame specific
563 // code away from this class.
564 friend class RenderFrameImpl;
566 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, DecideNavigationPolicyForWebUI);
567 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
568 DidFailProvisionalLoadWithErrorForError);
569 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
570 DidFailProvisionalLoadWithErrorForCancellation);
571 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
572 DontIgnoreBackAfterNavEntryLimit);
573 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ImeComposition);
574 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, InsertCharacters);
575 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, JSBlockSentAfterPageLoad);
576 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, LastCommittedUpdateState);
577 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnHandleKeyboardEvent);
578 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnImeTypeChanged);
579 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavStateChanged);
580 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnSetTextDirection);
581 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnUpdateWebPreferences);
582 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
583 SetEditableSelectionAndComposition);
584 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, StaleNavigationsIgnored);
585 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, UpdateTargetURLWithInvalidURL);
586 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
587 GetCompositionCharacterBoundsTest);
588 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavigationHttpPost);
589 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
590 DecideNavigationPolicyHandlesAllTopLevel);
591 #if defined(OS_MACOSX)
592 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, MacTestCmdUp);
593 #endif
594 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SetHistoryLengthAndPrune);
595 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ZoomLimit);
596 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, NavigateFrame);
597 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, BasicRenderFrame);
598 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, TextInputTypeWithPepper);
599 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
600 MessageOrderInDidChangeSelection);
601 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendCandidateWindowEvents);
602 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, Suppresses);
603 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, DoesNotSuppress);
605 typedef std::map<GURL, double> HostZoomLevels;
607 enum ErrorPageType {
608 DNS_ERROR,
609 HTTP_404,
610 CONNECTION_ERROR,
613 // Old WebFrameClient implementations ----------------------------------------
615 // RenderViewImpl used to be a WebFrameClient, but now RenderFrameImpl is the
616 // WebFrameClient. However, many implementations of WebFrameClient methods
617 // still live here and are called from RenderFrameImpl. These implementations
618 // are to be moved to RenderFrameImpl <http://crbug.com/361761>.
620 void didCreateDataSource(blink::WebLocalFrame* frame,
621 blink::WebDataSource* datasource);
622 void didClearWindowObject(blink::WebLocalFrame* frame);
623 void didChangeIcon(blink::WebLocalFrame*, blink::WebIconURL::Type);
624 void didUpdateCurrentHistoryItem(blink::WebLocalFrame* frame);
625 void didChangeScrollOffset(blink::WebLocalFrame* frame);
627 static bool IsReload(FrameMsg_Navigate_Type::Value navigation_type);
629 static Referrer GetReferrerFromRequest(
630 blink::WebFrame* frame,
631 const blink::WebURLRequest& request);
633 static WindowOpenDisposition NavigationPolicyToDisposition(
634 blink::WebNavigationPolicy policy);
636 void UpdateSessionHistory(blink::WebFrame* frame);
637 void SendUpdateState(HistoryEntry* entry);
639 // Sends a message and runs a nested message loop.
640 bool SendAndRunNestedMessageLoop(IPC::SyncMessage* message);
642 // IPC message handlers ------------------------------------------------------
644 // The documentation for these functions should be in
645 // content/common/*_messages.h for the message that the function is handling.
646 void OnExecuteEditCommand(const std::string& name, const std::string& value);
647 void OnMoveCaret(const gfx::Point& point);
648 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
649 void OnSetEditCommandsForNextKeyEvent(const EditCommands& edit_commands);
650 void OnAllowBindings(int enabled_bindings_flags);
651 void OnAllowScriptToClose(bool script_can_close);
652 void OnCancelDownload(int32 download_id);
653 void OnClearFocusedElement();
654 void OnClosePage();
655 void OnShowContextMenu(ui::MenuSourceType source_type,
656 const gfx::Point& location);
657 void OnCopyImageAt(int x, int y);
658 void OnSaveImageAt(int x, int y);
659 void OnDeterminePageLanguage();
660 void OnDisableScrollbarsForSmallWindows(
661 const gfx::Size& disable_scrollbars_size_limit);
662 void OnDragSourceEnded(const gfx::Point& client_point,
663 const gfx::Point& screen_point,
664 blink::WebDragOperation drag_operation);
665 void OnDragSourceSystemDragEnded();
666 void OnDragTargetDrop(const gfx::Point& client_pt,
667 const gfx::Point& screen_pt,
668 int key_modifiers);
669 void OnDragTargetDragEnter(const DropData& drop_data,
670 const gfx::Point& client_pt,
671 const gfx::Point& screen_pt,
672 blink::WebDragOperationsMask operations_allowed,
673 int key_modifiers);
674 void OnDragTargetDragLeave();
675 void OnDragTargetDragOver(const gfx::Point& client_pt,
676 const gfx::Point& screen_pt,
677 blink::WebDragOperationsMask operations_allowed,
678 int key_modifiers);
679 void OnEnablePreferredSizeChangedMode();
680 void OnEnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
681 void OnDisableAutoResize(const gfx::Size& new_size);
682 void OnEnumerateDirectoryResponse(int id,
683 const std::vector<base::FilePath>& paths);
684 void OnFileChooserResponse(
685 const std::vector<content::FileChooserFileInfo>& files);
686 void OnFind(int request_id,
687 const base::string16&,
688 const blink::WebFindOptions&);
689 void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url);
690 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
691 const std::vector<GURL>& links,
692 const std::vector<base::FilePath>& local_paths,
693 const base::FilePath& local_directory_name);
694 void OnMediaPlayerActionAt(const gfx::Point& location,
695 const blink::WebMediaPlayerAction& action);
696 void OnPluginActionAt(const gfx::Point& location,
697 const blink::WebPluginAction& action);
698 void OnMoveOrResizeStarted();
699 void OnPostMessageEvent(const ViewMsg_PostMessage_Params& params);
700 void OnReleaseDisambiguationPopupBitmap(const cc::SharedBitmapId& id);
701 void OnResetPageEncodingToDefault();
702 void OnSetActive(bool active);
703 void OnSetBackgroundOpaque(bool opaque);
704 void OnExitFullscreen();
705 void OnSetHistoryLengthAndPrune(int history_length, int32 minimum_page_id);
706 void OnSetInitialFocus(bool reverse);
707 void OnSetPageEncoding(const std::string& encoding_name);
708 void OnSetRendererPrefs(const RendererPreferences& renderer_prefs);
709 void OnSetWebUIProperty(const std::string& name, const std::string& value);
710 void OnSetZoomLevelForLoadingURL(const GURL& url, double zoom_level);
711 void OnSetZoomLevelForView(bool uses_temporary_zoom_level, double level);
712 void OnStopFinding(StopFindAction action);
713 void OnSuppressDialogsUntilSwapOut();
714 void OnThemeChanged();
715 void OnUpdateTargetURLAck();
716 void OnUpdateWebPreferences(const WebPreferences& prefs);
717 void OnZoom(PageZoom zoom);
718 void OnEnableViewSourceMode();
719 void OnWindowSnapshotCompleted(const int snapshot_id,
720 const gfx::Size& size, const std::vector<unsigned char>& png);
721 void OnForceRedraw(int request_id);
722 void OnSelectWordAroundCaret();
723 #if defined(OS_ANDROID)
724 void OnActivateNearestFindResult(int request_id, float x, float y);
725 void OnFindMatchRects(int current_version);
726 void OnUndoScrollFocusedEditableNodeIntoRect();
727 void OnUpdateTopControlsState(bool enable_hiding,
728 bool enable_showing,
729 bool animate);
730 void OnExtractSmartClipData(const gfx::Rect& rect);
731 #elif defined(OS_MACOSX)
732 void OnGetRenderedText();
733 void OnPluginImeCompositionCompleted(const base::string16& text,
734 int plugin_id);
735 void OnSetInLiveResize(bool in_live_resize);
736 void OnSetWindowVisibility(bool visible);
737 void OnWindowFrameChanged(const gfx::Rect& window_frame,
738 const gfx::Rect& view_frame);
739 #endif
741 // Adding a new message handler? Please add it in alphabetical order above
742 // and put it in the same position in the .cc file.
744 // Misc private functions ----------------------------------------------------
745 // Check whether the preferred size has changed.
746 void CheckPreferredSize();
748 // Called to get the WebPlugin to handle find requests in the document.
749 // Returns NULL if there is no such WebPlugin.
750 blink::WebPlugin* GetWebPluginForFind();
752 // Returns true if the |params| navigation is to an entry that has been
753 // cropped due to a recent navigation the browser did not know about.
754 bool IsBackForwardToStaleEntry(const PageState& state,
755 int pending_history_list_offset,
756 int32 page_id,
757 bool is_reload);
759 // Make the given |frame| show an empty, unscriptable page.
760 // TODO(creis): Move this to RenderFrame.
761 void NavigateToSwappedOutURL(blink::WebFrame* frame);
763 // If we initiated a navigation, this function will populate |document_state|
764 // with the navigation information saved in OnNavigate().
765 void PopulateDocumentStateFromPending(DocumentState* document_state);
767 // Returns a new NavigationState populated with the navigation information
768 // saved in OnNavigate().
769 NavigationState* CreateNavigationStateFromPending();
771 // Processes the command-line flags --enable-viewport,
772 // --enable-fixed-layout[=w,h] and --enable-pinch.
773 void ProcessViewLayoutFlags(const base::CommandLine& command_line);
775 #if defined(OS_ANDROID)
776 // Launch an Android content intent with the given URL.
777 void LaunchAndroidContentIntent(const GURL& intent_url, size_t request_id);
778 #endif
780 // Sends a reply to the current find operation handling if it was a
781 // synchronous find request.
782 void SendFindReply(int request_id,
783 int match_count,
784 int ordinal,
785 const blink::WebRect& selection_rect,
786 bool final_status_update);
788 // Starts nav_state_sync_timer_ if it isn't already running.
789 void StartNavStateSyncTimerIfNecessary();
791 #if defined(OS_POSIX) && !defined(OS_MACOSX)
792 void UpdateFontRenderingFromRendererPrefs();
793 #else
794 void UpdateFontRenderingFromRendererPrefs() {}
795 #endif
797 // Update the target url and tell the browser that the target URL has changed.
798 // If |url| is empty, show |fallback_url|.
799 void UpdateTargetURL(const GURL& url, const GURL& fallback_url);
801 // Tells the browser what the new list of favicons for the webpage is.
802 void SendUpdateFaviconURL(const std::vector<FaviconURL>& urls);
804 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
805 // the browser.
806 void DidStopLoadingIcons();
808 // Coordinate conversion -----------------------------------------------------
810 gfx::RectF ClientRectToPhysicalWindowRect(const gfx::RectF& rect) const;
812 // RenderFrameImpl accessible state ------------------------------------------
813 // The following section is the set of methods that RenderFrameImpl needs
814 // to access RenderViewImpl state. The set of state variables are page-level
815 // specific, so they don't belong in RenderFrameImpl and should remain in
816 // this object.
817 ObserverList<RenderViewObserver>& observers() {
818 return observers_;
821 // TODO(nasko): Remove this method when we move to frame proxy objects, since
822 // the concept of swapped out will be eliminated.
823 void set_is_swapped_out(bool swapped_out) {
824 is_swapped_out_ = swapped_out;
827 NavigationGesture navigation_gesture() {
828 return navigation_gesture_;
830 void set_navigation_gesture(NavigationGesture gesture) {
831 navigation_gesture_ = gesture;
834 // ---------------------------------------------------------------------------
835 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
836 // it in the same order in the .cc file as it was in the header.
837 // ---------------------------------------------------------------------------
839 // Settings ------------------------------------------------------------------
841 WebPreferences webkit_preferences_;
842 RendererPreferences renderer_preferences_;
844 HostZoomLevels host_zoom_levels_;
846 // Whether content state (such as form state, scroll position and page
847 // contents) should be sent to the browser immediately. This is normally
848 // false, but set to true by some tests.
849 bool send_content_state_immediately_;
851 // Bitwise-ORed set of extra bindings that have been enabled. See
852 // BindingsPolicy for details.
853 int enabled_bindings_;
855 // If true, we send IPC messages when |preferred_size_| changes.
856 bool send_preferred_size_changes_;
858 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
859 // scroll bars on windows smaller than this size. Used for windows that the
860 // browser resizes to the size of the content, such as browser action popups.
861 // If a render view is set to the minimum size of its content, webkit may add
862 // scroll bars. This makes sense for fixed sized windows, but it does not
863 // make sense when the size of the view was chosen to fit the content.
864 // This setting ensures that no scroll bars are drawn. The size limit exists
865 // because if the view grows beyond a size known to the browser, scroll bars
866 // should be drawn.
867 gfx::Size disable_scrollbars_size_limit_;
869 // Loading state -------------------------------------------------------------
871 // The gesture that initiated the current navigation.
872 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
873 NavigationGesture navigation_gesture_;
875 // Used for popups.
876 bool opened_by_user_gesture_;
878 // Whether this RenderView was created by a frame that was suppressing its
879 // opener. If so, we may want to load pages in a separate process. See
880 // decidePolicyForNavigation for details.
881 bool opener_suppressed_;
883 // Whether we must stop creating nested message loops for modal dialogs until
884 // OnSwapOut is called. This is necessary because modal dialogs have a
885 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
886 bool suppress_dialogs_until_swap_out_;
888 // Holds state pertaining to a navigation that we initiated. This is held by
889 // the WebDataSource::ExtraData attribute. We use pending_navigation_state_
890 // as a temporary holder for the state until the WebDataSource corresponding
891 // to the new navigation is created. See DidCreateDataSource.
892 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
893 scoped_ptr<FrameMsg_Navigate_Params> pending_navigation_params_;
895 // Timer used to delay the updating of nav state (see SyncNavigationState).
896 base::OneShotTimer<RenderViewImpl> nav_state_sync_timer_;
898 // Page IDs ------------------------------------------------------------------
899 // See documentation in RenderView.
900 int32 page_id_;
902 // Indicates the ID of the last page that we sent a FrameNavigate to the
903 // browser for. This is used to determine if the most recent transition
904 // generated a history entry (less than page_id_), or not (equal to or
905 // greater than). Note that this will be greater than page_id_ if the user
906 // goes back.
907 int32 last_page_id_sent_to_browser_;
909 // The next available page ID to use for this RenderView. These IDs are
910 // specific to a given RenderView and the frames within it.
911 int32 next_page_id_;
913 // The offset of the current item in the history list.
914 int history_list_offset_;
916 // The RenderView's current impression of the history length. This includes
917 // any items that have committed in this process, but because of cross-process
918 // navigations, the history may have some entries that were committed in other
919 // processes. We won't know about them until the next navigation in this
920 // process.
921 int history_list_length_;
923 // Counter to track how many frames have sent start notifications but not stop
924 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
925 // are gone.
926 int frames_in_progress_;
928 // The list of page IDs for each history item this RenderView knows about.
929 // Some entries may be -1 if they were rendered by other processes or were
930 // restored from a previous session. This lets us detect attempts to
931 // navigate to stale entries that have been cropped from our history.
932 std::vector<int32> history_page_ids_;
934 // UI state ------------------------------------------------------------------
936 // The state of our target_url transmissions. When we receive a request to
937 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
938 // comes back - if a new request comes in before the ACK, we store the new
939 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
940 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
941 // revert to TARGET_INFLIGHT.
943 // We don't need a queue of URLs to send, as only the latest is useful.
944 enum {
945 TARGET_NONE,
946 TARGET_INFLIGHT, // We have a request in-flight, waiting for an ACK
947 TARGET_PENDING // INFLIGHT + we have a URL waiting to be sent
948 } target_url_status_;
950 // The URL we show the user in the status bar. We use this to determine if we
951 // want to send a new one (we do not need to send duplicates). It will be
952 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
953 // updated last.
954 GURL target_url_;
956 // The URL the user's mouse is hovering over.
957 GURL mouse_over_url_;
959 // The URL that has keyboard focus.
960 GURL focus_url_;
962 // The next target URL we want to send to the browser.
963 GURL pending_target_url_;
965 // Indicates whether this view overrides url-based zoom settings.
966 bool uses_temporary_zoom_level_;
968 #if defined(OS_ANDROID)
969 // Cache the old top controls state constraints. Used when updating
970 // current value only without altering the constraints.
971 cc::TopControlsState top_controls_constraints_;
972 #endif
974 // View ----------------------------------------------------------------------
976 // Cache the preferred size of the page in order to prevent sending the IPC
977 // when layout() recomputes but doesn't actually change sizes.
978 gfx::Size preferred_size_;
980 // Used to delay determining the preferred size (to avoid intermediate
981 // states for the sizes).
982 base::OneShotTimer<RenderViewImpl> check_preferred_size_timer_;
984 // Bookkeeping to suppress redundant scroll and focus requests for an already
985 // scrolled and focused editable node.
986 bool has_scrolled_focused_editable_node_into_rect_;
987 gfx::Rect rect_for_scrolled_focused_editable_node_;
989 // Helper objects ------------------------------------------------------------
991 scoped_ptr<RenderFrameImpl> main_render_frame_;
993 // The next group of objects all implement RenderViewObserver, so are deleted
994 // along with the RenderView automatically. This is why we just store
995 // weak references.
997 // The speech recognition dispatcher attached to this view, lazily
998 // initialized.
999 SpeechRecognitionDispatcher* speech_recognition_dispatcher_;
1001 // BrowserPluginManager attached to this view; lazily initialized.
1002 scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
1004 DevToolsAgent* devtools_agent_;
1006 // Mouse Lock dispatcher attached to this view.
1007 MouseLockDispatcher* mouse_lock_dispatcher_;
1009 scoped_ptr<HistoryController> history_controller_;
1011 #if defined(OS_ANDROID)
1012 // Android Specific ---------------------------------------------------------
1014 // Expected id of the next content intent launched. Used to prevent scheduled
1015 // intents to be launched if aborted.
1016 size_t expected_content_intent_id_;
1018 // List of click-based content detectors.
1019 typedef std::vector< linked_ptr<ContentDetector> > ContentDetectorList;
1020 ContentDetectorList content_detectors_;
1022 // A date/time picker object for date and time related input elements.
1023 scoped_ptr<RendererDateTimePicker> date_time_picker_client_;
1024 #endif
1026 // Plugins -------------------------------------------------------------------
1028 // All the currently active plugin delegates for this RenderView; kept so
1029 // that we can enumerate them to send updates about things like window
1030 // location or tab focus and visibily. These are non-owning references.
1031 std::set<WebPluginDelegateProxy*> plugin_delegates_;
1033 #if defined(OS_WIN)
1034 // The ID of the focused NPAPI plug-in.
1035 int focused_plugin_id_;
1036 #endif
1038 #if defined(ENABLE_PLUGINS)
1039 PepperPluginInstanceImpl* plugin_find_handler_;
1041 typedef std::set<PepperPluginInstanceImpl*> PepperPluginSet;
1042 PepperPluginSet active_pepper_instances_;
1044 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
1045 // is focused and sends the IPCs which use these to the correct frame. Until
1046 // then, we must store these on RenderView as that's the one place that knows
1047 // about all the RenderFrames for a page.
1049 // Whether or not the focus is on a PPAPI plugin
1050 PepperPluginInstanceImpl* focused_pepper_plugin_;
1052 // The plugin instance that received the last mouse event. It is set to NULL
1053 // if the last mouse event went to elements other than Pepper plugins.
1054 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
1055 // the RenderFrameImpl to NULL it out when it destructs.
1056 PepperPluginInstanceImpl* pepper_last_mouse_event_target_;
1057 #endif
1059 // Misc ----------------------------------------------------------------------
1061 // The current and pending file chooser completion objects. If the queue is
1062 // nonempty, the first item represents the currently running file chooser
1063 // callback, and the remaining elements are the other file chooser completion
1064 // still waiting to be run (in order).
1065 struct PendingFileChooser;
1066 std::deque< linked_ptr<PendingFileChooser> > file_chooser_completions_;
1068 // The current directory enumeration callback
1069 std::map<int, blink::WebFileChooserCompletion*> enumeration_completions_;
1070 int enumeration_completion_id_;
1072 // The SessionStorage namespace that we're assigned to has an ID, and that ID
1073 // is passed to us upon creation. WebKit asks for this ID upon first use and
1074 // uses it whenever asking the browser process to allocate new storage areas.
1075 int64 session_storage_namespace_id_;
1077 // Stores edit commands associated to the next key event.
1078 // Shall be cleared as soon as the next key event is processed.
1079 EditCommands edit_commands_;
1081 // All the registered observers. We expect this list to be small, so vector
1082 // is fine.
1083 ObserverList<RenderViewObserver> observers_;
1085 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1086 scoped_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
1088 // State associated with the GetWindowSnapshot function.
1089 int next_snapshot_id_;
1090 typedef std::map<int, WindowSnapshotCallback> PendingSnapshotMap;
1091 PendingSnapshotMap pending_snapshots_;
1093 // This field stores drag/drop related info for the event that is currently
1094 // being handled. If the current event results in starting a drag/drop
1095 // session, this info is sent to the browser along with other drag/drop info.
1096 DragEventSourceInfo possible_drag_event_info_;
1098 // NOTE: stats_collection_observer_ should be the last members because their
1099 // constructors call the AddObservers method of RenderViewImpl.
1100 scoped_ptr<StatsCollectionObserver> stats_collection_observer_;
1102 typedef std::map<cc::SharedBitmapId, cc::SharedBitmap*> BitmapMap;
1103 BitmapMap disambiguation_bitmaps_;
1105 // ---------------------------------------------------------------------------
1106 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1107 // sections rather than throwing it randomly at the end. If you're adding a
1108 // bunch of stuff, you should probably create a helper class and put your
1109 // data and methods on that to avoid bloating RenderView more. You can
1110 // use the Observer interface to filter IPC messages and receive frame change
1111 // notifications.
1112 // ---------------------------------------------------------------------------
1114 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl);
1117 } // namespace content
1119 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_