Enable more sdk modules for Thunderbird

NEW
Unassigned

Status

P2
normal
4 years ago
8 months ago

People

(Reporter: fredw, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(5 attachments, 4 obsolete attachments)

(Reporter)

Description

4 years ago
This is essentially like bug 1023661 but for Thunderbird. I expect that the same patches will work.
(Reporter)

Updated

4 years ago
Assignee: nobody → fred.wang
Status: NEW → ASSIGNED
Priority: -- → P2
(Reporter)

Comment 1

4 years ago
Commit

https://github.com/mozilla/addon-sdk/pull/1706/files

is causing problem because browser.chromeURL is only defined on thunderbird mac as I see here:

http://mxr.mozilla.org/comm-central/source/mail/app/profile/all-thunderbird.js

I guess something like bug 1023661 comment 29 with about:blank as the default would be best.
Group: core-security
(Reporter)

Comment 2

4 years ago
Oops, it seems that I intentionally put this bug into the core-security group and I can't undo that...
"Only members of a group can change the visibility of a bug for that group." - I can't do anything about this either.
Group: core-security
(Reporter)

Comment 4

4 years ago
Created attachment 8526697 [details] [review]
Use browser.hiddenWindowChromeURL as a fallback since browser.ChromeURL is not defined on all Thunderbird versions

This addresses issue mentioned in comment 1. about:blank didn't work because "only chrome, resource and data uris are allowed", so I've used hiddenWindowChromeURL instead:

http://mxr.mozilla.org/comm-central/source/mail/app/profile/all-thunderbird.js#326
Attachment #8526697 - Flags: review?(evold)
(Reporter)

Comment 5

4 years ago
Created attachment 8526769 [details] [review]
Declare some low-level modules compatible with Thunderbird
Attachment #8526769 - Flags: review?(evold)
(Reporter)

Comment 6

4 years ago
Here are more testing. For the record, I'm trying with a Thunderbird Nightly and git addon-sdk with attachment 8526697 [details] [review] applied, as well as similar patches as bug 1023661. I'm building addon with the command

cfx xpi --no-strip-xpi --force-use-bundled-sdk

and adding Thunderbird compatibility in install.rdf by hand.

1) lib/sdk/clipboard.js

  Tested with

  var clipboard = require("sdk/clipboard");
  clipboard.set(clipboard.get() + "Lorem ipsum dolor sit amet");

  and seems to work OK.

2) lib/sdk/panel.js

   Tested with

   var panel = require("sdk/panel").Panel({
      width: 180, height: 180,
     contentURL: "https://en.wikipedia.org/w/index.php?title=Jetpack&useformat=mobile"
   });
   panel.show();

  and raises the error

  Message: TypeError: getMostRecentBrowserWindow(...) is null
  Stack:
    make@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/panel/utils.js:236:26
setup@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/panel.js:151:16
@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/core/disposable.js:48:56
dispatch@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/method/core.js:119:12
Disposable<.initialize@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/core/disposable.js:71:17
constructor@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/core/heritage.js:146:23
@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-panel/lib/main.js:1:13
CuddlefishLoader/options<.load@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:129:18
run@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/addon/runner.js:145:19
startup/</<@resource://jid1-gaw2rqtgssq4ew-at-jetpack/addon-sdk/lib/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:870:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:749:7
this.PromiseWalker.scheduleWalkerLoop/<@resource://gre/modules/Promise-backend.js:691:37

3) lib/sdk/context-menu.js

   Tested with

   var cm = require("sdk/context-menu");
   cm.Item({
     label: "***MY MENU ITEM***",
     context: cm.PageContext()
   });

   That does not seem to raise any error at startup, but I'm not able to test it. The custom item does not appear in any context menu.

3) lib/sdk/selection.js

    Tested with

    require("sdk/selection").on('select', function () {
      require("sdk/clipboard").set("Lorem ipsum dolor sit amet");
    });

    Same as context-menu.js: that does not seem to raise any error at startup, but does not have any other effect either.
