From a1f26c4c93e9bbb446527dbd8ecbd6016a490053 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 30 Jan 2015 17:45:22 -0800 Subject: [PATCH 1/5] Make file: protocol compatible with asar: protocol --- atom/browser/atom_browser_context.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 7e340867ab20..51e2a87d1c26 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -16,7 +16,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/common/url_constants.h" #include "net/url_request/data_protocol_handler.h" -#include "net/url_request/file_protocol_handler.h" #include "net/url_request/url_request_intercepting_job_factory.h" #include "url/url_constants.h" @@ -59,7 +58,7 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( job_factory->SetProtocolHandler( url::kDataScheme, new net::DataProtocolHandler); job_factory->SetProtocolHandler( - url::kFileScheme, new net::FileProtocolHandler( + url::kFileScheme, new asar::AsarProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); job_factory->SetProtocolHandler( From 8b712bac8dc3c71cb9f23057946c59f817446fd9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 30 Jan 2015 17:46:57 -0800 Subject: [PATCH 2/5] Remove the asar: protocol --- atom/browser/atom_browser_context.cc | 6 ------ spec/asar-spec.coffee | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 51e2a87d1c26..5fa88d560a79 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -25,8 +25,6 @@ namespace atom { namespace { -const char* kAsarScheme = "asar"; - class NoCacheBackend : public net::HttpCache::BackendFactory { int CreateBackend(net::NetLog* net_log, scoped_ptr* backend, @@ -61,10 +59,6 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( url::kFileScheme, new asar::AsarProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); - job_factory->SetProtocolHandler( - kAsarScheme, new asar::AsarProtocolHandler( - BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.Pass(); diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee index 8455f7cb18f5..547b7474a82b 100644 --- a/spec/asar-spec.coffee +++ b/spec/asar-spec.coffee @@ -348,47 +348,47 @@ describe 'asar package', -> assert.throws throws, /ENOENT/ describe 'asar protocol', -> + url = require 'url' + remote = require 'remote' + ipc = remote.require 'ipc' + BrowserWindow = remote.require 'browser-window' + it 'can request a file in package', (done) -> p = path.resolve fixtures, 'asar', 'a.asar', 'file1' - $.get "asar:#{p}", (data) -> + $.get "file://#{p}", (data) -> assert.equal data, 'file1\n' done() it 'can request a linked file in package', (done) -> p = path.resolve fixtures, 'asar', 'a.asar', 'link2', 'link1' - $.get "asar:#{p}", (data) -> + $.get "file://#{p}", (data) -> assert.equal data, 'file1\n' done() it 'can request a file in filesystem', (done) -> p = path.resolve fixtures, 'asar', 'file' - $.get "asar:#{p}", (data) -> + $.get "file://#{p}", (data) -> assert.equal data, 'file\n' done() it 'gets 404 when file is not found', (done) -> p = path.resolve fixtures, 'asar', 'a.asar', 'no-exist' $.ajax - url: "asar:#{p}" + url: "file://#{p}" error: (err) -> assert.equal err.status, 404 done() it 'sets __dirname correctly', (done) -> - url = require 'url' - remote = require 'remote' - ipc = remote.require 'ipc' - BrowserWindow = remote.require 'browser-window' - after -> w.destroy() ipc.removeAllListeners 'dirname' w = new BrowserWindow(show: false, width: 400, height: 400) p = path.resolve fixtures, 'asar', 'web.asar', 'index.html' - u = url.format protocol: 'asar', slashed: false, pathname: p + u = url.format protocol: 'file', slashed: true, pathname: p w.loadUrl u - ipc.on 'dirname', (event, dirname) -> + ipc.once 'dirname', (event, dirname) -> assert.equal dirname, path.dirname(p) done() From 24b5faf8dfa91c657742c7415368cf2fafb24d14 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 30 Jan 2015 17:56:31 -0800 Subject: [PATCH 3/5] spec: Test loading script tag in html --- spec/asar-spec.coffee | 13 +++++++++++++ spec/fixtures/asar/script.asar | Bin 0 -> 204 bytes 2 files changed, 13 insertions(+) create mode 100755 spec/fixtures/asar/script.asar diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee index 547b7474a82b..21203c0d4e10 100644 --- a/spec/asar-spec.coffee +++ b/spec/asar-spec.coffee @@ -392,6 +392,19 @@ describe 'asar package', -> assert.equal dirname, path.dirname(p) done() + it 'loads script tag in html', (done) -> + after -> + w.destroy() + ipc.removeAllListeners 'ping' + + w = new BrowserWindow(show: false, width: 400, height: 400) + p = path.resolve fixtures, 'asar', 'script.asar', 'index.html' + u = url.format protocol: 'file', slashed: true, pathname: p + w.loadUrl u + ipc.once 'ping', (event, message) -> + assert.equal message, 'pong' + done() + describe 'original-fs module', -> originalFs = require 'original-fs' diff --git a/spec/fixtures/asar/script.asar b/spec/fixtures/asar/script.asar new file mode 100755 index 0000000000000000000000000000000000000000..152045ad2a6bb6e1337bc70448fecde5100e3709 GIT binary patch literal 204 zcmYj}!3u&v5Qg{A$)}LHtb%AD7;NTabm~y(m=m^cI|h;LySJuLhmW5bzW?6{A literal 0 HcmV?d00001 From 37d278de345c47eb503feae55937d1ae2318791e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 31 Jan 2015 18:48:11 -0800 Subject: [PATCH 4/5] docs: Use file: instead of asar: --- docs/tutorial/application-packaging.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/tutorial/application-packaging.md b/docs/tutorial/application-packaging.md index a2dd5dabca15..6df917ad31d3 100644 --- a/docs/tutorial/application-packaging.md +++ b/docs/tutorial/application-packaging.md @@ -69,30 +69,26 @@ require('/path/to/example.asar/dir/module.js'); ### Web API -In a web page, files in archive can be requested by using the `asar:` protocol. -Like the Node API, `asar` archives are treated as directories. +In a web page, files in archive can be requested with the `file:` protocol. Like +the Node API, `asar` archives are treated as directories. For example, to get a file with `$.get`: ```html ``` -The `asar:` protocol can also be used to request normal files in filesystem, -just like the `file:` protocol. But unlike `file:` protocol, there are no -slashes (`//`) after `asar:`. - You can also display a web page in an `asar` archive with `BrowserWindow`: ```javascript var BrowserWindow = require('browser-window'); var win = new BrowserWindow({width: 800, height: 600}); -win.loadUrl('asar:/path/to/example.asar/static/index.html'); +win.loadUrl('file:///path/to/example.asar/static/index.html'); ``` ### Treating `asar` archive as normal file From 23b5c1f782a71ae1164470b874543032ccdfee40 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 31 Jan 2015 18:50:26 -0800 Subject: [PATCH 5/5] Cleanup usaages of asar: protocol --- atom/renderer/lib/init.coffee | 4 ++-- atom/renderer/lib/web-view/web-view-attributes.coffee | 2 +- atom/renderer/lib/web-view/web-view-constants.coffee | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/renderer/lib/init.coffee b/atom/renderer/lib/init.coffee index b90677462753..1d900ad349b1 100644 --- a/atom/renderer/lib/init.coffee +++ b/atom/renderer/lib/init.coffee @@ -60,8 +60,8 @@ if nodeIntegration in ['true', 'all', 'except-iframe', 'manual-enable-iframe'] global.require = require global.module = module - # Set the __filename to the path of html file if it's file: or asar: protocol. - if window.location.protocol in ['file:', 'asar:'] + # Set the __filename to the path of html file if it is file: protocol. + if window.location.protocol is 'file:' pathname = if process.platform is 'win32' and window.location.pathname[0] is '/' window.location.pathname.substr 1 diff --git a/atom/renderer/lib/web-view/web-view-attributes.coffee b/atom/renderer/lib/web-view/web-view-attributes.coffee index 00d076cdd8aa..e4b5dcb45bda 100644 --- a/atom/renderer/lib/web-view/web-view-attributes.coffee +++ b/atom/renderer/lib/web-view/web-view-attributes.coffee @@ -179,7 +179,7 @@ class PreloadAttribute extends WebViewAttribute return '' unless @webViewImpl.webviewNode.hasAttribute @name preload = resolveUrl @webViewImpl.webviewNode.getAttribute(@name) protocol = preload.substr 0, 5 - unless protocol in ['file:', 'asar:'] + unless protocol is 'file:' console.error webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE preload = '' preload diff --git a/atom/renderer/lib/web-view/web-view-constants.coffee b/atom/renderer/lib/web-view/web-view-constants.coffee index dd808f68775a..cda715423dd4 100644 --- a/atom/renderer/lib/web-view/web-view-constants.coffee +++ b/atom/renderer/lib/web-view/web-view-constants.coffee @@ -23,4 +23,4 @@ module.exports = ERROR_MSG_CANNOT_INJECT_SCRIPT: ': ' + 'Script cannot be injected into content until the page has loaded.' ERROR_MSG_INVALID_PARTITION_ATTRIBUTE: 'Invalid partition attribute.' - ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE: 'Only "file:" or "asar:" protocol is supported in "preload" attribute.' + ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE: 'Only "file:" protocol is supported in "preload" attribute.'