[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | |
lfg | 052af41 | 2015-03-19 16:49:53 | [diff] [blame^] | 10 | #include "base/atomic_sequence_num.h" |
[email protected] | 14c1c23 | 2013-06-11 17:52:44 | [diff] [blame] | 11 | #include "base/containers/hash_tables.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | fa20e00 | 2013-07-23 21:20:54 | [diff] [blame] | 13 | #include "base/process/process.h" |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 15 | #include "content/public/browser/content_browser_client.h" |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 16 | #include "content/public/browser/global_request_id.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 17 | #include "content/public/common/window_container_type.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 18 | #include "third_party/WebKit/public/web/WebPopupType.h" |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 19 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 20 | |
| 21 | namespace IPC { |
| 22 | class Message; |
| 23 | } |
| 24 | |
| 25 | namespace base { |
| 26 | class TimeDelta; |
| 27 | } |
| 28 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 29 | struct ViewHostMsg_CreateWindow_Params; |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 30 | struct ViewMsg_SwapOut_Params; |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 31 | |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 32 | namespace content { |
[email protected] | 4232b250 | 2014-05-13 01:00:35 | [diff] [blame] | 33 | class GpuProcessHost; |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 34 | class ResourceDispatcherHostImpl; |
| 35 | class SessionStorageNamespace; |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 36 | |
| 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 43 | // OPTIMIZED TAB SWITCHING |
| 44 | // |
| 45 | // When a RenderWidgetHost is in a background tab, it is flagged as hidden. |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 46 | // This causes the corresponding RenderWidget to stop sending BackingStore |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 47 | // 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] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 49 | // 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] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 51 | // 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] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 53 | // fill white overtop the RenderWidgetHost until the RenderWidgetHost |
| 54 | // receives a BackingStore message to refresh its backingstore. |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 55 | // |
| 56 | // To avoid this 'white flash', the RenderWidgetHost again makes use of the |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 57 | // 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 60 | // |
| 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] | f4675d4 | 2014-07-17 09:30:42 | [diff] [blame] | 70 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 71 | class RenderWidgetHelper |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 72 | : public base::RefCountedThreadSafe<RenderWidgetHelper, |
| 73 | BrowserThread::DeleteOnIOThread> { |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 74 | public: |
| 75 | RenderWidgetHelper(); |
| 76 | |
| 77 | void Init(int render_process_id, |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 78 | ResourceDispatcherHostImpl* resource_dispatcher_host); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 79 | |
| 80 | // Gets the next available routing id. This is thread safe. |
| 81 | int GetNextRoutingID(); |
| 82 | |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 83 | // 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 89 | |
| 90 | // UI THREAD ONLY ----------------------------------------------------------- |
| 91 | |
[email protected] | 23f41fd | 2014-06-21 05:29:17 | [diff] [blame] | 92 | // These four functions provide the backend implementation of the |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 93 | // corresponding functions in RenderProcessHost. See those declarations |
| 94 | // for documentation. |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 95 | void ResumeDeferredNavigation(const GlobalRequestID& request_id); |
[email protected] | 23f41fd | 2014-06-21 05:29:17 | [diff] [blame] | 96 | void ResumeResponseDeferredAtStart(const GlobalRequestID& request_id); |
[email protected] | f4675d4 | 2014-07-17 09:30:42 | [diff] [blame] | 97 | |
[email protected] | aacd1d7 | 2012-07-23 17:35:09 | [diff] [blame] | 98 | // 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 101 | |
[email protected] | f4675d4 | 2014-07-17 09:30:42 | [diff] [blame] | 102 | // IO THREAD ONLY ----------------------------------------------------------- |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 103 | |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 104 | void CreateNewWindow( |
| 105 | const ViewHostMsg_CreateWindow_Params& params, |
| 106 | bool no_javascript_access, |
| 107 | base::ProcessHandle render_process, |
| 108 | int* route_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 109 | int* main_frame_route_id, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 110 | int* surface_id, |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 111 | SessionStorageNamespace* session_storage_namespace); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 112 | void CreateNewWidget(int opener_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 113 | blink::WebPopupType popup_type, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 114 | int* route_id, |
| 115 | int* surface_id); |
| 116 | void CreateNewFullscreenWidget(int opener_id, int* route_id, int* surface_id); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 117 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 118 | private: |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 119 | friend class base::RefCountedThreadSafe<RenderWidgetHelper>; |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 120 | friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 121 | friend class base::DeleteHelper<RenderWidgetHelper>; |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 122 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 123 | ~RenderWidgetHelper(); |
| 124 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 125 | // Called on the UI thread to finish creating a window. |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 126 | void OnCreateWindowOnUI( |
| 127 | const ViewHostMsg_CreateWindow_Params& params, |
| 128 | int route_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 129 | int main_frame_route_id, |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 130 | SessionStorageNamespace* session_storage_namespace); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 131 | |
| 132 | // Called on the IO thread after a window was created on the UI thread. |
[email protected] | aacd1d7 | 2012-07-23 17:35:09 | [diff] [blame] | 133 | void OnResumeRequestsForView(int route_id); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 134 | |
| 135 | // Called on the UI thread to finish creating a widget. |
| 136 | void OnCreateWidgetOnUI(int opener_id, |
| 137 | int route_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 138 | blink::WebPopupType popup_type); |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 139 | |
| 140 | // Called on the UI thread to create a fullscreen widget. |
| 141 | void OnCreateFullscreenWidgetOnUI(int opener_id, int route_id); |
| 142 | |
[email protected] | e198683 | 2013-06-14 07:27:28 | [diff] [blame] | 143 | // 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 146 | |
[email protected] | 23f41fd | 2014-06-21 05:29:17 | [diff] [blame] | 147 | // 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] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 151 | int render_process_id_; |
| 152 | |
lfg | 052af41 | 2015-03-19 16:49:53 | [diff] [blame^] | 153 | // The next routing id to use. |
| 154 | base::AtomicSequenceNumber next_routing_id_; |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 155 | |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 156 | ResourceDispatcherHostImpl* resource_dispatcher_host_; |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 157 | |
| 158 | DISALLOW_COPY_AND_ASSIGN(RenderWidgetHelper); |
| 159 | }; |
| 160 | |
[email protected] | fc4616f | 2012-07-21 01:29:58 | [diff] [blame] | 161 | } // namespace content |
| 162 | |
[email protected] | 1d8a3d1f | 2011-02-19 07:11:52 | [diff] [blame] | 163 | #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_ |