static void openRemoteDebuggingSession(InspectorServerTest* test, gconstpointer) { // To test the whole pipeline this exploits a behavior of the inspector front-end which won't provide the page address as title unless the // debugging session was established correctly through web socket. // In our case page URL should be http://127.0.0.1:2999/ // So this test case will fail if: // - The page list didn't return a valid inspector URL // - Or the front-end couldn't be loaded through the inspector HTTP server // - Or the web socket connection couldn't be established between the front-end and the page through the inspector server // Let's see if this test isn't raising too many false positives, in which case we should use a better predicate if available. test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); g_assert(test->getPageList()); GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].inspectorUrl;", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); String resolvedURL = String("http://127.0.0.1:2999") + String::fromUTF8(WebViewTest::javascriptResultToCString(javascriptResult)); test->loadURI(resolvedURL.utf8().data()); test->waitUntilLoadFinished(); javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.title", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); GUniquePtr<char> title(WebViewTest::javascriptResultToCString(javascriptResult)); g_assert_cmpstr(title.get(), ==, "127.0.0.1"); }
static void sendIncompleteRequest(InspectorServerTest* test, gconstpointer) { GUniqueOutPtr<GError> error; // Connect to the inspector server. GRefPtr<GSocketClient> client = adoptGRef(g_socket_client_new()); GRefPtr<GSocketConnection> connection = adoptGRef(g_socket_client_connect_to_host(client.get(), "127.0.0.1", 2999, 0, &error.outPtr())); g_assert_no_error(error.get()); // Send incomplete request (missing blank line after headers) and check if inspector server // replies. The server should not reply to an incomplete request and the test should timeout // on read. GOutputStream* ostream = g_io_stream_get_output_stream(G_IO_STREAM(connection.get())); // Request missing blank line after headers. const gchar* incompleteRequest = "GET /devtools/page/1 HTTP/1.1\r\nHost: Localhost\r\n"; g_output_stream_write(ostream, incompleteRequest, strlen(incompleteRequest), 0, &error.outPtr()); g_assert_no_error(error.get()); GInputStream* istream = g_io_stream_get_input_stream(G_IO_STREAM(connection.get())); char response[16]; memset(response, 0, sizeof(response)); GRefPtr<GCancellable> cancel = adoptGRef(g_cancellable_new()); g_input_stream_read_async(istream, response, sizeof(response) - 1, G_PRIORITY_DEFAULT, cancel.get(), 0, 0); // Give a chance for the server to reply. test->wait(1); g_cancellable_cancel(cancel.get()); // If we got any answer it means the server replied to an incomplete request, lets fail. g_assert(response[0] == '\0'); }
void RenderThemeGtk::systemFont(CSSValueID, FontDescription& fontDescription) const { GtkSettings* settings = gtk_settings_get_default(); if (!settings) return; // This will be a font selection string like "Sans 10" so we cannot use it as the family name. GUniqueOutPtr<gchar> fontName; g_object_get(settings, "gtk-font-name", &fontName.outPtr(), NULL); PangoFontDescription* pangoDescription = pango_font_description_from_string(fontName.get()); if (!pangoDescription) return; fontDescription.setOneFamily(pango_font_description_get_family(pangoDescription)); int size = pango_font_description_get_size(pangoDescription) / PANGO_SCALE; // If the size of the font is in points, we need to convert it to pixels. if (!pango_font_description_get_size_is_absolute(pangoDescription)) size = size * (getScreenDPI() / 72.0); fontDescription.setSpecifiedSize(size); fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::NoFamily); fontDescription.setWeight(FontWeightNormal); fontDescription.setItalic(false); pango_font_description_free(pangoDescription); }
bool initializeGStreamer() { if (gst_is_initialized()) return true; #if ENABLE(SECCOMP_FILTERS) // The gst-plugin-scanner helper binary will receive SIGSYS and dump core // when it attempts to open a file. Disable it so that plugin scanning // occurs in-process. The disadvantage is that a plugin that crashes while // loading will now crash the web process. gst_registry_fork_set_enabled(FALSE); #endif GUniqueOutPtr<GError> error; // FIXME: We should probably pass the arguments from the command line. bool gstInitialized = gst_init_check(0, 0, &error.outPtr()); ASSERT_WITH_MESSAGE(gstInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred"); #if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS) if (gstInitialized) gst_mpegts_initialize(); #endif return gstInitialized; }
void WebViewTest::keyStroke(unsigned keyVal, unsigned keyModifiers) { g_assert(m_parentWindow); GtkWidget* viewWidget = GTK_WIDGET(m_webView); g_assert(gtk_widget_get_realized(viewWidget)); GUniquePtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS)); event->key.keyval = keyVal; event->key.time = GDK_CURRENT_TIME; event->key.window = gtk_widget_get_window(viewWidget); g_object_ref(event->key.window); gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget)))); event->key.state = keyModifiers; // When synthesizing an event, an invalid hardware_keycode value can cause it to be badly processed by GTK+. GUniqueOutPtr<GdkKeymapKey> keys; int keysCount; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), keyVal, &keys.outPtr(), &keysCount)) event->key.hardware_keycode = keys.get()[0].keycode; gtk_main_do_event(event.get()); event->key.type = GDK_KEY_RELEASE; gtk_main_do_event(event.get()); }
static void testWebContextSecurityFileXHR(WebViewTest* test, gconstpointer) { GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data())); test->loadURI(fileURL.get()); test->waitUntilLoadFinished(); GUniquePtr<char> jsonURL(g_strdup_printf("file://%s/simple.json", Test::getResourcesDir().data())); GUniquePtr<char> xhr(g_strdup_printf("var xhr = new XMLHttpRequest; xhr.open(\"GET\", \"%s\"); xhr.send();", jsonURL.get())); // By default file access is not allowed, this will fail with a cross-origin error. GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(!javascriptResult); g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); // Allow file access from file URLs. webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), TRUE); test->loadURI(fileURL.get()); test->waitUntilLoadFinished(); javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(javascriptResult); g_assert(!error); // It isn't still possible to load file from an HTTP URL. test->loadURI(kServer->getURIForPath("/").data()); test->waitUntilLoadFinished(); javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(!javascriptResult); g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), FALSE); }
static gboolean webkit_download_open_stream_for_uri(WebKitDownload* download, const gchar* uri, gboolean append=FALSE) { g_return_val_if_fail(uri, FALSE); WebKitDownloadPrivate* priv = download->priv; GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(uri)); GUniqueOutPtr<GError> error; if (append) priv->outputStream = g_file_append_to(file.get(), G_FILE_CREATE_NONE, NULL, &error.outPtr()); else priv->outputStream = g_file_replace(file.get(), NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error.outPtr()); if (error) { webkitDownloadEmitError(download, downloadDestinationError(core(priv->networkResponse), error->message)); return FALSE; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); const char* uri_string = webkit_download_get_uri(download); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", uri_string); g_file_info_set_attribute_string(info.get(), "xattr::xdg.origin.url", uri_string); g_file_set_attributes_async(file.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, 0, 0, 0); return TRUE; }
bool WebKitTestBus::run() { // FIXME: Use GTestDBus when we bump glib to 2.34. GUniquePtr<char> dbusLaunch(g_find_program_in_path("dbus-launch")); if (!dbusLaunch) { g_warning("Error starting DBUS daemon: dbus-launch not found in path"); return false; } GUniqueOutPtr<char> output; GUniqueOutPtr<GError> error; if (!g_spawn_command_line_sync(dbusLaunch.get(), &output.outPtr(), 0, 0, &error.outPtr())) { g_warning("Error starting DBUS daemon: %s", error->message); return false; } String outputString = String::fromUTF8(output.get()); Vector<String> lines; outputString.split(UChar('\n'), /* allowEmptyEntries */ false, lines); for (size_t i = 0; i < lines.size(); ++i) { char** keyValue = g_strsplit(lines[i].utf8().data(), "=", 2); g_assert_cmpuint(g_strv_length(keyValue), ==, 2); if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_ADDRESS")) { m_address = keyValue[1]; g_setenv("DBUS_SESSION_BUS_ADDRESS", keyValue[1], TRUE); } else if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_PID")) m_pid = g_ascii_strtoll(keyValue[1], 0, 10); g_strfreev(keyValue); } return m_pid > 0; }
static void busAcquiredCallback(GDBusConnection* connection, const char* name, gpointer userData) { static GDBusNodeInfo* introspectionData = 0; if (!introspectionData) introspectionData = g_dbus_node_info_new_for_xml(introspectionXML, 0); GUniqueOutPtr<GError> error; unsigned registrationID = g_dbus_connection_register_object( connection, "/org/webkit/gtk/WebExtensionTest", introspectionData->interfaces[0], &interfaceVirtualTable, g_object_ref(userData), static_cast<GDestroyNotify>(g_object_unref), &error.outPtr()); if (!registrationID) g_warning("Failed to register object: %s\n", error->message); g_object_set_data(G_OBJECT(userData), "dbus-connection", connection); while (delayedSignalsQueue.size()) { OwnPtr<DelayedSignal> delayedSignal = delayedSignalsQueue.takeFirst(); switch (delayedSignal->type) { case DocumentLoadedSignal: emitDocumentLoaded(connection); break; case URIChangedSignal: emitURIChanged(connection, delayedSignal->uri.data()); break; } } }
static PassRefPtr<SharedBuffer> loadResourceSharedBuffer(CString name) { GUniqueOutPtr<gchar> content; gsize length; if (!g_file_get_contents(name.data(), &content.outPtr(), &length, 0)) return SharedBuffer::create(); return SharedBuffer::create(content.get(), length); }
static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, WebViewTest* test) { GUniqueOutPtr<GError> error; test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); g_assert(!test->m_surface || !error.get()); if (error) g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE); test->quitMainLoop(); }
bool TrackPrivateBaseGStreamer::getTag(GstTagList* tags, const gchar* tagName, StringType& value) { GUniqueOutPtr<gchar> tagValue; if (gst_tag_list_get_string(tags, tagName, &tagValue.outPtr())) { INFO_MEDIA_MESSAGE("Track %d got %s %s.", m_index, tagName, tagValue.get()); value = tagValue.get(); return true; } return false; }
bool PluginProcessProxy::scanPlugin(const String& pluginPath, RawPluginMetaData& result) { #if PLATFORM(GTK) || PLATFORM(EFL) CString binaryPath = fileSystemRepresentation(executablePathOfPluginProcess()); CString pluginPathCString = fileSystemRepresentation(pluginPath); char* argv[4]; argv[0] = const_cast<char*>(binaryPath.data()); argv[1] = const_cast<char*>("-scanPlugin"); argv[2] = const_cast<char*>(pluginPathCString.data()); argv[3] = 0; int status; GUniqueOutPtr<char> stdOut; // If the disposition of SIGCLD signal is set to SIG_IGN (default) // then the signal will be ignored and g_spawn_sync() will not be // able to return the status. // As a consequence, we make sure that the disposition is set to // SIG_DFL before calling g_spawn_sync(). #if defined(SIGCLD) struct sigaction action; sigaction(SIGCLD, 0, &action); if (action.sa_handler == SIG_IGN) { action.sa_handler = SIG_DFL; sigaction(SIGCLD, &action, 0); } #endif if (!g_spawn_sync(0, argv, 0, G_SPAWN_STDERR_TO_DEV_NULL, 0, 0, &stdOut.outPtr(), 0, &status, 0)) return false; if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS || !stdOut) return false; String stdOutString = String::fromUTF8(stdOut.get()); Vector<String> lines; stdOutString.split(UChar('\n'), true, lines); if (lines.size() < 3) return false; result.name.swap(lines[0]); result.description.swap(lines[1]); result.mimeDescription.swap(lines[2]); #if PLATFORM(GTK) if (lines.size() > 3) result.requiresGtk2 = lines[3] == "requires-gtk2"; #endif return !result.mimeDescription.isEmpty(); #else // PLATFORM(GTK) || PLATFORM(EFL) return false; #endif // PLATFORM(GTK) || PLATFORM(EFL) }
int readFromFile(PlatformFileHandle handle, char* data, int length) { GUniqueOutPtr<GError> error; do { gssize bytesRead = g_input_stream_read(g_io_stream_get_input_stream(G_IO_STREAM(handle)), data, length, 0, &error.outPtr()); if (bytesRead >= 0) return bytesRead; } while (error && error->code == G_FILE_ERROR_INTR); return -1; }
static uint64_t getCacheDiskFreeSize(SoupCache* cache) { ASSERT(cache); GUniqueOutPtr<char> cacheDir; g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL); if (!cacheDir) return 0; return WebCore::getVolumeFreeSizeForPath(cacheDir.get()); }
void GeolocationProviderGeoclue::getGeoclueClientCallback(GObject* sourceObject, GAsyncResult* result, GeolocationProviderGeoclue* provider) { GUniqueOutPtr<GError> error; GUniqueOutPtr<gchar> path; if (!geoclue_manager_call_get_client_finish(GEOCLUE_MANAGER(sourceObject), &path.outPtr(), result, &error.outPtr())) { provider->errorOccurred(error->message); return; } geoclue_client_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, gGeoclueBusName, path.get(), nullptr, reinterpret_cast<GAsyncReadyCallback>(createGeoclueClientProxyCallback), provider); }
static void testWebExtensionWindowObjectCleared(WebViewTest* test, gconstpointer) { test->loadHtml("<html><header></header><body></body></html>", 0); test->waitUntilLoadFinished(); GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.echo('Foo');", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult)); g_assert_cmpstr(valueString.get(), ==, "Foo"); }
static void readReadyCallback(GInputStream* stream, GAsyncResult* result, void* id) { // Always finish the read, even if this SocketStreamHandle was deactivated earlier. GUniqueOutPtr<GError> error; gssize bytesRead = g_input_stream_read_finish(stream, result, &error.outPtr()); SocketStreamHandle* handle = getHandleFromId(id); if (!handle) return; handle->readBytes(bytesRead, error.get()); }
static void didResolveProxy(GProxyResolver* resolver, GAsyncResult* result, bool* isUsingProxyType, bool* isUsingProxy) { GUniqueOutPtr<GError> error; GUniquePtr<char*> uris(g_proxy_resolver_lookup_finish(resolver, result, &error.outPtr())); if (error) { WTFLogAlways("Error determining system proxy settings: %s", error->message); return; } *isUsingProxyType = didResolveProxy(uris.get()); *isUsingProxy = isUsingHttpProxy || isUsingHttpsProxy; }
static void testWebContextLanguages(WebViewTest* test, gconstpointer) { static const char* expectedDefaultLanguage = "en-US"; test->loadURI(kServer->getURIForPath("/").data()); test->waitUntilLoadFinished(); size_t mainResourceDataSize = 0; const char* mainResourceData = test->mainResourceData(mainResourceDataSize); g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedDefaultLanguage)); g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize)); GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en"))); g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("ES_es"))); g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("dE"))); g_ptr_array_add(languages.get(), 0); webkit_web_context_set_preferred_languages(test->m_webContext.get(), reinterpret_cast<const char* const*>(languages->pdata)); static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80"; test->loadURI(kServer->getURIForPath("/").data()); test->waitUntilLoadFinished(); mainResourceDataSize = 0; mainResourceData = test->mainResourceData(mainResourceDataSize); g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedLanguages)); g_assert(!strncmp(mainResourceData, expectedLanguages, mainResourceDataSize)); // When using the C locale, en-US should be used as default. const char* cLanguage[] = { "C", nullptr }; webkit_web_context_set_preferred_languages(test->m_webContext.get(), cLanguage); GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("Intl.DateTimeFormat().resolvedOptions().locale", &error.outPtr()); g_assert(javascriptResult); g_assert(!error); GUniquePtr<char> locale(WebViewTest::javascriptResultToCString(javascriptResult)); g_assert_cmpstr(locale.get(), ==, expectedDefaultLanguage); // When using the POSIX locale, en-US should be used as default. const char* posixLanguage[] = { "POSIX", nullptr }; webkit_web_context_set_preferred_languages(test->m_webContext.get(), posixLanguage); javascriptResult = test->runJavaScriptAndWaitUntilFinished("Intl.DateTimeFormat().resolvedOptions().locale", &error.outPtr()); g_assert(javascriptResult); g_assert(!error); locale.reset(WebViewTest::javascriptResultToCString(javascriptResult)); g_assert_cmpstr(locale.get(), ==, expectedDefaultLanguage); // An invalid locale should throw an exception. const char* invalidLanguage[] = { "A", nullptr }; webkit_web_context_set_preferred_languages(test->m_webContext.get(), invalidLanguage); javascriptResult = test->runJavaScriptAndWaitUntilFinished("Intl.DateTimeFormat().resolvedOptions().locale", &error.outPtr()); g_assert(!javascriptResult); g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); }
String ImageBuffer::toDataURL(const String& mimeType, std::optional<double> quality, CoordinateSystem) const { ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); GUniqueOutPtr<gchar> buffer; gsize bufferSize; if (!encodeImage(m_data.m_surface.get(), mimeType, quality, buffer, bufferSize)) return "data:,"; Vector<char> base64Data; base64Encode(buffer.get(), bufferSize, base64Data); return "data:" + mimeType + ";base64," + base64Data; }
gboolean AudioFileReader::handleMessage(GstMessage* message) { GUniqueOutPtr<GError> error; GUniqueOutPtr<gchar> debug; switch (GST_MESSAGE_TYPE(message)) { case GST_MESSAGE_EOS: g_main_loop_quit(m_loop.get()); break; case GST_MESSAGE_WARNING: gst_message_parse_warning(message, &error.outPtr(), &debug.outPtr()); g_warning("Warning: %d, %s. Debug output: %s", error->code, error->message, debug.get()); break; case GST_MESSAGE_ERROR: gst_message_parse_error(message, &error.outPtr(), &debug.outPtr()); g_warning("Error: %d, %s. Debug output: %s", error->code, error->message, debug.get()); m_errorOccurred = true; gst_element_set_state(m_pipeline, GST_STATE_NULL); g_main_loop_quit(m_loop.get()); break; default: break; } return TRUE; }
static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) { size_t dataSize; GUniqueOutPtr<GError> error; unsigned char* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(object), result, &dataSize, &error.outPtr()); g_assert(!error.get()); g_assert(data); g_assert_cmpint(dataSize, >, 0); ResourcesTest* test = static_cast<ResourcesTest*>(userData); test->m_resourceData.reset(reinterpret_cast<char*>(data)); test->m_resourceDataSize = dataSize; g_main_loop_quit(test->m_mainLoop); }
char* SoupNetworkSession::httpProxy() const { #if PLATFORM(EFL) SoupSessionFeature* soupResolver = soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_PROXY_URI_RESOLVER); if (!soupResolver) return nullptr; GUniqueOutPtr<SoupURI> uri; g_object_get(soupResolver, SOUP_PROXY_RESOLVER_WK_PROXY_URI, &uri.outPtr(), nullptr); return uri ? soup_uri_to_string(uri.get(), FALSE) : nullptr; #else return nullptr; #endif }
static void webkit_download_received_data(WebKitDownload* download, const gchar* data, int length) { WebKitDownloadPrivate* priv = download->priv; if (priv->currentSize == 0) webkit_download_set_status(download, WEBKIT_DOWNLOAD_STATUS_STARTED); ASSERT(priv->outputStream); gsize bytes_written; GUniqueOutPtr<GError> error; g_output_stream_write_all(G_OUTPUT_STREAM(priv->outputStream), data, length, &bytes_written, NULL, &error.outPtr()); if (error) { webkitDownloadEmitError(download, downloadDestinationError(core(priv->networkResponse), error->message)); return; } priv->currentSize += length; g_object_notify(G_OBJECT(download), "current-size"); ASSERT(priv->networkResponse); if (priv->currentSize > webkit_download_get_total_size(download)) g_object_notify(G_OBJECT(download), "total-size"); // Throttle progress notification to not consume high amounts of // CPU on fast links, except when the last notification occured // in more then 0.7 secs from now, or the last notified progress // is passed in 1% or we reached the end. static gdouble lastProgress = 0; static gdouble lastElapsed = 0; gdouble currentElapsed = g_timer_elapsed(priv->timer, NULL); gdouble currentProgress = webkit_download_get_progress(download); if (lastElapsed && lastProgress && (currentElapsed - lastElapsed) < 0.7 && (currentProgress - lastProgress) < 0.01 && currentProgress < 1.0) { return; } lastElapsed = currentElapsed; lastProgress = currentProgress; g_object_notify(G_OBJECT(download), "progress"); }
void SocketStreamHandle::readReadyCallback(GInputStream* stream, GAsyncResult* result, SocketStreamHandle* handle) { RefPtr<SocketStreamHandle> protectedThis = adoptRef(handle); // Always finish the read, even if this SocketStreamHandle was cancelled earlier. GUniqueOutPtr<GError> error; gssize bytesRead = g_input_stream_read_finish(stream, result, &error.outPtr()); if (g_cancellable_is_cancelled(handle->m_cancellable.get())) return; if (error) handle->didFail(SocketStreamError(error->code, error->message)); else handle->readBytes(bytesRead); }
static void connectedCallback(GSocketClient* client, GAsyncResult* result, void* id) { // Always finish the connection, even if this SocketStreamHandle was deactivated earlier. GUniqueOutPtr<GError> error; GSocketConnection* socketConnection = g_socket_client_connect_to_host_finish(client, result, &error.outPtr()); // The SocketStreamHandle has been deactivated, so just close the connection, ignoring errors. SocketStreamHandle* handle = getHandleFromId(id); if (!handle) { if (socketConnection) g_io_stream_close(G_IO_STREAM(socketConnection), 0, 0); return; } handle->connected(socketConnection, error.get()); }
bool WebViewTest::runWebProcessTest(const char* suiteName, const char* testName) { GUniquePtr<char> script(g_strdup_printf("WebProcessTestRunner.runTest('%s/%s');", suiteName, testName)); GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = runJavaScriptAndWaitUntilFinished(script.get(), &error.outPtr()); g_assert(!error); return javascriptResultToBoolean(javascriptResult); }
// Test to get inspector server page list from the test server. // Should contain only one entry pointing to http://127.0.0.1:2999/webinspector/Main.html?page=1 static void testInspectorServerPageList(InspectorServerTest* test, gconstpointer) { GUniqueOutPtr<GError> error; test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); g_assert(test->getPageList()); WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages.length;", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); g_assert_cmpint(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 1); javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].id;", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); int pageId = WebViewTest::javascriptResultToNumber(javascriptResult); GUniquePtr<char> valueString; javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].url;", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult)); g_assert_cmpstr(valueString.get(), ==, "http://127.0.0.1:2999/"); javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].inspectorUrl;", &error.outPtr()); g_assert(javascriptResult); g_assert(!error.get()); valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult)); String validInspectorURL = String("/Main.html?page=") + String::number(pageId); ASSERT_CMP_CSTRING(valueString.get(), ==, validInspectorURL.utf8()); }
String topPrivatelyControlledDomain(const String& domain) { if (domain.isEmpty()) return String(); GUniqueOutPtr<GError> error; if (const char* baseDomain = soup_tld_get_base_domain(domain.utf8().data(), &error.outPtr())) return String::fromUTF8(baseDomain); if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NO_BASE_DOMAIN) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS)) return String(); if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_IS_IP_ADDRESS) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_INVALID_HOSTNAME)) return domain; ASSERT_NOT_REACHED(); return String(); }