Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

WIP: installUrl; addon listeners #525

Closed
wants to merge 1 commit into from

4 participants

Gregg Lind ochameau Irakli Gozalishvili KWierso
Gregg Lind
  1. stubs for listerner for all addon install events
  2. method for installUrl

TODO:

  1. should these promises resolve with the aAddon, or aAddon.id?
  2. can we trigger the doorhanger ui?
Gregg Lind WIP: installUrl; addon listeners
1.  stubs for listerner for all addon install events
2.  method for installUrl

TODO:

1.  should these promises resolve with the aAddon, or aAddon.id?
2.  can we trigger the doorhanger ui?
50c419a
ochameau ochameau commented on the diff August 21, 2012
packages/api-utils/lib/addon/installer.js
@@ -18,6 +30,57 @@ exports.ERROR_CORRUPT_FILE = AddonManager.ERROR_CORRUPT_FILE;
18 30
 exports.ERROR_FILE_ACCESS = AddonManager.ERROR_FILE_ACCESS;
19 31
 
20 32
 /**
  33
+ * `install` listener events
  34
+ *
  35
+ * https://developer.mozilla.org/en-US/docs/Addons/Add-on_Manager/InstallListener
  36
+ */
  37
+
  38
+// Listen for various install events.  Using a class here is possibly overkill.
  39
+// see git history for when this was a simpler object.
3
ochameau Collaborator
ochameau added a note August 21, 2012

Yes, looks overkill to me.

Gregg Lind
gregglind added a note August 23, 2012

I am not sure how else to the Listener here without making a class for it. Ideas welcome.

ochameau Collaborator
ochameau added a note August 23, 2012

Any standard JS way of doing, like this:

function Listener(defer) {

  return {
    onInstallEnded: function () {
      ... defer.resolve  ...
    },
    ...
  };
}

Or with prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ochameau ochameau commented on the diff August 21, 2012
packages/api-utils/lib/addon/installer.js
@@ -68,6 +118,30 @@ exports.install = function install(xpiPath) {
68 118
   return promise;
69 119
 };
70 120
 
  121
+
  122
+exports.install = exports.installFile;
  123
+
  124
