Provide custom JavaScript Object to Window Object

351 views
Skip to first unread message

rex...@gmail.com

unread,
Jul 6, 2015, 7:41:31 AM7/6/15
to peppe...@chromium.org
Hello,

I am working on a plugin for a chromium based browser. I need to provide a custom JS Object to the window Object.
My current plugin can provide a custom JS object (with ExecuteScript function of the PrivateInstance) and it works so far. But i can access it only if the whole page and plugin is fully loaded. That is too late. 
The Custom JS Object have to be accessible on page loading like the window object. 

For Example:

<!DOCTYPE html>
<html>

<head>

  <script>

       console.log(customObject.customFunktion());  // get error "customObject is not defined "
  
</script
</head>
<body>

<embed id="plugin" type="application/test"
          width="1" height="1"/>
</body>

The Plugin is a trusted plugin, without NaCl. I build chromium from the sources and register the plugin through "--register-pepper-plugins" flag.
Chromium and PPAPI version 41.

Is there is a way to provide a JS Object to the JS Stack (through the Plugin and/or from somewhere in the chromium code) before the page is loading? 
Or start the plugin first and then load the page.


Best Regards! 

David Michael

unread,
Jul 6, 2015, 10:55:43 AM7/6/15
to rex...@gmail.com, peppe...@chromium.org
Hi,
I'm guessing you already know that you won't be able to provide a trusted plugin to users of Google Chrome, nor any of the usual Linux Chromium distributions. So this must be your own custom Chromium fork.

On Mon, Jul 6, 2015 at 5:41 AM, <rex...@gmail.com> wrote:
Hello,

I am working on a plugin for a chromium based browser. I need to provide a custom JS Object to the window Object.
My current plugin can provide a custom JS object (with ExecuteScript function of the PrivateInstance) and it works so far. But i can access it only if the whole page and plugin is fully loaded. That is too late. 
The Custom JS Object have to be accessible on page loading like the window object. 

For Example:

<!DOCTYPE html>
<html>

<head>

  <script>

       console.log(customObject.customFunktion());  // get error "customObject is not defined "
Yes, that's to be expected. Just to double check, you're saying it would *not* be good enough for your needs to run on appropriate page load event, like onDOMContentLoaded?
 
  
</script
</head>
<body>

<embed id="plugin" type="application/test"
          width="1" height="1"/>
</body>

The Plugin is a trusted plugin, without NaCl. I build chromium from the sources and register the plugin through "--register-pepper-plugins" flag.
Chromium and PPAPI version 41.

Is there is a way to provide a JS Object to the JS Stack (through the Plugin and/or from somewhere in the chromium code) before the page is loading? 
Or start the plugin first and then load the page.
I'm not very experienced in this area, but your best bet might be by providing a custom v8 object via gin::Wrappable:
You'd also need to modify some code somewhere to get your object added at the appropriate place/time. Check the "XRefs" section in the bottom frame of CodeSearch to see example subclasses where this is used.

Though if you really need it to be available at the same time as "Window", I suppose you might need to do that via a blink object. I'm mostly ignorant of the page load sequence.
 


Best Regards! 
By the way, if there's any way you can provide what you want via JavaScript or a NaCl plugin (e.g. using the postMessageAndAwaitResponse API), I would urge you to do that. Having your own fork of Chromium is going to get your users off of the security update track, where security and security updates are the very best features Chromium has to offer.

Good luck,
-Dave


To unsubscribe from this group and stop receiving emails from it, send an email to pepper-dev+...@chromium.org.

rex...@gmail.com

unread,
Jul 7, 2015, 5:35:52 AM7/7/15
to peppe...@chromium.org, dmic...@chromium.org
Hi

I'm guessing you already know that you won't be able to provide a trusted plugin to users of Google Chrome, nor any of the usual Linux Chromium distributions. So this must be your own custom Chromium fork.
 
Yes it is for a custom Chromium.  

I'm not very experienced in this area, but your best bet might be by providing a custom v8 object via gin::Wrappable:
https://code.google.com/p/chromium/codesearch#chromium/src/gin/wrappable.h&sq=package:chromium
You'd also need to modify some code somewhere to get your object added at the appropriate place/time. Check the "XRefs" section in the bottom frame of CodeSearch to see example subclasses where this is used.
Though if you really need it to be available at the same time as "Window", I suppose you might need to do that via a blink object. I'm mostly ignorant of the page load sequence.
 
Thank you for that Tips.

But i have found a other way that fit to my needs. Maybe someone search for something like that also. 

My solution is to use chrome extensions and inject script through the content script and the "run_at": "document_start" attribute in the manifest file. It allows to inject a script tag with custom javascript in it before the page loads. Then i can use my custom object to communicate with my plugin with my custom API. 

Best Regards!
-Artjom
Reply all
Reply to author
Forward
0 new messages