blob: 7f32035f2c68b6ed024016a1863ab99782929cb3 [file] [log] [blame]
[email protected]9f4f3322012-01-18 22:29:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1d8a3d1f2011-02-19 07:11:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_
6#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_
[email protected]1d8a3d1f2011-02-19 07:11:527
8#include <map>
9
lfg052af412015-03-19 16:49:5310#include "base/atomic_sequence_num.h"
[email protected]14c1c232013-06-11 17:52:4411#include "base/containers/hash_tables.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]fa20e002013-07-23 21:20:5413#include "base/process/process.h"
[email protected]c63b4d42012-04-26 01:01:0714#include "content/public/browser/browser_thread.h"
[email protected]03b6d552012-03-29 04:03:0115#include "content/public/browser/content_browser_client.h"
[email protected]e1986832013-06-14 07:27:2816#include "content/public/browser/global_request_id.h"
[email protected]87f3c082011-10-19 18:07:4417#include "content/public/common/window_container_type.h"
[email protected]2255a9332013-06-17 05:12:3118#include "third_party/WebKit/public/web/WebPopupType.h"
[email protected]2d7c8552011-06-27 19:21:5519#include "ui/gfx/native_widget_types.h"
[email protected]1d8a3d1f2011-02-19 07:11:5220
21namespace IPC {
22class Message;
23}
24
25namespace base {
26class TimeDelta;
27}
28
[email protected]1d8a3d1f2011-02-19 07:11:5229struct ViewHostMsg_CreateWindow_Params;
[email protected]992db4c2011-05-12 15:37:1530struct ViewMsg_SwapOut_Params;
[email protected]1d8a3d1f2011-02-19 07:11:5231
[email protected]fc4616f2012-07-21 01:29:5832namespace content {
[email protected]4232b2502014-05-13 01:00:3533class GpuProcessHost;
[email protected]fc4616f2012-07-21 01:29:5834class ResourceDispatcherHostImpl;
35class SessionStorageNamespace;
[email protected]1d8a3d1f2011-02-19 07:11:5236
37// Instantiated per RenderProcessHost to provide various optimizations on
38// behalf of a RenderWidgetHost. This class bridges between the IO thread
39// where the RenderProcessHost's MessageFilter lives and the UI thread where
40// the RenderWidgetHost lives.
41//
42//
[email protected]1d8a3d1f2011-02-19 07:11:5243// OPTIMIZED TAB SWITCHING
44//
45// When a RenderWidgetHost is in a background tab, it is flagged as hidden.
[email protected]c63b4d42012-04-26 01:01:0746// This causes the corresponding RenderWidget to stop sending BackingStore
[email protected]1d8a3d1f2011-02-19 07:11:5247// messages. The RenderWidgetHost also discards its backingstore when it is
48// hidden, which helps free up memory. As a result, when a RenderWidgetHost
[email protected]9e2e4632012-07-27 16:38:4149// is restored, it can be momentarily be without a backingstore. (Restoring
50// a RenderWidgetHost results in a WasShown message being sent to the
[email protected]c63b4d42012-04-26 01:01:0751// RenderWidget, which triggers a full BackingStore message.) This can lead
52// to an observed rendering glitch as the WebContentsImpl will just have to
[email protected]9e2e4632012-07-27 16:38:4153// fill white overtop the RenderWidgetHost until the RenderWidgetHost
54// receives a BackingStore message to refresh its backingstore.
[email protected]1d8a3d1f2011-02-19 07:11:5255//
56// To avoid this 'white flash', the RenderWidgetHost again makes use of the
[email protected]c63b4d42012-04-26 01:01:0757// RenderWidgetHelper's WaitForBackingStoreMsg method. When the
58// RenderWidgetHost's GetBackingStore method is called, it will call
59// WaitForBackingStoreMsg if it has no backingstore.
[email protected]1d8a3d1f2011-02-19 07:11:5260//
61// TRANSPORT DIB CREATION
62//
63// On some platforms (currently the Mac) the renderer cannot create transport
64// DIBs because of sandbox limitations. Thus, it has to make synchronous IPCs
65// to the browser for them. Since these requests are synchronous, they cannot
66// terminate on the UI thread. Thus, in this case, this object performs the
67// allocation and maintains the set of allocated transport DIBs which the
68// renderers can refer to.
69//
[email protected]f4675d42014-07-17 09:30:4270
[email protected]1d8a3d1f2011-02-19 07:11:5271class RenderWidgetHelper
[email protected]fc4616f2012-07-21 01:29:5872 : public base::RefCountedThreadSafe<RenderWidgetHelper,
73 BrowserThread::DeleteOnIOThread> {
[email protected]1d8a3d1f2011-02-19 07:11:5274 public:
75 RenderWidgetHelper();
76
77 void Init(int render_process_id,
[email protected]fc4616f2012-07-21 01:29:5878 ResourceDispatcherHostImpl* resource_dispatcher_host);
[email protected]1d8a3d1f2011-02-19 07:11:5279
80 // Gets the next available routing id. This is thread safe.
81 int GetNextRoutingID();
82
[email protected]c63b4d42012-04-26 01:01:0783 // IO THREAD ONLY -----------------------------------------------------------
84
85 // Lookup the RenderWidgetHelper from the render_process_host_id. Returns NULL
86 // if not found. NOTE: The raw pointer is for temporary use only. To retain,
87 // store in a scoped_refptr.
88 static RenderWidgetHelper* FromProcessHostID(int render_process_host_id);
[email protected]1d8a3d1f2011-02-19 07:11:5289
90 // UI THREAD ONLY -----------------------------------------------------------
91
[email protected]23f41fd2014-06-21 05:29:1792 // These four functions provide the backend implementation of the
[email protected]1d8a3d1f2011-02-19 07:11:5293 // corresponding functions in RenderProcessHost. See those declarations
94 // for documentation.
[email protected]e1986832013-06-14 07:27:2895 void ResumeDeferredNavigation(const GlobalRequestID& request_id);
[email protected]23f41fd2014-06-21 05:29:1796 void ResumeResponseDeferredAtStart(const GlobalRequestID& request_id);
[email protected]f4675d42014-07-17 09:30:4297
[email protected]aacd1d72012-07-23 17:35:0998 // Called to resume the requests for a view after it's ready. The view was
99 // created by CreateNewWindow which initially blocked the requests.
100 void ResumeRequestsForView(int route_id);
[email protected]1d8a3d1f2011-02-19 07:11:52101
[email protected]f4675d42014-07-17 09:30:42102 // IO THREAD ONLY -----------------------------------------------------------
[email protected]1d8a3d1f2011-02-19 07:11:52103
[email protected]97714c82012-06-06 10:15:13104 void CreateNewWindow(
105 const ViewHostMsg_CreateWindow_Params& params,
106 bool no_javascript_access,
107 base::ProcessHandle render_process,
108 int* route_id,
[email protected]227692c52013-05-31 22:43:04109 int* main_frame_route_id,
[email protected]97714c82012-06-06 10:15:13110 int* surface_id,
[email protected]fc4616f2012-07-21 01:29:58111 SessionStorageNamespace* session_storage_namespace);
[email protected]1d8a3d1f2011-02-19 07:11:52112 void CreateNewWidget(int opener_id,
[email protected]180ef242013-11-07 06:50:46113 blink::WebPopupType popup_type,
[email protected]9f4f3322012-01-18 22:29:56114 int* route_id,
115 int* surface_id);
116 void CreateNewFullscreenWidget(int opener_id, int* route_id, int* surface_id);
[email protected]1d8a3d1f2011-02-19 07:11:52117
[email protected]1d8a3d1f2011-02-19 07:11:52118 private:
[email protected]1d8a3d1f2011-02-19 07:11:52119 friend class base::RefCountedThreadSafe<RenderWidgetHelper>;
[email protected]fc4616f2012-07-21 01:29:58120 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
[email protected]c63b4d42012-04-26 01:01:07121 friend class base::DeleteHelper<RenderWidgetHelper>;
[email protected]1d8a3d1f2011-02-19 07:11:52122
[email protected]1d8a3d1f2011-02-19 07:11:52123 ~RenderWidgetHelper();
124
[email protected]1d8a3d1f2011-02-19 07:11:52125 // Called on the UI thread to finish creating a window.
[email protected]97714c82012-06-06 10:15:13126 void OnCreateWindowOnUI(
127 const ViewHostMsg_CreateWindow_Params& params,
128 int route_id,
[email protected]227692c52013-05-31 22:43:04129 int main_frame_route_id,
[email protected]fc4616f2012-07-21 01:29:58130 SessionStorageNamespace* session_storage_namespace);
[email protected]1d8a3d1f2011-02-19 07:11:52131
132 // Called on the IO thread after a window was created on the UI thread.
[email protected]aacd1d72012-07-23 17:35:09133 void OnResumeRequestsForView(int route_id);
[email protected]1d8a3d1f2011-02-19 07:11:52134
135 // Called on the UI thread to finish creating a widget.
136 void OnCreateWidgetOnUI(int opener_id,
137 int route_id,
[email protected]180ef242013-11-07 06:50:46138 blink::WebPopupType popup_type);
[email protected]1d8a3d1f2011-02-19 07:11:52139
140 // Called on the UI thread to create a fullscreen widget.
141 void OnCreateFullscreenWidgetOnUI(int opener_id, int route_id);
142
[email protected]e1986832013-06-14 07:27:28143 // Called on the IO thread to resume a paused navigation in the network
144 // stack without transferring it to a new renderer process.
145 void OnResumeDeferredNavigation(const GlobalRequestID& request_id);
[email protected]1d8a3d1f2011-02-19 07:11:52146
[email protected]23f41fd2014-06-21 05:29:17147 // Called on the IO thread to resume a navigation paused immediately after
148 // receiving response headers.
149 void OnResumeResponseDeferredAtStart(const GlobalRequestID& request_id);
150
[email protected]1d8a3d1f2011-02-19 07:11:52151 int render_process_id_;
152
lfg052af412015-03-19 16:49:53153 // The next routing id to use.
154 base::AtomicSequenceNumber next_routing_id_;
[email protected]1d8a3d1f2011-02-19 07:11:52155
[email protected]fc4616f2012-07-21 01:29:58156 ResourceDispatcherHostImpl* resource_dispatcher_host_;
[email protected]1d8a3d1f2011-02-19 07:11:52157
158 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper);
159};
160
[email protected]fc4616f2012-07-21 01:29:58161} // namespace content
162
[email protected]1d8a3d1f2011-02-19 07:11:52163#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_