blob: 6e2f5572164fe7cfaec23741cce710917954ca16 [file] [log] [blame]
[email protected]fd911dd2012-01-27 01:57:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]d353541f2012-05-03 22:45:415#include "content/renderer/render_process_impl.h"
6
[email protected]037fce02009-01-22 01:42:157#include "build/build_config.h"
8
[email protected]037fce02009-01-22 01:42:159#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2910#include <windows.h>
11#include <objidl.h>
12#include <mlang.h>
[email protected]037fce02009-01-22 01:42:1513#endif
initial.commit09911bf2008-07-26 23:55:2914
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]037fce02009-01-22 01:42:1516#include "base/compiler_specific.h"
ishell75fddc12016-04-12 14:03:1417#include "base/feature_list.h"
[email protected]35b4f0c2014-06-26 16:55:2718#include "base/sys_info.h"
nicke7cd12a2015-06-17 06:48:3819#include "content/child/site_isolation_stats_gatherer.h"
bradnelsonc79f5a6f2016-10-10 18:31:1420#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2921#include "content/public/common/content_switches.h"
[email protected]d344114c2011-10-01 01:24:3422#include "content/public/renderer/content_renderer_client.h"
[email protected]6bd867b2013-07-24 22:10:2023#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]067f5192014-01-29 05:22:0924#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:2925
ishell75fddc12016-04-12 14:03:1426namespace {
27
28const base::Feature kV8_ES2015_TailCalls_Feature {
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT
30};
31
ishell73f577b2016-04-14 11:59:3932const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT};
34
ishell75fddc12016-04-12 14:03:1435const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager",
36 base::FEATURE_DISABLED_BY_DEFAULT};
37
38const base::Feature kV8SerializeAgeCodeFeature{
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT};
40
41void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
42 if (base::FeatureList::IsEnabled(feature)) {
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
44 }
45}
46
47void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
50 }
51}
52
53} // namespace
54
[email protected]eb398192012-10-22 20:16:1955namespace content {
56
[email protected]396c3a462010-03-03 05:03:2257RenderProcessImpl::RenderProcessImpl()
[email protected]1cf03f7f2014-04-24 03:09:4958 : enabled_bindings_(0) {
[email protected]396c3a462010-03-03 05:03:2259#if defined(OS_WIN)
60 // HACK: See http://b/issue?id=1024307 for rationale.
61 if (GetModuleHandle(L"LPK.DLL") == NULL) {
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
63 // when buffering into a EMF buffer for printing.
64 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
65 GdiInitializeLanguagePack gdi_init_lpk =
66 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress(
67 GetModuleHandle(L"GDI32.DLL"),
68 "GdiInitializeLanguagePack"));
69 DCHECK(gdi_init_lpk);
[email protected]00c39612010-03-06 02:53:2870 if (gdi_init_lpk) {
[email protected]396c3a462010-03-03 05:03:2271 gdi_init_lpk(0);
[email protected]00c39612010-03-06 02:53:2872 }
[email protected]396c3a462010-03-03 05:03:2273 }
[email protected]e68e62fa2009-02-20 02:00:0474#endif
75
[email protected]35b4f0c2014-06-26 16:55:2776 if (base::SysInfo::IsLowEndDevice()) {
[email protected]067f5192014-01-29 05:22:0977 std::string optimize_flag("--optimize-for-size");
78 v8::V8::SetFlagsFromString(optimize_flag.c_str(),
79 static_cast<int>(optimize_flag.size()));
80 }
[email protected]987422f2013-10-01 10:33:3181
ishell75fddc12016-04-12 14:03:1482 SetV8FlagIfFeature(kV8_ES2015_TailCalls_Feature, "--harmony-tailcalls");
ishell73f577b2016-04-14 11:59:3983 SetV8FlagIfFeature(kV8_ES2016_ExplicitTailCalls_Feature,
84 "--harmony-explicit-tailcalls");
ishell75fddc12016-04-12 14:03:1485 SetV8FlagIfFeature(kV8SerializeEagerFeature, "--serialize_eager");
86 SetV8FlagIfFeature(kV8SerializeAgeCodeFeature, "--serialize_age_code");
87 SetV8FlagIfHasSwitch(switches::kDisableJavaScriptHarmonyShipping,
88 "--noharmony-shipping");
89 SetV8FlagIfHasSwitch(switches::kJavaScriptHarmony, "--harmony");
bradnelsonc79f5a6f2016-10-10 18:31:1490 SetV8FlagIfFeature(features::kAsmJsToWebAssembly, "--validate-asm");
91 SetV8FlagIfFeature(features::kWebAssembly, "--expose-wasm");
ishell75fddc12016-04-12 14:03:1492
avi83883c82014-12-23 00:08:4993 const base::CommandLine& command_line =
94 *base::CommandLine::ForCurrentProcess();
ishell75fddc12016-04-12 14:03:1495
[email protected]396c3a462010-03-03 05:03:2296 if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
[email protected]067f5192014-01-29 05:22:0997 std::string flags(
[email protected]95edc392010-07-30 22:00:3898 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
[email protected]067f5192014-01-29 05:22:0999 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
[email protected]396c3a462010-03-03 05:03:22100 }
[email protected]55dd9332013-09-04 17:17:50101
nick88299ba2015-06-16 23:57:41102 SiteIsolationStatsGatherer::SetEnabled(
103 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
[email protected]e68e62fa2009-02-20 02:00:04104}
105
[email protected]396c3a462010-03-03 05:03:22106RenderProcessImpl::~RenderProcessImpl() {
[email protected]396c3a462010-03-03 05:03:22107#ifndef NDEBUG
[email protected]180ef242013-11-07 06:50:46108 int count = blink::WebFrame::instanceCount();
[email protected]6bd867b2013-07-24 22:10:20109 if (count)
110 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
[email protected]396c3a462010-03-03 05:03:22111#endif
[email protected]e68e62fa2009-02-20 02:00:04112
[email protected]396c3a462010-03-03 05:03:22113 GetShutDownEvent()->Signal();
[email protected]396c3a462010-03-03 05:03:22114}
[email protected]e68e62fa2009-02-20 02:00:04115
[email protected]744c2a22012-03-15 18:42:04116void RenderProcessImpl::AddBindings(int bindings) {
117 enabled_bindings_ |= bindings;
118}
119
120int RenderProcessImpl::GetEnabledBindings() const {
121 return enabled_bindings_;
122}
123
[email protected]eb398192012-10-22 20:16:19124} // namespace content