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

View File

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

View File

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

View File

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

View File

@ -246,7 +246,12 @@ private:
* value. This is used to know the default tabindex value. * value. This is used to know the default tabindex value.
*/ */
bool IsFocusableForTabIndex(); bool IsFocusableForTabIndex();
nsContentPolicyType GetContentPolicyType() const override
{
return nsIContentPolicy::TYPE_INTERNAL_OBJECT;
}
virtual void GetItemValueText(DOMString& text) override; virtual void GetItemValueText(DOMString& text) override;
virtual void SetItemValueText(const nsAString& 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; 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 dom
} // namespace mozilla } // namespace mozilla

View File

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

View File

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