nsFileSystemDataSource.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. Implementation for a file system RDF data store.
  7. */
  8. #include "nsFileSystemDataSource.h"
  9. #include <ctype.h> // for toupper()
  10. #include <stdio.h>
  11. #include "nsArrayEnumerator.h"
  12. #include "nsCOMArray.h"
  13. #include "nsIRDFDataSource.h"
  14. #include "nsIRDFObserver.h"
  15. #include "nsIServiceManager.h"
  16. #include "nsXPIDLString.h"
  17. #include "nsRDFCID.h"
  18. #include "rdfutil.h"
  19. #include "rdf.h"
  20. #include "nsEnumeratorUtils.h"
  21. #include "nsIURL.h"
  22. #include "nsIFileURL.h"
  23. #include "nsNetUtil.h"
  24. #include "nsIInputStream.h"
  25. #include "nsIChannel.h"
  26. #include "nsIFile.h"
  27. #include "nsEscape.h"
  28. #include "nsCRTGlue.h"
  29. #include "nsAutoPtr.h"
  30. #include "prtime.h"
  31. #ifdef XP_WIN
  32. #include "windef.h"
  33. #include "winbase.h"
  34. #include "nsILineInputStream.h"
  35. #include "nsDirectoryServiceDefs.h"
  36. #endif
  37. #define NS_MOZICON_SCHEME "moz-icon:"
  38. static const char kFileProtocol[] = "file://";
  39. bool
  40. FileSystemDataSource::isFileURI(nsIRDFResource *r)
  41. {
  42. bool isFileURIFlag = false;
  43. const char *uri = nullptr;
  44. r->GetValueConst(&uri);
  45. if ((uri) && (!strncmp(uri, kFileProtocol, sizeof(kFileProtocol) - 1)))
  46. {
  47. // XXX HACK HACK HACK
  48. if (!strchr(uri, '#'))
  49. {
  50. isFileURIFlag = true;
  51. }
  52. }
  53. return(isFileURIFlag);
  54. }
  55. bool
  56. FileSystemDataSource::isDirURI(nsIRDFResource* source)
  57. {
  58. nsresult rv;
  59. const char *uri = nullptr;
  60. rv = source->GetValueConst(&uri);
  61. if (NS_FAILED(rv)) return(false);
  62. nsCOMPtr<nsIFile> aDir;
  63. rv = NS_GetFileFromURLSpec(nsDependentCString(uri), getter_AddRefs(aDir));
  64. if (NS_FAILED(rv)) return(false);
  65. bool isDirFlag = false;
  66. rv = aDir->IsDirectory(&isDirFlag);
  67. if (NS_FAILED(rv)) return(false);
  68. return(isDirFlag);
  69. }
  70. nsresult
  71. FileSystemDataSource::Init()
  72. {
  73. nsresult rv;
  74. mRDFService = do_GetService("@mozilla.org/rdf/rdf-service;1");
  75. NS_ENSURE_TRUE(mRDFService, NS_ERROR_FAILURE);
  76. rv = mRDFService->GetResource(NS_LITERAL_CSTRING("NC:FilesRoot"),
  77. getter_AddRefs(mNC_FileSystemRoot));
  78. nsresult tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
  79. getter_AddRefs(mNC_Child));
  80. if (NS_FAILED(tmp)) {
  81. rv = tmp;
  82. }
  83. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
  84. getter_AddRefs(mNC_Name));
  85. if (NS_FAILED(tmp)) {
  86. rv = tmp;
  87. }
  88. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
  89. getter_AddRefs(mNC_URL));
  90. if (NS_FAILED(tmp)) {
  91. rv = tmp;
  92. }
  93. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Icon"),
  94. getter_AddRefs(mNC_Icon));
  95. if (NS_FAILED(tmp)) {
  96. rv = tmp;
  97. }
  98. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Content-Length"),
  99. getter_AddRefs(mNC_Length));
  100. if (NS_FAILED(tmp)) {
  101. rv = tmp;
  102. }
  103. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IsDirectory"),
  104. getter_AddRefs(mNC_IsDirectory));
  105. if (NS_FAILED(tmp)) {
  106. rv = tmp;
  107. }
  108. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastModifiedDate"),
  109. getter_AddRefs(mWEB_LastMod));
  110. if (NS_FAILED(tmp)) {
  111. rv = tmp;
  112. }
  113. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FileSystemObject"),
  114. getter_AddRefs(mNC_FileSystemObject));
  115. if (NS_FAILED(tmp)) {
  116. rv = tmp;
  117. }
  118. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"),
  119. getter_AddRefs(mNC_pulse));
  120. if (NS_FAILED(tmp)) {
  121. rv = tmp;
  122. }
  123. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
  124. getter_AddRefs(mRDF_InstanceOf));
  125. if (NS_FAILED(tmp)) {
  126. rv = tmp;
  127. }
  128. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
  129. getter_AddRefs(mRDF_type));
  130. static const char16_t kTrue[] = {'t','r','u','e','\0'};
  131. static const char16_t kFalse[] = {'f','a','l','s','e','\0'};
  132. tmp = mRDFService->GetLiteral(kTrue, getter_AddRefs(mLiteralTrue));
  133. if (NS_FAILED(tmp)) {
  134. rv = tmp;
  135. }
  136. tmp = mRDFService->GetLiteral(kFalse, getter_AddRefs(mLiteralFalse));
  137. if (NS_FAILED(tmp)) {
  138. rv = tmp;
  139. }
  140. NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
  141. #ifdef USE_NC_EXTENSION
  142. rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "extension"),
  143. getter_AddRefs(mNC_extension));
  144. NS_ENSURE_SUCCESS(rv, rv);
  145. #endif
  146. #ifdef XP_WIN
  147. rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavorite"),
  148. getter_AddRefs(mNC_IEFavoriteObject));
  149. tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavoriteFolder"),
  150. getter_AddRefs(mNC_IEFavoriteFolder));
  151. if (NS_FAILED(tmp)) {
  152. rv = tmp;
  153. }
  154. NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
  155. nsCOMPtr<nsIFile> file;
  156. NS_GetSpecialDirectory(NS_WIN_FAVORITES_DIR, getter_AddRefs(file));
  157. if (file)
  158. {
  159. nsCOMPtr<nsIURI> furi;
  160. NS_NewFileURI(getter_AddRefs(furi), file);
  161. NS_ENSURE_TRUE(furi, NS_ERROR_FAILURE);
  162. file->GetNativePath(ieFavoritesDir);
  163. }
  164. #endif
  165. return NS_OK;
  166. }
  167. //static
  168. nsresult
  169. FileSystemDataSource::Create(nsISupports* aOuter, const nsIID& aIID, void **aResult)
  170. {
  171. NS_ENSURE_NO_AGGREGATION(aOuter);
  172. RefPtr<FileSystemDataSource> self = new FileSystemDataSource();
  173. if (!self)
  174. return NS_ERROR_OUT_OF_MEMORY;
  175. nsresult rv = self->Init();
  176. NS_ENSURE_SUCCESS(rv, rv);
  177. return self->QueryInterface(aIID, aResult);
  178. }
  179. NS_IMPL_ISUPPORTS(FileSystemDataSource, nsIRDFDataSource)
  180. NS_IMETHODIMP
  181. FileSystemDataSource::GetURI(char **uri)
  182. {
  183. NS_PRECONDITION(uri != nullptr, "null ptr");
  184. if (! uri)
  185. return NS_ERROR_NULL_POINTER;
  186. if ((*uri = NS_strdup("rdf:files")) == nullptr)
  187. return NS_ERROR_OUT_OF_MEMORY;
  188. return NS_OK;
  189. }
  190. NS_IMETHODIMP
  191. FileSystemDataSource::GetSource(nsIRDFResource* property,
  192. nsIRDFNode* target,
  193. bool tv,
  194. nsIRDFResource** source /* out */)
  195. {
  196. NS_PRECONDITION(property != nullptr, "null ptr");
  197. if (! property)
  198. return NS_ERROR_NULL_POINTER;
  199. NS_PRECONDITION(target != nullptr, "null ptr");
  200. if (! target)
  201. return NS_ERROR_NULL_POINTER;
  202. NS_PRECONDITION(source != nullptr, "null ptr");
  203. if (! source)
  204. return NS_ERROR_NULL_POINTER;
  205. *source = nullptr;
  206. return NS_RDF_NO_VALUE;
  207. }
  208. NS_IMETHODIMP
  209. FileSystemDataSource::GetSources(nsIRDFResource *property,
  210. nsIRDFNode *target,
  211. bool tv,
  212. nsISimpleEnumerator **sources /* out */)
  213. {
  214. // NS_NOTYETIMPLEMENTED("write me");
  215. return NS_ERROR_NOT_IMPLEMENTED;
  216. }
  217. NS_IMETHODIMP
  218. FileSystemDataSource::GetTarget(nsIRDFResource *source,
  219. nsIRDFResource *property,
  220. bool tv,
  221. nsIRDFNode **target /* out */)
  222. {
  223. NS_PRECONDITION(source != nullptr, "null ptr");
  224. if (! source)
  225. return NS_ERROR_NULL_POINTER;
  226. NS_PRECONDITION(property != nullptr, "null ptr");
  227. if (! property)
  228. return NS_ERROR_NULL_POINTER;
  229. NS_PRECONDITION(target != nullptr, "null ptr");
  230. if (! target)
  231. return NS_ERROR_NULL_POINTER;
  232. *target = nullptr;
  233. nsresult rv = NS_RDF_NO_VALUE;
  234. // we only have positive assertions in the file system data source.
  235. if (! tv)
  236. return NS_RDF_NO_VALUE;
  237. if (source == mNC_FileSystemRoot)
  238. {
  239. if (property == mNC_pulse)
  240. {
  241. nsIRDFLiteral *pulseLiteral;
  242. mRDFService->GetLiteral(u"12", &pulseLiteral);
  243. *target = pulseLiteral;
  244. return NS_OK;
  245. }
  246. }
  247. else if (isFileURI(source))
  248. {
  249. if (property == mNC_Name)
  250. {
  251. nsCOMPtr<nsIRDFLiteral> name;
  252. rv = GetName(source, getter_AddRefs(name));
  253. if (NS_FAILED(rv)) return(rv);
  254. if (!name) rv = NS_RDF_NO_VALUE;
  255. if (rv == NS_RDF_NO_VALUE) return(rv);
  256. return name->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  257. }
  258. else if (property == mNC_URL)
  259. {
  260. nsCOMPtr<nsIRDFLiteral> url;
  261. rv = GetURL(source, nullptr, getter_AddRefs(url));
  262. if (NS_FAILED(rv)) return(rv);
  263. if (!url) rv = NS_RDF_NO_VALUE;
  264. if (rv == NS_RDF_NO_VALUE) return(rv);
  265. return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  266. }
  267. else if (property == mNC_Icon)
  268. {
  269. nsCOMPtr<nsIRDFLiteral> url;
  270. bool isFavorite = false;
  271. rv = GetURL(source, &isFavorite, getter_AddRefs(url));
  272. if (NS_FAILED(rv)) return(rv);
  273. if (isFavorite || !url) rv = NS_RDF_NO_VALUE;
  274. if (rv == NS_RDF_NO_VALUE) return(rv);
  275. const char16_t *uni = nullptr;
  276. url->GetValueConst(&uni);
  277. if (!uni) return(NS_RDF_NO_VALUE);
  278. nsAutoString urlStr;
  279. urlStr.AssignLiteral(NS_MOZICON_SCHEME);
  280. urlStr.Append(uni);
  281. rv = mRDFService->GetLiteral(urlStr.get(), getter_AddRefs(url));
  282. if (NS_FAILED(rv) || !url) return(NS_RDF_NO_VALUE);
  283. return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  284. }
  285. else if (property == mNC_Length)
  286. {
  287. nsCOMPtr<nsIRDFInt> fileSize;
  288. rv = GetFileSize(source, getter_AddRefs(fileSize));
  289. if (NS_FAILED(rv)) return(rv);
  290. if (!fileSize) rv = NS_RDF_NO_VALUE;
  291. if (rv == NS_RDF_NO_VALUE) return(rv);
  292. return fileSize->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  293. }
  294. else if (property == mNC_IsDirectory)
  295. {
  296. *target = (isDirURI(source)) ? mLiteralTrue : mLiteralFalse;
  297. NS_ADDREF(*target);
  298. return NS_OK;
  299. }
  300. else if (property == mWEB_LastMod)
  301. {
  302. nsCOMPtr<nsIRDFDate> lastMod;
  303. rv = GetLastMod(source, getter_AddRefs(lastMod));
  304. if (NS_FAILED(rv)) return(rv);
  305. if (!lastMod) rv = NS_RDF_NO_VALUE;
  306. if (rv == NS_RDF_NO_VALUE) return(rv);
  307. return lastMod->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  308. }
  309. else if (property == mRDF_type)
  310. {
  311. nsCString type;
  312. rv = mNC_FileSystemObject->GetValueUTF8(type);
  313. if (NS_FAILED(rv)) return(rv);
  314. #ifdef XP_WIN
  315. // under Windows, if its an IE favorite, return that type
  316. if (!ieFavoritesDir.IsEmpty())
  317. {
  318. nsCString uri;
  319. rv = source->GetValueUTF8(uri);
  320. if (NS_FAILED(rv)) return(rv);
  321. NS_ConvertUTF8toUTF16 theURI(uri);
  322. if (theURI.Find(ieFavoritesDir) == 0)
  323. {
  324. if (theURI[theURI.Length() - 1] == '/')
  325. {
  326. rv = mNC_IEFavoriteFolder->GetValueUTF8(type);
  327. }
  328. else
  329. {
  330. rv = mNC_IEFavoriteObject->GetValueUTF8(type);
  331. }
  332. if (NS_FAILED(rv)) return(rv);
  333. }
  334. }
  335. #endif
  336. NS_ConvertUTF8toUTF16 url(type);
  337. nsCOMPtr<nsIRDFLiteral> literal;
  338. mRDFService->GetLiteral(url.get(), getter_AddRefs(literal));
  339. rv = literal->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  340. return(rv);
  341. }
  342. else if (property == mNC_pulse)
  343. {
  344. nsCOMPtr<nsIRDFLiteral> pulseLiteral;
  345. mRDFService->GetLiteral(u"12", getter_AddRefs(pulseLiteral));
  346. rv = pulseLiteral->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  347. return(rv);
  348. }
  349. else if (property == mNC_Child)
  350. {
  351. // Oh this is evil. Somebody kill me now.
  352. nsCOMPtr<nsISimpleEnumerator> children;
  353. rv = GetFolderList(source, false, true, getter_AddRefs(children));
  354. if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
  355. bool hasMore;
  356. rv = children->HasMoreElements(&hasMore);
  357. if (NS_FAILED(rv)) return(rv);
  358. if (hasMore)
  359. {
  360. nsCOMPtr<nsISupports> isupports;
  361. rv = children->GetNext(getter_AddRefs(isupports));
  362. if (NS_FAILED(rv)) return(rv);
  363. return isupports->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  364. }
  365. }
  366. #ifdef USE_NC_EXTENSION
  367. else if (property == mNC_extension)
  368. {
  369. nsCOMPtr<nsIRDFLiteral> extension;
  370. rv = GetExtension(source, getter_AddRefs(extension));
  371. if (!extension) rv = NS_RDF_NO_VALUE;
  372. if (rv == NS_RDF_NO_VALUE) return(rv);
  373. return extension->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
  374. }
  375. #endif
  376. }
  377. return(NS_RDF_NO_VALUE);
  378. }
  379. NS_IMETHODIMP
  380. FileSystemDataSource::GetTargets(nsIRDFResource *source,
  381. nsIRDFResource *property,
  382. bool tv,
  383. nsISimpleEnumerator **targets /* out */)
  384. {
  385. NS_PRECONDITION(source != nullptr, "null ptr");
  386. if (! source)
  387. return NS_ERROR_NULL_POINTER;
  388. NS_PRECONDITION(property != nullptr, "null ptr");
  389. if (! property)
  390. return NS_ERROR_NULL_POINTER;
  391. NS_PRECONDITION(targets != nullptr, "null ptr");
  392. if (! targets)
  393. return NS_ERROR_NULL_POINTER;
  394. *targets = nullptr;
  395. // we only have positive assertions in the file system data source.
  396. if (! tv)
  397. return NS_RDF_NO_VALUE;
  398. nsresult rv;
  399. if (source == mNC_FileSystemRoot)
  400. {
  401. if (property == mNC_Child)
  402. {
  403. return GetVolumeList(targets);
  404. }
  405. else if (property == mNC_pulse)
  406. {
  407. nsCOMPtr<nsIRDFLiteral> pulseLiteral;
  408. mRDFService->GetLiteral(u"12",
  409. getter_AddRefs(pulseLiteral));
  410. return NS_NewSingletonEnumerator(targets, pulseLiteral);
  411. }
  412. }
  413. else if (isFileURI(source))
  414. {
  415. if (property == mNC_Child)
  416. {
  417. return GetFolderList(source, false, false, targets);
  418. }
  419. else if (property == mNC_Name)
  420. {
  421. nsCOMPtr<nsIRDFLiteral> name;
  422. rv = GetName(source, getter_AddRefs(name));
  423. if (NS_FAILED(rv)) return rv;
  424. return NS_NewSingletonEnumerator(targets, name);
  425. }
  426. else if (property == mNC_URL)
  427. {
  428. nsCOMPtr<nsIRDFLiteral> url;
  429. rv = GetURL(source, nullptr, getter_AddRefs(url));
  430. if (NS_FAILED(rv)) return rv;
  431. return NS_NewSingletonEnumerator(targets, url);
  432. }
  433. else if (property == mRDF_type)
  434. {
  435. nsCString uri;
  436. rv = mNC_FileSystemObject->GetValueUTF8(uri);
  437. if (NS_FAILED(rv)) return rv;
  438. NS_ConvertUTF8toUTF16 url(uri);
  439. nsCOMPtr<nsIRDFLiteral> literal;
  440. rv = mRDFService->GetLiteral(url.get(), getter_AddRefs(literal));
  441. if (NS_FAILED(rv)) return rv;
  442. return NS_NewSingletonEnumerator(targets, literal);
  443. }
  444. else if (property == mNC_pulse)
  445. {
  446. nsCOMPtr<nsIRDFLiteral> pulseLiteral;
  447. rv = mRDFService->GetLiteral(u"12",
  448. getter_AddRefs(pulseLiteral));
  449. if (NS_FAILED(rv)) return rv;
  450. return NS_NewSingletonEnumerator(targets, pulseLiteral);
  451. }
  452. }
  453. return NS_NewEmptyEnumerator(targets);
  454. }
  455. NS_IMETHODIMP
  456. FileSystemDataSource::Assert(nsIRDFResource *source,
  457. nsIRDFResource *property,
  458. nsIRDFNode *target,
  459. bool tv)
  460. {
  461. return NS_RDF_ASSERTION_REJECTED;
  462. }
  463. NS_IMETHODIMP
  464. FileSystemDataSource::Unassert(nsIRDFResource *source,
  465. nsIRDFResource *property,
  466. nsIRDFNode *target)
  467. {
  468. return NS_RDF_ASSERTION_REJECTED;
  469. }
  470. NS_IMETHODIMP
  471. FileSystemDataSource::Change(nsIRDFResource* aSource,
  472. nsIRDFResource* aProperty,
  473. nsIRDFNode* aOldTarget,
  474. nsIRDFNode* aNewTarget)
  475. {
  476. return NS_RDF_ASSERTION_REJECTED;
  477. }
  478. NS_IMETHODIMP
  479. FileSystemDataSource::Move(nsIRDFResource* aOldSource,
  480. nsIRDFResource* aNewSource,
  481. nsIRDFResource* aProperty,
  482. nsIRDFNode* aTarget)
  483. {
  484. return NS_RDF_ASSERTION_REJECTED;
  485. }
  486. NS_IMETHODIMP
  487. FileSystemDataSource::HasAssertion(nsIRDFResource *source,
  488. nsIRDFResource *property,
  489. nsIRDFNode *target,
  490. bool tv,
  491. bool *hasAssertion /* out */)
  492. {
  493. NS_PRECONDITION(source != nullptr, "null ptr");
  494. if (! source)
  495. return NS_ERROR_NULL_POINTER;
  496. NS_PRECONDITION(property != nullptr, "null ptr");
  497. if (! property)
  498. return NS_ERROR_NULL_POINTER;
  499. NS_PRECONDITION(target != nullptr, "null ptr");
  500. if (! target)
  501. return NS_ERROR_NULL_POINTER;
  502. NS_PRECONDITION(hasAssertion != nullptr, "null ptr");
  503. if (! hasAssertion)
  504. return NS_ERROR_NULL_POINTER;
  505. // we only have positive assertions in the file system data source.
  506. *hasAssertion = false;
  507. if (! tv) {
  508. return NS_OK;
  509. }
  510. if ((source == mNC_FileSystemRoot) || isFileURI(source))
  511. {
  512. if (property == mRDF_type)
  513. {
  514. nsCOMPtr<nsIRDFResource> resource( do_QueryInterface(target) );
  515. if (resource.get() == mRDF_type)
  516. {
  517. *hasAssertion = true;
  518. }
  519. }
  520. #ifdef USE_NC_EXTENSION
  521. else if (property == mNC_extension)
  522. {
  523. // Cheat just a little here by making dirs always match
  524. if (isDirURI(source))
  525. {
  526. *hasAssertion = true;
  527. }
  528. else
  529. {
  530. nsCOMPtr<nsIRDFLiteral> extension;
  531. GetExtension(source, getter_AddRefs(extension));
  532. if (extension.get() == target)
  533. {
  534. *hasAssertion = true;
  535. }
  536. }
  537. }
  538. #endif
  539. else if (property == mNC_IsDirectory)
  540. {
  541. bool isDir = isDirURI(source);
  542. bool isEqual = false;
  543. target->EqualsNode(mLiteralTrue, &isEqual);
  544. if (isEqual)
  545. {
  546. *hasAssertion = isDir;
  547. }
  548. else
  549. {
  550. target->EqualsNode(mLiteralFalse, &isEqual);
  551. if (isEqual)
  552. *hasAssertion = !isDir;
  553. }
  554. }
  555. }
  556. return NS_OK;
  557. }
  558. NS_IMETHODIMP
  559. FileSystemDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, bool *result)
  560. {
  561. return NS_ERROR_NOT_IMPLEMENTED;
  562. }
  563. NS_IMETHODIMP
  564. FileSystemDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, bool *result)
  565. {
  566. *result = false;
  567. if (aSource == mNC_FileSystemRoot)
  568. {
  569. *result = (aArc == mNC_Child || aArc == mNC_pulse);
  570. }
  571. else if (isFileURI(aSource))
  572. {
  573. if (aArc == mNC_pulse)
  574. {
  575. *result = true;
  576. }
  577. else if (isDirURI(aSource))
  578. {
  579. #ifdef XP_WIN
  580. *result = isValidFolder(aSource);
  581. #else
  582. *result = true;
  583. #endif
  584. }
  585. else if (aArc == mNC_pulse || aArc == mNC_Name || aArc == mNC_Icon ||
  586. aArc == mNC_URL || aArc == mNC_Length || aArc == mWEB_LastMod ||
  587. aArc == mNC_FileSystemObject || aArc == mRDF_InstanceOf ||
  588. aArc == mRDF_type)
  589. {
  590. *result = true;
  591. }
  592. }
  593. return NS_OK;
  594. }
  595. NS_IMETHODIMP
  596. FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node,
  597. nsISimpleEnumerator ** labels /* out */)
  598. {
  599. // NS_NOTYETIMPLEMENTED("write me");
  600. return NS_ERROR_NOT_IMPLEMENTED;
  601. }
  602. NS_IMETHODIMP
  603. FileSystemDataSource::ArcLabelsOut(nsIRDFResource *source,
  604. nsISimpleEnumerator **labels /* out */)
  605. {
  606. NS_PRECONDITION(source != nullptr, "null ptr");
  607. if (! source)
  608. return NS_ERROR_NULL_POINTER;
  609. NS_PRECONDITION(labels != nullptr, "null ptr");
  610. if (! labels)
  611. return NS_ERROR_NULL_POINTER;
  612. if (source == mNC_FileSystemRoot)
  613. {
  614. nsCOMArray<nsIRDFResource> resources;
  615. resources.SetCapacity(2);
  616. resources.AppendObject(mNC_Child);
  617. resources.AppendObject(mNC_pulse);
  618. return NS_NewArrayEnumerator(labels, resources);
  619. }
  620. else if (isFileURI(source))
  621. {
  622. nsCOMArray<nsIRDFResource> resources;
  623. resources.SetCapacity(2);
  624. if (isDirURI(source))
  625. {
  626. #ifdef XP_WIN
  627. if (isValidFolder(source))
  628. {
  629. resources.AppendObject(mNC_Child);
  630. }
  631. #else
  632. resources.AppendObject(mNC_Child);
  633. #endif
  634. resources.AppendObject(mNC_pulse);
  635. }
  636. return NS_NewArrayEnumerator(labels, resources);
  637. }
  638. return NS_NewEmptyEnumerator(labels);
  639. }
  640. NS_IMETHODIMP
  641. FileSystemDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
  642. {
  643. NS_NOTYETIMPLEMENTED("sorry!");
  644. return NS_ERROR_NOT_IMPLEMENTED;
  645. }
  646. NS_IMETHODIMP
  647. FileSystemDataSource::AddObserver(nsIRDFObserver *n)
  648. {
  649. return NS_ERROR_NOT_IMPLEMENTED;
  650. }
  651. NS_IMETHODIMP
  652. FileSystemDataSource::RemoveObserver(nsIRDFObserver *n)
  653. {
  654. return NS_ERROR_NOT_IMPLEMENTED;
  655. }
  656. NS_IMETHODIMP
  657. FileSystemDataSource::GetAllCmds(nsIRDFResource* source,
  658. nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
  659. {
  660. return(NS_NewEmptyEnumerator(commands));
  661. }
  662. NS_IMETHODIMP
  663. FileSystemDataSource::IsCommandEnabled(nsISupports/*<nsIRDFResource>*/* aSources,
  664. nsIRDFResource* aCommand,
  665. nsISupports/*<nsIRDFResource>*/* aArguments,
  666. bool* aResult)
  667. {
  668. return(NS_ERROR_NOT_IMPLEMENTED);
  669. }
  670. NS_IMETHODIMP
  671. FileSystemDataSource::DoCommand(nsISupports/*<nsIRDFResource>*/* aSources,
  672. nsIRDFResource* aCommand,
  673. nsISupports/*<nsIRDFResource>*/* aArguments)
  674. {
  675. return(NS_ERROR_NOT_IMPLEMENTED);
  676. }
  677. NS_IMETHODIMP
  678. FileSystemDataSource::BeginUpdateBatch()
  679. {
  680. return NS_OK;
  681. }
  682. NS_IMETHODIMP
  683. FileSystemDataSource::EndUpdateBatch()
  684. {
  685. return NS_OK;
  686. }
  687. nsresult
  688. FileSystemDataSource::GetVolumeList(nsISimpleEnumerator** aResult)
  689. {
  690. nsCOMArray<nsIRDFResource> volumes;
  691. nsCOMPtr<nsIRDFResource> vol;
  692. #ifdef XP_WIN
  693. int32_t driveType;
  694. wchar_t drive[32];
  695. int32_t volNum;
  696. for (volNum = 0; volNum < 26; volNum++)
  697. {
  698. swprintf_s(drive, 32, L"%c:\\", volNum + (char16_t)'A');
  699. driveType = GetDriveTypeW(drive);
  700. if (driveType != DRIVE_UNKNOWN && driveType != DRIVE_NO_ROOT_DIR)
  701. {
  702. nsAutoCString url;
  703. url.AppendPrintf("file:///%c|/", volNum + 'A');
  704. nsresult rv = mRDFService->GetResource(url, getter_AddRefs(vol));
  705. if (NS_FAILED(rv))
  706. return rv;
  707. volumes.AppendObject(vol);
  708. }
  709. }
  710. #endif
  711. #ifdef XP_UNIX
  712. mRDFService->GetResource(NS_LITERAL_CSTRING("file:///"), getter_AddRefs(vol));
  713. volumes.AppendObject(vol);
  714. #endif
  715. return NS_NewArrayEnumerator(aResult, volumes);
  716. }
  717. #ifdef XP_WIN
  718. bool
  719. FileSystemDataSource::isValidFolder(nsIRDFResource *source)
  720. {
  721. bool isValid = true;
  722. if (ieFavoritesDir.IsEmpty()) return(isValid);
  723. nsresult rv;
  724. nsCString uri;
  725. rv = source->GetValueUTF8(uri);
  726. if (NS_FAILED(rv)) return(isValid);
  727. NS_ConvertUTF8toUTF16 theURI(uri);
  728. if (theURI.Find(ieFavoritesDir) == 0)
  729. {
  730. isValid = false;
  731. nsCOMPtr<nsISimpleEnumerator> folderEnum;
  732. if (NS_SUCCEEDED(rv = GetFolderList(source, true, false, getter_AddRefs(folderEnum))))
  733. {
  734. bool hasAny = false, hasMore;
  735. while (NS_SUCCEEDED(folderEnum->HasMoreElements(&hasMore)) &&
  736. hasMore)
  737. {
  738. hasAny = true;
  739. nsCOMPtr<nsISupports> isupports;
  740. if (NS_FAILED(rv = folderEnum->GetNext(getter_AddRefs(isupports))))
  741. break;
  742. nsCOMPtr<nsIRDFResource> res = do_QueryInterface(isupports);
  743. if (!res) break;
  744. nsCOMPtr<nsIRDFLiteral> nameLiteral;
  745. if (NS_FAILED(rv = GetName(res, getter_AddRefs(nameLiteral))))
  746. break;
  747. const char16_t *uniName;
  748. if (NS_FAILED(rv = nameLiteral->GetValueConst(&uniName)))
  749. break;
  750. nsAutoString name(uniName);
  751. // An empty folder, or a folder that contains just "desktop.ini",
  752. // is considered to be a IE Favorite; otherwise, its a folder
  753. if (!name.LowerCaseEqualsLiteral("desktop.ini"))
  754. {
  755. isValid = true;
  756. break;
  757. }
  758. }
  759. if (!hasAny) isValid = true;
  760. }
  761. }
  762. return(isValid);
  763. }
  764. #endif
  765. nsresult
  766. FileSystemDataSource::GetFolderList(nsIRDFResource *source, bool allowHidden,
  767. bool onlyFirst, nsISimpleEnumerator** aResult)
  768. {
  769. if (!isDirURI(source))
  770. return(NS_RDF_NO_VALUE);
  771. nsresult rv;
  772. const char *parentURI = nullptr;
  773. rv = source->GetValueConst(&parentURI);
  774. if (NS_FAILED(rv))
  775. return(rv);
  776. if (!parentURI)
  777. return(NS_ERROR_UNEXPECTED);
  778. nsCOMPtr<nsIURI> aIURI;
  779. if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(parentURI))))
  780. return(rv);
  781. nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
  782. if (!fileURL)
  783. return NS_OK;
  784. nsCOMPtr<nsIFile> aDir;
  785. if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aDir))))
  786. return(rv);
  787. // ensure that we DO NOT resolve aliases
  788. aDir->SetFollowLinks(false);
  789. nsCOMPtr<nsISimpleEnumerator> dirContents;
  790. if (NS_FAILED(rv = aDir->GetDirectoryEntries(getter_AddRefs(dirContents))))
  791. return(rv);
  792. if (!dirContents)
  793. return(NS_ERROR_UNEXPECTED);
  794. nsCOMArray<nsIRDFResource> resources;
  795. bool hasMore;
  796. while(NS_SUCCEEDED(rv = dirContents->HasMoreElements(&hasMore)) &&
  797. hasMore)
  798. {
  799. nsCOMPtr<nsISupports> isupports;
  800. if (NS_FAILED(rv = dirContents->GetNext(getter_AddRefs(isupports))))
  801. break;
  802. nsCOMPtr<nsIFile> aFile = do_QueryInterface(isupports);
  803. if (!aFile)
  804. break;
  805. if (!allowHidden)
  806. {
  807. bool hiddenFlag = false;
  808. if (NS_FAILED(rv = aFile->IsHidden(&hiddenFlag)))
  809. break;
  810. if (hiddenFlag)
  811. continue;
  812. }
  813. nsAutoString leafStr;
  814. if (NS_FAILED(rv = aFile->GetLeafName(leafStr)))
  815. break;
  816. if (leafStr.IsEmpty())
  817. continue;
  818. nsAutoCString fullURI;
  819. fullURI.Assign(parentURI);
  820. if (fullURI.Last() != '/')
  821. {
  822. fullURI.Append('/');
  823. }
  824. nsAutoCString leaf;
  825. bool escaped = NS_Escape(NS_ConvertUTF16toUTF8(leafStr), leaf, url_Path);
  826. leafStr.Truncate();
  827. if (!escaped) {
  828. continue;
  829. }
  830. // using nsEscape() [above] doesn't escape slashes, so do that by hand
  831. int32_t aOffset;
  832. while ((aOffset = leaf.FindChar('/')) >= 0)
  833. {
  834. leaf.Cut((uint32_t)aOffset, 1);
  835. leaf.Insert("%2F", (uint32_t)aOffset);
  836. }
  837. // append the encoded name
  838. fullURI.Append(leaf);
  839. bool dirFlag = false;
  840. rv = aFile->IsDirectory(&dirFlag);
  841. if (NS_SUCCEEDED(rv) && dirFlag)
  842. {
  843. fullURI.Append('/');
  844. }
  845. nsCOMPtr<nsIRDFResource> fileRes;
  846. mRDFService->GetResource(fullURI, getter_AddRefs(fileRes));
  847. resources.AppendObject(fileRes);
  848. if (onlyFirst)
  849. break;
  850. }
  851. return NS_NewArrayEnumerator(aResult, resources);
  852. }
  853. nsresult
  854. FileSystemDataSource::GetLastMod(nsIRDFResource *source, nsIRDFDate **aResult)
  855. {
  856. *aResult = nullptr;
  857. nsresult rv;
  858. const char *uri = nullptr;
  859. rv = source->GetValueConst(&uri);
  860. if (NS_FAILED(rv)) return(rv);
  861. if (!uri)
  862. return(NS_ERROR_UNEXPECTED);
  863. nsCOMPtr<nsIURI> aIURI;
  864. if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
  865. return(rv);
  866. nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
  867. if (!fileURL)
  868. return NS_OK;
  869. nsCOMPtr<nsIFile> aFile;
  870. if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
  871. return(rv);
  872. if (!aFile)
  873. return(NS_ERROR_UNEXPECTED);
  874. // ensure that we DO NOT resolve aliases
  875. aFile->SetFollowLinks(false);
  876. PRTime lastModDate;
  877. if (NS_FAILED(rv = aFile->GetLastModifiedTime(&lastModDate)))
  878. return(rv);
  879. // convert from milliseconds to seconds
  880. mRDFService->GetDateLiteral(lastModDate * PR_MSEC_PER_SEC, aResult);
  881. return(NS_OK);
  882. }
  883. nsresult
  884. FileSystemDataSource::GetFileSize(nsIRDFResource *source, nsIRDFInt **aResult)
  885. {
  886. *aResult = nullptr;
  887. nsresult rv;
  888. const char *uri = nullptr;
  889. rv = source->GetValueConst(&uri);
  890. if (NS_FAILED(rv))
  891. return(rv);
  892. if (!uri)
  893. return(NS_ERROR_UNEXPECTED);
  894. nsCOMPtr<nsIURI> aIURI;
  895. if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
  896. return(rv);
  897. nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
  898. if (!fileURL)
  899. return NS_OK;
  900. nsCOMPtr<nsIFile> aFile;
  901. if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
  902. return(rv);
  903. if (!aFile)
  904. return(NS_ERROR_UNEXPECTED);
  905. // ensure that we DO NOT resolve aliases
  906. aFile->SetFollowLinks(false);
  907. // don't do anything with directories
  908. bool isDir = false;
  909. if (NS_FAILED(rv = aFile->IsDirectory(&isDir)))
  910. return(rv);
  911. if (isDir)
  912. return(NS_RDF_NO_VALUE);
  913. int64_t aFileSize64;
  914. if (NS_FAILED(rv = aFile->GetFileSize(&aFileSize64)))
  915. return(rv);
  916. // convert 64bits to 32bits
  917. int32_t aFileSize32 = int32_t(aFileSize64);
  918. mRDFService->GetIntLiteral(aFileSize32, aResult);
  919. return(NS_OK);
  920. }
  921. nsresult
  922. FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
  923. {
  924. nsresult rv;
  925. const char *uri = nullptr;
  926. rv = source->GetValueConst(&uri);
  927. if (NS_FAILED(rv))
  928. return(rv);
  929. if (!uri)
  930. return(NS_ERROR_UNEXPECTED);
  931. nsCOMPtr<nsIURI> aIURI;
  932. if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri))))
  933. return(rv);
  934. nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(aIURI);
  935. if (!fileURL)
  936. return NS_OK;
  937. nsCOMPtr<nsIFile> aFile;
  938. if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile))))
  939. return(rv);
  940. if (!aFile)
  941. return(NS_ERROR_UNEXPECTED);
  942. // ensure that we DO NOT resolve aliases
  943. aFile->SetFollowLinks(false);
  944. nsAutoString name;
  945. if (NS_FAILED(rv = aFile->GetLeafName(name)))
  946. return(rv);
  947. if (name.IsEmpty())
  948. return(NS_ERROR_UNEXPECTED);
  949. #ifdef XP_WIN
  950. // special hack for IE favorites under Windows; strip off the
  951. // trailing ".url" or ".lnk" at the end of IE favorites names
  952. int32_t nameLen = name.Length();
  953. if ((strncmp(uri, ieFavoritesDir.get(), ieFavoritesDir.Length()) == 0) && (nameLen > 4))
  954. {
  955. nsAutoString extension;
  956. name.Right(extension, 4);
  957. if (extension.LowerCaseEqualsLiteral(".url") ||
  958. extension.LowerCaseEqualsLiteral(".lnk"))
  959. {
  960. name.Truncate(nameLen - 4);
  961. }
  962. }
  963. #endif
  964. mRDFService->GetLiteral(name.get(), aResult);
  965. return NS_OK;
  966. }
  967. #ifdef USE_NC_EXTENSION
  968. nsresult
  969. FileSystemDataSource::GetExtension(nsIRDFResource *source, nsIRDFLiteral **aResult)
  970. {
  971. nsCOMPtr<nsIRDFLiteral> name;
  972. nsresult rv = GetName(source, getter_AddRefs(name));
  973. if (NS_FAILED(rv))
  974. return rv;
  975. const char16_t* unicodeLeafName;
  976. rv = name->GetValueConst(&unicodeLeafName);
  977. if (NS_FAILED(rv))
  978. return rv;
  979. nsAutoString filename(unicodeLeafName);
  980. int32_t lastDot = filename.RFindChar('.');
  981. if (lastDot == -1)
  982. {
  983. mRDFService->GetLiteral(EmptyString().get(), aResult);
  984. }
  985. else
  986. {
  987. nsAutoString extension;
  988. filename.Right(extension, (filename.Length() - lastDot));
  989. mRDFService->GetLiteral(extension.get(), aResult);
  990. }
  991. return NS_OK;
  992. }
  993. #endif
  994. #ifdef XP_WIN
  995. nsresult
  996. FileSystemDataSource::getIEFavoriteURL(nsIRDFResource *source, nsString aFileURL, nsIRDFLiteral **urlLiteral)
  997. {
  998. nsresult rv = NS_OK;
  999. *urlLiteral = nullptr;
  1000. nsCOMPtr<nsIFile> f;
  1001. NS_GetFileFromURLSpec(NS_ConvertUTF16toUTF8(aFileURL), getter_AddRefs(f));
  1002. bool value;
  1003. if (NS_SUCCEEDED(f->IsDirectory(&value)) && value)
  1004. {
  1005. if (isValidFolder(source))
  1006. return(NS_RDF_NO_VALUE);
  1007. aFileURL.AppendLiteral("desktop.ini");
  1008. }
  1009. else if (aFileURL.Length() > 4)
  1010. {
  1011. nsAutoString extension;
  1012. aFileURL.Right(extension, 4);
  1013. if (!extension.LowerCaseEqualsLiteral(".url"))
  1014. {
  1015. return(NS_RDF_NO_VALUE);
  1016. }
  1017. }
  1018. nsCOMPtr<nsIInputStream> strm;
  1019. NS_NewLocalFileInputStream(getter_AddRefs(strm),f);
  1020. nsCOMPtr<nsILineInputStream> linereader = do_QueryInterface(strm, &rv);
  1021. nsAutoString line;
  1022. nsAutoCString cLine;
  1023. while(NS_SUCCEEDED(rv))
  1024. {
  1025. bool isEOF;
  1026. rv = linereader->ReadLine(cLine, &isEOF);
  1027. CopyASCIItoUTF16(cLine, line);
  1028. if (isEOF)
  1029. {
  1030. if (line.Find("URL=", true) == 0)
  1031. {
  1032. line.Cut(0, 4);
  1033. rv = mRDFService->GetLiteral(line.get(), urlLiteral);
  1034. break;
  1035. }
  1036. else if (line.Find("CDFURL=", true) == 0)
  1037. {
  1038. line.Cut(0, 7);
  1039. rv = mRDFService->GetLiteral(line.get(), urlLiteral);
  1040. break;
  1041. }
  1042. line.Truncate();
  1043. }
  1044. }
  1045. return(rv);
  1046. }
  1047. #endif
  1048. nsresult
  1049. FileSystemDataSource::GetURL(nsIRDFResource *source, bool *isFavorite, nsIRDFLiteral** aResult)
  1050. {
  1051. if (isFavorite) *isFavorite = false;
  1052. nsresult rv;
  1053. nsCString uri;
  1054. rv = source->GetValueUTF8(uri);
  1055. if (NS_FAILED(rv))
  1056. return(rv);
  1057. NS_ConvertUTF8toUTF16 url(uri);
  1058. #ifdef XP_WIN
  1059. // under Windows, if its an IE favorite, munge the URL
  1060. if (!ieFavoritesDir.IsEmpty())
  1061. {
  1062. if (url.Find(ieFavoritesDir) == 0)
  1063. {
  1064. if (isFavorite) *isFavorite = true;
  1065. rv = getIEFavoriteURL(source, url, aResult);
  1066. return(rv);
  1067. }
  1068. }
  1069. #endif
  1070. // if we fall through to here, its not any type of bookmark
  1071. // stored in the platform native file system, so just set the URL
  1072. mRDFService->GetLiteral(url.get(), aResult);
  1073. return(NS_OK);
  1074. }