2014-08-27 08:01:15 +00:00
|
|
|
app = require 'app'
|
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
|
|
|
url = require 'url'
|
|
|
|
|
|
|
|
# Mapping between hostname and file path.
|
|
|
|
hostPathMap = {}
|
|
|
|
hostPathMapNextKey = 0
|
|
|
|
|
|
|
|
getHostForPath = (path) ->
|
2014-08-27 13:05:54 +00:00
|
|
|
key = "extension-#{++hostPathMapNextKey}"
|
2014-08-27 08:01:15 +00:00
|
|
|
hostPathMap[key] = path
|
|
|
|
key
|
|
|
|
|
|
|
|
getPathForHost = (host) ->
|
|
|
|
hostPathMap[host]
|
|
|
|
|
|
|
|
app.once 'ready', ->
|
|
|
|
protocol = require 'protocol'
|
|
|
|
BrowserWindow = require 'browser-window'
|
|
|
|
|
|
|
|
protocol.registerProtocol 'chrome-extension', (request) ->
|
|
|
|
parsed = url.parse request.url
|
|
|
|
return unless parsed.hostname and parsed.path?
|
|
|
|
|
2014-08-27 13:05:54 +00:00
|
|
|
return unless /extension-\d+/.test parsed.hostname
|
|
|
|
|
2014-08-27 08:01:15 +00:00
|
|
|
directory = getPathForHost parsed.hostname
|
|
|
|
return new protocol.RequestFileJob(path.join(directory, parsed.path))
|
|
|
|
|
|
|
|
BrowserWindow::loadDevToolsExtension = (srcDirectory) ->
|
|
|
|
manifest = JSON.parse fs.readFileSync(path.join(srcDirectory, 'manifest.json'))
|
|
|
|
|
|
|
|
# We can not use 'file://' directly because all resources in the extension
|
|
|
|
# will be treated as relative to the root in Chrome.
|
|
|
|
page = url.format
|
|
|
|
protocol: 'chrome-extension'
|
|
|
|
slashes: true
|
|
|
|
hostname: getHostForPath srcDirectory
|
|
|
|
pathname: manifest.devtools_page
|
|
|
|
|
|
|
|
extensionInfo = startPage: page, name: manifest.name
|
|
|
|
@devToolsWebContents?.executeJavaScript "WebInspector.addExtensions([#{JSON.stringify(extensionInfo)}]);"
|