Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec] Update graceful-fs: 4.1.15 → 4.2.11 (minor) #631

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
405270c
feat: add support for will-navigate and will-fail-load custom error p…
MarshallOfSound Aug 25, 2020
af26e71
chore: fixup for review
MarshallOfSound Aug 27, 2020
820cc56
build(deps): bump terser from 4.6.7 to 4.8.1
dependabot[bot] Oct 4, 2022
46a11e7
build(deps): bump minimatch from 3.0.4 to 3.0.8
dependabot[bot] Nov 9, 2022
262e3c6
Merge pull request #597 from turkdevops/dependabot/npm_and_yarn/minim…
kadirselcuk Nov 14, 2022
065246c
build(deps): bump loader-utils from 1.2.3 to 1.4.2
dependabot[bot] Nov 16, 2022
5039890
Merge pull request #599 from turkdevops/dependabot/npm_and_yarn/loade…
kadirselcuk Nov 16, 2022
08020ca
build(deps): bump loader-utils from 1.2.3 to 1.4.2 in /spec-main
dependabot[bot] Nov 16, 2022
dbd3a07
Merge pull request #598 from turkdevops/dependabot/npm_and_yarn/spec-…
kadirselcuk Nov 16, 2022
afe831f
Merge pull request #575 from turkdevops/dependabot/npm_and_yarn/terse…
kadirselcuk Nov 16, 2022
0439f39
build(deps-dev): bump ws from 6.2.1 to 6.2.2 in /spec
dependabot[bot] Nov 16, 2022
de4f8cc
build(deps): bump lodash from 4.17.14 to 4.17.21 in /spec
dependabot[bot] Nov 16, 2022
34b00a1
Merge pull request #574 from turkdevops/dependabot/npm_and_yarn/spec/…
kadirselcuk Nov 26, 2022
48d2247
Merge pull request #572 from turkdevops/dependabot/npm_and_yarn/spec/…
kadirselcuk Nov 26, 2022
eeb58d4
build(deps-dev): bump ws from 7.2.1 to 7.4.6 in /spec-main
dependabot[bot] Nov 26, 2022
1954b6f
Merge pull request #573 from turkdevops/dependabot/npm_and_yarn/spec-…
kadirselcuk Nov 26, 2022
2f25598
build(deps): bump lodash from 4.17.15 to 4.17.21
dependabot[bot] Nov 26, 2022
72cb313
build(deps): bump tar from 4.4.10 to 4.4.19
dependabot[bot] Nov 26, 2022
9b3bc61
Merge pull request #600 from turkdevops/dependabot/npm_and_yarn/lodas…
kadirselcuk Dec 6, 2022
136afb2
build(deps): bump decode-uri-component from 0.2.0 to 0.2.2
dependabot[bot] Dec 6, 2022
8ab4653
Merge pull request #601 from turkdevops/dependabot/npm_and_yarn/tar-4…
kadirselcuk Dec 6, 2022
6245b7f
build(deps-dev): bump express from 4.17.1 to 4.17.3
dependabot[bot] Dec 6, 2022
d51a9c1
build(deps): bump qs from 6.5.2 to 6.5.3
dependabot[bot] Dec 6, 2022
ad5896f
build(deps): bump qs from 6.5.2 to 6.5.3 in /spec
dependabot[bot] Dec 6, 2022
886a59b
build(deps): bump json5 from 1.0.1 to 1.0.2
dependabot[bot] Jan 6, 2023
a0cc793
Merge pull request #617 from turkdevops/dependabot/npm_and_yarn/json5…
kadirselcuk Jan 7, 2023
0c62aea
Merge pull request #609 from turkdevops/dependabot/npm_and_yarn/qs-6.5.3
kadirselcuk Jan 7, 2023
33879cf
Merge pull request #608 from turkdevops/dependabot/npm_and_yarn/expre…
kadirselcuk Jan 7, 2023
8a3ac33
Merge pull request #607 from turkdevops/dependabot/npm_and_yarn/decod…
kadirselcuk Jan 7, 2023
95ea2e6
build(deps): bump json5 from 1.0.1 to 1.0.2 in /spec-main
dependabot[bot] Jan 7, 2023
468c492
Merge pull request #606 from turkdevops/dependabot/npm_and_yarn/spec/…
kadirselcuk Jan 7, 2023
34b8531
Merge pull request #618 from turkdevops/dependabot/npm_and_yarn/spec-…
kadirselcuk Jan 7, 2023
94b5d8d
Update graceful-fs to version 4.2.11
depfu[bot] Mar 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/structures/cancellable-navigation-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CancellableNavigationEvent Object extends `Event`

