sbDataRemoteWrapper.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 #include <nsMemory.h>
27 #include <nsIClassInfoImpl.h>
28 #include <nsIProgrammingLanguage.h>
29 
30 #include "sbDataRemoteWrapper.h"
31 
32 // CID for the original dataremote implementation, to which
33 // this object will delegate.
34 // {e0990420-e9c0-11dd-ba2f-0800200c9a66}
35 #define SB_DATAREMOTE_CID \
36 { 0xe0990420, 0xe9c0, 0x11dd, \
37  { 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
38 static NS_DEFINE_CID(kDataRemoteCID, SB_DATAREMOTE_CID);
39 
40 
42 
46 
47 NS_DECL_CLASSINFO(sbDataRemoteWrapper)
48 NS_IMPL_THREADSAFE_CI(sbDataRemoteWrapper)
49 
50 
51 sbDataRemoteWrapper::sbDataRemoteWrapper()
52 : mInnerDataRemote(nsnull),
53  mObserver(nsnull)
54 {}
55 
56 sbDataRemoteWrapper::~sbDataRemoteWrapper()
57 {
58  nsresult rv;
59  if (mObserver) {
60  // Destructor won't be called unless unbound, but
61  // do this anyway.
62  rv = Unbind();
63  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to unbind");
64  }
65  mInnerDataRemote = nsnull;
66 }
67 
69 {
70  nsresult rv;
71  // Forward everything to the original dataremote implementation
72  mInnerDataRemote =
73  do_CreateInstance(kDataRemoteCID, &rv);
74  NS_ENSURE_SUCCESS(rv, rv);
75  return rv;
76 }
77 
78 //
79 // sbIDataRemote
80 //
81 // Redirect getter/setters to methods rather than attributes
82 // in order to work around BMO 304048.
83 //
84 
85 /* attribute AString stringValue; */
86 NS_IMETHODIMP sbDataRemoteWrapper::GetStringValue(nsAString & aStringValue)
87 {
88  NS_ENSURE_STATE(mInnerDataRemote);
89  return mInnerDataRemote->GetAsString(aStringValue);
90 }
91 NS_IMETHODIMP sbDataRemoteWrapper::SetStringValue(const nsAString & aStringValue)
92 {
93  NS_ENSURE_STATE(mInnerDataRemote);
94  return mInnerDataRemote->SetAsString(aStringValue);
95 }
96 
97 /* attribute boolean boolValue; */
98 NS_IMETHODIMP sbDataRemoteWrapper::GetBoolValue(PRBool *aBoolValue)
99 {
100  NS_ENSURE_STATE(mInnerDataRemote);
101  return mInnerDataRemote->GetAsBool(aBoolValue);
102 }
103 NS_IMETHODIMP sbDataRemoteWrapper::SetBoolValue(PRBool aBoolValue)
104 {
105  NS_ENSURE_STATE(mInnerDataRemote);
106  return mInnerDataRemote->SetAsBool(aBoolValue);
107 }
108 
109 /* attribute long long intValue; */
110 NS_IMETHODIMP sbDataRemoteWrapper::GetIntValue(PRInt64 *aIntValue)
111 {
112  NS_ENSURE_STATE(mInnerDataRemote);
113  return mInnerDataRemote->GetAsInt(aIntValue);
114 }
115 NS_IMETHODIMP sbDataRemoteWrapper::SetIntValue(PRInt64 aIntValue)
116 {
117  NS_ENSURE_STATE(mInnerDataRemote);
118  return mInnerDataRemote->SetAsInt(aIntValue);
119 }
120 
121 /* void bindObserver (in nsIObserver aObserver, [optional] in boolean aSuppressFirst); */
122 NS_IMETHODIMP sbDataRemoteWrapper::BindObserver(nsIObserver *aObserver, PRBool aSuppressFirst)
123 {
124  NS_ENSURE_STATE(mInnerDataRemote);
125  NS_ENSURE_ARG_POINTER(aObserver);
126  mObserver = aObserver;
127  return mInnerDataRemote->BindObserver(this, aSuppressFirst);
128 }
129 
130 /* void bindRemoteObserver (in sbIRemoteObserver, [optional] in boolean aSuppressFirst); */
131 NS_IMETHODIMP sbDataRemoteWrapper::BindRemoteObserver(sbIRemoteObserver *aObserver, PRBool aSuppressFirst)
132 {
133  NS_ENSURE_STATE(mInnerDataRemote);
134  NS_ENSURE_ARG_POINTER(aObserver);
135 
136  // We don't pretend like we are this observer. It's not required by the
137  // security model.
138  return mInnerDataRemote->BindRemoteObserver(aObserver, aSuppressFirst);
139 }
140 
141 /* void unbind (); */
143 {
144  NS_ENSURE_STATE(mInnerDataRemote);
145  nsresult rv = mInnerDataRemote->Unbind();
146  mObserver = nsnull;
147  return rv;
148 }
149 
150 //
151 // nsIObserver
152 //
153 // Intercept Observer callbacks in order to update the subject param
154 // to point to this object.
155 //
156 
157 NS_IMETHODIMP sbDataRemoteWrapper::Observe( nsISupports *aSubject,
158  const char *aTopic,
159  const PRUnichar *aData )
160 {
161  NS_ENSURE_STATE(mObserver);
162  // Make sure our observer thinks the message is coming
163  // from this instance
164  return mObserver->Observe(NS_ISUPPORTS_CAST(sbIDataRemote*, this), aTopic, aData);
165 }
NS_SCRIPTABLE NS_IMETHOD BindObserver(nsIObserver *aObserver, PRBool aSuppressFirst)
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
An interface for accessing, and binding to, stored data.
static NS_DEFINE_CID(kDataRemoteCID,{0xe0990420, 0xe9c0, 0x11dd,{0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66}})
NS_SCRIPTABLE NS_IMETHOD GetStringValue(nsAString &aStringValue)
NS_SCRIPTABLE NS_IMETHOD SetIntValue(PRInt64 aIntValue)
NS_SCRIPTABLE NS_IMETHOD GetIntValue(PRInt64 *aIntValue)
NS_IMPL_ISUPPORTS3(sbLibraryConstraint, sbILibraryConstraint, nsISerializable, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER3(sbLibraryConstraint
sbIJobCancelable NS_DECL_CLASSINFO(sbGstreamerMediaInspector)
NS_SCRIPTABLE NS_IMETHOD Unbind(void)
NS_SCRIPTABLE NS_IMETHOD BindRemoteObserver(sbIRemoteObserver *aObserver, PRBool aSuppressFirst)
NS_SCRIPTABLE NS_IMETHOD SetBoolValue(PRBool aBoolValue)
NS_IMPL_CI_INTERFACE_GETTER2(sbDataRemoteWrapper, sbIDataRemote, nsIClassInfo) sbDataRemoteWrapper
NS_SCRIPTABLE NS_IMETHOD GetBoolValue(PRBool *aBoolValue)
NS_SCRIPTABLE NS_IMETHOD SetStringValue(const nsAString &aStringValue)
#define SB_DATAREMOTE_CID
Lightweight Observer style interface for use with sbIRemotePlayer::addListener.
_updateTextAndScrollDataForFrame aData