blob: 57713f55f4354a06386d974c5506ae6bdefd6773 [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
9#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"
[email protected]c08950d22011-10-13 22:20:2920#include "content/public/common/content_switches.h"
[email protected]d344114c2011-10-01 01:24:3421#include "content/public/renderer/content_renderer_client.h"
[email protected]6bd867b2013-07-24 22:10:2022#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]067f5192014-01-29 05:22:0923#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:2924
ishell75fddc12016-04-12 14:03:1425namespace {
26
27const base::Feature kV8_ES2015_TailCalls_Feature {
28 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT
29};
30
ishell73f577b2016-04-14 11:59:3931const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{
32 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT};
33
ishell75fddc12016-04-12 14:03:1434const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager",
35 base::FEATURE_DISABLED_BY_DEFAULT};
36
37const base::Feature kV8SerializeAgeCodeFeature{
38 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT};
39
40void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
41 if (base::FeatureList::IsEnabled(feature)) {
42 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
43 }
44}
45
46void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
47 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
48 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
49 }
50}
51
52} // namespace
53
[email protected]eb398192012-10-22 20:16:1954namespace content {
55
[email protected]396c3a462010-03-03 05:03:2256RenderProcessImpl::RenderProcessImpl()
[email protected]1cf03f7f2014-04-24 03:09:4957 : enabled_bindings_(0) {
[email protected]396c3a462010-03-03 05:03:2258#if defined(OS_WIN)
59 // HACK: See http://b/issue?id=1024307 for rationale.
60 if (GetModuleHandle(L"LPK.DLL") == NULL) {
61 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
62 // when buffering into a EMF buffer for printing.
63 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
64 GdiInitializeLanguagePack gdi_init_lpk =
65 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress(
66 GetModuleHandle(L"GDI32.DLL"),
67 "GdiInitializeLanguagePack"));
68 DCHECK(gdi_init_lpk);
[email protected]00c39612010-03-06 02:53:2869 if (gdi_init_lpk) {
[email protected]396c3a462010-03-03 05:03:2270 gdi_init_lpk(0);
[email protected]00c39612010-03-06 02:53:2871 }
[email protected]396c3a462010-03-03 05:03:2272 }
[email protected]e68e62fa2009-02-20 02:00:0473#endif
74
[email protected]35b4f0c2014-06-26 16:55:2775 if (base::SysInfo::IsLowEndDevice()) {
[email protected]067f5192014-01-29 05:22:0976 std::string optimize_flag("--optimize-for-size");
77 v8::V8::SetFlagsFromString(optimize_flag.c_str(),
78 static_cast<int>(optimize_flag.size()));
79 }
[email protected]987422f2013-10-01 10:33:3180
ishell75fddc12016-04-12 14:03:1481 SetV8FlagIfFeature(kV8_ES2015_TailCalls_Feature, "--harmony-tailcalls");
ishell73f577b2016-04-14 11:59:3982 SetV8FlagIfFeature(kV8_ES2016_ExplicitTailCalls_Feature,
83 "--harmony-explicit-tailcalls");
ishell75fddc12016-04-12 14:03:1484 SetV8FlagIfFeature(kV8SerializeEagerFeature, "--serialize_eager");
85 SetV8FlagIfFeature(kV8SerializeAgeCodeFeature, "--serialize_age_code");
86 SetV8FlagIfHasSwitch(switches::kDisableJavaScriptHarmonyShipping,
87 "--noharmony-shipping");
88 SetV8FlagIfHasSwitch(switches::kJavaScriptHarmony, "--harmony");
jppfd14dda2016-08-11 12:23:2889 SetV8FlagIfHasSwitch(switches::kEnableAsmWasm, "--validate-asm");
ishell75fddc12016-04-12 14:03:1490 SetV8FlagIfHasSwitch(switches::kEnableWasm, "--expose-wasm");
91
avi83883c82014-12-23 00:08:4992 const base::CommandLine& command_line =
93 *base::CommandLine::ForCurrentProcess();
ishell75fddc12016-04-12 14:03:1494
[email protected]396c3a462010-03-03 05:03:2295 if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
[email protected]067f5192014-01-29 05:22:0996 std::string flags(
[email protected]95edc392010-07-30 22:00:3897 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
[email protected]067f5192014-01-29 05:22:0998 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
[email protected]396c3a462010-03-03 05:03:2299 }
[email protected]55dd9332013-09-04 17:17:50100
nick88299ba2015-06-16 23:57:41101 SiteIsolationStatsGatherer::SetEnabled(
102 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
[email protected]e68e62fa2009-02-20 02:00:04103}
104
[email protected]396c3a462010-03-03 05:03:22105RenderProcessImpl::~RenderProcessImpl() {
[email protected]396c3a462010-03-03 05:03:22106#ifndef NDEBUG
[email protected]180ef242013-11-07 06:50:46107 int count = blink::WebFrame::instanceCount();
[email protected]6bd867b2013-07-24 22:10:20108 if (count)
109 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
[email protected]396c3a462010-03-03 05:03:22110#endif
[email protected]e68e62fa2009-02-20 02:00:04111
[email protected]396c3a462010-03-03 05:03:22112 GetShutDownEvent()->Signal();
[email protected]396c3a462010-03-03 05:03:22113}
[email protected]e68e62fa2009-02-20 02:00:04114
[email protected]744c2a22012-03-15 18:42:04115void RenderProcessImpl::AddBindings(int bindings) {
116 enabled_bindings_ |= bindings;
117}
118
119int RenderProcessImpl::GetEnabledBindings() const {
120 return enabled_bindings_;
121}
122
[email protected]eb398192012-10-22 20:16:19123} // namespace content