From 812b52988133bf13a8419411b8a020d15e87211d Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 14 Jul 2017 01:27:03 +0300 Subject: [PATCH] Add app.disableDomainBlockingFor3DAPIs() By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per domain basis if the GPU processes crashes too frequently. This function disables that behaviour. --- atom/browser/api/atom_api_app.cc | 14 ++++++++++++++ atom/browser/api/atom_api_app.h | 1 + docs/api/app.md | 8 ++++++++ spec/api-app-spec.js | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index b223f9e3f82f..06d4dd8aaf5b 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -35,6 +35,7 @@ #include "chrome/browser/icon_manager.h" #include "chrome/common/chrome_paths.h" #include "content/browser/gpu/compositor_util.h" +#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/public/browser/browser_accessibility_state.h" #include "content/public/browser/browser_child_process_host.h" #include "content/public/browser/child_process_data.h" @@ -852,6 +853,17 @@ void App::DisableHardwareAcceleration(mate::Arguments* args) { content::GpuDataManager::GetInstance()->DisableHardwareAcceleration(); } +void App::DisableDomainBlockingFor3DAPIs(mate::Arguments* args) { + if (Browser::Get()->is_ready()) { + args->ThrowError( + "app.disableDomainBlockingFor3DAPIs() can only be called " + "before app is ready"); + return; + } + content::GpuDataManagerImpl::GetInstance() + ->DisableDomainBlockingFor3DAPIsForTesting(); +} + bool App::IsAccessibilitySupportEnabled() { auto ax_state = content::BrowserAccessibilityState::GetInstance(); return ax_state->IsAccessibleBrowser(); @@ -1131,6 +1143,8 @@ void App::BuildPrototype( &App::IsAccessibilitySupportEnabled) .SetMethod("disableHardwareAcceleration", &App::DisableHardwareAcceleration) + .SetMethod("disableDomainBlockingFor3DAPIs", + &App::DisableDomainBlockingFor3DAPIs) .SetMethod("getFileIcon", &App::GetFileIcon) .SetMethod("getAppMetrics", &App::GetAppMetrics) .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus) diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index a6c4ef0bebdf..694a3e304730 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -169,6 +169,7 @@ class App : public AtomBrowserClient::Delegate, void ReleaseSingleInstance(); bool Relaunch(mate::Arguments* args); void DisableHardwareAcceleration(mate::Arguments* args); + void DisableDomainBlockingFor3DAPIs(mate::Arguments* args); bool IsAccessibilitySupportEnabled(); Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args); #if defined(USE_NSS_CERTS) diff --git a/docs/api/app.md b/docs/api/app.md index 82ae0e50f2fd..fa9d16d0ebd7 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -772,6 +772,14 @@ Disables hardware acceleration for current app. This method can only be called before app is ready. +### `app.disableDomainBlockingFor3DAPIs()` + +By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per +domain basis if the GPU processes crashes too frequently. This function +disables that behaviour. + +This method can only be called before app is ready. + ### `app.getAppMemoryInfo()` _Deprecated_ Returns [`ProcessMetric[]`](structures/process-metric.md): Array of `ProcessMetric` objects that correspond to memory and cpu usage statistics of all the processes associated with the app. diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 8932ac87faaa..1121521b6be9 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -647,4 +647,12 @@ describe('app module', function () { }) }) }) + + describe('disableDomainBlockingFor3DAPIs() API', function () { + it('throws when called after app is ready', function () { + assert.throws(function () { + app.disableDomainBlockingFor3DAPIs() + }, /before app is ready/) + }) + }) })