Bug 983845 - Port nsIFeedWriter to WebIDL and stop exposing BrowserFeedWriter to the Web; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 19 Mar 2014 12:29:00 -0400
changeset 174326 e9ea1662020a758e7b3ab8baf3b8d3636aa9a4d2
parent 174325 1a7c8da316467f8971012d446f402fa9df5dfae2
child 174327 b4d16778e50c9a24bfdf3a911ea15db215d5fb99
push id26451
push usercbook@mozilla.com
push dateThu, 20 Mar 2014 12:56:37 +0000
treeherdermozilla-central@358d369c8388 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs983845
milestone31.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 983845 - Port nsIFeedWriter to WebIDL and stop exposing BrowserFeedWriter to the Web; r=bzbarsky X-Git-Commit-ID: 487d201e67d932da2d4a73b680181072a13e35b3
browser/components/feeds/content/subscribe.js
browser/components/feeds/public/moz.build
browser/components/feeds/public/nsIFeedWriter.idl
browser/components/feeds/src/BrowserFeeds.manifest
browser/components/feeds/src/FeedWriter.js
browser/components/feeds/src/FeedWriterEnabled.h
browser/components/feeds/src/moz.build
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/BrowserFeedWriter.webidl
dom/webidl/moz.build
--- a/browser/components/feeds/content/subscribe.js
+++ b/browser/components/feeds/content/subscribe.js
@@ -6,23 +6,18 @@
 var SubscribeHandler = {
   /**
    * The nsIFeedWriter object that produces the UI
    */
   _feedWriter: null,
   
   init: function SH_init() {
     this._feedWriter = new BrowserFeedWriter();
-    this._feedWriter.init(window);
   },
 
   writeContent: function SH_writeContent() {
     this._feedWriter.writeContent();
   },
 
   uninit: function SH_uninit() {
     this._feedWriter.close();
-  },
-  
-  subscribe: function SH_subscribe() {
-    this._feedWriter.subscribe();
   }
 };
--- a/browser/components/feeds/public/moz.build
+++ b/browser/components/feeds/public/moz.build
@@ -1,14 +1,13 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPIDL_SOURCES += [
     'nsIFeedResultService.idl',
-    'nsIFeedWriter.idl',
     'nsIWebContentConverterRegistrar.idl',
 ]
 
 XPIDL_MODULE = 'browser-feeds'
 
deleted file mode 100644
--- a/browser/components/feeds/public/nsIFeedWriter.idl
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-interface nsIDOMWindow;
-
-/**
- * Instances of this component write UI into the display page. This component
- * is trusted so can access preferences etc, but page content isn't and so
- * cannot.
- */
-[scriptable, uuid(67003393-018c-4e96-af10-c6c51a049fad)]
-interface nsIFeedWriter : nsISupports
-{
-  /**
-   * Initializes the feed writer and loads the feed subscription UI.
-   * @param  aWindow
-   *         The DOMWindow of the preview page.
-   *         window.location.href == the URI of the feed.
-   */
-  void init(in nsIDOMWindow aWindow);
-
-  /**
-   * Writes the feed content, assumes that the feed writer is initialized.
-   */
-  void writeContent();
-
-  /**
-   * Uninitialize the feed writer.
-   */
-  void close();
-};
--- a/browser/components/feeds/src/BrowserFeeds.manifest
+++ b/browser/components/feeds/src/BrowserFeeds.manifest
@@ -18,12 +18,11 @@ contract @mozilla.org/streamconv;1?from=
 component {2376201c-bbc6-472f-9b62-7548040a61c6} FeedConverter.js
 contract @mozilla.org/browser/feeds/result-service;1 {2376201c-bbc6-472f-9b62-7548040a61c6}
 component {4f91ef2e-57ba-472e-ab7a-b4999e42d6c0} FeedConverter.js
 contract @mozilla.org/network/protocol;1?name=feed {4f91ef2e-57ba-472e-ab7a-b4999e42d6c0}
 component {1c31ed79-accd-4b94-b517-06e0c81999d5} FeedConverter.js
 contract @mozilla.org/network/protocol;1?name=pcast {1c31ed79-accd-4b94-b517-06e0c81999d5}
 component {49bb6593-3aff-4eb3-a068-2712c28bd58e} FeedWriter.js
 contract @mozilla.org/browser/feeds/result-writer;1 {49bb6593-3aff-4eb3-a068-2712c28bd58e}
-category JavaScript-global-constructor BrowserFeedWriter @mozilla.org/browser/feeds/result-writer;1
 component {792a7e82-06a0-437c-af63-b2d12e808acc} WebContentConverter.js
 contract @mozilla.org/embeddor.implemented/web-content-handler-registrar;1 {792a7e82-06a0-437c-af63-b2d12e808acc}
 category app-startup WebContentConverter service,@mozilla.org/embeddor.implemented/web-content-handler-registrar;1 application={3c2e2abc-06d4-11e1-ac3b-374f68613e61} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} application={aa3c5121-dab2-40e2-81ca-7ea25febc110} application={a23983c0-fd0e-11dc-95ff-0800200c9a66}
