Skip to content

Commit

Permalink
For future collaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-kehl committed Dec 11, 2017
1 parent ecba3ba commit 9ae57a4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
4 changes: 2 additions & 2 deletions extension-sequencer-client/background.html
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="utf-8">
<!--
moz-extension works in `web-ext run` OUT OF THE BOX.
Could we add moz-ext:// here programatically?:-->
moz-extension works: in `web-ext run` OUT OF THE BOX.
Could we add moz-extension:// here programatically?:-->
<!--<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src https://*; child-src 'none'; script-src 'self' moz-extension:">-->
<script type="text/javascript" src="background.js"></script>
</head>
Expand Down
4 changes: 3 additions & 1 deletion extension-sequencer-client/background.js
Expand Up @@ -12,6 +12,7 @@ browser.runtime.sendMessage( "extension-sequencer@selite.googlecode.com",
);

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/connect-src applies to XHR and Fetch
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

function loadScript(scriptURL) {
//var previousNumberOfScripts= window.document.scripts.length;
Expand All @@ -26,5 +27,6 @@ function loadScript(scriptURL) {
if( false ) {
// Loading from another extension worked, even without moz-extension:// in CSP in manifest.json of the current add-on.
//TODO check, as that was via ext-run (for the current add-on), not sure about an installed XPI.
// From pageAction error demo XPI
loadScript("moz-extension://001f3a9c-db40-49ff-ac55-c2f537f1f16c/scripts/background.js");
}
}
11 changes: 8 additions & 3 deletions extension-sequencer/manifest.json
Expand Up @@ -7,7 +7,8 @@

"applications": {
"gecko": {
"id": "extension-sequencer@selite.googlecode.com"
"id": "extension-sequencer@selite.googlecode.com",
"strict_min_version": "57.0a1"
}
},

Expand All @@ -18,11 +19,15 @@
},

"permissions": [
"management", "storage"
"management", "storage",

"idle"
],

"icons": {
"32": "shared/favicon-32x32.png",
"64": "shared/favicon-64x64.png"
}
},

"content_security_policy": "default-src 'self'; script-src 'self' blob:; object-src 'self'"
}
61 changes: 60 additions & 1 deletion shared/background.js
@@ -1,3 +1,62 @@
"use strict";

addListenerForUpdate();
addListenerForUpdate();

if( true) return; // UNTIL new SeIDE is deployed to thw world
const NEW_SELENIUM_IDE_ID= 'a6fd85ed-e919-4a43-a5af-8da18bda539f'; //@TODO change if different; and/or check versions
const OLD_SELENIUM_IDE_ID= 'a6fd85ed-e919-4a43-a5af-8da18bda539f';
const LOAD_ME= "LOAD_PLUGIN_FOR_SELENIUM_IDE";

var globalVarTest= 0;

//openTab( `aboutblank#window.navigator.registerProtocolHandler${window.navigator.registerProtocolHandler}`);
browser.management.getAll().then( extensions => {
var oldSeleniumIDEinstalled= false;
for( let ext of extensions ) {
if( ext.id===NEW_SELENIUM_IDE_ID ) { // Selenium IDE for Firefox 57+
var message= {
action: LOAD_ME
//extension_url: browser.extension.getURL()
};
browser.runtime.sendMessage( NEW_SELENIUM_IDE_ID, message, {} ).catch( error => openTab("about:blank#" +error)); // @TODO URL-encode error; have a page to show it
return;
}
// TODO only if new IDE has a different ID:
if( ext.id===OLD_SELENIUM_IDE_ID ) {
oldSeleniumIDEinstalled= true;
}
}
if( true) return; //@TODO; quiet while testing
openTab( oldSeleniumIDEinstalled
? "about:blank#Please upgrade/replace Selenium IDE first."
: "about:blank#Please install Selenium IDE first."
);
});

// For testing whether a message is guaranteed out even before the recipient add-on registers an (external) message listener. Will the message arrive here - will it be queued?
// Not using https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/alarms/create, since it fires in minute intervals only (at least in Chrome).
browser.idle.setDetectionInterval( 15 ); // minimum
browser.idle.onStateChanged.addListener( newState=>{
if( newState==='idle' ) {
console.error( 'detected-idle');

// @param sender See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/MessageSender -> url (to a page, not just a prefix), id
browser.runtime.onMessageExternal.addListener( (message, sender, sendResponse)=>{
console.error( `onMessageExternal handler: ${message}, ${sender}, ${sendResponse}`);
// load .js from the other extension; that .js should openTab()


//synch: sendResponse( JSON-ifiable)
//asynch: see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onMessageExternal
});
}
});

console.error( `runtime.getURL: ${browser.runtime.getURL('')}`);

// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
console.error( `window.document.currentScript.src ${window.document.currentScript.src}`);

console.error( `globalVarTest ${++globalVarTest}`);

//console.error( `Blob${Blob}`);

0 comments on commit 9ae57a4

Please sign in to comment.