• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
7 
8 #include <deque>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13 
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 "content/common/content_export.h"
26 #include "content/common/drag_event_source_info.h"
27 #include "content/common/edit_command.h"
28 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
29 #include "content/common/navigation_gesture.h"
30 #include "content/common/view_message_enums.h"
31 #include "content/public/common/javascript_message_type.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/renderer/render_view.h"
38 #include "content/renderer/media/webmediaplayer_delegate.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/renderer_date_time_picker.h"
43 #include "content/renderer/renderer_webcookiejar_impl.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/WebFrameClient.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/ui_base_types.h"
61 #include "ui/surface/transport_dib.h"
62 #include "webkit/common/webpreferences.h"
63 
64 #if defined(OS_ANDROID)
65 #include "content/renderer/android/content_detector.h"
66 #include "third_party/WebKit/public/web/WebContentDetectionResult.h"
67 #endif
68 
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
75 
76 class CommandLine;
77 class PepperDeviceTest;
78 class SkBitmap;
79 struct PP_NetAddress_Private;
80 struct ViewMsg_Navigate_Params;
81 struct ViewMsg_PostMessage_Params;
82 struct ViewMsg_StopFinding_Params;
83 
84 namespace ui {
85 struct SelectedFileInfo;
86 }  // namespace ui
87 
88 namespace blink {
89 class WebApplicationCacheHost;
90 class WebApplicationCacheHostClient;
91 class WebDOMMessageEvent;
92 class WebDataSource;
93 class WebDateTimeChooserCompletion;
94 class WebDragData;
95 class WebGeolocationClient;
96 class WebGestureEvent;
97 class WebIconURL;
98 class WebImage;
99 class WebPeerConnection00Handler;
100 class WebPeerConnection00HandlerClient;
101 class WebMediaPlayer;
102 class WebMediaPlayerClient;
103 class WebMouseEvent;
104 class WebPeerConnectionHandler;
105 class WebPeerConnectionHandlerClient;
106 class WebSocketStreamHandle;
107 class WebSpeechInputController;
108 class WebSpeechInputListener;
109 class WebSpeechRecognizer;
110 class WebStorageNamespace;
111 class WebTouchEvent;
112 class WebURLRequest;
113 class WebUserMediaClient;
114 struct WebActiveWheelFlingParameters;
115 struct WebDateTimeChooserParams;
116 struct WebFileChooserParams;
117 struct WebFindOptions;
118 struct WebMediaPlayerAction;
119 struct WebPluginAction;
120 struct WebPoint;
121 struct WebWindowFeatures;
122 
123 #if defined(OS_ANDROID)
124 class WebHitTestResult;
125 #endif
126 }
127 
128 namespace webkit_glue {
129 class WebURLResponseExtraDataImpl;
130 }
131 
132 namespace content {
133 class BrowserPluginManager;
134 class DeviceOrientationDispatcher;
135 class DevToolsAgent;
136 class DocumentState;
137 class DomAutomationController;
138 class ExternalPopupMenu;
139 class FaviconHelper;
140 class GeolocationDispatcher;
141 class ImageResourceFetcher;
142 class InputTagSpeechDispatcher;
143 class JavaBridgeDispatcher;
144 class LoadProgressTracker;
145 class MIDIDispatcher;
146 class MediaStreamClient;
147 class MediaStreamDispatcher;
148 class MouseLockDispatcher;
149 class NavigationState;
150 class NotificationProvider;
151 class PepperPluginInstanceImpl;
152 class RenderViewObserver;
153 class RenderViewTest;
154 class RendererAccessibility;
155 class RendererDateTimePicker;
156 class RendererWebColorChooserImpl;
157 class SpeechRecognitionDispatcher;
158 class WebPluginDelegateProxy;
159 struct CustomContextMenuContext;
160 struct DropData;
161 struct FaviconURL;
162 struct FileChooserParams;
163 struct RenderViewImplParams;
164 
165 #if defined(OS_ANDROID)
166 class RendererMediaPlayerManager;
167 class WebMediaPlayerProxyAndroid;
168 #endif
169 
170 //
171 // RenderView is an object that manages a WebView object, and provides a
172 // communication interface with an embedding application process
173 //
174 class CONTENT_EXPORT RenderViewImpl
175     : public RenderWidget,
176       NON_EXPORTED_BASE(public blink::WebViewClient),
177       NON_EXPORTED_BASE(public blink::WebFrameClient),
178       NON_EXPORTED_BASE(public blink::WebPageSerializerClient),
179       public RenderView,
180       NON_EXPORTED_BASE(public WebMediaPlayerDelegate),
181       public base::SupportsWeakPtr<RenderViewImpl> {
182  public:
183   // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
184   // responsible for creating this RenderView.
185   static RenderViewImpl* Create(
186       int32 opener_id,
187       const RendererPreferences& renderer_prefs,
188       const WebPreferences& webkit_prefs,
189       int32 routing_id,
190       int32 main_frame_routing_id,
191       int32 surface_id,
192       int64 session_storage_namespace_id,
193       const base::string16& frame_name,
194       bool is_renderer_created,
195       bool swapped_out,
196       bool hidden,
197       int32 next_page_id,
198       const blink::WebScreenInfo& screen_info,
199       AccessibilityMode accessibility_mode,
200       bool allow_partial_swap);
201 
202   // Used by content_layouttest_support to hook into the creation of
203   // RenderViewImpls.
204   static void InstallCreateHook(
205       RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*));
206 
207   // Returns the RenderViewImpl containing the given WebView.
208   static RenderViewImpl* FromWebView(blink::WebView* webview);
209 
210   // Returns the RenderViewImpl for the given routing ID.
211   static RenderViewImpl* FromRoutingID(int routing_id);
212 
213   // May return NULL when the view is closing.
214   blink::WebView* webview() const;
215 
history_list_offset()216   int history_list_offset() const { return history_list_offset_; }
217 
webkit_preferences()218   const WebPreferences& webkit_preferences() const {
219     return webkit_preferences_;
220   }
221 
renderer_preferences()222   const RendererPreferences& renderer_preferences() const {
223     return renderer_preferences_;
224   }
225 
set_send_content_state_immediately(bool value)226   void set_send_content_state_immediately(bool value) {
227     send_content_state_immediately_ = value;
228   }
229 
main_render_frame()230   RenderFrameImpl* main_render_frame() { return main_render_frame_.get(); }
231 
media_stream_dispatcher()232   MediaStreamDispatcher* media_stream_dispatcher() {
233     return media_stream_dispatcher_;
234   }
235 
renderer_accessibility()236   RendererAccessibility* renderer_accessibility() {
237     return renderer_accessibility_;
238   }
239 
mouse_lock_dispatcher()240   MouseLockDispatcher* mouse_lock_dispatcher() {
241     return mouse_lock_dispatcher_;
242   }
243 
cookie_jar()244   RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
245 
246   // Lazily initialize this view's BrowserPluginManager and return it.
247   BrowserPluginManager* GetBrowserPluginManager();
248 
249   // Functions to add and remove observers for this object.
250   void AddObserver(RenderViewObserver* observer);
251   void RemoveObserver(RenderViewObserver* observer);
252 
253   // Returns the StatsCollectionObserver associated with this view, or NULL
254   // if one wasn't created;
GetStatsCollectionObserver()255   StatsCollectionObserver* GetStatsCollectionObserver() {
256     return stats_collection_observer_.get();
257   }
258 
259   // Adds the given file chooser request to the file_chooser_completion_ queue
260   // (see that var for more) and requests the chooser be displayed if there are
261   // no other waiting items in the queue.
262   //
263   // Returns true if the chooser was successfully scheduled. False means we
264   // didn't schedule anything.
265   bool ScheduleFileChooser(const FileChooserParams& params,
266                            blink::WebFileChooserCompletion* completion);
267 
268   void LoadNavigationErrorPage(
269       blink::WebFrame* frame,
270       const blink::WebURLRequest& failed_request,
271       const blink::WebURLError& error,
272       const std::string& html,
273       bool replace);
274 
275 #if defined(OS_ANDROID)
276   void DismissDateTimeDialog();
277 #endif
278 
279   // Plugin-related functions --------------------------------------------------
280 
281 #if defined(ENABLE_PLUGINS)
focused_pepper_plugin()282   PepperPluginInstanceImpl* focused_pepper_plugin() {
283     return focused_pepper_plugin_;
284   }
set_focused_pepper_plugin(PepperPluginInstanceImpl * plugin)285   void set_focused_pepper_plugin(PepperPluginInstanceImpl* plugin) {
286     focused_pepper_plugin_ = plugin;
287   }
pepper_last_mouse_event_target()288   PepperPluginInstanceImpl* pepper_last_mouse_event_target() {
289     return pepper_last_mouse_event_target_;
290   }
set_pepper_last_mouse_event_target(PepperPluginInstanceImpl * plugin)291   void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl* plugin) {
292     pepper_last_mouse_event_target_ = plugin;
293   }
294 
295 #if defined(OS_MACOSX) || defined(OS_WIN)
296   // Informs the render view that the given plugin has gained or lost focus.
297   void PluginFocusChanged(bool focused, int plugin_id);
298 #endif
299 
300 #if defined(OS_MACOSX)
301   // Starts plugin IME.
302   void StartPluginIme();
303 #endif
304 
305   void RegisterPluginDelegate(WebPluginDelegateProxy* delegate);
306   void UnregisterPluginDelegate(WebPluginDelegateProxy* delegate);
307 #endif  // ENABLE_PLUGINS
308 
309   void TransferActiveWheelFlingAnimation(
310       const blink::WebActiveWheelFlingParameters& params);
311 
312   // Returns true if the focused element is editable text from the perspective
313   // of IME support (also used for on-screen keyboard). Works correctly inside
314   // supported PPAPI plug-ins.
315   bool HasIMETextFocus();
316 
317   // Callback for use with GetWindowSnapshot.
318   typedef base::Callback<void(
319       const gfx::Size&, const std::vector<unsigned char>&)>
320       WindowSnapshotCallback;
321 
322   void GetWindowSnapshot(const WindowSnapshotCallback& callback);
323 
324   // Dispatches the current navigation state to the browser. Called on a
325   // periodic timer so we don't send too many messages.
326   void SyncNavigationState();
327 
328   // Temporary call until all this media code moves to RenderFrame.
329   // TODO(jam): remove me
330   blink::WebMediaPlayer* CreateMediaPlayer(
331       RenderFrame* render_frame,
332       blink::WebFrame* frame,
333       const blink::WebURL& url,
334       blink::WebMediaPlayerClient* client);
335   // Temporary call until the context menu code moves to RenderFrmae.
336   // TODO(jam): remove me
337   int ShowContextMenu(ContextMenuClient* client,
338                       const ContextMenuParams& params);
339   void CancelContextMenu(int request_id);
340 
341   // Returns the length of the session history of this RenderView. Note that
342   // this only coincides with the actual length of the session history if this
343   // RenderView is the currently active RenderView of a WebContents.
344   unsigned GetLocalSessionHistoryLengthForTesting() const;
345 
346   // Invokes OnSetFocus and marks the widget as active depending on the value
347   // of |enable|. This is used for layout tests that need to control the focus
348   // synchronously from the renderer.
349   void SetFocusAndActivateForTesting(bool enable);
350 
351   // Change the device scale factor and force the compositor to resize.
352   void SetDeviceScaleFactorForTesting(float factor);
353 
354   // Used to force the size of a window when running layout tests.
355   void ForceResizeForTesting(const gfx::Size& new_size);
356 
357   void UseSynchronousResizeModeForTesting(bool enable);
358 
359   // Control autoresize mode.
360   void EnableAutoResizeForTesting(const gfx::Size& min_size,
361                                   const gfx::Size& max_size);
362   void DisableAutoResizeForTesting(const gfx::Size& new_size);
363 
364   // Overrides the MediaStreamClient used when creating MediaStream players.
365   // Must be called before any players are created.
366   void SetMediaStreamClientForTesting(MediaStreamClient* media_stream_client);
367 
368   // IPC::Listener implementation ----------------------------------------------
369 
370   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
371 
372   // blink::WebWidgetClient implementation ------------------------------------
373 
374   // Most methods are handled by RenderWidget.
375   virtual void didFocus();
376   virtual void didBlur();
377   virtual void show(blink::WebNavigationPolicy policy);
378   virtual void runModal();
379   virtual bool enterFullScreen();
380   virtual void exitFullScreen();
381   virtual bool requestPointerLock();
382   virtual void requestPointerUnlock();
383   virtual bool isPointerLocked();
384   virtual void didActivateCompositor(int input_handler_identifier);
385   virtual void didHandleGestureEvent(const blink::WebGestureEvent& event,
386                                      bool event_cancelled) OVERRIDE;
387   virtual void initializeLayerTreeView() OVERRIDE;
388 
389   // blink::WebViewClient implementation --------------------------------------
390 
391   virtual blink::WebView* createView(
392       blink::WebFrame* creator,
393       const blink::WebURLRequest& request,
394       const blink::WebWindowFeatures& features,
395       const blink::WebString& frame_name,
396       blink::WebNavigationPolicy policy,
397       bool suppress_opener);
398   virtual blink::WebWidget* createPopupMenu(blink::WebPopupType popup_type);
399   virtual blink::WebExternalPopupMenu* createExternalPopupMenu(
400       const blink::WebPopupMenuInfo& popup_menu_info,
401       blink::WebExternalPopupMenuClient* popup_menu_client);
402   virtual blink::WebStorageNamespace* createSessionStorageNamespace();
403   virtual bool shouldReportDetailedMessageForSource(
404       const blink::WebString& source);
405   virtual void didAddMessageToConsole(
406       const blink::WebConsoleMessage& message,
407       const blink::WebString& source_name,
408       unsigned source_line,
409       const blink::WebString& stack_trace);
410   virtual void printPage(blink::WebFrame* frame);
411   virtual blink::WebNotificationPresenter* notificationPresenter();
412   virtual bool enumerateChosenDirectory(
413       const blink::WebString& path,
414       blink::WebFileChooserCompletion* chooser_completion);
415   virtual void initializeHelperPluginWebFrame(blink::WebHelperPlugin*);
416   virtual void didStartLoading();
417   virtual void didStopLoading();
418   virtual void didChangeLoadProgress(blink::WebFrame* frame,
419                                      double load_progress);
420   virtual void didCancelCompositionOnSelectionChange();
421   virtual void didChangeSelection(bool is_selection_empty);
422   virtual void didExecuteCommand(const blink::WebString& command_name);
423   virtual bool handleCurrentKeyboardEvent();
424   virtual blink::WebColorChooser* createColorChooser(
425       blink::WebColorChooserClient*,
426       const blink::WebColor& initial_color,
427       const blink::WebVector<blink::WebColorSuggestion>& suggestions);
428   virtual bool runFileChooser(
429       const blink::WebFileChooserParams& params,
430       blink::WebFileChooserCompletion* chooser_completion);
431   virtual void runModalAlertDialog(blink::WebFrame* frame,
432                                    const blink::WebString& message);
433   virtual bool runModalConfirmDialog(blink::WebFrame* frame,
434                                      const blink::WebString& message);
435   virtual bool runModalPromptDialog(blink::WebFrame* frame,
436                                     const blink::WebString& message,
437                                     const blink::WebString& default_value,
438                                     blink::WebString* actual_value);
439   virtual bool runModalBeforeUnloadDialog(blink::WebFrame* frame,
440                                           bool is_reload,
441                                           const blink::WebString& message);
442   virtual void showValidationMessage(const blink::WebRect& anchor_in_root_view,
443                                      const blink::WebString& main_text,
444                                      const blink::WebString& sub_text,
445                                      blink::WebTextDirection hint) OVERRIDE;
446   virtual void hideValidationMessage() OVERRIDE;
447   virtual void moveValidationMessage(
448       const blink::WebRect& anchor_in_root_view) OVERRIDE;
449 
450   // DEPRECATED
451   virtual bool runModalBeforeUnloadDialog(blink::WebFrame* frame,
452                                           const blink::WebString& message);
453   virtual void showContextMenu(blink::WebFrame* frame,
454                                const blink::WebContextMenuData& data);
455   virtual void clearContextMenu();
456   virtual void setStatusText(const blink::WebString& text);
457   virtual void setMouseOverURL(const blink::WebURL& url);
458   virtual void setKeyboardFocusURL(const blink::WebURL& url);
459   virtual void startDragging(blink::WebFrame* frame,
460                              const blink::WebDragData& data,
461                              blink::WebDragOperationsMask mask,
462                              const blink::WebImage& image,
463                              const blink::WebPoint& imageOffset);
464   virtual bool acceptsLoadDrops();
465   virtual void focusNext();
466   virtual void focusPrevious();
467   virtual void focusedNodeChanged(const blink::WebNode& node);
468   virtual void numberOfWheelEventHandlersChanged(unsigned num_handlers);
469   virtual void didUpdateLayout();
470 #if defined(OS_ANDROID)
471   virtual bool didTapMultipleTargets(
472       const blink::WebGestureEvent& event,
473       const blink::WebVector<blink::WebRect>& target_rects);
474 #endif
475   virtual void navigateBackForwardSoon(int offset);
476   virtual int historyBackListCount();
477   virtual int historyForwardListCount();
478   virtual void postAccessibilityEvent(
479       const blink::WebAXObject& obj, blink::WebAXEvent event);
480   virtual void didUpdateInspectorSetting(const blink::WebString& key,
481                                          const blink::WebString& value);
482   virtual blink::WebGeolocationClient* geolocationClient();
483   virtual blink::WebSpeechInputController* speechInputController(
484       blink::WebSpeechInputListener* listener);
485   virtual blink::WebSpeechRecognizer* speechRecognizer();
486   virtual void zoomLimitsChanged(double minimum_level, double maximum_level);
487   virtual void zoomLevelChanged();
488   virtual double zoomLevelToZoomFactor(double zoom_level) const;
489   virtual double zoomFactorToZoomLevel(double factor) const;
490   virtual void registerProtocolHandler(const blink::WebString& scheme,
491                                        const blink::WebString& base_url,
492                                        const blink::WebString& url,
493                                        const blink::WebString& title);
494   virtual blink::WebPageVisibilityState visibilityState() const;
495   virtual blink::WebUserMediaClient* userMediaClient();
496   virtual blink::WebMIDIClient* webMIDIClient();
497   virtual void draggableRegionsChanged();
498 
499 #if defined(OS_ANDROID)
500   virtual void scheduleContentIntent(const blink::WebURL& intent);
501   virtual void cancelScheduledContentIntents();
502   virtual blink::WebContentDetectionResult detectContentAround(
503       const blink::WebHitTestResult& touch_hit);
504 
505   // Only used on Android since all other platforms implement
506   // date and time input fields using MULTIPLE_FIELDS_UI
507   virtual bool openDateTimeChooser(const blink::WebDateTimeChooserParams&,
508                                    blink::WebDateTimeChooserCompletion*);
509   virtual void didScrollWithKeyboard(const blink::WebSize& delta);
510 #endif
511 
512   // blink::WebFrameClient implementation -------------------------------------
513 
514   virtual blink::WebMediaPlayer* createMediaPlayer(
515       blink::WebFrame* frame,
516       const blink::WebURL& url,
517       blink::WebMediaPlayerClient* client);
518   virtual blink::WebCookieJar* cookieJar(blink::WebFrame* frame);
519   virtual void didAccessInitialDocument(blink::WebFrame* frame);
520   virtual void didDisownOpener(blink::WebFrame* frame);
521   virtual void frameDetached(blink::WebFrame* frame);
522   virtual void willClose(blink::WebFrame* frame);
523   virtual void didMatchCSS(
524       blink::WebFrame* frame,
525       const blink::WebVector<blink::WebString>& newly_matching_selectors,
526       const blink::WebVector<blink::WebString>& stopped_matching_selectors);
527 
528   // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
529   virtual blink::WebNavigationPolicy decidePolicyForNavigation(
530       blink::WebFrame* frame,
531       blink::WebDataSource::ExtraData* extraData,
532       const blink::WebURLRequest& request,
533       blink::WebNavigationType type,
534       blink::WebNavigationPolicy default_policy,
535       bool is_redirect);
536   // DEPRECATED.
537   virtual blink::WebNavigationPolicy decidePolicyForNavigation(
538       blink::WebFrame* frame,
539       const blink::WebURLRequest& request,
540       blink::WebNavigationType type,
541       blink::WebNavigationPolicy default_policy,
542       bool is_redirect);
543   virtual void willSendSubmitEvent(blink::WebFrame* frame,
544                                    const blink::WebFormElement& form);
545   virtual void willSubmitForm(blink::WebFrame* frame,
546                               const blink::WebFormElement& form);
547   virtual void didCreateDataSource(blink::WebFrame* frame,
548                                    blink::WebDataSource* datasource);
549   virtual void didStartProvisionalLoad(blink::WebFrame* frame);
550   virtual void didReceiveServerRedirectForProvisionalLoad(
551       blink::WebFrame* frame);
552   virtual void didFailProvisionalLoad(blink::WebFrame* frame,
553                                       const blink::WebURLError& error);
554   virtual void didCommitProvisionalLoad(blink::WebFrame* frame,
555                                         bool is_new_navigation);
556   virtual void didClearWindowObject(blink::WebFrame* frame);
557   virtual void didCreateDocumentElement(blink::WebFrame* frame);
558   virtual void didReceiveTitle(blink::WebFrame* frame,
559                                const blink::WebString& title,
560                                blink::WebTextDirection direction);
561   virtual void didChangeIcon(blink::WebFrame*,
562                              blink::WebIconURL::Type);
563   virtual void didFinishDocumentLoad(blink::WebFrame* frame);
564   virtual void didHandleOnloadEvents(blink::WebFrame* frame);
565   virtual void didFailLoad(blink::WebFrame* frame,
566                            const blink::WebURLError& error);
567   virtual void didFinishLoad(blink::WebFrame* frame);
568   virtual void didNavigateWithinPage(blink::WebFrame* frame,
569                                      bool is_new_navigation);
570   virtual void didUpdateCurrentHistoryItem(blink::WebFrame* frame);
571   virtual void willSendRequest(blink::WebFrame* frame,
572                                unsigned identifier,
573                                blink::WebURLRequest& request,
574                                const blink::WebURLResponse& redirect_response);
575   virtual void didReceiveResponse(blink::WebFrame* frame,
576                                   unsigned identifier,
577                                   const blink::WebURLResponse& response);
578   virtual void didFinishResourceLoad(blink::WebFrame* frame,
579                                      unsigned identifier);
580   virtual void didLoadResourceFromMemoryCache(
581       blink::WebFrame* frame,
582       const blink::WebURLRequest& request,
583       const blink::WebURLResponse&);
584   virtual void didDisplayInsecureContent(blink::WebFrame* frame);
585   virtual void didRunInsecureContent(
586       blink::WebFrame* frame,
587       const blink::WebSecurityOrigin& origin,
588       const blink::WebURL& target);
589   virtual void didExhaustMemoryAvailableForScript(blink::WebFrame* frame);
590   virtual void didCreateScriptContext(blink::WebFrame* frame,
591                                       v8::Handle<v8::Context>,
592                                       int extension_group,
593                                       int world_id);
594   virtual void willReleaseScriptContext(blink::WebFrame* frame,
595                                         v8::Handle<v8::Context>,
596                                         int world_id);
597   virtual void didChangeScrollOffset(blink::WebFrame* frame);
598   virtual void willInsertBody(blink::WebFrame* frame);
599   virtual void didFirstVisuallyNonEmptyLayout(blink::WebFrame*);
600   virtual void didChangeContentsSize(blink::WebFrame* frame,
601                                      const blink::WebSize& size);
602   virtual void reportFindInPageMatchCount(int request_id,
603                                           int count,
604                                           bool final_update);
605   virtual void reportFindInPageSelection(int request_id,
606                                          int active_match_ordinal,
607                                          const blink::WebRect& sel);
608   virtual void requestStorageQuota(
609       blink::WebFrame* frame,
610       blink::WebStorageQuotaType type,
611       unsigned long long requested_size,
612       blink::WebStorageQuotaCallbacks* callbacks);
613   virtual void willOpenSocketStream(
614       blink::WebSocketStreamHandle* handle);
615   virtual void willStartUsingPeerConnectionHandler(blink::WebFrame* frame,
616       blink::WebRTCPeerConnectionHandler* handler);
617   virtual bool willCheckAndDispatchMessageEvent(
618       blink::WebFrame* sourceFrame,
619       blink::WebFrame* targetFrame,
620       blink::WebSecurityOrigin targetOrigin,
621       blink::WebDOMMessageEvent event);
622   virtual blink::WebString acceptLanguages();
623   virtual blink::WebString userAgentOverride(
624       blink::WebFrame* frame,
625       const blink::WebURL& url);
626   virtual blink::WebString doNotTrackValue(blink::WebFrame* frame);
627   virtual bool allowWebGL(blink::WebFrame* frame, bool default_value);
628   virtual void didLoseWebGLContext(
629       blink::WebFrame* frame,
630       int arb_robustness_status_code);
631 
632   // blink::WebPageSerializerClient implementation ----------------------------
633 
634   virtual void didSerializeDataForFrame(
635       const blink::WebURL& frame_url,
636       const blink::WebCString& data,
637       PageSerializationStatus status) OVERRIDE;
638 
639   // RenderView implementation -------------------------------------------------
640 
641   virtual bool Send(IPC::Message* message) OVERRIDE;
642   virtual RenderFrame* GetMainRenderFrame() OVERRIDE;
643   virtual int GetRoutingID() const OVERRIDE;
644   virtual int GetPageId() const OVERRIDE;
645   virtual gfx::Size GetSize() const OVERRIDE;
646   virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
647   virtual void SetWebkitPreferences(const WebPreferences& preferences) OVERRIDE;
648   virtual blink::WebView* GetWebView() OVERRIDE;
649   virtual blink::WebNode GetFocusedNode() const OVERRIDE;
650   virtual blink::WebNode GetContextMenuNode() const OVERRIDE;
651   virtual bool IsEditableNode(const blink::WebNode& node) const OVERRIDE;
652   virtual void EvaluateScript(const base::string16& frame_xpath,
653                               const base::string16& jscript,
654                               int id,
655                               bool notify_result) OVERRIDE;
656   virtual bool ShouldDisplayScrollbars(int width, int height) const OVERRIDE;
657   virtual int GetEnabledBindings() const OVERRIDE;
658   virtual bool GetContentStateImmediately() const OVERRIDE;
659   virtual float GetFilteredTimePerFrame() const OVERRIDE;
660   virtual blink::WebPageVisibilityState GetVisibilityState() const OVERRIDE;
661   virtual void RunModalAlertDialog(blink::WebFrame* frame,
662                                    const blink::WebString& message) OVERRIDE;
663   virtual void DidStartLoading() OVERRIDE;
664   virtual void DidStopLoading() OVERRIDE;
665   virtual void Repaint(const gfx::Size& size) OVERRIDE;
666   virtual void SetEditCommandForNextKeyEvent(const std::string& name,
667                                              const std::string& value) OVERRIDE;
668   virtual void ClearEditCommands() OVERRIDE;
669   virtual SSLStatus GetSSLStatusOfFrame(blink::WebFrame* frame) const OVERRIDE;
670   virtual const std::string& GetAcceptLanguages() const OVERRIDE;
671 #if defined(OS_ANDROID)
672   virtual void UpdateTopControlsState(TopControlsState constraints,
673                                       TopControlsState current,
674                                       bool animate) OVERRIDE;
675 #endif
676 
677   // WebMediaPlayerDelegate implementation -----------------------
678 
679   virtual void DidPlay(blink::WebMediaPlayer* player) OVERRIDE;
680   virtual void DidPause(blink::WebMediaPlayer* player) OVERRIDE;
681   virtual void PlayerGone(blink::WebMediaPlayer* player) OVERRIDE;
682 
683   // Please do not add your stuff randomly to the end here. If there is an
684   // appropriate section, add it there. If not, there are some random functions
685   // nearer to the top you can add it to.
686 
687   // Cannot use std::set unfortunately since linked_ptr<> does not support
688   // operator<.
689   typedef std::vector<linked_ptr<ImageResourceFetcher> >
690       ImageResourceFetcherList;
691 
692  protected:
693   // RenderWidget overrides:
694   virtual void Close() OVERRIDE;
695   virtual void OnResize(const ViewMsg_Resize_Params& params) OVERRIDE;
696   virtual void DidInitiatePaint() OVERRIDE;
697   virtual void DidFlushPaint() OVERRIDE;
698   virtual PepperPluginInstanceImpl* GetBitmapForOptimizedPluginPaint(
699       const gfx::Rect& paint_bounds,
700       TransportDIB** dib,
701       gfx::Rect* location,
702       gfx::Rect* clip,
703       float* scale_factor) OVERRIDE;
704   virtual gfx::Vector2d GetScrollOffset() OVERRIDE;
705   virtual void DidHandleKeyEvent() OVERRIDE;
706   virtual bool WillHandleMouseEvent(
707       const blink::WebMouseEvent& event) OVERRIDE;
708   virtual bool WillHandleKeyEvent(
709       const blink::WebKeyboardEvent& event) OVERRIDE;
710   virtual bool WillHandleGestureEvent(
711       const blink::WebGestureEvent& event) OVERRIDE;
712   virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) OVERRIDE;
713   virtual void DidHandleTouchEvent(const blink::WebTouchEvent& event) OVERRIDE;
714   virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const OVERRIDE;
715   virtual void OnSetFocus(bool enable) OVERRIDE;
716   virtual void OnWasHidden() OVERRIDE;
717   virtual void OnWasShown(bool needs_repainting) OVERRIDE;
718   virtual GURL GetURLForGraphicsContext3D() OVERRIDE;
719   virtual bool ForceCompositingModeEnabled() OVERRIDE;
720   virtual void OnImeSetComposition(
721       const base::string16& text,
722       const std::vector<blink::WebCompositionUnderline>& underlines,
723       int selection_start,
724       int selection_end) OVERRIDE;
725   virtual void OnImeConfirmComposition(const base::string16& text,
726                                        const gfx::Range& replacement_range,
727                                        bool keep_selection) OVERRIDE;
728   virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
729   virtual ui::TextInputType GetTextInputType() OVERRIDE;
730   virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) OVERRIDE;
731 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
732   virtual void GetCompositionCharacterBounds(
733       std::vector<gfx::Rect>* character_bounds) OVERRIDE;
734   virtual void GetCompositionRange(gfx::Range* range) OVERRIDE;
735 #endif
736   virtual bool CanComposeInline() OVERRIDE;
737   virtual void DidCommitCompositorFrame() OVERRIDE;
738   virtual void InstrumentWillBeginFrame(int frame_id) OVERRIDE;
739   virtual void InstrumentDidBeginFrame() OVERRIDE;
740   virtual void InstrumentDidCancelFrame() OVERRIDE;
741   virtual void InstrumentWillComposite() OVERRIDE;
742   virtual bool AllowPartialSwap() const OVERRIDE;
743 
744  protected:
745   explicit RenderViewImpl(RenderViewImplParams* params);
746 
747   void Initialize(RenderViewImplParams* params);
748   virtual void SetScreenMetricsEmulationParameters(
749       float device_scale_factor,
750       const gfx::Point& root_layer_offset,
751       float root_layer_scale) OVERRIDE;
752 
753   // Do not delete directly.  This class is reference counted.
754   virtual ~RenderViewImpl();
755 
756  private:
757   // For unit tests.
758   friend class ExternalPopupMenuTest;
759   friend class PepperDeviceTest;
760   friend class RendererAccessibilityTest;
761   friend class RenderViewTest;
762 
763   // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
764   // utility functions needed in both classes, while we move frame specific
765   // code away from this class.
766   friend class RenderFrameImpl;
767 
768   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
769   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
770   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
771   FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
772                            AccessibilityMessagesQueueWhileSwappedOut);
773   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, DecideNavigationPolicyForWebUI);
774   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
775                            DidFailProvisionalLoadWithErrorForError);
776   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
777                            DidFailProvisionalLoadWithErrorForCancellation);
778   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
779                            DontIgnoreBackAfterNavEntryLimit);
780   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ImeComposition);
781   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, InsertCharacters);
782   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, JSBlockSentAfterPageLoad);
783   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, LastCommittedUpdateState);
784   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnExtendSelectionAndDelete);
785   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnHandleKeyboardEvent);
786   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnImeTypeChanged);
787   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavStateChanged);
788   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnSetTextDirection);
789   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnUpdateWebPreferences);
790   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendSwapOutACK);
791   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ReloadWhileSwappedOut);
792   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
793                            SetEditableSelectionAndComposition);
794   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, StaleNavigationsIgnored);
795   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, UpdateTargetURLWithInvalidURL);
796   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
797                            GetCompositionCharacterBoundsTest);
798   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavigationHttpPost);
799   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
800                            DecideNavigationPolicyHandlesAllTopLevel);
801 #if defined(OS_MACOSX)
802   FRIEND_TEST_ALL_PREFIXES(RenderViewTest, MacTestCmdUp);
803 #endif
804   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SetHistoryLengthAndPrune);
805   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ZoomLimit);
806   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, NavigateFrame);
807   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
808                            ShouldUpdateSelectionTextFromContextMenuParams);
809   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, BasicRenderFrame);
810   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, TextInputTypeWithPepper);
811   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
812                            MessageOrderInDidChangeSelection);
813   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendCandidateWindowEvents);
814   FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, Suppresses);
815   FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, DoesNotSuppress);
816 
817   typedef std::map<GURL, double> HostZoomLevels;
818 
819   enum ErrorPageType {
820     DNS_ERROR,
821     HTTP_404,
822     CONNECTION_ERROR,
823   };
824 
825   static blink::WebReferrerPolicy GetReferrerPolicyFromRequest(
826       blink::WebFrame* frame,
827       const blink::WebURLRequest& request);
828 
829   static Referrer GetReferrerFromRequest(
830       blink::WebFrame* frame,
831       const blink::WebURLRequest& request);
832 
833   static webkit_glue::WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
834       const blink::WebURLResponse& response);
835 
836   void UpdateURL(blink::WebFrame* frame);
837   void UpdateTitle(blink::WebFrame* frame, const base::string16& title,
838                    blink::WebTextDirection title_direction);
839   void UpdateSessionHistory(blink::WebFrame* frame);
840   void SendUpdateState(const blink::WebHistoryItem& item);
841 
842   // Update current main frame's encoding and send it to browser window.
843   // Since we want to let users see the right encoding info from menu
844   // before finishing loading, we call the UpdateEncoding in
845   // a) function:DidCommitLoadForFrame. When this function is called,
846   // that means we have got first data. In here we try to get encoding
847   // of page if it has been specified in http header.
848   // b) function:DidReceiveTitle. When this function is called,
849   // that means we have got specified title. Because in most of webpages,
850   // title tags will follow meta tags. In here we try to get encoding of
851   // page if it has been specified in meta tag.
852   // c) function:DidFinishDocumentLoadForFrame. When this function is
853   // called, that means we have got whole html page. In here we should
854   // finally get right encoding of page.
855   void UpdateEncoding(blink::WebFrame* frame,
856                       const std::string& encoding_name);
857 
858   void OpenURL(blink::WebFrame* frame,
859                const GURL& url,
860                const Referrer& referrer,
861                blink::WebNavigationPolicy policy);
862 
863   bool RunJavaScriptMessage(JavaScriptMessageType type,
864                             const base::string16& message,
865                             const base::string16& default_value,
866                             const GURL& frame_url,
867                             base::string16* result);
868 
869   // Sends a message and runs a nested message loop.
870   bool SendAndRunNestedMessageLoop(IPC::SyncMessage* message);
871 
872   // Called when the "pinned to left/right edge" state needs to be updated.
873   void UpdateScrollState(blink::WebFrame* frame);
874 
875   // IPC message handlers ------------------------------------------------------
876   //
877   // The documentation for these functions should be in
878   // content/common/*_messages.h for the message that the function is handling.
879 
880   void OnCopy();
881   void OnCut();
882   void OnDelete();
883   void OnExecuteEditCommand(const std::string& name, const std::string& value);
884   void OnMoveCaret(const gfx::Point& point);
885   void OnPaste();
886   void OnPasteAndMatchStyle();
887   void OnRedo();
888   void OnReplace(const base::string16& text);
889   void OnReplaceMisspelling(const base::string16& text);
890   void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
891   void OnSelectAll();
892   void OnSelectRange(const gfx::Point& start, const gfx::Point& end);
893   void OnSetEditCommandsForNextKeyEvent(const EditCommands& edit_commands);
894   void OnUndo();
895   void OnUnselect();
896   void OnAllowBindings(int enabled_bindings_flags);
897   void OnAllowScriptToClose(bool script_can_close);
898   void OnCancelDownload(int32 download_id);
899   void OnClearFocusedNode();
900   void OnClosePage();
901   void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
902   void OnShowContextMenu(const gfx::Point& location);
903   void OnCopyImageAt(int x, int y);
904   void OnCSSInsertRequest(const base::string16& frame_xpath,
905                           const std::string& css);
906   void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
907       unsigned action);
908   void OnSetName(const std::string& name);
909   void OnDeterminePageLanguage();
910   void OnDisableScrollbarsForSmallWindows(
911       const gfx::Size& disable_scrollbars_size_limit);
912   void OnDragSourceEndedOrMoved(const gfx::Point& client_point,
913                                 const gfx::Point& screen_point,
914                                 bool ended,
915                                 blink::WebDragOperation drag_operation);
916   void OnDragSourceSystemDragEnded();
917   void OnDragTargetDrop(const gfx::Point& client_pt,
918                         const gfx::Point& screen_pt,
919                         int key_modifiers);
920   void OnDragTargetDragEnter(const DropData& drop_data,
921                              const gfx::Point& client_pt,
922                              const gfx::Point& screen_pt,
923                              blink::WebDragOperationsMask operations_allowed,
924                              int key_modifiers);
925   void OnDragTargetDragLeave();
926   void OnDragTargetDragOver(const gfx::Point& client_pt,
927                             const gfx::Point& screen_pt,
928                             blink::WebDragOperationsMask operations_allowed,
929                             int key_modifiers);
930   void OnEnablePreferredSizeChangedMode();
931   void OnEnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
932   void OnDisableAutoResize(const gfx::Size& new_size);
933   void OnEnumerateDirectoryResponse(int id,
934                                     const std::vector<base::FilePath>& paths);
935   void OnExtendSelectionAndDelete(int before, int after);
936   void OnFileChooserResponse(
937       const std::vector<ui::SelectedFileInfo>& files);
938   void OnFind(int request_id,
939               const base::string16&,
940               const blink::WebFindOptions&);
941   void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url);
942   void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
943       const std::vector<GURL>& links,
944       const std::vector<base::FilePath>& local_paths,
945       const base::FilePath& local_directory_name);
946   void OnMediaPlayerActionAt(const gfx::Point& location,
947                              const blink::WebMediaPlayerAction& action);
948   void OnOrientationChangeEvent(int orientation);
949   void OnPluginActionAt(const gfx::Point& location,
950                         const blink::WebPluginAction& action);
951   void OnMoveOrResizeStarted();
952   void OnNavigate(const ViewMsg_Navigate_Params& params);
953   void OnPostMessageEvent(const ViewMsg_PostMessage_Params& params);
954   void OnReleaseDisambiguationPopupDIB(TransportDIB::Handle dib_handle);
955   void OnReloadFrame();
956   void OnResetPageEncodingToDefault();
957   void OnScriptEvalRequest(const base::string16& frame_xpath,
958                            const base::string16& jscript,
959                            int id,
960                            bool notify_result);
961   void OnSetAccessibilityMode(AccessibilityMode new_mode);
962   void OnSetActive(bool active);
963   void OnSetAltErrorPageURL(const GURL& gurl);
964   void OnSetBackground(const SkBitmap& background);
965   void OnSetCompositionFromExistingText(
966       int start, int end,
967       const std::vector<blink::WebCompositionUnderline>& underlines);
968   void OnExitFullscreen();
969   void OnSetEditableSelectionOffsets(int start, int end);
970   void OnSetHistoryLengthAndPrune(int history_length, int32 minimum_page_id);
971   void OnSetInitialFocus(bool reverse);
972   void OnSetPageEncoding(const std::string& encoding_name);
973   void OnSetRendererPrefs(const RendererPreferences& renderer_prefs);
974   void OnSetWebUIProperty(const std::string& name, const std::string& value);
975   void OnSetZoomLevel(double zoom_level);
976   void OnSetZoomLevelForLoadingURL(const GURL& url, double zoom_level);
977   void OnShouldClose();
978   void OnStop();
979   void OnStopFinding(StopFindAction action);
980   void OnSuppressDialogsUntilSwapOut();
981   void OnSwapOut();
982   void OnThemeChanged();
983   void OnUpdateTargetURLAck();
984   void OnUpdateTimezone();
985   void OnUpdateWebPreferences(const WebPreferences& prefs);
986   void OnZoom(PageZoom zoom);
987   void OnZoomFactor(PageZoom zoom, int zoom_center_x, int zoom_center_y);
988   void OnEnableViewSourceMode();
989   void OnDisownOpener();
990   void OnWindowSnapshotCompleted(const int snapshot_id,
991       const gfx::Size& size, const std::vector<unsigned char>& png);
992 #if defined(OS_ANDROID)
993   void OnActivateNearestFindResult(int request_id, float x, float y);
994   void OnFindMatchRects(int current_version);
995   void OnSelectPopupMenuItems(bool canceled,
996                               const std::vector<int>& selected_indices);
997   void OnUndoScrollFocusedEditableNodeIntoRect();
998   void OnUpdateTopControlsState(bool enable_hiding,
999                                 bool enable_showing,
1000                                 bool animate);
1001   void OnPauseVideo();
1002   void OnExtractSmartClipData(const gfx::Rect& rect);
1003 #elif defined(OS_MACOSX)
1004   void OnCopyToFindPboard();
1005   void OnPluginImeCompositionCompleted(const base::string16& text,
1006                                        int plugin_id);
1007   void OnSelectPopupMenuItem(int selected_index);
1008   void OnSetInLiveResize(bool in_live_resize);
1009   void OnSetWindowVisibility(bool visible);
1010   void OnWindowFrameChanged(const gfx::Rect& window_frame,
1011                             const gfx::Rect& view_frame);
1012 #endif
1013 
1014   // Adding a new message handler? Please add it in alphabetical order above
1015   // and put it in the same position in the .cc file.
1016 
1017   // Misc private functions ----------------------------------------------------
1018   void ZoomFactorHelper(PageZoom zoom, int zoom_center_x, int zoom_center_y,
1019                         float scaling_increment);
1020 
1021   void AltErrorPageFinished(blink::WebFrame* frame,
1022                             const blink::WebURLRequest& original_request,
1023                             const blink::WebURLError& original_error,
1024                             const std::string& html);
1025 
1026   // Check whether the preferred size has changed.
1027   void CheckPreferredSize();
1028 
1029   // Initializes |media_stream_client_|, returning true if successful. Returns
1030   // false if it wasn't possible to create a MediaStreamClient (e.g., WebRTC is
1031   // disabled) in which case |media_stream_client_| is NULL.
1032   bool InitializeMediaStreamClient();
1033 
1034   // This callback is triggered when DownloadFavicon completes, either
1035   // succesfully or with a failure. See DownloadFavicon for more
1036   // details.
1037   void DidDownloadFavicon(ImageResourceFetcher* fetcher,
1038                           const SkBitmap& image);
1039 
1040   // Requests to download a favicon image. When done, the RenderView is notified
1041   // by way of DidDownloadFavicon. Returns true if the request was successfully
1042   // started, false otherwise. id is used to uniquely identify the request and
1043   // passed back to the DidDownloadFavicon method. If the image has multiple
1044   // frames, the frame whose size is image_size is returned. If the image
1045   // doesn't have a frame at the specified size, the first is returned.
1046   bool DownloadFavicon(int id, const GURL& image_url, int image_size);
1047 
1048   GURL GetAlternateErrorPageURL(const GURL& failed_url,
1049                                 ErrorPageType error_type);
1050 
1051   // Locates a sub frame with given xpath
1052   blink::WebFrame* GetChildFrame(const base::string16& frame_xpath) const;
1053 
1054   // Returns the URL being loaded by the given frame's request.
1055   GURL GetLoadingUrl(blink::WebFrame* frame) const;
1056 
1057   // Should only be called if this object wraps a PluginDocument.
1058   blink::WebPlugin* GetWebPluginFromPluginDocument();
1059 
1060   // Returns true if the |params| navigation is to an entry that has been
1061   // cropped due to a recent navigation the browser did not know about.
1062   bool IsBackForwardToStaleEntry(const ViewMsg_Navigate_Params& params,
1063                                  bool is_reload);
1064 
1065   bool MaybeLoadAlternateErrorPage(blink::WebFrame* frame,
1066                                    const blink::WebURLError& error,
1067                                    bool replace);
1068 
1069   // Make this RenderView show an empty, unscriptable page.
1070   void NavigateToSwappedOutURL(blink::WebFrame* frame);
1071 
1072   // If we initiated a navigation, this function will populate |document_state|
1073   // with the navigation information saved in OnNavigate().
1074   void PopulateDocumentStateFromPending(DocumentState* document_state);
1075 
1076   // Returns a new NavigationState populated with the navigation information
1077   // saved in OnNavigate().
1078   NavigationState* CreateNavigationStateFromPending();
1079 
1080   // Processes the command-line flags --enable-viewport,
1081   // --enable-fixed-layout[=w,h] and --enable-pinch.
1082   void ProcessViewLayoutFlags(const CommandLine& command_line);
1083 
1084 #if defined(OS_ANDROID)
1085   // Launch an Android content intent with the given URL.
1086   void LaunchAndroidContentIntent(const GURL& intent_url, size_t request_id);
1087 
1088   blink::WebMediaPlayer* CreateAndroidWebMediaPlayer(
1089       blink::WebFrame* frame,
1090       const blink::WebURL& url,
1091       blink::WebMediaPlayerClient* client);
1092 #endif
1093 
1094   blink::WebMediaPlayer* CreateWebMediaPlayerForMediaStream(
1095       blink::WebFrame* frame,
1096       const blink::WebURL& url,
1097       blink::WebMediaPlayerClient* client);
1098 
1099   // Sends a reply to the current find operation handling if it was a
1100   // synchronous find request.
1101   void SendFindReply(int request_id,
1102                      int match_count,
1103                      int ordinal,
1104                      const blink::WebRect& selection_rect,
1105                      bool final_status_update);
1106 
1107   // Returns whether |params.selection_text| should be synchronized to the
1108   // browser before bringing up the context menu. Static for testing.
1109   static bool ShouldUpdateSelectionTextFromContextMenuParams(
1110       const base::string16& selection_text,
1111       size_t selection_text_offset,
1112       const gfx::Range& selection_range,
1113       const ContextMenuParams& params);
1114 
1115 
1116   // Returns the original request url. If there is no redirect, the original
1117   // url is the same as ds->request()->url(). If the WebDataSource belongs to a
1118   // frame was loaded by loadData, the original url will be ds->unreachableURL()
1119   static GURL GetOriginalRequestURL(blink::WebDataSource* ds);
1120 
1121   // Starts nav_state_sync_timer_ if it isn't already running.
1122   void StartNavStateSyncTimerIfNecessary();
1123 
1124   // Dispatches the current state of selection on the webpage to the browser if
1125   // it has changed.
1126   // TODO(varunjain): delete this method once we figure out how to keep
1127   // selection handles in sync with the webpage.
1128   void SyncSelectionIfRequired();
1129 
1130 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1131   void UpdateFontRenderingFromRendererPrefs();
1132 #else
UpdateFontRenderingFromRendererPrefs()1133   void UpdateFontRenderingFromRendererPrefs() {}
1134 #endif
1135 
1136   // Update the target url and tell the browser that the target URL has changed.
1137   // If |url| is empty, show |fallback_url|.
1138   void UpdateTargetURL(const GURL& url, const GURL& fallback_url);
1139 
1140   // Tells the browser what the new list of favicons for the webpage is.
1141   void SendUpdateFaviconURL(const std::vector<FaviconURL>& urls);
1142 
1143   // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
1144   // the browser.
1145   void DidStopLoadingIcons();
1146 
1147   // Coordinate conversion -----------------------------------------------------
1148 
1149   gfx::RectF ClientRectToPhysicalWindowRect(const gfx::RectF& rect) const;
1150 
1151   // Helper for LatencyInfo construction.
1152   int64 GetLatencyComponentId();
1153 
1154   // RenderFrameImpl accessible state ------------------------------------------
1155   // The following section is the set of methods that RenderFrameImpl needs
1156   // to access RenderViewImpl state. The set of state variables are page-level
1157   // specific, so they don't belong in RenderFrameImpl and should remain in
1158   // this object.
observers()1159   ObserverList<RenderViewObserver>& observers() {
1160     return observers_;
1161   }
1162 
1163   // TODO(nasko): Remove this method when we move to frame proxy objects, since
1164   // the concept of swapped out will be eliminated.
set_is_swapped_out(bool swapped_out)1165   void set_is_swapped_out(bool swapped_out) {
1166     is_swapped_out_ = swapped_out;
1167   }
1168 
navigation_gesture()1169   NavigationGesture navigation_gesture() {
1170     return navigation_gesture_;
1171   }
set_navigation_gesture(NavigationGesture gesture)1172   void set_navigation_gesture(NavigationGesture gesture) {
1173     navigation_gesture_ = gesture;
1174   }
1175 
1176   // ---------------------------------------------------------------------------
1177   // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
1178   // it in the same order in the .cc file as it was in the header.
1179   // ---------------------------------------------------------------------------
1180 
1181   // Settings ------------------------------------------------------------------
1182 
1183   WebPreferences webkit_preferences_;
1184   RendererPreferences renderer_preferences_;
1185 
1186   HostZoomLevels host_zoom_levels_;
1187 
1188   // Whether content state (such as form state, scroll position and page
1189   // contents) should be sent to the browser immediately. This is normally
1190   // false, but set to true by some tests.
1191   bool send_content_state_immediately_;
1192 
1193   // Bitwise-ORed set of extra bindings that have been enabled.  See
1194   // BindingsPolicy for details.
1195   int enabled_bindings_;
1196 
1197   // The alternate error page URL, if one exists.
1198   GURL alternate_error_page_url_;
1199 
1200   // If true, we send IPC messages when |preferred_size_| changes.
1201   bool send_preferred_size_changes_;
1202 
1203   // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
1204   // scroll bars on windows smaller than this size.  Used for windows that the
1205   // browser resizes to the size of the content, such as browser action popups.
1206   // If a render view is set to the minimum size of its content, webkit may add
1207   // scroll bars.  This makes sense for fixed sized windows, but it does not
1208   // make sense when the size of the view was chosen to fit the content.
1209   // This setting ensures that no scroll bars are drawn.  The size limit exists
1210   // because if the view grows beyond a size known to the browser, scroll bars
1211   // should be drawn.
1212   gfx::Size disable_scrollbars_size_limit_;
1213 
1214   // Loading state -------------------------------------------------------------
1215 
1216   // True if the top level frame is currently being loaded.
1217   bool is_loading_;
1218 
1219   // The gesture that initiated the current navigation.
1220   NavigationGesture navigation_gesture_;
1221 
1222   // Used for popups.
1223   bool opened_by_user_gesture_;
1224 
1225   // Whether this RenderView was created by a frame that was suppressing its
1226   // opener. If so, we may want to load pages in a separate process.  See
1227   // decidePolicyForNavigation for details.
1228   bool opener_suppressed_;
1229 
1230   // Whether we must stop creating nested message loops for modal dialogs until
1231   // OnSwapOut is called.  This is necessary because modal dialogs have a
1232   // PageGroupLoadDeferrer on the stack that interferes with swapping out.
1233   bool suppress_dialogs_until_swap_out_;
1234 
1235   // Holds state pertaining to a navigation that we initiated.  This is held by
1236   // the WebDataSource::ExtraData attribute.  We use pending_navigation_state_
1237   // as a temporary holder for the state until the WebDataSource corresponding
1238   // to the new navigation is created.  See DidCreateDataSource.
1239   scoped_ptr<ViewMsg_Navigate_Params> pending_navigation_params_;
1240 
1241   // Timer used to delay the updating of nav state (see SyncNavigationState).
1242   base::OneShotTimer<RenderViewImpl> nav_state_sync_timer_;
1243 
1244   // Page IDs ------------------------------------------------------------------
1245   // See documentation in RenderView.
1246   int32 page_id_;
1247 
1248   // Indicates the ID of the last page that we sent a FrameNavigate to the
1249   // browser for. This is used to determine if the most recent transition
1250   // generated a history entry (less than page_id_), or not (equal to or
1251   // greater than). Note that this will be greater than page_id_ if the user
1252   // goes back.
1253   int32 last_page_id_sent_to_browser_;
1254 
1255   // The next available page ID to use for this RenderView.  These IDs are
1256   // specific to a given RenderView and the frames within it.
1257   int32 next_page_id_;
1258 
1259   // The offset of the current item in the history list.
1260   int history_list_offset_;
1261 
1262   // The RenderView's current impression of the history length.  This includes
1263   // any items that have committed in this process, but because of cross-process
1264   // navigations, the history may have some entries that were committed in other
1265   // processes.  We won't know about them until the next navigation in this
1266   // process.
1267   int history_list_length_;
1268 
1269   // The list of page IDs for each history item this RenderView knows about.
1270   // Some entries may be -1 if they were rendered by other processes or were
1271   // restored from a previous session.  This lets us detect attempts to
1272   // navigate to stale entries that have been cropped from our history.
1273   std::vector<int32> history_page_ids_;
1274 
1275   // Page info -----------------------------------------------------------------
1276 
1277   // The last gotten main frame's encoding.
1278   std::string last_encoding_name_;
1279 
1280   // UI state ------------------------------------------------------------------
1281 
1282   // The state of our target_url transmissions. When we receive a request to
1283   // send a URL to the browser, we set this to TARGET_INFLIGHT until an ACK
1284   // comes back - if a new request comes in before the ACK, we store the new
1285   // URL in pending_target_url_ and set the status to TARGET_PENDING. If an
1286   // ACK comes back and we are in TARGET_PENDING, we send the stored URL and
1287   // revert to TARGET_INFLIGHT.
1288   //
1289   // We don't need a queue of URLs to send, as only the latest is useful.
1290   enum {
1291     TARGET_NONE,
1292     TARGET_INFLIGHT,  // We have a request in-flight, waiting for an ACK
1293     TARGET_PENDING    // INFLIGHT + we have a URL waiting to be sent
1294   } target_url_status_;
1295 
1296   // The URL we show the user in the status bar. We use this to determine if we
1297   // want to send a new one (we do not need to send duplicates). It will be
1298   // equal to either |mouse_over_url_| or |focus_url_|, depending on which was
1299   // updated last.
1300   GURL target_url_;
1301 
1302   // The URL the user's mouse is hovering over.
1303   GURL mouse_over_url_;
1304 
1305   // The URL that has keyboard focus.
1306   GURL focus_url_;
1307 
1308   // The next target URL we want to send to the browser.
1309   GURL pending_target_url_;
1310 
1311   // The text selection the last time DidChangeSelection got called. May contain
1312   // additional characters before and after the selected text, for IMEs. The
1313   // portion of this string that is the actual selected text starts at index
1314   // |selection_range_.GetMin() - selection_text_offset_| and has length
1315   // |selection_range_.length()|.
1316   base::string16 selection_text_;
1317   // The offset corresponding to the start of |selection_text_| in the document.
1318   size_t selection_text_offset_;
1319   // Range over the document corresponding to the actual selected text (which
1320   // could correspond to a substring of |selection_text_|; see above).
1321   gfx::Range selection_range_;
1322 
1323   // External context menu requests we're waiting for. "Internal"
1324   // (WebKit-originated) context menu events will have an ID of 0 and will not
1325   // be in this map.
1326   //
1327   // We don't want to add internal ones since some of the "special" page
1328   // handlers in the browser process just ignore the context menu requests so
1329   // avoid showing context menus, and so this will cause right clicks to leak
1330   // entries in this map. Most users of the custom context menu (e.g. Pepper
1331   // plugins) are normally only on "regular" pages and the regular pages will
1332   // always respond properly to the request, so we don't have to worry so
1333   // much about leaks.
1334   IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
1335 
1336 #if defined(OS_ANDROID)
1337   // Cache the old top controls state constraints. Used when updating
1338   // current value only without altering the constraints.
1339   cc::TopControlsState top_controls_constraints_;
1340 #endif
1341 
1342   // View ----------------------------------------------------------------------
1343 
1344   // Cache the preferred size of the page in order to prevent sending the IPC
1345   // when layout() recomputes but doesn't actually change sizes.
1346   gfx::Size preferred_size_;
1347 
1348   // Used to delay determining the preferred size (to avoid intermediate
1349   // states for the sizes).
1350   base::OneShotTimer<RenderViewImpl> check_preferred_size_timer_;
1351 
1352   // These store the "is main frame is scrolled all the way to the left
1353   // or right" state that was last sent to the browser.
1354   bool cached_is_main_frame_pinned_to_left_;
1355   bool cached_is_main_frame_pinned_to_right_;
1356 
1357   // These store the "has scrollbars" state last sent to the browser.
1358   bool cached_has_main_frame_horizontal_scrollbar_;
1359   bool cached_has_main_frame_vertical_scrollbar_;
1360 
1361   // Helper objects ------------------------------------------------------------
1362 
1363   scoped_ptr<RenderFrameImpl> main_render_frame_;
1364 
1365   RendererWebCookieJarImpl cookie_jar_;
1366 
1367   // The next group of objects all implement RenderViewObserver, so are deleted
1368   // along with the RenderView automatically.  This is why we just store
1369   // weak references.
1370 
1371   // Holds a reference to the service which provides desktop notifications.
1372   NotificationProvider* notification_provider_;
1373 
1374   // The geolocation dispatcher attached to this view, lazily initialized.
1375   GeolocationDispatcher* geolocation_dispatcher_;
1376 
1377   // The speech dispatcher attached to this view, lazily initialized.
1378   InputTagSpeechDispatcher* input_tag_speech_dispatcher_;
1379 
1380   // The speech recognition dispatcher attached to this view, lazily
1381   // initialized.
1382   SpeechRecognitionDispatcher* speech_recognition_dispatcher_;
1383 
1384   // Device orientation dispatcher attached to this view; lazily initialized.
1385   DeviceOrientationDispatcher* device_orientation_dispatcher_;
1386 
1387   // MediaStream dispatcher attached to this view; lazily initialized.
1388   MediaStreamDispatcher* media_stream_dispatcher_;
1389 
1390   // BrowserPluginManager attached to this view; lazily initialized.
1391   scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
1392 
1393   // MediaStreamClient attached to this view; lazily initialized.
1394   MediaStreamClient* media_stream_client_;
1395   blink::WebUserMediaClient* web_user_media_client_;
1396 
1397   // MIDIClient attached to this view; lazily initialized.
1398   MIDIDispatcher* midi_dispatcher_;
1399 
1400   DevToolsAgent* devtools_agent_;
1401 
1402   // The current accessibility mode.
1403   AccessibilityMode accessibility_mode_;
1404 
1405   // Only valid if |accessibility_mode_| is anything other than
1406   // AccessibilityModeOff.
1407   RendererAccessibility* renderer_accessibility_;
1408 
1409   // Mouse Lock dispatcher attached to this view.
1410   MouseLockDispatcher* mouse_lock_dispatcher_;
1411 
1412 #if defined(OS_ANDROID)
1413   // Android Specific ---------------------------------------------------------
1414 
1415   // The background color of the document body element. This is used as the
1416   // default background color for filling the screen areas for which we don't
1417   // have the actual content.
1418   SkColor body_background_color_;
1419 
1420   // Expected id of the next content intent launched. Used to prevent scheduled
1421   // intents to be launched if aborted.
1422   size_t expected_content_intent_id_;
1423 
1424   // List of click-based content detectors.
1425   typedef std::vector< linked_ptr<ContentDetector> > ContentDetectorList;
1426   ContentDetectorList content_detectors_;
1427 
1428   // The media player manager for managing all the media players on this view
1429   // for communicating with the real media player objects in browser process.
1430   RendererMediaPlayerManager* media_player_manager_;
1431 
1432   // A date/time picker object for date and time related input elements.
1433   scoped_ptr<RendererDateTimePicker> date_time_picker_client_;
1434 #endif
1435 
1436   // Plugins -------------------------------------------------------------------
1437 
1438   // All the currently active plugin delegates for this RenderView; kept so
1439   // that we can enumerate them to send updates about things like window
1440   // location or tab focus and visibily. These are non-owning references.
1441   std::set<WebPluginDelegateProxy*> plugin_delegates_;
1442 
1443 #if defined(OS_WIN)
1444   // The ID of the focused NPAPI plug-in.
1445   int focused_plugin_id_;
1446 #endif
1447 
1448 #if defined(ENABLE_PLUGINS)
1449   // TODO(jam): these belong on RenderFrame, once the browser knows which frame
1450   // is focused and sends the IPCs which use these to the correct frame. Until
1451   // then, we must store these on RenderView as that's the one place that knows
1452   // about all the RenderFrames for a page.
1453 
1454   // Whether or not the focus is on a PPAPI plugin
1455   PepperPluginInstanceImpl* focused_pepper_plugin_;
1456 
1457   // The plugin instance that received the last mouse event. It is set to NULL
1458   // if the last mouse event went to elements other than Pepper plugins.
1459   // |pepper_last_mouse_event_target_| is not owned by this class. We depend on
1460   // the RenderFrameImpl to NULL it out when it destructs.
1461   PepperPluginInstanceImpl* pepper_last_mouse_event_target_;
1462 #endif
1463 
1464   // Misc ----------------------------------------------------------------------
1465 
1466   // The current and pending file chooser completion objects. If the queue is
1467   // nonempty, the first item represents the currently running file chooser
1468   // callback, and the remaining elements are the other file chooser completion
1469   // still waiting to be run (in order).
1470   struct PendingFileChooser;
1471   std::deque< linked_ptr<PendingFileChooser> > file_chooser_completions_;
1472 
1473   // The current directory enumeration callback
1474   std::map<int, blink::WebFileChooserCompletion*> enumeration_completions_;
1475   int enumeration_completion_id_;
1476 
1477   // Reports load progress to the browser.
1478   scoped_ptr<LoadProgressTracker> load_progress_tracker_;
1479 
1480   // The SessionStorage namespace that we're assigned to has an ID, and that ID
1481   // is passed to us upon creation.  WebKit asks for this ID upon first use and
1482   // uses it whenever asking the browser process to allocate new storage areas.
1483   int64 session_storage_namespace_id_;
1484 
1485   // Stores edit commands associated to the next key event.
1486   // Shall be cleared as soon as the next key event is processed.
1487   EditCommands edit_commands_;
1488 
1489   // The external popup for the currently showing select popup.
1490   scoped_ptr<ExternalPopupMenu> external_popup_menu_;
1491 
1492   // The node that the context menu was pressed over.
1493   blink::WebNode context_menu_node_;
1494 
1495   // All the registered observers.  We expect this list to be small, so vector
1496   // is fine.
1497   ObserverList<RenderViewObserver> observers_;
1498 
1499   // Used to inform didChangeSelection() when it is called in the context
1500   // of handling a InputMsg_SelectRange IPC.
1501   bool handling_select_range_;
1502 
1503   // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1504   scoped_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
1505 
1506   // State associated with the GetWindowSnapshot function.
1507   int next_snapshot_id_;
1508   typedef std::map<int, WindowSnapshotCallback> PendingSnapshotMap;
1509   PendingSnapshotMap pending_snapshots_;
1510 
1511   // Allows to selectively disable partial buffer swap for this renderer's
1512   // compositor.
1513   bool allow_partial_swap_;
1514 
1515   // Allows JS to access DOM automation. The JS object is only exposed when the
1516   // DOM automation bindings are enabled.
1517   scoped_ptr<DomAutomationController> dom_automation_controller_;
1518 
1519   // This field stores drag/drop related info for the event that is currently
1520   // being handled. If the current event results in starting a drag/drop
1521   // session, this info is sent to the browser along with other drag/drop info.
1522   DragEventSourceInfo possible_drag_event_info_;
1523 
1524   // NOTE: stats_collection_observer_ should be the last members because their
1525   // constructors call the AddObservers method of RenderViewImpl.
1526   scoped_ptr<StatsCollectionObserver> stats_collection_observer_;
1527 
1528   ui::MenuSourceType context_menu_source_type_;
1529   gfx::Point touch_editing_context_menu_location_;
1530 
1531   // ---------------------------------------------------------------------------
1532   // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1533   // sections rather than throwing it randomly at the end. If you're adding a
1534   // bunch of stuff, you should probably create a helper class and put your
1535   // data and methods on that to avoid bloating RenderView more.  You can
1536   // use the Observer interface to filter IPC messages and receive frame change
1537   // notifications.
1538   // ---------------------------------------------------------------------------
1539 
1540   DISALLOW_COPY_AND_ASSIGN(RenderViewImpl);
1541 };
1542 
1543 }  // namespace content
1544 
1545 #endif  // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
1546