Home | History | Annotate | Download | only in renderer
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/renderer/render_process_impl.h"
      6 
      7 #include "build/build_config.h"
      8 
      9 #if defined(OS_WIN)
     10 #include <windows.h>
     11 #include <objidl.h>
     12 #include <mlang.h>
     13 #endif
     14 
     15 #include "base/basictypes.h"
     16 #include "base/command_line.h"
     17 #include "base/compiler_specific.h"
     18 #include "base/sys_info.h"
     19 #include "content/child/site_isolation_policy.h"
     20 #include "content/public/common/content_switches.h"
     21 #include "content/public/renderer/content_renderer_client.h"
     22 #include "third_party/WebKit/public/web/WebFrame.h"
     23 #include "v8/include/v8.h"
     24 
     25 namespace content {
     26 
     27 RenderProcessImpl::RenderProcessImpl()
     28     : enabled_bindings_(0) {
     29 #if defined(OS_WIN)
     30   // HACK:  See http://b/issue?id=1024307 for rationale.
     31   if (GetModuleHandle(L"LPK.DLL") == NULL) {
     32     // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
     33     // when buffering into a EMF buffer for printing.
     34     typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
     35     GdiInitializeLanguagePack gdi_init_lpk =
     36         reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress(
     37             GetModuleHandle(L"GDI32.DLL"),
     38             "GdiInitializeLanguagePack"));
     39     DCHECK(gdi_init_lpk);
     40     if (gdi_init_lpk) {
     41       gdi_init_lpk(0);
     42     }
     43   }
     44 #endif
     45 
     46   if (base::SysInfo::IsLowEndDevice()) {
     47     std::string optimize_flag("--optimize-for-size");
     48     v8::V8::SetFlagsFromString(optimize_flag.c_str(),
     49                                static_cast<int>(optimize_flag.size()));
     50   }
     51 
     52   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     53   if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
     54     std::string flags(
     55         command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
     56     v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
     57   }
     58 
     59   // Turn on cross-site document blocking for renderer processes.
     60   SiteIsolationPolicy::SetPolicyEnabled(
     61       GetContentClient()->renderer()->ShouldEnableSiteIsolationPolicy());
     62 }
     63 
     64 RenderProcessImpl::~RenderProcessImpl() {
     65 #ifndef NDEBUG
     66   int count = blink::WebFrame::instanceCount();
     67   if (count)
     68     DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
     69 #endif
     70 
     71   GetShutDownEvent()->Signal();
     72 }
     73 
     74 void RenderProcessImpl::AddBindings(int bindings) {
     75   enabled_bindings_ |= bindings;
     76 }
     77 
     78 int RenderProcessImpl::GetEnabledBindings() const {
     79   return enabled_bindings_;
     80 }
     81 
     82 }  // namespace content
     83