Skip to content

Commit

Permalink
Added initial Chrome packaging support - not really working, but at l…
Browse files Browse the repository at this point in the history
…east the extension installs
  • Loading branch information
Wladimir Palant committed Apr 25, 2016
1 parent 1a74f50 commit 4262486
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 66 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/build/
/build-jpm/
/build-chrome/
/node_modules/
*.xpi
*.crx
*.zip
*.pyc
*.sh
*.pem
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If all the dependencies are installed building EasyPasswords is simply a matter

gulp xpi

This will create a package inside the `build` directory with the file name like `easypasswords@palant.de-n.n.n.xpi` that you can install in Firefox.
This will create a package inside the `build-jpm` directory with the file name like `easypasswords@palant.de-n.n.n.xpi` that you can install in Firefox.

How to test
-----------
Expand Down
24 changes: 24 additions & 0 deletions chrome/data/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>

<!--
- This Source Code is subject to the terms of the Mozilla Public License
- version 2.0 (the "License"). You can obtain a copy of the License at
- http://mozilla.org/MPL/2.0/.
-->

<html>
<head>
<meta charset="utf-8">
<title data-l10n-id="options-title"></title>
<link rel="stylesheet" href="options.css">
</head>
<body>
<label for="autolock" data-l10n-id="autolock_title"></label>
<div class="subtitle" data-l10n-id="autolock_description"></div>
<input type="checkbox" id="autolock" checked>

<label for="autolock_delay" data-l10n-id="autolock_delay_title"></label>
<div class="subtitle" data-l10n-id="autolock_delay_description"></div>
<input type="number" id="autolock_delay" value="10" min="0">
</body>
</html>
13 changes: 13 additions & 0 deletions chrome/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

require("sdk/simple-storage").init.then(() =>
{
require("../../lib/masterPassword");
require("../../lib/passwords");
});
12 changes: 12 additions & 0 deletions chrome/lib/sdk/event/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

exports.emit = function(obj)
{
obj.emit.apply(obj, [].slice.call(arguments, 1));
}
47 changes: 47 additions & 0 deletions chrome/lib/sdk/event/target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

let proto = {
on: function(eventName, listener)
{
if (!(eventName in this._listeners))
this._listeners[eventName] = [];
this._listeners[eventName].push(listener);
},

off: function(eventName, listener)
{
let index = (eventName in this._listeners ? this._listeners[eventName].indexOf(listener) : -1);
if (index >= 0)
this._listeners[eventName].splice(index, 1);
},

once: function(eventName, listener)
{
let wrapper = () =>
{
this.off(eventName, wrapper);
listener.apply(this, arguments);
};
this.on(eventName, wrapper);
},

emit: function(eventName)
{
let args = [].slice.call(arguments, 1);
for (let listener of this._listeners[eventName] || [])
listener.apply(null, args);
}
};

exports.EventTarget = function()
{
let result = Object.create(proto);
result._listeners = [];
return result;
};
15 changes: 15 additions & 0 deletions chrome/lib/sdk/page-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

exports.Page = function(options)
{
this.frame = document.createElement("iframe");
document.body.appendChild(this.frame);

this.frame.src = options.contentURL;
};
16 changes: 16 additions & 0 deletions chrome/lib/sdk/self.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

/* global chrome */

exports.data = {
url: function(path)
{
return chrome.runtime.getURL("data/" + path);
}
};
18 changes: 18 additions & 0 deletions chrome/lib/sdk/simple-prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

exports.prefs = window.simpleStorage;

exports.on = function(key, handler)
{
window.addEventListener("storage", function(event)
{
if (event.key == key)
handler();
});
};
27 changes: 27 additions & 0 deletions chrome/lib/sdk/simple-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

/* global chrome */

exports.init = new Promise((resolve, reject) =>
{
chrome.storage.local.get("passwords", function(items)
{
if (chrome.runtime.lastError)
reject(chrome.runtime.lastError);
else
{
exports.storage = items.passwords;
setTimeout(function()
{
chrome.storage.local.set({passwords: exports.storage});
}, 30000);
resolve();
}
});
});
11 changes: 11 additions & 0 deletions chrome/lib/sdk/timers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/

"use strict";

exports.setTimeout = window.setTimeout;
exports.setInterval = window.setInterval;
exports.clearTimeout = window.clearTimeout;
Loading

0 comments on commit 4262486

Please sign in to comment.