Use normal loading path for ping loads
[WebKit-https.git] / Source / WebCore / loader / ResourceLoadInfo.cpp
1 /*
2  * Copyright (C) 2015 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ResourceLoadInfo.h"
28
29 #include "ContentExtensionActions.h"
30 #include "SecurityOrigin.h"
31
32 #if ENABLE(CONTENT_EXTENSIONS)
33
34 namespace WebCore {
35 namespace ContentExtensions {
36
37 ResourceType toResourceType(CachedResource::Type type)
38 {
39     switch (type) {
40     case CachedResource::Type::MainResource:
41         return ResourceType::Document;
42     case CachedResource::Type::SVGDocumentResource:
43         return ResourceType::SVGDocument;
44     case CachedResource::Type::ImageResource:
45         return ResourceType::Image;
46     case CachedResource::Type::CSSStyleSheet:
47 #if ENABLE(XSLT)
48     case CachedResource::Type::XSLStyleSheet:
49 #endif
50         return ResourceType::StyleSheet;
51
52     case CachedResource::Type::Script:
53         return ResourceType::Script;
54
55     case CachedResource::Type::FontResource:
56 #if ENABLE(SVG_FONTS)
57     case CachedResource::Type::SVGFontResource:
58 #endif
59         return ResourceType::Font;
60
61     case CachedResource::Type::MediaResource:
62         return ResourceType::Media;
63
64     case CachedResource::Type::Beacon:
65     case CachedResource::Type::Ping:
66     case CachedResource::Type::Icon:
67     case CachedResource::Type::RawResource:
68         return ResourceType::Raw;
69
70 #if ENABLE(VIDEO_TRACK)
71     case CachedResource::Type::TextTrackResource:
72         return ResourceType::Media;
73 #endif
74     case CachedResource::Type::LinkPrefetch:
75         ASSERT_NOT_REACHED();
76         break;
77 #if ENABLE(APPLICATION_MANIFEST)
78     case CachedResource::Type::ApplicationManifest:
79         return ResourceType::Raw;
80 #endif
81     };
82     return ResourceType::Raw;
83 }
84
85 uint16_t readResourceType(const String& name)
86 {
87     if (name == "document")
88         return static_cast<uint16_t>(ResourceType::Document);
89     if (name == "image")
90         return static_cast<uint16_t>(ResourceType::Image);
91     if (name == "style-sheet")
92         return static_cast<uint16_t>(ResourceType::StyleSheet);
93     if (name == "script")
94         return static_cast<uint16_t>(ResourceType::Script);
95     if (name == "font")
96         return static_cast<uint16_t>(ResourceType::Font);
97     if (name == "raw")
98         return static_cast<uint16_t>(ResourceType::Raw);
99     if (name == "svg-document")
100         return static_cast<uint16_t>(ResourceType::SVGDocument);
101     if (name == "media")
102         return static_cast<uint16_t>(ResourceType::Media);
103     if (name == "popup")
104         return static_cast<uint16_t>(ResourceType::Popup);
105     return static_cast<uint16_t>(ResourceType::Invalid);
106 }
107
108 uint16_t readLoadType(const String& name)
109 {
110     if (name == "first-party")
111         return static_cast<uint16_t>(LoadType::FirstParty);
112     if (name == "third-party")
113         return static_cast<uint16_t>(LoadType::ThirdParty);
114     return static_cast<uint16_t>(LoadType::Invalid);
115 }
116
117 bool ResourceLoadInfo::isThirdParty() const
118 {
119     Ref<SecurityOrigin> mainDocumentSecurityOrigin = SecurityOrigin::create(mainDocumentURL);
120     Ref<SecurityOrigin> resourceSecurityOrigin = SecurityOrigin::create(resourceURL);
121
122     return !mainDocumentSecurityOrigin->canAccess(resourceSecurityOrigin.get());
123 }
124     
125 ResourceFlags ResourceLoadInfo::getResourceFlags() const
126 {
127     ResourceFlags flags = 0;
128     ASSERT(type != ResourceType::Invalid);
129     flags |= static_cast<ResourceFlags>(type);
130     flags |= isThirdParty() ? static_cast<ResourceFlags>(LoadType::ThirdParty) : static_cast<ResourceFlags>(LoadType::FirstParty);
131     return flags;
132 }
133
134 } // namespace ContentExtensions
135 } // namespace WebCore
136
137 #endif // ENABLE(CONTENT_EXTENSIONS)