chore: modernize Value usage in converters (#34794)
* chore: modernize Value usage in converters * Date is parsed as an empty object now
This commit is contained in:
parent
d28ed0da20
commit
0ee7f14190
34 changed files with 203 additions and 829 deletions
|
@ -288,7 +288,7 @@ void BaseWindow::OnExecuteAppCommand(const std::string& command_name) {
|
|||
}
|
||||
|
||||
void BaseWindow::OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) {
|
||||
const base::Value::Dict& details) {
|
||||
Emit("-touch-bar-interaction", item_id, details);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
|||
void OnWindowAlwaysOnTopChanged() override;
|
||||
void OnExecuteAppCommand(const std::string& command_name) override;
|
||||
void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) override;
|
||||
const base::Value::Dict& details) override;
|
||||
void OnNewWindowForTab() override;
|
||||
void OnSystemContextMenu(int x, int y, bool* prevent_default) override;
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
|
|
|
@ -42,9 +42,10 @@ struct Converter<base::trace_event::TraceConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
base::DictionaryValue memory_dump_config;
|
||||
base::Value::Dict memory_dump_config;
|
||||
if (ConvertFromV8(isolate, val, &memory_dump_config)) {
|
||||
*out = base::trace_event::TraceConfig(memory_dump_config);
|
||||
*out = base::trace_event::TraceConfig(
|
||||
base::Value(std::move(memory_dump_config)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,27 +117,27 @@ bool MatchesDomain(std::string filter, const std::string& domain) {
|
|||
}
|
||||
|
||||
// Returns whether |cookie| matches |filter|.
|
||||
bool MatchesCookie(const base::Value& filter,
|
||||
bool MatchesCookie(const base::Value::Dict& filter,
|
||||
const net::CanonicalCookie& cookie) {
|
||||
const std::string* str;
|
||||
if ((str = filter.FindStringKey("name")) && *str != cookie.Name())
|
||||
if ((str = filter.FindString("name")) && *str != cookie.Name())
|
||||
return false;
|
||||
if ((str = filter.FindStringKey("path")) && *str != cookie.Path())
|
||||
if ((str = filter.FindString("path")) && *str != cookie.Path())
|
||||
return false;
|
||||
if ((str = filter.FindStringKey("domain")) &&
|
||||
if ((str = filter.FindString("domain")) &&
|
||||
!MatchesDomain(*str, cookie.Domain()))
|
||||
return false;
|
||||
absl::optional<bool> secure_filter = filter.FindBoolKey("secure");
|
||||
absl::optional<bool> secure_filter = filter.FindBool("secure");
|
||||
if (secure_filter && *secure_filter == cookie.IsSecure())
|
||||
return false;
|
||||
absl::optional<bool> session_filter = filter.FindBoolKey("session");
|
||||
absl::optional<bool> session_filter = filter.FindBool("session");
|
||||
if (session_filter && *session_filter != !cookie.IsPersistent())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
|
||||
void FilterCookies(const base::Value& filter,
|
||||
void FilterCookies(base::Value::Dict filter,
|
||||
gin_helper::Promise<net::CookieList> promise,
|
||||
const net::CookieList& cookies) {
|
||||
net::CookieList result;
|
||||
|
@ -149,11 +149,11 @@ void FilterCookies(const base::Value& filter,
|
|||
}
|
||||
|
||||
void FilterCookieWithStatuses(
|
||||
const base::Value& filter,
|
||||
base::Value::Dict filter,
|
||||
gin_helper::Promise<net::CookieList> promise,
|
||||
const net::CookieAccessResultList& list,
|
||||
const net::CookieAccessResultList& excluded_list) {
|
||||
FilterCookies(filter, std::move(promise),
|
||||
FilterCookies(std::move(filter), std::move(promise),
|
||||
net::cookie_util::StripAccessResults(list));
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ v8::Local<v8::Promise> Cookies::Get(v8::Isolate* isolate,
|
|||
auto* storage_partition = browser_context_->GetDefaultStoragePartition();
|
||||
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
||||
|
||||
base::DictionaryValue dict;
|
||||
base::Value::Dict dict;
|
||||
gin::ConvertFromV8(isolate, filter.GetHandle(), &dict);
|
||||
|
||||
std::string url;
|
||||
|
@ -280,31 +280,31 @@ v8::Local<v8::Promise> Cookies::Remove(v8::Isolate* isolate,
|
|||
}
|
||||
|
||||
v8::Local<v8::Promise> Cookies::Set(v8::Isolate* isolate,
|
||||
const base::DictionaryValue& details) {
|
||||
base::Value::Dict details) {
|
||||
gin_helper::Promise<void> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
const std::string* url_string = details.FindStringKey("url");
|
||||
const std::string* url_string = details.FindString("url");
|
||||
if (!url_string) {
|
||||
promise.RejectWithErrorMessage("Missing required option 'url'");
|
||||
return handle;
|
||||
}
|
||||
const std::string* name = details.FindStringKey("name");
|
||||
const std::string* value = details.FindStringKey("value");
|
||||
const std::string* domain = details.FindStringKey("domain");
|
||||
const std::string* path = details.FindStringKey("path");
|
||||
bool http_only = details.FindBoolKey("httpOnly").value_or(false);
|
||||
const std::string* same_site_string = details.FindStringKey("sameSite");
|
||||
const std::string* name = details.FindString("name");
|
||||
const std::string* value = details.FindString("value");
|
||||
const std::string* domain = details.FindString("domain");
|
||||
const std::string* path = details.FindString("path");
|
||||
bool http_only = details.FindBool("httpOnly").value_or(false);
|
||||
const std::string* same_site_string = details.FindString("sameSite");
|
||||
net::CookieSameSite same_site;
|
||||
std::string error = StringToCookieSameSite(same_site_string, &same_site);
|
||||
if (!error.empty()) {
|
||||
promise.RejectWithErrorMessage(error);
|
||||
return handle;
|
||||
}
|
||||
bool secure = details.FindBoolKey("secure").value_or(
|
||||
bool secure = details.FindBool("secure").value_or(
|
||||
same_site == net::CookieSameSite::NO_RESTRICTION);
|
||||
bool same_party =
|
||||
details.FindBoolKey("sameParty")
|
||||
details.FindBool("sameParty")
|
||||
.value_or(secure && same_site != net::CookieSameSite::STRICT_MODE);
|
||||
|
||||
GURL url(url_string ? *url_string : "");
|
||||
|
@ -317,10 +317,9 @@ v8::Local<v8::Promise> Cookies::Set(v8::Isolate* isolate,
|
|||
|
||||
auto canonical_cookie = net::CanonicalCookie::CreateSanitizedCookie(
|
||||
url, name ? *name : "", value ? *value : "", domain ? *domain : "",
|
||||
path ? *path : "",
|
||||
ParseTimeProperty(details.FindDoubleKey("creationDate")),
|
||||
ParseTimeProperty(details.FindDoubleKey("expirationDate")),
|
||||
ParseTimeProperty(details.FindDoubleKey("lastAccessDate")), secure,
|
||||
path ? *path : "", ParseTimeProperty(details.FindDouble("creationDate")),
|
||||
ParseTimeProperty(details.FindDouble("expirationDate")),
|
||||
ParseTimeProperty(details.FindDouble("lastAccessDate")), secure,
|
||||
http_only, same_site, net::COOKIE_PRIORITY_DEFAULT, same_party,
|
||||
absl::nullopt);
|
||||
if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "base/callback_list.h"
|
||||
#include "base/values.h"
|
||||
#include "gin/handle.h"
|
||||
#include "net/cookies/canonical_cookie.h"
|
||||
#include "net/cookies/cookie_change_dispatcher.h"
|
||||
|
@ -15,10 +16,6 @@
|
|||
#include "shell/common/gin_helper/promise.h"
|
||||
#include "shell/common/gin_helper/trackable_object.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
}
|
||||
|
||||
namespace gin_helper {
|
||||
class Dictionary;
|
||||
}
|
||||
|
@ -51,8 +48,7 @@ class Cookies : public gin::Wrappable<Cookies>,
|
|||
|
||||
v8::Local<v8::Promise> Get(v8::Isolate*,
|
||||
const gin_helper::Dictionary& filter);
|
||||
v8::Local<v8::Promise> Set(v8::Isolate*,
|
||||
const base::DictionaryValue& details);
|
||||
v8::Local<v8::Promise> Set(v8::Isolate*, base::Value::Dict details);
|
||||
v8::Local<v8::Promise> Remove(v8::Isolate*,
|
||||
const GURL& url,
|
||||
const std::string& name);
|
||||
|
|
|
@ -45,44 +45,35 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
|||
|
||||
base::StringPiece message_str(reinterpret_cast<const char*>(message.data()),
|
||||
message.size());
|
||||
std::unique_ptr<base::Value> parsed_message =
|
||||
base::JSONReader::ReadDeprecated(message_str,
|
||||
base::JSON_REPLACE_INVALID_CHARACTERS);
|
||||
absl::optional<base::Value> parsed_message = base::JSONReader::Read(
|
||||
message_str, base::JSON_REPLACE_INVALID_CHARACTERS);
|
||||
if (!parsed_message || !parsed_message->is_dict())
|
||||
return;
|
||||
auto* dict = static_cast<base::DictionaryValue*>(parsed_message.get());
|
||||
int id;
|
||||
if (!dict->GetInteger("id", &id)) {
|
||||
std::string method;
|
||||
if (!dict->GetString("method", &method))
|
||||
base::Value::Dict& dict = parsed_message->GetDict();
|
||||
absl::optional<int> id = dict.FindInt("id");
|
||||
if (!id) {
|
||||
std::string* method = dict.FindString("method");
|
||||
if (!method)
|
||||
return;
|
||||
std::string session_id;
|
||||
dict->GetString("sessionId", &session_id);
|
||||
base::DictionaryValue* params_value = nullptr;
|
||||
base::DictionaryValue params;
|
||||
if (dict->GetDictionary("params", ¶ms_value))
|
||||
params.Swap(params_value);
|
||||
Emit("message", method, params, session_id);
|
||||
std::string* session_id = dict.FindString("sessionId");
|
||||
base::Value::Dict* params = dict.FindDict("params");
|
||||
Emit("message", *method, params ? std::move(*params) : base::Value::Dict(),
|
||||
session_id ? *session_id : "");
|
||||
} else {
|
||||
auto it = pending_requests_.find(id);
|
||||
auto it = pending_requests_.find(*id);
|
||||
if (it == pending_requests_.end())
|
||||
return;
|
||||
|
||||
gin_helper::Promise<base::DictionaryValue> promise = std::move(it->second);
|
||||
gin_helper::Promise<base::Value::Dict> promise = std::move(it->second);
|
||||
pending_requests_.erase(it);
|
||||
|
||||
base::DictionaryValue* error = nullptr;
|
||||
if (dict->GetDictionary("error", &error)) {
|
||||
std::string message;
|
||||
error->GetString("message", &message);
|
||||
promise.RejectWithErrorMessage(message);
|
||||
base::Value::Dict* error = dict.FindDict("error");
|
||||
if (error) {
|
||||
std::string* message = error->FindString("message");
|
||||
promise.RejectWithErrorMessage(message ? *message : "");
|
||||
} else {
|
||||
base::DictionaryValue* result_body = nullptr;
|
||||
base::DictionaryValue result;
|
||||
if (dict->GetDictionary("result", &result_body)) {
|
||||
result.Swap(result_body);
|
||||
}
|
||||
promise.Resolve(result);
|
||||
base::Value::Dict* result = dict.FindDict("result");
|
||||
promise.Resolve(result ? std::move(*result) : base::Value::Dict());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +124,7 @@ void Debugger::Detach() {
|
|||
|
||||
v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
||||
v8::Isolate* isolate = args->isolate();
|
||||
gin_helper::Promise<base::DictionaryValue> promise(isolate);
|
||||
gin_helper::Promise<base::Value::Dict> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (!agent_host_) {
|
||||
|
@ -147,7 +138,7 @@ v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
|||
return handle;
|
||||
}
|
||||
|
||||
base::DictionaryValue command_params;
|
||||
base::Value::Dict command_params;
|
||||
args->GetNext(&command_params);
|
||||
|
||||
std::string session_id;
|
||||
|
@ -156,22 +147,21 @@ v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
|||
return handle;
|
||||
}
|
||||
|
||||
base::DictionaryValue request;
|
||||
base::Value::Dict request;
|
||||
int request_id = ++previous_request_id_;
|
||||
pending_requests_.emplace(request_id, std::move(promise));
|
||||
request.SetInteger("id", request_id);
|
||||
request.SetString("method", method);
|
||||
if (!command_params.DictEmpty()) {
|
||||
request.Set("params",
|
||||
base::Value::ToUniquePtrValue(command_params.Clone()));
|
||||
request.Set("id", request_id);
|
||||
request.Set("method", method);
|
||||
if (!command_params.empty()) {
|
||||
request.Set("params", base::Value(std::move(command_params)));
|
||||
}
|
||||
|
||||
if (!session_id.empty()) {
|
||||
request.SetString("sessionId", session_id);
|
||||
request.Set("sessionId", session_id);
|
||||
}
|
||||
|
||||
std::string json_args;
|
||||
base::JSONWriter::Write(request, &json_args);
|
||||
base::JSONWriter::Write(base::Value(std::move(request)), &json_args);
|
||||
agent_host_->DispatchProtocolMessage(
|
||||
this, base::as_bytes(base::make_span(json_args)));
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class Debugger : public gin::Wrappable<Debugger>,
|
|||
|
||||
private:
|
||||
using PendingRequestMap =
|
||||
std::map<int, gin_helper::Promise<base::DictionaryValue>>;
|
||||
std::map<int, gin_helper::Promise<base::Value::Dict>>;
|
||||
|
||||
void Attach(gin::Arguments* args);
|
||||
bool IsAttached();
|
||||
|
|
|
@ -1160,7 +1160,7 @@ gin::Handle<Session> Session::CreateFrom(
|
|||
// static
|
||||
gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
|
||||
const std::string& partition,
|
||||
base::DictionaryValue options) {
|
||||
base::Value::Dict options) {
|
||||
ElectronBrowserContext* browser_context;
|
||||
if (partition.empty()) {
|
||||
browser_context =
|
||||
|
@ -1265,7 +1265,7 @@ v8::Local<v8::Value> FromPartition(const std::string& partition,
|
|||
args->ThrowTypeError("Session can only be received when app is ready");
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
base::DictionaryValue options;
|
||||
base::Value::Dict options;
|
||||
args->GetNext(&options);
|
||||
return Session::FromPartition(args->isolate(), partition, std::move(options))
|
||||
.ToV8();
|
||||
|
|
|
@ -75,10 +75,9 @@ class Session : public gin::Wrappable<Session>,
|
|||
static Session* FromBrowserContext(content::BrowserContext* context);
|
||||
|
||||
// Gets the Session of |partition|.
|
||||
static gin::Handle<Session> FromPartition(
|
||||
v8::Isolate* isolate,
|
||||
const std::string& partition,
|
||||
base::DictionaryValue options = base::DictionaryValue());
|
||||
static gin::Handle<Session> FromPartition(v8::Isolate* isolate,
|
||||
const std::string& partition,
|
||||
base::Value::Dict options = {});
|
||||
|
||||
ElectronBrowserContext* browser_context() const { return browser_context_; }
|
||||
|
||||
|
|
|
@ -72,18 +72,18 @@ class SystemPreferences
|
|||
void(const std::string&, base::Value, const std::string&)>;
|
||||
|
||||
void PostNotification(const std::string& name,
|
||||
base::DictionaryValue user_info,
|
||||
base::Value::Dict user_info,
|
||||
gin::Arguments* args);
|
||||
int SubscribeNotification(v8::Local<v8::Value> maybe_name,
|
||||
const NotificationCallback& callback);
|
||||
void UnsubscribeNotification(int id);
|
||||
void PostLocalNotification(const std::string& name,
|
||||
base::DictionaryValue user_info);
|
||||
base::Value::Dict user_info);
|
||||
int SubscribeLocalNotification(v8::Local<v8::Value> maybe_name,
|
||||
const NotificationCallback& callback);
|
||||
void UnsubscribeLocalNotification(int request_id);
|
||||
void PostWorkspaceNotification(const std::string& name,
|
||||
base::DictionaryValue user_info);
|
||||
base::Value::Dict user_info);
|
||||
int SubscribeWorkspaceNotification(v8::Local<v8::Value> maybe_name,
|
||||
const NotificationCallback& callback);
|
||||
void UnsubscribeWorkspaceNotification(int request_id);
|
||||
|
|
|
@ -138,7 +138,7 @@ NSNotificationCenter* GetNotificationCenter(NotificationCenterKind kind) {
|
|||
} // namespace
|
||||
|
||||
void SystemPreferences::PostNotification(const std::string& name,
|
||||
base::DictionaryValue user_info,
|
||||
base::Value::Dict user_info,
|
||||
gin::Arguments* args) {
|
||||
bool immediate = false;
|
||||
args->GetNext(&immediate);
|
||||
|
@ -148,7 +148,7 @@ void SystemPreferences::PostNotification(const std::string& name,
|
|||
[center
|
||||
postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info.GetDict())
|
||||
userInfo:DictionaryValueToNSDictionary(std::move(user_info))
|
||||
deliverImmediately:immediate];
|
||||
}
|
||||
|
||||
|
@ -166,12 +166,12 @@ void SystemPreferences::UnsubscribeNotification(int request_id) {
|
|||
}
|
||||
|
||||
void SystemPreferences::PostLocalNotification(const std::string& name,
|
||||
base::DictionaryValue user_info) {
|
||||
base::Value::Dict user_info) {
|
||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||
[center
|
||||
postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info.GetDict())];
|
||||
userInfo:DictionaryValueToNSDictionary(std::move(user_info))];
|
||||
}
|
||||
|
||||
int SystemPreferences::SubscribeLocalNotification(
|
||||
|
@ -186,15 +186,14 @@ void SystemPreferences::UnsubscribeLocalNotification(int request_id) {
|
|||
NotificationCenterKind::kNSNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::PostWorkspaceNotification(
|
||||
const std::string& name,
|
||||
base::DictionaryValue user_info) {
|
||||
void SystemPreferences::PostWorkspaceNotification(const std::string& name,
|
||||
base::Value::Dict user_info) {
|
||||
NSNotificationCenter* center =
|
||||
[[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
[center
|
||||
postNotificationName:base::SysUTF8ToNSString(name)
|
||||
object:nil
|
||||
userInfo:DictionaryValueToNSDictionary(user_info.GetDict())];
|
||||
userInfo:DictionaryValueToNSDictionary(std::move(user_info))];
|
||||
}
|
||||
|
||||
int SystemPreferences::SubscribeWorkspaceNotification(
|
||||
|
@ -246,7 +245,7 @@ int SystemPreferences::DoSubscribeNotification(
|
|||
} else {
|
||||
copied_callback.Run(
|
||||
base::SysNSStringToUTF8(notification.name),
|
||||
base::DictionaryValue(), object);
|
||||
base::Value(base::Value::Dict()), object);
|
||||
}
|
||||
}];
|
||||
return request_id;
|
||||
|
@ -295,24 +294,24 @@ v8::Local<v8::Value> SystemPreferences::GetUserDefault(
|
|||
}
|
||||
|
||||
void SystemPreferences::RegisterDefaults(gin::Arguments* args) {
|
||||
base::DictionaryValue value;
|
||||
base::Value::Dict value;
|
||||
|
||||
if (!args->GetNext(&value)) {
|
||||
args->ThrowError();
|
||||
} else {
|
||||
@try {
|
||||
NSDictionary* dict = DictionaryValueToNSDictionary(value.GetDict());
|
||||
for (id key in dict) {
|
||||
id value = [dict objectForKey:key];
|
||||
if ([value isKindOfClass:[NSNull class]] || value == nil) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@try {
|
||||
NSDictionary* dict = DictionaryValueToNSDictionary(std::move(value));
|
||||
for (id key in dict) {
|
||||
id value = [dict objectForKey:key];
|
||||
if ([value isKindOfClass:[NSNull class]] || value == nil) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||
} @catch (NSException* exception) {
|
||||
args->ThrowError();
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||
} @catch (NSException* exception) {
|
||||
args->ThrowError();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ class Browser : public WindowListObserver {
|
|||
|
||||
// Creates an activity and sets it as the one currently in use.
|
||||
void SetUserActivity(const std::string& type,
|
||||
base::DictionaryValue user_info,
|
||||
base::Value::Dict user_info,
|
||||
gin::Arguments* args);
|
||||
|
||||
// Returns the type name of the current user activity.
|
||||
|
@ -180,7 +180,7 @@ class Browser : public WindowListObserver {
|
|||
|
||||
// Updates the current user activity
|
||||
void UpdateCurrentActivity(const std::string& type,
|
||||
base::DictionaryValue user_info);
|
||||
base::Value::Dict user_info);
|
||||
|
||||
// Indicates that an user activity is about to be resumed.
|
||||
bool WillContinueUserActivity(const std::string& type);
|
||||
|
@ -231,7 +231,7 @@ class Browser : public WindowListObserver {
|
|||
#endif // BUILDFLAG(IS_MAC)
|
||||
|
||||
void ShowAboutPanel();
|
||||
void SetAboutPanelOptions(base::DictionaryValue options);
|
||||
void SetAboutPanelOptions(base::Value::Dict options);
|
||||
|
||||
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
|
||||
void ShowEmojiPanel();
|
||||
|
|
|
@ -224,8 +224,8 @@ void Browser::ShowAboutPanel() {
|
|||
gtk_widget_destroy(dialogWidget);
|
||||
}
|
||||
|
||||
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
|
||||
about_panel_options_ = std::move(options);
|
||||
void Browser::SetAboutPanelOptions(base::Value::Dict options) {
|
||||
about_panel_options_ = base::Value(std::move(options));
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -235,14 +235,14 @@ bool Browser::SetBadgeCount(absl::optional<int> count) {
|
|||
}
|
||||
|
||||
void Browser::SetUserActivity(const std::string& type,
|
||||
base::DictionaryValue user_info,
|
||||
base::Value::Dict user_info,
|
||||
gin::Arguments* args) {
|
||||
std::string url_string;
|
||||
args->GetNext(&url_string);
|
||||
|
||||
[[AtomApplication sharedApplication]
|
||||
setCurrentActivity:base::SysUTF8ToNSString(type)
|
||||
withUserInfo:DictionaryValueToNSDictionary(user_info.GetDict())
|
||||
withUserInfo:DictionaryValueToNSDictionary(std::move(user_info))
|
||||
withWebpageURL:net::NSURLWithGURL(GURL(url_string))];
|
||||
}
|
||||
|
||||
|
@ -261,10 +261,11 @@ void Browser::ResignCurrentActivity() {
|
|||
}
|
||||
|
||||
void Browser::UpdateCurrentActivity(const std::string& type,
|
||||
base::DictionaryValue user_info) {
|
||||
base::Value::Dict user_info) {
|
||||
[[AtomApplication sharedApplication]
|
||||
updateCurrentActivity:base::SysUTF8ToNSString(type)
|
||||
withUserInfo:DictionaryValueToNSDictionary(user_info.GetDict())];
|
||||
withUserInfo:DictionaryValueToNSDictionary(
|
||||
std::move(user_info))];
|
||||
}
|
||||
|
||||
bool Browser::WillContinueUserActivity(const std::string& type) {
|
||||
|
@ -511,11 +512,11 @@ void Browser::ShowAboutPanel() {
|
|||
orderFrontStandardAboutPanelWithOptions:options];
|
||||
}
|
||||
|
||||
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
|
||||
void Browser::SetAboutPanelOptions(base::Value::Dict options) {
|
||||
about_panel_options_.DictClear();
|
||||
|
||||
for (const auto pair : options.DictItems()) {
|
||||
std::string key = std::string(pair.first);
|
||||
for (const auto pair : options) {
|
||||
std::string key = pair.first;
|
||||
if (!key.empty() && pair.second.is_string()) {
|
||||
key[0] = base::ToUpperASCII(key[0]);
|
||||
auto val = std::make_unique<base::Value>(pair.second.Clone());
|
||||
|
|
|
@ -851,8 +851,8 @@ void Browser::ShowAboutPanel() {
|
|||
electron::ShowMessageBoxSync(settings);
|
||||
}
|
||||
|
||||
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
|
||||
about_panel_options_ = std::move(options);
|
||||
void Browser::SetAboutPanelOptions(base::Value::Dict options) {
|
||||
about_panel_options_ = base::Value(std::move(options));
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -103,7 +103,7 @@ ElectronBrowserContext::browser_context_map() {
|
|||
|
||||
ElectronBrowserContext::ElectronBrowserContext(const std::string& partition,
|
||||
bool in_memory,
|
||||
base::DictionaryValue options)
|
||||
base::Value::Dict options)
|
||||
: storage_policy_(base::MakeRefCounted<SpecialStoragePolicy>()),
|
||||
protocol_registry_(base::WrapUnique(new ProtocolRegistry)),
|
||||
in_memory_(in_memory),
|
||||
|
@ -111,7 +111,7 @@ ElectronBrowserContext::ElectronBrowserContext(const std::string& partition,
|
|||
// Read options.
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
use_cache_ = !command_line->HasSwitch(switches::kDisableHttpCache);
|
||||
if (auto use_cache_opt = options.FindBoolKey("cache")) {
|
||||
if (auto use_cache_opt = options.FindBool("cache")) {
|
||||
use_cache_ = use_cache_opt.value();
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ bool ElectronBrowserContext::CheckDevicePermission(
|
|||
ElectronBrowserContext* ElectronBrowserContext::From(
|
||||
const std::string& partition,
|
||||
bool in_memory,
|
||||
base::DictionaryValue options) {
|
||||
base::Value::Dict options) {
|
||||
PartitionKey key(partition, in_memory);
|
||||
ElectronBrowserContext* browser_context = browser_context_map()[key].get();
|
||||
if (browser_context) {
|
||||
|
|
|
@ -44,7 +44,6 @@ using DevicePermissionMap =
|
|||
std::map<blink::PermissionType,
|
||||
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>;
|
||||
|
||||
class ElectronBrowserContext;
|
||||
class ElectronDownloadManagerDelegate;
|
||||
class ElectronPermissionManager;
|
||||
class CookieChangeNotifier;
|
||||
|
@ -82,10 +81,9 @@ class ElectronBrowserContext : public content::BrowserContext {
|
|||
// Get or create the BrowserContext according to its |partition| and
|
||||
// |in_memory|. The |options| will be passed to constructor when there is no
|
||||
// existing BrowserContext.
|
||||
static ElectronBrowserContext* From(
|
||||
const std::string& partition,
|
||||
bool in_memory,
|
||||
base::DictionaryValue options = base::DictionaryValue());
|
||||
static ElectronBrowserContext* From(const std::string& partition,
|
||||
bool in_memory,
|
||||
base::Value::Dict options = {});
|
||||
|
||||
static BrowserContextMap& browser_context_map();
|
||||
|
||||
|
@ -177,7 +175,7 @@ class ElectronBrowserContext : public content::BrowserContext {
|
|||
private:
|
||||
ElectronBrowserContext(const std::string& partition,
|
||||
bool in_memory,
|
||||
base::DictionaryValue options);
|
||||
base::Value::Dict options);
|
||||
|
||||
// Initialize pref registry.
|
||||
void InitPrefs();
|
||||
|
|
|
@ -658,9 +658,8 @@ void NativeWindow::NotifyWindowExecuteAppCommand(const std::string& command) {
|
|||
observer.OnExecuteAppCommand(command);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyTouchBarItemInteraction(
|
||||
const std::string& item_id,
|
||||
const base::DictionaryValue& details) {
|
||||
void NativeWindow::NotifyTouchBarItemInteraction(const std::string& item_id,
|
||||
base::Value::Dict details) {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnTouchBarItemResult(item_id, details);
|
||||
}
|
||||
|
|
|
@ -304,7 +304,7 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void NotifyWindowAlwaysOnTopChanged();
|
||||
void NotifyWindowExecuteAppCommand(const std::string& command);
|
||||
void NotifyTouchBarItemInteraction(const std::string& item_id,
|
||||
const base::DictionaryValue& details);
|
||||
base::Value::Dict details);
|
||||
void NotifyNewWindowForTab();
|
||||
void NotifyWindowSystemContextMenu(int x, int y, bool* prevent_default);
|
||||
void NotifyLayoutWindowControlsOverlay();
|
||||
|
|
|
@ -93,7 +93,7 @@ class NativeWindowObserver : public base::CheckedObserver {
|
|||
virtual void OnWindowLeaveHtmlFullScreen() {}
|
||||
virtual void OnWindowAlwaysOnTopChanged() {}
|
||||
virtual void OnTouchBarItemResult(const std::string& item_id,
|
||||
const base::DictionaryValue& details) {}
|
||||
const base::Value::Dict& details) {}
|
||||
virtual void OnNewWindowForTab() {}
|
||||
virtual void OnSystemContextMenu(int x, int y, bool* prevent_default) {}
|
||||
|
||||
|
|
|
@ -114,9 +114,9 @@ network::mojom::URLResponseHeadPtr ToResponseHead(
|
|||
bool has_mime_type = dict.Get("mimeType", &head->mime_type);
|
||||
bool has_content_type = false;
|
||||
|
||||
base::DictionaryValue headers;
|
||||
base::Value::Dict headers;
|
||||
if (dict.Get("headers", &headers)) {
|
||||
for (const auto iter : headers.DictItems()) {
|
||||
for (const auto iter : headers) {
|
||||
if (iter.second.is_string()) {
|
||||
// key, value
|
||||
head->headers->AddHeader(iter.first, iter.second.GetString());
|
||||
|
@ -513,7 +513,7 @@ void ElectronURLLoaderFactory::StartLoadingHttp(
|
|||
if (!dict.Get("method", &request->method))
|
||||
request->method = original_request.method;
|
||||
|
||||
base::DictionaryValue upload_data;
|
||||
base::Value::Dict upload_data;
|
||||
if (request->method != net::HttpRequestHeaders::kGetMethod &&
|
||||
request->method != net::HttpRequestHeaders::kHeadMethod)
|
||||
dict.Get("uploadData", &upload_data);
|
||||
|
|
|
@ -19,7 +19,7 @@ URLPipeLoader::URLPipeLoader(
|
|||
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
||||
const net::NetworkTrafficAnnotationTag& annotation,
|
||||
base::DictionaryValue upload_data)
|
||||
base::Value::Dict upload_data)
|
||||
: url_loader_(this, std::move(loader)), client_(std::move(client)) {
|
||||
url_loader_.set_disconnect_handler(base::BindOnce(
|
||||
&URLPipeLoader::NotifyComplete, base::Unretained(this), net::ERR_FAILED));
|
||||
|
@ -37,17 +37,17 @@ void URLPipeLoader::Start(
|
|||
scoped_refptr<network::SharedURLLoaderFactory> factory,
|
||||
std::unique_ptr<network::ResourceRequest> request,
|
||||
const net::NetworkTrafficAnnotationTag& annotation,
|
||||
base::DictionaryValue upload_data) {
|
||||
base::Value::Dict upload_data) {
|
||||
loader_ = network::SimpleURLLoader::Create(std::move(request), annotation);
|
||||
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
||||
&URLPipeLoader::OnResponseStarted, weak_factory_.GetWeakPtr()));
|
||||
|
||||
// TODO(zcbenz): The old protocol API only supports string as upload data,
|
||||
// we should seek to support more types in future.
|
||||
std::string content_type, data;
|
||||
if (upload_data.GetString("contentType", &content_type) &&
|
||||
upload_data.GetString("data", &data))
|
||||
loader_->AttachStringForUpload(data, content_type);
|
||||
std::string* content_type = upload_data.FindString("contentType");
|
||||
std::string* data = upload_data.FindString("data");
|
||||
if (content_type && data)
|
||||
loader_->AttachStringForUpload(*data, *content_type);
|
||||
|
||||
loader_->DownloadAsStream(factory.get(), this);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class URLPipeLoader : public network::mojom::URLLoader,
|
|||
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
||||
const net::NetworkTrafficAnnotationTag& annotation,
|
||||
base::DictionaryValue upload_data);
|
||||
base::Value::Dict upload_data);
|
||||
|
||||
// disable copy
|
||||
URLPipeLoader(const URLPipeLoader&) = delete;
|
||||
|
@ -51,7 +51,7 @@ class URLPipeLoader : public network::mojom::URLLoader,
|
|||
void Start(scoped_refptr<network::SharedURLLoaderFactory> factory,
|
||||
std::unique_ptr<network::ResourceRequest> request,
|
||||
const net::NetworkTrafficAnnotationTag& annotation,
|
||||
base::DictionaryValue upload_data);
|
||||
base::Value::Dict upload_data);
|
||||
void NotifyComplete(int result);
|
||||
void OnResponseStarted(const GURL& final_url,
|
||||
const network::mojom::URLResponseHead& response_head);
|
||||
|
|
|
@ -241,8 +241,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
- (void)buttonAction:(id)sender {
|
||||
NSString* item_id =
|
||||
[NSString stringWithFormat:@"%ld", ((NSButton*)sender).tag];
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String],
|
||||
base::DictionaryValue());
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String], {});
|
||||
}
|
||||
|
||||
- (void)colorPickerAction:(id)sender {
|
||||
|
@ -252,19 +251,20 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
NSColor* color = ((NSColorPickerTouchBarItem*)sender).color;
|
||||
std::string hex_color =
|
||||
electron::ToRGBHex(skia::NSDeviceColorToSkColor(color));
|
||||
base::DictionaryValue details;
|
||||
details.SetString("color", hex_color);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String], details);
|
||||
base::Value::Dict details;
|
||||
details.Set("color", hex_color);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String],
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
- (void)sliderAction:(id)sender {
|
||||
NSString* identifier = ((NSSliderTouchBarItem*)sender).identifier;
|
||||
NSString* item_id = [self idFromIdentifier:identifier
|
||||
withPrefix:SliderIdentifier];
|
||||
base::DictionaryValue details;
|
||||
details.SetInteger("value",
|
||||
[((NSSliderTouchBarItem*)sender).slider intValue]);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String], details);
|
||||
base::Value::Dict details;
|
||||
details.Set("value", [((NSSliderTouchBarItem*)sender).slider intValue]);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String],
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
- (NSString*)idFromIdentifier:(NSString*)identifier
|
||||
|
@ -275,32 +275,33 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
|||
- (void)segmentedControlAction:(id)sender {
|
||||
NSString* item_id =
|
||||
[NSString stringWithFormat:@"%ld", ((NSSegmentedControl*)sender).tag];
|
||||
base::DictionaryValue details;
|
||||
details.SetInteger("selectedIndex",
|
||||
((NSSegmentedControl*)sender).selectedSegment);
|
||||
details.SetBoolean(
|
||||
base::Value::Dict details;
|
||||
details.Set("selectedIndex",
|
||||
static_cast<int>(((NSSegmentedControl*)sender).selectedSegment));
|
||||
details.Set(
|
||||
"isSelected",
|
||||
[((NSSegmentedControl*)sender)
|
||||
isSelectedForSegment:((NSSegmentedControl*)sender).selectedSegment]);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String], details);
|
||||
window_->NotifyTouchBarItemInteraction([item_id UTF8String],
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
- (void)scrubber:(NSScrubber*)scrubber
|
||||
didSelectItemAtIndex:(NSInteger)selectedIndex {
|
||||
base::DictionaryValue details;
|
||||
details.SetInteger("selectedIndex", selectedIndex);
|
||||
details.SetString("type", "select");
|
||||
base::Value::Dict details;
|
||||
details.Set("selectedIndex", static_cast<int>(selectedIndex));
|
||||
details.Set("type", "select");
|
||||
window_->NotifyTouchBarItemInteraction([scrubber.identifier UTF8String],
|
||||
details);
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
- (void)scrubber:(NSScrubber*)scrubber
|
||||
didHighlightItemAtIndex:(NSInteger)highlightedIndex {
|
||||
base::DictionaryValue details;
|
||||
details.SetInteger("highlightedIndex", highlightedIndex);
|
||||
details.SetString("type", "highlight");
|
||||
base::Value::Dict details;
|
||||
details.Set("highlightedIndex", static_cast<int>(highlightedIndex));
|
||||
details.Set("type", "highlight");
|
||||
window_->NotifyTouchBarItemInteraction([scrubber.identifier UTF8String],
|
||||
details);
|
||||
std::move(details));
|
||||
}
|
||||
|
||||
- (NSTouchBarItemIdentifier)identifierFromID:(const std::string&)item_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue