tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RLBoxHunspell.h (2317B)


      1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef EXTENSIONS_SPELLCHECK_HUNSPELL_GLUE_RLBOXHUNSPELL_H_
      7 #define EXTENSIONS_SPELLCHECK_HUNSPELL_GLUE_RLBOXHUNSPELL_H_
      8 
      9 #include "RLBoxHunspellTypes.h"
     10 
     11 // Load general firefox configuration of RLBox
     12 #include "mozilla/rlbox/rlbox_config.h"
     13 
     14 #ifdef MOZ_WASM_SANDBOXING_HUNSPELL
     15 // Include the generated header file so that we are able to resolve the symbols
     16 // in the wasm binary
     17 #  include "rlbox.wasm.h"
     18 #  define RLBOX_USE_STATIC_CALLS() rlbox_wasm2c_sandbox_lookup_symbol
     19 #  include "mozilla/rlbox/rlbox_wasm2c_sandbox.hpp"
     20 #else
     21 #  define RLBOX_USE_STATIC_CALLS() rlbox_noop_sandbox_lookup_symbol
     22 #  include "mozilla/rlbox/rlbox_noop_sandbox.hpp"
     23 #endif
     24 
     25 #include "mozilla/rlbox/rlbox.hpp"
     26 
     27 #include <hunspell.h>
     28 #include "mozHunspellRLBoxGlue.h"
     29 
     30 class RLBoxHunspell {
     31 public:
     32  static RLBoxHunspell* Create(const nsCString& affpath,
     33                               const nsCString& dpath);
     34 
     35  ~RLBoxHunspell();
     36 
     37  int spell(const std::string& stdWord);
     38  const std::string& get_dict_encoding() const;
     39 
     40  std::vector<std::string> suggest(const std::string& word);
     41 
     42 private:
     43  struct RLBoxDeleter {
     44    void operator()(rlbox_sandbox_hunspell* sandbox) {
     45      sandbox->destroy_sandbox();
     46      delete sandbox;
     47    }
     48  };
     49 
     50  RLBoxHunspell(
     51      mozilla::UniquePtr<rlbox_sandbox_hunspell, RLBoxDeleter> aSandbox,
     52      const nsCString& affpath, const nsCString& dpath);
     53 
     54  mozilla::UniquePtr<rlbox_sandbox_hunspell, RLBoxDeleter> mSandbox;
     55  sandbox_callback_hunspell<hunspell_create_filemgr_t*> mCreateFilemgr;
     56  sandbox_callback_hunspell<hunspell_get_line_t*> mGetLine;
     57  sandbox_callback_hunspell<hunspell_get_line_num_t*> mGetLineNum;
     58  sandbox_callback_hunspell<hunspell_destruct_filemgr_t*> mDestructFilemgr;
     59  sandbox_callback_hunspell<hunspell_ToUpperCase_t*> mHunspellToUpperCase;
     60  sandbox_callback_hunspell<hunspell_ToLowerCase_t*> mHunspellToLowerCase;
     61  sandbox_callback_hunspell<hunspell_get_current_cs_t*> mHunspellGetCurrentCS;
     62  tainted_hunspell<Hunhandle*> mHandle;
     63  std::string mDicEncoding;
     64 };
     65 
     66 #endif