Skip to content

Commit

Permalink
fix: return pointer instead of pointer's content (#16014)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Zhao authored and John Kleinschmidt committed Dec 11, 2018
1 parent f3c64ea commit 624ade2
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 253 deletions.
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_top_level_window.cc
Expand Up @@ -696,8 +696,8 @@ v8::Local<v8::Value> TopLevelWindow::GetNativeWindowHandle() {
// TODO(MarshallOfSound): Replace once
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
// landed
auto handle = window_->GetNativeWindowHandlePointer();
return ToBuffer(isolate(), std::get<0>(handle), std::get<1>(handle));
NativeWindowHandle handle = window_->GetNativeWindowHandle();
return ToBuffer(isolate(), &handle, sizeof(handle));
}

void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) {
Expand Down
8 changes: 7 additions & 1 deletion atom/browser/native_window.h
Expand Up @@ -45,6 +45,12 @@ class NativeBrowserView;

struct DraggableRegion;

#if defined(OS_MACOSX)
typedef NSView* NativeWindowHandle;
#else
typedef gfx::AcceleratedWidget NativeWindowHandle;
#endif

class NativeWindow : public base::SupportsUserData,
public views::WidgetDelegate {
public:
Expand Down Expand Up @@ -153,7 +159,7 @@ class NativeWindow : public base::SupportsUserData,
virtual gfx::NativeView GetNativeView() const = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
virtual std::tuple<void*, int> GetNativeWindowHandlePointer() const = 0;
virtual NativeWindowHandle GetNativeWindowHandle() const = 0;

// Taskbar/Dock APIs.
enum ProgressState {
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/native_window_mac.h
Expand Up @@ -107,7 +107,7 @@ class NativeWindowMac : public NativeWindow {
gfx::NativeView GetNativeView() const override;
gfx::NativeWindow GetNativeWindow() const override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
std::tuple<void*, int> GetNativeWindowHandlePointer() const override;
NativeWindowHandle GetNativeWindowHandle() const override;
void SetProgressBar(double progress, const ProgressState state) override;
void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override;
Expand Down
5 changes: 2 additions & 3 deletions atom/browser/native_window_mac.mm
Expand Up @@ -1110,9 +1110,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
return gfx::kNullAcceleratedWidget;
}

std::tuple<void*, int> NativeWindowMac::GetNativeWindowHandlePointer() const {
NSView* view = [window_ contentView];
return std::make_tuple(static_cast<void*>(view), sizeof(view));
NativeWindowHandle NativeWindowMac::GetNativeWindowHandle() const {
return [window_ contentView];
}

void NativeWindowMac::SetProgressBar(double progress,
Expand Down
5 changes: 2 additions & 3 deletions atom/browser/native_window_views.cc
Expand Up @@ -1071,9 +1071,8 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
}

std::tuple<void*, int> NativeWindowViews::GetNativeWindowHandlePointer() const {
gfx::AcceleratedWidget handle = GetAcceleratedWidget();
return std::make_tuple(static_cast<void*>(&handle), sizeof(handle));
NativeWindowHandle NativeWindowViews::GetNativeWindowHandle() const {
return GetAcceleratedWidget();
}

gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/native_window_views.h
Expand Up @@ -130,7 +130,7 @@ class NativeWindowViews : public NativeWindow,
bool IsVisibleOnAllWorkspaces() override;

gfx::AcceleratedWidget GetAcceleratedWidget() const override;
std::tuple<void*, int> GetNativeWindowHandlePointer() const override;
NativeWindowHandle GetNativeWindowHandle() const override;

gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
Expand Down
13 changes: 13 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -3054,6 +3054,19 @@ describe('BrowserWindow module', () => {
})
})

describe('window.getNativeWindowHandle()', () => {
if (!nativeModulesEnabled) {
this.skip()
}

it('returns valid handle', () => {
// The module's source code is hosted at
// https://github.com/electron/node-is-valid-window
const isValidWindow = remote.require('is-valid-window')
assert.ok(isValidWindow(w.getNativeWindowHandle()))
})
})

describe('extensions and dev tools extensions', () => {
let showPanelTimeoutId

Expand Down

0 comments on commit 624ade2

Please sign in to comment.