Compare commits

...

3 Commits

4 changed files with 16 additions and 15 deletions

View File

@@ -11,6 +11,7 @@
#include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
#include "shell/common/node_util.h"
namespace { namespace {
@@ -98,15 +99,13 @@ std::string DecryptString(v8::Isolate* isolate, v8::Local<v8::Value> buffer) {
// ensures an error is thrown in Mac or Linux on // ensures an error is thrown in Mac or Linux on
// decryption failure, rather than failing silently // decryption failure, rather than failing silently
const char* data = node::Buffer::Data(buffer); const auto ciphertext =
auto size = node::Buffer::Length(buffer); std::string{base::as_string_view(electron::util::as_byte_span(buffer))};
std::string ciphertext(data, size); if (ciphertext.empty())
if (ciphertext.empty()) {
return ""; return "";
}
if (ciphertext.find(kEncryptionVersionPrefixV10) != 0 && if (!ciphertext.starts_with(kEncryptionVersionPrefixV10) &&
ciphertext.find(kEncryptionVersionPrefixV11) != 0) { !ciphertext.starts_with(kEncryptionVersionPrefixV11)) {
gin_helper::ErrorThrower(isolate).ThrowError( gin_helper::ErrorThrower(isolate).ThrowError(
"Error while decrypting the ciphertext provided to " "Error while decrypting the ciphertext provided to "
"safeStorage.decryptString. " "safeStorage.decryptString. "

View File

@@ -34,6 +34,7 @@
#include "shell/common/gin_converters/net_converter.h" #include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/dictionary.h"
#include "shell/common/v8_util.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h" #include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
@@ -498,8 +499,7 @@ void ElectronURLLoaderFactory::StartLoadingBuffer(
network::mojom::URLResponseHeadPtr head, network::mojom::URLResponseHeadPtr head,
v8::Local<v8::ArrayBufferView> buffer) { v8::Local<v8::ArrayBufferView> buffer) {
SendContents(std::move(client), std::move(head), SendContents(std::move(client), std::move(head),
std::string(node::Buffer::Data(buffer.As<v8::Value>()), base::as_string_view(electron::util::as_byte_span(buffer)));
node::Buffer::Length(buffer.As<v8::Value>())));
} }
// static // static
@@ -624,7 +624,7 @@ void ElectronURLLoaderFactory::StartLoadingStream(
void ElectronURLLoaderFactory::SendContents( void ElectronURLLoaderFactory::SendContents(
mojo::PendingRemote<network::mojom::URLLoaderClient> client, mojo::PendingRemote<network::mojom::URLLoaderClient> client,
network::mojom::URLResponseHeadPtr head, network::mojom::URLResponseHeadPtr head,
std::string data) { const std::string_view data) {
mojo::Remote<network::mojom::URLLoaderClient> client_remote( mojo::Remote<network::mojom::URLLoaderClient> client_remote(
std::move(client)); std::move(client));
@@ -645,7 +645,7 @@ void ElectronURLLoaderFactory::SendContents(
auto write_data = std::make_unique<WriteData>(); auto write_data = std::make_unique<WriteData>();
write_data->client = std::move(client_remote); write_data->client = std::move(client_remote);
write_data->data = std::move(data); write_data->data = data;
write_data->producer = write_data->producer =
std::make_unique<mojo::DataPipeProducer>(std::move(producer)); std::make_unique<mojo::DataPipeProducer>(std::move(producer));
auto* producer_ptr = write_data->producer.get(); auto* producer_ptr = write_data->producer.get();

View File

@@ -8,6 +8,7 @@
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>
#include <string_view>
#include <utility> #include <utility>
#include <vector> #include <vector>
@@ -175,7 +176,7 @@ class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
static void SendContents( static void SendContents(
mojo::PendingRemote<network::mojom::URLLoaderClient> client, mojo::PendingRemote<network::mojom::URLLoaderClient> client,
network::mojom::URLResponseHeadPtr head, network::mojom::URLResponseHeadPtr head,
std::string data); std::string_view data);
ProtocolType type_; ProtocolType type_;
ProtocolHandler handler_; ProtocolHandler handler_;

View File

@@ -10,6 +10,7 @@
#include "mojo/public/cpp/system/string_data_source.h" #include "mojo/public/cpp/system/string_data_source.h"
#include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
#include "shell/common/node_util.h"
namespace electron { namespace electron {
@@ -138,14 +139,14 @@ void NodeStreamLoader::ReadMore() {
// Hold the buffer until the write is done. // Hold the buffer until the write is done.
buffer_.Reset(isolate_, buffer); buffer_.Reset(isolate_, buffer);
bytes_written_ += node::Buffer::Length(buffer); const auto buffer_span = electron::util::as_byte_span(buffer);
bytes_written_ += buffer_span.size();
// Write buffer to mojo pipe asynchronously. // Write buffer to mojo pipe asynchronously.
is_reading_ = false; is_reading_ = false;
is_writing_ = true; is_writing_ = true;
producer_->Write(std::make_unique<mojo::StringDataSource>( producer_->Write(std::make_unique<mojo::StringDataSource>(
std::string_view{node::Buffer::Data(buffer), base::as_chars(buffer_span),
node::Buffer::Length(buffer)},
mojo::StringDataSource::AsyncWritingMode:: mojo::StringDataSource::AsyncWritingMode::
STRING_STAYS_VALID_UNTIL_COMPLETION), STRING_STAYS_VALID_UNTIL_COMPLETION),
base::BindOnce(&NodeStreamLoader::DidWrite, weak)); base::BindOnce(&NodeStreamLoader::DidWrite, weak));