Bug 1046420 - Part 1: Make MozSelfSupport a Window property instead of a global property. r=bz,wchen
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 26 Aug 2014 07:11:15 -0700
changeset 223302 2964a815862e3c94c0581631d0c72a212c39ad78
parent 223301 27e503753e0073f7a2eedad0f0e4276b844d028c
child 223303 dbd6f67cc8a8a4fb74eb46501519b216e15329fa
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, wchen
bugs1046420
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1046420 - Part 1: Make MozSelfSupport a Window property instead of a global property. r=bz,wchen
browser/components/selfsupport/SelfSupportService.js
browser/components/selfsupport/SelfSupportService.manifest
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/webidl/MozSelfSupport.webidl
dom/webidl/Window.webidl
--- a/browser/components/selfsupport/SelfSupportService.js
+++ b/browser/components/selfsupport/SelfSupportService.js
@@ -22,28 +22,22 @@ XPCOMUtils.defineLazyGetter(this, "repor
 
 function MozSelfSupportInterface() {
 }
 
 MozSelfSupportInterface.prototype = {
   classDescription: "MozSelfSupport",
   classID: Components.ID("{d30aae8b-f352-4de3-b936-bb9d875df0bb}"),
   contractID: "@mozilla.org/mozselfsupport;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
-                                         Ci.nsIObserver]),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]),
 
   _window: null,
 
   init: function (window) {
     this._window = window;
-
-    // FIXME: Remove this hack after static attributes work for JS-implemented
-    // WebIDL (see bug 863952). For a detailed description of how this works,
-    // see the comment accompanying the init function of amInstallTrigger.js.
-    return window.MozSelfSupportImpl._create(this._window, this);
   },
 
   get healthReportDataSubmissionEnabled() {
     return policy.healthReportUploadEnabled;
   },
 
   set healthReportDataSubmissionEnabled(enabled) {
     let reason = "Self-support interface sent " +
--- a/browser/components/selfsupport/SelfSupportService.manifest
+++ b/browser/components/selfsupport/SelfSupportService.manifest
@@ -1,4 +1,2 @@
 component {d30aae8b-f352-4de3-b936-bb9d875df0bb} SelfSupportService.js
 contract @mozilla.org/mozselfsupport;1 {d30aae8b-f352-4de3-b936-bb9d875df0bb}
-
-category JavaScript-global-privileged-property MozSelfSupport @mozilla.org/mozselfsupport;1
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -208,16 +208,17 @@
 #include "prrng.h"
 #include "nsSandboxFlags.h"
 #include "TimeChangeObserver.h"
 #include "mozilla/dom/AudioContext.h"
 #include "mozilla/dom/BrowserElementDictionariesBinding.h"
 #include "mozilla/dom/Console.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/HashChangeEvent.h"
+#include "mozilla/dom/MozSelfSupportBinding.h"
 #include "mozilla/dom/PopStateEvent.h"
 #include "mozilla/dom/PopupBlockedEvent.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "nsITabChild.h"
 #include "mozilla/dom/MediaQueryList.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/NavigatorBinding.h"
 #ifdef HAVE_SIDEBAR
@@ -1462,16 +1463,18 @@ nsGlobalWindow::CleanUp()
   mWindowUtils = nullptr;
   mApplicationCache = nullptr;
   mIndexedDB = nullptr;
 
   mConsole = nullptr;
 
   mExternal = nullptr;
 
+  mMozSelfSupport = nullptr;
+
   mPerformance = nullptr;
 
 #ifdef MOZ_WEBSPEECH
   mSpeechSynthesis = nullptr;
 #endif
 
   ClearControllers();
 
@@ -1781,16 +1784,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mToolbar)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocationbar)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPersonalbar)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExternal)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMozSelfSupport)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
   nsGlobalWindow::CleanupCachedXBLHandlers(tmp);
 
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mContext)
 
