react-native-windows 0.71.24 → 0.71.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Directory.Build.props +5 -0
- package/Libraries/Network/RCTNetworking.windows.js +10 -16
- package/Microsoft.ReactNative/IReactDispatcher.cpp +4 -0
- package/Microsoft.ReactNative/IReactDispatcher.h +1 -0
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +3 -7
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +0 -7
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +43 -21
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +0 -2
- package/Microsoft.ReactNative/Views/DevMenu.cpp +3 -3
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +16 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +43 -12
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +17 -6
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.WinAppSDK.CSharpApp.targets +1 -1
- package/PropertySheets/Generated/PackageVersion.g.props +3 -3
- package/PropertySheets/JSEngine.props +4 -4
- package/PropertySheets/React.Cpp.props +3 -3
- package/PropertySheets/Warnings.props +6 -0
- package/ReactCommon/ReactCommon.vcxproj +53 -1
- package/ReactCommon/cgmanifest.json +15 -0
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +36 -0
- package/Shared/BaseFileReaderResource.cpp +95 -0
- package/Shared/BaseFileReaderResource.h +41 -0
- package/Shared/CreateModules.h +27 -5
- package/Shared/DevSupportManager.cpp +2 -9
- package/Shared/DevSupportManager.h +2 -6
- package/Shared/HermesRuntimeHolder.cpp +344 -84
- package/Shared/HermesRuntimeHolder.h +32 -21
- package/Shared/HermesSamplingProfiler.cpp +66 -14
- package/Shared/HermesSamplingProfiler.h +5 -3
- package/Shared/IFileReaderResource.h +36 -0
- package/Shared/InspectorPackagerConnection.cpp +62 -108
- package/Shared/InspectorPackagerConnection.h +9 -21
- package/Shared/JSI/RuntimeHolder.h +2 -2
- package/Shared/JSI/ScriptStore.h +18 -20
- package/Shared/JSI/V8RuntimeHolder.cpp +260 -0
- package/Shared/JSI/V8RuntimeHolder.h +37 -0
- package/Shared/Modules/BlobModule.cpp +93 -298
- package/Shared/Modules/BlobModule.h +25 -91
- package/Shared/Modules/CxxModuleUtilities.cpp +32 -0
- package/Shared/Modules/CxxModuleUtilities.h +17 -0
- package/Shared/Modules/FileReaderModule.cpp +118 -51
- package/Shared/Modules/FileReaderModule.h +27 -1
- package/Shared/Modules/HttpModule.cpp +133 -9
- package/Shared/Modules/HttpModule.h +33 -0
- package/Shared/Modules/IRequestBodyHandler.h +6 -4
- package/Shared/Modules/IResponseHandler.h +3 -3
- package/Shared/Modules/IUriHandler.h +3 -3
- package/Shared/Modules/IWebSocketModuleContentHandler.h +6 -4
- package/Shared/Modules/WebSocketModule.cpp +190 -7
- package/Shared/Modules/WebSocketTurboModule.h +52 -0
- package/Shared/Networking/DefaultBlobResource.cpp +323 -0
- package/Shared/Networking/DefaultBlobResource.h +133 -0
- package/Shared/Networking/IBlobResource.h +56 -0
- package/Shared/Networking/IHttpResource.h +6 -5
- package/Shared/Networking/WinRTHttpResource.cpp +40 -32
- package/Shared/Networking/WinRTHttpResource.h +4 -3
- package/Shared/Networking/WinRTTypes.h +3 -3
- package/Shared/OInstance.cpp +17 -33
- package/Shared/SafeLoadLibrary.cpp +41 -0
- package/Shared/SafeLoadLibrary.h +15 -0
- package/Shared/Shared.vcxitems +27 -9
- package/Shared/Shared.vcxitems.filters +47 -33
- package/package.json +2 -2
- package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
- package/Microsoft.ReactNative/Base/CoreNativeModules.cpp +0 -59
- package/Microsoft.ReactNative/Base/CoreNativeModules.h +0 -30
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +0 -2103
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +0 -73
- package/Shared/HermesShim.cpp +0 -118
- package/Shared/HermesShim.h +0 -21
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +0 -209
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +0 -44
- package/Shared/V8JSIRuntimeHolder.cpp +0 -70
- package/Shared/V8JSIRuntimeHolder.h +0 -53
- /package/Shared/{Modules/IBlobPersistor.h → IBlobPersistor.h} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "IBlobResource.h"
|
|
7
|
+
|
|
8
|
+
#include <IBlobPersistor.h>
|
|
9
|
+
#include <Modules/IRequestBodyHandler.h>
|
|
10
|
+
#include <Modules/IResponseHandler.h>
|
|
11
|
+
#include <Modules/IWebSocketModuleContentHandler.h>
|
|
12
|
+
|
|
13
|
+
// React Native Windows
|
|
14
|
+
#include <ReactPropertyBag.h>
|
|
15
|
+
|
|
16
|
+
// Boost Libraries
|
|
17
|
+
#include <boost/uuid/uuid_generators.hpp>
|
|
18
|
+
|
|
19
|
+
// Standard Library
|
|
20
|
+
#include <mutex>
|
|
21
|
+
#include <unordered_set>
|
|
22
|
+
|
|
23
|
+
namespace Microsoft::React::Networking {
|
|
24
|
+
|
|
25
|
+
class MemoryBlobPersistor final : public IBlobPersistor {
|
|
26
|
+
std::unordered_map<std::string, std::vector<uint8_t>> m_blobs;
|
|
27
|
+
std::mutex m_mutex;
|
|
28
|
+
boost::uuids::random_generator m_guidGenerator;
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
#pragma region IBlobPersistor
|
|
32
|
+
|
|
33
|
+
winrt::array_view<uint8_t const> ResolveMessage(std::string &&blobId, int64_t offset, int64_t size) override;
|
|
34
|
+
|
|
35
|
+
void RemoveMessage(std::string &&blobId) noexcept override;
|
|
36
|
+
|
|
37
|
+
void StoreMessage(std::vector<uint8_t> &&message, std::string &&blobId) noexcept override;
|
|
38
|
+
|
|
39
|
+
std::string StoreMessage(std::vector<uint8_t> &&message) noexcept override;
|
|
40
|
+
|
|
41
|
+
#pragma endregion IBlobPersistor
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
class BlobWebSocketModuleContentHandler final : public IWebSocketModuleContentHandler {
|
|
45
|
+
std::unordered_set<int64_t> m_socketIds;
|
|
46
|
+
std::mutex m_mutex;
|
|
47
|
+
std::shared_ptr<IBlobPersistor> m_blobPersistor;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
BlobWebSocketModuleContentHandler(std::shared_ptr<IBlobPersistor> blobPersistor) noexcept;
|
|
51
|
+
|
|
52
|
+
#pragma region IWebSocketModuleContentHandler
|
|
53
|
+
|
|
54
|
+
void ProcessMessage(std::string &&message, winrt::Microsoft::ReactNative::JSValueObject ¶ms) noexcept override;
|
|
55
|
+
|
|
56
|
+
void ProcessMessage(std::vector<uint8_t> &&message, winrt::Microsoft::ReactNative::JSValueObject ¶ms) noexcept
|
|
57
|
+
override;
|
|
58
|
+
|
|
59
|
+
#pragma endregion IWebSocketModuleContentHandler
|
|
60
|
+
|
|
61
|
+
void Register(int64_t socketID) noexcept;
|
|
62
|
+
|
|
63
|
+
void Unregister(int64_t socketID) noexcept;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
class BlobModuleRequestBodyHandler final : public IRequestBodyHandler {
|
|
67
|
+
std::shared_ptr<IBlobPersistor> m_blobPersistor;
|
|
68
|
+
|
|
69
|
+
public:
|
|
70
|
+
BlobModuleRequestBodyHandler(std::shared_ptr<IBlobPersistor> blobPersistor) noexcept;
|
|
71
|
+
|
|
72
|
+
#pragma region IRequestBodyHandler
|
|
73
|
+
|
|
74
|
+
bool Supports(winrt::Microsoft::ReactNative::JSValueObject &data) override;
|
|
75
|
+
|
|
76
|
+
winrt::Microsoft::ReactNative::JSValueObject ToRequestBody(
|
|
77
|
+
winrt::Microsoft::ReactNative::JSValueObject &data,
|
|
78
|
+
std::string &contentType) override;
|
|
79
|
+
|
|
80
|
+
#pragma endregion IRequestBodyHandler
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
class BlobModuleResponseHandler final : public IResponseHandler {
|
|
84
|
+
std::shared_ptr<IBlobPersistor> m_blobPersistor;
|
|
85
|
+
|
|
86
|
+
public:
|
|
87
|
+
BlobModuleResponseHandler(std::shared_ptr<IBlobPersistor> blobPersistor) noexcept;
|
|
88
|
+
|
|
89
|
+
#pragma region IResponseHandler
|
|
90
|
+
|
|
91
|
+
bool Supports(std::string &responseType) override;
|
|
92
|
+
|
|
93
|
+
winrt::Microsoft::ReactNative::JSValueObject ToResponseData(std::vector<uint8_t> &&content) override;
|
|
94
|
+
|
|
95
|
+
#pragma endregion IResponseHandler
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
class DefaultBlobResource : public IBlobResource, public std::enable_shared_from_this<DefaultBlobResource> {
|
|
99
|
+
std::shared_ptr<MemoryBlobPersistor> m_blobPersistor;
|
|
100
|
+
std::shared_ptr<BlobWebSocketModuleContentHandler> m_contentHandler;
|
|
101
|
+
std::shared_ptr<BlobModuleRequestBodyHandler> m_requestBodyHandler;
|
|
102
|
+
std::shared_ptr<BlobModuleResponseHandler> m_responseHandler;
|
|
103
|
+
winrt::Microsoft::ReactNative::ReactPropertyBag m_propertyBag;
|
|
104
|
+
BlobCallbacks m_callbacks;
|
|
105
|
+
|
|
106
|
+
public:
|
|
107
|
+
DefaultBlobResource(
|
|
108
|
+
std::shared_ptr<MemoryBlobPersistor> blobPersistor,
|
|
109
|
+
std::shared_ptr<BlobWebSocketModuleContentHandler> contentHandler,
|
|
110
|
+
std::shared_ptr<BlobModuleRequestBodyHandler> requestBodyHandler,
|
|
111
|
+
std::shared_ptr<BlobModuleResponseHandler> responseHandler,
|
|
112
|
+
winrt::Microsoft::ReactNative::ReactPropertyBag propertyBag);
|
|
113
|
+
|
|
114
|
+
#pragma region IBlobResource
|
|
115
|
+
|
|
116
|
+
void SendOverSocket(std::string &&blobId, int64_t offset, int64_t size, int64_t socketId) noexcept override;
|
|
117
|
+
|
|
118
|
+
void CreateFromParts(winrt::Microsoft::ReactNative::JSValueArray &&parts, std::string &&blobId) noexcept override;
|
|
119
|
+
|
|
120
|
+
void Release(std::string &&blobId) noexcept override;
|
|
121
|
+
|
|
122
|
+
void AddNetworkingHandler() noexcept override;
|
|
123
|
+
|
|
124
|
+
void AddWebSocketHandler(int64_t id) noexcept override;
|
|
125
|
+
|
|
126
|
+
void RemoveWebSocketHandler(int64_t id) noexcept override;
|
|
127
|
+
|
|
128
|
+
BlobCallbacks &Callbacks() noexcept override;
|
|
129
|
+
|
|
130
|
+
#pragma endregion IBlobResource
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
} // namespace Microsoft::React::Networking
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <IBlobPersistor.h>
|
|
7
|
+
|
|
8
|
+
// React Native Windows
|
|
9
|
+
#include <JSValue.h>
|
|
10
|
+
|
|
11
|
+
// Windows API
|
|
12
|
+
#include <winrt/Windows.Foundation.h>
|
|
13
|
+
|
|
14
|
+
// Standard Library
|
|
15
|
+
#include <functional>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <string>
|
|
18
|
+
|
|
19
|
+
namespace Microsoft::React::Networking {
|
|
20
|
+
|
|
21
|
+
struct IBlobResource {
|
|
22
|
+
struct BlobCallbacks {
|
|
23
|
+
std::function<void(std::string &&errorText)> OnError;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
struct BlobFieldNames {
|
|
27
|
+
const char *Blob;
|
|
28
|
+
const char *BlobId;
|
|
29
|
+
const char *Offset;
|
|
30
|
+
const char *Size;
|
|
31
|
+
const char *Type;
|
|
32
|
+
const char *Data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static std::shared_ptr<IBlobResource> Make(winrt::Windows::Foundation::IInspectable const &inspectableProperties);
|
|
36
|
+
|
|
37
|
+
static const BlobFieldNames &FieldNames() noexcept;
|
|
38
|
+
|
|
39
|
+
virtual ~IBlobResource() noexcept {}
|
|
40
|
+
|
|
41
|
+
virtual void SendOverSocket(std::string &&blobId, int64_t offset, int64_t size, int64_t socketId) noexcept = 0;
|
|
42
|
+
|
|
43
|
+
virtual void CreateFromParts(winrt::Microsoft::ReactNative::JSValueArray &&parts, std::string &&blobId) noexcept = 0;
|
|
44
|
+
|
|
45
|
+
virtual void Release(std::string &&blobId) noexcept = 0;
|
|
46
|
+
|
|
47
|
+
virtual void AddNetworkingHandler() noexcept = 0;
|
|
48
|
+
|
|
49
|
+
virtual void AddWebSocketHandler(int64_t id) noexcept = 0;
|
|
50
|
+
|
|
51
|
+
virtual void RemoveWebSocketHandler(int64_t id) noexcept = 0;
|
|
52
|
+
|
|
53
|
+
virtual BlobCallbacks &Callbacks() noexcept = 0;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
} // namespace Microsoft::React::Networking
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
#include <
|
|
6
|
+
// React Native Windows
|
|
7
|
+
#include <JSValue.h>
|
|
8
8
|
|
|
9
9
|
// Windows API
|
|
10
10
|
#include <winrt/Windows.Foundation.h>
|
|
@@ -20,7 +20,6 @@ namespace Microsoft::React::Networking {
|
|
|
20
20
|
struct IHttpResource {
|
|
21
21
|
typedef std::unordered_map<std::string, std::string> Headers;
|
|
22
22
|
|
|
23
|
-
// TODO: Implement Form data
|
|
24
23
|
struct BodyData {
|
|
25
24
|
enum class Type : size_t { Empty, String, Base64, Uri, Form } Type = Type::Empty;
|
|
26
25
|
std::string Data;
|
|
@@ -81,7 +80,7 @@ struct IHttpResource {
|
|
|
81
80
|
std::string &&url,
|
|
82
81
|
int64_t requestId,
|
|
83
82
|
Headers &&headers,
|
|
84
|
-
|
|
83
|
+
winrt::Microsoft::ReactNative::JSValueObject &&data,
|
|
85
84
|
std::string &&responseType,
|
|
86
85
|
bool useIncrementalUpdates,
|
|
87
86
|
int64_t timeout,
|
|
@@ -146,7 +145,9 @@ struct IHttpResource {
|
|
|
146
145
|
/// Structured response content payload (i.e. Blob data)
|
|
147
146
|
/// </param>
|
|
148
147
|
/// </param>
|
|
149
|
-
virtual void SetOnData(
|
|
148
|
+
virtual void SetOnData(
|
|
149
|
+
std::function<void(int64_t requestId, winrt::Microsoft::ReactNative::JSValueObject &&responseData)>
|
|
150
|
+
&&handler) noexcept = 0;
|
|
150
151
|
|
|
151
152
|
/// <summary>
|
|
152
153
|
/// Sets a function to be invoked when a response content increment has been received.
|
|
@@ -23,8 +23,6 @@
|
|
|
23
23
|
#include <winrt/Windows.Storage.Streams.h>
|
|
24
24
|
#include <winrt/Windows.Web.Http.Headers.h>
|
|
25
25
|
|
|
26
|
-
using folly::dynamic;
|
|
27
|
-
|
|
28
26
|
using std::function;
|
|
29
27
|
using std::scoped_lock;
|
|
30
28
|
using std::shared_ptr;
|
|
@@ -35,6 +33,7 @@ using std::weak_ptr;
|
|
|
35
33
|
using winrt::fire_and_forget;
|
|
36
34
|
using winrt::hresult_error;
|
|
37
35
|
using winrt::to_hstring;
|
|
36
|
+
using winrt::Microsoft::ReactNative::JSValueObject;
|
|
38
37
|
using winrt::Windows::Foundation::IAsyncOperation;
|
|
39
38
|
using winrt::Windows::Foundation::IInspectable;
|
|
40
39
|
using winrt::Windows::Foundation::Uri;
|
|
@@ -69,15 +68,15 @@ constexpr char responseTypeBlob[] = "blob";
|
|
|
69
68
|
namespace Microsoft::React::Networking {
|
|
70
69
|
|
|
71
70
|
// May throw winrt::hresult_error
|
|
72
|
-
void AttachMultipartHeaders(IHttpContent content, const
|
|
71
|
+
void AttachMultipartHeaders(IHttpContent content, const JSValueObject &headers) {
|
|
73
72
|
HttpMediaTypeHeaderValue contentType{nullptr};
|
|
74
73
|
|
|
75
74
|
// Headers are generally case-insensitive
|
|
76
75
|
// https://www.ietf.org/rfc/rfc2616.txt section 4.2
|
|
77
76
|
// TODO: Consolidate with PerformRequest's header parsing.
|
|
78
|
-
for (auto &header : headers
|
|
79
|
-
auto &name = header.first
|
|
80
|
-
auto
|
|
77
|
+
for (auto &header : headers) {
|
|
78
|
+
auto &name = header.first;
|
|
79
|
+
auto value = header.second.AsString();
|
|
81
80
|
|
|
82
81
|
if (boost::iequals(name.c_str(), "Content-Type")) {
|
|
83
82
|
contentType = HttpMediaTypeHeaderValue::Parse(to_hstring(value));
|
|
@@ -147,6 +146,14 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
|
|
|
147
146
|
}
|
|
148
147
|
co_return nullptr;
|
|
149
148
|
}
|
|
149
|
+
} else if (boost::iequals(name.c_str(), "User-Agent")) {
|
|
150
|
+
bool success = request.Headers().TryAppendWithoutValidation(to_hstring(name), to_hstring(value));
|
|
151
|
+
if (!success) {
|
|
152
|
+
if (self->m_onError) {
|
|
153
|
+
self->m_onError(reqArgs->RequestId, "Failed to append User-Agent", false);
|
|
154
|
+
}
|
|
155
|
+
co_return nullptr;
|
|
156
|
+
}
|
|
150
157
|
} else {
|
|
151
158
|
try {
|
|
152
159
|
request.Headers().Append(to_hstring(name), to_hstring(value));
|
|
@@ -162,11 +169,11 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
|
|
|
162
169
|
// Initialize content
|
|
163
170
|
IHttpContent content{nullptr};
|
|
164
171
|
auto &data = reqArgs->Data;
|
|
165
|
-
if (!data.
|
|
172
|
+
if (!data.empty()) {
|
|
166
173
|
auto bodyHandler = self->m_requestBodyHandler.lock();
|
|
167
174
|
if (bodyHandler && bodyHandler->Supports(data)) {
|
|
168
175
|
auto contentTypeString = contentType ? winrt::to_string(contentType.ToString()) : "";
|
|
169
|
-
|
|
176
|
+
JSValueObject blob;
|
|
170
177
|
try {
|
|
171
178
|
blob = bodyHandler->ToRequestBody(data, contentTypeString);
|
|
172
179
|
} catch (const std::invalid_argument &e) {
|
|
@@ -175,44 +182,45 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
|
|
|
175
182
|
}
|
|
176
183
|
co_return nullptr;
|
|
177
184
|
}
|
|
178
|
-
auto bytes = blob["bytes"];
|
|
185
|
+
auto &bytes = blob["bytes"].AsArray();
|
|
179
186
|
auto byteVector = vector<uint8_t>(bytes.size());
|
|
180
187
|
for (auto &byte : bytes) {
|
|
181
|
-
byteVector.push_back(static_cast<uint8_t>(byte.
|
|
188
|
+
byteVector.push_back(static_cast<uint8_t>(byte.AsUInt8()));
|
|
182
189
|
}
|
|
183
190
|
auto view = winrt::array_view<uint8_t const>{byteVector};
|
|
184
191
|
auto buffer = CryptographicBuffer::CreateFromByteArray(view);
|
|
185
192
|
content = HttpBufferContent{std::move(buffer)};
|
|
186
|
-
} else if (
|
|
187
|
-
content = HttpStringContent{to_hstring(data["string"].
|
|
188
|
-
} else if (
|
|
189
|
-
auto buffer = CryptographicBuffer::DecodeFromBase64String(to_hstring(data["base64"].
|
|
193
|
+
} else if (data.find("string") != data.cend()) {
|
|
194
|
+
content = HttpStringContent{to_hstring(data["string"].AsString())};
|
|
195
|
+
} else if (data.find("base64") != data.cend()) {
|
|
196
|
+
auto buffer = CryptographicBuffer::DecodeFromBase64String(to_hstring(data["base64"].AsString()));
|
|
190
197
|
content = HttpBufferContent{std::move(buffer)};
|
|
191
|
-
} else if (
|
|
192
|
-
auto file = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{to_hstring(data["uri"].
|
|
198
|
+
} else if (data.find("uri") != data.cend()) {
|
|
199
|
+
auto file = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{to_hstring(data["uri"].AsString())});
|
|
193
200
|
auto stream = co_await file.OpenReadAsync();
|
|
194
201
|
content = HttpStreamContent{std::move(stream)};
|
|
195
|
-
} else if (
|
|
202
|
+
} else if (data.find("formData") != data.cend()) {
|
|
196
203
|
winrt::Windows::Web::Http::HttpMultipartFormDataContent multiPartContent;
|
|
197
|
-
auto formData = data["formData"];
|
|
204
|
+
auto &formData = data["formData"].AsObject();
|
|
198
205
|
|
|
199
206
|
// #6046 - Overwriting WinRT's HttpMultipartFormDataContent implicit Content-Type clears the generated boundary
|
|
200
207
|
contentType = nullptr;
|
|
201
208
|
|
|
202
209
|
for (auto &formDataPart : formData) {
|
|
203
210
|
IHttpContent formContent{nullptr};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
211
|
+
auto &itr = formDataPart.second["string"];
|
|
212
|
+
if (!formDataPart.second["string"].IsNull()) {
|
|
213
|
+
formContent = HttpStringContent{to_hstring(formDataPart.second["string"].AsString())};
|
|
214
|
+
} else if (!formDataPart.second["uri"].IsNull()) {
|
|
215
|
+
auto filePath = to_hstring(formDataPart.second["uri"].AsString());
|
|
208
216
|
auto file = co_await StorageFile::GetFileFromPathAsync(filePath);
|
|
209
217
|
auto stream = co_await file.OpenReadAsync();
|
|
210
218
|
formContent = HttpStreamContent{stream};
|
|
211
219
|
}
|
|
212
220
|
|
|
213
221
|
if (formContent) {
|
|
214
|
-
AttachMultipartHeaders(formContent, formDataPart["headers"]);
|
|
215
|
-
multiPartContent.Add(formContent, to_hstring(formDataPart["fieldName"].
|
|
222
|
+
AttachMultipartHeaders(formContent, formDataPart.second["headers"].AsObject());
|
|
223
|
+
multiPartContent.Add(formContent, to_hstring(formDataPart.second["fieldName"].AsString()));
|
|
216
224
|
}
|
|
217
225
|
} // foreach form data part
|
|
218
226
|
|
|
@@ -266,7 +274,7 @@ void WinRTHttpResource::SendRequest(
|
|
|
266
274
|
string &&url,
|
|
267
275
|
int64_t requestId,
|
|
268
276
|
Headers &&headers,
|
|
269
|
-
|
|
277
|
+
JSValueObject &&data,
|
|
270
278
|
string &&responseType,
|
|
271
279
|
bool useIncrementalUpdates,
|
|
272
280
|
int64_t timeout,
|
|
@@ -345,10 +353,10 @@ void WinRTHttpResource::SetOnData(function<void(int64_t requestId, string &&resp
|
|
|
345
353
|
m_onData = std::move(handler);
|
|
346
354
|
}
|
|
347
355
|
|
|
348
|
-
void WinRTHttpResource::SetOnData(function<void(int64_t requestId,
|
|
356
|
+
void WinRTHttpResource::SetOnData(function<void(int64_t requestId, JSValueObject &&responseData)> &&handler) noexcept
|
|
349
357
|
/*override*/
|
|
350
358
|
{
|
|
351
|
-
|
|
359
|
+
m_onDataObject = std::move(handler);
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
void WinRTHttpResource::SetOnIncrementalData(
|
|
@@ -397,7 +405,7 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
|
|
|
397
405
|
// Ensure background thread
|
|
398
406
|
co_await winrt::resume_background();
|
|
399
407
|
|
|
400
|
-
auto props = winrt::
|
|
408
|
+
auto props = winrt::single_threaded_map<winrt::hstring, IInspectable>();
|
|
401
409
|
props.Insert(L"RequestArgs", coArgs);
|
|
402
410
|
|
|
403
411
|
auto coRequestOp = CreateRequest(std::move(coMethod), std::move(coUri), props);
|
|
@@ -418,8 +426,8 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
|
|
|
418
426
|
try {
|
|
419
427
|
if (uriHandler->Supports(uri, reqArgs->ResponseType)) {
|
|
420
428
|
auto blob = uriHandler->Fetch(uri);
|
|
421
|
-
if (self->
|
|
422
|
-
self->
|
|
429
|
+
if (self->m_onDataObject && self->m_onRequestSuccess) {
|
|
430
|
+
self->m_onDataObject(reqArgs->RequestId, std::move(blob));
|
|
423
431
|
self->m_onRequestSuccess(reqArgs->RequestId);
|
|
424
432
|
}
|
|
425
433
|
|
|
@@ -528,8 +536,8 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
|
|
|
528
536
|
|
|
529
537
|
auto blob = responseHandler->ToResponseData(std::move(responseData));
|
|
530
538
|
|
|
531
|
-
if (self->
|
|
532
|
-
self->
|
|
539
|
+
if (self->m_onDataObject && self->m_onRequestSuccess) {
|
|
540
|
+
self->m_onDataObject(reqArgs->RequestId, std::move(blob));
|
|
533
541
|
self->m_onRequestSuccess(reqArgs->RequestId);
|
|
534
542
|
}
|
|
535
543
|
|
|
@@ -28,7 +28,7 @@ class WinRTHttpResource : public IHttpResource,
|
|
|
28
28
|
std::function<void(int64_t requestId)> m_onRequestSuccess;
|
|
29
29
|
std::function<void(int64_t requestId, Response &&response)> m_onResponse;
|
|
30
30
|
std::function<void(int64_t requestId, std::string &&responseData)> m_onData;
|
|
31
|
-
std::function<void(int64_t requestId,
|
|
31
|
+
std::function<void(int64_t requestId, winrt::Microsoft::ReactNative::JSValueObject &&responseData)> m_onDataObject;
|
|
32
32
|
std::function<void(int64_t requestId, std::string &&errorMessage, bool isTimeout)> m_onError;
|
|
33
33
|
std::function<void(int64_t requestId, std::string &&responseData, int64_t progress, int64_t total)>
|
|
34
34
|
m_onIncrementalData;
|
|
@@ -71,7 +71,7 @@ class WinRTHttpResource : public IHttpResource,
|
|
|
71
71
|
std::string &&url,
|
|
72
72
|
int64_t requestId,
|
|
73
73
|
Headers &&headers,
|
|
74
|
-
|
|
74
|
+
winrt::Microsoft::ReactNative::JSValueObject &&data,
|
|
75
75
|
std::string &&responseType,
|
|
76
76
|
bool useIncrementalUpdates,
|
|
77
77
|
int64_t timeout,
|
|
@@ -83,7 +83,8 @@ class WinRTHttpResource : public IHttpResource,
|
|
|
83
83
|
void SetOnRequestSuccess(std::function<void(int64_t requestId)> &&handler) noexcept override;
|
|
84
84
|
void SetOnResponse(std::function<void(int64_t requestId, Response &&response)> &&handler) noexcept override;
|
|
85
85
|
void SetOnData(std::function<void(int64_t requestId, std::string &&responseData)> &&handler) noexcept override;
|
|
86
|
-
void SetOnData(std::function<void(int64_t requestId,
|
|
86
|
+
void SetOnData(std::function<void(int64_t requestId, winrt::Microsoft::ReactNative::JSValueObject &&responseData)>
|
|
87
|
+
&&handler) noexcept override;
|
|
87
88
|
void SetOnIncrementalData(
|
|
88
89
|
std::function<void(int64_t requestId, std::string &&responseData, int64_t progress, int64_t total)>
|
|
89
90
|
&&handler) noexcept override;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
#include "IHttpResource.h"
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
#include <
|
|
8
|
+
// React Native Windows
|
|
9
|
+
#include <JSValue.h>
|
|
10
10
|
|
|
11
11
|
// Windows API
|
|
12
12
|
#include <winrt/Windows.Web.Http.h>
|
|
@@ -19,7 +19,7 @@ namespace Microsoft::React::Networking {
|
|
|
19
19
|
struct RequestArgs : public winrt::implements<RequestArgs, winrt::Windows::Foundation::IInspectable> {
|
|
20
20
|
int64_t RequestId;
|
|
21
21
|
IHttpResource::Headers Headers;
|
|
22
|
-
|
|
22
|
+
winrt::Microsoft::ReactNative::JSValueObject Data;
|
|
23
23
|
bool IncrementalUpdates;
|
|
24
24
|
bool WithCredentials;
|
|
25
25
|
std::string ResponseType;
|
package/Shared/OInstance.cpp
CHANGED
|
@@ -52,13 +52,11 @@
|
|
|
52
52
|
#include "HermesRuntimeHolder.h"
|
|
53
53
|
|
|
54
54
|
#if defined(USE_V8)
|
|
55
|
-
#include <JSI/
|
|
56
|
-
|
|
57
|
-
#include "BaseScriptStoreImpl.h"
|
|
58
|
-
#include "V8JSIRuntimeHolder.h"
|
|
55
|
+
#include <JSI/V8RuntimeHolder.h>
|
|
59
56
|
#endif
|
|
60
57
|
#include <ReactCommon/CallInvoker.h>
|
|
61
58
|
#include <ReactCommon/TurboModuleBinding.h>
|
|
59
|
+
#include "BaseScriptStoreImpl.h"
|
|
62
60
|
#include "ChakraRuntimeHolder.h"
|
|
63
61
|
|
|
64
62
|
#include <tracing/tracing.h>
|
|
@@ -318,46 +316,32 @@ InstanceImpl::InstanceImpl(
|
|
|
318
316
|
} else {
|
|
319
317
|
assert(m_devSettings->jsiEngineOverride != JSIEngineOverride::Default);
|
|
320
318
|
switch (m_devSettings->jsiEngineOverride) {
|
|
321
|
-
case JSIEngineOverride::Hermes:
|
|
322
|
-
|
|
323
|
-
break;
|
|
324
|
-
case JSIEngineOverride::V8: {
|
|
325
|
-
#if defined(USE_V8)
|
|
326
|
-
std::unique_ptr<facebook::jsi::ScriptStore> scriptStore = nullptr;
|
|
327
|
-
std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore = nullptr;
|
|
319
|
+
case JSIEngineOverride::Hermes: {
|
|
320
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore;
|
|
328
321
|
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
preparedScriptStore =
|
|
322
|
+
wchar_t tempPath[MAX_PATH];
|
|
323
|
+
if (GetTempPathW(MAX_PATH, tempPath)) {
|
|
324
|
+
preparedScriptStore =
|
|
325
|
+
std::make_shared<facebook::react::BasePreparedScriptStoreImpl>(winrt::to_string(tempPath));
|
|
332
326
|
}
|
|
333
327
|
|
|
334
|
-
m_devSettings->jsiRuntimeHolder = std::make_shared<
|
|
335
|
-
m_devSettings, m_jsThread, std::move(
|
|
328
|
+
m_devSettings->jsiRuntimeHolder = std::make_shared<Microsoft::ReactNative::HermesRuntimeHolder>(
|
|
329
|
+
m_devSettings, m_jsThread, std::move(preparedScriptStore));
|
|
336
330
|
break;
|
|
337
|
-
#else
|
|
338
|
-
assert(false); // V8 is not available in this build, fallthrough
|
|
339
|
-
[[fallthrough]];
|
|
340
|
-
#endif
|
|
341
331
|
}
|
|
332
|
+
case JSIEngineOverride::V8:
|
|
342
333
|
case JSIEngineOverride::V8NodeApi: {
|
|
343
334
|
#if defined(USE_V8)
|
|
344
|
-
std::
|
|
335
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore;
|
|
345
336
|
|
|
346
337
|
wchar_t tempPath[MAX_PATH];
|
|
347
|
-
if (GetTempPathW(
|
|
338
|
+
if (GetTempPathW(MAX_PATH, tempPath)) {
|
|
348
339
|
preparedScriptStore =
|
|
349
|
-
std::
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (!preparedScriptStore) {
|
|
353
|
-
if (m_devSettings->errorCallback)
|
|
354
|
-
m_devSettings->errorCallback("Could not initialize prepared script store");
|
|
355
|
-
|
|
356
|
-
break;
|
|
340
|
+
std::make_shared<facebook::react::BasePreparedScriptStoreImpl>(winrt::to_string(tempPath));
|
|
357
341
|
}
|
|
358
342
|
|
|
359
|
-
m_devSettings->jsiRuntimeHolder = make_shared<
|
|
360
|
-
m_devSettings, m_jsThread,
|
|
343
|
+
m_devSettings->jsiRuntimeHolder = make_shared<Microsoft::ReactNative::V8RuntimeHolder>(
|
|
344
|
+
m_devSettings, m_jsThread, std::move(preparedScriptStore), false);
|
|
361
345
|
break;
|
|
362
346
|
#else
|
|
363
347
|
if (m_devSettings->errorCallback)
|
|
@@ -637,7 +621,7 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
|
|
|
637
621
|
nativeQueue));
|
|
638
622
|
|
|
639
623
|
// These modules are instantiated separately in MSRN (Universal Windows).
|
|
640
|
-
// When there are module name
|
|
624
|
+
// When there are module name collisions, the last one registered is used.
|
|
641
625
|
// If this code is enabled, we will have unused module instances.
|
|
642
626
|
// Also, MSRN has a different property bag mechanism incompatible with this method's transitionalProps variable.
|
|
643
627
|
#if (defined(_MSC_VER) && !defined(WINRT))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#include "SafeLoadLibrary.h"
|
|
5
|
+
|
|
6
|
+
namespace Microsoft::ReactNative {
|
|
7
|
+
|
|
8
|
+
// Unsafe calls to LoadLibrary/LoadLibraryEx.
|
|
9
|
+
// The default behavior of LoadLibrary, or LoadLibraryEx without flags, is to try and find the dependency by iterating
|
|
10
|
+
// through a search order. This search order contains the current working directory. In the classic attack, a malicious
|
|
11
|
+
// DLL is dropped in the likely - controllable current working directory. The malicious DLL has the same name as a
|
|
12
|
+
// missing dependency or dependency that is not in the same directory as the executable. When the call to LoadLibrary
|
|
13
|
+
// is reached, the malicious DLL is loaded preferentially, and code execution occurs.
|
|
14
|
+
//
|
|
15
|
+
// The SafeLoadLibrary is the preferred ways to manually load dependencies.
|
|
16
|
+
// The API does not search the current working directory when resolving dependencies.
|
|
17
|
+
// The implementation is "borrowed" from Office MsoSafeLoadLibrary.
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
List of new flags that control where to search for DLLs. Requires KB2533623.
|
|
21
|
+
*/
|
|
22
|
+
const DWORD SafeLoadLibraryFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
|
|
23
|
+
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS;
|
|
24
|
+
|
|
25
|
+
HMODULE SafeLoadLibrary(const wchar_t *wzFileName, HANDLE hFile, DWORD dwFlags) noexcept {
|
|
26
|
+
// When calling LoadLibrary, OR in LOAD_LIBRARY_SEARCH_DEFAULT_DIRS which enables all of the
|
|
27
|
+
// safe behaviors. Note that this flag is not compatible with LOAD_WITH_ALTERED_SEARCH_PATH.
|
|
28
|
+
HMODULE module =
|
|
29
|
+
LoadLibraryExW(wzFileName, hFile, (dwFlags | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) & ~LOAD_WITH_ALTERED_SEARCH_PATH);
|
|
30
|
+
if (module == nullptr && GetLastError() == ERROR_INVALID_PARAMETER) {
|
|
31
|
+
// Could have failed with actual bad parameters or an unpatched OS without KB2533623.
|
|
32
|
+
if (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "AddDllDirectory") == nullptr) {
|
|
33
|
+
// Unpatched OS, remove all new flags.
|
|
34
|
+
module = LoadLibraryExW(wzFileName, hFile, dwFlags & ~SafeLoadLibraryFlags);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return module;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
} // namespace Microsoft::ReactNative
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
5
|
+
#define WIN32_LEAN_AND_MEAN
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <windows.h>
|
|
9
|
+
|
|
10
|
+
namespace Microsoft::ReactNative {
|
|
11
|
+
|
|
12
|
+
// Safe LoadLibraryEx wrapper that must be used instead of LoadLibrary.
|
|
13
|
+
extern HMODULE SafeLoadLibrary(const wchar_t *wzFileName, HANDLE hFile = nullptr, DWORD dwFlags = 0) noexcept;
|
|
14
|
+
|
|
15
|
+
} // namespace Microsoft::ReactNative
|