Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: missing handlescopes in touch bar #23970

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions shell/browser/ui/cocoa/electron_touch_bar.mm
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#include "base/strings/sys_string_conversions.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_converters/image_converter.h"
#include "skia/ext/skia_utils_mac.h"
Expand Down Expand Up @@ -195,6 +196,9 @@ - (void)refreshTouchBarItem:(NSTouchBar*)touchBar
if (![self hasItemWithID:item_id])
return;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[item_id];
std::string item_type;
settings.Get("type", &item_type);
Expand Down Expand Up @@ -345,6 +349,9 @@ - (NSTouchBarItem*)makeButtonForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item(
[[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -403,6 +410,9 @@ - (NSTouchBarItem*)makeLabelForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item(
[[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -437,6 +447,9 @@ - (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSColorPickerTouchBarItem> item(
[[NSColorPickerTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -472,6 +485,9 @@ - (NSTouchBarItem*)makeSliderForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSSliderTouchBarItem> item(
[[NSSliderTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -505,6 +521,9 @@ - (NSTouchBarItem*)makePopoverForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSPopoverTouchBarItem> item(
[[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]);
Expand All @@ -527,6 +546,9 @@ - (void)updatePopover:(NSPopoverTouchBarItem*)item
settings.Get("showCloseButton", &showCloseButton);
item.showsCloseButton = showCloseButton;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary child;
std::vector<gin_helper::PersistentDictionary> items;
if (settings.Get("child", &child) && child.Get("ordereredItems", &items)) {
Expand All @@ -540,6 +562,10 @@ - (NSTouchBarItem*)makeGroupForID:(NSString*)id
std::string s_id([id UTF8String]);
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];

gin_helper::PersistentDictionary child;
Expand Down Expand Up @@ -568,6 +594,9 @@ - (NSTouchBarItem*)makeGroupForID:(NSString*)id
- (void)updateGroup:(NSGroupTouchBarItem*)item
withSettings:(const gin_helper::PersistentDictionary&)settings
API_AVAILABLE(macosx(10.12.2)) {
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary child;
if (!settings.Get("child", &child))
return;
Expand All @@ -586,6 +615,9 @@ - (NSTouchBarItem*)makeSegmentedControlForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item(
[[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -671,6 +703,9 @@ - (NSTouchBarItem*)makeScrubberForID:(NSString*)id
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
base::scoped_nsobject<NSCustomTouchBarItem> item(
[[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]);
Expand Down Expand Up @@ -748,6 +783,9 @@ - (NSInteger)numberOfItemsForScrubber:(NSScrubber*)scrubber
if (![self hasItemWithID:s_id])
return 0;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
std::vector<gin_helper::PersistentDictionary> items;
settings.Get("items", &items);
Expand All @@ -761,6 +799,9 @@ - (NSScrubberItemView*)scrubber:(NSScrubber*)scrubber
if (![self hasItemWithID:s_id])
return nil;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
std::vector<gin_helper::PersistentDictionary> items;
if (!settings.Get("items", &items))
Expand Down Expand Up @@ -805,6 +846,9 @@ - (NSSize)scrubber:(NSScrubber*)scrubber
if (![self hasItemWithID:s_id])
return defaultSize;

v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);

gin_helper::PersistentDictionary settings = settings_[s_id];
std::vector<gin_helper::PersistentDictionary> items;
if (!settings.Get("items", &items))
Expand Down