* `returnValue` Object | null - Set this to cancel the navigation event and optionally return a custom error code or error page
* `errorCode` Number - Can be any error code from the [Net Error List](https://source.chromium.org/chromium/chromium/src/+/master:net/base/net_error_list.h). If you provide `errorPage` then this code can not be `-3`. We recommend using `-2` which is `net::Aborted`.
* `errorPage` String (optional) - Custom HTML error page to display when the navigation is cancelled.

24 changes: 23 additions & 1 deletion docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ Process: [Main](../glossary.md#main-process)
Emitted when the navigation is done, i.e. the spinner of the tab has stopped
spinning, and the `onload` event was dispatched.

#### Event: 'will-fail-load'

Returns:

* `event` [CancellableNavigationEvent](structures/cancellable-navigation-event.md)
* `url` String
* `isInPlace` Boolean
* `isMainFrame` Boolean
* `frameProcessId` Integer
* `frameRoutingId` Integer
* `errorCode` Integer
* `errorDescription` String

This event will be emitted after `did-start-loading` and always before the
`did-fail-load` event for the same navigation.

Settings `event.returnValue` to an HTML string will result in a custom error page being
displayed using that HTML.

#### Event: 'did-fail-load'

Returns:
Expand Down Expand Up @@ -193,7 +212,7 @@ myBrowserWindow.webContents.on('new-window', (event, url, frameName, disposition

Returns:

* `event` Event
* `event` [CancellableNavigationEvent](structures/cancellable-navigation-event.md)
* `url` String

Emitted when a user or the page wants to start navigation. It can happen when
Expand All @@ -208,6 +227,9 @@ this purpose.

Calling `event.preventDefault()` will prevent the navigation.

Settings `event.returnValue` to an HTML string will result in a custom error page being
displayed using that HTML and the navigation being cancelled.

#### Event: 'did-start-navigation'

Returns:
Expand Down
1 change: 1 addition & 0 deletions filenames.auto.gni
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ auto_filenames = {
"docs/api/webview-tag.md",
"docs/api/window-open.md",
"docs/api/structures/bluetooth-device.md",
"docs/api/structures/cancellable-navigation-event.md",
"docs/api/structures/certificate-principal.md",
"docs/api/structures/certificate.md",
"docs/api/structures/cookie.md",
Expand Down
25 changes: 25 additions & 0 deletions lib/browser/api/web-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,31 @@ WebContents.prototype._init = function () {
ipcMain.emit(channel, event, message);
});

const handleCustomErrorPageEvent = (eventName: string) => {
this.on(`-${eventName}` as any, function (this: any, event: any, ...args: any[]) {
let allowReturnValue = true;
Object.defineProperty(event, 'returnValue', {
set: (value) => {
if (!allowReturnValue) return;

if (typeof value !== 'object' || !value) { throw new TypeError(`event.returnValue must be set to a non-null object, was set to a "${typeof value}"`); }
if (typeof value.errorCode !== 'number') { throw new TypeError(`event.returnValue.errorCode must be set to a number, was set to a "${typeof value.errorCode}"`); }
if (value.errorCode >= 0) { throw new TypeError(`event.returnValue.errorCode must be negative, was set to "${value.errorCode}"`); }
if (value.errorPage && typeof value.errorPage !== 'string') { throw new TypeError(`event.returnValue.errorPage must be set to a string if provided, was set to a "${typeof value.errorPage}"`); }
if (typeof value.errorPage === 'string' && value.errorPage.length === 0) { throw new Error('event.returnValue.errorPage must be a non-empty string, an empty string was provided'); }
if (value.errorPage && value.errorCode === -3) { throw new Error('event.returnValue.errorCode can not be set to "-2" when an errorPage is provided'); }
event.preventDefault();
event.sendReply(value);
},
get: () => {}
});
this.emit(eventName, event, ...args);
allowReturnValue = false;
});
};
handleCustomErrorPageEvent('will-navigate');
handleCustomErrorPageEvent('will-fail-load');

// Handle context menu action request from pepper plugin.
this.on('pepper-context-menu' as any, function (event: any, params: {x: number, y: number, menu: Array<(MenuItemConstructorOptions) | (MenuItem)>}, callback: () => void) {
// Access Menu via electron.Menu to prevent circular require.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
"devDependencies": {
"@electron/docs-parser": "^0.9.1",
"@electron/typescript-definitions": "^8.7.5",
"@electron/typescript-definitions": "^8.7.7",
"@octokit/rest": "^18.0.3",
"@primer/octicons": "^10.0.0",
"@types/basic-auth": "^1.1.3",
Expand Down Expand Up @@ -37,7 +37,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-typescript": "^0.14.0",
"express": "^4.16.4",
"express": "^4.17.3",
"folder-hash": "^2.1.1",
"fs-extra": "^9.0.1",
"husky": "^2.2.0",
Expand Down
38 changes: 28 additions & 10 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ void WebContents::DidStopLoading() {

bool WebContents::EmitNavigationEvent(
const std::string& event,
content::NavigationHandle* navigation_handle) {
content::NavigationHandle* navigation_handle,
gin_helper::Event::ValueCallback callback) {
bool is_main_frame = navigation_handle->IsInMainFrame();
int frame_tree_node_id = navigation_handle->GetFrameTreeNodeId();
content::FrameTreeNode* frame_tree_node =
Expand All @@ -1136,8 +1137,18 @@ bool WebContents::EmitNavigationEvent(
}
bool is_same_document = navigation_handle->IsSameDocument();
auto url = navigation_handle->GetURL();
return Emit(event, url, is_same_document, is_main_frame, frame_process_id,
frame_routing_id);
int code = navigation_handle->GetNetErrorCode();
auto description = net::ErrorToShortString(code);
return EmitWithSender(event, nullptr, std::move(callback), url,
is_same_document, is_main_frame, frame_process_id,
frame_routing_id, code, description);
}

bool WebContents::EmitNavigationEvent(
const std::string& event,
content::NavigationHandle* navigation_handle) {
return EmitNavigationEvent(event, navigation_handle,
gin_helper::Event::ValueCallback());
}

void WebContents::BindElectronBrowser(
Expand All @@ -1159,8 +1170,9 @@ void WebContents::Message(bool internal,
TRACE_EVENT1("electron", "WebContents::Message", "channel", channel);
// webContents.emit('-ipc-message', new Event(), internal, channel,
// arguments);
EmitWithSender("-ipc-message", receivers_.current_context(), InvokeCallback(),
internal, channel, std::move(arguments));
EmitWithSender("-ipc-message", receivers_.current_context(),
gin_helper::Event::ValueCallback(), internal, channel,
std::move(arguments));
}

void WebContents::Invoke(bool internal,
Expand All @@ -1170,7 +1182,9 @@ void WebContents::Invoke(bool internal,
TRACE_EVENT1("electron", "WebContents::Invoke", "channel", channel);
// webContents.emit('-ipc-invoke', new Event(), internal, channel, arguments);
EmitWithSender("-ipc-invoke", receivers_.current_context(),
std::move(callback), internal, channel, std::move(arguments));
gin_helper::Event::AdaptInvokeCallbackToValueCallback(
std::move(callback)),
internal, channel, std::move(arguments));
}

void WebContents::ReceivePostMessage(const std::string& channel,
Expand All @@ -1181,8 +1195,9 @@ void WebContents::ReceivePostMessage(const std::string& channel,
MessagePort::EntanglePorts(isolate, std::move(message.ports));
v8::Local<v8::Value> message_value =
electron::DeserializeV8Value(isolate, message);
EmitWithSender("-ipc-ports", receivers_.current_context(), InvokeCallback(),
false, channel, message_value, std::move(wrapped_ports));
EmitWithSender("-ipc-ports", receivers_.current_context(),
gin_helper::Event::ValueCallback(), false, channel,
message_value, std::move(wrapped_ports));
}

void WebContents::PostMessage(const std::string& channel,
Expand Down Expand Up @@ -1226,7 +1241,9 @@ void WebContents::MessageSync(bool internal,
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
// channel, arguments);
EmitWithSender("-ipc-message-sync", receivers_.current_context(),
std::move(callback), internal, channel, std::move(arguments));
gin_helper::Event::AdaptInvokeCallbackToValueCallback(
std::move(callback)),
internal, channel, std::move(arguments));
}

void WebContents::MessageTo(bool internal,
Expand All @@ -1248,7 +1265,8 @@ void WebContents::MessageHost(const std::string& channel,
TRACE_EVENT1("electron", "WebContents::MessageHost", "channel", channel);
// webContents.emit('ipc-message-host', new Event(), channel, args);
EmitWithSender("ipc-message-host", receivers_.current_context(),
InvokeCallback(), channel, std::move(arguments));
gin_helper::Event::ValueCallback(), channel,
std::move(arguments));
}

void WebContents::UpdateDraggableRegions(
Expand Down
7 changes: 6 additions & 1 deletion shell/browser/api/electron_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "printing/buildflags/buildflags.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "shell/browser/api/event.h"
#include "shell/browser/api/frame_subscriber.h"
#include "shell/browser/api/save_page_handler.h"
#include "shell/browser/common_web_contents_delegate.h"
Expand Down Expand Up @@ -408,11 +409,15 @@ class WebContents : public gin::Wrappable<WebContents>,
bool EmitNavigationEvent(const std::string& event,
content::NavigationHandle* navigation_handle);

bool EmitNavigationEvent(const std::string& event,
content::NavigationHandle* navigation_handle,
gin_helper::Event::ValueCallback callback);

// this.emit(name, new Event(sender, message), args...);
template <typename... Args>
bool EmitWithSender(base::StringPiece name,
content::RenderFrameHost* sender,
electron::mojom::ElectronBrowser::InvokeCallback callback,
gin_helper::Event::ValueCallback callback,
Args&&... args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
Expand Down
34 changes: 26 additions & 8 deletions shell/browser/api/event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@

namespace gin_helper {

namespace {

bool InvokeCallbackAdapter(Event::InvokeCallback callback,
v8::Local<v8::Value> result) {
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
blink::CloneableMessage message;
if (!gin::ConvertFromV8(isolate, result, &message)) {
return false;
}

std::move(callback).Run(std::move(message));
return true;
}

} // namespace

gin::WrapperInfo Event::kWrapperInfo = {gin::kEmbedderNativeGin};

Event::Event() {}
Expand All @@ -29,7 +45,7 @@ Event::~Event() {
}
}

void Event::SetCallback(InvokeCallback callback) {
void Event::SetCallback(ValueCallback callback) {
DCHECK(!callback_);
callback_ = std::move(callback);
}
Expand All @@ -45,13 +61,7 @@ bool Event::SendReply(v8::Isolate* isolate, v8::Local<v8::Value> result) {
if (!callback_)
return false;

blink::CloneableMessage message;
if (!gin::ConvertFromV8(isolate, result, &message)) {
return false;
}

std::move(callback_).Run(std::move(message));
return true;
return std::move(callback_).Run(result);
}

gin::ObjectTemplateBuilder Event::GetObjectTemplateBuilder(
Expand All @@ -70,4 +80,12 @@ gin::Handle<Event> Event::Create(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new Event());
}

Event::ValueCallback Event::AdaptInvokeCallbackToValueCallback(
Event::InvokeCallback callback) {
if (!callback)
return ValueCallback();

return base::BindOnce(InvokeCallbackAdapter, std::move(callback));
}

} // namespace gin_helper
10 changes: 7 additions & 3 deletions shell/browser/api/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ namespace gin_helper {
class Event : public gin::Wrappable<Event> {
public:
using InvokeCallback = electron::mojom::ElectronBrowser::InvokeCallback;
using ValueCallback = base::OnceCallback<bool(v8::Local<v8::Value>)>;

static gin::WrapperInfo kWrapperInfo;

static gin::Handle<Event> Create(v8::Isolate* isolate);

// Pass the callback to be invoked.
void SetCallback(InvokeCallback callback);
static ValueCallback AdaptInvokeCallbackToValueCallback(
InvokeCallback callback);

// event.PreventDefault().
void PreventDefault(v8::Isolate* isolate);

// Pass the callback to be invoked.
void SetCallback(ValueCallback callback);

// event.sendReply(value), used for replying to synchronous messages and
// `invoke` calls.
bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> result);
Expand All @@ -44,7 +48,7 @@ class Event : public gin::Wrappable<Event> {

private:
// Replyer for the synchronous messages.
InvokeCallback callback_;
ValueCallback callback_;

DISALLOW_COPY_AND_ASSIGN(Event);
};
Expand Down
54 changes: 50 additions & 4 deletions shell/browser/electron_navigation_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@

#include "shell/browser/electron_navigation_throttle.h"

#include <memory>
#include <string>

#include "content/public/browser/navigation_handle.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_helper/dictionary.h"

namespace electron {

namespace {

bool HandleEventReturnValue(int* error_code,
std::string* error_html,
v8::Local<v8::Value> val) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict;
gin::ConvertFromV8(isolate, val, &dict);
if (!dict.Get("errorCode", error_code))
return false;
dict.Get("errorPage", error_html);
return true;
}

} // namespace

ElectronNavigationThrottle::ElectronNavigationThrottle(
content::NavigationHandle* navigation_handle)
: content::NavigationThrottle(navigation_handle) {}
Expand All @@ -21,7 +41,9 @@ const char* ElectronNavigationThrottle::GetNameForLogging() {
}

content::NavigationThrottle::ThrottleCheckResult
ElectronNavigationThrottle::WillStartRequest() {
ElectronNavigationThrottle::DelegateEventToWebContents(
const std::string& event_name,
net::Error error_code) {
auto* handle = navigation_handle();
auto* contents = handle->GetWebContents();
if (!contents) {
Expand All @@ -37,13 +59,37 @@ ElectronNavigationThrottle::WillStartRequest() {
return PROCEED;
}

if (handle->IsRendererInitiated() && handle->IsInMainFrame() &&
api_contents->EmitNavigationEvent("will-navigate", handle)) {
return CANCEL;
int error_code_int = error_code;
std::string error_html;
// JS ensures that this callback can not be called out-of-stack
if (api_contents->EmitNavigationEvent(
event_name, handle,
base::BindOnce(&HandleEventReturnValue,
base::Unretained(&error_code_int),
base::Unretained(&error_html)))) {
if (!error_html.empty()) {
return content::NavigationThrottle::ThrottleCheckResult(
CANCEL, error_code, error_html);
}
return content::NavigationThrottle::ThrottleCheckResult(CANCEL, error_code);
}
return PROCEED;
}

content::NavigationThrottle::ThrottleCheckResult
ElectronNavigationThrottle::WillFailRequest() {
return DelegateEventToWebContents("-will-fail-load",
navigation_handle()->GetNetErrorCode());
}

content::NavigationThrottle::ThrottleCheckResult
ElectronNavigationThrottle::WillStartRequest() {
auto* handle = navigation_handle();
if (handle->IsRendererInitiated() && handle->IsInMainFrame())
return DelegateEventToWebContents("-will-navigate", net::ERR_FAILED);
return PROCEED;
}

content::NavigationThrottle::ThrottleCheckResult
ElectronNavigationThrottle::WillRedirectRequest() {
auto* handle = navigation_handle();
Expand Down
Loading