From 78468098c5a5d93b9f5d5615fa5e4d42eec8f8c5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Mar 2018 16:12:10 +0900 Subject: [PATCH] Don't store WebContents in NativeWindow --- atom/browser/api/atom_api_menu_mac.mm | 8 ++------ atom/browser/browser_mac.mm | 1 + atom/browser/native_window.cc | 1 - atom/browser/native_window.h | 7 ------- atom/browser/native_window_mac.mm | 2 +- 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/atom/browser/api/atom_api_menu_mac.mm b/atom/browser/api/atom_api_menu_mac.mm index 1a0aba3894b3..ed491730a114 100644 --- a/atom/browser/api/atom_api_menu_mac.mm +++ b/atom/browser/api/atom_api_menu_mac.mm @@ -48,10 +48,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr& native_window, base::Closure callback) { if (!native_window) return; - brightray::InspectableWebContents* web_contents = - native_window->inspectable_web_contents(); - if (!web_contents) - return; + NSWindow* nswindow = native_window->GetNativeWindow(); auto close_callback = base::Bind( &MenuMac::OnClosed, weak_factory_.GetWeakPtr(), window_id, callback); @@ -59,7 +56,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr& native_window, [[AtomMenuController alloc] initWithModel:model() useDefaultAccelerator:NO]); NSMenu* menu = [popup_controllers_[window_id] menu]; - NSView* view = web_contents->GetView()->GetNativeView(); + NSView* view = [nswindow contentView]; // Which menu item to show. NSMenuItem* item = nil; @@ -69,7 +66,6 @@ void MenuMac::PopupOnUI(const base::WeakPtr& native_window, // (-1, -1) means showing on mouse location. NSPoint position; if (x == -1 || y == -1) { - NSWindow* nswindow = native_window->GetNativeWindow(); position = [view convertPoint:[nswindow mouseLocationOutsideOfEventStream] fromView:nil]; } else { diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 0faeee36f939..8f13626b9f4d 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -17,6 +17,7 @@ #include "base/strings/sys_string_conversions.h" #include "brightray/common/application_info.h" #include "net/base/mac/url_conversions.h" +#include "ui/gfx/image/image.h" #include "url/gurl.h" namespace atom { diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 2fdcbd75ee55..ee8ba1dc87da 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -34,7 +34,6 @@ NativeWindow::NativeWindow( is_modal_(false), is_osr_dummy_(false), browser_view_(nullptr), - inspectable_web_contents_(inspectable_web_contents), weak_factory_(this) { options.Get(options::kFrame, &has_frame_); options.Get(options::kTransparent, &transparent_); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 5bec3be26387..219463ac1568 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -265,10 +265,6 @@ class NativeWindow : public base::SupportsUserData { observers_.RemoveObserver(obs); } - brightray::InspectableWebContents* inspectable_web_contents() const { - return inspectable_web_contents_; - } - bool has_frame() const { return has_frame_; } void set_has_frame(bool has_frame) { has_frame_ = has_frame; } @@ -329,9 +325,6 @@ class NativeWindow : public base::SupportsUserData { // The browser view layer. NativeBrowserView* browser_view_; - // The page this window is viewing. - brightray::InspectableWebContents* inspectable_web_contents_; - // Observers of this window. base::ObserverList observers_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 60bbebc66250..d1b470002918 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -953,7 +953,7 @@ NativeWindowMac::NativeWindowMac( options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor); [window_ setDisableAutoHideCursor:disableAutoHideCursor]; - NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); + NSView* view = web_contents->GetView()->GetNativeView(); [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; // Use an NSEvent monitor to listen for the wheel event.