1 /*
2  * Copyright (C) 2011 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_FETCH_RESOURCE_LOADER_OPTIONS_H_
32 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_FETCH_RESOURCE_LOADER_OPTIONS_H_
33 
34 #include "base/memory/scoped_refptr.h"
35 #include "base/util/type_safety/strong_alias.h"
36 #include "mojo/public/cpp/bindings/pending_remote.h"
37 #include "services/network/public/mojom/content_security_policy.mojom-blink-forward.h"
38 #include "services/network/public/mojom/url_loader_factory.mojom-blink-forward.h"
39 #include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_info.h"
40 #include "third_party/blink/renderer/platform/loader/fetch/integrity_metadata.h"
41 #include "third_party/blink/renderer/platform/platform_export.h"
42 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
43 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
44 
45 namespace blink {
46 
47 enum DataBufferingPolicy : uint8_t { kBufferData, kDoNotBufferData };
48 
49 enum RequestInitiatorContext : uint8_t {
50   kDocumentContext,
51   kWorkerContext,
52 };
53 
54 enum SynchronousPolicy : uint8_t {
55   kRequestSynchronously,
56   kRequestAsynchronously
57 };
58 
59 // Used by the ThreadableLoader to turn off part of the CORS handling
60 // logic in the ResourceFetcher to use its own CORS handling logic.
61 enum CorsHandlingByResourceFetcher {
62   kDisableCorsHandlingByResourceFetcher,
63   kEnableCorsHandlingByResourceFetcher,
64 };
65 
66 // Was the request generated from a "parser-inserted" element?
67 // https://html.spec.whatwg.org/C/#parser-inserted
68 enum ParserDisposition : uint8_t { kParserInserted, kNotParserInserted };
69 
70 enum CacheAwareLoadingEnabled : uint8_t {
71   kNotCacheAwareLoadingEnabled,
72   kIsCacheAwareLoadingEnabled
73 };
74 
75 // https://github.com/WICG/cross-origin-embedder-policy/pull/13
76 // When true, a response is blocked unless it has
77 // cross-origin-embedder-policy: require-corp.
78 using RejectCoepUnsafeNone =
79     util::StrongAlias<class RejectCoepUnsafeNoneTag, bool>;
80 
81 // This class is thread-bound. Do not copy/pass an instance across threads.
82 struct PLATFORM_EXPORT ResourceLoaderOptions {
83   USING_FAST_MALLOC(ResourceLoaderOptions);
84 
85  public:
86   // We define constructors, destructor, and assignment operator in
87   // resource_loader_options.cc because they require the full definition of
88   // URLLoaderFactory for |url_loader_factory| data member, and we'd like
89   // to avoid to include huge url_loader_factory.mojom-blink.h.
90   ResourceLoaderOptions();
91   ResourceLoaderOptions(const ResourceLoaderOptions& other);
92   ResourceLoaderOptions& operator=(const ResourceLoaderOptions& other);
93   ~ResourceLoaderOptions();
94 
95   FetchInitiatorInfo initiator_info;
96 
97   DataBufferingPolicy data_buffering_policy;
98 
99   network::mojom::CSPDisposition content_security_policy_option;
100   RequestInitiatorContext request_initiator_context;
101   SynchronousPolicy synchronous_policy;
102 
103   // When set to kDisableCorsHandlingByResourceFetcher, the ResourceFetcher
104   // suppresses part of its CORS handling logic.
105   // Used by ThreadableLoader which does CORS handling by itself.
106   CorsHandlingByResourceFetcher cors_handling_by_resource_fetcher;
107 
108   // Corresponds to the CORS flag in the Fetch spec.
109   bool cors_flag;
110 
111   // TODO(crbug.com/1064920): Remove this once PlzDedicatedWorker ships.
112   RejectCoepUnsafeNone reject_coep_unsafe_none = RejectCoepUnsafeNone(false);
113 
114   String content_security_policy_nonce;
115   IntegrityMetadataSet integrity_metadata;
116   ParserDisposition parser_disposition;
117   CacheAwareLoadingEnabled cache_aware_loading_enabled;
118 
119   // If not null, this URLLoaderFactory should be used to load this resource
120   // rather than whatever factory the system might otherwise use.
121   // Used for example for loading blob: URLs and for prefetch loading.
122   scoped_refptr<base::RefCountedData<
123       mojo::PendingRemote<network::mojom::blink::URLLoaderFactory>>>
124       url_loader_factory;
125 };
126 
127 }  // namespace blink
128 
129 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_LOADER_FETCH_RESOURCE_LOADER_OPTIONS_H_
130