d6bb9b40b0
* feat: add blinkUtils module with getPathForFile method This is designed to replace the File.path augmentation we currently have in place to allow apps to get the filesystem path for a file that blink has a representation of. File.path is non-standard and messes with certain websites, using a method like this is effectively 0-cost and removes one of the final deviations we have with web standards. * add error * refactor: update per PR feedback * chore: update patches * oops * chore: update patches * chore: update patches * feat: add blinkUtils module with getPathForFile method This is designed to replace the File.path augmentation we currently have in place to allow apps to get the filesystem path for a file that blink has a representation of. File.path is non-standard and messes with certain websites, using a method like this is effectively 0-cost and removes one of the final deviations we have with web standards. * add error * refactor: update per PR feedback * chore: update patches * oops * chore: update patches * chore: update patches * chore: update patches * fix: provide isolate to WebBlob::FromV8Value * chore: add tests * build: fix depshash mismatch on arm64 macOS --------- Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
// Copyright (c) 2023 Salesforce, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/renderer/api/electron_api_web_utils.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
|
#include "shell/common/node_includes.h"
|
|
#include "third_party/blink/public/web/web_blob.h"
|
|
|
|
namespace electron::api::web_utils {
|
|
|
|
std::string GetPathForFile(v8::Isolate* isolate, v8::Local<v8::Value> file) {
|
|
blink::WebBlob blob = blink::WebBlob::FromV8Value(isolate, file);
|
|
if (blob.IsNull()) {
|
|
gin_helper::ErrorThrower(isolate).ThrowTypeError(
|
|
"getPathForFile expected to receive a File object but one was not "
|
|
"provided");
|
|
return "";
|
|
}
|
|
return blob.Path();
|
|
}
|
|
|
|
} // namespace electron::api::web_utils
|
|
|
|
namespace {
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context,
|
|
void* priv) {
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
gin_helper::Dictionary dict(isolate, exports);
|
|
dict.SetMethod("getPathForFile", &electron::api::web_utils::GetPathForFile);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_renderer_web_utils, Initialize)
|