Index: ui/views/cocoa/bridged_native_widget.mm |
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm |
index 591f4cba9f2232b5969c2d79e46de9a81c37cf90..ed1339d38afd318d0bf43b44f67c94dfdcabc8fb 100644 |
--- a/ui/views/cocoa/bridged_native_widget.mm |
+++ b/ui/views/cocoa/bridged_native_widget.mm |
@@ -4,6 +4,8 @@ |
#import "ui/views/cocoa/bridged_native_widget.h" |
+#import <objc/runtime.h> |
+ |
#include "base/logging.h" |
#include "base/mac/mac_util.h" |
#import "base/mac/sdk_forward_declarations.h" |
@@ -27,6 +29,8 @@ |
namespace { |
+int kWindowPropertiesKey; |
+ |
float GetDeviceScaleFactorFromView(NSView* view) { |
gfx::Display display = |
gfx::Screen::GetScreenFor(view)->GetDisplayNearestWindow(view); |
@@ -208,6 +212,22 @@ bool BridgedNativeWidget::HasCapture() { |
return mouse_capture_ && mouse_capture_->IsActive(); |
} |
+void BridgedNativeWidget::SetNativeWindowProperty(const char* name, |
+ void* value) { |
+ NSString* key = [NSString stringWithUTF8String:name]; |
+ if (value) { |
+ [GetWindowProperties() setObject:[NSValue valueWithPointer:value] |
+ forKey:key]; |
+ } else { |
+ [GetWindowProperties() removeObjectForKey:key]; |
+ } |
+} |
+ |
+void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { |
+ NSString* key = [NSString stringWithUTF8String:name]; |
+ return [[GetWindowProperties() objectForKey:key] pointerValue]; |
+} |
+ |
void BridgedNativeWidget::OnWindowWillClose() { |
if (parent_) |
parent_->RemoveChildWindow(this); |
@@ -609,4 +629,15 @@ void BridgedNativeWidget::UpdateLayerProperties() { |
ConvertSizeToPixel(scale_factor, size_in_dip)); |
} |
+NSMutableDictionary* BridgedNativeWidget::GetWindowProperties() const { |
+ NSMutableDictionary* properties = objc_getAssociatedObject( |
+ window_, &kWindowPropertiesKey); |
+ if (!properties) { |
+ properties = [NSMutableDictionary dictionary]; |
+ objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
+ properties, OBJC_ASSOCIATION_RETAIN); |
+ } |
+ return properties; |
+} |
+ |
} // namespace views |