Commit 41fba0e6 authored by jochen@chromium.org's avatar jochen@chromium.org

Replace the gc extension in content shell with a gin::Wrappable class

BUG=334679
R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/139413003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245258 0039d316-1c4b-4281-b951-d872f2087c98
parent 73907d55
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
'../base/base.gyp:base', '../base/base.gyp:base',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../components/components.gyp:breakpad_component', '../components/components.gyp:breakpad_component',
'../gin/gin.gyp:gin',
'../ipc/ipc.gyp:ipc', '../ipc/ipc.gyp:ipc',
'../media/media.gyp:media', '../media/media.gyp:media',
'../net/net.gyp:net', '../net/net.gyp:net',
...@@ -159,8 +160,8 @@ ...@@ -159,8 +160,8 @@
'shell/common/webkit_test_helpers.h', 'shell/common/webkit_test_helpers.h',
'shell/geolocation/shell_access_token_store.cc', 'shell/geolocation/shell_access_token_store.cc',
'shell/geolocation/shell_access_token_store.h', 'shell/geolocation/shell_access_token_store.h',
'shell/renderer/gc_extension.cc', 'shell/renderer/gc_controller.cc',
'shell/renderer/gc_extension.h', 'shell/renderer/gc_controller.h',
'shell/renderer/shell_content_renderer_client.cc', 'shell/renderer/shell_content_renderer_client.cc',
'shell/renderer/shell_content_renderer_client.h', 'shell/renderer/shell_content_renderer_client.h',
'shell/renderer/shell_render_frame_observer.cc', 'shell/renderer/shell_render_frame_observer.cc',
......
include_rules = [
"+gin",
]
// Copyright 2014 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 "content/shell/renderer/gc_controller.h"
#include "gin/arguments.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "v8/include/v8.h"
namespace content {
gin::WrapperInfo GCController::kWrapperInfo = {gin::kEmbedderNativeGin};
// static
void GCController::Install(blink::WebFrame* frame) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
gin::Handle<GCController> controller =
gin::CreateHandle(isolate, new GCController());
v8::Handle<v8::Object> global = context->Global();
global->Set(gin::StringToV8(isolate, "GCController"), controller.ToV8());
}
GCController::GCController() {}
GCController::~GCController() {}
gin::ObjectTemplateBuilder GCController::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<GCController>::GetObjectTemplateBuilder(isolate)
.SetMethod("collect", &GCController::Collect)
.SetMethod("minorCollect", &GCController::MinorCollect);
}
void GCController::Collect(const gin::Arguments& args) {
args.isolate()->RequestGarbageCollectionForTesting(
v8::Isolate::kFullGarbageCollection);
}
void GCController::MinorCollect(const gin::Arguments& args) {
args.isolate()->RequestGarbageCollectionForTesting(
v8::Isolate::kMinorGarbageCollection);
}
} // namespace content
// Copyright 2014 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 CONTENT_SHELL_RENDERER_GC_CONTROLLER_H_
#define CONTENT_SHELL_RENDERER_GC_CONTROLLER_H_
#include "base/basictypes.h"
#include "gin/wrappable.h"
namespace blink {
class WebFrame;
}
namespace gin {
class Arguments;
}
namespace content {
class GCController : public gin::Wrappable<GCController> {
public:
static gin::WrapperInfo kWrapperInfo;
static void Install(blink::WebFrame* frame);
private:
GCController();
virtual ~GCController();
// gin::Wrappable.
virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) OVERRIDE;
void Collect(const gin::Arguments& args);
void MinorCollect(const gin::Arguments& args);
DISALLOW_COPY_AND_ASSIGN(GCController);
};
} // namespace content
#endif // CONTENT_SHELL_RENDERER_GC_CONTROLLER_H_
// Copyright 2013 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 "content/shell/renderer/gc_extension.h"
#include "v8/include/v8.h"
const char kGCExtensionName[] = "v8/GCController";
namespace extensions_v8 {
// static
v8::Extension* GCExtension::Get() {
v8::Extension* extension = new v8::Extension(
kGCExtensionName,
"(function () {"
" var v8_gc;"
" if (gc) v8_gc = gc;"
" GCController = new Object();"
" GCController.collect ="
" function() {if (v8_gc) v8_gc(); };"
" GCController.minorCollect ="
" function() {if (v8_gc) v8_gc(true); };"
" })();");
return extension;
}
} // namespace extensions_v8
// Copyright 2013 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 CONTENT_SHELL_RENDERER_GC_EXTENSION_H_
#define CONTENT_SHELL_RENDERER_GC_EXTENSION_H_
namespace v8 {
class Extension;
}
namespace extensions_v8 {
// GCExtension is a v8 extension to expose a method into JS for triggering
// garbage collection. This should only be used for debugging.
class GCExtension {
public:
static v8::Extension* Get();
};
} // namespace extensions_v8
#endif // CONTENT_SHELL_RENDERER_GC_EXTENSION_H_
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "content/public/test/layouttest_support.h" #include "content/public/test/layouttest_support.h"
#include "content/shell/common/shell_messages.h" #include "content/shell/common/shell_messages.h"
#include "content/shell/common/shell_switches.h" #include "content/shell/common/shell_switches.h"
#include "content/shell/renderer/gc_extension.h"
#include "content/shell/renderer/shell_content_renderer_client.h" #include "content/shell/renderer/shell_content_renderer_client.h"
#include "content/shell/renderer/test_runner/WebTestInterfaces.h" #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
#include "content/shell/renderer/webkit_test_runner.h" #include "content/shell/renderer/webkit_test_runner.h"
...@@ -68,7 +67,6 @@ void ShellRenderProcessObserver::WebKitInitialized() { ...@@ -68,7 +67,6 @@ void ShellRenderProcessObserver::WebKitInitialized() {
// We always expose GC to layout tests. // We always expose GC to layout tests.
webkit_glue::SetJavaScriptFlags(" --expose-gc"); webkit_glue::SetJavaScriptFlags(" --expose-gc");
RenderThread::Get()->RegisterExtension(extensions_v8::GCExtension::Get());
if (!CommandLine::ForCurrentProcess()->HasSwitch( if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kStableReleaseMode)) { switches::kStableReleaseMode)) {
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "content/public/test/layouttest_support.h" #include "content/public/test/layouttest_support.h"
#include "content/shell/common/shell_messages.h" #include "content/shell/common/shell_messages.h"
#include "content/shell/common/webkit_test_helpers.h" #include "content/shell/common/webkit_test_helpers.h"
#include "content/shell/renderer/gc_controller.h"
#include "content/shell/renderer/shell_render_process_observer.h" #include "content/shell/renderer/shell_render_process_observer.h"
#include "content/shell/renderer/test_runner/WebTask.h" #include "content/shell/renderer/test_runner/WebTask.h"
#include "content/shell/renderer/test_runner/WebTestInterfaces.h" #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
...@@ -545,6 +546,8 @@ void WebKitTestRunner::captureHistoryForWindow( ...@@ -545,6 +546,8 @@ void WebKitTestRunner::captureHistoryForWindow(
void WebKitTestRunner::DidClearWindowObject(WebFrame* frame, int world_id) { void WebKitTestRunner::DidClearWindowObject(WebFrame* frame, int world_id) {
WebTestingSupport::injectInternalsObject(frame); WebTestingSupport::injectInternalsObject(frame);
ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame); ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame);
if (world_id == 0)
GCController::Install(frame);
} }
bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment