nsIconURI.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsIconURI.h"
  7. #include "mozilla/ArrayUtils.h"
  8. #include "mozilla/ipc/URIUtils.h"
  9. #include "mozilla/Sprintf.h"
  10. #include "nsIIOService.h"
  11. #include "nsIURL.h"
  12. #include "nsNetUtil.h"
  13. #include "plstr.h"
  14. #include <stdlib.h>
  15. using namespace mozilla;
  16. using namespace mozilla::ipc;
  17. #define DEFAULT_IMAGE_SIZE 16
  18. #if defined(MAX_PATH)
  19. #define SANE_FILE_NAME_LEN MAX_PATH
  20. #elif defined(PATH_MAX)
  21. #define SANE_FILE_NAME_LEN PATH_MAX
  22. #else
  23. #define SANE_FILE_NAME_LEN 1024
  24. #endif
  25. // helper function for parsing out attributes like size, and contentType
  26. // from the icon url.
  27. static void extractAttributeValue(const char* aSearchString,
  28. const char* aAttributeName,
  29. nsCString& aResult);
  30. static const char* kSizeStrings[] =
  31. {
  32. "button",
  33. "toolbar",
  34. "toolbarsmall",
  35. "menu",
  36. "dnd",
  37. "dialog"
  38. };
  39. static const char* kStateStrings[] =
  40. {
  41. "normal",
  42. "disabled"
  43. };
  44. ////////////////////////////////////////////////////////////////////////////////
  45. nsMozIconURI::nsMozIconURI()
  46. : mSize(DEFAULT_IMAGE_SIZE),
  47. mIconSize(-1),
  48. mIconState(-1)
  49. { }
  50. nsMozIconURI::~nsMozIconURI()
  51. { }
  52. NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI, nsIIPCSerializableURI)
  53. #define MOZICON_SCHEME "moz-icon:"
  54. #define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
  55. ////////////////////////////////////////////////////////////////////////////////
  56. // nsIURI methods:
  57. NS_IMETHODIMP
  58. nsMozIconURI::GetSpec(nsACString& aSpec)
  59. {
  60. aSpec = MOZICON_SCHEME;
  61. if (mIconURL) {
  62. nsAutoCString fileIconSpec;
  63. nsresult rv = mIconURL->GetSpec(fileIconSpec);
  64. NS_ENSURE_SUCCESS(rv, rv);
  65. aSpec += fileIconSpec;
  66. } else if (!mStockIcon.IsEmpty()) {
  67. aSpec += "//stock/";
  68. aSpec += mStockIcon;
  69. } else {
  70. aSpec += "//";
  71. aSpec += mFileName;
  72. }
  73. aSpec += "?size=";
  74. if (mIconSize >= 0) {
  75. aSpec += kSizeStrings[mIconSize];
  76. } else {
  77. char buf[20];
  78. SprintfLiteral(buf, "%d", mSize);
  79. aSpec.Append(buf);
  80. }
  81. if (mIconState >= 0) {
  82. aSpec += "&state=";
  83. aSpec += kStateStrings[mIconState];
  84. }
  85. if (!mContentType.IsEmpty()) {
  86. aSpec += "&contentType=";
  87. aSpec += mContentType.get();
  88. }
  89. return NS_OK;
  90. }
  91. NS_IMETHODIMP
  92. nsMozIconURI::GetSpecIgnoringRef(nsACString& result)
  93. {
  94. return GetSpec(result);
  95. }
  96. NS_IMETHODIMP
  97. nsMozIconURI::GetHasRef(bool* result)
  98. {
  99. *result = false;
  100. return NS_OK;
  101. }
  102. // takes a string like ?size=32&contentType=text/html and returns a new string
  103. // containing just the attribute value. i.e you could pass in this string with
  104. // an attribute name of 'size=', this will return 32
  105. // Assumption: attribute pairs in the string are separated by '&'.
  106. void
  107. extractAttributeValue(const char* aSearchString,
  108. const char* aAttributeName,
  109. nsCString& aResult)
  110. {
  111. //NS_ENSURE_ARG_POINTER(extractAttributeValue);
  112. aResult.Truncate();
  113. if (aSearchString && aAttributeName) {
  114. // search the string for attributeName
  115. uint32_t attributeNameSize = strlen(aAttributeName);
  116. const char* startOfAttribute = PL_strcasestr(aSearchString, aAttributeName);
  117. if (startOfAttribute &&
  118. ( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') ) {
  119. startOfAttribute += attributeNameSize; // skip over the attributeName
  120. // is there something after the attribute name
  121. if (*startOfAttribute) {
  122. const char* endofAttribute = strchr(startOfAttribute, '&');
  123. if (endofAttribute) {
  124. aResult.Assign(Substring(startOfAttribute, endofAttribute));
  125. } else {
  126. aResult.Assign(startOfAttribute);
  127. }
  128. } // if we have a attribute value
  129. } // if we have a attribute name
  130. } // if we got non-null search string and attribute name values
  131. }
  132. NS_IMETHODIMP
  133. nsMozIconURI::SetSpec(const nsACString& aSpec)
  134. {
  135. // Reset everything to default values.
  136. mIconURL = nullptr;
  137. mSize = DEFAULT_IMAGE_SIZE;
  138. mContentType.Truncate();
  139. mFileName.Truncate();
  140. mStockIcon.Truncate();
  141. mIconSize = -1;
  142. mIconState = -1;
  143. nsAutoCString iconSpec(aSpec);
  144. if (!Substring(iconSpec, 0,
  145. MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME)) {
  146. return NS_ERROR_MALFORMED_URI;
  147. }
  148. int32_t questionMarkPos = iconSpec.Find("?");
  149. if (questionMarkPos != -1 &&
  150. static_cast<int32_t>(iconSpec.Length()) > (questionMarkPos + 1)) {
  151. extractAttributeValue(iconSpec.get(), "contentType=", mContentType);
  152. nsAutoCString sizeString;
  153. extractAttributeValue(iconSpec.get(), "size=", sizeString);
  154. if (!sizeString.IsEmpty()) {
  155. const char* sizeStr = sizeString.get();
  156. for (uint32_t i = 0; i < ArrayLength(kSizeStrings); i++) {
  157. if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0) {
  158. mIconSize = i;
  159. break;
  160. }
  161. }
  162. int32_t sizeValue = atoi(sizeString.get());
  163. if (sizeValue > 0) {
  164. mSize = sizeValue;
  165. }
  166. }
  167. nsAutoCString stateString;
  168. extractAttributeValue(iconSpec.get(), "state=", stateString);
  169. if (!stateString.IsEmpty()) {
  170. const char* stateStr = stateString.get();
  171. for (uint32_t i = 0; i < ArrayLength(kStateStrings); i++) {
  172. if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0) {
  173. mIconState = i;
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. int32_t pathLength = iconSpec.Length() - MOZICON_SCHEME_LEN;
  180. if (questionMarkPos != -1) {
  181. pathLength = questionMarkPos - MOZICON_SCHEME_LEN;
  182. }
  183. if (pathLength < 3) {
  184. return NS_ERROR_MALFORMED_URI;
  185. }
  186. nsAutoCString iconPath(Substring(iconSpec, MOZICON_SCHEME_LEN, pathLength));
  187. // Icon URI path can have three forms:
  188. // (1) //stock/<icon-identifier>
  189. // (2) //<some dummy file with an extension>
  190. // (3) a valid URL
  191. if (!strncmp("//stock/", iconPath.get(), 8)) {
  192. mStockIcon.Assign(Substring(iconPath, 8));
  193. // An icon identifier must always be specified.
  194. if (mStockIcon.IsEmpty()) {
  195. return NS_ERROR_MALFORMED_URI;
  196. }
  197. return NS_OK;
  198. }
  199. if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//"))) {
  200. // Sanity check this supposed dummy file name.
  201. if (iconPath.Length() > SANE_FILE_NAME_LEN) {
  202. return NS_ERROR_MALFORMED_URI;
  203. }
  204. iconPath.Cut(0, 2);
  205. mFileName.Assign(iconPath);
  206. }
  207. nsresult rv;
  208. nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
  209. NS_ENSURE_SUCCESS(rv, rv);
  210. nsCOMPtr<nsIURI> uri;
  211. ioService->NewURI(iconPath, nullptr, nullptr, getter_AddRefs(uri));
  212. mIconURL = do_QueryInterface(uri);
  213. if (mIconURL) {
  214. mFileName.Truncate();
  215. } else if (mFileName.IsEmpty()) {
  216. return NS_ERROR_MALFORMED_URI;
  217. }
  218. return NS_OK;
  219. }
  220. NS_IMETHODIMP
  221. nsMozIconURI::GetPrePath(nsACString& prePath)
  222. {
  223. prePath = MOZICON_SCHEME;
  224. return NS_OK;
  225. }
  226. NS_IMETHODIMP
  227. nsMozIconURI::GetScheme(nsACString& aScheme)
  228. {
  229. aScheme = "moz-icon";
  230. return NS_OK;
  231. }
  232. NS_IMETHODIMP
  233. nsMozIconURI::SetScheme(const nsACString& aScheme)
  234. {
  235. // doesn't make sense to set the scheme of a moz-icon URL
  236. return NS_ERROR_FAILURE;
  237. }
  238. NS_IMETHODIMP
  239. nsMozIconURI::GetUsername(nsACString& aUsername)
  240. {
  241. return NS_ERROR_FAILURE;
  242. }
  243. NS_IMETHODIMP
  244. nsMozIconURI::SetUsername(const nsACString& aUsername)
  245. {
  246. return NS_ERROR_FAILURE;
  247. }
  248. NS_IMETHODIMP
  249. nsMozIconURI::GetPassword(nsACString& aPassword)
  250. {
  251. return NS_ERROR_FAILURE;
  252. }
  253. NS_IMETHODIMP
  254. nsMozIconURI::SetPassword(const nsACString& aPassword)
  255. {
  256. return NS_ERROR_FAILURE;
  257. }
  258. NS_IMETHODIMP
  259. nsMozIconURI::GetUserPass(nsACString& aUserPass)
  260. {
  261. return NS_ERROR_FAILURE;
  262. }
  263. NS_IMETHODIMP
  264. nsMozIconURI::SetUserPass(const nsACString& aUserPass)
  265. {
  266. return NS_ERROR_FAILURE;
  267. }
  268. NS_IMETHODIMP
  269. nsMozIconURI::GetHostPort(nsACString& aHostPort)
  270. {
  271. return NS_ERROR_FAILURE;
  272. }
  273. NS_IMETHODIMP
  274. nsMozIconURI::SetHostPort(const nsACString& aHostPort)
  275. {
  276. return NS_ERROR_FAILURE;
  277. }
  278. NS_IMETHODIMP
  279. nsMozIconURI::SetHostAndPort(const nsACString& aHostPort)
  280. {
  281. return NS_ERROR_FAILURE;
  282. }
  283. NS_IMETHODIMP
  284. nsMozIconURI::GetHost(nsACString& aHost)
  285. {
  286. return NS_ERROR_FAILURE;
  287. }
  288. NS_IMETHODIMP
  289. nsMozIconURI::SetHost(const nsACString& aHost)
  290. {
  291. return NS_ERROR_FAILURE;
  292. }
  293. NS_IMETHODIMP
  294. nsMozIconURI::GetPort(int32_t* aPort)
  295. {
  296. return NS_ERROR_FAILURE;
  297. }
  298. NS_IMETHODIMP
  299. nsMozIconURI::SetPort(int32_t aPort)
  300. {
  301. return NS_ERROR_FAILURE;
  302. }
  303. NS_IMETHODIMP
  304. nsMozIconURI::GetPath(nsACString& aPath)
  305. {
  306. aPath.Truncate();
  307. return NS_OK;
  308. }
  309. NS_IMETHODIMP
  310. nsMozIconURI::SetPath(const nsACString& aPath)
  311. {
  312. return NS_ERROR_FAILURE;
  313. }
  314. NS_IMETHODIMP
  315. nsMozIconURI::GetFilePath(nsACString& aFilePath)
  316. {
  317. aFilePath.Truncate();
  318. return NS_OK;
  319. }
  320. NS_IMETHODIMP
  321. nsMozIconURI::SetFilePath(const nsACString& aFilePath)
  322. {
  323. return NS_ERROR_FAILURE;
  324. }
  325. NS_IMETHODIMP
  326. nsMozIconURI::GetQuery(nsACString& aQuery)
  327. {
  328. aQuery.Truncate();
  329. return NS_OK;
  330. }
  331. NS_IMETHODIMP
  332. nsMozIconURI::SetQuery(const nsACString& aQuery)
  333. {
  334. return NS_ERROR_FAILURE;
  335. }
  336. NS_IMETHODIMP
  337. nsMozIconURI::GetRef(nsACString& aRef)
  338. {
  339. aRef.Truncate();
  340. return NS_OK;
  341. }
  342. NS_IMETHODIMP
  343. nsMozIconURI::SetRef(const nsACString& aRef)
  344. {
  345. return NS_ERROR_FAILURE;
  346. }
  347. NS_IMETHODIMP
  348. nsMozIconURI::Equals(nsIURI* other, bool* result)
  349. {
  350. *result = false;
  351. NS_ENSURE_ARG_POINTER(other);
  352. NS_PRECONDITION(result, "null pointer");
  353. nsAutoCString spec1;
  354. nsAutoCString spec2;
  355. nsresult rv = GetSpec(spec1);
  356. NS_ENSURE_SUCCESS(rv, rv);
  357. rv = other->GetSpec(spec2);
  358. NS_ENSURE_SUCCESS(rv, rv);
  359. if (!PL_strcasecmp(spec1.get(), spec2.get())) {
  360. *result = true;
  361. } else {
  362. *result = false;
  363. }
  364. return NS_OK;
  365. }
  366. NS_IMETHODIMP
  367. nsMozIconURI::EqualsExceptRef(nsIURI* other, bool* result)
  368. {
  369. // GetRef/SetRef not supported by nsMozIconURI, so
  370. // EqualsExceptRef() is the same as Equals().
  371. return Equals(other, result);
  372. }
  373. NS_IMETHODIMP
  374. nsMozIconURI::SchemeIs(const char* aScheme, bool* aEquals)
  375. {
  376. NS_ENSURE_ARG_POINTER(aEquals);
  377. if (!aScheme) {
  378. return NS_ERROR_INVALID_ARG;
  379. }
  380. *aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
  381. return NS_OK;
  382. }
  383. NS_IMETHODIMP
  384. nsMozIconURI::Clone(nsIURI** result)
  385. {
  386. nsCOMPtr<nsIURL> newIconURL;
  387. if (mIconURL) {
  388. nsCOMPtr<nsIURI> newURI;
  389. nsresult rv = mIconURL->Clone(getter_AddRefs(newURI));
  390. if (NS_FAILED(rv)) {
  391. return rv;
  392. }
  393. newIconURL = do_QueryInterface(newURI, &rv);
  394. if (NS_FAILED(rv)) {
  395. return rv;
  396. }
  397. }
  398. nsMozIconURI* uri = new nsMozIconURI();
  399. newIconURL.swap(uri->mIconURL);
  400. uri->mSize = mSize;
  401. uri->mContentType = mContentType;
  402. uri->mFileName = mFileName;
  403. uri->mStockIcon = mStockIcon;
  404. uri->mIconSize = mIconSize;
  405. uri->mIconState = mIconState;
  406. NS_ADDREF(*result = uri);
  407. return NS_OK;
  408. }
  409. NS_IMETHODIMP
  410. nsMozIconURI::CloneIgnoringRef(nsIURI** result)
  411. {
  412. // GetRef/SetRef not supported by nsMozIconURI, so
  413. // CloneIgnoringRef() is the same as Clone().
  414. return Clone(result);
  415. }
  416. NS_IMETHODIMP
  417. nsMozIconURI::CloneWithNewRef(const nsACString& newRef, nsIURI** result)
  418. {
  419. // GetRef/SetRef not supported by nsMozIconURI, so
  420. // CloneWithNewRef() is the same as Clone().
  421. return Clone(result);
  422. }
  423. NS_IMETHODIMP
  424. nsMozIconURI::Resolve(const nsACString& relativePath, nsACString& result)
  425. {
  426. return NS_ERROR_NOT_IMPLEMENTED;
  427. }
  428. NS_IMETHODIMP
  429. nsMozIconURI::GetAsciiSpec(nsACString& aSpecA)
  430. {
  431. return GetSpec(aSpecA);
  432. }
  433. NS_IMETHODIMP
  434. nsMozIconURI::GetAsciiHostPort(nsACString& aHostPortA)
  435. {
  436. return GetHostPort(aHostPortA);
  437. }
  438. NS_IMETHODIMP
  439. nsMozIconURI::GetAsciiHost(nsACString& aHostA)
  440. {
  441. return GetHost(aHostA);
  442. }
  443. NS_IMETHODIMP
  444. nsMozIconURI::GetOriginCharset(nsACString& result)
  445. {
  446. result.Truncate();
  447. return NS_OK;
  448. }
  449. ////////////////////////////////////////////////////////////////////////////////
  450. // nsIIconUri methods:
  451. NS_IMETHODIMP
  452. nsMozIconURI::GetIconURL(nsIURL** aFileUrl)
  453. {
  454. *aFileUrl = mIconURL;
  455. NS_IF_ADDREF(*aFileUrl);
  456. return NS_OK;
  457. }
  458. NS_IMETHODIMP
  459. nsMozIconURI::SetIconURL(nsIURL* aFileUrl)
  460. {
  461. // this isn't called anywhere, needs to go through SetSpec parsing
  462. return NS_ERROR_NOT_IMPLEMENTED;
  463. }
  464. NS_IMETHODIMP
  465. nsMozIconURI::GetImageSize(uint32_t* aImageSize)
  466. // measured by # of pixels in a row. defaults to 16.
  467. {
  468. *aImageSize = mSize;
  469. return NS_OK;
  470. }
  471. NS_IMETHODIMP
  472. nsMozIconURI::SetImageSize(uint32_t aImageSize)
  473. // measured by # of pixels in a row. defaults to 16.
  474. {
  475. mSize = aImageSize;
  476. return NS_OK;
  477. }
  478. NS_IMETHODIMP
  479. nsMozIconURI::GetContentType(nsACString& aContentType)
  480. {
  481. aContentType = mContentType;
  482. return NS_OK;
  483. }
  484. NS_IMETHODIMP
  485. nsMozIconURI::SetContentType(const nsACString& aContentType)
  486. {
  487. mContentType = aContentType;
  488. return NS_OK;
  489. }
  490. NS_IMETHODIMP
  491. nsMozIconURI::GetFileExtension(nsACString& aFileExtension)
  492. {
  493. // First, try to get the extension from mIconURL if we have one
  494. if (mIconURL) {
  495. nsAutoCString fileExt;
  496. if (NS_SUCCEEDED(mIconURL->GetFileExtension(fileExt))) {
  497. if (!fileExt.IsEmpty()) {
  498. // unfortunately, this code doesn't give us the required '.' in
  499. // front of the extension so we have to do it ourselves.
  500. aFileExtension.Assign('.');
  501. aFileExtension.Append(fileExt);
  502. }
  503. }
  504. return NS_OK;
  505. }
  506. if (!mFileName.IsEmpty()) {
  507. // truncate the extension out of the file path...
  508. const char* chFileName = mFileName.get(); // get the underlying buffer
  509. const char* fileExt = strrchr(chFileName, '.');
  510. if (!fileExt) {
  511. return NS_OK;
  512. }
  513. aFileExtension = fileExt;
  514. }
  515. return NS_OK;
  516. }
  517. NS_IMETHODIMP
  518. nsMozIconURI::GetStockIcon(nsACString& aStockIcon)
  519. {
  520. aStockIcon = mStockIcon;
  521. return NS_OK;
  522. }
  523. NS_IMETHODIMP
  524. nsMozIconURI::GetIconSize(nsACString& aSize)
  525. {
  526. if (mIconSize >= 0) {
  527. aSize = kSizeStrings[mIconSize];
  528. } else {
  529. aSize.Truncate();
  530. }
  531. return NS_OK;
  532. }
  533. NS_IMETHODIMP
  534. nsMozIconURI::GetIconState(nsACString& aState)
  535. {
  536. if (mIconState >= 0) {
  537. aState = kStateStrings[mIconState];
  538. } else {
  539. aState.Truncate();
  540. }
  541. return NS_OK;
  542. }
  543. ////////////////////////////////////////////////////////////////////////////////
  544. // nsIIPCSerializableURI methods:
  545. void
  546. nsMozIconURI::Serialize(URIParams& aParams)
  547. {
  548. IconURIParams params;
  549. if (mIconURL) {
  550. URIParams iconURLParams;
  551. SerializeURI(mIconURL, iconURLParams);
  552. if (iconURLParams.type() == URIParams::T__None) {
  553. // Serialization failed, bail.
  554. return;
  555. }
  556. params.uri() = iconURLParams;
  557. } else {
  558. params.uri() = void_t();
  559. }
  560. params.size() = mSize;
  561. params.fileName() = mFileName;
  562. params.stockIcon() = mStockIcon;
  563. params.iconSize() = mIconSize;
  564. params.iconState() = mIconState;
  565. aParams = params;
  566. }
  567. bool
  568. nsMozIconURI::Deserialize(const URIParams& aParams)
  569. {
  570. if (aParams.type() != URIParams::TIconURIParams) {
  571. MOZ_ASSERT_UNREACHABLE("Received unknown URI from other process!");
  572. return false;
  573. }
  574. const IconURIParams& params = aParams.get_IconURIParams();
  575. if (params.uri().type() != OptionalURIParams::Tvoid_t) {
  576. nsCOMPtr<nsIURI> uri = DeserializeURI(params.uri().get_URIParams());
  577. mIconURL = do_QueryInterface(uri);
  578. if (!mIconURL) {
  579. MOZ_ASSERT_UNREACHABLE("bad nsIURI passed");
  580. return false;
  581. }
  582. }
  583. mSize = params.size();
  584. mContentType = params.contentType();
  585. mFileName = params.fileName();
  586. mStockIcon = params.stockIcon();
  587. if (params.iconSize() < -1 ||
  588. params.iconSize() >= (int32_t) ArrayLength(kSizeStrings)) {
  589. return false;
  590. }
  591. mIconSize = params.iconSize();
  592. if (params.iconState() < -1 ||
  593. params.iconState() >= (int32_t) ArrayLength(kStateStrings)) {
  594. return false;
  595. }
  596. mIconState = params.iconState();
  597. return true;
  598. }
  599. ////////////////////////////////////////////////////////////
  600. // Nested version of nsIconURI
  601. nsNestedMozIconURI::nsNestedMozIconURI()
  602. { }
  603. nsNestedMozIconURI::~nsNestedMozIconURI()
  604. { }
  605. NS_IMPL_ISUPPORTS_INHERITED(nsNestedMozIconURI, nsMozIconURI, nsINestedURI)
  606. NS_IMETHODIMP
  607. nsNestedMozIconURI::GetInnerURI(nsIURI** aURI)
  608. {
  609. nsCOMPtr<nsIURI> iconURL = do_QueryInterface(mIconURL);
  610. if (iconURL) {
  611. iconURL.forget(aURI);
  612. } else {
  613. *aURI = nullptr;
  614. }
  615. return NS_OK;
  616. }
  617. NS_IMETHODIMP
  618. nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
  619. {
  620. return NS_ImplGetInnermostURI(this, aURI);
  621. }