Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

temporarily enabling canvas drawWindow() in regular web page

8 views
Skip to first unread message

Michael A. Puls II

unread,
Nov 6, 2009, 7:24:22 AM11/6/09
to dev-apps...@lists.mozilla.org
<https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas>
<http://mxr.mozilla.org/mozilla/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#2352>

Is there any way to enable drawWindow (via an about:config setting for
example) for a regular HTML page? I want to easily play with it.

Or, do I still have to create an extension to test it?

Thanks

--
Michael

Boris Zbarsky

unread,
Nov 6, 2009, 9:06:30 AM11/6/09
to
On 11/6/09 7:24 AM, Michael A. Puls II wrote:
> Is there any way to enable drawWindow (via an about:config setting for
> example) for a regular HTML page?

You can enablePrivilege the relevant privileges (probably
UniversalBrowserRead). Google should have some info on doing that.

-Boris

Michael A. Puls II

unread,
Nov 6, 2009, 9:44:03 AM11/6/09
to Boris Zbarsky, dev-apps...@lists.mozilla.org

Thanks.

netscape.security.PrivilegeManager.enablePrivilege();

I tried the privileges listed at
<http://www.mozilla.org/projects/security/components/signed-scripts.html#privs>,
but no single one or all of them make drawWindow allowed.

--
Michael

Boris Zbarsky

unread,
Nov 6, 2009, 9:58:02 AM11/6/09
to
On 11/6/09 9:44 AM, Michael A. Puls II wrote:
> Thanks.
>
> netscape.security.PrivilegeManager.enablePrivilege();
>
> I tried the privileges listed at
> <http://www.mozilla.org/projects/security/components/signed-scripts.html#privs>,
> but no single one or all of them make drawWindow allowed.

Either UniversalBrowserRead or UniversalXPConnect should allow it,
looking at the code. If it doesn't, you're doing something wrong in
terms of how you call enablePrivilege or in terms of how you set up your
profile (e.g. whether you set the
signed.applets.codebase_principal_support pref).

-Boris

Michael A. Puls II

unread,
Nov 6, 2009, 10:52:04 AM11/6/09
to Boris Zbarsky, dev-apps...@lists.mozilla.org

I got it working with the attached.

There's a note in
<https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas>
about it not working when handling the load event. But, it's actually
pickier than that. It won't work inside any event handler function or even
a function you call by clicking on a button. It has to be called when it's
in the top scope or FF throws a security error. (At least thats how it
seems from a regular web page.)

I see the text is drawn funny (probably because it's stretched). But, it
looks right when viewing the canvas as an image.

That's all I wanted to do for the moment. Eventually though, I want to see
if I can save a whole web page (not just what's in the viewport) as a png.

Thanks.

--
Michael

zest.html

Zack Weinberg

unread,
Nov 6, 2009, 11:35:03 AM11/6/09
to Michael A. Puls II, Boris Zbarsky, dev-apps...@lists.mozilla.org
"Michael A. Puls II" <shado...@gmail.com> wrote:
> There's a note in
> <https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas>
> about it not working when handling the load event. But, it's
> actually pickier than that. It won't work inside any event handler
> function or even a function you call by clicking on a button. It has
> to be called when it's in the top scope or FF throws a security
> error. (At least thats how it seems from a regular web page.)

Did you do the enablePrivilege call inside the same function that tries
to do drawWindow? If I remember correctly, the privilege flags are
per-function.

zw

Michael A. Puls II

unread,
Nov 6, 2009, 12:02:22 PM11/6/09
to Zack Weinberg, Boris Zbarsky, dev-apps...@lists.mozilla.org
On Fri, 06 Nov 2009 11:35:03 -0500, Zack Weinberg <zwei...@mozilla.com>
wrote:

> "Michael A. Puls II" <shado...@gmail.com> wrote:
>> There's a note in
>> <https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas>
>> about it not working when handling the load event. But, it's
>> actually pickier than that. It won't work inside any event handler
>> function or even a function you call by clicking on a button. It has
>> to be called when it's in the top scope or FF throws a security
>> error. (At least thats how it seems from a regular web page.)
>
> Did you do the enablePrivilege call inside the same function that tries
> to do drawWindow?

No.

> If I remember correctly, the privilege flags are
> per-function.

O.K. I must have missed that. Will try it.

Thanks

--
Michael

Michael A. Puls II

unread,
Nov 6, 2009, 12:41:05 PM11/6/09
to Zack Weinberg, Boris Zbarsky, dev-apps...@lists.mozilla.org
On Fri, 06 Nov 2009 11:35:03 -0500, Zack Weinberg <zwei...@mozilla.com>
wrote:

> Did you do the enablePrivilege call inside the same function that tries
> to do drawWindow?

That does the trick. Thanks.

--
Michael

Vector

unread,
Dec 3, 2009, 9:05:20 PM12/3/09
to
On Nov 6, 10:52 am, "Michael A. Puls II" <shadow2...@gmail.com> wrote:

> On Fri, 06 Nov 2009 09:58:02 -0500, Boris Zbarsky <bzbar...@mit.edu> wrote:
> > On 11/6/09 9:44 AM, Michael A. Puls II wrote:
> >> Thanks.
>
> >> netscape.security.PrivilegeManager.enablePrivilege();
>
> >> I tried the privileges listed at
> >> <http://www.mozilla.org/projects/security/components/signed-scripts.ht...>,

> >> but no single one or all of them make drawWindow allowed.
>
> > Either UniversalBrowserRead or UniversalXPConnect should allow it,  
> > looking at the code.  If it doesn't, you're doing something wrong in  
> > terms of how you call enablePrivilege or in terms of how you set up your  
> > profile (e.g. whether you set the  
> > signed.applets.codebase_principal_support pref).
>
> I got it working with the attached.
>
> There's a note in  
> <https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Renderi...>  

> about it not working when handling the load event. But, it's actually  
> pickier than that. It won't work inside any event handler function or even  
> a function you call by clicking on a button. It has to be called when it's  
> in the top scope or FF throws a security error. (At least thats how it  
> seems from a regular web page.)
>
> I see the text is drawn funny (probably because it's stretched). But, it  
> looks right when viewing the canvas as an image.
>
> That's all I wanted to do for the moment. Eventually though, I want to see  
> if I can save a whole web page (not just what's in the viewport) as a png.
>
> Thanks.
>
> --
> Michael
>
>  zest.html
> < 1KViewDownload

Thanks Michael!

0 new messages