Browse Source

Display GUI when accessed from a browser

release/v0.1
rohvsh 8 years ago
parent
commit
b15b64f4f0
  1. 99
      iguana/example.js
  2. 10
      iguana/iguana_rpc.c
  3. 7
      iguana/manifest.json

99
iguana/example.js

@ -46,23 +46,98 @@ function errorHandler(e,callback,name) {
}
var fileSystem=null;
var files={};
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
fileSystem = fs;
function copyHelpFiles(callback) {
var helpFiles = [
'agent.md',
'bootstrap-theme.min.css',
'bootstrap.min.css',
'bootstrap.min.js',
'field.html',
'field.md',
'footer.html',
'footer.md',
'formfooter.html',
'formfooter.md',
'formheader.html',
'formheader.md',
'header.html',
'header.md',
'html5shiv.min.js',
'jquery-ui.css',
'jquery-ui.min.js',
'jquery.min.js',
'mime.json',
'respond.min.js'
];
var rootDir='help';
var $dfds = $.map(helpFiles,function(fname){
var $dfd=$.Deferred();
$.get(chrome.runtime.getURL(rootDir+'/'+fname))
.done(function(str){
fileSystem.root.getFile('/'+rootDir+'/'+fname, {
create: true
}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function() {
console.log('Write completed.',fname,str.length);
$dfd.resolve(true);
};
fileWriter.onerror = function(e) {
console.log('Write failed: ',fname, e.toString());
$dfd.resolve(false);
};
// Create a new Blob and write it to log.txt.
var blob = new Blob([str], {
type: 'text/plain'
});
fileWriter.write(blob);
// $dfd.resolve(true);
}, function(createWriterErr){
console.log('createWriterErr for',fname,createWriterErr);
$dfd.resolve(false);
});
}, function(createFileErr){
console.log('createFileErr for',fname,createFileErr);
$dfd.resolve(false);
});
});
return $dfd;
});
return $.when.apply($,$dfds);
}
// Called by the common.js module.
function domContentLoaded(name, tc, config, width, height) {
navigator.webkitPersistentStorage.requestQuota(10000000000,
function(bytes){
window.requestFileSystem(PERSISTENT, bytes, onInitFs, errorHandler);
common.updateStatus(
navigator.webkitPersistentStorage.requestQuota(10000000000,
function(bytes) {
window.requestFileSystem(PERSISTENT, bytes, function(fs) {
console.log('Opened file system: ' + fs.name);
fileSystem = fs;
copyHelpFiles().done(function() {
common.updateStatus(
'Allocated ' + bytes + ' bytes of persistent storage. Running the first time will take 17 seconds to load');
common.attachDefaultListeners();
common.createNaClModule(name, tc, config, width, height);
}, function(e){
console.log('Error', e);
});
common.attachDefaultListeners();
common.createNaClModule(name, tc, config, width, height);
});
/*dirReader = fs.root.createReader();
dirReader.readEntries(function(results) {
console.log(results);
}, function(){
console.log('File IO error');
});*/
}, errorHandler);
},
function(e) {
console.log('Error', e);
});
}

10
iguana/iguana_rpc.c

@ -822,7 +822,7 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize;
char symbol[16],buf[4096],urlmethod[16],*data,url[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
char symbol[16],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
@ -837,6 +837,12 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
j = i = 0;
filetype[0] = 0;
//printf("url.(%s) method.(%s)\n",&url[i],urlmethod);
#ifdef __PNACL__
char *prefix="DB/";
snprintf(furl, sizeof furl, "%s%s", prefix,url+1);
#else
snprintf(furl, sizeof furl, "%s", url+1);
#endif
if ( strcmp(&url[i],"/") == 0 && strcmp(urlmethod,"GET") == 0 )
{
static int counter;
@ -852,7 +858,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
return(filestr);
else return(clonestr("{\"error\":\"cant find index7778\"}"));
}
else if ( (filestr= OS_filestr(&filesize,url+1)) != 0 )
else if ( (filestr= OS_filestr(&filesize,furl)) != 0 )
{
*jsonflagp = 1;
for (i=(int32_t)strlen(url)-1; i>0; i--)

7
iguana/manifest.json

@ -16,6 +16,9 @@
"128": "icon128.png"
},
"minimum_chrome_version": "36",
"web_accessible_resources":[
"help/*"
],
"permissions": [
{ "socket": [
"tcp-listen:*:*",
@ -26,7 +29,9 @@
]
},
"unlimitedStorage",
{"fileSystem": ["write"]},
{"fileSystem": ["write",
"retainEntries",
"directory"]},
"storage",
"system.storage",
"system.display",

Loading…
Cancel
Save