bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType) { // The page list contains an unformated list of pages that can be inspected with a link to open a session. if (path == "/pagelist.json") { buildPageList(data, contentType); return true; } // Point the default path to a formatted page that queries the page list and display them. CString localPath = WebCore::fileSystemRepresentation(inspectorServerFilesPath() + ((path == "/") ? "/inspectorPageIndex.html" : path)); if (localPath.isNull()) return false; GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(localPath.data())); GOwnPtr<GError> error; GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, 0, &error.outPtr())); if (!fileInfo) { StringBuilder builder; builder.appendLiteral("<!DOCTYPE html><html><head></head><body>Error: "); builder.appendNumber(error->code); builder.appendLiteral(", "); builder.append(error->message); builder.appendLiteral(" occurred during fetching webinspector resource files.<br>Make sure you ran make install or have set WEBKIT_INSPECTOR_SERVER_PATH in your environment to point to webinspector folder.</body></html>"); CString cstr = builder.toString().utf8(); data.append(cstr.data(), cstr.length()); contentType = "text/html; charset=utf-8"; g_warning("Error fetching webinspector resource files: %d, %s", error->code, error->message); return true; } GRefPtr<GFileInputStream> inputStream = adoptGRef(g_file_read(file.get(), 0, 0)); if (!inputStream) return false; data.grow(g_file_info_get_size(fileInfo.get())); if (!g_input_stream_read_all(G_INPUT_STREAM(inputStream.get()), data.data(), data.size(), 0, 0, 0)) return false; contentType = GOwnPtr<gchar>(g_file_info_get_attribute_as_string(fileInfo.get(), G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)).get(); return true; }
bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType) { // The page list contains an unformated list of pages that can be inspected with a link to open a session. if (path == "/pagelist.json") { buildPageList(data, contentType); return true; } // Point the default path to a formatted page that queries the page list and display them. String localPath = (path == "/") ? "/webkit/resources/inspectorPageIndex.html" : path; // All other paths are mapped directly to a resource, if possible. QFile file(QString::fromLatin1(":%1").arg(localPath)); if (file.exists()) { file.open(QIODevice::ReadOnly); data.grow(file.size()); file.read(data.data(), data.size()); size_t extStart = localPath.reverseFind('.'); String ext = localPath.substring(extStart != notFound ? extStart + 1 : 0); contentType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(ext); return true; } return false; }