RemoteInspectorUtils.cpp [plain text]
#include "config.h"
#include "RemoteInspectorUtils.h"
#if ENABLE(REMOTE_INSPECTOR)
#include <gio/gio.h>
#include <mutex>
#include <wtf/SHA1.h>
#include <wtf/glib/GUniquePtr.h>
#define INSPECTOR_BACKEND_COMMANDS_PATH "/org/webkit/inspector/UserInterface/Protocol/InspectorBackendCommands.js"
namespace Inspector {
GRefPtr<GBytes> backendCommands()
{
#if PLATFORM(WPE)
static std::once_flag flag;
std::call_once(flag, [] {
const char* libDir = PKGLIBDIR;
#if ENABLE(DEVELOPER_MODE)
const char* path = g_getenv("WEBKIT_INJECTED_BUNDLE_PATH");
if (path && g_file_test(path, G_FILE_TEST_IS_DIR))
libDir = path;
#endif
GUniquePtr<char> bundleFilename(g_build_filename(libDir, "libWPEWebInspectorResources.so", nullptr));
GModule* resourcesModule = g_module_open(bundleFilename.get(), G_MODULE_BIND_LAZY);
if (!resourcesModule) {
WTFLogAlways("Error loading libWPEWebInspectorResources.so: %s", g_module_error());
return;
}
g_module_make_resident(resourcesModule);
});
#endif
GRefPtr<GBytes> bytes = adoptGRef(g_resources_lookup_data(INSPECTOR_BACKEND_COMMANDS_PATH, G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr));
ASSERT(bytes);
return bytes;
}
const CString& backendCommandsHash()
{
static CString hexDigest;
if (hexDigest.isNull()) {
auto bytes = backendCommands();
size_t dataSize;
gconstpointer data = g_bytes_get_data(bytes.get(), &dataSize);
ASSERT(dataSize);
SHA1 sha1;
sha1.addBytes(static_cast<const uint8_t*>(data), dataSize);
hexDigest = sha1.computeHexDigest();
}
return hexDigest;
}
}
#endif // ENABLE(REMOTE_INSPECTOR)