From 80ac930684255dd24cecae70b488285a6058488e Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 1 Mar 2012 13:34:45 -0800 Subject: Optimizing URL intercepting detection Modified the way the webRequest maps to the file. --- js/controllers/document-controller.js | 9 ++++++--- js/document/html-document.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 64ff2c7e..194496a6 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -76,11 +76,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // handleWebRequest: { value: function (request) { - if (this._hackRootFlag && request.url.indexOf('js/document/templates/montage-html') !== -1) { + //TODO: Check if frameId is proper + if (this._hackRootFlag && request.parentFrameId !== -1) { //TODO: Optimize creating string - return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; - } + //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); + //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; + return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/montage-html/'))[1]}; } + } }, //////////////////////////////////////////////////////////////////// // diff --git a/js/document/html-document.js b/js/document/html-document.js index e40656a3..1691e3e4 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -486,11 +486,12 @@ exports.HTMLDocument = Montage.create(TextDocument, { if(this._document.styleSheets[i].rules === null) { //TODO: Revisit URLs and URI creation logic, very hack right now var fileUri, cssUrl, cssData, tag, query; - if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { + //TODO: Parse out relative URLs and map them to absolute + if (this._document.styleSheets[i].href.indexOf(chrome.extension.getURL('')) !== -1) { //Getting the url of the CSS file - cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; + cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];//TODO: Parse out relative URLs and map them to absolute //Creating the URI of the file (this is wrong should not be splitting cssUrl) - fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; + fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl; //Loading the data from the file cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); //Creating tag with file content @@ -506,6 +507,8 @@ exports.HTMLDocument = Montage.create(TextDocument, { tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); } } + //TODO: Parse out relative URLs and map them to absolute + //console.log(cssData.content); tag.innerHTML = cssData.content; //Looping through DOM to insert style tag at location of link element query = this._templateDocument.html.querySelectorAll(['link']); -- cgit v1.2.3