Changeset 41969 in webkit


Ignore:
Timestamp:
Mar 25, 2009 5:00:52 AM (15 years ago)
Author:
xan@webkit.org
Message:

2009-03-23 Alejandro Garcia Castro <alex@igalia.com>

Reviewed by Holger Freyther.

[Gtk] Current API does not allow us to open target="_blank" links
in new tabs instead of windows
https://bugs.webkit.org/show_bug.cgi?id=23932

Added a signal to the API (new-window-policy-decision-requested)
that allows the browser to decide the policy for the new window
request, if the signal is not handled we open the new window as
usual.

  • WebCoreSupport/FrameLoaderClientGtk.cpp: (WebKit::getNavigationAction): (WebKit::FrameLoaderClient::dispatchDecidePolicyForNewWindowAction): (WebKit::FrameLoaderClient::dispatchDecidePolicyForNavigationAction):
  • webkit/webkitwebview.cpp:
Location:
trunk/WebKit/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r41873 r41969  
     12009-03-23  Alejandro Garcia Castro  <alex@igalia.com>
     2
     3        Reviewed by Holger Freyther.
     4
     5        [Gtk] Current API does not allow us to open target="_blank" links
     6        in new tabs instead of windows
     7        https://bugs.webkit.org/show_bug.cgi?id=23932
     8
     9        Added a signal to the API (new-window-policy-decision-requested)
     10        that allows the browser to decide the policy for the new window
     11        request, if the signal is not handled we open the new window as
     12        usual.
     13
     14        * WebCoreSupport/FrameLoaderClientGtk.cpp:
     15        (WebKit::getNavigationAction):
     16        (WebKit::FrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
     17        (WebKit::FrameLoaderClient::dispatchDecidePolicyForNavigationAction):
     18        * webkit/webkitwebview.cpp:
     19
    1202009-03-20  Jan Michael Alonzo  <jmalonzo@gmail.com>
    221
  • trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

    r41747 r41969  
    304304}
    305305
     306static WebKitWebNavigationAction* getNavigationAction(const NavigationAction& action)
     307{
     308    gint button = -1;
     309
     310    const Event* event = action.event();
     311    if (event && event->isMouseEvent()) {
     312        const MouseEvent* mouseEvent = static_cast<const MouseEvent*>(event);
     313        // DOM button values are 0, 1 and 2 for left, middle and right buttons.
     314        // GTK+ uses 1, 2 and 3, so let's add 1 to remain consistent.
     315        button = mouseEvent->button() + 1;
     316    }
     317
     318    gint modifierFlags = 0;
     319    UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(event));
     320    if (keyStateEvent) {
     321        if (keyStateEvent->shiftKey())
     322            modifierFlags |= GDK_SHIFT_MASK;
     323        if (keyStateEvent->ctrlKey())
     324            modifierFlags |= GDK_CONTROL_MASK;
     325        if (keyStateEvent->altKey())
     326            modifierFlags |= GDK_MOD1_MASK;
     327        if (keyStateEvent->metaKey())
     328            modifierFlags |= GDK_MOD2_MASK;
     329    }
     330
     331    return WEBKIT_WEB_NAVIGATION_ACTION(g_object_new(WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
     332                                                     "reason", kit(action.type()),
     333                                                     "original-uri", action.url().string().utf8().data(),
     334                                                     "button", button,
     335                                                     "modifier-state", modifierFlags,
     336                                                     NULL));
     337}
     338
    306339void FrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction policyFunction, const NavigationAction& action, const ResourceRequest& resourceRequest, PassRefPtr<FormState>, const String& s)
    307340{
     
    315348    }
    316349
     350    WebKitWebPolicyDecision* policyDecision = webkit_web_policy_decision_new(m_frame, policyFunction);
     351
     352    if (m_policyDecision)
     353        g_object_unref(m_policyDecision);
     354    m_policyDecision = policyDecision;
     355
     356    WebKitWebView* webView = getViewFromFrame(m_frame);
     357    WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().string().utf8().data());
     358    WebKitWebNavigationAction* navigationAction = getNavigationAction(action);
     359    gboolean isHandled = false;
     360
     361    g_signal_emit_by_name(webView, "new-window-policy-decision-requested", m_frame, request, navigationAction, policyDecision, &isHandled);
     362
     363    g_object_unref(navigationAction);
     364    g_object_unref(request);
     365
    317366    // FIXME: I think Qt version marshals this to another thread so when we
    318367    // have multi-threaded download, we might need to do the same
    319     (core(m_frame)->loader()->*policyFunction)(PolicyUse);
     368    if (!isHandled)
     369        (core(m_frame)->loader()->*policyFunction)(PolicyUse);
    320370}
    321371
     
    354404    m_policyDecision = policyDecision;
    355405
    356     gint button = -1;
    357     gint modifierFlags = 0;
    358 
    359     const Event* event = action.event();
    360     if (event && event->isMouseEvent()) {
    361         const MouseEvent* mouseEvent = static_cast<const MouseEvent*>(event);
    362         // DOM button values are 0, 1 and 2 for left, middle and right buttons.
    363         // GTK+ uses 1, 2 and 3, so let's add 1 to remain consistent.
    364         button = mouseEvent->button() + 1;
    365     }
    366 
    367     UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(event));
    368     if (keyStateEvent) {
    369         if (keyStateEvent->shiftKey())
    370             modifierFlags |= GDK_SHIFT_MASK;
    371         if (keyStateEvent->ctrlKey())
    372             modifierFlags |= GDK_CONTROL_MASK;
    373         if (keyStateEvent->altKey())
    374             modifierFlags |= GDK_MOD1_MASK;
    375         if (keyStateEvent->metaKey())
    376             modifierFlags |= GDK_MOD2_MASK;
    377     }
    378 
    379     GObject* navigationAction = G_OBJECT(g_object_new(WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
    380                                                      "reason", kit(action.type()),
    381                                                       "original-uri", action.url().string().utf8().data(),
    382                                                       "button", button,
    383                                                       "modifier-state", modifierFlags,
    384                                                       NULL));
    385 
     406    WebKitWebNavigationAction* navigationAction = getNavigationAction(action);
    386407    gboolean isHandled = false;
    387408    g_signal_emit_by_name(webView, "navigation-policy-decision-requested", m_frame, request, navigationAction, policyDecision, &isHandled);
  • trunk/WebKit/gtk/webkit/webkitwebview.cpp

    r41747 r41969  
    113113    /* normal signals */
    114114    NAVIGATION_REQUESTED,
     115    NEW_WINDOW_POLICY_DECISION_REQUESTED,
    115116    NAVIGATION_POLICY_DECISION_REQUESTED,
    116117    MIME_TYPE_POLICY_DECISION_REQUESTED,
     
    10531054
    10541055    /**
     1056     * WebKitWebView::new-window-policy-decision-requested:
     1057     * @web_view: the object on which the signal is emitted
     1058     * @frame: the #WebKitWebFrame that required the navigation
     1059     * @request: a #WebKitNetworkRequest
     1060     * @navigation_action: a #WebKitWebNavigation
     1061     * @policy_decision: a #WebKitWebPolicyDecision
     1062     * @return: TRUE if the signal will be handled, FALSE to have the
     1063     *          default behavior apply
     1064     *
     1065     * Emitted when @frame requests opening a new window. With this
     1066     * signal the browser can use the context of the request to decide
     1067     * about the new window. If the request is not handled the default
     1068     * behavior is to allow opening the new window to load the url,
     1069     * which will cause a create-web-view signal emission where the
     1070     * browser handles the new window action but without information
     1071     * of the context that caused the navigation. The following
     1072     * navigation-policy-decision-requested emissions will load the
     1073     * page after the creation of the new window just with the
     1074     * information of this new navigation context, without any
     1075     * information about the action that made this new window to be
     1076     * opened.
     1077     *
     1078     * Since: 1.1.4
     1079     */
     1080    webkit_web_view_signals[NEW_WINDOW_POLICY_DECISION_REQUESTED] =
     1081        g_signal_new("new-window-policy-decision-requested",
     1082            G_TYPE_FROM_CLASS(webViewClass),
     1083            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
     1084            0,
     1085            g_signal_accumulator_true_handled,
     1086            NULL,
     1087            webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT,
     1088            G_TYPE_BOOLEAN, 4,
     1089            WEBKIT_TYPE_WEB_FRAME,
     1090            WEBKIT_TYPE_NETWORK_REQUEST,
     1091            WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
     1092            WEBKIT_TYPE_WEB_POLICY_DECISION);
     1093
     1094    /**
    10551095     * WebKitWebView::navigation-policy-decision-requested:
    10561096     * @web_view: the object on which the signal is emitted
Note: See TracChangeset for help on using the changeset viewer.