The default bug view has changed. See this FAQ.

btoa function is not defined in frame scripts

RESOLVED FIXED in mozilla8

Status

()

Core
IPC
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: Felipe, Assigned: jdm)

Tracking

({dev-doc-complete})

unspecified
mozilla8
x86_64
Linux
dev-doc-complete
Points:
---

Firefox Tracking Flags

(fennec-)

Details

(Whiteboard: [inbound], URL)

Attachments

(2 attachments, 3 obsolete attachments)

(Reporter)

Description

6 years ago
+++ This bug was initially created as a clone of Bug #622224 +++

The "btoa" function running in the frame script (see bug URL) sometimes works and sometimes is undefined.

I haven't found the right pattern yet. The function is called from a OnLocationChange listener, and when I open a url with a <iframe> (like "data:text/html,<iframe>" ) it always happen, but I'm not sure that's the only case.
(Reporter)

Comment 1

6 years ago
Created attachment 541817 [details] [diff] [review]
Debug

This is spewing a warning in debug builds so this should make it easier to see where that's coming from
Attachment #541817 - Flags: review?(mark.finkle)
FWIW, you might be able to work around this by using |content.btoa()|.  That wouldn't have worked for bug 622224.  But we should fix this anyway.
Comment on attachment 541817 [details] [diff] [review]
Debug

Try cjones' idea too
Attachment #541817 - Flags: review?(mark.finkle) → review+
(Reporter)

Comment 4

6 years ago
Created attachment 541923 [details] [diff] [review]
Add atob/btoa to frame scripts

the warning is flooding the logs during some mochi-4, and we can't use content.btoa because that could be an untrusted function.
This happens because btoa is not part of the frame script context, and I think the function call never worked there. cjones said that the real solution is to add atob/btoa for frame scripts, this is a patch for it.
Attachment #541923 - Flags: review?(Olli.Pettay)
(Reporter)

Comment 5

6 years ago
Created attachment 541924 [details] [diff] [review]
Add atob/btoa to frame scripts

with uuid rev'ed
Attachment #541923 - Attachment is obsolete: true
Attachment #541924 - Flags: review?(Olli.Pettay)
Attachment #541923 - Flags: review?(Olli.Pettay)
Comment on attachment 541924 [details] [diff] [review]
Add atob/btoa to frame scripts

Could you add nsContentUtils::Btoa/Atob, which would do
exactly what nsGlobalWindow::Btoa/Atob do now and call the nsContentUtils
methods in nsGlobalWindow and in message manager code.

And this needs some tests.
Attachment #541924 - Flags: review?(Olli.Pettay) → review-
(Reporter)

Updated

6 years ago
Summary: btoa function is sometimes not defined in frame scripts → btoa function is not defined in frame scripts
This makes me wonder if http://mxr.mozilla.org/mozilla-central/source/mobile/chrome/content/bindings/browser.js#366 has ever worked.  I noticed it spamming while running the mochitest-browser-chrome tests.
(Assignee)

Comment 8

6 years ago
Created attachment 548556 [details] [diff] [review]
Add atob/btoa to frame scripts

Scratch that itch.
Attachment #548556 - Flags: review?(Olli.Pettay)
(Assignee)

Updated

6 years ago
Attachment #548556 - Attachment description: "btoa function is not defined in frame scripts" [ → Add atob/btoa to frame scripts
(Assignee)

Updated

6 years ago
Attachment #541924 - Attachment is obsolete: true
(Assignee)

Updated

6 years ago
Assignee: nobody → josh
Comment on attachment 548556 [details] [diff] [review]
Add atob/btoa to frame scripts

Could you remove Is8bit from nsGlobalWindow and expose also it
in nsContentUtils?
Attachment #548556 - Flags: review?(Olli.Pettay) → review-
(Assignee)

Comment 10

6 years ago
Created attachment 548561 [details] [diff] [review]
Add atob/btoa to frame scripts.

Darn, forgot to save nsGlobalWindow after removing Is8Bit last time.
Attachment #548561 - Flags: review?(Olli.Pettay)
(Assignee)

Updated

6 years ago
Attachment #548556 - Attachment is obsolete: true
Comment on attachment 548561 [details] [diff] [review]
Add atob/btoa to frame scripts.


>+    // for each character in this chunk...
>+    while (c < fragmentEnd)
>+      if (*c++ & EIGHT_BIT)
>+        return PR_FALSE;

I know you're just moving code, but could you please
fix the coding style.
while (expr) {
  stmt;
}
and same with if
Attachment #548561 - Flags: review?(Olli.Pettay) → review+
(Assignee)

Comment 12

6 years ago
http://hg.mozilla.org/integration/mozilla-inbound/rev/91aa25a681a5
Whiteboard: [inbound]
http://hg.mozilla.org/mozilla-central/rev/91aa25a681a5
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8

Comment 14

6 years ago
dev-doc-needed: I didn't find existing documentation for frame scripts, but there should be a page listing the things (like globals, events) available to frame scripts.
Keywords: dev-doc-needed
(Assignee)

Comment 15

6 years ago
That would be https://developer.mozilla.org/en/The_message_manager . Good point.
(Assignee)

Updated

6 years ago
Keywords: dev-doc-needed → dev-doc-complete

Comment 16

6 years ago
Thanks! (Tweaked that page to mention "frame scripts", since googling that term doesn't find many useful results right now.)
You need to log in before you can comment on or make changes to this bug.