@@ -1841,16 +1845,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mToolbar)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocationbar)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mPersonalbar)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mExternal)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mMozSelfSupport)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 #ifdef DEBUG
 void
 nsGlobalWindow::RiskyUnlink()
 {
   NS_CYCLE_COLLECTION_INNERNAME.Unlink(this);
@@ -4060,16 +4065,29 @@ NS_IMETHODIMP
 nsGlobalWindow::GetContent(nsIDOMWindow** aContent)
 {
   ErrorResult rv;
   *aContent = GetContentInternal(rv).take();
 
   return rv.ErrorCode();
 }
 
+MozSelfSupport*
+nsGlobalWindow::GetMozSelfSupport(ErrorResult& aError)
+{
+  if (mMozSelfSupport) {
+    return mMozSelfSupport;
+  }
+
+  AutoSafeJSContext cx;
+  GlobalObject global(cx, FastGetGlobalJSObject());
+  mMozSelfSupport = MozSelfSupport::Constructor(global, cx, aError);
+  return mMozSelfSupport;
+}
+
 NS_IMETHODIMP
 nsGlobalWindow::GetScriptableContent(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
 {
   ErrorResult rv;
   JS::Rooted<JSObject*> content(aCx);
   GetContent(aCx, &content, rv);
   if (!rv.Failed()) {
     aVal.setObjectOrNull(content);
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -109,16 +109,17 @@ namespace mozilla {
 class DOMEventTargetHelper;
 namespace dom {
 class BarProp;
 class Console;
 class External;
 class Function;
 class Gamepad;
 class MediaQueryList;
+class MozSelfSupport;
 class Navigator;
 class OwningExternalOrWindowProxy;
 class Selection;
 class SpeechSynthesis;
 class WakeLock;
 namespace indexedDB {
 class IDBFactory;
 } // namespace indexedDB
@@ -1011,16 +1012,19 @@ public:
   void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError);
   void Back(mozilla::ErrorResult& aError);
   void Forward(mozilla::ErrorResult& aError);
   void Home(mozilla::ErrorResult& aError);
   bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
             bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
             bool aShowDialog, mozilla::ErrorResult& aError);
   uint64_t GetMozPaintCount(mozilla::ErrorResult& aError);
+
+  mozilla::dom::MozSelfSupport* GetMozSelfSupport(mozilla::ErrorResult& aError);
+
   already_AddRefed<nsIDOMWindow> OpenDialog(JSContext* aCx,
                                             const nsAString& aUrl,
                                             const nsAString& aName,
                                             const nsAString& aOptions,
                                             const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
                                             mozilla::ErrorResult& aError);
   void GetContent(JSContext* aCx,
                   JS::MutableHandle<JSObject*> aRetval,
@@ -1557,16 +1561,18 @@ protected:
   nsCOMPtr<nsIDOMCrypto>        mCrypto;
   nsRefPtr<mozilla::dom::Console> mConsole;
   // We need to store an nsISupports pointer to this object because the
   // mozilla::dom::External class doesn't exist on b2g and using the type
   // forward declared here means that ~nsGlobalWindow wouldn't compile because
   // it wouldn't see the ~External function's declaration.
   nsCOMPtr<nsISupports>         mExternal;
 
+  nsRefPtr<mozilla::dom::MozSelfSupport> mMozSelfSupport;
+
   nsRefPtr<mozilla::dom::DOMStorage> mLocalStorage;
   nsRefPtr<mozilla::dom::DOMStorage> mSessionStorage;
 
   // These member variable are used only on inner windows.
   nsRefPtr<mozilla::EventListenerManager> mListenerManager;
   // mTimeouts is generally sorted by mWhen, unless mTimeoutInsertionPoint is
   // non-null.  In that case, the dummy timeout pointed to by
   // mTimeoutInsertionPoint may have a later mWhen than some of the timeouts
--- a/dom/webidl/MozSelfSupport.webidl
+++ b/dom/webidl/MozSelfSupport.webidl
@@ -6,18 +6,19 @@
  * The MozSelfSupport interface allows external Mozilla support sites such as
  * FHR and SUMO to access data and control settings that are not otherwise
  * exposed to external content.
  *
  * At the moment, this is a ChromeOnly interface, but the plan is to allow
  * specific Mozilla domains to access it directly.
  */
 [ChromeOnly,
- JSImplementation="@mozilla.org/mozselfsupport;1"]
-interface MozSelfSupportImpl
+ JSImplementation="@mozilla.org/mozselfsupport;1",
+ Constructor()]
+interface MozSelfSupport
 {
   /**
    * Controls whether uploading FHR data is allowed.
    */
   attribute boolean healthReportDataSubmissionEnabled;
 
   /**
    * Retrieves the FHR payload object, which is of the form:
--- a/dom/webidl/Window.webidl
+++ b/dom/webidl/Window.webidl
@@ -323,16 +323,24 @@ partial interface Window {
                                  optional boolean showDialog = false);
 
   /**
    * Returns the number of times this document for this window has
    * been painted to the screen.
    */
   [Throws] readonly attribute unsigned long long mozPaintCount;
 
+  /**
+   * This property exists because static attributes don't yet work for
+   * JS-implemented WebIDL (see bugs 1058606 and 863952). With this hack, we
+   * can use `MozSelfSupport.something(...)`, which will continue to work
+   * after we ditch this property and switch to static attributes. See 
+   */
+  [ChromeOnly, Throws] readonly attribute MozSelfSupport MozSelfSupport;
+
   [Pure]
            attribute EventHandler onwheel;
 
            attribute EventHandler ondevicemotion;
            attribute EventHandler ondeviceorientation;
            attribute EventHandler ondeviceproximity;
            attribute EventHandler onuserproximity;
            attribute EventHandler ondevicelight;