📄 webkitwebview.cpp
字号:
{ 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_YES_NO; defaultResponse = GTK_RESPONSE_YES; 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_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(dialog)->vbox), 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_YES: didConfirm = TRUE; break; case GTK_RESPONSE_OK: didConfirm = TRUE; if (entry) *value = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); else *value = 0; break; case GTK_RESPONSE_NO: 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_print("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_paste_clipboard(WebKitWebView* webView){ Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); frame->editor()->command("Paste").execute();}static void webkit_web_view_dispose(GObject* object){ WebKitWebView* webView = WEBKIT_WEB_VIEW(object); WebKitWebViewPrivate* priv = webView->priv; priv->disposing = TRUE; if (priv->corePage) { webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object)); core(priv->mainFrame)->loader()->detachChildren(); delete priv->corePage; priv->corePage = NULL; } if (priv->horizontalAdjustment) { g_object_unref(priv->horizontalAdjustment); priv->horizontalAdjustment = NULL; } if (priv->verticalAdjustment) { g_object_unref(priv->verticalAdjustment); priv->verticalAdjustment = NULL; } if (priv->backForwardList) { g_object_unref(priv->backForwardList); priv->backForwardList = NULL; g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView); g_object_unref(priv->webSettings); priv->webSettings = NULL; g_object_unref(priv->webInspector); priv->webInspector = NULL; g_object_unref(priv->webWindowFeatures); priv->webWindowFeatures = NULL; g_object_unref(priv->imContext); priv->imContext = NULL; gtk_target_list_unref(priv->copy_target_list); priv->copy_target_list = NULL; gtk_target_list_unref(priv->paste_target_list); priv->paste_target_list = NULL; delete priv->userAgent; priv->userAgent = NULL; } G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);}static void webkit_web_view_finalize(GObject* object){ WebKitWebView* webView = WEBKIT_WEB_VIEW(object); WebKitWebViewPrivate* priv = webView->priv; g_free(priv->encoding); g_free(priv->customEncoding); G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);}static gboolean webkit_create_web_view_request_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 NULL; AXObjectCache::enableAccessibility(); Frame* coreFrame = core(webView)->mainFrame(); if (!coreFrame) return NULL; Document* doc = coreFrame->document(); if (!doc) return NULL; AccessibilityObject* coreAccessible = doc->axObjectCache()->get(doc->renderer()); if (!coreAccessible || !coreAccessible->wrapper()) return NULL; return coreAccessible->wrapper();}static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass){ GtkBindingSet* binding_set; webkit_init(); /* * Signals */ /** * WebKitWebView::create-web-view: * @web_view: the object on which the signal is emitted * @frame: the #WebKitWebFrame * @return: a newly allocated #WebKitWebView or %NULL * * 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. * * 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_SIGNAL_ACTION), G_STRUCT_OFFSET (WebKitWebViewClass, create_web_view), webkit_create_web_view_request_handled, NULL, webkit_marshal_OBJECT__OBJECT, WEBKIT_TYPE_WEB_VIEW , 1, WEBKIT_TYPE_WEB_FRAME); /** * WebKitWebView::web-view-ready: * @web_view: the object on which the signal is emitted * @return: %TRUE to stop other handlers from being invoked for * the event, %FALSE to propagate the event further * * 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. * * 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::navigation-requested: * @web_view: the object on which the signal is emitted * @frame: the #WebKitWebFrame that required the navigation * @request: a #WebKitNetworkRequest * @return: a WebKitNavigationResponse * * Emitted when @frame requests a navigation to another page. * * 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_SIGNAL_ACTION), 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::navigation-policy-decision-requested:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -