Bug 23932 - Current API does not allow us to open target="_blank" links in new tabs instead of windows
Summary: Current API does not allow us to open target="_blank" links in new tabs inste...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2009-02-12 12:59 PST by Gustavo Noronha (kov)
Modified: 2009-03-25 05:01 PDT (History)
4 users (show)

See Also:


Attachments
Patch adding the requested feature (6.96 KB, patch)
2009-02-27 00:07 PST, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
Modified patch (7.27 KB, patch)
2009-03-03 14:57 PST, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
New patch, with Changelog included (8.23 KB, patch)
2009-03-04 14:28 PST, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
New version of the patch (8.78 KB, patch)
2009-03-23 05:19 PDT, Alejandro G. Castro
zecke: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Noronha (kov) 2009-02-12 12:59:36 PST
This is doable, and I believe Midori is able to do it, but our current API doesn't give us an easy/elegant way of doing this.
Comment 1 Alejandro G. Castro 2009-02-27 00:07:37 PST
Created attachment 28066 [details]
Patch adding the requested feature

This patch adds a signal that allows the browser to handle the new window request, if not handled we do the usual new window opening. I'm going to add also a patch to Epiphany to use this new signal.
Comment 2 Alejandro G. Castro 2009-02-27 00:35:33 PST
(In reply to comment #1)
> Created an attachment (id=28066) [review]
> Patch adding the requested feature
> 
> This patch adds a signal that allows the browser to handle the new window
> request, if not handled we do the usual new window opening. I'm going to add
> also a patch to Epiphany to use this new signal.
> 

I've uploaded the patch for Epiphany to the bugzilla of gnome, it uses this signal to handle the middle button click:

   http://bugzilla.gnome.org/show_bug.cgi?id=573357
Comment 3 Gustavo Noronha (kov) 2009-02-27 19:14:04 PST
Comment on attachment 28066 [details]
Patch adding the requested feature

Thanks for working on this; a much needed fix =).

> +static GObject *getNavigationAction(const NavigationAction& action)

The * should be close to the type here. Why not use WebKitNavigationAction here, instead of GObject, by the way? It would look more correct to me, and it's not like you're saving on casts by using GObject, right?

