WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClient::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData) { RefPtr<WebKit::DocumentLoader> loader = WebKit::DocumentLoader::create(request, substituteData); GRefPtr<WebKitWebDataSource> webDataSource(adoptGRef(kitNew(loader.get()))); loader->setDataSource(webDataSource.get()); return loader.release(); }
GRefPtr<GstCaps> MediaPlayerPrivateGStreamerBase::currentVideoSinkCaps() const { if (!m_webkitVideoSink) return 0; GstCaps* currentCaps = 0; g_object_get(G_OBJECT(m_webkitVideoSink.get()), "current-caps", ¤tCaps, NULL); return adoptGRef(currentCaps); }
void RunLoop::wakeUp() { GRefPtr<GSource> source = adoptGRef(g_idle_source_new()); g_source_set_priority(source.get(), G_PRIORITY_DEFAULT); g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0); g_source_attach(source.get(), m_runLoopContext.get()); g_main_context_wakeup(m_runLoopContext.get()); }
bool EditorClient::shouldBeginEditing(WebCore::Range* range) { clearPendingComposition(); gboolean accept = TRUE; GRefPtr<WebKitDOMRange> kitRange(adoptGRef(kit(range))); g_signal_emit_by_name(m_webView, "should-begin-editing", kitRange.get(), &accept); return accept; }
void SocketStreamHandle::beginWaitingForSocketWritability() { if (m_writeReadySource) // Already waiting. return; m_writeReadySource = adoptGRef(g_pollable_output_stream_create_source(m_outputStream.get(), 0)); g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), m_id, 0); g_source_attach(m_writeReadySource.get(), 0); }
bool EditorClient::shouldApplyStyle(WebCore::StyleProperties* set, WebCore::Range* range) { gboolean accept = TRUE; Ref<MutableStyleProperties> mutableStyle(set->mutableCopy()); GRefPtr<WebKitDOMCSSStyleDeclaration> kitDeclaration(kit(mutableStyle->ensureCSSStyleDeclaration())); GRefPtr<WebKitDOMRange> kitRange(adoptGRef(kit(range))); g_signal_emit_by_name(m_webView, "should-apply-style", kitDeclaration.get(), kitRange.get(), &accept); return accept; }
WebKitTestServer::WebKitTestServer(ServerType type) { GUniquePtr<char> sslCertificateFile; GUniquePtr<char> sslKeyFile; if (type == ServerHTTPS) { CString resourcesDir = Test::getResourcesDir(); sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL)); sslKeyFile.reset(g_build_filename(resourcesDir.data(), "test-key.pem", NULL)); } GRefPtr<SoupAddress> address = adoptGRef(soup_address_new("127.0.0.1", SOUP_ADDRESS_ANY_PORT)); soup_address_resolve_sync(address.get(), 0); m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_INTERFACE, address.get(), SOUP_SERVER_SSL_CERT_FILE, sslCertificateFile.get(), SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), nullptr)); m_baseURI = type == ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/"); soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer.get())); }
static void testWebExtensionGetTitle(WebViewTest* test, gconstpointer) { test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0); test->waitUntilLoadFinished(); GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest", "/org/webkit/gtk/WebExtensionTest" , "org.webkit.gtk.WebExtensionTest", test->m_mainLoop)); GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync( proxy.get(), "GetTitle", g_variant_new("(t)", webkit_web_view_get_page_id(test->m_webView)), G_DBUS_CALL_FLAGS_NONE, -1, 0, 0)); g_assert(result); const char* title; g_variant_get(result.get(), "(&s)", &title); g_assert_cmpstr(title, ==, "WebKitGTK+ Web Extensions Test"); }
void ChromeClient::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation) { WebKitWebFrame* webFrame = kit(frame); GRefPtr<WebKitGeolocationPolicyDecision> policyDecision(adoptGRef(webkit_geolocation_policy_decision_new(webFrame, geolocation))); gboolean isHandled = FALSE; g_signal_emit_by_name(m_webView, "geolocation-policy-decision-requested", webFrame, policyDecision.get(), &isHandled); if (!isHandled) webkit_geolocation_policy_deny(policyDecision.get()); }
PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::cellForColumnAndRow(unsigned col, unsigned row) { if (!ATK_IS_TABLE(m_element.get())) return nullptr; // Adopt the AtkObject representing the cell because // at_table_ref_at() transfers full ownership. GRefPtr<AtkObject> foundCell = adoptGRef(atk_table_ref_at(ATK_TABLE(m_element.get()), row, col)); return foundCell ? AccessibilityUIElement::create(foundCell.get()) : nullptr; }
GRefPtr<GstBus> webkitGstPipelineGetBus(GstPipeline* pipeline) { #ifdef GST_API_VERSION_1 return adoptGRef(gst_pipeline_get_bus(pipeline)); #else // gst_pipeline_get_bus returns a floating reference in // gstreamer 0.10 so we should not adopt. return gst_pipeline_get_bus(pipeline); #endif }
AudioDestinationGStreamer::~AudioDestinationGStreamer() { GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline))); ASSERT(bus); g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(messageCallback), this); gst_bus_remove_signal_watch(bus.get()); gst_element_set_state(m_pipeline, GST_STATE_NULL); gst_object_unref(m_pipeline); }
void checkDestinationAndDeleteFile(WebKitDownload* download, const char* expectedName) { if (!webkit_download_get_destination(download)) return; GRefPtr<GFile> destFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(download))); GOwnPtr<char> destBasename(g_file_get_basename(destFile.get())); g_assert_cmpstr(destBasename.get(), ==, expectedName); g_file_delete(destFile.get(), 0, 0); }
bool AccessibilityUIElement::isChecked() const { if (!ATK_IS_OBJECT(m_element)) return false; GRefPtr<AtkStateSet> stateSet = adoptGRef(atk_object_ref_state_set(ATK_OBJECT(m_element))); gboolean isChecked = atk_state_set_contains_state(stateSet.get(), ATK_STATE_CHECKED); return isChecked; }
void GSourceWrap::DelayBased::schedule(std::chrono::microseconds delay) { ASSERT(m_source); m_context.delay = delay; if (g_cancellable_is_cancelled(m_context.cancellable.get())) m_context.cancellable = adoptGRef(g_cancellable_new()); g_source_set_ready_time(m_source.get(), targetTimeForDelay(delay)); }
bool AccessibilityUIElement::isFocusable() const { if (!ATK_IS_OBJECT(m_element)) return false; GRefPtr<AtkStateSet> stateSet = adoptGRef(atk_object_ref_state_set(ATK_OBJECT(m_element))); gboolean isFocusable = atk_state_set_contains_state(stateSet.get(), ATK_STATE_FOCUSABLE); return isFocusable; }
void RunLoop::TimerBase::start(double fireInterval, bool repeat) { if (m_timerSource) stop(); m_timerSource = adoptGRef(g_timeout_source_new(static_cast<guint>(fireInterval * 1000))); m_isRepeating = repeat; g_source_set_callback(m_timerSource.get(), reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::timerFiredCallback), this, 0); g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext.get()); }
static GRefPtr<GdkCursor> createNamedCursor(CustomCursorType cursorType) { CustomCursor cursor = CustomCursors[cursorType]; GRefPtr<GdkCursor> c = adoptGRef(gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name)); if (c) return c; IntSize cursorSize = IntSize(32, 32); RefPtr<cairo_surface_t> source = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.bits), CAIRO_FORMAT_A1, 32, 32, 4)); RefPtr<cairo_surface_t> mask = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.mask_bits), CAIRO_FORMAT_A1, 32, 32, 4)); RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A1, 32, 32)); RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get())); cairo_set_source_surface(cr.get(), source.get(), 0, 0); cairo_mask_surface(cr.get(), mask.get(), 0, 0); GRefPtr<GdkPixbuf> pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, 32, 32)); return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), cursor.hot_x, cursor.hot_y)); }
void AccessibilityUIElement::getChildrenWithRange(Vector<RefPtr<AccessibilityUIElement> >& children, unsigned location, unsigned length) { if (!ATK_IS_OBJECT(m_element.get())) return; unsigned end = location + length; for (unsigned i = location; i < end; i++) { GRefPtr<AtkObject> child = adoptGRef(atk_object_ref_accessible_child(ATK_OBJECT(m_element.get()), i)); children.append(AccessibilityUIElement::create(child.get())); } }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = response; m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url().string(), response.httpStatusText())); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { URL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; m_destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, overwrite); if (m_destinationURI.isEmpty()) { #if PLATFORM(GTK) GUniquePtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); String errorMessage = String::fromUTF8(buffer.get()); #else String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); #endif downloadFailed(platformDownloadDestinationError(response, errorMessage)); return; } String intermediateURI = m_destinationURI + ".wkdownload"; m_intermediateFile = adoptGRef(g_file_new_for_uri(intermediateURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(m_intermediateFile.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(platformDownloadDestinationError(response, error->message)); return; } m_download->didCreateDestination(m_destinationURI); }
static bool encodeImage(cairo_surface_t* surface, const String& mimeType, std::optional<double> quality, GUniqueOutPtr<gchar>& buffer, gsize& bufferSize) { // List of supported image encoding types comes from the GdkPixbuf documentation. // http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-File-saving.html#gdk-pixbuf-save-to-bufferv String type = mimeType.substring(sizeof "image"); if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp") return false; GRefPtr<GdkPixbuf> pixbuf; if (type == "jpeg") { // JPEG doesn't support alpha channel. The <canvas> spec states that toDataURL() must encode a Porter-Duff // composite source-over black for image types that do not support alpha. RefPtr<cairo_surface_t> newSurface; if (cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE) { newSurface = adoptRef(cairo_image_surface_create_for_data(cairo_image_surface_get_data(surface), CAIRO_FORMAT_RGB24, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), cairo_image_surface_get_stride(surface))); } else { IntSize size = cairoSurfaceSize(surface); newSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_RGB24, size.width(), size.height())); RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get())); cairo_set_source_surface(cr.get(), surface, 0, 0); cairo_paint(cr.get()); } pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(newSurface.get())); } else pixbuf = adoptGRef(cairoSurfaceToGdkPixbuf(surface)); if (!pixbuf) return false; GUniqueOutPtr<GError> error; if (type == "jpeg" && quality && *quality >= 0.0 && *quality <= 1.0) { String qualityString = String::format("%d", static_cast<int>(*quality * 100.0 + 0.5)); gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error.outPtr(), "quality", qualityString.utf8().data(), NULL); } else gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error.outPtr(), NULL); return !error; }
void SoupNetworkSession::setupLogger() { #if !LOG_DISABLED if (LogNetwork.state != WTFLogChannelOn || soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_LOGGER)) return; GRefPtr<SoupLogger> logger = adoptGRef(soup_logger_new(SOUP_LOGGER_LOG_BODY, -1)); soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(logger.get())); soup_logger_set_printer(logger.get(), soupLogPrinter, nullptr, nullptr); #endif }
void testWebKitSettingsNewWithSettings(Test* test, gconstpointer) { GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, "auto-load-images", FALSE, "load-icons-ignoring-image-load-setting", TRUE, NULL)); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(settings.get())); g_assert(!webkit_settings_get_enable_javascript(settings.get())); g_assert(!webkit_settings_get_auto_load_images(settings.get())); g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings.get())); }
void didFinishLoading(ResourceHandle*, double) { m_outputStream = 0; ASSERT(m_intermediateFile); GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_uri(m_destinationURI.utf8().data())); GOwnPtr<GError> error; if (!g_file_move(m_intermediateFile.get(), destinationFile.get(), G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error.outPtr())) { downloadFailed(platformDownloadDestinationError(m_response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); CString uri = m_response.url().string().utf8(); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", uri.data()); g_file_info_set_attribute_string(info.get(), "xattr::xdg.origin.url", uri.data()); g_file_set_attributes_async(destinationFile.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, nullptr, nullptr, nullptr); m_download->didFinish(); }
GRefPtr<GstCaps> webkitGstGetPadCaps(GstPad* pad) { if (!pad) return 0; #ifdef GST_API_VERSION_1 return adoptGRef(gst_pad_get_current_caps(pad)); // gst_pad_get_current_caps return a new reference. #else return GST_PAD_CAPS(pad); #endif }
WK_EXPORT int NetworkProcessMain(int argc, char* argv[]) { if (argc != 2) return 1; #if PLATFORM(EFL) if (!ecore_init()) return 1; if (!ecore_main_loop_glib_integrate()) return 1; #endif InitializeWebKit2(); #if USE(SOUP) SoupSession* session = ResourceHandle::defaultSession(); #if PLATFORM(EFL) // Only for EFL because GTK port uses the default resolver, which uses GIO's proxy resolver. const char* httpProxy = getenv("http_proxy"); if (httpProxy) { const char* noProxy = getenv("no_proxy"); GRefPtr<SoupProxyURIResolver> resolver = adoptGRef(soupProxyResolverWkNew(httpProxy, noProxy)); soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolver.get())); } #endif #endif int socket = atoi(argv[1]); WebKit::ChildProcessInitializationParameters parameters; parameters.connectionIdentifier = int(socket); NetworkProcess::shared().initialize(parameters); #if USE(SOUP) // Despite using system CAs to validate certificates we're // accepting invalid certificates by default. New API will be // added later to let client accept/discard invalid certificates. g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, SOUP_SESSION_SSL_STRICT, FALSE, NULL); #endif RunLoop::run(); #if USE(SOUP) if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) { soup_cache_flush(SOUP_CACHE(soupCache)); soup_cache_dump(SOUP_CACHE(soupCache)); } #endif return 0; }
String openTemporaryFile(const String& prefix, PlatformFileHandle& handle) { GUniquePtr<gchar> filename(g_strdup_printf("%s%s", prefix.utf8().data(), createCanonicalUUIDString().utf8().data())); GUniquePtr<gchar> tempPath(g_build_filename(g_get_tmp_dir(), filename.get(), NULL)); GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(tempPath.get())); handle = g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, 0, 0); if (!isHandleValid(handle)) return String(); return String::fromUTF8(tempPath.get()); }
void AccessibilityUIElement::getChildren(Vector<RefPtr<AccessibilityUIElement> >& children) { if (!ATK_IS_OBJECT(m_element.get())) return; int count = childrenCount(); for (int i = 0; i < count; i++) { GRefPtr<AtkObject> child = adoptGRef(atk_object_ref_accessible_child(ATK_OBJECT(m_element.get()), i)); children.append(AccessibilityUIElement::create(child.get())); } }
static void testWebViewGroupSettings(Test* test, gconstpointer) { GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1")); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get())); GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, nullptr)); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get())); webkit_web_view_group_set_settings(viewGroup1.get(), newSettings.get()); g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) == newSettings.get()); GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get())); GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new()); WebKitSettings* webView1Settings = webkit_web_view_get_settings(webView1.get()); WebKitSettings* webView2Settings = webkit_web_view_get_settings(webView2.get()); g_assert(webView1Settings != webView2Settings); g_assert(webkit_settings_get_enable_javascript(webView1Settings) != webkit_settings_get_enable_javascript(webView2Settings)); webkit_web_view_set_settings(webView1.get(), webView2Settings); g_assert(webkit_web_view_get_settings(webView1.get()) == webView2Settings); g_assert(webkit_web_view_group_get_settings(webkit_web_view_get_group(webView1.get())) == webView2Settings); }
void SocketStreamHandle::beginWaitingForSocketWritability() { if (m_writeReadySource) // Already waiting. return; m_writeReadySource = adoptGRef(g_pollable_output_stream_create_source(m_outputStream.get(), m_cancellable.get())); ref(); g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), this, [](gpointer handle) { static_cast<SocketStreamHandle*>(handle)->deref(); }); g_source_attach(m_writeReadySource.get(), g_main_context_get_thread_default()); }