Add BrowserWindow.prototype.setContentProtection(enable)

This commit is contained in:
Milan Burda 2016-06-22 10:40:01 +02:00
parent fd40f3d344
commit c243cf0c0f
8 changed files with 28 additions and 0 deletions

View file

@ -572,6 +572,10 @@ void Window::SetIgnoreMouseEvents(bool ignore) {
return window_->SetIgnoreMouseEvents(ignore); return window_->SetIgnoreMouseEvents(ignore);
} }
void Window::SetContentProtection(bool enable) {
return window_->SetContentProtection(enable);
}
void Window::SetFocusable(bool focusable) { void Window::SetFocusable(bool focusable) {
return window_->SetFocusable(focusable); return window_->SetFocusable(focusable);
} }
@ -833,6 +837,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited) .SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
.SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents) .SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
.SetMethod("setContentProtection", &Window::SetContentProtection)
.SetMethod("setFocusable", &Window::SetFocusable) .SetMethod("setFocusable", &Window::SetFocusable)
.SetMethod("focusOnWebView", &Window::FocusOnWebView) .SetMethod("focusOnWebView", &Window::FocusOnWebView)
.SetMethod("blurWebView", &Window::BlurWebView) .SetMethod("blurWebView", &Window::BlurWebView)

View file

@ -153,6 +153,7 @@ class Window : public mate::TrackableObject<Window>,
void SetDocumentEdited(bool edited); void SetDocumentEdited(bool edited);
bool IsDocumentEdited(); bool IsDocumentEdited();
void SetIgnoreMouseEvents(bool ignore); void SetIgnoreMouseEvents(bool ignore);
void SetContentProtection(bool enable);
void SetFocusable(bool focusable); void SetFocusable(bool focusable);
void CapturePage(mate::Arguments* args); void CapturePage(mate::Arguments* args);
void SetProgressBar(double progress); void SetProgressBar(double progress);

View file

@ -157,6 +157,7 @@ class NativeWindow : public base::SupportsUserData,
virtual void SetDocumentEdited(bool edited); virtual void SetDocumentEdited(bool edited);
virtual bool IsDocumentEdited(); virtual bool IsDocumentEdited();
virtual void SetIgnoreMouseEvents(bool ignore) = 0; virtual void SetIgnoreMouseEvents(bool ignore) = 0;
virtual void SetContentProtection(bool enable) = 0;
virtual void SetFocusable(bool focusable); virtual void SetFocusable(bool focusable);
virtual void SetMenu(ui::MenuModel* menu); virtual void SetMenu(ui::MenuModel* menu);
virtual bool HasModalDialog(); virtual bool HasModalDialog();

View file

@ -79,6 +79,7 @@ class NativeWindowMac : public NativeWindow {
void SetDocumentEdited(bool edited) override; void SetDocumentEdited(bool edited) override;
bool IsDocumentEdited() override; bool IsDocumentEdited() override;
void SetIgnoreMouseEvents(bool ignore) override; void SetIgnoreMouseEvents(bool ignore) override;
void SetContentProtection(bool enable) override;
bool HasModalDialog() override; bool HasModalDialog() override;
void SetParentWindow(NativeWindow* parent) override; void SetParentWindow(NativeWindow* parent) override;
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;

View file

@ -941,6 +941,11 @@ void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
[window_ setIgnoresMouseEvents:ignore]; [window_ setIgnoresMouseEvents:ignore];
} }
void NativeWindowMac::SetContentProtection(bool enable) {
[window_ setSharingType:enable ? NSWindowSharingNone
: NSWindowSharingReadOnly];
}
bool NativeWindowMac::HasModalDialog() { bool NativeWindowMac::HasModalDialog() {
return [window_ attachedSheet] != nil; return [window_ attachedSheet] != nil;
} }

View file

@ -728,6 +728,13 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
#endif #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) { void NativeWindowViews::SetFocusable(bool focusable) {
#if defined(OS_WIN) #if defined(OS_WIN)
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);

View file

@ -96,6 +96,7 @@ class NativeWindowViews : public NativeWindow,
void SetHasShadow(bool has_shadow) override; void SetHasShadow(bool has_shadow) override;
bool HasShadow() override; bool HasShadow() override;
void SetIgnoreMouseEvents(bool ignore) override; void SetIgnoreMouseEvents(bool ignore) override;
void SetContentProtection(bool enable) override;
void SetFocusable(bool focusable) override; void SetFocusable(bool focusable) override;
void SetMenu(ui::MenuModel* menu_model) override; void SetMenu(ui::MenuModel* menu_model) override;
void SetParentWindow(NativeWindow* parent) override; void SetParentWindow(NativeWindow* parent) override;

View 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 this window, but if this window has focus, it will still receive keyboard
events. 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_ ### `win.setFocusable(focusable)` _Windows_
* `focusable` Boolean * `focusable` Boolean