Commit cd09887d authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Avoid redefining IsMsgHandled by making all Win message handlers safe

There were two sets of message map macros, one with IsMsgHandled as a
function, one with it as a macro. If combined in some translation unit
that could cause compilation problems, and it did in some Opera builds.

This patch changes the code so that there is only one implementation
of the macros and it's the "safe" one, where "safe" means that it
can handle that the underlying object is deleted inside a message
handler without crashing.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I2f039d8d93a539c8322caa664e642956c5d6d372
Reviewed-on: https://chromium-review.googlesource.com/995896Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550711}
parent dc9987c8
......@@ -7,6 +7,7 @@
#include <memory>
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h"
#include "base/win/scoped_hdc.h"
......@@ -114,6 +115,8 @@ class HiddenPopupWindow : public gfx::WindowImpl {
CR_BEGIN_MSG_MAP_EX(HiddenPopupWindow)
CR_MSG_WM_CLOSE(OnClose)
CR_END_MSG_MAP()
CR_MSG_MAP_CLASS_DECLARATIONS(HiddenPopupWindow)
};
// This runs on the window owner thread.
......
......@@ -9,6 +9,9 @@
namespace ui {
ForegroundHelper::ForegroundHelper() : window_(NULL) {}
ForegroundHelper::~ForegroundHelper() = default;
// static
HRESULT ForegroundHelper::SetForeground(HWND window) {
DCHECK(::IsWindow(window));
......
......@@ -23,7 +23,8 @@ namespace ui {
// This is probably leveraging a windows bug.
class UI_BASE_EXPORT ForegroundHelper : public gfx::WindowImpl {
public:
ForegroundHelper() : window_(NULL) { }
ForegroundHelper();
~ForegroundHelper() override;
CR_BEGIN_MSG_MAP_EX(ForegroundHelper)
CR_MSG_WM_HOTKEY(OnHotKey)
......@@ -42,6 +43,8 @@ class UI_BASE_EXPORT ForegroundHelper : public gfx::WindowImpl {
HWND window_;
CR_MSG_MAP_CLASS_DECLARATIONS(ForegroundHelper)
DISALLOW_COPY_AND_ASSIGN(ForegroundHelper);
};
......
......@@ -42,9 +42,11 @@ class TempParent : public gfx::WindowImpl {
void OnClose() {
}
CR_BEGIN_MSG_MAP_EX(WebContentsViewWin)
CR_BEGIN_MSG_MAP_EX(TempParent)
CR_MSG_WM_CLOSE(OnClose)
CR_END_MSG_MAP()
CR_MSG_MAP_CLASS_DECLARATIONS(TempParent)
};
} // namespace
......
......@@ -59,6 +59,8 @@ class TestCompositorHostWin : public TestCompositorHost,
std::unique_ptr<ui::Compositor> compositor_;
CR_MSG_MAP_CLASS_DECLARATIONS(TestCompositorHostWin)
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin);
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -41,8 +41,7 @@ gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style,
} // namespace
WinWindow::WinWindow(PlatformWindowDelegate* delegate,
const gfx::Rect& bounds)
WinWindow::WinWindow(PlatformWindowDelegate* delegate, const gfx::Rect& bounds)
: delegate_(delegate) {
CHECK(delegate_);
DWORD window_style = WS_OVERLAPPEDWINDOW;
......
......@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/win/window_impl.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/win/win_window_export.h"
......@@ -48,8 +49,7 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindow,
CR_BEGIN_MSG_MAP_EX(WinWindow)
CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE,
WM_NCXBUTTONDBLCLK,
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK,
OnMouseRange)
CR_MESSAGE_HANDLER_EX(WM_CAPTURECHANGED, OnCaptureChanged)
......@@ -81,6 +81,8 @@ class WIN_WINDOW_EXPORT WinWindow : public PlatformWindow,
PlatformWindowDelegate* delegate_;
CR_MSG_MAP_CLASS_DECLARATIONS(WinWindow)
DISALLOW_COPY_AND_ASSIGN(WinWindow);
};
......
This diff is collapsed.
......@@ -27,6 +27,7 @@
#include "ui/events/event.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/sequential_id_generator.h"
#include "ui/gfx/win/msg_util.h"
#include "ui/gfx/win/window_impl.h"
#include "ui/views/views_export.h"
#include "ui/views/win/pen_event_processor.h"
......@@ -65,54 +66,6 @@ const int WM_NCUAHDRAWFRAME = 0xAF;
// WM_WINDOWPOSCHANGED won't be received.
const int WM_WINDOWSIZINGFINISHED = WM_USER;
// IsMsgHandled() and BEGIN_SAFE_MSG_MAP_EX are a modified version of
// BEGIN_MSG_MAP_EX. The main difference is it uses a WeakPtrFactory member
// (|weak_factory|) that is used in _ProcessWindowMessage() and changing
// IsMsgHandled() from a member function to a define that checks if the weak
// factory is still valid in addition to the member. Together these allow for
// |this| to be deleted during dispatch.
#define IsMsgHandled() !ref.get() || msg_handled_
#define BEGIN_SAFE_MSG_MAP_EX(weak_factory) \
private: \
BOOL msg_handled_; \
\
public: \
/* "handled" management for cracked handlers */ \
void SetMsgHandled(BOOL handled) { \
msg_handled_ = handled; \
} \
BOOL ProcessWindowMessage(HWND hwnd, \
UINT msg, \
WPARAM w_param, \
LPARAM l_param, \
LRESULT& l_result, \
DWORD msg_map_id = 0) override { \
base::WeakPtr<HWNDMessageHandler> ref(weak_factory.GetWeakPtr()); \
BOOL old_msg_handled = msg_handled_; \
BOOL ret = _ProcessWindowMessage(hwnd, msg, w_param, l_param, l_result, \
msg_map_id); \
if (ref.get()) \
msg_handled_ = old_msg_handled; \
return ret; \
} \
BOOL _ProcessWindowMessage(HWND hWnd, \
UINT uMsg, \
WPARAM wParam, \
LPARAM lParam, \
LRESULT& lResult, \
DWORD dwMsgMapID) { \
base::WeakPtr<HWNDMessageHandler> ref(weak_factory.GetWeakPtr()); \
BOOL bHandled = TRUE; \
hWnd; \
uMsg; \
wParam; \
lParam; \
lResult; \
bHandled; \
switch(dwMsgMapID) { \
case 0:
// An object that handles messages for a HWND that implements the views
// "Custom Frame" look. The purpose of this class is to isolate the windows-
// specific message handling from the code that wraps it. It is intended to be
......@@ -360,11 +313,10 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
// Message Handlers ----------------------------------------------------------
BEGIN_SAFE_MSG_MAP_EX(weak_factory_)
CR_BEGIN_MSG_MAP_EX(HWNDMessageHandler)
// Range handlers must go first!
CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE,
WM_NCXBUTTONDBLCLK,
CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK,
OnMouseRange)
// CustomFrameWindow hacks
......@@ -771,15 +723,15 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
static base::LazyInstance<FullscreenWindowMonitorMap>::DestructorAtExit
fullscreen_monitor_map_;
// The WeakPtrFactories below must occur last in the class definition so they
// get destroyed last.
// The WeakPtrFactories below (one inside the
// CR_MSG_MAP_CLASS_DECLARATIONS macro and autohide_factory_) must
// occur last in the class definition so they get destroyed last.
CR_MSG_MAP_CLASS_DECLARATIONS(HWNDMessageHandler)
// The factory used to lookup appbar autohide edges.
base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_;
// The factory used with BEGIN_SAFE_MSG_MAP_EX.
base::WeakPtrFactory<HWNDMessageHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment