30 #include <nsINetUtil.h>
31 #include <nsIPrefService.h>
32 #include <nsIProgrammingLanguage.h>
33 #include <nsIProperties.h>
34 #include <nsISupportsPrimitives.h>
37 #include <nsIWritablePropertyBag2.h>
38 #include <sbILibraryFactory.h>
39 #include <sbILibraryManager.h>
41 #include <nsComponentManagerUtils.h>
42 #include <nsHashKeys.h>
45 #include <nsNetUtil.h>
46 #include <nsServiceManagerUtils.h>
47 #include <nsXPCOMCIDInternal.h>
61 #define LOG(args) LOG_LIB(args)
68 "site:scanMediaOnCreation"
78 "site:scanMediaOnCreation",
93 "classinfo:classDescription",
94 "classinfo:contractID",
96 "classinfo:implementationLanguage",
102 "site:createSimpleMediaList",
103 "site:createMediaListFromURL",
104 "site:createMediaItem",
105 "site:getMediaListBySiteID",
115 "site:getItemByGuid",
116 "site:getItemByIndex",
117 "site:enumerateAllItems",
118 "site:enumerateItemsByProperty",
127 "site:removeByIndex",
128 "site:getDistinctValuesForProperty",
160 LOG_LIB((
"sbRemoteSiteLibrary::sbRemoteSiteLibrary()"));
165 LOG_LIB((
"sbRemoteSiteLibrary::~sbRemoteSiteLibrary()"));
176 sbRemoteSiteLibrary::GetFilename( nsAString &aFilename )
178 LOG_LIB((
"sbRemoteSiteLibrary::GetFilename()"));
180 aFilename.Assign(mFilename);
186 sbRemoteSiteLibrary::ConnectToSiteLibrary(
const nsACString &aDomain,
187 const nsACString &
aPath )
190 LOG_LIB((
"sbRemoteSiteLibrary::ConnectToSiteLibrary(domain:%s path:%s)",
191 aDomain.BeginReading(), aPath.BeginReading() ));
195 LOG_LIB((
"sbRemoteSiteLibrary::ConnectToSiteLibrary() - no site db file "));
196 return NS_ERROR_FAILURE;
202 rv = siteDBFile->GetLeafName(mFilename);
203 NS_ENSURE_SUCCESS( rv, rv );
207 nsCOMPtr<sbILibraryFactory> libFactory(
209 NS_ENSURE_SUCCESS( rv, rv );
212 nsCOMPtr<nsIWritablePropertyBag2> propBag(
213 do_CreateInstance( NS_HASH_PROPERTY_BAG_CONTRACTID, &rv ) );
214 NS_ENSURE_SUCCESS( rv, rv );
216 rv = propBag->SetPropertyAsInterface( NS_LITERAL_STRING(
"databaseFile"),
218 NS_ENSURE_SUCCESS( rv, rv );
221 rv = libFactory->CreateLibrary( propBag, getter_AddRefs(
mLibrary) );
222 NS_ENSURE_SUCCESS( rv, rv );
225 NS_LITERAL_STRING(
"1" ) );
226 NS_ENSURE_SUCCESS( rv, rv );
230 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv );
231 NS_ENSURE_SUCCESS( rv, rv );
234 rv = libraryManager->HasLibrary(
mLibrary, &hasLibrary );
235 NS_ENSURE_SUCCESS( rv, rv );
238 rv = libraryManager->RegisterLibrary(
mLibrary, PR_FALSE );
239 NS_ENSURE_SUCCESS( rv, rv );
243 NS_ENSURE_SUCCESS( rv, rv );
257 LOG_LIB((
"sbRemoteSiteLibrary::InitInternalMediaList()"));
260 nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(
mLibrary);
261 NS_ENSURE_TRUE( mediaList, NS_ERROR_FAILURE );
263 nsCOMPtr<sbIMediaListView> mediaListView;
264 nsresult rv = mediaList->CreateView( nsnull, getter_AddRefs(mediaListView) );
265 NS_ENSURE_SUCCESS( rv, rv );
273 NS_ENSURE_SUCCESS( rv, rv );
281 already_AddRefed<nsIFile>
283 const nsACString &aPath )
286 LOG_LIB((
"sbRemoteSiteLibrary::GetSiteLibraryFile(domain:%s path:%s)",
287 aDomain.BeginReading(),
288 aPath.BeginReading() ));
290 nsCOMPtr<nsIURI> siteURI =
GetURI();
292 LOG_LIB((
"sbRemoteSiteLibrary::GetSiteLibraryFile() -- FAILED to get URI"));
296 nsCString domain(aDomain);
297 nsCString
path(aPath);
299 if ( NS_FAILED(rv) ) {
302 LOG_LIB((
"sbRemoteSiteLibrary::GetSiteLibraryFile() -- FAILED URI Check"));
308 NS_ENSURE_SUCCESS( rv, nsnull );
311 nsCOMPtr<nsIProperties> directoryService(
312 do_GetService( NS_DIRECTORY_SERVICE_CONTRACTID, &rv ) );
313 NS_ENSURE_SUCCESS( rv, nsnull );
316 nsCOMPtr<nsIFile> siteDBFile;
317 rv = directoryService->Get(
"ProfD", NS_GET_IID(nsIFile),
318 getter_AddRefs(siteDBFile) );
319 NS_ENSURE_SUCCESS( rv, nsnull );
322 siteDBFile->Append( NS_LITERAL_STRING(
"db") );
323 siteDBFile->Append(filename);
325 nsIFile* outFile = nsnull;
326 siteDBFile.swap(outFile);
331 already_AddRefed<nsIURI>
334 LOG_LIB((
"sbRemoteSiteLibrary::GetURI()"));
337 nsCOMPtr<sbISecurityMixin> mixin( do_QueryInterface(
mSecurityMixin, &rv ) );
338 NS_ENSURE_SUCCESS( rv, nsnull );
342 rv = mixin->GetCodebase( &siteURI );
343 NS_ENSURE_SUCCESS( rv, nsnull );
351 const nsACString& aPath,
359 nsCString domain,
path;
363 NS_ENSURE_SUCCESS( rv, rv );
366 NS_ENSURE_SUCCESS( rv, rv );
371 domain.Assign(aDomain);
376 nsCOMPtr<nsINetUtil> netUtil = do_GetService( NS_NETUTIL_CONTRACTID, &rv );
377 NS_ENSURE_SUCCESS( rv, nsnull );
379 nsCString escapedDomain;
380 rv = netUtil->EscapeString( domain, nsINetUtil::ESCAPE_XALPHAS,
382 NS_ENSURE_SUCCESS( rv, nsnull );
384 nsCString escapedPath;
385 rv = netUtil->EscapeString( path, nsINetUtil::ESCAPE_XALPHAS,
387 NS_ENSURE_SUCCESS( rv, nsnull );
389 nsString
filename = NS_ConvertUTF8toUTF16(escapedDomain);
390 filename.Append( NS_ConvertUTF8toUTF16(escapedPath) );
391 filename.AppendLiteral(
".db");
393 _retval.Assign(filename);
#define SB_IMPL_SECURITYCHECKEDCOMP_INIT(_class)
static nsresult CheckURI(nsACString &aDomain, nsACString &aPath, nsIURI *aURI)
sbRemoteSiteLibrary(sbRemotePlayer *aRemotePlayer)
static const char * sPublicRProperties[]
static nsresult FixupDomain(const nsACString &aDomain, nsACString &_retval)
#define SB_PROPERTY_HIDDEN
readonly attribute AString filename
The filename of the library file Set only in debug builds.
virtual nsresult InitInternalMediaList()
nsISecurityCheckedComponent
static const char * sPublicMethods[]
#define SB_LOCALDATABASE_LIBRARYFACTORY_CONTRACTID
An interface for a sandbox library created by the website.
already_AddRefed< nsIFile > GetSiteLibraryFile(const nsACString &aDomain, const nsACString &aPath)
A marker interface for objects that aggregate the security mixin.
nsRefPtr< sbRemoteSiteMediaList > mRemSiteMediaList
nsRefPtr< sbRemoteMediaListBase > mRemMediaList
static nsresult FixupPath(nsIURI *aURI, nsACString &_retval)
nsCOMPtr< nsISecurityCheckedComponent > mSecurityMixin
An interface to control a media library from remote web pages.
The result of a filtering expression in a library.
nsCOMPtr< sbILibrary > mLibrary
nsRefPtr< sbRemotePlayer > mRemotePlayer
virtual ~sbRemoteSiteLibrary()
#define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class)
already_AddRefed< nsIURI > GetURI()
static const char * sPublicWProperties[]
static nsresult GetFilenameForSiteLibraryInternal(const nsACString &aDomain, const nsACString &aPath, PRBool aDoFixup, nsAString &_retval)
NS_IMPL_ISUPPORTS_INHERITED2(sbRemoteSiteLibrary, sbRemoteLibraryBase, sbIRemoteSiteLibrary, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER8(sbRemoteSiteLibrary