After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 692968 - Add support to handle external URIs
Add support to handle external URIs
Status: RESOLVED FIXED
Product: gnome-documents
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME documents maintainer(s)
GNOME documents maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-01-31 21:20 UTC by Fabiano Fidêncio
Modified: 2013-02-13 15:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add support to handle external URIs (2.45 KB, patch)
2013-01-31 21:20 UTC, Fabiano Fidêncio
needs-work Details | Review
Add support to handle external URIs (3.25 KB, patch)
2013-02-07 12:07 UTC, Fabiano Fidêncio
reviewed Details | Review
Add support to handle external URIs (3.25 KB, patch)
2013-02-07 12:24 UTC, Fabiano Fidêncio
accepted-commit_now Details | Review
Add support to handle external URIs (3.22 KB, patch)
2013-02-13 15:50 UTC, Fabiano Fidêncio
committed Details | Review

Description Fabiano Fidêncio 2013-01-31 21:20:13 UTC
Currently, Documents don't handle links. The patch add support to handle
(only) external URIs, leaving the anothers EV_LINK_ACTION_TYPE_*
unimplemented, at least for now.
Comment 1 Fabiano Fidêncio 2013-01-31 21:20:15 UTC
Created attachment 234937 [details] [review]
Add support to handle external URIs
Comment 2 Cosimo Cecchi 2013-02-03 14:19:57 UTC
Review of attachment 234937 [details] [review]:

Thanks for the patch! This looks mostly good - I have some comments on the code below.

::: src/preview.js
@@ +185,3 @@
     },
 
