Closed Bug 1211401 Opened 10 years ago Closed 10 years ago

Implement chrome.runtime.sendMessage on b2g

Categories

(WebExtensions :: Untriaged, defect, P3)

defect

Tracking

(firefox46 fixed)

RESOLVED FIXED
mozilla46
Tracking Status
firefox46 --- fixed

People

(Reporter: daleharvey, Assigned: fabrice)

References

Details

(Whiteboard: [runtime])

Attachments

(3 files)

No description provided.
This is required for the password manager on Firefox OS, a content_script embedded in arbitrary web content needs the ability to send a message and receive a result from the main password manager process
https://developer.chrome.com/extensions/runtime#method-sendMessage is the chrome documentation for this, note that chrome will only allow sendMessage from a content_script if the origin has been explicitly whitelisted by the addon, for the password manager however we need this ability from arbitrary origins
Assignee: nobody → dale
Blocks: 877648
Hey Fabrice, so described what I need here and will start trying to implement it. I would really prefer to be able to prototype the implementation for desktop and then make it work on b2g, is that possible? and any pointers for implementing this api (as oposed to the tabs one) Cheers Dale
Flags: needinfo?(fabrice)
That seems to be implemented in https://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ext-runtime.js#25 Can you check on desktop? If that works fine we'll investigate why it's failing on b2g.
Flags: needinfo?(fabrice)
Blocks: 1206010
Ok so I wasted a good few weeks expecting this to not exist, was pretty dumb of me to not look into it further, apologies. Initial testing on desktop looks great, going to flesh out the demo on desktop and will then test it on b2g and see what the status is there.
So done my initial testing, its working well on desktop, ran into one major issue @ https://bugzilla.mozilla.org/show_bug.cgi?id=1212743 Now testing on b2g
So first problem E/GeckoConsole( 4122): [JavaScript Error: "TypeError: chrome.runtime is undefined" {file: "moz-extension://1de1b431-dc9b-42f4-a50d-bafd0b976ab1/js/PasswordManager.js" line: 15}] https://github.com/daleharvey/fxospwdmgr/blob/master/js/PasswordManager.js#L15 Going to look @ https://bugzilla.mozilla.org/show_bug.cgi?id=1199504 to see if I can figure out how to enable it, but Fabrice if you have an pointers, cheers
Flags: needinfo?(fabrice)
Summary: Implement chrome.runtime.sendMessage → Implement chrome.runtime.sendMessage on b2g
Whiteboard: [runtime]
Quick update, with the patch @ https://bugzilla.mozilla.org/show_bug.cgi?id=1199504 applied chrome.runtime exists, but sendMessage is not getting sent. I should hopefully be able to debug it but right now being asked to spend time on blockers
Flags: blocking-webextensions-
This is blocked and currently working on 2.5 blockers, if anyone else was able to get it going would be hugely appreciated
Assignee: dale → nobody
I submitted https://github.com/mdn/webextensions-examples/pull/12 to webextensions-examples today which I wrote to demo cs to bg messaging (works fine in Nightly Firefox on Windows XP and Linux). The initial UI shows up in Firefox OS as well (installed via WebIDE), but no message passing takes place, as evidenced by this bug. Trying to sends messages from bg to cs (by Disable/Enable Add-on) reports chrome.tabs is undefined in the bg script.
That's expected as the chrome.tabs API is not implemented yet on b2g.
Flags: needinfo?(fabrice)
Depends on: 1199504
Assignee: nobody → ferjmoreno
Trying to enable more tests I looked into that a bit. Here's some debug log: 1878 is the parent process, 1955 the child process running the mochitest. The child is sending `Extension:Message` but the parent never receives it in the Broker. I don't know why since the ChromeMessageBroadcaster is listening to this message... Bill, how is that different from the desktop e10s setup? I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Message on [object ChromeMessageBroadcaster] I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Connect on [object ChromeMessageBroadcaster] I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Message on [object ChromeMessageBroadcaster] I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Connect on [object ChromeMessageBroadcaster] I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Message on [object ContentFrameMessageManager] I/Gecko ( 1878): ZZZ MessageBroker listening to Extension:Connect on [object ContentFrameMessageManager] I/Gecko ( 1955): ZZZ MessageBroker listening to Extension:Message on [object ContentFrameMessageManager] I/Gecko ( 1955): ZZZ MessageBroker listening to Extension:Connect on [object ContentFrameMessageManager] I/Gecko ( 1878): ZZZ Creating Messenger {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","url":"moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/_blank.html"} I/Gecko ( 1878): ZZZ Messenger.onMessage runtime.onMessage {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","url":"moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/_blank.html"} I/Gecko ( 1878): ZZZ Messenger.onMessage runtime.onMessage {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","url":"moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/_blank.html"} I/Gecko ( 1878): ZZZ SingletonEventManager callback I/Gecko ( 1878): ZZZ adding broker message listener, filter is {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}"} I/Gecko ( 1878): ZZZ MessageBroker.addListener message filter is {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}"} I/Gecko ( 1955): ZZZ MessageBroker listening to Extension:Message on [object ContentFrameMessageManager] I/Gecko ( 1955): ZZZ MessageBroker listening to Extension:Connect on [object ContentFrameMessageManager] I/Gecko ( 1955): ZZZ Creating Messenger {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","frameId":0,"url":"http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_sample.html"} I/Gecko ( 1955): ZZZ Messenger.onMessage runtime.onMessage {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","frameId":0,"url":"http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_sample.html"} I/Gecko ( 1955): ZZZ Messenger.sendMessage {"id":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","frameId":0,"url":"http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest/file_sample.html"} ["moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/test_file.html","moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/test_file.html"] undefined I/Gecko ( 1955): ZZZ broker.sendMessage [object ContentFrameMessageManager] Extension:Message ["moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/test_file.html","moz-extension://6ddd8b4e-6ac6-443b-8d1d-8185b01a3bde/test_file.html"] to {"extensionId":"{0bab3193-1971-40a4-b3f6-1c7b5f232661}","messageId":1}
Flags: needinfo?(wmccloskey)
Replacing https://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ExtensionContent.jsm#85 by Service.cpmm (like in ext-runtime.js) sends the message properly to the broker in the parent, but we then fail at ExtensionUtils.jsm#557 because |this.delegate| is an empty object. I'm not sure why yet.
Blocks: 1224703
That makes things work for me on b2g (and eg. test_ext_geturl.html passes), but I haven't push to try yet.
Assignee: ferjmoreno → fabrice
Attachment #8687517 - Flags: review?(wmccloskey)
Attachment #8687517 - Flags: review?(wmccloskey)
Looks like this broke test_ext_sendmessage_doublereply.html and test_ext_sendmessage_reply.html
Blocks: 1225463
No longer blocks: 1225463
(In reply to Bill McCloskey (:billm) from comment #17) > Can you see what getWindowMessageManager is returning in this case? > http://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ > ExtensionContent.jsm#208 > http://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ > ExtensionContent.jsm#178 We get a ContentFrameMessageManager
Flags: needinfo?(fabrice)
It looks like the global message manager just doesn't work in b2g. The parent of the TabParent's message manager is null. The parent gets set here: https://dxr.mozilla.org/mozilla-central/source/dom/base/nsFrameLoader.cpp#2579 So if there's no chrome window (and I assume there isn't in b2g) then the parent will be null. Olli, do you think it would be okay to make every frame message manager be a direct child of the global message manager on b2g? I don't see what harm it could do since no one seems to be using the global message manager there.
Flags: needinfo?(bugs)
If I use the globalmessagemanager as the parent, there are still a couple other bugs to be fixed, but the test passes.
mozbrowser's message manager, when mozbrowser is in content (not in chrome), doesn't on purpose have parent. (I would need to look at the blame to find some reasoning, but at least if was the safest approach when mozbrowser was implemented). If we can ensure global message manager isn't used currently, making mozbrowser's mm child of that sounds ok to me (in case mozbrowser isn't in chrome window). Another special case, but mozbrowser has been special anyway.
Flags: needinfo?(bugs)
But, question, why isn't process message manager used here?
On desktop, at least, we need to know which tab sent the message. Eventually we'll need that for b2g too.
Hi Kershaw, we're trying to make a change in this bug where mozbrowser message managers are children of the global message manager. This causes some test failures: https://treeherder.mozilla.org/#/jobs?repo=try&revision=5d647709f169 Fabrice looked at them and they seem to be caused by special powers message listeners running multiple times. Do you think this could be related to bug 1038620? I'm having trouble understanding when the nested setup is used during b2g tests.
Flags: needinfo?(kechang)
(In reply to Bill McCloskey (:billm) from comment #24) > Hi Kershaw, we're trying to make a change in this bug where mozbrowser > message managers are children of the global message manager. This causes > some test failures: > https://treeherder.mozilla.org/#/jobs?repo=try&revision=5d647709f169 > > Fabrice looked at them and they seem to be caused by special powers message > listeners running multiple times. Do you think this could be related to bug > 1038620? I'm having trouble understanding when the nested setup is used > during b2g tests. If I am not wrong, nested oop is not used during b2g tests currently. So, I think this is not related to bug 1038620.
Flags: needinfo?(kechang)
Attached patch mm-fixSplinter Review
This makes <iframe mozbrowser>s use the global message manager as their parent, as discussed above.
Attachment #8696183 - Flags: review?(bugs)
Attached patch test-fixSplinter Review
Doing so allows us to clean up the test harness a little bit. Before we needed a special case for b2g so that we could pass in the <iframe> message manager. Now we can always use the global message manager. The try results look pretty good: https://treeherder.mozilla.org/#/jobs?repo=try&revision=a8fc2e6c5ba6 Fabrice, does that xpcshell stuff look okay to you?
Attachment #8696184 - Flags: review?(ahalberstadt)
Attachment #8696183 - Flags: review?(bugs) → review+
Yes the testing part looks fine to me. I'm checking what I can enable on top of that in bug 1224703
Comment on attachment 8696184 [details] [diff] [review] test-fix Review of attachment 8696184 [details] [diff] [review]: ----------------------------------------------------------------- This lgtm assuming b2g mochitest was the only thing passing in a non-global message manager. Might be good to include b2g reftests in the try run just in case.
Attachment #8696184 - Flags: review?(ahalberstadt) → review+
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: