widget/windows/WindowHook.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  *
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef __mozilla_WindowHook_h__
     8 #define __mozilla_WindowHook_h__
    10 #include <windows.h>
    12 #include <nsHashKeys.h>
    13 #include <nsClassHashtable.h>
    14 #include <nsTArray.h>
    16 #include "nsAppShell.h"
    18 class nsWindow;
    20 namespace mozilla {
    21 namespace widget {
    23 struct MSGResult;
    25 class WindowHook {
    26 public:
    28   // It is expected that most callbacks will return false
    29   typedef bool (*Callback)(void *aContext, HWND hWnd, UINT nMsg,
    30                              WPARAM wParam, LPARAM lParam, LRESULT *aResult);
    32   nsresult AddHook(UINT nMsg, Callback callback, void *context);
    33   nsresult RemoveHook(UINT nMsg, Callback callback, void *context);
    34   nsresult AddMonitor(UINT nMsg, Callback callback, void *context);
    35   nsresult RemoveMonitor(UINT nMsg, Callback callback, void *context);
    37 private:
    38   struct CallbackData {
    39     Callback cb;
    40     void *context;
    42     CallbackData() : cb(nullptr), context(nullptr) {}
    43     CallbackData(Callback cb, void *ctx) : cb(cb), context(ctx) {}
    44     bool Invoke(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam,
    45                   LRESULT *aResult);
    46     bool operator== (const CallbackData &rhs) const {
    47       return cb == rhs.cb && context == rhs.context;
    48     }
    49     bool operator!= (const CallbackData &rhs) const {
    50       return !(*this == rhs);
    51     }
    52     operator bool () const {
    53       return !!cb;
    54     }
    55   };
    57   typedef nsTArray<CallbackData> CallbackDataArray;
    58   struct MessageData {
    59     UINT nMsg;
    60     CallbackData hook;
    61     CallbackDataArray monitors;
    62   };
    64   bool Notify(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
    65               MSGResult& aResult);
    67   MessageData *Lookup(UINT nMsg);
    68   MessageData *LookupOrCreate(UINT nMsg);
    69   void DeleteIfEmpty(MessageData *data);
    71   typedef nsTArray<MessageData> MessageDataArray;
    72   MessageDataArray mMessageData;
    74   // For Notify
    75   friend class ::nsWindow;
    76 };
    78 }
    79 }
    81 #endif // __mozilla_WindowHook_h__

mercurial