sbRemoteSiteLibraryResource.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 <sbILibrary.h>
28 #include <sbIPropertyManager.h>
29 #include <sbIRemotePlayer.h>
30 
32 #include <sbStandardProperties.h>
33 #include <nsServiceManagerUtils.h>
34 #include <prlog.h>
35 
36 /*
37  * To log this module, set the following environment variable:
38  * NSPR_LOG_MODULES=sbRemoteLibraryResource:5
39  * LOG_RES() defined in sbRemoteLibraryResource.h/.cpp
40  */
41 
44 
46  sbIMediaItem *aMediaItem ) :
47  sbRemoteLibraryResource( aRemotePlayer, aMediaItem )
48 {
49  NS_ASSERTION( aRemotePlayer, "Null remote player!" );
50  NS_ASSERTION( aMediaItem, "Null media item!" );
51 
52  LOG_RES(("sbRemoteSiteLibraryResource::sbRemoteSiteLibraryResource()"));
53 }
54 
56  LOG_RES(("sbRemoteSiteLibraryResource::~sbRemoteSiteLibraryResource()"));
57 }
58 
59 // ----------------------------------------------------------------------------
60 //
61 // sbILibraryResource
62 //
63 // ----------------------------------------------------------------------------
64 
65 NS_IMETHODIMP
67  nsAString &_retval )
68 {
69  LOG_RES(( "sbRemoteSiteLibraryResource::GetProperty(%s)",
70  NS_LossyConvertUTF16toASCII(aID).get() ));
71 
72  // First call the base class impl and see what it says. contentURL will get
73  // denied as it is not remoteReadable by default, we special case for site
74  // objects
75  nsresult rv = sbRemoteLibraryResource::GetProperty( aID, _retval );
76  if ( NS_SUCCEEDED(rv) || !aID.EqualsLiteral(SB_PROPERTY_CONTENTURL) ) {
77  return rv;
78  }
79 
80  // Do some special checking for contentURL properties. Sites should be able
81  // to access the contentURLs for tracks that aren't on the hard drive.
82  nsString contentURL;
83  rv = mMediaItem->GetProperty( aID, contentURL );
84  NS_ENSURE_SUCCESS( rv, rv );
85 
86  if ( StringBeginsWith( contentURL, NS_LITERAL_STRING("file:") ) ) {
87  LOG_RES(( "sbRemoteSiteLibraryResource::GetProperty() - "
88  "Disallowing access to 'file:' URI from contentURL property" ));
89  _retval.AssignLiteral("__BLOCKED__");
90  return NS_ERROR_FAILURE;
91  }
92  LOG_RES(( "sbRemoteSiteLibraryResource::GetProperty() - "
93  "Allowing access to non-file contentURL to site item/list/lib: %s",
94  NS_LossyConvertUTF16toASCII(contentURL).get() ));
95 
96  _retval.Assign(contentURL);
97  return NS_OK;
98 }
99 
return NS_OK
NS_IMETHOD GetProperty(const nsAString &aID, nsAString &_retval)
nsCOMPtr< sbIMediaItem > mMediaItem
NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD GetProperty(const nsAString &aID, nsAString &_retval)
General interface to data resources.
NS_IMPL_ISUPPORTS1(sbRemoteSiteLibraryResource, sbILibraryResource) sbRemoteSiteLibraryResource
Interface that defines a single item of media in the system.
#define SB_PROPERTY_CONTENTURL
#define LOG_RES(args)