-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from the8472/fs-uris
support for fs: URIs without redirecting to http: - disabled by default - implements #48
- Loading branch information
Showing
10 changed files
with
236 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "4.1" | ||
sudo: false | ||
addons: | ||
apt: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const {Ci} = require('chrome') | ||
const events = require('sdk/system/events') | ||
const gw = require('./gateways.js') | ||
|
||
/* | ||
const catman = Cc['@mozilla.org/categorymanager;1'].getService(CI.nsICategoryManager) | ||
// category ("net-channel-event-sinks") | ||
catman.addCategoryEntry(in string aCategory, in string aEntry, in string aValue, in boolean aPersist, in boolean aReplace) | ||
*/ | ||
|
||
function fixupRequest (e) { | ||
if (e.type !== 'http-on-modify-request') { | ||
return | ||
} | ||
if (!gw.fsUris) { | ||
return | ||
} | ||
const channel = e.subject.QueryInterface(Ci.nsIHttpChannel) | ||
|
||
channel.QueryInterface(Ci.nsIHttpChannelInternal) | ||
channel.QueryInterface(Ci.nsIPropertyBag2) | ||
channel.QueryInterface(Ci.nsIPropertyBag) | ||
|
||
let isIpfsReq = null | ||
try { | ||
isIpfsReq = channel.hasKey('ipfs-uri') | ||
} catch (e) { | ||
// console.log(e) | ||
} | ||
|
||
if (isIpfsReq && channel.originalURI.scheme === 'fs') { | ||
/* | ||
// TODO: investigate effects of the following flags | ||
// cookies make no sense in the ipfs context, we don't want to carry different gateway cookies into the page | ||
channel.loadFlags |= Ci.nsIRequest.LOAD_ANONYMOUS | ||
// should only do that for /ipfs/ paths since those are stable | ||
channel.loadFlags |= Ci.nsIRequest.VALIDATE_NEVER | ||
*/ | ||
|
||
// prevent redirects from replacing the effective URI | ||
channel.loadFlags &= ~Ci.nsIChannel.LOAD_REPLACE | ||
|
||
} | ||
|
||
} | ||
|
||
events.on('http-on-modify-request', fixupRequest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
'use strict' | ||
|
||
const { before, after } = require('sdk/test/utils') | ||
const { before } = require('sdk/test/utils') | ||
const { prefs } = require('sdk/simple-prefs') | ||
|
||
exports.storePrefs = (backup) => { | ||
// console.log('Backing up simple-prefs') | ||
if (!backup) { | ||
backup = new Map() | ||
} | ||
for (let key in prefs) { | ||
backup.set(key, prefs[key]) | ||
} | ||
return backup | ||
const backup = new Map() | ||
|
||
for (let key in prefs) { | ||
backup.set(key, prefs[key]) | ||
} | ||
|
||
exports.restorePrefs = (backup) => { | ||
function restorePrefs () { | ||
// console.log('Restoring simple-prefs') | ||
for (let [key, data] of backup) { | ||
prefs[key] = data | ||
} | ||
} | ||
|
||
exports.restorePrefs = restorePrefs | ||
|
||
exports.isolateTestCases = (testCases) => { | ||
let backup = null | ||
before(testCases, (name, assert) => { | ||
backup = exports.storePrefs() | ||
}) | ||
after(testCases, (name, assert) => { | ||
exports.restorePrefs(backup) | ||
restorePrefs() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict' | ||
|
||
const tabs = require('sdk/tabs') | ||
const protocols = require('../lib/protocols.js') | ||
const fsFactory = protocols.fs | ||
|
||
protocols.register() | ||
|
||
const fs = fsFactory.createInstance() | ||
const gw = require('../lib/gateways.js') | ||
const self = require('sdk/self') | ||
const testpage = self.data.url('linkify-demo.html') | ||
const sripage = 'fs:/ipfs/QmSrCRJmzE4zE1nAfWPbzVfanKQNBhp7ZWmMnEdbiLvYNh/mdown#sample.md' | ||
const parent = require('sdk/remote/parent') | ||
|
||
const childMain = require.resolve('../lib/child-main.js') | ||
|
||
parent.remoteRequire(childMain) | ||
|
||
const {Cc, Ci} = require('chrome') | ||
const ioservice = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService) | ||
|
||
ioservice.newURI('fs:/ipns/foo', null, null) | ||
|
||
exports['test newURI'] = function (assert) { | ||
require('sdk/simple-prefs').prefs.fsUris = true | ||
|
||
assert.equal(fs.newURI('fs:/ipns/foo', null, null).spec, 'fs:/ipns/foo', 'keeps fs:/ uris as-is') | ||
} | ||
|
||
exports['test newChannel'] = function (assert) { | ||
require('sdk/simple-prefs').prefs.fsUris = true | ||
gw.redirectEnabled = false | ||
|
||
let uri = fs.newURI('fs:///ipns/foo', null, null) | ||
let chan = fs.newChannel(uri) | ||
|
||
assert.equal(chan.originalURI.spec, 'fs:/ipns/foo', "keeps fs: URI as channel's originalURI") | ||
|
||
// double and triple slashes lead to gateway redirects, which cause CORS troubles -> check normalization | ||
assert.equal(chan.URI.spec, 'https://ipfs.io/ipns/foo', 'redirect off, channel has normalized http urls') | ||
|
||
gw.redirectEnabled = true | ||
|
||
chan = fs.newChannel(uri) | ||
|
||
assert.equal(chan.URI.spec, 'http://127.0.0.1:8080/ipns/foo', 'redirect on, channel has normalized http urls') | ||
} | ||
|
||
// https://github.com/lidel/ipfs-firefox-addon/issues/3 | ||
exports['test subresource loading'] = function (assert, done) { | ||
require('sdk/simple-prefs').prefs.fsUris = true | ||
gw.redirectEnabled = false | ||
|
||
tabs.open({ | ||
url: testpage, | ||
onReady: (tab) => { | ||
|
||
// first load somehow doesn't have protocol handlers registered. so load resource:// first, then redirect to fs:/ page | ||
if (tab.url !== sripage) { | ||
tab.url = sripage | ||
tab.reload() | ||
return | ||
} | ||
|
||
let worker = tab.attach({ | ||
contentScript: ` | ||
let obs = new MutationObserver(function(mutations) { | ||
let result = (document.querySelector("#ipfs-markdown-reader") instanceof HTMLHeadingElement) | ||
self.port.emit("test result", {result: result}) | ||
}) | ||
obs.observe(document.body,{childList: true}) | ||
` | ||
}) | ||
worker.port.on('test result', (msg) => { | ||
assert.equal(msg.result, true, 'subresource loaded successfully') | ||
|
||
require('sdk/simple-prefs').prefs.fsUris = false | ||
tab.close(done) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
require('./prefs-util.js').isolateTestCases(exports) | ||
require('sdk/test').run(exports) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters