From 32580a380e2ff45a3d092d666644e1ee77815a9e Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 9 Dec 2015 15:52:38 -0500 Subject: [PATCH] Bug 1231100 - Get rid of nsIDOMFileReader - patch 2, r=sicking --- b2g/components/LogCapture.jsm | 1 + browser/components/migration/MSMigrationUtils.jsm | 2 ++ devtools/server/actors/device.js | 1 + devtools/server/actors/webapps.js | 1 + dom/apps/ImportExport.jsm | 2 +- .../test/unit/xpcshell-head-parent-process.js | 2 +- dom/mobilemessage/gonk/MmsService.js | 2 +- js/xpconnect/src/Sandbox.cpp | 6 ++++++ js/xpconnect/src/xpcprivate.h | 1 + js/xpconnect/tests/unit/test_fileReader.js | 13 +++++++++++++ js/xpconnect/tests/unit/xpcshell.ini | 1 + toolkit/components/thumbnails/PageThumbs.jsm | 2 ++ .../content/backgroundPageThumbsContent.js | 2 +- toolkit/modules/PropertyListUtils.jsm | 2 +- 14 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 js/xpconnect/tests/unit/test_fileReader.js diff --git a/b2g/components/LogCapture.jsm b/b2g/components/LogCapture.jsm index bace9fa51ff1..803028d5749b 100644 --- a/b2g/components/LogCapture.jsm +++ b/b2g/components/LogCapture.jsm @@ -10,6 +10,7 @@ const Cu = Components.utils; const Ci = Components.interfaces; const Cc = Components.classes; +Cu.importGlobalProperties(['FileReader']); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Promise", "resource://gre/modules/Promise.jsm"); diff --git a/browser/components/migration/MSMigrationUtils.jsm b/browser/components/migration/MSMigrationUtils.jsm index e9e77bd4eca2..7c30348166b1 100644 --- a/browser/components/migration/MSMigrationUtils.jsm +++ b/browser/components/migration/MSMigrationUtils.jsm @@ -16,6 +16,8 @@ Cu.import("resource:///modules/MigrationUtils.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/LoginHelper.jsm"); +Cu.importGlobalProperties(['FileReader']); + XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry", diff --git a/devtools/server/actors/device.js b/devtools/server/actors/device.js index e9878568bf03..92e25f78955a 100644 --- a/devtools/server/actors/device.js +++ b/devtools/server/actors/device.js @@ -11,6 +11,7 @@ const {LongStringActor} = require("devtools/server/actors/string"); const {DebuggerServer} = require("devtools/server/main"); const {getSystemInfo, getSetting} = require("devtools/shared/system"); +Cu.importGlobalProperties(["FileReader"]); Cu.import("resource://gre/modules/PermissionsTable.jsm") var DeviceActor = exports.DeviceActor = protocol.ActorClass({ diff --git a/devtools/server/actors/webapps.js b/devtools/server/actors/webapps.js index a547e118d67f..8d6b53e0ffc1 100644 --- a/devtools/server/actors/webapps.js +++ b/devtools/server/actors/webapps.js @@ -11,6 +11,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/UserCustomizations.jsm"); +Cu.importGlobalProperties(["FileReader"]); var promise = require("promise"); var DevToolsUtils = require("devtools/shared/DevToolsUtils"); diff --git a/dom/apps/ImportExport.jsm b/dom/apps/ImportExport.jsm index 94184d213593..63d78fcdcb44 100644 --- a/dom/apps/ImportExport.jsm +++ b/dom/apps/ImportExport.jsm @@ -15,7 +15,7 @@ Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Webapps.jsm"); Cu.import("resource://gre/modules/MessageBroadcaster.jsm"); -Cu.importGlobalProperties(['File']); +Cu.importGlobalProperties(['File', 'FileReader']); XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm"); diff --git a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js index 95b1c627d954..a3050b19e424 100644 --- a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js +++ b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js @@ -52,7 +52,7 @@ if (!this.runTest) { enableExperimental(); } - Cu.importGlobalProperties(["indexedDB", "Blob", "File"]); + Cu.importGlobalProperties(["indexedDB", "Blob", "File", "FileReader"]); do_test_pending(); testGenerator.next(); diff --git a/dom/mobilemessage/gonk/MmsService.js b/dom/mobilemessage/gonk/MmsService.js index 37151445fa4e..a58ea4eb6de1 100644 --- a/dom/mobilemessage/gonk/MmsService.js +++ b/dom/mobilemessage/gonk/MmsService.js @@ -8,7 +8,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; -Cu.importGlobalProperties(['Blob']); +Cu.importGlobalProperties(['Blob', 'FileReader']); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/PhoneNumberUtils.jsm"); diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 950be005a064..73ddd935a16e 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -40,6 +40,7 @@ #ifdef MOZ_WEBRTC #include "mozilla/dom/RTCIdentityProviderRegistrar.h" #endif +#include "mozilla/dom/FileReaderBinding.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/TextDecoderBinding.h" #include "mozilla/dom/TextEncoderBinding.h" @@ -892,6 +893,8 @@ xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj) fetch = true; } else if (!strcmp(name.ptr(), "caches")) { caches = true; + } else if (!strcmp(name.ptr(), "FileReader")) { + fileReader = true; } else { JS_ReportError(cx, "Unknown property name: %s", name.ptr()); return false; @@ -960,6 +963,9 @@ xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj) if (caches && !dom::cache::CacheStorage::DefineCaches(cx, obj)) return false; + if (fileReader && !dom::FileReaderBinding::GetConstructorObject(cx, obj)) + return false; + return true; } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index d210885d4dec..e754c5bfec93 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -3424,6 +3424,7 @@ struct GlobalProperties { bool rtcIdentityProvider : 1; bool fetch : 1; bool caches : 1; + bool fileReader: 1; }; // Infallible. diff --git a/js/xpconnect/tests/unit/test_fileReader.js b/js/xpconnect/tests/unit/test_fileReader.js new file mode 100644 index 000000000000..cd4859301778 --- /dev/null +++ b/js/xpconnect/tests/unit/test_fileReader.js @@ -0,0 +1,13 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +function run_test() { + var Cu = Components.utils; + var sb = new Cu.Sandbox('http://www.example.com', + { wantGlobalProperties: ["FileReader"] }); + sb.do_check_true = do_check_true; + Cu.evalInSandbox('do_check_true((new FileReader()) instanceof FileReader);', + sb); + Cu.importGlobalProperties(["FileReader"]); + do_check_true((new FileReader()) instanceof FileReader); +} diff --git a/js/xpconnect/tests/unit/xpcshell.ini b/js/xpconnect/tests/unit/xpcshell.ini index 6d931eb88e4b..fb8ab4107e0e 100644 --- a/js/xpconnect/tests/unit/xpcshell.ini +++ b/js/xpconnect/tests/unit/xpcshell.ini @@ -109,6 +109,7 @@ skip-if = os == "android" # native test components aren't available on Android [test_textDecoder.js] [test_url.js] [test_URLSearchParams.js] +[test_fileReader.js] [test_crypto.js] [test_css.js] [test_rtcIdentityProvider.js] diff --git a/toolkit/components/thumbnails/PageThumbs.jsm b/toolkit/components/thumbnails/PageThumbs.jsm index 1e0b4200ca71..711d8cf8f23a 100644 --- a/toolkit/components/thumbnails/PageThumbs.jsm +++ b/toolkit/components/thumbnails/PageThumbs.jsm @@ -33,6 +33,8 @@ Cu.import("resource://gre/modules/PromiseWorker.jsm", this); Cu.import("resource://gre/modules/Promise.jsm", this); Cu.import("resource://gre/modules/osfile.jsm", this); +Cu.importGlobalProperties(['FileReader']); + XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm"); diff --git a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js index 6ed1090d8a8a..dcbc7a81fa45 100644 --- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js +++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js @@ -4,7 +4,7 @@ var { classes: Cc, interfaces: Ci, utils: Cu } = Components; -Cu.importGlobalProperties(['Blob']); +Cu.importGlobalProperties(['Blob', 'FileReader']); Cu.import("resource://gre/modules/PageThumbUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); diff --git a/toolkit/modules/PropertyListUtils.jsm b/toolkit/modules/PropertyListUtils.jsm index 2c072cefd33b..adc300e5a65c 100644 --- a/toolkit/modules/PropertyListUtils.jsm +++ b/toolkit/modules/PropertyListUtils.jsm @@ -61,7 +61,7 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; -Cu.importGlobalProperties(['File']); +Cu.importGlobalProperties(['File', 'FileReader']); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "ctypes",