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