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