+exports.installUrl = function installUrl(url,hash,mimetype){
  125
+  let { promise, resolve, reject } = defer();
  126
+
  127
+  if (mimetype === undefined) {mimetype = "application/x-xpinstall"};
  128
+  if (hash === undefined) {hash = ""};
  129
+
  130
+  // TODO, should we download the file ourselves, then go with file?
1
ochameau Collaborator
ochameau added a note August 21, 2012

It seems fine to use AddonManager.getInstallForURL here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ochameau
Collaborator

It is ok to change the resolution from id to addon if it can help your usage.
But please modify unit test. And it would be really cool to have your new method tested!

Irakli Gozalishvili Gozala commented on the diff September 13, 2012
packages/api-utils/lib/addon/installer.js
((15 lines not shown))
5 16
 const { Cc, Ci, Cu } = require("chrome");
6 17
 const { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm");
7 18
 const { defer } = require("api-utils/promise");
8 19
 const { setTimeout } = require("api-utils/timer");
  20
+const { Class, mix } = require('api-utils/heritage');
1
Irakli Gozalishvili Collaborator
Gozala added a note September 13, 2012

mix is not used, no need to import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Irakli Gozalishvili
Collaborator

@ochameau @gregglind what's a plan for this change. Do you still intend on implementing such a change ? If not please close a pull request.

KWierso KWierso closed this December 13, 2012
Irakli Gozalishvili
Collaborator

Feel free to reopen if you still find it to be relevant

Gregg Lind gregglind referenced this pull request in mozilla/testpilot2 March 28, 2013
Closed

Use the jetpack addon/installer.js once it lands #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 14, 2012
Gregg Lind WIP: installUrl; addon listeners
1.  stubs for listerner for all addon install events
2.  method for installUrl

TODO:

1.  should these promises resolve with the aAddon, or aAddon.id?
2.  can we trigger the doorhanger ui?
50c419a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 99 additions and 25 deletions. Show diff stats Hide diff stats

  1. 124  packages/api-utils/lib/addon/installer.js
124  packages/api-utils/lib/addon/installer.js
@@ -2,10 +2,22 @@
2 2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3 3
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
 
  5
+/*  Promise-style installer for a addons */
  6
+
  7
+
  8
+/*  references:
  9
+
  10
+aInstall:  https://developer.mozilla.org/en-US/docs/Addons/Add-on_Manager/AddonInstall
  11
+aAddon:    https://developer.mozilla.org/en-US/docs/Addons/Add-on_Manager/Addon
  12
+Listener:  https://developer.mozilla.org/en-US/docs/Addons/Add-on_Manager/InstallListener
  13
+
  14
+*/
  15
+
5 16
 const { Cc, Ci, Cu } = require("chrome");
6 17
 const { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm");
7 18
 const { defer } = require("api-utils/promise");
8 19
 const { setTimeout } = require("api-utils/timer");
  20
+const { Class, mix } = require('api-utils/heritage');
9 21
 
10 22
 /**
11 23
  * `install` method error codes:
@@ -18,6 +30,57 @@ exports.ERROR_CORRUPT_FILE = AddonManager.ERROR_CORRUPT_FILE;
18 30
 exports.ERROR_FILE_ACCESS = AddonManager.ERROR_FILE_ACCESS;
19 31
 
20 32
 /**
  33
+ * `install` listener events
  34
+ *
  35
+ * https://developer.mozilla.org/en-US/docs/Addons/Add-on_Manager/InstallListener
  36
+ */
  37
+
  38
+// Listen for various install events.  Using a class here is possibly overkill.
  39
+// see git history for when this was a simpler object.
  40
+
  41
+let Listener =  Class({
  42
+  initialize: function initialize(promise,resolve,reject) {
  43
+    // TODO, what should the args here be?  we need to bind to the promise.
  44
+    this.promise = promise;
  45
+    this.reject = reject;
  46
+    this.resolve = resolve;
  47
+  },
  48
+  //extends: EventTarget, // ?
  49
+  type: 'InstallEventListener',
  50
+  myself: this, // are we dancing too much here?
  51
+  onInstallEnded: function(aInstall, aAddon) {
  52
+    console.log('hooray, we finished the install!');
  53
+    aInstall.removeListener(this.myself);
  54
+    // Bug 749745: on FF14+, onInstallEnded is called just before `startup()`
  55
+    // is called, but we expect to resolve the promise only after it.
  56
+    // As startup is called synchronously just after onInstallEnded,
  57
+    // a simple setTimeout(0) is enough
  58
+    setTimeout(this.resolve, 0, aAddon); // return the whole addon
  59
+    //
  60
+  },
  61
+  onInstallFailed: function (aInstall) {
  62
+    console.log("failed");
  63
+    aInstall.removeListener(this.myself);
  64
+    console.log('I really truly failed');
  65
+    this.reject(aInstall.error);
  66
+  },
  67
+  onDownloadFailed: function(aInstall) {
  68
+    this.onInstallFailed(aInstall);
  69
+  },
  70
+  onNewInstall: function(aInstall){ console.log('NewInstall')},
  71
+  onDownloadStarted: function(aInstall){},
  72
+  onDownloadProgress: function(aInstall){},
  73
+  onDownloadEnded: function(aInstall){},
  74
+  onDownloadCancelled: function(aInstall){},
  75
+  onInstallStarted: function(aInstall){console.log('Install starting in listener')},
  76
+  onInstallCancelled: function(aInstall){},
  77
+  onExternalInstall: function(aInstall,aAddon,needsRestart){}
  78
+
  79
+  // TODO, add 'hash failure?'
  80
+});
  81
+
  82
+
  83
+/**
21 84
  * Immediatly install an addon.
22 85
  *
23 86
  * @param {String} xpiPath
@@ -26,7 +89,9 @@ exports.ERROR_FILE_ACCESS = AddonManager.ERROR_FILE_ACCESS;
26 89
  *   A promise resolved when the addon is finally installed.
27 90
  *   Resolved with addon id as value or rejected with an error code.
28 91
  */
29  
-exports.install = function install(xpiPath) {
  92
+
  93
+exports.installFile = function installFile(xpiPath) {
  94
+  console.log('into the install');
30 95
   let { promise, resolve, reject } = defer();
31 96
 
32 97
   // Create nsIFile for the xpi file
@@ -40,24 +105,9 @@ exports.install = function install(xpiPath) {
40 105
   }
41 106
 
42 107
   // Listen for installation end
43  
-  let listener = {
44  
-    onInstallEnded: function(aInstall, aAddon) {
45  
-      aInstall.removeListener(listener);
46  
-      // Bug 749745: on FF14+, onInstallEnded is called just before `startup()`
47  
-      // is called, but we expect to resolve the promise only after it.
48  
-      // As startup is called synchronously just after onInstallEnded,
49  
-      // a simple setTimeout(0) is enough
50  
-      setTimeout(resolve, 0, aAddon.id);
51  
-    },
52  
-    onInstallFailed: function (aInstall) {
53  
-      console.log("failed");
54  
-      aInstall.removeListener(listener);
55  
-      reject(aInstall.error);
56  
-    },
57  
-    onDownloadFailed: function(aInstall) {
58  
-      this.onInstallFailed(aInstall);
59  
-    }
60  
-  };
  108
+  let listener = new Listener(promise,resolve,reject);
  109
+  console.log("made a listener");
  110
+  listener.onNewInstall(); // test some pipes
61 111
 
62 112
   // Order AddonManager to install the addon
63 113
   AddonManager.getInstallForFile(file, function(install) {
@@ -68,6 +118,30 @@ exports.install = function install(xpiPath) {
68 118
   return promise;
69 119
 };
70 120
 
  121
+
  122
+exports.install = exports.installFile;
  123
+
  124
+exports.installUrl = function installUrl(url,hash,mimetype){
  125
+  let { promise, resolve, reject } = defer();
  126
+
  127
+  if (mimetype === undefined) {mimetype = "application/x-xpinstall"};
  128
+  if (hash === undefined) {hash = ""};
  129
+
  130
+  // TODO, should we download the file ourselves, then go with file?
  131
+  let listener = new Listener(promise,resolve,reject);
  132
+  console.log("made a listener");
  133
+  listener.onNewInstall();
  134
+
  135
+  AddonManager.getInstallForURL(url, function(install) {
  136
+    install.addListener(listener);
  137
+    install.install();
  138
+  },
  139
+  mimetype,
  140
+  hash
  141
+  );
  142
+  return promise;
  143
+};
  144
+
71 145
 exports.uninstall = function uninstall(addonId) {
72 146
   let { promise, resolve, reject } = defer();
73 147
 
@@ -77,14 +151,14 @@ exports.uninstall = function uninstall(addonId) {
77 151
       if (aAddon.id != addonId)
78 152
         return;
79 153
       AddonManager.removeAddonListener(listener);
80  
-      resolve();
  154
+      resolve(aAddon);
81 155
     }
82 156
   };
83 157
   AddonManager.addAddonListener(listener);
84 158
 
85 159
   // Order Addonmanager to uninstall the addon
86  
-  AddonManager.getAddonByID(addonId, function (addon) {
87  
-    addon.uninstall();
  160
+  AddonManager.getAddonByID(addonId, function (aAddon) {
  161
+    aAddon.uninstall();
88 162
   });
89 163
 
90 164
   return promise;
@@ -93,9 +167,9 @@ exports.uninstall = function uninstall(addonId) {
93 167
 exports.disable = function disable(addonId) {
94 168
   let { promise, resolve, reject } = defer();
95 169
 
96  
-  AddonManager.getAddonByID(addonId, function (addon) {
97  
-    addon.userDisabled = true;
98  
-    resolve();
  170
+  AddonManager.getAddonByID(addonId, function (aAddon) {
  171
+    aAddon.userDisabled = true;
  172
+    resolve(aAddon);
99 173
   });
100 174
 
101 175
   return promise;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.