static void cache_up (GrlNetWc *self) { SoupCache *cache; GrlNetWcPrivate *priv = self->priv; gchar *dir; GRL_DEBUG ("cache up"); dir = g_dir_make_tmp ("grilo-plugin-cache-XXXXXX", NULL); if (!dir) return; cache = soup_cache_new (dir, SOUP_CACHE_SINGLE_USER); g_free (dir); soup_session_add_feature (priv->session, SOUP_SESSION_FEATURE (cache)); if (priv->cache_size) { soup_cache_set_max_size (cache, priv->cache_size * 1024 * 1024); } g_object_unref (cache); }
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, IPC::MessageDecoder&) { #if ENABLE(SECCOMP_FILTERS) { #if PLATFORM(EFL) SeccompFiltersWebProcessEfl seccompFilters(parameters); #endif seccompFilters.initialize(); } #endif if (usesNetworkProcess()) return; ASSERT(!parameters.diskCacheDirectory.isEmpty()); GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER)); soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get())); soup_cache_load(soupCache.get()); if (!parameters.cookiePersistentStoragePath.isEmpty()) { supplement<WebCookieManager>()->setCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType); } supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy); if (!parameters.languages.isEmpty()) setSoupSessionAcceptLanguage(parameters.languages); for (size_t i = 0; i < parameters.urlSchemesRegistered.size(); i++) supplement<WebSoupRequestManager>()->registerURIScheme(parameters.urlSchemesRegistered[i]); setIgnoreTLSErrors(parameters.ignoreTLSErrors); WebCore::addLanguageChangeObserver(this, languageChanged); }
void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& parameters) { #if ENABLE(SECCOMP_FILTERS) { #if PLATFORM(EFL) SeccompFiltersWebProcessEfl seccompFilters(parameters); #elif PLATFORM(GTK) SeccompFiltersWebProcessGtk seccompFilters(parameters); #endif seccompFilters.initialize(); } #endif if (usesNetworkProcess()) return; ASSERT(!parameters.diskCacheDirectory.isEmpty()); // We used to use the given cache directory for the soup cache, but now we use a subdirectory to avoid // conflicts with other cache files in the same directory. Remove the old cache files if they still exist. WebCore::SoupNetworkSession::defaultSession().clearCache(WebCore::directoryName(parameters.diskCacheDirectory)); #if ENABLE(NETWORK_CACHE) // When network cache is enabled, the disk cache directory is the network process one. CString diskCachePath = WebCore::pathByAppendingComponent(WebCore::directoryName(parameters.diskCacheDirectory), "webkit").utf8(); #else CString diskCachePath = parameters.diskCacheDirectory.utf8(); #endif GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(diskCachePath.data(), SOUP_CACHE_SINGLE_USER)); WebCore::SoupNetworkSession::defaultSession().setCache(soupCache.get()); // Set an initial huge max_size for the SoupCache so the call to soup_cache_load() won't evict any cached // resource. The final size of the cache will be set by NetworkProcess::platformSetCacheModel(). unsigned initialMaxSize = soup_cache_get_max_size(soupCache.get()); soup_cache_set_max_size(soupCache.get(), G_MAXUINT); soup_cache_load(soupCache.get()); soup_cache_set_max_size(soupCache.get(), initialMaxSize); if (!parameters.cookiePersistentStoragePath.isEmpty()) { supplement<WebCookieManager>()->setCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType); } supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy); if (!parameters.languages.isEmpty()) setSoupSessionAcceptLanguage(parameters.languages); setIgnoreTLSErrors(parameters.ignoreTLSErrors); WebCore::addLanguageChangeObserver(this, languageChanged); }
void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters) { ASSERT(!parameters.diskCacheDirectory.isEmpty()); GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER)); soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get())); soup_cache_load(soupCache.get()); if (!parameters.cookiePersistentStoragePath.isEmpty()) { supplement<WebCookieManager>()->setCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType); } supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy); setIgnoreTLSErrors(parameters.ignoreTLSErrors); }
WK_EXPORT int WebProcessMainGtk(int argc, char* argv[]) { ASSERT(argc == 2); #ifndef NDEBUG if (g_getenv("WEBKIT2_PAUSE_WEB_PROCESS_ON_LAUNCH")) sleep(30); #endif gtk_init(&argc, &argv); bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); JSC::initializeThreading(); WTF::initializeMainThread(); RunLoop::initializeMainRunLoop(); int socket = atoi(argv[1]); ChildProcessInitializationParameters parameters; parameters.connectionIdentifier = socket; WebProcess::shared().initialize(parameters); // Despite using system CAs to validate certificates we're // accepting invalid certificates by default. New API will be // added later to let client accept/discard invalid certificates. SoupSession* session = WebCore::ResourceHandle::defaultSession(); g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, SOUP_SESSION_SSL_STRICT, FALSE, NULL); GOwnPtr<char> soupCacheDirectory(g_build_filename(g_get_user_cache_dir(), g_get_prgname(), NULL)); GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(soupCacheDirectory.get(), SOUP_CACHE_SINGLE_USER)); soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCache.get())); soup_cache_load(soupCache.get()); RunLoop::run(); soup_cache_flush(soupCache.get()); soup_cache_dump(soupCache.get()); return 0; }
WK_EXPORT int WebProcessMainEfl(int argc, char* argv[]) { // WebProcess should be launched with an option. if (argc != 2) return 1; if (!eina_init()) return 1; if (!ecore_init()) { // Could not init ecore. eina_shutdown(); return 1; } #ifdef HAVE_ECORE_X XSetExtensionErrorHandler(dummyExtensionErrorHandler); if (!ecore_x_init(0)) { // Could not init ecore_x. // PlatformScreenEfl and systemBeep() functions // depend on ecore_x functionality. ecore_shutdown(); eina_shutdown(); return 1; } #endif #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif if (!ecore_main_loop_glib_integrate()) return 1; JSC::initializeThreading(); WTF::initializeMainThread(); RunLoop::initializeMainRunLoop(); SoupSession* session = WebCore::ResourceHandle::defaultSession(); const char* httpProxy = getenv("http_proxy"); if (httpProxy) { const char* noProxy = getenv("no_proxy"); SoupProxyURIResolver* resolverEfl = soupProxyResolverWkNew(httpProxy, noProxy); soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolverEfl)); g_object_unref(resolverEfl); } // Set SOUP cache. String soupCacheDirectory = String::fromUTF8(efreet_cache_home_get()) + "/WebKitEfl"; SoupCache* soupCache = soup_cache_new(soupCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER); soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCache)); soup_cache_load(soupCache); int socket = atoi(argv[1]); ChildProcessInitializationParameters parameters; parameters.connectionIdentifier = socket; WebProcess::shared().initialize(parameters); RunLoop::run(); soup_cache_flush(soupCache); soup_cache_dump(soupCache); g_object_unref(soupCache); ecore_x_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; }
static void do_basics_test (SoupURI *base_uri) { SoupSession *session; SoupCache *cache; char *cache_dir; char *body1, *body2, *body3, *body4, *body5, *cmp; debug_printf (1, "Cache basics\n"); cache_dir = g_dir_make_tmp ("cache-test-XXXXXX", NULL); debug_printf (2, " Caching to %s\n", cache_dir); cache = soup_cache_new (cache_dir, SOUP_CACHE_SINGLE_USER); session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, SOUP_SESSION_ADD_FEATURE, cache, NULL); g_signal_connect (session, "request-started", G_CALLBACK (request_started), NULL); debug_printf (2, " Initial requests\n"); body1 = do_request (session, base_uri, "GET", "/1", "Test-Set-Expires", "Fri, 01 Jan 2100 00:00:00 GMT", NULL); body2 = do_request (session, base_uri, "GET", "/2", "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT", NULL); body3 = do_request (session, base_uri, "GET", "/3", "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT", "Test-Set-Cache-Control", "must-revalidate", NULL); body4 = do_request (session, base_uri, "GET", "/4", "Test-Set-ETag", "\"abcdefg\"", "Test-Set-Cache-Control", "must-revalidate", NULL); body5 = do_request (session, base_uri, "GET", "/5", "Test-Set-Cache-Control", "no-cache", NULL); /* Resource with future Expires should have been cached */ debug_printf (1, " Fresh cached resource\n"); cmp = do_request (session, base_uri, "GET", "/1", NULL); if (last_request_hit_network) { debug_printf (1, " Request for /1 not filled from cache!\n"); errors++; } if (strcmp (body1, cmp) != 0) { debug_printf (1, " Cached response (%s) did not match original (%s)\n", cmp, body1); errors++; } g_free (cmp); /* Resource with long-ago Last-Modified should have been cached */ debug_printf (1, " Heuristically-fresh cached resource\n"); cmp = do_request (session, base_uri, "GET", "/2", NULL); if (last_request_hit_network) { debug_printf (1, " Request for /2 not filled from cache!\n"); errors++; } if (strcmp (body2, cmp) != 0) { debug_printf (1, " Cached response (%s) did not match original (%s)\n", cmp, body2); errors++; } g_free (cmp); /* Adding a query string should bypass the cache but not invalidate it */ debug_printf (1, " Fresh cached resource with a query\n"); cmp = do_request (session, base_uri, "GET", "/1?attr=value", NULL); if (!last_request_hit_network) { debug_printf (1, " Request for /1?attr=value filled from cache!\n"); errors++; } g_free (cmp); debug_printf (2, " Second request\n"); cmp = do_request (session, base_uri, "GET", "/1", NULL); if (last_request_hit_network) { debug_printf (1, " Second request for /1 not filled from cache!\n"); errors++; } if (strcmp (body1, cmp) != 0) { debug_printf (1, " Cached response (%s) did not match original (%s)\n", cmp, body1); errors++; } g_free (cmp); /* Last-Modified + must-revalidate causes a conditional request */ debug_printf (1, " Unchanged must-revalidate resource w/ Last-Modified\n"); cmp = do_request (session, base_uri, "GET", "/3", "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT", "Test-Set-Cache-Control", "must-revalidate", NULL); if (!last_request_validated) { debug_printf (1, " Request for /3 not validated!\n"); errors++; } if (last_request_hit_network) { debug_printf (1, " Request for /3 not filled from cache!\n"); errors++; } if (strcmp (body3, cmp) != 0) { debug_printf (1, " Cached response (%s) did not match original (%s)\n", cmp, body3); errors++; } g_free (cmp); /* Validation failure should update cache */ debug_printf (1, " Changed must-revalidate resource w/ Last-Modified\n"); cmp = do_request (session, base_uri, "GET", "/3", "Test-Set-Last-Modified", "Sat, 02 Jan 2010 00:00:00 GMT", "Test-Set-Cache-Control", "must-revalidate", NULL); if (!last_request_validated) { debug_printf (1, " Request for /3 not validated!\n"); errors++; } if (!last_request_hit_network) { debug_printf (1, " Request for /3 filled from cache!\n"); errors++; } if (strcmp (body3, cmp) == 0) { debug_printf (1, " Request for /3 returned cached response\n"); errors++; } g_free (cmp); #if 0 /* This doesn't work... is the test wrong or is SoupCache? */ debug_printf (2, " Second request\n"); cmp = do_request (session, base_uri, "GET", "/3", "Test-Set-Last-Modified", "Sat, 02 Jan 2010 00:00:00 GMT", "Test-Set-Cache-Control", "must-revalidate", NULL); if (!last_request_validated) { debug_printf (1, " Second request for /3 not validated!\n"); errors++; } if (last_request_hit_network) { debug_printf (1, " Second request for /3 not filled from cache!\n"); errors++; } if (strcmp (body3, cmp) == 0) { debug_printf (1, " Replacement body for /3 not cached!\n"); errors++; } g_free (cmp); #endif /* ETag + must-revalidate causes a conditional request */ debug_printf (1, " Unchanged must-revalidate resource w/ ETag\n"); cmp = do_request (session, base_uri, "GET", "/4", "Test-Set-ETag", "\"abcdefg\"", NULL); if (!last_request_validated) { debug_printf (1, " Request for /4 not validated!\n"); errors++; } if (last_request_hit_network) { debug_printf (1, " Request for /4 not filled from cache!\n"); errors++; } if (strcmp (body4, cmp) != 0) { debug_printf (1, " Cached response (%s) did not match original (%s)\n", cmp, body4); errors++; } g_free (cmp); /* Cache-Control: no-cache prevents caching */ debug_printf (1, " Uncacheable resource\n"); cmp = do_request (session, base_uri, "GET", "/5", "Test-Set-Cache-Control", "no-cache", NULL); if (!last_request_hit_network) { debug_printf (1, " Request for /5 filled from cache!\n"); errors++; } if (strcmp (body5, cmp) != 0) { debug_printf (1, " Re-retrieved response (%s) did not match original (%s)\n", cmp, body5); errors++; } g_free (cmp); /* PUT to a URI invalidates the cache entry */ debug_printf (1, " Invalidating and re-requesting a cached resource\n"); cmp = do_request (session, base_uri, "PUT", "/1", NULL); if (!last_request_hit_network) { debug_printf (1, " PUT filled from cache!\n"); errors++; } g_free (cmp); cmp = do_request (session, base_uri, "GET", "/1", NULL); if (!last_request_hit_network) { debug_printf (1, " PUT failed to invalidate cache entry!\n"); errors++; } g_free (cmp); soup_test_session_abort_unref (session); g_object_unref (cache); g_free (cache_dir); g_free (body1); g_free (body2); g_free (body3); g_free (body4); g_free (body5); }