Accessing Chrome Extension Temporary FileSystem

770 views
Skip to first unread message

Monami Ghosh

unread,
Feb 11, 2016, 6:28:30 AM2/11/16
to Native-Client-Discuss
Hi,

I have created a Chrome extension with Temporary File System. I am trying to read the file using Native Client(fread). Is it possible for Native Client to access the file system of a Chrome Extension? 

Regards,
Monami

Ben Smith

unread,
Feb 11, 2016, 1:23:49 PM2/11/16
to Native-Client-Discuss
Yes, use nacl_io and mount a Html5Filesystem. You can see an example of this in the nacl_io_demo in the Native Client SDK. You'll want to change the line to "type=TEMPORARY".

Monami Ghosh

unread,
Feb 12, 2016, 1:26:15 AM2/12/16
to Native-Client-Discuss
Thank you for the help. I have tried mounting the html5fs filesystem. When I tried opening the file, Null error is reported. 

This is how I am requesting the filesystem:
window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler1);

function onInitFs(fs) {
  fs.root.getFile('log.txt', {create: true}, function(fileEntry) {
  fileEntry.createWriter(function(fileWriter){
  fileWriter.onwriteend = function(e) {
        window.open('filesystem:chrome-extension://' + chrome.i18n.getMessage('@@extension_id') + '/temporary/' + 'log.txt');
        console.log('Write completed.');
      };

      fileWriter.onerror = function(e) {
        console.log('Write failed: ' + e.toString());
      };

      // Create a new Blob and write it to log.txt.
      var blob = new Blob(['HELLO WORLD'], {type: 'text/plain'});
      console.log('bb size:' + blob.size);
      fileWriter.write(blob);
 //fileWriter.writeLine("Another line");
}, errorHandler);

  }, errorHandler);

}

function errorHandler(){
console.log('ERROR');
}

After loading the extension, I can see the file created under the chrome extension temporary folder.

This is my Nacl code:

int mount_success = mount(
"chrome-extension://efaaglhdpajbdnjnjfjhpnigocemogmh/temporary/",                                    /* source */
        "/MyMount",                            /* target */
        "html5fs",                                /* filesystemtype */
        0,                                        /* mountflags */
        "type=PERSISTENT,expected_size=1048576"); /* data */
  PostMessage("Mounting Result: %d\n", mount_success);

Mount Value is resulting to 0.

I tried opening the file:
fp = fopen("/MyMount/log.txt","r");

Reporting NULL.

Ben Smith

unread,
Feb 12, 2016, 12:55:55 PM2/12/16
to Native-Client-Discuss
I think you want the source to be "". When mounting the html5fs, source is used to mount a subtree of the filesystem.

Monami Ghosh

unread,
Feb 17, 2016, 2:56:17 AM2/17/16
to Native-Client-Discuss
int result = mount("chrome-extension://aojbeenieckcnghnifkidjdakbekhebo/persistent/",  /* source. Use relative URL */
        "/persistent",  /* target */
"html5fs", /* filesystemtype */
0,        /* mountflags */
"type=PERSISTENT,expected_size=1048576");      /* data */
 if (!result)
 PostMessage("Mounting htmlfs successfully....");

The mount is successful.
chrome-extension://aojbeenieckcnghnifkidjdakbekhebo/persistent/ - the path of my chrome extension persistent file system.
When I try to read an existing file through nacl io it fails.

fp = fopen("/persistent/log.txt","r");
     if (!fp)
     {
        *out_error = PrintfToNewString("Entering Persistent mount");
     }

Ben Smith

unread,
Feb 18, 2016, 1:52:02 PM2/18/16
to Native-Client-Discuss
On Tuesday, February 16, 2016 at 11:56:17 PM UTC-8, Monami Ghosh wrote:
int result = mount("chrome-extension://aojbeenieckcnghnifkidjdakbekhebo/persistent/",  /* source. Use relative URL */
        "/persistent",  /* target */
"html5fs", /* filesystemtype */
0,        /* mountflags */
"type=PERSISTENT,expected_size=1048576");      /* data */
 if (!result)
 PostMessage("Mounting htmlfs successfully....");

The mount is successful.

IIRC, the mount may be successful (i.e. return 0) even if it is an invalid path.
 
chrome-extension://aojbeenieckcnghnifkidjdakbekhebo/persistent/ - the path of my chrome extension persistent file system.

Yes, but you are only allowed to access the filesystem from the same origin as the current document, so specifying the path here is not necessary or allowed.

Or am I misunderstanding, and you're trying to access the filesystem of an extension from a different origin? If so, that is not possible.
Reply all
Reply to author
Forward
0 new messages