OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
15 #include <utility> // for pair<> | 15 #include <utility> // for pair<> |
16 #endif | 16 #endif |
17 | 17 |
18 #include "base/base_switches.h" | 18 #include "base/base_switches.h" |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/bind_helpers.h" | 20 #include "base/bind_helpers.h" |
21 #include "base/callback.h" | 21 #include "base/callback.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/debug/trace_event.h" | 23 #include "base/debug/trace_event.h" |
24 #include "base/files/file.h" | 24 #include "base/files/file.h" |
25 #include "base/lazy_instance.h" | 25 #include "base/lazy_instance.h" |
26 #include "base/logging.h" | 26 #include "base/logging.h" |
27 #include "base/metrics/field_trial.h" | 27 #include "base/metrics/field_trial.h" |
28 #include "base/metrics/histogram.h" | 28 #include "base/metrics/histogram.h" |
29 #include "base/numerics/safe_math.h" | |
30 #include "base/path_service.h" | 29 #include "base/path_service.h" |
31 #include "base/process/process_handle.h" | 30 #include "base/process/process_handle.h" |
32 #include "base/rand_util.h" | 31 #include "base/rand_util.h" |
33 #include "base/stl_util.h" | 32 #include "base/stl_util.h" |
34 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
35 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
36 #include "base/supports_user_data.h" | 35 #include "base/supports_user_data.h" |
37 #include "base/sys_info.h" | 36 #include "base/sys_info.h" |
38 #include "base/threading/thread.h" | 37 #include "base/threading/thread.h" |
39 #include "base/threading/thread_restrictions.h" | 38 #include "base/threading/thread_restrictions.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 #include "content/browser/shared_worker/worker_storage_partition.h" | 101 #include "content/browser/shared_worker/worker_storage_partition.h" |
103 #include "content/browser/speech/speech_recognition_dispatcher_host.h" | 102 #include "content/browser/speech/speech_recognition_dispatcher_host.h" |
104 #include "content/browser/storage_partition_impl.h" | 103 #include "content/browser/storage_partition_impl.h" |
105 #include "content/browser/streams/stream_context.h" | 104 #include "content/browser/streams/stream_context.h" |
106 #include "content/browser/tracing/trace_message_filter.h" | 105 #include "content/browser/tracing/trace_message_filter.h" |
107 #include "content/browser/vibration/vibration_message_filter.h" | 106 #include "content/browser/vibration/vibration_message_filter.h" |
108 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 107 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
109 #include "content/common/child_process_host_impl.h" | 108 #include "content/common/child_process_host_impl.h" |
110 #include "content/common/child_process_messages.h" | 109 #include "content/common/child_process_messages.h" |
111 #include "content/common/content_switches_internal.h" | 110 #include "content/common/content_switches_internal.h" |
112 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
113 #include "content/common/gpu/gpu_messages.h" | 111 #include "content/common/gpu/gpu_messages.h" |
114 #include "content/common/mojo/mojo_messages.h" | 112 #include "content/common/mojo/mojo_messages.h" |
115 #include "content/common/resource_messages.h" | 113 #include "content/common/resource_messages.h" |
116 #include "content/common/view_messages.h" | 114 #include "content/common/view_messages.h" |
117 #include "content/public/browser/browser_context.h" | 115 #include "content/public/browser/browser_context.h" |
118 #include "content/public/browser/content_browser_client.h" | 116 #include "content/public/browser/content_browser_client.h" |
119 #include "content/public/browser/notification_service.h" | 117 #include "content/public/browser/notification_service.h" |
120 #include "content/public/browser/notification_types.h" | 118 #include "content/public/browser/notification_types.h" |
121 #include "content/public/browser/render_process_host_factory.h" | 119 #include "content/public/browser/render_process_host_factory.h" |
122 #include "content/public/browser/render_process_host_observer.h" | 120 #include "content/public/browser/render_process_host_observer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
144 #include "third_party/skia/include/core/SkBitmap.h" | 142 #include "third_party/skia/include/core/SkBitmap.h" |
145 #include "ui/base/ui_base_switches.h" | 143 #include "ui/base/ui_base_switches.h" |
146 #include "ui/events/event_switches.h" | 144 #include "ui/events/event_switches.h" |
147 #include "ui/gfx/switches.h" | 145 #include "ui/gfx/switches.h" |
148 #include "ui/gl/gl_switches.h" | 146 #include "ui/gl/gl_switches.h" |
149 #include "ui/native_theme/native_theme_switches.h" | 147 #include "ui/native_theme/native_theme_switches.h" |
150 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 148 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
151 | 149 |
152 #if defined(OS_ANDROID) | 150 #if defined(OS_ANDROID) |
153 #include "content/browser/media/android/browser_demuxer_android.h" | 151 #include "content/browser/media/android/browser_demuxer_android.h" |
154 #include "content/browser/renderer_host/compositor_impl_android.h" | |
155 #include "content/browser/screen_orientation/screen_orientation_message_filter_a
ndroid.h" | 152 #include "content/browser/screen_orientation/screen_orientation_message_filter_a
ndroid.h" |
156 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" | |
157 #endif | |
158 | |
159 #if defined(OS_MACOSX) | |
160 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | |
161 #endif | 153 #endif |
162 | 154 |
163 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
164 #include "base/win/scoped_com_initializer.h" | 156 #include "base/win/scoped_com_initializer.h" |
165 #include "content/common/font_cache_dispatcher_win.h" | 157 #include "content/common/font_cache_dispatcher_win.h" |
166 #include "content/common/sandbox_win.h" | 158 #include "content/common/sandbox_win.h" |
167 #include "ui/gfx/win/dpi.h" | 159 #include "ui/gfx/win/dpi.h" |
168 #endif | 160 #endif |
169 | 161 |
170 #if defined(ENABLE_PLUGINS) | 162 #if defined(ENABLE_PLUGINS) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 return ipc_fd_; | 325 return ipc_fd_; |
334 } | 326 } |
335 #endif // OS_WIN | 327 #endif // OS_WIN |
336 | 328 |
337 private: | 329 private: |
338 #if defined(OS_POSIX) | 330 #if defined(OS_POSIX) |
339 int ipc_fd_; | 331 int ipc_fd_; |
340 #endif // OS_POSIX | 332 #endif // OS_POSIX |
341 }; | 333 }; |
342 | 334 |
343 #if defined(OS_MACOSX) | |
344 void AddBooleanValue(CFMutableDictionaryRef dictionary, | |
345 const CFStringRef key, | |
346 bool value) { | |
347 CFDictionaryAddValue( | |
348 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); | |
349 } | |
350 | |
351 void AddIntegerValue(CFMutableDictionaryRef dictionary, | |
352 const CFStringRef key, | |
353 int32 value) { | |
354 base::ScopedCFTypeRef<CFNumberRef> number( | |
355 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | |
356 CFDictionaryAddValue(dictionary, key, number.get()); | |
357 } | |
358 #endif | |
359 | |
360 const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey"; | 335 const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey"; |
361 | 336 |
362 class SessionStorageHolder : public base::SupportsUserData::Data { | 337 class SessionStorageHolder : public base::SupportsUserData::Data { |
363 public: | 338 public: |
364 SessionStorageHolder() {} | 339 SessionStorageHolder() {} |
365 virtual ~SessionStorageHolder() {} | 340 virtual ~SessionStorageHolder() {} |
366 | 341 |
367 void Hold(const SessionStorageNamespaceMap& sessions, int view_route_id) { | 342 void Hold(const SessionStorageNamespaceMap& sessions, int view_route_id) { |
368 session_storage_namespaces_awaiting_close_[view_route_id] = sessions; | 343 session_storage_namespaces_awaiting_close_[view_route_id] = sessions; |
369 } | 344 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 queued_messages_.pop(); | 527 queued_messages_.pop(); |
553 } | 528 } |
554 | 529 |
555 UnregisterHost(GetID()); | 530 UnregisterHost(GetID()); |
556 | 531 |
557 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 532 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
558 switches::kDisableGpuShaderDiskCache)) { | 533 switches::kDisableGpuShaderDiskCache)) { |
559 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 534 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
560 base::Bind(&RemoveShaderInfo, GetID())); | 535 base::Bind(&RemoveShaderInfo, GetID())); |
561 } | 536 } |
562 | |
563 #if defined(OS_ANDROID) | |
564 CompositorImpl::DestroyAllSurfaceTextures(GetID()); | |
565 #endif | |
566 } | 537 } |
567 | 538 |
568 void RenderProcessHostImpl::EnableSendQueue() { | 539 void RenderProcessHostImpl::EnableSendQueue() { |
569 is_initialized_ = false; | 540 is_initialized_ = false; |
570 } | 541 } |
571 | 542 |
572 bool RenderProcessHostImpl::Init() { | 543 bool RenderProcessHostImpl::Init() { |
573 // calling Init() more than once does nothing, this makes it more convenient | 544 // calling Init() more than once does nothing, this makes it more convenient |
574 // for the view host which may not be sure in some cases | 545 // for the view host which may not be sure in some cases |
575 if (channel_) | 546 if (channel_) |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg) | 1352 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg) |
1382 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, | 1353 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, |
1383 OnShutdownRequest) | 1354 OnShutdownRequest) |
1384 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, | 1355 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, |
1385 OnDumpHandlesDone) | 1356 OnDumpHandlesDone) |
1386 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 1357 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
1387 SuddenTerminationChanged) | 1358 SuddenTerminationChanged) |
1388 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 1359 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
1389 OnUserMetricsRecordAction) | 1360 OnUserMetricsRecordAction) |
1390 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) | 1361 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) |
1391 IPC_MESSAGE_HANDLER_DELAY_REPLY( | |
1392 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer, | |
1393 OnAllocateGpuMemoryBuffer) | |
1394 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DeletedGpuMemoryBuffer, | |
1395 OnDeletedGpuMemoryBuffer) | |
1396 IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK) | 1362 IPC_MESSAGE_HANDLER(ViewHostMsg_Close_ACK, OnCloseACK) |
1397 #if defined(ENABLE_WEBRTC) | 1363 #if defined(ENABLE_WEBRTC) |
1398 IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer, | 1364 IPC_MESSAGE_HANDLER(AecDumpMsg_RegisterAecDumpConsumer, |
1399 OnRegisterAecDumpConsumer) | 1365 OnRegisterAecDumpConsumer) |
1400 IPC_MESSAGE_HANDLER(AecDumpMsg_UnregisterAecDumpConsumer, | 1366 IPC_MESSAGE_HANDLER(AecDumpMsg_UnregisterAecDumpConsumer, |
1401 OnUnregisterAecDumpConsumer) | 1367 OnUnregisterAecDumpConsumer) |
1402 #endif | 1368 #endif |
1403 // Adding single handlers for your service here is fine, but once your | 1369 // Adding single handlers for your service here is fine, but once your |
1404 // service needs more than one handler, please extract them into a new | 1370 // service needs more than one handler, please extract them into a new |
1405 // message filter and add that filter to CreateMessageFilters(). | 1371 // message filter and add that filter to CreateMessageFilters(). |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 --worker_ref_count_; | 2224 --worker_ref_count_; |
2259 if (worker_ref_count_ == 0) | 2225 if (worker_ref_count_ == 0) |
2260 Cleanup(); | 2226 Cleanup(); |
2261 } | 2227 } |
2262 | 2228 |
2263 void RenderProcessHostImpl::EnsureMojoActivated() { | 2229 void RenderProcessHostImpl::EnsureMojoActivated() { |
2264 mojo_activation_required_ = true; | 2230 mojo_activation_required_ = true; |
2265 MaybeActivateMojo(); | 2231 MaybeActivateMojo(); |
2266 } | 2232 } |
2267 | 2233 |
2268 void RenderProcessHostImpl::OnAllocateGpuMemoryBuffer(uint32 width, | |
2269 uint32 height, | |
2270 uint32 internalformat, | |
2271 uint32 usage, | |
2272 IPC::Message* reply) { | |
2273 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
2274 if (!GpuMemoryBufferImpl::IsFormatValid(internalformat) || | |
2275 !GpuMemoryBufferImpl::IsUsageValid(usage)) { | |
2276 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); | |
2277 return; | |
2278 } | |
2279 base::CheckedNumeric<int> size = width; | |
2280 size *= height; | |
2281 if (!size.IsValid()) { | |
2282 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); | |
2283 return; | |
2284 } | |
2285 | |
2286 #if defined(OS_MACOSX) | |
2287 // TODO(reveman): This should be moved to | |
2288 // GpuMemoryBufferImpl::AllocateForChildProcess and | |
2289 // GpuMemoryBufferImplIOSurface. crbug.com/325045, crbug.com/323304 | |
2290 if (GpuMemoryBufferImplIOSurface::IsConfigurationSupported(internalformat, | |
2291 usage)) { | |
2292 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | |
2293 properties.reset( | |
2294 CFDictionaryCreateMutable(kCFAllocatorDefault, | |
2295 0, | |
2296 &kCFTypeDictionaryKeyCallBacks, | |
2297 &kCFTypeDictionaryValueCallBacks)); | |
2298 AddIntegerValue(properties, kIOSurfaceWidth, width); | |
2299 AddIntegerValue(properties, kIOSurfaceHeight, height); | |
2300 AddIntegerValue(properties, | |
2301 kIOSurfaceBytesPerElement, | |
2302 GpuMemoryBufferImpl::BytesPerPixel(internalformat)); | |
2303 AddIntegerValue( | |
2304 properties, | |
2305 kIOSurfacePixelFormat, | |
2306 GpuMemoryBufferImplIOSurface::PixelFormat(internalformat)); | |
2307 // TODO(reveman): Remove this when using a mach_port_t to transfer | |
2308 // IOSurface to renderer process. crbug.com/323304 | |
2309 AddBooleanValue( | |
2310 properties, kIOSurfaceIsGlobal, true); | |
2311 | |
2312 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | |
2313 if (io_surface) { | |
2314 gfx::GpuMemoryBufferHandle handle; | |
2315 handle.type = gfx::IO_SURFACE_BUFFER; | |
2316 handle.io_surface_id = IOSurfaceGetID(io_surface); | |
2317 | |
2318 // TODO(reveman): This makes the assumption that the renderer will | |
2319 // grab a reference to the surface before sending another message. | |
2320 // crbug.com/325045 | |
2321 last_io_surface_ = io_surface; | |
2322 GpuMemoryBufferAllocated(reply, handle); | |
2323 return; | |
2324 } | |
2325 } | |
2326 #endif | |
2327 | |
2328 #if defined(OS_ANDROID) | |
2329 // TODO(reveman): This should be moved to | |
2330 // GpuMemoryBufferImpl::AllocateForChildProcess and | |
2331 // GpuMemoryBufferImplSurfaceTexture when adding support for out-of-process | |
2332 // GPU service. crbug.com/368716 | |
2333 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported( | |
2334 internalformat, usage)) { | |
2335 // Each surface texture is associated with a render process id. This allows | |
2336 // the GPU service and Java Binder IPC to verify that a renderer is not | |
2337 // trying to use a surface texture it doesn't own. | |
2338 int surface_texture_id = CompositorImpl::CreateSurfaceTexture(GetID()); | |
2339 if (surface_texture_id != -1) { | |
2340 gfx::GpuMemoryBufferHandle handle; | |
2341 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
2342 handle.surface_texture_id = | |
2343 gfx::SurfaceTextureId(surface_texture_id, GetID()); | |
2344 GpuMemoryBufferAllocated(reply, handle); | |
2345 return; | |
2346 } | |
2347 } | |
2348 #endif | |
2349 | |
2350 GpuMemoryBufferImpl::AllocateForChildProcess( | |
2351 gfx::Size(width, height), | |
2352 internalformat, | |
2353 usage, | |
2354 GetHandle(), | |
2355 GetID(), | |
2356 base::Bind(&RenderProcessHostImpl::GpuMemoryBufferAllocated, | |
2357 weak_factory_.GetWeakPtr(), | |
2358 reply)); | |
2359 } | |
2360 | |
2361 void RenderProcessHostImpl::GpuMemoryBufferAllocated( | |
2362 IPC::Message* reply, | |
2363 const gfx::GpuMemoryBufferHandle& handle) { | |
2364 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
2365 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, | |
2366 handle); | |
2367 Send(reply); | |
2368 } | |
2369 | |
2370 void RenderProcessHostImpl::OnDeletedGpuMemoryBuffer( | |
2371 gfx::GpuMemoryBufferType type, | |
2372 const gfx::GpuMemoryBufferId& id) { | |
2373 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
2374 GpuMemoryBufferImpl::DeletedByChildProcess(type, id, GetHandle()); | |
2375 } | |
2376 | |
2377 } // namespace content | 2234 } // namespace content |
OLD | NEW |