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_helper/dictionary.h"
#include "shell/common/node_includes.h"
#include "shell/common/node_util.h"
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
// decryption failure, rather than failing silently
const char* data = node::Buffer::Data(buffer);
auto size = node::Buffer::Length(buffer);
std::string ciphertext(data, size);
if (ciphertext.empty()) {
const auto ciphertext =
std::string{base::as_string_view(electron::util::as_byte_span(buffer))};
if (ciphertext.empty())
return "";
}
if (ciphertext.find(kEncryptionVersionPrefixV10) != 0 &&
ciphertext.find(kEncryptionVersionPrefixV11) != 0) {
if (!ciphertext.starts_with(kEncryptionVersionPrefixV10) &&
!ciphertext.starts_with(kEncryptionVersionPrefixV11)) {
gin_helper::ErrorThrower(isolate).ThrowError(
"Error while decrypting the ciphertext provided to "
"safeStorage.decryptString. "

View File

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

View File

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

View File

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