зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1410214: Part 3 - Support packed WebExtension dictionaries. r=aswan,masayuki
MozReview-Commit-ID: 6nrw0IIe4UG --HG-- extra : rebase_source : 3e2c2b24bd7a9136d326da9bea3d1dc197cb908b extra : absorb_source : 9f7ab2b81c220463b82a74cb64e93528a54ff2c4
This commit is contained in:
Родитель
e2d0c50adb
Коммит
f55bef228c
|
@ -74,6 +74,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
|
||||
using mozilla::dom::ContentParent;
|
||||
|
@ -158,31 +159,14 @@ NS_IMETHODIMP mozHunspell::SetDictionary(const char16_t *aDictionary)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFile* affFile = mDictionaries.GetWeak(nsDependentString(aDictionary));
|
||||
nsIURI* affFile = mDictionaries.GetWeak(nsDependentString(aDictionary));
|
||||
if (!affFile)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
nsAutoCString dictFileName, affFileName;
|
||||
|
||||
#ifdef XP_WIN
|
||||
nsAutoString affFileNameU;
|
||||
nsresult rv = affFile->GetPath(affFileNameU);
|
||||
nsresult rv = affFile->GetSpec(affFileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Hunspell 1.3.3+ supports UTF-8 file paths on Windows
|
||||
// by prefixing "\\\\?\\".
|
||||
if (StringBeginsWith(affFileNameU, NS_LITERAL_STRING("\\\\"))) {
|
||||
CopyUTF16toUTF8(affFileNameU, affFileName);
|
||||
if (affFileNameU.CharAt(2) != u'?') {
|
||||
affFileName.InsertLiteral("?\\UNC\\", 2);
|
||||
}
|
||||
} else {
|
||||
affFileName.AssignLiteral("\\\\?\\");
|
||||
AppendUTF16toUTF8(affFileNameU, affFileName);
|
||||
}
|
||||
#else
|
||||
nsresult rv = affFile->GetNativePath(affFileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
#endif
|
||||
|
||||
if (mAffixFileName.Equals(affFileName.get()))
|
||||
return NS_OK;
|
||||
|
@ -203,7 +187,7 @@ NS_IMETHODIMP mozHunspell::SetDictionary(const char16_t *aDictionary)
|
|||
mAffixFileName = affFileName;
|
||||
|
||||
mHunspell = new Hunspell(affFileName.get(),
|
||||
dictFileName.get());
|
||||
dictFileName.get());
|
||||
if (!mHunspell)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -488,7 +472,11 @@ mozHunspell::LoadDictionariesFromDir(nsIFile* aDir)
|
|||
// Replace '_' separator with '-'
|
||||
dict.ReplaceChar("_", '-');
|
||||
|
||||
mDictionaries.Put(dict, file);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mDictionaries.Put(dict, uri);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -667,7 +655,7 @@ NS_IMETHODIMP mozHunspell::RemoveDirectory(nsIFile *aDir)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP mozHunspell::AddDictionary(const nsAString& aLang, nsIFile *aFile)
|
||||
NS_IMETHODIMP mozHunspell::AddDictionary(const nsAString& aLang, nsIURI *aFile)
|
||||
{
|
||||
NS_ENSURE_TRUE(aFile, NS_ERROR_INVALID_ARG);
|
||||
|
||||
|
@ -677,11 +665,11 @@ NS_IMETHODIMP mozHunspell::AddDictionary(const nsAString& aLang, nsIFile *aFile)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP mozHunspell::RemoveDictionary(const nsAString& aLang, nsIFile *aFile)
|
||||
NS_IMETHODIMP mozHunspell::RemoveDictionary(const nsAString& aLang, nsIURI *aFile)
|
||||
{
|
||||
NS_ENSURE_TRUE(aFile, NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsCOMPtr<nsIFile> file = mDynamicDictionaries.Get(aLang);
|
||||
nsCOMPtr<nsIURI> file = mDynamicDictionaries.Get(aLang);
|
||||
bool equal;
|
||||
if (file && NS_SUCCEEDED(file->Equals(aFile, &equal)) && equal) {
|
||||
mDynamicDictionaries.Remove(aLang);
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include "nsCOMArray.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIURI.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
@ -112,14 +113,14 @@ protected:
|
|||
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
||||
|
||||
// Hashtable matches dictionary name to .aff file
|
||||
nsInterfaceHashtable<nsStringHashKey, nsIFile> mDictionaries;
|
||||
nsInterfaceHashtable<nsStringHashKey, nsIURI> mDictionaries;
|
||||
nsString mDictionary;
|
||||
nsString mLanguage;
|
||||
nsCString mAffixFileName;
|
||||
|
||||
// dynamic dirs used to search for dictionaries
|
||||
nsCOMArray<nsIFile> mDynamicDirectories;
|
||||
nsInterfaceHashtable<nsStringHashKey, nsIFile> mDynamicDictionaries;
|
||||
nsInterfaceHashtable<nsStringHashKey, nsIURI> mDynamicDictionaries;
|
||||
|
||||
Hunspell *mHunspell;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsILoadInfo.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsXPCOM.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -24,13 +23,7 @@ Result<Ok, nsresult>
|
|||
FileMgr::Open(const nsACString& aPath)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
MOZ_TRY(NS_NewNativeLocalFile(aPath, false, getter_AddRefs(file)));
|
||||
MOZ_TRY(NS_NewFileURI(getter_AddRefs(uri), file));
|
||||
}
|
||||
MOZ_TRY(NS_NewURI(getter_AddRefs(uri), aPath));
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
MOZ_TRY(NS_NewChannel(
|
||||
|
|
|
@ -20,8 +20,7 @@ class FileMgr final
|
|||
{
|
||||
public:
|
||||
/**
|
||||
* aFilename may be the native filesystem path or local file/jar URI for the
|
||||
* file to load.
|
||||
* aFilename must be a local file/jar URI for the file to load.
|
||||
*
|
||||
* aKey is the decription key for encrypted Hunzip files, and is
|
||||
* unsupported. The argument is there solely for compatibility.
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
Cu.importGlobalProperties(["TextEncoder"]);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "spellCheck",
|
||||
"@mozilla.org/spellchecker/engine;1", "mozISpellCheckingEngine");
|
||||
|
||||
const nsFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile",
|
||||
"initWithPath");
|
||||
|
||||
add_task(async function() {
|
||||
let prof = do_get_profile();
|
||||
|
||||
let basePath = OS.Path.join(prof.path, "\u263a", "dictionaries");
|
||||
let baseDir = nsFile(basePath);
|
||||
await OS.File.makeDir(basePath, {from: prof.path});
|
||||
|
||||
let dicPath = OS.Path.join(basePath, "dict.dic");
|
||||
let affPath = OS.Path.join(basePath, "dict.aff");
|
||||
|
||||
const WORD = "Flehgragh";
|
||||
|
||||
await OS.File.writeAtomic(dicPath, new TextEncoder().encode(`1\n${WORD}\n`));
|
||||
await OS.File.writeAtomic(affPath, new TextEncoder().encode(""));
|
||||
|
||||
spellCheck.loadDictionariesFromDir(baseDir);
|
||||
spellCheck.dictionary = "dict";
|
||||
|
||||
ok(spellCheck.check(WORD), "Dictionary should have been loaded from a unicode path");
|
||||
});
|
||||
|
|
@ -2,5 +2,7 @@
|
|||
head =
|
||||
skip-if = toolkit == 'android'
|
||||
support-files = data/**
|
||||
firefox-appdir = browser
|
||||
|
||||
[test_hunspell.js]
|
||||
[test_hunspell_unicode_paths.js]
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIURI;
|
||||
interface mozIPersonalDictionary;
|
||||
|
||||
[scriptable, uuid(8ba643a4-7ddc-4662-b976-7ec123843f10)]
|
||||
|
@ -87,16 +88,16 @@ interface mozISpellCheckingEngine : nsISupports {
|
|||
void removeDirectory(in nsIFile dir);
|
||||
|
||||
/**
|
||||
* Add a dictionary with the given language code and file path.
|
||||
* Add a dictionary with the given language code and file URI.
|
||||
*/
|
||||
void addDictionary(in AString lang, in nsIFile dir);
|
||||
void addDictionary(in AString lang, in nsIURI file);
|
||||
|
||||
/**
|
||||
* Remove a dictionary with the given language code and path. If the path does
|
||||
* not match that of the current entry with the given language code, it is not
|
||||
* removed.
|
||||
*/
|
||||
void removeDictionary(in AString lang, in nsIFile dir);
|
||||
void removeDictionary(in AString lang, in nsIURI file);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -1874,10 +1874,10 @@ class Dictionary extends ExtensionData {
|
|||
async startup(reason) {
|
||||
this.dictionaries = {};
|
||||
for (let [lang, path] of Object.entries(this.startupData.dictionaries)) {
|
||||
let {file} = Services.io.newURI(path, null, this.rootURI).QueryInterface(Ci.nsIFileURL);
|
||||
this.dictionaries[lang] = file;
|
||||
let uri = Services.io.newURI(path, null, this.rootURI);
|
||||
this.dictionaries[lang] = uri;
|
||||
|
||||
spellCheck.addDictionary(lang, file);
|
||||
spellCheck.addDictionary(lang, uri);
|
||||
}
|
||||
|
||||
Management.emit("ready", this);
|
||||
|
|
|
@ -325,7 +325,7 @@ class AddonInternal {
|
|||
}
|
||||
|
||||
get unpack() {
|
||||
return this.type === "dictionary" || this.type === "webextension-dictionary";
|
||||
return this.type === "dictionary";
|
||||
}
|
||||
|
||||
get isCompatible() {
|
||||
|
|
|
@ -12,5 +12,4 @@ tags = webextensions
|
|||
tags = webextensions
|
||||
|
||||
[test_dictionary.js]
|
||||
[test_dictionary_webextension.js]
|
||||
[test_filepointer.js]
|
||||
|
|
|
@ -91,6 +91,7 @@ head =
|
|||
skip-if = appname == "thunderbird"
|
||||
tags = webextensions
|
||||
[test_dependencies.js]
|
||||
[test_dictionary_webextension.js]
|
||||
[test_distribution.js]
|
||||
[test_duplicateplugins.js]
|
||||
# Bug 676992: test consistently hangs on Android
|
||||
|
|
Загрузка…
Ссылка в новой задаче