genericcom.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
  16. import { BasePreferences } from "./preferences.js";
  17. import { DownloadManager } from "./download_manager.js";
  18. import { GenericL10n } from "./genericl10n.js";
  19. import { GenericScripting } from "./generic_scripting.js";
  20. if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
  21. throw new Error(
  22. 'Module "pdfjs-web/genericcom" shall not be used outside GENERIC build.'
  23. );
  24. }
  25. const GenericCom = {};
  26. class GenericPreferences extends BasePreferences {
  27. async _writeToStorage(prefObj) {
  28. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  29. }
  30. async _readFromStorage(prefObj) {
  31. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  32. }
  33. }
  34. class GenericExternalServices extends DefaultExternalServices {
  35. static createDownloadManager() {
  36. return new DownloadManager();
  37. }
  38. static createPreferences() {
  39. return new GenericPreferences();
  40. }
  41. static createL10n({ locale = "en-US" }) {
  42. return new GenericL10n(locale);
  43. }
  44. static createScripting({ sandboxBundleSrc }) {
  45. return new GenericScripting(sandboxBundleSrc);
  46. }
  47. }
  48. PDFViewerApplication.externalServices = GenericExternalServices;
  49. export { GenericCom };