Last Comment Bug 667077 - btoa function is not defined in frame scripts
: btoa function is not defined in frame scripts
Status: RESOLVED FIXED
[inbound]
: dev-doc-complete
Product: Core
Classification: Components
Component: IPC (show other bugs)
: unspecified
: x86_64 Linux
: -- normal (vote)
: mozilla8
Assigned To: Josh Matthews [:jdm]
:
Mentors:
http://mxr.mozilla.org/mozilla-centra...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-24 15:01 PDT by :Felipe Gomes (needinfo me!) [offline until Jun 24]
Modified: 2011-07-27 15:10 PDT (History)
10 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
-


Attachments
Debug (1.08 KB, patch)
2011-06-24 15:03 PDT, :Felipe Gomes (needinfo me!) [offline until Jun 24]
mark.finkle: review+
Details | Diff | Review
Add atob/btoa to frame scripts (6.07 KB, patch)
2011-06-25 05:50 PDT, :Felipe Gomes (needinfo me!) [offline until Jun 24]
no flags Details | Diff | Review
Add atob/btoa to frame scripts (6.60 KB, patch)
2011-06-25 05:52 PDT, :Felipe Gomes (needinfo me!) [offline until Jun 24]
bugs: review-
Details | Diff | Review
Add atob/btoa to frame scripts (10.83 KB, patch)
2011-07-26 13:01 PDT, Josh Matthews [:jdm]
bugs: review-
Details | Diff | Review
Add atob/btoa to frame scripts. (11.64 KB, patch)
2011-07-26 13:16 PDT, Josh Matthews [:jdm]
bugs: review+
Details | Diff | Review

Description :Felipe Gomes (needinfo me!) [offline until Jun 24] 2011-06-24 15:01:37 PDT
+++ 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.
Comment 1 :Felipe Gomes (needinfo me!) [offline until Jun 24] 2011-06-24 15:03:18 PDT
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
Comment 2 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2011-06-24 15:07:27 PDT
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 3 Mark Finkle (:mfinkle) (use needinfo?) 2011-06-24 15:25:17 PDT
Comment on attachment 541817 [details] [diff] [review]
Debug

Try cjones' idea too
Comment 4 :Felipe Gomes (needinfo me!) [offline until Jun 24] 2011-06-25 05:50:22 PDT
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.
Comment 5 :Felipe Gomes (needinfo me!) [offline until Jun 24] 2011-06-25 05:52:22 PDT
Created attachment 541924 [details] [diff] [review]
Add atob/btoa to frame scripts

with uuid rev'ed
Comment 6 Olli Pettay [:smaug] (high review load, please consider other reviewers) 2011-06-27 06:55:26 PDT
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.
Comment 7 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2011-07-12 23:42:27 PDT
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.
Comment 8 Josh Matthews [:jdm] 2011-07-26 13:01:21 PDT
Created attachment 548556 [details] [diff] [review]
Add atob/btoa to frame scripts

Scratch that itch.
Comment 9 Olli Pettay [:smaug] (high review load, please consider other reviewers) 2011-07-26 13:11:52 PDT
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?
Comment 10 Josh Matthews [:jdm] 2011-07-26 13:16:29 PDT
Created attachment 548561 [details] [diff] [review]
Add atob/btoa to frame scripts.

Darn, forgot to save nsGlobalWindow after removing Is8Bit last time.
Comment 11 Olli Pettay [:smaug] (high review load, please consider other reviewers) 2011-07-26 13:50:28 PDT
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
Comment 13 Marco Bonardo [::mak] 2011-07-27 03:40:08 PDT
http://hg.mozilla.org/mozilla-central/rev/91aa25a681a5
Comment 14 Nickolay_Ponomarev 2011-07-27 14:52:50 PDT
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.
Comment 15 Josh Matthews [:jdm] 2011-07-27 14:57:00 PDT
That would be https://developer.mozilla.org/en/The_message_manager . Good point.
Comment 16 Nickolay_Ponomarev 2011-07-27 15:10:12 PDT
Thanks! (Tweaked that page to mention "frame scripts", since googling that term doesn't find many useful results right now.)

Note You need to log in before you can comment on or make changes to this bug.