summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_process_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/render_process_impl.cc')
-rw-r--r--chrome/renderer/render_process_impl.cc154
1 files changed, 83 insertions, 71 deletions
diff --git a/chrome/renderer/render_process_impl.cc b/chrome/renderer/render_process_impl.cc
index 9d621da..a508e77 100644
--- a/chrome/renderer/render_process_impl.cc
+++ b/chrome/renderer/render_process_impl.cc
@@ -4,14 +4,14 @@
#include "build/build_config.h"
-#include "chrome/renderer/render_process_impl.h"
-
#if defined(OS_WIN)
#include <windows.h>
#include <objidl.h>
#include <mlang.h>
#endif
+#include "chrome/renderer/render_process_impl.h"
+
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
@@ -31,6 +31,7 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_message_utils.h"
#include "media/base/media.h"
+#include "media/base/media_switches.h"
#include "native_client/src/trusted/plugin/nacl_entry_points.h"
#include "webkit/glue/webkit_glue.h"
@@ -67,8 +68,7 @@ bool LaunchNaClProcess(const char* url,
//-----------------------------------------------------------------------------
RenderProcessImpl::RenderProcessImpl()
- : RenderProcess(),
- ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
+ : ALLOW_THIS_IN_INITIALIZER_LIST(shared_mem_cache_cleaner_(
base::TimeDelta::FromSeconds(5),
this, &RenderProcessImpl::ClearTransportDIBCache)),
transport_dib_next_sequence_number_(0) {
@@ -87,8 +87,9 @@ RenderProcessImpl::RenderProcessImpl()
GetModuleHandle(L"GDI32.DLL"),
"GdiInitializeLanguagePack"));
DCHECK(gdi_init_lpk);
- if (gdi_init_lpk)
+ if (gdi_init_lpk) {
gdi_init_lpk(0);
+ }
}
#endif
@@ -101,7 +102,7 @@ RenderProcessImpl::RenderProcessImpl()
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
webkit_glue::SetJavaScriptFlags(
- command_line.GetSwitchValue(switches::kJavaScriptFlags));
+ command_line.GetSwitchValue(switches::kJavaScriptFlags));
}
if (command_line.HasSwitch(switches::kEnableWatchdog)) {
@@ -117,8 +118,9 @@ RenderProcessImpl::RenderProcessImpl()
RegisterInternalNaClPlugin(LaunchNaClProcess);
#endif
- if (!command_line.HasSwitch(switches::kDisableByteRangeSupport))
+ if (!command_line.HasSwitch(switches::kDisableByteRangeSupport)) {
webkit_glue::SetMediaCacheEnabled(true);
+ }
#if defined(OS_MACOSX)
FilePath bundle_path = mac_util::MainAppBundlePath();
@@ -130,6 +132,12 @@ RenderProcessImpl::RenderProcessImpl()
initialized_media_library_ =
PathService::Get(base::DIR_MODULE, &module_path) &&
media::InitializeMediaLibrary(module_path);
+
+ // TODO(hclam): Add more checks here. Currently this is not used.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableOpenMax)) {
+ media::InitializeOpenMaxLibrary(module_path);
+ }
#endif
}
@@ -144,9 +152,59 @@ RenderProcessImpl::~RenderProcessImpl() {
ClearTransportDIBCache();
}
+bool RenderProcessImpl::InProcessPlugins() {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+#if defined(OS_LINUX)
+ // Plugin processes require a UI message loop, and the Linux message loop
+ // implementation only allows one UI loop per process.
+ if (command_line.HasSwitch(switches::kInProcessPlugins))
+ NOTIMPLEMENTED() << ": in process plugins not supported on Linux";
+ return command_line.HasSwitch(switches::kInProcessPlugins);
+#else
+ return command_line.HasSwitch(switches::kInProcessPlugins) ||
+ command_line.HasSwitch(switches::kSingleProcess);
+#endif
+}
+
+// -----------------------------------------------------------------------------
+// Platform specific code for dealing with bitmap transport...
+
+TransportDIB* RenderProcessImpl::CreateTransportDIB(size_t size) {
+#if defined(OS_WIN) || defined(OS_LINUX)
+ // Windows and Linux create transport DIBs inside the renderer
+ return TransportDIB::Create(size, transport_dib_next_sequence_number_++);
+#elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX)
+ // Mac creates transport DIBs in the browser, so we need to do a sync IPC to
+ // get one.
+ TransportDIB::Handle handle;
+ IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
+ if (!main_thread()->Send(msg))
+ return NULL;
+ if (handle.fd < 0)
+ return NULL;
+ return TransportDIB::Map(handle);
+#endif // defined(OS_MACOSX)
+}
+
+void RenderProcessImpl::FreeTransportDIB(TransportDIB* dib) {
+ if (!dib)
+ return;
+
+#if defined(OS_MACOSX)
+ // On Mac we need to tell the browser that it can drop a reference to the
+ // shared memory.
+ IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
+ main_thread()->Send(msg);
+#endif
+
+ delete dib;
+}
+
+// -----------------------------------------------------------------------------
+
+
skia::PlatformCanvas* RenderProcessImpl::GetDrawingCanvas(
- TransportDIB** memory,
- const gfx::Rect& rect) {
+ TransportDIB** memory, const gfx::Rect& rect) {
int width = rect.width();
int height = rect.height();
const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width());
@@ -167,7 +225,7 @@ skia::PlatformCanvas* RenderProcessImpl::GetDrawingCanvas(
if (!GetTransportDIBFromCache(memory, size)) {
*memory = CreateTransportDIB(size);
if (!*memory)
- return NULL;
+ return false;
}
return (*memory)->GetPlatformCanvas(width, height);
@@ -190,23 +248,8 @@ bool RenderProcessImpl::HasInitializedMediaLibrary() const {
return initialized_media_library_;
}
-// static
-bool RenderProcessImpl::InProcessPlugins() {
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
-#if defined(OS_LINUX)
- // Plugin processes require a UI message loop, and the Linux message loop
- // implementation only allows one UI loop per process.
- if (command_line.HasSwitch(switches::kInProcessPlugins))
- NOTIMPLEMENTED() << ": in process plugins not supported on Linux";
- return command_line.HasSwitch(switches::kInProcessPlugins);
-#else
- return command_line.HasSwitch(switches::kInProcessPlugins) ||
- command_line.HasSwitch(switches::kSingleProcess);
-#endif
-}
-
bool RenderProcessImpl::GetTransportDIBFromCache(TransportDIB** mem,
- size_t size) {
+ size_t size) {
// look for a cached object that is suitable for the requested size.
for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) {
if (shared_mem_cache_[i] &&
@@ -220,24 +263,6 @@ bool RenderProcessImpl::GetTransportDIBFromCache(TransportDIB** mem,
return false;
}
-bool RenderProcessImpl::PutSharedMemInCache(TransportDIB* mem) {
- const int slot = FindFreeCacheSlot(mem->size());
- if (slot == -1)
- return false;
-
- shared_mem_cache_[slot] = mem;
- return true;
-}
-
-void RenderProcessImpl::ClearTransportDIBCache() {
- for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) {
- if (shared_mem_cache_[i]) {
- FreeTransportDIB(shared_mem_cache_[i]);
- shared_mem_cache_[i] = NULL;
- }
- }
-}
-
int RenderProcessImpl::FindFreeCacheSlot(size_t size) {
// simple algorithm:
// - look for an empty slot to store mem, or
@@ -266,33 +291,20 @@ int RenderProcessImpl::FindFreeCacheSlot(size_t size) {
return smallest_index;
}
-TransportDIB* RenderProcessImpl::CreateTransportDIB(size_t size) {
-#if defined(OS_WIN) || defined(OS_LINUX)
- // Windows and Linux create transport DIBs inside the renderer
- return TransportDIB::Create(size, transport_dib_next_sequence_number_++);
-#elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX)
- // Mac creates transport DIBs in the browser, so we need to do a sync IPC to
- // get one.
- TransportDIB::Handle handle;
- IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
- if (!main_thread()->Send(msg))
- return NULL;
- if (handle.fd < 0)
- return NULL;
- return TransportDIB::Map(handle);
-#endif // defined(OS_MACOSX)
-}
-
-void RenderProcessImpl::FreeTransportDIB(TransportDIB* dib) {
- if (!dib)
- return;
+bool RenderProcessImpl::PutSharedMemInCache(TransportDIB* mem) {
+ const int slot = FindFreeCacheSlot(mem->size());
+ if (slot == -1)
+ return false;
-#if defined(OS_MACOSX)
- // On Mac we need to tell the browser that it can drop a reference to the
- // shared memory.
- IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
- main_thread()->Send(msg);
-#endif
+ shared_mem_cache_[slot] = mem;
+ return true;
+}
- delete dib;
+void RenderProcessImpl::ClearTransportDIBCache() {
+ for (size_t i = 0; i < arraysize(shared_mem_cache_); ++i) {
+ if (shared_mem_cache_[i]) {
+ FreeTransportDIB(shared_mem_cache_[i]);
+ shared_mem_cache_[i] = NULL;
+ }
+ }
}