Git Product home page Git Product logo

Comments (5)

mkiol avatar mkiol commented on August 26, 2024

Thanks for this discover.

So as you suggested in Bug 858519, text should be filter out before passing data to libnotify. I would be very appreciated if you could propose javascript function that can do such filtering.

from gnotifier.

ssokolow avatar ssokolow commented on August 26, 2024

I have no experience with Firefox internals but I'll do what I can. (almost a decade ago, I tried to write extensions and found the API documentation and tooling discouragingly awful. Since the Jetpack SDK came out, I haven't needed to write an extension.)

I ran out of time today, but here's the partly-pseudo code I was able to come up with in the time given. (eg. No HTML sanitization yet and it just assumes that the notification daemon has the IMAGE_SVG capability when the site provides an SVG icon rather than rasterizing it)

The more you can clarify what you need me to do, the more I can focus my efforts.

// --== Stuff you'll probably want to call once on init ==--

var capabilities = notify_get_server_caps();
var server_info = notify_get_server_info();

var clean_markup = function(dom_node) {
    // TODO: Maybe tomorrow.
};

// --== Stuff to call each time ==--

var title = title_as_provided_by_the_api;
var body_dom = dom_firefox_generates_for_internal_notification_renderer;
var icon = icon_as_provided_by_the_api;

if (capabilities.index_of('body-markup') === -1) {
  // I'm too used to jQuery to write this on my own but here's the relevant bit of jQuery().text()
  // http://stackoverflow.com/a/5023626
  var notification = new NotifyNotification(
      title,
      jQuery(body_dom).text(),
      icon);
} else {
  var notification = new NotifyNotification(
      title,
      clean_markup(body_dom),
      icon);
}

if (capabilities.index_of('actions') !== -1 and server_info.name !== 'notify-osd') {
  // This name-matching is really how Unity's notify-osd expects you to manage its dysfunctional 
  // "if there are actions, show an old-style dialog" behaviour.

    var actions = body_dom.querySelectorAll(
        'input[type="submit"], input[type="button"], button');
    for (var i = 0; i < actions.length; ++i) {
        var dom_node = actions[i];
        var action_id = /* Whatever code you use to reconcile DOM and GTK+ events */
        var action_callback = /* Whatever code you use to reconcile DOM and GTK+ events */

        notification.add_action(
            action_id,
            jQuery(dom_node).text(),
            action_callback);
    }
}

Since I ran out of time before implementing it, here's what render_markup must do:

  1. Replace <img> tags with the contents of their alt attributes unless body-images is present in the capabilities.
  2. Subject to the effects of other rules like body-images, remove any elements which are neither text nor <b>, <big>, <i>, <sub>, <sup>, <small>, <span>, <tt>, <u>, or <s> and hoist their children to become children of their parent node.
  3. Remove all attributes except <img src=""> (assuming body-images) and <a href=""> (assuming body-hyperlinks).
  4. Use a regex like sub('\s+', ' ') to perform HTML-like normalization on text nodes since Pango renders as if white-space: pre is in effect.
  5. Replace <br> and <p> with \n since that's how Pango insists newlines be represented.
  6. If the host is GNOME Shell (I'm not sure what the exact server_info.name value is), filter markup further to only <b>, <i>, and <u> or it'll treat other tags as stuff like &lt;big&gt;.

from gnotifier.

ssokolow avatar ssokolow commented on August 26, 2024

As my not commenting yesterday implied, I'm a bit busy. Do you want me to wait until I can give code for clean_markup that will actually run or will pseudocode do?

(All my DOM manipulation experience is using either jQuery or the Python LXML DOM library so familiarizing myself with the W3C DOM API is a very non-trivial portion of the time it'll take.)

from gnotifier.

mkiol avatar mkiol commented on August 26, 2024

I think I have enough information (from you) and can do this dirty work by myself :-) Many thanks for your involvement!

from gnotifier.

mkiol avatar mkiol commented on August 26, 2024

Finally, the issue has been fixed in the latest dev xpi. It took me only 4 years! ;-)

from gnotifier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.