2 * Copyright (C) 2007 Holger Hans Peter Freyther
3 * Copyright (C) 2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "webkitprivate.h"
24 #include "ApplicationCacheStorage.h"
26 #include "ChromeClientGtk.h"
28 #include "FrameLoader.h"
29 #include "FrameLoaderClientGtk.h"
30 #include "GtkVersioning.h"
31 #include "HitTestResult.h"
32 #include "IconDatabase.h"
34 #include "PageCache.h"
35 #include "PageGroup.h"
36 #include "Pasteboard.h"
37 #include "PasteboardHelperGtk.h"
38 #include "ResourceHandle.h"
39 #include "ResourceHandleClient.h"
40 #include "ResourceHandleInternal.h"
41 #include "ResourceResponse.h"
42 #include "SecurityOrigin.h"
43 #include "TextEncodingRegistry.h"
44 #include "WebKitDOMBinding.h"
45 #include "webkitnetworkresponse.h"
46 #include "webkitsoupauthdialog.h"
47 #include "webkitversion.h"
49 #include <runtime/InitializeThreading.h>
51 #include <wtf/Threading.h>
54 #include "DatabaseTracker.h"
57 using namespace WebCore;
61 WebKitWebView* getViewFromFrame(WebKitWebFrame* frame)
63 WebKitWebFramePrivate* priv = frame->priv;
67 WebCore::Frame* core(WebKitWebFrame* frame)
72 WebKitWebFramePrivate* priv = frame->priv;
73 return priv ? priv->coreFrame : 0;
76 WebKitWebFrame* kit(WebCore::Frame* coreFrame)
81 ASSERT(coreFrame->loader());
82 WebKit::FrameLoaderClient* client = static_cast<WebKit::FrameLoaderClient*>(coreFrame->loader()->client());
83 return client ? client->webFrame() : 0;
86 WebCore::Page* core(WebKitWebView* webView)
91 WebKitWebViewPrivate* priv = webView->priv;
92 return priv ? priv->corePage : 0;
95 WebKitWebView* kit(WebCore::Page* corePage)
100 ASSERT(corePage->chrome());
101 WebKit::ChromeClient* client = static_cast<WebKit::ChromeClient*>(corePage->chrome()->client());
102 return client ? client->webView() : 0;
105 WebKitWebNavigationReason kit(WebCore::NavigationType type)
107 return (WebKitWebNavigationReason)type;
110 WebCore::NavigationType core(WebKitWebNavigationReason type)
112 return static_cast<WebCore::NavigationType>(type);
115 WebCore::ResourceRequest core(WebKitNetworkRequest* request)
117 SoupMessage* soupMessage = webkit_network_request_get_message(request);
119 return ResourceRequest(soupMessage);
121 KURL url = KURL(KURL(), String::fromUTF8(webkit_network_request_get_uri(request)));
122 return ResourceRequest(url);
125 WebCore::ResourceResponse core(WebKitNetworkResponse* response)
127 SoupMessage* soupMessage = webkit_network_response_get_message(response);
129 return ResourceResponse(soupMessage);
131 return ResourceResponse();
134 WebCore::EditingBehaviorType core(WebKitEditingBehavior type)
136 return (WebCore::EditingBehaviorType)type;
139 WebKitHitTestResult* kit(const WebCore::HitTestResult& result)
141 guint context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
142 GOwnPtr<char> linkURI(0);
143 GOwnPtr<char> imageURI(0);
144 GOwnPtr<char> mediaURI(0);
145 WebKitDOMNode* node = 0;
147 if (!result.absoluteLinkURL().isEmpty()) {
148 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
149 linkURI.set(g_strdup(result.absoluteLinkURL().string().utf8().data()));
152 if (!result.absoluteImageURL().isEmpty()) {
153 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
154 imageURI.set(g_strdup(result.absoluteImageURL().string().utf8().data()));
157 if (!result.absoluteMediaURL().isEmpty()) {
158 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
159 mediaURI.set(g_strdup(result.absoluteMediaURL().string().utf8().data()));
162 if (result.isSelected())
163 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
165 if (result.isContentEditable())
166 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
168 if (result.innerNonSharedNode())
169 node = static_cast<WebKitDOMNode*>(kit(result.innerNonSharedNode()));
171 return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
172 "link-uri", linkURI.get(),
173 "image-uri", imageURI.get(),
174 "media-uri", mediaURI.get(),
180 PasteboardHelperGtk* pasteboardHelperInstance()
182 static PasteboardHelperGtk* helper = new PasteboardHelperGtk();
186 } /** end namespace WebKit */
188 static GtkWidget* currentToplevelCallback(WebKitSoupAuthDialog* feature, SoupMessage* message, gpointer userData)
190 gpointer messageData = g_object_get_data(G_OBJECT(message), "resourceHandle");
194 ResourceHandle* handle = static_cast<ResourceHandle*>(messageData);
198 ResourceHandleInternal* d = handle->getInternal();
202 WebCore::Frame* frame = d->m_frame;
206 GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(frame->page()->chrome()->platformPageClient()));
207 if (gtk_widget_is_toplevel(toplevel))
213 static void closeIconDatabaseOnExit()
215 iconDatabase()->close();
218 #ifdef HAVE_GSETTINGS
219 static bool isSchemaAvailable(const char* schemaID)
221 const char* const* availableSchemas = g_settings_list_schemas();
222 char* const* iter = const_cast<char* const*>(availableSchemas);
225 if (g_str_equal(schemaID, *iter))
233 GSettings* inspectorGSettings()
235 static GSettings* settings = 0;
240 const gchar* schemaID = "org.webkitgtk-"WEBKITGTK_API_VERSION_STRING".inspector";
242 // Unfortunately GSettings will abort the process execution if the
243 // schema is not installed, which is the case for when running
244 // tests, or even the introspection dump at build time, so check
245 // if we have the schema before trying to initialize it.
246 if (!isSchemaAvailable(schemaID)) {
247 g_warning("GSettings schema not found - settings will not be used or saved.");
251 settings = g_settings_new(schemaID);
259 static bool isInitialized = false;
262 isInitialized = true;
264 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
265 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
267 JSC::initializeThreading();
268 WTF::initializeMainThread();
270 WebCore::InitializeLoggingChannelsIfNecessary();
272 // We make sure the text codecs have been initialized, because
273 // that may only be done by the main thread.
274 atomicCanonicalTextEncodingName("UTF-8");
276 // Page cache capacity (in pages). Comment from Mac port:
277 // (Research indicates that value / page drops substantially after 3 pages.)
278 // FIXME: Expose this with an API and/or calculate based on available resources
279 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
281 #ifdef HAVE_GSETTINGS
282 // Initialize settings variables here to make sure this happens in
284 inspectorGSettings();
288 gchar* databaseDirectory = g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL);
289 webkit_set_web_database_directory_path(databaseDirectory);
291 // FIXME: It should be possible for client applications to override the default appcache location
292 WebCore::cacheStorage().setCacheDirectory(databaseDirectory);
293 g_free(databaseDirectory);
296 PageGroup::setShouldTrackVisitedLinks(true);
298 Pasteboard::generalPasteboard()->setHelper(WebKit::pasteboardHelperInstance());
300 iconDatabase()->setEnabled(true);
302 GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_user_data_dir(), "webkit", "icondatabase", NULL));
303 iconDatabase()->open(iconDatabasePath.get());
305 atexit(closeIconDatabaseOnExit);
307 SoupSession* session = webkit_get_default_session();
309 SoupSessionFeature* authDialog = static_cast<SoupSessionFeature*>(g_object_new(WEBKIT_TYPE_SOUP_AUTH_DIALOG, NULL));
310 g_signal_connect(authDialog, "current-toplevel", G_CALLBACK(currentToplevelCallback), NULL);
311 soup_session_add_feature(session, authDialog);
312 g_object_unref(authDialog);
314 SoupSessionFeature* sniffer = static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL));
315 soup_session_add_feature(session, sniffer);
316 g_object_unref(sniffer);
318 soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
321 void webkit_white_list_access_from_origin(const gchar* sourceOrigin, const gchar* destinationProtocol, const gchar* destinationHost, bool allowDestinationSubdomains)
323 SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
326 void webkit_reset_origin_access_white_lists()
328 SecurityOrigin::resetOriginAccessWhitelists();