2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-07-31 07:08:54 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <set>
|
2014-10-11 11:11:34 +00:00
|
|
|
#include <string>
|
2014-07-31 07:08:54 +00:00
|
|
|
|
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "content/public/browser/tracing_controller.h"
|
2014-08-10 11:14:20 +00:00
|
|
|
#include "native_mate/callback.h"
|
2014-07-31 07:08:54 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
|
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
|
|
|
using content::TracingController;
|
|
|
|
|
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct Converter<std::set<T> > {
|
|
|
|
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const std::set<T>& val) {
|
|
|
|
v8::Handle<v8::Array> result = v8::Array::New(
|
|
|
|
isolate, static_cast<int>(val.size()));
|
|
|
|
typename std::set<T>::const_iterator it;
|
|
|
|
int i;
|
|
|
|
for (i = 0, it = val.begin(); it != val.end(); ++it, ++i)
|
|
|
|
result->Set(i, Converter<T>::ToV8(isolate, *it));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2014-10-11 11:11:34 +00:00
|
|
|
struct Converter<base::debug::CategoryFilter> {
|
2014-07-31 07:08:54 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
2014-10-11 11:11:34 +00:00
|
|
|
base::debug::CategoryFilter* out) {
|
|
|
|
std::string filter;
|
|
|
|
if (!ConvertFromV8(isolate, val, &filter))
|
2014-07-31 07:08:54 +00:00
|
|
|
return false;
|
2014-10-11 11:11:34 +00:00
|
|
|
*out = base::debug::CategoryFilter(filter);
|
2014-07-31 07:08:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-11 11:11:34 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<base::debug::TraceOptions> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
|
|
|
base::debug::TraceOptions* out) {
|
|
|
|
std::string options;
|
|
|
|
if (!ConvertFromV8(isolate, val, &options))
|
|
|
|
return false;
|
|
|
|
return out->SetFromString(options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-31 07:08:54 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
|
|
|
v8::Handle<v8::Context> context, void* priv) {
|
2015-03-10 23:02:22 +00:00
|
|
|
auto controller = base::Unretained(TracingController::GetInstance());
|
2014-07-31 07:08:54 +00:00
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
|
|
|
dict.SetMethod("getCategories", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::GetCategories, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("startRecording", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::EnableRecording, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("stopRecording", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::DisableRecording, controller, nullptr));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("startMonitoring", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::EnableMonitoring, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("stopMonitoring", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::DisableMonitoring, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("captureMonitoringSnapshot", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::CaptureMonitoringSnapshot, controller, nullptr));
|
|
|
|
dict.SetMethod("getTraceBufferUsage", base::Bind(
|
|
|
|
&TracingController::GetTraceBufferUsage, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("setWatchEvent", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::SetWatchEvent, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
dict.SetMethod("cancelWatchEvent", base::Bind(
|
2015-03-10 23:02:22 +00:00
|
|
|
&TracingController::CancelWatchEvent, controller));
|
2014-07-31 07:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_content_tracing, Initialize)
|