[Pkg-mozext-commits] [greasemonkey] 26/43: Just BARELY working script installs.

David Prévot taffit at moszumanska.debian.org
Sun Feb 22 21:56:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository greasemonkey.

commit e0f002bce37a83da4ed6e666446bc6cf994275b3
Author: Anthony Lieuallen <arantius at gmail.com>
Date:   Fri Nov 21 13:10:47 2014 -0500

    Just BARELY working script installs.
    
    Refs #2004
---
 chrome.manifest                   |  1 -
 components/greasemonkey.js        | 68 ++++-------------------------------
 content/framescript.js            | 75 +++++++++++++++++++++++++++++++++------
 modules/util/showInstallDialog.js |  4 +--
 4 files changed, 73 insertions(+), 75 deletions(-)

diff --git a/chrome.manifest b/chrome.manifest
index 72296ab..cd9a430 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -1,7 +1,6 @@
 component  {77bf3650-1cd6-11da-8cd6-0800200c9a66} components/greasemonkey.js
 contract   @greasemonkey.mozdev.org/greasemonkey-service;1 {77bf3650-1cd6-11da-8cd6-0800200c9a66}
 category   profile-after-change @greasemonkey.mozdev.org/greasemonkey-service;1 @greasemonkey.mozdev.org/greasemonkey-service;1
-category   content-policy @greasemonkey.mozdev.org/greasemonkey-service;1 @greasemonkey.mozdev.org/greasemonkey-service;1
 
 component  {20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598} components/scriptProtocol.js
 contract   @mozilla.org/network/protocol;1?name=greasemonkey-script {20d898f3-2fb8-4b3a-b8c7-7ad6c2c48598}
diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index 436209a..716fc7e 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -19,7 +19,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 
 var gStartupHasRun = false;
-var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
 
 var gFileProtocolHandler = Components
     .classes["@mozilla.org/network/protocol;1?name=file"]
@@ -30,11 +29,6 @@ var gTmpDir = Components.classes["@mozilla.org/file/directory_service;1"]
 
 /////////////////////// Component-global Helper Functions //////////////////////
 
