如何设置协议处理程序

时间:2014-08-03 10:41:41

标签: firefox-addon

在自定义mailto处理程序中: see red arrow pointing to newlly added

我试图找出如何动态模仿它的设置。正如registerProtocoLHandler只添加处理程序但不设置它。

所以我打开了如上所示的prefs窗格,然后在盒子上做了dom检查器。我找到了它正在做的一些功能:

var me = Services.wm.getMostRecentWindow(null);
var win = Services.wm.getMostRecentWindow('Browser:Preferences');
me.alert(win.gApplicationsPane.onSelectAction) //gApplicationsPane.onSelectAction(event.originalTarget)

me.alert(win.gApplicationsPane._storeAction)

如此明确地指示下拉列表onSelectAction,但它传递给它event.originalTarget,这是我的mxr冒险让我疯狂的地方。我无法弄清楚它在做什么。请帮助模仿而不必传递event.originalTarget甚至使用onSelectAction,因为我希望从此窗格未打开的范围执行。

2 个答案:

答案 0 :(得分:0)

呃我想我几周前回答了我自己的问题哈哈: Intercept/handle mime type/file

我会告诉你我想出了什么。

答案 1 :(得分:0)

想出来。

此代码段将mailto处理程序设置为yahoo mail(如果找到它)。如果没有找到它会告诉你它没找到。

复制粘贴并在浏览器环境中从暂存器运行:

 var handlers = handlerInfo.possibleApplicationHandlers.enumerate();
 var foundYahooMailHandler = false;
 while (handlers.hasMoreElements()) {
   var handler = handlers.getNext().QueryInterface(Ci.nsIWebHandlerApp);
   if (handler.uriTemplate == 'https://compose.mail.yahoo.com/?To=%s') { //this is how i decided to indentify if the handler is of yahoo mail
     foundYahooMailHandler = true;
     break;
   }
 }

if (foundYahooMailHandler) {
  //it was found. and in the while loop when i found it, i "break"ed out of the loop which left handlerInfo set at the yahoo mail handler
  //set this to the prefered handler as this handler is the y! mail handler
  handlerInfo.preferredAction = Ci.nsIHandlerInfo.useHelperApp; //Ci.nsIHandlerInfo has keys: alwaysAsk:1, handleInternally:3, saveToDisk:0, useHelperApp:2, useSystemDefault:4
  handlerInfo.preferredApplicationHandler = handler;
  handlerInfo.alwaysAskBeforeHandling = false;
  var hs = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService);
  hs.store(handlerInfo);
} else {
  Services.wm.getMostRecentWindow(null).alert('could not find yahoo mail handler. meaning i couldnt find a handler with uriTemplate of ...compose.mail.yahoo....')
}
相关问题