1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/web_url_request_util.h"
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/platform/WebURLRequest.h"
10 using blink::WebURLRequest
;
14 ResourceType
WebURLRequestToResourceType(const WebURLRequest
& request
) {
15 WebURLRequest::RequestContext requestContext
= request
.requestContext();
16 if (request
.frameType() != WebURLRequest::FrameTypeNone
) {
17 DCHECK(requestContext
== WebURLRequest::RequestContextForm
||
18 requestContext
== WebURLRequest::RequestContextFrame
||
19 requestContext
== WebURLRequest::RequestContextHyperlink
||
20 requestContext
== WebURLRequest::RequestContextIframe
||
21 requestContext
== WebURLRequest::RequestContextInternal
||
22 requestContext
== WebURLRequest::RequestContextLocation
);
23 if (request
.frameType() == WebURLRequest::FrameTypeTopLevel
||
24 request
.frameType() == WebURLRequest::FrameTypeAuxiliary
) {
25 return RESOURCE_TYPE_MAIN_FRAME
;
27 if (request
.frameType() == WebURLRequest::FrameTypeNested
)
28 return RESOURCE_TYPE_SUB_FRAME
;
30 return RESOURCE_TYPE_SUB_RESOURCE
;
33 switch (requestContext
) {
35 case WebURLRequest::RequestContextFavicon
:
36 return RESOURCE_TYPE_FAVICON
;
39 case WebURLRequest::RequestContextFont
:
40 return RESOURCE_TYPE_FONT_RESOURCE
;
43 case WebURLRequest::RequestContextImage
:
44 case WebURLRequest::RequestContextImageSet
:
45 return RESOURCE_TYPE_IMAGE
;
48 case WebURLRequest::RequestContextAudio
:
49 case WebURLRequest::RequestContextVideo
:
50 return RESOURCE_TYPE_MEDIA
;
53 case WebURLRequest::RequestContextEmbed
:
54 case WebURLRequest::RequestContextObject
:
55 return RESOURCE_TYPE_OBJECT
;
58 case WebURLRequest::RequestContextBeacon
:
59 case WebURLRequest::RequestContextCSPReport
:
60 case WebURLRequest::RequestContextPing
:
61 return RESOURCE_TYPE_PING
;
64 case WebURLRequest::RequestContextPrefetch
:
65 return RESOURCE_TYPE_PREFETCH
;
68 case WebURLRequest::RequestContextImport
:
69 case WebURLRequest::RequestContextScript
:
70 return RESOURCE_TYPE_SCRIPT
;
73 case WebURLRequest::RequestContextXSLT
:
74 case WebURLRequest::RequestContextStyle
:
75 return RESOURCE_TYPE_STYLESHEET
;
78 case WebURLRequest::RequestContextDownload
:
79 case WebURLRequest::RequestContextManifest
:
80 case WebURLRequest::RequestContextSubresource
:
81 case WebURLRequest::RequestContextPlugin
:
82 return RESOURCE_TYPE_SUB_RESOURCE
;
85 case WebURLRequest::RequestContextTrack
:
86 return RESOURCE_TYPE_MEDIA
;
89 case WebURLRequest::RequestContextServiceWorker
:
90 return RESOURCE_TYPE_SERVICE_WORKER
;
91 case WebURLRequest::RequestContextSharedWorker
:
92 return RESOURCE_TYPE_SHARED_WORKER
;
93 case WebURLRequest::RequestContextWorker
:
94 return RESOURCE_TYPE_WORKER
;
97 case WebURLRequest::RequestContextInternal
:
98 case WebURLRequest::RequestContextUnspecified
:
99 return RESOURCE_TYPE_SUB_RESOURCE
;
102 case WebURLRequest::RequestContextEventSource
:
103 case WebURLRequest::RequestContextFetch
:
104 case WebURLRequest::RequestContextXMLHttpRequest
:
105 return RESOURCE_TYPE_XHR
;
107 // These should be handled by the FrameType checks at the top of the
109 case WebURLRequest::RequestContextForm
:
110 case WebURLRequest::RequestContextHyperlink
:
111 case WebURLRequest::RequestContextLocation
:
112 case WebURLRequest::RequestContextFrame
:
113 case WebURLRequest::RequestContextIframe
:
115 return RESOURCE_TYPE_SUB_RESOURCE
;
119 return RESOURCE_TYPE_SUB_RESOURCE
;
123 } // namespace content