-function isTempScript(uri) {
-  if (uri.scheme != "file") return false;
-  var file = gFileProtocolHandler.getFileFromURLSpec(uri.spec);
-  return gTmpDir.contains(file, true);
-}
 
 function shutdown(aService) {
   aService.closeAllScriptValStores();
@@ -54,6 +48,8 @@ function startup(aService) {
       .getService(Ci.nsIMessageListenerManager);
 
   messageManager.addMessageListener(
+      'greasemonkey:script-install', aService.scriptInstall.bind(aService));
+  messageManager.addMessageListener(
       'greasemonkey:scripts-for-url', aService.getScriptsForUrl.bind(aService));
 
   var scriptValHandler = aService.handleScriptValMsg.bind(aService);
@@ -88,60 +84,7 @@ function service() {
 service.prototype.classDescription = DESCRIPTION;
 service.prototype.classID = CLASSID;
 service.prototype.contractID = CONTRACTID;
-service.prototype._xpcom_categories = [{
-      // TODO: Fix.  Move to frame script?!
-      category: "content-policy",
-      entry: CONTRACTID,
-      value: CONTRACTID,
-      service: true
-    }];
-service.prototype.QueryInterface = XPCOMUtils.generateQI([
-      Ci.nsIObserver,
-      Ci.nsISupports,
-      Ci.nsISupportsWeakReference,
-      Ci.nsIWindowMediatorListener,
-      Ci.nsIContentPolicy
-    ]);
-
-/////////////////////////////// nsIContentPolicy ///////////////////////////////
-
-service.prototype.shouldLoad = function(ct, cl, org, ctx, mt, ext) {
-  var ret = Ci.nsIContentPolicy.ACCEPT;
-
-  // Don't intercept anything when GM is not enabled.
-  if (!GM_util.getEnabled()) {
-    return ret;
-  }
-
-  // Don't interrupt the "view-source:" scheme (which is triggered if the link
-  // in the error console is clicked), nor the "greasemonkey-script:" scheme.
-  if ("view-source" == cl.scheme || "greasemonkey-script" == cl.scheme) {
-    return ret;
-  }
-
-  // Do not install scripts when the origin URL "is a script".  See #1875
-  if (org && org.spec.match(gScriptEndingRegexp)) {
-    return ret;
-  }
-
-  if ((ct == Ci.nsIContentPolicy.TYPE_DOCUMENT
-       || ct == Ci.nsIContentPolicy.TYPE_SUBDOCUMENT)
-      && cl.spec.match(gScriptEndingRegexp)
-  ) {
-    if (!this._ignoreNextScript && !isTempScript(cl)) {
-      GM_util.showInstallDialog(cl.spec, ctx, this);
-      ret = Ci.nsIContentPolicy.REJECT_REQUEST;
-    }
-
-    this._ignoreNextScript = false;
-  }
-
-  return ret;
-};
-
-service.prototype.shouldProcess = function(ct, cl, org, ctx, mt, ext) {
-  return Ci.nsIContentPolicy.ACCEPT;
-};
+service.prototype.QueryInterface = XPCOMUtils.generateQI([Ci.nsIObserver]);
 
 ///////////////////////////////// nsIObserver //////////////////////////////////
 
@@ -235,8 +178,9 @@ service.prototype.handleScriptValMsg = function(aMessage) {
   }
 };
 
-service.prototype.ignoreNextScript = function() {
-  this._ignoreNextScript = true;
+service.prototype.scriptInstall = function(aMessage) {
+  dump('>>> component scriptInstall ... '+aMessage.data+'\n');
+  GM_util.showInstallDialog(aMessage.data.url, aMessage.target);
 };
 
 //////////////////////////// Component Registration ////////////////////////////
diff --git a/content/framescript.js b/content/framescript.js
index d35d133..ede7a09 100644
--- a/content/framescript.js
+++ b/content/framescript.js
@@ -17,11 +17,22 @@ Cu.import('resource://greasemonkey/util.js');
 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
 
 var gScope = this;
+var gScriptEndingRegexp = new RegExp('\\.user\\.js$');
 var gScriptRunners = {};
 var gStripUserPassRegexp = new RegExp('(://)([^:/]+)(:[^@/]+)?@');
 
 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
 
+function isTempScript(uri) {
+  // RAGE FACE can't do files in frames!!!
+//  if (uri.scheme != "file") return false;
+//  var file = gFileProtocolHandler.getFileFromURLSpec(uri.spec);
+//  return gTmpDir.contains(file, true);
+  return false;
+}
+
+// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
+
 function ScriptRunner(aWindow, aUrl) {
   this.menuCommands = [];
   this.window = aWindow;
@@ -86,6 +97,7 @@ ScriptRunner.prototype.windowIsTop = function(aContentWin) {
 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
 
 function ContentObserver() {
+  this._ignoreNextScript = false;
 }
 
 
@@ -93,13 +105,33 @@ ContentObserver.prototype.QueryInterface = XPCOMUtils.generateQI([
     Ci.nsIObserver]);
 
 
-ContentObserver.prototype.createScriptFromObject = function(aObject) {
-  var script = Object.create(IPCScript.prototype);
-  // TODO: better way for this? Object.create needs property descriptors.
-  for (var key in aObject) {
-    script[key] = aObject[key];
+ContentObserver.prototype.checkHttpEvent = function(aChannel) {
+  var uri = aChannel.URI;
+
+  if (!GM_util.getEnabled()) return;
+
+  // Don't interrupt the "view-source:" scheme (which is triggered if the link
+  // in the error console is clicked), nor the "greasemonkey-script:" scheme.
+  if ('view-source' == uri.scheme) return;
+  if ('greasemonkey-script' == uri.scheme) return;
+
+  // Do not install scripts when the origin URL "is a script".  See #1875
+  if (aChannel.referer && aChannel.referer.spec.match(gScriptEndingRegexp)) {
+    return;
+  }
+
+  if (uri.spec.match(gScriptEndingRegexp)
+      && !this._ignoreNextScript
+      && !isTempScript(uri)
+  ) {
+    this._ignoreNextScript = true;
+    aChannel.cancel(Components.results.NS_BINDING_ABORTED);
+    dump('TODO SHOW INSTALL DIALOG HERE\n');
+    dump(uri.spec+'\n');
+    sendAsyncMessage('greasemonkey:script-install', {
+      'url': uri.spec,
+    });
   }
-  return script;
 };
 
 
@@ -114,6 +146,16 @@ ContentObserver.prototype.contentLoad = function(aEvent) {
 };
 
 
+ContentObserver.prototype.createScriptFromObject = function(aObject) {
+  var script = Object.create(IPCScript.prototype);
+  // TODO: better way for this? Object.create needs property descriptors.
+  for (var key in aObject) {
+    script[key] = aObject[key];
+  }
+  return script;
+};
+
+
 ContentObserver.prototype.observe = function(aSubject, aTopic, aData) {
   if (!GM_util.getEnabled()) return;
 
@@ -135,6 +177,10 @@ ContentObserver.prototype.observe = function(aSubject, aTopic, aData) {
 
       this.runScripts('document-start', win);
       break;
+    case 'http-on-modify-request':
+      aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
+      this.checkHttpEvent(aSubject);
+      break;
     default:
       dump('Content frame observed unknown topic: ' + aTopic + '\n');
   }
@@ -241,20 +287,29 @@ ContentObserver.prototype.runScripts = function(aRunWhen, aContentWin) {
 
 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
 
-// Create a singleton object within this frame, attach observer/listeners to it.
 var contentObserver = new ContentObserver();
-
-// This global function reference can easily be both attached as an event
-// listener, and then removed again.
 var gContentLoad = contentObserver.contentLoad.bind(contentObserver);
 
 addEventListener('pagehide', contentObserver.pagehide.bind(contentObserver));
 addEventListener('pageshow', contentObserver.pageshow.bind(contentObserver));
+
 addMessageListener('greasemonkey:inject-script',
     contentObserver.runDelayedScript.bind(contentObserver));
 addMessageListener('greasemonkey:menu-command-clicked',
     contentObserver.runMenuCommand.bind(contentObserver));
+
 Services.obs.addObserver(contentObserver, 'document-element-inserted', false);
+try {
+  Services.obs.addObserver(contentObserver, 'http-on-modify-request', false);
+} catch (e) {
+  // Ignore; this will sometimes fail on some weird frames that happen to
+  // be loading about:blank. (WHY?!?!?!?)
+}
 addEventListener('unload', function() {
   Services.obs.removeObserver(contentObserver, 'document-element-inserted');
+  try {
+    Services.obs.removeObserver(contentObserver, 'http-on-modify-request');
+  } catch (e) {
+    // Ignore, in case we ignored failure to add above.
+  }
 }, false);
diff --git a/modules/util/showInstallDialog.js b/modules/util/showInstallDialog.js
index f20543f..2c916a9 100644
--- a/modules/util/showInstallDialog.js
+++ b/modules/util/showInstallDialog.js
@@ -7,7 +7,7 @@ var gWindowWatcher = Components
     .classes["@mozilla.org/embedcomp/window-watcher;1"]
     .getService(Components.interfaces.nsIWindowWatcher);
 
-function showInstallDialog(aUrlOrRemoteScript, aBrowser, aService) {
+function showInstallDialog(aUrlOrRemoteScript, aBrowser) {
   var rs = null;
   if ('string' == typeof aUrlOrRemoteScript) {
     rs = new RemoteScript(aUrlOrRemoteScript);
@@ -40,7 +40,7 @@ function showInstallDialog(aUrlOrRemoteScript, aBrowser, aService) {
   rs.download(function(aSuccess, aType) {
     if (!aSuccess && 'script' == aType) {
       // Failure downloading script; browse to it.
-      aService.ignoreNextScript();
+//      aService.ignoreNextScript();
       aBrowser.loadURI(rs.url, /* aReferrer */ null, /* aCharset */ null);
     }
   });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/greasemonkey.git



More information about the Pkg-mozext-commits mailing list