+    _launch_external_uri: function(widget, action) {

We use camel case for function names - should be _launchExternalUri

@@ +194,3 @@
+        context.set_timestamp(Gtk.get_current_event_time());
+
+        let context = screen.get_display().get_app_launch_context();

It's cleaner to use uri.startsWith(), here and below for the 'www.' check,

@@ +205,3 @@
+                    uri = parent.get_uri() + uri;
+                else
+        if (uri.indexOf("://") == -1 && uri.substring(0, 6) != "mailto:") {

I don't really understand what this piece of code is trying to do, but I see Evince performs similar checks. Would be nice to:
- comment the code a bit explaining why this URI rewriting is necessary
- split the URI rewriting in a separate function

@@ +210,3 @@
+
+        if (!Gio.AppInfo.launch_default_for_uri(uri, context, error))
+            } else {

This is not the correct way to use GErrors in JS - you don't pass the error structure down to the function but use try/catch blocks for functions that can throw exceptions (GErrors are automatically translated into thrown exceptions by the binding)

So code should do something like
try {
  Gio.AppInfo.launch_default_for_uri(uri, context);
} catch (e) {
  log('Unable... ' + e.message);
}
Comment 3 Fabiano Fidêncio 2013-02-03 14:30:08 UTC
(In reply to comment #2)
> Review of attachment 234937 [details] [review]:
> 
> Thanks for the patch! This looks mostly good - I have some comments on the code
> below.
> 
> ::: src/preview.js
> @@ +185,3 @@
>      },
> 
> +    _launch_external_uri: function(widget, action) {
> 
> We use camel case for function names - should be _launchExternalUri

Right.

> 
> @@ +194,3 @@
> +        context.set_timestamp(Gtk.get_current_event_time());
> +
> +        let context = screen.get_display().get_app_launch_context();
> 
> It's cleaner to use uri.startsWith(), here and below for the 'www.' check,

When you say "here" are you referring the "mailto" part, right?

> 
> @@ +205,3 @@
> +                    uri = parent.get_uri() + uri;
> +                else
> +        if (uri.indexOf("://") == -1 && uri.substring(0, 6) != "mailto:") {
> 
> I don't really understand what this piece of code is trying to do, but I see
> Evince performs similar checks. Would be nice to:
> - comment the code a bit explaining why this URI rewriting is necessary
> - split the URI rewriting in a separate function

Right.

> 
> @@ +210,3 @@
> +
> +        if (!Gio.AppInfo.launch_default_for_uri(uri, context, error))
> +            } else {
> 
> This is not the correct way to use GErrors in JS - you don't pass the error
> structure down to the function but use try/catch blocks for functions that can
> throw exceptions (GErrors are automatically translated into thrown exceptions
> by the binding)

Nice. It was one of my doubts :-)
I really have zero (actually, 2, this patch and the another one) experience with JS at all.

> 
> So code should do something like
> try {
>   Gio.AppInfo.launch_default_for_uri(uri, context);
> } catch (e) {
>   log('Unable... ' + e.message);
> }

Right.

Thank you for your comments and I will re-up the patch as soon as possible.
Comment 4 Fabiano Fidêncio 2013-02-03 17:40:29 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Review of attachment 234937 [details] [review] [details]:
> > 
> > Thanks for the patch! This looks mostly good - I have some comments on the code
> > below.
> > 
> > ::: src/preview.js
> > @@ +185,3 @@
> >      },
> > 
> > +    _launch_external_uri: function(widget, action) {
> > 
> > We use camel case for function names - should be _launchExternalUri
> 
> Right.
> 
> > 
> > @@ +194,3 @@
> > +        context.set_timestamp(Gtk.get_current_event_time());
> > +
> > +        let context = screen.get_display().get_app_launch_context();
> > 
> > It's cleaner to use uri.startsWith(), here and below for the 'www.' check,
> 
> When you say "here" are you referring the "mailto" part, right?

Now I remember why didn't use uri.startsWith() neither uri.contains().

    JS ERROR: !!!   Exception was: TypeError: uri.contains is not a function
    JS ERROR: !!!     message = '"uri.contains is not a function"'
    JS ERROR: !!!     fileName = '"/home/fidencio/dev/share/gnome-documents/js/preview.js"'
    JS ERROR: !!!     lineNumber = '229'
    JS ERROR: !!!     stack = '"([object GObject_Object],[object GObject_Object])@/home/fidencio/dev/share/gnome-documents/js/preview.js:229

    JS ERROR: !!!   Exception was: TypeError: uri.startsWith is not a function
    JS ERROR: !!!     message = '"uri.startsWith is not a function"'
    JS ERROR: !!!     fileName = '"/home/fidencio/dev/share/gnome-documents/js/preview.js"'
    JS ERROR: !!!     lineNumber = '226'
    JS ERROR: !!!     stack = '"([object GObject_Object],[object GObject_Object])@/home/fidencio/dev/share/gnome-documents/js/preview.js:226


> 
> > 
> > @@ +205,3 @@
> > +                    uri = parent.get_uri() + uri;
> > +                else
> > +        if (uri.indexOf("://") == -1 && uri.substring(0, 6) != "mailto:") {
> > 
> > I don't really understand what this piece of code is trying to do, but I see
> > Evince performs similar checks. Would be nice to:
> > - comment the code a bit explaining why this URI rewriting is necessary
> > - split the URI rewriting in a separate function
> 
> Right.
> 
> > 
> > @@ +210,3 @@
> > +
> > +        if (!Gio.AppInfo.launch_default_for_uri(uri, context, error))
> > +            } else {
> > 
> > This is not the correct way to use GErrors in JS - you don't pass the error
> > structure down to the function but use try/catch blocks for functions that can
> > throw exceptions (GErrors are automatically translated into thrown exceptions
> > by the binding)
> 
> Nice. It was one of my doubts :-)
> I really have zero (actually, 2, this patch and the another one) experience
> with JS at all.
> 
> > 
> > So code should do something like
> > try {
> >   Gio.AppInfo.launch_default_for_uri(uri, context);
> > } catch (e) {
> >   log('Unable... ' + e.message);
> > }
> 
> Right.
> 
> Thank you for your comments and I will re-up the patch as soon as possible.
Comment 5 Cosimo Cecchi 2013-02-07 11:52:02 UTC
I tried applying your patch and changing it to use startsWith() and it seemed to work fine for a document with a simple http URL...can you post the patch with the new code?
For debugging you can also find the type of an object with the typeof(object) function.
Comment 6 Fabiano Fidêncio 2013-02-07 12:07:45 UTC
Created attachment 235381 [details] [review]
Add support to handle external URIs
Comment 7 Cosimo Cecchi 2013-02-07 12:12:32 UTC
Review of attachment 235381 [details] [review]:

Generally, in Documents code I always use single quotes for strings that are not translated and double quotes for translated strings.

::: src/preview.js
@@ +186,3 @@
 
+    _uriRewrite: function(uri) {
+        if (uri.substring(0, 6) != "mailto:") {

Shouldn't you check for www. instead of mailto here?
Comment 8 Fabiano Fidêncio 2013-02-07 12:19:25 UTC
(In reply to comment #7)
> Review of attachment 235381 [details] [review]:
> 
> Generally, in Documents code I always use single quotes for strings that are
> not translated and double quotes for translated strings.

Right, I'll change it.

> 
> ::: src/preview.js
> @@ +186,3 @@
> 
> +    _uriRewrite: function(uri) {
> +        if (uri.substring(0, 6) != "mailto:") {
> 
> Shouldn't you check for www. instead of mailto here?

Yes! It was a wrong sed. :-p
Comment 9 Fabiano Fidêncio 2013-02-07 12:24:07 UTC
Created attachment 235383 [details] [review]
Add support to handle external URIs
Comment 10 Cosimo Cecchi 2013-02-13 15:38:01 UTC
Review of attachment 235383 [details] [review]:

Looks good with this minor comment fixed.

::: src/preview.js
@@ +232,3 @@
+            Gio.AppInfo.launch_default_for_uri(uri, context)
+        } catch (e) {
+    _launchExternalUri: function(widget, action) {

Should be e.message
Comment 11 Fabiano Fidêncio 2013-02-13 15:50:57 UTC
Created attachment 235900 [details] [review]
Add support to handle external URIs
Comment 12 Cosimo Cecchi 2013-02-13 15:51:56 UTC
Attachment 235900 [details] pushed as 8718f18 - Add support to handle external URIs