chore: bump chromium to 117.0.5852.0 (main) (#38891)

* chore: bump chromium in DEPS to 117.0.5846.0

* chore: update patches

* 4628901: Bump the macOS deployment target to 10.15

4628901

* 4593350: [Private Network Access] Trigger Permission Prompt

4593350

* 4631011: Remove unlaunched "InstallReplacementAndroidApp" Platform App APIs

4631011

* chore: disable API deprecation warnings in NSKeyedArchiver

* chore: update libcxx filenames

* chore: bump chromium in DEPS to 117.0.5848.2

* chore: update feat_add_set_theme_source_to_allow_apps_to.patch

Xref: 4629743

No manual changes; patch succeeded with fuzz

* chore: update process_singleton.patch

Xref: 4605398

Trivial manual patch adjustments to account for code shear.

* chore: remove electron::BrowserContext::GetMediaDeviceIDSalt()

Xref: 4608130

upstream tldr:
- content::BrowserContext::GetMediaDeviceIDSalt()
- content::ContentBrowserClient::ArePersistentMediaDeviceIDsAllowed()
+ content::ContentBrowserClient::GetMediaDeviceIDSalt()

This commit leaves ElectronBrowserContext::GetMediaDeviceIDSalt() in
place (now non-virtual, non-override). It is now called by the new
function ElectronBrowserClient::GetMediaDeviceIDSalt().

As a followup, we might want to consider using the new upstream
media_device_salt::MediaDeviceSaltService and removing our
electron::MediaDeviceIDSalt code. CC @MarshallOfSound for 2nd
opinion since he has done the most work on MediaDeviceIDSalt and
may have more context.

* chore: fix iwyu breakage

Xref: 4629624

electron_browser_main_parts.cc uses ui::ColorProviderManager but didn't
include it. Things worked anyway because we got it indirectly from
content/public/browser/web_contents.h until 4629624.

* chore: remove call to base::mac::IsAtLeastOS10_14

upstream has bumped minimum version to 10.15 so this call is moot?

* chore: remove obsolete API_AVAILABLE calls in IAP

upstream has bumped minimum version to 10.15 so this call is moot?

* chore: remove obsolete API_AVAILABLE calls in electron_application_delegate

upstream has bumped minimum version to 10.15 so this call is moot?

* chore: remove broken-before-macOS-10.15 patch in mas_avoid_usage_of_private_macos_apis.patch

Upstream has bumped minimum to macOS 10.15

* chore: remove @available(macOS 10.14) check

Upstream minimum requirement for macOS is now 10.15

* chore: update patches

* chore: bump chromium in DEPS to 117.0.5850.0

* chore: update patches

* chore: bump chromium in DEPS to 117.0.5852.0

* chore: update patches

* Move two params from NetworkContextParams to NetworkContextFilePaths.

4615930

* WebUSB: Add exclusionFilters to USBRequestDeviceOptions

4614682

* Convert /chrome/browser/ui to use ARC

4615920

* fixup! Bump the macOS deployment target to 10.15

* fixup! Bump the macOS deployment target to 10.15

* chore: update libcxx files

* win: Remove 10Glass from Windows10Glass function and var names

4641314

* chore: revert 392e5f43 from chromium

* Add an ExecutionContext to ScriptState

4609446

* fixup! Add an ExecutionContext to ScriptState

* chore: fix header

* Revert "chore: revert 392e5f43 from chromium"

This reverts commit b7f782943e4ce83cae8cd35780d8d3618cf0772c.

* fix: return correct min/max sizes in WinFrameView

* fixup! Revert chore: revert 392e5f43 from chromium

* fixup! Add an ExecutionContext to ScriptState

* Revert "fixup! Revert chore: revert 392e5f43 from chromium"

This reverts commit 7e2c7281abfc4f309255339fdba073d90a9ae3eb.

* Revert "fix: return correct min/max sizes in WinFrameView"

This reverts commit 3f418b1ab5155686730e087ae6cabe4a21b4bb61.

* Revert "Revert "chore: revert 392e5f43 from chromium""

This reverts commit 56296d8b7c434147e032e3c3b08c0e371b6c27ba.

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
electron-roller[bot] 2023-07-01 16:22:55 -04:00 committed by GitHub
parent 499d893040
commit ccd4531bfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
93 changed files with 1054 additions and 652 deletions

View file

@ -29,14 +29,8 @@ namespace {
#if BUILDFLAG(IS_MAC)
bool RegisteringMediaKeyForUntrustedClient(const ui::Accelerator& accelerator) {
if (base::mac::IsAtLeastOS10_14()) {
if (Command::IsMediaKey(accelerator)) {
if (!electron::api::SystemPreferences::IsTrustedAccessibilityClient(
false))
return true;
}
}
return false;
return Command::IsMediaKey(accelerator) &&
!electron::api::SystemPreferences::IsTrustedAccessibilityClient(false);
}
bool MapHasMediaKeys(

View file

@ -109,8 +109,6 @@ struct Converter<in_app_purchase::Product> {
dict.Set("productIdentifier", val.productIdentifier);
dict.Set("localizedDescription", val.localizedDescription);
dict.Set("localizedTitle", val.localizedTitle);
dict.Set("contentVersion", val.contentVersion);
dict.Set("contentLengths", val.contentLengths);
// Pricing Information
dict.Set("price", val.price);

View file

@ -10,23 +10,20 @@ namespace electron::api {
void NativeTheme::UpdateMacOSAppearanceForOverrideValue(
ui::NativeTheme::ThemeSource override) {
if (@available(macOS 10.14, *)) {
NSAppearance* new_appearance;
switch (override) {
case ui::NativeTheme::ThemeSource::kForcedDark:
new_appearance =
[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
break;
case ui::NativeTheme::ThemeSource::kForcedLight:
new_appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
break;
case ui::NativeTheme::ThemeSource::kSystem:
default:
new_appearance = nil;
break;
}
[[NSApplication sharedApplication] setAppearance:new_appearance];
NSAppearance* new_appearance;
switch (override) {
case ui::NativeTheme::ThemeSource::kForcedDark:
new_appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
break;
case ui::NativeTheme::ThemeSource::kForcedLight:
new_appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
break;
case ui::NativeTheme::ThemeSource::kSystem:
default:
new_appearance = nil;
break;
}
[[NSApplication sharedApplication] setAppearance:new_appearance];
}
} // namespace electron::api

View file

@ -51,11 +51,7 @@ struct Converter<NSAppearance*> {
*out = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
return true;
} else if (name == "dark") {
if (@available(macOS 10.14, *)) {
*out = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
} else {
*out = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
}
*out = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
return true;
}
@ -63,17 +59,13 @@ struct Converter<NSAppearance*> {
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, NSAppearance* val) {
if (val == nil) {
if (val == nil)
return v8::Null(isolate);
}
if ([val.name isEqualToString:NSAppearanceNameAqua]) {
return gin::ConvertToV8(isolate, "light");
}
if (@available(macOS 10.14, *)) {
if ([val.name isEqualToString:NSAppearanceNameDarkAqua]) {
return gin::ConvertToV8(isolate, "dark");
}
} else if ([val.name isEqualToString:NSAppearanceNameDarkAqua]) {
return gin::ConvertToV8(isolate, "dark");
}
return gin::ConvertToV8(isolate, "unknown");
@ -382,10 +374,7 @@ void SystemPreferences::SetUserDefault(const std::string& name,
}
std::string SystemPreferences::GetAccentColor() {
NSColor* sysColor = nil;
if (@available(macOS 10.14, *))
sysColor = [NSColor controlAccentColor];
NSColor* sysColor = sysColor = [NSColor controlAccentColor];
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor),
false /* include_hash */);
}
@ -421,14 +410,10 @@ std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
bool SystemPreferences::CanPromptTouchID() {
base::scoped_nsobject<LAContext> context([[LAContext alloc] init]);
LAPolicy auth_policy = LAPolicyDeviceOwnerAuthenticationWithBiometrics;
if (@available(macOS 10.15, *))
auth_policy = LAPolicyDeviceOwnerAuthenticationWithBiometricsOrWatch;
LAPolicy auth_policy = LAPolicyDeviceOwnerAuthenticationWithBiometricsOrWatch;
if (![context canEvaluatePolicy:auth_policy error:nil])
return false;
if (@available(macOS 10.13.2, *))
return [context biometryType] == LABiometryTypeTouchID;
return true;
return [context biometryType] == LABiometryTypeTouchID;
}
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
@ -501,8 +486,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
} else if (color == "disabled-control-text") {
sysColor = [NSColor disabledControlTextColor];
} else if (color == "find-highlight") {
if (@available(macOS 10.14, *))
sysColor = [NSColor findHighlightColor];
sysColor = [NSColor findHighlightColor];
} else if (color == "grid") {
sysColor = [NSColor gridColor];
} else if (color == "header-text") {
@ -524,8 +508,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
} else if (color == "secondary-label") {
sysColor = [NSColor secondaryLabelColor];
} else if (color == "selected-content-background") {
if (@available(macOS 10.14, *))
sysColor = [NSColor selectedContentBackgroundColor];
sysColor = [NSColor selectedContentBackgroundColor];
} else if (color == "selected-control") {
sysColor = [NSColor selectedControlColor];
} else if (color == "selected-control-text") {
@ -537,8 +520,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
} else if (color == "selected-text") {
sysColor = [NSColor selectedTextColor];
} else if (color == "separator") {
if (@available(macOS 10.14, *))
sysColor = [NSColor separatorColor];
sysColor = [NSColor separatorColor];
} else if (color == "shadow") {
sysColor = [NSColor shadowColor];
} else if (color == "tertiary-label") {
@ -550,14 +532,11 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
} else if (color == "under-page-background") {
sysColor = [NSColor underPageBackgroundColor];
} else if (color == "unemphasized-selected-content-background") {
if (@available(macOS 10.14, *))
sysColor = [NSColor unemphasizedSelectedContentBackgroundColor];
sysColor = [NSColor unemphasizedSelectedContentBackgroundColor];
} else if (color == "unemphasized-selected-text-background") {
if (@available(macOS 10.14, *))
sysColor = [NSColor unemphasizedSelectedTextBackgroundColor];
sysColor = [NSColor unemphasizedSelectedTextBackgroundColor];
} else if (color == "unemphasized-selected-text") {
if (@available(macOS 10.14, *))
sysColor = [NSColor unemphasizedSelectedTextColor];
sysColor = [NSColor unemphasizedSelectedTextColor];
} else if (color == "window-background") {
sysColor = [NSColor windowBackgroundColor];
} else if (color == "window-frame-text") {
@ -596,18 +575,13 @@ v8::Local<v8::Promise> SystemPreferences::AskForMediaAccess(
v8::Local<v8::Promise> handle = promise.GetHandle();
if (auto type = ParseMediaType(media_type)) {
if (@available(macOS 10.14, *)) {
__block gin_helper::Promise<bool> p = std::move(promise);
[AVCaptureDevice requestAccessForMediaType:type
completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
p.Resolve(!!granted);
});
}];
} else {
// access always allowed pre-10.14 Mojave
promise.Resolve(true);
}
__block gin_helper::Promise<bool> p = std::move(promise);
[AVCaptureDevice requestAccessForMediaType:type
completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{
p.Resolve(!!granted);
});
}];
} else {
promise.RejectWithErrorMessage("Invalid media type");
}
@ -626,30 +600,22 @@ bool SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled() {
v8::Local<v8::Value> SystemPreferences::GetEffectiveAppearance(
v8::Isolate* isolate) {
if (@available(macOS 10.14, *)) {
return gin::ConvertToV8(
isolate, [NSApplication sharedApplication].effectiveAppearance);
}
return v8::Null(isolate);
return gin::ConvertToV8(
isolate, [NSApplication sharedApplication].effectiveAppearance);
}
v8::Local<v8::Value> SystemPreferences::GetAppLevelAppearance(
v8::Isolate* isolate) {
if (@available(macOS 10.14, *)) {
return gin::ConvertToV8(isolate,
[NSApplication sharedApplication].appearance);
}
return v8::Null(isolate);
return gin::ConvertToV8(isolate,
[NSApplication sharedApplication].appearance);
}
void SystemPreferences::SetAppLevelAppearance(gin::Arguments* args) {
if (@available(macOS 10.14, *)) {
NSAppearance* appearance;
if (args->GetNext(&appearance)) {
[[NSApplication sharedApplication] setAppearance:appearance];
} else {
args->ThrowError();
}
NSAppearance* appearance;
if (args->GetNext(&appearance)) {
[[NSApplication sharedApplication] setAppearance:appearance];
} else {
args->ThrowError();
}
}

View file

@ -90,6 +90,12 @@ class SimpleURLLoaderWrapper
const scoped_refptr<net::SSLCertRequestInfo>& cert_info,
mojo::PendingRemote<network::mojom::ClientCertificateResponder>
client_cert_responder) override {}
void OnPrivateNetworkAccessPermissionRequired(
const GURL& url,
const net::IPAddress& ip_address,
const std::string& private_network_device_id,
const std::string& private_network_device_name,
OnPrivateNetworkAccessPermissionRequiredCallback callback) override {}
void OnClearSiteData(
const GURL& url,
const std::string& header_value,

View file

@ -179,7 +179,11 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
CFStringRef protocol_cf = base::mac::NSToCFCast(protocol_ns);
// TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CFArrayRef bundleList = LSCopyAllHandlersForURLScheme(protocol_cf);
#pragma clang diagnostic pop
if (!bundleList) {
return false;
}
@ -229,9 +233,12 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
// TODO(codebytere): Use -[NSWorkspace URLForApplicationToOpenURL:] instead
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
base::ScopedCFTypeRef<CFStringRef> bundleId(
LSCopyDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns)));
#pragma clang diagnostic pop
if (!bundleId)
return false;

View file

@ -759,12 +759,17 @@ bool ElectronBrowserClient::ShouldUseProcessPerSite(
#endif
}
bool ElectronBrowserClient::ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& scope,
void ElectronBrowserClient::GetMediaDeviceIDSalt(
content::RenderFrameHost* rfh,
const net::SiteForCookies& site_for_cookies,
const absl::optional<url::Origin>& top_frame_origin) {
return true;
const blink::StorageKey& storage_key,
base::OnceCallback<void(bool, const std::string&)> callback) {
constexpr bool persistent_media_device_id_allowed = true;
std::string persistent_media_device_id_salt =
static_cast<ElectronBrowserContext*>(rfh->GetBrowserContext())
->GetMediaDeviceIDSalt();
std::move(callback).Run(persistent_media_device_id_allowed,
persistent_media_device_id_salt);
}
base::FilePath ElectronBrowserClient::GetLoggingFileName(

View file

@ -287,11 +287,11 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
const GURL& site_url) override;
bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
const GURL& effective_url) override;
bool ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& scope,
void GetMediaDeviceIDSalt(
content::RenderFrameHost* rfh,
const net::SiteForCookies& site_for_cookies,
const absl::optional<url::Origin>& top_frame_origin) override;
const blink::StorageKey& storage_key,
base::OnceCallback<void(bool, const std::string&)> callback) override;
base::FilePath GetLoggingFileName(const base::CommandLine& cmd_line) override;
// content::RenderProcessHostObserver:

