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