1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_VIEW_IMPL_H_
14 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/id_map.h"
17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h"
20 #include "base/process/process.h"
21 #include "base/strings/string16.h"
22 #include "base/timer/timer.h"
23 #include "build/build_config.h"
24 #include "cc/input/top_controls_state.h"
25 #include "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_webcookiejar_impl.h"
43 #include "content/renderer/stats_collection_observer.h"
44 #include "ipc/ipc_platform_file.h"
45 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
46 #include "third_party/WebKit/public/web/WebAXObject.h"
47 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
48 #include "third_party/WebKit/public/web/WebDataSource.h"
49 #include "third_party/WebKit/public/web/WebFrameClient.h"
50 #include "third_party/WebKit/public/web/WebHistoryItem.h"
51 #include "third_party/WebKit/public/web/WebIconURL.h"
52 #include "third_party/WebKit/public/web/WebInputEvent.h"
53 #include "third_party/WebKit/public/web/WebNavigationType.h"
54 #include "third_party/WebKit/public/web/WebNode.h"
55 #include "third_party/WebKit/public/web/WebPageSerializerClient.h"
56 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
57 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
58 #include "third_party/WebKit/public/web/WebViewClient.h"
59 #include "ui/base/ui_base_types.h"
60 #include "ui/surface/transport_dib.h"
61 #include "webkit/common/webpreferences.h"
63 #if defined(OS_ANDROID)
64 #include "content/renderer/android/content_detector.h"
65 #include "third_party/WebKit/public/web/WebContentDetectionResult.h"
68 #if defined(COMPILER_MSVC)
69 // RenderViewImpl is a diamond-shaped hierarchy, with WebWidgetClient at the
70 // root. VS warns when we inherit the WebWidgetClient method implementations
71 // from RenderWidget. It's safe to ignore that warning.
72 #pragma warning(disable: 4250)
76 class PepperDeviceTest;
78 struct PP_NetAddress_Private;
79 struct ViewMsg_Navigate_Params;
80 struct ViewMsg_PostMessage_Params;
81 struct ViewMsg_StopFinding_Params;
84 struct SelectedFileInfo;
88 class WebApplicationCacheHost;
89 class WebApplicationCacheHostClient;
90 class WebDOMMessageEvent;
92 class WebDateTimeChooserCompletion;
94 class WebGeolocationClient;
95 class WebGestureEvent;
98 class WebPeerConnection00Handler;
99 class WebPeerConnection00HandlerClient;
100 class WebMediaPlayer;
101 class WebMediaPlayerClient;
103 class WebPeerConnectionHandler;
104 class WebPeerConnectionHandlerClient;
105 class WebSocketStreamHandle;
106 class WebSpeechInputController;
107 class WebSpeechInputListener;
108 class WebSpeechRecognizer;
109 class WebStorageNamespace;
112 class WebUserMediaClient;
113 struct WebActiveWheelFlingParameters;
114 struct WebCursorInfo;
115 struct WebDateTimeChooserParams;
116 struct WebFileChooserParams;
117 struct WebFindOptions;
118 struct WebMediaPlayerAction;
119 struct WebPluginAction;
121 struct WebWindowFeatures;
123 #if defined(OS_ANDROID)
124 class WebHitTestResult;
128 namespace webkit_glue {
129 class WebURLResponseExtraDataImpl;
133 class BrowserPluginManager;
134 class DeviceOrientationDispatcher;
137 class DomAutomationController;
138 class ExternalPopupMenu;
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 RendererPpapiHost;
157 class RendererWebColorChooserImpl;
158 class RenderWidgetFullscreenPepper;
159 class SpeechRecognitionDispatcher;
160 class StatsCollectionController;
161 class WebPluginDelegateProxy;
162 struct CustomContextMenuContext;
165 struct FileChooserParams;
166 struct RenderViewImplParams;
168 #if defined(OS_ANDROID)
169 class RendererMediaPlayerManager;
170 class WebMediaPlayerProxyAndroid;
174 // RenderView is an object that manages a WebView object, and provides a
175 // communication interface with an embedding application process
177 class CONTENT_EXPORT RenderViewImpl
178 : public RenderWidget,
179 NON_EXPORTED_BASE(public WebKit::WebViewClient),
180 NON_EXPORTED_BASE(public WebKit::WebFrameClient),
181 NON_EXPORTED_BASE(public WebKit::WebPageSerializerClient),
183 NON_EXPORTED_BASE(public WebMediaPlayerDelegate),
184 public base::SupportsWeakPtr<RenderViewImpl> {
186 // Creates a new RenderView. |opener_id| is the routing ID of the RenderView
187 // responsible for creating this RenderView.
188 static RenderViewImpl* Create(
190 const RendererPreferences& renderer_prefs,
191 const WebPreferences& webkit_prefs,
193 int32 main_frame_routing_id,
195 int64 session_storage_namespace_id,
196 const string16& frame_name,
197 bool is_renderer_created,
201 const WebKit::WebScreenInfo& screen_info,
202 AccessibilityMode accessibility_mode,
203 bool allow_partial_swap);
205 // Used by content_layouttest_support to hook into the creation of
207 static void InstallCreateHook(
208 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*));
210 // Returns the RenderViewImpl containing the given WebView.
211 static RenderViewImpl* FromWebView(WebKit::WebView* webview);
213 // Returns the RenderViewImpl for the given routing ID.
214 static RenderViewImpl* FromRoutingID(int routing_id);
216 // May return NULL when the view is closing.
217 WebKit::WebView* webview() const;
219 int history_list_offset() const { return history_list_offset_; }
221 const WebPreferences& webkit_preferences() const {
222 return webkit_preferences_;
225 void set_send_content_state_immediately(bool value) {
226 send_content_state_immediately_ = value;
229 MediaStreamDispatcher* media_stream_dispatcher() {
230 return media_stream_dispatcher_;
233 MouseLockDispatcher* mouse_lock_dispatcher() {
234 return mouse_lock_dispatcher_;
237 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
239 // Lazily initialize this view's BrowserPluginManager and return it.
240 BrowserPluginManager* GetBrowserPluginManager();
242 // Functions to add and remove observers for this object.
243 void AddObserver(RenderViewObserver* observer);
244 void RemoveObserver(RenderViewObserver* observer);
246 // Returns the StatsCollectionObserver associated with this view, or NULL
247 // if one wasn't created;
248 StatsCollectionObserver* GetStatsCollectionObserver() {
249 return stats_collection_observer_.get();
252 // Adds the given file chooser request to the file_chooser_completion_ queue
253 // (see that var for more) and requests the chooser be displayed if there are
254 // no other waiting items in the queue.
256 // Returns true if the chooser was successfully scheduled. False means we
257 // didn't schedule anything.
258 bool ScheduleFileChooser(const FileChooserParams& params,
259 WebKit::WebFileChooserCompletion* completion);
261 void LoadNavigationErrorPage(
262 WebKit::WebFrame* frame,
263 const WebKit::WebURLRequest& failed_request,
264 const WebKit::WebURLError& error,
265 const std::string& html,
268 // Plugin-related functions --------------------------------------------------
270 #if defined(ENABLE_PLUGINS)
271 // Indicates that the given instance has been created.
272 void PepperInstanceCreated(PepperPluginInstanceImpl* instance);
274 // Indicates that the given instance is being destroyed. This is called from
275 // the destructor, so it's important that the instance is not dereferenced
277 void PepperInstanceDeleted(PepperPluginInstanceImpl* instance);
279 // Notifies that |instance| has changed the cursor.
280 // This will update the cursor appearance if it is currently over the plugin
282 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
283 const WebKit::WebCursorInfo& cursor);
285 // Notifies that |instance| has received a mouse event.
286 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
288 // Notification that the given plugin is focused or unfocused.
289 void PepperFocusChanged(PepperPluginInstanceImpl* instance, bool focused);
291 // Informs the render view that a PPAPI plugin has changed text input status.
292 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
293 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
295 // Cancels current composition.
296 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
298 // Informs the render view that a PPAPI plugin has changed selection.
299 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
301 // Creates a fullscreen container for a pepper plugin instance.
302 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
303 PepperPluginInstanceImpl* plugin);
305 // Notification that a PPAPI plugin has been created.
306 void PepperPluginCreated(RendererPpapiHost* host);
308 // Retrieves the current caret position if a PPAPI plugin has focus.
309 bool GetPepperCaretBounds(gfx::Rect* rect);
311 bool IsPepperAcceptingCompositionEvents() const;
313 // Notification that the given plugin has crashed.
314 void PluginCrashed(const base::FilePath& plugin_path,
315 base::ProcessId plugin_pid);
317 // Simulates IME events for testing purpose.
318 void SimulateImeSetComposition(
319 const string16& text,
320 const std::vector<WebKit::WebCompositionUnderline>& underlines,
323 void SimulateImeConfirmComposition(const string16& text,
324 const gfx::Range& replacement_range);
326 #if defined(OS_MACOSX) || defined(OS_WIN)
327 // Informs the render view that the given plugin has gained or lost focus.
328 void PluginFocusChanged(bool focused, int plugin_id);
331 #if defined(OS_MACOSX)
332 // Starts plugin IME.
333 void StartPluginIme();
336 void RegisterPluginDelegate(WebPluginDelegateProxy* delegate);
337 void UnregisterPluginDelegate(WebPluginDelegateProxy* delegate);
339 // Helper function to retrieve information about a plugin for a URL and mime
340 // type. Returns false if no plugin was found.
341 // |actual_mime_type| is the actual mime type supported by the
342 // plugin found that match the URL given (one for each item in
344 bool GetPluginInfo(const GURL& url,
345 const GURL& page_url,
346 const std::string& mime_type,
347 WebPluginInfo* plugin_info,
348 std::string* actual_mime_type);
350 #endif // ENABLE_PLUGINS
352 void TransferActiveWheelFlingAnimation(
353 const WebKit::WebActiveWheelFlingParameters& params);
355 // Returns true if the focused element is editable text from the perspective
356 // of IME support (also used for on-screen keyboard). Works correctly inside
357 // supported PPAPI plug-ins.
358 bool HasIMETextFocus();
360 // Callback for use with GetWindowSnapshot.
361 typedef base::Callback<void(
362 const gfx::Size&, const std::vector<unsigned char>&)>
363 WindowSnapshotCallback;
365 void GetWindowSnapshot(const WindowSnapshotCallback& callback);
367 // Dispatches the current navigation state to the browser. Called on a
368 // periodic timer so we don't send too many messages.
369 void SyncNavigationState();
371 // Returns the length of the session history of this RenderView. Note that
372 // this only coincides with the actual length of the session history if this
373 // RenderView is the currently active RenderView of a WebContents.
374 unsigned GetLocalSessionHistoryLengthForTesting() const;
376 // Invokes OnSetFocus and marks the widget as active depending on the value
377 // of |enable|. This is used for layout tests that need to control the focus
378 // synchronously from the renderer.
379 void SetFocusAndActivateForTesting(bool enable);
381 // Change the device scale factor and force the compositor to resize.
382 void SetDeviceScaleFactorForTesting(float factor);
384 // Used to force the size of a window when running layout tests.
385 void ForceResizeForTesting(const gfx::Size& new_size);
387 void UseSynchronousResizeModeForTesting(bool enable);
389 // Control autoresize mode.
390 void EnableAutoResizeForTesting(const gfx::Size& min_size,
391 const gfx::Size& max_size);
392 void DisableAutoResizeForTesting(const gfx::Size& new_size);
394 // Overrides the MediaStreamClient used when creating MediaStream players.
395 // Must be called before any players are created.
396 void SetMediaStreamClientForTesting(MediaStreamClient* media_stream_client);
398 // Determines whether plugins are allowed to enter fullscreen mode.
399 bool IsPluginFullscreenAllowed();
401 // IPC::Listener implementation ----------------------------------------------
403 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
405 // WebKit::WebWidgetClient implementation ------------------------------------
407 // Most methods are handled by RenderWidget.
408 virtual void didFocus();
409 virtual void didBlur();
410 virtual void show(WebKit::WebNavigationPolicy policy);
411 virtual void runModal();
412 virtual bool enterFullScreen();
413 virtual void exitFullScreen();
414 virtual bool requestPointerLock();
415 virtual void requestPointerUnlock();
416 virtual bool isPointerLocked();
417 virtual void didActivateCompositor(int input_handler_identifier);
418 virtual void didHandleGestureEvent(const WebKit::WebGestureEvent& event,
419 bool event_cancelled) OVERRIDE;
420 virtual void initializeLayerTreeView() OVERRIDE;
422 // WebKit::WebViewClient implementation --------------------------------------
424 virtual WebKit::WebView* createView(
425 WebKit::WebFrame* creator,
426 const WebKit::WebURLRequest& request,
427 const WebKit::WebWindowFeatures& features,
428 const WebKit::WebString& frame_name,
429 WebKit::WebNavigationPolicy policy);
430 virtual WebKit::WebWidget* createPopupMenu(WebKit::WebPopupType popup_type);
431 virtual WebKit::WebExternalPopupMenu* createExternalPopupMenu(
432 const WebKit::WebPopupMenuInfo& popup_menu_info,
433 WebKit::WebExternalPopupMenuClient* popup_menu_client);
434 virtual WebKit::WebStorageNamespace* createSessionStorageNamespace();
435 virtual bool shouldReportDetailedMessageForSource(
436 const WebKit::WebString& source);
437 virtual void didAddMessageToConsole(
438 const WebKit::WebConsoleMessage& message,
439 const WebKit::WebString& source_name,
440 unsigned source_line,
441 const WebKit::WebString& stack_trace);
442 virtual void printPage(WebKit::WebFrame* frame);
443 virtual WebKit::WebNotificationPresenter* notificationPresenter();
444 virtual bool enumerateChosenDirectory(
445 const WebKit::WebString& path,
446 WebKit::WebFileChooserCompletion* chooser_completion);
447 virtual void initializeHelperPluginWebFrame(WebKit::WebHelperPlugin*);
448 virtual void didStartLoading();
449 virtual void didStopLoading();
450 virtual void didChangeLoadProgress(WebKit::WebFrame* frame,
451 double load_progress);
452 virtual void didCancelCompositionOnSelectionChange();
453 virtual void didChangeSelection(bool is_selection_empty);
454 virtual void didExecuteCommand(const WebKit::WebString& command_name);
455 virtual bool handleCurrentKeyboardEvent();
456 virtual WebKit::WebColorChooser* createColorChooser(
457 WebKit::WebColorChooserClient*, const WebKit::WebColor& initial_color);
458 virtual bool runFileChooser(
459 const WebKit::WebFileChooserParams& params,
460 WebKit::WebFileChooserCompletion* chooser_completion);
461 virtual void runModalAlertDialog(WebKit::WebFrame* frame,
462 const WebKit::WebString& message);
463 virtual bool runModalConfirmDialog(WebKit::WebFrame* frame,
464 const WebKit::WebString& message);
465 virtual bool runModalPromptDialog(WebKit::WebFrame* frame,
466 const WebKit::WebString& message,
467 const WebKit::WebString& default_value,
468 WebKit::WebString* actual_value);
469 virtual bool runModalBeforeUnloadDialog(WebKit::WebFrame* frame,
471 const WebKit::WebString& message);
473 virtual bool runModalBeforeUnloadDialog(WebKit::WebFrame* frame,
474 const WebKit::WebString& message);
475 virtual void showContextMenu(WebKit::WebFrame* frame,
476 const WebKit::WebContextMenuData& data);
477 virtual void clearContextMenu();
478 virtual void setStatusText(const WebKit::WebString& text);
479 virtual void setMouseOverURL(const WebKit::WebURL& url);
480 virtual void setKeyboardFocusURL(const WebKit::WebURL& url);
481 virtual void startDragging(WebKit::WebFrame* frame,
482 const WebKit::WebDragData& data,
483 WebKit::WebDragOperationsMask mask,
484 const WebKit::WebImage& image,
485 const WebKit::WebPoint& imageOffset);
486 virtual bool acceptsLoadDrops();
487 virtual void focusNext();
488 virtual void focusPrevious();
489 virtual void focusedNodeChanged(const WebKit::WebNode& node);
490 virtual void numberOfWheelEventHandlersChanged(unsigned num_handlers);
491 virtual void didUpdateLayout();
492 #if defined(OS_ANDROID)
493 virtual bool didTapMultipleTargets(
494 const WebKit::WebGestureEvent& event,
495 const WebKit::WebVector<WebKit::WebRect>& target_rects);
497 virtual void navigateBackForwardSoon(int offset);
498 virtual int historyBackListCount();
499 virtual int historyForwardListCount();
500 virtual void postAccessibilityEvent(
501 const WebKit::WebAXObject& obj, WebKit::WebAXEvent event);
502 virtual void didUpdateInspectorSetting(const WebKit::WebString& key,
503 const WebKit::WebString& value);
504 virtual WebKit::WebGeolocationClient* geolocationClient();
505 virtual WebKit::WebSpeechInputController* speechInputController(
506 WebKit::WebSpeechInputListener* listener);
507 virtual WebKit::WebSpeechRecognizer* speechRecognizer();
508 virtual void zoomLimitsChanged(double minimum_level, double maximum_level);
509 virtual void zoomLevelChanged();
510 virtual double zoomLevelToZoomFactor(double zoom_level) const;
511 virtual double zoomFactorToZoomLevel(double factor) const;
512 virtual void registerProtocolHandler(const WebKit::WebString& scheme,
513 const WebKit::WebString& base_url,
514 const WebKit::WebString& url,
515 const WebKit::WebString& title);
516 virtual WebKit::WebPageVisibilityState visibilityState() const;
517 virtual WebKit::WebUserMediaClient* userMediaClient();
518 virtual WebKit::WebMIDIClient* webMIDIClient();
519 virtual void draggableRegionsChanged();
521 #if defined(OS_ANDROID)
522 virtual void scheduleContentIntent(const WebKit::WebURL& intent);
523 virtual void cancelScheduledContentIntents();
524 virtual WebKit::WebContentDetectionResult detectContentAround(
525 const WebKit::WebHitTestResult& touch_hit);
527 // Only used on Android since all other platforms implement
528 // date and time input fields using MULTIPLE_FIELDS_UI
529 virtual bool openDateTimeChooser(const WebKit::WebDateTimeChooserParams&,
530 WebKit::WebDateTimeChooserCompletion*);
531 virtual void didScrollWithKeyboard(const WebKit::WebSize& delta);
534 // WebKit::WebFrameClient implementation -------------------------------------
536 virtual WebKit::WebMediaPlayer* createMediaPlayer(
537 WebKit::WebFrame* frame,
538 const WebKit::WebURL& url,
539 WebKit::WebMediaPlayerClient* client);
540 virtual WebKit::WebCookieJar* cookieJar(WebKit::WebFrame* frame);
541 virtual void didAccessInitialDocument(WebKit::WebFrame* frame);
542 virtual void didDisownOpener(WebKit::WebFrame* frame);
543 virtual void frameDetached(WebKit::WebFrame* frame);
544 virtual void willClose(WebKit::WebFrame* frame);
545 virtual void didMatchCSS(
546 WebKit::WebFrame* frame,
547 const WebKit::WebVector<WebKit::WebString>& newly_matching_selectors,
548 const WebKit::WebVector<WebKit::WebString>& stopped_matching_selectors);
550 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
551 virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
552 WebKit::WebFrame* frame,
553 WebKit::WebDataSource::ExtraData* extraData,
554 const WebKit::WebURLRequest& request,
555 WebKit::WebNavigationType type,
556 WebKit::WebNavigationPolicy default_policy,
559 virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
560 WebKit::WebFrame* frame,
561 const WebKit::WebURLRequest& request,
562 WebKit::WebNavigationType type,
563 WebKit::WebNavigationPolicy default_policy,
565 virtual void willSendSubmitEvent(WebKit::WebFrame* frame,
566 const WebKit::WebFormElement& form);
567 virtual void willSubmitForm(WebKit::WebFrame* frame,
568 const WebKit::WebFormElement& form);
569 virtual void didCreateDataSource(WebKit::WebFrame* frame,
570 WebKit::WebDataSource* datasource);
571 virtual void didStartProvisionalLoad(WebKit::WebFrame* frame);
572 virtual void didReceiveServerRedirectForProvisionalLoad(
573 WebKit::WebFrame* frame);
574 virtual void didFailProvisionalLoad(WebKit::WebFrame* frame,
575 const WebKit::WebURLError& error);
576 virtual void didCommitProvisionalLoad(WebKit::WebFrame* frame,
577 bool is_new_navigation);
578 virtual void didClearWindowObject(WebKit::WebFrame* frame);
579 virtual void didCreateDocumentElement(WebKit::WebFrame* frame);
580 virtual void didReceiveTitle(WebKit::WebFrame* frame,
581 const WebKit::WebString& title,
582 WebKit::WebTextDirection direction);
583 virtual void didChangeIcon(WebKit::WebFrame*,
584 WebKit::WebIconURL::Type);
585 virtual void didFinishDocumentLoad(WebKit::WebFrame* frame);
586 virtual void didHandleOnloadEvents(WebKit::WebFrame* frame);
587 virtual void didFailLoad(WebKit::WebFrame* frame,
588 const WebKit::WebURLError& error);
589 virtual void didFinishLoad(WebKit::WebFrame* frame);
590 virtual void didNavigateWithinPage(WebKit::WebFrame* frame,
591 bool is_new_navigation);
592 virtual void didUpdateCurrentHistoryItem(WebKit::WebFrame* frame);
593 virtual void willSendRequest(WebKit::WebFrame* frame,
595 WebKit::WebURLRequest& request,
596 const WebKit::WebURLResponse& redirect_response);
597 virtual void didReceiveResponse(WebKit::WebFrame* frame,
599 const WebKit::WebURLResponse& response);
600 virtual void didFinishResourceLoad(WebKit::WebFrame* frame,
601 unsigned identifier);
602 virtual void didLoadResourceFromMemoryCache(
603 WebKit::WebFrame* frame,
604 const WebKit::WebURLRequest& request,
605 const WebKit::WebURLResponse&);
606 virtual void didDisplayInsecureContent(WebKit::WebFrame* frame);
607 virtual void didRunInsecureContent(
608 WebKit::WebFrame* frame,
609 const WebKit::WebSecurityOrigin& origin,
610 const WebKit::WebURL& target);
611 virtual void didExhaustMemoryAvailableForScript(WebKit::WebFrame* frame);
612 virtual void didCreateScriptContext(WebKit::WebFrame* frame,
613 v8::Handle<v8::Context>,
616 virtual void willReleaseScriptContext(WebKit::WebFrame* frame,
617 v8::Handle<v8::Context>,
619 virtual void didChangeScrollOffset(WebKit::WebFrame* frame);
620 virtual void willInsertBody(WebKit::WebFrame* frame);
621 virtual void didFirstVisuallyNonEmptyLayout(WebKit::WebFrame*);
622 virtual void didChangeContentsSize(WebKit::WebFrame* frame,
623 const WebKit::WebSize& size);
624 virtual void reportFindInPageMatchCount(int request_id,
627 virtual void reportFindInPageSelection(int request_id,
628 int active_match_ordinal,
629 const WebKit::WebRect& sel);
630 virtual void requestStorageQuota(
631 WebKit::WebFrame* frame,
632 WebKit::WebStorageQuotaType type,
633 unsigned long long requested_size,
634 WebKit::WebStorageQuotaCallbacks* callbacks);
635 virtual void willOpenSocketStream(
636 WebKit::WebSocketStreamHandle* handle);
637 virtual void willStartUsingPeerConnectionHandler(WebKit::WebFrame* frame,
638 WebKit::WebRTCPeerConnectionHandler* handler);
639 virtual bool willCheckAndDispatchMessageEvent(
640 WebKit::WebFrame* sourceFrame,
641 WebKit::WebFrame* targetFrame,
642 WebKit::WebSecurityOrigin targetOrigin,
643 WebKit::WebDOMMessageEvent event);
644 virtual WebKit::WebString acceptLanguages();
645 virtual WebKit::WebString userAgentOverride(
646 WebKit::WebFrame* frame,
647 const WebKit::WebURL& url);
648 virtual WebKit::WebString doNotTrackValue(WebKit::WebFrame* frame);
649 virtual bool allowWebGL(WebKit::WebFrame* frame, bool default_value);
650 virtual void didLoseWebGLContext(
651 WebKit::WebFrame* frame,
652 int arb_robustness_status_code);
654 // WebKit::WebPageSerializerClient implementation ----------------------------
656 virtual void didSerializeDataForFrame(
657 const WebKit::WebURL& frame_url,
658 const WebKit::WebCString& data,
659 PageSerializationStatus status) OVERRIDE;
661 // RenderView implementation -------------------------------------------------
663 virtual bool Send(IPC::Message* message) OVERRIDE;
664 virtual int GetRoutingID() const OVERRIDE;
665 virtual int GetPageId() const OVERRIDE;
666 virtual gfx::Size GetSize() const OVERRIDE;
667 virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
668 virtual void SetWebkitPreferences(const WebPreferences& preferences) OVERRIDE;
669 virtual WebKit::WebView* GetWebView() OVERRIDE;
670 virtual WebKit::WebNode GetFocusedNode() const OVERRIDE;
671 virtual WebKit::WebNode GetContextMenuNode() const OVERRIDE;
672 virtual bool IsEditableNode(const WebKit::WebNode& node) const OVERRIDE;
673 virtual WebKit::WebPlugin* CreatePlugin(
674 WebKit::WebFrame* frame,
675 const WebPluginInfo& info,
676 const WebKit::WebPluginParams& params) OVERRIDE;
677 virtual void EvaluateScript(const string16& frame_xpath,
678 const string16& jscript,
680 bool notify_result) OVERRIDE;
681 virtual bool ShouldDisplayScrollbars(int width, int height) const OVERRIDE;
682 virtual int GetEnabledBindings() const OVERRIDE;
683 virtual bool GetContentStateImmediately() const OVERRIDE;
684 virtual float GetFilteredTimePerFrame() const OVERRIDE;
685 virtual int ShowContextMenu(ContextMenuClient* client,
686 const ContextMenuParams& params) OVERRIDE;
687 virtual void CancelContextMenu(int request_id) OVERRIDE;
688 virtual WebKit::WebPageVisibilityState GetVisibilityState() const OVERRIDE;
689 virtual void RunModalAlertDialog(WebKit::WebFrame* frame,
690 const WebKit::WebString& message) OVERRIDE;
691 virtual void LoadURLExternally(
692 WebKit::WebFrame* frame,
693 const WebKit::WebURLRequest& request,
694 WebKit::WebNavigationPolicy policy) OVERRIDE;
695 virtual void DidStartLoading() OVERRIDE;
696 virtual void DidStopLoading() OVERRIDE;
697 virtual void Repaint(const gfx::Size& size) OVERRIDE;
698 virtual void SetEditCommandForNextKeyEvent(const std::string& name,
699 const std::string& value) OVERRIDE;
700 virtual void ClearEditCommands() OVERRIDE;
701 virtual SSLStatus GetSSLStatusOfFrame(WebKit::WebFrame* frame) const OVERRIDE;
702 virtual const std::string& GetAcceptLanguages() const OVERRIDE;
703 #if defined(OS_ANDROID)
704 virtual void UpdateTopControlsState(TopControlsState constraints,
705 TopControlsState current,
706 bool animate) OVERRIDE;
709 // WebMediaPlayerDelegate implementation -----------------------
711 virtual void DidPlay(WebKit::WebMediaPlayer* player) OVERRIDE;
712 virtual void DidPause(WebKit::WebMediaPlayer* player) OVERRIDE;
713 virtual void PlayerGone(WebKit::WebMediaPlayer* player) OVERRIDE;
715 // Please do not add your stuff randomly to the end here. If there is an
716 // appropriate section, add it there. If not, there are some random functions
717 // nearer to the top you can add it to.
719 // Cannot use std::set unfortunately since linked_ptr<> does not support
721 typedef std::vector<linked_ptr<ImageResourceFetcher> >
722 ImageResourceFetcherList;
725 // RenderWidget overrides:
726 virtual void Close() OVERRIDE;
727 virtual void OnResize(const ViewMsg_Resize_Params& params) OVERRIDE;
728 virtual void DidInitiatePaint() OVERRIDE;
729 virtual void DidFlushPaint() OVERRIDE;
730 virtual PepperPluginInstanceImpl* GetBitmapForOptimizedPluginPaint(
731 const gfx::Rect& paint_bounds,
735 float* scale_factor) OVERRIDE;
736 virtual gfx::Vector2d GetScrollOffset() OVERRIDE;
737 virtual void DidHandleKeyEvent() OVERRIDE;
738 virtual bool WillHandleMouseEvent(
739 const WebKit::WebMouseEvent& event) OVERRIDE;
740 virtual bool WillHandleKeyEvent(
741 const WebKit::WebKeyboardEvent& event) OVERRIDE;
742 virtual bool WillHandleGestureEvent(
743 const WebKit::WebGestureEvent& event) OVERRIDE;
744 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) OVERRIDE;
745 virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) OVERRIDE;
746 virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const OVERRIDE;
747 virtual void OnSetFocus(bool enable) OVERRIDE;
748 virtual void OnWasHidden() OVERRIDE;
749 virtual void OnWasShown(bool needs_repainting) OVERRIDE;
750 virtual GURL GetURLForGraphicsContext3D() OVERRIDE;
751 virtual bool ForceCompositingModeEnabled() OVERRIDE;
752 virtual void OnImeSetComposition(
753 const string16& text,
754 const std::vector<WebKit::WebCompositionUnderline>& underlines,
756 int selection_end) OVERRIDE;
757 virtual void OnImeConfirmComposition(const string16& text,
758 const gfx::Range& replacement_range,
759 bool keep_selection) OVERRIDE;
760 virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE;
761 virtual ui::TextInputType GetTextInputType() OVERRIDE;
762 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) OVERRIDE;
763 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
764 virtual void GetCompositionCharacterBounds(
765 std::vector<gfx::Rect>* character_bounds) OVERRIDE;
766 virtual void GetCompositionRange(gfx::Range* range) OVERRIDE;
768 virtual bool CanComposeInline() OVERRIDE;
769 virtual void DidCommitCompositorFrame() OVERRIDE;
770 virtual void InstrumentWillBeginFrame() OVERRIDE;
771 virtual void InstrumentDidBeginFrame() OVERRIDE;
772 virtual void InstrumentDidCancelFrame() OVERRIDE;
773 virtual void InstrumentWillComposite() OVERRIDE;
774 virtual bool AllowPartialSwap() const OVERRIDE;
777 explicit RenderViewImpl(RenderViewImplParams* params);
779 void Initialize(RenderViewImplParams* params);
780 virtual void SetScreenMetricsEmulationParameters(
781 float device_scale_factor, float root_layer_scale) OVERRIDE;
783 // Do not delete directly. This class is reference counted.
784 virtual ~RenderViewImpl();
788 friend class ExternalPopupMenuTest;
789 friend class PepperDeviceTest;
790 friend class RendererAccessibilityTest;
791 friend class RenderViewTest;
793 // TODO(nasko): Temporarily friend RenderFrameImpl, so we don't duplicate
794 // utility functions needed in both classes, while we move frame specific
795 // code away from this class.
796 friend class RenderFrameImpl;
798 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
799 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
800 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
801 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
802 AccessibilityMessagesQueueWhileSwappedOut);
803 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, DecideNavigationPolicyForWebUI);
804 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
805 DidFailProvisionalLoadWithErrorForError);
806 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
807 DidFailProvisionalLoadWithErrorForCancellation);
808 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
809 DontIgnoreBackAfterNavEntryLimit);
810 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ImeComposition);
811 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, InsertCharacters);
812 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, JSBlockSentAfterPageLoad);
813 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, LastCommittedUpdateState);
814 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnExtendSelectionAndDelete);
815 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnHandleKeyboardEvent);
816 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnImeTypeChanged);
817 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavStateChanged);
818 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnSetTextDirection);
819 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnUpdateWebPreferences);
820 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendSwapOutACK);
821 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ReloadWhileSwappedOut);
822 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
823 SetEditableSelectionAndComposition);
824 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, StaleNavigationsIgnored);
825 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, UpdateTargetURLWithInvalidURL);
826 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
827 GetCompositionCharacterBoundsTest);
828 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavigationHttpPost);
829 #if defined(OS_MACOSX)
830 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, MacTestCmdUp);
832 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SetHistoryLengthAndPrune);
833 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ZoomLimit);
834 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, NavigateFrame);
835 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
836 ShouldUpdateSelectionTextFromContextMenuParams);
837 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, BasicRenderFrame);
838 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, TextInputTypeWithPepper);
839 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, Suppresses);
840 FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, DoesNotSuppress);
842 typedef std::map<GURL, double> HostZoomLevels;
850 static WebKit::WebReferrerPolicy GetReferrerPolicyFromRequest(
851 WebKit::WebFrame* frame,
852 const WebKit::WebURLRequest& request);
854 static Referrer GetReferrerFromRequest(
855 WebKit::WebFrame* frame,
856 const WebKit::WebURLRequest& request);
858 static webkit_glue::WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
859 const WebKit::WebURLResponse& response);
861 void UpdateURL(WebKit::WebFrame* frame);
862 void UpdateTitle(WebKit::WebFrame* frame, const string16& title,
863 WebKit::WebTextDirection title_direction);
864 void UpdateSessionHistory(WebKit::WebFrame* frame);
865 void SendUpdateState(const WebKit::WebHistoryItem& item);
867 // Update current main frame's encoding and send it to browser window.
868 // Since we want to let users see the right encoding info from menu
869 // before finishing loading, we call the UpdateEncoding in
870 // a) function:DidCommitLoadForFrame. When this function is called,
871 // that means we have got first data. In here we try to get encoding
872 // of page if it has been specified in http header.
873 // b) function:DidReceiveTitle. When this function is called,
874 // that means we have got specified title. Because in most of webpages,
875 // title tags will follow meta tags. In here we try to get encoding of
876 // page if it has been specified in meta tag.
877 // c) function:DidFinishDocumentLoadForFrame. When this function is
878 // called, that means we have got whole html page. In here we should
879 // finally get right encoding of page.
880 void UpdateEncoding(WebKit::WebFrame* frame,
881 const std::string& encoding_name);
883 void OpenURL(WebKit::WebFrame* frame,
885 const Referrer& referrer,
886 WebKit::WebNavigationPolicy policy);
888 bool RunJavaScriptMessage(JavaScriptMessageType type,
889 const string16& message,
890 const string16& default_value,
891 const GURL& frame_url,
894 // Sends a message and runs a nested message loop.
895 bool SendAndRunNestedMessageLoop(IPC::SyncMessage* message);
897 // Called when the "pinned to left/right edge" state needs to be updated.
898 void UpdateScrollState(WebKit::WebFrame* frame);
900 // IPC message handlers ------------------------------------------------------
902 // The documentation for these functions should be in
903 // content/common/*_messages.h for the message that the function is handling.
908 void OnExecuteEditCommand(const std::string& name, const std::string& value);
909 void OnMoveCaret(const gfx::Point& point);
911 void OnPasteAndMatchStyle();
913 void OnReplace(const string16& text);
914 void OnReplaceMisspelling(const string16& text);
915 void OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect);
917 void OnSelectRange(const gfx::Point& start, const gfx::Point& end);
918 void OnSetEditCommandsForNextKeyEvent(const EditCommands& edit_commands);
921 void OnAllowBindings(int enabled_bindings_flags);
922 void OnAllowScriptToClose(bool script_can_close);
923 void OnCancelDownload(int32 download_id);
924 void OnClearFocusedNode();
926 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
927 void OnShowContextMenu(const gfx::Point& location);
928 void OnCopyImageAt(int x, int y);
929 void OnCSSInsertRequest(const string16& frame_xpath,
930 const std::string& css);
931 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
933 void OnSetName(const std::string& name);
934 void OnDeterminePageLanguage();
935 void OnDisableScrollbarsForSmallWindows(
936 const gfx::Size& disable_scrollbars_size_limit);
937 void OnDragSourceEndedOrMoved(const gfx::Point& client_point,
938 const gfx::Point& screen_point,
940 WebKit::WebDragOperation drag_operation);
941 void OnDragSourceSystemDragEnded();
942 void OnDragTargetDrop(const gfx::Point& client_pt,
943 const gfx::Point& screen_pt,
945 void OnDragTargetDragEnter(const DropData& drop_data,
946 const gfx::Point& client_pt,
947 const gfx::Point& screen_pt,
948 WebKit::WebDragOperationsMask operations_allowed,
950 void OnDragTargetDragLeave();
951 void OnDragTargetDragOver(const gfx::Point& client_pt,
952 const gfx::Point& screen_pt,
953 WebKit::WebDragOperationsMask operations_allowed,
955 void OnEnablePreferredSizeChangedMode();
956 void OnEnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
957 void OnDisableAutoResize(const gfx::Size& new_size);
958 void OnEnumerateDirectoryResponse(int id,
959 const std::vector<base::FilePath>& paths);
960 void OnExtendSelectionAndDelete(int before, int after);
961 void OnFileChooserResponse(
962 const std::vector<ui::SelectedFileInfo>& files);
963 void OnFind(int request_id, const string16&, const WebKit::WebFindOptions&);
964 void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url);
965 void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
966 const std::vector<GURL>& links,
967 const std::vector<base::FilePath>& local_paths,
968 const base::FilePath& local_directory_name);
969 void OnMediaPlayerActionAt(const gfx::Point& location,
970 const WebKit::WebMediaPlayerAction& action);
971 void OnOrientationChangeEvent(int orientation);
972 void OnPluginActionAt(const gfx::Point& location,
973 const WebKit::WebPluginAction& action);
974 void OnMoveOrResizeStarted();
975 void OnNavigate(const ViewMsg_Navigate_Params& params);
976 void OnPostMessageEvent(const ViewMsg_PostMessage_Params& params);
977 void OnReleaseDisambiguationPopupDIB(TransportDIB::Handle dib_handle);
978 void OnReloadFrame();
979 void OnResetPageEncodingToDefault();
980 void OnScriptEvalRequest(const string16& frame_xpath,
981 const string16& jscript,
984 void OnSetAccessibilityMode(AccessibilityMode new_mode);
985 void OnSetActive(bool active);
986 void OnSetAltErrorPageURL(const GURL& gurl);
987 void OnSetBackground(const SkBitmap& background);
988 void OnSetCompositionFromExistingText(
990 const std::vector<WebKit::WebCompositionUnderline>& underlines);
991 void OnExitFullscreen();
992 void OnSetEditableSelectionOffsets(int start, int end);
993 void OnSetHistoryLengthAndPrune(int history_length, int32 minimum_page_id);
994 void OnSetInitialFocus(bool reverse);
995 void OnSetPageEncoding(const std::string& encoding_name);
996 void OnSetRendererPrefs(const RendererPreferences& renderer_prefs);
997 void OnSetWebUIProperty(const std::string& name, const std::string& value);
998 void OnSetZoomLevel(double zoom_level);
999 void OnSetZoomLevelForLoadingURL(const GURL& url, double zoom_level);
1000 void OnShouldClose();
1002 void OnStopFinding(StopFindAction action);
1004 void OnThemeChanged();
1005 void OnUpdateTargetURLAck();
1006 void OnUpdateTimezone();
1007 void OnUpdateWebPreferences(const WebPreferences& prefs);
1008 void OnZoom(PageZoom zoom);
1009 void OnZoomFactor(PageZoom zoom, int zoom_center_x, int zoom_center_y);
1010 void OnEnableViewSourceMode();
1011 void OnDisownOpener();
1012 void OnWindowSnapshotCompleted(const int snapshot_id,
1013 const gfx::Size& size, const std::vector<unsigned char>& png);
1014 #if defined(OS_ANDROID)
1015 void OnActivateNearestFindResult(int request_id, float x, float y);
1016 void OnFindMatchRects(int current_version);
1017 void OnSelectPopupMenuItems(bool canceled,
1018 const std::vector<int>& selected_indices);
1019 void OnUndoScrollFocusedEditableNodeIntoRect();
1020 void OnUpdateTopControlsState(bool enable_hiding,
1021 bool enable_showing,
1023 void OnPauseVideo();
1025 #elif defined(OS_MACOSX)
1026 void OnCopyToFindPboard();
1027 void OnPluginImeCompositionCompleted(const string16& text, int plugin_id);
1028 void OnSelectPopupMenuItem(int selected_index);
1029 void OnSetInLiveResize(bool in_live_resize);
1030 void OnSetWindowVisibility(bool visible);
1031 void OnWindowFrameChanged(const gfx::Rect& window_frame,
1032 const gfx::Rect& view_frame);
1035 // Adding a new message handler? Please add it in alphabetical order above
1036 // and put it in the same position in the .cc file.
1038 // Misc private functions ----------------------------------------------------
1039 void ZoomFactorHelper(PageZoom zoom, int zoom_center_x, int zoom_center_y,
1040 float scaling_increment);
1042 void AltErrorPageFinished(WebKit::WebFrame* frame,
1043 const WebKit::WebURLRequest& original_request,
1044 const WebKit::WebURLError& original_error,
1045 const std::string& html);
1047 // Check whether the preferred size has changed.
1048 void CheckPreferredSize();
1050 // Initializes |media_stream_client_|, returning true if successful. Returns
1051 // false if it wasn't possible to create a MediaStreamClient (e.g., WebRTC is
1052 // disabled) in which case |media_stream_client_| is NULL.
1053 bool InitializeMediaStreamClient();
1055 // This callback is triggered when DownloadFavicon completes, either
1056 // succesfully or with a failure. See DownloadFavicon for more
1058 void DidDownloadFavicon(ImageResourceFetcher* fetcher,
1059 const SkBitmap& image);
1061 // Requests to download a favicon image. When done, the RenderView is notified
1062 // by way of DidDownloadFavicon. Returns true if the request was successfully
1063 // started, false otherwise. id is used to uniquely identify the request and
1064 // passed back to the DidDownloadFavicon method. If the image has multiple
1065 // frames, the frame whose size is image_size is returned. If the image
1066 // doesn't have a frame at the specified size, the first is returned.
1067 bool DownloadFavicon(int id, const GURL& image_url, int image_size);
1069 GURL GetAlternateErrorPageURL(const GURL& failed_url,
1070 ErrorPageType error_type);
1072 // Locates a sub frame with given xpath
1073 WebKit::WebFrame* GetChildFrame(const string16& frame_xpath) const;
1075 // Returns the URL being loaded by the given frame's request.
1076 GURL GetLoadingUrl(WebKit::WebFrame* frame) const;
1078 // Should only be called if this object wraps a PluginDocument.
1079 WebKit::WebPlugin* GetWebPluginFromPluginDocument();
1081 // Returns true if the |params| navigation is to an entry that has been
1082 // cropped due to a recent navigation the browser did not know about.
1083 bool IsBackForwardToStaleEntry(const ViewMsg_Navigate_Params& params,
1086 bool MaybeLoadAlternateErrorPage(WebKit::WebFrame* frame,
1087 const WebKit::WebURLError& error,
1090 // Make this RenderView show an empty, unscriptable page.
1091 void NavigateToSwappedOutURL(WebKit::WebFrame* frame);
1093 // If we initiated a navigation, this function will populate |document_state|
1094 // with the navigation information saved in OnNavigate().
1095 void PopulateDocumentStateFromPending(DocumentState* document_state);
1097 // Returns a new NavigationState populated with the navigation information
1098 // saved in OnNavigate().
1099 NavigationState* CreateNavigationStateFromPending();
1101 // Processes the command-line flags --enable-viewport,
1102 // --enable-fixed-layout[=w,h] and --enable-pinch.
1103 void ProcessViewLayoutFlags(const CommandLine& command_line);
1105 #if defined(OS_ANDROID)
1106 // Launch an Android content intent with the given URL.
1107 void LaunchAndroidContentIntent(const GURL& intent_url, size_t request_id);
1110 // Sends a reply to the current find operation handling if it was a
1111 // synchronous find request.
1112 void SendFindReply(int request_id,
1115 const WebKit::WebRect& selection_rect,
1116 bool final_status_update);
1118 // Returns whether |params.selection_text| should be synchronized to the
1119 // browser before bringing up the context menu. Static for testing.
1120 static bool ShouldUpdateSelectionTextFromContextMenuParams(
1121 const string16& selection_text,
1122 size_t selection_text_offset,
1123 const gfx::Range& selection_range,
1124 const ContextMenuParams& params);
1126 // Starts nav_state_sync_timer_ if it isn't already running.
1127 void StartNavStateSyncTimerIfNecessary();
1129 // Dispatches the current state of selection on the webpage to the browser if
1131 // TODO(varunjain): delete this method once we figure out how to keep
1132 // selection handles in sync with the webpage.
1133 void SyncSelectionIfRequired();
1135 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1136 void UpdateFontRenderingFromRendererPrefs();
1138 void UpdateFontRenderingFromRendererPrefs() {}
1141 // Update the target url and tell the browser that the target URL has changed.
1142 // If |url| is empty, show |fallback_url|.
1143 void UpdateTargetURL(const GURL& url, const GURL& fallback_url);
1145 // Tells the browser what the new list of favicons for the webpage is.
1146 void SendUpdateFaviconURL(const std::vector<FaviconURL>& urls);
1148 // Invoked from DidStopLoading(). Sends the current list of loaded favicons to
1150 void DidStopLoadingIcons();
1152 // Coordinate conversion -----------------------------------------------------
1154 gfx::RectF ClientRectToPhysicalWindowRect(const gfx::RectF& rect) const;
1156 // Helper for LatencyInfo construction.
1157 int64 GetLatencyComponentId();
1159 // RenderFrameImpl accessible state ------------------------------------------
1160 // The following section is the set of methods that RenderFrameImpl needs
1161 // to access RenderViewImpl state. The set of state variables are page-level
1162 // specific, so they don't belong in RenderFrameImpl and should remain in
1164 ObserverList<RenderViewObserver>& observers() {
1168 // TODO(nasko): Remove this method when we move to frame proxy objects, since
1169 // the concept of swapped out will be eliminated.
1170 void set_is_swapped_out(bool swapped_out) {
1171 is_swapped_out_ = swapped_out;
1174 NavigationGesture navigation_gesture() {
1175 return navigation_gesture_;
1177 void set_navigation_gesture(NavigationGesture gesture) {
1178 navigation_gesture_ = gesture;
1181 // ---------------------------------------------------------------------------
1182 // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
1183 // it in the same order in the .cc file as it was in the header.
1184 // ---------------------------------------------------------------------------
1186 // Settings ------------------------------------------------------------------
1188 WebPreferences webkit_preferences_;
1189 RendererPreferences renderer_preferences_;
1191 HostZoomLevels host_zoom_levels_;
1193 // Whether content state (such as form state, scroll position and page
1194 // contents) should be sent to the browser immediately. This is normally
1195 // false, but set to true by some tests.
1196 bool send_content_state_immediately_;
1198 // Bitwise-ORed set of extra bindings that have been enabled. See
1199 // BindingsPolicy for details.
1200 int enabled_bindings_;
1202 // The alternate error page URL, if one exists.
1203 GURL alternate_error_page_url_;
1205 // If true, we send IPC messages when |preferred_size_| changes.
1206 bool send_preferred_size_changes_;
1208 // If non-empty, and |send_preferred_size_changes_| is true, disable drawing
1209 // scroll bars on windows smaller than this size. Used for windows that the
1210 // browser resizes to the size of the content, such as browser action popups.
1211 // If a render view is set to the minimum size of its content, webkit may add
1212 // scroll bars. This makes sense for fixed sized windows, but it does not
1213 // make sense when the size of the view was chosen to fit the content.
1214 // This setting ensures that no scroll bars are drawn. The size limit exists
1215 // because if the view grows beyond a size known to the browser, scroll bars
1217 gfx::Size disable_scrollbars_size_limit_;
1219 // Loading state -------------------------------------------------------------
1221 // True if the top level frame is currently being loaded.
1224 // The gesture that initiated the current navigation.
1225 NavigationGesture navigation_gesture_;
1228 bool opened_by_user_gesture_;
1230 // Whether this RenderView was created by a frame that was suppressing its
1231 // opener. If so, we may want to load pages in a separate process. See
1232 // decidePolicyForNavigation for details.
1233 bool opener_suppressed_;
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_;
1241 // Timer used to delay the updating of nav state (see SyncNavigationState).
1242 base::OneShotTimer<RenderViewImpl> nav_state_sync_timer_;
1244 // Page IDs ------------------------------------------------------------------
1245 // See documentation in RenderView.
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
1253 int32 last_page_id_sent_to_browser_;
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_;
1259 // The offset of the current item in the history list.
1260 int history_list_offset_;
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
1267 int history_list_length_;
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_;
1275 // Page info -----------------------------------------------------------------
1277 // The last gotten main frame's encoding.
1278 std::string last_encoding_name_;
1280 // UI state ------------------------------------------------------------------
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.
1289 // We don't need a queue of URLs to send, as only the latest is useful.
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_;
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
1302 // The URL the user's mouse is hovering over.
1303 GURL mouse_over_url_;
1305 // The URL that has keyboard focus.
1308 // The next target URL we want to send to the browser.
1309 GURL pending_target_url_;
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 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_;
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
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_;
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_;
1342 // View ----------------------------------------------------------------------
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_;
1348 // Used to delay determining the preferred size (to avoid intermediate
1349 // states for the sizes).
1350 base::OneShotTimer<RenderViewImpl> check_preferred_size_timer_;
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_;
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_;
1361 // Helper objects ------------------------------------------------------------
1363 scoped_ptr<RenderFrameImpl> main_render_frame_;
1365 RendererWebCookieJarImpl cookie_jar_;
1367 // The next group of objects all implement RenderViewObserver, so are deleted
1368 // along with the RenderView automatically. This is why we just store
1371 // Holds a reference to the service which provides desktop notifications.
1372 NotificationProvider* notification_provider_;
1374 // The geolocation dispatcher attached to this view, lazily initialized.
1375 GeolocationDispatcher* geolocation_dispatcher_;
1377 // The speech dispatcher attached to this view, lazily initialized.
1378 InputTagSpeechDispatcher* input_tag_speech_dispatcher_;
1380 // The speech recognition dispatcher attached to this view, lazily
1382 SpeechRecognitionDispatcher* speech_recognition_dispatcher_;
1384 // Device orientation dispatcher attached to this view; lazily initialized.
1385 DeviceOrientationDispatcher* device_orientation_dispatcher_;
1387 // MediaStream dispatcher attached to this view; lazily initialized.
1388 MediaStreamDispatcher* media_stream_dispatcher_;
1390 // BrowserPluginManager attached to this view; lazily initialized.
1391 scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
1393 // MediaStreamClient attached to this view; lazily initialized.
1394 MediaStreamClient* media_stream_client_;
1395 WebKit::WebUserMediaClient* web_user_media_client_;
1397 // MIDIClient attached to this view; lazily initialized.
1398 MIDIDispatcher* midi_dispatcher_;
1400 DevToolsAgent* devtools_agent_;
1402 // The current accessibility mode.
1403 AccessibilityMode accessibility_mode_;
1405 // Only valid if |accessibility_mode_| is anything other than
1406 // AccessibilityModeOff.
1407 RendererAccessibility* renderer_accessibility_;
1409 // Mouse Lock dispatcher attached to this view.
1410 MouseLockDispatcher* mouse_lock_dispatcher_;
1412 #if defined(OS_ANDROID)
1413 // Android Specific ---------------------------------------------------------
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_;
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_;
1424 // List of click-based content detectors.
1425 typedef std::vector< linked_ptr<ContentDetector> > ContentDetectorList;
1426 ContentDetectorList content_detectors_;
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_;
1432 // A date/time picker object for date and time related input elements.
1433 scoped_ptr<RendererDateTimePicker> date_time_picker_client_;
1436 // Plugins -------------------------------------------------------------------
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_;
1444 // The ID of the focused NPAPI plug-in.
1445 int focused_plugin_id_;
1448 #if defined(ENABLE_PLUGINS)
1449 typedef std::set<PepperPluginInstanceImpl*> PepperPluginSet;
1450 PepperPluginSet active_pepper_instances_;
1452 // Whether or not the focus is on a PPAPI plugin
1453 PepperPluginInstanceImpl* focused_pepper_plugin_;
1455 // Current text input composition text. Empty if no composition is in
1457 string16 pepper_composition_text_;
1459 // The plugin instance that received the last mouse event. It is set to NULL
1460 // if the last mouse event went to elements other than Pepper plugins.
1461 // |pepper_last_mouse_event_target_| is not owned by this class. We can know
1462 // about when it is destroyed via InstanceDeleted().
1463 PepperPluginInstanceImpl* pepper_last_mouse_event_target_;
1466 // Misc ----------------------------------------------------------------------
1468 // The current and pending file chooser completion objects. If the queue is
1469 // nonempty, the first item represents the currently running file chooser
1470 // callback, and the remaining elements are the other file chooser completion
1471 // still waiting to be run (in order).
1472 struct PendingFileChooser;
1473 std::deque< linked_ptr<PendingFileChooser> > file_chooser_completions_;
1475 // The current directory enumeration callback
1476 std::map<int, WebKit::WebFileChooserCompletion*> enumeration_completions_;
1477 int enumeration_completion_id_;
1479 // Reports load progress to the browser.
1480 scoped_ptr<LoadProgressTracker> load_progress_tracker_;
1482 // The SessionStorage namespace that we're assigned to has an ID, and that ID
1483 // is passed to us upon creation. WebKit asks for this ID upon first use and
1484 // uses it whenever asking the browser process to allocate new storage areas.
1485 int64 session_storage_namespace_id_;
1487 // Stores edit commands associated to the next key event.
1488 // Shall be cleared as soon as the next key event is processed.
1489 EditCommands edit_commands_;
1491 // The external popup for the currently showing select popup.
1492 scoped_ptr<ExternalPopupMenu> external_popup_menu_;
1494 // The node that the context menu was pressed over.
1495 WebKit::WebNode context_menu_node_;
1497 // All the registered observers. We expect this list to be small, so vector
1499 ObserverList<RenderViewObserver> observers_;
1501 // Used to inform didChangeSelection() when it is called in the context
1502 // of handling a InputMsg_SelectRange IPC.
1503 bool handling_select_range_;
1505 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
1506 scoped_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
1508 // State associated with the GetWindowSnapshot function.
1509 int next_snapshot_id_;
1510 typedef std::map<int, WindowSnapshotCallback> PendingSnapshotMap;
1511 PendingSnapshotMap pending_snapshots_;
1513 // Allows to selectively disable partial buffer swap for this renderer's
1515 bool allow_partial_swap_;
1517 // Allows JS to access DOM automation. The JS object is only exposed when the
1518 // DOM automation bindings are enabled.
1519 scoped_ptr<DomAutomationController> dom_automation_controller_;
1521 // Allows JS to read out a variety of internal various metrics. The JS object
1522 // is only exposed when the stats collection bindings are enabled.
1523 scoped_ptr<StatsCollectionController> stats_collection_controller_;
1525 // This field stores drag/drop related info for the event that is currently
1526 // being handled. If the current event results in starting a drag/drop
1527 // session, this info is sent to the browser along with other drag/drop info.
1528 DragEventSourceInfo possible_drag_event_info_;
1530 // NOTE: stats_collection_observer_ should be the last members because their
1531 // constructors call the AddObservers method of RenderViewImpl.
1532 scoped_ptr<StatsCollectionObserver> stats_collection_observer_;
1534 ui::MenuSourceType context_menu_source_type_;
1535 gfx::Point touch_editing_context_menu_location_;
1537 // ---------------------------------------------------------------------------
1538 // ADDING NEW DATA? Please see if it fits appropriately in one of the above
1539 // sections rather than throwing it randomly at the end. If you're adding a
1540 // bunch of stuff, you should probably create a helper class and put your
1541 // data and methods on that to avoid bloating RenderView more. You can
1542 // use the Observer interface to filter IPC messages and receive frame change
1544 // ---------------------------------------------------------------------------
1546 DISALLOW_COPY_AND_ASSIGN(RenderViewImpl);
1549 } // namespace content
1551 #endif // CONTENT_RENDERER_RENDER_VIEW_IMPL_H_