DevTools: cut host and port from webSocketDebuggerUrl in addition to ws:// prefix
[chromium-blink-merge.git] / content / browser / renderer_host / render_view_host_impl.h
blob6e14b189003d87f160db5e5be37557cce9c5f2b8
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_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/process/kill.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/site_instance_impl.h"
19 #include "content/common/drag_event_source_info.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/render_process_host_observer.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/common/window_container_type.h"
24 #include "net/base/load_states.h"
25 #include "third_party/WebKit/public/web/WebAXEnums.h"
26 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
27 #include "third_party/WebKit/public/web/WebPopupType.h"
28 #include "third_party/skia/include/core/SkColor.h"
29 #include "ui/base/window_open_disposition.h"
31 class SkBitmap;
32 class FrameMsg_Navigate;
33 struct MediaPlayerAction;
34 struct ViewHostMsg_CreateWindow_Params;
35 struct ViewMsg_PostMessage_Params;
37 namespace base {
38 class ListValue;
41 namespace gfx {
42 class Range;
45 namespace ui {
46 class AXTree;
49 namespace content {
51 class MediaWebContentsObserver;
52 class ChildProcessSecurityPolicyImpl;
53 class PageState;
54 class RenderWidgetHostDelegate;
55 class SessionStorageNamespace;
56 class SessionStorageNamespaceImpl;
57 class TestRenderViewHost;
58 struct FileChooserFileInfo;
59 struct FileChooserParams;
60 struct FrameReplicationState;
62 #if defined(COMPILER_MSVC)
63 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
64 // with RenderWidgetHost at the root. VS warns when methods from the
65 // root are overridden in only one of the base classes and not both
66 // (in this case, RenderWidgetHostImpl provides implementations of
67 // many of the methods). This is a silly warning when dealing with
68 // pure virtual methods that only have a single implementation in the
69 // hierarchy above this class, and is safe to ignore in this case.
70 #pragma warning(push)
71 #pragma warning(disable: 4250)
72 #endif
74 // This implements the RenderViewHost interface that is exposed to
75 // embedders of content, and adds things only visible to content.
77 // The exact API of this object needs to be more thoroughly designed. Right
78 // now it mimics what WebContentsImpl exposed, which is a fairly large API and
79 // may contain things that are not relevant to a common subset of views. See
80 // also the comment in render_view_host_delegate.h about the size and scope of
81 // the delegate API.
83 // Right now, the concept of page navigation (both top level and frame) exists
84 // in the WebContentsImpl still, so if you instantiate one of these elsewhere,
85 // you will not be able to traverse pages back and forward. We need to determine
86 // if we want to bring that and other functionality down into this object so it
87 // can be shared by others.
89 // DEPRECATED: RenderViewHostImpl is being removed as part of the SiteIsolation
90 // project. New code should not be added here, but to either RenderFrameHostImpl
91 // (if frame specific) or WebContentsImpl (if page specific).
93 // For context, please see https://crbug.com/467770 and
94 // http://www.chromium.org/developers/design-documents/site-isolation.
95 class CONTENT_EXPORT RenderViewHostImpl
96 : public RenderViewHost,
97 public RenderWidgetHostImpl,
98 public RenderProcessHostObserver {
99 public:
100 // Convenience function, just like RenderViewHost::FromID.
101 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
103 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
104 // which case RenderWidgetHost will create a new one. |swapped_out| indicates
105 // whether the view should initially be swapped out (e.g., for an opener
106 // frame being rendered by another process). |hidden| indicates whether the
107 // view is initially hidden or visible.
109 // The |session_storage_namespace| parameter allows multiple render views and
110 // WebContentses to share the same session storage (part of the WebStorage
111 // spec) space. This is useful when restoring contentses, but most callers
112 // should pass in NULL which will cause a new SessionStorageNamespace to be
113 // created.
114 RenderViewHostImpl(SiteInstance* instance,
115 RenderViewHostDelegate* delegate,
116 RenderWidgetHostDelegate* widget_delegate,
117 int routing_id,
118 int main_frame_routing_id,
119 bool swapped_out,
120 bool hidden,
121 bool has_initialized_audio_host);
122 ~RenderViewHostImpl() override;
124 // RenderViewHost implementation.
125 RenderFrameHost* GetMainFrame() override;
126 void AllowBindings(int binding_flags) override;
127 void ClearFocusedElement() override;
128 bool IsFocusedElementEditable() override;
129 void CopyImageAt(int x, int y) override;
130 void SaveImageAt(int x, int y) override;
131 void DirectoryEnumerationFinished(
132 int request_id,
133 const std::vector<base::FilePath>& files) override;
134 void DisableScrollbarsForThreshold(const gfx::Size& size) override;
135 void DragSourceEndedAt(int client_x,
136 int client_y,
137 int screen_x,
138 int screen_y,
139 blink::WebDragOperation operation) override;
140 void DragSourceSystemDragEnded() override;
141 void DragTargetDragEnter(const DropData& drop_data,
142 const gfx::Point& client_pt,
143 const gfx::Point& screen_pt,
144 blink::WebDragOperationsMask operations_allowed,
145 int key_modifiers) override;
146 void DragTargetDragOver(const gfx::Point& client_pt,
147 const gfx::Point& screen_pt,
148 blink::WebDragOperationsMask operations_allowed,
149 int key_modifiers) override;
150 void DragTargetDragLeave() override;
151 void DragTargetDrop(const gfx::Point& client_pt,
152 const gfx::Point& screen_pt,
153 int key_modifiers) override;
154 void EnableAutoResize(const gfx::Size& min_size,
155 const gfx::Size& max_size) override;
156 void DisableAutoResize(const gfx::Size& new_size) override;
157 void EnablePreferredSizeMode() override;
158 void ExecuteMediaPlayerActionAtLocation(
159 const gfx::Point& location,
160 const blink::WebMediaPlayerAction& action) override;
161 void ExecutePluginActionAtLocation(
162 const gfx::Point& location,
163 const blink::WebPluginAction& action) override;
164 void FilesSelectedInChooser(
165 const std::vector<content::FileChooserFileInfo>& files,
166 FileChooserParams::Mode permissions) override;
167 RenderViewHostDelegate* GetDelegate() const override;
168 int GetEnabledBindings() const override;
169 SiteInstanceImpl* GetSiteInstance() const override;
170 bool IsRenderViewLive() const override;
171 void NotifyMoveOrResizeStarted() override;
172 void SetWebUIProperty(const std::string& name,
173 const std::string& value) override;
174 void Zoom(PageZoom zoom) override;
175 void SyncRendererPrefs() override;
176 WebPreferences GetWebkitPreferences() override;
177 void UpdateWebkitPreferences(const WebPreferences& prefs) override;
178 void OnWebkitPreferencesChanged() override;
179 void SelectWordAroundCaret() override;
181 #if defined(OS_ANDROID)
182 void ActivateNearestFindResult(int request_id, float x, float y) override;
183 void RequestFindMatchRects(int current_version) override;
184 #endif
186 // RenderProcessHostObserver implementation
187 void RenderProcessExited(RenderProcessHost* host,
188 base::TerminationStatus status,
189 int exit_code) override;
191 void set_delegate(RenderViewHostDelegate* d) {
192 CHECK(d); // http://crbug.com/82827
193 delegate_ = d;
196 // Set up the RenderView child process. Virtual because it is overridden by
197 // TestRenderViewHost.
198 // The |opener_route_id| parameter indicates which RenderView created this
199 // (MSG_ROUTING_NONE if none). If |max_page_id| is larger than -1, the
200 // RenderView is told to start issuing page IDs at |max_page_id| + 1.
201 // |window_was_created_with_opener| is true if this top-level frame was
202 // created with an opener. (The opener may have been closed since.)
203 // The |proxy_route_id| is only used when creating a RenderView in swapped out
204 // state. |replicated_frame_state| contains replicated data for the
205 // top-level frame, such as its name and sandbox flags.
206 virtual bool CreateRenderView(
207 int opener_route_id,
208 int proxy_route_id,
209 int32 max_page_id,
210 const FrameReplicationState& replicated_frame_state,
211 bool window_was_created_with_opener);
213 base::TerminationStatus render_view_termination_status() const {
214 return render_view_termination_status_;
217 // Tracks whether this RenderViewHost is in an active state (rather than
218 // pending swap out, pending deletion, or swapped out), according to its main
219 // frame RenderFrameHost.
220 bool is_active() const { return is_active_; }
221 void set_is_active(bool is_active) { is_active_ = is_active; }
223 // Tracks whether this RenderViewHost is swapped out, according to its main
224 // frame RenderFrameHost.
225 void set_is_swapped_out(bool is_swapped_out) {
226 is_swapped_out_ = is_swapped_out;
229 // TODO(creis): Remove as part of http://crbug.com/418265.
230 bool is_waiting_for_close_ack() const { return is_waiting_for_close_ack_; }
232 // Tells the renderer that this RenderView will soon be swapped out, and thus
233 // not to create any new modal dialogs until it happens. This must be done
234 // separately so that the PageGroupLoadDeferrers of any current dialogs are no
235 // longer on the stack when we attempt to swap it out.
236 void SuppressDialogsUntilSwapOut();
238 // Tells the renderer process to run the page's unload handler.
239 // A ClosePage_ACK ack is sent back when the handler execution completes.
240 void ClosePage();
242 // Close the page ignoring whether it has unload events registers.
243 // This is called after the beforeunload and unload events have fired
244 // and the user has agreed to continue with closing the page.
245 void ClosePageIgnoringUnloadEvents();
247 // Tells the renderer view to focus the first (last if reverse is true) node.
248 void SetInitialFocus(bool reverse);
250 // Get html data by serializing all frames of current page with lists
251 // which contain all resource links that have local copy.
252 // The parameter links contain original URLs of all saved links.
253 // The parameter local_paths contain corresponding local file paths of
254 // all saved links, which matched with vector:links one by one.
255 // The parameter local_directory_name is relative path of directory which
256 // contain all saved auxiliary files included all sub frames and resouces.
257 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(
258 const std::vector<GURL>& links,
259 const std::vector<base::FilePath>& local_paths,
260 const base::FilePath& local_directory_name);
262 // Notifies the RenderViewHost that its load state changed.
263 void LoadStateChanged(const GURL& url,
264 const net::LoadStateWithParam& load_state,
265 uint64 upload_position,
266 uint64 upload_size);
268 bool SuddenTerminationAllowed() const;
269 void set_sudden_termination_allowed(bool enabled) {
270 sudden_termination_allowed_ = enabled;
273 // RenderWidgetHost public overrides.
274 void Init() override;
275 void Shutdown() override;
276 void WasHidden() override;
277 void WasShown(const ui::LatencyInfo& latency_info) override;
278 bool IsRenderView() const override;
279 bool OnMessageReceived(const IPC::Message& msg) override;
280 void GotFocus() override;
281 void LostCapture() override;
282 void LostMouseLock() override;
283 void SetIsLoading(bool is_loading) override;
284 void ForwardMouseEvent(const blink::WebMouseEvent& mouse_event) override;
285 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event) override;
286 gfx::Rect GetRootWindowResizerRect() const override;
288 // Creates a new RenderView with the given route id.
289 void CreateNewWindow(
290 int route_id,
291 int main_frame_route_id,
292 const ViewHostMsg_CreateWindow_Params& params,
293 SessionStorageNamespace* session_storage_namespace);
295 // Creates a new RenderWidget with the given route id. |popup_type| indicates
296 // if this widget is a popup and what kind of popup it is (select, autofill).
297 void CreateNewWidget(int route_id, blink::WebPopupType popup_type);
299 // Creates a full screen RenderWidget.
300 void CreateNewFullscreenWidget(int route_id);
302 int main_frame_routing_id() const {
303 return main_frame_routing_id_;
305 void set_main_frame_routing_id(int routing_id) {
306 main_frame_routing_id_ = routing_id;
309 void OnTextSurroundingSelectionResponse(const base::string16& content,
310 size_t start_offset,
311 size_t end_offset);
313 // Increases the refcounting on this RVH. This is done by the FrameTree on
314 // creation of a RenderFrameHost.
315 void increment_ref_count() { ++frames_ref_count_; }
317 // Decreases the refcounting on this RVH. This is done by the FrameTree on
318 // destruction of a RenderFrameHost.
319 void decrement_ref_count() { --frames_ref_count_; }
321 // Returns the refcount on this RVH, that is the number of RenderFrameHosts
322 // currently using it.
323 int ref_count() { return frames_ref_count_; }
325 // NOTE: Do not add functions that just send an IPC message that are called in
326 // one or two places. Have the caller send the IPC message directly (unless
327 // the caller places are in different platforms, in which case it's better
328 // to keep them consistent).
330 protected:
331 // RenderWidgetHost protected overrides.
332 void OnUserGesture() override;
333 void NotifyRendererUnresponsive() override;
334 void NotifyRendererResponsive() override;
335 void OnRenderAutoResized(const gfx::Size& size) override;
336 void RequestToLockMouse(bool user_gesture,
337 bool last_unlocked_by_target) override;
338 bool IsFullscreenGranted() const override;
339 blink::WebDisplayMode GetDisplayMode() const override;
340 void OnFocus() override;
341 void OnBlur() override;
343 // IPC message handlers.
344 void OnShowView(int route_id,
345 WindowOpenDisposition disposition,
346 const gfx::Rect& initial_rect,
347 bool user_gesture);
348 void OnShowWidget(int route_id, const gfx::Rect& initial_rect);
349 void OnShowFullscreenWidget(int route_id);
350 void OnRenderViewReady();
351 void OnRenderProcessGone(int status, int error_code);
352 void OnUpdateState(int32 page_id, const PageState& state);
353 void OnUpdateTargetURL(const GURL& url);
354 void OnClose();
355 void OnRequestMove(const gfx::Rect& pos);
356 void OnDocumentAvailableInMainFrame(bool uses_temporary_zoom_level);
357 void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
358 void OnPasteFromSelectionClipboard();
359 void OnRouteCloseEvent();
360 void OnStartDragging(const DropData& drop_data,
361 blink::WebDragOperationsMask operations_allowed,
362 const SkBitmap& bitmap,
363 const gfx::Vector2d& bitmap_offset_in_dip,
364 const DragEventSourceInfo& event_info);
365 void OnUpdateDragCursor(blink::WebDragOperation drag_operation);
366 void OnTargetDropACK();
367 void OnTakeFocus(bool reverse);
368 void OnFocusedNodeChanged(bool is_editable_node,
369 const gfx::Rect& node_bounds_in_viewport);
370 void OnClosePageACK();
371 void OnDidZoomURL(double zoom_level, const GURL& url);
372 void OnPageScaleFactorIsOneChanged(bool is_one);
373 void OnRunFileChooser(const FileChooserParams& params);
374 void OnFocusedNodeTouched(bool editable);
376 private:
377 // TODO(nasko): Temporarily friend RenderFrameHostImpl, so we don't duplicate
378 // utility functions and state needed in both classes, while we move frame
379 // specific code away from this class.
380 friend class RenderFrameHostImpl;
381 friend class TestRenderViewHost;
382 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
383 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
384 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest,
385 CleanUpSwappedOutRVHOnProcessCrash);
387 // TODO(creis): Move to a private namespace on RenderFrameHostImpl.
388 // Delay to wait on closing the WebContents for a beforeunload/unload handler
389 // to fire.
390 static const int64 kUnloadTimeoutMS;
392 // Returns the content specific prefs for this RenderViewHost.
393 // TODO(creis): Move most of this method to RenderProcessHost, since it's
394 // mostly the same across all RVHs in a process. Move the rest to RFH.
395 // See https://crbug.com/304341.
396 WebPreferences ComputeWebkitPrefs();
398 // Returns whether the current RenderProcessHost has read access to the files
399 // reported in |state|.
400 bool CanAccessFilesOfPageState(const PageState& state) const;
402 // Grants the current RenderProcessHost read access to any file listed in
403 // |validated_state|. It is important that the PageState has been validated
404 // upon receipt from the renderer process to prevent it from forging access to
405 // files without the user's consent.
406 void GrantFileAccessFromPageState(const PageState& validated_state);
408 // The number of RenderFrameHosts which have a reference to this RVH.
409 int frames_ref_count_;
411 // Our delegate, which wants to know about changes in the RenderView.
412 RenderViewHostDelegate* delegate_;
414 // The SiteInstance associated with this RenderViewHost. All pages drawn
415 // in this RenderViewHost are part of this SiteInstance. Cannot change
416 // over time.
417 scoped_refptr<SiteInstanceImpl> instance_;
419 // true if we are currently waiting for a response for drag context
420 // information.
421 bool waiting_for_drag_context_response_;
423 // A bitwise OR of bindings types that have been enabled for this RenderView.
424 // See BindingsPolicy for details.
425 int enabled_bindings_;
427 // The most recent page ID we've heard from the renderer process. This is
428 // used as context when other session history related IPCs arrive.
429 // TODO(creis): Allocate this in WebContents/NavigationController instead.
430 int32 page_id_;
432 // Tracks whether this RenderViewHost is in an active state. False if the
433 // main frame is pending swap out, pending deletion, or swapped out, because
434 // it is not visible to the user in any of these cases.
435 bool is_active_;
437 // Tracks whether the main frame RenderFrameHost is swapped out. Unlike
438 // is_active_, this is false when the frame is pending swap out or deletion.
439 // TODO(creis): Remove this when we no longer use swappedout://.
440 // See http://crbug.com/357747.
441 bool is_swapped_out_;
443 // Routing ID for the main frame's RenderFrameHost.
444 int main_frame_routing_id_;
446 // Set to true when waiting for a ViewHostMsg_ClosePageACK.
447 // TODO(creis): Move to RenderFrameHost and RenderWidgetHost.
448 // See http://crbug.com/418265.
449 bool is_waiting_for_close_ack_;
451 // True if the render view can be shut down suddenly.
452 bool sudden_termination_allowed_;
454 // The termination status of the last render view that terminated.
455 base::TerminationStatus render_view_termination_status_;
457 // Set to true if we requested the on screen keyboard to be displayed.
458 bool virtual_keyboard_requested_;
460 // True if the current focused element is editable.
461 bool is_focused_element_editable_;
463 // This is updated every time UpdateWebkitPreferences is called. That method
464 // is in turn called when any of the settings change that the WebPreferences
465 // values depend on.
466 scoped_ptr<WebPreferences> web_preferences_;
468 bool updating_web_preferences_;
470 base::WeakPtrFactory<RenderViewHostImpl> weak_factory_;
472 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
475 #if defined(COMPILER_MSVC)
476 #pragma warning(pop)
477 #endif
479 } // namespace content
481 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_