refactor: use gin::Arguments in WebContents (#24604)

This commit is contained in:
Jeremy Rose 2020-07-20 11:07:02 -07:00 committed by GitHub
parent 682f78b9a8
commit e5cb22b7f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 34 deletions

View file

@ -47,6 +47,7 @@
#include "content/public/common/referrer_type_converters.h"
#include "electron/buildflags/buildflags.h"
#include "electron/shell/common/api/api.mojom.h"
#include "gin/arguments.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
@ -1651,8 +1652,7 @@ bool WebContents::IsCrashed() const {
return web_contents()->IsCrashed();
}
void WebContents::SetUserAgent(const std::string& user_agent,
gin_helper::Arguments* args) {
void WebContents::SetUserAgent(const std::string& user_agent) {
web_contents()->SetUserAgentOverride(
blink::UserAgentOverride::UserAgentOnly(user_agent), false);
}
@ -1674,7 +1674,7 @@ v8::Local<v8::Promise> WebContents::SavePage(
return handle;
}
void WebContents::OpenDevTools(gin_helper::Arguments* args) {
void WebContents::OpenDevTools(gin::Arguments* args) {
if (type_ == Type::REMOTE)
return;
@ -1897,20 +1897,21 @@ void WebContents::OnGetDefaultPrinter(
std::move(print_callback));
}
void WebContents::Print(gin_helper::Arguments* args) {
void WebContents::Print(gin::Arguments* args) {
gin_helper::Dictionary options =
gin::Dictionary::CreateEmpty(args->isolate());
base::Value settings(base::Value::Type::DICTIONARY);
if (args->Length() >= 1 && !args->GetNext(&options)) {
args->ThrowError("webContents.print(): Invalid print settings specified.");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("webContents.print(): Invalid print settings specified.");
return;
}
printing::CompletionCallback callback;
if (args->Length() == 2 && !args->GetNext(&callback)) {
args->ThrowError(
"webContents.print(): Invalid optional callback provided.");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("webContents.print(): Invalid optional callback provided.");
return;
}
@ -1970,7 +1971,8 @@ void WebContents::Print(gin_helper::Arguments* args) {
base::string16 device_name;
options.Get("deviceName", &device_name);
if (!device_name.empty() && !IsDeviceNameValid(device_name)) {
args->ThrowError("webContents.print(): Invalid deviceName provided.");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("webContents.print(): Invalid deviceName provided.");
return;
}
@ -2092,19 +2094,21 @@ v8::Local<v8::Promise> WebContents::PrintToPDF(base::DictionaryValue settings) {
}
#endif
void WebContents::AddWorkSpace(gin_helper::Arguments* args,
void WebContents::AddWorkSpace(gin::Arguments* args,
const base::FilePath& path) {
if (path.empty()) {
args->ThrowError("path cannot be empty");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("path cannot be empty");
return;
}
DevToolsAddFileSystem(std::string(), path);
}
void WebContents::RemoveWorkSpace(gin_helper::Arguments* args,
void WebContents::RemoveWorkSpace(gin::Arguments* args,
const base::FilePath& path) {
if (path.empty()) {
args->ThrowError("path cannot be empty");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("path cannot be empty");
return;
}
DevToolsRemoveFileSystem(path);
@ -2154,10 +2158,11 @@ void WebContents::ReplaceMisspelling(const base::string16& word) {
web_contents()->ReplaceMisspelling(word);
}
uint32_t WebContents::FindInPage(gin_helper::Arguments* args) {
uint32_t WebContents::FindInPage(gin::Arguments* args) {
base::string16 search_text;
if (!args->GetNext(&search_text) || search_text.empty()) {
args->ThrowError("Must provide a non-empty search content");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("Must provide a non-empty search content");
return 0;
}
@ -2353,11 +2358,16 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
v8::Exception::Error(gin::StringToV8(isolate, "Invalid event object")));
}
void WebContents::BeginFrameSubscription(gin_helper::Arguments* args) {
void WebContents::BeginFrameSubscription(gin::Arguments* args) {
bool only_dirty = false;
FrameSubscriber::FrameCaptureCallback callback;
args->GetNext(&only_dirty);
if (args->Length() > 1) {
if (!args->GetNext(&only_dirty)) {
args->ThrowError();
return;
}
}
if (!args->GetNext(&callback)) {
args->ThrowError();
return;
@ -2372,7 +2382,7 @@ void WebContents::EndFrameSubscription() {
}
void WebContents::StartDrag(const gin_helper::Dictionary& item,
gin_helper::Arguments* args) {
gin::Arguments* args) {
base::FilePath file;
std::vector<base::FilePath> files;
if (!item.Get("files", &files) && item.Get("file", &file)) {
@ -2381,7 +2391,8 @@ void WebContents::StartDrag(const gin_helper::Dictionary& item,
gin::Handle<NativeImage> icon;
if (!item.Get("icon", &icon) || icon->image().IsEmpty()) {
args->ThrowError("Must specify non-empty 'icon' option");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("Must specify non-empty 'icon' option");
return;
}
@ -2390,11 +2401,12 @@ void WebContents::StartDrag(const gin_helper::Dictionary& item,
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
DragFileItems(files, icon->image(), web_contents()->GetNativeView());
} else {
args->ThrowError("Must specify either 'file' or 'files' option");
gin_helper::ErrorThrower(args->isolate())
.ThrowError("Must specify either 'file' or 'files' option");
}
}
v8::Local<v8::Promise> WebContents::CapturePage(gin_helper::Arguments* args) {
v8::Local<v8::Promise> WebContents::CapturePage(gin::Arguments* args) {
gfx::Rect rect;
gin_helper::Promise<gfx::Image> promise(args->isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -2428,7 +2440,7 @@ v8::Local<v8::Promise> WebContents::CapturePage(gin_helper::Arguments* args) {
return handle;
}
void WebContents::IncrementCapturerCount(gin_helper::Arguments* args) {
void WebContents::IncrementCapturerCount(gin::Arguments* args) {
gfx::Size size;
bool stay_hidden = false;
@ -2440,7 +2452,7 @@ void WebContents::IncrementCapturerCount(gin_helper::Arguments* args) {
web_contents()->IncrementCapturerCount(size, stay_hidden);
}
void WebContents::DecrementCapturerCount(gin_helper::Arguments* args) {
void WebContents::DecrementCapturerCount(gin::Arguments* args) {
bool stay_hidden = false;
// get stayHidden arguments if they exist