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