1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
14 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/id_map.h"
17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h"
20 #include "base/process/process.h"
21 #include "base/strings/string16.h"
22 #include "base/timer/timer.h"
23 #include "build/build_config.h"
24 #include "cc/input/top_controls_state.h"
25 #include "cc/resources/shared_bitmap.h"
26 #include "content/common/content_export.h"
27 #include "content/common/drag_event_source_info.h"
28 #include "content/common/edit_command.h"
29 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
30 #include "content/common/navigation_gesture.h"
31 #include "content/common/view_message_enums.h"
32 #include "content/public/common/page_zoom.h"
33 #include "content/public/common/referrer.h"
34 #include "content/public/common/renderer_preferences.h"
35 #include "content/public/common/stop_find_action.h"
36 #include "content/public/common/top_controls_state.h"
37 #include "content/public/common/web_preferences.h"
38 #include "content/public/renderer/render_view.h"
39 #include "content/renderer/mouse_lock_dispatcher.h"
40 #include "content/renderer/render_frame_impl.h"
41 #include "content/renderer/render_widget.h"
42 #include "content/renderer/stats_collection_observer.h"
43 #include "ipc/ipc_platform_file.h"
44 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
45 #include "third_party/WebKit/public/web/WebAXObject.h"
46 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
47 #include "third_party/WebKit/public/web/WebDataSource.h"
48 #include "third_party/WebKit/public/web/WebElement.h"
49 #include "third_party/WebKit/public/web/WebHistoryItem.h"
50 #include "third_party/WebKit/public/web/WebIconURL.h"
51 #include "third_party/WebKit/public/web/WebInputEvent.h"
52 #include "third_party/WebKit/public/web/WebNavigationType.h"
53 #include "third_party/WebKit/public/web/WebNode.h"
54 #include "third_party/WebKit/public/web/WebPageSerializerClient.h"
55 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
56 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
57 #include "third_party/WebKit/public/web/WebViewClient.h"
58 #include "ui/base/window_open_disposition.h"
59 #include "ui/surface/transport_dib.h"
61 #if defined(OS_ANDROID)
62 #include "content/renderer/android/content_detector.h"
63 #include "content/renderer/android/renderer_date_time_picker.h"
64 #include "third_party/WebKit/public/web/WebContentDetectionResult.h"
67 #if defined(COMPILER_MSVC)
68 // RenderViewImpl is a diamond-shaped hierarchy, with WebWidgetClient at the
69 // root. VS warns when we inherit the WebWidgetClient method implementations
70 // from RenderWidget. It's safe to ignore that warning.
71 #pragma warning(disable: 4250)
74 class PepperDeviceTest;
76 struct PP_NetAddress_Private;
77 struct FrameMsg_Navigate_Params;
78 struct ViewMsg_PostMessage_Params;
79 struct ViewMsg_StopFinding_Params;
86 class WebApplicationCacheHost;
87 class WebApplicationCacheHostClient;
88 class WebDOMMessageEvent;
90 class WebDateTimeChooserCompletion;
92 class WebGestureEvent;
95 class WebPeerConnection00Handler;
96 class WebPeerConnection00HandlerClient;
98 class WebPeerConnectionHandler;
99 class WebPeerConnectionHandlerClient;
100 class WebSocketStreamHandle;
101 class WebSpeechRecognizer;
102 class WebStorageNamespace;
105 struct WebActiveWheelFlingParameters;
106 struct WebDateTimeChooserParams;
107 struct WebFileChooserParams;
108 struct WebFindOptions;
109 struct WebMediaPlayerAction;
110 struct WebPluginAction;
112 struct WebWindowFeatures;
114 #if defined(OS_ANDROID)
115 class WebHitTestResult;
120 struct SelectedFileInfo;
125 class BrowserPluginManager;
128 class HistoryController;
130 class ImageResourceFetcher;
131 class MouseLockDispatcher;
132 class NavigationState;
133 class PepperPluginInstanceImpl;
134 class RenderViewImplTest;
135 class RenderViewObserver;
136 class RenderViewTest;
137 class RendererDateTimePicker;
138 class RendererWebColorChooserImpl;
139 class SpeechRecognitionDispatcher;
140 class WebPluginDelegateProxy;
143 struct FileChooserParams;
144 struct RenderViewImplParams;
146 #if defined(OS_ANDROID)
147 class WebMediaPlayerProxyAndroid;
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),
159 public base::SupportsWeakPtr<RenderViewImpl> {
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,
172 int32 main_frame_routing_id,
174 int64 session_storage_namespace_id,
175 const base::string16& frame_name,
176 bool is_renderer_created,
178 int32 proxy_routing_id,
182 const blink::WebScreenInfo& screen_info);
184 // Used by content_layouttest_support to hook into the creation of
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();
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);
279 #if defined(OS_MACOSX)
280 // Starts plugin IME.
281 void StartPluginIme();
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
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);
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);
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;
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
492 typedef std::vector<linked_ptr<ImageResourceFetcher> >
493 ImageResourceFetcherList;
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,
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;
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;
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();
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);
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;
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(const FrameMsg_Navigate_Params& params);
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();
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,
669 void OnDragTargetDragEnter(const DropData& drop_data,
670 const gfx::Point& client_pt,
671 const gfx::Point& screen_pt,
672 blink::WebDragOperationsMask operations_allowed,
674 void OnDragTargetDragLeave();
675 void OnDragTargetDragOver(const gfx::Point& client_pt,
676 const gfx::Point& screen_pt,
677 blink::WebDragOperationsMask operations_allowed,
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<ui::SelectedFileInfo>& 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,
730 void OnExtractSmartClipData(const gfx::Rect& rect);
731 #elif defined(OS_MACOSX)
732 void OnGetRenderedText();
733 void OnPluginImeCompositionCompleted(const base::string16& text,
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);
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 FrameMsg_Navigate_Params& params,
757 // Make the given |frame| show an empty, unscriptable page.
758 // TODO(creis): Move this to RenderFrame.
759 void NavigateToSwappedOutURL(blink::WebFrame* frame);
761 // If we initiated a navigation, this function will populate |document_state|
762 // with the navigation information saved in OnNavigate().
763 void PopulateDocumentStateFromPending(DocumentState* document_state);
765 // Returns a new NavigationState populated with the navigation information
766 // saved in OnNavigate().
767 NavigationState* CreateNavigationStateFromPending();
769 // Processes the command-line flags --enable-viewport,
770 // --enable-fixed-layout[=w,h] and --enable-pinch.
771 void ProcessViewLayoutFlags(const base::CommandLine& command_line);
773 #if defined(OS_ANDROID)
774 // Launch an Android content intent with the given URL.
775 void LaunchAndroidContentIntent(const GURL& intent_url, size_t request_id);
778 // Sends a reply to the current find operation handling if it was a
779 // synchronous find request.
780 void SendFindReply(int request_id,
783 const blink::WebRect& selection_rect,
784 bool final_status_update);
786 // Starts nav_state_sync_timer_ if it isn't already running.
787 void StartNavStateSyncTimerIfNecessary();
789 #if defined(OS_POSIX) && !defined(OS_MACOSX)
790 void UpdateFontRenderingFromRendererPrefs();
792 void UpdateFontRenderingFromRendererPrefs() {}
795 // Update the target url and tell the browser that the target URL has changed.
796 // If |url| is empty, show |fallback_url|.
797 void UpdateTargetURL(const GURL& url, const GURL& fallback_url);
799 // Tells the browser what the new list of favicons for the webpage is.
800 void SendUpdateFaviconURL(const std::vector<FaviconURL>& urls);
802 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
804 void DidStopLoadingIcons();
806 // Coordinate conversion -----------------------------------------------------
808 gfx::RectF ClientRectToPhysicalWindowRect(const gfx::RectF& rect) const;
810 // RenderFrameImpl accessible state ------------------------------------------
811 // The following section is the set of methods that RenderFrameImpl needs
812 // to access RenderViewImpl state. The set of state variables are page-level
813 // specific, so they don't belong in RenderFrameImpl and should remain in
815 ObserverList<RenderViewObserver>& observers() {
819 // TODO(nasko): Remove this method when we move to frame proxy objects, since
820 // the concept of swapped out will be eliminated.
821 void set_is_swapped_out(bool swapped_out) {
822 is_swapped_out_ = swapped_out;
825 NavigationGesture navigation_gesture() {
826 return navigation_gesture_;
828 void set_navigation_gesture(NavigationGesture gesture) {
829 navigation_gesture_ = gesture;
832 // ---------------------------------------------------------------------------
833 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
834 // it in the same order in the .cc file as it was in the header.
835 // ---------------------------------------------------------------------------
837 // Settings ------------------------------------------------------------------
839 WebPreferences webkit_preferences_;
840 RendererPreferences renderer_preferences_;
842 HostZoomLevels host_zoom_levels_;
844 // Whether content state (such as form state, scroll position and page
845 // contents) should be sent to the browser immediately. This is normally
846 // false, but set to true by some tests.
847 bool send_content_state_immediately_;
849 // Bitwise-ORed set of extra bindings that have been enabled. See
850 // BindingsPolicy for details.
851 int enabled_bindings_;
853 // If true, we send IPC messages when |preferred_size_| changes.
854 bool send_preferred_size_changes_;
856 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
857 // scroll bars on windows smaller than this size. Used for windows that the
858 // browser resizes to the size of the content, such as browser action popups.
859 // If a render view is set to the minimum size of its content, webkit may add
860 // scroll bars. This makes sense for fixed sized windows, but it does not
861 // make sense when the size of the view was chosen to fit the content.
862 // This setting ensures that no scroll bars are drawn. The size limit exists
863 // because if the view grows beyond a size known to the browser, scroll bars
865 gfx::Size disable_scrollbars_size_limit_;
867 // Loading state -------------------------------------------------------------
869 // The gesture that initiated the current navigation.
870 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
871 NavigationGesture navigation_gesture_;
874 bool opened_by_user_gesture_;
876 // Whether this RenderView was created by a frame that was suppressing its
877 // opener. If so, we may want to load pages in a separate process. See
878 // decidePolicyForNavigation for details.
879 bool opener_suppressed_;
881 // Whether we must stop creating nested message loops for modal dialogs until
882 // OnSwapOut is called. This is necessary because modal dialogs have a
883 // PageGroupLoadDeferrer on the stack that interferes with swapping out.
884 bool suppress_dialogs_until_swap_out_;
886 // Holds state pertaining to a navigation that we initiated. This is held by
887 // the WebDataSource::ExtraData attribute. We use pending_navigation_state_
888 // as a temporary holder for the state until the WebDataSource corresponding
889 // to the new navigation is created. See DidCreateDataSource.
890 // TODO(nasko): Move to RenderFrame, as this is per-frame state.
891 scoped_ptr<FrameMsg_Navigate_Params> pending_navigation_params_;
893 // Timer used to delay the updating of nav state (see SyncNavigationState).
894 base::OneShotTimer<RenderViewImpl> nav_state_sync_timer_;
896 // Page IDs ------------------------------------------------------------------
897 // See documentation in RenderView.
900 // Indicates the ID of the last page that we sent a FrameNavigate to the
901 // browser for. This is used to determine if the most recent transition
902 // generated a history entry (less than page_id_), or not (equal to or
903 // greater than). Note that this will be greater than page_id_ if the user
905 int32 last_page_id_sent_to_browser_;
907 // The next available page ID to use for this RenderView. These IDs are
908 // specific to a given RenderView and the frames within it.
911 // The offset of the current item in the history list.
912 int history_list_offset_;
914 // The RenderView's current impression of the history length. This includes
915 // any items that have committed in this process, but because of cross-process
916 // navigations, the history may have some entries that were committed in other
917 // processes. We won't know about them until the next navigation in this
919 int history_list_length_;
921 // Counter to track how many frames have sent start notifications but not stop
922 // notifications. TODO(avi): Remove this once DidStartLoading/DidStopLoading
924 int frames_in_progress_;
926 // The list of page IDs for each history item this RenderView knows about.
927 // Some entries may be -1 if they were rendered by other processes or were
928 // restored from a previous session. This lets us detect attempts to
929 // navigate to stale entries that have been cropped from our history.
930 std::vector<int32> history_page_ids_;
932 // UI state ------------------------------------------------------------------
934 // The state of our target_url transmissions. When we receive a request to
935 // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
936 // comes back - if a new request comes in before the ACK, we store the new
937 // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
938 // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
939 // revert to TARGET_INFLIGHT.
941 // We don't need a queue of URLs to send, as only the latest is useful.
944 TARGET_INFLIGHT, // We have a request in-flight, waiting for an ACK
945 TARGET_PENDING // INFLIGHT + we have a URL waiting to be sent
946 } target_url_status_;
948 // The URL we show the user in the status bar. We use this to determine if we
949 // want to send a new one (we do not need to send duplicates). It will be
950 // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
954 // The URL the user's mouse is hovering over.
955 GURL mouse_over_url_;
957 // The URL that has keyboard focus.
960 // The next target URL we want to send to the browser.
961 GURL pending_target_url_;
963 // Indicates whether this view overrides url-based zoom settings.
964 bool uses_temporary_zoom_level_;
966 #if defined(OS_ANDROID)
967 // Cache the old top controls state constraints. Used when updating
968 // current value only without altering the constraints.
969 cc::TopControlsState top_controls_constraints_;
972 // View ----------------------------------------------------------------------
974 // Cache the preferred size of the page in order to prevent sending the IPC
975 // when layout() recomputes but doesn't actually change sizes.
976 gfx::Size preferred_size_;
978 // Used to delay determining the preferred size (to avoid intermediate
979 // states for the sizes).
980 base::OneShotTimer<RenderViewImpl> check_preferred_size_timer_;
982 // Bookkeeping to suppress redundant scroll and focus requests for an already
983 // scrolled and focused editable node.
984 bool has_scrolled_focused_editable_node_into_rect_;
985 gfx::Rect rect_for_scrolled_focused_editable_node_;
987 // Helper objects ------------------------------------------------------------
989 scoped_ptr<RenderFrameImpl> main_render_frame_;
991 // The next group of objects all implement RenderViewObserver, so are deleted
992 // along with the RenderView automatically. This is why we just store
995 // The speech recognition dispatcher attached to this view, lazily
997 SpeechRecognitionDispatcher* speech_recognition_dispatcher_;
999 // BrowserPluginManager attached to this view; lazily initialized.
1000 scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
1002 DevToolsAgent* devtools_agent_;
1004 // Mouse Lock dispatcher attached to this view.
1005 MouseLockDispatcher* mouse_lock_dispatcher_;
1007 scoped_ptr<HistoryController> history_controller_;
1009 #if defined(OS_ANDROID)
1010 // Android Specific ---------------------------------------------------------
1012 // Expected id of the next content intent launched. Used to prevent scheduled
1013 // intents to be launched if aborted.
1014 size_t expected_content_intent_id_;
1016 // List of click-based content detectors.
1017 typedef std::vector< linked_ptr<ContentDetector> > ContentDetectorList;
1018 ContentDetectorList content_detectors_;
1020 // A date/time picker object for date and time related input elements.
1021 scoped_ptr<RendererDateTimePicker> date_time_picker_client_;
1024 // Plugins -------------------------------------------------------------------
1026 // All the currently active plugin delegates for this RenderView; kept so
1027 // that we can enumerate them to send updates about things like window
1028 // location or tab focus and visibily. These are non-owning references.
1029 std::set<WebPluginDelegateProxy*> plugin_delegates_;
1032 // The ID of the focused NPAPI plug-in.
1033 int focused_plugin_id_;
1036 #if defined(ENABLE_PLUGINS)
1037 PepperPluginInstanceImpl* plugin_find_handler_;
1039 typedef std::set<PepperPluginInstanceImpl*> PepperPluginSet;
1040 PepperPluginSet active_pepper_instances_;
1042 // TODO(jam): these belong on RenderFrame, once the browser knows which frame
1043 // is focused and sends the IPCs which use these to the correct frame. Until
1044 // then, we must store these on RenderView as that's the one place that knows
1045 // about all the RenderFrames for a page.
1047 // Whether or not the focus is on a PPAPI plugin
1048 PepperPluginInstanceImpl* focused_pepper_plugin_;
1050 // The plugin instance that received the last mouse event. It is set to NULL
1051 // if the last mouse event went to elements other than Pepper plugins.
1052 // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
1053 // the RenderFrameImpl to NULL it out when it destructs.
1054 PepperPluginInstanceImpl* pepper_last_mouse_event_target_;
1057 // Misc ----------------------------------------------------------------------
1059 // The current and pending file chooser completion objects. If the queue is
1060 // nonempty, the first item represents the currently running file chooser
1061 // callback, and the remaining elements are the other file chooser completion
1062 // still waiting to be run (in order).
1063 struct PendingFileChooser;
1064 std::deque< linked_ptr<PendingFileChooser> > file_chooser_completions_;
1066 // The current directory enumeration callback
1067 std::map<int, blink::WebFileChooserCompletion*> enumeration_completions_;
1068 int enumeration_completion_id_;
1070 // The SessionStorage namespace that we're assigned to has an ID, and that ID
1071 // is passed to us upon creation. WebKit asks for this ID upon first use and
1072 // uses it whenever asking the browser process to allocate new storage areas.
1073 int64 session_storage_namespace_id_;
1075 // Stores edit commands associated to the next key event.
1076 // Shall be cleared as soon as the next key event is processed.
1077 EditCommands edit_commands_;
1079 // All the registered observers. We expect this list to be small, so vector
1081 ObserverList<RenderViewObserver> observers_;
1083 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1084 scoped_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
1086 // State associated with the GetWindowSnapshot function.
1087 int next_snapshot_id_;
1088 typedef std::map<int, WindowSnapshotCallback> PendingSnapshotMap;
1089 PendingSnapshotMap pending_snapshots_;
1091 // This field stores drag/drop related info for the event that is currently
1092 // being handled. If the current event results in starting a drag/drop
1093 // session, this info is sent to the browser along with other drag/drop info.
1094 DragEventSourceInfo possible_drag_event_info_;
1096 // NOTE: stats_collection_observer_ should be the last members because their
1097 // constructors call the AddObservers method of RenderViewImpl.
1098 scoped_ptr<StatsCollectionObserver> stats_collection_observer_;
1100 typedef std::map<cc::SharedBitmapId, cc::SharedBitmap*> BitmapMap;
1101 BitmapMap disambiguation_bitmaps_;
1103 // ---------------------------------------------------------------------------
1104 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1105 // sections rather than throwing it randomly at the end. If you're adding a
1106 // bunch of stuff, you should probably create a helper class and put your
1107 // data and methods on that to avoid bloating RenderView more. You can
1108 // use the Observer interface to filter IPC messages and receive frame change
1110 // ---------------------------------------------------------------------------
1112 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl);
1115 } // namespace content
1117 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_