WebInspectorServerEfl.cpp [plain text]
#include "config.h"
#if ENABLE(INSPECTOR_SERVER)
#include "WebInspectorServer.h"
#include "WebInspectorProxy.h"
#include "WebPageProxy.h"
#include <WebCore/EflInspectorUtilities.h>
#include <WebCore/MIMETypeRegistry.h>
#include <sys/stat.h>
#include <wtf/text/StringBuilder.h>
namespace WebKit {
bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType)
{
if (path == "/pagelist.json" || path == "/json") {
buildPageList(data, contentType);
return true;
}
String localPath = WebCore::inspectorResourcePath() + ((path == "/") ? ASCIILiteral("/inspectorPageIndex.html") : path);
FILE* fileHandle = fopen(localPath.utf8().data(), "r");
if (!fileHandle)
return false;
struct stat fileStat;
if (fstat(fileno(fileHandle), &fileStat)) {
fclose(fileHandle);
return false;
}
data.grow(fileStat.st_size);
int bytesRead = fread(data.data(), 1, fileStat.st_size, fileHandle);
fclose(fileHandle);
if (bytesRead < fileStat.st_size)
return false;
size_t extStart = localPath.reverseFind('.');
if (extStart == notFound)
return false;
String ext = localPath.substring(extStart + 1);
if (ext.isEmpty())
return false;
contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(ext);
return true;
}
void WebInspectorServer::buildPageList(Vector<char>& data, String& contentType)
{
StringBuilder builder;
builder.append('[');
ClientMap::iterator end = m_clientMap.end();
for (ClientMap::iterator it = m_clientMap.begin(); it != end; ++it) {
WebPageProxy* webPage = it->value->inspectedPage();
if (it != m_clientMap.begin())
builder.appendLiteral(", ");
builder.appendLiteral("{ \"id\": ");
builder.appendNumber(it->key);
builder.appendLiteral(", \"title\": \"");
builder.append(webPage->pageLoadState().title());
builder.appendLiteral("\", \"url\": \"");
builder.append(webPage->pageLoadState().activeURL());
builder.appendLiteral("\", \"inspectorUrl\": \"");
builder.appendLiteral("/Main.html?page=");
builder.appendNumber(it->key);
builder.appendLiteral("\", \"devtoolsFrontendUrl\": \"");
builder.appendLiteral("/Main.html?ws=");
builder.append(bindAddress());
builder.appendLiteral(":");
builder.appendNumber(port());
builder.appendLiteral("/devtools/page/");
builder.appendNumber(it->key);
builder.appendLiteral("\", \"webSocketDebuggerUrl\": \"");
builder.appendLiteral("ws://");
builder.append(bindAddress());
builder.appendLiteral(":");
builder.appendNumber(port());
builder.appendLiteral("/devtools/page/");
builder.appendNumber(it->key);
builder.appendLiteral("\" }");
}
builder.append(']');
CString clientList = builder.toString().utf8();
data.append(clientList.data(), clientList.length());
contentType = String("application/json; charset=utf-8", String::ConstructFromLiteral);
}
}
#endif