Closed Bug 667077 Opened 8 years ago Closed 8 years ago

btoa function is not defined in frame scripts

Categories

(Core :: IPC, defect)

x86_64
Linux
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla8
Tracking Status
fennec - ---

People

(Reporter: Felipe, Assigned: jdm)

References

()

Details

(Keywords: dev-doc-complete, Whiteboard: [inbound])

Attachments

(2 files, 3 obsolete files)

+++ 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.
Attached patch DebugSplinter Review
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+
Attached patch Add atob/btoa to frame scripts (obsolete) — Splinter Review
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)
Attached patch Add atob/btoa to frame scripts (obsolete) — Splinter Review
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-
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.
Attached patch Add atob/btoa to frame scripts (obsolete) — Splinter Review
Scratch that itch.
Attachment #548556 - Flags: review?(Olli.Pettay)
Attachment #548556 - Attachment description: "btoa function is not defined in frame scripts" [ → Add atob/btoa to frame scripts
Attachment #541924 - Attachment is obsolete: true
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-
Darn, forgot to save nsGlobalWindow after removing Is8Bit last time.
Attachment #548561 - Flags: review?(Olli.Pettay)
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+
http://hg.mozilla.org/mozilla-central/rev/91aa25a681a5
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
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
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.