View file

@ -140,6 +140,8 @@ class ElectronBrowserContext : public content::BrowserContext {
predictors::PreconnectManager* GetPreconnectManager();
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory();
std::string GetMediaDeviceIDSalt();
// content::BrowserContext:
base::FilePath GetPath() override;
bool IsOffTheRecord() override;
@ -152,7 +154,6 @@ class ElectronBrowserContext : public content::BrowserContext {
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
std::string GetMediaDeviceIDSalt() override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
content::PlatformNotificationService* GetPlatformNotificationService()

View file

@ -67,6 +67,7 @@
#include "ui/base/idle/idle.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_switches.h"
#include "ui/color/color_provider_manager.h"
#if defined(USE_AURA)
#include "ui/display/display.h"

View file

@ -164,23 +164,6 @@ void ElectronManagementAPIDelegate::InstallOrLaunchReplacementWebApp(
// TODO(sentialx)
}
bool ElectronManagementAPIDelegate::CanContextInstallAndroidApps(
content::BrowserContext* context) const {
return false;
}
void ElectronManagementAPIDelegate::CheckAndroidAppInstallStatus(
const std::string& package_name,
AndroidAppInstallStatusCallback callback) const {
std::move(callback).Run(false);
}
void ElectronManagementAPIDelegate::InstallReplacementAndroidApp(
const std::string& package_name,
InstallAndroidAppCallback callback) const {
std::move(callback).Run(false);
}
void ElectronManagementAPIDelegate::EnableExtension(
content::BrowserContext* context,
const std::string& extension_id) const {

View file

@ -54,15 +54,6 @@ class ElectronManagementAPIDelegate : public extensions::ManagementAPIDelegate {
const GURL& web_app_url,
ManagementAPIDelegate::InstallOrLaunchWebAppCallback callback)
const override;
bool CanContextInstallAndroidApps(
content::BrowserContext* context) const override;
void CheckAndroidAppInstallStatus(
const std::string& package_name,
ManagementAPIDelegate::AndroidAppInstallStatusCallback callback)
const override;
void InstallReplacementAndroidApp(
const std::string& package_name,
ManagementAPIDelegate::InstallAndroidAppCallback callback) const override;
void EnableExtension(content::BrowserContext* context,
const std::string& extension_id) const override;
void DisableExtension(

View file

@ -24,7 +24,7 @@
#endif
static NSDictionary* UNNotificationResponseToNSDictionary(
UNNotificationResponse* response) API_AVAILABLE(macosx(10.14)) {
UNNotificationResponse* response) {
if (![response respondsToSelector:@selector(actionIdentifier)] ||
![response respondsToSelector:@selector(notification)]) {
return nil;
@ -82,7 +82,7 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
if ([user_notification isKindOfClass:[NSUserNotification class]]) {
notification_info =
[static_cast<NSUserNotification*>(user_notification) userInfo];
} else if (@available(macOS 10.14, *)) {
} else {
notification_info = UNNotificationResponseToNSDictionary(
static_cast<UNNotificationResponse*>(user_notification));
}

View file

@ -99,7 +99,7 @@ using InAppTransactionCallback = base::RepeatingCallback<void(
* @param paymentDiscount - The SKPaymentDiscount object to convert.
*/
- (in_app_purchase::PaymentDiscount)skPaymentDiscountToStruct:
(SKPaymentDiscount*)paymentDiscount API_AVAILABLE(macosx(10.14.4)) {
(SKPaymentDiscount*)paymentDiscount {
in_app_purchase::PaymentDiscount paymentDiscountStruct;
paymentDiscountStruct.identifier = [paymentDiscount.identifier UTF8String];
@ -133,11 +133,9 @@ using InAppTransactionCallback = base::RepeatingCallback<void(
[payment.applicationUsername UTF8String];
}
if (@available(macOS 10.14.4, *)) {
if (payment.paymentDiscount != nil) {
paymentStruct.paymentDiscount =
[self skPaymentDiscountToStruct:payment.paymentDiscount];
}
if (payment.paymentDiscount != nil) {
paymentStruct.paymentDiscount =
[self skPaymentDiscountToStruct:payment.paymentDiscount];
}
return paymentStruct;

View file

@ -45,8 +45,6 @@ struct Product {
// Product Attributes
std::string localizedDescription;
std::string localizedTitle;
std::string contentVersion;
std::vector<uint32_t> contentLengths;
// Pricing Information
double price = 0.0;

View file

@ -114,8 +114,7 @@
*/
- (in_app_purchase::ProductSubscriptionPeriod)
skProductSubscriptionPeriodToStruct:
(SKProductSubscriptionPeriod*)productSubscriptionPeriod
API_AVAILABLE(macosx(10.13.2)) {
(SKProductSubscriptionPeriod*)productSubscriptionPeriod {
in_app_purchase::ProductSubscriptionPeriod productSubscriptionPeriodStruct;
productSubscriptionPeriodStruct.numberOfUnits =
@ -140,7 +139,7 @@
* @param productDiscount - The SKProductDiscount object to convert.
*/
- (in_app_purchase::ProductDiscount)skProductDiscountToStruct:
(SKProductDiscount*)productDiscount API_AVAILABLE(macosx(10.13.2)) {
(SKProductDiscount*)productDiscount {
in_app_purchase::ProductDiscount productDiscountStruct;
if (productDiscount.paymentMode == SKProductDiscountPaymentModePayAsYouGo) {
@ -166,14 +165,11 @@
skProductSubscriptionPeriodToStruct:productDiscount.subscriptionPeriod];
}
if (@available(macOS 10.14.4, *)) {
productDiscountStruct.type = (int)productDiscount.type;
if (productDiscount.identifier != nil) {
productDiscountStruct.identifier =
[productDiscount.identifier UTF8String];
}
productDiscountStruct.price = [productDiscount.price doubleValue];
productDiscountStruct.type = (int)productDiscount.type;
if (productDiscount.identifier != nil) {
productDiscountStruct.identifier = [productDiscount.identifier UTF8String];
}
productDiscountStruct.price = [productDiscount.price doubleValue];
return productDiscountStruct;
}
@ -199,16 +195,6 @@
if (product.localizedTitle != nil) {
productStruct.localizedTitle = [product.localizedTitle UTF8String];
}
if (product.contentVersion != nil) {
productStruct.contentVersion = [product.contentVersion UTF8String];
}
if (product.contentLengths != nil) {
productStruct.contentLengths.reserve([product.contentLengths count]);
for (NSNumber* contentLength in product.contentLengths) {
productStruct.contentLengths.push_back([contentLength longLongValue]);
}
}
// Pricing Information
if (product.price != nil) {
@ -226,62 +212,45 @@
}
}
}
if (@available(macOS 10.13.2, *)) {
if (product.introductoryPrice != nil) {
productStruct.introductoryPrice =
[self skProductDiscountToStruct:product.introductoryPrice];
}
if (product.subscriptionPeriod != nil) {
productStruct.subscriptionPeriod =
[self skProductSubscriptionPeriodToStruct:product.subscriptionPeriod];
}
}
if (@available(macOS 10.14, *)) {
if (product.subscriptionGroupIdentifier != nil) {
productStruct.subscriptionGroupIdentifier =
[product.subscriptionGroupIdentifier UTF8String];
}
}
if (@available(macOS 10.14.4, *)) {
if (product.discounts != nil) {
productStruct.discounts.reserve([product.discounts count]);
for (SKProductDiscount* discount in product.discounts) {
productStruct.discounts.push_back(
[self skProductDiscountToStruct:discount]);
}
if (product.introductoryPrice != nil) {
productStruct.introductoryPrice =
[self skProductDiscountToStruct:product.introductoryPrice];
}
if (product.subscriptionPeriod != nil) {
productStruct.subscriptionPeriod =
[self skProductSubscriptionPeriodToStruct:product.subscriptionPeriod];
}
if (product.subscriptionGroupIdentifier != nil) {
productStruct.subscriptionGroupIdentifier =
[product.subscriptionGroupIdentifier UTF8String];
}
if (product.discounts != nil) {
productStruct.discounts.reserve([product.discounts count]);
for (SKProductDiscount* discount in product.discounts) {
productStruct.discounts.push_back(
[self skProductDiscountToStruct:discount]);
}
}
// Downloadable Content Information
productStruct.isDownloadable = [product downloadable];
if (@available(macOS 10.14, *)) {
if (product.downloadContentVersion != nil) {
productStruct.downloadContentVersion =
[product.downloadContentVersion UTF8String];
}
if (product.downloadContentLengths != nil) {
productStruct.downloadContentLengths.reserve(
[product.downloadContentLengths count]);
productStruct.isDownloadable = [product isDownloadable];
for (NSNumber* contentLength in product.downloadContentLengths) {
productStruct.downloadContentLengths.push_back(
[contentLength longLongValue]);
}
}
} else {
if (product.contentVersion != nil) {
productStruct.downloadContentVersion =
[product.contentVersion UTF8String];
}
if (product.contentLengths != nil) {
productStruct.downloadContentLengths.reserve(
[product.contentLengths count]);
if (product.downloadContentVersion != nil) {
productStruct.downloadContentVersion =
[product.downloadContentVersion UTF8String];
}
for (NSNumber* contentLength in product.contentLengths) {
productStruct.downloadContentLengths.push_back(
[contentLength longLongValue]);
}
if (product.downloadContentLengths != nil) {
productStruct.downloadContentLengths.reserve(
[product.downloadContentLengths count]);
for (NSNumber* contentLength in product.downloadContentLengths) {
productStruct.downloadContentLengths.push_back(
[contentLength longLongValue]);
}
}

View file

@ -4,6 +4,7 @@
#include "shell/browser/media/media_device_id_salt.h"
#include "base/unguessable_token.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
@ -24,8 +25,7 @@ MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service) {
media_device_id_salt_.Init(kMediaDeviceIdSalt, pref_service);
if (media_device_id_salt_.GetValue().empty()) {
media_device_id_salt_.SetValue(
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
media_device_id_salt_.SetValue(base::UnguessableToken::Create().ToString());
}
}
@ -46,9 +46,8 @@ void MediaDeviceIDSalt::RegisterPrefs(PrefRegistrySimple* registry) {
// static
void MediaDeviceIDSalt::Reset(PrefService* pref_service) {
pref_service->SetString(
kMediaDeviceIdSalt,
content::BrowserContext::CreateRandomMediaDeviceIDSalt());
pref_service->SetString(kMediaDeviceIdSalt,
base::UnguessableToken::Create().ToString());
}
} // namespace electron

View file

@ -58,7 +58,7 @@
@implementation ElectronProgressBar
- (void)drawRect:(NSRect)dirtyRect {
if (self.style != NSProgressIndicatorBarStyle)
if (self.style != NSProgressIndicatorStyleBar)
return;
// Draw edges of rounded rect.
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
@ -915,7 +915,6 @@ void NativeWindowMac::Center() {
}
void NativeWindowMac::Invalidate() {
[window_ flushWindow];
[[window_ contentView] setNeedsDisplay:YES];
}
@ -1289,7 +1288,7 @@ void NativeWindowMac::SetProgressBar(double progress,
NSRect frame = NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0);
NSProgressIndicator* progress_indicator =
[[[ElectronProgressBar alloc] initWithFrame:frame] autorelease];
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
[progress_indicator setStyle:NSProgressIndicatorStyleBar];
[progress_indicator setIndeterminate:NO];
[progress_indicator setBezeled:YES];
[progress_indicator setMinValue:0];
@ -1400,26 +1399,10 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
return;
}
std::string dep_warn = " has been deprecated and removed as of macOS 10.15.";
node::Environment* env =
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
NSVisualEffectMaterial vibrancyType{};
if (type == "appearance-based") {
EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
"electron");
vibrancyType = NSVisualEffectMaterialAppearanceBased;
} else if (type == "light") {
EmitWarning(env, "NSVisualEffectMaterialLight" + dep_warn, "electron");
vibrancyType = NSVisualEffectMaterialLight;
} else if (type == "dark") {
EmitWarning(env, "NSVisualEffectMaterialDark" + dep_warn, "electron");
vibrancyType = NSVisualEffectMaterialDark;
} else if (type == "titlebar") {
if (type == "titlebar") {
vibrancyType = NSVisualEffectMaterialTitlebar;
}
if (type == "selection") {
} else if (type == "selection") {
vibrancyType = NSVisualEffectMaterialSelection;
} else if (type == "menu") {
vibrancyType = NSVisualEffectMaterialMenu;
@ -1427,35 +1410,24 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
vibrancyType = NSVisualEffectMaterialPopover;
} else if (type == "sidebar") {
vibrancyType = NSVisualEffectMaterialSidebar;
} else if (type == "medium-light") {
EmitWarning(env, "NSVisualEffectMaterialMediumLight" + dep_warn,
"electron");
vibrancyType = NSVisualEffectMaterialMediumLight;
} else if (type == "ultra-dark") {
EmitWarning(env, "NSVisualEffectMaterialUltraDark" + dep_warn, "electron");
vibrancyType = NSVisualEffectMaterialUltraDark;
}
if (@available(macOS 10.14, *)) {
if (type == "header") {
vibrancyType = NSVisualEffectMaterialHeaderView;
} else if (type == "sheet") {
vibrancyType = NSVisualEffectMaterialSheet;
} else if (type == "window") {
vibrancyType = NSVisualEffectMaterialWindowBackground;
} else if (type == "hud") {
vibrancyType = NSVisualEffectMaterialHUDWindow;
} else if (type == "fullscreen-ui") {
vibrancyType = NSVisualEffectMaterialFullScreenUI;
} else if (type == "tooltip") {
vibrancyType = NSVisualEffectMaterialToolTip;
} else if (type == "content") {
vibrancyType = NSVisualEffectMaterialContentBackground;
} else if (type == "under-window") {
vibrancyType = NSVisualEffectMaterialUnderWindowBackground;
} else if (type == "under-page") {
vibrancyType = NSVisualEffectMaterialUnderPageBackground;
}
} else if (type == "header") {
vibrancyType = NSVisualEffectMaterialHeaderView;
} else if (type == "sheet") {
vibrancyType = NSVisualEffectMaterialSheet;
} else if (type == "window") {
vibrancyType = NSVisualEffectMaterialWindowBackground;
} else if (type == "hud") {
vibrancyType = NSVisualEffectMaterialHUDWindow;
} else if (type == "fullscreen-ui") {
vibrancyType = NSVisualEffectMaterialFullScreenUI;
} else if (type == "tooltip") {
vibrancyType = NSVisualEffectMaterialToolTip;
} else if (type == "content") {
vibrancyType = NSVisualEffectMaterialContentBackground;
} else if (type == "under-window") {
vibrancyType = NSVisualEffectMaterialUnderWindowBackground;
} else if (type == "under-page") {
vibrancyType = NSVisualEffectMaterialUnderPageBackground;
}
if (vibrancyType) {

View file

@ -80,8 +80,6 @@ void NetworkContextService::ConfigureNetworkContextParams(
// Configure on-disk storage for persistent sessions.
if (!in_memory) {
// Configure the HTTP cache path and size.
network_context_params->http_cache_directory =
path.Append(chrome::kCacheDirname);
network_context_params->http_cache_max_size =
browser_context_->GetMaxCacheSize();
@ -92,6 +90,8 @@ void NetworkContextService::ConfigureNetworkContextParams(
network_context_params->file_paths->unsandboxed_data_path = path;
network_context_params->file_paths->trigger_migration =
ShouldTriggerNetworkDataMigration();
network_context_params->file_paths->http_cache_directory =
path.Append(chrome::kCacheDirname);
// Currently this just contains HttpServerProperties
network_context_params->file_paths->http_server_properties_file_name =

View file

@ -467,7 +467,8 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
BOOL checked = model->IsItemCheckedAt(modelIndex);
DCHECK([(id)item isKindOfClass:[NSMenuItem class]]);
[(id)item setState:(checked ? NSOnState : NSOffState)];
[(id)item
setState:(checked ? NSControlStateValueOn : NSControlStateValueOff)];
[(id)item setHidden:(!model->IsVisibleAt(modelIndex))];
return model->IsEnabledAt(modelIndex);

View file

@ -92,8 +92,9 @@ NSAlert* CreateNSAlert(const MessageBoxSettings& settings) {
alert.showsSuppressionButton = YES;
alert.suppressionButton.title =
base::SysUTF8ToNSString(settings.checkbox_label);
alert.suppressionButton.state =
settings.checkbox_checked ? NSOnState : NSOffState;
alert.suppressionButton.state = settings.checkbox_checked
? NSControlStateValueOn
: NSControlStateValueOff;
}
if (!settings.icon.isNull()) {
@ -145,7 +146,8 @@ void ShowMessageBox(const MessageBoxSettings& settings,
// window to wait for.
if (!settings.parent_window) {
int ret = [[alert autorelease] runModal];
std::move(callback).Run(ret, alert.suppressionButton.state == NSOnState);
std::move(callback).Run(
ret, alert.suppressionButton.state == NSControlStateValueOn);
} else {
if (settings.id) {
if (base::Contains(GetDialogsMap(), *settings.id))
@ -172,7 +174,7 @@ void ShowMessageBox(const MessageBoxSettings& settings,
// CloseMessageBox API, and we should return cancelId as result.
if (response < 0)
response = cancel_id;
bool suppressed = alert.suppressionButton.state == NSOnState;
bool suppressed = alert.suppressionButton.state == NSControlStateValueOn;
[alert release];
// The completionHandler runs inside a transaction commit, and we should
// not do any runModal inside it. However since we can not control what

View file

@ -44,8 +44,11 @@
if ((self = [super initWithFrame:CGRectZero])) {
[self registerForDraggedTypes:@[
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSFilenamesPboardType,
NSStringPboardType,
#pragma clang diagnostic pop
NSPasteboardTypeString,
]];
// Create the status item.
@ -123,16 +126,13 @@
// Change font type, if specified
CGFloat existing_size = [[[statusItem_ button] font] pointSize];
if ([font_type isEqualToString:@"monospaced"]) {
if (@available(macOS 10.15, *)) {
NSDictionary* attributes = @{
NSFontAttributeName :
[NSFont monospacedSystemFontOfSize:existing_size
weight:NSFontWeightRegular]
};
[attributed_title
addAttributes:attributes
range:NSMakeRange(0, [attributed_title length])];
}
NSDictionary* attributes = @{
NSFontAttributeName :
[NSFont monospacedSystemFontOfSize:existing_size
weight:NSFontWeightRegular]
};
[attributed_title addAttributes:attributes
range:NSMakeRange(0, [attributed_title length])];
} else if ([font_type isEqualToString:@"monospacedDigit"]) {
NSDictionary* attributes = @{
NSFontAttributeName :
@ -292,6 +292,10 @@
- (BOOL)handleDrop:(id<NSDraggingInfo>)sender {
NSPasteboard* pboard = [sender draggingPasteboard];
// TODO(codebytere): update to currently supported NSPasteboardTypeFileURL or
// kUTTypeFileURL.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
std::vector<std::string> dropFiles;
NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
@ -299,12 +303,12 @@
dropFiles.push_back(base::SysNSStringToUTF8(file));
trayIcon_->NotifyDropFiles(dropFiles);
return YES;
} else if ([[pboard types] containsObject:NSStringPboardType]) {
NSString* dropText = [pboard stringForType:NSStringPboardType];
} else if ([[pboard types] containsObject:NSPasteboardTypeString]) {
NSString* dropText = [pboard stringForType:NSPasteboardTypeString];
trayIcon_->NotifyDropText(base::SysNSStringToUTF8(dropText));
return YES;
}
#pragma clang diagnostic pop
return NO;
}

View file

@ -120,7 +120,7 @@ int WinCaptionButton::GetBetweenButtonSpacing() const {
const int display_order_index = GetButtonDisplayOrderIndex();
return display_order_index == 0
? 0
: WindowFrameUtil::kWindows10GlassCaptionButtonVisualSpacing;
: WindowFrameUtil::kWindowsCaptionButtonVisualSpacing;
}
int WinCaptionButton::GetButtonDisplayOrderIndex() const {

View file

@ -63,8 +63,8 @@ class WinCaptionButton : public views::Button {
std::unique_ptr<WinIconPainter> icon_painter_;
ViewID button_type_;
int base_width_ = WindowFrameUtil::kWindows10GlassCaptionButtonWidth;
int height_ = WindowFrameUtil::kWindows10GlassCaptionButtonHeightRestored;
int base_width_ = WindowFrameUtil::kWindowsCaptionButtonWidth;
int height_ = WindowFrameUtil::kWindowsCaptionButtonHeightRestored;
};
} // namespace electron

View file

@ -159,13 +159,13 @@ void ElectronUsbDelegate::AdjustProtectedInterfaceClasses(
std::unique_ptr<UsbChooser> ElectronUsbDelegate::RunChooser(
content::RenderFrameHost& frame,
std::vector<device::mojom::UsbDeviceFilterPtr> filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback) {
UsbChooserController* controller = ControllerForFrame(&frame);
if (controller) {
DeleteControllerForFrame(&frame);
}
AddControllerForFrame(&frame, std::move(filters), std::move(callback));
AddControllerForFrame(&frame, std::move(options), std::move(callback));
// Return a nullptr because the return value isn't used for anything. The
// return value is simply used in Chromium to cleanup the chooser UI once the
// usb service is destroyed.
@ -269,12 +269,12 @@ UsbChooserController* ElectronUsbDelegate::ControllerForFrame(
UsbChooserController* ElectronUsbDelegate::AddControllerForFrame(
content::RenderFrameHost* render_frame_host,
std::vector<device::mojom::UsbDeviceFilterPtr> filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback) {
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
auto controller = std::make_unique<UsbChooserController>(
render_frame_host, std::move(filters), std::move(callback), web_contents,
render_frame_host, std::move(options), std::move(callback), web_contents,
weak_factory_.GetWeakPtr());
controller_map_.insert(
std::make_pair(render_frame_host, std::move(controller)));

View file

@ -45,7 +45,7 @@ class ElectronUsbDelegate : public content::UsbDelegate {
std::vector<uint8_t>& classes) override;
std::unique_ptr<content::UsbChooser> RunChooser(
content::RenderFrameHost& frame,
std::vector<device::mojom::UsbDeviceFilterPtr> filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback) override;
bool CanRequestDevicePermission(content::BrowserContext* browser_context,
const url::Origin& origin) override;
@ -83,7 +83,7 @@ class ElectronUsbDelegate : public content::UsbDelegate {
UsbChooserController* AddControllerForFrame(
content::RenderFrameHost* render_frame_host,
std::vector<device::mojom::UsbDeviceFilterPtr> filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback);
class ContextObservation;

View file

@ -8,6 +8,7 @@
#include <utility>
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@ -35,12 +36,12 @@ namespace electron {
UsbChooserController::UsbChooserController(
RenderFrameHost* render_frame_host,
std::vector<device::mojom::UsbDeviceFilterPtr> device_filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback,
content::WebContents* web_contents,
base::WeakPtr<ElectronUsbDelegate> usb_delegate)
: WebContentsObserver(web_contents),
filters_(std::move(device_filters)),
options_(std::move(options)),
callback_(std::move(callback)),
origin_(render_frame_host->GetMainFrame()->GetLastCommittedOrigin()),
usb_delegate_(usb_delegate),
@ -136,8 +137,16 @@ void UsbChooserController::GotUsbDeviceList(
bool UsbChooserController::DisplayDevice(
const device::mojom::UsbDeviceInfo& device_info) const {
if (!device::UsbDeviceFilterMatchesAny(filters_, device_info))
if (!device::UsbDeviceFilterMatchesAny(options_->filters, device_info)) {
return false;
}
if (base::ranges::any_of(
options_->exclusion_filters, [&device_info](const auto& filter) {
return device::UsbDeviceFilterMatches(*filter, device_info);
})) {
return false;
}
return true;
}

View file

@ -32,7 +32,7 @@ class UsbChooserController final : public UsbChooserContext::DeviceObserver,
public:
UsbChooserController(
content::RenderFrameHost* render_frame_host,
std::vector<device::mojom::UsbDeviceFilterPtr> device_filters,
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
blink::mojom::WebUsbService::GetPermissionCallback callback,
content::WebContents* web_contents,
base::WeakPtr<ElectronUsbDelegate> usb_delegate);
@ -58,7 +58,7 @@ class UsbChooserController final : public UsbChooserContext::DeviceObserver,
void RunCallback(device::mojom::UsbDeviceInfoPtr device_info);
void OnDeviceChosen(gin::Arguments* args);
std::vector<device::mojom::UsbDeviceFilterPtr> filters_;
blink::mojom::WebUsbRequestDeviceOptionsPtr options_;
blink::mojom::WebUsbService::GetPermissionCallback callback_;
url::Origin origin_;

View file

@ -29,7 +29,7 @@ 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
return [rep representationUsingType:NSBitmapImageFileTypePNG
properties:[[NSDictionary alloc] init]];
}
@ -54,80 +54,51 @@ v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
CGSize cg_size = size.ToCGSize();
if (@available(macOS 10.15, *)) {
NSURL* nsurl = base::mac::FilePathToNSURL(path);
NSURL* nsurl = base::mac::FilePathToNSURL(path);
// We need to explicitly check if the user has passed an invalid path
// because QLThumbnailGenerationRequest will generate a stock file icon
// and pass silently if we do not.
if (![[NSFileManager defaultManager] fileExistsAtPath:[nsurl path]]) {
promise.RejectWithErrorMessage(
"unable to retrieve thumbnail preview image for the given path");
return handle;
}
NSScreen* screen = [[NSScreen screens] firstObject];
base::scoped_nsobject<QLThumbnailGenerationRequest> request(
[[QLThumbnailGenerationRequest alloc]
initWithFileAtURL:nsurl
size:cg_size
scale:[screen backingScaleFactor]
representationTypes:
QLThumbnailGenerationRequestRepresentationTypeAll]);
__block gin_helper::Promise<gfx::Image> p = std::move(promise);
[[QLThumbnailGenerator sharedGenerator]
generateBestRepresentationForRequest:request
completionHandler:^(
QLThumbnailRepresentation* thumbnail,
NSError* error) {
if (error || !thumbnail) {
std::string err_msg(
[error.localizedDescription UTF8String]);
dispatch_async(dispatch_get_main_queue(), ^{
p.RejectWithErrorMessage(
"unable to retrieve thumbnail preview "
"image for the given path: " +
err_msg);
});
} else {
NSImage* result = [[[NSImage alloc]
initWithCGImage:[thumbnail CGImage]
size:cg_size] autorelease];
gfx::Image image(result);
dispatch_async(dispatch_get_main_queue(), ^{
p.Resolve(image);
});
}
}];
} else {
base::ScopedCFTypeRef<CFURLRef> cfurl = base::mac::FilePathToCFURL(path);
base::ScopedCFTypeRef<QLThumbnailRef> ql_thumbnail(
QLThumbnailCreate(kCFAllocatorDefault, cfurl, cg_size, NULL));
__block gin_helper::Promise<gfx::Image> p = std::move(promise);
// Do not block the main thread waiting for quicklook to generate the
// thumbnail.
QLThumbnailDispatchAsync(
ql_thumbnail,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, /*flags*/ 0), ^{
base::ScopedCFTypeRef<CGImageRef> cg_thumbnail(
QLThumbnailCopyImage(ql_thumbnail));
if (cg_thumbnail) {
NSImage* result =
[[[NSImage alloc] initWithCGImage:cg_thumbnail
size:cg_size] autorelease];
gfx::Image thumbnail(result);
dispatch_async(dispatch_get_main_queue(), ^{
p.Resolve(thumbnail);
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
p.RejectWithErrorMessage("unable to retrieve thumbnail preview "
"image for the given path");
});
}
});
// We need to explicitly check if the user has passed an invalid path
// because QLThumbnailGenerationRequest will generate a stock file icon
// and pass silently if we do not.
if (![[NSFileManager defaultManager] fileExistsAtPath:[nsurl path]]) {
promise.RejectWithErrorMessage(
"unable to retrieve thumbnail preview image for the given path");
return handle;
}
NSScreen* screen = [[NSScreen screens] firstObject];
base::scoped_nsobject<QLThumbnailGenerationRequest> request(
[[QLThumbnailGenerationRequest alloc]
initWithFileAtURL:nsurl
size:cg_size
scale:[screen backingScaleFactor]
representationTypes:
QLThumbnailGenerationRequestRepresentationTypeAll]);
__block gin_helper::Promise<gfx::Image> p = std::move(promise);
[[QLThumbnailGenerator sharedGenerator]
generateBestRepresentationForRequest:request
completionHandler:^(
QLThumbnailRepresentation* thumbnail,
NSError* error) {
if (error || !thumbnail) {
std::string err_msg(
[error.localizedDescription UTF8String]);
dispatch_async(dispatch_get_main_queue(), ^{
p.RejectWithErrorMessage(
"unable to retrieve thumbnail preview "
"image for the given path: " +
err_msg);
});
} else {
NSImage* result = [[[NSImage alloc]
initWithCGImage:[thumbnail CGImage]
size:cg_size] autorelease];
gfx::Image image(result);
dispatch_async(dispatch_get_main_queue(), ^{
p.Resolve(image);
});
}
}];
return handle;
}