Bug 1580782 - Expose SchemeIs on nsIPrincipal r=ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D45653
This commit is contained in:
Sebastian Streich
2019-09-26 10:47:03 +00:00
parent 6b6673ea5a
commit 21651eaa36
3 changed files with 29 additions and 0 deletions

View File

@@ -410,6 +410,18 @@ BasePrincipal::GetIsAddonOrExpandedAddonPrincipal(bool* aResult) {
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::SchemeIs(const char* aScheme, bool* aResult) {
*aResult = false;
nsCOMPtr<nsIURI> prinURI;
nsresult rv = GetURI(getter_AddRefs(prinURI));
if (NS_FAILED(rv) || !prinURI) {
return NS_OK;
}
*aResult = prinURI->SchemeIs(aScheme);
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::GetOriginAttributes(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal) {

View File

@@ -116,6 +116,7 @@ class BasePrincipal : public nsJSPrincipals {
NS_IMETHOD GetIsContentPrincipal(bool* aResult) override;
NS_IMETHOD GetIsExpandedPrincipal(bool* aResult) override;
NS_IMETHOD GetIsSystemPrincipal(bool* aResult) override;
NS_IMETHOD SchemeIs(const char* aScheme, bool* aResult) override;
NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override;
NS_IMETHOD GetOriginAttributes(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal) final;

View File

@@ -180,6 +180,22 @@ interface nsIPrincipal : nsISerializable
*/
readonly attribute ACString origin;
/**
* Checks if the Principal's URI Scheme matches with the parameter
*
* @param scheme The scheme to be checked
*/
boolean schemeIs(in string scheme);
// Nicer, C++ Callable Version of SchemeIs
%{C++
inline bool SchemeIs(const char* aScheme) {
bool ret;
SchemeIs(aScheme, &ret);
return ret;
}
%}
/**
* The base part of |origin| without the concatenation with |originSuffix|.
* This doesn't have the important invariants described above with |origin|,