(Reporter)

Comment 7

4 years ago
Created attachment 8526802 [details] [review]
enable clipboard.js for Thunderbird
Attachment #8526802 - Flags: review?(evold)

Comment 8

4 years ago
(In reply to Frédéric Wang (:fredw) from comment #6)

> 3) lib/sdk/context-menu.js
> 
>    Tested with
> 
>    var cm = require("sdk/context-menu");
>    cm.Item({
>      label: "***MY MENU ITEM***",
>      context: cm.PageContext()
>    });
> 
>    That does not seem to raise any error at startup, but I'm not able to
> test it. The custom item does not appear in any context menu.

The Thunderbird context menu id is "mailContext". This might help.

context-menu.js:

let WindowWrapper = Class({
  initialize: function initialize(window) {
    this.window = window;
    this.menus = [
      new MenuWrapper(this, contentContextMenu, window.document.getElementById("contentAreaContextMenu")),
    ];
  },

/panel/utils.js:

function allowContextMenu(panel, allow) {
  if (allow) {
    panel.setAttribute("context", "contentAreaContextMenu");
  }
  else {
    panel.removeAttribute("context");
  }
}

Complication 1:
In the Thunderbird main 3pane window there are two context menus:
"mailContext" and "folderPaneContext"
(There used to be three so count your blessings)
I suggest contacting the TB people on irc://moznet/maildev and asking them - but probably mailContext is the more important one.

Complication 2:
SeaMonkeys 3pane window follows Thunderbird (mostly for addon-compat).
But this is out of scope for this bug.
(Reporter)

Comment 9

4 years ago
Thanks Philip. Replacing by "mailContext" does not seem to help for context-menu...

Additional note: someone also commented on the addon-sdk mailing list that the changes in bug 1071048 don't really help for Thunderbird. More specifically, lib/sdk/tabs/tab.js seems to raise js errors.

Comment 10

4 years ago
(In reply to Frédéric Wang (:fredw) from comment #9)
> Additional note: someone also commented on the addon-sdk mailing list that
> the changes in bug 1071048 don't really help for Thunderbird. More
> specifically, lib/sdk/tabs/tab.js seems to raise js errors.
The tabmail.xml implementation in Thunderbird (and SeaMonkey MailNews) is significantly different from the Firefox tabbrowser. Probably someone who understands the Thunderbird code would have to write a different view.js for TB.

Comment 11

4 years ago
(In reply to Frédéric Wang (:fredw) from comment #9)
> Thanks Philip. Replacing by "mailContext" does not seem to help for
> context-menu...
> 
> Additional note: someone also commented on the addon-sdk mailing list that
> the changes in bug 1071048 don't really help for Thunderbird. More
> specifically, lib/sdk/tabs/tab.js seems to raise js errors.

An update from my test, basically just to confirm: in the following scenario, requiring and invoking sdk/tabs#open does not cause any error, but also has no effect:

 * Tried both with dummy simple add-on and with the actual add-on I'd like to build. They include instructions like:
  console.log('*************** TABS 1 ****************');  // DEBUG
  var tabs = require("sdk/tabs");
  tabs.open("http://www.google.com");
  console.log('*************** TABS 2 ****************');  // DEBUG

 * Their XPI also included local add-on SDK code, through: cfx xpi --no-strip-xpi --force-use-bundled-sdk

 * Local add-on SDK is taken from master branch, updated to commit "Merge pull request #1733 from Gozala/detraitify-bond" from Nov 22 (https://github.com/mozilla/addon-sdk/commit/481192bf13b7eac1596a378d8b407dc9265ec18a), plus some "minimal" commits I use to make cfx work on Windows, patch install.rdf, avoid some warnings.

 * XPI were manually installed "from file" in Thunderbird Daily 36.0a1 (2014-11-21) on Windows 7 64

As said, no error showed up, code ran through smoothly (one can see both logs), but no tab was open. By watching the 'tabs' instance through remote debugger, this is how it looked like: http://i.imgur.com/ArNwFmd.png

Comment 12

4 years ago
With the same setup as above (local add-on SDK patched and added to XPI, XPI manually loaded into same version of TB Daily), module 'page-worker' works out of the box. Tried with this sample code essentially copied from SDK docs:

    dump('\n\n------------------- START -------------------\n\n');

    var getFirstParagraph = "var paras = document.getElementsByTagName('p');" +
                            "dump('\\n\\n\\n\\n**********************\\n' + paras[0].textContent + '\\n**********************\\n\\n\\n\\n');" +
                            "self.port.emit('loaded');"

    var pageWorker = require("sdk/page-worker").Page({
      contentScript: getFirstParagraph,
      contentURL: "http://en.wikipedia.org/wiki/Chalk"
    });

    pageWorker.port.on("loaded", function() {
      pageWorker.contentURL = "http://en.wikipedia.org/wiki/Cheese"
    });

    dump('\n\n------------------- DONE --------------------\n\n');

the code runs through smoothly, and apart from tons of error reported during processing the actual wikipedia pages, console shows the two paragraphs taken from their own pages.

Comment 13

4 years ago
Created attachment 8528620 [details]
Archive with add-on to test page-mod in Thunderbird

Comment 14

4 years ago
Created attachment 8528627 [details]
Archive with add-on to test page-mod in Thunderbird
Attachment #8528620 - Attachment is obsolete: true

Comment 15

4 years ago
Created attachment 8528630 [details]
Archive with add-on to test page-worker in Thunderbird

Comment 16

4 years ago
Created attachment 8528651 [details]
Archive with add-on to test page-mod in Thunderbird

Code in previous version was completely unrelated, plain wrong (picked up old scratch file). Also, Zip included packaged XPI, which was unnecessary.

Apart from that: code runs through smoothly (start/end logs are visible) but nothing happens when HTML document opens. Not from command console, neither from Firefox remote debugging console.
Attachment #8528627 - Attachment is obsolete: true
Attachment #8526769 - Flags: review?(evold) → review+

Comment 17

4 years ago
Commits pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/ebce0d6682474d9db5225eda0d34f13aaacf91a8
Bug 1100644 - Declare some low-level modules compatible with Thunderbird. r=erikvold

https://github.com/mozilla/addon-sdk/commit/952aa10dd571a5aeea04cb887bc68c0c5ee5ff35
Merge pull request #1730 from fred-wang/thunderbird-low-level

Bug 1100644 - Declare some low-level modules compatible with Thunderbird r=erikvold
Attachment #8526802 - Flags: review?(evold) → review+

Comment 18

4 years ago
Commits pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/c1203c013a37b932337aa4d8faa5663a82f17823
Bug 1100644: enable clipboard.js for Thunderbird. r=erikvold

https://github.com/mozilla/addon-sdk/commit/32c2ec53b9b354e1c7d71186c03f8e8058518a44
Merge pull request #1732 from fred-wang/thunderbird-clipboard

Bug 1100644: enable clipboard.js for Thunderbird. r=erikvold
Comment on attachment 8526697 [details] [review]
Use browser.hiddenWindowChromeURL as a fallback since browser.ChromeURL is not defined on all Thunderbird versions

using a hidden window url doesn't seem right, is there some thunderbird code that uses this which you can point to?
Flags: needinfo?(fred.wang)
(Reporter)

Comment 20

4 years ago
(In reply to Erik Vold [:erikvold] (please needinfo? me) from comment #19)
> using a hidden window url doesn't seem right, is there some thunderbird code
> that uses this which you can point to?

No, I just read what Philip mentioned on bug 1023661 and hiddenWindowChromeURL seemed to be the only option available in http://mxr.mozilla.org/comm-central/source/mail/app/profile/all-thunderbird.js

Unfortunately, I'm not sure there is a good default URI for Thunderbird. At the moment, the problem is that browser.hiddenWindowChromeURL is only defined on Thunderbird Mac, so the module throws a javascript exception, which is even worse.
Flags: needinfo?(fred.wang)
Comment on attachment 8526697 [details] [review]
Use browser.hiddenWindowChromeURL as a fallback since browser.ChromeURL is not defined on all Thunderbird versions

I think I'd rather hard cord a url rather than use this pref, Irakli what do you think?
Attachment #8526697 - Flags: review?(evold) → review?(rFobic)
(In reply to Erik Vold [:erikvold] (please needinfo? me) from comment #21)
> Comment on attachment 8526697 [details] [review]
> Use browser.hiddenWindowChromeURL as a fallback since browser.ChromeURL is
> not defined on all Thunderbird versions
> 
> I think I'd rather hard cord a url rather than use this pref, Irakli what do
> you think?

hard code*
(Reporter)

Comment 23

4 years ago
(In reply to Erik Vold [:erikvold] (please needinfo? me) from comment #22)
> > I think I'd rather hard cord a url rather than use this pref, Irakli what do
> > you think?
> 

What about just doing

prefs.get('browser.chromeURL', '') then?

that will return a failure if the user does not provide an explicit URL, but at least that won't raise at exception when the module is loaded.
Flags: needinfo?(evold)
Comment on attachment 8526697 [details] [review]
Use browser.hiddenWindowChromeURL as a fallback since browser.ChromeURL is not defined on all Thunderbird versions

Frédéric it's not clear why would we use `browser.hiddenWindowChromeURL` it's not the url to a main window & I think results maybe quite surprising. I would rather force user to specify a URL than try to load something that is rarely useful.

Am I missing something ?
(Reporter)

Comment 25

4 years ago
Yes, that makes sense. How do I "force" the user to specify a URL. Is the suggestion in comment 23 (fail if no URL is provided) enough?
(In reply to Frédéric Wang (:fredw) from comment #23)
> (In reply to Erik Vold [:erikvold] (please needinfo? me) from comment #22)
> > > I think I'd rather hard cord a url rather than use this pref, Irakli what do
> > > you think?
> > 
> 
> What about just doing
> 
> prefs.get('browser.chromeURL', '') then?
> 
> that will return a failure if the user does not provide an explicit URL, but
> at least that won't raise at exception when the module is loaded.

That seems fine to me, I'll ni Irakli though.
Flags: needinfo?(evold) → needinfo?(rFobic)
(Reporter)

Comment 27

4 years ago
@Irakli: any update here?
(Reporter)

Updated

4 years ago
Attachment #8526697 - Flags: review?(rFobic)
(Reporter)

Comment 28

4 years ago
Created attachment 8554143 [details] [review]
Fix a Javascript exception on Thunderbird ('browser.chromeURL' undefined)
Flags: needinfo?(rFobic)
Attachment #8554143 - Flags: review?(rFobic)
Attachment #8554143 - Flags: review?(evold)
(Reporter)

Updated

4 years ago
Blocks: 1114752
What does `open` function in that case supposed to do ? Does it actually open anything if `url` isn't provided ? I think I'd much rather default to `null` and throw a clear message in `open` if `url` is falsy.
(Reporter)

Comment 30

4 years ago
(In reply to Irakli Gozalishvili [:irakli] [:gozala] [@gozala] from comment #29)
> What does `open` function in that case supposed to do ? Does it actually
> open anything if `url` isn't provided ? I think I'd much rather default to
> `null` and throw a clear message in `open` if `url` is falsy.

I think it will do the same as if the user had entered an empty URL, that is throw an exception "only chrome, resource and data uris are allowed". I agree that defaulting to null and throwing a specific message might be better.

Updated

4 years ago
Blocks: 1106414
(Reporter)

Updated

4 years ago
Attachment #8526697 - Attachment is obsolete: true
(Reporter)

Updated

4 years ago
Attachment #8554143 - Attachment is obsolete: true
Attachment #8554143 - Flags: review?(evold)
(Reporter)

Comment 31

4 years ago
Created attachment 8557086 [details] [review]
Fix a Javascript exception in Thunderbird ('browser.chromeURL' undefined)
Attachment #8557086 - Flags: review?(rFobic)
Attachment #8557086 - Flags: review?(evold)
Comment on attachment 8557086 [details] [review]
Fix a Javascript exception in Thunderbird ('browser.chromeURL' undefined)

Thanks!
Attachment #8557086 - Flags: review?(rFobic)
Attachment #8557086 - Flags: review?(evold)
Attachment #8557086 - Flags: review+

Comment 33

4 years ago
Commit pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/48d2c16852b732860b87e805f6aa3b91e6a3107c
Merge pull request #1853 from fred-wang/thunderbird-chromeURL3

Bug 1100644 - Fix a Javascript exception in Thunderbird ('browser.chromeURL' undefined) r=erikvold
(In reply to Frédéric Wang (:fredw) from comment #9)
> Thanks Philip. Replacing by "mailContext" does not seem to help for
> context-menu...
> 
> Additional note: someone also commented on the addon-sdk mailing list that
> the changes in bug 1071048 don't really help for Thunderbird. More
> specifically, lib/sdk/tabs/tab.js seems to raise js errors.

Hi Frédéric, what is the status of context-menu support in Thunderbird?

It's not in Earlybird 39.0a2 (2015-04-15) and
https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/context-menu.js
does not have it either.

Are you still working on this bug? I see some other fixes have already been merged.
(Reporter)

Comment 35

3 years ago
Hi Adrian. AFAIK all my patches have been merged into GitHub and I'm no longer working on this. Basically, some modules were claimed not to work with Thunderbird and I just verified that they actually work and fixed that in the module declaration. Other modules (including context-menu IIRC) would really need more work from Thunderbird/SeaMonkey/add-on-sdk peers to make them compatible, but that's out of my field of expertise...
(Reporter)

Updated

3 years ago
Assignee: fred.wang → nobody
Status: ASSIGNED → NEW
Thanks for quick response, Frédéric!

Would you have any links you could share about any insight you gained working on this bug.

Which addon-sdk APIs work well in thunderbird?

E.g. do you have any thunderbird jetpack add-on sources you used for testing or to actually extend thunderbird?

I would like to see whether I can extend some Firefox/Fennec add-ons I wrote for use in Thunderbird.

Thanks!
Adrian

Comment 37

3 years ago
Frédéric, thanks for all your work so far.
Can you help Adrian with these questions?

(In reply to Adrian Aichner [:anaran] from comment #36)
> Thanks for quick response, Frédéric!
> 
> Would you have any links you could share about any insight you gained
> working on this bug.
> 
> Which addon-sdk APIs work well in thunderbird?
> 
> E.g. do you have any thunderbird jetpack add-on sources you used for testing
> or to actually extend thunderbird?
> 
> I would like to see whether I can extend some Firefox/Fennec add-ons I wrote
> for use in Thunderbird.
> 
> Thanks!
> Adrian
Flags: needinfo?(fred.wang)
(Reporter)

Comment 38

3 years ago
Sorry, I missed this messaged.

Unfortunaly, my progress on this was quite disappointing for Thunderbird. Just like SeaMonkey, e10s-based modules do not work but also, since the UI is quite different, the context menu and page mod modules do not work. This makes hard to write "real-life" add-on for Thunderbird using the add-on sdk. So the only thing I've made here is:

- enable clipboard.js: So the examples to set/get clipboard here should work: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/clipboard

- fix a javascript error and make the testcase in https://bugzilla.mozilla.org/show_bug.cgi?id=1023661#c30 work again.
Flags: needinfo?(fred.wang)
You need to log in before you can comment on or make changes to this bug.