IndexOf on nsTArray doesn't return |int|. It returns the relevant index_type. Make this function return nsTArray<OverridePermissionEntry>::index_type (and return NoIndex in the case when GetHost fails).
>+static int iprint = 0;
I have no idea what this is left over from, but presumably it should go away.
Did you actually test this? It looks like with your patch calling reloadImage on a data: image, say, will throw an exception on the ignorePolicy() call and that you don't bother catching that. I don't know whether you want to change this code or the caller, but one or the other needs changing. I should note that your IDL doesn't talk about the fact that this method will throw on all sorts of URIs...
>+ if (aReturn && *aReturn == aNewDecision)
>+ return NS_OK; // xxx: Should we override future policies?
Why exactly are we null-testing aReturn here? It can't be null if the caller is following the contract.
>+ const int loc = FindPermission(aURI, aContentType);
>+ if (loc == -1) {
Again, index_type. You might want to typedef the right type (e.g. the relevant nsTArray specialization type) for readability.
>+ const int loc = FindPermission(aURI, aContentType);
>+ if (loc != -1)
>+ mOverridePermissionEntries.RemoveElementAt(loc);
This looks bad to me. In particular if I ignorePolicy, then someone else does ignorePolicy, then they restorePolicy they'll restore both ignores. If that's not desirable, then we should either throw on nested ignore or properly have an ignore/restore stack or something.
I'm not sure why ignorePolicy and restorePolicy are returning "the current policy", given the above.
>+ * @param aContentLocation The location for which to override content policies.
>+ * The policy is ignored for the domain of the site.
This should document what happens if the URI passed in doesn't have a meaningful "domain" (whatever that is; are these policies really per-host and not at least per hostport?)
>+ * @param aContentType The type of content for which to override the policy.
That's completely useless documentation. The right way to document something like this is to at least mention that the values are precisely the TYPE_* values of nsIContentPolicy or precisely the types one would pass to nsIContentPolicy::shouldLoad, or something.
>+ * @param aNewDecision What the new policy should be. If null, the policy
>+ * will be ACCEPT.
Similar here; document what the values here can actually be, preferably by reference to the canonical place where they're defined. @see is your friend.
>+ * @returns The current nsContentBlocker policy that is being overriden.
Probably clearer as "@returns the value content blocker policy had for this location and type before this ignorePolicy call". That is, don't mention the concrete implementation and make it clear when the value is measured.
Similar comments apply to the other functions on this interface, where applicable. And discuss the behavior if calls to ignore/restorePolicy are interleaved in various ways, ok?
>+ * @returns The current nsContentBlocker policy for this content/domain.
Here "current" means "after this call completes", right?
(From update of attachment 384802) base/content/ test/image_ Reload. html
>+++ b/browser/
You have Windows newlines here. Fix that, please.
>+++ b/extensions/ permissions/ nsContentBlocke r.cpp
>+struct OverridePermiss ionEntry { ionEntry( nsCString aHost, PRUint32 aContentType, PRInt16 aPolicy) : aContentType) , aHost);
>+ OverridePermiss
>+ mContentType(
>+ mPolicy(aPolicy)
>+ {
>+ mHost.Assign(
Why not just mHost(aHost) in the initializers?
>+ OverridePermiss ionEntry( const OverridePermiss ionEntry &entry) : entry.mContentT ype), entry.mPolicy) entry.mHost) ;
>+ mContentType(
>+ mPolicy(
>+ {
>+ mHost.Assign(
And mHost(entry.mHost) here?
Also, s/entry/aOther/ or some such?
>+ OverridePermiss ionEntry( ) {};
>+static nsTArray< OverridePermiss ionEntry> mOverridePermis sionEntries;
This will show up as a leak. Why exactly do you need this as a static global instead of a member on nsContentBlocker?
>+static int FindPermission( nsIURI *aURI, PRUint32 aContentType) SUCCESS( rv, -1); sionEntries. IndexOf( temp);
....
>+ NS_ENSURE_
...
>+ return mOverridePermis
IndexOf on nsTArray doesn't return |int|. It returns the relevant index_type. Make this function return nsTArray< OverridePermiss ionEntry> ::index_ type (and return NoIndex in the case when GetHost fails).
>+static int iprint = 0;
I have no idea what this is left over from, but presumably it should go away.
>+nsContentBloc ker::IgnorePoli cy(nsIURI *aURI, ARG(aContentTyp e);
>+ NS_ENSURE_
I'm not sure why you're doing that, since you're not actually making sure it's a "valid" content type.
>+ if (!aNewDecision) y::ACCEPT;
>+ aNewDecision = nsIContentPolic
I don't like this part, but more on that below.
>+ nsCString host; host); SUCCESS( rv, rv);
>+ nsresult rv = aURI->GetHost(
>+ NS_ENSURE_
Did you actually test this? It looks like with your patch calling reloadImage on a data: image, say, will throw an exception on the ignorePolicy() call and that you don't bother catching that. I don't know whether you want to change this code or the caller, but one or the other needs changing. I should note that your IDL doesn't talk about the fact that this method will throw on all sorts of URIs...
>+ if (aReturn && *aReturn == aNewDecision)
>+ return NS_OK; // xxx: Should we override future policies?
Why exactly are we null-testing aReturn here? It can't be null if the caller is following the contract.
>+ const int loc = FindPermission( aURI, aContentType);
>+ if (loc == -1) {
Again, index_type. You might want to typedef the right type (e.g. the relevant nsTArray specialization type) for readability.
>+nsContentBloc ker::RestorePol icy(nsIURI *aURI, ARG(aContentTyp e);
>+ NS_ENSURE_
Again, not sure what that would even mean.
>+ const int loc = FindPermission( aURI, aContentType); sionEntries. RemoveElementAt (loc);
>+ if (loc != -1)
>+ mOverridePermis
This looks bad to me. In particular if I ignorePolicy, then someone else does ignorePolicy, then they restorePolicy they'll restore both ignores. If that's not desirable, then we should either throw on nested ignore or properly have an ignore/restore stack or something.
I'm not sure why ignorePolicy and restorePolicy are returning "the current policy", given the above.
>+nsContentBloc ker::IsPolicyOv erriden( nsIURI *aURI, ARG(aContentTyp e);
>+ NS_ENSURE_
Again, not sure what this means.
>+ if (aReturn) aURI, aContentType) != -1;
>+ *aReturn = FindPermission(
aReturn can't be null here And again, use the right types and NoIndex.
>@@ -264,6 +358,12 @@ nsContentBlocke r::TestPermissi on(nsIURI
>+ const int loc = FindPermission( aCurrentURI, aContentType);
>+ if (loc != -1) {
Again, the right types and NoIndex.
>+ *aPermission = mOverridePermis sionEntries[ loc].mPolicy == BEHAVIOR_ACCEPT ? PR_TRUE :
>+ PR_FALSE;
No need for the whole "? PR_TRUE : PR_FALSE" part.
Also, shouldn't this compare to nsIContentPolic y::ACCEPT, since that's what the callers will be passing in?
It looks like overriding with REJECT_* is just ignored. Is that actually on purpose? If so, the API should reflect that, I would think.
>+++ b/extensions/ permissions/ nsIContentBlock er.idl
Nix the Windows newlines throughout this file.
>+ * @param aContentLocation The location for which to override content policies.
>+ * The policy is ignored for the domain of the site.
This should document what happens if the URI passed in doesn't have a meaningful "domain" (whatever that is; are these policies really per-host and not at least per hostport?)
>+ * @param aContentType The type of content for which to override the policy.
That's completely useless documentation. The right way to document something like this is to at least mention that the values are precisely the TYPE_* values of nsIContentPolicy or precisely the types one would pass to nsIContentPolic y::shouldLoad, or something.
>+ * @param aNewDecision What the new policy should be. If null, the policy
>+ * will be ACCEPT.
Similar here; document what the values here can actually be, preferably by reference to the canonical place where they're defined. @see is your friend.
>+ * @returns The current nsContentBlocker policy that is being overriden.
Probably clearer as "@returns the value content blocker policy had for this location and type before this ignorePolicy call". That is, don't mention the concrete implementation and make it clear when the value is measured.
Similar comments apply to the other functions on this interface, where applicable. And discuss the behavior if calls to ignore/ restorePolicy are interleaved in various ways, ok?
>+ * @returns The current nsContentBlocker policy for this content/domain.
Here "current" means "after this call completes", right?