nsILoadInfo.idl 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. * vim: ft=cpp tw=78 sw=2 et ts=2 sts=2 cin
  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 "nsISupports.idl"
  7. #include "nsIContentPolicy.idl"
  8. interface nsIDOMDocument;
  9. interface nsINode;
  10. interface nsIPrincipal;
  11. native LoadContextRef(already_AddRefed<nsISupports>);
  12. %{C++
  13. #include "nsTArray.h"
  14. #include "mozilla/BasePrincipal.h"
  15. #include "mozilla/LoadTainting.h"
  16. class nsCString;
  17. %}
  18. [ref] native const_nsIPrincipalArray(const nsTArray<nsCOMPtr<nsIPrincipal>>);
  19. native NeckoOriginAttributes(mozilla::NeckoOriginAttributes);
  20. [ref] native const_OriginAttributesRef(const mozilla::NeckoOriginAttributes);
  21. [ref] native StringArrayRef(const nsTArray<nsCString>);
  22. typedef unsigned long nsSecurityFlags;
  23. /**
  24. * The LoadInfo object contains information about a network load, why it
  25. * was started, and how we plan on using the resulting response.
  26. * If a network request is redirected, the new channel will receive a new
  27. * LoadInfo object. The new object will contain mostly the same
  28. * information as the pre-redirect one, but updated as appropriate.
  29. * For detailed information about what parts of LoadInfo are updated on
  30. * redirect, see documentation on individual properties.
  31. */
  32. [scriptable, builtinclass, uuid(ddc65bf9-2f60-41ab-b22a-4f1ae9efcd36)]
  33. interface nsILoadInfo : nsISupports
  34. {
  35. /**
  36. * *** DEPRECATED ***
  37. * No LoadInfo created within Gecko should contain this security flag.
  38. * Please use any of the five security flags defined underneath.
  39. * We only keep this security flag to provide backwards compatibilty.
  40. */
  41. const unsigned long SEC_NORMAL = 0;
  42. /**
  43. * The following five flags determine the security mode and hence what kind of
  44. * security checks should be performed throughout the lifetime of the channel.
  45. *
  46. * * SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS
  47. * * SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED
  48. * * SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS
  49. * * SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
  50. * * SEC_REQUIRE_CORS_DATA_INHERITS
  51. *
  52. * Exactly one of these flags are required to be set in order to allow
  53. * the channel to perform the correct security checks (SOP, CORS, ...) and
  54. * return the correct result principal. If none or more than one of these
  55. * flags are set AsyncOpen2 will fail.
  56. */
  57. /*
  58. * Enforce the same origin policy where data: loads inherit
  59. * the principal.
  60. */
  61. const unsigned long SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS = (1<<0);
  62. /*
  63. * Enforce the same origin policy but data: loads are blocked.
  64. */
  65. const unsigned long SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED = (1<<1);
  66. /**
  67. * Allow loads from other origins. Loads from data: will inherit
  68. * the principal of the origin that triggered the load.
  69. * Commonly used by plain <img>, <video>, <link rel=stylesheet> etc.
  70. */
  71. const unsigned long SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS = (1<<2);
  72. /**
  73. * Allow loads from other origins. Loads from data: will be allowed,
  74. * but the resulting resource will get a null principal.
  75. * Used in blink/webkit for <iframe>s. Likely also the mode
  76. * that should be used by most Chrome code.
  77. */
  78. const unsigned long SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL = (1<<3);
  79. /**
  80. * Allow loads from any origin, but require CORS for cross-origin
  81. * loads. Loads from data: are allowed and the result will inherit
  82. * the principal of the origin that triggered the load.
  83. * Commonly used by <img crossorigin>, <video crossorigin>,
  84. * XHR, fetch(), etc.
  85. */
  86. const unsigned long SEC_REQUIRE_CORS_DATA_INHERITS = (1<<4);
  87. /**
  88. * Choose cookie policy. The default policy is equivalent to "INCLUDE" for
  89. * SEC_REQUIRE_SAME_ORIGIN_* and SEC_ALLOW_CROSS_ORIGIN_* modes, and
  90. * equivalent to "SAME_ORIGIN" for SEC_REQUIRE_CORS_DATA_INHERITS mode.
  91. *
  92. * This means that if you want to perform a CORS load with credentials, pass
  93. * SEC_COOKIES_INCLUDE.
  94. *
  95. * Note that these flags are still subject to the user's cookie policies.
  96. * For example, if the user is blocking 3rd party cookies, those cookies
  97. * will be blocked no matter which of these flags are set.
  98. */
  99. const unsigned long SEC_COOKIES_DEFAULT = (0 << 5);
  100. const unsigned long SEC_COOKIES_INCLUDE = (1 << 5);
  101. const unsigned long SEC_COOKIES_SAME_ORIGIN = (2 << 5);
  102. const unsigned long SEC_COOKIES_OMIT = (3 << 5);
  103. /**
  104. * Force inheriting of the Principal. The resulting resource will use the
  105. * principal of the document which is doing the load. Setting this flag
  106. * will cause GetChannelResultPrincipal to return the same principal as
  107. * the loading principal that's passed in when creating the channel.
  108. *
  109. * This will happen independently of the scheme of the URI that the
  110. * channel is loading.
  111. *
  112. * So if the loading document comes from "http://a.com/", and the channel
  113. * is loading the URI "http://b.com/whatever", GetChannelResultPrincipal
  114. * will return a principal from "http://a.com/".
  115. *
  116. * This flag can not be used together with SEC_SANDBOXED. If both are passed
  117. * to the LoadInfo constructor then this flag will be dropped. If you need
  118. * to know whether this flag would have been present but was dropped due to
  119. * sandboxing, check for the forceInheritPrincipalDropped flag.
  120. */
  121. const unsigned long SEC_FORCE_INHERIT_PRINCIPAL = (1<<7);
  122. /**
  123. * Sandbox the load. The resulting resource will use a freshly created
  124. * null principal. So GetChannelResultPrincipal will always return a
  125. * null principal whenever this flag is set.
  126. *
  127. * This will happen independently of the scheme of the URI that the
  128. * channel is loading.
  129. *
  130. * This flag can not be used together with SEC_FORCE_INHERIT_PRINCIPAL.
  131. */
  132. const unsigned long SEC_SANDBOXED = (1<<8);
  133. /**
  134. * Inherit the Principal for about:blank.
  135. */
  136. const unsigned long SEC_ABOUT_BLANK_INHERITS = (1<<9);
  137. /**
  138. * Allow access to chrome: packages that are content accessible.
  139. */
  140. const unsigned long SEC_ALLOW_CHROME = (1<<10);
  141. /**
  142. * Disallow access to javascript: uris.
  143. */
  144. const unsigned long SEC_DISALLOW_SCRIPT = (1<<11);
  145. /**
  146. * Don't follow redirects. Instead the redirect response is returned
  147. * as a successful response for the channel.
  148. *
  149. * Redirects not initiated by a server response, i.e. REDIRECT_INTERNAL and
  150. * REDIRECT_STS_UPGRADE, are still followed.
  151. *
  152. * Note: If this flag is set and the channel response is a redirect, then
  153. * the response body might not be available.
  154. * This can happen if the redirect was cached.
  155. */
  156. const unsigned long SEC_DONT_FOLLOW_REDIRECTS = (1<<12);
  157. /**
  158. * Load an error page, it should be one of following : about:neterror,
  159. * about:certerror, about:blocked, or about:tabcrashed.
  160. */
  161. const unsigned long SEC_LOAD_ERROR_PAGE = (1<<13);
  162. /**
  163. * Force inheriting of the principalToInherit, overruling any owner
  164. * that might be set on the channel. (Please note that channel.owner
  165. * is deprecated and will be removed within Bug 1286838).
  166. * Setting this flag will cause GetChannelResultPrincipal to return the
  167. * principalToInherit set in the loadInfo.
  168. *
  169. * This will happen independently of the scheme of the URI that the
  170. * channel is loading.
  171. */
  172. const unsigned long SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER = (1<<14);
  173. /**
  174. * This is the principal of the network request's caller/requester where
  175. * the resulting resource will be used. I.e. it is the principal which
  176. * will get access to the result of the request. (Where "get access to"
  177. * might simply mean "embed" depending on the type of resource that is
  178. * loaded).
  179. *
  180. * For example for an image, it is the principal of the document where
  181. * the image is rendered. For a stylesheet it is the principal of the
  182. * document where the stylesheet will be applied.
  183. *
  184. * So if document at http://a.com/page.html loads an image from
  185. * http://b.com/pic.jpg, then loadingPrincipal will be
  186. * http://a.com/page.html.
  187. *
  188. * For <iframe> and <frame> loads, the LoadingPrincipal is the
  189. * principal of the parent document. For top-level loads, the
  190. * LoadingPrincipal is null. For all loads except top-level loads
  191. * the LoadingPrincipal is never null.
  192. *
  193. * If the loadingPrincipal is the system principal, no security checks
  194. * will be done at all. There will be no security checks on the initial
  195. * load or any subsequent redirects. This means there will be no
  196. * nsIContentPolicy checks or any CheckLoadURI checks. Because of
  197. * this, never set the loadingPrincipal to the system principal when
  198. * the URI to be loaded is controlled by a webpage.
  199. * If the loadingPrincipal and triggeringPrincipal are both
  200. * codebase-principals, then we will always call into
  201. * nsIContentPolicies and CheckLoadURI. The call to nsIContentPolicies
  202. * and CheckLoadURI happen even if the URI to be loaded is same-origin
  203. * with the loadingPrincipal or triggeringPrincipal.
  204. */
  205. readonly attribute nsIPrincipal loadingPrincipal;
  206. /**
  207. * A C++-friendly version of loadingPrincipal.
  208. */
  209. [noscript, notxpcom, nostdcall, binaryname(LoadingPrincipal)]
  210. nsIPrincipal binaryLoadingPrincipal();
  211. /**
  212. * This is the principal which caused the network load to start. I.e.
  213. * this is the principal which provided the URL to be loaded. This is
  214. * often the same as the LoadingPrincipal, but there are a few cases
  215. * where that's not true.
  216. *
  217. * For example for loads into an <iframe>, the LoadingPrincipal is always
  218. * the principal of the parent document. However the triggeringPrincipal
  219. * is the principal of the document which provided the URL that the
  220. * <iframe> is navigating to. This could be the previous document inside
  221. * the <iframe> which set document.location. Or a document elsewhere in
  222. * the frame tree which contained a <a target="..."> which targetted the
  223. * <iframe>.
  224. *
  225. * If a stylesheet links to a sub-resource, like an @imported stylesheet,
  226. * or a background image, then the triggeringPrincipal is the principal
  227. * of the stylesheet, while the LoadingPrincipal is the principal of the
  228. * document being styled.
  229. *
  230. * The triggeringPrincipal is never null.
  231. *
  232. * If the triggeringPrincipal is the system principal, no security checks
  233. * will be done at all. There will be no security checks on the initial
  234. * load or any subsequent redirects. This means there will be no
  235. * nsIContentPolicy checks or any CheckLoadURI checks. Because of
  236. * this, never set the triggeringPrincipal to the system principal when
  237. * the URI to be loaded is controlled by a webpage.
  238. * If the loadingPrincipal and triggeringPrincipal are both
  239. * codebase-principals, then we will always call into
  240. * nsIContentPolicies and CheckLoadURI. The call to nsIContentPolicies
  241. * and CheckLoadURI happen even if the URI to be loaded is same-origin
  242. * with the loadingPrincipal or triggeringPrincipal.
  243. */
  244. readonly attribute nsIPrincipal triggeringPrincipal;
  245. /**
  246. * A C++-friendly version of triggeringPrincipal.
  247. */
  248. [noscript, notxpcom, nostdcall, binaryname(TriggeringPrincipal)]
  249. nsIPrincipal binaryTriggeringPrincipal();
  250. /**
  251. * For non-document loads the principalToInherit is always null. For
  252. * loads of type TYPE_DOCUMENT or TYPE_SUBDOCUMENT the principalToInherit
  253. * might be null. If it's non null, then this is the principal that is
  254. * inherited if a principal needs to be inherited. If the principalToInherit
  255. * is null but the inherit flag is set, then the triggeringPrincipal is
  256. * the principal that is inherited.
  257. */
  258. attribute nsIPrincipal principalToInherit;
  259. /**
  260. * A C++-friendly version of principalToInherit.
  261. */
  262. [noscript, notxpcom, nostdcall, binaryname(PrincipalToInherit)]
  263. nsIPrincipal binaryPrincipalToInherit();
  264. /**
  265. * This is the ownerDocument of the LoadingNode. Unless the LoadingNode
  266. * is a Document, in which case the LoadingDocument is the same as the
  267. * LoadingNode.
  268. *
  269. * For top-level loads, and for loads originating from workers, the
  270. * LoadingDocument is null. When the LoadingDocument is not null, the
  271. * LoadingPrincipal is set to the principal of the LoadingDocument.
  272. */
  273. readonly attribute nsIDOMDocument loadingDocument;
  274. /**
  275. * A C++-friendly version of loadingDocument (loadingNode).
  276. * This is the Node where the resulting resource will be used. I.e. it is
  277. * the Node which will get access to the result of the request. (Where
  278. * "get access to" might simply mean "embed" depending on the type of
  279. * resource that is loaded).
  280. *
  281. * For example for an <img>/<video> it is the image/video element. For
  282. * document loads inside <iframe> and <frame>s, the LoadingNode is the
  283. * <iframe>/<frame> element. For an XMLHttpRequest, it is the Document
  284. * which contained the JS which initiated the XHR. For a stylesheet, it
  285. * is the Document that contains <link rel=stylesheet>.
  286. *
  287. * For loads triggered by the HTML pre-parser, the LoadingNode is the
  288. * Document which is currently being parsed.
  289. *
  290. * For top-level loads, and for loads originating from workers, the
  291. * LoadingNode is null. If the LoadingNode is non-null, then the
  292. * LoadingPrincipal is the principal of the LoadingNode.
  293. */
  294. [noscript, notxpcom, nostdcall, binaryname(LoadingNode)]
  295. nsINode binaryLoadingNode();
  296. /**
  297. * A C++ friendly version of the loadingContext for toplevel loads.
  298. * Most likely you want to query the ownerDocument or LoadingNode
  299. * and not this context only available for TYPE_DOCUMENT loads.
  300. * Please note that except for loads of TYPE_DOCUMENT, this
  301. * ContextForTopLevelLoad will always return null.
  302. */
  303. [noscript, notxpcom, nostdcall, binaryname(ContextForTopLevelLoad)]
  304. nsISupports binaryContextForTopLevelLoad();
  305. /**
  306. * For all loads except loads of TYPE_DOCUMENT, the loadingContext
  307. * simply returns the loadingNode. For loads of TYPE_DOCUMENT this
  308. * will return the context available for top-level loads which
  309. * do not have a loadingNode.
  310. */
  311. [binaryname(LoadingContextXPCOM)]
  312. readonly attribute nsISupports loadingContext;
  313. /**
  314. * A C++ friendly version of the loadingContext.
  315. */
  316. [noscript, notxpcom, nostdcall, binaryname(GetLoadingContext)]
  317. LoadContextRef binaryGetLoadingContext();
  318. /**
  319. * The securityFlags of that channel.
  320. */
  321. readonly attribute nsSecurityFlags securityFlags;
  322. %{ C++
  323. inline nsSecurityFlags GetSecurityFlags()
  324. {
  325. nsSecurityFlags result;
  326. mozilla::DebugOnly<nsresult> rv = GetSecurityFlags(&result);
  327. MOZ_ASSERT(NS_SUCCEEDED(rv));
  328. return result;
  329. }
  330. %}
  331. /**
  332. * Allows to query only the security mode bits from above.
  333. */
  334. [infallible] readonly attribute unsigned long securityMode;
  335. /**
  336. * True if this request is embedded in a context that can't be third-party
  337. * (i.e. an iframe embedded in a cross-origin parent window). If this is
  338. * false, then this request may be third-party if it's a third-party to
  339. * loadingPrincipal.
  340. */
  341. [infallible] readonly attribute boolean isInThirdPartyContext;
  342. /**
  343. * See the SEC_COOKIES_* flags above. This attribute will never return
  344. * SEC_COOKIES_DEFAULT, but will instead return what the policy resolves to.
  345. * I.e. SEC_COOKIES_SAME_ORIGIN for CORS mode, and SEC_COOKIES_INCLUDE
  346. * otherwise.
  347. */
  348. [infallible] readonly attribute unsigned long cookiePolicy;
  349. /**
  350. * If forceInheritPrincipal is true, the data coming from the channel should
  351. * use loadingPrincipal for its principal, even when the data is loaded over
  352. * http:// or another protocol that would normally use a URI-based principal.
  353. * This attribute will never be true when loadingSandboxed is true.
  354. */
  355. [infallible] readonly attribute boolean forceInheritPrincipal;
  356. /**
  357. * If forceInheritPrincipalOverruleOwner is true, the data coming from the
  358. * channel should use principalToInherit for its principal, even when the
  359. * data is loaded over http:// or another protocol that would normally use
  360. * a URI-based principal.
  361. */
  362. [infallible] readonly attribute boolean forceInheritPrincipalOverruleOwner;
  363. /**
  364. * If loadingSandboxed is true, the data coming from the channel is
  365. * being loaded sandboxed, so it should have a nonce origin and
  366. * hence should use a NullPrincipal.
  367. */
  368. [infallible] readonly attribute boolean loadingSandboxed;
  369. /**
  370. * If aboutBlankInherits is true, then about:blank should inherit
  371. * the principal.
  372. */
  373. [infallible] readonly attribute boolean aboutBlankInherits;
  374. /**
  375. * If allowChrome is true, then use nsIScriptSecurityManager::ALLOW_CHROME
  376. * when calling CheckLoadURIWithPrincipal().
  377. */
  378. [infallible] readonly attribute boolean allowChrome;
  379. /**
  380. * If disallowScript is true, then use nsIScriptSecurityManager::DISALLOW_SCRIPT
  381. * when calling CheckLoadURIWithPrincipal().
  382. */
  383. [infallible] readonly attribute boolean disallowScript;
  384. /**
  385. * Returns true if SEC_DONT_FOLLOW_REDIRECTS is set.
  386. */
  387. [infallible] readonly attribute boolean dontFollowRedirects;
  388. /**
  389. * Returns true if SEC_LOAD_ERROR_PAGE is set.
  390. */
  391. [infallible] readonly attribute boolean loadErrorPage;
  392. /**
  393. * The external contentPolicyType of the channel, used for security checks
  394. * like Mixed Content Blocking and Content Security Policy.
  395. *
  396. * Specifically, content policy types with _INTERNAL_ in their name will
  397. * never get returned from this attribute.
  398. */
  399. readonly attribute nsContentPolicyType externalContentPolicyType;
  400. %{ C++
  401. inline nsContentPolicyType GetExternalContentPolicyType()
  402. {
  403. nsContentPolicyType result;
  404. mozilla::DebugOnly<nsresult> rv = GetExternalContentPolicyType(&result);
  405. MOZ_ASSERT(NS_SUCCEEDED(rv));
  406. return result;
  407. }
  408. %}
  409. /**
  410. * The internal contentPolicyType of the channel, used for constructing
  411. * RequestContext values when creating a fetch event for an intercepted
  412. * channel.
  413. *
  414. * This should not be used for the purposes of security checks, since
  415. * the content policy implementations cannot be expected to deal with
  416. * _INTERNAL_ values. Please use the contentPolicyType attribute above
  417. * for that purpose.
  418. */
  419. [noscript, notxpcom]
  420. nsContentPolicyType internalContentPolicyType();
  421. /**
  422. * Returns true if document or any of the documents ancestors
  423. * up to the toplevel document make use of the CSP directive
  424. * 'upgrade-insecure-requests'. Used to identify upgrade
  425. * requests in e10s where the loadingDocument is not available.
  426. *
  427. * Warning: If the loadingDocument is null, then the
  428. * upgradeInsecureRequests is false.
  429. */
  430. [infallible] readonly attribute boolean upgradeInsecureRequests;
  431. /**
  432. * If true, the content of the channel is queued up and checked
  433. * if it matches a content signature. Note, setting this flag
  434. * to true will negatively impact performance since the preloader
  435. * can not start until all of the content is fetched from the
  436. * netwerk.
  437. *
  438. * Only use that in combination with TYPE_DOCUMENT.
  439. */
  440. [infallible] attribute boolean verifySignedContent;
  441. /**
  442. * If true, this load will fail if it has no SRI integrity
  443. */
  444. [infallible] attribute boolean enforceSRI;
  445. /**
  446. * If true, toplevel data: URI navigation is allowed
  447. */
  448. [infallible] attribute boolean forceAllowDataURI;
  449. /**
  450. * The SEC_FORCE_INHERIT_PRINCIPAL flag may be dropped when a load info
  451. * object is created. Specifically, it will be dropped if the SEC_SANDBOXED
  452. * flag is also present. This flag is set if SEC_FORCE_INHERIT_PRINCIPAL was
  453. * dropped.
  454. */
  455. [infallible] readonly attribute boolean forceInheritPrincipalDropped;
  456. /**
  457. * These are the window IDs of the window in which the element being
  458. * loaded lives. parentOuterWindowID is the window ID of this window's
  459. * parent.
  460. *
  461. * Note that these window IDs can be 0 if the window is not
  462. * available. parentOuterWindowID will be the same as outerWindowID if the
  463. * window has no parent.
  464. */
  465. [infallible] readonly attribute unsigned long long innerWindowID;
  466. [infallible] readonly attribute unsigned long long outerWindowID;
  467. [infallible] readonly attribute unsigned long long parentOuterWindowID;
  468. /**
  469. * Only when the element being loaded is <frame src="foo.html">
  470. * (or, more generally, if the element QIs to nsIFrameLoaderOwner),
  471. * the frameOuterWindowID is the outer window containing the
  472. * foo.html document.
  473. *
  474. * Note: For other cases, frameOuterWindowID is 0.
  475. */
  476. [infallible] readonly attribute unsigned long long frameOuterWindowID;
  477. /**
  478. * For all loads of none TYPE_DOUCMENT this function resets the
  479. * LoadingPrincipal, the TriggeringPrincipal and the
  480. * PrincipalToInherit to a freshly created NullPrincipal which inherits
  481. * the current origin attributes from the loadinfo.
  482. * For loads of TYPE_DOCUMENT this function resets only the
  483. * TriggeringPrincipal as well as the PrincipalToInherit to a freshly
  484. * created NullPrincipal which inherits the origin attributes from
  485. * the loadInfo. (Please note that the LoadingPrincipal for TYPE_DOCUMENT
  486. * loads is always null.)
  487. *
  488. * WARNING: Please only use that function if you know exactly what
  489. * you are doing!!!
  490. */
  491. void resetPrincipalsToNullPrincipal();
  492. /**
  493. * Customized NeckoOriginAttributes within LoadInfo to allow overwriting of the
  494. * default originAttributes from the loadingPrincipal.
  495. *
  496. * In chrome side, originAttributes.privateBrowsingId will always be 0 even if
  497. * the usePrivateBrowsing is true, because chrome docshell won't set
  498. * privateBrowsingId on origin attributes (See bug 1278664). This is to make
  499. * sure nsILoadInfo and nsILoadContext have the same origin attributes.
  500. */
  501. [implicit_jscontext, binaryname(ScriptableOriginAttributes)]
  502. attribute jsval originAttributes;
  503. [noscript, nostdcall, binaryname(GetOriginAttributes)]
  504. NeckoOriginAttributes binaryGetOriginAttributes();
  505. [noscript, nostdcall, binaryname(SetOriginAttributes)]
  506. void binarySetOriginAttributes(in const_OriginAttributesRef aOriginAttrs);
  507. %{ C++
  508. inline mozilla::NeckoOriginAttributes GetOriginAttributes()
  509. {
  510. mozilla::NeckoOriginAttributes result;
  511. mozilla::DebugOnly<nsresult> rv = GetOriginAttributes(&result);
  512. MOZ_ASSERT(NS_SUCCEEDED(rv));
  513. return result;
  514. }
  515. %}
  516. /**
  517. * Whenever a channel is openend by asyncOpen2() [or also open2()],
  518. * lets set this flag so that redirects of such channels are also
  519. * openend using asyncOpen2() [open2()].
  520. *
  521. * Please note, once the flag is set to true it must remain true
  522. * throughout the lifetime of the channel. Trying to set it
  523. * to anything else than true will be discareded.
  524. *
  525. */
  526. [infallible] attribute boolean enforceSecurity;
  527. /**
  528. * Whenever a channel is evaluated by the ContentSecurityManager
  529. * the first time, we set this flag to true to indicate that
  530. * subsequent calls of AsyncOpen2() do not have to enforce all
  531. * security checks again. E.g., after a redirect there is no
  532. * need to set up CORS again. We need this separate flag
  533. * because the redirectChain might also contain internal
  534. * redirects which might pollute the redirectChain so we can't
  535. * rely on the size of the redirectChain-array to query whether
  536. * a channel got redirected or not.
  537. *
  538. * Please note, once the flag is set to true it must remain true
  539. * throughout the lifetime of the channel. Trying to set it
  540. * to anything else than true will be discarded.
  541. *
  542. */
  543. [infallible] attribute boolean initialSecurityCheckDone;
  544. /**
  545. * Returns true if the load was triggered from an external application
  546. * (e.g. Thunderbird). Please note that this flag will only ever be true
  547. * if the load is of TYPE_DOCUMENT.
  548. */
  549. [infallible] attribute boolean loadTriggeredFromExternal;
  550. /**
  551. * Whenever a channel gets redirected, append the principal of the
  552. * channel [before the channels got redirected] to the loadinfo,
  553. * so that at every point this array lets us reason about all the
  554. * redirects this channel went through.
  555. * @param aPrincipal, the channelURIPrincipal before the channel
  556. * got redirected.
  557. * @param aIsInternalRedirect should be true if the channel is going
  558. * through an internal redirect, otherwise false.
  559. */
  560. void appendRedirectedPrincipal(in nsIPrincipal principal,
  561. in boolean isInternalRedirect);
  562. /**
  563. * An array of nsIPrincipals which stores redirects associated with this
  564. * channel. This array is filled whether or not the channel has ever been
  565. * opened. The last element of the array is associated with the most recent
  566. * redirect. Please note, that this array *includes* internal redirects.
  567. */
  568. [implicit_jscontext]
  569. readonly attribute jsval redirectChainIncludingInternalRedirects;
  570. /**
  571. * A C++-friendly version of redirectChain.
  572. * Please note that this array has the same lifetime as the
  573. * loadInfo object - use with caution!
  574. */
  575. [noscript, notxpcom, nostdcall, binaryname(RedirectChainIncludingInternalRedirects)]
  576. const_nsIPrincipalArray binaryRedirectChainIncludingInternalRedirects();
  577. /**
  578. * Same as RedirectChain but does *not* include internal redirects.
  579. */
  580. [implicit_jscontext]
  581. readonly attribute jsval redirectChain;
  582. /**
  583. * A C++-friendly version of redirectChain.
  584. * Please note that this array has the same lifetime as the
  585. * loadInfo object - use with caution!
  586. */
  587. [noscript, notxpcom, nostdcall, binaryname(RedirectChain)]
  588. const_nsIPrincipalArray binaryRedirectChain();
  589. /**
  590. * Sets the list of unsafe headers according to CORS spec, as well as
  591. * potentially forces a preflight.
  592. * Note that you do not need to set the Content-Type header. That will be
  593. * automatically detected as needed.
  594. *
  595. * Only call this function when using the SEC_REQUIRE_CORS_DATA_INHERITS mode.
  596. */
  597. [noscript, notxpcom, nostdcall]
  598. void setCorsPreflightInfo(in StringArrayRef unsafeHeaders,
  599. in boolean forcePreflight);
  600. /**
  601. * A C++-friendly getter for the list of cors-unsafe headers.
  602. * Please note that this array has the same lifetime as the
  603. * loadInfo object - use with caution!
  604. */
  605. [noscript, notxpcom, nostdcall, binaryname(CorsUnsafeHeaders)]
  606. StringArrayRef corsUnsafeHeaders();
  607. /**
  608. * Returns value set through setCorsPreflightInfo.
  609. */
  610. [infallible] readonly attribute boolean forcePreflight;
  611. /**
  612. * A C++ friendly getter for the forcePreflight flag.
  613. */
  614. [infallible] readonly attribute boolean isPreflight;
  615. /**
  616. * Constants reflecting the channel tainting. These are mainly defined here
  617. * for script. Internal C++ code should use the enum defined in LoadTainting.h.
  618. * See LoadTainting.h for documentation.
  619. */
  620. const unsigned long TAINTING_BASIC = 0;
  621. const unsigned long TAINTING_CORS = 1;
  622. const unsigned long TAINTING_OPAQUE = 2;
  623. /**
  624. * Determine the associated channel's current tainting. Note, this can
  625. * change due to a service worker intercept, so it should be checked after
  626. * OnStartRequest() fires.
  627. */
  628. readonly attribute unsigned long tainting;
  629. /**
  630. * Note a new tainting level and possibly increase the current tainting
  631. * to match. If the tainting level is already greater than the given
  632. * value, then there is no effect. It is not possible to reduce the tainting
  633. * level on an existing channel/loadinfo.
  634. */
  635. void maybeIncreaseTainting(in unsigned long aTainting);
  636. /**
  637. * Various helper code to provide more convenient C++ access to the tainting
  638. * attribute and maybeIncreaseTainting().
  639. */
  640. %{C++
  641. static_assert(TAINTING_BASIC == static_cast<uint32_t>(mozilla::LoadTainting::Basic),
  642. "basic tainting enums should match");
  643. static_assert(TAINTING_CORS == static_cast<uint32_t>(mozilla::LoadTainting::CORS),
  644. "cors tainting enums should match");
  645. static_assert(TAINTING_OPAQUE == static_cast<uint32_t>(mozilla::LoadTainting::Opaque),
  646. "opaque tainting enums should match");
  647. mozilla::LoadTainting GetTainting()
  648. {
  649. uint32_t tainting = TAINTING_BASIC;
  650. MOZ_ALWAYS_SUCCEEDS(GetTainting(&tainting));
  651. return static_cast<mozilla::LoadTainting>(tainting);
  652. }
  653. void MaybeIncreaseTainting(mozilla::LoadTainting aTainting)
  654. {
  655. uint32_t tainting = static_cast<uint32_t>(aTainting);
  656. MOZ_ALWAYS_SUCCEEDS(MaybeIncreaseTainting(tainting));
  657. }
  658. %}
  659. /**
  660. * Returns true if this load is for top level document.
  661. * Note that the load for a sub-frame's document will return false here.
  662. */
  663. [infallible] readonly attribute boolean isTopLevelLoad;
  664. /**
  665. * This attribute will be true if this is a load triggered by
  666. * https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes
  667. * or https://html.spec.whatwg.org/multipage/obsolete.html#process-the-frame-attributes
  668. */
  669. [infallible] readonly attribute boolean isFromProcessingFrameAttributes;
  670. };