从addon调用checkCurrentDictionary()崩溃FF - 为什么?

时间:2014-08-08 09:24:22

标签: firefox crash firefox-addon spell-checking

我正在尝试从加载项中调用checkCurrentDictionary()的方法nsIEditorSpellCheck。我使用的相关代码是:

var editorSpellCheck = Cc["@mozilla.org/editor/editorspellchecker;1"].createInstance(Ci.nsIEditorSpellCheck);
editorSpellCheck.checkCurrentDictionary();

这会立即导致Fx崩溃。这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

所以这可能与nsIEditorSpellCheck is not a scriptable interface

这个事实有关

基本上是scriptable interface is one that can be used from JavaScript

如果您想访问拼写检查服务,您可以执行以下操作:

let editor = editableElement.editor;
if (!editor) {
  let win = editableElement.ownerDocument.defaultView;
  editor = win.QueryInterface(Ci.nsIInterfaceRequestor).
               getInterface(Ci.nsIWebNavigation).
               QueryInterface(Ci.nsIInterfaceRequestor).
               getInterface(Ci.nsIEditingSession).
               getEditorForWindow(win);
}
if (!editor)
  throw new Error("Unable to find editor for element " + editableElement);

(以上来自http://dxr.mozilla.org/mozilla-central/source/editor/AsyncSpellCheckTestHelper.jsm,即MPL)。

然后你可以使用InlineSpellCheck.jsm做一些疯狂的事情。

我不确定你想做什么,所以也许你应该把更具体的问题作为一个新问题。