Guest User

Untitled

a guest
Mar 11th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. navigator.registerProtocolHandler('mailto','http://mail.live.com/secure/start?action=compose&to=%s','Live Mail');
  2.  
  3. var nsiwchr = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].getService(Ci.nsIWebContentHandlerRegistrar);
  4.  
  5. nsiwchr.registerProtocolHandler('mailto','http://mail.live.com/secure/start?action=compose&to=%s','Live Mail', null);
  6.  
  7. var uri = this._checkAndGetURI(aURIString, aContentWindow);
  8.  
  9. aContentWindow.location.hostname != uri.host)
  10.  
  11. var fakeContentWindow = {
  12. document: {
  13. baseURIObject: {
  14. asciiHost:"mail.live.com",
  15. asciiSpec:"http://mail.live.com/secure",
  16. hasRef:true,
  17. host:"mail.live.com",
  18. hostPort:"mail.live.com",
  19. originCharset:"UTF-8",
  20. password:"",
  21. path:"/secure",
  22. port:-1,
  23. prePath:"http://mail.live.com",
  24. ref:"", //369
  25. scheme:"http",
  26. spec:"http://mail.live.com/secure",
  27. specIgnoringRef:"http://mail.live.com",
  28. userPass:"",
  29. username:""
  30. }
  31. },
  32. location: {
  33. hash:"", //#369
  34. host:"mail.live.com",
  35. hostname:"mail.live.com",
  36. href:"http://mail.live.com/secure",
  37. origin:"http://mxr.mozilla.org",
  38. pathname:"/secure",
  39. port:"",
  40. protocol:"http:",
  41. search:""
  42. }
  43. };
  44.  
  45. nsiwchr.registerProtocolHandler('mailto','http://mail.live.com/secure/start?action=compose&to=%s','Live Mail', fakeContentWindow);
  46.  
  47. "[object XPCWrappedNative_NoHelper]" scratchpad.js:999
  48. SP_writeAsErrorComment/<() scratchpad.js:999
  49. Handler.prototype.process() Promise-backend.js:863
  50. this.PromiseWalker.walkerLoop() Promise-backend.js:742
  51.  
  52. var protocolScheme = "mailtoorsomething";
  53. var uri = Services.io.newURI("someuri?with_%s_replacement", null, null);
  54. var name = "Some Name";
  55. var desc = "Some description";
  56.  
  57. var protocolHandler = Services.io.getProtocolHandler(protocolScheme);
  58. if (!(protocolHandler instanceof Ci.nsIExternalProtocolHandler)) {
  59. throw new Error("Cannot register handler for built-in protocol");
  60. }
  61.  
  62. var eps = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
  63. getService(Ci.nsIExternalProtocolService);
  64. var handlerInfo = eps.getProtocolHandlerInfo(protocolScheme);
  65. var handlers = handlerInfo.possibleApplicationHandlers;
  66. for (let i = 0; i < handlers.length; i++) {
  67. let h = handlers.queryElementAt(i, Ci.nsIWebHandlerApp);
  68. if (h.uriTemplate == uri.spec) {
  69. throw new Error("Already registered");
  70. }
  71. }
  72.  
  73. var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
  74. createInstance(Ci.nsIWebHandlerApp);
  75. handler.name = name;
  76. handler.detailedDescription = desc;
  77. handler.uriTemplate = uri.spec;
  78. handlerInfo.possibleApplicationHandlers.appendElement(handler, false);
  79.  
  80. handlerInfo.alwaysAskBeforeHandling = false;
  81. handlerInfo.preferredApplicationHandler = handler;
  82. handlerInfo.preferredAction = Ci.nsIHandlerInfo.useHelperApp;
  83.  
  84. var hs = Cc["@mozilla.org/uriloader/handler-service;1"].
  85. getService(Ci.nsIHandlerService);
  86. hs.store(handlerInfo);
Add Comment
Please, Sign In to add comment