Otherwise looks good to me.
Comment 4 Xan Lopez 2009-02-28 07:39:39 PST
(In reply to comment #1)

+    if (!isHandled)
+        (core(m_frame)->loader()->*policyFunction)(PolicyUse);

Here you can just do webkit_web_policy_decision_use(policyDecision); (which you created earlier). Also this has a bug that we just found for the other signals, in that you have to call webkit_web_policy_decision_ignore(policyDecision); if the signal is not handled.
Comment 5 Alejandro G. Castro 2009-03-03 14:06:18 PST
(In reply to comment #3)
> (From update of attachment 28066 [details] [review])
> Thanks for working on this; a much needed fix =).
> 
> > +static GObject *getNavigationAction(const NavigationAction& action)
> 
> The * should be close to the type here. Why not use WebKitNavigationAction
> here, instead of GObject, by the way? It would look more correct to me, and
> it's not like you're saving on casts by using GObject, right?
> 

Yes, saving casts was not my intention (actually I'm seeing an unnecesary G_OBJECT cast :), the only reason to use Gobject it was reuse the old code of the function as it was. I agree with your proposal.

Thanks for the review.
Comment 6 Alejandro G. Castro 2009-03-03 14:57:23 PST
Created attachment 28240 [details]
Modified patch

I've modified the patch according to the comments: changed the type of the return value (WebKitWebNavigationAction) and modified the statements using the policy decision depending on the result of signal handling.
Comment 7 Christian Dywan 2009-03-04 11:17:18 PST
(In reply to comment #6)
> Created an attachment (id=28240) [review]
> Modified patch
> 
> I've modified the patch according to the comments: changed the type of the
> return value (WebKitWebNavigationAction) and modified the statements using the
> policy decision depending on the result of signal handling.


After looking at the patch, I'm not 100% what functionality the signal is meant to cover. It looks like it is pretty similar to what navigation-policy-decision or a create-web-view do.

Could you describe exactly what page content and according user action trigger this? I guess it must at least be anchors with a blank target, but then again, that's what create-web-view already does? And does it cover anchors with, say, "_new" or "madeuptargetname"? Does it cover the context menu item "New Window"?

I'm not sure if it's a good idea to introduce several similar signals which all say "handles new window", application developers will have a hard time implementing them.
Comment 8 Xan Lopez 2009-03-04 11:36:07 PST
(In reply to comment #7)
> Could you describe exactly what page content and according user action trigger
> this? I guess it must at least be anchors with a blank target, but then again,
> that's what create-web-view already does? And does it cover anchors with, say,
> "_new" or "madeuptargetname"? Does it cover the context menu item "New Window"?

Keep in mind that create-web-view is much more generic than this, and does not include neither a 'reason' (like 'link clicked') or state/button information. This signal overlaps a lot with navigation-action, but the problem with that one signal is that it won't include any metadata (reason, state, button, ...) for, at least, target=_blank links. I suggested fixing that, but various Apple developers told me this was by design.

One way to see it would be that this signal covers new-windows created by some navigation action, while create-web-view covers all possible cases of new 'windows' (all covered by this signal + popups, etc). They both cover different use-case cases, and I think if properly documented users will know which one they need.


Comment 9 Alejandro G. Castro 2009-03-04 14:28:25 PST
Created attachment 28284 [details]
New patch, with Changelog included

I've added the Changelog comment to the patch.
Comment 10 Alejandro G. Castro 2009-03-23 05:19:58 PDT
Created attachment 28850 [details]
New version of the patch

New version of the patch, I've reviewed the behavior when the handler returns TRUE after talking to Xan. We have also added more information about the signals to the documentation trying to clarify how to use this signal:

     * Emitted when @frame requests opening a new window. With this
     * signal the browser can use the context of the request to decide
     * about the new window. If the request is not handled the default
     * behavior is to allow opening the new window to load the url,
     * which will cause a create-web-view signal emission where the
     * browser hanbles the new window action but without information
     * of the context that caused the navigation. The following
     * navigation-policy-decision-requested emissions will load the
     * page after the creation of the new window just with the
     * information of this new navigation context, without any
     * information about the action that made this new window to be
     * opened.
Comment 11 Emilio Pozuelo Monfort 2009-03-24 12:49:29 PDT
(In reply to comment #8)
> Keep in mind that create-web-view is much more generic than this, and does not
> include neither a 'reason' (like 'link clicked') or state/button information.
> This signal overlaps a lot with navigation-action, but the problem with that
> one signal is that it won't include any metadata (reason, state, button, ...)
> for, at least, target=_blank links. I suggested fixing that, but various Apple
> developers told me this was by design.

Actually navigation-policy-decision-requested won't be emitted at all for target=_blank links, and as you point out, create-web-view doesn't have enough information. So we either need a new signal like it's done here, or implement the missing cases in the current signals (I'd prefer the later i.e. having one signal for all the "user clicks on a link" cases, but if that's not wanted due to the design, this is OK).
Comment 12 Xan Lopez 2009-03-24 13:04:24 PDT
(In reply to comment #11)
> (In reply to comment #8)
> > Keep in mind that create-web-view is much more generic than this, and does not
> > include neither a 'reason' (like 'link clicked') or state/button information.
> > This signal overlaps a lot with navigation-action, but the problem with that
> > one signal is that it won't include any metadata (reason, state, button, ...)
> > for, at least, target=_blank links. I suggested fixing that, but various Apple
> > developers told me this was by design.
> 
> Actually navigation-policy-decision-requested won't be emitted at all for
> target=_blank links, and as you point out, create-web-view doesn't have enough
> information. So we either need a new signal like it's done here, or implement
> the missing cases in the current signals (I'd prefer the later i.e. having one
> signal for all the "user clicks on a link" cases, but if that's not wanted due
> to the design, this is OK).
> 

navigation-policy-decision-requested *is* emitted, but it lacks the information to do certain things, like open them in a new tab, as commented in the bug. The signal doc in alex's comment is pretty accurate AFAIK, and I think is the best solution, because "fixing" the navigation-policy action is not an option (ie, there's nothing wrong with it, it's just that webkit gives you a lot of details about what's going on in the browser, not just one-fits-all signal).

Comment 13 Emilio Pozuelo Monfort 2009-03-24 13:45:55 PDT
(In reply to comment #12)
> navigation-policy-decision-requested *is* emitted, but it lacks the information
> to do certain things, like open them in a new tab, as commented in the bug. The
> signal doc in alex's comment is pretty accurate AFAIK, and I think is the best
> solution, because "fixing" the navigation-policy action is not an option (ie,
> there's nothing wrong with it, it's just that webkit gives you a lot of details
> about what's going on in the browser, not just one-fits-all signal).

JFTR, I've debugged this with Xan on IRC and in my case (Liferea) navigation-policy-decision-requested wasn't emitted because the create-web-view callback wasn't implemented, and navigation-policy-decision-requested is emitted after that one is processed and the new webview is ready.
Comment 14 Holger Freyther 2009-03-25 03:52:11 PDT
Comment on attachment 28850 [details]
New version of the patch

Please use the prepare-ChangeLog script in the future and who ever lands this patch please fix the coding style.



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

tabs?


> +        * WebCoreSupport/FrameLoaderClientGtk.cpp:

tabs? and maybe even in th enext lines...



>      // FIXME: I think Qt version marshals this to another thread so when we
>      // have multi-threaded download, we might need to do the same
> -    (core(m_frame)->loader()->*policyFunction)(PolicyUse);
> +    if (!isHandled)
> +        webkit_web_policy_decision_use(m_policyDecision);

please don't include this hunk in this when landing, IIRC there was another patch making these consistent!



> +    WebKitWebNavigationAction* navigationAction = getNavigationAction (action);

Coding Style, no ' ' between Action and (action) please. The other call to getNavigationAction was wrong too.
Comment 15 Xan Lopez 2009-03-25 03:57:20 PDT
(In reply to comment #14)
> >      // FIXME: I think Qt version marshals this to another thread so when we
> >      // have multi-threaded download, we might need to do the same
> > -    (core(m_frame)->loader()->*policyFunction)(PolicyUse);
> > +    if (!isHandled)
> > +        webkit_web_policy_decision_use(m_policyDecision);
> 
> please don't include this hunk in this when landing, IIRC there was another
> patch making these consistent!
> 

The other bug was about

 if (isHandled) webkit_web_policy_decision_ignore(policy);

I think. We are already using the policy if the signal is not handled in the other cases, and I think that's right.
> 
> 
> > +    WebKitWebNavigationAction* navigationAction = getNavigationAction (action);
> 
> Coding Style, no ' ' between Action and (action) please. The other call to
> getNavigationAction was wrong too.
> 

Comment 16 Holger Freyther 2009-03-25 04:15:32 PDT
(In reply to comment #15)
> (In reply to comment #14)
> > >      // FIXME: I think Qt version marshals this to another thread so when we
> > >      // have multi-threaded download, we might need to do the same
> > > -    (core(m_frame)->loader()->*policyFunction)(PolicyUse);
> > > +    if (!isHandled)
> > > +        webkit_web_policy_decision_use(m_policyDecision);
> > 
> > please don't include this hunk in this when landing, IIRC there was another
> > patch making these consistent!
> > 
> 
> The other bug was about
> 
>  if (isHandled) webkit_web_policy_decision_ignore(policy);
> 
> I think. We are already using the policy if the signal is not handled in the
> other cases, and I think that's right.

Sorry, what I meant is: It is okay to use the WebKit functions but probably should not be done in the same commit.
Comment 17 Xan Lopez 2009-03-25 04:19:03 PDT
(In reply to comment #15)
> (In reply to comment #14)
> > >      // FIXME: I think Qt version marshals this to another thread so when we
> > >      // have multi-threaded download, we might need to do the same
> > > -    (core(m_frame)->loader()->*policyFunction)(PolicyUse);
> > > +    if (!isHandled)
> > > +        webkit_web_policy_decision_use(m_policyDecision);
> > 
> > please don't include this hunk in this when landing, IIRC there was another
> > patch making these consistent!
> > 
> 
> The other bug was about
> 
>  if (isHandled) webkit_web_policy_decision_ignore(policy);
> 
> I think. We are already using the policy if the signal is not handled in the
> other cases, and I think that's right.

Ok, nevermind, he was saying we shouldn't change the style of the function call, no that the call should be removed. Didn't have coffee yet today ;)
Comment 18 Xan Lopez 2009-03-25 05:01:20 PDT
Landed in r41969 with the style changes, closing the bug.