JSInspectorFrontendHostCustom.cpp [plain text]
#include "config.h"
#include "JSInspectorFrontendHost.h"
#if ENABLE(INSPECTOR)
#include "ContextMenuItem.h"
#include "InspectorController.h"
#include "InspectorFrontendHost.h"
#include "JSEvent.h"
#include "MouseEvent.h"
#include <runtime/JSArray.h>
#include <runtime/JSLock.h>
#include <runtime/JSObject.h>
#include <wtf/Vector.h>
using namespace JSC;
namespace WebCore {
JSValue JSInspectorFrontendHost::platform(ExecState* execState, const ArgList&)
{
#if PLATFORM(MAC)
DEFINE_STATIC_LOCAL(const String, platform, ("mac"));
#elif OS(WINDOWS)
DEFINE_STATIC_LOCAL(const String, platform, ("windows"));
#elif OS(LINUX)
DEFINE_STATIC_LOCAL(const String, platform, ("linux"));
#else
DEFINE_STATIC_LOCAL(const String, platform, ("unknown"));
#endif
return jsString(execState, platform);
}
JSValue JSInspectorFrontendHost::port(ExecState* execState, const ArgList&)
{
#if PLATFORM(QT)
DEFINE_STATIC_LOCAL(const String, port, ("qt"));
#elif PLATFORM(GTK)
DEFINE_STATIC_LOCAL(const String, port, ("gtk"));
#elif PLATFORM(WX)
DEFINE_STATIC_LOCAL(const String, port, ("wx"));
#else
DEFINE_STATIC_LOCAL(const String, port, ("unknown"));
#endif
return jsString(execState, port);
}
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const ArgList& args)
{
if (args.size() < 2)
return jsUndefined();
#if ENABLE(CONTEXT_MENUS)
Event* event = toEvent(args.at(0));
JSArray* array = asArray(args.at(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(execState, Identifier(execState, "label"));
JSValue id = item->get(execState, Identifier(execState, "id"));
if (label.isUndefined() || id.isUndefined())
items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
items.append(new ContextMenuItem(ActionType, typedId, ustringToString(label.toString(execState))));
}
}
impl()->showContextMenu(event, items);
#else
UNUSED_PARAM(execState);
#endif
return jsUndefined();
}
}
#endif // ENABLE(INSPECTOR)