diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:20:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-15 10:28:57 +0000 |
commit | d17ea114e5ef69ad5d5d7413280a13e6428098aa (patch) | |
tree | 2c01a75df69f30d27b1432467cfe7c1467a498da /chromium/third_party/blink/renderer/controller | |
parent | 8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (diff) | |
download | qtwebengine-chromium-d17ea114e5ef69ad5d5d7413280a13e6428098aa.tar.gz |
BASELINE: Update Chromium to 67.0.3396.47
Change-Id: Idcb1341782e417561a2473eeecc82642dafda5b7
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/controller')
12 files changed, 784 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/controller/BUILD.gn b/chromium/third_party/blink/renderer/controller/BUILD.gn new file mode 100644 index 00000000000..7f3cf01859a --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/BUILD.gn @@ -0,0 +1,126 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//build/config/jumbo.gni") +import("//build/config/ui.gni") +import("//testing/test.gni") +import("//third_party/blink/renderer/bindings/bindings.gni") +import("//third_party/blink/renderer/config.gni") +import("//third_party/blink/renderer/core/core.gni") +import("//third_party/blink/renderer/modules/modules.gni") + +visibility = [ "//third_party/blink/*" ] + +component("controller") { + output_name = "blink_controller" + + deps = [ + "//skia", + "//third_party/blink/renderer/core", + "//third_party/blink/renderer/modules", + "//third_party/blink/renderer/platform", + "//v8", + ] + + configs += [ + "//build/config/compiler:wexit_time_destructors", + "//third_party/blink/renderer:config", + "//third_party/blink/renderer:inside_blink", + "//third_party/blink/renderer:non_test_config", + "//third_party/blink/renderer/core:blink_core_pch", + ] + + defines = [ "BLINK_CONTROLLER_IMPLEMENTATION=1" ] + + sources = [ + "blink_initializer.cc", + "blink_initializer.h", + "controller_export.h", + "dev_tools_frontend_impl.cc", + "dev_tools_frontend_impl.h", + "oom_intervention_impl.cc", + "oom_intervention_impl.h", + ] + + if (is_mac) { + libs = [ + "AppKit.framework", + "Foundation.framework", + ] + } + + configs -= [ "//build/config/compiler:default_symbols" ] + configs += blink_symbols_config +} + +group("webkit_unit_tests_data") { + data = [ + "../core/testing/data/", + "../core/paint/test_data/", + "../core/animation/test_data/", + "../core/css/test_data/", + ] +} + +test("webkit_unit_tests") { + deps = [ + ":webkit_unit_tests_sources", + ] + + data_deps = [ + ":webkit_unit_tests_data", + "//content/shell:pak", + ] + + if (is_android) { + enable_multidex = true + deps += [ + "//base:base_java", + "//content/public/android:content_java", + "//content/shell/android:content_shell_assets", + "//net/android:net_java", + ] + } +} + +jumbo_source_set("webkit_unit_tests_sources") { + visibility = [] # Allow re-assignment of list. + visibility = [ "*" ] + testonly = true + + sources = [ + "oom_intervention_impl_test.cc", + "tests/run_all_tests.cc", + ] + sources += bindings_unittest_files + + deps = [ + ":controller", + "//base", + "//base:i18n", + "//base/test:test_support", + "//components/payments/mojom:mojom_blink", + "//content/test:test_support", + "//gpu:test_support", + "//testing/gmock", + "//testing/gtest", + "//third_party/blink/renderer/core:unit_tests", + "//third_party/blink/renderer/modules:unit_tests", + "//third_party/blink/renderer/modules/exported:test_support", + "//third_party/blink/renderer/platform", + "//third_party/blink/renderer/platform:test_support", + "//third_party/blink/renderer/platform:unit_tests", + "//third_party/blink/renderer/platform/wtf", + "//third_party/libwebp", + "//third_party/zlib", + "//url", + "//v8", + ] + + configs += [ + "//third_party/blink/renderer:config", + "//third_party/blink/renderer:inside_blink", + "//third_party/blink/renderer/core:blink_core_pch", + ] +} diff --git a/chromium/third_party/blink/renderer/controller/DEPS b/chromium/third_party/blink/renderer/controller/DEPS new file mode 100644 index 00000000000..1b72c4c6fb1 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/DEPS @@ -0,0 +1,9 @@ +include_rules = [ + "+mojo/public", + "+third_party/blink/public/web", + "+third_party/blink/renderer/bindings", + "+third_party/blink/renderer/controller", + "+third_party/blink/renderer/core", + "+third_party/blink/renderer/modules", + "+web", +] diff --git a/chromium/third_party/blink/renderer/controller/OWNERS b/chromium/third_party/blink/renderer/controller/OWNERS new file mode 100644 index 00000000000..c4622a1fe9e --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/OWNERS @@ -0,0 +1,9 @@ +dcheng@chromium.org +haraken@chromium.org +nverne@chromium.org +slangley@chromium.org +tkent@chromium.org + + +# TEAM: platform-architecture-dev@chromium.org +# COMPONENT: Blink>Internals>Modularization diff --git a/chromium/third_party/blink/renderer/controller/README.md b/chromium/third_party/blink/renderer/controller/README.md new file mode 100644 index 00000000000..1309feb76f2 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/README.md @@ -0,0 +1,5 @@ +# The controller/ directory + +controller/ contains the system infrastructure of the renderer process that uses or drives the web platform. controller/ can directly use core/ and modules/ without using Web types (but with some DEPS rules). Examples are RenderProcess, RenderThread, Android View, Extensions, Native Client etc. + +We should avoid making controller/ a "catch-all" directory. Things that are part of core/ should go to core/. Things that are part of modules/ should go to modules/. Only things that lives outside the web platform should go to controller/. diff --git a/chromium/third_party/blink/renderer/controller/blink_initializer.cc b/chromium/third_party/blink/renderer/controller/blink_initializer.cc new file mode 100644 index 00000000000..442becb3a09 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/blink_initializer.cc @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "third_party/blink/renderer/controller/blink_initializer.h" + +#include <memory> + +#include "build/build_config.h" +#include "third_party/blink/public/platform/interface_registry.h" +#include "third_party/blink/public/platform/platform.h" +#include "third_party/blink/public/platform/web_thread.h" +#include "third_party/blink/public/web/blink.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_context_snapshot_external_references.h" +#include "third_party/blink/renderer/controller/dev_tools_frontend_impl.h" +#include "third_party/blink/renderer/controller/oom_intervention_impl.h" +#include "third_party/blink/renderer/core/animation/animation_clock.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" +#include "third_party/blink/renderer/platform/bindings/microtask.h" +#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" +#include "third_party/blink/renderer/platform/heap/heap.h" +#include "third_party/blink/renderer/platform/histogram.h" +#include "third_party/blink/renderer/platform/wtf/assertions.h" +#include "third_party/blink/renderer/platform/wtf/functional.h" +#include "third_party/blink/renderer/platform/wtf/wtf.h" +#include "v8/include/v8.h" + +namespace blink { + +namespace { + +class EndOfTaskRunner : public WebThread::TaskObserver { + public: + void WillProcessTask() override { AnimationClock::NotifyTaskStart(); } + void DidProcessTask() override { + Microtask::PerformCheckpoint(V8PerIsolateData::MainThreadIsolate()); + V8Initializer::ReportRejectedPromisesOnMainThread(); + } +}; + +} // namespace + +static WebThread::TaskObserver* g_end_of_task_runner = nullptr; + +static BlinkInitializer& GetBlinkInitializer() { + DEFINE_STATIC_LOCAL(std::unique_ptr<BlinkInitializer>, initializer, + (std::make_unique<BlinkInitializer>())); + return *initializer; +} + +void Initialize(Platform* platform, service_manager::BinderRegistry* registry) { + DCHECK(registry); + Platform::Initialize(platform); + +#if !defined(ARCH_CPU_X86_64) && !defined(ARCH_CPU_ARM64) && defined(OS_WIN) + // Reserve address space on 32 bit Windows, to make it likelier that large + // array buffer allocations succeed. + BOOL is_wow_64 = -1; + if (!IsWow64Process(GetCurrentProcess(), &is_wow_64)) + is_wow_64 = FALSE; + if (!is_wow_64) { + // Try to reserve as much address space as we reasonably can. + const size_t kMB = 1024 * 1024; + for (size_t size = 512 * kMB; size >= 32 * kMB; size -= 16 * kMB) { + if (base::ReserveAddressSpace(size)) { + // Report successful reservation. + DEFINE_STATIC_LOCAL(CustomCountHistogram, reservation_size_histogram, + ("Renderer4.ReservedMemory", 32, 512, 32)); + reservation_size_histogram.Count(size / kMB); + + break; + } + } + } +#endif // !defined(ARCH_CPU_X86_64) && !defined(ARCH_CPU_ARM64) && + // defined(OS_WIN) + + // BlinkInitializer::Initialize() must be called before InitializeMainThread + GetBlinkInitializer().Initialize(); + + V8Initializer::InitializeMainThread( + V8ContextSnapshotExternalReferences::GetTable()); + + GetBlinkInitializer().RegisterInterfaces(*registry); + + // currentThread is null if we are running on a thread without a message loop. + if (WebThread* current_thread = platform->CurrentThread()) { + DCHECK(!g_end_of_task_runner); + g_end_of_task_runner = new EndOfTaskRunner; + current_thread->AddTaskObserver(g_end_of_task_runner); + } +} + +void BlinkInitializer::RegisterInterfaces( + service_manager::BinderRegistry& registry) { + ModulesInitializer::RegisterInterfaces(registry); + WebThread* main_thread = Platform::Current()->MainThread(); + // GetSingleThreadTaskRunner() uses GetTaskRunner() internally. + // crbug.com/781664 + if (!main_thread || !main_thread->GetTaskRunner()) + return; + + registry.AddInterface( + ConvertToBaseCallback(CrossThreadBind(&OomInterventionImpl::Create)), + main_thread->GetTaskRunner()); +} + +void BlinkInitializer::InitLocalFrame(LocalFrame& frame) const { + frame.GetInterfaceRegistry()->AddAssociatedInterface(WTF::BindRepeating( + &DevToolsFrontendImpl::BindMojoRequest, WrapWeakPersistent(&frame))); + ModulesInitializer::InitLocalFrame(frame); +} + +void BlinkInitializer::OnClearWindowObjectInMainWorld( + Document& document, + const Settings& settings) const { + if (DevToolsFrontendImpl* devtools_frontend = + DevToolsFrontendImpl::From(document.GetFrame())) { + devtools_frontend->DidClearWindowObject(); + } + ModulesInitializer::OnClearWindowObjectInMainWorld(document, settings); +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/controller/blink_initializer.h b/chromium/third_party/blink/renderer/controller/blink_initializer.h new file mode 100644 index 00000000000..a7179d2abac --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/blink_initializer.h @@ -0,0 +1,22 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_BLINK_INITIALIZER_H_ +#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_BLINK_INITIALIZER_H_ + +#include "third_party/blink/renderer/modules/modules_initializer.h" + +namespace blink { + +class BlinkInitializer : public ModulesInitializer { + public: + void RegisterInterfaces(service_manager::BinderRegistry&) override; + void OnClearWindowObjectInMainWorld(Document&, + const Settings&) const override; + void InitLocalFrame(LocalFrame&) const override; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_CONTROLLER_BLINK_INITIALIZER_H_ diff --git a/chromium/third_party/blink/renderer/controller/controller_export.h b/chromium/third_party/blink/renderer/controller/controller_export.h new file mode 100644 index 00000000000..963dccd50ab --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/controller_export.h @@ -0,0 +1,29 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_CONTROLLER_EXPORT_H_ +#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_CONTROLLER_EXPORT_H_ + +namespace blink { + +// This macro is intended to export symbols in Source/controller/ which are +// still private to Blink (for instance, because they are used in unit tests). + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) +#if BLINK_CONTROLLER_IMPLEMENTATION +#define CONTROLLER_EXPORT __declspec(dllexport) +#else +#define CONTROLLER_EXPORT __declspec(dllimport) +#endif // BLINK_CONTROLLER_IMPLEMENTATION +#else // defined(WIN32) +#define CONTROLLER_EXPORT __attribute__((visibility("default"))) +#endif +#else // defined(COMPONENT_BUILD) +#define CONTROLLER_EXPORT +#endif + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_CONTROLLER_CONTROLLER_EXPORT_H_ diff --git a/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.cc b/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.cc new file mode 100644 index 00000000000..bc771367026 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.cc @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "third_party/blink/renderer/controller/dev_tools_frontend_impl.h" + +#include "third_party/blink/renderer/bindings/core/v8/script_controller.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" +#include "third_party/blink/renderer/bindings/core/v8/v8_dev_tools_host.h" +#include "third_party/blink/renderer/core/exported/web_view_impl.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" +#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" +#include "third_party/blink/renderer/core/inspector/dev_tools_host.h" +#include "third_party/blink/renderer/core/page/page.h" + +namespace blink { + +// static +void DevToolsFrontendImpl::BindMojoRequest( + LocalFrame* local_frame, + mojom::blink::DevToolsFrontendAssociatedRequest request) { + if (!local_frame) + return; + local_frame->ProvideSupplement( + new DevToolsFrontendImpl(*local_frame, std::move(request))); +} + +// static +DevToolsFrontendImpl* DevToolsFrontendImpl::From(LocalFrame* local_frame) { + if (!local_frame) + return nullptr; + return local_frame->RequireSupplement<DevToolsFrontendImpl>(); +} + +// static +const char DevToolsFrontendImpl::kSupplementName[] = "DevToolsFrontendImpl"; + +DevToolsFrontendImpl::DevToolsFrontendImpl( + LocalFrame& frame, + mojom::blink::DevToolsFrontendAssociatedRequest request) + : Supplement<LocalFrame>(frame), binding_(this, std::move(request)) {} + +DevToolsFrontendImpl::~DevToolsFrontendImpl() = default; + +void DevToolsFrontendImpl::DidClearWindowObject() { + if (host_) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + // Use higher limit for DevTools isolate so that it does not OOM when + // profiling large heaps. + isolate->IncreaseHeapLimitForDebugging(); + ScriptState* script_state = ToScriptStateForMainWorld(GetSupplementable()); + DCHECK(script_state); + ScriptState::Scope scope(script_state); + if (devtools_host_) + devtools_host_->DisconnectClient(); + devtools_host_ = DevToolsHost::Create(this, GetSupplementable()); + v8::Local<v8::Object> global = script_state->GetContext()->Global(); + v8::Local<v8::Value> devtools_host_obj = + ToV8(devtools_host_.Get(), global, script_state->GetIsolate()); + DCHECK(!devtools_host_obj.IsEmpty()); + global->Set(V8AtomicString(isolate, "DevToolsHost"), devtools_host_obj); + } + + if (!api_script_.IsEmpty()) { + GetSupplementable()->GetScriptController().ExecuteScriptInMainWorld( + api_script_); + } +} + +void DevToolsFrontendImpl::SetupDevToolsFrontend( + const String& api_script, + mojom::blink::DevToolsFrontendHostAssociatedPtrInfo host) { + DCHECK(GetSupplementable()->IsMainFrame()); + api_script_ = api_script; + host_.Bind(std::move(host)); + host_.set_connection_error_handler(WTF::Bind( + &DevToolsFrontendImpl::DestroyOnHostGone, WrapWeakPersistent(this))); + GetSupplementable()->GetPage()->SetDefaultPageScaleLimits(1.f, 1.f); +} + +void DevToolsFrontendImpl::SetupDevToolsExtensionAPI( + const String& extension_api) { + DCHECK(!GetSupplementable()->IsMainFrame()); + api_script_ = extension_api; +} + +void DevToolsFrontendImpl::SendMessageToEmbedder(const String& message) { + if (host_) + host_->DispatchEmbedderMessage(message); +} + +void DevToolsFrontendImpl::ShowContextMenu(LocalFrame* target_frame, + float x, + float y, + ContextMenuProvider* menu_provider) { + WebLocalFrameImpl::FromFrame(target_frame) + ->ViewImpl() + ->ShowContextMenuAtPoint(x, y, menu_provider); +} + +void DevToolsFrontendImpl::DestroyOnHostGone() { + if (devtools_host_) + devtools_host_->DisconnectClient(); + GetSupplementable()->RemoveSupplement<DevToolsFrontendImpl>(); +} + +void DevToolsFrontendImpl::Trace(blink::Visitor* visitor) { + visitor->Trace(devtools_host_); + Supplement<LocalFrame>::Trace(visitor); +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.h b/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.h new file mode 100644 index 00000000000..1fb6e08d887 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/dev_tools_frontend_impl.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_DEV_TOOLS_FRONTEND_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_DEV_TOOLS_FRONTEND_IMPL_H_ + +#include "base/macros.h" +#include "mojo/public/cpp/bindings/associated_binding.h" +#include "third_party/blink/public/web/devtools_frontend.mojom-blink.h" +#include "third_party/blink/renderer/core/inspector/inspector_frontend_client.h" +#include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/supplementable.h" +#include "third_party/blink/renderer/platform/wtf/hash_map.h" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +class DevToolsHost; +class LocalFrame; + +// This class lives as long as a frame (being a supplement), or until +// it's host (mojom.DevToolsFrontendHost) is destroyed. +class DevToolsFrontendImpl final + : public GarbageCollectedFinalized<DevToolsFrontendImpl>, + public Supplement<LocalFrame>, + public mojom::blink::DevToolsFrontend, + public InspectorFrontendClient { + USING_GARBAGE_COLLECTED_MIXIN(DevToolsFrontendImpl); + + public: + static const char kSupplementName[]; + + static void BindMojoRequest(LocalFrame*, + mojom::blink::DevToolsFrontendAssociatedRequest); + static DevToolsFrontendImpl* From(LocalFrame*); + + ~DevToolsFrontendImpl() override; + void DidClearWindowObject(); + void Trace(blink::Visitor*); + + private: + DevToolsFrontendImpl(LocalFrame&, + mojom::blink::DevToolsFrontendAssociatedRequest); + void DestroyOnHostGone(); + + // mojom::blink::DevToolsFrontend implementation. + void SetupDevToolsFrontend( + const String& api_script, + mojom::blink::DevToolsFrontendHostAssociatedPtrInfo) override; + void SetupDevToolsExtensionAPI(const String& extension_api) override; + + // InspectorFrontendClient implementation. + void SendMessageToEmbedder(const String&) override; + void ShowContextMenu(LocalFrame*, + float x, + float y, + ContextMenuProvider*) override; + + Member<DevToolsHost> devtools_host_; + String api_script_; + mojom::blink::DevToolsFrontendHostAssociatedPtr host_; + mojo::AssociatedBinding<mojom::blink::DevToolsFrontend> binding_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsFrontendImpl); +}; + +} // namespace blink + +#endif diff --git a/chromium/third_party/blink/renderer/controller/oom_intervention_impl.cc b/chromium/third_party/blink/renderer/controller/oom_intervention_impl.cc new file mode 100644 index 00000000000..83b8c23a92d --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/oom_intervention_impl.cc @@ -0,0 +1,82 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/controller/oom_intervention_impl.h" + +#include "mojo/public/cpp/bindings/strong_binding.h" +#include "third_party/blink/public/platform/platform.h" +#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" +#include "third_party/blink/renderer/platform/heap/handle.h" +#include "third_party/blink/renderer/platform/web_task_runner.h" +#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h" + +namespace blink { + +namespace { + +// Roughly caclculates amount of memory which is used to execute pages. +size_t BlinkMemoryWorkloadCaculator() { + v8::Isolate* isolate = V8PerIsolateData::MainThreadIsolate(); + DCHECK(isolate); + v8::HeapStatistics heap_statistics; + isolate->GetHeapStatistics(&heap_statistics); + // TODO: Add memory usage for worker threads. + size_t v8_size = + heap_statistics.total_heap_size() + heap_statistics.malloced_memory(); + size_t blink_gc_size = ProcessHeap::TotalAllocatedObjectSize() + + ProcessHeap::TotalMarkedObjectSize(); + size_t partition_alloc_size = WTF::Partitions::TotalSizeOfCommittedPages(); + return v8_size + blink_gc_size + partition_alloc_size; +} + +} // namespace + +// If memory workload is above this threshold, we assume that we are in a +// near-OOM situation. +const size_t OomInterventionImpl::kMemoryWorkloadThreshold = 80 * 1024 * 1024; + +// static +void OomInterventionImpl::Create(mojom::blink::OomInterventionRequest request) { + mojo::MakeStrongBinding( + std::make_unique<OomInterventionImpl>( + WTF::BindRepeating(&BlinkMemoryWorkloadCaculator)), + std::move(request)); +} + +OomInterventionImpl::OomInterventionImpl( + MemoryWorkloadCaculator workload_calculator) + : workload_calculator_(std::move(workload_calculator)), + timer_(Platform::Current()->MainThread()->GetTaskRunner(), + this, + &OomInterventionImpl::Check) { + DCHECK(workload_calculator_); +} + +OomInterventionImpl::~OomInterventionImpl() = default; + +void OomInterventionImpl::StartDetection( + mojom::blink::OomInterventionHostPtr host, + bool trigger_intervention) { + host_ = std::move(host); + trigger_intervention_ = trigger_intervention; + + timer_.Start(TimeDelta(), TimeDelta::FromSeconds(1), FROM_HERE); +} + +void OomInterventionImpl::Check(TimerBase*) { + DCHECK(host_); + + size_t workload = workload_calculator_.Run(); + if (workload > kMemoryWorkloadThreshold) { + host_->OnHighMemoryUsage(trigger_intervention_); + + if (trigger_intervention_) { + // The ScopedPagePauser is destroyed when the intervention is declined and + // mojo strong binding is disconnected. + pauser_.reset(new ScopedPagePauser); + } + } +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/controller/oom_intervention_impl.h b/chromium/third_party/blink/renderer/controller/oom_intervention_impl.h new file mode 100644 index 00000000000..a3b3b7234ca --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/oom_intervention_impl.h @@ -0,0 +1,50 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_OOM_INTERVENTION_IMPL_H_ +#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_OOM_INTERVENTION_IMPL_H_ + +#include "third_party/blink/public/platform/oom_intervention.mojom-blink.h" +#include "third_party/blink/renderer/controller/controller_export.h" +#include "third_party/blink/renderer/core/page/scoped_page_pauser.h" +#include "third_party/blink/renderer/platform/timer.h" + +namespace blink { + +class OomInterventionImplTest; + +// Implementation of OOM intervention. This pauses all pages by using +// ScopedPagePauser when near-OOM situation is detected. +class CONTROLLER_EXPORT OomInterventionImpl + : public mojom::blink::OomIntervention { + public: + static void Create(mojom::blink::OomInterventionRequest); + + using MemoryWorkloadCaculator = base::RepeatingCallback<size_t()>; + + explicit OomInterventionImpl(MemoryWorkloadCaculator); + ~OomInterventionImpl() override; + + // mojom::blink::OomIntervention: + void StartDetection(mojom::blink::OomInterventionHostPtr, + bool trigger_intervention) override; + + private: + FRIEND_TEST_ALL_PREFIXES(OomInterventionImplTest, DetectedAndDeclined); + + void Check(TimerBase*); + + // This constant is declared here for testing. + static const size_t kMemoryWorkloadThreshold; + + MemoryWorkloadCaculator workload_calculator_; + mojom::blink::OomInterventionHostPtr host_; + bool trigger_intervention_ = false; + TaskRunnerTimer<OomInterventionImpl> timer_; + std::unique_ptr<ScopedPagePauser> pauser_; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_CONTROLLER_OOM_INTERVENTION_IMPL_H_ diff --git a/chromium/third_party/blink/renderer/controller/oom_intervention_impl_test.cc b/chromium/third_party/blink/renderer/controller/oom_intervention_impl_test.cc new file mode 100644 index 00000000000..cf06203dae4 --- /dev/null +++ b/chromium/third_party/blink/renderer/controller/oom_intervention_impl_test.cc @@ -0,0 +1,67 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/renderer/controller/oom_intervention_impl.h" + +#include "mojo/public/cpp/bindings/binding.h" +#include "services/service_manager/public/cpp/interface_provider.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/blink/renderer/core/exported/web_view_impl.h" +#include "third_party/blink/renderer/core/frame/frame_test_helpers.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" +#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" +#include "third_party/blink/renderer/core/page/page.h" +#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" +#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" + +namespace blink { + +namespace { + +class MockOomInterventionHost : public mojom::blink::OomInterventionHost { + public: + MockOomInterventionHost(mojom::blink::OomInterventionHostRequest request) + : binding_(this, std::move(request)) {} + ~MockOomInterventionHost() = default; + + void OnHighMemoryUsage(bool intervention_triggered) override {} + + private: + mojo::Binding<mojom::blink::OomInterventionHost> binding_; +}; + +} // namespace + +class OomInterventionImplTest : public testing::Test { + public: + size_t MockMemoryWorkloadCalculator() { return memory_workload_; } + + protected: + size_t memory_workload_ = 0; + FrameTestHelpers::WebViewHelper web_view_helper_; +}; + +TEST_F(OomInterventionImplTest, DetectedAndDeclined) { + WebViewImpl* web_view = web_view_helper_.InitializeAndLoad("about::blank"); + Page* page = web_view->MainFrameImpl()->GetFrame()->GetPage(); + EXPECT_FALSE(page->Paused()); + + auto intervention = std::make_unique<OomInterventionImpl>( + WTF::BindRepeating(&OomInterventionImplTest::MockMemoryWorkloadCalculator, + WTF::Unretained(this))); + EXPECT_FALSE(page->Paused()); + + memory_workload_ = OomInterventionImpl::kMemoryWorkloadThreshold + 1; + mojom::blink::OomInterventionHostPtr host_ptr; + MockOomInterventionHost mock_host(mojo::MakeRequest(&host_ptr)); + intervention->StartDetection(std::move(host_ptr), + true /*trigger_intervention*/); + test::RunDelayedTasks(TimeDelta::FromSeconds(1)); + EXPECT_TRUE(page->Paused()); + + intervention.reset(); + EXPECT_FALSE(page->Paused()); +} + +} // namespace blink |