clang-format objc files (#12673)
This commit is contained in:
parent
94236bf4eb
commit
12a57ff1c2
54 changed files with 1298 additions and 1033 deletions
|
@ -20,16 +20,19 @@ NSData* bufferFromNSImage(NSImage* image) {
|
|||
CGImageRef ref = [image CGImageForProposedRect:nil context:nil hints:nil];
|
||||
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCGImage:ref];
|
||||
[rep setSize:[image size]];
|
||||
return [rep representationUsingType:NSPNGFileType properties:[[NSDictionary alloc] init]];
|
||||
return [rep representationUsingType:NSPNGFileType
|
||||
properties:[[NSDictionary alloc] init]];
|
||||
}
|
||||
|
||||
double safeShift(double in, double def) {
|
||||
if (in >= 0 || in <= 1 || in == def) return in;
|
||||
if (in >= 0 || in <= 1 || in == def)
|
||||
return in;
|
||||
return def;
|
||||
}
|
||||
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||
mate::Arguments* args, const std::string& name) {
|
||||
mate::Arguments* args,
|
||||
const std::string& name) {
|
||||
@autoreleasepool {
|
||||
std::vector<double> hsl_shift;
|
||||
NSImage* image = [NSImage imageNamed:base::SysUTF8ToNSString(name)];
|
||||
|
@ -41,18 +44,19 @@ mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
|||
|
||||
if (args->GetNext(&hsl_shift) && hsl_shift.size() == 3) {
|
||||
gfx::Image gfx_image = gfx::Image::CreateFrom1xPNGBytes(
|
||||
reinterpret_cast<const unsigned char*>((char *) [png_data bytes]), [png_data length]);
|
||||
color_utils::HSL shift = {
|
||||
safeShift(hsl_shift[0], -1),
|
||||
safeShift(hsl_shift[1], 0.5),
|
||||
safeShift(hsl_shift[2], 0.5)
|
||||
};
|
||||
png_data = bufferFromNSImage(gfx::Image(
|
||||
gfx::ImageSkiaOperations::CreateHSLShiftedImage(
|
||||
gfx_image.AsImageSkia(), shift)).CopyNSImage());
|
||||
reinterpret_cast<const unsigned char*>((char*)[png_data bytes]),
|
||||
[png_data length]);
|
||||
color_utils::HSL shift = {safeShift(hsl_shift[0], -1),
|
||||
safeShift(hsl_shift[1], 0.5),
|
||||
safeShift(hsl_shift[2], 0.5)};
|
||||
png_data = bufferFromNSImage(
|
||||
gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage(
|
||||
gfx_image.AsImageSkia(), shift))
|
||||
.CopyNSImage());
|
||||
}
|
||||
|
||||
return CreateFromPNG(args->isolate(), (char *) [png_data bytes], [png_data length]);
|
||||
return CreateFromPNG(args->isolate(), (char*)[png_data bytes],
|
||||
[png_data length]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,11 +20,9 @@
|
|||
|
||||
namespace crash_reporter {
|
||||
|
||||
CrashReporterMac::CrashReporterMac() {
|
||||
}
|
||||
CrashReporterMac::CrashReporterMac() {}
|
||||
|
||||
CrashReporterMac::~CrashReporterMac() {
|
||||
}
|
||||
CrashReporterMac::~CrashReporterMac() {}
|
||||
|
||||
void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
||||
const std::string& version,
|
||||
|
@ -45,17 +43,13 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
|||
framework_bundle_path.Append("Resources").Append("crashpad_handler");
|
||||
|
||||
std::vector<std::string> args = {
|
||||
"--no-rate-limit",
|
||||
"--no-upload-gzip", // not all servers accept gzip
|
||||
"--no-rate-limit",
|
||||
"--no-upload-gzip", // not all servers accept gzip
|
||||
};
|
||||
|
||||
crashpad::CrashpadClient crashpad_client;
|
||||
crashpad_client.StartHandler(handler_path, crashes_dir, crashes_dir,
|
||||
submit_url,
|
||||
StringMap(),
|
||||
args,
|
||||
true,
|
||||
false);
|
||||
submit_url, StringMap(), args, true, false);
|
||||
} // @autoreleasepool
|
||||
}
|
||||
|
||||
|
@ -73,12 +67,11 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
|||
SetCrashKeyValue("process_type", is_browser_ ? "browser" : "renderer");
|
||||
SetCrashKeyValue("ver", version);
|
||||
|
||||
for (const auto& upload_parameter: upload_parameters_) {
|
||||
for (const auto& upload_parameter : upload_parameters_) {
|
||||
SetCrashKeyValue(upload_parameter.first, upload_parameter.second);
|
||||
}
|
||||
if (is_browser_) {
|
||||
database_ =
|
||||
crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
database_ = crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
SetUploadToServer(upload_to_server);
|
||||
}
|
||||
}
|
||||
|
@ -126,9 +119,10 @@ std::map<std::string, std::string> CrashReporterMac::GetParameters() const {
|
|||
if (simple_string_dictionary_) {
|
||||
std::map<std::string, std::string> ret;
|
||||
crashpad::SimpleStringDictionary::Iterator iter(*simple_string_dictionary_);
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
auto* const entry = iter.Next();
|
||||
if (!entry) break;
|
||||
if (!entry)
|
||||
break;
|
||||
ret[entry->key] = entry->value;
|
||||
}
|
||||
return ret;
|
||||
|
@ -148,7 +142,7 @@ CrashReporterMac::GetUploadedReports(const base::FilePath& crashes_dir) {
|
|||
}
|
||||
// Load crashpad database.
|
||||
std::unique_ptr<crashpad::CrashReportDatabase> database =
|
||||
crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
crashpad::CrashReportDatabase::Initialize(crashes_dir);
|
||||
DCHECK(database);
|
||||
|
||||
std::vector<crashpad::CrashReportDatabase::Report> completed_reports;
|
||||
|
@ -168,7 +162,9 @@ CrashReporterMac::GetUploadedReports(const base::FilePath& crashes_dir) {
|
|||
}
|
||||
|
||||
auto sort_by_time = [](const UploadReportResult& a,
|
||||
const UploadReportResult& b) {return a.first >= b.first;};
|
||||
const UploadReportResult& b) {
|
||||
return a.first >= b.first;
|
||||
};
|
||||
std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time);
|
||||
return uploaded_reports;
|
||||
}
|
||||
|
|
|
@ -75,9 +75,7 @@ std::string MessageForOSStatus(OSStatus status, const char* default_message) {
|
|||
std::string OpenURL(NSURL* ns_url, bool activate) {
|
||||
CFURLRef openingApp = nullptr;
|
||||
OSStatus status = LSGetApplicationForURL(base::mac::NSToCFCast(ns_url),
|
||||
kLSRolesAll,
|
||||
nullptr,
|
||||
&openingApp);
|
||||
kLSRolesAll, nullptr, &openingApp);
|
||||
if (status != noErr)
|
||||
return MessageForOSStatus(status, "Failed to open");
|
||||
|
||||
|
@ -87,12 +85,11 @@ std::string OpenURL(NSURL* ns_url, bool activate) {
|
|||
if (!activate)
|
||||
launchOptions |= NSWorkspaceLaunchWithoutActivation;
|
||||
|
||||
bool opened = [[NSWorkspace sharedWorkspace]
|
||||
openURLs:@[ns_url]
|
||||
withAppBundleIdentifier:nil
|
||||
options:launchOptions
|
||||
additionalEventParamDescriptor:nil
|
||||
launchIdentifiers:nil];
|
||||
bool opened = [[NSWorkspace sharedWorkspace] openURLs:@[ ns_url ]
|
||||
withAppBundleIdentifier:nil
|
||||
options:launchOptions
|
||||
additionalEventParamDescriptor:nil
|
||||
launchIdentifiers:nil];
|
||||
if (!opened)
|
||||
return "Failed to open URL";
|
||||
|
||||
|
@ -100,7 +97,8 @@ std::string OpenURL(NSURL* ns_url, bool activate) {
|
|||
}
|
||||
|
||||
NSString* GetLoginHelperBundleIdentifier() {
|
||||
return [[[NSBundle mainBundle] bundleIdentifier] stringByAppendingString:@".loginhelper"];
|
||||
return [[[NSBundle mainBundle] bundleIdentifier]
|
||||
stringByAppendingString:@".loginhelper"];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -135,10 +133,10 @@ bool OpenItem(const base::FilePath& full_path) {
|
|||
const NSWorkspaceLaunchOptions launch_options =
|
||||
NSWorkspaceLaunchAsync | NSWorkspaceLaunchWithErrorPresentation;
|
||||
return [[NSWorkspace sharedWorkspace] openURLs:@[ url ]
|
||||
withAppBundleIdentifier:nil
|
||||
options:launch_options
|
||||
additionalEventParamDescriptor:nil
|
||||
launchIdentifiers:NULL];
|
||||
withAppBundleIdentifier:nil
|
||||
options:launch_options
|
||||
additionalEventParamDescriptor:nil
|
||||
launchIdentifiers:NULL];
|
||||
}
|
||||
|
||||
bool OpenExternal(const GURL& url, bool activate) {
|
||||
|
@ -149,7 +147,8 @@ bool OpenExternal(const GURL& url, bool activate) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void OpenExternal(const GURL& url, bool activate,
|
||||
void OpenExternal(const GURL& url,
|
||||
bool activate,
|
||||
const OpenExternalCallback& callback) {
|
||||
NSURL* ns_url = net::NSURLWithGURL(url);
|
||||
if (!ns_url) {
|
||||
|
@ -158,20 +157,21 @@ void OpenExternal(const GURL& url, bool activate,
|
|||
}
|
||||
|
||||
__block OpenExternalCallback c = callback;
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
__block std::string error = OpenURL(ns_url, activate);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
c.Run(error);
|
||||
});
|
||||
});
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||
^{
|
||||
__block std::string error = OpenURL(ns_url, activate);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
c.Run(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
bool MoveItemToTrash(const base::FilePath& full_path) {
|
||||
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
|
||||
BOOL status = [[NSFileManager defaultManager]
|
||||
trashItemAtURL:[NSURL fileURLWithPath:path_string]
|
||||
resultingItemURL:nil
|
||||
error:nil];
|
||||
trashItemAtURL:[NSURL fileURLWithPath:path_string]
|
||||
resultingItemURL:nil
|
||||
error:nil];
|
||||
if (!path_string || !status)
|
||||
LOG(WARNING) << "NSWorkspace failed to move file " << full_path.value()
|
||||
<< " to trash";
|
||||
|
@ -201,7 +201,7 @@ bool GetLoginItemEnabled() {
|
|||
|
||||
void SetLoginItemEnabled(bool enabled) {
|
||||
NSString* identifier = GetLoginHelperBundleIdentifier();
|
||||
SMLoginItemSetEnabled((__bridge CFStringRef) identifier, enabled);
|
||||
SMLoginItemSetEnabled((__bridge CFStringRef)identifier, enabled);
|
||||
}
|
||||
|
||||
} // namespace platform_util
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue