/** \brief Save the content of the current page. \param app Pointer to the application object (or NULL). \param w Pointer to the current window object (or NULL). \param context Execution context. \param arg List of arguments. \return return_void on success. \return return_error if there is no window or the argument list is badly formed. **/ int save(application *app, app_window *w, const exec_context context, std::vector<std::string> arg) { unsigned arg_size = arg.size(); std::string cmd = haku::string::implode(arg,' '); if ( w == NULL && arg_size >= 2 ) { WebKitNetworkRequest *r = webkit_network_request_new(arg[1].c_str()); w = app->create_window(); w->download = webkit_download_new(r); w->osl = (context == exec_context_callback); if ( arg_size >= 3 ) webkit_download_set_destination_uri(w->download, haku::string::trim(cmd.substr(arg[0].size()+2+arg[1].size(), -1)).c_str()); app_window::initdownload(NULL, w->download, w); return return_void; } else if ( w != NULL ) { WebKitNetworkRequest *r = webkit_network_request_new(w->geturi().c_str()); WebKitDownload *o = webkit_download_new(r); if ( arg_size >= 2 ) webkit_download_set_destination_uri(o, haku::string::trim(cmd.substr(arg[0].size(), -1)).c_str()); app_window::initdownload(NULL, o, w); return return_void; } return return_error; }
void ContextMenuClient::downloadURL(const KURL& url) { WebKitNetworkRequest* networkRequest = webkit_network_request_new(url.string().utf8().data()); webkit_web_view_request_download(m_webView, networkRequest); g_object_unref(networkRequest); }
static void test_network_request_properties() { WebKitNetworkRequest* request; SoupMessage* message; gchar* soupURI; /* Test URI is set correctly when creating with URI */ request = webkit_network_request_new("http://debian.org/"); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); g_object_unref(request); /* Test URI is set correctly when creating with Message */ message = soup_message_new("GET", "http://debian.org/"); request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL)); g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); g_object_unref(message); message = webkit_network_request_get_message(request); soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE); g_assert_cmpstr(soupURI, ==, "http://debian.org/"); g_free(soupURI); g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); g_object_unref(request); }
void FrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction policyFunction, const NavigationAction& action, const ResourceRequest& resourceRequest, PassRefPtr<FormState>, const String& frameName) { ASSERT(policyFunction); if (!policyFunction) return; if (resourceRequest.isNull()) { (core(m_frame)->loader()->policyChecker()->*policyFunction)(PolicyIgnore); return; } WebKitWebPolicyDecision* policyDecision = webkit_web_policy_decision_new(m_frame, policyFunction); if (m_policyDecision) g_object_unref(m_policyDecision); m_policyDecision = policyDecision; WebKitWebView* webView = getViewFromFrame(m_frame); WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().string().utf8().data()); WebKitWebNavigationAction* navigationAction = getNavigationAction(action, frameName.utf8().data()); gboolean isHandled = false; g_signal_emit_by_name(webView, "new-window-policy-decision-requested", m_frame, request, navigationAction, policyDecision, &isHandled); g_object_unref(navigationAction); g_object_unref(request); // FIXME: I think Qt version marshals this to another thread so when we // have multi-threaded download, we might need to do the same if (!isHandled) (core(m_frame)->loader()->policyChecker()->*policyFunction)(PolicyUse); }
/** * ephy_download_new_for_uri: * @uri: a source URI from where to download * * Creates an #EphyDownload to download @uri. * * Returns: an #EphyDownload. **/ EphyDownload * ephy_download_new_for_uri (const char *uri) { EphyDownload *ephy_download; WebKitDownload *download; #ifndef HAVE_WEBKIT2 WebKitNetworkRequest *request; #endif g_return_val_if_fail (uri != NULL, NULL); #ifdef HAVE_WEBKIT2 download = webkit_web_context_download_uri (webkit_web_context_get_default (), uri); #else request = webkit_network_request_new (uri); download = webkit_download_new (request); g_return_val_if_fail (download != NULL, NULL); g_object_unref (request); #endif ephy_download = ephy_download_new_for_download (download); g_object_unref (download); return ephy_download; }
static void test_webkit_download_create(void) { WebKitNetworkRequest* request; WebKitDownload* download; const gchar* uri = "http://example.com"; gchar* tmpDir; request = webkit_network_request_new(uri); download = webkit_download_new(request); g_object_unref(request); g_assert_cmpstr(webkit_download_get_uri(download), ==, uri); g_assert(webkit_download_get_network_request(download) == request); g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download))); g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED); g_assert(!webkit_download_get_total_size(download)); g_assert(!webkit_download_get_current_size(download)); g_assert(!webkit_download_get_progress(download)); g_assert(!webkit_download_get_elapsed_time(download)); tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL); webkit_download_set_destination_uri(download, tmpDir); g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));; g_free(tmpDir); g_object_unref(download); }
/* download_on_idle */ static gboolean _download_on_idle(gpointer data) { Download * download = data; DownloadPrefs * prefs = &download->prefs; #ifdef WITH_WEBKIT char * p = NULL; char * cwd = NULL; size_t len; WebKitNetworkRequest * request; download->timeout = 0; if(prefs->output[0] != '/' && (cwd = getcwd(NULL, 0)) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); return FALSE; } len = ((cwd != NULL) ? strlen(cwd) : 0) + strlen(prefs->output) + 7; if((p = malloc(len)) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); free(cwd); return FALSE; } snprintf(p, len, "%s%s%s%s", "file:", (cwd != NULL) ? cwd : "", (cwd != NULL) ? "/" : "", prefs->output); request = webkit_network_request_new(download->url); download->conn = webkit_download_new(request); webkit_download_set_destination_uri(download->conn, p); free(p); free(cwd); webkit_download_start(download->conn); #else download->timeout = 0; if((download->fp = fopen(prefs->output, "w")) == NULL) { _download_error(download, prefs->output, 0); download_cancel(download); return FALSE; } download->conn = gnet_conn_http_new(); if(gnet_conn_http_set_method(download->conn, GNET_CONN_HTTP_METHOD_GET, NULL, 0) != TRUE) return _download_error(download, _("Unknown error"), FALSE); gnet_conn_http_set_uri(download->conn, download->url); if(prefs->user_agent != NULL) gnet_conn_http_set_user_agent(download->conn, prefs->user_agent); gnet_conn_http_run_async(download->conn, _download_on_http, download); #endif download->timeout = g_timeout_add(250, _download_on_timeout, download); return FALSE; }
void FrameLoaderClient::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest&, const ResourceResponse& response) { // FIXME: We could reuse the same handle here, but when I tried // implementing that the main load would fail and stop, so I have // simplified this case for now. handle->cancel(); WebKitNetworkRequest* networkRequest = webkit_network_request_new(request.url().string().utf8().data()); WebKitWebView* view = getViewFromFrame(m_frame); webkit_web_view_request_download(view, networkRequest, response); g_object_unref(networkRequest); }
JNIEXPORT jintLong JNICALL WebKitGTK_NATIVE(_1webkit_1network_1request_1new) (JNIEnv *env, jclass that, jbyteArray arg0) { jbyte *lparg0=NULL; jintLong rc = 0; WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1network_1request_1new_FUNC); if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; rc = (jintLong)webkit_network_request_new((const gchar *)lparg0); fail: if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1network_1request_1new_FUNC); return rc; }
void download(Client *c, const Arg *arg) { char *uri; WebKitNetworkRequest *r; WebKitDownload *dl; if(arg->v) uri = (char *)arg->v; else uri = c->linkhover ? c->linkhover : geturi(c); r = webkit_network_request_new(uri); dl = webkit_download_new(r); initdownload(c->view, dl, c); }
/** * Creates a new download on the stack. * * \param L The Lua VM state. * * \luastack * \lvalue A table containing properties to set on the download. * \lreturn A new \c download object. */ static gint luaH_download_new(lua_State *L) { luaH_class_new(L, &download_class); download_t *download = luaH_checkdownload(L, -1); /* create download from constructor properties */ WebKitNetworkRequest *request = webkit_network_request_new( download->uri); download->webkit_download = webkit_download_new(request); g_object_ref(G_OBJECT(download->webkit_download)); /* raise error signal on error */ g_signal_connect(G_OBJECT(download->webkit_download), "error", G_CALLBACK(error_cb), download); /* return download */ return 1; }
bool LoadItem::invoke() const { gchar* targetString = JSStringCopyUTF8CString(m_target.get()); WebKitWebFrame* targetFrame; if (!strlen(targetString)) targetFrame = mainFrame; else targetFrame = webkit_web_frame_find_frame(mainFrame, targetString); g_free(targetString); gchar* urlString = JSStringCopyUTF8CString(m_url.get()); WebKitNetworkRequest* request = webkit_network_request_new(urlString); g_free(urlString); webkit_web_frame_load_request(targetFrame, request); g_object_unref(request); return true; }
static void test_webkit_web_data_source_get_initial_request() { WebKitWebView* view; WebKitWebFrame* frame; WebKitWebDataSource* dataSource; WebKitNetworkRequest* initialRequest; view = WEBKIT_WEB_VIEW(webkit_web_view_new()); g_object_ref_sink(view); frame = webkit_web_view_get_main_frame(view); WebKitNetworkRequest* request = webkit_network_request_new("http://www.google.com"); webkit_web_frame_load_request(frame, request); g_object_unref(request); dataSource = webkit_web_frame_get_provisional_data_source(frame); g_assert(dataSource); initialRequest = webkit_web_data_source_get_initial_request(dataSource); g_assert_cmpstr(webkit_network_request_get_uri(initialRequest), ==, "http://www.google.com/"); g_object_unref(view); }
gboolean command_save(const Arg *arg) { WebKitDownload *download; const char *uri, *path = NULL; if (arg->i == COMMAND_SAVE_CURRENT) { uri = vb.state.uri; /* given string is the path to save the download to */ if (arg->s && *(arg->s) != '\0') { path = arg->s; } } else { uri = arg->s; } if (!uri || !*uri) { return false; } download = webkit_download_new(webkit_network_request_new(uri)); vb_download(vb.gui.webview, download, path); return true; }
static void session_command_open_uris (EphySession *session, char **uris, const char *options, guint32 user_time) { EphyShell *shell; EphyWindow *window; EphyEmbed *embed; EphySessionPrivate *priv; EphyNewTabFlags flags = 0; guint i; priv = session->priv; shell = ephy_shell_get_default (); g_object_ref (shell); window = ephy_session_get_active_window (session); if (options != NULL && strstr (options, "external") != NULL) { flags |= EPHY_NEW_TAB_FROM_EXTERNAL; } if (options != NULL && strstr (options, "new-window") != NULL) { window = NULL; flags |= EPHY_NEW_TAB_IN_NEW_WINDOW; } else if (options != NULL && strstr (options, "new-tab") != NULL) { flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_JUMP; } for (i = 0; uris[i] != NULL; ++i) { const char *url = uris[i]; EphyNewTabFlags page_flags; #ifdef HAVE_WEBKIT2 WebKitURIRequest *request = NULL; #else WebKitNetworkRequest *request = NULL; #endif if (url[0] == '\0') { page_flags = EPHY_NEW_TAB_HOME_PAGE; } else { page_flags = EPHY_NEW_TAB_OPEN_PAGE; #ifdef HAVE_WEBKIT2 request = webkit_uri_request_new (url); #else request = webkit_network_request_new (url); #endif } /* For the first URI, if we have a valid recovery * window, reuse the already existing embed instead of * creating a new one, except if we still want to * present the option to resume a crashed session, in * that case use a new tab in the same window */ if (i == 0 && priv->resume_window != NULL) { EphyWebView *web_view; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (priv->resume_window)); web_view = ephy_embed_get_web_view (embed); ephy_web_view_load_url (web_view, url); } else { embed = ephy_shell_new_tab_full (shell, window, NULL /* parent tab */, request, flags | page_flags, EPHY_WEB_VIEW_CHROME_ALL, FALSE /* is popup? */, user_time); } if (request) g_object_unref (request); window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))); } g_object_unref (shell); }