--- a/browser/components/feeds/src/FeedWriter.js
+++ b/browser/components/feeds/src/FeedWriter.js
@@ -1118,17 +1118,17 @@ FeedWriter.prototype = {
   },
 
   _window: null,
   _document: null,
   _feedURI: null,
   _feedPrincipal: null,
   _handlersMenuList: null,
 
-  // nsIFeedWriter
+  // BrowserFeedWriter WebIDL methods
   init: function FW_init(aWindow) {
     var window = aWindow;
     this._feedURI = this._getOriginalURI(window);
     if (!this._feedURI)
       return;
 
     this._window = window;
     this._document = window.document;
@@ -1371,18 +1371,14 @@ FeedWriter.prototype = {
           Cu.evalInSandbox(codeStr, self._contentSandbox);
           self._contentSandbox.menuItem = null;
           self._contentSandbox.dataURL = null;
         }
       });
   },
 
   classID: FEEDWRITER_CID,
-  classInfo: XPCOMUtils.generateCI({classID: FEEDWRITER_CID,
-                                    contractID: FEEDWRITER_CONTRACTID,
-                                    interfaces: [Ci.nsIFeedWriter],
-                                    flags: Ci.nsIClassInfo.DOM_OBJECT}),
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFeedWriter,
-                                         Ci.nsIDOMEventListener, Ci.nsIObserver,
-                                         Ci.nsINavHistoryObserver])
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener, Ci.nsIObserver,
+                                         Ci.nsINavHistoryObserver,
+                                         Ci.nsIDOMGlobalPropertyInitializer])
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FeedWriter]);
new file mode 100644
--- /dev/null
+++ b/browser/components/feeds/src/FeedWriterEnabled.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "js/TypeDecls.h"
+#include "nsGlobalWindow.h"
+#include "nsIPrincipal.h"
+#include "nsIURI.h"
+#include "nsString.h"
+#include "xpcpublic.h"
+
+namespace mozilla {
+
+struct FeedWriterEnabled {
+  static bool IsEnabled(JSContext* cx, JSObject* aGlobal)
+  {
+    // Make sure the global is a window
+    nsGlobalWindow* win = xpc::WindowGlobalOrNull(aGlobal);
+    if (!win) {
+      return false;
+    }
+
+    // Make sure that the principal is about:feeds.
+    nsCOMPtr<nsIPrincipal> principal = win->GetPrincipal();
+    NS_ENSURE_TRUE(principal, false);
+    nsCOMPtr<nsIURI> uri;
+    principal->GetURI(getter_AddRefs(uri));
+    if (!uri) {
+      return false;
+    }
+
+    // First check the scheme to avoid getting long specs in the common case.
+    bool isAbout = false;
+    uri->SchemeIs("about", &isAbout);
+    if (!isAbout) {
+      return false;
+    }
+
+    // Now check the spec itself
+    nsAutoCString spec;
+    uri->GetSpec(spec);
+    return spec.Equals("about:feeds");
+  }
+};
+
+}
--- a/browser/components/feeds/src/moz.build
+++ b/browser/components/feeds/src/moz.build
@@ -3,16 +3,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     'nsFeedSniffer.cpp',
 ]
 
+EXPORTS.mozilla += [
+    'FeedWriterEnabled.h',
+]
+
 EXTRA_COMPONENTS += [
     'BrowserFeeds.manifest',
     'FeedConverter.js',
     'WebContentConverter.js',
 ]
 
 EXTRA_PP_COMPONENTS += [
     'FeedWriter.js',
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -159,18 +159,16 @@ var interfaceNamesInGlobalScope =
     {name: "BluetoothDeviceEvent", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "BluetoothManager", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "BluetoothStatusChangedEvent", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "BoxObject", xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    {name: "BrowserFeedWriter", desktop: true},
-// IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "CallEvent", b2g: true, pref: "dom.telephony.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "CallGroupErrorEvent", b2g: true, pref: "dom.telephony.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CameraCapabilities",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CameraControl",
 // IMPORTANT: Do not change this list without review from a DOM peer!
new file mode 100644
--- /dev/null
+++ b/dom/webidl/BrowserFeedWriter.webidl
@@ -0,0 +1,20 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+[JSImplementation="@mozilla.org/browser/feeds/result-writer;1",
+ Func="mozilla::FeedWriterEnabled::IsEnabled",
+ Constructor]
+interface BrowserFeedWriter {
+  /**
+   * Writes the feed content, assumes that the feed writer is initialized.
+   */
+  void writeContent();
+
+  /**
+   * Uninitialize the feed writer.
+   */
+  void close();
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -607,8 +607,12 @@ if CONFIG['MOZ_GAMEPAD']:
     ]
 
 if CONFIG['MOZ_B2G_BT']:
     GENERATED_EVENTS_WEBIDL_FILES += [
         'BluetoothDeviceEvent.webidl',
         'BluetoothStatusChangedEvent.webidl',
     ]
 
+if CONFIG['MOZ_BUILD_APP'] in ['browser', 'xulrunner']:
+    WEBIDL_FILES += [
+        'BrowserFeedWriter.webidl',
+    ]