Add BrowserWindow.prototype.setContentProtection(enable)
authorMilan Burda <milan.burda@gmail.com>
Wed, 22 Jun 2016 08:40:01 +0000 (10:40 +0200)
committerMilan Burda <milan.burda@gmail.com>
Wed, 22 Jun 2016 08:40:33 +0000 (10:40 +0200)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
docs/api/browser-window.md

index cc3749b..ae6bb77 100644 (file)
@@ -572,6 +572,10 @@ void Window::SetIgnoreMouseEvents(bool ignore) {
   return window_->SetIgnoreMouseEvents(ignore);
 }
 
+void Window::SetContentProtection(bool enable) {
+  return window_->SetContentProtection(enable);
+}
+
 void Window::SetFocusable(bool focusable) {
   return window_->SetFocusable(focusable);
 }
@@ -833,6 +837,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
       .SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
       .SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
+      .SetMethod("setContentProtection", &Window::SetContentProtection)
       .SetMethod("setFocusable", &Window::SetFocusable)
       .SetMethod("focusOnWebView", &Window::FocusOnWebView)
       .SetMethod("blurWebView", &Window::BlurWebView)
index 21ecca4..a204b70 100644 (file)
@@ -153,6 +153,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetDocumentEdited(bool edited);
   bool IsDocumentEdited();
   void SetIgnoreMouseEvents(bool ignore);
+  void SetContentProtection(bool enable);
   void SetFocusable(bool focusable);
   void CapturePage(mate::Arguments* args);
   void SetProgressBar(double progress);
index d3b6f8a..8656c02 100644 (file)
@@ -157,6 +157,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual void SetDocumentEdited(bool edited);
   virtual bool IsDocumentEdited();
   virtual void SetIgnoreMouseEvents(bool ignore) = 0;
+  virtual void SetContentProtection(bool enable) = 0;
   virtual void SetFocusable(bool focusable);
   virtual void SetMenu(ui::MenuModel* menu);
   virtual bool HasModalDialog();
index af99b39..d07d586 100644 (file)
@@ -79,6 +79,7 @@ class NativeWindowMac : public NativeWindow {
   void SetDocumentEdited(bool edited) override;
   bool IsDocumentEdited() override;
   void SetIgnoreMouseEvents(bool ignore) override;
+  void SetContentProtection(bool enable) override;
   bool HasModalDialog() override;
   void SetParentWindow(NativeWindow* parent) override;
   gfx::NativeWindow GetNativeWindow() override;
index 3330eb8..004d2ca 100644 (file)
@@ -941,6 +941,11 @@ void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
   [window_ setIgnoresMouseEvents:ignore];
 }
 
+void NativeWindowMac::SetContentProtection(bool enable) {
+  [window_ setSharingType:enable ? NSWindowSharingNone
+                                 : NSWindowSharingReadOnly];
+}
+
 bool NativeWindowMac::HasModalDialog() {
   return [window_ attachedSheet] != nil;
 }
index 1feb961..e9ff695 100644 (file)
@@ -728,6 +728,13 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
 #endif
 }
 
+void NativeWindowViews::SetContentProtection(bool enable) {
+#if defined(OS_WIN)
+  DWORD affinity = enable ? WDA_MONITOR : WDA_NONE;
+  ::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity);
+#endif
+}
+
 void NativeWindowViews::SetFocusable(bool focusable) {
 #if defined(OS_WIN)
   LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
index 69d3d27..71f3741 100644 (file)
@@ -96,6 +96,7 @@ class NativeWindowViews : public NativeWindow,
   void SetHasShadow(bool has_shadow) override;
   bool HasShadow() override;
   void SetIgnoreMouseEvents(bool ignore) override;
+  void SetContentProtection(bool enable) override;
   void SetFocusable(bool focusable) override;
   void SetMenu(ui::MenuModel* menu_model) override;
   void SetParentWindow(NativeWindow* parent) override;
index e955704..e5a9732 100644 (file)
@@ -1050,6 +1050,13 @@ All mouse events happened in this window will be passed to the window below
 this window, but if this window has focus, it will still receive keyboard
 events.
 
+### `win.setContentProtection(enable)` _macOS_ _Windows_
+
+Prevents the window contents from being captured by other apps.
+
+On macOS it sets the NSWindow's sharingType to NSWindowSharingNone.
+On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.
+
 ### `win.setFocusable(focusable)` _Windows_
 
 * `focusable` Boolean