From 1ce346ca0057d1dbc39a82dc351daca40b3e207e Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 19 Mar 2014 12:29:00 -0400 Subject: [PATCH] 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 | 5 -- browser/components/feeds/public/moz.build | 1 - .../components/feeds/public/nsIFeedWriter.idl | 35 -------------- .../feeds/src/BrowserFeeds.manifest | 1 - browser/components/feeds/src/FeedWriter.js | 12 ++--- .../components/feeds/src/FeedWriterEnabled.h | 47 +++++++++++++++++++ browser/components/feeds/src/moz.build | 4 ++ .../mochitest/general/test_interfaces.html | 2 - dom/webidl/BrowserFeedWriter.webidl | 20 ++++++++ dom/webidl/moz.build | 4 ++ 10 files changed, 79 insertions(+), 52 deletions(-) delete mode 100644 browser/components/feeds/public/nsIFeedWriter.idl create mode 100644 browser/components/feeds/src/FeedWriterEnabled.h create mode 100644 dom/webidl/BrowserFeedWriter.webidl diff --git a/browser/components/feeds/content/subscribe.js b/browser/components/feeds/content/subscribe.js index c8cb3a03a959..34de59689fce 100644 --- a/browser/components/feeds/content/subscribe.js +++ b/browser/components/feeds/content/subscribe.js @@ -11,7 +11,6 @@ var SubscribeHandler = { init: function SH_init() { this._feedWriter = new BrowserFeedWriter(); - this._feedWriter.init(window); }, writeContent: function SH_writeContent() { @@ -20,9 +19,5 @@ var SubscribeHandler = { uninit: function SH_uninit() { this._feedWriter.close(); - }, - - subscribe: function SH_subscribe() { - this._feedWriter.subscribe(); } }; diff --git a/browser/components/feeds/public/moz.build b/browser/components/feeds/public/moz.build index 3f1b6d29a936..664ff93bd403 100644 --- a/browser/components/feeds/public/moz.build +++ b/browser/components/feeds/public/moz.build @@ -6,7 +6,6 @@ XPIDL_SOURCES += [ 'nsIFeedResultService.idl', - 'nsIFeedWriter.idl', 'nsIWebContentConverterRegistrar.idl', ] diff --git a/browser/components/feeds/public/nsIFeedWriter.idl b/browser/components/feeds/public/nsIFeedWriter.idl deleted file mode 100644 index 4018067a9d19..000000000000 --- 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(); -}; diff --git a/browser/components/feeds/src/BrowserFeeds.manifest b/browser/components/feeds/src/BrowserFeeds.manifest index 82d895de77c7..cf558af23a6c 100644 --- a/browser/components/feeds/src/BrowserFeeds.manifest +++ b/browser/components/feeds/src/BrowserFeeds.manifest @@ -23,7 +23,6 @@ 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} diff --git a/browser/components/feeds/src/FeedWriter.js b/browser/components/feeds/src/FeedWriter.js index ea15e9d3d539..a0dabea1b91d 100644 --- a/browser/components/feeds/src/FeedWriter.js +++ b/browser/components/feeds/src/FeedWriter.js @@ -1123,7 +1123,7 @@ FeedWriter.prototype = { _feedPrincipal: null, _handlersMenuList: null, - // nsIFeedWriter + // BrowserFeedWriter WebIDL methods init: function FW_init(aWindow) { var window = aWindow; this._feedURI = this._getOriginalURI(window); @@ -1376,13 +1376,9 @@ FeedWriter.prototype = { }, 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]); diff --git a/browser/components/feeds/src/FeedWriterEnabled.h b/browser/components/feeds/src/FeedWriterEnabled.h new file mode 100644 index 000000000000..e61824115db3 --- /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 principal = win->GetPrincipal(); + NS_ENSURE_TRUE(principal, false); + nsCOMPtr 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"); + } +}; + +} diff --git a/browser/components/feeds/src/moz.build b/browser/components/feeds/src/moz.build index 31639f793962..7fd84f13e6ed 100644 --- a/browser/components/feeds/src/moz.build +++ b/browser/components/feeds/src/moz.build @@ -8,6 +8,10 @@ SOURCES += [ 'nsFeedSniffer.cpp', ] +EXPORTS.mozilla += [ + 'FeedWriterEnabled.h', +] + EXTRA_COMPONENTS += [ 'BrowserFeeds.manifest', 'FeedConverter.js', diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 2d83e7401ccd..a5ad22971aa3 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -163,8 +163,6 @@ var interfaceNamesInGlobalScope = {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! diff --git a/dom/webidl/BrowserFeedWriter.webidl b/dom/webidl/BrowserFeedWriter.webidl new file mode 100644 index 000000000000..d756a8837ebc --- /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(); +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 41c7566e2d71..c07545993e0b 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -612,3 +612,7 @@ if CONFIG['MOZ_B2G_BT']: 'BluetoothStatusChangedEvent.webidl', ] +if CONFIG['MOZ_BUILD_APP'] in ['browser', 'xulrunner']: + WEBIDL_FILES += [ + 'BrowserFeedWriter.webidl', + ]