| [email protected] | fd911dd | 2012-01-27 01:57:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| [email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 5 | #include "content/renderer/render_process_impl.h" |
| 6 | |
| [email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 7 | #include "build/build_config.h" |
| 8 | |
| [email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 9 | #if defined(OS_WIN) |
| initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include <windows.h> |
| 11 | #include <objidl.h> |
| 12 | #include <mlang.h> |
| [email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 13 | #endif |
| initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | |
| initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/command_line.h" |
| [email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 17 | #include "base/feature_list.h" |
| [email protected] | 35b4f0c | 2014-06-26 16:55:27 | [diff] [blame] | 18 | #include "base/sys_info.h" |
| nick | e7cd12a | 2015-06-17 06:48:38 | [diff] [blame] | 19 | #include "content/child/site_isolation_stats_gatherer.h" |
| bradnelson | c79f5a6f | 2016-10-10 18:31:14 | [diff] [blame^] | 20 | #include "content/public/common/content_features.h" |
| [email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 21 | #include "content/public/common/content_switches.h" |
| [email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 22 | #include "content/public/renderer/content_renderer_client.h" |
| [email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 23 | #include "third_party/WebKit/public/web/WebFrame.h" |
| [email protected] | 067f519 | 2014-01-29 05:22:09 | [diff] [blame] | 24 | #include "v8/include/v8.h" |
| initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | const base::Feature kV8_ES2015_TailCalls_Feature { |
| 29 | "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT |
| 30 | }; |
| 31 | |
| ishell | 73f577b | 2016-04-14 11:59:39 | [diff] [blame] | 32 | const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ |
| 33 | "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 34 | |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 35 | const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", |
| 36 | base::FEATURE_DISABLED_BY_DEFAULT}; |
| 37 | |
| 38 | const base::Feature kV8SerializeAgeCodeFeature{ |
| 39 | "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 40 | |
| 41 | void 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 | |
| 47 | void 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] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 55 | namespace content { |
| 56 | |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 57 | RenderProcessImpl::RenderProcessImpl() |
| [email protected] | 1cf03f7f | 2014-04-24 03:09:49 | [diff] [blame] | 58 | : enabled_bindings_(0) { |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 59 | #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] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 70 | if (gdi_init_lpk) { |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 71 | gdi_init_lpk(0); |
| [email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 72 | } |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 73 | } |
| [email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 74 | #endif |
| 75 | |
| [email protected] | 35b4f0c | 2014-06-26 16:55:27 | [diff] [blame] | 76 | if (base::SysInfo::IsLowEndDevice()) { |
| [email protected] | 067f519 | 2014-01-29 05:22:09 | [diff] [blame] | 77 | 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] | 987422f | 2013-10-01 10:33:31 | [diff] [blame] | 81 | |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 82 | SetV8FlagIfFeature(kV8_ES2015_TailCalls_Feature, "--harmony-tailcalls"); |
| ishell | 73f577b | 2016-04-14 11:59:39 | [diff] [blame] | 83 | SetV8FlagIfFeature(kV8_ES2016_ExplicitTailCalls_Feature, |
| 84 | "--harmony-explicit-tailcalls"); |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 85 | SetV8FlagIfFeature(kV8SerializeEagerFeature, "--serialize_eager"); |
| 86 | SetV8FlagIfFeature(kV8SerializeAgeCodeFeature, "--serialize_age_code"); |
| 87 | SetV8FlagIfHasSwitch(switches::kDisableJavaScriptHarmonyShipping, |
| 88 | "--noharmony-shipping"); |
| 89 | SetV8FlagIfHasSwitch(switches::kJavaScriptHarmony, "--harmony"); |
| bradnelson | c79f5a6f | 2016-10-10 18:31:14 | [diff] [blame^] | 90 | SetV8FlagIfFeature(features::kAsmJsToWebAssembly, "--validate-asm"); |
| 91 | SetV8FlagIfFeature(features::kWebAssembly, "--expose-wasm"); |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 92 | |
| avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 93 | const base::CommandLine& command_line = |
| 94 | *base::CommandLine::ForCurrentProcess(); |
| ishell | 75fddc1 | 2016-04-12 14:03:14 | [diff] [blame] | 95 | |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 96 | if (command_line.HasSwitch(switches::kJavaScriptFlags)) { |
| [email protected] | 067f519 | 2014-01-29 05:22:09 | [diff] [blame] | 97 | std::string flags( |
| [email protected] | 95edc39 | 2010-07-30 22:00:38 | [diff] [blame] | 98 | command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); |
| [email protected] | 067f519 | 2014-01-29 05:22:09 | [diff] [blame] | 99 | v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 100 | } |
| [email protected] | 55dd933 | 2013-09-04 17:17:50 | [diff] [blame] | 101 | |
| nick | 88299ba | 2015-06-16 23:57:41 | [diff] [blame] | 102 | SiteIsolationStatsGatherer::SetEnabled( |
| 103 | GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); |
| [email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 104 | } |
| 105 | |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 106 | RenderProcessImpl::~RenderProcessImpl() { |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 107 | #ifndef NDEBUG |
| [email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 108 | int count = blink::WebFrame::instanceCount(); |
| [email protected] | 6bd867b | 2013-07-24 22:10:20 | [diff] [blame] | 109 | if (count) |
| 110 | DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 111 | #endif |
| [email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 112 | |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 113 | GetShutDownEvent()->Signal(); |
| [email protected] | 396c3a46 | 2010-03-03 05:03:22 | [diff] [blame] | 114 | } |
| [email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 115 | |
| [email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 116 | void RenderProcessImpl::AddBindings(int bindings) { |
| 117 | enabled_bindings_ |= bindings; |
| 118 | } |
| 119 | |
| 120 | int RenderProcessImpl::GetEnabledBindings() const { |
| 121 | return enabled_bindings_; |
| 122 | } |
| 123 | |
| [email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 124 | } // namespace content |