sbRemoteWrappingSimpleEnumerator.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 
27 #include "sbRemoteAPIUtils.h"
30 
31 #include <sbClassInfoUtils.h>
32 #include <sbIMediaItem.h>
33 
34 #include <nsAutoPtr.h>
35 #include <nsStringGlue.h>
36 
37 const static char* sPublicWProperties[] =
38 {
39  // Need this empty string to make VC happy
40  ""
41 };
42 
43 const static char* sPublicRProperties[] =
44 {
45  // Need this empty string to make VC happy
46  ""
47 };
48 
49 const static char* sPublicMethods[] =
50 {
51  // internal for helper classes like this
52  // nsISimpleEnumerator
53  "helper:hasMoreElements",
54  "helper:getNext"
55 };
56 
62 
67 
68 SB_IMPL_CLASSINFO_INTERFACES_ONLY(sbRemoteWrappingSimpleEnumerator)
69 
70 SB_IMPL_SECURITYCHECKEDCOMP_INIT(sbRemoteWrappingSimpleEnumerator)
71 
72 // ---------------------------------------------------------------------------
73 //
74 // sbISecurityAggregator
75 //
76 // ---------------------------------------------------------------------------
77 
78 NS_IMETHODIMP
79 sbRemoteWrappingSimpleEnumerator::GetRemotePlayer(sbIRemotePlayer * *aRemotePlayer)
80 {
81  NS_ENSURE_STATE(mRemotePlayer);
82  NS_ENSURE_ARG_POINTER(aRemotePlayer);
83 
84  nsresult rv;
85  *aRemotePlayer = nsnull;
86 
87  nsCOMPtr<sbIRemotePlayer> remotePlayer;
88 
89  rv = mRemotePlayer->QueryInterface( NS_GET_IID( sbIRemotePlayer ), getter_AddRefs( remotePlayer ) );
90  NS_ENSURE_SUCCESS( rv, rv );
91 
92  remotePlayer.swap( *aRemotePlayer );
93 
94  return NS_OK;
95 }
96 
97 // ---------------------------------------------------------------------------
98 //
99 // nsISimpleEnumerator
100 //
101 // ---------------------------------------------------------------------------
102 
103 NS_IMETHODIMP
104 sbRemoteWrappingSimpleEnumerator::HasMoreElements(PRBool* _retval)
105 {
106  NS_ENSURE_ARG_POINTER(_retval);
107 
108  return mWrapped->HasMoreElements(_retval);
109 }
110 
111 NS_IMETHODIMP
112 sbRemoteWrappingSimpleEnumerator::GetNext(nsISupports** _retval)
113 {
114  NS_ENSURE_ARG_POINTER(_retval);
115 
116  nsCOMPtr<nsISupports> supports;
117  nsresult rv = mWrapped->GetNext(getter_AddRefs(supports));
118  NS_ENSURE_SUCCESS(rv, rv);
119 
120  nsCOMPtr<sbIIndexedMediaItem> item = do_QueryInterface(supports, &rv);
121  if (NS_SUCCEEDED(rv)) {
122  // we have an IndexedMediaItem, we're handling a selection enumeration
123  nsRefPtr<sbRemoteIndexedMediaItem> indexedMediaItem =
125  NS_ENSURE_TRUE(indexedMediaItem, NS_ERROR_OUT_OF_MEMORY);
126 
127  rv = indexedMediaItem->Init();
128  NS_ENSURE_SUCCESS(rv, rv);
129  NS_ADDREF( *_retval = NS_ISUPPORTS_CAST(sbIIndexedMediaItem*,
130  indexedMediaItem) );
131  }
132  else {
133  nsCOMPtr<sbIMediaItem> item = do_QueryInterface(supports, &rv);
134  if (NS_SUCCEEDED(rv)) {
135  nsCOMPtr<sbIMediaItem> remoteItem;
136  rv = SB_WrapMediaItem(mRemotePlayer, item, getter_AddRefs(remoteItem));
137  NS_ENSURE_SUCCESS(rv, rv);
138  NS_ADDREF( *_retval = NS_ISUPPORTS_CAST(sbIMediaItem*,
139  remoteItem) );
140  }
141  }
142 
143  return NS_OK;
144 }
145 
#define SB_IMPL_SECURITYCHECKEDCOMP_INIT(_class)
Definition: sbRemoteAPI.h:82
return NS_OK
NS_IMPL_ISUPPORTS4(sbRemoteWrappingSimpleEnumerator, nsIClassInfo, nsISecurityCheckedComponent, sbISecurityAggregator, nsISimpleEnumerator) NS_IMPL_CI_INTERFACE_GETTER3(sbRemoteWrappingSimpleEnumerator
NS_IMPL_CI_INTERFACE_GETTER3(sbMediaListEnumeratorWrapper, sbIMediaListEnumeratorWrapper, nsISimpleEnumerator, nsIClassInfo)
This interface is a composition of many of our other interfaces with the goal of exposing a more web-...
static const char * sPublicRProperties[]
static const char * sPublicMethods[]
A marker interface for objects that aggregate the security mixin.
A container for a media item and its index.
static const char * sPublicWProperties[]
static nsresult SB_WrapMediaItem(sbRemotePlayer *aRemotePlayer, sbIMediaItem *aMediaItem, sbIMediaItem **aRemoteMediaItem)
Interface that defines a single item of media in the system.
#define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class)