Bug 1119037 - Add context attribute to Request. r=baku
authorNikhil Marathe <nsm.nikhil@gmail.com>
Tue, 27 Jan 2015 15:43:09 -0800
changeset 256530 4ac6715d8224b35a1bbe4518ed99e9177a82b605
parent 256529 798d15daa5a9d6860667a5d4d27ca6e425c7db29
child 256531 ecd613d5d87ceb0983bd737e276fdab051cd1468
push id721
push userjlund@mozilla.com
push dateTue, 21 Apr 2015 23:03:33 +0000
treeherdermozilla-release@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1119037
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1119037 - Add context attribute to Request. r=baku
dom/fetch/FetchDriver.cpp
dom/fetch/InternalRequest.cpp
dom/fetch/InternalRequest.h
dom/fetch/Request.cpp
dom/fetch/Request.h
dom/webidl/Request.webidl
dom/workers/test/fetch/worker_test_request.js
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -345,17 +345,17 @@ FetchDriver::HttpFetch(bool aCORSFlag, b
   // From here on we create a channel and set its properties with the
   // information from the InternalRequest. This is an implementation detail.
   MOZ_ASSERT(mLoadGroup);
   nsCOMPtr<nsIChannel> chan;
   rv = NS_NewChannel(getter_AddRefs(chan),
                      uri,
                      mPrincipal,
                      nsILoadInfo::SEC_NORMAL,
-                     mRequest->GetContext(),
+                     mRequest->ContentPolicyType(),
                      mLoadGroup,
                      nullptr, /* aCallbacks */
                      nsIRequest::LOAD_NORMAL | credentialsFlag,
                      ios);
   mLoadGroup = nullptr;
   if (NS_WARN_IF(NS_FAILED(rv))) {
     FailWithNetworkError();
     return rv;
--- a/dom/fetch/InternalRequest.cpp
+++ b/dom/fetch/InternalRequest.cpp
@@ -31,17 +31,17 @@ InternalRequest::GetRequestConstructorCo
   copy->mForceOriginHeader = true;
   // The "client" is not stored in our implementation. Fetch API users should
   // use the appropriate window/document/principal and other Gecko security
   // mechanisms as appropriate.
   copy->mSameOriginDataURL = true;
   copy->mPreserveContentCodings = true;
   // The default referrer is already about:client.
 
-  copy->mContext = nsIContentPolicy::TYPE_FETCH;
+  copy->mContentPolicyType = nsIContentPolicy::TYPE_FETCH;
   copy->mMode = mMode;
   copy->mCredentialsMode = mCredentialsMode;
   copy->mCacheMode = mCacheMode;
   return copy.forget();
 }
 
 InternalRequest::~InternalRequest()
 {
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -32,35 +32,26 @@ class Request;
 
 class InternalRequest MOZ_FINAL
 {
   friend class Request;
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
 
-  enum ContextFrameType
-  {
-    FRAMETYPE_AUXILIARY = 0,
-    FRAMETYPE_TOP_LEVEL,
-    FRAMETYPE_NESTED,
-    FRAMETYPE_NONE,
-  };
-
   enum ResponseTainting
   {
     RESPONSETAINT_BASIC,
     RESPONSETAINT_CORS,
     RESPONSETAINT_OPAQUE,
   };
 
   explicit InternalRequest()
     : mMethod("GET")
     , mHeaders(new InternalHeaders(HeadersGuardEnum::None))
-    , mContextFrameType(FRAMETYPE_NONE)
     , mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR))
     , mMode(RequestMode::No_cors)
     , mCredentialsMode(RequestCredentials::Omit)
     , mResponseTainting(RESPONSETAINT_BASIC)
     , mCacheMode(RequestCache::Default)
     , mAuthenticationFlag(false)
     , mForceOriginHeader(false)
     , mPreserveContentCodings(false)
@@ -76,18 +67,17 @@ public:
   {
   }
 
   explicit InternalRequest(const InternalRequest& aOther)
     : mMethod(aOther.mMethod)
     , mURL(aOther.mURL)
     , mHeaders(aOther.mHeaders)
     , mBodyStream(aOther.mBodyStream)
-    , mContext(aOther.mContext)
-    , mContextFrameType(aOther.mContextFrameType)
+    , mContentPolicyType(aOther.mContentPolicyType)
     , mReferrer(aOther.mReferrer)
     , mMode(aOther.mMode)
     , mCredentialsMode(aOther.mCredentialsMode)
     , mResponseTainting(aOther.mResponseTainting)
     , mCacheMode(aOther.mCacheMode)
     , mAuthenticationFlag(aOther.mAuthenticationFlag)
     , mForceOriginHeader(aOther.mForceOriginHeader)
     , mPreserveContentCodings(aOther.mPreserveContentCodings)
@@ -235,19 +225,19 @@ public:
 
   RequestCache
   GetCacheMode() const
   {
     return mCacheMode;
   }
 
   nsContentPolicyType
-  GetContext() const
+  ContentPolicyType() const
   {
-    return mContext;
+    return mContentPolicyType;
   }
 
   bool
   UnsafeRequest() const
   {
     return mUnsafeRequest;
   }
 
@@ -307,19 +297,17 @@ private:
 
   nsCString mMethod;
   nsCString mURL;
   nsRefPtr<InternalHeaders> mHeaders;
   nsCOMPtr<nsIInputStream> mBodyStream;
 
   // nsContentPolicyType does not cover the complete set defined in the spec,
   // but it is a good start.
-  nsContentPolicyType mContext;
-
-  ContextFrameType mContextFrameType;
+  nsContentPolicyType mContentPolicyType;
 
   // Empty string: no-referrer
   // "about:client": client (default)
   // URL: an URL
   nsString mReferrer;
 
   RequestMode mMode;
   RequestCredentials mCredentialsMode;
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -28,16 +28,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest)
   : FetchBody<Request>()
   , mOwner(aOwner)
   , mRequest(aRequest)
