OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ |
7 | 7 |
| 8 #include "build/build_config.h" |
| 9 |
| 10 #if defined(OS_WIN) |
| 11 #include <windows.h> |
| 12 #endif |
| 13 |
8 #include <limits> | 14 #include <limits> |
9 #include <set> | 15 #include <set> |
10 #include <vector> | 16 #include <vector> |
11 #include <windows.h> | |
12 | 17 |
13 #include "base/id_map.h" | 18 #include "base/id_map.h" |
14 #include "base/object_watcher.h" | 19 #include "base/process.h" |
15 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
16 #include "base/ref_counted.h" | 21 #include "base/ref_counted.h" |
17 #include "base/scoped_handle.h" | |
18 #include "base/scoped_ptr.h" | 22 #include "base/scoped_ptr.h" |
19 #include "chrome/browser/renderer_host/render_process_host.h" | 23 #include "chrome/browser/renderer_host/render_process_host.h" |
20 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
21 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
22 | 26 |
23 class PrefService; | 27 class PrefService; |
24 class RenderWidgetHelper; | 28 class RenderWidgetHelper; |
25 class WebContents; | 29 class WebContents; |
26 | 30 |
27 namespace base { | 31 namespace base { |
28 class Thread; | 32 class Thread; |
29 } | 33 } |
30 | 34 |
31 // Implements a concrete RenderProcessHost for the browser process for talking | 35 // Implements a concrete RenderProcessHost for the browser process for talking |
32 // to actual renderer processes (as opposed to mocks). | 36 // to actual renderer processes (as opposed to mocks). |
33 // | 37 // |
34 // Represents the browser side of the browser <--> renderer communication | 38 // Represents the browser side of the browser <--> renderer communication |
35 // channel. There will be one RenderProcessHost per renderer process. | 39 // channel. There will be one RenderProcessHost per renderer process. |
36 // | 40 // |
37 // This object is refcounted so that it can release its resources when all | 41 // This object is refcounted so that it can release its resources when all |
38 // hosts using it go away. | 42 // hosts using it go away. |
39 // | 43 // |
40 // This object communicates back and forth with the RenderProcess object | 44 // This object communicates back and forth with the RenderProcess object |
41 // running in the renderer process. Each RenderProcessHost and RenderProcess | 45 // running in the renderer process. Each RenderProcessHost and RenderProcess |
42 // keeps a list of RenderView (renderer) and WebContents (browser) which | 46 // keeps a list of RenderView (renderer) and WebContents (browser) which |
43 // are correlated with IDs. This way, the Views and the corresponding ViewHosts | 47 // are correlated with IDs. This way, the Views and the corresponding ViewHosts |
44 // communicate through the two process objects. | 48 // communicate through the two process objects. |
45 class BrowserRenderProcessHost : public RenderProcessHost, | 49 class BrowserRenderProcessHost : public RenderProcessHost, |
46 public base::ObjectWatcher::Delegate, | |
47 public NotificationObserver { | 50 public NotificationObserver { |
48 public: | 51 public: |
49 explicit BrowserRenderProcessHost(Profile* profile); | 52 explicit BrowserRenderProcessHost(Profile* profile); |
50 ~BrowserRenderProcessHost(); | 53 ~BrowserRenderProcessHost(); |
51 | 54 |
52 // RenderProcessHost implementation (public portion). | 55 // RenderProcessHost implementation (public portion). |
53 virtual bool Init(); | 56 virtual bool Init(); |
54 virtual int GetNextRoutingID(); | 57 virtual int GetNextRoutingID(); |
55 virtual void CancelResourceRequests(int render_widget_id); | 58 virtual void CancelResourceRequests(int render_widget_id); |
56 virtual void CrossSiteClosePageACK(int new_render_process_host_id, | 59 virtual void CrossSiteClosePageACK(int new_render_process_host_id, |
57 int new_request_id); | 60 int new_request_id); |
58 virtual bool WaitForPaintMsg(int render_widget_id, | 61 virtual bool WaitForPaintMsg(int render_widget_id, |
59 const base::TimeDelta& max_delay, | 62 const base::TimeDelta& max_delay, |
60 IPC::Message* msg); | 63 IPC::Message* msg); |
61 virtual void ReceivedBadMessage(uint16 msg_type); | 64 virtual void ReceivedBadMessage(uint16 msg_type); |
62 virtual void WidgetRestored(); | 65 virtual void WidgetRestored(); |
63 virtual void WidgetHidden(); | 66 virtual void WidgetHidden(); |
64 virtual void AddWord(const std::wstring& word); | 67 virtual void AddWord(const std::wstring& word); |
65 virtual bool FastShutdownIfPossible(); | 68 virtual bool FastShutdownIfPossible(); |
66 | 69 |
67 // IPC::Channel::Sender via RenderProcessHost. | 70 // IPC::Channel::Sender via RenderProcessHost. |
68 virtual bool Send(IPC::Message* msg); | 71 virtual bool Send(IPC::Message* msg); |
69 | 72 |
70 // IPC::Channel::Listener via RenderProcessHost. | 73 // IPC::Channel::Listener via RenderProcessHost. |
71 virtual void OnMessageReceived(const IPC::Message& msg); | 74 virtual void OnMessageReceived(const IPC::Message& msg); |
72 virtual void OnChannelConnected(int32 peer_pid); | 75 virtual void OnChannelConnected(int32 peer_pid); |
| 76 virtual void OnChannelError(); |
73 | 77 |
74 static void RegisterPrefs(PrefService* prefs); | 78 static void RegisterPrefs(PrefService* prefs); |
75 | 79 |
76 // If the a process has sent a message that cannot be decoded, it is deemed | 80 // If the a process has sent a message that cannot be decoded, it is deemed |
77 // corrupted and thus needs to be terminated using this call. This function | 81 // corrupted and thus needs to be terminated using this call. This function |
78 // can be safely called from any thread. | 82 // can be safely called from any thread. |
79 static void BadMessageTerminateProcess(uint16 msg_type, HANDLE renderer); | 83 static void BadMessageTerminateProcess(uint16 msg_type, |
80 | 84 base::ProcessHandle renderer); |
81 // ObjectWatcher::Delegate | |
82 virtual void OnObjectSignaled(HANDLE object); | |
83 | 85 |
84 // NotificationObserver implementation. | 86 // NotificationObserver implementation. |
85 virtual void Observe(NotificationType type, | 87 virtual void Observe(NotificationType type, |
86 const NotificationSource& source, | 88 const NotificationSource& source, |
87 const NotificationDetails& details); | 89 const NotificationDetails& details); |
88 | 90 |
89 private: | 91 private: |
90 // RenderProcessHost implementation (protected portion). | 92 // RenderProcessHost implementation (protected portion). |
91 virtual void Unregister(); | 93 virtual void Unregister(); |
92 | 94 |
(...skipping 22 matching lines...) Expand all Loading... |
115 void SendUserScriptsUpdate(base::SharedMemory* shared_memory); | 117 void SendUserScriptsUpdate(base::SharedMemory* shared_memory); |
116 | 118 |
117 // Gets a handle to the renderer process, normalizing the case where we were | 119 // Gets a handle to the renderer process, normalizing the case where we were |
118 // started with --single-process. | 120 // started with --single-process. |
119 base::ProcessHandle GetRendererProcessHandle(); | 121 base::ProcessHandle GetRendererProcessHandle(); |
120 | 122 |
121 // Callers can reduce the RenderProcess' priority. | 123 // Callers can reduce the RenderProcess' priority. |
122 // Returns true if the priority is backgrounded; false otherwise. | 124 // Returns true if the priority is backgrounded; false otherwise. |
123 void SetBackgrounded(bool boost); | 125 void SetBackgrounded(bool boost); |
124 | 126 |
125 // Used to watch the renderer process handle. | |
126 base::ObjectWatcher watcher_; | |
127 | |
128 // The count of currently visible widgets. Since the host can be a container | 127 // The count of currently visible widgets. Since the host can be a container |
129 // for multiple widgets, it uses this count to determine when it should be | 128 // for multiple widgets, it uses this count to determine when it should be |
130 // backgrounded. | 129 // backgrounded. |
131 int32 visible_widgets_; | 130 int32 visible_widgets_; |
132 | 131 |
133 // Does this process have backgrounded priority. | 132 // Does this process have backgrounded priority. |
134 bool backgrounded_; | 133 bool backgrounded_; |
135 | 134 |
136 // Used to allow a RenderWidgetHost to intercept various messages on the | 135 // Used to allow a RenderWidgetHost to intercept various messages on the |
137 // IO thread. | 136 // IO thread. |
138 scoped_refptr<RenderWidgetHelper> widget_helper_; | 137 scoped_refptr<RenderWidgetHelper> widget_helper_; |
139 | 138 |
140 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); | 139 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); |
141 }; | 140 }; |
142 | 141 |
143 // Generates a unique channel name for a child renderer/plugin process. | 142 // Generates a unique channel name for a child renderer/plugin process. |
144 // The "instance" pointer value is baked into the channel id. | 143 // The "instance" pointer value is baked into the channel id. |
145 inline std::wstring GenerateRandomChannelID(void* instance) { | 144 std::wstring GenerateRandomChannelID(void* instance); |
146 // Note: the string must start with the current process id, this is how | |
147 // child processes determine the pid of the parent. | |
148 // Build the channel ID. This is composed of a unique identifier for the | |
149 // parent browser process, an identifier for the renderer/plugin instance, | |
150 // and a random component. We use a random component so that a hacked child | |
151 // process can't cause denial of service by causing future named pipe creation | |
152 // to fail. | |
153 return StringPrintf(L"%d.%x.%d", | |
154 GetCurrentProcessId(), instance, | |
155 base::RandInt(0, std::numeric_limits<int>::max())); | |
156 } | |
157 | |
158 | 145 |
159 #endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | 146 #endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ |
160 | 147 |
OLD | NEW |