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 "HTMLMediaElement.h"
32 #include "HTMLNames.h"
33 #include "HitTestResult.h"
34 #include "IconDatabase.h"
36 #include "PageCache.h"
37 #include "PageGroup.h"
38 #include "Pasteboard.h"
39 #include "PasteboardHelperGtk.h"
40 #include "ResourceHandle.h"
41 #include "ResourceHandleClient.h"
42 #include "ResourceHandleInternal.h"
43 #include "ResourceResponse.h"
44 #include "SecurityOrigin.h"
45 #include "TextEncodingRegistry.h"
46 #include "WebKitDOMBinding.h"
47 #include "webkitnetworkresponse.h"
48 #include "webkitsoupauthdialog.h"
49 #include "webkitversion.h"
51 #include <runtime/InitializeThreading.h>
53 #include <wtf/Threading.h>
56 #include "FullscreenVideoController.h"
60 #include "DatabaseTracker.h"
63 using namespace WebCore;
67 WebKitWebView* getViewFromFrame(WebKitWebFrame* frame)
69 WebKitWebFramePrivate* priv = frame->priv;
73 WebCore::Frame* core(WebKitWebFrame* frame)
78 WebKitWebFramePrivate* priv = frame->priv;
79 return priv ? priv->coreFrame : 0;
82 WebKitWebFrame* kit(WebCore::Frame* coreFrame)
87 ASSERT(coreFrame->loader());
88 WebKit::FrameLoaderClient* client = static_cast<WebKit::FrameLoaderClient*>(coreFrame->loader()->client());
89 return client ? client->webFrame() : 0;
92 WebCore::Page* core(WebKitWebView* webView)
97 WebKitWebViewPrivate* priv = webView->priv;
98 return priv ? priv->corePage : 0;
101 WebKitWebView* kit(WebCore::Page* corePage)
106 ASSERT(corePage->chrome());
107 WebKit::ChromeClient* client = static_cast<WebKit::ChromeClient*>(corePage->chrome()->client());
108 return client ? client->webView() : 0;
111 WebKitWebNavigationReason kit(WebCore::NavigationType type)
113 return (WebKitWebNavigationReason)type;
116 WebCore::NavigationType core(WebKitWebNavigationReason type)
118 return static_cast<WebCore::NavigationType>(type);
121 WebCore::ResourceRequest core(WebKitNetworkRequest* request)
123 SoupMessage* soupMessage = webkit_network_request_get_message(request);
125 return ResourceRequest(soupMessage);
127 KURL url = KURL(KURL(), String::fromUTF8(webkit_network_request_get_uri(request)));
128 return ResourceRequest(url);
131 WebCore::ResourceResponse core(WebKitNetworkResponse* response)
133 SoupMessage* soupMessage = webkit_network_response_get_message(response);
135 return ResourceResponse(soupMessage);
137 return ResourceResponse();
140 WebCore::EditingBehaviorType core(WebKitEditingBehavior type)
142 return (WebCore::EditingBehaviorType)type;
145 WebKitHitTestResult* kit(const WebCore::HitTestResult& result)
147 guint context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
148 GOwnPtr<char> linkURI(0);
149 GOwnPtr<char> imageURI(0);
150 GOwnPtr<char> mediaURI(0);
151 WebKitDOMNode* node = 0;
153 if (!result.absoluteLinkURL().isEmpty()) {
154 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
155 linkURI.set(g_strdup(result.absoluteLinkURL().string().utf8().data()));
158 if (!result.absoluteImageURL().isEmpty()) {
159 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
160 imageURI.set(g_strdup(result.absoluteImageURL().string().utf8().data()));
163 if (!result.absoluteMediaURL().isEmpty()) {
164 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
165 mediaURI.set(g_strdup(result.absoluteMediaURL().string().utf8().data()));
168 if (result.isSelected())
169 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
171 if (result.isContentEditable())
172 context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
174 if (result.innerNonSharedNode())
175 node = static_cast<WebKitDOMNode*>(kit(result.innerNonSharedNode()));
177 return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
178 "link-uri", linkURI.get(),
179 "image-uri", imageURI.get(),
180 "media-uri", mediaURI.get(),
186 PasteboardHelperGtk* pasteboardHelperInstance()
188 static PasteboardHelperGtk* helper = new PasteboardHelperGtk();
192 } /** end namespace WebKit */
194 static GtkWidget* currentToplevelCallback(WebKitSoupAuthDialog* feature, SoupMessage* message, gpointer userData)
196 gpointer messageData = g_object_get_data(G_OBJECT(message), "resourceHandle");
200 ResourceHandle* handle = static_cast<ResourceHandle*>(messageData);
204 ResourceHandleInternal* d = handle->getInternal();
208 WebCore::Frame* frame = d->m_frame;
212 GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(frame->page()->chrome()->platformPageClient()));
213 if (gtk_widget_is_toplevel(toplevel))
219 static void closeIconDatabaseOnExit()
221 iconDatabase()->close();
224 #ifdef HAVE_GSETTINGS
225 static bool isSchemaAvailable(const char* schemaID)
227 const char* const* availableSchemas = g_settings_list_schemas();
228 char* const* iter = const_cast<char* const*>(availableSchemas);
231 if (g_str_equal(schemaID, *iter))
239 GSettings* inspectorGSettings()
241 static GSettings* settings = 0;
246 const gchar* schemaID = "org.webkitgtk-"WEBKITGTK_API_VERSION_STRING".inspector";
248 // Unfortunately GSettings will abort the process execution if the
249 // schema is not installed, which is the case for when running
250 // tests, or even the introspection dump at build time, so check
251 // if we have the schema before trying to initialize it.
252 if (!isSchemaAvailable(schemaID)) {
253 g_warning("GSettings schema not found - settings will not be used or saved.");
257 settings = g_settings_new(schemaID);
265 static bool isInitialized = false;
268 isInitialized = true;
270 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
271 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
273 JSC::initializeThreading();
274 WTF::initializeMainThread();
276 WebCore::InitializeLoggingChannelsIfNecessary();
278 // We make sure the text codecs have been initialized, because
279 // that may only be done by the main thread.
280 atomicCanonicalTextEncodingName("UTF-8");
282 // Page cache capacity (in pages). Comment from Mac port:
283 // (Research indicates that value / page drops substantially after 3 pages.)
284 // FIXME: Expose this with an API and/or calculate based on available resources
285 webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
287 #ifdef HAVE_GSETTINGS
288 // Initialize settings variables here to make sure this happens in
290 inspectorGSettings();
294 gchar* databaseDirectory = g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL);
295 webkit_set_web_database_directory_path(databaseDirectory);
297 // FIXME: It should be possible for client applications to override the default appcache location
298 WebCore::cacheStorage().setCacheDirectory(databaseDirectory);
299 g_free(databaseDirectory);
302 PageGroup::setShouldTrackVisitedLinks(true);
304 Pasteboard::generalPasteboard()->setHelper(WebKit::pasteboardHelperInstance());
306 iconDatabase()->setEnabled(true);
308 GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_user_data_dir(), "webkit", "icondatabase", NULL));
309 iconDatabase()->open(iconDatabasePath.get());
311 atexit(closeIconDatabaseOnExit);
313 SoupSession* session = webkit_get_default_session();
315 SoupSessionFeature* authDialog = static_cast<SoupSessionFeature*>(g_object_new(WEBKIT_TYPE_SOUP_AUTH_DIALOG, NULL));
316 g_signal_connect(authDialog, "current-toplevel", G_CALLBACK(currentToplevelCallback), NULL);
317 soup_session_add_feature(session, authDialog);
318 g_object_unref(authDialog);
320 SoupSessionFeature* sniffer = static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL));
321 soup_session_add_feature(session, sniffer);
322 g_object_unref(sniffer);
324 soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
327 void webkit_white_list_access_from_origin(const gchar* sourceOrigin, const gchar* destinationProtocol, const gchar* destinationHost, bool allowDestinationSubdomains)
329 SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
332 void webkit_reset_origin_access_white_lists()
334 SecurityOrigin::resetOriginAccessWhitelists();
338 void webkitWebViewEnterFullscreen(WebKitWebView* webView, Node* node)
340 if (!node->hasTagName(HTMLNames::videoTag))
344 HTMLMediaElement* videoElement = static_cast<HTMLMediaElement*>(node);
345 WebKitWebViewPrivate* priv = webView->priv;
347 // First exit Fullscreen for the old mediaElement.
348 if (priv->fullscreenVideoController)
349 priv->fullscreenVideoController->exitFullscreen();
351 priv->fullscreenVideoController = new FullscreenVideoController;
352 priv->fullscreenVideoController->setMediaElement(videoElement);
353 priv->fullscreenVideoController->enterFullscreen();
357 void webkitWebViewExitFullscreen(WebKitWebView* webView)
360 WebKitWebViewPrivate* priv = webView->priv;
361 if (priv->fullscreenVideoController)
362 priv->fullscreenVideoController->exitFullscreen();