[Pkg-mozext-commits] [autofill-forms] 01/10: a better async method that allows reaching background tabs
David Prévot
taffit at moszumanska.debian.org
Fri May 27 19:28:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository autofill-forms.
commit 7ec5eaabd8b4b6c801863a622e02860607ec5101
Author: Sarah Avilov <sarah.avilov at gmail.com>
Date: Sat May 21 14:59:53 2016 +0430
a better async method that allows reaching background tabs
---
aff.xpi | Bin 152640 -> 153765 bytes
chrome.manifest | 2 ++
chrome/content/autofillForms.js | 59 +++++++++++++++++++++++++-----
chrome/content/sdk.js | 77 ++++++++++++++++++++++++++++++++++++++++
install.rdf | 2 +-
5 files changed, 130 insertions(+), 10 deletions(-)
diff --git a/aff.xpi b/aff.xpi
index 712d2c7..33c30c7 100644
Binary files a/aff.xpi and b/aff.xpi differ
diff --git a/chrome.manifest b/chrome.manifest
index 82f2961..057f4f8 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -27,3 +27,5 @@ style chrome://autofillforms/content/autofillFormsOptions.xul chrome://autofil
style chrome://autofillforms/content/autofillFormsOptions.xul chrome://autofillforms/skin/autofillFormsOptions1.5.css appversion<2.0
style chrome://browser/content/browser.xul chrome://autofillforms/skin/autofillFormsMac.css appversion>=3.0 os=Darwin
style chrome://global/content/customizeToolbar.xul chrome://autofillforms/skin/autofillFormsMac.css appversion>=3.0 os=Darwin
+
+resource autofillforms chrome/content/
diff --git a/chrome/content/autofillForms.js b/chrome/content/autofillForms.js
index eff2aff..3791ede 100644
--- a/chrome/content/autofillForms.js
+++ b/chrome/content/autofillForms.js
@@ -7,6 +7,14 @@
*/
var autofillForms = {
+ require: (function () {
+ var {require} = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
+ return require ? {
+ Worker: require('sdk/content/worker').Worker,
+ utils: require('sdk/tabs/utils'),
+ tabs: require('sdk/tabs')
+ } : {};
+ })(),
// The selected profile index:
profileIndex: null,
@@ -93,15 +101,47 @@ var autofillForms = {
action: function (elem, cmd, val) {
elem.setAttribute('data-aff-' + cmd, val);
- var wm = Components.classes['@mozilla.org/appshell/window-mediator;1']
- .getService(Components.interfaces.nsIWindowMediator);
- var browser = wm.getMostRecentWindow('navigator:browser').gBrowser.selectedBrowser;
- var mm = browser.messageManager;
- if (!browser.slScript) {
- mm.loadFrameScript('chrome://autofillforms/content/inject.js', true);
- browser.slScript = true;
+
+ var doc = elem.ownerDocument;
+ var contentWindow = doc.defaultView || doc.parentWindow;
+
+
+ function oldMethod () {
+ console.error('old Method');
+ var wm = Components.classes['@mozilla.org/appshell/window-mediator;1']
+ .getService(Components.interfaces.nsIWindowMediator);
+ var browser = wm.getMostRecentWindow('navigator:browser').gBrowser.selectedBrowser;
+ var mm = browser.messageManager;
+ if (!browser.slScript) {
+ mm.loadFrameScript('chrome://autofillforms/content/inject.js', true);
+ browser.slScript = true;
+ }
+ mm.sendAsyncMessage(cmd);
+ }
+
+ if ('Worker' in autofillForms.require && contentWindow) {
+ var tab = autofillForms.require.utils.getTabForContentWindow(contentWindow);
+ if (tab) {
+ var tabId = autofillForms.require.utils.getTabId(tab);
+ for each (let sdkTab in autofillForms.require.tabs) {
+ if (sdkTab.id === tabId) {
+ let worker = sdkTab.attach({
+ contentScriptFile: 'resource://autofillforms/sdk.js',
+ });
+ worker.port.on('done', function () {
+ worker.destroy();
+ });
+ worker.port.emit(cmd, val);
+ return;
+ }
+ }
+ }
+
+ oldMethod();
+ }
+ else {
+ oldMethod();
}
- mm.sendAsyncMessage(cmd);
},
initialize: function () {
@@ -644,7 +684,6 @@ var autofillForms = {
}
autoSubmit = autoSubmit ? autoSubmit : null;
-
if(allTabs) {
// Fill out forms on all open browser tabs:
for(var i=0; i<this.getBrowser().browsers.length; i++) {
@@ -4447,6 +4486,7 @@ var autofillForms = {
try {
var regExpObj = new RegExp(this.getDynamicTags()[j],'g');
// We use eval() here without restrictions - the given tagCode must be trusted:
+ // http://forums.mozillazine.org/viewtopic.php?f=48&t=537839&start=435
fieldRuleValue = fieldRuleValue.replace(regExpObj, eval(this.getDynamicTagCodes()[j]));
} catch(e) {
this.log(e);
@@ -5300,6 +5340,7 @@ var autofillForms = {
try {
validationResultTextBox.removeAttribute('style');
// We use eval() here without restrictions - the given tagCode must be trusted:
+ // http://forums.mozillazine.org/viewtopic.php?f=48&t=537839&start=435
validationResultTextBox.value = eval(tagCode);
} catch(e) {
validationResultTextBox.setAttribute('style', 'color:red;');
diff --git a/chrome/content/sdk.js b/chrome/content/sdk.js
new file mode 100644
index 0000000..62df9ac
--- /dev/null
+++ b/chrome/content/sdk.js
@@ -0,0 +1,77 @@
+/* global self */
+'use strict';
+
+function onchange (elem) {
+ try {
+ elem.dispatchEvent(new Event('change'));
+ elem.dispatchEvent(new Event('keydown'));
+ elem.dispatchEvent(new Event('keyup'));
+ elem.dispatchEvent(new Event('keychange'));
+ }
+ catch (e) {}
+}
+
+function toList (att) {
+ return [].concat.apply(
+ [window.document],
+ [].map.call(window.document.getElementsByTagName('iframe'), f => f.contentDocument)
+ )
+ .map(function (doc) {
+ return [].slice.call(doc.querySelectorAll(att), 0);
+ })
+ .reduce(function (a, b) {
+ return [].concat.call(a, b);
+ });
+}
+
+self.port.on('click', function () {
+ toList('[data-aff-click=true]').forEach(function (elem) {
+ elem.removeAttribute('data-aff-click');
+ elem.click();
+ });
+ self.port.emit('done');
+});
+self.port.on('submit', function () {
+ toList('[data-aff-submit=true]').forEach(function (elem) {
+ elem.removeAttribute('data-aff-submit');
+ elem.submit();
+ });
+ self.port.emit('done');
+});
+self.port.on('focus', function () {
+ toList('[data-aff-focus=true]').forEach(function (elem) {
+ elem.removeAttribute('data-aff-focus');
+ elem.focus();
+ onchange(elem);
+ });
+ self.port.emit('done');
+});
+self.port.on('change', function () {
+ toList('[data-aff-change=true]').forEach(function (elem) {
+ elem.removeAttribute('data-aff-change');
+ onchange(elem);
+ });
+ self.port.emit('done');
+});
+self.port.on('value', function () {
+ toList('[data-aff-value]').forEach(function (elem) {
+ elem.value = elem.dataset.affValue;
+ elem.removeAttribute('data-aff-value');
+ onchange(elem);
+ });
+ self.port.emit('done');
+});
+self.port.on('selectionEnd', function () {
+ toList('[data-aff-selectionEnd]').forEach(function (elem) {
+ elem.selectionEnd = elem.dataset.affSelectionend;
+ elem.removeAttribute('data-aff-selectionEnd');
+ });
+ self.port.emit('done');
+});
+self.port.on('selectionStart', function () {
+ toList('[data-aff-selectionStart]').forEach(function (elem) {
+ elem.selectionStart = elem.dataset.affSelectionstart;
+ elem.removeAttribute('data-aff-selectionstart');
+ });
+ self.port.emit('done');
+});
diff --git a/install.rdf b/install.rdf
index 94d17dc..acf8e47 100644
--- a/install.rdf
+++ b/install.rdf
@@ -9,7 +9,7 @@
<em:iconURL>chrome://autofillForms/skin/icon.png</em:iconURL>
<em:optionsURL>chrome://autofillForms/content/autofillFormsOptions.xul</em:optionsURL>
<em:homepageURL>http://firefox.add0n.com/autofill-forms.html</em:homepageURL>
- <em:version>1.1.0</em:version>
+ <em:version>1.1.1</em:version>
<em:type>2</em:type>
<em:targetApplication>
<Description>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/autofill-forms.git
More information about the Pkg-mozext-commits
mailing list