fix: return pointer instead of pointer's content (#16641)

This commit is contained in:
Cheng Zhao 2019-01-31 20:19:21 +09:00 committed by GitHub
parent 440a3fa6d8
commit 8ab1309215
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 344 additions and 324 deletions

View file

@ -667,8 +667,8 @@ v8::Local<v8::Value> TopLevelWindow::GetNativeWindowHandle() {
// TODO(MarshallOfSound): Replace once // TODO(MarshallOfSound): Replace once
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has // https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
// landed // landed
auto handle = window_->GetNativeWindowHandlePointer(); NativeWindowHandle handle = window_->GetNativeWindowHandle();
return ToBuffer(isolate(), std::get<0>(handle), std::get<1>(handle)); return ToBuffer(isolate(), &handle, sizeof(handle));
} }
void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) { void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) {

View file

@ -45,6 +45,12 @@ class NativeBrowserView;
struct DraggableRegion; struct DraggableRegion;
#if defined(OS_MACOSX)
typedef NSView* NativeWindowHandle;
#else
typedef gfx::AcceleratedWidget NativeWindowHandle;
#endif
class NativeWindow : public base::SupportsUserData, class NativeWindow : public base::SupportsUserData,
public views::WidgetDelegate { public views::WidgetDelegate {
public: public:
@ -151,7 +157,7 @@ class NativeWindow : public base::SupportsUserData,
virtual gfx::NativeView GetNativeView() const = 0; virtual gfx::NativeView GetNativeView() const = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0; virtual gfx::NativeWindow GetNativeWindow() const = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
virtual std::tuple<void*, int> GetNativeWindowHandlePointer() const = 0; virtual NativeWindowHandle GetNativeWindowHandle() const = 0;
// Taskbar/Dock APIs. // Taskbar/Dock APIs.
enum ProgressState { enum ProgressState {

View file

@ -104,7 +104,7 @@ class NativeWindowMac : public NativeWindow {
gfx::NativeView GetNativeView() const override; gfx::NativeView GetNativeView() const override;
gfx::NativeWindow GetNativeWindow() const override; gfx::NativeWindow GetNativeWindow() const override;
gfx::AcceleratedWidget GetAcceleratedWidget() 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 SetProgressBar(double progress, const ProgressState state) override;
void SetOverlayIcon(const gfx::Image& overlay, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override; const std::string& description) override;

View file

@ -1081,9 +1081,8 @@ gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() const {
return gfx::kNullAcceleratedWidget; return gfx::kNullAcceleratedWidget;
} }
std::tuple<void*, int> NativeWindowMac::GetNativeWindowHandlePointer() const { NativeWindowHandle NativeWindowMac::GetNativeWindowHandle() const {
NSView* view = [window_ contentView]; return [window_ contentView];
return std::make_tuple(static_cast<void*>(view), sizeof(view));
} }
void NativeWindowMac::SetProgressBar(double progress, void NativeWindowMac::SetProgressBar(double progress,

View file

@ -1047,9 +1047,8 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
} }
std::tuple<void*, int> NativeWindowViews::GetNativeWindowHandlePointer() const { NativeWindowHandle NativeWindowViews::GetNativeWindowHandle() const {
gfx::AcceleratedWidget handle = GetAcceleratedWidget(); return GetAcceleratedWidget();
return std::make_tuple(static_cast<void*>(&handle), sizeof(handle));
} }
gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds( gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(

View file

@ -124,7 +124,7 @@ class NativeWindowViews : public NativeWindow,
bool IsVisibleOnAllWorkspaces() override; bool IsVisibleOnAllWorkspaces() override;
gfx::AcceleratedWidget GetAcceleratedWidget() const 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 ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override; gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;

2
spec/.hash Normal file
View file

@ -0,0 +1,2 @@
24d8222313d02ffe2a2181b9c82fbfa5ab8372aec6442839302622fbf45cbe47
null

View file

@ -2790,6 +2790,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', () => { describe('extensions and dev tools extensions', () => {
let showPanelTimeoutId let showPanelTimeoutId

626
spec/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -15,6 +15,7 @@
"dbus-native": "^0.2.5", "dbus-native": "^0.2.5",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1",
"graceful-fs": "^4.1.11", "graceful-fs": "^4.1.11",
"is-valid-window": "^0.0.3",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"mocha-junit-reporter": "^1.17.0", "mocha-junit-reporter": "^1.17.0",