sbDataRemoteWrapper.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef nsDataRemoteWrapper_h__
26 #define nsDataRemoteWrapper_h__
27 
28 #include <nsIClassInfo.h>
29 #include <nsIObserver.h>
30 #include <nsCOMPtr.h>
31 #include <nsStringGlue.h>
32 #include <sbIDataRemote.h>
33 #include <sbPIDataRemote2.h>
34 #include <nsComponentManagerUtils.h>
35 
36 
37 #define SB_DATAREMOTEWRAPPER_CLASSNAME \
38  "Songbird Data Remote Wrapper Instance"
39 
40 // {1cb891b0-e9c5-11dd-ba2f-0800200c9a66}
41 #define SB_DATAREMOTEWRAPPER_CID \
42 { 0x1cb891b0, 0xe9c5, 0x11dd, \
43  { 0xba, 0x2f, 0xd1, 0x08, 0x02, 0x00, 0xc9, 0x66 } }
44 
45 #define SB_DATAREMOTEWRAPPER_CONTRACTID \
46  "@songbirdnest.com/Songbird/DataRemote;1"
47 
48 #define NS_FORWARD_SOME_SBIDATAREMOTE_METHODS(_to) \
49  NS_SCRIPTABLE NS_IMETHOD Init(const nsAString & aKey, const nsAString & aRoot) { return !_to ? NS_ERROR_NULL_POINTER : _to->Init(aKey, aRoot); } \
50  NS_SCRIPTABLE NS_IMETHOD BindProperty(nsIDOMElement *aElement, const nsAString & aProperty, PRBool aIsBool, PRBool aIsNot, const nsAString & aEvalString) { return !_to ? NS_ERROR_NULL_POINTER : _to->BindProperty(aElement, aProperty, aIsBool, aIsNot, aEvalString); } \
51  NS_SCRIPTABLE NS_IMETHOD BindAttribute(nsIDOMElement *aElement, const nsAString & aProperty, PRBool aIsBool, PRBool aIsNot, const nsAString & aEvalString) { return !_to ? NS_ERROR_NULL_POINTER : _to->BindAttribute(aElement, aProperty, aIsBool, aIsNot, aEvalString); } \
52  NS_SCRIPTABLE NS_IMETHOD DeleteBranch() { return !_to ? NS_ERROR_NULL_POINTER : _to->DeleteBranch(); }
53 
54 
55 /******************************************************************************
56  * \class sbDataRemoteWrapper
57  * \brief An adaptor for DataRemote that allows getters/setters to be used
58  * from an unprivileged web page context. This is a hack.
59  *
60  * The DataRemote ContractID "@songbirdnest.com/Songbird/DataRemote;1"
61  * now maps to this wrapper class, which delegates to the original
62  * implementation via the new sbPIDataRemote2 interface. This bypasses
63  * Mozilla Bug 304048, which prevents our Remote Web Page API from accessing
64  * properties on a JavaScript XPCOM component. This is a hack, but
65  * it is the safest, simplest way to improve performance until the
66  * DataRemote system is completely ripped out.
67  *
68  * \sa sbIDataRemote.idl
69  * https://bugzilla.mozilla.org/show_bug.cgi?id=304048
70  * xpconnect getters/setters don't have principals until after they
71  * pass or fail their security check
72  * http://bugzilla.songbirdnest.com/show_bug.cgi?id=8703
73  * "There is no data, there are only prefs"
74  * http://bugzilla.songbirdnest.com/show_bug.cgi?id=10806
75  * "Memory leak during playback"
76  *
77  *****************************************************************************/
79  public nsIClassInfo
80 {
81 public:
83  nsresult InitWrapper();
84 
86  NS_DECL_NSICLASSINFO
87  NS_DECL_NSIOBSERVER
89 
90  NS_SCRIPTABLE NS_IMETHOD Unbind(void);
91  NS_SCRIPTABLE NS_IMETHOD BindObserver(nsIObserver *aObserver, PRBool aSuppressFirst);
92  NS_SCRIPTABLE NS_IMETHOD BindRemoteObserver(sbIRemoteObserver *aObserver, PRBool aSuppressFirst);
93  NS_SCRIPTABLE NS_IMETHOD GetStringValue(nsAString & aStringValue);
94  NS_SCRIPTABLE NS_IMETHOD SetStringValue(const nsAString & aStringValue);
95  NS_SCRIPTABLE NS_IMETHOD GetBoolValue(PRBool *aBoolValue);
96  NS_SCRIPTABLE NS_IMETHOD SetBoolValue(PRBool aBoolValue);
97  NS_SCRIPTABLE NS_IMETHOD GetIntValue(PRInt64 *aIntValue);
98  NS_SCRIPTABLE NS_IMETHOD SetIntValue(PRInt64 aIntValue);
99 
100 private:
102  nsCOMPtr<sbPIDataRemote2> mInnerDataRemote;
103  nsCOMPtr<nsIObserver> mObserver;
104 };
105 
106 #endif
NS_SCRIPTABLE NS_IMETHOD BindObserver(nsIObserver *aObserver, PRBool aSuppressFirst)
An additional interface for accessing dataremote values. Adds the ability to access values via method...
An interface for accessing, and binding to, stored data.
NS_SCRIPTABLE NS_IMETHOD GetStringValue(nsAString &aStringValue)
NS_SCRIPTABLE NS_IMETHOD SetIntValue(PRInt64 aIntValue)
NS_SCRIPTABLE NS_IMETHOD GetIntValue(PRInt64 *aIntValue)
#define NS_FORWARD_SOME_SBIDATAREMOTE_METHODS(_to)
NS_SCRIPTABLE NS_IMETHOD Unbind(void)
NS_SCRIPTABLE NS_IMETHOD BindRemoteObserver(sbIRemoteObserver *aObserver, PRBool aSuppressFirst)
NS_SCRIPTABLE NS_IMETHOD SetBoolValue(PRBool aBoolValue)
NS_SCRIPTABLE NS_IMETHOD GetBoolValue(PRBool *aBoolValue)
NS_SCRIPTABLE NS_IMETHOD SetStringValue(const nsAString &aStringValue)
Lightweight Observer style interface for use with sbIRemotePlayer::addListener.