diff options
Diffstat (limited to 'Source/WebKit/gtk/webkit')
77 files changed, 19687 insertions, 0 deletions
diff --git a/Source/WebKit/gtk/webkit/webkit.h b/Source/WebKit/gtk/webkit/webkit.h new file mode 100644 index 0000000..77e96bc --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkit.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __WEBKIT_H__ +#define __WEBKIT_H__ + +#include <webkit/webkitversion.h> +#include <webkit/webkitapplicationcache.h> +#include <webkit/webkitdefines.h> +#include <webkit/webkitdom.h> +#include <webkit/webkitdownload.h> +#include <webkit/webkitenumtypes.h> +#include <webkit/webkitgeolocationpolicydecision.h> +#include <webkit/webkitglobals.h> +#include <webkit/webkithittestresult.h> +#include <webkit/webkiticondatabase.h> +#include <webkit/webkitnetworkrequest.h> +#include <webkit/webkitnetworkresponse.h> +#include <webkit/webkitsecurityorigin.h> +#include <webkit/webkitsoupauthdialog.h> +#include <webkit/webkitviewportattributes.h> +#include <webkit/webkitwebbackforwardlist.h> +#include <webkit/webkitwebdatabase.h> +#include <webkit/webkitwebdatasource.h> +#include <webkit/webkitwebframe.h> +#include <webkit/webkitwebhistoryitem.h> +#include <webkit/webkitwebinspector.h> +#include <webkit/webkitwebnavigationaction.h> +#include <webkit/webkitwebplugin.h> +#include <webkit/webkitwebplugindatabase.h> +#include <webkit/webkitwebpolicydecision.h> +#include <webkit/webkitwebresource.h> +#include <webkit/webkitwebsettings.h> +#include <webkit/webkitwebview.h> +#include <webkit/webkitwebwindowfeatures.h> + +#endif /* __WEBKIT_H__ */ diff --git a/Source/WebKit/gtk/webkit/webkitapplicationcache.cpp b/Source/WebKit/gtk/webkit/webkitapplicationcache.cpp new file mode 100644 index 0000000..0b65d04 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitapplicationcache.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com> + * Copyright (C) 2011 Lukasz Slachciak + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitapplicationcache.h" + +#include "ApplicationCacheStorage.h" +#include "FileSystem.h" +#include <wtf/UnusedParam.h> +#include <wtf/text/CString.h> + +// web application cache maximum storage size +static unsigned long long cacheMaxSize = UINT_MAX; + +/** + * webkit_application_cache_get_maximum_size: + * + * Returns the maximum size of the cache storage. + * By default it is set to UINT_MAX i.e. no quota. + * + * Returns: the current application cache maximum storage size + * + * Since: 1.3.13 + **/ +unsigned long long webkit_application_cache_get_maximum_size() +{ +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + return (cacheMaxSize = WebCore::cacheStorage().maximumSize()); +#else + return 0; +#endif +} + +/** + * webkit_application_cache_set_maximum_size: + * @size: the new web application cache maximum storage size + * + * Sets new application cache maximum storage size. + * Changing the application cache storage size will clear the cache + * and rebuild cache storage. + * + * Since: 1.3.13 + **/ +void webkit_application_cache_set_maximum_size(unsigned long long size) +{ +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + if (size != cacheMaxSize) { + WebCore::cacheStorage().empty(); + WebCore::cacheStorage().vacuumDatabaseFile(); + WebCore::cacheStorage().setMaximumSize(size); + cacheMaxSize = size; + } +#else + UNUSED_PARAM(size); +#endif +} + +/** + * webkit_spplication_cache_get_database_directory_path: + * + * Returns the current path to the directory WebKit will write web application + * cache databases. By default this path is set to $XDG_DATA_HOME/webkit/databases + * with webkit_application_cache_set_database_directory_path + * + * Returns: the current application cache database directory path + * + * Since: 1.3.13 + **/ +G_CONST_RETURN gchar* webkit_application_cache_get_database_directory_path() +{ +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + CString path = WebCore::fileSystemRepresentation(WebCore::cacheStorage().cacheDirectory()); + return path.data(); +#else + return ""; +#endif +} + diff --git a/Source/WebKit/gtk/webkit/webkitapplicationcache.h b/Source/WebKit/gtk/webkit/webkitapplicationcache.h new file mode 100644 index 0000000..bb0f867 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitapplicationcache.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 Lukasz Slachciak + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitapplicationcache_h +#define webkitapplicationcache_h + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +WEBKIT_API unsigned long long +webkit_application_cache_get_maximum_size(void); + +WEBKIT_API void +webkit_application_cache_set_maximum_size(unsigned long long size); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_application_cache_get_database_directory_path(void); + +G_END_DECLS + +#endif /* webkitapplicationcache_h */ diff --git a/Source/WebKit/gtk/webkit/webkitdefines.h b/Source/WebKit/gtk/webkit/webkitdefines.h new file mode 100644 index 0000000..0b88084 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitdefines.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitdefines_h +#define webkitdefines_h + +#include <glib.h> + +#ifdef G_OS_WIN32 + #ifdef BUILDING_WEBKIT + #define WEBKIT_API __declspec(dllexport) + #else + #define WEBKIT_API __declspec(dllimport) + #endif + #define WEBKIT_OBSOLETE_API WEBKIT_API +#else + #define WEBKIT_API __attribute__((visibility("default"))) + #define WEBKIT_OBSOLETE_API WEBKIT_API __attribute__((deprecated)) +#endif + +#ifndef WEBKIT_API + #define WEBKIT_API +#endif + +G_BEGIN_DECLS + +typedef struct _WebKitIconDatabase WebKitIconDatabase; +typedef struct _WebKitIconDatabaseClass WebKitIconDatabaseClass; + +typedef struct _WebKitNetworkRequest WebKitNetworkRequest; +typedef struct _WebKitNetworkRequestClass WebKitNetworkRequestClass; + +typedef struct _WebKitNetworkResponse WebKitNetworkResponse; +typedef struct _WebKitNetworkResponseClass WebKitNetworkResponseClass; + +typedef struct _WebKitWebBackForwardList WebKitWebBackForwardList; +typedef struct _WebKitWebBackForwardListClass WebKitWebBackForwardListClass; + +typedef struct _WebKitWebHistoryItem WebKitWebHistoryItem; +typedef struct _WebKitWebHistoryItemClass WebKitWebHistoryItemClass; + +typedef struct _WebKitWebFrame WebKitWebFrame; +typedef struct _WebKitWebFrameClass WebKitWebFrameClass; + +typedef struct _WebKitWebPolicyDecision WebKitWebPolicyDecision; +typedef struct _WebKitWebPolicyDecisionClass WebKitWebPolicyDecisionClass; + +typedef struct _WebKitWebSettings WebKitWebSettings; +typedef struct _WebKitWebSettingsClass WebKitWebSettingsClass; + +typedef struct _WebKitWebInspector WebKitWebInspector; +typedef struct _WebKitWebInspectorClass WebKitWebInspectorClass; + +typedef struct _WebKitWebWindowFeatures WebKitWebWindowFeatures; +typedef struct _WebKitWebWindowFeaturesClass WebKitWebWindowFeaturesClass; + +typedef struct _WebKitWebView WebKitWebView; +typedef struct _WebKitWebViewClass WebKitWebViewClass; + +typedef struct _WebKitDownload WebKitDownload; +typedef struct _WebKitDownloadClass WebKitDownloadClass; + +typedef struct _WebKitWebResource WebKitWebResource; +typedef struct _WebKitWebResourceClass WebKitWebResourceClass; + +typedef struct _WebKitWebDataSource WebKitWebDataSource; +typedef struct _WebKitWebDataSourceClass WebKitWebDataSourceClass; + +typedef struct _WebKitWebDatabase WebKitWebDatabase; +typedef struct _WebKitWebDatabaseClass WebKitWebDatabaseClass; + +typedef struct _WebKitSecurityOrigin WebKitSecurityOrigin; +typedef struct _WebKitSecurityOriginClass WebKitSecurityOriginClass; + +typedef struct _WebKitHitTestResult WebKitHitTestResult; +typedef struct _WebKitHitTestResultClass WebKitHitTestResultClass; + +typedef struct _WebKitGeolocationPolicyDecision WebKitGeolocationPolicyDecision; +typedef struct _WebKitGeolocationPolicyDecisionClass WebKitGeolocationPolicyDecisionClass; + +typedef struct _WebKitViewportAttributes WebKitViewportAttributes; +typedef struct _WebKitViewportAttributesClass WebKitViewportAttributesClass; + +typedef struct _WebKitWebPluginDatabase WebKitWebPluginDatabase; +typedef struct _WebKitWebPluginDatabaseClass WebKitWebPluginDatabaseClass; + +typedef struct _WebKitWebPlugin WebKitWebPlugin; +typedef struct _WebKitWebPluginClass WebKitWebPluginClass; + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitdownload.cpp b/Source/WebKit/gtk/webkit/webkitdownload.cpp new file mode 100644 index 0000000..f2d706f --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitdownload.cpp @@ -0,0 +1,957 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitdownload.h" + +#include "GRefPtr.h" +#include "Noncopyable.h" +#include "NotImplemented.h" +#include "ResourceHandleClient.h" +#include "ResourceHandleInternal.h" +#include "ResourceRequest.h" +#include "ResourceResponse.h" +#include "webkitdownloadprivate.h" +#include "webkitenumtypes.h" +#include "webkitglobals.h" +#include "webkitglobalsprivate.h" +#include "webkitmarshal.h" +#include "webkitnetworkrequestprivate.h" +#include "webkitnetworkresponse.h" +#include "webkitnetworkresponseprivate.h" +#include <glib/gi18n-lib.h> +#include <glib/gstdio.h> +#include <wtf/text/CString.h> + +#ifdef ERROR +#undef ERROR +#endif + +using namespace WebKit; +using namespace WebCore; + +/** + * SECTION:webkitdownload + * @short_description: Object used to communicate with the application when downloading. + * + * #WebKitDownload carries information about a download request, + * including a #WebKitNetworkRequest object. The application may use + * this object to control the download process, or to simply figure + * out what is to be downloaded, and do it itself. + */ + +class DownloadClient : public ResourceHandleClient { + WTF_MAKE_NONCOPYABLE(DownloadClient); + public: + DownloadClient(WebKitDownload*); + + virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&); + virtual void didReceiveData(ResourceHandle*, const char*, int, int); + virtual void didFinishLoading(ResourceHandle*, double); + virtual void didFail(ResourceHandle*, const ResourceError&); + virtual void wasBlocked(ResourceHandle*); + virtual void cannotShowURL(ResourceHandle*); + + private: + WebKitDownload* m_download; +}; + +struct _WebKitDownloadPrivate { + gchar* destinationURI; + gchar* suggestedFilename; + guint64 currentSize; + GTimer* timer; + WebKitDownloadStatus status; + GFileOutputStream* outputStream; + DownloadClient* downloadClient; + WebKitNetworkRequest* networkRequest; + WebKitNetworkResponse* networkResponse; + RefPtr<ResourceHandle> resourceHandle; +}; + +enum { + // Normal signals. + ERROR, + LAST_SIGNAL +}; + +static guint webkit_download_signals[LAST_SIGNAL] = { 0 }; + +enum { + PROP_0, + + PROP_NETWORK_REQUEST, + PROP_DESTINATION_URI, + PROP_SUGGESTED_FILENAME, + PROP_PROGRESS, + PROP_STATUS, + PROP_CURRENT_SIZE, + PROP_TOTAL_SIZE, + PROP_NETWORK_RESPONSE +}; + +G_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT); + + +static void webkit_download_set_response(WebKitDownload* download, const ResourceResponse& response); +static void webkit_download_set_status(WebKitDownload* download, WebKitDownloadStatus status); + +static void webkit_download_dispose(GObject* object) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + WebKitDownloadPrivate* priv = download->priv; + + if (priv->outputStream) { + g_object_unref(priv->outputStream); + priv->outputStream = NULL; + } + + if (priv->networkRequest) { + g_object_unref(priv->networkRequest); + priv->networkRequest = NULL; + } + + if (priv->networkResponse) { + g_object_unref(priv->networkResponse); + priv->networkResponse = NULL; + } + + G_OBJECT_CLASS(webkit_download_parent_class)->dispose(object); +} + +static void webkit_download_finalize(GObject* object) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + WebKitDownloadPrivate* priv = download->priv; + + // We don't call webkit_download_cancel() because we don't want to emit + // signals when finalizing an object. + if (priv->resourceHandle) { + if (priv->status == WEBKIT_DOWNLOAD_STATUS_STARTED) { + priv->resourceHandle->setClient(0); + priv->resourceHandle->cancel(); + } + priv->resourceHandle.release(); + } + + delete priv->downloadClient; + + // The download object may never have _start called on it, so we + // need to make sure timer is non-NULL. + if (priv->timer) { + g_timer_destroy(priv->timer); + priv->timer = NULL; + } + + g_free(priv->destinationURI); + g_free(priv->suggestedFilename); + + G_OBJECT_CLASS(webkit_download_parent_class)->finalize(object); +} + +static void webkit_download_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + + switch(prop_id) { + case PROP_NETWORK_REQUEST: + g_value_set_object(value, webkit_download_get_network_request(download)); + break; + case PROP_NETWORK_RESPONSE: + g_value_set_object(value, webkit_download_get_network_response(download)); + break; + case PROP_DESTINATION_URI: + g_value_set_string(value, webkit_download_get_destination_uri(download)); + break; + case PROP_SUGGESTED_FILENAME: + g_value_set_string(value, webkit_download_get_suggested_filename(download)); + break; + case PROP_PROGRESS: + g_value_set_double(value, webkit_download_get_progress(download)); + break; + case PROP_STATUS: + g_value_set_enum(value, webkit_download_get_status(download)); + break; + case PROP_CURRENT_SIZE: + g_value_set_uint64(value, webkit_download_get_current_size(download)); + break; + case PROP_TOTAL_SIZE: + g_value_set_uint64(value, webkit_download_get_total_size(download)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void webkit_download_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + WebKitDownloadPrivate* priv = download->priv; + + switch(prop_id) { + case PROP_NETWORK_REQUEST: + priv->networkRequest = WEBKIT_NETWORK_REQUEST(g_value_dup_object(value)); + break; + case PROP_NETWORK_RESPONSE: + priv->networkResponse = WEBKIT_NETWORK_RESPONSE(g_value_dup_object(value)); + break; + case PROP_DESTINATION_URI: + webkit_download_set_destination_uri(download, g_value_get_string(value)); + break; + case PROP_STATUS: + webkit_download_set_status(download, static_cast<WebKitDownloadStatus>(g_value_get_enum(value))); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void webkit_download_class_init(WebKitDownloadClass* downloadClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass); + objectClass->dispose = webkit_download_dispose; + objectClass->finalize = webkit_download_finalize; + objectClass->get_property = webkit_download_get_property; + objectClass->set_property = webkit_download_set_property; + + webkitInit(); + + /** + * WebKitDownload::error: + * @download: the object on which the signal is emitted + * @error_code: the corresponding error code + * @error_detail: detailed error code for the error, see + * #WebKitDownloadError + * @reason: a string describing the error + * + * Emitted when @download is interrupted either by user action or by + * network errors, @error_detail will take any value of + * #WebKitDownloadError. + * + * Since: 1.1.2 + */ + webkit_download_signals[ERROR] = g_signal_new("error", + G_TYPE_FROM_CLASS(downloadClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__INT_INT_STRING, + G_TYPE_BOOLEAN, 3, + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_STRING); + + // Properties. + + /** + * WebKitDownload:network-request + * + * The #WebKitNetworkRequest instance associated with the download. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, + PROP_NETWORK_REQUEST, + g_param_spec_object("network-request", + _("Network Request"), + _("The network request for the URI that should be downloaded"), + WEBKIT_TYPE_NETWORK_REQUEST, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitDownload:network-response + * + * The #WebKitNetworkResponse instance associated with the download. + * + * Since: 1.1.16 + */ + g_object_class_install_property(objectClass, + PROP_NETWORK_RESPONSE, + g_param_spec_object("network-response", + _("Network Response"), + _("The network response for the URI that should be downloaded"), + WEBKIT_TYPE_NETWORK_RESPONSE, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitDownload:destination-uri + * + * The URI of the save location for this download. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, + PROP_DESTINATION_URI, + g_param_spec_string("destination-uri", + _("Destination URI"), + _("The destination URI where to save the file"), + "", + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitDownload:suggested-filename + * + * The file name suggested as default when saving + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, + PROP_SUGGESTED_FILENAME, + g_param_spec_string("suggested-filename", + _("Suggested Filename"), + _("The filename suggested as default when saving"), + "", + WEBKIT_PARAM_READABLE)); + + /** + * WebKitDownload:progress: + * + * Determines the current progress of the download. Notice that, + * although the progress changes are reported as soon as possible, + * the emission of the notify signal for this property is + * throttled, for the benefit of download managers. If you care + * about every update, use WebKitDownload:current-size. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, PROP_PROGRESS, + g_param_spec_double("progress", + _("Progress"), + _("Determines the current progress of the download"), + 0.0, 1.0, 1.0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitDownload:status: + * + * Determines the current status of the download. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, PROP_STATUS, + g_param_spec_enum("status", + _("Status"), + _("Determines the current status of the download"), + WEBKIT_TYPE_DOWNLOAD_STATUS, + WEBKIT_DOWNLOAD_STATUS_CREATED, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitDownload:current-size + * + * The length of the data already downloaded + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, + PROP_CURRENT_SIZE, + g_param_spec_uint64("current-size", + _("Current Size"), + _("The length of the data already downloaded"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitDownload:total-size + * + * The total size of the file + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, + PROP_CURRENT_SIZE, + g_param_spec_uint64("total-size", + _("Total Size"), + _("The total size of the file"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(downloadClass, sizeof(WebKitDownloadPrivate)); +} + +static void webkit_download_init(WebKitDownload* download) +{ + WebKitDownloadPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(download, WEBKIT_TYPE_DOWNLOAD, WebKitDownloadPrivate); + download->priv = priv; + + priv->downloadClient = new DownloadClient(download); + priv->currentSize = 0; + priv->status = WEBKIT_DOWNLOAD_STATUS_CREATED; +} + +/** + * webkit_download_new: + * @request: a #WebKitNetworkRequest + * + * Creates a new #WebKitDownload object for the given + * #WebKitNetworkRequest object. + * + * Returns: the new #WebKitDownload + * + * Since: 1.1.2 + */ +WebKitDownload* webkit_download_new(WebKitNetworkRequest* request) +{ + g_return_val_if_fail(request, NULL); + + return WEBKIT_DOWNLOAD(g_object_new(WEBKIT_TYPE_DOWNLOAD, "network-request", request, NULL)); +} + +// Internal usage only +WebKitDownload* webkit_download_new_with_handle(WebKitNetworkRequest* request, WebCore::ResourceHandle* handle, const WebCore::ResourceResponse& response) +{ + g_return_val_if_fail(request, NULL); + + ResourceHandleInternal* d = handle->getInternal(); + if (d->m_soupMessage) + soup_session_pause_message(webkit_get_default_session(), d->m_soupMessage.get()); + + WebKitDownload* download = WEBKIT_DOWNLOAD(g_object_new(WEBKIT_TYPE_DOWNLOAD, "network-request", request, NULL)); + WebKitDownloadPrivate* priv = download->priv; + + handle->ref(); + priv->resourceHandle = handle; + + webkit_download_set_response(download, response); + + return download; +} + +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; + GFile* file = g_file_new_for_uri(uri); + GError* error = NULL; + + if (append) + priv->outputStream = g_file_append_to(file, G_FILE_CREATE_NONE, NULL, &error); + else + priv->outputStream = g_file_replace(file, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error); + + g_object_unref(file); + + if (error) { + gboolean handled; + g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled); + g_error_free(error); + return FALSE; + } + + return TRUE; +} + +static void webkit_download_close_stream(WebKitDownload* download) +{ + WebKitDownloadPrivate* priv = download->priv; + if (priv->outputStream) { + g_object_unref(priv->outputStream); + priv->outputStream = NULL; + } +} + +/** + * webkit_download_start: + * @download: the #WebKitDownload + * + * Initiates the download. Notice that you must have set the + * destination-uri property before calling this method. + * + * Since: 1.1.2 + */ +void webkit_download_start(WebKitDownload* download) +{ + g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); + + WebKitDownloadPrivate* priv = download->priv; + g_return_if_fail(priv->destinationURI); + g_return_if_fail(priv->status == WEBKIT_DOWNLOAD_STATUS_CREATED); + g_return_if_fail(priv->timer == NULL); + + // For GTK, when downloading a file NetworkingContext is null + if (!priv->resourceHandle) + priv->resourceHandle = ResourceHandle::create(/* Null NetworkingContext */ NULL, core(priv->networkRequest), priv->downloadClient, false, false); + else { + priv->resourceHandle->setClient(priv->downloadClient); + + ResourceHandleInternal* d = priv->resourceHandle->getInternal(); + if (d->m_soupMessage) + soup_session_unpause_message(webkit_get_default_session(), d->m_soupMessage.get()); + } + + priv->timer = g_timer_new(); + webkit_download_open_stream_for_uri(download, priv->destinationURI); +} + +/** + * webkit_download_cancel: + * @download: the #WebKitDownload + * + * Cancels the download. Calling this will not free the + * #WebKitDownload object, so you still need to call + * g_object_unref() on it, if you are the owner of a reference. Notice + * that cancelling the download provokes the emission of the + * WebKitDownload::error signal, reporting that the download was + * cancelled. + * + * Since: 1.1.2 + */ +void webkit_download_cancel(WebKitDownload* download) +{ + g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); + + WebKitDownloadPrivate* priv = download->priv; + + // Cancel may be called even if start was not called, so we need + // to make sure timer is non-NULL. + if (priv->timer) + g_timer_stop(priv->timer); + + if (priv->resourceHandle) + priv->resourceHandle->cancel(); + + webkit_download_set_status(download, WEBKIT_DOWNLOAD_STATUS_CANCELLED); + + gboolean handled; + g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER, _("User cancelled the download"), &handled); +} + +/** + * webkit_download_get_uri: + * @download: the #WebKitDownload + * + * Convenience method to retrieve the URI from the + * #WebKitNetworkRequest which is being downloaded. + * + * Returns: the uri + * + * Since: 1.1.2 + */ +const gchar* webkit_download_get_uri(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); + + WebKitDownloadPrivate* priv = download->priv; + return webkit_network_request_get_uri(priv->networkRequest); +} + +/** + * webkit_download_get_network_request: + * @download: the #WebKitDownload + * + * Retrieves the #WebKitNetworkRequest object that backs the download + * process. + * + * Returns: (transfer none): the #WebKitNetworkRequest instance + * + * Since: 1.1.2 + */ +WebKitNetworkRequest* webkit_download_get_network_request(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); + + WebKitDownloadPrivate* priv = download->priv; + return priv->networkRequest; +} + +/** + * webkit_download_get_network_response: + * @download: the #WebKitDownload + * + * Retrieves the #WebKitNetworkResponse object that backs the download + * process. + * + * Returns: (transfer none): the #WebKitNetworkResponse instance + * + * Since: 1.1.16 + */ +WebKitNetworkResponse* webkit_download_get_network_response(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); + + WebKitDownloadPrivate* priv = download->priv; + return priv->networkResponse; +} + +static void webkit_download_set_response(WebKitDownload* download, const ResourceResponse& response) +{ + WebKitDownloadPrivate* priv = download->priv; + priv->networkResponse = kitNew(response); + + if (!response.isNull() && !response.suggestedFilename().isEmpty()) + webkit_download_set_suggested_filename(download, response.suggestedFilename().utf8().data()); +} + +/** + * webkit_download_get_suggested_filename: + * @download: the #WebKitDownload + * + * Retrieves the filename that was suggested by the server, or the one + * derived by WebKit from the URI. + * + * Returns: the suggested filename + * + * Since: 1.1.2 + */ +const gchar* webkit_download_get_suggested_filename(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); + + WebKitDownloadPrivate* priv = download->priv; + if (priv->suggestedFilename) + return priv->suggestedFilename; + + KURL url = KURL(KURL(), webkit_network_request_get_uri(priv->networkRequest)); + url.setQuery(String()); + url.removeFragmentIdentifier(); + priv->suggestedFilename = g_strdup(decodeURLEscapeSequences(url.lastPathComponent()).utf8().data()); + return priv->suggestedFilename; +} + +// for internal use only +void webkit_download_set_suggested_filename(WebKitDownload* download, const gchar* suggestedFilename) +{ + WebKitDownloadPrivate* priv = download->priv; + g_free(priv->suggestedFilename); + priv->suggestedFilename = g_strdup(suggestedFilename); + + g_object_notify(G_OBJECT(download), "suggested-filename"); +} + + +/** + * webkit_download_get_destination_uri: + * @download: the #WebKitDownload + * + * Obtains the URI to which the downloaded file will be written. This + * must have been set by the application before calling + * webkit_download_start(), and may be %NULL. + * + * Returns: the destination URI or %NULL + * + * Since: 1.1.2 + */ +const gchar* webkit_download_get_destination_uri(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); + + WebKitDownloadPrivate* priv = download->priv; + return priv->destinationURI; +} + +/** + * webkit_download_set_destination_uri: + * @download: the #WebKitDownload + * @destination_uri: the destination URI + * + * Defines the URI that should be used to save the downloaded file to. + * + * Since: 1.1.2 + */ +void webkit_download_set_destination_uri(WebKitDownload* download, const gchar* destination_uri) +{ + g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); + g_return_if_fail(destination_uri); + + WebKitDownloadPrivate* priv = download->priv; + if (priv->destinationURI && !strcmp(priv->destinationURI, destination_uri)) + return; + + if (priv->status != WEBKIT_DOWNLOAD_STATUS_CREATED && priv->status != WEBKIT_DOWNLOAD_STATUS_CANCELLED) { + ASSERT(priv->destinationURI); + + gboolean downloading = priv->outputStream != NULL; + if (downloading) + webkit_download_close_stream(download); + + GFile* src = g_file_new_for_uri(priv->destinationURI); + GFile* dest = g_file_new_for_uri(destination_uri); + GError* error = NULL; + + g_file_move(src, dest, G_FILE_COPY_BACKUP, NULL, NULL, NULL, &error); + + g_object_unref(src); + g_object_unref(dest); + + g_free(priv->destinationURI); + priv->destinationURI = g_strdup(destination_uri); + + if (error) { + gboolean handled; + g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled); + g_error_free(error); + return; + } + + if (downloading) { + if (!webkit_download_open_stream_for_uri(download, destination_uri, TRUE)) { + webkit_download_cancel(download); + return; + } + } + } else { + g_free(priv->destinationURI); + priv->destinationURI = g_strdup(destination_uri); + } + + // Only notify change if everything went fine. + g_object_notify(G_OBJECT(download), "destination-uri"); +} + +/** + * webkit_download_get_status: + * @download: the #WebKitDownload + * + * Obtains the current status of the download, as a + * #WebKitDownloadStatus. + * + * Returns: the current #WebKitDownloadStatus + * + * Since: 1.1.2 + */ +WebKitDownloadStatus webkit_download_get_status(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), WEBKIT_DOWNLOAD_STATUS_ERROR); + + WebKitDownloadPrivate* priv = download->priv; + return priv->status; +} + +static void webkit_download_set_status(WebKitDownload* download, WebKitDownloadStatus status) +{ + g_return_if_fail(WEBKIT_IS_DOWNLOAD(download)); + + WebKitDownloadPrivate* priv = download->priv; + priv->status = status; + + g_object_notify(G_OBJECT(download), "status"); +} + +/** + * webkit_download_get_total_size: + * @download: the #WebKitDownload + * + * Returns the expected total size of the download. This is expected + * because the server may provide incorrect or missing + * Content-Length. Notice that this may grow over time, as it will be + * always the same as current_size in the cases where current size + * surpasses it. + * + * Returns: the expected total size of the downloaded file + * + * Since: 1.1.2 + */ +guint64 webkit_download_get_total_size(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0); + + WebKitDownloadPrivate* priv = download->priv; + SoupMessage* message = priv->networkResponse ? webkit_network_response_get_message(priv->networkResponse) : NULL; + + if (!message) + return 0; + + return MAX(priv->currentSize, static_cast<guint64>(soup_message_headers_get_content_length(message->response_headers))); +} + +/** + * webkit_download_get_current_size: + * @download: the #WebKitDownload + * + * Current already downloaded size. + * + * Returns: the already downloaded size + * + * Since: 1.1.2 + */ +guint64 webkit_download_get_current_size(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0); + + WebKitDownloadPrivate* priv = download->priv; + return priv->currentSize; +} + +/** + * webkit_download_get_progress: + * @download: a #WebKitDownload + * + * Determines the current progress of the download. + * + * Returns: a #gdouble ranging from 0.0 to 1.0. + * + * Since: 1.1.2 + */ +gdouble webkit_download_get_progress(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 1.0); + + WebKitDownloadPrivate* priv = download->priv; + if (!priv->networkResponse) + return 0.0; + + gdouble total_size = static_cast<gdouble>(webkit_download_get_total_size(download)); + + if (total_size == 0) + return 1.0; + + return ((gdouble)priv->currentSize) / total_size; +} + +/** + * webkit_download_get_elapsed_time: + * @download: a #WebKitDownload + * + * Elapsed time for the download in seconds, including any fractional + * part. If the download is finished, had an error or was cancelled + * this is the time between its start and the event. + * + * Returns: seconds since the download was started, as a #gdouble + * + * Since: 1.1.2 + */ +gdouble webkit_download_get_elapsed_time(WebKitDownload* download) +{ + g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0.0); + + WebKitDownloadPrivate* priv = download->priv; + if (!priv->timer) + return 0; + + return g_timer_elapsed(priv->timer, NULL); +} + +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; + GError* error = NULL; + + g_output_stream_write_all(G_OUTPUT_STREAM(priv->outputStream), + data, length, &bytes_written, NULL, &error); + + if (error) { + gboolean handled; + g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled); + g_error_free(error); + 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"); +} + +static void webkit_download_finished_loading(WebKitDownload* download) +{ + webkit_download_close_stream(download); + + WebKitDownloadPrivate* priv = download->priv; + + g_timer_stop(priv->timer); + + g_object_notify(G_OBJECT(download), "progress"); + webkit_download_set_status(download, WEBKIT_DOWNLOAD_STATUS_FINISHED); +} + +static void webkit_download_error(WebKitDownload* download, const ResourceError& error) +{ + webkit_download_close_stream(download); + + WebKitDownloadPrivate* priv = download->priv; + GRefPtr<WebKitDownload> protect(download); + + g_timer_stop(priv->timer); + webkit_download_set_status(download, WEBKIT_DOWNLOAD_STATUS_ERROR); + + gboolean handled; + g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_NETWORK, error.localizedDescription().utf8().data(), &handled); +} + +DownloadClient::DownloadClient(WebKitDownload* download) + : m_download(download) +{ +} + +void DownloadClient::didReceiveResponse(ResourceHandle*, const ResourceResponse& response) +{ + webkit_download_set_response(m_download, response); +} + +void DownloadClient::didReceiveData(ResourceHandle*, const char* data, int length, int encodedDataLength) +{ + webkit_download_received_data(m_download, data, length); +} + +void DownloadClient::didFinishLoading(ResourceHandle*, double) +{ + webkit_download_finished_loading(m_download); +} + +void DownloadClient::didFail(ResourceHandle*, const ResourceError& error) +{ + webkit_download_error(m_download, error); +} + +void DownloadClient::wasBlocked(ResourceHandle*) +{ + // FIXME: Implement this when we have the new frame loader signals + // and error handling. + notImplemented(); +} + +void DownloadClient::cannotShowURL(ResourceHandle*) +{ + // FIXME: Implement this when we have the new frame loader signals + // and error handling. + notImplemented(); +} diff --git a/Source/WebKit/gtk/webkit/webkitdownload.h b/Source/WebKit/gtk/webkit/webkitdownload.h new file mode 100644 index 0000000..a732a57 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitdownload.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitdownload_h +#define webkitdownload_h + +#include <webkit/webkitdefines.h> + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_DOWNLOAD (webkit_download_get_type()) +#define WEBKIT_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownload)) +#define WEBKIT_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass)) +#define WEBKIT_IS_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DOWNLOAD)) +#define WEBKIT_IS_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_DOWNLOAD)) +#define WEBKIT_DOWNLOAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass)) + +typedef enum { + WEBKIT_DOWNLOAD_STATUS_ERROR = -1, + WEBKIT_DOWNLOAD_STATUS_CREATED = 0, + WEBKIT_DOWNLOAD_STATUS_STARTED, + WEBKIT_DOWNLOAD_STATUS_CANCELLED, + WEBKIT_DOWNLOAD_STATUS_FINISHED +} WebKitDownloadStatus; + +typedef enum { + WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER, + WEBKIT_DOWNLOAD_ERROR_DESTINATION, + WEBKIT_DOWNLOAD_ERROR_NETWORK +} WebKitDownloadError; + +typedef struct _WebKitDownloadPrivate WebKitDownloadPrivate; + +struct _WebKitDownload { + GObject parent_instance; + + WebKitDownloadPrivate *priv; +}; + +struct _WebKitDownloadClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_download_get_type (void); + +WEBKIT_API WebKitDownload* +webkit_download_new (WebKitNetworkRequest *request); + +WEBKIT_API void +webkit_download_start (WebKitDownload *download); + +WEBKIT_API void +webkit_download_cancel (WebKitDownload *download); + +WEBKIT_API const gchar* +webkit_download_get_uri (WebKitDownload *download); + +WEBKIT_API WebKitNetworkRequest* +webkit_download_get_network_request (WebKitDownload *download); + +WEBKIT_API WebKitNetworkResponse* +webkit_download_get_network_response (WebKitDownload *download); + +WEBKIT_API const gchar* +webkit_download_get_suggested_filename (WebKitDownload *download); + +WEBKIT_API const gchar* +webkit_download_get_destination_uri (WebKitDownload *download); + +WEBKIT_API void +webkit_download_set_destination_uri (WebKitDownload *download, + const gchar *destination_uri); + +WEBKIT_API gdouble +webkit_download_get_progress (WebKitDownload *download); + +WEBKIT_API gdouble +webkit_download_get_elapsed_time (WebKitDownload *download); + +WEBKIT_API guint64 +webkit_download_get_total_size (WebKitDownload *download); + +WEBKIT_API guint64 +webkit_download_get_current_size (WebKitDownload *download); + +WEBKIT_API WebKitDownloadStatus +webkit_download_get_status (WebKitDownload *download); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitdownloadprivate.h b/Source/WebKit/gtk/webkit/webkitdownloadprivate.h new file mode 100644 index 0000000..13cc2a4 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitdownloadprivate.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitdownloadprivate_h +#define webkitdownloadprivate_h + +#include "webkitdownload.h" + +extern "C" { + +WebKitDownload* webkit_download_new_with_handle(WebKitNetworkRequest*, WebCore::ResourceHandle*, const WebCore::ResourceResponse&); + +void webkit_download_set_suggested_filename(WebKitDownload*, const gchar* suggestedFilename); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkiterror.cpp b/Source/WebKit/gtk/webkit/webkiterror.cpp new file mode 100644 index 0000000..e93a5d5 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkiterror.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2008 Luca Bruno <lethalman88@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#include "webkiterror.h" + +GQuark webkit_network_error_quark(void) +{ + return g_quark_from_static_string("webkit-network-error-quark"); +} + +GQuark webkit_policy_error_quark(void) +{ + return g_quark_from_static_string("webkit-policy-error-quark"); +} + +GQuark webkit_plugin_error_quark(void) +{ + return g_quark_from_static_string("webkit-plugin-error-quark"); +} diff --git a/Source/WebKit/gtk/webkit/webkiterror.h b/Source/WebKit/gtk/webkit/webkiterror.h new file mode 100644 index 0000000..8fec949 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkiterror.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2008 Luca Bruno <lethalman88@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkiterror_h +#define webkiterror_h + +#include <glib.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_NETWORK_ERROR webkit_network_error_quark () +#define WEBKIT_POLICY_ERROR webkit_policy_error_quark () +#define WEBKIT_PLUGIN_ERROR webkit_plugin_error_quark () + +typedef enum { + WEBKIT_NETWORK_ERROR_FAILED = 399, + WEBKIT_NETWORK_ERROR_TRANSPORT = 300, + WEBKIT_NETWORK_ERROR_UNKNOWN_PROTOCOL = 301, + WEBKIT_NETWORK_ERROR_CANCELLED = 302, + WEBKIT_NETWORK_ERROR_FILE_DOES_NOT_EXIST = 303, +} WebKitNetworkError; + +/* Sync'd with Mac's WebKit Errors */ +typedef enum { + WEBKIT_POLICY_ERROR_FAILED = 199, + WEBKIT_POLICY_ERROR_CANNOT_SHOW_MIME_TYPE = 100, + WEBKIT_POLICY_ERROR_CANNOT_SHOW_URL = 101, + WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE = 102, + WEBKIT_POLICY_ERROR_CANNOT_USE_RESTRICTED_PORT = 103, +} WebKitPolicyError; + +typedef enum { + WEBKIT_PLUGIN_ERROR_FAILED = 299, + WEBKIT_PLUGIN_ERROR_CANNOT_FIND_PLUGIN = 200, + WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN = 201, + WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE = 202, + WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED = 203, + WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD = 204, +} WebKitPluginError; + + +WEBKIT_API GQuark +webkit_network_error_quark (void); + +WEBKIT_API GQuark +webkit_policy_error_quark (void); + +WEBKIT_API GQuark +webkit_plugin_error_quark (void); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.cpp b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.cpp new file mode 100644 index 0000000..2523c9b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010 Arno Renevier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitgeolocationpolicydecision.h" + +#include "Geolocation.h" +#include "webkitgeolocationpolicydecisionprivate.h" + +using namespace WebCore; + +/** + * SECTION:webkitgeolocationpolicydecision + * @short_description: Liaison between WebKit and the application regarding asynchronous geolocation policy decisions + * + * #WebKitGeolocationPolicyDecision objects are given to the application when + * geolocation-policy-decision-requested signal is emitted. The application + * uses it to tell the engine whether it wants to allow or deny geolocation for + * a given frame. + */ + +G_DEFINE_TYPE(WebKitGeolocationPolicyDecision, webkit_geolocation_policy_decision, G_TYPE_OBJECT); + +struct _WebKitGeolocationPolicyDecisionPrivate { + WebKitWebFrame* frame; + Geolocation* geolocation; +}; + +static void webkit_geolocation_policy_decision_class_init(WebKitGeolocationPolicyDecisionClass* decisionClass) +{ + g_type_class_add_private(decisionClass, sizeof(WebKitGeolocationPolicyDecisionPrivate)); +} + +static void webkit_geolocation_policy_decision_init(WebKitGeolocationPolicyDecision* decision) +{ + decision->priv = G_TYPE_INSTANCE_GET_PRIVATE(decision, WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION, WebKitGeolocationPolicyDecisionPrivate); +} + +WebKitGeolocationPolicyDecision* webkit_geolocation_policy_decision_new(WebKitWebFrame* frame, Geolocation* geolocation) +{ + g_return_val_if_fail(frame, NULL); + WebKitGeolocationPolicyDecision* decision = WEBKIT_GEOLOCATION_POLICY_DECISION(g_object_new(WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION, NULL)); + WebKitGeolocationPolicyDecisionPrivate* priv = decision->priv; + + priv->frame = frame; + priv->geolocation = geolocation; + return decision; +} + +/** + * webkit_geolocation_policy_allow + * @decision: a #WebKitGeolocationPolicyDecision + * + * Will send the allow decision to the policy implementer. + * + * Since: 1.1.23 + */ +void webkit_geolocation_policy_allow(WebKitGeolocationPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_GEOLOCATION_POLICY_DECISION(decision)); + + WebKitGeolocationPolicyDecisionPrivate* priv = decision->priv; + priv->geolocation->setIsAllowed(TRUE); +} + +/** + * webkit_geolocation_policy_deny + * @decision: a #WebKitGeolocationPolicyDecision + * + * Will send the deny decision to the policy implementer. + * + * Since: 1.1.23 + */ +void webkit_geolocation_policy_deny(WebKitGeolocationPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_GEOLOCATION_POLICY_DECISION(decision)); + + WebKitGeolocationPolicyDecisionPrivate* priv = decision->priv; + priv->geolocation->setIsAllowed(FALSE); +} + diff --git a/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.h b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.h new file mode 100644 index 0000000..27e0ef2 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecision.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Arno Renevier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitgeolocationpolicydecision_h +#define webkitgeolocationpolicydecision_h + +#include <glib-object.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION (webkit_geolocation_policy_decision_get_type()) +#define WEBKIT_GEOLOCATION_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION, WebKitGeolocationPolicyDecision)) +#define WEBKIT_GEOLOCATION_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION, WebKitGeolocationPolicyDecisionClass)) +#define WEBKIT_IS_GEOLOCATION_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION)) +#define WEBKIT_IS_GEOLOCATION_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION)) +#define WEBKIT_GEOLOCATION_POLICY_DECISION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION, WebKitGeolocationPolicyDecisionClass)) + +typedef struct _WebKitGeolocationPolicyDecisionPrivate WebKitGeolocationPolicyDecisionPrivate; +struct _WebKitGeolocationPolicyDecision { + GObject parent_instance; + + /*< private >*/ + WebKitGeolocationPolicyDecisionPrivate* priv; +}; + +struct _WebKitGeolocationPolicyDecisionClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_geolocation_policy_decision_get_type (void); + +WEBKIT_API void +webkit_geolocation_policy_allow (WebKitGeolocationPolicyDecision* decision); + +WEBKIT_API void +webkit_geolocation_policy_deny (WebKitGeolocationPolicyDecision* decision); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecisionprivate.h b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecisionprivate.h new file mode 100644 index 0000000..d250044 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitgeolocationpolicydecisionprivate.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitgeolocationpolicydecisionprivate_h +#define webkitgeolocationpolicydecisionprivate_h + +#include "webkitgeolocationpolicydecision.h" + +extern "C" { + +WebKitGeolocationPolicyDecision* webkit_geolocation_policy_decision_new(WebKitWebFrame*, WebCore::Geolocation*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitglobals.cpp b/Source/WebKit/gtk/webkit/webkitglobals.cpp new file mode 100644 index 0000000..b8d8b1f --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitglobals.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008, 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitglobals.h" + +#include "ApplicationCacheStorage.h" +#include "Chrome.h" +#include "FrameNetworkingContextGtk.h" +#include "GOwnPtr.h" +#include "IconDatabase.h" +#include "Logging.h" +#include "MemoryCache.h" +#include "Page.h" +#include "PageCache.h" +#include "PageGroup.h" +#include "TextEncodingRegistry.h" +#include "Pasteboard.h" +#include "PasteboardHelperGtk.h" +#include "ResourceHandle.h" +#include "ResourceHandleClient.h" +#include "ResourceHandleInternal.h" +#include "ResourceResponse.h" +#include "webkitapplicationcache.h" +#include "webkitglobalsprivate.h" +#include "webkiticondatabase.h" +#include "webkitsoupauthdialog.h" +#include "webkitwebdatabase.h" +#include "webkitwebplugindatabaseprivate.h" +#include <libintl.h> +#include <runtime/InitializeThreading.h> +#include <stdlib.h> +#include <wtf/Threading.h> + +static WebKitCacheModel cacheModel = WEBKIT_CACHE_MODEL_DEFAULT; + +using namespace WebCore; + +/** + * SECTION:webkit + * @short_description: Global functions controlling WebKit + * + * WebKit manages many resources which are not related to specific + * views. These functions relate to cross-view limits, such as cache + * sizes, database quotas, and the HTTP session management. + */ + +/** + * webkit_get_default_session: + * + * Retrieves the default #SoupSession used by all web views. + * Note that the session features are added by WebKit on demand, + * so if you insert your own #SoupCookieJar before any network + * traffic occurs, WebKit will use it instead of the default. + * + * Return value: (transfer none): the default #SoupSession + * + * Since: 1.1.1 + */ +SoupSession* webkit_get_default_session () +{ + webkitInit(); + return ResourceHandle::defaultSession(); +} + +/** + * webkit_set_cache_model: + * @cache_model: a #WebKitCacheModel + * + * Specifies a usage model for WebViews, which WebKit will use to + * determine its caching behavior. All web views follow the cache + * model. This cache model determines the RAM and disk space to use + * for caching previously viewed content . + * + * Research indicates that users tend to browse within clusters of + * documents that hold resources in common, and to revisit previously + * visited documents. WebKit and the frameworks below it include + * built-in caches that take advantage of these patterns, + * substantially improving document load speed in browsing + * situations. The WebKit cache model controls the behaviors of all of + * these caches, including various WebCore caches. + * + * Browsers can improve document load speed substantially by + * specifying WEBKIT_CACHE_MODEL_WEB_BROWSER. Applications without a + * browsing interface can reduce memory usage substantially by + * specifying WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER. Default value is + * WEBKIT_CACHE_MODEL_WEB_BROWSER. + * + * Since: 1.1.18 + */ +void webkit_set_cache_model(WebKitCacheModel model) +{ + webkitInit(); + + if (cacheModel == model) + return; + + // FIXME: Add disk cache handling when soup has the API + guint cacheTotalCapacity; + guint cacheMinDeadCapacity; + guint cacheMaxDeadCapacity; + gdouble deadDecodedDataDeletionInterval; + guint pageCacheCapacity; + + // FIXME: The Mac port calculates these values based on the amount of physical memory that's + // installed on the system. Currently these values match the Mac port for users with more than + // 512 MB and less than 1024 MB of physical memory. + switch (model) { + case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: + pageCacheCapacity = 0; + cacheTotalCapacity = 0; // FIXME: The Mac port actually sets this to larger than 0. + cacheMinDeadCapacity = 0; + cacheMaxDeadCapacity = 0; + deadDecodedDataDeletionInterval = 0; + break; + case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: + pageCacheCapacity = 2; + cacheTotalCapacity = 16 * 1024 * 1024; + cacheMinDeadCapacity = cacheTotalCapacity / 8; + cacheMaxDeadCapacity = cacheTotalCapacity / 4; + deadDecodedDataDeletionInterval = 0; + break; + case WEBKIT_CACHE_MODEL_WEB_BROWSER: + // Page cache capacity (in pages). Comment from Mac port: + // (Research indicates that value / page drops substantially after 3 pages.) + pageCacheCapacity = 3; + cacheTotalCapacity = 32 * 1024 * 1024; + cacheMinDeadCapacity = cacheTotalCapacity / 4; + cacheMaxDeadCapacity = cacheTotalCapacity / 2; + deadDecodedDataDeletionInterval = 60; + break; + default: + g_return_if_reached(); + } + + memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity); + memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval); + pageCache()->setCapacity(pageCacheCapacity); + cacheModel = model; +} + +/** + * webkit_get_cache_model: + * + * Returns the current cache model. For more information about this + * value check the documentation of the function + * webkit_set_cache_model(). + * + * Return value: the current #WebKitCacheModel + * + * Since: 1.1.18 + */ +WebKitCacheModel webkit_get_cache_model() +{ + webkitInit(); + return cacheModel; +} + +/** + * webkit_get_web_plugin_database: + * + * Returns the current #WebKitWebPluginDatabase with information about + * all the plugins WebKit knows about in this instance. + * + * Return value: (transfer none): the current #WebKitWebPluginDatabase + * + * Since: 1.3.8 + */ +WebKitWebPluginDatabase* webkit_get_web_plugin_database() +{ + static WebKitWebPluginDatabase* database = 0; + + webkitInit(); + + if (!database) + database = webkit_web_plugin_database_new(); + + return database; +} + + +static GtkWidget* currentToplevelCallback(WebKitSoupAuthDialog* feature, SoupMessage* message, gpointer userData) +{ + gpointer messageData = g_object_get_data(G_OBJECT(message), "resourceHandle"); + if (!messageData) + return NULL; + + ResourceHandle* handle = static_cast<ResourceHandle*>(messageData); + if (!handle) + return NULL; + + ResourceHandleInternal* d = handle->getInternal(); + if (!d) + return NULL; + + WebKit::FrameNetworkingContextGtk* context = static_cast<WebKit::FrameNetworkingContextGtk*>(d->m_context.get()); + if (!context) + return NULL; + + if (!context->coreFrame()) + return NULL; + + GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(context->coreFrame()->page()->chrome()->platformPageClient())); + if (gtk_widget_is_toplevel(toplevel)) + return toplevel; + else + return NULL; +} + +/** + * webkit_get_icon_database: + * + * Returns the #WebKitIconDatabase providing access to website icons. + * + * Return value: (transfer none): the current #WebKitIconDatabase + * + * Since: 1.3.13 + */ +WebKitIconDatabase* webkit_get_icon_database() +{ + webkitInit(); + + static WebKitIconDatabase* database = 0; + if (!database) + database = WEBKIT_ICON_DATABASE(g_object_new(WEBKIT_TYPE_ICON_DATABASE, NULL)); + + return database; +} + +void webkitInit() +{ + static bool isInitialized = false; + if (isInitialized) + return; + isInitialized = true; + + bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + + JSC::initializeThreading(); + WTF::initializeMainThread(); + + WebCore::InitializeLoggingChannelsIfNecessary(); + + // We make sure the text codecs have been initialized, because + // that may only be done by the main thread. + atomicCanonicalTextEncodingName("UTF-8"); + + gchar* databaseDirectory = g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL); + webkit_set_web_database_directory_path(databaseDirectory); + WebCore::cacheStorage().setCacheDirectory(databaseDirectory); + + g_free(databaseDirectory); + + PageGroup::setShouldTrackVisitedLinks(true); + + Pasteboard::generalPasteboard()->setHelper(WebKit::pasteboardHelperInstance()); + GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_user_data_dir(), "webkit", "icondatabase", NULL)); + webkit_icon_database_set_path(webkit_get_icon_database(), iconDatabasePath.get()); + + SoupSession* session = webkit_get_default_session(); + + SoupSessionFeature* authDialog = static_cast<SoupSessionFeature*>(g_object_new(WEBKIT_TYPE_SOUP_AUTH_DIALOG, NULL)); + g_signal_connect(authDialog, "current-toplevel", G_CALLBACK(currentToplevelCallback), NULL); + soup_session_add_feature(session, authDialog); + g_object_unref(authDialog); + + SoupSessionFeature* sniffer = static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL)); + soup_session_add_feature(session, sniffer); + g_object_unref(sniffer); + + soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER); +} + +namespace WebKit { + +PasteboardHelperGtk* pasteboardHelperInstance() +{ + static PasteboardHelperGtk* helper = new PasteboardHelperGtk(); + return helper; +} + +} /** end namespace WebKit */ + diff --git a/Source/WebKit/gtk/webkit/webkitglobals.h b/Source/WebKit/gtk/webkit/webkitglobals.h new file mode 100644 index 0000000..33d2b8b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitglobals.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitglobals_h +#define webkitglobals_h + +#include "webkitdefines.h" +#include <glib.h> +#include <libsoup/soup.h> + +G_BEGIN_DECLS + +/* + * WebKitCacheModel: + * @WEBKIT_CACHE_MODEL_DEFAULT: The default cache model. This is + * WEBKIT_CACHE_MODEL_WEB_BROWSER. + * @WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: Disable the cache completely, which + * substantially reduces memory usage. Useful for applications that only + * access a single local file, with no navigation to other pages. No remote + * resources will be cached. + * @WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: A cache model optimized for viewing + * a series of local files -- for example, a documentation viewer or a website + * designer. WebKit will cache a moderate number of resources. + * @WEBKIT_CACHE_MODEL_WEB_BROWSER: Improve document load speed substantially + * by caching a very large number of resources and previously viewed content. + * + * Enum values used for determining the webview cache model. + */ +typedef enum { + WEBKIT_CACHE_MODEL_DEFAULT, + WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER, + WEBKIT_CACHE_MODEL_WEB_BROWSER, + WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER, +} WebKitCacheModel; + +WEBKIT_API SoupSession* +webkit_get_default_session (void); + +WEBKIT_API WebKitWebPluginDatabase * +webkit_get_web_plugin_database (void); + +WEBKIT_API WebKitIconDatabase * +webkit_get_icon_database (void); + +WEBKIT_API void +webkit_set_cache_model (WebKitCacheModel cache_model); + +WEBKIT_API WebKitCacheModel +webkit_get_cache_model (void); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitglobalsprivate.h b/Source/WebKit/gtk/webkit/webkitglobalsprivate.h new file mode 100644 index 0000000..5923f2e --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitglobalsprivate.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitglobalsprivate_h +#define webkitglobalsprivate_h + +#include <glib.h> + +#define WEBKIT_PARAM_READABLE ((GParamFlags)(G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_READWRITE ((GParamFlags)(G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) + +namespace WebKit { + +class PasteboardHelperGtk; +PasteboardHelperGtk* pasteboardHelperInstance(); + +} + +extern "C" { + +void webkitInit(); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkithittestresult.cpp b/Source/WebKit/gtk/webkit/webkithittestresult.cpp new file mode 100644 index 0000000..9632493 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkithittestresult.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkithittestresult.h" + +#include "GOwnPtr.h" +#include "HitTestResult.h" +#include "KURL.h" +#include "WebKitDOMBinding.h" +#include "WebKitDOMNode.h" +#include "webkitenumtypes.h" +#include "webkitglobals.h" +#include "webkitglobalsprivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkithittestresult + * @short_description: The target of a mouse event + * + * This class holds context information about the coordinates + * specified by a GDK event. + */ + +G_DEFINE_TYPE(WebKitHitTestResult, webkit_hit_test_result, G_TYPE_OBJECT) + +struct _WebKitHitTestResultPrivate { + guint context; + char* linkURI; + char* imageURI; + char* mediaURI; + WebKitDOMNode* innerNode; +}; + +enum { + PROP_0, + + PROP_CONTEXT, + PROP_LINK_URI, + PROP_IMAGE_URI, + PROP_MEDIA_URI, + PROP_INNER_NODE +}; + +static void webkit_hit_test_result_finalize(GObject* object) +{ + WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object); + WebKitHitTestResultPrivate* priv = web_hit_test_result->priv; + + g_free(priv->linkURI); + g_free(priv->imageURI); + g_free(priv->mediaURI); + + G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->finalize(object); +} + +static void webkit_hit_test_result_dispose(GObject* object) +{ + g_object_unref(WEBKIT_HIT_TEST_RESULT(object)->priv->innerNode); + + G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->dispose(object); +} + +static void webkit_hit_test_result_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec) +{ + WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object); + WebKitHitTestResultPrivate* priv = web_hit_test_result->priv; + + switch(propertyID) { + case PROP_CONTEXT: + g_value_set_flags(value, priv->context); + break; + case PROP_LINK_URI: + g_value_set_string(value, priv->linkURI); + break; + case PROP_IMAGE_URI: + g_value_set_string(value, priv->imageURI); + break; + case PROP_MEDIA_URI: + g_value_set_string(value, priv->mediaURI); + break; + case PROP_INNER_NODE: + g_value_set_object(value, priv->innerNode); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_hit_test_result_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec) +{ + WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object); + WebKitHitTestResultPrivate* priv = web_hit_test_result->priv; + + switch(propertyID) { + case PROP_CONTEXT: + priv->context = g_value_get_flags(value); + break; + case PROP_LINK_URI: + g_free (priv->linkURI); + priv->linkURI = g_value_dup_string(value); + break; + case PROP_IMAGE_URI: + g_free (priv->imageURI); + priv->imageURI = g_value_dup_string(value); + break; + case PROP_MEDIA_URI: + g_free (priv->mediaURI); + priv->mediaURI = g_value_dup_string(value); + break; + case PROP_INNER_NODE: + priv->innerNode = static_cast<WebKitDOMNode*>(g_value_get_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* webHitTestResultClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(webHitTestResultClass); + + objectClass->finalize = webkit_hit_test_result_finalize; + objectClass->dispose = webkit_hit_test_result_dispose; + objectClass->get_property = webkit_hit_test_result_get_property; + objectClass->set_property = webkit_hit_test_result_set_property; + + webkitInit(); + + /** + * WebKitHitTestResult:context: + * + * Flags indicating the kind of target that received the event. + * + * Since: 1.1.15 + */ + g_object_class_install_property(objectClass, PROP_CONTEXT, + g_param_spec_flags("context", + _("Context"), + _("Flags indicating the kind of target that received the event."), + WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT, + WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, + static_cast<GParamFlags>((WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)))); + + /** + * WebKitHitTestResult:link-uri: + * + * The URI to which the target that received the event points, if any. + * + * Since: 1.1.15 + */ + g_object_class_install_property(objectClass, PROP_LINK_URI, + g_param_spec_string("link-uri", + _("Link URI"), + _("The URI to which the target that received the event points, if any."), + NULL, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitHitTestResult:image-uri: + * + * The URI of the image that is part of the target that received the event, if any. + * + * Since: 1.1.15 + */ + g_object_class_install_property(objectClass, PROP_IMAGE_URI, + g_param_spec_string("image-uri", + _("Image URI"), + _("The URI of the image that is part of the target that received the event, if any."), + NULL, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitHitTestResult:media-uri: + * + * The URI of the media that is part of the target that received the event, if any. + * + * Since: 1.1.15 + */ + g_object_class_install_property(objectClass, PROP_MEDIA_URI, + g_param_spec_string("media-uri", + _("Media URI"), + _("The URI of the media that is part of the target that received the event, if any."), + NULL, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitHitTestResult:inner-node: + * + * The DOM node at the coordinates where the hit test + * happened. Keep in mind that the node might not be + * representative of the information given in the context + * property, since WebKit uses a series of heuristics to figure + * out that information. One common example is inner-node having + * the text node inside the anchor (<a>) tag; WebKit knows the + * whole context and will put WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK + * in the 'context' property, but the user might be confused by + * the lack of any link tag in 'inner-node'. + * + * Since: 1.3.2 + */ + g_object_class_install_property(objectClass, PROP_INNER_NODE, + g_param_spec_object("inner-node", + _("Inner node"), + _("The inner DOM node associated with the hit test result."), + WEBKIT_TYPE_DOM_NODE, + static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + g_type_class_add_private(webHitTestResultClass, sizeof(WebKitHitTestResultPrivate)); +} + +static void webkit_hit_test_result_init(WebKitHitTestResult* web_hit_test_result) +{ + web_hit_test_result->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_hit_test_result, WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResultPrivate); +} + +namespace WebKit { + +WebKitHitTestResult* kit(const WebCore::HitTestResult& result) +{ + guint context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT; + GOwnPtr<char> linkURI(0); + GOwnPtr<char> imageURI(0); + GOwnPtr<char> mediaURI(0); + WebKitDOMNode* node = 0; + + if (!result.absoluteLinkURL().isEmpty()) { + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK; + linkURI.set(g_strdup(result.absoluteLinkURL().string().utf8().data())); + } + + if (!result.absoluteImageURL().isEmpty()) { + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE; + imageURI.set(g_strdup(result.absoluteImageURL().string().utf8().data())); + } + + if (!result.absoluteMediaURL().isEmpty()) { + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA; + mediaURI.set(g_strdup(result.absoluteMediaURL().string().utf8().data())); + } + + if (result.isSelected()) + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION; + + if (result.isContentEditable()) + context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE; + + if (result.innerNonSharedNode()) + node = kit(result.innerNonSharedNode()); + + return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT, + "link-uri", linkURI.get(), + "image-uri", imageURI.get(), + "media-uri", mediaURI.get(), + "context", context, + "inner-node", node, + NULL)); +} + +} diff --git a/Source/WebKit/gtk/webkit/webkithittestresult.h b/Source/WebKit/gtk/webkit/webkithittestresult.h new file mode 100644 index 0000000..6caa84e --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkithittestresult.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkithittestresult_h +#define webkithittestresult_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_HIT_TEST_RESULT (webkit_hit_test_result_get_type()) +#define WEBKIT_HIT_TEST_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResult)) +#define WEBKIT_HIT_TEST_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResultClass)) +#define WEBKIT_IS_HIT_TEST_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_HIT_TEST_RESULT)) +#define WEBKIT_IS_HIT_TEST_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_HIT_TEST_RESULT)) +#define WEBKIT_HIT_TEST_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_HIT_TEST_RESULT, WebKitHitTestResultClass)) + +typedef struct _WebKitHitTestResultPrivate WebKitHitTestResultPrivate; + +struct _WebKitHitTestResult { + GObject parent_instance; + + /*< private >*/ + WebKitHitTestResultPrivate *priv; +}; + +struct _WebKitHitTestResultClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +/** + * WebKitHitTestResultContext + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT: anywhere in the document. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK: a hyperlink element. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE: an image element. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA: a video or audio element. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION: the area is selected by + * the user. + * @WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE: the area is + * editable by the user. + */ +typedef enum +{ + WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT = 1 << 1, + WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK = 1 << 2, + WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE = 1 << 3, + WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA = 1 << 4, + WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION = 1 << 5, + WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE = 1 << 6, +} WebKitHitTestResultContext; + +WEBKIT_API GType +webkit_hit_test_result_get_type (void); + +G_END_DECLS + +#endif + diff --git a/Source/WebKit/gtk/webkit/webkithittestresultprivate.h b/Source/WebKit/gtk/webkit/webkithittestresultprivate.h new file mode 100644 index 0000000..237ac27 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkithittestresultprivate.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkithittestresultprivate_h +#define webkithittestresultprivate_h + +#include "HitTestResult.h" +#include "webkithittestresult.h" + +namespace WebKit { + +WebKitHitTestResult* kit(const WebCore::HitTestResult&); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkiticondatabase.cpp b/Source/WebKit/gtk/webkit/webkiticondatabase.cpp new file mode 100644 index 0000000..397bd51 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkiticondatabase.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (C) 2011 Christian Dywan <christian@lanedo.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkiticondatabase.h" + +#include "DatabaseDetails.h" +#include "DatabaseTracker.h" +#include "FileSystem.h" +#include "IconDatabase.h" +#include "Image.h" +#include "IntSize.h" +#include "webkitglobalsprivate.h" +#include "webkitmarshal.h" +#include "webkitsecurityoriginprivate.h" +#include "webkitwebframe.h" +#include <glib/gi18n-lib.h> +#include <wtf/gobject/GOwnPtr.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitwebdatabase + * @short_description: A WebKit web application database + * + * #WebKitIconDatabase provides access to website icons, as shown + * in tab labels, window captions or bookmarks. All views share + * the same icon database. + * + * The icon database is enabled by default and stored in + * ~/.local/share/webkit/icondatabase, depending on XDG_DATA_HOME. + * + * WebKit will automatically look for available icons in link elements + * on opened pages as well as an existing favicon.ico and load the + * images found into the memory cache if possible. The signal "icon-loaded" + * will be emitted when any icon is found and loaded. + * Old Icons are automatically cleaned up after 4 days. + * + * webkit_icon_database_set_path() can be used to change the location + * of the database and also to disable it by passing %NULL. + * + * If WebKitWebSettings::enable-private-browsing is %TRUE new icons + * won't be added to the database on disk and no existing icons will + * be deleted from it. + * + * Since: 1.3.13 + */ + +using namespace WebKit; + +enum { + PROP_0, + + PROP_PATH, +}; + +enum { + ICON_LOADED, + + LAST_SIGNAL +}; + +static guint webkit_icon_database_signals[LAST_SIGNAL] = { 0, }; + +G_DEFINE_TYPE(WebKitIconDatabase, webkit_icon_database, G_TYPE_OBJECT); + +struct _WebKitIconDatabasePrivate { + GOwnPtr<gchar> path; +}; + +static void webkit_icon_database_finalize(GObject* object) +{ + // Call C++ destructors, the reverse of 'placement new syntax' + WEBKIT_ICON_DATABASE(object)->priv->~WebKitIconDatabasePrivate(); + + G_OBJECT_CLASS(webkit_icon_database_parent_class)->finalize(object); +} + +static void webkit_icon_database_dispose(GObject* object) +{ + G_OBJECT_CLASS(webkit_icon_database_parent_class)->dispose(object); +} + +static void webkit_icon_database_set_property(GObject* object, guint propId, const GValue* value, GParamSpec* pspec) +{ + WebKitIconDatabase* database = WEBKIT_ICON_DATABASE(object); + + switch (propId) { + case PROP_PATH: + webkit_icon_database_set_path(database, g_value_get_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static void webkit_icon_database_get_property(GObject* object, guint propId, GValue* value, GParamSpec* pspec) +{ + WebKitIconDatabase* database = WEBKIT_ICON_DATABASE(object); + + switch (propId) { + case PROP_PATH: + g_value_set_string(value, webkit_icon_database_get_path(database)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static void webkit_icon_database_class_init(WebKitIconDatabaseClass* klass) +{ + webkitInit(); + + GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); + gobjectClass->dispose = webkit_icon_database_dispose; + gobjectClass->finalize = webkit_icon_database_finalize; + gobjectClass->set_property = webkit_icon_database_set_property; + gobjectClass->get_property = webkit_icon_database_get_property; + + /** + * WebKitIconDatabase:path: + * + * The absolute path of the icon database folder. + * + * Since: 1.3.13 + */ + g_object_class_install_property(gobjectClass, PROP_PATH, + g_param_spec_string("path", + _("Path"), + _("The absolute path of the icon database folder"), + NULL, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitIconDatabase::icon-loaded: + * @database: the object on which the signal is emitted + * @frame: the frame containing the icon + * @frame_uri: the URI of the frame containing the icon + * + * This signal is emitted when a favicon is available for a page, + * or a child frame. + * See WebKitWebView::icon-loaded if you only need the favicon for + * the main frame of a particular #WebKitWebView. + * + * Since: 1.3.13 + */ + webkit_icon_database_signals[ICON_LOADED] = g_signal_new("icon-loaded", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + webkit_marshal_VOID__OBJECT_STRING, + G_TYPE_NONE, 2, + WEBKIT_TYPE_WEB_FRAME, + G_TYPE_STRING); + + g_type_class_add_private(klass, sizeof(WebKitIconDatabasePrivate)); +} + +static void webkit_icon_database_init(WebKitIconDatabase* database) +{ + database->priv = G_TYPE_INSTANCE_GET_PRIVATE(database, WEBKIT_TYPE_ICON_DATABASE, WebKitIconDatabasePrivate); + // 'placement new syntax', see webkitwebview.cpp + new (database->priv) WebKitIconDatabasePrivate(); +} + +/** + * webkit_icon_database_get_path: + * @database: a #WebKitIconDatabase + * + * Determines the absolute path to the database folder on disk. + * + * Returns: the absolute path of the database folder, or %NULL + * + * Since: 1.3.13 + **/ +G_CONST_RETURN gchar* webkit_icon_database_get_path(WebKitIconDatabase* database) +{ + g_return_val_if_fail(WEBKIT_IS_ICON_DATABASE(database), 0); + + return database->priv->path.get(); +} + +static void closeIconDatabaseOnExit() +{ + if (WebCore::iconDatabase().isEnabled()) { + WebCore::iconDatabase().setEnabled(false); + WebCore::iconDatabase().close(); + } +} + +/** + * webkit_icon_database_set_path: + * @database: a #WebKitIconDatabase + * @path: an absolute path to the icon database folder + * + * Specifies the absolute path to the database folder on disk. + * + * Passing %NULL or "" disables the icon database. + * + * Since: 1.3.13 + **/ +void webkit_icon_database_set_path(WebKitIconDatabase* database, const gchar* path) +{ + g_return_if_fail(WEBKIT_IS_ICON_DATABASE(database)); + + if (database->priv->path.get()) + WebCore::iconDatabase().close(); + + if (!(path && path[0])) { + database->priv->path.set(0); + WebCore::iconDatabase().setEnabled(false); + return; + } + + database->priv->path.set(g_strdup(path)); + + WebCore::iconDatabase().setEnabled(true); + WebCore::iconDatabase().open(WebCore::filenameToString(database->priv->path.get()), WebCore::IconDatabase::defaultDatabaseFilename()); + + static bool initialized = false; + if (!initialized) { + atexit(closeIconDatabaseOnExit); + initialized = true; + } +} + +/** + * webkit_icon_database_get_icon_uri: + * @database: a #WebKitIconDatabase + * @page_uri: URI of the page containing the icon + * + * Obtains the URI for the favicon for the given page URI. + * See also webkit_web_view_get_icon_uri(). + * + * Returns: a newly allocated URI for the favicon, or %NULL + * + * Since: 1.3.13 + **/ +gchar* webkit_icon_database_get_icon_uri(WebKitIconDatabase* database, const gchar* pageURI) +{ + g_return_val_if_fail(WEBKIT_IS_ICON_DATABASE(database), 0); + g_return_val_if_fail(pageURI, 0); + + String pageURL = String::fromUTF8(pageURI); + return g_strdup(WebCore::iconDatabase().synchronousIconURLForPageURL(pageURL).utf8().data()); +} + +/** + * webkit_icon_database_get_icon_pixbuf: + * @database: a #WebKitIconDatabase + * @page_uri: URI of the page containing the icon + * + * Obtains a #GdkPixbuf of the favicon for the given page URI, or + * a default icon if there is no icon for the given page. Use + * webkit_icon_database_get_icon_uri() if you need to distinguish these cases. + * Usually you want to connect to WebKitIconDatabase::icon-loaded and call this + * method in the callback. + * + * The pixbuf will have the largest size provided by the server and should + * be resized before it is displayed. + * See also webkit_web_view_get_icon_pixbuf(). + * + * Returns: (transfer full): a new reference to a #GdkPixbuf, or %NULL + * + * Since: 1.3.13 + **/ +GdkPixbuf* webkit_icon_database_get_icon_pixbuf(WebKitIconDatabase* database, const gchar* pageURI) +{ + g_return_val_if_fail(WEBKIT_IS_ICON_DATABASE(database), 0); + g_return_val_if_fail(pageURI, 0); + + String pageURL = String::fromUTF8(pageURI); + // The exact size we pass is irrelevant to the WebCore::iconDatabase code. + // We must pass something greater than 0, 0 to get a pixbuf. + WebCore::Image* icon = WebCore::iconDatabase().synchronousIconForPageURL(pageURL, WebCore::IntSize(16, 16)); + if (!icon) + return 0; + GdkPixbuf* pixbuf = icon->getGdkPixbuf(); + if (!pixbuf) + return 0; + return static_cast<GdkPixbuf*>(g_object_ref(pixbuf)); +} + +/** + * webkit_icon_database_clear(): + * @database: a #WebKitIconDatabase + * + * Clears all icons from the database. + * + * Since: 1.3.13 + **/ +void webkit_icon_database_clear(WebKitIconDatabase* database) +{ + g_return_if_fail(WEBKIT_IS_ICON_DATABASE(database)); + + WebCore::iconDatabase().removeAllIcons(); +} + diff --git a/Source/WebKit/gtk/webkit/webkiticondatabase.h b/Source/WebKit/gtk/webkit/webkiticondatabase.h new file mode 100644 index 0000000..7fe5acd --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkiticondatabase.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2011 Christian Dywan <christian@lanedo.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkiticondatabase_h +#define webkiticondatabase_h + +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <glib-object.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_ICON_DATABASE (webkit_icon_database_get_type()) +#define WEBKIT_ICON_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_ICON_DATABASE, WebKitIconDatabase)) +#define WEBKIT_ICON_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_ICON_DATABASE, WebKitIconDatabaseClass)) +#define WEBKIT_IS_ICON_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_ICON_DATABASE)) +#define WEBKIT_IS_ICON_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_ICON_DATABASE)) +#define WEBKIT_ICON_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_ICON_DATABASE, WebKitIconDatabaseClass)) + +typedef struct _WebKitIconDatabasePrivate WebKitIconDatabasePrivate; + +struct _WebKitIconDatabase { + GObject parent_instance; + + /*< private >*/ + WebKitIconDatabasePrivate* priv; +}; + +struct _WebKitIconDatabaseClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_icon_database_get_type (void); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_icon_database_get_path (WebKitIconDatabase* database); + +WEBKIT_API void +webkit_icon_database_set_path (WebKitIconDatabase* database, + const gchar* path); + +WEBKIT_API gchar* +webkit_icon_database_get_icon_uri (WebKitIconDatabase* database, + const gchar* page_uri); + +WEBKIT_API GdkPixbuf* +webkit_icon_database_get_icon_pixbuf (WebKitIconDatabase* database, + const gchar* page_uri); + +WEBKIT_API void +webkit_icon_database_clear (WebKitIconDatabase* database); + +G_END_DECLS + +#endif /* webkiticondatabase_h */ diff --git a/Source/WebKit/gtk/webkit/webkitnetworkrequest.cpp b/Source/WebKit/gtk/webkit/webkitnetworkrequest.cpp new file mode 100644 index 0000000..7005637 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkrequest.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2007, 2008 Holger Hans Peter Freyther + * Copyright (C) 2009 Gustavo Noronha Silva + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitnetworkrequest.h" + +#include "GRefPtr.h" +#include "ResourceRequest.h" +#include "webkitglobalsprivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitnetworkrequest + * @short_description: The target of a navigation request + * @see_also: #WebKitWebView::navigation-policy-decision-requested + * + * This class represents the network related aspects of a navigation + * request. It is used whenever WebKit wants to provide information + * about a request that will be sent, or has been sent. Inside it you + * can find the URI of the request, and, for valid URIs, a + * #SoupMessage object, which provides access to further information + * such as headers. + * + */ + +G_DEFINE_TYPE(WebKitNetworkRequest, webkit_network_request, G_TYPE_OBJECT); + +struct _WebKitNetworkRequestPrivate { + gchar* uri; + SoupMessage* message; +}; + +enum { + PROP_0, + + PROP_URI, + PROP_MESSAGE, +}; + +static void webkit_network_request_dispose(GObject* object) +{ + WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); + WebKitNetworkRequestPrivate* priv = request->priv; + + if (priv->message) { + g_object_unref(priv->message); + priv->message = NULL; + } + + G_OBJECT_CLASS(webkit_network_request_parent_class)->dispose(object); +} + +static void webkit_network_request_finalize(GObject* object) +{ + WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); + WebKitNetworkRequestPrivate* priv = request->priv; + + g_free(priv->uri); + + G_OBJECT_CLASS(webkit_network_request_parent_class)->finalize(object); +} + +static void webkit_network_request_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec) +{ + WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); + + switch(propertyID) { + case PROP_URI: + g_value_set_string(value, webkit_network_request_get_uri(request)); + break; + case PROP_MESSAGE: + g_value_set_object(value, webkit_network_request_get_message(request)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_network_request_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec) +{ + WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(object); + WebKitNetworkRequestPrivate* priv = request->priv; + + switch(propertyID) { + case PROP_URI: + webkit_network_request_set_uri(request, g_value_get_string(value)); + break; + case PROP_MESSAGE: + priv->message = SOUP_MESSAGE(g_value_dup_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_network_request_class_init(WebKitNetworkRequestClass* requestClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(requestClass); + + objectClass->dispose = webkit_network_request_dispose; + objectClass->finalize = webkit_network_request_finalize; + objectClass->get_property = webkit_network_request_get_property; + objectClass->set_property = webkit_network_request_set_property; + + webkitInit(); + + /** + * WebKitNetworkRequest:uri: + * + * The URI to which the request will be made. + * + * Since: 1.1.10 + */ + g_object_class_install_property(objectClass, PROP_URI, + g_param_spec_string("uri", + _("URI"), + _("The URI to which the request will be made."), + NULL, + (GParamFlags)(WEBKIT_PARAM_READWRITE))); + + /** + * WebKitNetworkRequest:message: + * + * The #SoupMessage that backs the request. + * + * Since: 1.1.10 + */ + g_object_class_install_property(objectClass, PROP_MESSAGE, + g_param_spec_object("message", + _("Message"), + _("The SoupMessage that backs the request."), + SOUP_TYPE_MESSAGE, + (GParamFlags)(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + + g_type_class_add_private(requestClass, sizeof(WebKitNetworkRequestPrivate)); +} + +static void webkit_network_request_init(WebKitNetworkRequest* request) +{ + WebKitNetworkRequestPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(request, WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequestPrivate); + request->priv = priv; +} + +/** + * webkit_network_request_new: + * @uri: an URI + * + * Creates a new #WebKitNetworkRequest initialized with an URI. + * + * Returns: a new #WebKitNetworkRequest, or %NULL if the URI is + * invalid. + */ +WebKitNetworkRequest* webkit_network_request_new(const gchar* uri) +{ + g_return_val_if_fail(uri, NULL); + + return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", uri, NULL)); +} + +/** + * webkit_network_request_set_uri: + * @request: a #WebKitNetworkRequest + * @uri: an URI + * + * Sets the URI held and used by the given request. When the request + * has an associated #SoupMessage, its URI will also be set by this + * call. + * + */ +void webkit_network_request_set_uri(WebKitNetworkRequest* request, const gchar* uri) +{ + g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request)); + g_return_if_fail(uri); + + WebKitNetworkRequestPrivate* priv = request->priv; + + if (priv->uri) + g_free(priv->uri); + priv->uri = g_strdup(uri); + + if (!priv->message) + return; + + SoupURI* soupURI = soup_uri_new(uri); + g_return_if_fail(soupURI); + + soup_message_set_uri(priv->message, soupURI); + soup_uri_free(soupURI); +} + +/** + * webkit_network_request_get_uri: + * @request: a #WebKitNetworkRequest + * + * Returns: the uri of the #WebKitNetworkRequest + * + * Since: 1.0.0 + */ +G_CONST_RETURN gchar* webkit_network_request_get_uri(WebKitNetworkRequest* request) +{ + g_return_val_if_fail(WEBKIT_IS_NETWORK_REQUEST(request), NULL); + + WebKitNetworkRequestPrivate* priv = request->priv; + + if (priv->uri) + return priv->uri; + + SoupURI* soupURI = soup_message_get_uri(priv->message); + priv->uri = soup_uri_to_string(soupURI, FALSE); + return priv->uri; +} + +/** + * webkit_network_request_get_message: + * @request: a #WebKitNetworkRequest + * + * Obtains the #SoupMessage held and used by the given request. Notice + * that modification of the SoupMessage of a request by signal + * handlers is only supported (as in, will only affect what is + * actually sent to the server) where explicitly documented. + * + * Returns: (transfer none): the #SoupMessage + * Since: 1.1.9 + */ +SoupMessage* webkit_network_request_get_message(WebKitNetworkRequest* request) +{ + g_return_val_if_fail(WEBKIT_IS_NETWORK_REQUEST(request), NULL); + + WebKitNetworkRequestPrivate* priv = request->priv; + + return priv->message; +} + +namespace WebKit { + +WebKitNetworkRequest* kitNew(const WebCore::ResourceRequest& resourceRequest) +{ + GRefPtr<SoupMessage> soupMessage(adoptGRef(resourceRequest.toSoupMessage())); + if (soupMessage) + return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", soupMessage.get(), NULL)); + + return WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", resourceRequest.url().string().utf8().data(), NULL)); +} + +WebCore::ResourceRequest core(WebKitNetworkRequest* request) +{ + SoupMessage* soupMessage = webkit_network_request_get_message(request); + if (soupMessage) + return WebCore::ResourceRequest(soupMessage); + + WebCore::KURL url = WebCore::KURL(WebCore::KURL(), String::fromUTF8(webkit_network_request_get_uri(request))); + return WebCore::ResourceRequest(url); +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitnetworkrequest.h b/Source/WebKit/gtk/webkit/webkitnetworkrequest.h new file mode 100644 index 0000000..825ca9e --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkrequest.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007 Holger Hans Peter Freyther + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitnetworkrequest_h +#define webkitnetworkrequest_h + +#include <glib-object.h> +#include <libsoup/soup.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_NETWORK_REQUEST (webkit_network_request_get_type()) +#define WEBKIT_NETWORK_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequest)) +#define WEBKIT_NETWORK_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequestClass)) +#define WEBKIT_IS_NETWORK_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_NETWORK_REQUEST)) +#define WEBKIT_IS_NETWORK_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_NETWORK_REQUEST)) +#define WEBKIT_NETWORK_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequestClass)) + +typedef struct _WebKitNetworkRequestPrivate WebKitNetworkRequestPrivate; + +struct _WebKitNetworkRequest { + GObject parent_instance; + + /*< private >*/ + WebKitNetworkRequestPrivate *priv; +}; + +struct _WebKitNetworkRequestClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_network_request_get_type (void); + +WEBKIT_API WebKitNetworkRequest * +webkit_network_request_new (const gchar *uri); + +WEBKIT_API void +webkit_network_request_set_uri (WebKitNetworkRequest *request, + const gchar* uri); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_network_request_get_uri (WebKitNetworkRequest *request); + +WEBKIT_API SoupMessage * +webkit_network_request_get_message(WebKitNetworkRequest* request); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitnetworkrequestprivate.h b/Source/WebKit/gtk/webkit/webkitnetworkrequestprivate.h new file mode 100644 index 0000000..84b4593 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkrequestprivate.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitnetworkrequestprivate_h +#define webkitnetworkrequestprivate_h + +namespace WebKit { + +WebCore::ResourceRequest core(WebKitNetworkRequest*); +WebKitNetworkRequest* kitNew(const WebCore::ResourceRequest&); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitnetworkresponse.cpp b/Source/WebKit/gtk/webkit/webkitnetworkresponse.cpp new file mode 100644 index 0000000..4b8661b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkresponse.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2007, 2008 Holger Hans Peter Freyther + * Copyright (C) 2009 Gustavo Noronha Silva + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitnetworkresponse.h" + +#include "GRefPtr.h" +#include "ResourceResponse.h" +#include "webkitglobalsprivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitnetworkresponse + * @short_description: the response given to a network request + * @see_also: #WebKitNetworkRequest + * + * This class represents the network related aspects of a navigation + * response. + * + * Since: 1.1.14 + */ + +G_DEFINE_TYPE(WebKitNetworkResponse, webkit_network_response, G_TYPE_OBJECT); + +struct _WebKitNetworkResponsePrivate { + gchar* uri; + SoupMessage* message; +}; + +#define WEBKIT_NETWORK_RESPONSE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_NETWORK_RESPONSE, WebKitNetworkResponsePrivate)) + +enum { + PROP_0, + + PROP_URI, + PROP_MESSAGE, +}; + +static void webkit_network_response_dispose(GObject* object) +{ + WebKitNetworkResponse* response = WEBKIT_NETWORK_RESPONSE(object); + WebKitNetworkResponsePrivate* priv = response->priv; + + if (priv->message) { + g_object_unref(priv->message); + priv->message = NULL; + } + + G_OBJECT_CLASS(webkit_network_response_parent_class)->dispose(object); +} + +static void webkit_network_response_finalize(GObject* object) +{ + WebKitNetworkResponse* response = WEBKIT_NETWORK_RESPONSE(object); + WebKitNetworkResponsePrivate* priv = response->priv; + + g_free(priv->uri); + + G_OBJECT_CLASS(webkit_network_response_parent_class)->finalize(object); +} + +static void webkit_network_response_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec) +{ + WebKitNetworkResponse* response = WEBKIT_NETWORK_RESPONSE(object); + + switch(propertyID) { + case PROP_URI: + g_value_set_string(value, webkit_network_response_get_uri(response)); + break; + case PROP_MESSAGE: + g_value_set_object(value, webkit_network_response_get_message(response)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_network_response_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec) +{ + WebKitNetworkResponse* response = WEBKIT_NETWORK_RESPONSE(object); + WebKitNetworkResponsePrivate* priv = response->priv; + + switch(propertyID) { + case PROP_URI: + webkit_network_response_set_uri(response, g_value_get_string(value)); + break; + case PROP_MESSAGE: + priv->message = SOUP_MESSAGE(g_value_dup_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec); + } +} + +static void webkit_network_response_class_init(WebKitNetworkResponseClass* responseClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(responseClass); + + objectClass->dispose = webkit_network_response_dispose; + objectClass->finalize = webkit_network_response_finalize; + objectClass->get_property = webkit_network_response_get_property; + objectClass->set_property = webkit_network_response_set_property; + + webkitInit(); + + /** + * WebKitNetworkResponse:uri: + * + * The URI to which the response will be made. + * + * Since: 1.1.14 + */ + g_object_class_install_property(objectClass, PROP_URI, + g_param_spec_string("uri", + _("URI"), + _("The URI to which the response will be made."), + NULL, + (GParamFlags)(WEBKIT_PARAM_READWRITE))); + + /** + * WebKitNetworkResponse:message: + * + * The #SoupMessage that backs the response. + * + * Since: 1.1.14 + */ + g_object_class_install_property(objectClass, PROP_MESSAGE, + g_param_spec_object("message", + _("Message"), + _("The SoupMessage that backs the response."), + SOUP_TYPE_MESSAGE, + (GParamFlags)(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + + g_type_class_add_private(responseClass, sizeof(WebKitNetworkResponsePrivate)); +} + +static void webkit_network_response_init(WebKitNetworkResponse* response) +{ + response->priv = WEBKIT_NETWORK_RESPONSE_GET_PRIVATE(response); +} + +/** + * webkit_network_response_new: + * @uri: an URI + * + * Creates a new #WebKitNetworkResponse initialized with an URI. + * + * Returns: a new #WebKitNetworkResponse, or %NULL if the URI is + * invalid. + * + * Since: 1.1.14 + */ +WebKitNetworkResponse* webkit_network_response_new(const gchar* uri) +{ + g_return_val_if_fail(uri, NULL); + + return WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "uri", uri, NULL)); +} + +/** + * webkit_network_response_set_uri: + * @response: a #WebKitNetworkResponse + * @uri: an URI + * + * Sets the URI held and used by the given response. When the response + * has an associated #SoupMessage, its URI will also be set by this + * call. + * + * Since: 1.1.14 + */ +void webkit_network_response_set_uri(WebKitNetworkResponse* response, const gchar* uri) +{ + g_return_if_fail(WEBKIT_IS_NETWORK_RESPONSE(response)); + g_return_if_fail(uri); + + WebKitNetworkResponsePrivate* priv = response->priv; + + if (priv->uri) + g_free(priv->uri); + priv->uri = g_strdup(uri); + + if (!priv->message) + return; + + SoupURI* soupURI = soup_uri_new(uri); + g_return_if_fail(soupURI); + + soup_message_set_uri(priv->message, soupURI); + soup_uri_free(soupURI); +} + +/** + * webkit_network_response_get_uri: + * @response: a #WebKitNetworkResponse + * + * Returns: the uri of the #WebKitNetworkResponse + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_network_response_get_uri(WebKitNetworkResponse* response) +{ + g_return_val_if_fail(WEBKIT_IS_NETWORK_RESPONSE(response), NULL); + + WebKitNetworkResponsePrivate* priv = response->priv; + + if (priv->uri) + return priv->uri; + + SoupURI* soupURI = soup_message_get_uri(priv->message); + priv->uri = soup_uri_to_string(soupURI, FALSE); + return priv->uri; +} + +/** + * webkit_network_response_get_message: + * @response: a #WebKitNetworkResponse + * + * Obtains the #SoupMessage that represents the given response. Notice + * that only the response side of the HTTP conversation is + * represented. + * + * Returns: (transfer none): the #SoupMessage + * Since: 1.1.14 + */ +SoupMessage* webkit_network_response_get_message(WebKitNetworkResponse* response) +{ + g_return_val_if_fail(WEBKIT_IS_NETWORK_RESPONSE(response), NULL); + + WebKitNetworkResponsePrivate* priv = response->priv; + + return priv->message; +} + +namespace WebKit { + +WebCore::ResourceResponse core(WebKitNetworkResponse* response) +{ + SoupMessage* soupMessage = webkit_network_response_get_message(response); + if (soupMessage) + return WebCore::ResourceResponse(soupMessage); + + return WebCore::ResourceResponse(); +} + +WebKitNetworkResponse* kitNew(const WebCore::ResourceResponse& resourceResponse) +{ + GRefPtr<SoupMessage> soupMessage(adoptGRef(resourceResponse.toSoupMessage())); + if (soupMessage) + return WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", soupMessage.get(), NULL)); + + return WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "uri", resourceResponse.url().string().utf8().data(), NULL)); +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitnetworkresponse.h b/Source/WebKit/gtk/webkit/webkitnetworkresponse.h new file mode 100644 index 0000000..a00308d --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkresponse.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitnewtorkresponse_h +#define webkitnewtorkresponse_h + +#include <glib-object.h> +#include <libsoup/soup.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_NETWORK_RESPONSE (webkit_network_response_get_type()) +#define WEBKIT_NETWORK_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_NETWORK_RESPONSE, WebKitNetworkResponse)) +#define WEBKIT_NETWORK_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_NETWORK_RESPONSE, WebKitNetworkResponseClass)) +#define WEBKIT_IS_NETWORK_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_NETWORK_RESPONSE)) +#define WEBKIT_IS_NETWORK_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_NETWORK_RESPONSE)) +#define WEBKIT_NETWORK_RESPONSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_NETWORK_RESPONSE, WebKitNetworkResponseClass)) + +typedef struct _WebKitNetworkResponsePrivate WebKitNetworkResponsePrivate; + +struct _WebKitNetworkResponse { + GObject parent_instance; + + /*< private >*/ + WebKitNetworkResponsePrivate *priv; +}; + +struct _WebKitNetworkResponseClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_network_response_get_type (void); + +WEBKIT_API WebKitNetworkResponse * +webkit_network_response_new (const gchar *uri); + +WEBKIT_API void +webkit_network_response_set_uri (WebKitNetworkResponse *response, + const gchar* uri); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_network_response_get_uri (WebKitNetworkResponse *response); + +WEBKIT_API SoupMessage * +webkit_network_response_get_message(WebKitNetworkResponse* response); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitnetworkresponseprivate.h b/Source/WebKit/gtk/webkit/webkitnetworkresponseprivate.h new file mode 100644 index 0000000..ab38a50 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitnetworkresponseprivate.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitnetworkresponseprivate_h +#define webkitnetworkresponseprivate_h + +#include "ResourceResponse.h" + +namespace WebKit { + +WebCore::ResourceResponse core(WebKitNetworkResponse*); +WebKitNetworkResponse* kitNew(const WebCore::ResourceResponse&); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitsecurityorigin.cpp b/Source/WebKit/gtk/webkit/webkitsecurityorigin.cpp new file mode 100644 index 0000000..5f9afae --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitsecurityorigin.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2009 Martin Robinson, Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitsecurityorigin.h" + +#include "DatabaseTracker.h" +#include "PlatformString.h" +#include "webkitglobalsprivate.h" +#include "webkitsecurityoriginprivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitsecurityorigin + * @short_description: A security boundary for web sites + * + * #WebKitSecurityOrigin is a representation of a security domain defined + * by web sites. An origin consists of a host name, a protocol, and a port + * number. Web sites with the same security origin can access each other's + * resources for client-side scripting or database access. + * + * Use #webkit_web_frame_get_security_origin to get the security origin of a + * #WebKitWebFrame. + * + * Database quotas and usages are also defined per security origin. The + * cumulative disk usage of an origin's databases may be retrieved with + * #webkit_security_origin_get_web_database_usage. An origin's quota can be + * adjusted with #webkit_security_origin_set_web_database_quota. + */ + +using namespace WebKit; + +enum { + PROP_0, + + PROP_PROTOCOL, + PROP_HOST, + PROP_PORT, + PROP_DATABASE_USAGE, + PROP_DATABASE_QUOTA +}; + +G_DEFINE_TYPE(WebKitSecurityOrigin, webkit_security_origin, G_TYPE_OBJECT) + +static void webkit_security_origin_finalize(GObject* object) +{ + WebKitSecurityOrigin* securityOrigin = WEBKIT_SECURITY_ORIGIN(object); + WebKitSecurityOriginPrivate* priv = securityOrigin->priv; + + g_free(priv->protocol); + g_free(priv->host); + + G_OBJECT_CLASS(webkit_security_origin_parent_class)->finalize(object); +} + +static void webkit_security_origin_dispose(GObject* object) +{ + WebKitSecurityOrigin* securityOrigin = WEBKIT_SECURITY_ORIGIN(object); + WebKitSecurityOriginPrivate* priv = securityOrigin->priv; + + if (!priv->disposed) { + priv->coreOrigin->deref(); + g_hash_table_destroy(priv->webDatabases); + priv->disposed = true; + } + + G_OBJECT_CLASS(webkit_security_origin_parent_class)->dispose(object); +} + +static void webkit_security_origin_set_property(GObject* object, guint propId, const GValue* value, GParamSpec* pspec) +{ + WebKitSecurityOrigin* securityOrigin = WEBKIT_SECURITY_ORIGIN(object); + + switch (propId) { + case PROP_DATABASE_QUOTA: + webkit_security_origin_set_web_database_quota(securityOrigin, g_value_get_uint64(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static void webkit_security_origin_get_property(GObject* object, guint propId, GValue* value, GParamSpec* pspec) +{ + WebKitSecurityOrigin* securityOrigin = WEBKIT_SECURITY_ORIGIN(object); + + switch (propId) { + case PROP_PROTOCOL: + g_value_set_string(value, webkit_security_origin_get_protocol(securityOrigin)); + break; + case PROP_HOST: + g_value_set_string(value, webkit_security_origin_get_host(securityOrigin)); + break; + case PROP_PORT: + g_value_set_uint(value, webkit_security_origin_get_port(securityOrigin)); + break; + case PROP_DATABASE_USAGE: + g_value_set_uint64(value, webkit_security_origin_get_web_database_usage(securityOrigin)); + break; + case PROP_DATABASE_QUOTA: + g_value_set_uint64(value, webkit_security_origin_get_web_database_quota(securityOrigin)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static GHashTable* webkit_security_origins() +{ + static GHashTable* securityOrigins = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref); + return securityOrigins; +} + +static void webkit_security_origin_class_init(WebKitSecurityOriginClass* klass) +{ + GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); + gobjectClass->dispose = webkit_security_origin_dispose; + gobjectClass->finalize = webkit_security_origin_finalize; + gobjectClass->set_property = webkit_security_origin_set_property; + gobjectClass->get_property = webkit_security_origin_get_property; + + /** + * WebKitSecurityOrigin:protocol: + * + * The protocol of the security origin. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_PROTOCOL, + g_param_spec_string("protocol", + _("Protocol"), + _("The protocol of the security origin"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitSecurityOrigin:host: + * + * The host of the security origin. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_HOST, + g_param_spec_string("host", + _("Host"), + _("The host of the security origin"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitSecurityOrigin:port: + * + * The port of the security origin. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_PORT, + g_param_spec_uint("port", + _("Port"), + _("The port of the security origin"), + 0, G_MAXUSHORT, 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitSecurityOrigin:web-database-usage: + * + * The cumulative size of all web databases in the security origin in bytes. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_DATABASE_USAGE, + g_param_spec_uint64("web-database-usage", + _("Web Database Usage"), + _("The cumulative size of all web databases in the security origin"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + /** + * WebKitSecurityOrigin:web-database-quota: + * + * The web database qouta of the security origin in bytes. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_DATABASE_QUOTA, + g_param_spec_uint64("web-database-quota", + _("Web Database Quota"), + _("The web database quota of the security origin in bytes"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READWRITE)); + + g_type_class_add_private(klass, sizeof(WebKitSecurityOriginPrivate)); +} + +static void webkit_security_origin_init(WebKitSecurityOrigin* securityOrigin) +{ + WebKitSecurityOriginPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(securityOrigin, WEBKIT_TYPE_SECURITY_ORIGIN, WebKitSecurityOriginPrivate); + priv->webDatabases = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); + securityOrigin->priv = priv; +} + +/** + * webkit_security_origin_get_protocol: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns the protocol for the security origin. + * + * Returns: the protocol for the security origin + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_security_origin_get_protocol(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), NULL); + + WebKitSecurityOriginPrivate* priv = securityOrigin->priv; + WTF::String protocol = priv->coreOrigin->protocol(); + + if (!priv->protocol) + priv->protocol = g_strdup(protocol.utf8().data()); + + return priv->protocol; +} + +/** + * webkit_security_origin_get_host: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns the hostname for the security origin. + * + * Returns: the hostname for the security origin + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_security_origin_get_host(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), NULL); + + WebKitSecurityOriginPrivate* priv = securityOrigin->priv; + WTF::String host = priv->coreOrigin->host(); + + if (!priv->host) + priv->host = g_strdup(host.utf8().data()); + + return priv->host; +} + +/** + * webkit_security_origin_get_port: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns the port for the security origin. + * + * Returns: the port for the security origin + * + * Since: 1.1.14 + **/ +guint webkit_security_origin_get_port(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), 0); + + WebCore::SecurityOrigin* coreOrigin = core(securityOrigin); + return coreOrigin->port(); +} + +/** + * webkit_security_origin_get_web_database_usage: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns the cumulative size of all Web Database database's in the origin + * in bytes. + * + * Returns: the cumulative size of all databases + * + * Since: 1.1.14 + **/ +guint64 webkit_security_origin_get_web_database_usage(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), 0); + +#if ENABLE(DATABASE) + WebCore::SecurityOrigin* coreOrigin = core(securityOrigin); + return WebCore::DatabaseTracker::tracker().usageForOrigin(coreOrigin); +#else + return 0; +#endif +} + +/** + * webkit_security_origin_get_web_database_quota: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns the quota for Web Database storage of the security origin + * in bytes. + * + * Returns: the Web Database quota + * + * Since: 1.1.14 + **/ +guint64 webkit_security_origin_get_web_database_quota(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), 0); + +#if ENABLE(DATABASE) + WebCore::SecurityOrigin* coreOrigin = core(securityOrigin); + return WebCore::DatabaseTracker::tracker().quotaForOrigin(coreOrigin); +#else + return 0; +#endif +} + +/** + * webkit_security_origin_set_web_database_quota: + * @securityOrigin: a #WebKitSecurityOrigin + * @quota: a new Web Database quota in bytes + * + * Adjust the quota for Web Database storage of the security origin + * + * Since: 1.1.14 + **/ +void webkit_security_origin_set_web_database_quota(WebKitSecurityOrigin* securityOrigin, guint64 quota) +{ + g_return_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin)); + +#if ENABLE(DATABASE) + WebCore::SecurityOrigin* coreOrigin = core(securityOrigin); + WebCore::DatabaseTracker::tracker().setQuota(coreOrigin, quota); +#endif +} + +/** + * webkit_security_origin_get_all_web_databases: + * @securityOrigin: a #WebKitSecurityOrigin + * + * Returns a list of all Web Databases in the security origin. + * + * Returns: (transfer container) (element-type WebKitWebDatabase): a + * #GList of databases in the security origin. + * + * Since: 1.1.14 + **/ +GList* webkit_security_origin_get_all_web_databases(WebKitSecurityOrigin* securityOrigin) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), NULL); + GList* databases = NULL; + +#if ENABLE(DATABASE) + WebCore::SecurityOrigin* coreOrigin = core(securityOrigin); + Vector<WTF::String> databaseNames; + + if (!WebCore::DatabaseTracker::tracker().databaseNamesForOrigin(coreOrigin, databaseNames)) + return NULL; + + for (unsigned i = 0; i < databaseNames.size(); ++i) { + WebKitWebDatabase* database = webkit_security_origin_get_web_database(securityOrigin, databaseNames[i].utf8().data()); + databases = g_list_append(databases, database); + } +#endif + + return databases; +} + +WebKitWebDatabase* webkit_security_origin_get_web_database(WebKitSecurityOrigin* securityOrigin, const gchar* databaseName) +{ + g_return_val_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin), NULL); + + WebKitSecurityOriginPrivate* priv = securityOrigin->priv; + GHashTable* databaseHash = priv->webDatabases; + WebKitWebDatabase* database = (WebKitWebDatabase*) g_hash_table_lookup(databaseHash, databaseName); + + if (!database) { + database = WEBKIT_WEB_DATABASE(g_object_new(WEBKIT_TYPE_WEB_DATABASE, + "security-origin", securityOrigin, + "name", databaseName, + NULL)); + g_hash_table_insert(databaseHash, g_strdup(databaseName), database); + } + + return database; +} + +namespace WebKit { + +WebCore::SecurityOrigin* core(WebKitSecurityOrigin* securityOrigin) +{ + ASSERT(securityOrigin); + + return securityOrigin->priv->coreOrigin.get(); +} + +WebKitSecurityOrigin* kit(WebCore::SecurityOrigin* coreOrigin) +{ + ASSERT(coreOrigin); + + GHashTable* table = webkit_security_origins(); + WebKitSecurityOrigin* origin = (WebKitSecurityOrigin*) g_hash_table_lookup(table, coreOrigin); + + if (!origin) { + origin = WEBKIT_SECURITY_ORIGIN(g_object_new(WEBKIT_TYPE_SECURITY_ORIGIN, NULL)); + origin->priv->coreOrigin = coreOrigin; + g_hash_table_insert(table, coreOrigin, origin); + } + + return origin; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitsecurityorigin.h b/Source/WebKit/gtk/webkit/webkitsecurityorigin.h new file mode 100644 index 0000000..24ebe06 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitsecurityorigin.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2009 Martin Robinson, Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitsecurityorigin_h +#define webkitsecurityorigin_h + +#include "webkitwebdatabase.h" + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_SECURITY_ORIGIN (webkit_security_origin_get_type()) +#define WEBKIT_SECURITY_ORIGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_SECURITY_ORIGIN, WebKitSecurityOrigin)) +#define WEBKIT_SECURITY_ORIGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_SECURITY_ORIGIN, WebKitSecurityOriginClass)) +#define WEBKIT_IS_SECURITY_ORIGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_SECURITY_ORIGIN)) +#define WEBKIT_IS_SECURITY_ORIGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_SECURITY_ORIGIN)) +#define WEBKIT_SECURITY_ORIGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_SECURITY_ORIGIN, WebKitSecurityOriginClass)) + +typedef struct _WebKitSecurityOriginPrivate WebKitSecurityOriginPrivate; + +struct _WebKitSecurityOrigin { + GObject parent_instance; + + /*< private >*/ + WebKitSecurityOriginPrivate* priv; +}; + +struct _WebKitSecurityOriginClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_security_origin_get_type (void); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_security_origin_get_protocol (WebKitSecurityOrigin* securityOrigin); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_security_origin_get_host (WebKitSecurityOrigin* securityOrigin); + +WEBKIT_API guint +webkit_security_origin_get_port (WebKitSecurityOrigin* securityOrigin); + +WEBKIT_API guint64 +webkit_security_origin_get_web_database_usage (WebKitSecurityOrigin* securityOrigin); + +WEBKIT_API guint64 +webkit_security_origin_get_web_database_quota (WebKitSecurityOrigin* securityOrigin); + +WEBKIT_API void +webkit_security_origin_set_web_database_quota (WebKitSecurityOrigin* securityOrigin, guint64 quota); + +WEBKIT_API GList * +webkit_security_origin_get_all_web_databases (WebKitSecurityOrigin* securityOrigin); + +G_END_DECLS + +#endif /* __WEBKIT_SECURITY_ORIGIN_H__ */ diff --git a/Source/WebKit/gtk/webkit/webkitsecurityoriginprivate.h b/Source/WebKit/gtk/webkit/webkitsecurityoriginprivate.h new file mode 100644 index 0000000..5a4a87b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitsecurityoriginprivate.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitsecurityoriginprivate_h +#define webkitnavigationactionprivate_h + +#include "SecurityOrigin.h" +#include "webkitsecurityorigin.h" + +namespace WebKit { + +WebKitSecurityOrigin* kit(WebCore::SecurityOrigin*); +WebCore::SecurityOrigin* core(WebKitSecurityOrigin*); + +} + +extern "C" { + +struct _WebKitSecurityOriginPrivate { + RefPtr<WebCore::SecurityOrigin> coreOrigin; + gchar* protocol; + gchar* host; + GHashTable* webDatabases; + + gboolean disposed; +}; + +WEBKIT_API WebKitWebDatabase* webkit_security_origin_get_web_database(WebKitSecurityOrigin*, const char*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c b/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c new file mode 100644 index 0000000..c407e6a --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c @@ -0,0 +1,372 @@ +/* + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#define LIBSOUP_I_HAVE_READ_BUG_594377_AND_KNOW_SOUP_PASSWORD_MANAGER_MIGHT_GO_AWAY + +#include <glib/gi18n-lib.h> +#include <gtk/gtk.h> +#include <libsoup/soup.h> + +#include "GtkVersioning.h" +#include "webkitmarshal.h" +#include "webkitsoupauthdialog.h" + +/** + * SECTION:webkitsoupauthdialog + * @short_description: A #SoupSessionFeature to provide a simple + * authentication dialog for HTTP basic auth support. + * + * #WebKitSoupAuthDialog is a #SoupSessionFeature that you can attach to your + * #SoupSession to provide a simple authentication dialog while + * handling HTTP basic auth. It is built as a simple C-only module + * to ease reuse. + */ + +static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface* feature_interface, gpointer interface_data); +static void attach(SoupSessionFeature* manager, SoupSession* session); +static void detach(SoupSessionFeature* manager, SoupSession* session); + +enum { + CURRENT_TOPLEVEL, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE_WITH_CODE(WebKitSoupAuthDialog, webkit_soup_auth_dialog, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE, + webkit_soup_auth_dialog_session_feature_init)) + +static void webkit_soup_auth_dialog_class_init(WebKitSoupAuthDialogClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + /** + * WebKitSoupAuthDialog::current-toplevel: + * @authDialog: the object on which the signal is emitted + * @message: the #SoupMessage being used in the authentication process + * + * This signal is emitted by the @authDialog when it needs to know + * the current toplevel widget in order to correctly set the + * transiency for the authentication dialog. + * + * Return value: (transfer none): the current toplevel #GtkWidget or %NULL if there's none + * + * Since: 1.1.1 + */ + signals[CURRENT_TOPLEVEL] = + g_signal_new("current-toplevel", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitSoupAuthDialogClass, current_toplevel), + NULL, NULL, + webkit_marshal_OBJECT__OBJECT, + GTK_TYPE_WIDGET, 1, + SOUP_TYPE_MESSAGE); +} + +static void webkit_soup_auth_dialog_init(WebKitSoupAuthDialog* instance) +{ +} + +static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface *feature_interface, + gpointer interface_data) +{ + feature_interface->attach = attach; + feature_interface->detach = detach; +} + +typedef struct _WebKitAuthData { + SoupMessage* msg; + SoupAuth* auth; + SoupSession* session; + SoupSessionFeature* manager; + GtkWidget* loginEntry; + GtkWidget* passwordEntry; + GtkWidget* checkButton; + char *username; + char *password; +} WebKitAuthData; + +static void free_authData(WebKitAuthData* authData) +{ + g_object_unref(authData->msg); + g_free(authData->username); + g_free(authData->password); + g_slice_free(WebKitAuthData, authData); +} + +#ifdef SOUP_TYPE_PASSWORD_MANAGER +static void save_password_callback(SoupMessage* msg, WebKitAuthData* authData) +{ + /* Anything but 401 and 5xx means the password was accepted */ + if (msg->status_code != 401 && msg->status_code < 500) + soup_auth_save_password(authData->auth, authData->username, authData->password); + + /* Disconnect the callback. If the authentication succeeded we are + * done, and if it failed we'll create a new authData and we'll + * connect to 'got-headers' again in response_callback */ + g_signal_handlers_disconnect_by_func(msg, save_password_callback, authData); + + free_authData(authData); +} +#endif + +static void response_callback(GtkDialog* dialog, gint response_id, WebKitAuthData* authData) +{ + gboolean freeAuthData = TRUE; + + if (response_id == GTK_RESPONSE_OK) { + authData->username = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->loginEntry))); + authData->password = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->passwordEntry))); + + soup_auth_authenticate(authData->auth, authData->username, authData->password); + +#ifdef SOUP_TYPE_PASSWORD_MANAGER + if (authData->checkButton && + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(authData->checkButton))) { + g_signal_connect(authData->msg, "got-headers", G_CALLBACK(save_password_callback), authData); + freeAuthData = FALSE; + } +#endif + } + + soup_session_unpause_message(authData->session, authData->msg); + if (freeAuthData) + free_authData(authData); + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + +static GtkWidget * +table_add_entry(GtkWidget* table, + int row, + const char* label_text, + const char* value, + gpointer user_data) +{ + GtkWidget* entry; + GtkWidget* label; + + label = gtk_label_new(label_text); + gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); + + entry = gtk_entry_new(); + gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); + + if (value) + gtk_entry_set_text(GTK_ENTRY(entry), value); + + gtk_table_attach(GTK_TABLE(table), label, + 0, 1, row, row + 1, + GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_table_attach_defaults(GTK_TABLE(table), entry, + 1, 2, row, row + 1); + + return entry; +} + +static gboolean session_can_save_passwords(SoupSession* session) +{ +#ifdef SOUP_TYPE_PASSWORD_MANAGER + return soup_session_get_feature(session, SOUP_TYPE_PASSWORD_MANAGER) != NULL; +#else + return FALSE; +#endif +} + +static void show_auth_dialog(WebKitAuthData* authData, const char* login, const char* password) +{ + GtkWidget* toplevel; + GtkWidget* widget; + GtkDialog* dialog; + GtkWindow* window; + GtkWidget* entryContainer; + GtkWidget* hbox; + GtkWidget* mainVBox; + GtkWidget* vbox; + GtkWidget* icon; + GtkWidget* table; + GtkWidget* serverMessageDescriptionLabel; + GtkWidget* serverMessageLabel; + GtkWidget* descriptionLabel; + char* description; + const char* realm; + gboolean hasRealm; + SoupURI* uri; + GtkWidget* rememberBox; + GtkWidget* checkButton; + + /* From GTK+ gtkmountoperation.c, modified and simplified. LGPL 2 license */ + + widget = gtk_dialog_new(); + window = GTK_WINDOW(widget); + dialog = GTK_DIALOG(widget); + + gtk_dialog_add_buttons(dialog, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + /* Set the dialog up with HIG properties */ + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); + gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(dialog)), 2); /* 2 * 5 + 2 = 12 */ + gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_action_area(dialog)), 5); + gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_action_area(dialog)), 6); + + gtk_window_set_resizable(window, FALSE); + gtk_window_set_title(window, ""); + gtk_window_set_icon_name(window, GTK_STOCK_DIALOG_AUTHENTICATION); + + gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK); + + /* Get the current toplevel */ + g_signal_emit(authData->manager, signals[CURRENT_TOPLEVEL], 0, authData->msg, &toplevel); + + if (toplevel) + gtk_window_set_transient_for(window, GTK_WINDOW(toplevel)); + + /* Build contents */ + hbox = gtk_hbox_new(FALSE, 12); + gtk_container_set_border_width(GTK_CONTAINER(hbox), 5); + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(dialog)), hbox, TRUE, TRUE, 0); + + icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, + GTK_ICON_SIZE_DIALOG); + + gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0); + gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); + + mainVBox = gtk_vbox_new(FALSE, 18); + gtk_box_pack_start(GTK_BOX(hbox), mainVBox, TRUE, TRUE, 0); + + uri = soup_message_get_uri(authData->msg); + description = g_strdup_printf(_("A username and password are being requested by the site %s"), uri->host); + descriptionLabel = gtk_label_new(description); + g_free(description); + gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0.0, 0.5); + gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE); + gtk_box_pack_start(GTK_BOX(mainVBox), GTK_WIDGET(descriptionLabel), + FALSE, FALSE, 0); + + vbox = gtk_vbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(mainVBox), vbox, FALSE, FALSE, 0); + + /* The table that holds the entries */ + entryContainer = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); + + gtk_alignment_set_padding(GTK_ALIGNMENT(entryContainer), + 0, 0, 0, 0); + + gtk_box_pack_start(GTK_BOX(vbox), entryContainer, + FALSE, FALSE, 0); + + realm = soup_auth_get_realm(authData->auth); + // Checking that realm is not an empty string + hasRealm = (realm && (strlen(realm) > 0)); + + table = gtk_table_new(hasRealm ? 3 : 2, 2, FALSE); + gtk_table_set_col_spacings(GTK_TABLE(table), 12); + gtk_table_set_row_spacings(GTK_TABLE(table), 6); + gtk_container_add(GTK_CONTAINER(entryContainer), table); + + if (hasRealm) { + serverMessageDescriptionLabel = gtk_label_new(_("Server message:")); + serverMessageLabel = gtk_label_new(realm); + gtk_misc_set_alignment(GTK_MISC(serverMessageDescriptionLabel), 0.0, 0.5); + gtk_label_set_line_wrap(GTK_LABEL(serverMessageDescriptionLabel), TRUE); + gtk_misc_set_alignment(GTK_MISC(serverMessageLabel), 0.0, 0.5); + gtk_label_set_line_wrap(GTK_LABEL(serverMessageLabel), TRUE); + + gtk_table_attach_defaults(GTK_TABLE(table), serverMessageDescriptionLabel, + 0, 1, 0, 1); + gtk_table_attach_defaults(GTK_TABLE(table), serverMessageLabel, + 1, 2, 0, 1); + } + + authData->loginEntry = table_add_entry(table, hasRealm ? 1 : 0, _("Username:"), + login, NULL); + authData->passwordEntry = table_add_entry(table, hasRealm ? 2 : 1, _("Password:"), + password, NULL); + + gtk_entry_set_visibility(GTK_ENTRY(authData->passwordEntry), FALSE); + + if (session_can_save_passwords(authData->session)) { + rememberBox = gtk_vbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(vbox), rememberBox, + FALSE, FALSE, 0); + checkButton = gtk_check_button_new_with_mnemonic(_("_Remember password")); + if (login && password) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkButton), TRUE); + gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(checkButton))), TRUE); + gtk_box_pack_start(GTK_BOX(rememberBox), checkButton, FALSE, FALSE, 0); + authData->checkButton = checkButton; + } + + g_signal_connect(dialog, "response", G_CALLBACK(response_callback), authData); + gtk_widget_show_all(widget); +} + +static void session_authenticate(SoupSession* session, SoupMessage* msg, SoupAuth* auth, gboolean retrying, gpointer user_data) +{ + SoupURI* uri; + WebKitAuthData* authData; + SoupSessionFeature* manager = (SoupSessionFeature*)user_data; +#ifdef SOUP_TYPE_PASSWORD_MANAGER + GSList* users; +#endif + const char *login, *password; + + soup_session_pause_message(session, msg); + /* We need to make sure the message sticks around when pausing it */ + g_object_ref(msg); + + uri = soup_message_get_uri(msg); + authData = g_slice_new0(WebKitAuthData); + authData->msg = msg; + authData->auth = auth; + authData->session = session; + authData->manager = manager; + + login = password = NULL; + +#ifdef SOUP_TYPE_PASSWORD_MANAGER + users = soup_auth_get_saved_users(auth); + if (users) { + login = users->data; + password = soup_auth_get_saved_password(auth, login); + g_slist_free(users); + } +#endif + + show_auth_dialog(authData, login, password); +} + +static void attach(SoupSessionFeature* manager, SoupSession* session) +{ + g_signal_connect(session, "authenticate", G_CALLBACK(session_authenticate), manager); +} + +static void detach(SoupSessionFeature* manager, SoupSession* session) +{ + g_signal_handlers_disconnect_by_func(session, session_authenticate, manager); +} + + diff --git a/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h b/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h new file mode 100644 index 0000000..08b7c9f --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitsoupauthdialog_h +#define webkitsoupauthdialog_h + +#include <gtk/gtk.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_SOUP_AUTH_DIALOG (webkit_soup_auth_dialog_get_type ()) +#define WEBKIT_SOUP_AUTH_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), WEBKIT_TYPE_SOUP_AUTH_DIALOG, WebKitSoupAuthDialog)) +#define WEBKIT_SOUP_AUTH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WEBKIT_TYPE_SOUP_AUTH_DIALOG, WebKitSoupAuthDialog)) +#define WEBKIT_IS_SOUP_AUTH_DIALOG(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), WEBKIT_TYPE_SOUP_AUTH_DIALOG)) +#define WEBKIT_IS_SOUP_AUTH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WEBKIT_TYPE_SOUP_AUTH_DIALOG)) +#define WEBKIT_SOUP_AUTH_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WEBKIT_TYPE_SOUP_AUTH_DIALOG, WebKitSoupAuthDialog)) + +typedef struct { + GObject parent_instance; +} WebKitSoupAuthDialog; + +typedef struct { + GObjectClass parent_class; + + GtkWidget* (*current_toplevel) (WebKitSoupAuthDialog* authDialog, SoupMessage* message); +} WebKitSoupAuthDialogClass; + +WEBKIT_API GType +webkit_soup_auth_dialog_get_type (void); + +G_END_DECLS + +#endif /* webkitsoupauthdialog_h */ diff --git a/Source/WebKit/gtk/webkit/webkitversion.cpp b/Source/WebKit/gtk/webkit/webkitversion.cpp new file mode 100644 index 0000000..62750f5 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitversion.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2008 Christian Dywan <christian@imendio.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitversion.h" + +/** + * webkit_major_version: + * + * The major version number of the WebKit that is linked against. + * + * Return value: The major version + * + * Since: 1.0.1 + */ +guint webkit_major_version() +{ + return WEBKIT_MAJOR_VERSION; +} + +/** + * webkit_minor_version: + * + * The minor version number of the WebKit that is linked against. + * + * Return value: The minor version + * + * Since: 1.0.1 + */ +guint webkit_minor_version() +{ + return WEBKIT_MINOR_VERSION; +} + +/** + * webkit_micro_version: + * + * The micro version number of the WebKit that is linked against. + * + * Return value: The micro version + * + * Since: 1.0.1 + */ +guint webkit_micro_version() +{ + return WEBKIT_MICRO_VERSION; +} diff --git a/Source/WebKit/gtk/webkit/webkitversion.h.in b/Source/WebKit/gtk/webkit/webkitversion.h.in new file mode 100644 index 0000000..ce6b569 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitversion.h.in @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Christian Dywan <christian@imendio.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitversion_h +#define webkitversion_h + +#include <glib.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_MAJOR_VERSION (@WEBKIT_MAJOR_VERSION@) +#define WEBKIT_MINOR_VERSION (@WEBKIT_MINOR_VERSION@) +#define WEBKIT_MICRO_VERSION (@WEBKIT_MICRO_VERSION@) +#define WEBKIT_USER_AGENT_MAJOR_VERSION (@WEBKIT_USER_AGENT_MAJOR_VERSION@) +#define WEBKIT_USER_AGENT_MINOR_VERSION (@WEBKIT_USER_AGENT_MINOR_VERSION@) +#define WEBKITGTK_API_VERSION (@WEBKITGTK_API_VERSION@) + +#define WEBKIT_CHECK_VERSION(major, minor, micro) \ + (WEBKIT_MAJOR_VERSION > (major) || \ + (WEBKIT_MAJOR_VERSION == (major) && WEBKIT_MINOR_VERSION > (minor)) || \ + (WEBKIT_MAJOR_VERSION == (major) && WEBKIT_MINOR_VERSION == (minor) && \ + WEBKIT_MICRO_VERSION >= (micro))) + +WEBKIT_API guint +webkit_major_version (void); + +WEBKIT_API guint +webkit_minor_version (void); + +WEBKIT_API guint +webkit_micro_version (void); + +WEBKIT_API gboolean +webkit_check_version (guint major, guint minor, guint micro); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitviewportattributes.cpp b/Source/WebKit/gtk/webkit/webkitviewportattributes.cpp new file mode 100644 index 0000000..742cddd --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitviewportattributes.cpp @@ -0,0 +1,571 @@ +/* + * Copyright (C) 2010 Joone Hur <joone@kldp.org> + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitviewportattributes.h" + +#include "Chrome.h" +#include "Frame.h" +#include "Page.h" +#include "webkitglobalsprivate.h" +#include "webkitviewportattributesprivate.h" +#include "webkitwebviewprivate.h" +#include <glib/gi18n-lib.h> + +/** + * SECTION:webkitviewportattributes + * @short_description: Represents the viewport properties of a web page + * @see_also: #WebKitWebView::viewport-attributes-recompute-requested + * @see_also: #WebKitWebView::viewport-attributes-changed + * + * #WebKitViewportAttributes offers the viewport properties to user agents to + * control the viewport layout. It contains the viewport size, initial scale with limits, + * and information about whether a user is able to scale the contents in the viewport. + * This makes a web page fit the device screen. + * + * The #WebKitWebView::viewport-attributes-changed signal will be emitted with #WebKitViewportAttributes + * when the viewport attributes are updated in the case of loading web pages contain + * the viewport properties and calling webkit_viewport_attributes_recompute. + * + * If the device size, available size, desktop width, or device DPI needs to be changed due to + * a consequence of an explicit browser request (caused by screen rotation, resizing, or similar reasons), + * You should call #webkit_viewport_attributes_recompute to recompute the viewport properties and + * override those values in the handler of #WebKitWebView::viewport-attributes-recompute-requested signal. + * + * For more information on the viewport properties, refer to the Safari reference library at + * http://developer.apple.com/safari/library/documentation/appleapplications/reference/safarihtmlref/articles/metatags.html + * + * <informalexample><programlisting> + * /<!-- -->* Connect to the viewport-attributes-changes signal *<!-- -->/ + * WebKitViewportAttributes* attributes = webkit_web_view_get_viewport_attributes (web_view); + * g_signal_connect (web_view, "viewport-attributes-recompute-requested", G_CALLBACK (viewport_recompute_cb), window); + * g_signal_connect (web_view, "viewport-attributes-changed", G_CALLBACK (viewport_changed_cb), window); + * g_signal_connect (attributes, "notify::valid", G_CALLBACK (viewport_valid_changed_cb), web_view); + * + * /<!-- -->* Handle the viewport-attributes-recompute-requested signal to override the device width *<!-- -->/ + * static void + * viewport_recompute_cb (WebKitWebView* web_view, WebKitViewportAttributes* attributes, GtkWidget* window) + * { + * int override_available_width = 480; + * g_object_set (G_OBJECT(attributes), "available-width", override_available_width, NULL); + * } + * + * /<!-- -->* Handle the viewport-attributes-changed signal to recompute the initial scale factor *<!-- -->/ + * static void + * viewport_changed_cb (WebKitWebView* web_view, WebKitViewportAttributes* attributes, gpointer data) + * { + * gfloat initialScale; + * g_object_get (G_OBJECT (atributes), "initial-scale-factor", &initialScale, NULL); + * webkit_web_view_set_zoom_level (web_view, initialScale); + * } + * + * /<!-- -->* Handle the notify::valid signal to initialize the zoom level *<!-- -->/ + * static void + * viewport_valid_changed_cb (WebKitViewportAttributes* attributes, GParamSpec* pspec, WebKitWebView* web_view) + * { + * gboolean is_valid; + * g_object_get (attributes, "valid", &is_valid, NULL); + * if (!is_valid) + * webkit_web_view_set_zoom_level (web_view, 1.0); + * } + * </programlisting></informalexample> + */ + +using namespace WebKit; +using namespace WebCore; + +enum { + PROP_0, + + PROP_DEVICE_WIDTH, + PROP_DEVICE_HEIGHT, + PROP_AVAILABLE_WIDTH, + PROP_AVAILABLE_HEIGHT, + PROP_DESKTOP_WIDTH, + PROP_DEVICE_DPI, + PROP_WIDTH, + PROP_HEIGHT, + PROP_INITIAL_SCALE_FACTOR, + PROP_MINIMUM_SCALE_FACTOR, + PROP_MAXIMUM_SCALE_FACTOR, + PROP_DEVICE_PIXEL_RATIO, + PROP_USER_SCALABLE, + PROP_VALID +}; + +G_DEFINE_TYPE(WebKitViewportAttributes, webkit_viewport_attributes, G_TYPE_OBJECT); + +static void webkit_viewport_attributes_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* paramSpec); +static void webkit_viewport_attributes_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* paramSpec); + +static void webkit_viewport_attributes_class_init(WebKitViewportAttributesClass* kclass) +{ + GObjectClass* gobjectClass = G_OBJECT_CLASS(kclass); + gobjectClass->get_property = webkit_viewport_attributes_get_property; + gobjectClass->set_property = webkit_viewport_attributes_set_property; + + /** + * WebKitViewportAttributs:device-width: + * + * The width of the screen. This value is always automatically + * pre-computed during a viewport attributes recomputation, and + * can be overridden by the handler of + * WebKitWebView::viewport-attributes-recompute-requested. You + * should not do that unless you have a very good reason. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_DEVICE_WIDTH, + g_param_spec_int( + "device-width", + _("Device Width"), + _("The width of the screen."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:device-height: + * + * The height of the screen. This value is always automatically + * pre-computed during a viewport attributes recomputation, and + * can be overriden by the handler of + * WebKitWebView::viewport-attributes-recompute-requested. You + * should not do that unless you have a very good reason. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_DEVICE_HEIGHT, + g_param_spec_int( + "device-height", + _("Device Height"), + _("The height of the screen."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:available-width: + * + * The width of the current visible area. This will usually be the + * same as the space allocated to the widget, but in some cases + * you may have decided to make the widget bigger than the visible + * area. This value is by default initialized to the size + * allocated by the widget, but you can override it in the handler + * of WebKitWebView::viewport-attributes-recompute-requested to + * let the engine know what the visible area is. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_AVAILABLE_WIDTH, + g_param_spec_int( + "available-width", + _("Available Width"), + _("The width of the visible area."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:available-height: + * + * The height of the current visible area. This will usually be the + * same as the space allocated to the widget, but in some cases + * you may have decided to make the widget bigger than the visible + * area. This value is by default initialized to the size + * allocated by the widget, but you can override it in the handler + * of WebKitWebView::viewport-attributes-recompute-requested to + * let the engine know what the visible area is. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_AVAILABLE_HEIGHT, + g_param_spec_int( + "available-height", + _("Available Height"), + _("The height of the visible area."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:desktop-width: + * + * The width of viewport that works well for most web pages designed for + * desktop. This value is initialized to 980 pixels by default and used + * during a viewport attributes recomputation. Also, it can be overriden by + * the handler of WebKitWebView::viewport-attributes-recompute-requested. + * You should not do that unless you have a very good reason. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_DESKTOP_WIDTH, + g_param_spec_int( + "desktop-width", + _("Desktop Width"), + _("The width of viewport that works well for most web pages designed for desktop."), + 0, + G_MAXINT, + 980, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:device-dpi: + * + * The number of dots per inch of the screen. This value is + * initialized to 160 dpi by default and used during a viewport + * attributes recomputation, because it is the dpi of the original + * iPhone and Android devices. Also, it can be overriden by the + * handler of WebKitWebView::viewport-attributes-recompute-requested. + * You should not do that unless you have a very good reason. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_DEVICE_DPI, + g_param_spec_int( + "device-dpi", + _("Device DPI"), + _("The number of dots per inch of the screen."), + 0, + G_MAXINT, + 160, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitViewportAttributs:width: + * + * The width of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_WIDTH, + g_param_spec_int( + "width", + _("Width"), + _("The width of the viewport."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:height: + * + * The height of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_HEIGHT, + g_param_spec_int( + "height", + _("Height"), + _("The height of the viewport."), + 0, + G_MAXINT, + 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:initial-scale-factor: + * + * The initial scale of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_INITIAL_SCALE_FACTOR, + g_param_spec_float( + "initial-scale-factor", + _("Initial Scale Factor"), + _("The initial scale of the viewport."), + -1, + G_MAXFLOAT, + -1, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:minimum-scale-factor: + * + * The minimum scale of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_MINIMUM_SCALE_FACTOR, + g_param_spec_float( + "minimum-scale-factor", + _("Minimum Scale Factor"), + _("The minimum scale of the viewport."), + -1, + G_MAXFLOAT, + -1, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:maximum-scale-factor: + * + * The maximum scale of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_MAXIMUM_SCALE_FACTOR, + g_param_spec_float( + "maximum-scale-factor", + _("Maximum Scale Factor"), + _("The maximum scale of the viewport."), + -1, + G_MAXFLOAT, + -1, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:device-pixel-ratio: + * + * The device pixel ratio of the viewport. Before getting this property, + * you need to make sure that #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_DEVICE_PIXEL_RATIO, + g_param_spec_float( + "device-pixel-ratio", + _("Device Pixel Ratio"), + _("The device pixel ratio of the viewport."), + -1, + G_MAXFLOAT, + -1, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:user-scalable: + * + * Determines whether or not the user can zoom in and out. + * Before getting this property, you need to make sure that + * #WebKitViewportAttributes is valid. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_USER_SCALABLE, + g_param_spec_boolean( + _("user-scalable"), + _("User Scalable"), + _("Determines whether or not the user can zoom in and out."), + TRUE, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitViewportAttributs:valid: + * + * Determines whether or not the attributes are valid. + * #WebKitViewportAttributes are only valid on pages + * which have a viewport meta tag, and have already + * had the attributes calculated. + * + * Since: 1.3.8 + */ + g_object_class_install_property(gobjectClass, + PROP_VALID, + g_param_spec_boolean( + _("valid"), + _("Valid"), + _("Determines whether or not the attributes are valid, and can be used."), + FALSE, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(kclass, sizeof(WebKitViewportAttributesPrivate)); +} + +static void webkit_viewport_attributes_init(WebKitViewportAttributes* viewport) +{ + viewport->priv = G_TYPE_INSTANCE_GET_PRIVATE(viewport, WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, WebKitViewportAttributesPrivate); + + viewport->priv->deviceWidth = 0; + viewport->priv->deviceHeight = 0; + viewport->priv->availableWidth = 0; + viewport->priv->availableHeight = 0; + viewport->priv->desktopWidth = 980; // This value works well for most web pages designed for desktop browsers. + viewport->priv->deviceDPI = 160; // It is the dpi of the original iPhone and Android devices. + viewport->priv->width = 0; + viewport->priv->height = 0; + viewport->priv->initialScaleFactor = -1; + viewport->priv->minimumScaleFactor = -1; + viewport->priv->maximumScaleFactor = -1; + viewport->priv->devicePixelRatio = -1; + viewport->priv->userScalable = TRUE; + viewport->priv->isValid = FALSE; +} + +static void webkit_viewport_attributes_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* paramSpec) +{ + WebKitViewportAttributes* viewportAttributes = WEBKIT_VIEWPORT_ATTRIBUTES(object); + WebKitViewportAttributesPrivate* priv = viewportAttributes->priv; + + switch (propertyID) { + case PROP_DEVICE_WIDTH: + g_value_set_int(value, priv->deviceWidth); + break; + case PROP_DEVICE_HEIGHT: + g_value_set_int(value, priv->deviceHeight); + break; + case PROP_AVAILABLE_WIDTH: + g_value_set_int(value, priv->availableWidth); + break; + case PROP_AVAILABLE_HEIGHT: + g_value_set_int(value, priv->availableHeight); + break; + case PROP_DESKTOP_WIDTH: + g_value_set_int(value, priv->desktopWidth); + break; + case PROP_DEVICE_DPI: + g_value_set_int(value, priv->deviceDPI); + break; + case PROP_WIDTH: + g_value_set_int(value, priv->width); + break; + case PROP_HEIGHT: + g_value_set_int(value, priv->height); + break; + case PROP_INITIAL_SCALE_FACTOR: + g_value_set_float(value, priv->initialScaleFactor); + break; + case PROP_MINIMUM_SCALE_FACTOR: + g_value_set_float(value, priv->minimumScaleFactor); + break; + case PROP_MAXIMUM_SCALE_FACTOR: + g_value_set_float(value, priv->maximumScaleFactor); + break; + case PROP_DEVICE_PIXEL_RATIO: + g_value_set_float(value, priv->devicePixelRatio); + break; + case PROP_USER_SCALABLE: + g_value_set_boolean(value, priv->userScalable); + break; + case PROP_VALID: + g_value_set_boolean(value, priv->isValid); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, paramSpec); + break; + } +} + +static void webkit_viewport_attributes_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* paramSpec) +{ + WebKitViewportAttributes* viewportAttributes = WEBKIT_VIEWPORT_ATTRIBUTES(object); + WebKitViewportAttributesPrivate* priv = viewportAttributes->priv; + + switch (propertyID) { + case PROP_DEVICE_WIDTH: + priv->deviceWidth = g_value_get_int(value); + break; + case PROP_DEVICE_HEIGHT: + priv->deviceHeight = g_value_get_int(value); + break; + case PROP_AVAILABLE_WIDTH: + priv->availableWidth = g_value_get_int(value); + break; + case PROP_AVAILABLE_HEIGHT: + priv->availableHeight = g_value_get_int(value); + break; + case PROP_DESKTOP_WIDTH: + priv->desktopWidth = g_value_get_int(value); + break; + case PROP_DEVICE_DPI: + priv->deviceDPI = g_value_get_int(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, paramSpec); + break; + } +} + +void webkitViewportAttributesRecompute(WebKitViewportAttributes* viewportAttributes) +{ + WebKitViewportAttributesPrivate* priv = viewportAttributes->priv; + WebKitWebView* webView = priv->webView; + + IntRect windowRect(webView->priv->corePage->chrome()->windowRect()); + priv->deviceWidth = windowRect.width(); + priv->deviceHeight = windowRect.height(); + + IntRect rect(webView->priv->corePage->chrome()->pageRect()); + priv->availableWidth = rect.width(); + priv->availableHeight = rect.height(); + + // First of all, we give the application an opportunity to override some of the values. + g_signal_emit_by_name(webView, "viewport-attributes-recompute-requested", viewportAttributes); + + ViewportArguments arguments = webView->priv->corePage->mainFrame()->document()->viewportArguments(); + + ViewportAttributes attributes = computeViewportAttributes(arguments, priv->desktopWidth, priv->deviceWidth, priv->deviceHeight, priv->deviceDPI, IntSize(priv->availableWidth, priv->availableHeight)); + + priv->width = attributes.layoutSize.width(); + priv->height = attributes.layoutSize.height(); + priv->initialScaleFactor = attributes.initialScale; + priv->minimumScaleFactor = attributes.minimumScale; + priv->maximumScaleFactor = attributes.maximumScale; + priv->devicePixelRatio = attributes.devicePixelRatio; + priv->userScalable = static_cast<bool>(arguments.userScalable); + + if (!priv->isValid) { + priv->isValid = TRUE; + g_object_notify(G_OBJECT(viewportAttributes), "valid"); + } + + // Now let the application know it is safe to use the new values. + g_signal_emit_by_name(webView, "viewport-attributes-changed", viewportAttributes); +} + +/** + * webkit_viewport_attributes_recompute: + * @viewportAttributes: a #WebKitViewportAttributes + * + * Recompute the optimal viewport attributes and emit the viewport-attribute-changed signal. + * The viewport-attributes-recompute-requested signal also will be handled to override + * the device size, available size, desktop width, or device DPI. + * + * Since: 1.3.8 + */ +void webkit_viewport_attributes_recompute(WebKitViewportAttributes* viewportAttributes) +{ + if (!viewportAttributes->priv->isValid) + return; + webkitViewportAttributesRecompute(viewportAttributes); +} diff --git a/Source/WebKit/gtk/webkit/webkitviewportattributes.h b/Source/WebKit/gtk/webkit/webkitviewportattributes.h new file mode 100644 index 0000000..7d90c1b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitviewportattributes.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 Joone Hur <joone@kldp.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitviewportattributes_h +#define webkitviewportattributes_h + +#include <glib-object.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_VIEWPORT_ATTRIBUTES (webkit_viewport_attributes_get_type()) +#define WEBKIT_VIEWPORT_ATTRIBUTES(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, WebKitViewportAttributes)) +#define WEBKIT_VIEWPORT_ATTRIBUTES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, WebKitViewportAttributesClass)) +#define WEBKIT_IS_VIEWPORT_ATTRIBUTES(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_VIEWPORT_ATTRIBUTES)) +#define WEBKIT_IS_VIEWPORT_ATTRIBUTES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_VIEWPORT_ATTRIBUTES)) +#define WEBKIT_VIEWPORT_ATTRIBUTES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, WebKitViewportAttributesClass)) + +typedef struct _WebKitViewportAttributesPrivate WebKitViewportAttributesPrivate; + +struct _WebKitViewportAttributes { + GObject parent_instance; + + /*< private >*/ + WebKitViewportAttributesPrivate *priv; +}; + +struct _WebKitViewportAttributesClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_viewport_attributes_get_type (void); + +WEBKIT_API void +webkit_viewport_attributes_recompute(WebKitViewportAttributes* viewportAttributes); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitviewportattributesprivate.h b/Source/WebKit/gtk/webkit/webkitviewportattributesprivate.h new file mode 100644 index 0000000..11cb668 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitviewportattributesprivate.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitviewportattributesprivate_h +#define webkitnavigationactionprivate_h + +#include <webkit/webkitviewportattributes.h> + +extern "C" { + +struct _WebKitViewportAttributesPrivate { + WebKitWebView* webView; + int deviceWidth; + int deviceHeight; + int availableWidth; + int availableHeight; + int desktopWidth; + int deviceDPI; + + int width; + int height; + float initialScaleFactor; + float minimumScaleFactor; + float maximumScaleFactor; + float devicePixelRatio; + gboolean userScalable; + gboolean isValid; +}; + + +void webkitViewportAttributesRecompute(WebKitViewportAttributes*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.cpp b/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.cpp new file mode 100644 index 0000000..62f7e8c --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.cpp @@ -0,0 +1,472 @@ +/* + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebbackforwardlist.h" + +#include "BackForwardListImpl.h" +#include "HistoryItem.h" +#include "Page.h" +#include "webkitglobalsprivate.h" +#include "webkitwebbackforwardlistprivate.h" +#include "webkitwebhistoryitem.h" +#include "webkitwebhistoryitemprivate.h" +#include "webkitwebview.h" +#include "webkitwebviewprivate.h" +#include <glib.h> + +/** + * SECTION:webkitwebbackforwardlist + * @short_description: The history of a #WebKitWebView + * @see_also: #WebKitWebView, #WebKitWebHistoryItem + * + * <informalexample><programlisting> + * /<!-- -->* Get the WebKitWebBackForwardList from the WebKitWebView *<!-- -->/ + * WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list (my_web_view); + * WebKitWebHistoryItem *item = webkit_web_back_forward_list_get_current_item (back_forward_list); + * + * /<!-- -->* Do something with a WebKitWebHistoryItem *<!-- -->/ + * g_print("%p", item); + * + * /<!-- -->* Control some parameters *<!-- -->/ + * WebKitWebBackForwardList *back_forward_list = webkit_web_view_get_back_forward_list (my_web_view); + * webkit_web_back_forward_list_set_limit (back_forward_list, 30); + * </programlisting></informalexample> + * + */ + +using namespace WebKit; + +struct _WebKitWebBackForwardListPrivate { + WebCore::BackForwardListImpl* backForwardList; + gboolean disposed; +}; + +G_DEFINE_TYPE(WebKitWebBackForwardList, webkit_web_back_forward_list, G_TYPE_OBJECT); + +static void webkit_web_back_forward_list_dispose(GObject* object) +{ + WebKitWebBackForwardList* list = WEBKIT_WEB_BACK_FORWARD_LIST(object); + WebCore::BackForwardListImpl* backForwardList = core(list); + WebKitWebBackForwardListPrivate* priv = list->priv; + + if (!priv->disposed) { + priv->disposed = true; + + WebCore::HistoryItemVector items = backForwardList->entries(); + GHashTable* table = webkit_history_items(); + for (unsigned i = 0; i < items.size(); i++) + g_hash_table_remove(table, items[i].get()); + } + + G_OBJECT_CLASS(webkit_web_back_forward_list_parent_class)->dispose(object); +} + +static void webkit_web_back_forward_list_class_init(WebKitWebBackForwardListClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + object_class->dispose = webkit_web_back_forward_list_dispose; + + webkitInit(); + + g_type_class_add_private(klass, sizeof(WebKitWebBackForwardListPrivate)); +} + +static void webkit_web_back_forward_list_init(WebKitWebBackForwardList* webBackForwardList) +{ + webBackForwardList->priv = G_TYPE_INSTANCE_GET_PRIVATE(webBackForwardList, WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, WebKitWebBackForwardListPrivate); +} + +/** + * webkit_web_back_forward_list_new_with_web_view: (skip) + * @web_view: the back forward list's #WebKitWebView + * + * Creates an instance of the back forward list with a controlling #WebKitWebView + * + * Return value: a #WebKitWebBackForwardList + * + * Deprecated: 1.3.4: Instances of #WebKitWebBackForwardList are + * created and owned by #WebKitWebView instances only. + */ +WebKitWebBackForwardList* webkit_web_back_forward_list_new_with_web_view(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + + WebKitWebBackForwardList* webBackForwardList; + + webBackForwardList = WEBKIT_WEB_BACK_FORWARD_LIST(g_object_new(WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, NULL)); + WebKitWebBackForwardListPrivate* priv = webBackForwardList->priv; + + priv->backForwardList = static_cast<WebCore::BackForwardListImpl*>(core(webView)->backForwardList()); + priv->backForwardList->setEnabled(TRUE); + + return webBackForwardList; +} + +/** + * webkit_web_back_forward_list_go_forward: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Steps forward in the back forward list + */ +void webkit_web_back_forward_list_go_forward(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (backForwardList->enabled()) + backForwardList->goForward(); +} + +/** + * webkit_web_back_forward_list_go_back: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Steps backward in the back forward list + */ +void webkit_web_back_forward_list_go_back(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (backForwardList->enabled()) + backForwardList->goBack(); +} + +/** + * webkit_web_back_forward_list_contains_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @history_item: (type WebKit.WebHistoryItem) (transfer none): the #WebKitWebHistoryItem to check + * + * Checks if @web_history_item is in the back forward list + * + * Return value: %TRUE if @web_history_item is in the back forward list, %FALSE if it doesn't + */ +gboolean webkit_web_back_forward_list_contains_item(WebKitWebBackForwardList* webBackForwardList, WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), FALSE); + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), FALSE); + + WebCore::HistoryItem* historyItem = core(webHistoryItem); + + g_return_val_if_fail(historyItem != NULL, FALSE); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + + return (backForwardList->enabled() ? backForwardList->containsItem(historyItem) : FALSE); +} + +/** + * webkit_web_back_forward_list_go_to_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @history_item: (type WebKit.WebHistoryItem) (transfer none): the #WebKitWebHistoryItem to go to + * + * Go to the specified @web_history_item in the back forward list + */ +void webkit_web_back_forward_list_go_to_item(WebKitWebBackForwardList* webBackForwardList, WebKitWebHistoryItem* webHistoryItem) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + g_return_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem)); + + WebCore::HistoryItem* historyItem = core(webHistoryItem); + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + + if (backForwardList->enabled() && historyItem) + backForwardList->goToItem(historyItem); +} + +/** + * webkit_web_back_forward_list_get_forward_list_with_limit: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @limit: the number of items to retrieve + * + * Returns a list of items that succeed the current item, limited by @limit + * + * Return value: (element-type WebKit.WebHistoryItem) (transfer container): a #GList of items succeeding the current item, limited by @limit + */ +GList* webkit_web_back_forward_list_get_forward_list_with_limit(WebKitWebBackForwardList* webBackForwardList, gint limit) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return NULL; + + WebCore::HistoryItemVector items; + GList* forwardItems = { 0 }; + + backForwardList->forwardListWithLimit(limit, items); + + for (unsigned i = 0; i < items.size(); i++) { + WebKitWebHistoryItem* webHistoryItem = kit(items[i]); + forwardItems = g_list_prepend(forwardItems, webHistoryItem); + } + + return forwardItems; +} + +/** + * webkit_web_back_forward_list_get_back_list_with_limit: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @limit: the number of items to retrieve + * + * Returns a list of items that precede the current item, limited by @limit + * + * Return value: (element-type WebKit.WebHistoryItem) (transfer container): a #GList of items preceding the current item, limited by @limit + */ +GList* webkit_web_back_forward_list_get_back_list_with_limit(WebKitWebBackForwardList* webBackForwardList, gint limit) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return NULL; + + WebCore::HistoryItemVector items; + GList* backItems = { 0 }; + + backForwardList->backListWithLimit(limit, items); + + for (unsigned i = 0; i < items.size(); i++) { + WebKitWebHistoryItem* webHistoryItem = kit(items[i]); + backItems = g_list_prepend(backItems, webHistoryItem); + } + + return backItems; +} + +/** + * webkit_web_back_forward_list_get_back_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the item that precedes the current item + * + * Return value: (type WebKit.WebHistoryItem) (transfer none): the #WebKitWebHistoryItem preceding the current item + */ +WebKitWebHistoryItem* webkit_web_back_forward_list_get_back_item(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return NULL; + + WebCore::HistoryItem* historyItem = backForwardList->backItem(); + + return (historyItem ? kit(historyItem) : NULL); +} + +/** + * webkit_web_back_forward_list_get_current_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the current item. + * + * Returns a NULL value if the back forward list is empty + * + * Return value: (type WebKit.WebHistoryItem) (transfer none): a #WebKitWebHistoryItem + */ +WebKitWebHistoryItem* webkit_web_back_forward_list_get_current_item(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return NULL; + + WebCore::HistoryItem* historyItem = backForwardList->currentItem(); + + return (historyItem ? kit(historyItem) : NULL); +} + +/** + * webkit_web_back_forward_list_get_forward_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the item that succeeds the current item. + * + * Returns a NULL value if there nothing that succeeds the current item + * + * Return value: (type WebKit.WebHistoryItem) (transfer none): a #WebKitWebHistoryItem + */ +WebKitWebHistoryItem* webkit_web_back_forward_list_get_forward_item(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return NULL; + + WebCore::HistoryItem* historyItem = backForwardList->forwardItem(); + + return (historyItem ? kit(historyItem) : NULL); +} + +/** + * webkit_web_back_forward_list_get_nth_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @index: the index of the item + * + * Returns the item at a given index relative to the current item. + * + * Return value: (type WebKit.WebHistoryItem) (transfer none): the #WebKitWebHistoryItem located at the specified index relative to the current item + */ +WebKitWebHistoryItem* webkit_web_back_forward_list_get_nth_item(WebKitWebBackForwardList* webBackForwardList, gint index) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList) + return NULL; + + WebCore::HistoryItem* historyItem = backForwardList->itemAtIndex(index); + + return (historyItem ? kit(historyItem) : NULL); +} + +/** + * webkit_web_back_forward_list_get_back_length: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the number of items that preced the current item. + * + * Return value: a #gint corresponding to the number of items preceding the current item + */ +gint webkit_web_back_forward_list_get_back_length(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return 0; + + return backForwardList->backListCount(); +} + +/** + * webkit_web_back_forward_list_get_forward_length: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the number of items that succeed the current item. + * + * Return value: a #gint corresponding to the nuber of items succeeding the current item + */ +gint webkit_web_back_forward_list_get_forward_length(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return 0; + + return backForwardList->forwardListCount(); +} + +/** + * webkit_web_back_forward_list_get_limit: + * @web_back_forward_list: a #WebKitWebBackForwardList + * + * Returns the maximum limit of the back forward list. + * + * Return value: a #gint indicating the number of #WebKitWebHistoryItem the back forward list can hold + */ +gint webkit_web_back_forward_list_get_limit(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), 0); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled()) + return 0; + + return backForwardList->capacity(); +} + +/** + * webkit_web_back_forward_list_set_limit: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @limit: the limit to set the back forward list to + * + * Sets the maximum limit of the back forward list. If the back forward list + * exceeds its capacity, items will be removed everytime a new item has been + * added. + */ +void webkit_web_back_forward_list_set_limit(WebKitWebBackForwardList* webBackForwardList, gint limit) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (backForwardList) + backForwardList->setCapacity(limit); +} + +/** + * webkit_web_back_forward_list_add_item: + * @web_back_forward_list: a #WebKitWebBackForwardList + * @history_item: (type WebKit.WebHistoryItem) (transfer none): the #WebKitWebHistoryItem to add + * + * Adds the item to the #WebKitWebBackForwardList. + * + * The @webBackForwardList will add a reference to the @webHistoryItem, so you + * don't need to keep a reference once you've added it to the list. + * + * Since: 1.1.1 + */ +void webkit_web_back_forward_list_add_item(WebKitWebBackForwardList *webBackForwardList, WebKitWebHistoryItem *webHistoryItem) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + + g_object_ref(webHistoryItem); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + WebCore::HistoryItem* historyItem = core(webHistoryItem); + + backForwardList->addItem(historyItem); +} + +/** + * webkit_web_back_forward_list_clear: + * @web_back_forward_list: the #WebKitWebBackForwardList to be cleared + * + * Clears the @webBackForwardList by removing all its elements. Note that not even + * the current page is kept in list when cleared so you would have to add it later. + * + * Since: 1.3.1 + **/ +void webkit_web_back_forward_list_clear(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList)); + + WebCore::BackForwardListImpl* backForwardList = core(webBackForwardList); + if (!backForwardList || !backForwardList->enabled() || !backForwardList->entries().size()) + return; + + // Clear the current list by setting capacity to 0 + int capacity = backForwardList->capacity(); + backForwardList->setCapacity(0); + backForwardList->setCapacity(capacity); +} + +WebCore::BackForwardListImpl* WebKit::core(WebKitWebBackForwardList* webBackForwardList) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_BACK_FORWARD_LIST(webBackForwardList), NULL); + + return webBackForwardList->priv ? webBackForwardList->priv->backForwardList : 0; +} diff --git a/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.h b/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.h new file mode 100644 index 0000000..15ddc94 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebbackforwardlist.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2008 Jan Michael C. Alonzo <jmalonzo@unpluggable.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebbackforwardlist_h +#define webkitwebbackforwardlist_h + +#include <glib.h> +#include <glib-object.h> + +#include <webkit/webkitdefines.h> +#include <webkit/webkitwebhistoryitem.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_BACK_FORWARD_LIST (webkit_web_back_forward_list_get_type()) +#define WEBKIT_WEB_BACK_FORWARD_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, WebKitWebBackForwardList)) +#define WEBKIT_WEB_BACK_FORWARD_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, WebKitWebBackForwardListClass)) +#define WEBKIT_IS_WEB_BACK_FORWARD_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST)) +#define WEBKIT_IS_WEB_BACK_FORWARD_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST)) +#define WEBKIT_WEB_BACK_FORWARD_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_BACK_FORWARD_LIST, WebKitWebBackForwardListClass)) + +typedef struct _WebKitWebBackForwardListPrivate WebKitWebBackForwardListPrivate; + +struct _WebKitWebBackForwardList { + GObject parent_instance; + + /*< private >*/ + WebKitWebBackForwardListPrivate *priv; +}; + +struct _WebKitWebBackForwardListClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_back_forward_list_get_type (void); + +WEBKIT_API WebKitWebBackForwardList * +webkit_web_back_forward_list_new_with_web_view (WebKitWebView *web_view); + +WEBKIT_API void +webkit_web_back_forward_list_go_forward (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API void +webkit_web_back_forward_list_go_back (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API gboolean +webkit_web_back_forward_list_contains_item (WebKitWebBackForwardList *web_back_forward_list, + WebKitWebHistoryItem *history_item); + +WEBKIT_API void +webkit_web_back_forward_list_go_to_item (WebKitWebBackForwardList *web_back_forward_list, + WebKitWebHistoryItem *history_item); + +WEBKIT_API GList * +webkit_web_back_forward_list_get_forward_list_with_limit (WebKitWebBackForwardList *web_back_forward_list, + gint limit); + +WEBKIT_API GList * +webkit_web_back_forward_list_get_back_list_with_limit (WebKitWebBackForwardList *web_back_forward_list, + gint limit); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_back_forward_list_get_back_item (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_back_forward_list_get_current_item (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_back_forward_list_get_forward_item (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_back_forward_list_get_nth_item (WebKitWebBackForwardList *web_back_forward_list, + gint index); + +WEBKIT_API gint +webkit_web_back_forward_list_get_back_length (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API gint +webkit_web_back_forward_list_get_forward_length (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API gint +webkit_web_back_forward_list_get_limit (WebKitWebBackForwardList *web_back_forward_list); + +WEBKIT_API void +webkit_web_back_forward_list_set_limit (WebKitWebBackForwardList *web_back_forward_list, + gint limit); + +WEBKIT_API void +webkit_web_back_forward_list_add_item (WebKitWebBackForwardList *web_back_forward_list, + WebKitWebHistoryItem *history_item); + +WEBKIT_API void +webkit_web_back_forward_list_clear (WebKitWebBackForwardList *web_back_forward_list); + +G_END_DECLS + + +#endif /* webkitwebbackforwardlist_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebbackforwardlistprivate.h b/Source/WebKit/gtk/webkit/webkitwebbackforwardlistprivate.h new file mode 100644 index 0000000..79424c0 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebbackforwardlistprivate.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebbackforwardlistprivate_h +#define webkitwebbackforwardlistprivate_h + +#include "BackForwardListImpl.h" + +namespace WebKit { + +WebCore::BackForwardListImpl* core(WebKitWebBackForwardList*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebdatabase.cpp b/Source/WebKit/gtk/webkit/webkitwebdatabase.cpp new file mode 100644 index 0000000..1291986 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebdatabase.cpp @@ -0,0 +1,530 @@ +/* + * Copyright (C) 2009 Martin Robinson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebdatabase.h" + +#include "DatabaseDetails.h" +#include "DatabaseTracker.h" +#include "webkitglobalsprivate.h" +#include "webkitsecurityoriginprivate.h" +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitwebdatabase + * @short_description: A WebKit web application database + * + * #WebKitWebDatabase is a representation of a Web Database database. The + * proposed Web Database standard introduces support for SQL databases that web + * sites can create and access on a local computer through JavaScript. + * + * To get access to all databases defined by a security origin, use + * #webkit_security_origin_get_databases. Each database has a canonical + * name, as well as a user-friendly display name. + * + * WebKit uses SQLite to create and access the local SQL databases. The location + * of a #WebKitWebDatabase can be accessed wth #webkit_web_database_get_filename. + * You can configure the location of all databases with + * #webkit_set_database_directory_path. + * + * For each database the web site can define an estimated size which can be + * accessed with #webkit_web_database_get_expected_size. The current size of the + * database in bytes is returned by #webkit_web_database_get_size. + * + * For more information refer to the Web Database specification proposal at + * http://dev.w3.org/html5/webdatabase + */ + +using namespace WebKit; + +enum { + PROP_0, + + PROP_SECURITY_ORIGIN, + PROP_NAME, + PROP_DISPLAY_NAME, + PROP_EXPECTED_SIZE, + PROP_SIZE, + PROP_PATH +}; + +G_DEFINE_TYPE(WebKitWebDatabase, webkit_web_database, G_TYPE_OBJECT) + +struct _WebKitWebDatabasePrivate { + WebKitSecurityOrigin* origin; + gchar* name; + gchar* displayName; + gchar* filename; +}; + +static gchar* webkit_database_directory_path = NULL; +static guint64 webkit_default_database_quota = 5 * 1024 * 1024; + +static void webkit_web_database_set_security_origin(WebKitWebDatabase* webDatabase, WebKitSecurityOrigin* security_origin); + +static void webkit_web_database_set_name(WebKitWebDatabase* webDatabase, const gchar* name); + +static void webkit_web_database_finalize(GObject* object) +{ + WebKitWebDatabase* webDatabase = WEBKIT_WEB_DATABASE(object); + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + g_free(priv->name); + g_free(priv->displayName); + g_free(priv->filename); + + G_OBJECT_CLASS(webkit_web_database_parent_class)->finalize(object); +} + +static void webkit_web_database_dispose(GObject* object) +{ + WebKitWebDatabase* webDatabase = WEBKIT_WEB_DATABASE(object); + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + if (priv->origin) { + g_object_unref(priv->origin); + priv->origin = NULL; + } + + G_OBJECT_CLASS(webkit_web_database_parent_class)->dispose(object); +} + +static void webkit_web_database_set_property(GObject* object, guint propId, const GValue* value, GParamSpec* pspec) +{ + WebKitWebDatabase* webDatabase = WEBKIT_WEB_DATABASE(object); + + switch (propId) { + case PROP_SECURITY_ORIGIN: + webkit_web_database_set_security_origin(webDatabase, WEBKIT_SECURITY_ORIGIN(g_value_get_object(value))); + break; + case PROP_NAME: + webkit_web_database_set_name(webDatabase, g_value_get_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static void webkit_web_database_get_property(GObject* object, guint propId, GValue* value, GParamSpec* pspec) +{ + WebKitWebDatabase* webDatabase = WEBKIT_WEB_DATABASE(object); + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + switch (propId) { + case PROP_SECURITY_ORIGIN: + g_value_set_object(value, priv->origin); + break; + case PROP_NAME: + g_value_set_string(value, webkit_web_database_get_name(webDatabase)); + break; + case PROP_DISPLAY_NAME: + g_value_set_string(value, webkit_web_database_get_display_name(webDatabase)); + break; + case PROP_EXPECTED_SIZE: + g_value_set_uint64(value, webkit_web_database_get_expected_size(webDatabase)); + break; + case PROP_SIZE: + g_value_set_uint64(value, webkit_web_database_get_size(webDatabase)); + break; + case PROP_PATH: + g_value_set_string(value, webkit_web_database_get_filename(webDatabase)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec); + break; + } +} + +static void webkit_web_database_class_init(WebKitWebDatabaseClass* klass) +{ + GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); + gobjectClass->dispose = webkit_web_database_dispose; + gobjectClass->finalize = webkit_web_database_finalize; + gobjectClass->set_property = webkit_web_database_set_property; + gobjectClass->get_property = webkit_web_database_get_property; + + /** + * WebKitWebDatabase:security-origin: + * + * The security origin of the database. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_SECURITY_ORIGIN, + g_param_spec_object("security-origin", + _("Security Origin"), + _("The security origin of the database"), + WEBKIT_TYPE_SECURITY_ORIGIN, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebDatabase:name: + * + * The name of the Web Database database. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_NAME, + g_param_spec_string("name", + _("Name"), + _("The name of the Web Database database"), + NULL, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebDatabase:display-name: + * + * The display name of the Web Database database. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_DISPLAY_NAME, + g_param_spec_string("display-name", + _("Display Name"), + _("The display name of the Web Storage database"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebDatabase:expected-size: + * + * The expected size of the database in bytes as defined by the web author. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_EXPECTED_SIZE, + g_param_spec_uint64("expected-size", + _("Expected Size"), + _("The expected size of the Web Database database"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + /** + * WebKitWebDatabase:size: + * + * The current size of the database in bytes. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_SIZE, + g_param_spec_uint64("size", + _("Size"), + _("The current size of the Web Database database"), + 0, G_MAXUINT64, 0, + WEBKIT_PARAM_READABLE)); + /** + * WebKitWebDatabase:filename: + * + * The absolute filename of the Web Database database. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobjectClass, PROP_PATH, + g_param_spec_string("filename", + _("Filename"), + _("The absolute filename of the Web Storage database"), + NULL, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(klass, sizeof(WebKitWebDatabasePrivate)); +} + +static void webkit_web_database_init(WebKitWebDatabase* webDatabase) +{ + webDatabase->priv = G_TYPE_INSTANCE_GET_PRIVATE(webDatabase, WEBKIT_TYPE_WEB_DATABASE, WebKitWebDatabasePrivate); +} + +// Internal use only +static void webkit_web_database_set_security_origin(WebKitWebDatabase *webDatabase, WebKitSecurityOrigin *securityOrigin) +{ + g_return_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase)); + g_return_if_fail(WEBKIT_IS_SECURITY_ORIGIN(securityOrigin)); + + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + if (priv->origin) + g_object_unref(priv->origin); + + g_object_ref(securityOrigin); + priv->origin = securityOrigin; +} + +static void webkit_web_database_set_name(WebKitWebDatabase* webDatabase, const gchar* name) +{ + g_return_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase)); + + WebKitWebDatabasePrivate* priv = webDatabase->priv; + g_free(priv->name); + priv->name = g_strdup(name); +} + +/** + * webkit_web_database_get_security_origin: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the security origin of the #WebKitWebDatabase. + * + * Returns: (transfer none): the security origin of the database + * + * Since: 1.1.14 + **/ +WebKitSecurityOrigin* webkit_web_database_get_security_origin(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), NULL); + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + return priv->origin; +} + +/** + * webkit_web_database_get_name: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the canonical name of the #WebKitWebDatabase. + * + * Returns: the name of the database + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_web_database_get_name(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), NULL); + WebKitWebDatabasePrivate* priv = webDatabase->priv; + + return priv->name; +} + +/** + * webkit_web_database_get_display_name: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the name of the #WebKitWebDatabase as seen by the user. + * + * Returns: the name of the database as seen by the user. + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_web_database_get_display_name(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), NULL); + +#if ENABLE(DATABASE) + WebKitWebDatabasePrivate* priv = webDatabase->priv; + WebCore::DatabaseDetails details = WebCore::DatabaseTracker::tracker().detailsForNameAndOrigin(priv->name, core(priv->origin)); + WTF::String displayName = details.displayName(); + + if (displayName.isEmpty()) + return ""; + + g_free(priv->displayName); + priv->displayName = g_strdup(displayName.utf8().data()); + return priv->displayName; +#else + return ""; +#endif +} + +/** + * webkit_web_database_get_expected_size: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the expected size of the #WebKitWebDatabase in bytes as defined by the + * web author. The Web Database standard allows web authors to specify an expected + * size of the database to optimize the user experience. + * + * Returns: the expected size of the database in bytes + * + * Since: 1.1.14 + **/ +guint64 webkit_web_database_get_expected_size(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), 0); + +#if ENABLE(DATABASE) + WebKitWebDatabasePrivate* priv = webDatabase->priv; + WebCore::DatabaseDetails details = WebCore::DatabaseTracker::tracker().detailsForNameAndOrigin(priv->name, core(priv->origin)); + return details.expectedUsage(); +#else + return 0; +#endif +} + +/** + * webkit_web_database_get_size: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the actual size of the #WebKitWebDatabase space on disk in bytes. + * + * Returns: the actual size of the database in bytes + * + * Since: 1.1.14 + **/ +guint64 webkit_web_database_get_size(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), 0); + +#if ENABLE(DATABASE) + WebKitWebDatabasePrivate* priv = webDatabase->priv; + WebCore::DatabaseDetails details = WebCore::DatabaseTracker::tracker().detailsForNameAndOrigin(priv->name, core(priv->origin)); + return details.currentUsage(); +#else + return 0; +#endif +} + +/** + * webkit_web_database_get_filename: + * @webDatabase: a #WebKitWebDatabase + * + * Returns the absolute filename to the #WebKitWebDatabase file on disk. + * + * Returns: the absolute filename of the database + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_web_database_get_filename(WebKitWebDatabase* webDatabase) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase), NULL); + +#if ENABLE(DATABASE) + WebKitWebDatabasePrivate* priv = webDatabase->priv; + WTF::String coreName = WTF::String::fromUTF8(priv->name); + WTF::String corePath = WebCore::DatabaseTracker::tracker().fullPathForDatabase(core(priv->origin), coreName); + + if (corePath.isEmpty()) + return""; + + g_free(priv->filename); + priv->filename = g_strdup(corePath.utf8().data()); + return priv->filename; + +#else + return ""; +#endif +} + +/** + * webkit_web_database_remove: + * @webDatabase: a #WebKitWebDatabase + * + * Removes the #WebKitWebDatabase from its security origin and destroys all data + * stored in the database. + * + * Since: 1.1.14 + **/ +void webkit_web_database_remove(WebKitWebDatabase* webDatabase) +{ + g_return_if_fail(WEBKIT_IS_WEB_DATABASE(webDatabase)); + +#if ENABLE(DATABASE) + WebKitWebDatabasePrivate* priv = webDatabase->priv; + WebCore::DatabaseTracker::tracker().deleteDatabase(core(priv->origin), priv->name); +#endif +} + +/** + * webkit_remove_all_web_databases: + * + * Removes all web databases from the current database directory path. + * + * Since: 1.1.14 + **/ +void webkit_remove_all_web_databases() +{ +#if ENABLE(DATABASE) + WebCore::DatabaseTracker::tracker().deleteAllDatabases(); +#endif +} + +/** + * webkit_get_web_database_directory_path: + * + * Returns the current path to the directory WebKit will write Web + * Database databases. By default this path will be in the user data + * directory. + * + * Returns: the current database directory path + * + * Since: 1.1.14 + **/ +G_CONST_RETURN gchar* webkit_get_web_database_directory_path() +{ +#if ENABLE(DATABASE) + WTF::String path = WebCore::DatabaseTracker::tracker().databaseDirectoryPath(); + + if (path.isEmpty()) + return ""; + + g_free(webkit_database_directory_path); + webkit_database_directory_path = g_strdup(path.utf8().data()); + return webkit_database_directory_path; +#else + return ""; +#endif +} + +/** + * webkit_set_web_database_directory_path: + * @path: the new database directory path + * + * Sets the current path to the directory WebKit will write Web + * Database databases. + * + * Since: 1.1.14 + **/ +void webkit_set_web_database_directory_path(const gchar* path) +{ +#if ENABLE(DATABASE) + WTF::String corePath = WTF::String::fromUTF8(path); + WebCore::DatabaseTracker::tracker().setDatabaseDirectoryPath(corePath); + + g_free(webkit_database_directory_path); + webkit_database_directory_path = g_strdup(corePath.utf8().data()); +#endif +} + +/** + * webkit_get_default_web_database_quota: + * + * Returns the default quota for Web Database databases. By default + * this value is 5MB. + + * Returns: the current default database quota in bytes + * + * Since: 1.1.14 + **/ +guint64 webkit_get_default_web_database_quota() +{ + return webkit_default_database_quota; +} + +/** + * webkit_set_default_web_database_quota: + * @defaultQuota: the new default database quota + * + * Sets the current path to the directory WebKit will write Web + * Database databases. + * + * Since: 1.1.14 + **/ +void webkit_set_default_web_database_quota(guint64 defaultQuota) +{ + webkit_default_database_quota = defaultQuota; +} diff --git a/Source/WebKit/gtk/webkit/webkitwebdatabase.h b/Source/WebKit/gtk/webkit/webkitwebdatabase.h new file mode 100644 index 0000000..8a9a151 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebdatabase.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009 Martin Robinson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebdatabase_h +#define webkitwebdatabase_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_DATABASE (webkit_web_database_get_type()) +#define WEBKIT_WEB_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_DATABASE, WebKitWebDatabase)) +#define WEBKIT_WEB_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_DATABASE, WebKitWebDatabaseClass)) +#define WEBKIT_IS_WEB_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_DATABASE)) +#define WEBKIT_IS_WEB_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_DATABASE)) +#define WEBKIT_WEB_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_DATABASE, WebKitWebDatabaseClass)) + +typedef struct _WebKitWebDatabasePrivate WebKitWebDatabasePrivate; + +struct _WebKitWebDatabase { + GObject parent_instance; + + /*< private >*/ + WebKitWebDatabasePrivate* priv; +}; + +struct _WebKitWebDatabaseClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_web_database_get_type (void); + +WEBKIT_API WebKitSecurityOrigin * +webkit_web_database_get_security_origin (WebKitWebDatabase* webDatabase); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_web_database_get_name (WebKitWebDatabase* webDatabase); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_web_database_get_display_name (WebKitWebDatabase* webDatabase); + +WEBKIT_API guint64 +webkit_web_database_get_expected_size (WebKitWebDatabase* webDatabase); + +WEBKIT_API guint64 +webkit_web_database_get_size (WebKitWebDatabase* webDatabase); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_web_database_get_filename (WebKitWebDatabase* webDatabase); + +WEBKIT_API void +webkit_web_database_remove (WebKitWebDatabase* webDatabase); + +WEBKIT_API void +webkit_remove_all_web_databases (void); + +WEBKIT_API G_CONST_RETURN gchar* +webkit_get_web_database_directory_path (void); + +WEBKIT_API void +webkit_set_web_database_directory_path (const gchar* path); + +WEBKIT_API guint64 +webkit_get_default_web_database_quota (void); + +WEBKIT_API void +webkit_set_default_web_database_quota (guint64 defaultQuota); + +G_END_DECLS + +#endif /* webkitwebdatabase_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebdatasource.cpp b/Source/WebKit/gtk/webkit/webkitwebdatasource.cpp new file mode 100644 index 0000000..8538665 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebdatasource.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (C) 2009 Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebdatasource.h" + +#include "ArchiveResource.h" +#include "DocumentLoaderGtk.h" +#include "FrameLoader.h" +#include "FrameLoaderClientGtk.h" +#include "KURL.h" +#include "PlatformString.h" +#include "ResourceRequest.h" +#include "SharedBuffer.h" +#include "SubstituteData.h" +#include "runtime/InitializeThreading.h" +#include "webkitglobalsprivate.h" +#include "webkitnetworkrequestprivate.h" +#include "webkitwebdatasourceprivate.h" +#include "webkitwebframeprivate.h" +#include "webkitwebresource.h" +#include "webkitwebviewprivate.h" +#include "wtf/Assertions.h" +#include <glib.h> + +/** + * SECTION:webkitwebdatasource + * @short_description: Encapsulates the content to be displayed in a #WebKitWebFrame. + * @see_also: #WebKitWebFrame + * + * Data source encapsulates the content of a #WebKitWebFrame. A + * #WebKitWebFrame has a main resource and subresources and the data source + * provides access to these resources. When a request gets loaded initially, + * it is set to a provisional state. The application can request for the + * request that initiated the load by asking for the provisional data source + * and invoking the webkit_web_data_source_get_initial_request method of + * #WebKitWebDataSource. This data source may not have enough data and some + * methods may return empty values. To get a "full" data source with the data + * and resources loaded, you need to get the non-provisional data source + * through #WebKitWebFrame's webkit_web_frame_get_data_source method. This + * data source will have the data after everything was loaded. Make sure that + * the data source was finished loading before using any of its methods. You + * can do this via webkit_web_data_source_is_loading. + */ + +using namespace WebCore; +using namespace WebKit; + +struct _WebKitWebDataSourcePrivate { + WebKit::DocumentLoader* loader; + + WebKitNetworkRequest* initialRequest; + WebKitNetworkRequest* networkRequest; + WebKitWebResource* mainresource; + + GString* data; + + gchar* textEncoding; + gchar* unreachableURL; +}; + +G_DEFINE_TYPE(WebKitWebDataSource, webkit_web_data_source, G_TYPE_OBJECT); + +static void webkit_web_data_source_dispose(GObject* object) +{ + WebKitWebDataSource* webDataSource = WEBKIT_WEB_DATA_SOURCE(object); + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + + ASSERT(priv->loader); + ASSERT(!priv->loader->isLoading()); + priv->loader->detachDataSource(); + priv->loader->deref(); + + if (priv->initialRequest) { + g_object_unref(priv->initialRequest); + priv->initialRequest = NULL; + } + + if (priv->networkRequest) { + g_object_unref(priv->networkRequest); + priv->networkRequest = NULL; + } + + if (priv->mainresource) { + g_object_unref(priv->mainresource); + priv->mainresource = NULL; + } + + G_OBJECT_CLASS(webkit_web_data_source_parent_class)->dispose(object); +} + +static void webkit_web_data_source_finalize(GObject* object) +{ + WebKitWebDataSource* dataSource = WEBKIT_WEB_DATA_SOURCE(object); + WebKitWebDataSourcePrivate* priv = dataSource->priv; + + g_free(priv->unreachableURL); + g_free(priv->textEncoding); + + if (priv->data) { + g_string_free(priv->data, TRUE); + priv->data = NULL; + } + + G_OBJECT_CLASS(webkit_web_data_source_parent_class)->finalize(object); +} + +static void webkit_web_data_source_class_init(WebKitWebDataSourceClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + gobject_class->dispose = webkit_web_data_source_dispose; + gobject_class->finalize = webkit_web_data_source_finalize; + + webkitInit(); + + g_type_class_add_private(gobject_class, sizeof(WebKitWebDataSourcePrivate)); +} + +static void webkit_web_data_source_init(WebKitWebDataSource* webDataSource) +{ + webDataSource->priv = G_TYPE_INSTANCE_GET_PRIVATE(webDataSource, WEBKIT_TYPE_WEB_DATA_SOURCE, WebKitWebDataSourcePrivate); +} + +/** + * webkit_web_data_source_new: + * + * Creates a new #WebKitWebDataSource instance. The URL of the + * #WebKitWebDataSource will be set to "about:blank". + * + * Return: a new #WebKitWebDataSource. + * + * Since: 1.1.14 + */ +WebKitWebDataSource* webkit_web_data_source_new() +{ + WebKitNetworkRequest* request = webkit_network_request_new("about:blank"); + WebKitWebDataSource* datasource = webkit_web_data_source_new_with_request(request); + g_object_unref(request); + + return datasource; +} + +/** + * webkit_web_data_source_new_with_request: + * @request: the #WebKitNetworkRequest to use to create this data source + * + * Creates a new #WebKitWebDataSource from a #WebKitNetworkRequest. Normally, + * #WebKitWebFrame objects create their data sources so you will almost never + * want to invoke this method directly. + * + * Returns: a new #WebKitWebDataSource + * + * Since: 1.1.14 + */ +WebKitWebDataSource* webkit_web_data_source_new_with_request(WebKitNetworkRequest* request) +{ + ASSERT(request); + + const gchar* uri = webkit_network_request_get_uri(request); + + ResourceRequest resourceRequest(ResourceRequest(KURL(KURL(), String::fromUTF8(uri)))); + WebKitWebDataSource* datasource = kitNew(WebKit::DocumentLoader::create(resourceRequest, SubstituteData())); + + WebKitWebDataSourcePrivate* priv = datasource->priv; + priv->initialRequest = request; + + return datasource; +} + +/** + * webkit_web_data_source_get_web_frame: + * @data_source: a #WebKitWebDataSource + * + * Returns the #WebKitWebFrame that represents this data source + * + * Return value: (transfer none): the #WebKitWebFrame that represents + * the @data_source. The #WebKitWebFrame is owned by WebKit and should + * not be freed or destroyed. This will return %NULL if the + * @data_source is not attached to a frame. + * + * Since: 1.1.14 + */ +WebKitWebFrame* webkit_web_data_source_get_web_frame(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + FrameLoader* frameLoader = priv->loader->frameLoader(); + + if (!frameLoader) + return NULL; + + return static_cast<WebKit::FrameLoaderClient*>(frameLoader->client())->webFrame(); +} + +/** + * webkit_web_data_source_get_initial_request: + * @data_source: a #WebKitWebDataSource + * + * Returns a reference to the original request that was used to load the web + * content. The #WebKitNetworkRequest returned by this method is the request + * prior to the "committed" load state. See webkit_web_data_source_get_request + * for getting the "committed" request. + * + * Return value: (transfer none): the original #WebKitNetworkRequest + * + * Since: 1.1.14 + */ +WebKitNetworkRequest* webkit_web_data_source_get_initial_request(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + ResourceRequest request = priv->loader->originalRequest(); + + if (priv->initialRequest) + g_object_unref(priv->initialRequest); + + priv->initialRequest = kitNew(request); + return priv->initialRequest; +} + +/** + * webkit_web_data_source_get_request: + * @data_source: a #WebKitWebDataSource + * + * Returns a #WebKitNetworkRequest that was used to create this + * #WebKitWebDataSource. The #WebKitNetworkRequest returned by this method is + * the request that was "committed", and hence, different from the request you + * get from the webkit_web_data_source_get_initial_request method. + * + * Return value: (transfer none): the #WebKitNetworkRequest that + * created the @data_source or %NULL if the @data_source is not + * attached to the frame or the frame hasn't been loaded. + * + * Since: 1.1.14 + */ +WebKitNetworkRequest* webkit_web_data_source_get_request(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + FrameLoader* frameLoader = priv->loader->frameLoader(); + if (!frameLoader || !frameLoader->frameHasLoaded()) + return NULL; + + ResourceRequest request = priv->loader->request(); + + if (priv->networkRequest) + g_object_unref(priv->networkRequest); + + priv->networkRequest = kitNew(request); + return priv->networkRequest; +} + +/** + * webkit_web_data_source_get_encoding: + * @data_source: a #WebKitWebDataSource + * + * Returns the text encoding name as set in the #WebKitWebView, or if not, the + * text encoding of the response. + * + * Return value: the encoding name of the #WebKitWebView or of the response. + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_data_source_get_encoding(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + String textEncodingName = priv->loader->overrideEncoding(); + + if (!textEncodingName) + textEncodingName = priv->loader->response().textEncodingName(); + + CString encoding = textEncodingName.utf8(); + g_free(priv->textEncoding); + priv->textEncoding = g_strdup(encoding.data()); + return priv->textEncoding; +} + +/** + * webkit_web_data_source_is_loading: + * @data_source: a #WebKitWebDataSource + * + * Determines whether the data source is in the process of loading its content. + * + * Return value: %TRUE if the @data_source is still loading, %FALSE otherwise + * + * Since: 1.1.14 + */ +gboolean webkit_web_data_source_is_loading(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), FALSE); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + + return priv->loader->isLoadingInAPISense(); +} + +/** + * webkit_web_data_source_get_data: + * @data_source: a #WebKitWebDataSource + * + * Returns the raw data that represents the the frame's content.The data will + * be incomplete until the data has finished loading. Returns %NULL if the web + * frame hasn't loaded any data. Use webkit_web_data_source_is_loading to test + * if data source is in the process of loading. + * + * Return value: (transfer none): a #GString which contains the raw + * data that represents the @data_source or %NULL if the @data_source + * hasn't loaded any data. + * + * Since: 1.1.14 + */ +GString* webkit_web_data_source_get_data(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + + RefPtr<SharedBuffer> mainResourceData = priv->loader->mainResourceData(); + + if (!mainResourceData) + return NULL; + + if (priv->data) { + g_string_free(priv->data, TRUE); + priv->data = NULL; + } + + priv->data = g_string_new_len(mainResourceData->data(), mainResourceData->size()); + return priv->data; +} + +/** + * webkit_web_data_source_get_main_resource: + * @data_source: a #WebKitWebDataSource + * + * Returns the main resource of the @data_source + * + * Return value: (transfer none): a new #WebKitWebResource + * representing the main resource of the @data_source. + * + * Since: 1.1.14 + */ +WebKitWebResource* webkit_web_data_source_get_main_resource(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + + if (priv->mainresource) + return priv->mainresource; + + WebKitWebFrame* webFrame = webkit_web_data_source_get_web_frame(webDataSource); + WebKitWebView* webView = getViewFromFrame(webFrame); + + priv->mainresource = WEBKIT_WEB_RESOURCE(g_object_ref(webkit_web_view_get_main_resource(webView))); + + return priv->mainresource; +} + +/** + * webkit_web_data_source_get_unreachable_uri: + * @data_source: a #WebKitWebDataSource + * + * Return the unreachable URI of @data_source. The @data_source will have an + * unreachable URL if it was created using #WebKitWebFrame's + * webkit_web_frame_load_alternate_html_string method. + * + * Return value: the unreachable URL of @data_source or %NULL if there is no unreachable URL. + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_data_source_get_unreachable_uri(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + const KURL& unreachableURL = priv->loader->unreachableURL(); + + if (unreachableURL.isEmpty()) + return NULL; + + g_free(priv->unreachableURL); + priv->unreachableURL = g_strdup(unreachableURL.string().utf8().data()); + return priv->unreachableURL; +} + +/** + * webkit_web_data_source_get_subresources: + * @data_source: a #WebKitWebDataSource + * + * Gives you a #GList of #WebKitWebResource objects that compose the + * #WebKitWebView to which this #WebKitWebDataSource is attached. + * + * Return value: (element-type WebKitWebResource) (transfer container): + * a #GList of #WebKitWebResource objects; the objects are owned by + * WebKit, but the GList must be freed. + * + * Since: 1.1.15 + */ +GList* webkit_web_data_source_get_subresources(WebKitWebDataSource* webDataSource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_DATA_SOURCE(webDataSource), NULL); + + WebKitWebFrame* webFrame = webkit_web_data_source_get_web_frame(webDataSource); + WebKitWebView* webView = getViewFromFrame(webFrame); + + return webkit_web_view_get_subresources(webView); +} + +namespace WebKit { + +WebKitWebDataSource* kitNew(PassRefPtr<WebKit::DocumentLoader> loader) +{ + WebKitWebDataSource* webDataSource = WEBKIT_WEB_DATA_SOURCE(g_object_new(WEBKIT_TYPE_WEB_DATA_SOURCE, NULL)); + WebKitWebDataSourcePrivate* priv = webDataSource->priv; + priv->loader = loader.releaseRef(); + + return webDataSource; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebdatasource.h b/Source/WebKit/gtk/webkit/webkitwebdatasource.h new file mode 100644 index 0000000..df83118 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebdatasource.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009 Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebdatasource_h +#define webkitwebdatasource_h + +#include <glib.h> +#include <glib-object.h> + +#include <webkit/webkitdefines.h> +#include <webkit/webkitwebframe.h> +#include <webkit/webkitnetworkrequest.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_DATA_SOURCE (webkit_web_data_source_get_type()) +#define WEBKIT_WEB_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_DATA_SOURCE, WebKitWebDataSource)) +#define WEBKIT_WEB_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_DATA_SOURCE, WebKitWebDataSourceClass)) +#define WEBKIT_IS_WEB_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_DATA_SOURCE)) +#define WEBKIT_IS_WEB_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_DATA_SOURCE)) +#define WEBKIT_WEB_DATA_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_DATA_SOURCE, WebKitWebDataSourceClass)) + +typedef struct _WebKitWebDataSourcePrivate WebKitWebDataSourcePrivate; + +struct _WebKitWebDataSource { + GObject parent_instance; + + /*< private >*/ + WebKitWebDataSourcePrivate *priv; +}; + +struct _WebKitWebDataSourceClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_data_source_get_type (void); + +WEBKIT_API WebKitWebDataSource * +webkit_web_data_source_new (void); + +WEBKIT_API WebKitWebDataSource * +webkit_web_data_source_new_with_request (WebKitNetworkRequest *request); + +WEBKIT_API WebKitWebFrame * +webkit_web_data_source_get_web_frame (WebKitWebDataSource *data_source); + +WEBKIT_API WebKitNetworkRequest * +webkit_web_data_source_get_initial_request (WebKitWebDataSource *data_source); + +WEBKIT_API WebKitNetworkRequest * +webkit_web_data_source_get_request (WebKitWebDataSource *data_source); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_data_source_get_encoding (WebKitWebDataSource *data_source); + +WEBKIT_API gboolean +webkit_web_data_source_is_loading (WebKitWebDataSource *data_source); + +WEBKIT_API GString * +webkit_web_data_source_get_data (WebKitWebDataSource *data_source); + +WEBKIT_API WebKitWebResource * +webkit_web_data_source_get_main_resource (WebKitWebDataSource *data_source); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_data_source_get_unreachable_uri (WebKitWebDataSource *data_source); + +WEBKIT_API GList* +webkit_web_data_source_get_subresources (WebKitWebDataSource *data_source); + +G_END_DECLS + +#endif /* webkitwebdatasource_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebdatasourceprivate.h b/Source/WebKit/gtk/webkit/webkitwebdatasourceprivate.h new file mode 100644 index 0000000..5c18493 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebdatasourceprivate.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebdatasourceprivate_h +#define webkitwebdatasourceprivate_h + +#include "RefPtr.h" +#include "webkitwebdatasource.h" + +namespace WebKit { + +WebKitWebDataSource* kitNew(PassRefPtr<WebKit::DocumentLoader>); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebframe.cpp b/Source/WebKit/gtk/webkit/webkitwebframe.cpp new file mode 100644 index 0000000..a0e40b3 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebframe.cpp @@ -0,0 +1,1004 @@ +/* + * Copyright (C) 2007, 2008 Holger Hans Peter Freyther + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * Copyright (C) 2007 Apple Inc. + * Copyright (C) 2008 Christian Dywan <christian@imendio.com> + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2008 Nuanti Ltd. + * Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com> + * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebframe.h" + +#include "AXObjectCache.h" +#include "AccessibilityObjectWrapperAtk.h" +#include "AnimationController.h" +#include "DOMObjectCache.h" +#include "DocumentLoader.h" +#include "DocumentLoaderGtk.h" +#include "FrameLoader.h" +#include "FrameLoaderClientGtk.h" +#include "FrameTree.h" +#include "FrameView.h" +#include "GCController.h" +#include "GraphicsContext.h" +#include "GtkVersioning.h" +#include "HTMLFrameOwnerElement.h" +#include "JSDOMBinding.h" +#include "JSDOMWindow.h" +#include "JSElement.h" +#include "PlatformContextCairo.h" +#include "PrintContext.h" +#include "RenderListItem.h" +#include "RenderTreeAsText.h" +#include "RenderView.h" +#include "ScriptController.h" +#include "SubstituteData.h" +#include "webkitenumtypes.h" +#include "webkitglobalsprivate.h" +#include "webkitmarshal.h" +#include "webkitnetworkrequestprivate.h" +#include "webkitnetworkresponseprivate.h" +#include "webkitsecurityoriginprivate.h" +#include "webkitwebframeprivate.h" +#include "webkitwebview.h" +#include "webkitwebviewprivate.h" +#include <JavaScriptCore/APICast.h> +#include <atk/atk.h> +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +#if ENABLE(SVG) +#include "SVGSMILElement.h" +#endif + +/** + * SECTION:webkitwebframe + * @short_description: The content of a #WebKitWebView + * + * A #WebKitWebView contains a main #WebKitWebFrame. A #WebKitWebFrame + * contains the content of one URI. The URI and name of the frame can + * be retrieved, the load status and progress can be observed using the + * signals and can be controlled using the methods of the #WebKitWebFrame. + * A #WebKitWebFrame can have any number of children and one child can + * be found by using #webkit_web_frame_find_frame. + * + * <informalexample><programlisting> + * /<!-- -->* Get the frame from the #WebKitWebView *<!-- -->/ + * WebKitWebFrame *frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW(my_view)); + * g_print("The URI of this frame is '%s'", webkit_web_frame_get_uri (frame)); + * </programlisting></informalexample> + */ + +using namespace WebKit; +using namespace WebCore; +using namespace std; + +enum { + CLEARED, + LOAD_COMMITTED, + LOAD_DONE, + TITLE_CHANGED, + HOVERING_OVER_LINK, + SCROLLBARS_POLICY_CHANGED, + LAST_SIGNAL +}; + +enum { + PROP_0, + + PROP_NAME, + PROP_TITLE, + PROP_URI, + PROP_LOAD_STATUS, + PROP_HORIZONTAL_SCROLLBAR_POLICY, + PROP_VERTICAL_SCROLLBAR_POLICY +}; + +static guint webkit_web_frame_signals[LAST_SIGNAL] = { 0, }; + +G_DEFINE_TYPE(WebKitWebFrame, webkit_web_frame, G_TYPE_OBJECT) + +static void webkit_web_frame_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* paramSpec) +{ + WebKitWebFrame* frame = WEBKIT_WEB_FRAME(object); + + switch (propertyId) { + case PROP_NAME: + g_value_set_string(value, webkit_web_frame_get_name(frame)); + break; + case PROP_TITLE: + g_value_set_string(value, webkit_web_frame_get_title(frame)); + break; + case PROP_URI: + g_value_set_string(value, webkit_web_frame_get_uri(frame)); + break; + case PROP_LOAD_STATUS: + g_value_set_enum(value, webkit_web_frame_get_load_status(frame)); + break; + case PROP_HORIZONTAL_SCROLLBAR_POLICY: + g_value_set_enum(value, webkit_web_frame_get_horizontal_scrollbar_policy(frame)); + break; + case PROP_VERTICAL_SCROLLBAR_POLICY: + g_value_set_enum(value, webkit_web_frame_get_vertical_scrollbar_policy(frame)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, paramSpec); + break; + } +} + +// Called from the FrameLoaderClient when it is destroyed. Normally +// the unref in the FrameLoaderClient is destroying this object as +// well but due reference counting a user might have added a reference... +void webkit_web_frame_core_frame_gone(WebKitWebFrame* frame) +{ + ASSERT(WEBKIT_IS_WEB_FRAME(frame)); + WebKitWebFramePrivate* priv = frame->priv; + if (priv->coreFrame) + DOMObjectCache::clearByFrame(priv->coreFrame); + priv->coreFrame = 0; +} + +static WebKitWebDataSource* webkit_web_frame_get_data_source_from_core_loader(WebCore::DocumentLoader* loader) +{ + return loader ? static_cast<WebKit::DocumentLoader*>(loader)->dataSource() : 0; +} + +static void webkit_web_frame_finalize(GObject* object) +{ + WebKitWebFrame* frame = WEBKIT_WEB_FRAME(object); + WebKitWebFramePrivate* priv = frame->priv; + + if (priv->coreFrame) { + DOMObjectCache::clearByFrame(priv->coreFrame); + priv->coreFrame->loader()->cancelAndClear(); + priv->coreFrame = 0; + } + + g_free(priv->name); + g_free(priv->title); + g_free(priv->uri); + + G_OBJECT_CLASS(webkit_web_frame_parent_class)->finalize(object); +} + +static void webkit_web_frame_class_init(WebKitWebFrameClass* frameClass) +{ + webkitInit(); + + /* + * signals + */ + webkit_web_frame_signals[CLEARED] = g_signal_new("cleared", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + 0, + 0, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebFrame::load-done + * @web_frame: the object on which the signal is emitted + * + * Emitted when frame loading is done. + * + * Deprecated: Use the "load-status" property instead. + */ + webkit_web_frame_signals[LOAD_COMMITTED] = g_signal_new("load-committed", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + 0, + 0, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebFrame::load-done + * @web_frame: the object on which the signal is emitted + * + * Emitted when frame loading is done. + * + * Deprecated: Use the "load-status" property instead, and/or + * WebKitWebView::load-error to be notified of load errors + */ + webkit_web_frame_signals[LOAD_DONE] = g_signal_new("load-done", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + 0, + 0, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, + G_TYPE_BOOLEAN); + + /** + * WebKitWebFrame::title-changed: + * @frame: the object on which the signal is emitted + * @title: the new title + * + * When a #WebKitWebFrame changes the document title this signal is emitted. + * + * Deprecated: 1.1.18: Use "notify::title" instead. + */ + webkit_web_frame_signals[TITLE_CHANGED] = g_signal_new("title-changed", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + 0, + 0, + webkit_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + webkit_web_frame_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + 0, + 0, + webkit_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, + G_TYPE_STRING, G_TYPE_STRING); + + /** + * WebKitWebFrame::scrollbars-policy-changed: + * @web_view: the object which received the signal + * + * Signal emitted when policy for one or both of the scrollbars of + * the view has changed. The default handler will apply the new + * policy to the container that holds the #WebKitWebFrame if it is + * a #GtkScrolledWindow and the frame is the main frame. If you do + * not want this to be handled automatically, you need to handle + * this signal. + * + * The exception to this rule is that policies to disable the + * scrollbars are applied as %GTK_POLICY_AUTOMATIC instead, since + * the size request of the widget would force browser windows to + * not be resizable. + * + * You can obtain the new policies from the + * WebKitWebFrame:horizontal-scrollbar-policy and + * WebKitWebFrame:vertical-scrollbar-policy properties. + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + * + * Since: 1.1.14 + */ + webkit_web_frame_signals[SCROLLBARS_POLICY_CHANGED] = g_signal_new("scrollbars-policy-changed", + G_TYPE_FROM_CLASS(frameClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + g_signal_accumulator_true_handled, + 0, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); + + /* + * implementations of virtual methods + */ + GObjectClass* objectClass = G_OBJECT_CLASS(frameClass); + objectClass->finalize = webkit_web_frame_finalize; + objectClass->get_property = webkit_web_frame_get_property; + + /* + * properties + */ + g_object_class_install_property(objectClass, PROP_NAME, + g_param_spec_string("name", + _("Name"), + _("The name of the frame"), + 0, + WEBKIT_PARAM_READABLE)); + + g_object_class_install_property(objectClass, PROP_TITLE, + g_param_spec_string("title", + _("Title"), + _("The document title of the frame"), + 0, + WEBKIT_PARAM_READABLE)); + + g_object_class_install_property(objectClass, PROP_URI, + g_param_spec_string("uri", + _("URI"), + _("The current URI of the contents displayed by the frame"), + 0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebFrame:load-status: + * + * Determines the current status of the load. + * + * Since: 1.1.7 + */ + g_object_class_install_property(objectClass, PROP_LOAD_STATUS, + g_param_spec_enum("load-status", + "Load Status", + "Determines the current status of the load", + WEBKIT_TYPE_LOAD_STATUS, + WEBKIT_LOAD_FINISHED, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebFrame:horizontal-scrollbar-policy: + * + * Determines the current policy for the horizontal scrollbar of + * the frame. For the main frame, make sure to set the same policy + * on the scrollable widget containing the #WebKitWebView, unless + * you know what you are doing. + * + * Since: 1.1.14 + */ + g_object_class_install_property(objectClass, PROP_HORIZONTAL_SCROLLBAR_POLICY, + g_param_spec_enum("horizontal-scrollbar-policy", + _("Horizontal Scrollbar Policy"), + _("Determines the current policy for the horizontal scrollbar of the frame."), + GTK_TYPE_POLICY_TYPE, + GTK_POLICY_AUTOMATIC, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebFrame:vertical-scrollbar-policy: + * + * Determines the current policy for the vertical scrollbar of + * the frame. For the main frame, make sure to set the same policy + * on the scrollable widget containing the #WebKitWebView, unless + * you know what you are doing. + * + * Since: 1.1.14 + */ + g_object_class_install_property(objectClass, PROP_VERTICAL_SCROLLBAR_POLICY, + g_param_spec_enum("vertical-scrollbar-policy", + _("Vertical Scrollbar Policy"), + _("Determines the current policy for the vertical scrollbar of the frame."), + GTK_TYPE_POLICY_TYPE, + GTK_POLICY_AUTOMATIC, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(frameClass, sizeof(WebKitWebFramePrivate)); +} + +static void webkit_web_frame_init(WebKitWebFrame* frame) +{ + WebKitWebFramePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(frame, WEBKIT_TYPE_WEB_FRAME, WebKitWebFramePrivate); + + // TODO: Move constructor code here. + frame->priv = priv; +} + + +/** + * webkit_web_frame_new: + * @web_view: the controlling #WebKitWebView + * + * Creates a new #WebKitWebFrame initialized with a controlling #WebKitWebView. + * + * Returns: a new #WebKitWebFrame + * + * Deprecated: 1.0.2: #WebKitWebFrame can only be used to inspect existing + * frames. + **/ +WebKitWebFrame* webkit_web_frame_new(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + WebKitWebFrame* frame = WEBKIT_WEB_FRAME(g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL)); + WebKitWebFramePrivate* priv = frame->priv; + WebKitWebViewPrivate* viewPriv = webView->priv; + + priv->webView = webView; + WebKit::FrameLoaderClient* client = new WebKit::FrameLoaderClient(frame); + priv->coreFrame = Frame::create(viewPriv->corePage, 0, client).get(); + priv->coreFrame->init(); + + priv->origin = 0; + + return frame; +} + +/** + * webkit_web_frame_get_title: + * @frame: a #WebKitWebFrame + * + * Returns the @frame's document title + * + * Return value: the title of @frame + */ +G_CONST_RETURN gchar* webkit_web_frame_get_title(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + WebKitWebFramePrivate* priv = frame->priv; + return priv->title; +} + +/** + * webkit_web_frame_get_uri: + * @frame: a #WebKitWebFrame + * + * Returns the current URI of the contents displayed by the @frame + * + * Return value: the URI of @frame + */ +G_CONST_RETURN gchar* webkit_web_frame_get_uri(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + WebKitWebFramePrivate* priv = frame->priv; + return priv->uri; +} + +/** + * webkit_web_frame_get_web_view: + * @frame: a #WebKitWebFrame + * + * Returns the #WebKitWebView that manages this #WebKitWebFrame. + * + * The #WebKitWebView returned manages the entire hierarchy of #WebKitWebFrame + * objects that contains @frame. + * + * Return value: (transfer none): the #WebKitWebView that manages @frame + */ +WebKitWebView* webkit_web_frame_get_web_view(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + WebKitWebFramePrivate* priv = frame->priv; + return priv->webView; +} + +/** + * webkit_web_frame_get_name: + * @frame: a #WebKitWebFrame + * + * Returns the @frame's name + * + * Return value: the name of @frame. This method will return NULL if + * the #WebKitWebFrame is invalid or an empty string if it is not backed + * by a live WebCore frame. + */ +G_CONST_RETURN gchar* webkit_web_frame_get_name(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + Frame* coreFrame = core(frame); + if (!coreFrame) + return ""; + + WebKitWebFramePrivate* priv = frame->priv; + CString frameName = coreFrame->tree()->uniqueName().string().utf8(); + if (!g_strcmp0(frameName.data(), priv->name)) + return priv->name; + + g_free(priv->name); + priv->name = g_strdup(frameName.data()); + return priv->name; +} + +/** + * webkit_web_frame_get_parent: + * @frame: a #WebKitWebFrame + * + * Returns the @frame's parent frame, or %NULL if it has none. + * + * Return value: (transfer none): the parent #WebKitWebFrame or %NULL in case there is none + */ +WebKitWebFrame* webkit_web_frame_get_parent(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return 0; + + return kit(coreFrame->tree()->parent()); +} + +/** + * webkit_web_frame_load_uri: + * @frame: a #WebKitWebFrame + * @uri: an URI string + * + * Requests loading of the specified URI string. + * + * Since: 1.1.1 + */ +void webkit_web_frame_load_uri(WebKitWebFrame* frame, const gchar* uri) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + g_return_if_fail(uri); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return; + + coreFrame->loader()->load(ResourceRequest(KURL(KURL(), String::fromUTF8(uri))), false); +} + +static void webkit_web_frame_load_data(WebKitWebFrame* frame, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseURL, const gchar* unreachableURL) +{ + Frame* coreFrame = core(frame); + ASSERT(coreFrame); + + KURL baseKURL = baseURL ? KURL(KURL(), String::fromUTF8(baseURL)) : blankURL(); + + ResourceRequest request(baseKURL); + + RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(content, strlen(content)); + SubstituteData substituteData(sharedBuffer.release(), + mimeType ? String::fromUTF8(mimeType) : String::fromUTF8("text/html"), + encoding ? String::fromUTF8(encoding) : String::fromUTF8("UTF-8"), + KURL(KURL(), String::fromUTF8(unreachableURL)), + KURL(KURL(), String::fromUTF8(unreachableURL))); + + coreFrame->loader()->load(request, substituteData, false); +} + +/** + * webkit_web_frame_load_string: + * @frame: a #WebKitWebFrame + * @content: an URI string + * @mime_type: the MIME type, or %NULL + * @encoding: the encoding, or %NULL + * @base_uri: the base URI for relative locations + * + * Requests loading of the given @content with the specified @mime_type, + * @encoding and @base_uri. + * + * If @mime_type is %NULL, "text/html" is assumed. + * + * If @encoding is %NULL, "UTF-8" is assumed. + * + * Since: 1.1.1 + */ +void webkit_web_frame_load_string(WebKitWebFrame* frame, const gchar* content, const gchar* contentMimeType, const gchar* contentEncoding, const gchar* baseUri) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + g_return_if_fail(content); + + webkit_web_frame_load_data(frame, content, contentMimeType, contentEncoding, baseUri, 0); +} + +/** + * webkit_web_frame_load_alternate_string: + * @frame: a #WebKitWebFrame + * @content: the alternate content to display as the main page of the @frame + * @base_url: the base URI for relative locations + * @unreachable_url: the URL for the alternate page content + * + * Request loading of an alternate content for a URL that is unreachable. + * Using this method will preserve the back-forward list. The URI passed in + * @base_url has to be an absolute URI. + * + * Since: 1.1.6 + */ +void webkit_web_frame_load_alternate_string(WebKitWebFrame* frame, const gchar* content, const gchar* baseURL, const gchar* unreachableURL) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + g_return_if_fail(content); + + webkit_web_frame_load_data(frame, content, 0, 0, baseURL, unreachableURL); +} + +/** + * webkit_web_frame_load_request: + * @frame: a #WebKitWebFrame + * @request: a #WebKitNetworkRequest + * + * Connects to a given URI by initiating an asynchronous client request. + * + * Creates a provisional data source that will transition to a committed data + * source once any data has been received. Use webkit_web_frame_stop_loading() to + * stop the load. This function is typically invoked on the main frame. + */ +void webkit_web_frame_load_request(WebKitWebFrame* frame, WebKitNetworkRequest* request) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request)); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return; + + coreFrame->loader()->load(core(request), false); +} + +/** + * webkit_web_frame_stop_loading: + * @frame: a #WebKitWebFrame + * + * Stops any pending loads on @frame's data source, and those of its children. + */ +void webkit_web_frame_stop_loading(WebKitWebFrame* frame) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return; + + coreFrame->loader()->stopAllLoaders(); +} + +/** + * webkit_web_frame_reload: + * @frame: a #WebKitWebFrame + * + * Reloads the initial request. + */ +void webkit_web_frame_reload(WebKitWebFrame* frame) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return; + + coreFrame->loader()->reload(); +} + +/** + * webkit_web_frame_find_frame: + * @frame: a #WebKitWebFrame + * @name: the name of the frame to be found + * + * For pre-defined names, returns @frame if @name is "_self" or "_current", + * returns @frame's parent frame if @name is "_parent", and returns the main + * frame if @name is "_top". Also returns @frame if it is the main frame and + * @name is either "_parent" or "_top". For other names, this function returns + * the first frame that matches @name. This function searches @frame and its + * descendents first, then @frame's parent and its children moving up the + * hierarchy until a match is found. If no match is found in @frame's + * hierarchy, this function will search for a matching frame in other main + * frame hierarchies. Returns %NULL if no match is found. + * + * Return value: (transfer none): the found #WebKitWebFrame or %NULL in case none is found + */ +WebKitWebFrame* webkit_web_frame_find_frame(WebKitWebFrame* frame, const gchar* name) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + g_return_val_if_fail(name, 0); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return 0; + + String nameString = String::fromUTF8(name); + return kit(coreFrame->tree()->find(AtomicString(nameString))); +} + +/** + * webkit_web_frame_get_global_context: + * @frame: a #WebKitWebFrame + * + * Gets the global JavaScript execution context. Use this function to bridge + * between the WebKit and JavaScriptCore APIs. + * + * Return value: (transfer none): the global JavaScript context + */ +JSGlobalContextRef webkit_web_frame_get_global_context(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + Frame* coreFrame = core(frame); + if (!coreFrame) + return 0; + + return toGlobalRef(coreFrame->script()->globalObject(mainThreadNormalWorld())->globalExec()); +} + +/** + * webkit_web_frame_get_data_source: + * @frame: a #WebKitWebFrame + * + * Returns the committed data source. + * + * Return value: (transfer none): the committed #WebKitWebDataSource. + * + * Since: 1.1.14 + */ +WebKitWebDataSource* webkit_web_frame_get_data_source(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + Frame* coreFrame = core(frame); + return webkit_web_frame_get_data_source_from_core_loader(coreFrame->loader()->documentLoader()); +} + +/** + * webkit_web_frame_get_provisional_data_source: + * @frame: a #WebKitWebFrame + * + * You use the webkit_web_frame_load_request method to initiate a request that + * creates a provisional data source. The provisional data source will + * transition to a committed data source once any data has been received. Use + * webkit_web_frame_get_data_source to get the committed data source. + * + * Return value: (transfer none): the provisional #WebKitWebDataSource or %NULL if a load + * request is not in progress. + * + * Since: 1.1.14 + */ +WebKitWebDataSource* webkit_web_frame_get_provisional_data_source(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), 0); + + Frame* coreFrame = core(frame); + return webkit_web_frame_get_data_source_from_core_loader(coreFrame->loader()->provisionalDocumentLoader()); +} + +static void begin_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data) +{ + PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); + + float width = gtk_print_context_get_width(context); + float height = gtk_print_context_get_height(context); + FloatRect printRect = FloatRect(0, 0, width, height); + + printContext->begin(width); + + // TODO: Margin adjustments and header/footer support + float headerHeight = 0; + float footerHeight = 0; + float pageHeight; // height of the page adjusted by margins + printContext->computePageRects(printRect, headerHeight, footerHeight, 1.0, pageHeight); + gtk_print_operation_set_n_pages(op, printContext->pageCount()); +} + +static void draw_page_callback(GtkPrintOperation*, GtkPrintContext* gtkPrintContext, gint pageNumber, PrintContext* corePrintContext) +{ + if (pageNumber >= static_cast<gint>(corePrintContext->pageCount())) + return; + + cairo_t* cr = gtk_print_context_get_cairo_context(gtkPrintContext); + float pageWidth = gtk_print_context_get_width(gtkPrintContext); + + PlatformContextCairo platformContext(cr); + GraphicsContext graphicsContext(&platformContext); + corePrintContext->spoolPage(graphicsContext, pageNumber, pageWidth); +} + +static void end_print_callback(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data) +{ + PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); + printContext->end(); +} + +/** + * webkit_web_frame_print_full: + * @frame: a #WebKitWebFrame to be printed + * @operation: the #GtkPrintOperation to be carried + * @action: the #GtkPrintOperationAction to be performed + * @error: #GError for error return + * + * Prints the given #WebKitWebFrame, using the given #GtkPrintOperation + * and #GtkPrintOperationAction. This function wraps a call to + * gtk_print_operation_run() for printing the contents of the + * #WebKitWebFrame. + * + * Since: 1.1.5 + */ +GtkPrintOperationResult webkit_web_frame_print_full(WebKitWebFrame* frame, GtkPrintOperation* operation, GtkPrintOperationAction action, GError** error) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), GTK_PRINT_OPERATION_RESULT_ERROR); + g_return_val_if_fail(GTK_IS_PRINT_OPERATION(operation), GTK_PRINT_OPERATION_RESULT_ERROR); + + GtkWidget* topLevel = gtk_widget_get_toplevel(GTK_WIDGET(webkit_web_frame_get_web_view(frame))); + + if (!gtk_widget_is_toplevel(topLevel)) + topLevel = 0; + + Frame* coreFrame = core(frame); + if (!coreFrame) + return GTK_PRINT_OPERATION_RESULT_ERROR; + + PrintContext printContext(coreFrame); + + g_signal_connect(operation, "begin-print", G_CALLBACK(begin_print_callback), &printContext); + g_signal_connect(operation, "draw-page", G_CALLBACK(draw_page_callback), &printContext); + g_signal_connect(operation, "end-print", G_CALLBACK(end_print_callback), &printContext); + + return gtk_print_operation_run(operation, action, GTK_WINDOW(topLevel), error); +} + +/** + * webkit_web_frame_print: + * @frame: a #WebKitWebFrame + * + * Prints the given #WebKitWebFrame, by presenting a print dialog to the + * user. If you need more control over the printing process, see + * webkit_web_frame_print_full(). + * + * Since: 1.1.5 + */ +void webkit_web_frame_print(WebKitWebFrame* frame) +{ + g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); + + WebKitWebFramePrivate* priv = frame->priv; + GtkPrintOperation* operation = gtk_print_operation_new(); + GError* error = 0; + + webkit_web_frame_print_full(frame, operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error); + g_object_unref(operation); + + if (error) { + GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(priv->webView)); + GtkWidget* dialog = gtk_message_dialog_new(gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : 0, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", error->message); + + g_error_free(error); + + g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); + gtk_widget_show(dialog); + } +} + +gchar* webkit_web_frame_get_response_mime_type(WebKitWebFrame* frame) +{ + Frame* coreFrame = core(frame); + WebCore::DocumentLoader* docLoader = coreFrame->loader()->documentLoader(); + String mimeType = docLoader->responseMIMEType(); + return g_strdup(mimeType.utf8().data()); +} + +/** + * webkit_web_frame_get_load_status: + * @frame: a #WebKitWebView + * + * Determines the current status of the load. + * + * Since: 1.1.7 + */ +WebKitLoadStatus webkit_web_frame_get_load_status(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), WEBKIT_LOAD_FINISHED); + + WebKitWebFramePrivate* priv = frame->priv; + return priv->loadStatus; +} + +GtkPolicyType webkit_web_frame_get_horizontal_scrollbar_policy(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), GTK_POLICY_AUTOMATIC); + + Frame* coreFrame = core(frame); + FrameView* view = coreFrame->view(); + if (!view) + return GTK_POLICY_AUTOMATIC; + + ScrollbarMode hMode = view->horizontalScrollbarMode(); + + if (hMode == ScrollbarAlwaysOn) + return GTK_POLICY_ALWAYS; + + if (hMode == ScrollbarAlwaysOff) + return GTK_POLICY_NEVER; + + return GTK_POLICY_AUTOMATIC; +} + +GtkPolicyType webkit_web_frame_get_vertical_scrollbar_policy(WebKitWebFrame* frame) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), GTK_POLICY_AUTOMATIC); + + Frame* coreFrame = core(frame); + FrameView* view = coreFrame->view(); + if (!view) + return GTK_POLICY_AUTOMATIC; + + ScrollbarMode vMode = view->verticalScrollbarMode(); + + if (vMode == ScrollbarAlwaysOn) + return GTK_POLICY_ALWAYS; + + if (vMode == ScrollbarAlwaysOff) + return GTK_POLICY_NEVER; + + return GTK_POLICY_AUTOMATIC; +} + +/** + * webkit_web_frame_get_security_origin: + * @frame: a #WebKitWebFrame + * + * Returns the @frame's security origin. + * + * Return value: (transfer none): the security origin of @frame + * + * Since: 1.1.14 + */ +WebKitSecurityOrigin* webkit_web_frame_get_security_origin(WebKitWebFrame* frame) +{ + WebKitWebFramePrivate* priv = frame->priv; + if (!priv->coreFrame || !priv->coreFrame->document() || !priv->coreFrame->document()->securityOrigin()) + return 0; + + if (priv->origin && priv->origin->priv->coreOrigin.get() == priv->coreFrame->document()->securityOrigin()) + return priv->origin; + + if (priv->origin) + g_object_unref(priv->origin); + + priv->origin = kit(priv->coreFrame->document()->securityOrigin()); + return priv->origin; +} + +/** + * webkit_web_frame_get_network_response: + * @frame: a #WebKitWebFrame + * + * Returns a #WebKitNetworkResponse object representing the response + * that was given to the request for the given frame, or NULL if the + * frame was not created by a load. You must unref the object when you + * are done with it. + * + * Return value: (transfer full): a #WebKitNetworkResponse object + * + * Since: 1.1.18 + */ +WebKitNetworkResponse* webkit_web_frame_get_network_response(WebKitWebFrame* frame) +{ + Frame* coreFrame = core(frame); + if (!coreFrame) + return 0; + + WebCore::DocumentLoader* loader = coreFrame->loader()->activeDocumentLoader(); + if (!loader) + return 0; + + return kitNew(loader->response()); +} + +namespace WebKit { + +WebKitWebView* getViewFromFrame(WebKitWebFrame* frame) +{ + WebKitWebFramePrivate* priv = frame->priv; + return priv->webView; +} + +WebCore::Frame* core(WebKitWebFrame* frame) +{ + if (!frame) + return 0; + + WebKitWebFramePrivate* priv = frame->priv; + return priv ? priv->coreFrame : 0; +} + +WebKitWebFrame* kit(WebCore::Frame* coreFrame) +{ + if (!coreFrame) + return 0; + + ASSERT(coreFrame->loader()); + WebKit::FrameLoaderClient* client = static_cast<WebKit::FrameLoaderClient*>(coreFrame->loader()->client()); + return client ? client->webFrame() : 0; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebframe.h b/Source/WebKit/gtk/webkit/webkitwebframe.h new file mode 100644 index 0000000..28d7113 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebframe.h @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebframe_h +#define webkitwebframe_h + +#include <glib-object.h> +#include <gtk/gtk.h> + +#include <JavaScriptCore/JSBase.h> + +#include <webkit/webkitdefines.h> +#include <webkit/webkitnetworkrequest.h> +#include <webkit/webkitwebdatasource.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_FRAME (webkit_web_frame_get_type()) +#define WEBKIT_WEB_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_FRAME, WebKitWebFrame)) +#define WEBKIT_WEB_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_FRAME, WebKitWebFrameClass)) +#define WEBKIT_IS_WEB_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_FRAME)) +#define WEBKIT_IS_WEB_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_FRAME)) +#define WEBKIT_WEB_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_FRAME, WebKitWebFrameClass)) + +typedef struct _WebKitWebFramePrivate WebKitWebFramePrivate; + +struct _WebKitWebFrame { + GObject parent_instance; + + /*< private >*/ + WebKitWebFramePrivate *priv; +}; + +struct _WebKitWebFrameClass { + GObjectClass parent_class; + + /*< public >*/ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); + void (*_webkit_reserved5) (void); + void (*_webkit_reserved6) (void); +}; + +/** + * WebKitLoadStatus + * @WEBKIT_LOAD_PROVISIONAL: No data has been received yet, empty + * structures have been allocated to perform the load; the load may + * still fail for transport issues such as not being able to resolve a + * name, or connect to a port. + * @WEBKIT_LOAD_COMMITTED: The first data chunk has arrived, meaning + * that the necessary transport requirements are stabilished, and the + * load is being performed. + * @WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT: The first layout with + * actual visible content happened; one or more layouts may have + * happened before that caused nothing to be visible on the screen, + * because the data available at the time was not significant enough. + * @WEBKIT_LOAD_FINISHED: This state means that everything that was + * required to display the page has been loaded. + * @WEBKIT_LOAD_FAILED: This state means that some error occurred + * during the page load that prevented it from being completed. You + * can connect to the #WebKitWebView::load-error signal if you want to + * know precisely what kind of error occurred. + */ +typedef enum { + WEBKIT_LOAD_PROVISIONAL, + WEBKIT_LOAD_COMMITTED, + WEBKIT_LOAD_FINISHED, + WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT, + WEBKIT_LOAD_FAILED +} WebKitLoadStatus; + +WEBKIT_API GType +webkit_web_frame_get_type (void); + +#ifndef WEBKIT_DISABLE_DEPRECATED +WEBKIT_API WebKitWebFrame * +webkit_web_frame_new (WebKitWebView *web_view); +#endif + +WEBKIT_API WebKitWebView * +webkit_web_frame_get_web_view (WebKitWebFrame *frame); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_frame_get_name (WebKitWebFrame *frame); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_frame_get_title (WebKitWebFrame *frame); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_frame_get_uri (WebKitWebFrame *frame); + +WEBKIT_API WebKitWebFrame* +webkit_web_frame_get_parent (WebKitWebFrame *frame); + +WEBKIT_API void +webkit_web_frame_load_uri (WebKitWebFrame *frame, + const gchar *uri); + +WEBKIT_API void +webkit_web_frame_load_string (WebKitWebFrame *frame, + const gchar *content, + const gchar *mime_type, + const gchar *encoding, + const gchar *base_uri); + +WEBKIT_API void +webkit_web_frame_load_alternate_string (WebKitWebFrame *frame, + const gchar *content, + const gchar *base_url, + const gchar *unreachable_url); + +WEBKIT_API void +webkit_web_frame_load_request (WebKitWebFrame *frame, + WebKitNetworkRequest *request); + +WEBKIT_API void +webkit_web_frame_stop_loading (WebKitWebFrame *frame); + +WEBKIT_API void +webkit_web_frame_reload (WebKitWebFrame *frame); + +WEBKIT_API WebKitWebFrame * +webkit_web_frame_find_frame (WebKitWebFrame *frame, + const gchar *name); + +WEBKIT_API JSGlobalContextRef +webkit_web_frame_get_global_context (WebKitWebFrame *frame); + +WEBKIT_API GtkPrintOperationResult +webkit_web_frame_print_full (WebKitWebFrame *frame, + GtkPrintOperation *operation, + GtkPrintOperationAction action, + GError **error); + +WEBKIT_API void +webkit_web_frame_print (WebKitWebFrame *frame); + +WEBKIT_API WebKitLoadStatus +webkit_web_frame_get_load_status (WebKitWebFrame *frame); + +WEBKIT_API GtkPolicyType +webkit_web_frame_get_horizontal_scrollbar_policy (WebKitWebFrame *frame); + +WEBKIT_API GtkPolicyType +webkit_web_frame_get_vertical_scrollbar_policy (WebKitWebFrame *frame); + +WEBKIT_API WebKitWebDataSource * +webkit_web_frame_get_data_source (WebKitWebFrame *frame); + +WEBKIT_API WebKitWebDataSource * +webkit_web_frame_get_provisional_data_source (WebKitWebFrame *frame); + +WEBKIT_API WebKitSecurityOrigin* +webkit_web_frame_get_security_origin (WebKitWebFrame *frame); + +WEBKIT_API WebKitNetworkResponse* +webkit_web_frame_get_network_response (WebKitWebFrame *frame); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebframeprivate.h b/Source/WebKit/gtk/webkit/webkitwebframeprivate.h new file mode 100644 index 0000000..80210d8 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebframeprivate.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebframeprivate_h +#define webkitwebframeprivate_h + +#include "Frame.h" +#include "webkitwebframe.h" + +namespace WebKit { + +WebKitWebView* getViewFromFrame(WebKitWebFrame*); + +WebCore::Frame* core(WebKitWebFrame*); +WebKitWebFrame* kit(WebCore::Frame*); + +} + +extern "C" { + +typedef struct _WebKitWebFramePrivate WebKitWebFramePrivate; +struct _WebKitWebFramePrivate { + WebCore::Frame* coreFrame; + WebKitWebView* webView; + + gchar* name; + gchar* title; + gchar* uri; + WebKitLoadStatus loadStatus; + WebKitSecurityOrigin* origin; +}; + +void webkit_web_frame_core_frame_gone(WebKitWebFrame*); + +// FIXME: move this functionality into 'WebKitWebDataSource'? +WEBKIT_API gchar* webkit_web_frame_get_response_mime_type(WebKitWebFrame*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebhistoryitem.cpp b/Source/WebKit/gtk/webkit/webkitwebhistoryitem.cpp new file mode 100644 index 0000000..015d770 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebhistoryitem.cpp @@ -0,0 +1,530 @@ +/* + * Copyright (C) 2008, 2009 Jan Michael C. Alonzo + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebhistoryitem.h" + +#include "HistoryItem.h" +#include "KURL.h" +#include "PlatformString.h" +#include "webkitglobalsprivate.h" +#include "webkitwebhistoryitemprivate.h" +#include <glib.h> +#include <glib/gi18n-lib.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitwebhistoryitem + * @short_description: One item of the #WebKitWebBackForwardList and or global history + * @see_also: #WebKitWebBackForwardList + * + * A history item consists out of a title and a uri. It can be part of the + * #WebKitWebBackForwardList and the global history. The global history is used + * for coloring the links of visited sites. #WebKitWebHistoryItem's constructed with + * #webkit_web_history_item_new and #webkit_web_history_item_new_with_data are + * automatically added to the global history. + * + * <informalexample><programlisting> + * /<!-- -->* Inject a visited page into the global history *<!-- -->/ + * webkit_web_history_item_new_with_data("http://www.gnome.org/", "GNOME: The Free Software Desktop Project"); + * webkit_web_history_item_new_with_data("http://www.webkit.org/", "The WebKit Open Source Project"); + * </programlisting></informalexample> + * + */ + +using namespace WebKit; + +struct _WebKitWebHistoryItemPrivate { + WebCore::HistoryItem* historyItem; + + WTF::CString title; + WTF::CString alternateTitle; + WTF::CString uri; + WTF::CString originalUri; + + gboolean disposed; +}; + +enum { + PROP_0, + + PROP_TITLE, + PROP_ALTERNATE_TITLE, + PROP_URI, + PROP_ORIGINAL_URI, + PROP_LAST_VISITED_TIME +}; + +G_DEFINE_TYPE(WebKitWebHistoryItem, webkit_web_history_item, G_TYPE_OBJECT); + +static void webkit_web_history_item_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); + +static void webkit_web_history_item_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); + +GHashTable* webkit_history_items() +{ + static GHashTable* historyItems = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref); + return historyItems; +} + +void webkit_history_item_add(WebKitWebHistoryItem* webHistoryItem, WebCore::HistoryItem* historyItem) +{ + g_return_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem)); + + GHashTable* table = webkit_history_items(); + g_hash_table_insert(table, historyItem, webHistoryItem); +} + +static void webkit_web_history_item_dispose(GObject* object) +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + + if (!priv->disposed) { + WebCore::HistoryItem* item = core(webHistoryItem); + item->deref(); + priv->disposed = true; + } + + G_OBJECT_CLASS(webkit_web_history_item_parent_class)->dispose(object); +} + +static void webkit_web_history_item_finalize(GObject* object) +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + + priv->title = WTF::CString(); + priv->alternateTitle = WTF::CString(); + priv->uri = WTF::CString(); + priv->originalUri = WTF::CString(); + + G_OBJECT_CLASS(webkit_web_history_item_parent_class)->finalize(object); +} + +static void webkit_web_history_item_class_init(WebKitWebHistoryItemClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = webkit_web_history_item_dispose; + gobject_class->finalize = webkit_web_history_item_finalize; + gobject_class->set_property = webkit_web_history_item_set_property; + gobject_class->get_property = webkit_web_history_item_get_property; + + webkitInit(); + + /** + * WebKitWebHistoryItem:title: + * + * The title of the history item. + * + * Since: 1.0.2 + */ + g_object_class_install_property(gobject_class, + PROP_TITLE, + g_param_spec_string( + "title", + _("Title"), + _("The title of the history item"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebHistoryItem:alternate-title: + * + * The alternate title of the history item. + * + * Since: 1.0.2 + */ + g_object_class_install_property(gobject_class, + PROP_ALTERNATE_TITLE, + g_param_spec_string( + "alternate-title", + _("Alternate Title"), + _("The alternate title of the history item"), + NULL, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebHistoryItem:uri: + * + * The URI of the history item. + * + * Since: 1.0.2 + */ + g_object_class_install_property(gobject_class, + PROP_URI, + g_param_spec_string( + "uri", + _("URI"), + _("The URI of the history item"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebHistoryItem:original-uri: + * + * The original URI of the history item. + * + * Since: 1.0.2 + */ + g_object_class_install_property(gobject_class, + PROP_ORIGINAL_URI, + g_param_spec_string( + "original-uri", + _("Original URI"), + _("The original URI of the history item"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebHistoryItem:last-visited-time: + * + * The time at which the history item was last visited. + * + * Since: 1.0.2 + */ + g_object_class_install_property(gobject_class, + PROP_LAST_VISITED_TIME, + g_param_spec_double( + "last-visited-time", + _("Last visited Time"), + _("The time at which the history item was last visited"), + 0, G_MAXDOUBLE, 0, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(gobject_class, sizeof(WebKitWebHistoryItemPrivate)); +} + +static void webkit_web_history_item_init(WebKitWebHistoryItem* webHistoryItem) +{ + webHistoryItem->priv = G_TYPE_INSTANCE_GET_PRIVATE(webHistoryItem, WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItemPrivate); +} + +static void webkit_web_history_item_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); + + switch(prop_id) { + case PROP_ALTERNATE_TITLE: + webkit_web_history_item_set_alternate_title(webHistoryItem, g_value_get_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_history_item_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(object); + + switch (prop_id) { + case PROP_TITLE: + g_value_set_string(value, webkit_web_history_item_get_title(webHistoryItem)); + break; + case PROP_ALTERNATE_TITLE: + g_value_set_string(value, webkit_web_history_item_get_alternate_title(webHistoryItem)); + break; + case PROP_URI: + g_value_set_string(value, webkit_web_history_item_get_uri(webHistoryItem)); + break; + case PROP_ORIGINAL_URI: + g_value_set_string(value, webkit_web_history_item_get_original_uri(webHistoryItem)); + break; + case PROP_LAST_VISITED_TIME: + g_value_set_double(value, webkit_web_history_item_get_last_visited_time(webHistoryItem)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +/* Helper function to create a new WebHistoryItem instance when needed */ +WebKitWebHistoryItem* webkit_web_history_item_new_with_core_item(PassRefPtr<WebCore::HistoryItem> historyItem) +{ + return kit(historyItem); +} + + +/** + * webkit_web_history_item_new: + * + * Creates a new #WebKitWebHistoryItem instance + * + * Return value: the new #WebKitWebHistoryItem + */ +WebKitWebHistoryItem* webkit_web_history_item_new() +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL)); + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + + RefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create(); + priv->historyItem = item.release().releaseRef(); + webkit_history_item_add(webHistoryItem, priv->historyItem); + + return webHistoryItem; +} + +/** + * webkit_web_history_item_new_with_data: + * @uri: the uri of the page + * @title: the title of the page + * + * Creates a new #WebKitWebHistoryItem with the given URI and title + * + * Return value: the new #WebKitWebHistoryItem + */ +WebKitWebHistoryItem* webkit_web_history_item_new_with_data(const gchar* uri, const gchar* title) +{ + WebKitWebHistoryItem* webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL)); + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + + WebCore::KURL historyUri(WebCore::KURL(), uri); + WTF::String historyTitle = WTF::String::fromUTF8(title); + RefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create(historyUri, historyTitle, 0); + priv->historyItem = item.release().releaseRef(); + webkit_history_item_add(webHistoryItem, priv->historyItem); + + return webHistoryItem; +} + +/** + * webkit_web_history_item_get_title: + * @web_history_item: a #WebKitWebHistoryItem + * + * Returns: the page title of @web_history_item + */ +G_CONST_RETURN gchar* webkit_web_history_item_get_title(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(webHistoryItem); + + g_return_val_if_fail(item, NULL); + + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + priv->title = item->title().utf8(); + + return priv->title.data(); +} + +/** + * webkit_web_history_item_get_alternate_title: + * @web_history_item: a #WebKitWebHistoryItem + * + * Returns the alternate title of @web_history_item + * + * Return value: the alternate title of @web_history_item + */ +G_CONST_RETURN gchar* webkit_web_history_item_get_alternate_title(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(webHistoryItem); + + g_return_val_if_fail(item, NULL); + + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + priv->alternateTitle = item->alternateTitle().utf8(); + + return priv->alternateTitle.data(); +} + +/** + * webkit_web_history_item_set_alternate_title: + * @web_history_item: a #WebKitWebHistoryItem + * @title: the alternate title for @this history item + * + * Sets an alternate title for @web_history_item + */ +void webkit_web_history_item_set_alternate_title(WebKitWebHistoryItem* webHistoryItem, const gchar* title) +{ + g_return_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem)); + g_return_if_fail(title); + + WebCore::HistoryItem* item = core(webHistoryItem); + + item->setAlternateTitle(WTF::String::fromUTF8(title)); + g_object_notify(G_OBJECT(webHistoryItem), "alternate-title"); +} + +/** + * webkit_web_history_item_get_uri: + * @web_history_item: a #WebKitWebHistoryItem + * + * Returns the URI of @this + * + * Return value: the URI of @web_history_item + */ +G_CONST_RETURN gchar* webkit_web_history_item_get_uri(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem)); + + g_return_val_if_fail(item, NULL); + + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + priv->uri = item->urlString().utf8(); + + return priv->uri.data(); +} + +/** + * webkit_web_history_item_get_original_uri: + * @web_history_item: a #WebKitWebHistoryItem + * + * Returns the original URI of @web_history_item. + * + * Return value: the original URI of @web_history_item + */ +G_CONST_RETURN gchar* webkit_web_history_item_get_original_uri(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem)); + + g_return_val_if_fail(item, NULL); + + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + priv->originalUri = item->originalURLString().utf8(); + + return webHistoryItem->priv->originalUri.data(); +} + +/** + * webkit_web_history_item_get_last_visisted_time : + * @web_history_item: a #WebKitWebHistoryItem + * + * Returns the last time @web_history_item was visited + * + * Return value: the time in seconds this @web_history_item was last visited + */ +gdouble webkit_web_history_item_get_last_visited_time(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), 0); + + WebCore::HistoryItem* item = core(WEBKIT_WEB_HISTORY_ITEM(webHistoryItem)); + + g_return_val_if_fail(item, 0); + + return item->lastVisitedTime(); +} + +/** + * webkit_web_history_item_copy: + * @web_history_item: a #WebKitWebHistoryItem + * + * Makes a copy of the item for use with other WebView objects. + * + * Since: 1.1.18 + * + * Return value: (transfer full): the new #WebKitWebHistoryItem. + */ +WebKitWebHistoryItem* webkit_web_history_item_copy(WebKitWebHistoryItem* self) +{ + WebKitWebHistoryItemPrivate* selfPrivate = self->priv; + + WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, 0)); + WebKitWebHistoryItemPrivate* priv = item->priv; + + priv->title = selfPrivate->title; + priv->alternateTitle = selfPrivate->alternateTitle; + priv->uri = selfPrivate->uri; + priv->originalUri = selfPrivate->originalUri; + + priv->historyItem = selfPrivate->historyItem->copy().releaseRef(); + + return item; +} + +/* private methods */ + +G_CONST_RETURN gchar* webkit_web_history_item_get_target(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(webHistoryItem); + + g_return_val_if_fail(item, NULL); + + WTF::CString t = item->target().utf8(); + return g_strdup(t.data()); +} + +gboolean webkit_web_history_item_is_target_item(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), false); + + WebCore::HistoryItem* item = core(webHistoryItem); + + g_return_val_if_fail(item, false); + + return item->isTargetItem(); +} + +GList* webkit_web_history_item_get_children(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + WebCore::HistoryItem* item = core(webHistoryItem); + + g_return_val_if_fail(item, NULL); + + const WebCore::HistoryItemVector& children = item->children(); + if (!children.size()) + return NULL; + + unsigned size = children.size(); + GList* kids = NULL; + for (unsigned i = 0; i < size; ++i) + kids = g_list_prepend(kids, kit(children[i].get())); + + return g_list_reverse(kids); +} + +WebCore::HistoryItem* WebKit::core(WebKitWebHistoryItem* webHistoryItem) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(webHistoryItem), NULL); + + return webHistoryItem->priv->historyItem; +} + +WebKitWebHistoryItem* WebKit::kit(PassRefPtr<WebCore::HistoryItem> historyItem) +{ + g_return_val_if_fail(historyItem, NULL); + + RefPtr<WebCore::HistoryItem> item = historyItem; + GHashTable* table = webkit_history_items(); + WebKitWebHistoryItem* webHistoryItem = (WebKitWebHistoryItem*) g_hash_table_lookup(table, item.get()); + + if (!webHistoryItem) { + webHistoryItem = WEBKIT_WEB_HISTORY_ITEM(g_object_new(WEBKIT_TYPE_WEB_HISTORY_ITEM, NULL)); + WebKitWebHistoryItemPrivate* priv = webHistoryItem->priv; + + priv->historyItem = item.release().releaseRef(); + webkit_history_item_add(webHistoryItem, priv->historyItem); + } + + return webHistoryItem; +} + diff --git a/Source/WebKit/gtk/webkit/webkitwebhistoryitem.h b/Source/WebKit/gtk/webkit/webkitwebhistoryitem.h new file mode 100644 index 0000000..1820736 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebhistoryitem.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebhistoryitem_h +#define webkitwebhistoryitem_h + +#include <glib.h> +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_HISTORY_ITEM (webkit_web_history_item_get_type()) +#define WEBKIT_WEB_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItem)) +#define WEBKIT_WEB_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItemClass)) +#define WEBKIT_IS_WEB_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_HISTORY_ITEM)) +#define WEBKIT_IS_WEB_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_HISTORY_ITEM)) +#define WEBKIT_WEB_HISTORY_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_HISTORY_ITEM, WebKitWebHistoryItemClass)) + +typedef struct _WebKitWebHistoryItemPrivate WebKitWebHistoryItemPrivate; + +struct _WebKitWebHistoryItem { + GObject parent_instance; + + /*< private >*/ + WebKitWebHistoryItemPrivate *priv; +}; + +struct _WebKitWebHistoryItemClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_history_item_get_type (void); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_history_item_new (void); + +WEBKIT_API WebKitWebHistoryItem * +webkit_web_history_item_new_with_data (const gchar *uri, + const gchar *title); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_history_item_get_title (WebKitWebHistoryItem *web_history_item); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_history_item_get_alternate_title (WebKitWebHistoryItem *web_history_item); + +WEBKIT_API void +webkit_web_history_item_set_alternate_title (WebKitWebHistoryItem *web_history_item, + const gchar *title); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_history_item_get_uri (WebKitWebHistoryItem *web_history_item); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_history_item_get_original_uri (WebKitWebHistoryItem *web_history_item); + +WEBKIT_API gdouble +webkit_web_history_item_get_last_visited_time (WebKitWebHistoryItem *web_history_item); + +WEBKIT_API WebKitWebHistoryItem* +webkit_web_history_item_copy (WebKitWebHistoryItem *web_history_item); + +G_END_DECLS + +#endif /* webkitwebhistoryitem_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebhistoryitemprivate.h b/Source/WebKit/gtk/webkit/webkitwebhistoryitemprivate.h new file mode 100644 index 0000000..22b50ee --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebhistoryitemprivate.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebhistoryitemprivate_h +#define webkitwebhistoryitemprivate_h + +#include "HistoryItem.h" + +namespace WebKit { + +WebCore::HistoryItem* core(WebKitWebHistoryItem*); +WebKitWebHistoryItem* kit(PassRefPtr<WebCore::HistoryItem>); + +} + +extern "C" { + +GHashTable* webkit_history_items(); + +WebKitWebHistoryItem* webkit_web_history_item_new_with_core_item(PassRefPtr<WebCore::HistoryItem>); + +WEBKIT_API G_CONST_RETURN gchar* webkit_web_history_item_get_target(WebKitWebHistoryItem*); + +WEBKIT_API gboolean webkit_web_history_item_is_target_item(WebKitWebHistoryItem*); + +WEBKIT_API GList* webkit_web_history_item_get_children(WebKitWebHistoryItem*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebinspector.cpp b/Source/WebKit/gtk/webkit/webkitwebinspector.cpp new file mode 100644 index 0000000..8b5b5ac --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebinspector.cpp @@ -0,0 +1,621 @@ +/* + * Copyright (C) 2008 Gustavo Noronha Silva + * Copyright (C) 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebinspector.h" + +#include "DumpRenderTreeSupportGtk.h" +#include "FocusController.h" +#include "Frame.h" +#include "HitTestRequest.h" +#include "HitTestResult.h" +#include "InspectorClientGtk.h" +#include "InspectorController.h" +#include "InspectorInstrumentation.h" +#include "IntPoint.h" +#include "Page.h" +#include "RenderLayer.h" +#include "RenderView.h" +#include "webkit/WebKitDOMNodePrivate.h" +#include "webkitglobalsprivate.h" +#include "webkitmarshal.h" +#include "webkitwebinspectorprivate.h" +#include <glib/gi18n-lib.h> + +/** + * SECTION:webkitwebinspector + * @short_description: Access to the WebKit Inspector + * + * The WebKit Inspector is a graphical tool to inspect and change + * the content of a #WebKitWebView. It also includes an interactive + * JavaScriptDebugger. Using this class one can get a GtkWidget which + * can be embedded into an application to show the inspector. + * + * The inspector is available when the #WebKitWebSettings of the + * #WebKitWebView has set the #WebKitWebSettings:enable-developer-extras + * to true otherwise no inspector is available. + * + * <informalexample><programlisting> + * /<!-- -->* Enable the developer extras *<!-- -->/ + * WebKitWebSettings *setting = webkit_web_view_get_settings (WEBKIT_WEB_VIEW(my_webview)); + * g_object_set (G_OBJECT(settings), "enable-developer-extras", TRUE, NULL); + * + * /<!-- -->* load some data or reload to be able to inspect the page*<!-- -->/ + * webkit_web_view_open (WEBKIT_WEB_VIEW(my_webview), "http://www.gnome.org"); + * + * /<!-- -->* Embed the inspector somewhere *<!-- -->/ + * WebKitWebInspector *inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW(my_webview)); + * g_signal_connect (G_OBJECT (inspector), "inspect-web-view", G_CALLBACK(create_gtk_window_around_it), NULL); + * g_signal_connect (G_OBJECT (inspector), "show-window", G_CALLBACK(show_inpector_window), NULL)); + * g_signal_connect (G_OBJECT (inspector), "notify::inspected-uri", G_CALLBACK(inspected_uri_changed_do_stuff), NULL); + * </programlisting></informalexample> + */ + +using namespace WebKit; +using namespace WebCore; + +enum { + INSPECT_WEB_VIEW, + SHOW_WINDOW, + ATTACH_WINDOW, + DETACH_WINDOW, + CLOSE_WINDOW, + FINISHED, + LAST_SIGNAL +}; + +static guint webkit_web_inspector_signals[LAST_SIGNAL] = { 0, }; + +enum { + PROP_0, + + PROP_WEB_VIEW, + PROP_INSPECTED_URI, + PROP_JAVASCRIPT_PROFILING_ENABLED, + PROP_TIMELINE_PROFILING_ENABLED +}; + +G_DEFINE_TYPE(WebKitWebInspector, webkit_web_inspector, G_TYPE_OBJECT) + +struct _WebKitWebInspectorPrivate { + WebCore::Page* page; + WebKitWebView* inspector_view; + gchar* inspected_uri; +}; + +static void webkit_web_inspector_finalize(GObject* object); + +static void webkit_web_inspector_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); + +static void webkit_web_inspector_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); + +static gboolean webkit_inspect_web_view_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy) +{ + gboolean continueEmission = TRUE; + gpointer newWebView = g_value_get_object(handlerReturn); + g_value_set_object(returnAccu, newWebView); + + if (newWebView) + continueEmission = FALSE; + + return continueEmission; +} + +static void webkit_web_inspector_class_init(WebKitWebInspectorClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + gobject_class->finalize = webkit_web_inspector_finalize; + gobject_class->set_property = webkit_web_inspector_set_property; + gobject_class->get_property = webkit_web_inspector_get_property; + + /** + * WebKitWebInspector::inspect-web-view: + * @web_inspector: the object on which the signal is emitted + * @web_view: the #WebKitWebView which will be inspected + * + * Emitted when the user activates the 'inspect' context menu item + * to inspect a web view. The application which is interested in + * the inspector should create a window, or otherwise add the + * #WebKitWebView it creates to an existing window. + * + * You don't need to handle the reference count of the + * #WebKitWebView instance you create; the widget to which you add + * it will do that. + * + * Return value: (transfer none): a newly allocated #WebKitWebView or %NULL + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[INSPECT_WEB_VIEW] = g_signal_new("inspect-web-view", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + webkit_inspect_web_view_request_handled, + NULL, + webkit_marshal_OBJECT__OBJECT, + WEBKIT_TYPE_WEB_VIEW , 1, + WEBKIT_TYPE_WEB_VIEW); + + /** + * WebKitWebInspector::show-window: + * @web_inspector: the object on which the signal is emitted + * @return: %TRUE if the signal has been handled + * + * Emitted when the inspector window should be displayed. Notice + * that the window must have been created already by handling + * #WebKitWebInspector::inspect-web-view. + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[SHOW_WINDOW] = g_signal_new("show-window", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN , 0); + + /** + * WebKitWebInspector::attach-window: + * @web_inspector: the object on which the signal is emitted + * @return: %TRUE if the signal has been handled + * + * Emitted when the inspector should appear at the same window as + * the #WebKitWebView being inspected. + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[ATTACH_WINDOW] = g_signal_new("attach-window", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN , 0); + + /** + * WebKitWebInspector::detach-window: + * @web_inspector: the object on which the signal is emitted + * @return: %TRUE if the signal has been handled + * + * Emitted when the inspector should appear in a separate window. + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[DETACH_WINDOW] = g_signal_new("detach-window", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN , 0); + + /** + * WebKitWebInspector::close-window: + * @web_inspector: the object on which the signal is emitted + * @return: %TRUE if the signal has been handled + * + * Emitted when the inspector window should be closed. You can + * destroy the window or hide it so that it can be displayed again + * by handling #WebKitWebInspector::show-window later on. + * + * Notice that the inspected #WebKitWebView may no longer exist + * when this signal is emitted. + * + * Notice, too, that if you decide to destroy the window, + * #WebKitWebInspector::inspect-web-view will be emmited again, when the user + * inspects an element. + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[CLOSE_WINDOW] = g_signal_new("close-window", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN , 0); + + /** + * WebKitWebInspector::finished: + * @web_inspector: the object on which the signal is emitted + * + * Emitted when the inspection is done. You should release your + * references on the inspector at this time. The inspected + * #WebKitWebView may no longer exist when this signal is emitted. + * + * Since: 1.0.3 + */ + webkit_web_inspector_signals[FINISHED] = g_signal_new("finished", + G_TYPE_FROM_CLASS(klass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE , 0); + + /* + * properties + */ + + /** + * WebKitWebInspector:web-view: + * + * The Web View that renders the Web Inspector itself. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, PROP_WEB_VIEW, + g_param_spec_object("web-view", + _("Web View"), + _("The Web View that renders the Web Inspector itself"), + WEBKIT_TYPE_WEB_VIEW, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebInspector:inspected-uri: + * + * The URI that is currently being inspected. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, PROP_INSPECTED_URI, + g_param_spec_string("inspected-uri", + _("Inspected URI"), + _("The URI that is currently being inspected"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebInspector:javascript-profiling-enabled + * + * This is enabling JavaScript profiling in the Inspector. This means + * that Console.profiles will return the profiles. + * + * Since: 1.1.1 + */ + g_object_class_install_property(gobject_class, + PROP_JAVASCRIPT_PROFILING_ENABLED, + g_param_spec_boolean( + "javascript-profiling-enabled", + _("Enable JavaScript profiling"), + _("Profile the executed JavaScript."), + FALSE, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebInspector:timeline-profiling-enabled + * + * This is enabling Timeline profiling in the Inspector. + * + * Since: 1.1.17 + */ + g_object_class_install_property(gobject_class, + PROP_TIMELINE_PROFILING_ENABLED, + g_param_spec_boolean( + "timeline-profiling-enabled", + _("Enable Timeline profiling"), + _("Profile the WebCore instrumentation."), + FALSE, + WEBKIT_PARAM_READWRITE)); + + g_type_class_add_private(klass, sizeof(WebKitWebInspectorPrivate)); +} + +static void webkit_web_inspector_init(WebKitWebInspector* web_inspector) +{ + web_inspector->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_inspector, WEBKIT_TYPE_WEB_INSPECTOR, WebKitWebInspectorPrivate); +} + +static void webkit_web_inspector_finalize(GObject* object) +{ + WebKitWebInspector* web_inspector = WEBKIT_WEB_INSPECTOR(object); + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + if (priv->inspector_view) + g_object_unref(priv->inspector_view); + + if (priv->inspected_uri) + g_free(priv->inspected_uri); + + G_OBJECT_CLASS(webkit_web_inspector_parent_class)->finalize(object); +} + +static void webkit_web_inspector_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +{ + WebKitWebInspector* web_inspector = WEBKIT_WEB_INSPECTOR(object); + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + switch(prop_id) { + case PROP_JAVASCRIPT_PROFILING_ENABLED: { +#if ENABLE(JAVASCRIPT_DEBUGGER) + bool enabled = g_value_get_boolean(value); + WebCore::InspectorController* controller = priv->page->inspectorController(); + if (enabled) + controller->enableProfiler(); + else + controller->disableProfiler(); +#else + g_message("PROP_JAVASCRIPT_PROFILING_ENABLED is not work because of the javascript debugger is disabled\n"); +#endif + break; + } + case PROP_TIMELINE_PROFILING_ENABLED: { + bool enabled = g_value_get_boolean(value); + WebCore::InspectorController* controller = priv->page->inspectorController(); + if (enabled) + controller->startTimelineProfiler(); + else + controller->stopTimelineProfiler(); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_inspector_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebInspector* web_inspector = WEBKIT_WEB_INSPECTOR(object); + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + switch (prop_id) { + case PROP_WEB_VIEW: + g_value_set_object(value, priv->inspector_view); + break; + case PROP_INSPECTED_URI: + g_value_set_string(value, priv->inspected_uri); + break; + case PROP_JAVASCRIPT_PROFILING_ENABLED: +#if ENABLE(JAVASCRIPT_DEBUGGER) + g_value_set_boolean(value, priv->page->inspectorController()->profilerEnabled()); +#else + g_message("PROP_JAVASCRIPT_PROFILING_ENABLED is not work because of the javascript debugger is disabled\n"); +#endif + break; + case PROP_TIMELINE_PROFILING_ENABLED: + g_value_set_boolean(value, priv->page->inspectorController()->timelineProfilerEnabled()); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +// internal use only +void webkit_web_inspector_set_web_view(WebKitWebInspector *web_inspector, WebKitWebView *web_view) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(web_inspector)); + g_return_if_fail(WEBKIT_IS_WEB_VIEW(web_view)); + + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + if (priv->inspector_view) + g_object_unref(priv->inspector_view); + + g_object_ref(web_view); + priv->inspector_view = web_view; +} + +/** + * webkit_web_inspector_get_web_view: + * + * Obtains the #WebKitWebView that is used to render the + * inspector. The #WebKitWebView instance is created by the + * application, by handling the #WebKitWebInspector::inspect-web-view signal. This means + * that this method may return %NULL if the user hasn't inspected + * anything. + * + * Returns: (transfer none): the #WebKitWebView instance that is used + * to render the inspector or %NULL if it is not yet created. + * + * Since: 1.0.3 + **/ +WebKitWebView* webkit_web_inspector_get_web_view(WebKitWebInspector *web_inspector) +{ + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + return priv->inspector_view; +} + +// internal use only +void webkit_web_inspector_set_inspected_uri(WebKitWebInspector* web_inspector, const gchar* inspected_uri) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(web_inspector)); + + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + g_free(priv->inspected_uri); + priv->inspected_uri = g_strdup(inspected_uri); +} + +/** + * webkit_web_inspector_get_inspected_uri: + * + * Obtains the URI that is currently being inspected. + * + * Returns: a pointer to the URI as an internally allocated string; it + * should not be freed, modified or stored. + * + * Since: 1.0.3 + **/ +const gchar* webkit_web_inspector_get_inspected_uri(WebKitWebInspector *web_inspector) +{ + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + return priv->inspected_uri; +} + +void +webkit_web_inspector_set_inspector_client(WebKitWebInspector* web_inspector, WebCore::Page* page) +{ + WebKitWebInspectorPrivate* priv = web_inspector->priv; + + priv->page = page; +} + +/** + * webkit_web_inspector_show: + * @webInspector: the #WebKitWebInspector that will be shown + * + * Causes the Web Inspector to be shown. + * + * Since: 1.1.17 + */ +void webkit_web_inspector_show(WebKitWebInspector* webInspector) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(webInspector)); + + WebKitWebInspectorPrivate* priv = webInspector->priv; + + Frame* frame = priv->page->focusController()->focusedOrMainFrame(); + FrameView* view = frame->view(); + + if (!view) + return; + + priv->page->inspectorController()->show(); +} + +/** + * webkit_web_inspector_inspect_node: + * @web_inspector: the #WebKitWebInspector that will do the inspection + * @node: the #WebKitDOMNode to inspect + * + * Causes the Web Inspector to inspect the given node. + * + * Since: 1.3.7 + */ +void webkit_web_inspector_inspect_node(WebKitWebInspector* webInspector, WebKitDOMNode* node) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(webInspector)); + g_return_if_fail(WEBKIT_DOM_IS_NODE(node)); + + webInspector->priv->page->inspectorController()->inspect(core(node)); +} + +/** + * webkit_web_inspector_inspect_coordinates: + * @web_inspector: the #WebKitWebInspector that will do the inspection + * @x: the X coordinate of the node to be inspected + * @y: the Y coordinate of the node to be inspected + * + * Causes the Web Inspector to inspect the node that is located at the + * given coordinates of the widget. The coordinates should be relative + * to the #WebKitWebView widget, not to the scrollable content, and + * may be obtained from a #GdkEvent directly. + * + * This means @x, and @y being zero doesn't guarantee you will hit the + * left-most top corner of the content, since the contents may have + * been scrolled. + * + * Since: 1.1.17 + */ +void webkit_web_inspector_inspect_coordinates(WebKitWebInspector* webInspector, gdouble x, gdouble y) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(webInspector)); + g_return_if_fail(x >= 0 && y >= 0); + + WebKitWebInspectorPrivate* priv = webInspector->priv; + + Frame* frame = priv->page->focusController()->focusedOrMainFrame(); + FrameView* view = frame->view(); + + if (!view) + return; + + HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); + IntPoint documentPoint = view->windowToContents(IntPoint(static_cast<int>(x), static_cast<int>(y))); + HitTestResult result(documentPoint); + + frame->contentRenderer()->layer()->hitTest(request, result); + priv->page->inspectorController()->inspect(result.innerNonSharedNode()); +} + +/** + * webkit_web_inspector_close: + * @webInspector: the #WebKitWebInspector that will be closed + * + * Causes the Web Inspector to be closed. + * + * Since: 1.1.17 + */ +void webkit_web_inspector_close(WebKitWebInspector* webInspector) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(webInspector)); + + WebKitWebInspectorPrivate* priv = webInspector->priv; + priv->page->inspectorController()->close(); +} + +void webkit_web_inspector_execute_script(WebKitWebInspector* webInspector, long callId, const gchar* script) +{ + g_return_if_fail(WEBKIT_IS_WEB_INSPECTOR(webInspector)); + g_return_if_fail(script); + + WebKitWebInspectorPrivate* priv = webInspector->priv; + priv->page->inspectorController()->evaluateForTestInFrontend(callId, script); +} + +#ifdef HAVE_GSETTINGS +static bool isSchemaAvailable(const char* schemaID) +{ + const char* const* availableSchemas = g_settings_list_schemas(); + char* const* iter = const_cast<char* const*>(availableSchemas); + + while (*iter) { + if (g_str_equal(schemaID, *iter)) + return true; + iter++; + } + + return false; +} + +GSettings* inspectorGSettings() +{ + static GSettings* settings = 0; + if (settings) + return settings; + + // Unfortunately GSettings will abort the process execution if the schema is not + // installed, which is the case for when running tests, or even the introspection dump + // at build time, so check if we have the schema before trying to initialize it. + const gchar* schemaID = "org.webkitgtk-"WEBKITGTK_API_VERSION_STRING".inspector"; + if (!isSchemaAvailable(schemaID)) { + + // This warning is very common on the build bots, which hides valid warnings. + // Skip printing it if we are running inside DumpRenderTree. + if (!DumpRenderTreeSupportGtk::dumpRenderTreeModeEnabled()) + g_warning("GSettings schema not found - settings will not be used or saved."); + return 0; + } + + settings = g_settings_new(schemaID); + return settings; +} +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebinspector.h b/Source/WebKit/gtk/webkit/webkitwebinspector.h new file mode 100644 index 0000000..458e370 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebinspector.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2008 Gustavo Noronha Silva + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebinspector_h +#define webkitwebinspector_h + +#include <glib-object.h> + +#include <webkit/webkitdomdefines.h> +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_INSPECTOR (webkit_web_inspector_get_type()) +#define WEBKIT_WEB_INSPECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_INSPECTOR, WebKitWebInspector)) +#define WEBKIT_WEB_INSPECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_INSPECTOR, WebKitWebInspectorClass)) +#define WEBKIT_IS_WEB_INSPECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_INSPECTOR)) +#define WEBKIT_IS_WEB_INSPECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_INSPECTOR)) +#define WEBKIT_WEB_INSPECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_INSPECTOR, WebKitWebInspectorClass)) + +typedef struct _WebKitWebInspectorPrivate WebKitWebInspectorPrivate; + +struct _WebKitWebInspector { + GObject parent_instance; + + WebKitWebInspectorPrivate* priv; +}; + +struct _WebKitWebInspectorClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_web_inspector_get_type (void); + +WEBKIT_API WebKitWebView* +webkit_web_inspector_get_web_view(WebKitWebInspector* web_inspector); + +WEBKIT_API const gchar* +webkit_web_inspector_get_inspected_uri(WebKitWebInspector* web_inspector); + +WEBKIT_API void +webkit_web_inspector_inspect_node(WebKitWebInspector* webInspector, WebKitDOMNode* node); + +WEBKIT_API void +webkit_web_inspector_inspect_coordinates(WebKitWebInspector* web_inspector, gdouble x, gdouble y); + +WEBKIT_API void +webkit_web_inspector_show(WebKitWebInspector* webInspector); + +WEBKIT_API void +webkit_web_inspector_close(WebKitWebInspector* webInspector); +G_END_DECLS + +#endif /* webkitwebinspector_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebinspectorprivate.h b/Source/WebKit/gtk/webkit/webkitwebinspectorprivate.h new file mode 100644 index 0000000..46d57b0 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebinspectorprivate.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebinspectorprivate_h +#define webkitwebinspectorprivate_h + +extern "C" { + +#ifdef HAVE_GSETTINGS +GSettings* inspectorGSettings(); +#endif + +void webkit_web_inspector_set_inspector_client(WebKitWebInspector*, WebCore::Page*); + +void webkit_web_inspector_set_web_view(WebKitWebInspector*, WebKitWebView*); + +void webkit_web_inspector_set_inspected_uri(WebKitWebInspector*, const gchar*); + +WEBKIT_API void webkit_web_inspector_execute_script(WebKitWebInspector*, long callId, const gchar* script); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebnavigationaction.cpp b/Source/WebKit/gtk/webkit/webkitwebnavigationaction.cpp new file mode 100644 index 0000000..868e49c --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebnavigationaction.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebnavigationaction.h" + +#include "FrameLoaderTypes.h" +#include "webkitenumtypes.h" +#include "webkitglobalsprivate.h" +#include <glib/gi18n-lib.h> +#include <string.h> +#include <wtf/Assertions.h> + +static void webkit_web_navigation_action_set_target_frame(WebKitWebNavigationAction* navigationAction, const gchar* targetFrame); + +/** + * SECTION:webkitwebnavigationaction + * @short_description: Object used to report details of navigation actions + * + * #WebKitWebNavigationAction is used in signals to provide details about + * what led the navigation to happen. This includes, for instance, if the user + * clicked a link to start that navigation, and what mouse button was used. + */ + +struct _WebKitWebNavigationActionPrivate { + WebKitWebNavigationReason reason; + gchar* originalUri; + gint button; + gint modifier_state; + gchar* targetFrame; +}; + +enum { + PROP_0, + + PROP_REASON, + PROP_ORIGINAL_URI, + PROP_BUTTON, + PROP_MODIFIER_STATE, + PROP_TARGET_FRAME +}; + +G_DEFINE_TYPE(WebKitWebNavigationAction, webkit_web_navigation_action, G_TYPE_OBJECT) + + +static void webkit_web_navigation_action_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) +{ + WebKitWebNavigationAction* navigationAction = WEBKIT_WEB_NAVIGATION_ACTION(object); + + switch(propertyId) { + case PROP_REASON: + g_value_set_enum(value, webkit_web_navigation_action_get_reason(navigationAction)); + break; + case PROP_ORIGINAL_URI: + g_value_set_string(value, webkit_web_navigation_action_get_original_uri(navigationAction)); + break; + case PROP_BUTTON: + g_value_set_int(value, webkit_web_navigation_action_get_button(navigationAction)); + break; + case PROP_MODIFIER_STATE: + g_value_set_int(value, webkit_web_navigation_action_get_modifier_state(navigationAction)); + break; + case PROP_TARGET_FRAME: + g_value_set_string(value, webkit_web_navigation_action_get_target_frame(navigationAction)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); + break; + } +} + +static void webkit_web_navigation_action_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) +{ + WebKitWebNavigationAction* navigationAction = WEBKIT_WEB_NAVIGATION_ACTION(object); + WebKitWebNavigationActionPrivate* priv = navigationAction->priv; + + switch(propertyId) { + case PROP_REASON: + webkit_web_navigation_action_set_reason(navigationAction, (WebKitWebNavigationReason)g_value_get_enum(value)); + break; + case PROP_ORIGINAL_URI: + webkit_web_navigation_action_set_original_uri(navigationAction, g_value_get_string(value)); + break; + case PROP_BUTTON: + priv->button = g_value_get_int(value); + break; + case PROP_MODIFIER_STATE: + priv->modifier_state = g_value_get_int(value); + break; + case PROP_TARGET_FRAME: + webkit_web_navigation_action_set_target_frame(navigationAction, g_value_get_string(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); + break; + } +} + +static void webkit_web_navigation_action_init(WebKitWebNavigationAction* navigationAction) +{ + navigationAction->priv = G_TYPE_INSTANCE_GET_PRIVATE(navigationAction, WEBKIT_TYPE_WEB_NAVIGATION_ACTION, WebKitWebNavigationActionPrivate); +} + +static void webkit_web_navigation_action_finalize(GObject* obj) +{ + WebKitWebNavigationAction* navigationAction = WEBKIT_WEB_NAVIGATION_ACTION(obj); + WebKitWebNavigationActionPrivate* priv = navigationAction->priv; + + g_free(priv->originalUri); + + G_OBJECT_CLASS(webkit_web_navigation_action_parent_class)->finalize(obj); +} + +static void webkit_web_navigation_action_class_init(WebKitWebNavigationActionClass* requestClass) +{ + GObjectClass* objectClass = G_OBJECT_CLASS(requestClass); + + objectClass->get_property = webkit_web_navigation_action_get_property; + objectClass->set_property = webkit_web_navigation_action_set_property; + objectClass->dispose = webkit_web_navigation_action_finalize; + + /** + * WebKitWebNavigationAction:reason: + * + * The reason why this navigation is occuring. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_REASON, + g_param_spec_enum("reason", + _("Reason"), + _("The reason why this navigation is occurring"), + WEBKIT_TYPE_WEB_NAVIGATION_REASON, + WEBKIT_WEB_NAVIGATION_REASON_OTHER, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT))); + + /** + * WebKitWebNavigationAction:original-uri: + * + * The URI that was requested as the target for the navigation. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_ORIGINAL_URI, + g_param_spec_string("original-uri", + _("Original URI"), + _("The URI that was requested as the target for the navigation"), + "", + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT))); + /** + * WebKitWebNavigationAction:button: + * + * The GTK+ identifier for the mouse button used to click. Notice that GTK+ button values + * are 1, 2 and 3 for left, middle and right buttons, so they are DOM button values +1. If the action was not + * initiated by a mouse click the value will be -1. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_BUTTON, + g_param_spec_int("button", + _("Button"), + _("The button used to click"), + -1, + G_MAXINT, + -1, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebNavigationAction:modifier-state: + * + * The state of the modifier keys when the action was requested. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_MODIFIER_STATE, + g_param_spec_int("modifier-state", + _("Modifier state"), + _("A bitmask representing the state of the modifier keys"), + 0, + G_MAXINT, + 0, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + /** + * WebKitWebNavigationAction:target-frame: + * + * The target frame for the navigation. + * + * Since: 1.1.13 + */ + g_object_class_install_property(objectClass, PROP_TARGET_FRAME, + g_param_spec_string("target-frame", + _("Target frame"), + _("The target frame for the navigation"), + NULL, + (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); + + + + g_type_class_add_private(requestClass, sizeof(WebKitWebNavigationActionPrivate)); +} + +/** + * webkit_web_navigation_action_get_reason: + * @navigationAction: a #WebKitWebNavigationAction + * + * Returns the reason why WebKit is requesting a navigation. + * + * Return value: a #WebKitWebNavigationReason + * + * Since: 1.0.3 + */ +WebKitWebNavigationReason webkit_web_navigation_action_get_reason(WebKitWebNavigationAction* navigationAction) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction), WEBKIT_WEB_NAVIGATION_REASON_OTHER); + + return navigationAction->priv->reason; +} + +/** + * webkit_web_navigation_action_set_reason: + * @navigationAction: a #WebKitWebNavigationAction + * @reason: a #WebKitWebNavigationReason + * + * Sets the reason why WebKit is requesting a navigation. + * + * Since: 1.0.3 + */ +void webkit_web_navigation_action_set_reason(WebKitWebNavigationAction* navigationAction, WebKitWebNavigationReason reason) +{ + g_return_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction)); + + if (navigationAction->priv->reason == reason) + return; + + navigationAction->priv->reason = reason; + g_object_notify(G_OBJECT(navigationAction), "reason"); +} + +/** + * webkit_web_navigation_action_get_original_uri: + * @navigationAction: a #WebKitWebNavigationAction + * + * Returns the URI that was originally requested. This may differ from the + * navigation target, for instance because of a redirect. + * + * Return value: the originally requested URI + * + * Since: 1.0.3 + */ +const gchar* webkit_web_navigation_action_get_original_uri(WebKitWebNavigationAction* navigationAction) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction), NULL); + + return navigationAction->priv->originalUri; +} + +/** + * webkit_web_navigation_action_set_original_uri: + * @navigationAction: a #WebKitWebNavigationAction + * @originalUri: a URI + * + * Sets the URI that was originally requested. This may differ from the + * navigation target, for instance because of a redirect. + * + * Since: 1.0.3 + */ +void webkit_web_navigation_action_set_original_uri(WebKitWebNavigationAction* navigationAction, const gchar* originalUri) +{ + g_return_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction)); + g_return_if_fail(originalUri); + + if (navigationAction->priv->originalUri && + (!strcmp(navigationAction->priv->originalUri, originalUri))) + return; + + g_free(navigationAction->priv->originalUri); + navigationAction->priv->originalUri = g_strdup(originalUri); + g_object_notify(G_OBJECT(navigationAction), "original-uri"); +} + +/** + * webkit_web_navigation_action_get_button: + * @navigationAction: a #WebKitWebNavigationAction + * + * The GTK+ identifier for the mouse button used to click. Notice that GTK+ button values + * are 1, 2 and 3 for left, middle and right buttons, so they are DOM button values +1. If the action was not + * initiated by a mouse click the value will be -1. + * + * Return value: the mouse button used to click + * + * Since: 1.0.3 + */ +gint webkit_web_navigation_action_get_button(WebKitWebNavigationAction* navigationAction) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction), -1); + + return navigationAction->priv->button; +} + +/** + * webkit_web_navigation_action_get_modifier_state: + * @navigationAction: a #WebKitWebNavigationAction + * + * Returns a bitmask with the the state of the modifier keys. + * + * Return value: a bitmask with the state of the modifier keys + * + * Since: 1.0.3 + */ +gint webkit_web_navigation_action_get_modifier_state(WebKitWebNavigationAction* navigationAction) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction), 0); + + return navigationAction->priv->modifier_state; +} + +/** + * webkit_web_navigation_action_get_target_frame: + * @navigationAction: a #WebKitWebNavigationAction + * + * Returns the target frame of the action. + * + * Return value: the target frame of the action or NULL + * if there is no target. + * + * Since: 1.1.13 + */ +G_CONST_RETURN gchar* webkit_web_navigation_action_get_target_frame(WebKitWebNavigationAction* navigationAction) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_NAVIGATION_ACTION(navigationAction), NULL); + + return navigationAction->priv->targetFrame; +} + +static void webkit_web_navigation_action_set_target_frame(WebKitWebNavigationAction* navigationAction, const gchar* targetFrame) +{ + if (!g_strcmp0(navigationAction->priv->targetFrame, targetFrame)) + return; + + g_free(navigationAction->priv->targetFrame); + navigationAction->priv->targetFrame = g_strdup(targetFrame); + g_object_notify(G_OBJECT(navigationAction), "target-frame"); +} + +namespace WebKit { + +WebKitWebNavigationReason kit(WebCore::NavigationType type) +{ + return (WebKitWebNavigationReason)type; +} + +WebCore::NavigationType core(WebKitWebNavigationReason type) +{ + return static_cast<WebCore::NavigationType>(type); +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebnavigationaction.h b/Source/WebKit/gtk/webkit/webkitwebnavigationaction.h new file mode 100644 index 0000000..dbb47a8 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebnavigationaction.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebnavigationaction_h +#define webkitwebnavigationaction_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +/* + * The order of this enum must be the same as NavigationType in + * FrameLoaderTypes.h + */ +typedef enum { + WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED, + WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED, + WEBKIT_WEB_NAVIGATION_REASON_BACK_FORWARD, + WEBKIT_WEB_NAVIGATION_REASON_RELOAD, + WEBKIT_WEB_NAVIGATION_REASON_FORM_RESUBMITTED, + WEBKIT_WEB_NAVIGATION_REASON_OTHER, +} WebKitWebNavigationReason; + +#define WEBKIT_TYPE_WEB_NAVIGATION_ACTION (webkit_web_navigation_action_get_type()) +#define WEBKIT_WEB_NAVIGATION_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_NAVIGATION_ACTION, WebKitWebNavigationAction)) +#define WEBKIT_WEB_NAVIGATION_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_NAVIGATION_ACTION, WebKitWebNavigationActionClass)) +#define WEBKIT_IS_WEB_NAVIGATION_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_NAVIGATION_ACTION)) +#define WEBKIT_IS_WEB_NAVIGATION_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_NAVIGATION_ACTION)) +#define WEBKIT_WEB_NAVIGATION_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_NAVIGATION_ACTION, WebKitWebNavigationActionClass)) + +typedef struct _WebKitWebNavigationAction WebKitWebNavigationAction; +typedef struct _WebKitWebNavigationActionClass WebKitWebNavigationActionClass; +typedef struct _WebKitWebNavigationActionPrivate WebKitWebNavigationActionPrivate; + +struct _WebKitWebNavigationAction { + GObject parent_instance; + + /*< private >*/ + WebKitWebNavigationActionPrivate* priv; +}; + +struct _WebKitWebNavigationActionClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_navigation_action_get_type(void); + +WEBKIT_API WebKitWebNavigationReason +webkit_web_navigation_action_get_reason(WebKitWebNavigationAction* navigationAction); + +WEBKIT_API void +webkit_web_navigation_action_set_reason(WebKitWebNavigationAction* navigationAction, WebKitWebNavigationReason reason); + +WEBKIT_API const gchar* +webkit_web_navigation_action_get_original_uri(WebKitWebNavigationAction* navigationAction); + +WEBKIT_API void +webkit_web_navigation_action_set_original_uri(WebKitWebNavigationAction* navigationAction, const gchar* originalUri); + +WEBKIT_API gint +webkit_web_navigation_action_get_button(WebKitWebNavigationAction* navigationAction); + +WEBKIT_API gint +webkit_web_navigation_action_get_modifier_state(WebKitWebNavigationAction* navigationAction); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_navigation_action_get_target_frame(WebKitWebNavigationAction* navigationAction); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebnavigationactionprivate.h b/Source/WebKit/gtk/webkit/webkitwebnavigationactionprivate.h new file mode 100644 index 0000000..a8bc5ca --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebnavigationactionprivate.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebnavigationactionprivate_h +#define webkitnavigationactionprivate_h + +#include <webkit/webkitwebnavigationaction.h> + +namespace WebKit { + +WebKitWebNavigationReason kit(WebCore::NavigationType); +WebCore::NavigationType core(WebKitWebNavigationReason); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebplugin.cpp b/Source/WebKit/gtk/webkit/webkitwebplugin.cpp new file mode 100644 index 0000000..95ac614 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebplugin.cpp @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * Copyright (C) 2011 Gustavo Noronha Silva <gns@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "webkitwebplugin.h" + +#include "PluginPackage.h" +#include "webkitglobalsprivate.h" +#include "webkitwebpluginprivate.h" +#include <glib/gi18n-lib.h> + +/** + * SECTION:webkitwebplugin + * @short_description: Represents a plugin, enabling fine-grained control + * @see_also: #WebKitWebPluginDatabase + * + * This object represents a single plugin, found by WebKitGTK+ while + * scanning the various usual directories. This object can be used to + * get more information about a plugin, and enable/disable it, + * allowing fine-grained control of plugins. The list of available + * plugins can be obtained from the #WebKitWebPluginDatabase object. + */ + +using namespace WebCore; + +enum { + PROP_0, + + PROP_ENABLED +}; + +G_DEFINE_TYPE(WebKitWebPlugin, webkit_web_plugin, G_TYPE_OBJECT) + +static void freeMIMEType(WebKitWebPluginMIMEType* mimeType) +{ + if (mimeType->name) + g_free(mimeType->name); + if (mimeType->description) + g_free(mimeType->description); + if (mimeType->extensions) + g_strfreev(mimeType->extensions); + g_slice_free(WebKitWebPluginMIMEType, mimeType); +} + +static void webkit_web_plugin_finalize(GObject* object) +{ + WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(object); + WebKitWebPluginPrivate* priv = plugin->priv; + + g_free(priv->path); + + g_slist_foreach(priv->mimeTypes, (GFunc)freeMIMEType, 0); + g_slist_free(priv->mimeTypes); + + delete plugin->priv; + + G_OBJECT_CLASS(webkit_web_plugin_parent_class)->finalize(object); +} + +static void webkit_web_plugin_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* paramSpec) +{ + WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(object); + + switch (prop_id) { + case PROP_ENABLED: + g_value_set_boolean(value, webkit_web_plugin_get_enabled(plugin)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, paramSpec); + } +} + +static void webkit_web_plugin_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* paramSpec) +{ + WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(object); + + switch (prop_id) { + case PROP_ENABLED: + webkit_web_plugin_set_enabled(plugin, g_value_get_boolean(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, paramSpec); + } +} + +static void webkit_web_plugin_class_init(WebKitWebPluginClass* klass) +{ + webkitInit(); + + GObjectClass* gobjectClass = reinterpret_cast<GObjectClass*>(klass); + + gobjectClass->finalize = webkit_web_plugin_finalize; + gobjectClass->get_property = webkit_web_plugin_get_property; + gobjectClass->set_property = webkit_web_plugin_set_property; + + g_object_class_install_property(gobjectClass, + PROP_ENABLED, + g_param_spec_boolean("enabled", + _("Enabled"), + _("Whether the plugin is enabled"), + FALSE, + WEBKIT_PARAM_READWRITE)); +} + +static void webkit_web_plugin_init(WebKitWebPlugin *plugin) +{ + plugin->priv = new WebKitWebPluginPrivate(); + plugin->priv->mimeTypes = 0; +} + +namespace WebKit { +WebKitWebPlugin* kitNew(WebCore::PluginPackage* package) +{ + WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(g_object_new(WEBKIT_TYPE_WEB_PLUGIN, 0)); + + plugin->priv->corePlugin = package; + + return plugin; +} +} + +/** + * webkit_web_plugin_get_name: + * @plugin: a #WebKitWebPlugin + * + * Returns: the name string for @plugin. + * + * Since: 1.3.8 + */ +const char* webkit_web_plugin_get_name(WebKitWebPlugin* plugin) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), 0); + + WebKitWebPluginPrivate* priv = plugin->priv; + + if (!priv->name.length()) + priv->name = priv->corePlugin->name().utf8(); + + return priv->name.data(); +} + +/** + * webkit_web_plugin_get_description: + * @plugin: a #WebKitWebPlugin + * + * Returns: the description string for @plugin. + * + * Since: 1.3.8 + */ +const char* webkit_web_plugin_get_description(WebKitWebPlugin* plugin) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), 0); + + WebKitWebPluginPrivate* priv = plugin->priv; + + if (!priv->description.length()) + priv->description = priv->corePlugin->description().utf8(); + + return priv->description.data(); +} + +/** + * webkit_web_plugin_get_path: + * @plugin: a #WebKitWebPlugin + * + * Returns: the absolute path to @plugin in system filename encoding + * or %NULL on failure to convert the filename from UTF-8. + * + * Since: 1.4.0 + */ +const char* webkit_web_plugin_get_path(WebKitWebPlugin* plugin) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), 0); + + WebKitWebPluginPrivate* priv = plugin->priv; + + if (priv->path) + return priv->path; + + GError* error = 0; + priv->path = g_filename_from_utf8(priv->corePlugin->path().utf8().data(), -1, 0, 0, &error); + + if (!error) + return priv->path; + + // In the unlikely case the convertion fails, report the error and make sure we free + // any partial convertion that ended up in the variable. + g_free(priv->path); + priv->path = 0; + + g_warning("Failed to convert '%s' to system filename encoding: %s", priv->corePlugin->path().utf8().data(), error->message); + + g_clear_error(&error); + + return 0; +} + + +/** + * webkit_web_plugin_get_mimetypes: + * @plugin: a #WebKitWebPlugin + * + * Returns all the #WebKitWebPluginMIMEType that @plugin is handling + * at the moment. + * + * Returns: (transfer none) (element-type WebKitWebPluginMIMEType): a #GSList of #WebKitWebPluginMIMEType + * + * Since: 1.3.8 + */ +GSList* webkit_web_plugin_get_mimetypes(WebKitWebPlugin* plugin) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), 0); + + WebKitWebPluginPrivate* priv = plugin->priv; + + if (priv->mimeTypes) + return priv->mimeTypes; + + const MIMEToDescriptionsMap& mimeToDescriptions = priv->corePlugin->mimeToDescriptions(); + MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end(); + + for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) { + WebKitWebPluginMIMEType* mimeType = g_slice_new0(WebKitWebPluginMIMEType); + mimeType->name = g_strdup(it->first.utf8().data()); + mimeType->description = g_strdup(it->second.utf8().data()); + + Vector<String> extensions = priv->corePlugin->mimeToExtensions().get(it->first); + mimeType->extensions = static_cast<gchar**>(g_malloc0(extensions.size() + 1)); + for (unsigned i = 0; i < extensions.size(); i++) + mimeType->extensions[i] = g_strdup(extensions[i].utf8().data()); + + priv->mimeTypes = g_slist_append(priv->mimeTypes, mimeType); + } + + return priv->mimeTypes; +} + +/** + * webkit_web_plugin_set_enabled: + * @plugin: a #WebKitWebPlugin + * @enabled: whether to enable the plugin + * + * Sets the enabled status of the @plugin. + * + * Since: 1.3.8 + */ +void webkit_web_plugin_set_enabled(WebKitWebPlugin* plugin, gboolean enabled) +{ + g_return_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin)); + WebKitWebPluginPrivate* priv = plugin->priv; + + ASSERT(priv->corePlugin); + if (priv->corePlugin->isEnabled() == enabled) + return; + + priv->corePlugin->setEnabled(enabled); + + g_object_notify(G_OBJECT(plugin), "enabled"); +} + +/** + * webkit_web_plugin_get_enabled: + * @plugin: a #WebKitWebPlugin + * + * Returns: %TRUE if the plugin is enabled, %FALSE otherwise + * + * Since: 1.3.8 + */ +gboolean webkit_web_plugin_get_enabled(WebKitWebPlugin* plugin) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), FALSE); + + ASSERT(plugin->priv->corePlugin); + return plugin->priv->corePlugin->isEnabled(); +} diff --git a/Source/WebKit/gtk/webkit/webkitwebplugin.h b/Source/WebKit/gtk/webkit/webkitwebplugin.h new file mode 100644 index 0000000..9205674 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebplugin.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef webkitwebplugin_h +#define webkitwebplugin_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_PLUGIN (webkit_web_plugin_get_type()) +#define WEBKIT_WEB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_PLUGIN, WebKitWebPlugin)) +#define WEBKIT_WEB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_PLUGIN, WebKitWebPluginClass)) +#define WEBKIT_IS_WEB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_PLUGIN)) +#define WEBKIT_IS_WEB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_PLUGIN)) +#define WEBKIT_WEB_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_PLUGIN, WebKitWebPluginClass)) + +typedef struct _WebKitWebPluginPrivate WebKitWebPluginPrivate; + +/** + * WebKitWebPluginMIMEType: + * @name: the name of the MIME type. + * @description: the description of the MIME type. + * @extensions: a %NULL-terminated array with the extensions + * associated with this MIME type. + * + * A structure representing one of the MIME types associated with a + * plugin. A #GSList of these objects will be returned by + * #webkit_web_plugin_get_mimetypes, use + * #webkit_web_plugin_mime_type_list_free to free it. + * + * Since: 1.3.8 + */ +typedef struct _WebKitWebPluginMIMEType { + char* name; + char* description; + char** extensions; +} WebKitWebPluginMIMEType; + +struct _WebKitWebPluginClass { + GObjectClass parentClass; +}; + +struct _WebKitWebPlugin { + GObject parentInstance; + + WebKitWebPluginPrivate* priv; +}; + +WEBKIT_API GType +webkit_web_plugin_get_type (void) G_GNUC_CONST; + +WEBKIT_API const char* +webkit_web_plugin_get_name (WebKitWebPlugin*); + +WEBKIT_API const char* +webkit_web_plugin_get_description (WebKitWebPlugin*); + +WEBKIT_API const char* +webkit_web_plugin_get_path (WebKitWebPlugin*); + +WEBKIT_API GSList* +webkit_web_plugin_get_mimetypes (WebKitWebPlugin*); + +WEBKIT_API void +webkit_web_plugin_set_enabled (WebKitWebPlugin*, gboolean); + +WEBKIT_API gboolean +webkit_web_plugin_get_enabled (WebKitWebPlugin*); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebplugindatabase.cpp b/Source/WebKit/gtk/webkit/webkitwebplugindatabase.cpp new file mode 100644 index 0000000..1ed5205 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebplugindatabase.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "webkitwebplugindatabase.h" + +#include "PluginDatabase.h" +#include "webkitglobalsprivate.h" +#include "webkitwebplugindatabaseprivate.h" +#include "webkitwebpluginprivate.h" + +/** + * SECTION:webkitwebplugindatabase + * @short_description: Provides information about the plugins the engine knows about + * @see_also: #WebKitWebPlugin + * + * This object allows you to query information about the plugins found + * by the engine while scanning the usual directories. You can then + * use the #WebKitWebPlugin objects to get more information or + * enable/disable individual plugins. + */ + +using namespace WebKit; +using namespace WebCore; + +G_DEFINE_TYPE(WebKitWebPluginDatabase, webkit_web_plugin_database, G_TYPE_OBJECT) + +static void webkit_web_plugin_database_dispose(GObject* object) +{ + G_OBJECT_CLASS(webkit_web_plugin_database_parent_class)->dispose(object); +} + +static void webkit_web_plugin_database_class_init(WebKitWebPluginDatabaseClass* klass) +{ + webkitInit(); + + GObjectClass* gobjectClass = reinterpret_cast<GObjectClass*>(klass); + + gobjectClass->dispose = webkit_web_plugin_database_dispose; + + g_type_class_add_private(klass, sizeof(WebKitWebPluginDatabasePrivate)); +} + +static void webkit_web_plugin_database_init(WebKitWebPluginDatabase* database) +{ + WebKitWebPluginDatabasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(database, WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabasePrivate); + database->priv = priv; + + priv->coreDatabase = PluginDatabase::installedPlugins(); +} + +/** + * webkit_web_plugin_database_list_free: + * @list: a #WebKitWebPluginDatabasePluginList + * + * Frees @list. + * + * Since: 1.3.8 + */ +void webkit_web_plugin_database_plugins_list_free(GSList* list) +{ + if (!list) + return; + + for (GSList* p = list; p; p = p->next) + g_object_unref(p->data); + + g_slist_free(list); +} + +/** + * webkit_web_plugin_database_get_plugins: + * @database: a #WebKitWebPluginDatabase + * + * Returns all #WebKitWebPlugin available in @database. + * The returned list must be freed with webkit_web_plugin_database_plugins_list_free() + * + * Returns: (transfer full) (element-type WebKitWebPlugin): a #GSList of #WebKitWebPlugin + * + * Since: 1.3.8 + */ +GSList* webkit_web_plugin_database_get_plugins(WebKitWebPluginDatabase* database) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0); + + GSList* gPlugins = 0; + const Vector<PluginPackage*>& plugins = database->priv->coreDatabase->plugins(); + + for (unsigned int i = 0; i < plugins.size(); ++i) { + PluginPackage* plugin = plugins[i]; + gPlugins = g_slist_append(gPlugins, kitNew(plugin)); + } + + return gPlugins; +} + +/** + * webkit_web_plugin_database_get_plugin_for_mimetype: + * @database: a #WebKitWebPluginDatabase + * @mimeType: a mime type + * + * Returns the #WebKitWebPlugin that is handling @mimeType in the + * @database, or %NULL if there's none doing so. + * + * Returns: (transfer full): a #WebKitWebPlugin + * + * Since: 1.3.8 + */ +WebKitWebPlugin* webkit_web_plugin_database_get_plugin_for_mimetype(WebKitWebPluginDatabase* database, const char* mimeType) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0); + g_return_val_if_fail(mimeType, 0); + + return kitNew(database->priv->coreDatabase->pluginForMIMEType(mimeType)); +} + +/** + * webkit_web_plugin_database_refresh: + * @database: a #WebKitWebPluginDatabase + * + * Refreshes @database adding new plugins that are now in use and + * removing those that have been disabled or are otherwise no longer + * available. + * + * Since: 1.3.8 + */ +void webkit_web_plugin_database_refresh(WebKitWebPluginDatabase* database) +{ + g_return_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database)); + + database->priv->coreDatabase->refresh(); +} + +WebKitWebPluginDatabase* webkit_web_plugin_database_new(void) +{ + return WEBKIT_WEB_PLUGIN_DATABASE(g_object_new(WEBKIT_TYPE_WEB_PLUGIN_DATABASE, 0)); +} diff --git a/Source/WebKit/gtk/webkit/webkitwebplugindatabase.h b/Source/WebKit/gtk/webkit/webkitwebplugindatabase.h new file mode 100644 index 0000000..0b02c26 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebplugindatabase.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef webkitwebplugindatabase_h +#define webkitwebplugindatabase_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_PLUGIN_DATABASE (webkit_web_plugin_database_get_type()) +#define WEBKIT_WEB_PLUGIN_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabase)) +#define WEBKIT_WEB_PLUGIN_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabaseClass)) +#define WEBKIT_IS_WEB_PLUGIN_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_PLUGIN_DATABASE)) +#define WEBKIT_IS_WEB_PLUGIN_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_PLUGIN_DATABASE)) +#define WEBKIT_WEB_PLUGIN_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabaseClass)) + +typedef struct _WebKitWebPluginDatabasePrivate WebKitWebPluginDatabasePrivate; + +struct _WebKitWebPluginDatabaseClass { + GObjectClass parentClass; +}; + +struct _WebKitWebPluginDatabase { + GObject parentInstance; + + WebKitWebPluginDatabasePrivate* priv; +}; + +WEBKIT_API GType +webkit_web_plugin_database_get_type (void) G_GNUC_CONST; + +WEBKIT_API void +webkit_web_plugin_database_plugins_list_free (GSList*); + +WEBKIT_API GSList* +webkit_web_plugin_database_get_plugins (WebKitWebPluginDatabase*); + +WEBKIT_API WebKitWebPlugin* +webkit_web_plugin_database_get_plugin_for_mimetype (WebKitWebPluginDatabase*, const char *); + +WEBKIT_API void +webkit_web_plugin_database_refresh (WebKitWebPluginDatabase*); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebplugindatabaseprivate.h b/Source/WebKit/gtk/webkit/webkitwebplugindatabaseprivate.h new file mode 100644 index 0000000..199aede --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebplugindatabaseprivate.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebplugindatabaseprivate_h +#define webkitwebplugindatabaseprivate_h + +#include <glib-object.h> + +namespace WebCore { +class PluginDatabase; +} + +extern "C" { + +typedef struct _WebKitWebPluginDatabasePrivate WebKitWebPluginDatabasePrivate; +struct _WebKitWebPluginDatabasePrivate { + WebCore::PluginDatabase* coreDatabase; +}; + +WebKitWebPluginDatabase* webkit_web_plugin_database_new(); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebpluginprivate.h b/Source/WebKit/gtk/webkit/webkitwebpluginprivate.h new file mode 100644 index 0000000..8a1ba1b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebpluginprivate.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef webkitwebpluginprivate_h +#define webkitwebpluginprivate_h + +#include "webkitwebplugin.h" +#include <glib-object.h> +#include <wtf/text/CString.h> + +namespace WebCore { +class PluginPackage; +} + +namespace WebKit { +WebKitWebPlugin* kitNew(WebCore::PluginPackage* package); +} + +extern "C" { + +typedef struct _WebKitWebPluginPrivate WebKitWebPluginPrivate; +struct _WebKitWebPluginPrivate { + RefPtr<WebCore::PluginPackage> corePlugin; + CString name; + CString description; + char* path; + GSList* mimeTypes; +}; + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebpolicydecision.cpp b/Source/WebKit/gtk/webkit/webkitwebpolicydecision.cpp new file mode 100644 index 0000000..624ff9a --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebpolicydecision.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebpolicydecision.h" + +#include "FrameLoaderClient.h" +#include "FrameLoaderTypes.h" +#include "webkitwebframeprivate.h" +#include "webkitwebpolicydecisionprivate.h" + +using namespace WebKit; +using namespace WebCore; + +/** + * SECTION:webkitwebpolicydecision + * @short_description: Liason between WebKit and the application regarding asynchronous policy decisions + * + * #WebKitWebPolicyDecision objects are given to the application on + * signal emissions that deal with policy decisions, such as if a new + * window should be opened, or if a given navigation should be + * allowed. The application uses it to tell the engine what to do. + */ + +G_DEFINE_TYPE(WebKitWebPolicyDecision, webkit_web_policy_decision, G_TYPE_OBJECT); + +struct _WebKitWebPolicyDecisionPrivate { + WebKitWebFrame* frame; + FramePolicyFunction framePolicyFunction; + gboolean isCancelled; +}; + +static void webkit_web_policy_decision_class_init(WebKitWebPolicyDecisionClass* decisionClass) +{ + g_type_class_add_private(decisionClass, sizeof(WebKitWebPolicyDecisionPrivate)); +} + +static void webkit_web_policy_decision_init(WebKitWebPolicyDecision* decision) +{ + decision->priv = G_TYPE_INSTANCE_GET_PRIVATE(decision, WEBKIT_TYPE_WEB_POLICY_DECISION, WebKitWebPolicyDecisionPrivate); +} + +WebKitWebPolicyDecision* webkit_web_policy_decision_new(WebKitWebFrame* frame, WebCore::FramePolicyFunction function) +{ + g_return_val_if_fail(frame, NULL); + + WebKitWebPolicyDecision* decision = WEBKIT_WEB_POLICY_DECISION(g_object_new(WEBKIT_TYPE_WEB_POLICY_DECISION, NULL)); + WebKitWebPolicyDecisionPrivate* priv = decision->priv; + + priv->frame = frame; + priv->framePolicyFunction = function; + priv->isCancelled = FALSE; + + return decision; +} + +/** + * webkit_web_policy_decision_use + * @decision: a #WebKitWebPolicyDecision + * + * Will send the USE decision to the policy implementer. + * + * Since: 1.0.3 + */ +void webkit_web_policy_decision_use(WebKitWebPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); + + WebKitWebPolicyDecisionPrivate* priv = decision->priv; + + if (!priv->isCancelled) + (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyUse); +} + +/** + * webkit_web_policy_decision_ignore + * @decision: a #WebKitWebPolicyDecision + * + * Will send the IGNORE decision to the policy implementer. + * + * Since: 1.0.3 + */ +void webkit_web_policy_decision_ignore(WebKitWebPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); + + WebKitWebPolicyDecisionPrivate* priv = decision->priv; + + if (!priv->isCancelled) + (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyIgnore); +} + +/** + * webkit_web_policy_decision_download + * @decision: a #WebKitWebPolicyDecision + * + * Will send the DOWNLOAD decision to the policy implementer. + * + * Since: 1.0.3 + */ +void webkit_web_policy_decision_download(WebKitWebPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); + + WebKitWebPolicyDecisionPrivate* priv = decision->priv; + + if (!priv->isCancelled) + (core(priv->frame)->loader()->policyChecker()->*(priv->framePolicyFunction))(WebCore::PolicyDownload); +} + +void webkit_web_policy_decision_cancel(WebKitWebPolicyDecision* decision) +{ + g_return_if_fail(WEBKIT_IS_WEB_POLICY_DECISION(decision)); + + WebKitWebPolicyDecisionPrivate* priv = decision->priv; + + priv->isCancelled = TRUE; +} diff --git a/Source/WebKit/gtk/webkit/webkitwebpolicydecision.h b/Source/WebKit/gtk/webkit/webkitwebpolicydecision.h new file mode 100644 index 0000000..2b61837 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebpolicydecision.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebpolicydecision_h +#define webkitwebpolicydecision_h + +#include <glib-object.h> +#include <stdint.h> +#include "webkitdefines.h" + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_POLICY_DECISION (webkit_web_policy_decision_get_type()) +#define WEBKIT_WEB_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_POLICY_DECISION, WebKitWebPolicyDecision)) +#define WEBKIT_WEB_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_POLICY_DECISION, WebKitWebPolicyDecisionClass)) +#define WEBKIT_IS_WEB_POLICY_DECISION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_POLICY_DECISION)) +#define WEBKIT_IS_WEB_POLICY_DECISION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_POLICY_DECISION)) +#define WEBKIT_WEB_POLICY_DECISION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_POLICY_DECISION, WebKitWebPolicyDecisionClass)) + +typedef struct _WebKitWebPolicyDecisionPrivate WebKitWebPolicyDecisionPrivate; +struct _WebKitWebPolicyDecision { + GObject parent_instance; + + /*< private >*/ + WebKitWebPolicyDecisionPrivate* priv; +}; + +struct _WebKitWebPolicyDecisionClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_policy_decision_get_type (void); + +WEBKIT_API void +webkit_web_policy_decision_use (WebKitWebPolicyDecision* decision); + +WEBKIT_API void +webkit_web_policy_decision_ignore (WebKitWebPolicyDecision* decision); + +WEBKIT_API void +webkit_web_policy_decision_download (WebKitWebPolicyDecision* decision); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebpolicydecisionprivate.h b/Source/WebKit/gtk/webkit/webkitwebpolicydecisionprivate.h new file mode 100644 index 0000000..2d264ab --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebpolicydecisionprivate.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebpolicydecisionprivate_h +#define webkitwebpolicydecisionprivate_h + +#include "webkitwebpolicydecision.h" + +extern "C" { + +WebKitWebPolicyDecision* webkit_web_policy_decision_new(WebKitWebFrame*, WebCore::FramePolicyFunction); + +void webkit_web_policy_decision_cancel(WebKitWebPolicyDecision*); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebresource.cpp b/Source/WebKit/gtk/webkit/webkitwebresource.cpp new file mode 100644 index 0000000..b7f4036 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebresource.cpp @@ -0,0 +1,400 @@ +/* + * Copyright (C) 2009 Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebresource.h" + +#include "ArchiveResource.h" +#include "KURL.h" +#include "PlatformString.h" +#include "SharedBuffer.h" +#include "webkitenumtypes.h" +#include "webkitglobalsprivate.h" +#include "webkitmarshal.h" +#include "webkitwebresourceprivate.h" +#include <glib.h> +#include <glib/gi18n-lib.h> +#include <wtf/Assertions.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitwebresource + * @short_description: Represents a downloaded URI. + * @see_also: #WebKitWebDataSource + * + * A web resource encapsulates the data of the download as well as the URI, + * MIME type and frame name of the resource. + */ + +using namespace WebCore; + +enum { + PROP_0, + + PROP_URI, + PROP_MIME_TYPE, + PROP_ENCODING, + PROP_FRAME_NAME +}; + +G_DEFINE_TYPE(WebKitWebResource, webkit_web_resource, G_TYPE_OBJECT); + +static void webkit_web_resource_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); +static void webkit_web_resource_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); + +static void webkit_web_resource_cleanup(WebKitWebResource* webResource) +{ + WebKitWebResourcePrivate* priv = webResource->priv; + + g_free(priv->uri); + priv->uri = NULL; + + g_free(priv->mimeType); + priv->mimeType = NULL; + + g_free(priv->textEncoding); + priv->textEncoding = NULL; + + g_free(priv->frameName); + priv->frameName = NULL; + + if (priv->data) + g_string_free(priv->data, TRUE); + priv->data = NULL; +} + +static void webkit_web_resource_dispose(GObject* object) +{ + WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(object); + WebKitWebResourcePrivate* priv = webResource->priv; + + if (priv->resource) { + priv->resource->deref(); + priv->resource = 0; + } + + G_OBJECT_CLASS(webkit_web_resource_parent_class)->dispose(object); +} + +static void webkit_web_resource_finalize(GObject* object) +{ + WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(object); + + webkit_web_resource_cleanup(webResource); + + G_OBJECT_CLASS(webkit_web_resource_parent_class)->finalize(object); +} + +static void webkit_web_resource_class_init(WebKitWebResourceClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = webkit_web_resource_dispose; + gobject_class->finalize = webkit_web_resource_finalize; + gobject_class->get_property = webkit_web_resource_get_property; + gobject_class->set_property = webkit_web_resource_set_property; + + /** + * WebKitWebResource:uri: + * + * The URI of the web resource + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobject_class, + PROP_URI, + g_param_spec_string( + "uri", + _("URI"), + _("The uri of the resource"), + NULL, + (GParamFlags)(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))); + /** + * WebKitWebResource:mime-type: + * + * The MIME type of the web resource. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobject_class, + PROP_MIME_TYPE, + g_param_spec_string( + "mime-type", + _("MIME Type"), + _("The MIME type of the resource"), + NULL, + WEBKIT_PARAM_READABLE)); + /** + * WebKitWebResource:encoding: + * + * The encoding name to which the web resource was encoded in. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobject_class, + PROP_ENCODING, + g_param_spec_string( + "encoding", + _("Encoding"), + _("The text encoding name of the resource"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebResource:frame-name: + * + * The frame name for the web resource. + * + * Since: 1.1.14 + */ + g_object_class_install_property(gobject_class, + PROP_FRAME_NAME, + g_param_spec_string( + "frame-name", + _("Frame Name"), + _("The frame name of the resource"), + NULL, + WEBKIT_PARAM_READABLE)); + + g_type_class_add_private(gobject_class, sizeof(WebKitWebResourcePrivate)); +} + +static void webkit_web_resource_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(object); + + switch (prop_id) { + case PROP_URI: + g_value_set_string(value, webkit_web_resource_get_uri(webResource)); + break; + case PROP_MIME_TYPE: + g_value_set_string(value, webkit_web_resource_get_mime_type(webResource)); + break; + case PROP_ENCODING: + g_value_set_string(value, webkit_web_resource_get_encoding(webResource)); + break; + case PROP_FRAME_NAME: + g_value_set_string(value, webkit_web_resource_get_frame_name(webResource)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_resource_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +{ + WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(object); + + switch (prop_id) { + case PROP_URI: + g_free(webResource->priv->uri); + webResource->priv->uri = g_value_dup_string(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_resource_init(WebKitWebResource* webResource) +{ + webResource->priv = G_TYPE_INSTANCE_GET_PRIVATE(webResource, WEBKIT_TYPE_WEB_RESOURCE, WebKitWebResourcePrivate); +} + +// internal use only +WebKitWebResource* webkit_web_resource_new_with_core_resource(PassRefPtr<ArchiveResource> resource) +{ + WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(g_object_new(WEBKIT_TYPE_WEB_RESOURCE, NULL)); + WebKitWebResourcePrivate* priv = webResource->priv; + priv->resource = resource.releaseRef(); + + return webResource; +} + +void webkit_web_resource_init_with_core_resource(WebKitWebResource* webResource, PassRefPtr<ArchiveResource> resource) +{ + ASSERT(resource); + + WebKitWebResourcePrivate* priv = webResource->priv; + + if (priv->resource) + priv->resource->deref(); + + priv->resource = resource.releaseRef(); +} + +/** + * webkit_web_resource_new: + * @data: the data to initialize the #WebKitWebResource + * @size: the length of @data + * @uri: the uri of the #WebKitWebResource + * @mime_type: the MIME type of the #WebKitWebResource + * @encoding: the text encoding name of the #WebKitWebResource + * @frame_name: the frame name of the #WebKitWebResource + * + * Returns a new #WebKitWebResource. The @encoding can be %NULL. The + * @frame_name argument can be used if the resource represents contents of an + * entire HTML frame, otherwise pass %NULL. + * + * Return value: a new #WebKitWebResource + * + * Since: 1.1.14 + */ +WebKitWebResource* webkit_web_resource_new(const gchar* data, + gssize size, + const gchar* uri, + const gchar* mimeType, + const gchar* encoding, + const gchar* frameName) +{ + g_return_val_if_fail(data, NULL); + g_return_val_if_fail(uri, NULL); + g_return_val_if_fail(mimeType, NULL); + + if (size < 0) + size = strlen(data); + + RefPtr<SharedBuffer> buffer = SharedBuffer::create(data, size); + WebKitWebResource* webResource = webkit_web_resource_new_with_core_resource(ArchiveResource::create(buffer, KURL(KURL(), String::fromUTF8(uri)), String::fromUTF8(mimeType), String::fromUTF8(encoding), String::fromUTF8(frameName))); + + return webResource; +} + +/** + * webkit_web_resource_get_data: + * @web_resource: a #WebKitWebResource + * + * Returns the data of the @webResource. + * + * Return value: (transfer none): a #GString containing the character + * data of the @webResource. The string is owned by WebKit and should + * not be freed or destroyed. + * + * Since: 1.1.14 + */ +GString* webkit_web_resource_get_data(WebKitWebResource* webResource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(webResource), NULL); + + WebKitWebResourcePrivate* priv = webResource->priv; + + if (!priv->resource) + return NULL; + + if (!priv->data) + priv->data = g_string_new_len(priv->resource->data()->data(), priv->resource->data()->size()); + + return priv->data; +} + +/** + * webkit_web_resource_get_uri: + * @web_resource: a #WebKitWebResource + * + * Return value: the URI of the resource + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_resource_get_uri(WebKitWebResource* webResource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(webResource), NULL); + + WebKitWebResourcePrivate* priv = webResource->priv; + + + // We may have an URI without having a resource assigned to us (e.g., if the + // FrameLoaderClient only had a ResourceRequest when we got created + if (priv->uri) + return priv->uri; + + if (!priv->resource) + return NULL; + + priv->uri = g_strdup(priv->resource->url().string().utf8().data()); + + return priv->uri; +} + +/** + * webkit_web_resource_get_mime_type: + * @web_resource: a #WebKitWebResource + * + * Return value: the MIME type of the resource + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_resource_get_mime_type(WebKitWebResource* webResource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(webResource), NULL); + + WebKitWebResourcePrivate* priv = webResource->priv; + if (!priv->resource) + return NULL; + + if (!priv->mimeType) + priv->mimeType = g_strdup(priv->resource->mimeType().utf8().data()); + + return priv->mimeType; +} + +/** + * webkit_web_resource_get_encoding: + * @web_resource: a #WebKitWebResource + * + * Return value: the encoding name of the resource + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_resource_get_encoding(WebKitWebResource* webResource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(webResource), NULL); + + WebKitWebResourcePrivate* priv = webResource->priv; + if (!priv->resource) + return NULL; + + if (!priv->textEncoding) + priv->textEncoding = g_strdup(priv->resource->textEncoding().utf8().data()); + + return priv->textEncoding; +} + +/** + * webkit_web_resource_get_frame_name: + * @web_resource: a #WebKitWebResource + * + * Return value: the frame name of the resource. + * + * Since: 1.1.14 + */ +G_CONST_RETURN gchar* webkit_web_resource_get_frame_name(WebKitWebResource* webResource) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(webResource), NULL); + + WebKitWebResourcePrivate* priv = webResource->priv; + if (!priv->resource) + return NULL; + + if (!priv->frameName) + priv->frameName = g_strdup(priv->resource->frameName().utf8().data()); + + return priv->frameName; +} + diff --git a/Source/WebKit/gtk/webkit/webkitwebresource.h b/Source/WebKit/gtk/webkit/webkitwebresource.h new file mode 100644 index 0000000..05f6066 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebresource.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2009 Jan Michael C. Alonzo + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebresource_h +#define webkitwebresource_h + +#include <glib.h> +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_RESOURCE (webkit_web_resource_get_type()) +#define WEBKIT_WEB_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_RESOURCE, WebKitWebResource)) +#define WEBKIT_WEB_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_RESOURCE, WebKitWebResourceClass)) +#define WEBKIT_IS_WEB_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_RESOURCE)) +#define WEBKIT_IS_WEB_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_RESOURCE)) +#define WEBKIT_WEB_RESOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_RESOURCE, WebKitWebResourceClass)) + +typedef struct _WebKitWebResourcePrivate WebKitWebResourcePrivate; + +struct _WebKitWebResource { + GObject parent_instance; + + /*< private >*/ + WebKitWebResourcePrivate *priv; +}; + +struct _WebKitWebResourceClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WEBKIT_API GType +webkit_web_resource_get_type (void); + +WEBKIT_API WebKitWebResource * +webkit_web_resource_new (const gchar *data, + gssize size, + const gchar *uri, + const gchar *mime_type, + const gchar *encoding, + const gchar *frame_name); + +WEBKIT_API GString * +webkit_web_resource_get_data (WebKitWebResource *web_resource); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_resource_get_uri (WebKitWebResource *web_resource); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_resource_get_mime_type (WebKitWebResource *web_resource); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_resource_get_encoding (WebKitWebResource *web_resource); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_resource_get_frame_name (WebKitWebResource *web_resource); + +G_END_DECLS + +#endif /* webkitwebresource_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebresourceprivate.h b/Source/WebKit/gtk/webkit/webkitwebresourceprivate.h new file mode 100644 index 0000000..2ae3d05 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebresourceprivate.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebresourceprivate_h +#define webkitwebresourceprivate_h + +#include "ArchiveResource.h" +#include "webkitwebresource.h" + +extern "C" { + +struct _WebKitWebResourcePrivate { + WebCore::ArchiveResource* resource; + + gchar* uri; + gchar* mimeType; + gchar* textEncoding; + gchar* frameName; + + GString* data; +}; + +WebKitWebResource* webkit_web_resource_new_with_core_resource(PassRefPtr<WebCore::ArchiveResource>); + +void webkit_web_resource_init_with_core_resource(WebKitWebResource*, PassRefPtr<WebCore::ArchiveResource>); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebsettings.cpp b/Source/WebKit/gtk/webkit/webkitwebsettings.cpp new file mode 100644 index 0000000..e833de9 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebsettings.cpp @@ -0,0 +1,1420 @@ +/* + * Copyright (C) 2008 Christian Dywan <christian@imendio.com> + * Copyright (C) 2008 Nuanti Ltd. + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2008 Holger Hans Peter Freyther + * Copyright (C) 2009 Jan Michael Alonzo + * Copyright (C) 2009 Movial Creative Technologies Inc. + * Copyright (C) 2009 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebsettings.h" + +#include "EditingBehavior.h" +#include "FileSystem.h" +#include "PluginDatabase.h" +#include "webkitenumtypes.h" +#include "webkitglobalsprivate.h" +#include "webkitversion.h" +#include "webkitwebsettingsprivate.h" +#include <wtf/text/CString.h> +#include <wtf/text/StringConcatenate.h> +#include <glib/gi18n-lib.h> + +#if OS(UNIX) +#include <sys/utsname.h> +#elif OS(WINDOWS) +#include "SystemInfo.h" +#endif + +/** + * SECTION:webkitwebsettings + * @short_description: Control the behaviour of a #WebKitWebView + * + * #WebKitWebSettings can be applied to a #WebKitWebView to control text encoding, + * color, font sizes, printing mode, script support, loading of images and various other things. + * After creation, a #WebKitWebSettings object contains default settings. + * + * <informalexample><programlisting> + * /<!-- -->* Create a new websettings and disable java script *<!-- -->/ + * WebKitWebSettings *settings = webkit_web_settings_new (); + * g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL); + * + * /<!-- -->* Apply the result *<!-- -->/ + * webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings); + * </programlisting></informalexample> + */ + +using namespace WebCore; + +G_DEFINE_TYPE(WebKitWebSettings, webkit_web_settings, G_TYPE_OBJECT) + +struct _WebKitWebSettingsPrivate { + gchar* default_encoding; + gchar* cursive_font_family; + gchar* default_font_family; + gchar* fantasy_font_family; + gchar* monospace_font_family; + gchar* sans_serif_font_family; + gchar* serif_font_family; + guint default_font_size; + guint default_monospace_font_size; + guint minimum_font_size; + guint minimum_logical_font_size; + gboolean enforce_96_dpi; + gboolean auto_load_images; + gboolean auto_shrink_images; + gboolean print_backgrounds; + gboolean enable_scripts; + gboolean enable_plugins; + gboolean resizable_text_areas; + gchar* user_stylesheet_uri; + gfloat zoom_step; + gboolean enable_developer_extras; + gboolean enable_private_browsing; + gboolean enable_spell_checking; + gchar* spell_checking_languages; + gboolean enable_caret_browsing; + gboolean enable_html5_database; + gboolean enable_html5_local_storage; + gboolean enable_xss_auditor; + gboolean enable_spatial_navigation; + gboolean enable_frame_flattening; + gchar* user_agent; + gboolean javascript_can_open_windows_automatically; + gboolean javascript_can_access_clipboard; + gboolean enable_offline_web_application_cache; + WebKitEditingBehavior editing_behavior; + gboolean enable_universal_access_from_file_uris; + gboolean enable_file_access_from_file_uris; + gboolean enable_dom_paste; + gboolean tab_key_cycles_through_elements; + gboolean enable_default_context_menu; + gboolean enable_site_specific_quirks; + gboolean enable_page_cache; + gboolean auto_resize_window; + gboolean enable_java_applet; + gboolean enable_hyperlink_auditing; + gboolean enable_fullscreen; + gboolean enable_dns_prefetching; + gboolean enable_webgl; +}; + +#define WEBKIT_WEB_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate)) + +enum { + PROP_0, + + PROP_DEFAULT_ENCODING, + PROP_CURSIVE_FONT_FAMILY, + PROP_DEFAULT_FONT_FAMILY, + PROP_FANTASY_FONT_FAMILY, + PROP_MONOSPACE_FONT_FAMILY, + PROP_SANS_SERIF_FONT_FAMILY, + PROP_SERIF_FONT_FAMILY, + PROP_DEFAULT_FONT_SIZE, + PROP_DEFAULT_MONOSPACE_FONT_SIZE, + PROP_MINIMUM_FONT_SIZE, + PROP_MINIMUM_LOGICAL_FONT_SIZE, + PROP_ENFORCE_96_DPI, + PROP_AUTO_LOAD_IMAGES, + PROP_AUTO_SHRINK_IMAGES, + PROP_PRINT_BACKGROUNDS, + PROP_ENABLE_SCRIPTS, + PROP_ENABLE_PLUGINS, + PROP_RESIZABLE_TEXT_AREAS, + PROP_USER_STYLESHEET_URI, + PROP_ZOOM_STEP, + PROP_ENABLE_DEVELOPER_EXTRAS, + PROP_ENABLE_PRIVATE_BROWSING, + PROP_ENABLE_SPELL_CHECKING, + PROP_SPELL_CHECKING_LANGUAGES, + PROP_ENABLE_CARET_BROWSING, + PROP_ENABLE_HTML5_DATABASE, + PROP_ENABLE_HTML5_LOCAL_STORAGE, + PROP_ENABLE_XSS_AUDITOR, + PROP_ENABLE_SPATIAL_NAVIGATION, + PROP_ENABLE_FRAME_FLATTENING, + PROP_USER_AGENT, + PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY, + PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD, + PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE, + PROP_EDITING_BEHAVIOR, + PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS, + PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS, + PROP_ENABLE_DOM_PASTE, + PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS, + PROP_ENABLE_DEFAULT_CONTEXT_MENU, + PROP_ENABLE_SITE_SPECIFIC_QUIRKS, + PROP_ENABLE_PAGE_CACHE, + PROP_AUTO_RESIZE_WINDOW, + PROP_ENABLE_JAVA_APPLET, + PROP_ENABLE_HYPERLINK_AUDITING, + PROP_ENABLE_FULLSCREEN, + PROP_ENABLE_DNS_PREFETCHING, + PROP_ENABLE_WEBGL +}; + +// Create a default user agent string +// This is a liberal interpretation of http://www.mozilla.org/build/revised-user-agent-strings.html +// See also http://developer.apple.com/internet/safari/faq.html#anchor2 +static String webkitPlatform() +{ +#if PLATFORM(X11) + DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("X11; "))); +#elif OS(WINDOWS) + DEFINE_STATIC_LOCAL(const String, uaPlatform, (String(""))); +#elif PLATFORM(MAC) + DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Macintosh; "))); +#elif defined(GDK_WINDOWING_DIRECTFB) + DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("DirectFB; "))); +#else + DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Unknown; "))); +#endif + + return uaPlatform; +} + +static String webkitOSVersion() +{ + // FIXME: platform/version detection can be shared. +#if OS(DARWIN) + +#if CPU(X86) + DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Intel Mac OS X"))); +#else + DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("PPC Mac OS X"))); +#endif + +#elif OS(UNIX) + DEFINE_STATIC_LOCAL(String, uaOSVersion, (String())); + + if (!uaOSVersion.isEmpty()) + return uaOSVersion; + + struct utsname name; + if (uname(&name) != -1) + uaOSVersion = makeString(name.sysname, ' ', name.machine); + else + uaOSVersion = String("Unknown"); +#elif OS(WINDOWS) + DEFINE_STATIC_LOCAL(const String, uaOSVersion, (windowsVersionForUAString())); +#else + DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Unknown"))); +#endif + + return uaOSVersion; +} + +String webkitUserAgent() +{ + // We mention Safari since many broken sites check for it (OmniWeb does this too) + // We re-use the WebKit version, though it doesn't seem to matter much in practice + + DEFINE_STATIC_LOCAL(const String, uaVersion, (makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.', String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+'))); + DEFINE_STATIC_LOCAL(const String, staticUA, (makeString("Mozilla/5.0 (", webkitPlatform(), webkitOSVersion(), ") AppleWebKit/", uaVersion) + + makeString(" (KHTML, like Gecko) Version/5.0 Safari/", uaVersion))); + + return staticUA; +} + +static void webkit_web_settings_finalize(GObject* object); + +static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); + +static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); + +static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + gobject_class->finalize = webkit_web_settings_finalize; + gobject_class->set_property = webkit_web_settings_set_property; + gobject_class->get_property = webkit_web_settings_get_property; + + webkitInit(); + + GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT); + + g_object_class_install_property(gobject_class, + PROP_DEFAULT_ENCODING, + g_param_spec_string( + "default-encoding", + _("Default Encoding"), + _("The default encoding used to display text."), + "iso-8859-1", + flags)); + + g_object_class_install_property(gobject_class, + PROP_CURSIVE_FONT_FAMILY, + g_param_spec_string( + "cursive-font-family", + _("Cursive Font Family"), + _("The default Cursive font family used to display text."), + "serif", + flags)); + + g_object_class_install_property(gobject_class, + PROP_DEFAULT_FONT_FAMILY, + g_param_spec_string( + "default-font-family", + _("Default Font Family"), + _("The default font family used to display text."), + "sans-serif", + flags)); + + g_object_class_install_property(gobject_class, + PROP_FANTASY_FONT_FAMILY, + g_param_spec_string( + "fantasy-font-family", + _("Fantasy Font Family"), + _("The default Fantasy font family used to display text."), + "serif", + flags)); + + g_object_class_install_property(gobject_class, + PROP_MONOSPACE_FONT_FAMILY, + g_param_spec_string( + "monospace-font-family", + _("Monospace Font Family"), + _("The default font family used to display monospace text."), + "monospace", + flags)); + + g_object_class_install_property(gobject_class, + PROP_SANS_SERIF_FONT_FAMILY, + g_param_spec_string( + "sans-serif-font-family", + _("Sans Serif Font Family"), + _("The default Sans Serif font family used to display text."), + "sans-serif", + flags)); + + g_object_class_install_property(gobject_class, + PROP_SERIF_FONT_FAMILY, + g_param_spec_string( + "serif-font-family", + _("Serif Font Family"), + _("The default Serif font family used to display text."), + "serif", + flags)); + + g_object_class_install_property(gobject_class, + PROP_DEFAULT_FONT_SIZE, + g_param_spec_int( + "default-font-size", + _("Default Font Size"), + _("The default font size used to display text."), + 5, G_MAXINT, 12, + flags)); + + g_object_class_install_property(gobject_class, + PROP_DEFAULT_MONOSPACE_FONT_SIZE, + g_param_spec_int( + "default-monospace-font-size", + _("Default Monospace Font Size"), + _("The default font size used to display monospace text."), + 5, G_MAXINT, 10, + flags)); + + g_object_class_install_property(gobject_class, + PROP_MINIMUM_FONT_SIZE, + g_param_spec_int( + "minimum-font-size", + _("Minimum Font Size"), + _("The minimum font size used to display text."), + 0, G_MAXINT, 5, + flags)); + + g_object_class_install_property(gobject_class, + PROP_MINIMUM_LOGICAL_FONT_SIZE, + g_param_spec_int( + "minimum-logical-font-size", + _("Minimum Logical Font Size"), + _("The minimum logical font size used to display text."), + 1, G_MAXINT, 5, + flags)); + + /** + * WebKitWebSettings:enforce-96-dpi: + * + * Enforce a resolution of 96 DPI. This is meant for compatibility + * with web pages which cope badly with different screen resolutions + * and for automated testing. + * Web browsers and applications that typically display arbitrary + * content from the web should provide a preference for this. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_ENFORCE_96_DPI, + g_param_spec_boolean( + "enforce-96-dpi", + _("Enforce 96 DPI"), + _("Enforce a resolution of 96 DPI"), + FALSE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_AUTO_LOAD_IMAGES, + g_param_spec_boolean( + "auto-load-images", + _("Auto Load Images"), + _("Load images automatically."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_AUTO_SHRINK_IMAGES, + g_param_spec_boolean( + "auto-shrink-images", + _("Auto Shrink Images"), + _("Automatically shrink standalone images to fit."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_PRINT_BACKGROUNDS, + g_param_spec_boolean( + "print-backgrounds", + _("Print Backgrounds"), + _("Whether background images should be printed."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_ENABLE_SCRIPTS, + g_param_spec_boolean( + "enable-scripts", + _("Enable Scripts"), + _("Enable embedded scripting languages."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_ENABLE_PLUGINS, + g_param_spec_boolean( + "enable-plugins", + _("Enable Plugins"), + _("Enable embedded plugin objects."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_RESIZABLE_TEXT_AREAS, + g_param_spec_boolean( + "resizable-text-areas", + _("Resizable Text Areas"), + _("Whether text areas are resizable."), + TRUE, + flags)); + + g_object_class_install_property(gobject_class, + PROP_USER_STYLESHEET_URI, + g_param_spec_string("user-stylesheet-uri", + _("User Stylesheet URI"), + _("The URI of a stylesheet that is applied to every page."), + 0, + flags)); + + /** + * WebKitWebSettings:zoom-step: + * + * The value by which the zoom level is changed when zooming in or out. + * + * Since: 1.0.1 + */ + g_object_class_install_property(gobject_class, + PROP_ZOOM_STEP, + g_param_spec_float( + "zoom-step", + _("Zoom Stepping Value"), + _("The value by which the zoom level is changed when zooming in or out."), + 0.0f, G_MAXFLOAT, 0.1f, + flags)); + + /** + * WebKitWebSettings:enable-developer-extras: + * + * Whether developer extensions should be enabled. This enables, + * for now, the Web Inspector, which can be controlled using the + * #WebKitWebInspector instance held by the #WebKitWebView this + * setting is enabled for. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_DEVELOPER_EXTRAS, + g_param_spec_boolean( + "enable-developer-extras", + _("Enable Developer Extras"), + _("Enables special extensions that help developers"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-private-browsing: + * + * Whether to enable private browsing mode. Private browsing mode prevents + * WebKit from updating the global history and storing any session + * information e.g., on-disk cache, as well as suppressing any messages + * from being printed into the (javascript) console. + * + * This is currently experimental for WebKitGtk. + * + * Since: 1.1.2 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_PRIVATE_BROWSING, + g_param_spec_boolean( + "enable-private-browsing", + _("Enable Private Browsing"), + _("Enables private browsing mode"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-spell-checking: + * + * Whether to enable spell checking while typing. + * + * Since: 1.1.6 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_SPELL_CHECKING, + g_param_spec_boolean( + "enable-spell-checking", + _("Enable Spell Checking"), + _("Enables spell checking while typing"), + FALSE, + flags)); + + /** + * WebKitWebSettings:spell-checking-languages: + * + * The languages to be used for spell checking, separated by commas. + * + * The locale string typically is in the form lang_COUNTRY, where lang + * is an ISO-639 language code, and COUNTRY is an ISO-3166 country code. + * For instance, sv_FI for Swedish as written in Finland or pt_BR + * for Portuguese as written in Brazil. + * + * If no value is specified then the value returned by + * gtk_get_default_language will be used. + * + * Since: 1.1.6 + */ + g_object_class_install_property(gobject_class, + PROP_SPELL_CHECKING_LANGUAGES, + g_param_spec_string( + "spell-checking-languages", + _("Languages to use for spell checking"), + _("Comma separated list of languages to use for spell checking"), + 0, + flags)); + + /** + * WebKitWebSettings:enable-caret-browsing: + * + * Whether to enable caret browsing mode. + * + * Since: 1.1.6 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_CARET_BROWSING, + g_param_spec_boolean("enable-caret-browsing", + _("Enable Caret Browsing"), + _("Whether to enable accessibility enhanced keyboard navigation"), + FALSE, + flags)); + /** + * WebKitWebSettings:enable-html5-database: + * + * Whether to enable HTML5 client-side SQL database support. Client-side + * SQL database allows web pages to store structured data and be able to + * use SQL to manipulate that data asynchronously. + * + * Since: 1.1.8 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_HTML5_DATABASE, + g_param_spec_boolean("enable-html5-database", + _("Enable HTML5 Database"), + _("Whether to enable HTML5 database support"), + TRUE, + flags)); + + /** + * WebKitWebSettings:enable-html5-local-storage: + * + * Whether to enable HTML5 localStorage support. localStorage provides + * simple synchronous storage access. + * + * Since: 1.1.8 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_HTML5_LOCAL_STORAGE, + g_param_spec_boolean("enable-html5-local-storage", + _("Enable HTML5 Local Storage"), + _("Whether to enable HTML5 Local Storage support"), + TRUE, + flags)); + /** + * WebKitWebSettings:enable-xss-auditor + * + * Whether to enable the XSS Auditor. This feature filters some kinds of + * reflective XSS attacks on vulnerable web sites. + * + * Since: 1.1.11 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_XSS_AUDITOR, + g_param_spec_boolean("enable-xss-auditor", + _("Enable XSS Auditor"), + _("Whether to enable the XSS auditor"), + TRUE, + flags)); + /** + * WebKitWebSettings:enable-spatial-navigation + * + * Whether to enable the Spatial Navigation. This feature consists in the ability + * to navigate between focusable elements in a Web page, such as hyperlinks and + * form controls, by using Left, Right, Up and Down arrow keys. For example, if + * an user presses the Right key, heuristics determine whether there is an element + * he might be trying to reach towards the right, and if there are multiple elements, + * which element he probably wants. + * + * Since: 1.1.23 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_SPATIAL_NAVIGATION, + g_param_spec_boolean("enable-spatial-navigation", + _("Enable Spatial Navigation"), + _("Whether to enable Spatial Navigation"), + FALSE, + flags)); + /** + * WebKitWebSettings:enable-frame-flattening + * + * Whether to enable the Frame Flattening. With this setting each subframe is expanded + * to its contents, which will flatten all the frames to become one scrollable page. + * On touch devices, it is desired to not have any scrollable sub parts of the page as + * it results in a confusing user experience, with scrolling sometimes scrolling sub parts + * and at other times scrolling the page itself. For this reason iframes and framesets are + * barely usable on touch devices. + * + * Since: 1.3.5 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_FRAME_FLATTENING, + g_param_spec_boolean("enable-frame-flattening", + _("Enable Frame Flattening"), + _("Whether to enable Frame Flattening"), + FALSE, + flags)); + /** + * WebKitWebSettings:user-agent: + * + * The User-Agent string used by WebKitGtk. + * + * This will return a default User-Agent string if a custom string wasn't + * provided by the application. Setting this property to a NULL value or + * an empty string will result in the User-Agent string being reset to the + * default value. + * + * Since: 1.1.11 + */ + g_object_class_install_property(gobject_class, PROP_USER_AGENT, + g_param_spec_string("user-agent", + _("User Agent"), + _("The User-Agent string used by WebKitGtk"), + webkitUserAgent().utf8().data(), + flags)); + + /** + * WebKitWebSettings:javascript-can-open-windows-automatically + * + * Whether JavaScript can open popup windows automatically without user + * intervention. + * + * Since: 1.1.11 + */ + g_object_class_install_property(gobject_class, + PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY, + g_param_spec_boolean("javascript-can-open-windows-automatically", + _("JavaScript can open windows automatically"), + _("Whether JavaScript can open windows automatically"), + FALSE, + flags)); + + /** + * WebKitWebSettings:javascript-can-access-clipboard + * + * Whether JavaScript can access Clipboard. + * + * Since: 1.3.0 + */ + g_object_class_install_property(gobject_class, + PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD, + g_param_spec_boolean("javascript-can-access-clipboard", + _("JavaScript can access Clipboard"), + _("Whether JavaScript can access Clipboard"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-offline-web-application-cache + * + * Whether to enable HTML5 offline web application cache support. Offline + * Web Application Cache ensures web applications are available even when + * the user is not connected to the network. + * + * Since: 1.1.13 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE, + g_param_spec_boolean("enable-offline-web-application-cache", + _("Enable offline web application cache"), + _("Whether to enable offline web application cache"), + TRUE, + flags)); + + + /** + * WebKitWebSettings:editing-behavior + * + * This setting controls various editing behaviors that differ + * between platforms and that have been combined in two groups, + * 'Mac' and 'Windows'. Some examples: + * + * 1) Clicking below the last line of an editable area puts the + * caret at the end of the last line on Mac, but in the middle of + * the last line on Windows. + * + * 2) Pushing down the arrow key on the last line puts the caret + * at the end of the last line on Mac, but does nothing on + * Windows. A similar case exists on the top line. + * + * Since: 1.1.13 + */ + g_object_class_install_property(gobject_class, + PROP_EDITING_BEHAVIOR, + g_param_spec_enum("editing-behavior", + _("Editing behavior"), + _("The behavior mode to use in editing mode"), + WEBKIT_TYPE_EDITING_BEHAVIOR, + WEBKIT_EDITING_BEHAVIOR_UNIX, + flags)); + + /** + * WebKitWebSettings:enable-universal-access-from-file-uris + * + * Whether to allow files loaded through file:// URIs universal access to + * all pages. + * + * Since: 1.1.13 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS, + g_param_spec_boolean("enable-universal-access-from-file-uris", + _("Enable universal access from file URIs"), + _("Whether to allow universal access from file URIs"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-dom-paste + * + * Whether to enable DOM paste. If set to %TRUE, document.execCommand("Paste") + * will correctly execute and paste content of the clipboard. + * + * Since: 1.1.16 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_DOM_PASTE, + g_param_spec_boolean("enable-dom-paste", + _("Enable DOM paste"), + _("Whether to enable DOM paste"), + FALSE, + flags)); + /** + * WebKitWebSettings:tab-key-cycles-through-elements: + * + * Whether the tab key cycles through elements on the page. + * + * If @flag is %TRUE, pressing the tab key will focus the next element in + * the @web_view. If @flag is %FALSE, the @web_view will interpret tab + * key presses as normal key presses. If the selected element is editable, the + * tab key will cause the insertion of a tab character. + * + * Since: 1.1.17 + */ + g_object_class_install_property(gobject_class, + PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS, + g_param_spec_boolean("tab-key-cycles-through-elements", + _("Tab key cycles through elements"), + _("Whether the tab key cycles through elements on the page."), + TRUE, + flags)); + + /** + * WebKitWebSettings:enable-default-context-menu: + * + * Whether right-clicks should be handled automatically to create, + * and display the context menu. Turning this off will make + * WebKitGTK+ not emit the populate-popup signal. Notice that the + * default button press event handler may still handle right + * clicks for other reasons, such as in-page context menus, or + * right-clicks that are handled by the page itself. + * + * Since: 1.1.18 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_DEFAULT_CONTEXT_MENU, + g_param_spec_boolean( + "enable-default-context-menu", + _("Enable Default Context Menu"), + _("Enables the handling of right-clicks for the creation of the default context menu"), + TRUE, + flags)); + + /** + * WebKitWebSettings::enable-site-specific-quirks + * + * Whether to turn on site-specific hacks. Turning this on will + * tell WebKitGTK+ to use some site-specific workarounds for + * better web compatibility. For example, older versions of + * MediaWiki will incorrectly send WebKit a css file with KHTML + * workarounds. By turning on site-specific quirks, WebKit will + * special-case this and other cases to make the sites work. + * + * Since: 1.1.18 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_SITE_SPECIFIC_QUIRKS, + g_param_spec_boolean( + "enable-site-specific-quirks", + _("Enable Site Specific Quirks"), + _("Enables the site-specific compatibility workarounds"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-page-cache: + * + * Enable or disable the page cache. Disabling the page cache is + * generally only useful for special circumstances like low-memory + * scenarios or special purpose applications like static HTML + * viewers. This setting only controls the Page Cache, this cache + * is different than the disk-based or memory-based traditional + * resource caches, its point is to make going back and forth + * between pages much faster. For details about the different types + * of caches and their purposes see: + * http://webkit.org/blog/427/webkit-page-cache-i-the-basics/ + * + * Since: 1.1.18 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_PAGE_CACHE, + g_param_spec_boolean("enable-page-cache", + _("Enable page cache"), + _("Whether the page cache should be used"), + FALSE, + flags)); + + /** + * WebKitWebSettings:auto-resize-window: + * + * Web pages can request to modify the size and position of the + * window containing the #WebKitWebView through various DOM methods + * (resizeTo, moveTo, resizeBy, moveBy). By default WebKit will not + * honor this requests, but you can set this property to %TRUE if + * you'd like it to do so. If you wish to handle this manually, you + * can connect to the notify signal for the + * #WebKitWebWindowFeatures of your #WebKitWebView. + * + * Since: 1.1.22 + */ + g_object_class_install_property(gobject_class, + PROP_AUTO_RESIZE_WINDOW, + g_param_spec_boolean("auto-resize-window", + _("Auto Resize Window"), + _("Automatically resize the toplevel window when a page requests it"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-file-access-from-file-uris: + * + * Boolean property to control file access for file:// URIs. If this + * option is enabled every file:// will have its own security unique domain. + * + * Since: 1.1.22 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS, + g_param_spec_boolean("enable-file-access-from-file-uris", + "Enable file access from file URIs", + "Controls file access for file:// URIs.", + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-java-applet: + * + * Enable or disable support for the Java <applet> tag. Keep in + * mind that Java content can be still shown in the page through + * <object> or <embed>, which are the preferred tags for this task. + * + * Since: 1.1.22 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_JAVA_APPLET, + g_param_spec_boolean("enable-java-applet", + _("Enable Java Applet"), + _("Whether Java Applet support through <applet> should be enabled"), + TRUE, + flags)); + + /** + * WebKitWebSettings:enable-hyperlink-auditing: + * + * Enable or disable support for <a ping>. + * + * Since: 1.2.5 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_HYPERLINK_AUDITING, + g_param_spec_boolean("enable-hyperlink-auditing", + _("Enable Hyperlink Auditing"), + _("Whether <a ping> should be able to send pings"), + FALSE, + flags)); + + /* Undocumented for now */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_FULLSCREEN, + g_param_spec_boolean("enable-fullscreen", + _("Enable Fullscreen"), + _("Whether the Mozilla style API should be enabled."), + FALSE, + flags)); + /** + * WebKitWebSettings:enable-webgl: + * + * Enable or disable support for WebGL on pages. WebGL is an experimental + * proposal for allowing web pages to use OpenGL ES-like calls directly. The + * standard is currently a work-in-progress by the Khronos Group. + * + * Since: 1.3.14 + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_WEBGL, + g_param_spec_boolean("enable-webgl", + _("Enable WebGL"), + _("Whether WebGL content should be rendered"), + FALSE, + flags)); + + /** + * WebKitWebSettings:enable-dns-prefetching + * + * Whether webkit prefetches domain names. This is a separate knob from private browsing. + * Whether private browsing should set this or not is up for debate, for now it doesn't. + * + * Since: 1.3.13. + */ + g_object_class_install_property(gobject_class, + PROP_ENABLE_DNS_PREFETCHING, + g_param_spec_boolean("enable-dns-prefetching", + _("WebKit prefetches domain names"), + _("Whether WebKit prefetches domain names"), + TRUE, + flags)); + + g_type_class_add_private(klass, sizeof(WebKitWebSettingsPrivate)); +} + +static void webkit_web_settings_init(WebKitWebSettings* web_settings) +{ + web_settings->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_settings, WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsPrivate); +} + +static void webkit_web_settings_finalize(GObject* object) +{ + WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object); + WebKitWebSettingsPrivate* priv = web_settings->priv; + + g_free(priv->default_encoding); + g_free(priv->cursive_font_family); + g_free(priv->default_font_family); + g_free(priv->fantasy_font_family); + g_free(priv->monospace_font_family); + g_free(priv->sans_serif_font_family); + g_free(priv->serif_font_family); + g_free(priv->user_stylesheet_uri); + g_free(priv->spell_checking_languages); + + g_free(priv->user_agent); + + G_OBJECT_CLASS(webkit_web_settings_parent_class)->finalize(object); +} + +static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +{ + WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object); + WebKitWebSettingsPrivate* priv = web_settings->priv; + + switch(prop_id) { + case PROP_DEFAULT_ENCODING: + g_free(priv->default_encoding); + priv->default_encoding = g_strdup(g_value_get_string(value)); + break; + case PROP_CURSIVE_FONT_FAMILY: + g_free(priv->cursive_font_family); + priv->cursive_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_DEFAULT_FONT_FAMILY: + g_free(priv->default_font_family); + priv->default_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_FANTASY_FONT_FAMILY: + g_free(priv->fantasy_font_family); + priv->fantasy_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_MONOSPACE_FONT_FAMILY: + g_free(priv->monospace_font_family); + priv->monospace_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_SANS_SERIF_FONT_FAMILY: + g_free(priv->sans_serif_font_family); + priv->sans_serif_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_SERIF_FONT_FAMILY: + g_free(priv->serif_font_family); + priv->serif_font_family = g_strdup(g_value_get_string(value)); + break; + case PROP_DEFAULT_FONT_SIZE: + priv->default_font_size = g_value_get_int(value); + break; + case PROP_DEFAULT_MONOSPACE_FONT_SIZE: + priv->default_monospace_font_size = g_value_get_int(value); + break; + case PROP_MINIMUM_FONT_SIZE: + priv->minimum_font_size = g_value_get_int(value); + break; + case PROP_MINIMUM_LOGICAL_FONT_SIZE: + priv->minimum_logical_font_size = g_value_get_int(value); + break; + case PROP_ENFORCE_96_DPI: + priv->enforce_96_dpi = g_value_get_boolean(value); + break; + case PROP_AUTO_LOAD_IMAGES: + priv->auto_load_images = g_value_get_boolean(value); + break; + case PROP_AUTO_SHRINK_IMAGES: + priv->auto_shrink_images = g_value_get_boolean(value); + break; + case PROP_PRINT_BACKGROUNDS: + priv->print_backgrounds = g_value_get_boolean(value); + break; + case PROP_ENABLE_SCRIPTS: + priv->enable_scripts = g_value_get_boolean(value); + break; + case PROP_ENABLE_PLUGINS: + priv->enable_plugins = g_value_get_boolean(value); + break; + case PROP_RESIZABLE_TEXT_AREAS: + priv->resizable_text_areas = g_value_get_boolean(value); + break; + case PROP_USER_STYLESHEET_URI: + g_free(priv->user_stylesheet_uri); + priv->user_stylesheet_uri = g_strdup(g_value_get_string(value)); + break; + case PROP_ZOOM_STEP: + priv->zoom_step = g_value_get_float(value); + break; + case PROP_ENABLE_DEVELOPER_EXTRAS: + priv->enable_developer_extras = g_value_get_boolean(value); + break; + case PROP_ENABLE_PRIVATE_BROWSING: + priv->enable_private_browsing = g_value_get_boolean(value); + break; + case PROP_ENABLE_CARET_BROWSING: + priv->enable_caret_browsing = g_value_get_boolean(value); + break; + case PROP_ENABLE_HTML5_DATABASE: + priv->enable_html5_database = g_value_get_boolean(value); + break; + case PROP_ENABLE_HTML5_LOCAL_STORAGE: + priv->enable_html5_local_storage = g_value_get_boolean(value); + break; + case PROP_ENABLE_SPELL_CHECKING: + priv->enable_spell_checking = g_value_get_boolean(value); + break; + case PROP_SPELL_CHECKING_LANGUAGES: + g_free(priv->spell_checking_languages); + priv->spell_checking_languages = g_strdup(g_value_get_string(value)); + break; + case PROP_ENABLE_XSS_AUDITOR: + priv->enable_xss_auditor = g_value_get_boolean(value); + break; + case PROP_ENABLE_SPATIAL_NAVIGATION: + priv->enable_spatial_navigation = g_value_get_boolean(value); + break; + case PROP_ENABLE_FRAME_FLATTENING: + priv->enable_frame_flattening = g_value_get_boolean(value); + break; + case PROP_USER_AGENT: + g_free(priv->user_agent); + if (!g_value_get_string(value) || !strlen(g_value_get_string(value))) + priv->user_agent = g_strdup(webkitUserAgent().utf8().data()); + else + priv->user_agent = g_strdup(g_value_get_string(value)); + break; + case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY: + priv->javascript_can_open_windows_automatically = g_value_get_boolean(value); + break; + case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD: + priv->javascript_can_access_clipboard = g_value_get_boolean(value); + break; + case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE: + priv->enable_offline_web_application_cache = g_value_get_boolean(value); + break; + case PROP_EDITING_BEHAVIOR: + priv->editing_behavior = static_cast<WebKitEditingBehavior>(g_value_get_enum(value)); + break; + case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS: + priv->enable_universal_access_from_file_uris = g_value_get_boolean(value); + break; + case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS: + priv->enable_file_access_from_file_uris = g_value_get_boolean(value); + break; + case PROP_ENABLE_DOM_PASTE: + priv->enable_dom_paste = g_value_get_boolean(value); + break; + case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS: + priv->tab_key_cycles_through_elements = g_value_get_boolean(value); + break; + case PROP_ENABLE_DEFAULT_CONTEXT_MENU: + priv->enable_default_context_menu = g_value_get_boolean(value); + break; + case PROP_ENABLE_SITE_SPECIFIC_QUIRKS: + priv->enable_site_specific_quirks = g_value_get_boolean(value); + break; + case PROP_ENABLE_PAGE_CACHE: + priv->enable_page_cache = g_value_get_boolean(value); + break; + case PROP_AUTO_RESIZE_WINDOW: + priv->auto_resize_window = g_value_get_boolean(value); + break; + case PROP_ENABLE_JAVA_APPLET: + priv->enable_java_applet = g_value_get_boolean(value); + break; + case PROP_ENABLE_HYPERLINK_AUDITING: + priv->enable_hyperlink_auditing = g_value_get_boolean(value); + break; + case PROP_ENABLE_FULLSCREEN: + priv->enable_fullscreen = g_value_get_boolean(value); + break; + case PROP_ENABLE_DNS_PREFETCHING: + priv->enable_dns_prefetching = g_value_get_boolean(value); + break; + case PROP_ENABLE_WEBGL: + priv->enable_webgl = g_value_get_boolean(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_settings_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebSettings* web_settings = WEBKIT_WEB_SETTINGS(object); + WebKitWebSettingsPrivate* priv = web_settings->priv; + + switch (prop_id) { + case PROP_DEFAULT_ENCODING: + g_value_set_string(value, priv->default_encoding); + break; + case PROP_CURSIVE_FONT_FAMILY: + g_value_set_string(value, priv->cursive_font_family); + break; + case PROP_DEFAULT_FONT_FAMILY: + g_value_set_string(value, priv->default_font_family); + break; + case PROP_FANTASY_FONT_FAMILY: + g_value_set_string(value, priv->fantasy_font_family); + break; + case PROP_MONOSPACE_FONT_FAMILY: + g_value_set_string(value, priv->monospace_font_family); + break; + case PROP_SANS_SERIF_FONT_FAMILY: + g_value_set_string(value, priv->sans_serif_font_family); + break; + case PROP_SERIF_FONT_FAMILY: + g_value_set_string(value, priv->serif_font_family); + break; + case PROP_DEFAULT_FONT_SIZE: + g_value_set_int(value, priv->default_font_size); + break; + case PROP_DEFAULT_MONOSPACE_FONT_SIZE: + g_value_set_int(value, priv->default_monospace_font_size); + break; + case PROP_MINIMUM_FONT_SIZE: + g_value_set_int(value, priv->minimum_font_size); + break; + case PROP_MINIMUM_LOGICAL_FONT_SIZE: + g_value_set_int(value, priv->minimum_logical_font_size); + break; + case PROP_ENFORCE_96_DPI: + g_value_set_boolean(value, priv->enforce_96_dpi); + break; + case PROP_AUTO_LOAD_IMAGES: + g_value_set_boolean(value, priv->auto_load_images); + break; + case PROP_AUTO_SHRINK_IMAGES: + g_value_set_boolean(value, priv->auto_shrink_images); + break; + case PROP_PRINT_BACKGROUNDS: + g_value_set_boolean(value, priv->print_backgrounds); + break; + case PROP_ENABLE_SCRIPTS: + g_value_set_boolean(value, priv->enable_scripts); + break; + case PROP_ENABLE_PLUGINS: + g_value_set_boolean(value, priv->enable_plugins); + break; + case PROP_RESIZABLE_TEXT_AREAS: + g_value_set_boolean(value, priv->resizable_text_areas); + break; + case PROP_USER_STYLESHEET_URI: + g_value_set_string(value, priv->user_stylesheet_uri); + break; + case PROP_ZOOM_STEP: + g_value_set_float(value, priv->zoom_step); + break; + case PROP_ENABLE_DEVELOPER_EXTRAS: + g_value_set_boolean(value, priv->enable_developer_extras); + break; + case PROP_ENABLE_PRIVATE_BROWSING: + g_value_set_boolean(value, priv->enable_private_browsing); + break; + case PROP_ENABLE_CARET_BROWSING: + g_value_set_boolean(value, priv->enable_caret_browsing); + break; + case PROP_ENABLE_HTML5_DATABASE: + g_value_set_boolean(value, priv->enable_html5_database); + break; + case PROP_ENABLE_HTML5_LOCAL_STORAGE: + g_value_set_boolean(value, priv->enable_html5_local_storage); + break; + case PROP_ENABLE_SPELL_CHECKING: + g_value_set_boolean(value, priv->enable_spell_checking); + break; + case PROP_SPELL_CHECKING_LANGUAGES: + g_value_set_string(value, priv->spell_checking_languages); + break; + case PROP_ENABLE_XSS_AUDITOR: + g_value_set_boolean(value, priv->enable_xss_auditor); + break; + case PROP_ENABLE_SPATIAL_NAVIGATION: + g_value_set_boolean(value, priv->enable_spatial_navigation); + break; + case PROP_ENABLE_FRAME_FLATTENING: + g_value_set_boolean(value, priv->enable_frame_flattening); + break; + case PROP_USER_AGENT: + g_value_set_string(value, priv->user_agent); + break; + case PROP_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY: + g_value_set_boolean(value, priv->javascript_can_open_windows_automatically); + break; + case PROP_JAVASCRIPT_CAN_ACCESS_CLIPBOARD: + g_value_set_boolean(value, priv->javascript_can_access_clipboard); + break; + case PROP_ENABLE_OFFLINE_WEB_APPLICATION_CACHE: + g_value_set_boolean(value, priv->enable_offline_web_application_cache); + break; + case PROP_EDITING_BEHAVIOR: + g_value_set_enum(value, priv->editing_behavior); + break; + case PROP_ENABLE_UNIVERSAL_ACCESS_FROM_FILE_URIS: + g_value_set_boolean(value, priv->enable_universal_access_from_file_uris); + break; + case PROP_ENABLE_FILE_ACCESS_FROM_FILE_URIS: + g_value_set_boolean(value, priv->enable_file_access_from_file_uris); + break; + case PROP_ENABLE_DOM_PASTE: + g_value_set_boolean(value, priv->enable_dom_paste); + break; + case PROP_TAB_KEY_CYCLES_THROUGH_ELEMENTS: + g_value_set_boolean(value, priv->tab_key_cycles_through_elements); + break; + case PROP_ENABLE_DEFAULT_CONTEXT_MENU: + g_value_set_boolean(value, priv->enable_default_context_menu); + break; + case PROP_ENABLE_SITE_SPECIFIC_QUIRKS: + g_value_set_boolean(value, priv->enable_site_specific_quirks); + break; + case PROP_ENABLE_PAGE_CACHE: + g_value_set_boolean(value, priv->enable_page_cache); + break; + case PROP_AUTO_RESIZE_WINDOW: + g_value_set_boolean(value, priv->auto_resize_window); + break; + case PROP_ENABLE_JAVA_APPLET: + g_value_set_boolean(value, priv->enable_java_applet); + break; + case PROP_ENABLE_HYPERLINK_AUDITING: + g_value_set_boolean(value, priv->enable_hyperlink_auditing); + break; + case PROP_ENABLE_FULLSCREEN: + g_value_set_boolean(value, priv->enable_fullscreen); + break; + case PROP_ENABLE_DNS_PREFETCHING: + g_value_set_boolean(value, priv->enable_dns_prefetching); + break; + case PROP_ENABLE_WEBGL: + g_value_set_boolean(value, priv->enable_webgl); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +/** + * webkit_web_settings_new: + * + * Creates a new #WebKitWebSettings instance with default values. It must + * be manually attached to a WebView. + * + * Returns: a new #WebKitWebSettings instance + **/ +WebKitWebSettings* webkit_web_settings_new() +{ + return WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, NULL)); +} + +/** + * webkit_web_settings_copy: + * + * Copies an existing #WebKitWebSettings instance. + * + * Returns: (transfer full): a new #WebKitWebSettings instance + **/ +WebKitWebSettings* webkit_web_settings_copy(WebKitWebSettings* web_settings) +{ + WebKitWebSettingsPrivate* priv = web_settings->priv; + + WebKitWebSettings* copy = WEBKIT_WEB_SETTINGS(g_object_new(WEBKIT_TYPE_WEB_SETTINGS, + "default-encoding", priv->default_encoding, + "cursive-font-family", priv->cursive_font_family, + "default-font-family", priv->default_font_family, + "fantasy-font-family", priv->fantasy_font_family, + "monospace-font-family", priv->monospace_font_family, + "sans-serif-font-family", priv->sans_serif_font_family, + "serif-font-family", priv->serif_font_family, + "default-font-size", priv->default_font_size, + "default-monospace-font-size", priv->default_monospace_font_size, + "minimum-font-size", priv->minimum_font_size, + "minimum-logical-font-size", priv->minimum_logical_font_size, + "auto-load-images", priv->auto_load_images, + "auto-shrink-images", priv->auto_shrink_images, + "print-backgrounds", priv->print_backgrounds, + "enable-scripts", priv->enable_scripts, + "enable-plugins", priv->enable_plugins, + "resizable-text-areas", priv->resizable_text_areas, + "user-stylesheet-uri", priv->user_stylesheet_uri, + "zoom-step", priv->zoom_step, + "enable-developer-extras", priv->enable_developer_extras, + "enable-private-browsing", priv->enable_private_browsing, + "enable-spell-checking", priv->enable_spell_checking, + "spell-checking-languages", priv->spell_checking_languages, + "enable-caret-browsing", priv->enable_caret_browsing, + "enable-html5-database", priv->enable_html5_database, + "enable-html5-local-storage", priv->enable_html5_local_storage, + "enable-xss-auditor", priv->enable_xss_auditor, + "enable-spatial-navigation", priv->enable_spatial_navigation, + "enable-frame-flattening", priv->enable_frame_flattening, + "user-agent", webkit_web_settings_get_user_agent(web_settings), + "javascript-can-open-windows-automatically", priv->javascript_can_open_windows_automatically, + "javascript-can-access-clipboard", priv->javascript_can_access_clipboard, + "enable-offline-web-application-cache", priv->enable_offline_web_application_cache, + "editing-behavior", priv->editing_behavior, + "enable-universal-access-from-file-uris", priv->enable_universal_access_from_file_uris, + "enable-file-access-from-file-uris", priv->enable_file_access_from_file_uris, + "enable-dom-paste", priv->enable_dom_paste, + "tab-key-cycles-through-elements", priv->tab_key_cycles_through_elements, + "enable-default-context-menu", priv->enable_default_context_menu, + "enable-site-specific-quirks", priv->enable_site_specific_quirks, + "enable-page-cache", priv->enable_page_cache, + "auto-resize-window", priv->auto_resize_window, + "enable-java-applet", priv->enable_java_applet, + "enable-hyperlink-auditing", priv->enable_hyperlink_auditing, + "enable-fullscreen", priv->enable_fullscreen, + "enable-dns-prefetching", priv->enable_dns_prefetching, + NULL)); + + return copy; +} + +/** + * webkit_web_settings_add_extra_plugin_directory: + * @web_view: a #WebKitWebView + * @directory: the directory to add + * + * Adds the @directory to paths where @web_view will search for plugins. + * + * Since: 1.0.3 + */ +void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* webView, const gchar* directory) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + PluginDatabase::installedPlugins()->addExtraPluginDirectory(filenameToString(directory)); +} + +/** + * webkit_web_settings_get_user_agent: + * @web_settings: a #WebKitWebSettings + * + * Returns the User-Agent string currently used by the web view(s) associated + * with the @web_settings. + * + * Since: 1.1.11 + */ +G_CONST_RETURN gchar* webkit_web_settings_get_user_agent(WebKitWebSettings* webSettings) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings), NULL); + + WebKitWebSettingsPrivate* priv = webSettings->priv; + + return priv->user_agent; +} + +namespace WebKit { + +WebCore::EditingBehaviorType core(WebKitEditingBehavior type) +{ + return (WebCore::EditingBehaviorType)type; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebsettings.h b/Source/WebKit/gtk/webkit/webkitwebsettings.h new file mode 100644 index 0000000..eee0d04 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebsettings.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2008 Christian Dywan <christian@imendio.com> + * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebsettings_h +#define webkitwebsettings_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_SETTINGS (webkit_web_settings_get_type()) +#define WEBKIT_WEB_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettings)) +#define WEBKIT_WEB_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsClass)) +#define WEBKIT_IS_WEB_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_SETTINGS)) +#define WEBKIT_IS_WEB_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_SETTINGS)) +#define WEBKIT_WEB_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_SETTINGS, WebKitWebSettingsClass)) + +typedef enum { + WEBKIT_EDITING_BEHAVIOR_MAC, + WEBKIT_EDITING_BEHAVIOR_WINDOWS, + WEBKIT_EDITING_BEHAVIOR_UNIX +} WebKitEditingBehavior; + +typedef struct _WebKitWebSettingsPrivate WebKitWebSettingsPrivate; + +struct _WebKitWebSettings { + GObject parent_instance; + + /*< private >*/ + WebKitWebSettingsPrivate *priv; +}; + +struct _WebKitWebSettingsClass { + GObjectClass parent_class; + + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_web_settings_get_type (void); + +WEBKIT_API WebKitWebSettings * +webkit_web_settings_new (void); + +WEBKIT_API WebKitWebSettings * +webkit_web_settings_copy (WebKitWebSettings *web_settings); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_settings_get_user_agent (WebKitWebSettings *web_settings); + +G_END_DECLS + +#endif /* webkitwebsettings_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebsettingsprivate.h b/Source/WebKit/gtk/webkit/webkitwebsettingsprivate.h new file mode 100644 index 0000000..9700ba5 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebsettingsprivate.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebsettingsprivate_h +#define webkitwebsettingsprivate_h + +#include "webkitwebsettings.h" + +extern "C" { + +WEBKIT_API void webkit_web_settings_add_extra_plugin_directory(WebKitWebView*, const gchar* directory); + +GSList* webkitWebViewGetEnchantDicts(WebKitWebView*); + +WTF::String webkitUserAgent(); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebview.cpp b/Source/WebKit/gtk/webkit/webkitwebview.cpp new file mode 100644 index 0000000..85ad904 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebview.cpp @@ -0,0 +1,5158 @@ +/* + * Copyright (C) 2007, 2008 Holger Hans Peter Freyther + * Copyright (C) 2007, 2008, 2009 Christian Dywan <christian@imendio.com> + * Copyright (C) 2007 Xan Lopez <xan@gnome.org> + * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com> + * Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com> + * Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org> + * Copyright (C) 2008 Nuanti Ltd. + * Copyright (C) 2008, 2009, 2010 Collabora Ltd. + * Copyright (C) 2009, 2010 Igalia S.L. + * Copyright (C) 2009 Movial Creative Technologies Inc. + * Copyright (C) 2009 Bobby Powers + * Copyright (C) 2010 Joone Hur <joone@kldp.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "webkitwebview.h" + +#include "AXObjectCache.h" +#include "AbstractDatabase.h" +#include "BackForwardListImpl.h" +#include "Chrome.h" +#include "ChromeClientGtk.h" +#include "ClipboardUtilitiesGtk.h" +#include "ContextMenu.h" +#include "ContextMenuClientGtk.h" +#include "ContextMenuController.h" +#include "Cursor.h" +#include "Document.h" +#include "DocumentLoader.h" +#include "DragActions.h" +#include "DragClientGtk.h" +#include "DragController.h" +#include "DragData.h" +#include "Editor.h" +#include "EditorClientGtk.h" +#include "EventHandler.h" +#include "FloatQuad.h" +#include "FocusController.h" +#include "FrameLoader.h" +#include "FrameLoaderTypes.h" +#include "FrameView.h" +#include "GOwnPtrGtk.h" +#include "GraphicsContext.h" +#include "GtkVersioning.h" +#include "HTMLNames.h" +#include "HitTestRequest.h" +#include "HitTestResult.h" +#include "IconDatabase.h" +#include "InspectorClientGtk.h" +#include "InspectorController.h" +#include "MemoryCache.h" +#include "MouseEventWithHitTestResults.h" +#include "NotImplemented.h" +#include "PageCache.h" +#include "Pasteboard.h" +#include "PasteboardHelper.h" +#include "PasteboardHelperGtk.h" +#include "PlatformKeyboardEvent.h" +#include "PlatformWheelEvent.h" +#include "ProgressTracker.h" +#include "RenderView.h" +#include "ResourceHandle.h" +#include "ScriptValue.h" +#include "Scrollbar.h" +#include "Settings.h" +#include "webkit/WebKitDOMDocumentPrivate.h" +#include "webkitdownload.h" +#include "webkitdownloadprivate.h" +#include "webkitenumtypes.h" +#include "webkitgeolocationpolicydecision.h" +#include "webkitglobalsprivate.h" +#include "webkithittestresultprivate.h" +#include "webkiticondatabase.h" +#include "webkitmarshal.h" +#include "webkitnetworkrequest.h" +#include "webkitnetworkresponse.h" +#include "webkitviewportattributes.h" +#include "webkitviewportattributesprivate.h" +#include "webkitwebbackforwardlist.h" +#include "webkitwebframeprivate.h" +#include "webkitwebhistoryitem.h" +#include "webkitwebhistoryitemprivate.h" +#include "webkitwebinspector.h" +#include "webkitwebinspectorprivate.h" +#include "webkitwebpolicydecision.h" +#include "webkitwebresource.h" +#include "webkitwebsettingsprivate.h" +#include "webkitwebplugindatabaseprivate.h" +#include "webkitwebwindowfeatures.h" +#include "webkitwebviewprivate.h" +#include <gdk/gdkkeysyms.h> +#include <glib/gi18n-lib.h> +#include <wtf/gobject/GOwnPtr.h> +#include <wtf/text/CString.h> + +/** + * SECTION:webkitwebview + * @short_description: The central class of the WebKitGTK+ API + * @see_also: #WebKitWebSettings, #WebKitWebFrame + * + * #WebKitWebView is the central class of the WebKitGTK+ API. It is a + * #GtkWidget implementing the scrolling interface which means you can + * embed in a #GtkScrolledWindow. It is responsible for managing the + * drawing of the content, forwarding of events. You can load any URI + * into the #WebKitWebView or any kind of data string. With #WebKitWebSettings + * you can control various aspects of the rendering and loading of the content. + * Each #WebKitWebView has exactly one #WebKitWebFrame as main frame. A + * #WebKitWebFrame can have n children. + * + * <programlisting> + * /<!-- -->* Create the widgets *<!-- -->/ + * GtkWidget *main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + * GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); + * GtkWidget *web_view = webkit_web_view_new (); + * + * /<!-- -->* Place the WebKitWebView in the GtkScrolledWindow *<!-- -->/ + * gtk_container_add (GTK_CONTAINER (scrolled_window), web_view); + * gtk_container_add (GTK_CONTAINER (main_window), scrolled_window); + * + * /<!-- -->* Open a webpage *<!-- -->/ + * webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), "http://www.gnome.org"); + * + * /<!-- -->* Show the result *<!-- -->/ + * gtk_window_set_default_size (GTK_WINDOW (main_window), 800, 600); + * gtk_widget_show_all (main_window); + * </programlisting> + */ + +static const double defaultDPI = 96.0; +static IntPoint globalPointForClientPoint(GdkWindow* window, const IntPoint& clientPoint); + +using namespace WebKit; +using namespace WebCore; + +enum { + /* normal signals */ + NAVIGATION_REQUESTED, + NEW_WINDOW_POLICY_DECISION_REQUESTED, + NAVIGATION_POLICY_DECISION_REQUESTED, + MIME_TYPE_POLICY_DECISION_REQUESTED, + CREATE_WEB_VIEW, + WEB_VIEW_READY, + WINDOW_OBJECT_CLEARED, + LOAD_STARTED, + LOAD_COMMITTED, + LOAD_PROGRESS_CHANGED, + LOAD_ERROR, + LOAD_FINISHED, + TITLE_CHANGED, + HOVERING_OVER_LINK, + POPULATE_POPUP, + STATUS_BAR_TEXT_CHANGED, + ICON_LOADED, + SELECTION_CHANGED, + CONSOLE_MESSAGE, + SCRIPT_ALERT, + SCRIPT_CONFIRM, + SCRIPT_PROMPT, + SELECT_ALL, + COPY_CLIPBOARD, + PASTE_CLIPBOARD, + CUT_CLIPBOARD, + DOWNLOAD_REQUESTED, + MOVE_CURSOR, + PRINT_REQUESTED, + PLUGIN_WIDGET, + CLOSE_WEB_VIEW, + UNDO, + REDO, + DATABASE_QUOTA_EXCEEDED, + RESOURCE_REQUEST_STARTING, + DOCUMENT_LOAD_FINISHED, + GEOLOCATION_POLICY_DECISION_REQUESTED, + GEOLOCATION_POLICY_DECISION_CANCELLED, + ONLOAD_EVENT, + FRAME_CREATED, + SHOULD_BEGIN_EDITING, + SHOULD_END_EDITING, + SHOULD_INSERT_NODE, + SHOULD_INSERT_TEXT, + SHOULD_DELETE_RANGE, + SHOULD_SHOW_DELETE_INTERFACE_FOR_ELEMENT, + SHOULD_CHANGE_SELECTED_RANGE, + SHOULD_APPLY_STYLE, + EDITING_BEGAN, + USER_CHANGED_CONTENTS, + EDITING_ENDED, + VIEWPORT_ATTRIBUTES_RECOMPUTE_REQUESTED, + VIEWPORT_ATTRIBUTES_CHANGED, + + LAST_SIGNAL +}; + +enum { + PROP_0, + + PROP_TITLE, + PROP_URI, + PROP_COPY_TARGET_LIST, + PROP_PASTE_TARGET_LIST, + PROP_EDITABLE, + PROP_SETTINGS, + PROP_WEB_INSPECTOR, + PROP_VIEWPORT_ATTRIBUTES, + PROP_WINDOW_FEATURES, + PROP_TRANSPARENT, + PROP_ZOOM_LEVEL, + PROP_FULL_CONTENT_ZOOM, + PROP_LOAD_STATUS, + PROP_PROGRESS, + PROP_ENCODING, + PROP_CUSTOM_ENCODING, + PROP_ICON_URI, + PROP_IM_CONTEXT, +#ifdef GTK_API_VERSION_2 + PROP_VIEW_MODE +#else + PROP_VIEW_MODE, + PROP_HADJUSTMENT, + PROP_VADJUSTMENT, + PROP_HSCROLL_POLICY, + PROP_VSCROLL_POLICY +#endif +}; + +static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, }; + +#ifdef GTK_API_VERSION_2 +G_DEFINE_TYPE(WebKitWebView, webkit_web_view, GTK_TYPE_CONTAINER) +#else +G_DEFINE_TYPE_WITH_CODE(WebKitWebView, webkit_web_view, GTK_TYPE_CONTAINER, + G_IMPLEMENT_INTERFACE(GTK_TYPE_SCROLLABLE, 0)) +#endif + +static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView); +static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures); + +static GtkIMContext* webkit_web_view_get_im_context(WebKitWebView*); + +static void PopupMenuPositionFunc(GtkMenu* menu, gint *x, gint *y, gboolean *pushIn, gpointer userData) +{ + WebKitWebView* view = WEBKIT_WEB_VIEW(userData); + WebKitWebViewPrivate* priv = view->priv; + GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(view)); + GtkRequisition menuSize; + +#ifdef GTK_API_VERSION_2 + gtk_widget_size_request(GTK_WIDGET(menu), &menuSize); +#else + gtk_widget_get_preferred_size(GTK_WIDGET(menu), &menuSize, NULL); +#endif + + *x = priv->lastPopupXPosition; + if ((*x + menuSize.width) >= gdk_screen_get_width(screen)) + *x -= menuSize.width; + + *y = priv->lastPopupYPosition; + if ((*y + menuSize.height) >= gdk_screen_get_height(screen)) + *y -= menuSize.height; + + *pushIn = FALSE; +} + +static Node* getFocusedNode(Frame* frame) +{ + if (Document* doc = frame->document()) + return doc->focusedNode(); + return 0; +} + +static void contextMenuItemActivated(GtkMenuItem* item, ContextMenuController* controller) +{ + ContextMenuItem contextItem(item); + controller->contextMenuItemSelected(&contextItem); +} + +static void contextMenuConnectActivate(GtkMenuItem* item, ContextMenuController* controller) +{ + if (GTK_IS_SEPARATOR_MENU_ITEM(item)) + return; + + if (GtkWidget* menu = gtk_menu_item_get_submenu(item)) { + gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback)contextMenuConnectActivate, controller); + return; + } + + g_signal_connect(item, "activate", G_CALLBACK(contextMenuItemActivated), controller); +} + +static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event) +{ + Page* page = core(webView); + page->contextMenuController()->clearContextMenu(); + Frame* focusedFrame; + Frame* mainFrame = page->mainFrame(); + gboolean mousePressEventResult = FALSE; + + if (!mainFrame->view()) + return FALSE; + + mainFrame->view()->setCursor(pointerCursor()); + if (page->frameCount()) { + HitTestRequest request(HitTestRequest::Active); + IntPoint point = mainFrame->view()->windowToContents(event.pos()); + MouseEventWithHitTestResults mev = mainFrame->document()->prepareMouseEvent(request, point, event); + + Frame* targetFrame = EventHandler::subframeForHitTestResult(mev); + if (!targetFrame) + targetFrame = mainFrame; + + focusedFrame = page->focusController()->focusedOrMainFrame(); + if (targetFrame != focusedFrame) { + page->focusController()->setFocusedFrame(targetFrame); + focusedFrame = targetFrame; + } + } else + focusedFrame = mainFrame; + + if (focusedFrame->view() && focusedFrame->eventHandler()->handleMousePressEvent(event)) + mousePressEventResult = TRUE; + + + bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event); + if (!handledEvent) + return FALSE; + + // If coreMenu is NULL, this means WebCore decided to not create + // the default context menu; this may happen when the page is + // handling the right-click for reasons other than the context menu. + ContextMenuController* controller = page->contextMenuController(); + ContextMenu* coreMenu = controller->contextMenu(); + if (!coreMenu) + return mousePressEventResult; + + // If we reach here, it's because WebCore is going to show the + // default context menu. We check our setting to figure out + // whether we want it or not. + WebKitWebSettings* settings = webkit_web_view_get_settings(webView); + gboolean enableDefaultContextMenu; + g_object_get(settings, "enable-default-context-menu", &enableDefaultContextMenu, NULL); + + if (!enableDefaultContextMenu) + return FALSE; + + GtkMenu* menu = GTK_MENU(coreMenu->platformDescription()); + if (!menu) + return FALSE; + + // We connect the "activate" signal here rather than in ContextMenuGtk to avoid + // a layering violation. ContextMenuGtk should not know about the ContextMenuController. + gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback)contextMenuConnectActivate, controller); + + g_signal_emit(webView, webkit_web_view_signals[POPULATE_POPUP], 0, menu); + + // If the context menu is now empty, don't show it. + GOwnPtr<GList> items(gtk_container_get_children(GTK_CONTAINER(menu))); + if (!items) + return FALSE; + + WebKitWebViewPrivate* priv = webView->priv; + priv->currentMenu = menu; + priv->lastPopupXPosition = event.globalX(); + priv->lastPopupYPosition = event.globalY(); + + gtk_menu_popup(menu, 0, 0, &PopupMenuPositionFunc, webView, event.button() + 1, gtk_get_current_event_time()); + return TRUE; +} + +static const int gContextMenuMargin = 1; +static IntPoint getLocationForKeyboardGeneratedContextMenu(Frame* frame) +{ + SelectionController* selection = frame->selection(); + if (!selection->selection().isNonOrphanedCaretOrRange() + || (selection->selection().isCaret() && !selection->selection().isContentEditable())) { + if (Node* focusedNode = getFocusedNode(frame)) + return focusedNode->getRect().location(); + + // There was no selection and no focused node, so just put the context + // menu into the corner of the view, offset slightly. + return IntPoint(gContextMenuMargin, gContextMenuMargin); + } + + // selection->selection().firstRange can return 0 here, but if that was the case + // selection->selection().isNonOrphanedCaretOrRange() would have returned false + // above, so we do not have to check it. + IntRect firstRect = frame->editor()->firstRectForRange(selection->selection().firstRange().get()); + return IntPoint(firstRect.x(), firstRect.maxY()); +} + +static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget) +{ + Frame* frame = core(WEBKIT_WEB_VIEW(widget))->focusController()->focusedOrMainFrame(); + IntPoint location = getLocationForKeyboardGeneratedContextMenu(frame); + + FrameView* view = frame->view(); + if (!view) + return FALSE; + + // Never let the context menu touch the very edge of the view. + location = view->contentsToWindow(location); + location.expandedTo(IntPoint(gContextMenuMargin, gContextMenuMargin)); + location.shrunkTo(IntPoint(view->width() - gContextMenuMargin, view->height() - gContextMenuMargin)); + + IntPoint globalPoint(globalPointForClientPoint(gtk_widget_get_window(widget), location)); + PlatformMouseEvent event(location, globalPoint, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time()); + return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event); +} + +#ifndef GTK_API_VERSION_2 +static void setHorizontalAdjustment(WebKitWebView* webView, GtkAdjustment* adjustment) +{ + if (!core(webView)) + return; + + webView->priv->horizontalAdjustment = adjustment; + FrameView* view = core(webkit_web_view_get_main_frame(webView))->view(); + if (!view) + return; + view->setHorizontalAdjustment(adjustment); +} + +static void setVerticalAdjustment(WebKitWebView* webView, GtkAdjustment* adjustment) +{ + if (!core(webView)) + return; + + webView->priv->verticalAdjustment = adjustment; + FrameView* view = core(webkit_web_view_get_main_frame(webView))->view(); + if (!view) + return; + view->setVerticalAdjustment(adjustment); +} + +static GtkAdjustment* getHorizontalAdjustment(WebKitWebView* webView) +{ + return webView->priv->horizontalAdjustment.get(); +} + +static GtkAdjustment* getVerticalAdjustment(WebKitWebView* webView) +{ + return webView->priv->verticalAdjustment.get(); +} + +static void setHorizontalScrollPolicy(WebKitWebView* webView, GtkScrollablePolicy policy) +{ + webView->priv->horizontalScrollingPolicy = policy; + gtk_widget_queue_resize(GTK_WIDGET(webView)); +} + +static void setVerticalScrollPolicy(WebKitWebView* webView, GtkScrollablePolicy policy) +{ + webView->priv->verticalScrollingPolicy = policy; + gtk_widget_queue_resize(GTK_WIDGET(webView)); +} + +static GtkScrollablePolicy getHorizontalScrollPolicy(WebKitWebView* webView) +{ + return webView->priv->horizontalScrollingPolicy; +} + +static GtkScrollablePolicy getVerticalScrollPolicy(WebKitWebView* webView) +{ + return webView->priv->verticalScrollingPolicy; +} + +#endif + +static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + + switch(prop_id) { + case PROP_TITLE: + g_value_set_string(value, webkit_web_view_get_title(webView)); + break; + case PROP_URI: + g_value_set_string(value, webkit_web_view_get_uri(webView)); + break; + case PROP_COPY_TARGET_LIST: + g_value_set_boxed(value, webkit_web_view_get_copy_target_list(webView)); + break; + case PROP_PASTE_TARGET_LIST: + g_value_set_boxed(value, webkit_web_view_get_paste_target_list(webView)); + break; + case PROP_EDITABLE: + g_value_set_boolean(value, webkit_web_view_get_editable(webView)); + break; + case PROP_SETTINGS: + g_value_set_object(value, webkit_web_view_get_settings(webView)); + break; + case PROP_WEB_INSPECTOR: + g_value_set_object(value, webkit_web_view_get_inspector(webView)); + break; + case PROP_VIEWPORT_ATTRIBUTES: + g_value_set_object(value, webkit_web_view_get_viewport_attributes(webView)); + break; + case PROP_WINDOW_FEATURES: + g_value_set_object(value, webkit_web_view_get_window_features(webView)); + break; + case PROP_TRANSPARENT: + g_value_set_boolean(value, webkit_web_view_get_transparent(webView)); + break; + case PROP_ZOOM_LEVEL: + g_value_set_float(value, webkit_web_view_get_zoom_level(webView)); + break; + case PROP_FULL_CONTENT_ZOOM: + g_value_set_boolean(value, webkit_web_view_get_full_content_zoom(webView)); + break; + case PROP_ENCODING: + g_value_set_string(value, webkit_web_view_get_encoding(webView)); + break; + case PROP_CUSTOM_ENCODING: + g_value_set_string(value, webkit_web_view_get_custom_encoding(webView)); + break; + case PROP_LOAD_STATUS: + g_value_set_enum(value, webkit_web_view_get_load_status(webView)); + break; + case PROP_PROGRESS: + g_value_set_double(value, webkit_web_view_get_progress(webView)); + break; + case PROP_ICON_URI: + g_value_set_string(value, webkit_web_view_get_icon_uri(webView)); + break; + case PROP_IM_CONTEXT: + g_value_set_object(value, webkit_web_view_get_im_context(webView)); + break; + case PROP_VIEW_MODE: + g_value_set_enum(value, webkit_web_view_get_view_mode(webView)); + break; +#ifndef GTK_API_VERSION_2 + case PROP_HADJUSTMENT: + g_value_set_object(value, getHorizontalAdjustment(webView)); + break; + case PROP_VADJUSTMENT: + g_value_set_object(value, getVerticalAdjustment(webView)); + break; + case PROP_HSCROLL_POLICY: + g_value_set_enum(value, getHorizontalScrollPolicy(webView)); + break; + case PROP_VSCROLL_POLICY: + g_value_set_enum(value, getVerticalScrollPolicy(webView)); + break; +#endif + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void webkit_web_view_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + + switch(prop_id) { + case PROP_EDITABLE: + webkit_web_view_set_editable(webView, g_value_get_boolean(value)); + break; + case PROP_SETTINGS: + webkit_web_view_set_settings(webView, WEBKIT_WEB_SETTINGS(g_value_get_object(value))); + break; + case PROP_WINDOW_FEATURES: + webkit_web_view_set_window_features(webView, WEBKIT_WEB_WINDOW_FEATURES(g_value_get_object(value))); + break; + case PROP_TRANSPARENT: + webkit_web_view_set_transparent(webView, g_value_get_boolean(value)); + break; + case PROP_ZOOM_LEVEL: + webkit_web_view_set_zoom_level(webView, g_value_get_float(value)); + break; + case PROP_FULL_CONTENT_ZOOM: + webkit_web_view_set_full_content_zoom(webView, g_value_get_boolean(value)); + break; + case PROP_CUSTOM_ENCODING: + webkit_web_view_set_custom_encoding(webView, g_value_get_string(value)); + break; + case PROP_VIEW_MODE: + webkit_web_view_set_view_mode(webView, static_cast<WebKitWebViewViewMode>(g_value_get_enum(value))); + break; +#ifndef GTK_API_VERSION_2 + case PROP_HADJUSTMENT: + setHorizontalAdjustment(webView, static_cast<GtkAdjustment*>(g_value_get_object(value))); + break; + case PROP_VADJUSTMENT: + setVerticalAdjustment(webView, static_cast<GtkAdjustment*>(g_value_get_object(value))); + break; + case PROP_HSCROLL_POLICY: + setHorizontalScrollPolicy(webView, static_cast<GtkScrollablePolicy>(g_value_get_enum(value))); + break; + case PROP_VSCROLL_POLICY: + setVerticalScrollPolicy(webView, static_cast<GtkScrollablePolicy>(g_value_get_enum(value))); + break; +#endif + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static bool shouldCoalesce(const IntRect& rect, const Vector<IntRect>& rects) +{ + const unsigned int cRectThreshold = 10; + const float cWastedSpaceThreshold = 0.75f; + bool useUnionedRect = (rects.size() <= 1) || (rects.size() > cRectThreshold); + if (useUnionedRect) + return true; + // Attempt to guess whether or not we should use the unioned rect or the individual rects. + // We do this by computing the percentage of "wasted space" in the union. If that wasted space + // is too large, then we will do individual rect painting instead. + float unionPixels = (rect.width() * rect.height()); + float singlePixels = 0; + for (size_t i = 0; i < rects.size(); ++i) + singlePixels += rects[i].width() * rects[i].height(); + float wastedSpace = 1 - (singlePixels / unionPixels); + if (wastedSpace <= cWastedSpaceThreshold) + useUnionedRect = true; + return useUnionedRect; +} + +static void paintWebView(Frame* frame, gboolean transparent, GraphicsContext& context, const IntRect& clipRect, const Vector<IntRect>& rects) +{ + bool coalesce = true; + + if (rects.size() > 0) + coalesce = shouldCoalesce(clipRect, rects); + + if (coalesce) { + context.clip(clipRect); + if (transparent) + context.clearRect(clipRect); + frame->view()->paint(&context, clipRect); + } else { + for (size_t i = 0; i < rects.size(); i++) { + IntRect rect = rects[i]; + context.save(); + context.clip(rect); + if (transparent) + context.clearRect(rect); + frame->view()->paint(&context, rect); + context.restore(); + } + } + + context.save(); + context.clip(clipRect); + frame->page()->inspectorController()->drawNodeHighlight(context); + context.restore(); +} +#ifdef GTK_API_VERSION_2 +static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + Frame* frame = core(webView)->mainFrame(); + if (frame->contentRenderer() && frame->view()) { + frame->view()->updateLayoutAndStyleIfNeededRecursive(); + + RefPtr<cairo_t> cr = adoptRef(gdk_cairo_create(event->window)); + GraphicsContext gc(cr.get()); + gc.setGdkExposeEvent(event); + + int rectCount; + GOwnPtr<GdkRectangle> rects; + gdk_region_get_rectangles(event->region, &rects.outPtr(), &rectCount); + Vector<IntRect> paintRects; + for (int i = 0; i < rectCount; i++) + paintRects.append(IntRect(rects.get()[i])); + + paintWebView(frame, priv->transparent, gc, static_cast<IntRect>(event->area), paintRects); + } + + return FALSE; +} +#else +static gboolean webkit_web_view_draw(GtkWidget* widget, cairo_t* cr) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + GdkRectangle clipRect; + + if (!gdk_cairo_get_clip_rectangle(cr, &clipRect)) + return FALSE; + + Frame* frame = core(webView)->mainFrame(); + if (frame->contentRenderer() && frame->view()) { + GraphicsContext gc(cr); + IntRect rect = clipRect; + cairo_rectangle_list_t* rectList = cairo_copy_clip_rectangle_list(cr); + + frame->view()->updateLayoutAndStyleIfNeededRecursive(); + + Vector<IntRect> rects; + if (!rectList->status && rectList->num_rectangles > 0) { + for (int i = 0; i < rectList->num_rectangles; i++) + rects.append(enclosingIntRect(FloatRect(rectList->rectangles[i]))); + } + paintWebView(frame, priv->transparent, gc, rect, rects); + + cairo_rectangle_list_destroy(rectList); + } + + return FALSE; +} +#endif // GTK_API_VERSION_2 + +static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + PlatformKeyboardEvent keyboardEvent(event); + + if (!frame->view()) + return FALSE; + + if (frame->eventHandler()->keyEvent(keyboardEvent)) + return TRUE; + + /* Chain up to our parent class for binding activation */ + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event); +} + +static gboolean webkit_web_view_key_release_event(GtkWidget* widget, GdkEventKey* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + // GTK+ IM contexts often require us to filter key release events, which + // WebCore does not do by default, so we filter the event here. We only block + // the event if we don't have a pending composition, because that means we + // are using a context like 'simple' which marks every keystroke as filtered. + WebKit::EditorClient* client = static_cast<WebKit::EditorClient*>(core(webView)->editorClient()); + if (gtk_im_context_filter_keypress(webView->priv->imContext.get(), event) && !client->hasPendingComposition()) + return TRUE; + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + if (!frame->view()) + return FALSE; + + PlatformKeyboardEvent keyboardEvent(event); + if (frame->eventHandler()->keyEvent(keyboardEvent)) + return TRUE; + + /* Chain up to our parent class for binding activation */ + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_release_event(widget, event); +} + +static guint32 getEventTime(GdkEvent* event) +{ + guint32 time = gdk_event_get_time(event); + if (time) + return time; + + // Real events always have a non-zero time, but events synthesized + // by the DRT do not and we must calculate a time manually. This time + // is not calculated in the DRT, because GTK+ does not work well with + // anything other than GDK_CURRENT_TIME on synthesized events. + GTimeVal timeValue; + g_get_current_time(&timeValue); + return (timeValue.tv_sec * 1000) + (timeValue.tv_usec / 1000); +} + +static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + // FIXME: need to keep track of subframe focus for key events + gtk_widget_grab_focus(widget); + + // For double and triple clicks GDK sends both a normal button press event + // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press + // coming up, ignore this event as it certainly generated the double or triple + // click. The consequence of not eating this event is two DOM button press events + // are generated. + GOwnPtr<GdkEvent> nextEvent(gdk_event_peek()); + if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS)) + return TRUE; + + gint doubleClickDistance = 250; + gint doubleClickTime = 5; + GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); + g_object_get(settings, + "gtk-double-click-distance", &doubleClickDistance, + "gtk-double-click-time", &doubleClickTime, NULL); + + // GTK+ only counts up to triple clicks, but WebCore wants to know about + // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the + // GDK logic for counting clicks. + guint32 eventTime = getEventTime(reinterpret_cast<GdkEvent*>(event)); + if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) + || ((abs(event->x - priv->previousClickPoint.x()) < doubleClickDistance) + && (abs(event->y - priv->previousClickPoint.y()) < doubleClickDistance) + && (eventTime - priv->previousClickTime < static_cast<guint>(doubleClickTime)) + && (event->button == priv->previousClickButton))) + priv->currentClickCount++; + else + priv->currentClickCount = 1; + + PlatformMouseEvent platformEvent(event); + platformEvent.setClickCount(priv->currentClickCount); + priv->previousClickPoint = platformEvent.pos(); + priv->previousClickButton = event->button; + priv->previousClickTime = eventTime; + + if (event->button == 3) + return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event)); + + Frame* frame = core(webView)->mainFrame(); + if (!frame->view()) + return FALSE; + + gboolean result = frame->eventHandler()->handleMousePressEvent(platformEvent); + // Handle the IM context when a mouse press fires + static_cast<WebKit::EditorClient*>(core(webView)->editorClient())->handleInputMethodMousePress(); + +#if PLATFORM(X11) + /* Copy selection to the X11 selection clipboard */ + if (event->button == 2) { + bool primary = webView->priv->usePrimaryForPaste; + webView->priv->usePrimaryForPaste = true; + + Editor* editor = webView->priv->corePage->focusController()->focusedOrMainFrame()->editor(); + result = result || editor->canPaste() || editor->canDHTMLPaste(); + editor->paste(); + + webView->priv->usePrimaryForPaste = primary; + } +#endif + + return result; +} + +static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEventButton* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + Frame* focusedFrame = core(webView)->focusController()->focusedFrame(); + + if (focusedFrame && focusedFrame->editor()->canEdit()) { +#ifdef MAEMO_CHANGES + WebKitWebViewPrivate* priv = webView->priv; + hildon_gtk_im_context_filter_event(priv->imContext.get(), (GdkEvent*)event); +#endif + } + + Frame* mainFrame = core(webView)->mainFrame(); + if (mainFrame->view()) + mainFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event)); + + /* We always return FALSE here because WebKit can, for the same click, decide + * to not handle press-event but handle release-event, which can totally confuse + * some GTK+ containers when there are no other events in between. This way we + * guarantee that this case never happens, and that if press-event goes through + * release-event also goes through. + */ + + return FALSE; +} + +static gboolean webkit_web_view_motion_event(GtkWidget* widget, GdkEventMotion* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + Frame* frame = core(webView)->mainFrame(); + if (!frame->view()) + return FALSE; + + return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event)); +} + +static gboolean webkit_web_view_scroll_event(GtkWidget* widget, GdkEventScroll* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + Frame* frame = core(webView)->mainFrame(); + if (!frame->view()) + return FALSE; + + PlatformWheelEvent wheelEvent(event); + return frame->eventHandler()->handleWheelEvent(wheelEvent); +} + +#ifdef GTK_API_VERSION_2 +static void webkit_web_view_size_request(GtkWidget* widget, GtkRequisition* requisition) +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(widget); + Frame* coreFrame = core(webkit_web_view_get_main_frame(web_view)); + if (!coreFrame) + return; + + FrameView* view = coreFrame->view(); + if (!view) + return; + + requisition->width = view->contentsWidth(); + requisition->height = view->contentsHeight(); +} +#else +static void webkit_web_view_get_preferred_width(GtkWidget* widget, gint* minimum, gint* natural) +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(widget); + Frame* coreFrame = core(webkit_web_view_get_main_frame(web_view)); + if (!coreFrame) + return; + + FrameView* view = coreFrame->view(); + if (!view) + return; + + *minimum = *natural = view->contentsWidth(); +} + +static void webkit_web_view_get_preferred_height(GtkWidget* widget, gint* minimum, gint* natural) +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(widget); + Frame* coreFrame = core(webkit_web_view_get_main_frame(web_view)); + if (!coreFrame) + return; + + FrameView* view = coreFrame->view(); + if (!view) + return; + + *minimum = *natural = view->contentsHeight(); +} +#endif + +static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation) +{ + GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget,allocation); + + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + Frame* frame = core(webView)->mainFrame(); + if (!frame->view()) + return; + + frame->view()->resize(allocation->width, allocation->height); +} + +static void webkit_web_view_grab_focus(GtkWidget* widget) +{ + + if (gtk_widget_is_sensitive(widget)) { + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + FocusController* focusController = core(webView)->focusController(); + + focusController->setActive(true); + + if (focusController->focusedFrame()) + focusController->setFocused(true); + else + focusController->setFocusedFrame(core(webView)->mainFrame()); + } + + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->grab_focus(widget); +} + +static gboolean webkit_web_view_focus_in_event(GtkWidget* widget, GdkEventFocus* event) +{ + // TODO: Improve focus handling as suggested in + // http://bugs.webkit.org/show_bug.cgi?id=16910 + GtkWidget* toplevel = gtk_widget_get_toplevel(widget); + if (gtk_widget_is_toplevel(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) { + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + FocusController* focusController = core(webView)->focusController(); + + focusController->setActive(true); + + if (focusController->focusedFrame()) + focusController->setFocused(true); + else + focusController->setFocusedFrame(core(webView)->mainFrame()); + + if (focusController->focusedFrame()->editor()->canEdit()) + gtk_im_context_focus_in(webView->priv->imContext.get()); + } + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_in_event(widget, event); +} + +static gboolean webkit_web_view_focus_out_event(GtkWidget* widget, GdkEventFocus* event) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + // We may hit this code while destroying the widget, and we might + // no longer have a page, then. + Page* page = core(webView); + if (page) { + page->focusController()->setActive(false); + page->focusController()->setFocused(false); + } + + if (webView->priv->imContext) + gtk_im_context_focus_out(webView->priv->imContext.get()); + + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_out_event(widget, event); +} + +static void webkit_web_view_realize(GtkWidget* widget) +{ + gtk_widget_set_realized(widget, TRUE); + + GtkAllocation allocation; +#if GTK_CHECK_VERSION(2, 18, 0) + gtk_widget_get_allocation(widget, &allocation); +#else + allocation = widget->allocation; +#endif + + GdkWindowAttr attributes; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual(widget); +#ifdef GTK_API_VERSION_2 + attributes.colormap = gtk_widget_get_colormap(widget); +#endif + attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK + | GDK_EXPOSURE_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_POINTER_MOTION_MASK + | GDK_KEY_PRESS_MASK + | GDK_KEY_RELEASE_MASK + | GDK_BUTTON_MOTION_MASK + | GDK_BUTTON1_MOTION_MASK + | GDK_BUTTON2_MOTION_MASK + | GDK_BUTTON3_MOTION_MASK; + + gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; +#ifdef GTK_API_VERSION_2 + attributes_mask |= GDK_WA_COLORMAP; +#endif + GdkWindow* window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask); + gtk_widget_set_window(widget, window); + gdk_window_set_user_data(window, widget); + +#ifdef GTK_API_VERSION_2 +#if GTK_CHECK_VERSION(2, 20, 0) + gtk_widget_style_attach(widget); +#else + widget->style = gtk_style_attach(gtk_widget_get_style(widget), window); +#endif + gtk_style_set_background(gtk_widget_get_style(widget), window, GTK_STATE_NORMAL); +#else + gtk_style_context_set_background(gtk_widget_get_style_context(widget), window); +#endif + + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + gtk_im_context_set_client_window(priv->imContext.get(), window); +} + +#ifdef GTK_API_VERSION_2 +static void webkit_web_view_set_scroll_adjustments(WebKitWebView* webView, GtkAdjustment* hadj, GtkAdjustment* vadj) +{ + if (!core(webView)) + return; + + webView->priv->horizontalAdjustment = hadj; + webView->priv->verticalAdjustment = vadj; + + FrameView* view = core(webkit_web_view_get_main_frame(webView))->view(); + if (!view) + return; + view->setGtkAdjustments(hadj, vadj); +} +#endif + +static void webkit_web_view_container_add(GtkContainer* container, GtkWidget* widget) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(container); + WebKitWebViewPrivate* priv = webView->priv; + + priv->children.add(widget); + gtk_widget_set_parent(widget, GTK_WIDGET(container)); +} + +static void webkit_web_view_container_remove(GtkContainer* container, GtkWidget* widget) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(container); + WebKitWebViewPrivate* priv = webView->priv; + + if (priv->children.contains(widget)) { + gtk_widget_unparent(widget); + priv->children.remove(widget); + } +} + +static void webkit_web_view_container_forall(GtkContainer* container, gboolean, GtkCallback callback, gpointer callbackData) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(container); + WebKitWebViewPrivate* priv = webView->priv; + + HashSet<GtkWidget*> children = priv->children; + HashSet<GtkWidget*>::const_iterator end = children.end(); + for (HashSet<GtkWidget*>::const_iterator current = children.begin(); current != end; ++current) + (*callback)(*current, callbackData); +} + +static WebKitWebView* webkit_web_view_real_create_web_view(WebKitWebView*, WebKitWebFrame*) +{ + return 0; +} + +static gboolean webkit_web_view_real_web_view_ready(WebKitWebView*) +{ + return FALSE; +} + +static gboolean webkit_web_view_real_close_web_view(WebKitWebView*) +{ + return FALSE; +} + +static WebKitNavigationResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame*, WebKitNetworkRequest*) +{ + return WEBKIT_NAVIGATION_RESPONSE_ACCEPT; +} + +static void webkit_web_view_real_window_object_cleared(WebKitWebView*, WebKitWebFrame*, JSGlobalContextRef context, JSObjectRef window_object) +{ + notImplemented(); +} + +static gchar* webkit_web_view_real_choose_file(WebKitWebView*, WebKitWebFrame*, const gchar* old_name) +{ + notImplemented(); + return g_strdup(old_name); +} + +typedef enum { + WEBKIT_SCRIPT_DIALOG_ALERT, + WEBKIT_SCRIPT_DIALOG_CONFIRM, + WEBKIT_SCRIPT_DIALOG_PROMPT + } WebKitScriptDialogType; + +static gboolean webkit_web_view_script_dialog(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, WebKitScriptDialogType type, const gchar* defaultValue, gchar** value) +{ + GtkMessageType messageType; + GtkButtonsType buttons; + gint defaultResponse; + GtkWidget* window; + GtkWidget* dialog; + GtkWidget* entry = 0; + gboolean didConfirm = FALSE; + + switch (type) { + case WEBKIT_SCRIPT_DIALOG_ALERT: + messageType = GTK_MESSAGE_WARNING; + buttons = GTK_BUTTONS_CLOSE; + defaultResponse = GTK_RESPONSE_CLOSE; + break; + case WEBKIT_SCRIPT_DIALOG_CONFIRM: + messageType = GTK_MESSAGE_QUESTION; + buttons = GTK_BUTTONS_OK_CANCEL; + defaultResponse = GTK_RESPONSE_OK; + break; + case WEBKIT_SCRIPT_DIALOG_PROMPT: + messageType = GTK_MESSAGE_QUESTION; + buttons = GTK_BUTTONS_OK_CANCEL; + defaultResponse = GTK_RESPONSE_OK; + break; + default: + g_warning("Unknown value for WebKitScriptDialogType."); + return FALSE; + } + + window = gtk_widget_get_toplevel(GTK_WIDGET(webView)); + dialog = gtk_message_dialog_new(gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : 0, GTK_DIALOG_DESTROY_WITH_PARENT, messageType, buttons, "%s", message); + gchar* title = g_strconcat("JavaScript - ", webkit_web_frame_get_uri(frame), NULL); + gtk_window_set_title(GTK_WINDOW(dialog), title); + g_free(title); + + if (type == WEBKIT_SCRIPT_DIALOG_PROMPT) { + entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(entry), defaultValue); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), entry); + gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); + gtk_widget_show(entry); + } + + gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse); + gint response = gtk_dialog_run(GTK_DIALOG(dialog)); + + switch (response) { + case GTK_RESPONSE_OK: + didConfirm = TRUE; + if (entry) + *value = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); + break; + case GTK_RESPONSE_CANCEL: + didConfirm = FALSE; + break; + + } + gtk_widget_destroy(GTK_WIDGET(dialog)); + return didConfirm; +} + +static gboolean webkit_web_view_real_script_alert(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message) +{ + webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_ALERT, 0, 0); + return TRUE; +} + +static gboolean webkit_web_view_real_script_confirm(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, gboolean* didConfirm) +{ + *didConfirm = webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_CONFIRM, 0, 0); + return TRUE; +} + +static gboolean webkit_web_view_real_script_prompt(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, const gchar* defaultValue, gchar** value) +{ + if (!webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_PROMPT, defaultValue, value)) + *value = NULL; + return TRUE; +} + +static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, const gchar* message, unsigned int line, const gchar* sourceId) +{ + g_message("console message: %s @%d: %s\n", sourceId, line, message); + return TRUE; +} + +static void webkit_web_view_real_select_all(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("SelectAll").execute(); +} + +static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("Cut").execute(); +} + +static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("Copy").execute(); +} + +static void webkit_web_view_real_undo(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("Undo").execute(); +} + +static void webkit_web_view_real_redo(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("Redo").execute(); +} + +static gboolean webkit_web_view_real_move_cursor (WebKitWebView* webView, GtkMovementStep step, gint count) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW (webView), FALSE); + g_return_val_if_fail(step == GTK_MOVEMENT_VISUAL_POSITIONS || + step == GTK_MOVEMENT_DISPLAY_LINES || + step == GTK_MOVEMENT_PAGES || + step == GTK_MOVEMENT_BUFFER_ENDS, FALSE); + g_return_val_if_fail(count == 1 || count == -1, FALSE); + + ScrollDirection direction; + ScrollGranularity granularity; + + switch (step) { + case GTK_MOVEMENT_DISPLAY_LINES: + granularity = ScrollByLine; + if (count == 1) + direction = ScrollDown; + else + direction = ScrollUp; + break; + case GTK_MOVEMENT_VISUAL_POSITIONS: + granularity = ScrollByLine; + if (count == 1) + direction = ScrollRight; + else + direction = ScrollLeft; + break; + case GTK_MOVEMENT_PAGES: + granularity = ScrollByPage; + if (count == 1) + direction = ScrollDown; + else + direction = ScrollUp; + break; + case GTK_MOVEMENT_BUFFER_ENDS: + granularity = ScrollByDocument; + if (count == 1) + direction = ScrollDown; + else + direction = ScrollUp; + break; + default: + g_assert_not_reached(); + return false; + } + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + if (!frame->eventHandler()->scrollOverflow(direction, granularity)) + frame->view()->scroll(direction, granularity); + + return true; +} + +static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView) +{ + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->command("Paste").execute(); +} + +static gboolean webkit_web_view_real_should_allow_editing_action(WebKitWebView*) +{ + return TRUE; +} + +static void webkit_web_view_dispose(GObject* object) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + WebKitWebViewPrivate* priv = webView->priv; + + priv->disposing = TRUE; + + // These smart pointers are cleared manually, because some cleanup operations are + // very sensitive to their value. We may crash if these are done in the wrong order. + priv->horizontalAdjustment.clear(); + priv->verticalAdjustment.clear(); + priv->backForwardList.clear(); + + if (priv->corePage) { + webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object)); + core(priv->mainFrame)->loader()->detachFromParent(); + delete priv->corePage; + priv->corePage = 0; + } + + if (priv->webSettings) { + g_signal_handlers_disconnect_by_func(priv->webSettings.get(), (gpointer)webkit_web_view_settings_notify, webView); + priv->webSettings.clear(); + } + + if (priv->currentMenu) { + gtk_widget_destroy(GTK_WIDGET(priv->currentMenu)); + priv->currentMenu = 0; + } + + priv->webInspector.clear(); + priv->viewportAttributes.clear(); + priv->webWindowFeatures.clear(); + priv->mainResource.clear(); + priv->subResources.clear(); + + HashMap<GdkDragContext*, DroppingContext*>::iterator endDroppingContexts = priv->droppingContexts.end(); + for (HashMap<GdkDragContext*, DroppingContext*>::iterator iter = priv->droppingContexts.begin(); iter != endDroppingContexts; ++iter) + delete (iter->second); + priv->droppingContexts.clear(); + + G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object); +} + +static void webkit_web_view_finalize(GObject* object) +{ + // We need to manually call the destructor here, since this object's memory is managed + // by GLib. This calls all C++ members' destructors and prevents memory leaks. + WEBKIT_WEB_VIEW(object)->priv->~WebKitWebViewPrivate(); + G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object); +} + +static gboolean webkit_signal_accumulator_object_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy) +{ + gpointer newWebView = g_value_get_object(handlerReturn); + g_value_set_object(returnAccu, newWebView); + + // Continue if we don't have a newWebView + return !newWebView; +} + +static gboolean webkit_navigation_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy) +{ + WebKitNavigationResponse navigationResponse = (WebKitNavigationResponse)g_value_get_enum(handlerReturn); + g_value_set_enum(returnAccu, navigationResponse); + + if (navigationResponse != WEBKIT_NAVIGATION_RESPONSE_ACCEPT) + return FALSE; + + return TRUE; +} + +static AtkObject* webkit_web_view_get_accessible(GtkWidget* widget) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + if (!core(webView)) + return 0; + + AXObjectCache::enableAccessibility(); + + Frame* coreFrame = core(webView)->mainFrame(); + if (!coreFrame) + return 0; + + Document* doc = coreFrame->document(); + if (!doc) + return 0; + + AccessibilityObject* rootAccessible = doc->axObjectCache()->rootObject(); + if (!rootAccessible) + return 0; + + // We need to return the root accessibility object's first child + // to get to the actual ATK Object associated with the web view. + // See https://bugs.webkit.org/show_bug.cgi?id=51932 + AtkObject* axRoot = rootAccessible->wrapper(); + if (!axRoot || !ATK_IS_OBJECT(axRoot)) + return 0; + + AtkObject* axWebView = atk_object_ref_accessible_child(ATK_OBJECT(axRoot), 0); + if (!axWebView || !ATK_IS_OBJECT(axWebView)) + return 0; + + // We don't want the extra reference returned by ref_accessible_child. + g_object_unref(axWebView); + return axWebView; +} + +static gdouble webViewGetDPI(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + WebKitWebSettings* webSettings = priv->webSettings.get(); + gboolean enforce96DPI; + g_object_get(webSettings, "enforce-96-dpi", &enforce96DPI, NULL); + if (enforce96DPI) + return 96.0; + + gdouble DPI = defaultDPI; + GdkScreen* screen = gtk_widget_has_screen(GTK_WIDGET(webView)) ? gtk_widget_get_screen(GTK_WIDGET(webView)) : gdk_screen_get_default(); + if (screen) { + DPI = gdk_screen_get_resolution(screen); + // gdk_screen_get_resolution() returns -1 when no DPI is set. + if (DPI == -1) + DPI = defaultDPI; + } + ASSERT(DPI > 0); + return DPI; +} + +static void webkit_web_view_screen_changed(GtkWidget* widget, GdkScreen* previousScreen) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + if (priv->disposing) + return; + + WebKitWebSettings* webSettings = priv->webSettings.get(); + Settings* settings = core(webView)->settings(); + gdouble DPI = webViewGetDPI(webView); + + guint defaultFontSize, defaultMonospaceFontSize, minimumFontSize, minimumLogicalFontSize; + + g_object_get(webSettings, + "default-font-size", &defaultFontSize, + "default-monospace-font-size", &defaultMonospaceFontSize, + "minimum-font-size", &minimumFontSize, + "minimum-logical-font-size", &minimumLogicalFontSize, + NULL); + + settings->setDefaultFontSize(defaultFontSize / 72.0 * DPI); + settings->setDefaultFixedFontSize(defaultMonospaceFontSize / 72.0 * DPI); + settings->setMinimumFontSize(minimumFontSize / 72.0 * DPI); + settings->setMinimumLogicalFontSize(minimumLogicalFontSize / 72.0 * DPI); +} + +static IntPoint globalPointForClientPoint(GdkWindow* window, const IntPoint& clientPoint) +{ + int x, y; + gdk_window_get_origin(window, &x, &y); + return clientPoint + IntSize(x, y); +} + + +static void webkit_web_view_drag_end(GtkWidget* widget, GdkDragContext* context) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + // This might happen if a drag is still in progress after a WebKitWebView + // is disposed and before it is finalized. + if (!priv->draggingDataObjects.contains(context)) + return; + + priv->draggingDataObjects.remove(context); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + if (!frame) + return; + + GOwnPtr<GdkEvent> event(gdk_event_new(GDK_BUTTON_RELEASE)); + int x, y, xRoot, yRoot; + GdkModifierType modifiers = static_cast<GdkModifierType>(0); +#ifdef GTK_API_VERSION_2 + GdkDisplay* display = gdk_display_get_default(); + gdk_display_get_pointer(display, 0, &xRoot, &yRoot, &modifiers); + event->button.window = gdk_display_get_window_at_pointer(display, &x, &y); +#else + GdkDevice* device = gdk_drag_context_get_device(context); + event->button.window = gdk_device_get_window_at_position(device, &x, &y); + gdk_device_get_position(device, 0, &xRoot, &yRoot); +#endif + + if (event->button.window) + g_object_ref(event->button.window); + event->button.x = x; + event->button.y = y; + event->button.x_root = xRoot; + event->button.y_root = yRoot; + event->button.state = modifiers; + + PlatformMouseEvent platformEvent(&event->button); + frame->eventHandler()->dragSourceEndedAt(platformEvent, gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context))); +} + +static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint) +{ + WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW(widget)->priv; + + // This might happen if a drag is still in progress after a WebKitWebView + // is diposed and before it is finalized. + if (!priv->draggingDataObjects.contains(context)) + return; + + pasteboardHelperInstance()->fillSelectionData(selectionData, info, priv->draggingDataObjects.get(context).get()); +} + +static gboolean doDragLeaveLater(DroppingContext* context) +{ + WebKitWebView* webView = context->webView; + WebKitWebViewPrivate* priv = webView->priv; + + if (!priv->droppingContexts.contains(context->gdkContext)) + return FALSE; + + // If the view doesn't know about the drag yet (there are still pending data) + // requests, don't update it with information about the drag. + if (context->pendingDataRequests) + return FALSE; + + // Don't call dragExited if we have just received a drag-drop signal. This + // happens in the case of a successful drop onto the view. + if (!context->dropHappened) { + const IntPoint& position = context->lastMotionPosition; + DragData dragData(context->dataObject.get(), position, globalPointForClientPoint(gtk_widget_get_window(GTK_WIDGET(webView)), position), DragOperationNone); + core(webView)->dragController()->dragExited(&dragData); + } + + core(webView)->dragController()->dragEnded(); + priv->droppingContexts.remove(context->gdkContext); + delete context; + return FALSE; +} + +static void webkit_web_view_drag_leave(GtkWidget* widget, GdkDragContext* context, guint time) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + if (!priv->droppingContexts.contains(context)) + return; + + // During a drop GTK+ will fire a drag-leave signal right before firing + // the drag-drop signal. We want the actions for drag-leave to happen after + // those for drag-drop, so schedule them to happen asynchronously here. + g_timeout_add(0, reinterpret_cast<GSourceFunc>(doDragLeaveLater), priv->droppingContexts.get(context)); +} + +static gboolean webkit_web_view_drag_motion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + DroppingContext* droppingContext = 0; + IntPoint position = IntPoint(x, y); + if (!priv->droppingContexts.contains(context)) { + droppingContext = new DroppingContext; + droppingContext->webView = webView; + droppingContext->gdkContext = context; + droppingContext->dataObject = WebCore::DataObjectGtk::create(); + droppingContext->dropHappened = false; + droppingContext->lastMotionPosition = position; + priv->droppingContexts.set(context, droppingContext); + + Vector<GdkAtom> acceptableTargets(pasteboardHelperInstance()->dropAtomsForContext(widget, context)); + droppingContext->pendingDataRequests = acceptableTargets.size(); + for (size_t i = 0; i < acceptableTargets.size(); i++) + gtk_drag_get_data(widget, context, acceptableTargets.at(i), time); + } else { + droppingContext = priv->droppingContexts.get(context); + droppingContext->lastMotionPosition = position; + } + + // Don't send any drag information to WebCore until we've retrieved all + // the data for this drag operation. Otherwise we'd have to block to wait + // for the drag's data. + ASSERT(droppingContext); + if (droppingContext->pendingDataRequests > 0) + return TRUE; + + DragData dragData(droppingContext->dataObject.get(), position, globalPointForClientPoint(gtk_widget_get_window(widget), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + DragOperation operation = core(webView)->dragController()->dragUpdated(&dragData); + gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); + + return TRUE; +} + +static void webkit_web_view_drag_data_received(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + if (!priv->droppingContexts.contains(context)) + return; + + DroppingContext* droppingContext = priv->droppingContexts.get(context); + droppingContext->pendingDataRequests--; + pasteboardHelperInstance()->fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get()); + + if (droppingContext->pendingDataRequests) + return; + + // The coordinates passed to drag-data-received signal are sometimes + // inaccurate in DRT, so use the coordinates of the last motion event. + const IntPoint& position = droppingContext->lastMotionPosition; + + // If there are no more pending requests, start sending dragging data to WebCore. + DragData dragData(droppingContext->dataObject.get(), position, globalPointForClientPoint(gtk_widget_get_window(widget), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + DragOperation operation = core(webView)->dragController()->dragEntered(&dragData); + gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time); +} + +static gboolean webkit_web_view_drag_drop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + WebKitWebViewPrivate* priv = webView->priv; + + if (!priv->droppingContexts.contains(context)) + return FALSE; + + DroppingContext* droppingContext = priv->droppingContexts.get(context); + droppingContext->dropHappened = true; + + IntPoint position(x, y); + DragData dragData(droppingContext->dataObject.get(), position, globalPointForClientPoint(gtk_widget_get_window(widget), position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context))); + core(webView)->dragController()->performDrag(&dragData); + + gtk_drag_finish(context, TRUE, FALSE, time); + return TRUE; +} + +#if GTK_CHECK_VERSION(2, 12, 0) +static gboolean webkit_web_view_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip) +{ + WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW(widget)->priv; + + if (keyboard_mode) { + WebKitWebView* webView = WEBKIT_WEB_VIEW(widget); + + // Get the title of the current focused element. + Frame* coreFrame = core(webView)->focusController()->focusedOrMainFrame(); + if (!coreFrame) + return FALSE; + + Node* node = getFocusedNode(coreFrame); + if (!node) + return FALSE; + + for (Node* titleNode = node; titleNode; titleNode = titleNode->parentNode()) { + if (titleNode->isElementNode()) { + String title = static_cast<Element*>(titleNode)->title(); + if (!title.isEmpty()) { + if (FrameView* view = coreFrame->view()) { + GdkRectangle area = view->contentsToWindow(node->getRect()); + gtk_tooltip_set_tip_area(tooltip, &area); + } + gtk_tooltip_set_text(tooltip, title.utf8().data()); + + return TRUE; + } + } + } + + return FALSE; + } + + if (priv->tooltipText.length() > 0) { + if (!keyboard_mode) { + if (!priv->tooltipArea.isEmpty()) { + GdkRectangle area = priv->tooltipArea; + gtk_tooltip_set_tip_area(tooltip, &area); + } else + gtk_tooltip_set_tip_area(tooltip, 0); + } + gtk_tooltip_set_text(tooltip, priv->tooltipText.data()); + return TRUE; + } + + return FALSE; +} + +static gboolean webkit_web_view_show_help(GtkWidget* widget, GtkWidgetHelpType help_type) +{ + if (help_type == GTK_WIDGET_HELP_TOOLTIP) + gtk_widget_set_has_tooltip(widget, TRUE); + + return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->show_help(widget, help_type); +} +#endif + +static GtkIMContext* webkit_web_view_get_im_context(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + return GTK_IM_CONTEXT(webView->priv->imContext.get()); +} + +static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) +{ + GtkBindingSet* binding_set; + + webkitInit(); + + /* + * Signals + */ + + /** + * WebKitWebView::create-web-view: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame + * + * Emitted when the creation of a new window is requested. + * If this signal is handled the signal handler should return the + * newly created #WebKitWebView. + * + * The new #WebKitWebView should not be displayed to the user + * until the #WebKitWebView::web-view-ready signal is emitted. + * + * The signal handlers should not try to deal with the reference count for + * the new #WebKitWebView. The widget to which the widget is added will + * handle that. + * + * Return value: (transfer full): a newly allocated #WebKitWebView, or %NULL + * + * Since: 1.0.3 + */ + webkit_web_view_signals[CREATE_WEB_VIEW] = g_signal_new("create-web-view", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (WebKitWebViewClass, create_web_view), + webkit_signal_accumulator_object_handled, + NULL, + webkit_marshal_OBJECT__OBJECT, + WEBKIT_TYPE_WEB_VIEW , 1, + WEBKIT_TYPE_WEB_FRAME); + + /** + * WebKitWebView::web-view-ready: + * @webView: the object on which the signal is emitted + * + * Emitted after #WebKitWebView::create-web-view when the new #WebKitWebView + * should be displayed to the user. When this signal is emitted + * all the information about how the window should look, including + * size, position, whether the location, status and scroll bars + * should be displayed, is already set on the + * #WebKitWebWindowFeatures object contained by the #WebKitWebView. + * + * Notice that some of that information may change during the life + * time of the window, so you may want to connect to the ::notify + * signal of the #WebKitWebWindowFeatures object to handle those. + * + * Return value: %TRUE to stop handlers from being invoked for the event or + * %FALSE to propagate the event furter + * + * Since: 1.0.3 + */ + webkit_web_view_signals[WEB_VIEW_READY] = g_signal_new("web-view-ready", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (WebKitWebViewClass, web_view_ready), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); + + /** + * WebKitWebView::close-web-view: + * @webView: the object on which the signal is emitted + * + * Emitted when closing a #WebKitWebView is requested. This occurs when a + * call is made from JavaScript's window.close function. The default + * signal handler does not do anything. It is the owner's responsibility + * to hide or delete the web view, if necessary. + * + * Return value: %TRUE to stop handlers from being invoked for the event or + * %FALSE to propagate the event furter + * + * Since: 1.1.11 + */ + webkit_web_view_signals[CLOSE_WEB_VIEW] = g_signal_new("close-web-view", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (WebKitWebViewClass, close_web_view), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); + + /** + * WebKitWebView::navigation-requested: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame that required the navigation + * @request: a #WebKitNetworkRequest + * + * Emitted when @frame requests a navigation to another page. + * + * Return value: a #WebKitNavigationResponse + * + * Deprecated: Use WebKitWebView::navigation-policy-decision-requested + * instead + */ + webkit_web_view_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (WebKitWebViewClass, navigation_requested), + webkit_navigation_request_handled, + NULL, + webkit_marshal_ENUM__OBJECT_OBJECT, + WEBKIT_TYPE_NAVIGATION_RESPONSE, 2, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_NETWORK_REQUEST); + + /** + * WebKitWebView::new-window-policy-decision-requested: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame that required the navigation + * @request: a #WebKitNetworkRequest + * @navigation_action: a #WebKitWebNavigationAction + * @policy_decision: a #WebKitWebPolicyDecision + * + * Emitted when @frame requests opening a new window. With this + * signal the browser can use the context of the request to decide + * about the new window. If the request is not handled the default + * behavior is to allow opening the new window to load the URI, + * which will cause a create-web-view signal emission where the + * browser handles the new window action but without information + * of the context that caused the navigation. The following + * navigation-policy-decision-requested emissions will load the + * page after the creation of the new window just with the + * information of this new navigation context, without any + * information about the action that made this new window to be + * opened. + * + * Notice that if you return TRUE, meaning that you handled the + * signal, you are expected to have decided what to do, by calling + * webkit_web_policy_decision_ignore(), + * webkit_web_policy_decision_use(), or + * webkit_web_policy_decision_download() on the @policy_decision + * object. + * + * Return value: %TRUE if a decision was made, %FALSE to have the + * default behavior apply + * + * Since: 1.1.4 + */ + webkit_web_view_signals[NEW_WINDOW_POLICY_DECISION_REQUESTED] = + g_signal_new("new-window-policy-decision-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT, + G_TYPE_BOOLEAN, 4, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_NETWORK_REQUEST, + WEBKIT_TYPE_WEB_NAVIGATION_ACTION, + WEBKIT_TYPE_WEB_POLICY_DECISION); + + /** + * WebKitWebView::navigation-policy-decision-requested: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame that required the navigation + * @request: a #WebKitNetworkRequest + * @navigation_action: a #WebKitWebNavigationAction + * @policy_decision: a #WebKitWebPolicyDecision + * + * Emitted when @frame requests a navigation to another page. + * If this signal is not handled, the default behavior is to allow the + * navigation. + * + * Notice that if you return TRUE, meaning that you handled the + * signal, you are expected to have decided what to do, by calling + * webkit_web_policy_decision_ignore(), + * webkit_web_policy_decision_use(), or + * webkit_web_policy_decision_download() on the @policy_decision + * object. + * + * Return value: %TRUE if a decision was made, %FALSE to have the + * default behavior apply + * + * Since: 1.0.3 + */ + webkit_web_view_signals[NAVIGATION_POLICY_DECISION_REQUESTED] = g_signal_new("navigation-policy-decision-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT, + G_TYPE_BOOLEAN, 4, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_NETWORK_REQUEST, + WEBKIT_TYPE_WEB_NAVIGATION_ACTION, + WEBKIT_TYPE_WEB_POLICY_DECISION); + + /** + * WebKitWebView::mime-type-policy-decision-requested: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame that required the policy decision + * @request: a WebKitNetworkRequest + * @mimetype: the MIME type attempted to load + * @policy_decision: a #WebKitWebPolicyDecision + * + * Decide whether or not to display the given MIME type. If this + * signal is not handled, the default behavior is to show the + * content of the requested URI if WebKit can show this MIME + * type and the content disposition is not a download; if WebKit + * is not able to show the MIME type nothing happens. + * + * Notice that if you return TRUE, meaning that you handled the + * signal, you are expected to be aware of the "Content-Disposition" + * header. A value of "attachment" usually indicates a download + * regardless of the MIME type, see also + * soup_message_headers_get_content_disposition(). And you must call + * webkit_web_policy_decision_ignore(), + * webkit_web_policy_decision_use(), or + * webkit_web_policy_decision_download() on the @policy_decision + * object. + * + * Return value: %TRUE if a decision was made, %FALSE to have the + * default behavior apply + * + * Since: 1.0.3 + */ + webkit_web_view_signals[MIME_TYPE_POLICY_DECISION_REQUESTED] = g_signal_new("mime-type-policy-decision-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_OBJECT_STRING_OBJECT, + G_TYPE_BOOLEAN, 4, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_NETWORK_REQUEST, + G_TYPE_STRING, + WEBKIT_TYPE_WEB_POLICY_DECISION); + + /** + * WebKitWebView::window-object-cleared: + * @webView: the object on which the signal is emitted + * @frame: the #WebKitWebFrame to which @window_object belongs + * @context: the #JSGlobalContextRef holding the global object and other + * execution state; equivalent to the return value of + * webkit_web_frame_get_global_context(@frame) + * @window_object: the #JSObjectRef representing the frame's JavaScript + * window object + * + * Emitted when the JavaScript window object in a #WebKitWebFrame has been + * cleared in preparation for a new load. This is the preferred place to + * set custom properties on the window object using the JavaScriptCore API. + */ + webkit_web_view_signals[WINDOW_OBJECT_CLEARED] = g_signal_new("window-object-cleared", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (WebKitWebViewClass, window_object_cleared), + NULL, + NULL, + webkit_marshal_VOID__OBJECT_POINTER_POINTER, + G_TYPE_NONE, 3, + WEBKIT_TYPE_WEB_FRAME, + G_TYPE_POINTER, + G_TYPE_POINTER); + + /** + * WebKitWebView::download-requested: + * @webView: the object on which the signal is emitted + * @download: a #WebKitDownload object that lets you control the + * download process + * + * A new Download is being requested. By default, if the signal is + * not handled, the download is cancelled. If you handle the download + * and call webkit_download_set_destination_uri(), it will be + * started for you. If you need to set the destination asynchronously + * you are responsible for starting or cancelling it yourself. + * + * If you intend to handle downloads yourself rather than using + * the #WebKitDownload helper object you must handle this signal, + * and return %FALSE. + * + * Also, keep in mind that the default policy for WebKitGTK+ is to + * ignore files with a MIME type that it does not know how to + * handle, which means this signal won't be emitted in the default + * setup. One way to trigger downloads is to connect to + * WebKitWebView::mime-type-policy-decision-requested and call + * webkit_web_policy_decision_download() on the + * #WebKitWebPolicyDecision in the parameter list for the kind of + * files you want your application to download (a common solution + * is to download anything that WebKit can't handle, which you can + * figure out by using webkit_web_view_can_show_mime_type()). + * + * Return value: TRUE if the download should be performed, %FALSE to + * cancel it + * + * Since: 1.1.2 + */ + webkit_web_view_signals[DOWNLOAD_REQUESTED] = g_signal_new("download-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT, + G_TYPE_BOOLEAN, 1, + G_TYPE_OBJECT); + + /** + * WebKitWebView::load-started: + * @webView: the object on which the signal is emitted + * @frame: the frame going to do the load + * + * When a #WebKitWebFrame begins to load this signal is emitted. + * + * Deprecated: Use the "load-status" property instead. + */ + webkit_web_view_signals[LOAD_STARTED] = g_signal_new("load-started", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + /** + * WebKitWebView::load-committed: + * @webView: the object on which the signal is emitted + * @frame: the main frame that received the first data + * + * When a #WebKitWebFrame loaded the first data this signal is emitted. + * + * Deprecated: Use the "load-status" property instead. + */ + webkit_web_view_signals[LOAD_COMMITTED] = g_signal_new("load-committed", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + + /** + * WebKitWebView::load-progress-changed: + * @webView: the #WebKitWebView + * @progress: the global progress + * + * Deprecated: Use the "progress" property instead. + */ + webkit_web_view_signals[LOAD_PROGRESS_CHANGED] = g_signal_new("load-progress-changed", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); + + /** + * WebKitWebView::load-error + * @webView: the object on which the signal is emitted + * @web_frame: the #WebKitWebFrame + * @uri: the URI that triggered the error + * @web_error: the #GError that was triggered + * + * An error occurred while loading. By default, if the signal is not + * handled, the @web_view will display a stock error page. You need to + * handle the signal if you want to provide your own error page. + * + * Since: 1.1.6 + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + */ + webkit_web_view_signals[LOAD_ERROR] = g_signal_new("load-error", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST), + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_STRING_POINTER, + G_TYPE_BOOLEAN, 3, + WEBKIT_TYPE_WEB_FRAME, + G_TYPE_STRING, + G_TYPE_POINTER); + + /** + * WebKitWebView::load-finished: + * @webView: the #WebKitWebView + * @frame: the #WebKitWebFrame + * + * Deprecated: Use the "load-status" property instead. + */ + webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + /** + * WebKitWebView::onload-event: + * @webView: the object on which the signal is emitted + * @frame: the frame + * + * When a #WebKitWebFrame receives an onload event this signal is emitted. + */ + webkit_web_view_signals[ONLOAD_EVENT] = g_signal_new("onload-event", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + /** + * WebKitWebView::title-changed: + * @webView: the object on which the signal is emitted + * @frame: the main frame + * @title: the new title + * + * When a #WebKitWebFrame changes the document title this signal is emitted. + * + * Deprecated: 1.1.4: Use "notify::title" instead. + */ + webkit_web_view_signals[TITLE_CHANGED] = g_signal_new("title-changed", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + webkit_marshal_VOID__OBJECT_STRING, + G_TYPE_NONE, 2, + WEBKIT_TYPE_WEB_FRAME, + G_TYPE_STRING); + + /** + * WebKitWebView::hovering-over-link: + * @webView: the object on which the signal is emitted + * @title: the link's title + * @uri: the URI the link points to + * + * When the cursor is over a link, this signal is emitted. + */ + webkit_web_view_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + webkit_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_STRING); + + /** + * WebKitWebView::populate-popup: + * @webView: the object on which the signal is emitted + * @menu: the context menu + * + * When a context menu is about to be displayed this signal is emitted. + * + * Add menu items to #menu to extend the context menu. + */ + webkit_web_view_signals[POPULATE_POPUP] = g_signal_new("populate-popup", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + GTK_TYPE_MENU); + + /** + * WebKitWebView::print-requested + * @webView: the object in which the signal is emitted + * @web_frame: the frame that is requesting to be printed + * + * Emitted when printing is requested by the frame, usually + * because of a javascript call. When handling this signal you + * should call webkit_web_frame_print_full() or + * webkit_web_frame_print() to do the actual printing. + * + * The default handler will present a print dialog and carry a + * print operation. Notice that this means that if you intend to + * ignore a print request you must connect to this signal, and + * return %TRUE. + * + * Return value: %TRUE if the print request has been handled, %FALSE if + * the default handler should run + * + * Since: 1.1.5 + */ + webkit_web_view_signals[PRINT_REQUESTED] = g_signal_new("print-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT, + G_TYPE_BOOLEAN, 1, + WEBKIT_TYPE_WEB_FRAME); + + webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + /** + * WebKitWebView::icon-loaded: + * @webView: the object on which the signal is emitted + * @icon_uri: the URI for the icon + * + * This signal is emitted when the main frame has got a favicon. + * See WebKitIconDatabase::icon-loaded if you want to keep track of + * icons for child frames. + * + * Since: 1.1.18 + */ + webkit_web_view_signals[ICON_LOADED] = g_signal_new("icon-loaded", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + /** + * WebKitWebView::console-message: + * @webView: the object on which the signal is emitted + * @message: the message text + * @line: the line where the error occured + * @source_id: the source id + * + * A JavaScript console message was created. + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + */ + webkit_web_view_signals[CONSOLE_MESSAGE] = g_signal_new("console-message", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, console_message), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__STRING_INT_STRING, + G_TYPE_BOOLEAN, 3, + G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); + + /** + * WebKitWebView::script-alert: + * @webView: the object on which the signal is emitted + * @frame: the relevant frame + * @message: the message text + * + * A JavaScript alert dialog was created. + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + */ + webkit_web_view_signals[SCRIPT_ALERT] = g_signal_new("script-alert", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, script_alert), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_STRING, + G_TYPE_BOOLEAN, 2, + WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING); + + /** + * WebKitWebView::script-confirm: + * @webView: the object on which the signal is emitted + * @frame: the relevant frame + * @message: the message text + * @confirmed: whether the dialog has been confirmed + * + * A JavaScript confirm dialog was created, providing Yes and No buttons. + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + */ + webkit_web_view_signals[SCRIPT_CONFIRM] = g_signal_new("script-confirm", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_STRING_POINTER, + G_TYPE_BOOLEAN, 3, + WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_POINTER); + + /** + * WebKitWebView::script-prompt: + * @webView: the object on which the signal is emitted + * @frame: the relevant frame + * @message: the message text + * @default: the default value + * @text: To be filled with the return value or NULL if the dialog was cancelled. + * + * A JavaScript prompt dialog was created, providing an entry to input text. + * + * Return value: %TRUE to stop other handlers from being invoked for the + * event. %FALSE to propagate the event further. + */ + webkit_web_view_signals[SCRIPT_PROMPT] = g_signal_new("script-prompt", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt), + g_signal_accumulator_true_handled, + NULL, + webkit_marshal_BOOLEAN__OBJECT_STRING_STRING_STRING, + G_TYPE_BOOLEAN, 4, + WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + + /** + * WebKitWebView::select-all: + * @webView: the object which received the signal + * + * The #WebKitWebView::select-all signal is a keybinding signal which gets emitted to + * select the complete contents of the text view. + * + * The default bindings for this signal is Ctrl-a. + */ + webkit_web_view_signals[SELECT_ALL] = g_signal_new("select-all", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, select_all), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::cut-clipboard: + * @webView: the object which received the signal + * + * The #WebKitWebView::cut-clipboard signal is a keybinding signal which gets emitted to + * cut the selection to the clipboard. + * + * The default bindings for this signal are Ctrl-x and Shift-Delete. + */ + webkit_web_view_signals[CUT_CLIPBOARD] = g_signal_new("cut-clipboard", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, cut_clipboard), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::copy-clipboard: + * @webView: the object which received the signal + * + * The #WebKitWebView::copy-clipboard signal is a keybinding signal which gets emitted to + * copy the selection to the clipboard. + * + * The default bindings for this signal are Ctrl-c and Ctrl-Insert. + */ + webkit_web_view_signals[COPY_CLIPBOARD] = g_signal_new("copy-clipboard", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, copy_clipboard), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::paste-clipboard: + * @webView: the object which received the signal + * + * The #WebKitWebView::paste-clipboard signal is a keybinding signal which gets emitted to + * paste the contents of the clipboard into the Web view. + * + * The default bindings for this signal are Ctrl-v and Shift-Insert. + */ + webkit_web_view_signals[PASTE_CLIPBOARD] = g_signal_new("paste-clipboard", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, paste_clipboard), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::undo + * @webView: the object which received the signal + * + * The #WebKitWebView::undo signal is a keybinding signal which gets emitted to + * undo the last editing command. + * + * The default binding for this signal is Ctrl-z + * + * Since: 1.1.14 + */ + webkit_web_view_signals[UNDO] = g_signal_new("undo", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, undo), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::redo + * @webView: the object which received the signal + * + * The #WebKitWebView::redo signal is a keybinding signal which gets emitted to + * redo the last editing command. + * + * The default binding for this signal is Ctrl-Shift-z + * + * Since: 1.1.14 + */ + webkit_web_view_signals[REDO] = g_signal_new("redo", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, redo), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * WebKitWebView::move-cursor: + * @webView: the object which received the signal + * @step: the type of movement, one of #GtkMovementStep + * @count: an integer indicating the subtype of movement. Currently + * the permitted values are '1' = forward, '-1' = backwards. + * + * The #WebKitWebView::move-cursor will be emitted to apply the + * cursor movement described by its parameters to the @view. + * + * Return value: %TRUE or %FALSE + * + * Since: 1.1.4 + */ + webkit_web_view_signals[MOVE_CURSOR] = g_signal_new("move-cursor", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, move_cursor), + NULL, NULL, + webkit_marshal_BOOLEAN__ENUM_INT, + G_TYPE_BOOLEAN, 2, + GTK_TYPE_MOVEMENT_STEP, + G_TYPE_INT); + + /** + * WebKitWebView::create-plugin-widget: + * @webView: the object which received the signal + * @mime_type: the mimetype of the requested object + * @uri: the URI to load + * @param: a #GHashTable with additional attributes (strings) + * + * The #WebKitWebView::create-plugin-widget signal will be emitted to + * create a plugin widget for embed or object HTML tags. This + * allows to embed a GtkWidget as a plugin into HTML content. In + * case of a textual selection of the GtkWidget WebCore will attempt + * to set the property value of "webkit-widget-is-selected". This can + * be used to draw a visual indicator of the selection. + * + * Return value: (transfer full): a new #GtkWidget, or %NULL + * + * Since: 1.1.8 + */ + webkit_web_view_signals[PLUGIN_WIDGET] = g_signal_new("create-plugin-widget", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + webkit_signal_accumulator_object_handled, + NULL, + webkit_marshal_OBJECT__STRING_STRING_POINTER, + GTK_TYPE_WIDGET, 3, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_HASH_TABLE); + + /** + * WebKitWebView::database-quota-exceeded + * @webView: the object which received the signal + * @frame: the relevant frame + * @database: the #WebKitWebDatabase which exceeded the quota of its #WebKitSecurityOrigin + * + * The #WebKitWebView::database-quota-exceeded signal will be emitted when + * a Web Database exceeds the quota of its security origin. This signal + * may be used to increase the size of the quota before the originating + * operation fails. + * + * Since: 1.1.14 + */ + webkit_web_view_signals[DATABASE_QUOTA_EXCEEDED] = g_signal_new("database-quota-exceeded", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags) (G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + NULL, NULL, + webkit_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + G_TYPE_OBJECT, G_TYPE_OBJECT); + + /** + * WebKitWebView::resource-request-starting: + * @webView: the object which received the signal + * @web_frame: the #WebKitWebFrame whose load dispatched this request + * @web_resource: an empty #WebKitWebResource object + * @request: the #WebKitNetworkRequest that will be dispatched + * @response: the #WebKitNetworkResponse representing the redirect + * response, if any + * + * Emitted when a request is about to be sent. You can modify the + * request while handling this signal. You can set the URI in the + * #WebKitNetworkRequest object itself, and add/remove/replace + * headers using the #SoupMessage object it carries, if it is + * present. See webkit_network_request_get_message(). Setting the + * request URI to "about:blank" will effectively cause the request + * to load nothing, and can be used to disable the loading of + * specific resources. + * + * Notice that information about an eventual redirect is available + * in @response's #SoupMessage, not in the #SoupMessage carried by + * the @request. If @response is %NULL, then this is not a + * redirected request. + * + * The #WebKitWebResource object will be the same throughout all + * the lifetime of the resource, but the contents may change from + * inbetween signal emissions. + * + * Since: 1.1.14 + */ + webkit_web_view_signals[RESOURCE_REQUEST_STARTING] = g_signal_new("resource-request-starting", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + NULL, NULL, + webkit_marshal_VOID__OBJECT_OBJECT_OBJECT_OBJECT, + G_TYPE_NONE, 4, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_WEB_RESOURCE, + WEBKIT_TYPE_NETWORK_REQUEST, + WEBKIT_TYPE_NETWORK_RESPONSE); + + /** + * WebKitWebView::geolocation-policy-decision-requested: + * @webView: the object on which the signal is emitted + * @frame: the frame that requests permission + * @policy_decision: a WebKitGeolocationPolicyDecision + * + * This signal is emitted when a @frame wants to obtain the user's + * location. The decision can be made asynchronously, but you must + * call g_object_ref() the @policy_decision, and return %TRUE if + * you are going to handle the request. To actually make the + * decision you need to call webkit_geolocation_policy_allow() or + * webkit_geolocation_policy_deny() on @policy_decision. + * + * Since: 1.1.23 + */ + webkit_web_view_signals[GEOLOCATION_POLICY_DECISION_REQUESTED] = g_signal_new("geolocation-policy-decision-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST), + 0, + NULL, NULL, + webkit_marshal_BOOLEAN__OBJECT_OBJECT, + G_TYPE_BOOLEAN, 2, + WEBKIT_TYPE_WEB_FRAME, + WEBKIT_TYPE_GEOLOCATION_POLICY_DECISION); + + /** + * WebKitWebView::geolocation-policy-decision-cancelled: + * @webView: the object on which the signal is emitted + * @frame: the frame that cancels geolocation request. + * + * When a @frame wants to cancel geolocation permission it had requested + * before. + * + * Since: 1.1.23 + */ + webkit_web_view_signals[GEOLOCATION_POLICY_DECISION_CANCELLED] = g_signal_new("geolocation-policy-decision-cancelled", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST), + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + /* + * DOM-related signals. These signals are experimental, for now, + * and may change API and ABI. Their comments lack one * on + * purpose, to make them not be catched by gtk-doc. + */ + + /* + * WebKitWebView::document-load-finished + * @webView: the object which received the signal + * @web_frame: the #WebKitWebFrame whose load dispatched this request + * + * Emitted when the DOM document object load is finished for the + * given frame. + */ + webkit_web_view_signals[DOCUMENT_LOAD_FINISHED] = g_signal_new("document-load-finished", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + /* + * WebKitWebView::frame-created + * @webView: the object which received the signal + * @web_frame: the #WebKitWebFrame which was just created. + * + * Emitted when a WebKitWebView has created a new frame. This signal will + * be emitted for all sub-frames created during page load. It will not be + * emitted for the main frame, which originates in the WebKitWebView constructor + * and may be accessed at any time using webkit_web_view_get_main_frame. + * + * Since: 1.3.4 + */ + webkit_web_view_signals[FRAME_CREATED] = g_signal_new("frame-created", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_WEB_FRAME); + + webkit_web_view_signals[SHOULD_BEGIN_EDITING] = g_signal_new("should-begin-editing", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, WEBKIT_TYPE_DOM_RANGE); + + webkit_web_view_signals[SHOULD_END_EDITING] = g_signal_new("should-end-editing", G_TYPE_FROM_CLASS(webViewClass), + static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, WEBKIT_TYPE_DOM_RANGE); + + webkit_web_view_signals[SHOULD_INSERT_NODE] = g_signal_new("should-insert-node", G_TYPE_FROM_CLASS(webViewClass), + static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT_OBJECT_ENUM, G_TYPE_BOOLEAN, + 3, WEBKIT_TYPE_DOM_NODE, WEBKIT_TYPE_DOM_RANGE, WEBKIT_TYPE_INSERT_ACTION); + + webkit_web_view_signals[SHOULD_INSERT_TEXT] = g_signal_new("should-insert-text", G_TYPE_FROM_CLASS(webViewClass), + static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__STRING_OBJECT_ENUM, G_TYPE_BOOLEAN, + 3, G_TYPE_STRING, WEBKIT_TYPE_DOM_RANGE, WEBKIT_TYPE_INSERT_ACTION); + + webkit_web_view_signals[SHOULD_DELETE_RANGE] = g_signal_new("should-delete-range", G_TYPE_FROM_CLASS(webViewClass), + static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, WEBKIT_TYPE_DOM_RANGE); + + webkit_web_view_signals[SHOULD_SHOW_DELETE_INTERFACE_FOR_ELEMENT] = g_signal_new("should-show-delete-interface-for-element", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, WEBKIT_TYPE_DOM_HTML_ELEMENT); + + webkit_web_view_signals[SHOULD_CHANGE_SELECTED_RANGE] = g_signal_new("should-change-selected-range", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT_OBJECT_ENUM_BOOLEAN, G_TYPE_BOOLEAN, + 4, WEBKIT_TYPE_DOM_RANGE, WEBKIT_TYPE_DOM_RANGE, WEBKIT_TYPE_SELECTION_AFFINITY, G_TYPE_BOOLEAN); + + webkit_web_view_signals[SHOULD_APPLY_STYLE] = g_signal_new("should-apply-style", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0, + webkit_marshal_BOOLEAN__OBJECT_OBJECT, G_TYPE_BOOLEAN, + 2, WEBKIT_TYPE_DOM_CSS_STYLE_DECLARATION, WEBKIT_TYPE_DOM_RANGE); + + webkit_web_view_signals[EDITING_BEGAN] = g_signal_new("editing-began", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, 0, 0, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + webkit_web_view_signals[USER_CHANGED_CONTENTS] = g_signal_new("user-changed-contents", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, 0, 0, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + webkit_web_view_signals[EDITING_ENDED] = g_signal_new("editing-ended", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, 0, 0, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + webkit_web_view_signals[SELECTION_CHANGED] = g_signal_new("selection-changed", + G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), 0, 0, 0, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /* + * WebKitWebView::viewport-attributes-recompute-requested + * @web_view: the object which received the signal + * @viewport_attributes: the #WebKitViewportAttributes which has the viewport attributes. + * + * The #WebKitWebView::viewport-attributes-recompute-requested + * signal will be emitted when a page with a viewport meta tag + * loads and when webkit_viewport_attributes_recompute is called. + * + * The #WebKitViewportAttributes will have device size, available size, + * desktop width, and device DPI pre-filled by values that make sense + * for the current screen and widget, but you can override those values + * if you have special requirements (for instance, if you made your + * widget bigger than the available visible area, you should override + * the available-width and available-height properties to the actual + * visible area). + * + * Since: 1.3.8 + */ + webkit_web_view_signals[VIEWPORT_ATTRIBUTES_RECOMPUTE_REQUESTED] = g_signal_new("viewport-attributes-recompute-requested", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + 0, 0, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_VIEWPORT_ATTRIBUTES); + + /* + * WebKitWebView::viewport-attributes-changed + * @web_view: the object which received the signal + * @viewport_attributes: the #WebKitViewportAttributes which has the viewport attributes. + * + * The #WebKitWebView::viewport-attributes-changed signal will be emitted + * after the emission of #WebKitWebView::viewport-attributes-recompute-requested + * and the subsequent viewport attribute recomputation. At this point, + * if the #WebKitViewportAttributes are valid, the viewport attributes are available. + * + * Since: 1.3.8 + */ + webkit_web_view_signals[VIEWPORT_ATTRIBUTES_CHANGED] = g_signal_new("viewport-attributes-changed", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + 0, + 0, 0, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_VIEWPORT_ATTRIBUTES); + + /* + * implementations of virtual methods + */ + webViewClass->create_web_view = webkit_web_view_real_create_web_view; + webViewClass->web_view_ready = webkit_web_view_real_web_view_ready; + webViewClass->close_web_view = webkit_web_view_real_close_web_view; + webViewClass->navigation_requested = webkit_web_view_real_navigation_requested; + webViewClass->window_object_cleared = webkit_web_view_real_window_object_cleared; + webViewClass->choose_file = webkit_web_view_real_choose_file; + webViewClass->script_alert = webkit_web_view_real_script_alert; + webViewClass->script_confirm = webkit_web_view_real_script_confirm; + webViewClass->script_prompt = webkit_web_view_real_script_prompt; + webViewClass->console_message = webkit_web_view_real_console_message; + webViewClass->select_all = webkit_web_view_real_select_all; + webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard; + webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard; + webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard; + webViewClass->undo = webkit_web_view_real_undo; + webViewClass->redo = webkit_web_view_real_redo; + webViewClass->move_cursor = webkit_web_view_real_move_cursor; + webViewClass->should_allow_editing_action = webkit_web_view_real_should_allow_editing_action; + + GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass); + objectClass->dispose = webkit_web_view_dispose; + objectClass->finalize = webkit_web_view_finalize; + objectClass->get_property = webkit_web_view_get_property; + objectClass->set_property = webkit_web_view_set_property; + + GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webViewClass); + widgetClass->realize = webkit_web_view_realize; +#ifdef GTK_API_VERSION_2 + widgetClass->expose_event = webkit_web_view_expose_event; +#else + widgetClass->draw = webkit_web_view_draw; +#endif + widgetClass->key_press_event = webkit_web_view_key_press_event; + widgetClass->key_release_event = webkit_web_view_key_release_event; + widgetClass->button_press_event = webkit_web_view_button_press_event; + widgetClass->button_release_event = webkit_web_view_button_release_event; + widgetClass->motion_notify_event = webkit_web_view_motion_event; + widgetClass->scroll_event = webkit_web_view_scroll_event; + widgetClass->size_allocate = webkit_web_view_size_allocate; +#ifdef GTK_API_VERSION_2 + widgetClass->size_request = webkit_web_view_size_request; +#else + widgetClass->get_preferred_width = webkit_web_view_get_preferred_width; + widgetClass->get_preferred_height = webkit_web_view_get_preferred_height; +#endif + widgetClass->popup_menu = webkit_web_view_popup_menu_handler; + widgetClass->grab_focus = webkit_web_view_grab_focus; + widgetClass->focus_in_event = webkit_web_view_focus_in_event; + widgetClass->focus_out_event = webkit_web_view_focus_out_event; + widgetClass->get_accessible = webkit_web_view_get_accessible; + widgetClass->screen_changed = webkit_web_view_screen_changed; + widgetClass->drag_end = webkit_web_view_drag_end; + widgetClass->drag_data_get = webkit_web_view_drag_data_get; + widgetClass->drag_motion = webkit_web_view_drag_motion; + widgetClass->drag_leave = webkit_web_view_drag_leave; + widgetClass->drag_drop = webkit_web_view_drag_drop; + widgetClass->drag_data_received = webkit_web_view_drag_data_received; +#if GTK_CHECK_VERSION(2, 12, 0) + widgetClass->query_tooltip = webkit_web_view_query_tooltip; + widgetClass->show_help = webkit_web_view_show_help; +#endif + + GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewClass); + containerClass->add = webkit_web_view_container_add; + containerClass->remove = webkit_web_view_container_remove; + containerClass->forall = webkit_web_view_container_forall; + + /* + * make us scrollable (e.g. addable to a GtkScrolledWindow) + */ +#ifdef GTK_API_VERSION_2 + webViewClass->set_scroll_adjustments = webkit_web_view_set_scroll_adjustments; + GTK_WIDGET_CLASS(webViewClass)->set_scroll_adjustments_signal = g_signal_new("set-scroll-adjustments", + G_TYPE_FROM_CLASS(webViewClass), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET(WebKitWebViewClass, set_scroll_adjustments), + NULL, NULL, + webkit_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); +#else + g_object_class_override_property(objectClass, PROP_HADJUSTMENT, "hadjustment"); + g_object_class_override_property(objectClass, PROP_VADJUSTMENT, "vadjustment"); + g_object_class_override_property(objectClass, PROP_HSCROLL_POLICY, "hscroll-policy"); + g_object_class_override_property(objectClass, PROP_VSCROLL_POLICY, "vscroll-policy"); +#endif + + /* + * Key bindings + */ + + binding_set = gtk_binding_set_by_class(webViewClass); + + gtk_binding_entry_add_signal(binding_set, GDK_a, GDK_CONTROL_MASK, + "select_all", 0); + + /* Cut/copy/paste */ + + gtk_binding_entry_add_signal(binding_set, GDK_x, GDK_CONTROL_MASK, + "cut_clipboard", 0); + gtk_binding_entry_add_signal(binding_set, GDK_c, GDK_CONTROL_MASK, + "copy_clipboard", 0); + gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK, + "paste_clipboard", 0); + gtk_binding_entry_add_signal(binding_set, GDK_z, GDK_CONTROL_MASK, + "undo", 0); + gtk_binding_entry_add_signal(binding_set, GDK_z, static_cast<GdkModifierType>(GDK_CONTROL_MASK | GDK_SHIFT_MASK), + "redo", 0); + + gtk_binding_entry_add_signal(binding_set, GDK_Delete, GDK_SHIFT_MASK, + "cut_clipboard", 0); + gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_CONTROL_MASK, + "copy_clipboard", 0); + gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_SHIFT_MASK, + "paste_clipboard", 0); + + /* Movement */ + + gtk_binding_entry_add_signal(binding_set, GDK_Down, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINES, + G_TYPE_INT, 1); + gtk_binding_entry_add_signal(binding_set, GDK_Up, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINES, + G_TYPE_INT, -1); + gtk_binding_entry_add_signal(binding_set, GDK_Right, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS, + G_TYPE_INT, 1); + gtk_binding_entry_add_signal(binding_set, GDK_Left, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS, + G_TYPE_INT, -1); + gtk_binding_entry_add_signal(binding_set, GDK_space, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_PAGES, + G_TYPE_INT, 1); + gtk_binding_entry_add_signal(binding_set, GDK_space, GDK_SHIFT_MASK, + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_PAGES, + G_TYPE_INT, -1); + gtk_binding_entry_add_signal(binding_set, GDK_Page_Down, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_PAGES, + G_TYPE_INT, 1); + gtk_binding_entry_add_signal(binding_set, GDK_Page_Up, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_PAGES, + G_TYPE_INT, -1); + gtk_binding_entry_add_signal(binding_set, GDK_End, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS, + G_TYPE_INT, 1); + gtk_binding_entry_add_signal(binding_set, GDK_Home, static_cast<GdkModifierType>(0), + "move-cursor", 2, + G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS, + G_TYPE_INT, -1); + + /* + * properties + */ + + /** + * WebKitWebView:title: + * + * Returns the @web_view's document title. + * + * Since: 1.1.4 + */ + g_object_class_install_property(objectClass, PROP_TITLE, + g_param_spec_string("title", + _("Title"), + _("Returns the @web_view's document title"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:uri: + * + * Returns the current URI of the contents displayed by the @web_view. + * + * Since: 1.1.4 + */ + g_object_class_install_property(objectClass, PROP_URI, + g_param_spec_string("uri", + _("URI"), + _("Returns the current URI of the contents displayed by the @web_view"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:copy-target-list: + * + * The list of targets this web view supports for clipboard copying. + * + * Since: 1.0.2 + */ + g_object_class_install_property(objectClass, PROP_COPY_TARGET_LIST, + g_param_spec_boxed("copy-target-list", + _("Copy target list"), + _("The list of targets this web view supports for clipboard copying"), + GTK_TYPE_TARGET_LIST, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:paste-target-list: + * + * The list of targets this web view supports for clipboard pasting. + * + * Since: 1.0.2 + */ + g_object_class_install_property(objectClass, PROP_PASTE_TARGET_LIST, + g_param_spec_boxed("paste-target-list", + _("Paste target list"), + _("The list of targets this web view supports for clipboard pasting"), + GTK_TYPE_TARGET_LIST, + WEBKIT_PARAM_READABLE)); + + g_object_class_install_property(objectClass, PROP_SETTINGS, + g_param_spec_object("settings", + _("Settings"), + _("An associated WebKitWebSettings instance"), + WEBKIT_TYPE_WEB_SETTINGS, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebView:web-inspector: + * + * The associated WebKitWebInspector instance. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_WEB_INSPECTOR, + g_param_spec_object("web-inspector", + _("Web Inspector"), + _("The associated WebKitWebInspector instance"), + WEBKIT_TYPE_WEB_INSPECTOR, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:viewport-attributes: + * + * The associated #WebKitViewportAttributes instance. + * + * Since: 1.3.8 + */ + g_object_class_install_property(objectClass, PROP_VIEWPORT_ATTRIBUTES, + g_param_spec_object("viewport-attributes", + _("Viewport Attributes"), + _("The associated WebKitViewportAttributes instance"), + WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:window-features: + * + * An associated WebKitWebWindowFeatures instance. + * + * Since: 1.0.3 + */ + g_object_class_install_property(objectClass, PROP_WINDOW_FEATURES, + g_param_spec_object("window-features", + "Window Features", + "An associated WebKitWebWindowFeatures instance", + WEBKIT_TYPE_WEB_WINDOW_FEATURES, + WEBKIT_PARAM_READWRITE)); + + g_object_class_install_property(objectClass, PROP_EDITABLE, + g_param_spec_boolean("editable", + _("Editable"), + _("Whether content can be modified by the user"), + FALSE, + WEBKIT_PARAM_READWRITE)); + + g_object_class_install_property(objectClass, PROP_TRANSPARENT, + g_param_spec_boolean("transparent", + _("Transparent"), + _("Whether content has a transparent background"), + FALSE, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebView:zoom-level: + * + * The level of zoom of the content. + * + * Since: 1.0.1 + */ + g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL, + g_param_spec_float("zoom-level", + _("Zoom level"), + _("The level of zoom of the content"), + G_MINFLOAT, + G_MAXFLOAT, + 1.0f, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebView:full-content-zoom: + * + * Whether the full content is scaled when zooming. + * + * Since: 1.0.1 + */ + g_object_class_install_property(objectClass, PROP_FULL_CONTENT_ZOOM, + g_param_spec_boolean("full-content-zoom", + _("Full content zoom"), + _("Whether the full content is scaled when zooming"), + FALSE, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebView:encoding: + * + * The default encoding of the web view. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, PROP_ENCODING, + g_param_spec_string("encoding", + _("Encoding"), + _("The default encoding of the web view"), + NULL, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:custom-encoding: + * + * The custom encoding of the web view. + * + * Since: 1.1.2 + */ + g_object_class_install_property(objectClass, PROP_CUSTOM_ENCODING, + g_param_spec_string("custom-encoding", + _("Custom Encoding"), + _("The custom encoding of the web view"), + NULL, + WEBKIT_PARAM_READWRITE)); + + /** + * WebKitWebView:load-status: + * + * Determines the current status of the load. + * + * Connect to "notify::load-status" to monitor loading. + * + * Some versions of WebKitGTK+ emitted this signal for the default + * error page, while loading it. This behavior was considered bad, + * because it was essentially exposing an implementation + * detail. From 1.1.19 onwards this signal is no longer emitted for + * the default error pages, but keep in mind that if you override + * the error pages by using webkit_web_frame_load_alternate_string() + * the signals will be emitted. + * + * Since: 1.1.7 + */ + g_object_class_install_property(objectClass, PROP_LOAD_STATUS, + g_param_spec_enum("load-status", + "Load Status", + "Determines the current status of the load", + WEBKIT_TYPE_LOAD_STATUS, + WEBKIT_LOAD_FINISHED, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:progress: + * + * Determines the current progress of the load. + * + * Since: 1.1.7 + */ + g_object_class_install_property(objectClass, PROP_PROGRESS, + g_param_spec_double("progress", + "Progress", + "Determines the current progress of the load", + 0.0, 1.0, 1.0, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:icon-uri: + * + * The URI for the favicon for the #WebKitWebView. + * + * Since: 1.1.18 + */ + g_object_class_install_property(objectClass, PROP_ICON_URI, + g_param_spec_string("icon-uri", + _("Icon URI"), + _("The URI for the favicon for the #WebKitWebView."), + NULL, + WEBKIT_PARAM_READABLE)); + /** + * WebKitWebView:im-context: + * + * The GtkIMMulticontext for the #WebKitWebView. + * + * This is the input method context used for all text entry widgets inside + * the #WebKitWebView. It can be used to generate context menu items for + * controlling the active input method. + * + * Since: 1.1.20 + */ + g_object_class_install_property(objectClass, PROP_IM_CONTEXT, + g_param_spec_object("im-context", + "IM Context", + "The GtkIMMultiContext for the #WebKitWebView.", + GTK_TYPE_IM_CONTEXT, + WEBKIT_PARAM_READABLE)); + + /** + * WebKitWebView:view-mode: + * + * The "view-mode" media feature for the #WebKitWebView. + * + * The "view-mode" media feature is additional information for web + * applications about how the application is running, when it comes + * to user experience. Whether the application is running inside a + * regular browser window, in a dedicated window, fullscreen, for + * instance. + * + * This property stores a %WebKitWebViewViewMode value that matches + * the "view-mode" media feature the web application will see. + * + * See http://www.w3.org/TR/view-mode/ for more information. + * + * Since: 1.3.4 + */ + g_object_class_install_property(objectClass, PROP_VIEW_MODE, + g_param_spec_enum("view-mode", + "View Mode", + "The view-mode media feature for the #WebKitWebView.", + WEBKIT_TYPE_WEB_VIEW_VIEW_MODE, + WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED, + WEBKIT_PARAM_READWRITE)); + + g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate)); +} + +static void webkit_web_view_update_settings(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + WebKitWebSettings* webSettings = priv->webSettings.get(); + Settings* settings = core(webView)->settings(); + + gchar* defaultEncoding, *cursiveFontFamily, *defaultFontFamily, *fantasyFontFamily, *monospaceFontFamily, *sansSerifFontFamily, *serifFontFamily, *userStylesheetUri, *defaultSpellCheckingLanguages; + gboolean autoLoadImages, autoShrinkImages, printBackgrounds, + enableScripts, enablePlugins, enableDeveloperExtras, resizableTextAreas, + enablePrivateBrowsing, enableCaretBrowsing, enableHTML5Database, enableHTML5LocalStorage, + enableXSSAuditor, enableSpatialNavigation, enableFrameFlattening, javascriptCanOpenWindows, + javaScriptCanAccessClipboard, enableOfflineWebAppCache, + enableUniversalAccessFromFileURI, enableFileAccessFromFileURI, + enableDOMPaste, tabKeyCyclesThroughElements, enableWebGL, + enableSiteSpecificQuirks, usePageCache, enableJavaApplet, + enableHyperlinkAuditing, enableFullscreen, enableDNSPrefetching; + + WebKitEditingBehavior editingBehavior; + + g_object_get(webSettings, + "default-encoding", &defaultEncoding, + "cursive-font-family", &cursiveFontFamily, + "default-font-family", &defaultFontFamily, + "fantasy-font-family", &fantasyFontFamily, + "monospace-font-family", &monospaceFontFamily, + "sans-serif-font-family", &sansSerifFontFamily, + "serif-font-family", &serifFontFamily, + "auto-load-images", &autoLoadImages, + "auto-shrink-images", &autoShrinkImages, + "print-backgrounds", &printBackgrounds, + "enable-scripts", &enableScripts, + "enable-plugins", &enablePlugins, + "resizable-text-areas", &resizableTextAreas, + "user-stylesheet-uri", &userStylesheetUri, + "enable-developer-extras", &enableDeveloperExtras, + "enable-private-browsing", &enablePrivateBrowsing, + "enable-caret-browsing", &enableCaretBrowsing, + "enable-html5-database", &enableHTML5Database, + "enable-html5-local-storage", &enableHTML5LocalStorage, + "enable-xss-auditor", &enableXSSAuditor, + "enable-spatial-navigation", &enableSpatialNavigation, + "enable-frame-flattening", &enableFrameFlattening, + "javascript-can-open-windows-automatically", &javascriptCanOpenWindows, + "javascript-can-access-clipboard", &javaScriptCanAccessClipboard, + "enable-offline-web-application-cache", &enableOfflineWebAppCache, + "editing-behavior", &editingBehavior, + "enable-universal-access-from-file-uris", &enableUniversalAccessFromFileURI, + "enable-file-access-from-file-uris", &enableFileAccessFromFileURI, + "enable-dom-paste", &enableDOMPaste, + "tab-key-cycles-through-elements", &tabKeyCyclesThroughElements, + "enable-site-specific-quirks", &enableSiteSpecificQuirks, + "enable-page-cache", &usePageCache, + "enable-java-applet", &enableJavaApplet, + "enable-hyperlink-auditing", &enableHyperlinkAuditing, + "spell-checking-languages", &defaultSpellCheckingLanguages, + "enable-fullscreen", &enableFullscreen, + "enable-dns-prefetching", &enableDNSPrefetching, + "enable-webgl", &enableWebGL, + NULL); + + settings->setDefaultTextEncodingName(defaultEncoding); + settings->setCursiveFontFamily(cursiveFontFamily); + settings->setStandardFontFamily(defaultFontFamily); + settings->setFantasyFontFamily(fantasyFontFamily); + settings->setFixedFontFamily(monospaceFontFamily); + settings->setSansSerifFontFamily(sansSerifFontFamily); + settings->setSerifFontFamily(serifFontFamily); + settings->setLoadsImagesAutomatically(autoLoadImages); + settings->setShrinksStandaloneImagesToFit(autoShrinkImages); + settings->setShouldPrintBackgrounds(printBackgrounds); + settings->setJavaScriptEnabled(enableScripts); + settings->setPluginsEnabled(enablePlugins); + settings->setTextAreasAreResizable(resizableTextAreas); + settings->setUserStyleSheetLocation(KURL(KURL(), userStylesheetUri)); + settings->setDeveloperExtrasEnabled(enableDeveloperExtras); + settings->setPrivateBrowsingEnabled(enablePrivateBrowsing); + settings->setCaretBrowsingEnabled(enableCaretBrowsing); +#if ENABLE(DATABASE) + AbstractDatabase::setIsAvailable(enableHTML5Database); +#endif + settings->setLocalStorageEnabled(enableHTML5LocalStorage); + settings->setXSSAuditorEnabled(enableXSSAuditor); + settings->setSpatialNavigationEnabled(enableSpatialNavigation); + settings->setFrameFlatteningEnabled(enableFrameFlattening); + settings->setJavaScriptCanOpenWindowsAutomatically(javascriptCanOpenWindows); + settings->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard); + settings->setOfflineWebApplicationCacheEnabled(enableOfflineWebAppCache); + settings->setEditingBehaviorType(static_cast<WebCore::EditingBehaviorType>(editingBehavior)); + settings->setAllowUniversalAccessFromFileURLs(enableUniversalAccessFromFileURI); + settings->setAllowFileAccessFromFileURLs(enableFileAccessFromFileURI); + settings->setDOMPasteAllowed(enableDOMPaste); + settings->setNeedsSiteSpecificQuirks(enableSiteSpecificQuirks); + settings->setUsesPageCache(usePageCache); + settings->setJavaEnabled(enableJavaApplet); + settings->setHyperlinkAuditingEnabled(enableHyperlinkAuditing); + settings->setDNSPrefetchingEnabled(enableDNSPrefetching); + +#if ENABLE(FULLSCREEN_API) + settings->setFullScreenEnabled(enableFullscreen); +#endif + +#if ENABLE(SPELLCHECK) + WebKit::EditorClient* client = static_cast<WebKit::EditorClient*>(core(webView)->editorClient()); + static_cast<WebKit::TextCheckerClientEnchant*>(client->textChecker())->updateSpellCheckingLanguage(defaultSpellCheckingLanguages); +#endif + +#if ENABLE(WEBGL) + settings->setWebGLEnabled(enableWebGL); +#endif + + Page* page = core(webView); + if (page) + page->setTabKeyCyclesThroughElements(tabKeyCyclesThroughElements); + + g_free(defaultEncoding); + g_free(cursiveFontFamily); + g_free(defaultFontFamily); + g_free(fantasyFontFamily); + g_free(monospaceFontFamily); + g_free(sansSerifFontFamily); + g_free(serifFontFamily); + g_free(userStylesheetUri); + + webkit_web_view_screen_changed(GTK_WIDGET(webView), NULL); +} + +static inline gint pixelsFromSize(WebKitWebView* webView, gint size) +{ + gdouble DPI = webViewGetDPI(webView); + return size / 72.0 * DPI; +} + +static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView) +{ + Settings* settings = core(webView)->settings(); + + const gchar* name = g_intern_string(pspec->name); + GValue value = { 0, { { 0 } } }; + g_value_init(&value, pspec->value_type); + g_object_get_property(G_OBJECT(webSettings), name, &value); + + if (name == g_intern_string("default-encoding")) + settings->setDefaultTextEncodingName(g_value_get_string(&value)); + else if (name == g_intern_string("cursive-font-family")) + settings->setCursiveFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("default-font-family")) + settings->setStandardFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("fantasy-font-family")) + settings->setFantasyFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("monospace-font-family")) + settings->setFixedFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("sans-serif-font-family")) + settings->setSansSerifFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("serif-font-family")) + settings->setSerifFontFamily(g_value_get_string(&value)); + else if (name == g_intern_string("default-font-size")) + settings->setDefaultFontSize(pixelsFromSize(webView, g_value_get_int(&value))); + else if (name == g_intern_string("default-monospace-font-size")) + settings->setDefaultFixedFontSize(pixelsFromSize(webView, g_value_get_int(&value))); + else if (name == g_intern_string("minimum-font-size")) + settings->setMinimumFontSize(pixelsFromSize(webView, g_value_get_int(&value))); + else if (name == g_intern_string("minimum-logical-font-size")) + settings->setMinimumLogicalFontSize(pixelsFromSize(webView, g_value_get_int(&value))); + else if (name == g_intern_string("enforce-96-dpi")) + webkit_web_view_screen_changed(GTK_WIDGET(webView), NULL); + else if (name == g_intern_string("auto-load-images")) + settings->setLoadsImagesAutomatically(g_value_get_boolean(&value)); + else if (name == g_intern_string("auto-shrink-images")) + settings->setShrinksStandaloneImagesToFit(g_value_get_boolean(&value)); + else if (name == g_intern_string("print-backgrounds")) + settings->setShouldPrintBackgrounds(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-scripts")) + settings->setJavaScriptEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-plugins")) + settings->setPluginsEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-dns-prefetching")) + settings->setDNSPrefetchingEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("resizable-text-areas")) + settings->setTextAreasAreResizable(g_value_get_boolean(&value)); + else if (name == g_intern_string("user-stylesheet-uri")) + settings->setUserStyleSheetLocation(KURL(KURL(), g_value_get_string(&value))); + else if (name == g_intern_string("enable-developer-extras")) + settings->setDeveloperExtrasEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-private-browsing")) + settings->setPrivateBrowsingEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-caret-browsing")) + settings->setCaretBrowsingEnabled(g_value_get_boolean(&value)); +#if ENABLE(DATABASE) + else if (name == g_intern_string("enable-html5-database")) { + AbstractDatabase::setIsAvailable(g_value_get_boolean(&value)); + } +#endif + else if (name == g_intern_string("enable-html5-local-storage")) + settings->setLocalStorageEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-xss-auditor")) + settings->setXSSAuditorEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-spatial-navigation")) + settings->setSpatialNavigationEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-frame-flattening")) + settings->setFrameFlatteningEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("javascript-can-open-windows-automatically")) + settings->setJavaScriptCanOpenWindowsAutomatically(g_value_get_boolean(&value)); + else if (name == g_intern_string("javascript-can-access-clipboard")) + settings->setJavaScriptCanAccessClipboard(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-offline-web-application-cache")) + settings->setOfflineWebApplicationCacheEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("editing-behavior")) + settings->setEditingBehaviorType(static_cast<WebCore::EditingBehaviorType>(g_value_get_enum(&value))); + else if (name == g_intern_string("enable-universal-access-from-file-uris")) + settings->setAllowUniversalAccessFromFileURLs(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-file-access-from-file-uris")) + settings->setAllowFileAccessFromFileURLs(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-dom-paste")) + settings->setDOMPasteAllowed(g_value_get_boolean(&value)); + else if (name == g_intern_string("tab-key-cycles-through-elements")) { + Page* page = core(webView); + if (page) + page->setTabKeyCyclesThroughElements(g_value_get_boolean(&value)); + } else if (name == g_intern_string("enable-site-specific-quirks")) + settings->setNeedsSiteSpecificQuirks(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-page-cache")) + settings->setUsesPageCache(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-java-applet")) + settings->setJavaEnabled(g_value_get_boolean(&value)); + else if (name == g_intern_string("enable-hyperlink-auditing")) + settings->setHyperlinkAuditingEnabled(g_value_get_boolean(&value)); + +#if ENABLE(SPELLCHECK) + else if (name == g_intern_string("spell-checking-languages")) { + WebKit::EditorClient* client = static_cast<WebKit::EditorClient*>(core(webView)->editorClient()); + static_cast<WebKit::TextCheckerClientEnchant*>(client->textChecker())->updateSpellCheckingLanguage(g_value_get_string(&value)); + } +#endif + +#if ENABLE(WEBGL) + else if (name == g_intern_string("enable-webgl")) + settings->setWebGLEnabled(g_value_get_boolean(&value)); +#endif + + else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name)) + g_warning("Unexpected setting '%s'", name); + g_value_unset(&value); +} + +static void webkit_web_view_init(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(webView, WEBKIT_TYPE_WEB_VIEW, WebKitWebViewPrivate); + webView->priv = priv; + // This is the placement new syntax: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10 + // It allows us to call a constructor on manually allocated locations in memory. We must use it + // in this case, because GLib manages the memory for the private data section, but we wish it + // to contain C++ object members. The use of placement new calls the constructor on all C++ data + // members, which ensures they are initialized properly. + new (priv) WebKitWebViewPrivate(); + + priv->imContext = adoptGRef(gtk_im_multicontext_new()); + + Page::PageClients pageClients; + pageClients.chromeClient = new WebKit::ChromeClient(webView); + pageClients.contextMenuClient = new WebKit::ContextMenuClient(webView); + pageClients.editorClient = new WebKit::EditorClient(webView); + pageClients.dragClient = new WebKit::DragClient(webView); + pageClients.inspectorClient = new WebKit::InspectorClient(webView); + priv->corePage = new Page(pageClients); + + // Pages within a same session need to be linked together otherwise some functionalities such + // as visited link coloration (across pages) and changing popup window location will not work. + // To keep the default behavior simple (and because no PageGroup API exist in WebKitGTK at the + // time of writing this comment), we simply set all the pages to the same group. + priv->corePage->setGroupName("org.webkit.gtk.WebKitGTK"); + + // We also add a simple wrapper class to provide the public + // interface for the Web Inspector. + priv->webInspector = adoptGRef(WEBKIT_WEB_INSPECTOR(g_object_new(WEBKIT_TYPE_WEB_INSPECTOR, NULL))); + webkit_web_inspector_set_inspector_client(priv->webInspector.get(), priv->corePage); + + // And our ViewportAttributes friend. + priv->viewportAttributes = adoptGRef(WEBKIT_VIEWPORT_ATTRIBUTES(g_object_new(WEBKIT_TYPE_VIEWPORT_ATTRIBUTES, NULL))); + priv->viewportAttributes->priv->webView = webView; + + // The smart pointer will call g_object_ref_sink on these adjustments. + priv->horizontalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); + priv->verticalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); + + gtk_widget_set_can_focus(GTK_WIDGET(webView), TRUE); + priv->mainFrame = WEBKIT_WEB_FRAME(webkit_web_frame_new(webView)); + priv->lastPopupXPosition = priv->lastPopupYPosition = -1; + + priv->backForwardList = adoptGRef(webkit_web_back_forward_list_new_with_web_view(webView)); + + priv->zoomFullContent = FALSE; + + priv->webSettings = adoptGRef(webkit_web_settings_new()); + webkit_web_view_update_settings(webView); + g_signal_connect(priv->webSettings.get(), "notify", G_CALLBACK(webkit_web_view_settings_notify), webView); + + priv->webWindowFeatures = adoptGRef(webkit_web_window_features_new()); + + priv->subResources = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref)); + + priv->currentClickCount = 0; + priv->previousClickButton = 0; + priv->previousClickTime = 0; + gtk_drag_dest_set(GTK_WIDGET(webView), static_cast<GtkDestDefaults>(0), 0, 0, static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE)); + gtk_drag_dest_set_target_list(GTK_WIDGET(webView), pasteboardHelperInstance()->targetList()); +} + +GtkWidget* webkit_web_view_new(void) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL)); + + return GTK_WIDGET(webView); +} + +// for internal use only +void webkit_web_view_notify_ready(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + gboolean isHandled = FALSE; + g_signal_emit(webView, webkit_web_view_signals[WEB_VIEW_READY], 0, &isHandled); +} + +void webkit_web_view_request_download(WebKitWebView* webView, WebKitNetworkRequest* request, const ResourceResponse& response, ResourceHandle* handle) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + WebKitDownload* download; + + if (handle) + download = webkit_download_new_with_handle(request, handle, response); + else + download = webkit_download_new(request); + + gboolean handled; + g_signal_emit(webView, webkit_web_view_signals[DOWNLOAD_REQUESTED], 0, download, &handled); + + if (!handled) { + webkit_download_cancel(download); + g_object_unref(download); + return; + } + + /* Start the download now if it has a destination URI, otherwise it + may be handled asynchronously by the application. */ + if (webkit_download_get_destination_uri(download)) + webkit_download_start(download); +} + +bool webkit_web_view_use_primary_for_paste(WebKitWebView* webView) +{ + return webView->priv->usePrimaryForPaste; +} + +/** + * webkit_web_view_set_settings: + * @webView: a #WebKitWebView + * @settings: (transfer none): the #WebKitWebSettings to be set + * + * Replaces the #WebKitWebSettings instance that is currently attached + * to @web_view with @settings. The reference held by the @web_view on + * the old #WebKitWebSettings instance is dropped, and the reference + * count of @settings is inscreased. + * + * The settings are automatically applied to @web_view. + */ +void webkit_web_view_set_settings(WebKitWebView* webView, WebKitWebSettings* webSettings) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings)); + + WebKitWebViewPrivate* priv = webView->priv; + g_signal_handlers_disconnect_by_func(priv->webSettings.get(), (gpointer)webkit_web_view_settings_notify, webView); + priv->webSettings = webSettings; + webkit_web_view_update_settings(webView); + g_signal_connect(webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView); + g_object_notify(G_OBJECT(webView), "settings"); +} + +/** + * webkit_web_view_get_settings: + * @webView: a #WebKitWebView + * + * Obtains the #WebKitWebSettings associated with the + * #WebKitWebView. The #WebKitWebView always has an associated + * instance of #WebKitWebSettings. The reference that is returned by + * this call is owned by the #WebKitWebView. You may need to increase + * its reference count if you intend to keep it alive for longer than + * the #WebKitWebView. + * + * Return value: (transfer none): the #WebKitWebSettings instance + */ +WebKitWebSettings* webkit_web_view_get_settings(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + return webView->priv->webSettings.get(); +} + +/** + * webkit_web_view_get_inspector: + * @webView: a #WebKitWebView + * + * Obtains the #WebKitWebInspector associated with the + * #WebKitWebView. Every #WebKitWebView object has a + * #WebKitWebInspector object attached to it as soon as it is created, + * so this function will only return NULL if the argument is not a + * valid #WebKitWebView. + * + * Return value: (transfer none): the #WebKitWebInspector instance. + * + * Since: 1.0.3 + */ +WebKitWebInspector* webkit_web_view_get_inspector(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + return webView->priv->webInspector.get(); +} + +/** + * webkit_web_view_get_viewport_attributes: + * @webView: a #WebKitWebView + * + * Obtains the #WebKitViewportAttributes associated with the + * #WebKitWebView. Every #WebKitWebView object has a + * #WebKitWebViewporAttributes object attached to it as soon as it is + * created, so this function will only return NULL if the argument is + * not a valid #WebKitWebView. Do note however that the viewport + * attributes object only contains valid information when the current + * page has a viewport meta tag. You can check whether the data should + * be used by checking the #WebKitViewport:valid property. + * + * Return value: (transfer none): the #WebKitViewportAttributes instance. + * + * Since: 1.3.8 + */ +WebKitViewportAttributes* webkit_web_view_get_viewport_attributes(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + return webView->priv->viewportAttributes.get(); +} + +// internal +static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures) +{ + if (!webWindowFeatures) + return; + if (webkit_web_window_features_equal(webView->priv->webWindowFeatures.get(), webWindowFeatures)) + return; + webView->priv->webWindowFeatures = webWindowFeatures; +} + +/** + * webkit_web_view_get_window_features: + * @webView: a #WebKitWebView + * + * Returns the instance of #WebKitWebWindowFeatures held by the given + * #WebKitWebView. + * + * Return value: (transfer none): the #WebKitWebWindowFeatures + * + * Since: 1.0.3 + */ +WebKitWebWindowFeatures* webkit_web_view_get_window_features(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + return webView->priv->webWindowFeatures.get(); +} + +/** + * webkit_web_view_get_title: + * @webView: a #WebKitWebView + * + * Returns the @web_view's document title + * + * Since: 1.1.4 + * + * Return value: the title of @web_view + */ +G_CONST_RETURN gchar* webkit_web_view_get_title(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + + WebKitWebViewPrivate* priv = webView->priv; + return priv->mainFrame->priv->title; +} + +/** + * webkit_web_view_get_uri: + * @webView: a #WebKitWebView + * + * Returns the current URI of the contents displayed by the @web_view + * + * Since: 1.1.4 + * + * Return value: the URI of @web_view + */ +G_CONST_RETURN gchar* webkit_web_view_get_uri(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + + WebKitWebViewPrivate* priv = webView->priv; + return priv->mainFrame->priv->uri; +} + +/** + * webkit_web_view_set_maintains_back_forward_list: + * @webView: a #WebKitWebView + * @flag: to tell the view to maintain a back or forward list + * + * Set the view to maintain a back or forward list of history items. + */ +void webkit_web_view_set_maintains_back_forward_list(WebKitWebView* webView, gboolean flag) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + static_cast<BackForwardListImpl*>(core(webView)->backForwardList())->setEnabled(flag); +} + +/** + * webkit_web_view_get_back_forward_list: + * @webView: a #WebKitWebView + * + * Obtains the #WebKitWebBackForwardList associated with the given #WebKitWebView. The + * #WebKitWebBackForwardList is owned by the #WebKitWebView. + * + * Return value: (transfer none): the #WebKitWebBackForwardList + */ +WebKitWebBackForwardList* webkit_web_view_get_back_forward_list(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + if (!core(webView) || !static_cast<BackForwardListImpl*>(core(webView)->backForwardList())->enabled()) + return 0; + return webView->priv->backForwardList.get(); +} + +/** + * webkit_web_view_go_to_back_forward_item: + * @webView: a #WebKitWebView + * @item: a #WebKitWebHistoryItem* + * + * Go to the specified #WebKitWebHistoryItem + * + * Return value: %TRUE if loading of item is successful, %FALSE if not + */ +gboolean webkit_web_view_go_to_back_forward_item(WebKitWebView* webView, WebKitWebHistoryItem* item) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(item), FALSE); + + WebKitWebBackForwardList* backForwardList = webkit_web_view_get_back_forward_list(webView); + if (!webkit_web_back_forward_list_contains_item(backForwardList, item)) + return FALSE; + + core(webView)->goToItem(core(item), FrameLoadTypeIndexedBackForward); + return TRUE; +} + +/** + * webkit_web_view_go_back: + * @webView: a #WebKitWebView + * + * Loads the previous history item. + */ +void webkit_web_view_go_back(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->goBack(); +} + +/** + * webkit_web_view_go_back_or_forward: + * @webView: a #WebKitWebView + * @steps: the number of steps + * + * Loads the history item that is the number of @steps away from the current + * item. Negative values represent steps backward while positive values + * represent steps forward. + */ +void webkit_web_view_go_back_or_forward(WebKitWebView* webView, gint steps) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->goBackOrForward(steps); +} + +/** + * webkit_web_view_go_forward: + * @webView: a #WebKitWebView + * + * Loads the next history item. + */ +void webkit_web_view_go_forward(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->goForward(); +} + +/** + * webkit_web_view_can_go_back: + * @webView: a #WebKitWebView + * + * Determines whether #web_view has a previous history item. + * + * Return value: %TRUE if able to move back, %FALSE otherwise + */ +gboolean webkit_web_view_can_go_back(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + if (!core(webView) || !core(webView)->backForwardList()->backItem()) + return FALSE; + + return TRUE; +} + +/** + * webkit_web_view_can_go_back_or_forward: + * @webView: a #WebKitWebView + * @steps: the number of steps + * + * Determines whether #web_view has a history item of @steps. Negative values + * represent steps backward while positive values represent steps forward. + * + * Return value: %TRUE if able to move back or forward the given number of + * steps, %FALSE otherwise + */ +gboolean webkit_web_view_can_go_back_or_forward(WebKitWebView* webView, gint steps) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + return core(webView)->canGoBackOrForward(steps); +} + +/** + * webkit_web_view_can_go_forward: + * @webView: a #WebKitWebView + * + * Determines whether #web_view has a next history item. + * + * Return value: %TRUE if able to move forward, %FALSE otherwise + */ +gboolean webkit_web_view_can_go_forward(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Page* page = core(webView); + + if (!page) + return FALSE; + + if (!page->backForwardList()->forwardItem()) + return FALSE; + + return TRUE; +} + +/** + * webkit_web_view_open: + * @webView: a #WebKitWebView + * @uri: an URI + * + * Requests loading of the specified URI string. + * + * Deprecated: 1.1.1: Use webkit_web_view_load_uri() instead. + */ +void webkit_web_view_open(WebKitWebView* webView, const gchar* uri) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(uri); + + // We used to support local paths, unlike the newer + // function webkit_web_view_load_uri + if (g_path_is_absolute(uri)) { + gchar* fileUri = g_filename_to_uri(uri, NULL, NULL); + webkit_web_view_load_uri(webView, fileUri); + g_free(fileUri); + } + else + webkit_web_view_load_uri(webView, uri); +} + +void webkit_web_view_reload(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->mainFrame()->loader()->reload(); +} + +/** + * webkit_web_view_reload_bypass_cache: + * @webView: a #WebKitWebView + * + * Reloads the @web_view without using any cached data. + * + * Since: 1.0.3 + */ +void webkit_web_view_reload_bypass_cache(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->mainFrame()->loader()->reload(true); +} + +/** + * webkit_web_view_load_uri: + * @webView: a #WebKitWebView + * @uri: an URI string + * + * Requests loading of the specified URI string. + * + * Since: 1.1.1 + */ +void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(uri); + + WebKitWebFrame* frame = webView->priv->mainFrame; + webkit_web_frame_load_uri(frame, uri); +} + +/** + * webkit_web_view_load_string: + * @webView: a #WebKitWebView + * @content: an URI string + * @mime_type: the MIME type, or %NULL + * @encoding: the encoding, or %NULL + * @base_uri: the base URI for relative locations + * + * Requests loading of the given @content with the specified @mime_type, + * @encoding and @base_uri. + * + * If @mime_type is %NULL, "text/html" is assumed. + * + * If @encoding is %NULL, "UTF-8" is assumed. + */ +void webkit_web_view_load_string(WebKitWebView* webView, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseUri) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(content); + + WebKitWebFrame* frame = webView->priv->mainFrame; + webkit_web_frame_load_string(frame, content, mimeType, encoding, baseUri); +} +/** + * webkit_web_view_load_html_string: + * @webView: a #WebKitWebView + * @content: an URI string + * @base_uri: the base URI for relative locations + * + * Requests loading of the given @content with the specified @base_uri. + * + * Deprecated: 1.1.1: Use webkit_web_view_load_string() instead. + */ +void webkit_web_view_load_html_string(WebKitWebView* webView, const gchar* content, const gchar* baseUri) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(content); + + webkit_web_view_load_string(webView, content, NULL, NULL, baseUri); +} + +/** + * webkit_web_view_load_request: + * @webView: a #WebKitWebView + * @request: a #WebKitNetworkRequest + * + * Requests loading of the specified asynchronous client request. + * + * Creates a provisional data source that will transition to a committed data + * source once any data has been received. Use webkit_web_view_stop_loading() to + * stop the load. + * + * Since: 1.1.1 + */ +void webkit_web_view_load_request(WebKitWebView* webView, WebKitNetworkRequest* request) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request)); + + WebKitWebFrame* frame = webView->priv->mainFrame; + webkit_web_frame_load_request(frame, request); +} + +/** + * webkit_web_view_stop_loading: + * @webView: a #WebKitWebView + * + * Stops any ongoing load in the @webView. + **/ +void webkit_web_view_stop_loading(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + Frame* frame = core(webView)->mainFrame(); + + if (FrameLoader* loader = frame->loader()) + loader->stopForUserCancel(); +} + +/** + * webkit_web_view_search_text: + * @webView: a #WebKitWebView + * @text: a string to look for + * @forward: whether to find forward or not + * @case_sensitive: whether to respect the case of text + * @wrap: whether to continue looking at the beginning after reaching the end + * + * Looks for a specified string inside #web_view. + * + * Return value: %TRUE on success or %FALSE on failure + */ +gboolean webkit_web_view_search_text(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, gboolean forward, gboolean shouldWrap) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + g_return_val_if_fail(string, FALSE); + + TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive; + FindDirection direction = forward ? FindDirectionForward : FindDirectionBackward; + + return core(webView)->findString(String::fromUTF8(string), caseSensitivity, direction, shouldWrap); +} + +/** + * webkit_web_view_mark_text_matches: + * @webView: a #WebKitWebView + * @string: a string to look for + * @case_sensitive: whether to respect the case of text + * @limit: the maximum number of strings to look for or 0 for all + * + * Attempts to highlight all occurances of #string inside #web_view. + * + * Return value: the number of strings highlighted + */ +guint webkit_web_view_mark_text_matches(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, guint limit) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + g_return_val_if_fail(string, 0); + + TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive; + + return core(webView)->markAllMatchesForText(String::fromUTF8(string), caseSensitivity, false, limit); +} + +/** + * webkit_web_view_set_highlight_text_matches: + * @webView: a #WebKitWebView + * @highlight: whether to highlight text matches + * + * Highlights text matches previously marked by webkit_web_view_mark_text_matches. + */ +void webkit_web_view_set_highlight_text_matches(WebKitWebView* webView, gboolean shouldHighlight) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + Frame *frame = core(webView)->mainFrame(); + do { + frame->editor()->setMarkedTextMatchesAreHighlighted(shouldHighlight); + frame = frame->tree()->traverseNextWithWrap(false); + } while (frame); +} + +/** + * webkit_web_view_unmark_text_matches: + * @webView: a #WebKitWebView + * + * Removes highlighting previously set by webkit_web_view_mark_text_matches. + */ +void webkit_web_view_unmark_text_matches(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + return core(webView)->unmarkAllTextMatches(); +} + +/** + * webkit_web_view_get_main_frame: + * @webView: a #WebKitWebView + * + * Returns the main frame for the @webView. + * + * Return value: (transfer none): the main #WebKitWebFrame for @webView + */ +WebKitWebFrame* webkit_web_view_get_main_frame(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + + return webView->priv->mainFrame; +} + +/** + * webkit_web_view_get_focused_frame: + * @webView: a #WebKitWebView + * + * Returns the frame that has focus or an active text selection. + * + * Return value: (transfer none): The focused #WebKitWebFrame or %NULL if no frame is focused + */ +WebKitWebFrame* webkit_web_view_get_focused_frame(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + + Frame* focusedFrame = core(webView)->focusController()->focusedFrame(); + return kit(focusedFrame); +} + +void webkit_web_view_execute_script(WebKitWebView* webView, const gchar* script) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(script); + + core(webView)->mainFrame()->script()->executeScript(String::fromUTF8(script), true); +} + +/** + * webkit_web_view_can_cut_clipboard: + * @webView: a #WebKitWebView + * + * Determines whether or not it is currently possible to cut to the clipboard. + * + * Return value: %TRUE if a selection can be cut, %FALSE if not + */ +gboolean webkit_web_view_can_cut_clipboard(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return frame->editor()->canCut() || frame->editor()->canDHTMLCut(); +} + +/** + * webkit_web_view_can_copy_clipboard: + * @webView: a #WebKitWebView + * + * Determines whether or not it is currently possible to copy to the clipboard. + * + * Return value: %TRUE if a selection can be copied, %FALSE if not + */ +gboolean webkit_web_view_can_copy_clipboard(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return frame->editor()->canCopy() || frame->editor()->canDHTMLCopy(); +} + +/** + * webkit_web_view_can_paste_clipboard: + * @webView: a #WebKitWebView + * + * Determines whether or not it is currently possible to paste from the clipboard. + * + * Return value: %TRUE if a selection can be pasted, %FALSE if not + */ +gboolean webkit_web_view_can_paste_clipboard(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return frame->editor()->canPaste() || frame->editor()->canDHTMLPaste(); +} + +/** + * webkit_web_view_cut_clipboard: + * @webView: a #WebKitWebView + * + * Cuts the current selection inside the @web_view to the clipboard. + */ +void webkit_web_view_cut_clipboard(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (webkit_web_view_can_cut_clipboard(webView)) + g_signal_emit(webView, webkit_web_view_signals[CUT_CLIPBOARD], 0); +} + +/** + * webkit_web_view_copy_clipboard: + * @webView: a #WebKitWebView + * + * Copies the current selection inside the @web_view to the clipboard. + */ +void webkit_web_view_copy_clipboard(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (webkit_web_view_can_copy_clipboard(webView)) + g_signal_emit(webView, webkit_web_view_signals[COPY_CLIPBOARD], 0); +} + +/** + * webkit_web_view_paste_clipboard: + * @webView: a #WebKitWebView + * + * Pastes the current contents of the clipboard to the @web_view. + */ +void webkit_web_view_paste_clipboard(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (webkit_web_view_can_paste_clipboard(webView)) + g_signal_emit(webView, webkit_web_view_signals[PASTE_CLIPBOARD], 0); +} + +/** + * webkit_web_view_delete_selection: + * @webView: a #WebKitWebView + * + * Deletes the current selection inside the @web_view. + */ +void webkit_web_view_delete_selection(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + frame->editor()->performDelete(); +} + +/** + * webkit_web_view_has_selection: + * @webView: a #WebKitWebView + * + * Determines whether text was selected. + * + * Return value: %TRUE if there is selected text, %FALSE if not + */ +gboolean webkit_web_view_has_selection(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + return !core(webView)->selection().isNone(); +} + +/** + * webkit_web_view_get_selected_text: + * @webView: a #WebKitWebView + * + * Retrieves the selected text if any. + * + * Return value: a newly allocated string with the selection or %NULL + */ +gchar* webkit_web_view_get_selected_text(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return g_strdup(frame->editor()->selectedText().utf8().data()); +} + +/** + * webkit_web_view_select_all: + * @webView: a #WebKitWebView + * + * Attempts to select everything inside the @web_view. + */ +void webkit_web_view_select_all(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + g_signal_emit(webView, webkit_web_view_signals[SELECT_ALL], 0); +} + +/** + * webkit_web_view_get_editable: + * @webView: a #WebKitWebView + * + * Returns whether the user is allowed to edit the document. + * + * Returns %TRUE if @web_view allows the user to edit the HTML document, %FALSE if + * it doesn't. You can change @web_view's document programmatically regardless of + * this setting. + * + * Return value: a #gboolean indicating the editable state + */ +gboolean webkit_web_view_get_editable(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + return core(webView)->isEditable(); +} + +/** + * webkit_web_view_set_editable: + * @webView: a #WebKitWebView + * @flag: a #gboolean indicating the editable state + * + * Sets whether @web_view allows the user to edit its HTML document. + * + * If @flag is %TRUE, @web_view allows the user to edit the document. If @flag is + * %FALSE, an element in @web_view's document can only be edited if the + * CONTENTEDITABLE attribute has been set on the element or one of its parent + * elements. You can change @web_view's document programmatically regardless of + * this setting. By default a #WebKitWebView is not editable. + + * Normally, an HTML document is not editable unless the elements within the + * document are editable. This function provides a low-level way to make the + * contents of a #WebKitWebView editable without altering the document or DOM + * structure. + */ +void webkit_web_view_set_editable(WebKitWebView* webView, gboolean flag) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + flag = flag != FALSE; + if (flag == webkit_web_view_get_editable(webView)) + return; + + core(webView)->setEditable(flag); + + Frame* frame = core(webView)->mainFrame(); + g_return_if_fail(frame); + + if (flag) { + frame->editor()->applyEditingStyleToBodyElement(); + // TODO: If the WebKitWebView is made editable and the selection is empty, set it to something. + //if (!webkit_web_view_get_selected_dom_range(webView)) + // mainFrame->setSelectionFromNone(); + } + g_object_notify(G_OBJECT(webView), "editable"); +} + +/** + * webkit_web_view_get_copy_target_list: + * @webView: a #WebKitWebView + * + * This function returns the list of targets this #WebKitWebView can + * provide for clipboard copying and as DND source. The targets in the list are + * added with values from the #WebKitWebViewTargetInfo enum, + * using gtk_target_list_add() and + * gtk_target_list_add_text_targets(). + * + * Return value: the #GtkTargetList + **/ +GtkTargetList* webkit_web_view_get_copy_target_list(WebKitWebView* webView) +{ + return pasteboardHelperInstance()->targetList(); +} + +/** + * webkit_web_view_get_paste_target_list: + * @webView: a #WebKitWebView + * + * This function returns the list of targets this #WebKitWebView can + * provide for clipboard pasting and as DND destination. The targets in the list are + * added with values from the #WebKitWebViewTargetInfo enum, + * using gtk_target_list_add() and + * gtk_target_list_add_text_targets(). + * + * Return value: the #GtkTargetList + **/ +GtkTargetList* webkit_web_view_get_paste_target_list(WebKitWebView* webView) +{ + return pasteboardHelperInstance()->targetList(); +} + +/** + * webkit_web_view_can_show_mime_type: + * @webView: a #WebKitWebView + * @mime_type: a MIME type + * + * This functions returns whether or not a MIME type can be displayed using this view. + * + * Return value: a #gboolean indicating if the MIME type can be displayed + * + * Since: 1.0.3 + **/ + +gboolean webkit_web_view_can_show_mime_type(WebKitWebView* webView, const gchar* mimeType) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webkit_web_view_get_main_frame(webView)); + if (FrameLoader* loader = frame->loader()) + return loader->canShowMIMEType(String::fromUTF8(mimeType)); + else + return FALSE; +} + +/** + * webkit_web_view_get_transparent: + * @webView: a #WebKitWebView + * + * Returns whether the #WebKitWebView has a transparent background. + * + * Return value: %FALSE when the #WebKitWebView draws a solid background + * (the default), otherwise %TRUE. + */ +gboolean webkit_web_view_get_transparent(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + WebKitWebViewPrivate* priv = webView->priv; + return priv->transparent; +} + +/** + * webkit_web_view_set_transparent: + * @webView: a #WebKitWebView + * + * Sets whether the #WebKitWebView has a transparent background. + * + * Pass %FALSE to have the #WebKitWebView draw a solid background + * (the default), otherwise %TRUE. + */ +void webkit_web_view_set_transparent(WebKitWebView* webView, gboolean flag) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + WebKitWebViewPrivate* priv = webView->priv; + priv->transparent = flag; + + // TODO: This needs to be made persistent or it could become a problem when + // the main frame is replaced. + Frame* frame = core(webView)->mainFrame(); + g_return_if_fail(frame); + frame->view()->setTransparent(flag); + g_object_notify(G_OBJECT(webView), "transparent"); +} + +/** + * webkit_web_view_get_zoom_level: + * @webView: a #WebKitWebView + * + * Returns the zoom level of @web_view, i.e. the factor by which elements in + * the page are scaled with respect to their original size. + * If the "full-content-zoom" property is set to %FALSE (the default) + * the zoom level changes the text size, or if %TRUE, scales all + * elements in the page. + * + * Return value: the zoom level of @web_view + * + * Since: 1.0.1 + */ +gfloat webkit_web_view_get_zoom_level(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1.0f); + + Frame* frame = core(webView)->mainFrame(); + if (!frame) + return 1.0f; + + WebKitWebViewPrivate* priv = webView->priv; + return priv->zoomFullContent ? frame->pageZoomFactor() : frame->textZoomFactor(); +} + +static void webkit_web_view_apply_zoom_level(WebKitWebView* webView, gfloat zoomLevel) +{ + Frame* frame = core(webView)->mainFrame(); + if (!frame) + return; + + WebKitWebViewPrivate* priv = webView->priv; + if (priv->zoomFullContent) + frame->setPageZoomFactor(zoomLevel); + else + frame->setTextZoomFactor(zoomLevel); +} + +/** + * webkit_web_view_set_zoom_level: + * @webView: a #WebKitWebView + * @zoom_level: the new zoom level + * + * Sets the zoom level of @web_view, i.e. the factor by which elements in + * the page are scaled with respect to their original size. + * If the "full-content-zoom" property is set to %FALSE (the default) + * the zoom level changes the text size, or if %TRUE, scales all + * elements in the page. + * + * Since: 1.0.1 + */ +void webkit_web_view_set_zoom_level(WebKitWebView* webView, gfloat zoomLevel) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + webkit_web_view_apply_zoom_level(webView, zoomLevel); + g_object_notify(G_OBJECT(webView), "zoom-level"); +} + +/** + * webkit_web_view_zoom_in: + * @webView: a #WebKitWebView + * + * Increases the zoom level of @web_view. The current zoom + * level is incremented by the value of the "zoom-step" + * property of the #WebKitWebSettings associated with @web_view. + * + * Since: 1.0.1 + */ +void webkit_web_view_zoom_in(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + WebKitWebViewPrivate* priv = webView->priv; + gfloat zoomMultiplierRatio; + g_object_get(priv->webSettings.get(), "zoom-step", &zoomMultiplierRatio, NULL); + + webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) + zoomMultiplierRatio); +} + +/** + * webkit_web_view_zoom_out: + * @webView: a #WebKitWebView + * + * Decreases the zoom level of @web_view. The current zoom + * level is decremented by the value of the "zoom-step" + * property of the #WebKitWebSettings associated with @web_view. + * + * Since: 1.0.1 + */ +void webkit_web_view_zoom_out(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + WebKitWebViewPrivate* priv = webView->priv; + gfloat zoomMultiplierRatio; + g_object_get(priv->webSettings.get(), "zoom-step", &zoomMultiplierRatio, NULL); + + webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) - zoomMultiplierRatio); +} + +/** + * webkit_web_view_get_full_content_zoom: + * @webView: a #WebKitWebView + * + * Returns whether the zoom level affects only text or all elements. + * + * Return value: %FALSE if only text should be scaled (the default), + * %TRUE if the full content of the view should be scaled. + * + * Since: 1.0.1 + */ +gboolean webkit_web_view_get_full_content_zoom(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + WebKitWebViewPrivate* priv = webView->priv; + return priv->zoomFullContent; +} + +/** + * webkit_web_view_set_full_content_zoom: + * @webView: a #WebKitWebView + * @full_content_zoom: %FALSE if only text should be scaled (the default), + * %TRUE if the full content of the view should be scaled. + * + * Sets whether the zoom level affects only text or all elements. + * + * Since: 1.0.1 + */ +void webkit_web_view_set_full_content_zoom(WebKitWebView* webView, gboolean zoomFullContent) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + WebKitWebViewPrivate* priv = webView->priv; + if (priv->zoomFullContent == zoomFullContent) + return; + + Frame* frame = core(webView)->mainFrame(); + if (!frame) + return; + + gfloat zoomLevel = priv->zoomFullContent ? frame->pageZoomFactor() : frame->textZoomFactor(); + + priv->zoomFullContent = zoomFullContent; + if (priv->zoomFullContent) + frame->setPageAndTextZoomFactors(zoomLevel, 1); + else + frame->setPageAndTextZoomFactors(1, zoomLevel); + + g_object_notify(G_OBJECT(webView), "full-content-zoom"); +} + +/** + * webkit_web_view_get_load_status: + * @webView: a #WebKitWebView + * + * Determines the current status of the load. + * + * Since: 1.1.7 + */ +WebKitLoadStatus webkit_web_view_get_load_status(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), WEBKIT_LOAD_FINISHED); + + WebKitWebViewPrivate* priv = webView->priv; + return priv->loadStatus; +} + +/** + * webkit_web_view_get_progress: + * @webView: a #WebKitWebView + * + * Determines the current progress of the load. + * + * Since: 1.1.7 + */ +gdouble webkit_web_view_get_progress(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1.0); + + return core(webView)->progress()->estimatedProgress(); +} + +/** + * webkit_web_view_get_encoding: + * @webView: a #WebKitWebView + * + * Returns the default encoding of the #WebKitWebView. + * + * Return value: the default encoding + * + * Since: 1.1.1 + */ +const gchar* webkit_web_view_get_encoding(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + String encoding = core(webView)->mainFrame()->document()->loader()->writer()->encoding(); + if (encoding.isEmpty()) + return 0; + webView->priv->encoding = encoding.utf8(); + return webView->priv->encoding.data(); +} + +/** + * webkit_web_view_set_custom_encoding: + * @webView: a #WebKitWebView + * @encoding: the new encoding, or %NULL to restore the default encoding + * + * Sets the current #WebKitWebView encoding, without modifying the default one, + * and reloads the page. + * + * Since: 1.1.1 + */ +void webkit_web_view_set_custom_encoding(WebKitWebView* webView, const char* encoding) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + core(webView)->mainFrame()->loader()->reloadWithOverrideEncoding(String::fromUTF8(encoding)); +} + +/** + * webkit_web_view_get_custom_encoding: + * @webView: a #WebKitWebView + * + * Returns the current encoding of the #WebKitWebView, not the default-encoding + * of WebKitWebSettings. + * + * Return value: a string containing the current custom encoding for @web_view, or %NULL if there's none set. + * + * Since: 1.1.1 + */ +const char* webkit_web_view_get_custom_encoding(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + String overrideEncoding = core(webView)->mainFrame()->loader()->documentLoader()->overrideEncoding(); + if (overrideEncoding.isEmpty()) + return 0; + webView->priv->customEncoding = overrideEncoding.utf8(); + return webView->priv->customEncoding.data(); +} + +/** + * webkit_web_view_set_view_mode: + * @webView: the #WebKitWebView that will have its view mode set + * @mode: the %WebKitWebViewViewMode to be set + * + * Sets the view-mode property of the #WebKitWebView. Check the + * property's documentation for more information. + * + * Since: 1.3.4 + */ +void webkit_web_view_set_view_mode(WebKitWebView* webView, WebKitWebViewViewMode mode) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + Page* page = core(webView); + + switch (mode) { + case WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING: + page->setViewMode(Page::ViewModeFloating); + break; + case WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN: + page->setViewMode(Page::ViewModeFullscreen); + break; + case WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED: + page->setViewMode(Page::ViewModeMaximized); + break; + case WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED: + page->setViewMode(Page::ViewModeMinimized); + break; + default: + page->setViewMode(Page::ViewModeWindowed); + break; + } +} + +/** + * webkit_web_view_get_view_mode: + * @webView: the #WebKitWebView to obtain the view mode from + * + * Gets the value of the view-mode property of the + * #WebKitWebView. Check the property's documentation for more + * information. + * + * Return value: the %WebKitWebViewViewMode currently set for the + * #WebKitWebView. + * + * Since: 1.3.4 + */ +WebKitWebViewViewMode webkit_web_view_get_view_mode(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED); + + Page* page = core(webView); + Page::ViewMode mode = page->viewMode(); + + if (mode == Page::ViewModeFloating) + return WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING; + + if (mode == Page::ViewModeFullscreen) + return WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN; + + if (mode == Page::ViewModeMaximized) + return WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED; + + if (mode == Page::ViewModeMinimized) + return WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED; + + return WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED; +} + +/** + * webkit_web_view_move_cursor: + * @webView: a #WebKitWebView + * @step: a #GtkMovementStep + * @count: integer describing the direction of the movement. 1 for forward, -1 for backwards. + * + * Move the cursor in @view as described by @step and @count. + * + * Since: 1.1.4 + */ +void webkit_web_view_move_cursor(WebKitWebView* webView, GtkMovementStep step, gint count) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(step == GTK_MOVEMENT_VISUAL_POSITIONS || + step == GTK_MOVEMENT_DISPLAY_LINES || + step == GTK_MOVEMENT_PAGES || + step == GTK_MOVEMENT_BUFFER_ENDS); + g_return_if_fail(count == 1 || count == -1); + + gboolean handled; + g_signal_emit(webView, webkit_web_view_signals[MOVE_CURSOR], 0, step, count, &handled); +} + +/** + * webkit_web_view_can_undo: + * @webView: a #WebKitWebView + * + * Determines whether or not it is currently possible to undo the last + * editing command in the view. + * + * Return value: %TRUE if a undo can be done, %FALSE if not + * + * Since: 1.1.14 + */ +gboolean webkit_web_view_can_undo(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return frame->editor()->canUndo(); +} + +/** + * webkit_web_view_undo: + * @webView: a #WebKitWebView + * + * Undoes the last editing command in the view, if possible. + * + * Since: 1.1.14 + */ +void webkit_web_view_undo(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (webkit_web_view_can_undo(webView)) + g_signal_emit(webView, webkit_web_view_signals[UNDO], 0); +} + +/** + * webkit_web_view_can_redo: + * @webView: a #WebKitWebView + * + * Determines whether or not it is currently possible to redo the last + * editing command in the view. + * + * Return value: %TRUE if a redo can be done, %FALSE if not + * + * Since: 1.1.14 + */ +gboolean webkit_web_view_can_redo(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + return frame->editor()->canRedo(); +} + +/** + * webkit_web_view_redo: + * @webView: a #WebKitWebView + * + * Redoes the last editing command in the view, if possible. + * + * Since: 1.1.14 + */ +void webkit_web_view_redo(WebKitWebView* webView) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (webkit_web_view_can_redo(webView)) + g_signal_emit(webView, webkit_web_view_signals[REDO], 0); +} + + +/** + * webkit_web_view_set_view_source_mode: + * @webView: a #WebKitWebView + * @view_source_mode: the mode to turn on or off view source mode + * + * Set whether the view should be in view source mode. Setting this mode to + * %TRUE before loading a URI will display the source of the web page in a + * nice and readable format. + * + * Since: 1.1.14 + */ +void webkit_web_view_set_view_source_mode (WebKitWebView* webView, gboolean mode) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + + if (Frame* mainFrame = core(webView)->mainFrame()) + mainFrame->setInViewSourceMode(mode); +} + +/** + * webkit_web_view_get_view_source_mode: + * @webView: a #WebKitWebView + * + * Return value: %TRUE if @web_view is in view source mode, %FALSE otherwise. + * + * Since: 1.1.14 + */ +gboolean webkit_web_view_get_view_source_mode (WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); + + if (Frame* mainFrame = core(webView)->mainFrame()) + return mainFrame->inViewSourceMode(); + + return FALSE; +} + +// Internal subresource management +void webkit_web_view_add_main_resource(WebKitWebView* webView, const char* identifier, WebKitWebResource* webResource) +{ + WebKitWebViewPrivate* priv = webView->priv; + + priv->mainResource = adoptGRef(webResource); + priv->mainResourceIdentifier = identifier; +} + +void webkit_web_view_add_resource(WebKitWebView* webView, const char* identifier, WebKitWebResource* webResource) +{ + WebKitWebViewPrivate* priv = webView->priv; + g_hash_table_insert(priv->subResources.get(), g_strdup(identifier), webResource); +} + +void webkit_web_view_remove_resource(WebKitWebView* webView, const char* identifier) +{ + WebKitWebViewPrivate* priv = webView->priv; + if (g_str_equal(identifier, priv->mainResourceIdentifier.data())) { + priv->mainResourceIdentifier = ""; + priv->mainResource = 0; + } else + g_hash_table_remove(priv->subResources.get(), identifier); +} + +WebKitWebResource* webkit_web_view_get_resource(WebKitWebView* webView, char* identifier) +{ + WebKitWebViewPrivate* priv = webView->priv; + gpointer webResource = 0; + gboolean resourceFound = g_hash_table_lookup_extended(priv->subResources.get(), identifier, NULL, &webResource); + + // The only resource we do not store in this hash table is the + // main! If we did not find a request, it probably means the load + // has been interrupted while while a resource was still being + // loaded. + if (!resourceFound && !g_str_equal(identifier, priv->mainResourceIdentifier.data())) + return 0; + + if (!webResource) + return webkit_web_view_get_main_resource(webView); + + return WEBKIT_WEB_RESOURCE(webResource); +} + +WebKitWebResource* webkit_web_view_get_main_resource(WebKitWebView* webView) +{ + return webView->priv->mainResource.get(); +} + +void webkit_web_view_clear_resources(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + + if (priv->subResources) + g_hash_table_remove_all(priv->subResources.get()); +} + +GList* webkit_web_view_get_subresources(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + GList* subResources = g_hash_table_get_values(priv->subResources.get()); + return g_list_remove(subResources, priv->mainResource.get()); +} + +/* From EventHandler.cpp */ +static IntPoint documentPointForWindowPoint(Frame* frame, const IntPoint& windowPoint) +{ + FrameView* view = frame->view(); + // FIXME: Is it really OK to use the wrong coordinates here when view is 0? + // Historically the code would just crash; this is clearly no worse than that. + return view ? view->windowToContents(windowPoint) : windowPoint; +} + +void webkit_web_view_set_tooltip_text(WebKitWebView* webView, const char* tooltip) +{ +#if GTK_CHECK_VERSION(2, 12, 0) + WebKitWebViewPrivate* priv = webView->priv; + if (tooltip && *tooltip != '\0') { + priv->tooltipText = tooltip; + gtk_widget_set_has_tooltip(GTK_WIDGET(webView), TRUE); + } else { + priv->tooltipText = ""; + gtk_widget_set_has_tooltip(GTK_WIDGET(webView), FALSE); + } + + gtk_widget_trigger_tooltip_query(GTK_WIDGET(webView)); +#else + // TODO: Support older GTK+ versions + // See http://bugs.webkit.org/show_bug.cgi?id=15793 + notImplemented(); +#endif +} + +/** + * webkit_web_view_get_hit_test_result: + * @webView: a #WebKitWebView + * @event: a #GdkEventButton + * + * Does a 'hit test' in the coordinates specified by @event to figure + * out context information about that position in the @webView. + * + * Returns: (transfer none): a newly created #WebKitHitTestResult with the context of the + * specified position. + * + * Since: 1.1.15 + **/ +WebKitHitTestResult* webkit_web_view_get_hit_test_result(WebKitWebView* webView, GdkEventButton* event) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL); + g_return_val_if_fail(event, NULL); + + PlatformMouseEvent mouseEvent = PlatformMouseEvent(event); + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + HitTestRequest request(HitTestRequest::Active); + IntPoint documentPoint = documentPointForWindowPoint(frame, mouseEvent.pos()); + MouseEventWithHitTestResults mev = frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent); + + return kit(mev.hitTestResult()); +} + +/** + * webkit_web_view_get_icon_uri: + * @webView: the #WebKitWebView object + * + * Obtains the URI for the favicon for the given #WebKitWebView, or + * %NULL if there is none. + * + * Return value: the URI for the favicon, or %NULL + * + * Since: 1.1.18 + */ +G_CONST_RETURN gchar* webkit_web_view_get_icon_uri(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + String iconURL = iconDatabase().synchronousIconURLForPageURL(core(webView)->mainFrame()->document()->url().prettyURL()); + webView->priv->iconURI = iconURL.utf8(); + return webView->priv->iconURI.data(); +} + +/** + * webkit_web_view_get_icon_pixbuf: + * @webView: the #WebKitWebView object + * + * Obtains a #GdkPixbuf of the favicon for the given #WebKitWebView, or + * a default icon if there is no icon for the given page. Use + * webkit_web_view_get_icon_uri() if you need to distinguish these cases. + * Usually you want to connect to WebKitWebView::icon-loaded and call this + * method in the callback. + * + * The pixbuf will have the largest size provided by the server and should + * be resized before it is displayed. + * See also webkit_icon_database_get_icon_pixbuf(). + * + * Returns: (transfer full): a new reference to a #GdkPixbuf, or %NULL + * + * Since: 1.3.13 + */ +GdkPixbuf* webkit_web_view_get_icon_pixbuf(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + const gchar* pageURI = webkit_web_view_get_uri(webView); + WebKitIconDatabase* database = webkit_get_icon_database(); + return webkit_icon_database_get_icon_pixbuf(database, pageURI); +} + + + +/** + * webkit_web_view_get_dom_document: + * @webView: a #WebKitWebView + * + * Returns: (transfer none): the #WebKitDOMDocument currently loaded in the @webView + * + * Since: 1.3.1 + **/ +WebKitDOMDocument* +webkit_web_view_get_dom_document(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + Frame* coreFrame = core(webView)->mainFrame(); + if (!coreFrame) + return 0; + + Document* doc = coreFrame->document(); + if (!doc) + return 0; + + return kit(doc); +} + +GtkMenu* webkit_web_view_get_context_menu(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + +#if ENABLE(CONTEXT_MENUS) + ContextMenu* menu = core(webView)->contextMenuController()->contextMenu(); + if (!menu) + return 0; + return menu->platformDescription(); +#else + return 0; +#endif +} + +void webViewEnterFullscreen(WebKitWebView* webView, Node* node) +{ + if (!node->hasTagName(HTMLNames::videoTag)) + return; + +#if ENABLE(VIDEO) + HTMLMediaElement* videoElement = static_cast<HTMLMediaElement*>(node); + WebKitWebViewPrivate* priv = webView->priv; + + // First exit Fullscreen for the old mediaElement. + if (priv->fullscreenVideoController) + priv->fullscreenVideoController->exitFullscreen(); + + priv->fullscreenVideoController = new FullscreenVideoController; + priv->fullscreenVideoController->setMediaElement(videoElement); + priv->fullscreenVideoController->enterFullscreen(); +#endif +} + +void webViewExitFullscreen(WebKitWebView* webView) +{ +#if ENABLE(VIDEO) + WebKitWebViewPrivate* priv = webView->priv; + if (priv->fullscreenVideoController) + priv->fullscreenVideoController->exitFullscreen(); +#endif +} + +namespace WebKit { + +WebCore::Page* core(WebKitWebView* webView) +{ + if (!webView) + return 0; + + WebKitWebViewPrivate* priv = webView->priv; + return priv ? priv->corePage : 0; +} + +WebKitWebView* kit(WebCore::Page* corePage) +{ + if (!corePage) + return 0; + + ASSERT(corePage->chrome()); + WebKit::ChromeClient* client = static_cast<WebKit::ChromeClient*>(corePage->chrome()->client()); + return client ? client->webView() : 0; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebview.h b/Source/WebKit/gtk/webkit/webkitwebview.h new file mode 100644 index 0000000..38c9a70 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebview.h @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com> + * Copyright (C) 2008 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebview_h +#define webkitwebview_h + +#include <gtk/gtk.h> +#include <libsoup/soup.h> +#include <JavaScriptCore/JSBase.h> + +#include <webkit/webkitdefines.h> +#include <webkit/webkitdom.h> +#include <webkit/webkitwebbackforwardlist.h> +#include <webkit/webkitwebframe.h> +#include <webkit/webkitwebhistoryitem.h> +#include <webkit/webkitwebsettings.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_VIEW (webkit_web_view_get_type()) +#define WEBKIT_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView)) +#define WEBKIT_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) +#define WEBKIT_IS_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW)) +#define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_VIEW)) +#define WEBKIT_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass)) + +typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate; + +typedef enum { + WEBKIT_NAVIGATION_RESPONSE_ACCEPT, + WEBKIT_NAVIGATION_RESPONSE_IGNORE, + WEBKIT_NAVIGATION_RESPONSE_DOWNLOAD +} WebKitNavigationResponse; + +typedef enum +{ + WEBKIT_WEB_VIEW_TARGET_INFO_HTML, + WEBKIT_WEB_VIEW_TARGET_INFO_TEXT, + WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE, + WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST, + WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL +} WebKitWebViewTargetInfo; + +typedef enum +{ + WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED, + WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING, + WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN, + WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED, + WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED +} WebKitWebViewViewMode; + +typedef enum +{ + WEBKIT_SELECTION_AFFINITY_UPSTREAM, + WEBKIT_SELECTION_AFFINITY_DOWNSTREAM, +} WebKitSelectionAffinity; + +typedef enum +{ + WEBKIT_INSERT_ACTION_TYPED, + WEBKIT_INSERT_ACTION_PASTED, + WEBKIT_INSERT_ACTION_DROPPED, +} WebKitInsertAction; + +struct _WebKitWebView { + GtkContainer parent_instance; + + /*< private >*/ + WebKitWebViewPrivate *priv; +}; + +struct _WebKitWebViewClass { + GtkContainerClass parent_class; + + /*< public >*/ + /* + * default handler/virtual methods + */ + WebKitWebView * (* create_web_view) (WebKitWebView *web_view, + WebKitWebFrame *web_frame); + + gboolean (* web_view_ready) (WebKitWebView* web_view); + + gboolean (* close_web_view) (WebKitWebView* web_view); + + WebKitNavigationResponse (* navigation_requested) (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request); + void (* window_object_cleared) (WebKitWebView *web_view, + WebKitWebFrame *frame, + JSGlobalContextRef context, + JSObjectRef window_object); + gchar * (* choose_file) (WebKitWebView *web_view, + WebKitWebFrame *frame, + const gchar *old_file); + gboolean (* script_alert) (WebKitWebView *web_view, + WebKitWebFrame *frame, + const gchar *alert_message); + gboolean (* script_confirm) (WebKitWebView *web_view, + WebKitWebFrame *frame, + const gchar *confirm_message, + gboolean *did_confirm); + gboolean (* script_prompt) (WebKitWebView *web_view, + WebKitWebFrame *frame, + const gchar *message, + const gchar *default_value, + gchar* *value); + gboolean (* console_message) (WebKitWebView *web_view, + const gchar *message, + guint line_number, + const gchar* source_id); + void (* select_all) (WebKitWebView *web_view); + void (* cut_clipboard) (WebKitWebView *web_view); + void (* copy_clipboard) (WebKitWebView *web_view); + void (* paste_clipboard) (WebKitWebView *web_view); + gboolean (* move_cursor) (WebKitWebView *web_view, + GtkMovementStep step, + gint count); + + /* + * internal + */ + void (* set_scroll_adjustments) (WebKitWebView *web_view, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); + + void (* undo) (WebKitWebView *web_view); + void (* redo) (WebKitWebView *web_view); + gboolean (* should_allow_editing_action) (WebKitWebView *web_view); + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); +}; + +WEBKIT_API GType +webkit_web_view_get_type (void); + +WEBKIT_API GtkWidget * +webkit_web_view_new (void); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_view_get_title (WebKitWebView *webView); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_view_get_uri (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_maintains_back_forward_list (WebKitWebView *webView, + gboolean flag); + +WEBKIT_API WebKitWebBackForwardList * +webkit_web_view_get_back_forward_list (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_go_to_back_forward_item (WebKitWebView *webView, + WebKitWebHistoryItem *item); + +WEBKIT_API gboolean +webkit_web_view_can_go_back (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_go_back_or_forward (WebKitWebView *webView, + gint steps); + +WEBKIT_API gboolean +webkit_web_view_can_go_forward (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_go_back (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_go_back_or_forward (WebKitWebView *webView, + gint steps); + +WEBKIT_API void +webkit_web_view_go_forward (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_stop_loading (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_open (WebKitWebView *webView, + const gchar *uri); + +WEBKIT_API void +webkit_web_view_reload (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_reload_bypass_cache (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_load_uri (WebKitWebView *webView, + const gchar *uri); + +WEBKIT_API void +webkit_web_view_load_string (WebKitWebView *webView, + const gchar *content, + const gchar *mime_type, + const gchar *encoding, + const gchar *base_uri); + +WEBKIT_API void +webkit_web_view_load_html_string (WebKitWebView *webView, + const gchar *content, + const gchar *base_uri); + +WEBKIT_API void +webkit_web_view_load_request (WebKitWebView *webView, + WebKitNetworkRequest *request); + +WEBKIT_API gboolean +webkit_web_view_search_text (WebKitWebView *webView, + const gchar *text, + gboolean case_sensitive, + gboolean forward, + gboolean wrap); + +WEBKIT_API guint +webkit_web_view_mark_text_matches (WebKitWebView *webView, + const gchar *string, + gboolean case_sensitive, + guint limit); + +WEBKIT_API void +webkit_web_view_set_highlight_text_matches (WebKitWebView *webView, + gboolean highlight); + +WEBKIT_API void +webkit_web_view_unmark_text_matches (WebKitWebView *webView); + +WEBKIT_API WebKitWebFrame * +webkit_web_view_get_main_frame (WebKitWebView *webView); + +WEBKIT_API WebKitWebFrame * +webkit_web_view_get_focused_frame (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_execute_script (WebKitWebView *webView, + const gchar *script); + +WEBKIT_API gboolean +webkit_web_view_can_cut_clipboard (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_copy_clipboard (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_paste_clipboard (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_cut_clipboard (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_copy_clipboard (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_paste_clipboard (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_delete_selection (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_has_selection (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_select_all (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_get_editable (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_editable (WebKitWebView *webView, + gboolean flag); + +WEBKIT_API GtkTargetList * +webkit_web_view_get_copy_target_list (WebKitWebView *webView); + +WEBKIT_API GtkTargetList * +webkit_web_view_get_paste_target_list (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_settings (WebKitWebView *webView, + WebKitWebSettings *settings); + +WEBKIT_API WebKitWebSettings * +webkit_web_view_get_settings (WebKitWebView *webView); + +WEBKIT_API WebKitWebInspector * +webkit_web_view_get_inspector (WebKitWebView *webView); + +WEBKIT_API WebKitWebWindowFeatures* +webkit_web_view_get_window_features (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_show_mime_type (WebKitWebView *webView, + const gchar *mime_type); + +WEBKIT_API gboolean +webkit_web_view_get_transparent (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_transparent (WebKitWebView *webView, + gboolean flag); + +WEBKIT_API gfloat +webkit_web_view_get_zoom_level (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_zoom_level (WebKitWebView *webView, + gfloat zoom_level); + +WEBKIT_API void +webkit_web_view_zoom_in (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_zoom_out (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_get_full_content_zoom (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_full_content_zoom (WebKitWebView *webView, + gboolean full_content_zoom); + +WEBKIT_API const gchar* +webkit_web_view_get_encoding (WebKitWebView * webView); + +WEBKIT_API void +webkit_web_view_set_custom_encoding (WebKitWebView * webView, + const gchar * encoding); + +WEBKIT_API const char* +webkit_web_view_get_custom_encoding (WebKitWebView * webView); + +WEBKIT_API void +webkit_web_view_set_view_mode (WebKitWebView *webView, + WebKitWebViewViewMode mode); + +WEBKIT_API WebKitWebViewViewMode +webkit_web_view_get_view_mode (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_move_cursor (WebKitWebView * webView, + GtkMovementStep step, + gint count); + +WEBKIT_API WebKitLoadStatus +webkit_web_view_get_load_status (WebKitWebView *webView); + +WEBKIT_API gdouble +webkit_web_view_get_progress (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_undo (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_undo (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_redo (WebKitWebView *webView); + +WEBKIT_API gboolean +webkit_web_view_can_redo (WebKitWebView *webView); + +WEBKIT_API void +webkit_web_view_set_view_source_mode (WebKitWebView *webView, + gboolean view_source_mode); + +WEBKIT_API gboolean +webkit_web_view_get_view_source_mode (WebKitWebView *webView); + +WEBKIT_API WebKitHitTestResult* +webkit_web_view_get_hit_test_result (WebKitWebView *webView, + GdkEventButton *event); + +WEBKIT_API G_CONST_RETURN gchar * +webkit_web_view_get_icon_uri (WebKitWebView *webView); + +WEBKIT_API GdkPixbuf * +webkit_web_view_get_icon_pixbuf (WebKitWebView *webView); + +WEBKIT_API WebKitDOMDocument * +webkit_web_view_get_dom_document (WebKitWebView *webView); + +WEBKIT_API WebKitViewportAttributes* +webkit_web_view_get_viewport_attributes (WebKitWebView *webView); + +G_END_DECLS + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebviewprivate.h b/Source/WebKit/gtk/webkit/webkitwebviewprivate.h new file mode 100644 index 0000000..a355a53 --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebviewprivate.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008, 2010 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebviewprivate_h +#define webkitwebviewprivate_h + +#include "DataObjectGtk.h" +#include "FullscreenVideoController.h" +#include "GOwnPtr.h" +#include "ResourceHandle.h" +#include <webkit/webkitwebview.h> + +namespace WebKit { + +WebCore::Page* core(WebKitWebView*); +WebKitWebView* kit(WebCore::Page*); + + +typedef struct DroppingContext_ { + WebKitWebView* webView; + GdkDragContext* gdkContext; + RefPtr<WebCore::DataObjectGtk> dataObject; + WebCore::IntPoint lastMotionPosition; + int pendingDataRequests; + bool dropHappened; +} DroppingContext; + +} + +extern "C" { + +#define WEBKIT_WEB_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewPrivate)) +typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate; +struct _WebKitWebViewPrivate { + WebCore::Page* corePage; + GRefPtr<WebKitWebSettings> webSettings; + GRefPtr<WebKitWebInspector> webInspector; + GRefPtr<WebKitViewportAttributes> viewportAttributes; + GRefPtr<WebKitWebWindowFeatures> webWindowFeatures; + + WebKitWebFrame* mainFrame; + GRefPtr<WebKitWebBackForwardList> backForwardList; + + GtkMenu* currentMenu; + gint lastPopupXPosition; + gint lastPopupYPosition; + + HashSet<GtkWidget*> children; + GRefPtr<GtkIMContext> imContext; + + gboolean transparent; + + GRefPtr<GtkAdjustment> horizontalAdjustment; + GRefPtr<GtkAdjustment> verticalAdjustment; + +#ifndef GTK_API_VERSION_2 + // GtkScrollablePolicy needs to be checked when + // driving the scrollable adjustment values + GtkScrollablePolicy horizontalScrollingPolicy; + GtkScrollablePolicy verticalScrollingPolicy; +#endif + + gboolean zoomFullContent; + WebKitLoadStatus loadStatus; + CString encoding; + CString customEncoding; + + CString iconURI; + + gboolean disposing; + gboolean usePrimaryForPaste; + +#if ENABLE(VIDEO) + FullscreenVideoController* fullscreenVideoController; +#endif + + // These are hosted here because the DataSource object is + // created too late in the frame loading process. + GRefPtr<WebKitWebResource> mainResource; + CString mainResourceIdentifier; + GRefPtr<GHashTable> subResources; + CString tooltipText; + WebCore::IntRect tooltipArea; + + int currentClickCount; + WebCore::IntPoint previousClickPoint; + guint previousClickButton; + guint32 previousClickTime; + HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk> > draggingDataObjects; + HashMap<GdkDragContext*, WebKit::DroppingContext*> droppingContexts; +}; + +void webkit_web_view_notify_ready(WebKitWebView*); + +void webkit_web_view_request_download(WebKitWebView*, WebKitNetworkRequest*, const WebCore::ResourceResponse& = WebCore::ResourceResponse(), WebCore::ResourceHandle* = 0); + +void webkit_web_view_add_resource(WebKitWebView*, const char*, WebKitWebResource*); +void webkit_web_view_add_main_resource(WebKitWebView*, const char*, WebKitWebResource*); +void webkit_web_view_remove_resource(WebKitWebView*, const char*); +WebKitWebResource* webkit_web_view_get_resource(WebKitWebView*, char*); +WebKitWebResource* webkit_web_view_get_main_resource(WebKitWebView*); +void webkit_web_view_clear_resources(WebKitWebView*); +GList* webkit_web_view_get_subresources(WebKitWebView*); + +void webkit_web_view_set_tooltip_text(WebKitWebView*, const char*); +GtkMenu* webkit_web_view_get_context_menu(WebKitWebView*); + +WEBKIT_API gchar* webkit_web_view_get_selected_text(WebKitWebView*); +bool webkit_web_view_use_primary_for_paste(WebKitWebView*); + +void webViewEnterFullscreen(WebKitWebView* webView, WebCore::Node*); +void webViewExitFullscreen(WebKitWebView* webView); + +} + +#endif diff --git a/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.cpp b/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.cpp new file mode 100644 index 0000000..93e08ac --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.cpp @@ -0,0 +1,449 @@ +/* + * Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org> + * Copyright (C) 2008 Holger Hans Peter Freyther + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "webkitwebwindowfeatures.h" + +#include "WindowFeatures.h" +#include "webkitglobalsprivate.h" +#include "webkitwebwindowfeaturesprivate.h" + +/** + * SECTION:webkitwebwindowfeatures + * @short_description: Window properties of a #WebKitWebView + * @see_also: #WebKitWebView::web-view-ready + * + * The content of a #WebKitWebView can request to change certain + * properties of a #WebKitWebView. This can include the x, y position + * of the window, the width and height but also if a toolbar, + * scrollbar, statusbar, locationbar should be visible to the user, + * the request to show the #WebKitWebView fullscreen. + * + * In the normal case one will use #webkit_web_view_get_window_features + * to get the #WebKitWebWindowFeatures and then monitor the property + * changes. Be aware that the #WebKitWebWindowFeatures might change + * before #WebKitWebView::web-view-ready signal is emitted. + * To be safe listen to the notify::window-features signal of the #WebKitWebView + * and reconnect the signals whenever the #WebKitWebWindowFeatures of + * a #WebKitWebView changes. + * + * <informalexample><programlisting> + * /<!-- -->* Get the current WebKitWebWindowFeatures *<!-- -->/ + * WebKitWebWindowFeatures *features = webkit_web_view_get_window_features (my_webview); + * + * /<!-- -->* Connect to the property changes *<!-- -->/ + * g_signal_connect (G_OBJECT(features), "notify::menubar-visible", G_CALLBACK(make_menu_bar_visible), NULL); + * g_signal_connect (G_OBJECT(features), "notify::statusbar-visible", G_CALLBACK(make_status_bar_visible), NULL); + * + * </programlisting></informalexample> + */ + +enum { + PROP_0, + + PROP_X, + PROP_Y, + PROP_WIDTH, + PROP_HEIGHT, + PROP_TOOLBAR_VISIBLE, + PROP_STATUSBAR_VISIBLE, + PROP_SCROLLBAR_VISIBLE, + PROP_MENUBAR_VISIBLE, + PROP_LOCATIONBAR_VISIBLE, + PROP_FULLSCREEN, +}; + +G_DEFINE_TYPE(WebKitWebWindowFeatures, webkit_web_window_features, G_TYPE_OBJECT) + +struct _WebKitWebWindowFeaturesPrivate { + gint x; + gint y; + gint width; + gint height; + + gboolean toolbar_visible; + gboolean statusbar_visible; + gboolean scrollbar_visible; + gboolean menubar_visible; + gboolean locationbar_visible; + + gboolean fullscreen; +}; + +#define WEBKIT_WEB_WINDOW_FEATURES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate)) + +static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); + +static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); + +static void webkit_web_window_features_class_init(WebKitWebWindowFeaturesClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + gobject_class->set_property = webkit_web_window_features_set_property; + gobject_class->get_property = webkit_web_window_features_get_property; + + GParamFlags flags = (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT); + + webkitInit(); + + /** + * WebKitWebWindowFeatures:x: + * + * The starting x position of the window on the screen. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_X, + g_param_spec_int( + "x", + "x", + "The starting x position of the window on the screen.", + -1, + G_MAXINT, + -1, + flags)); + + /** + * WebKitWebWindowFeatures:y: + * + * The starting y position of the window on the screen. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_Y, + g_param_spec_int( + "y", + "y", + "The starting y position of the window on the screen.", + -1, + G_MAXINT, + -1, + flags)); + + /** + * WebKitWebWindowFeatures:width: + * + * The width of the window on the screen. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_WIDTH, + g_param_spec_int( + "width", + "Width", + "The width of the window on the screen.", + -1, + G_MAXINT, + -1, + flags)); + + /** + * WebKitWebWindowFeatures:height: + * + * The height of the window on the screen. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_HEIGHT, + g_param_spec_int( + "height", + "Height", + "The height of the window on the screen.", + -1, + G_MAXINT, + -1, + flags)); + + /** + * WebKitWebWindowFeatures:toolbar-visible: + * + * Controls whether the toolbar should be visible for the window. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_TOOLBAR_VISIBLE, + g_param_spec_boolean( + "toolbar-visible", + "Toolbar Visible", + "Controls whether the toolbar should be visible for the window.", + TRUE, + flags)); + + /** + * WebKitWebWindowFeatures:statusbar-visible: + * + * Controls whether the statusbar should be visible for the window. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_STATUSBAR_VISIBLE, + g_param_spec_boolean( + "statusbar-visible", + "Statusbar Visible", + "Controls whether the statusbar should be visible for the window.", + TRUE, + flags)); + + /** + * WebKitWebWindowFeatures:scrollbar-visible: + * + * Controls whether the scrollbars should be visible for the window. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_SCROLLBAR_VISIBLE, + g_param_spec_boolean( + "scrollbar-visible", + "Scrollbar Visible", + "Controls whether the scrollbars should be visible for the window.", + TRUE, + flags)); + + /** + * WebKitWebWindowFeatures:menubar-visible: + * + * Controls whether the menubar should be visible for the window. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_MENUBAR_VISIBLE, + g_param_spec_boolean( + "menubar-visible", + "Menubar Visible", + "Controls whether the menubar should be visible for the window.", + TRUE, + flags)); + + /** + * WebKitWebWindowFeatures:locationbar-visible: + * + * Controls whether the locationbar should be visible for the window. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_LOCATIONBAR_VISIBLE, + g_param_spec_boolean( + "locationbar-visible", + "Locationbar Visible", + "Controls whether the locationbar should be visible for the window.", + TRUE, + flags)); + + /** + * WebKitWebWindowFeatures:fullscreen: + * + * Controls whether window will be displayed fullscreen. + * + * Since: 1.0.3 + */ + g_object_class_install_property(gobject_class, + PROP_FULLSCREEN, + g_param_spec_boolean( + "fullscreen", + "Fullscreen", + "Controls whether window will be displayed fullscreen.", + FALSE, + flags)); + + + g_type_class_add_private(klass, sizeof(WebKitWebWindowFeaturesPrivate)); +} + +static void webkit_web_window_features_init(WebKitWebWindowFeatures* web_window_features) +{ + web_window_features->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_window_features, WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesPrivate); +} + +static void webkit_web_window_features_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) +{ + WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object); + WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv; + + switch(prop_id) { + case PROP_X: + priv->x = g_value_get_int(value); + break; + case PROP_Y: + priv->y = g_value_get_int(value); + break; + case PROP_WIDTH: + priv->width = g_value_get_int(value); + break; + case PROP_HEIGHT: + priv->height = g_value_get_int(value); + break; + case PROP_TOOLBAR_VISIBLE: + priv->toolbar_visible = g_value_get_boolean(value); + break; + case PROP_STATUSBAR_VISIBLE: + priv->statusbar_visible = g_value_get_boolean(value); + break; + case PROP_SCROLLBAR_VISIBLE: + priv->scrollbar_visible = g_value_get_boolean(value); + break; + case PROP_MENUBAR_VISIBLE: + priv->menubar_visible = g_value_get_boolean(value); + break; + case PROP_LOCATIONBAR_VISIBLE: + priv->locationbar_visible = g_value_get_boolean(value); + break; + case PROP_FULLSCREEN: + priv->fullscreen = g_value_get_boolean(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void webkit_web_window_features_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +{ + WebKitWebWindowFeatures* web_window_features = WEBKIT_WEB_WINDOW_FEATURES(object); + WebKitWebWindowFeaturesPrivate* priv = web_window_features->priv; + + switch (prop_id) { + case PROP_X: + g_value_set_int(value, priv->x); + break; + case PROP_Y: + g_value_set_int(value, priv->y); + break; + case PROP_WIDTH: + g_value_set_int(value, priv->width); + break; + case PROP_HEIGHT: + g_value_set_int(value, priv->height); + break; + case PROP_TOOLBAR_VISIBLE: + g_value_set_boolean(value, priv->toolbar_visible); + break; + case PROP_STATUSBAR_VISIBLE: + g_value_set_boolean(value, priv->statusbar_visible); + break; + case PROP_SCROLLBAR_VISIBLE: + g_value_set_boolean(value, priv->scrollbar_visible); + break; + case PROP_MENUBAR_VISIBLE: + g_value_set_boolean(value, priv->menubar_visible); + break; + case PROP_LOCATIONBAR_VISIBLE: + g_value_set_boolean(value, priv->locationbar_visible); + break; + case PROP_FULLSCREEN: + g_value_set_boolean(value, priv->fullscreen); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +/** + * webkit_web_window_features_new: + * + * Creates a new #WebKitWebWindowFeatures instance with default values. It must + * be manually attached to a WebView. + * + * Returns: a new #WebKitWebWindowFeatures instance + * + * Since: 1.0.3 + */ +WebKitWebWindowFeatures* webkit_web_window_features_new() +{ + return WEBKIT_WEB_WINDOW_FEATURES(g_object_new(WEBKIT_TYPE_WEB_WINDOW_FEATURES, NULL)); +} + +/** + * webkit_web_window_features_equal: + * @features1: a #WebKitWebWindowFeatures instance + * @features2: another #WebKitWebWindowFeatures instance + * + * Decides if a #WebKitWebWindowFeatures instance equals another, as + * in has the same values. + * + * Returns: %TRUE if the instances have the same values, %FALSE + * otherwise + * + * Since: 1.0.3 + */ +gboolean webkit_web_window_features_equal(WebKitWebWindowFeatures* features1, WebKitWebWindowFeatures* features2) +{ + if (features1 == features2) + return TRUE; + if (!features1 || !features2) + return FALSE; + + WebKitWebWindowFeaturesPrivate* priv1 = features1->priv; + WebKitWebWindowFeaturesPrivate* priv2 = features2->priv; + + if ((priv1->x == priv2->x) + && (priv1->y == priv2->y) + && (priv1->width == priv2->width) + && (priv1->height == priv2->height) + && (priv1->toolbar_visible == priv2->toolbar_visible) + && (priv1->statusbar_visible == priv2->statusbar_visible) + && (priv1->scrollbar_visible == priv2->scrollbar_visible) + && (priv1->menubar_visible == priv2->menubar_visible) + && (priv1->locationbar_visible == priv2->locationbar_visible) + && (priv1->fullscreen == priv2->fullscreen)) + return TRUE; + return FALSE; +} + +namespace WebKit { + +WebKitWebWindowFeatures* kitNew(const WebCore::WindowFeatures& features) +{ + WebKitWebWindowFeatures *webWindowFeatures = webkit_web_window_features_new(); + + if(features.xSet) + g_object_set(webWindowFeatures, "x", static_cast<int>(features.x), NULL); + + if(features.ySet) + g_object_set(webWindowFeatures, "y", static_cast<int>(features.y), NULL); + + if(features.widthSet) + g_object_set(webWindowFeatures, "width", static_cast<int>(features.width), NULL); + + if(features.heightSet) + g_object_set(webWindowFeatures, "height", static_cast<int>(features.height), NULL); + + g_object_set(webWindowFeatures, + "toolbar-visible", features.toolBarVisible, + "statusbar-visible", features.statusBarVisible, + "scrollbar-visible", features.scrollbarsVisible, + "menubar-visible", features.menuBarVisible, + "locationbar-visible", features.locationBarVisible, + "fullscreen", features.fullscreen, + NULL); + + return webWindowFeatures; +} + +} diff --git a/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.h b/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.h new file mode 100644 index 0000000..a79119d --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebwindowfeatures.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebwindowfeatures_h +#define webkitwebwindowfeatures_h + +#include <glib-object.h> + +#include <webkit/webkitdefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_WINDOW_FEATURES (webkit_web_window_features_get_type()) +#define WEBKIT_WEB_WINDOW_FEATURES(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeatures)) +#define WEBKIT_WEB_WINDOW_FEATURES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesClass)) +#define WEBKIT_IS_WEB_WINDOW_FEATURES(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES)) +#define WEBKIT_IS_WEB_WINDOW_FEATURES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_WINDOW_FEATURES)) +#define WEBKIT_WEB_WINDOW_FEATURES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_WINDOW_FEATURES, WebKitWebWindowFeaturesClass)) + +typedef struct _WebKitWebWindowFeaturesPrivate WebKitWebWindowFeaturesPrivate; + +struct _WebKitWebWindowFeatures { + GObject parent_instance; + + /*< private >*/ + WebKitWebWindowFeaturesPrivate* priv; +}; + +struct _WebKitWebWindowFeaturesClass { + GObjectClass parent_class; + + /*< private >*/ + /* Padding for future expansion */ + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); + void (*_webkit_reserved4) (void); +}; + +WEBKIT_API GType +webkit_web_window_features_get_type (void); + +WEBKIT_API WebKitWebWindowFeatures* +webkit_web_window_features_new (void); + +WEBKIT_API gboolean +webkit_web_window_features_equal (WebKitWebWindowFeatures* features1, + WebKitWebWindowFeatures* features2); + +G_END_DECLS + +#endif /* webkitwebwindowfeatures_h */ diff --git a/Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h b/Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h new file mode 100644 index 0000000..6ea919b --- /dev/null +++ b/Source/WebKit/gtk/webkit/webkitwebwindowfeaturesprivate.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007, 2008, 2009 Holger Hans Peter Freyther + * Copyright (C) 2008 Jan Michael C. Alonzo + * Copyright (C) 2008 Collabora Ltd. + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef webkitwebwindowfeaturesprivate_h +#define webkitwebwindowfeaturesprivate_h + +#include "webkitwebwindowfeatures.h" + +namespace WebKit { + +WebKitWebWindowFeatures* kitNew(const WebCore::WindowFeatures&); + +} + +#endif |