+  , mContext(RequestContext::Fetch)
 {
 }
 
 Request::~Request()
 {
 }
 
 already_AddRefed<InternalRequest>
--- a/dom/fetch/Request.h
+++ b/dom/fetch/Request.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_Request_h
 #define mozilla_dom_Request_h
 
+#include "nsIContentPolicy.h"
 #include "nsISupportsImpl.h"
 #include "nsWrapperCache.h"
 
 #include "mozilla/dom/Fetch.h"
 #include "mozilla/dom/InternalRequest.h"
 // Required here due to certain WebIDL enums/classes being declared in both
 // files.
 #include "mozilla/dom/RequestBinding.h"
@@ -69,16 +70,22 @@ public:
   }
 
   RequestCache
   Cache() const
   {
     return mRequest->GetCacheMode();
   }
 
+  RequestContext
+  Context() const
+  {
+    return mContext;
+  }
+
   void
   GetReferrer(nsAString& aReferrer) const
   {
     mRequest->GetReferrer(aReferrer);
   }
 
   InternalHeaders*
   GetInternalHeaders() const
@@ -107,14 +114,15 @@ public:
   GetInternalRequest();
 private:
   ~Request();
 
   nsCOMPtr<nsIGlobalObject> mOwner;
   nsRefPtr<InternalRequest> mRequest;
   // Lazily created.
   nsRefPtr<Headers> mHeaders;
+  RequestContext mContext;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_Request_h
--- a/dom/webidl/Request.webidl
+++ b/dom/webidl/Request.webidl
@@ -12,17 +12,17 @@ typedef (Request or USVString) RequestIn
 [Constructor(RequestInfo input, optional RequestInit init),
  Exposed=(Window,Worker),
  Func="mozilla::dom::Headers::PrefEnabled"]
 interface Request {
   readonly attribute ByteString method;
   readonly attribute USVString url;
   [SameObject] readonly attribute Headers headers;
 
-  // FIXME(nsm) Bug 1119037: readonly attribute RequestContext context;
+  readonly attribute RequestContext context;
   readonly attribute DOMString referrer;
   readonly attribute RequestMode mode;
   readonly attribute RequestCredentials credentials;
   readonly attribute RequestCache cache;
 
   [NewObject] Request clone();
 };
 Request implements Body;
@@ -31,17 +31,23 @@ dictionary RequestInit {
   ByteString method;
   HeadersInit headers;
   BodyInit body;
   RequestMode mode;
   RequestCredentials credentials;
   RequestCache cache;
 };
 
-// FIXME(nsm): Bug 1119037 Implement RequestContext.
+enum RequestContext {
+  "audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch",
+  "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import",
+  "internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script",
+  "serviceworker", "sharedworker", "subresource", "style", "track", "video", "worker",
+  "xmlhttprequest", "xslt"
+};
 
 // cors-with-forced-preflight is internal to the Fetch spec, but adding it here
 // allows us to use the various conversion conveniences offered by the WebIDL
 // codegen. The Request constructor has explicit checks to prevent it being
 // passed as a valid value, while Request.mode never returns it. Since enums
 // are only exposed as strings to client JS, this has the same effect as not
 // exposing it at all.
 enum RequestMode { "same-origin", "no-cors", "cors", "cors-with-forced-preflight" };
--- a/dom/workers/test/fetch/worker_test_request.js
+++ b/dom/workers/test/fetch/worker_test_request.js
@@ -6,24 +6,26 @@ function is(a, b, msg) {
   postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
 }
 
 function testDefaultCtor() {
   var req = new Request("");
   is(req.method, "GET", "Default Request method is GET");
   ok(req.headers instanceof Headers, "Request should have non-null Headers object");
   is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
+  is(req.context, "fetch", "Default context is fetch.");
   is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
   is(req.mode, "cors", "Request mode for string input is cors");
   is(req.credentials, "omit", "Default Request credentials is omit");
 
   var req = new Request(req);
   is(req.method, "GET", "Default Request method is GET");
   ok(req.headers instanceof Headers, "Request should have non-null Headers object");
   is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
+  is(req.context, "fetch", "Default context is fetch.");
   is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
   is(req.mode, "cors", "Request mode string input is cors");
   is(req.credentials, "omit", "Default Request credentials is omit");
 }
 
 function testClone() {
   var req = (new Request("./cloned_request.txt", {
               method: 'POST',