Bug 1148030 - Correctly reflect object and embed RequestContext values; r=smaug

Note that these elements cannot be intercepted for now.  See bug
1168676 for the background.
This commit is contained in:
Ehsan Akhgari 2015-07-18 11:51:00 -04:00
parent fd21120a21
commit eb1370f8cf
8 changed files with 41 additions and 10 deletions

View File

@ -1485,8 +1485,10 @@ nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy)
nsIDocument* doc = thisContent->OwnerDoc();
nsContentPolicyType contentPolicyType = GetContentPolicyType();
*aContentPolicy = nsIContentPolicy::ACCEPT;
nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT,
nsresult rv = NS_CheckContentLoadPolicy(contentPolicyType,
mURI,
doc->NodePrincipal(),
thisContent,
@ -1532,7 +1534,7 @@ nsObjectLoadingContent::CheckProcessPolicy(int16_t *aContentPolicy)
objectType = nsIContentPolicy::TYPE_DOCUMENT;
break;
case eType_Plugin:
objectType = nsIContentPolicy::TYPE_OBJECT;
objectType = GetContentPolicyType();
break;
default:
NS_NOTREACHED("Calling checkProcessPolicy with a unloadable type");
@ -2485,11 +2487,13 @@ nsObjectLoadingContent::OpenChannel()
securityFlags |= nsILoadInfo::SEC_SANDBOXED;
}
nsContentPolicyType contentPolicyType = GetContentPolicyType();
rv = NS_NewChannel(getter_AddRefs(chan),
mURI,
thisContent,
securityFlags,
nsIContentPolicy::TYPE_OBJECT,
contentPolicyType,
group, // aLoadGroup
shim, // aCallbacks
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS |

View File

@ -17,6 +17,7 @@
#include "nsImageLoadingContent.h"
#include "nsIStreamListener.h"
#include "nsIChannelEventSink.h"
#include "nsIContentPolicy.h"
#include "nsIObjectLoadingContent.h"
#include "nsIRunnable.h"
#include "nsIThreadInternal.h"
@ -332,6 +333,11 @@ class nsObjectLoadingContent : public nsImageLoadingContent
void UnbindFromTree(bool aDeep = true,
bool aNullParent = true);
/**
* Return the content policy type used for loading the element.
*/
virtual nsContentPolicyType GetContentPolicyType() const = 0;
private:
// Object parameter changes returned by UpdateObjectParameters

View File

@ -128,9 +128,12 @@ InternalRequest::MapContentPolicyTypeToRequestContext(nsContentPolicyType aConte
case nsIContentPolicy::TYPE_STYLESHEET:
context = RequestContext::Style;
break;
case nsIContentPolicy::TYPE_OBJECT:
case nsIContentPolicy::TYPE_INTERNAL_OBJECT:
context = RequestContext::Object;
break;
case nsIContentPolicy::TYPE_INTERNAL_EMBED:
context = RequestContext::Embed;
break;
case nsIContentPolicy::TYPE_DOCUMENT:
context = RequestContext::Internal;
break;

View File

@ -34,7 +34,7 @@ namespace dom {
* beacon | TYPE_BEACON
* cspreport | TYPE_CSP_REPORT
* download |
* embed | TYPE_OBJECT
* embed | TYPE_INTERNAL_EMBED
* eventsource |
* favicon |
* fetch | TYPE_FETCH
@ -49,7 +49,7 @@ namespace dom {
* internal | TYPE_DOCUMENT, TYPE_XBL, TYPE_OTHER
* location |
* manifest | TYPE_WEB_MANIFEST
* object | TYPE_OBJECT
* object | TYPE_INTERNAL_OBJECT
* ping | TYPE_PING
* plugin | TYPE_OBJECT_SUBREQUEST
* prefetch |
@ -74,7 +74,6 @@ namespace dom {
* TODO: Add a content type for form
* TODO: Add a content type for favicon
* TODO: Add a content type for download
* TODO: Split TYPE_OBJECT into TYPE_EMBED and TYPE_OBJECT
*/
class Request;

View File

@ -247,6 +247,11 @@ private:
*/
bool IsFocusableForTabIndex();
nsContentPolicyType GetContentPolicyType() const override
{
return nsIContentPolicy::TYPE_INTERNAL_OBJECT;
}
virtual void GetItemValueText(DOMString& text) override;
virtual void SetItemValueText(const nsAString& text) override;

View File

@ -387,5 +387,18 @@ HTMLSharedObjectElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenPr
return rootedObj;
}
nsContentPolicyType
HTMLSharedObjectElement::GetContentPolicyType() const
{
if (mNodeInfo->Equals(nsGkAtoms::applet)) {
// We use TYPE_INTERNAL_OBJECT for applet too, since it is not exposed
// through RequestContext yet.
return nsIContentPolicy::TYPE_INTERNAL_OBJECT;
} else {
MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::embed));
return nsIContentPolicy::TYPE_INTERNAL_EMBED;
}
}
} // namespace dom
} // namespace mozilla

View File

@ -207,6 +207,8 @@ private:
nsGkAtoms::src;
}
nsContentPolicyType GetContentPolicyType() const override;
// mIsDoneAddingChildren is only really used for <applet>. This boolean is
// always true for <embed>, per the documentation in nsIContent.h.
bool mIsDoneAddingChildren;

View File

@ -128,8 +128,7 @@
document.documentElement.appendChild(embed);
navigator.serviceWorker.addEventListener("message", function onMessage(e) {
if (e.data.data == "embed") {
// FIXME: Bug 1148030: This should be "embed".
is(e.data.context, "object", "Expected the object context on an embed");
is(e.data.context, "embed", "Expected the object context on an embed");
navigator.serviceWorker.removeEventListener("message", onMessage);
resolve();
}