other-licenses/7zstub/src/Windows/Window.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 // Windows/Window.cpp
     3 #include "StdAfx.h"
     5 #ifndef _UNICODE
     6 #include "Common/StringConvert.h"
     7 #endif
     8 #include "Windows/Window.h"
    10 #ifndef _UNICODE
    11 extern bool g_IsNT;
    12 #endif
    14 namespace NWindows {
    16 #ifndef _UNICODE
    17 ATOM MyRegisterClass(CONST WNDCLASSW *wndClass)
    18 {
    19   if (g_IsNT)
    20     return RegisterClassW(wndClass);
    21   WNDCLASSA wndClassA;
    22   wndClassA.style = wndClass->style; 
    23   wndClassA.lpfnWndProc = wndClass->lpfnWndProc; 
    24   wndClassA.cbClsExtra = wndClass->cbClsExtra; 
    25   wndClassA.cbWndExtra = wndClass->cbWndExtra; 
    26   wndClassA.hInstance = wndClass->hInstance; 
    27   wndClassA.hIcon = wndClass->hIcon; 
    28   wndClassA.hCursor = wndClass->hCursor; 
    29   wndClassA.hbrBackground = wndClass->hbrBackground; 
    30   AString menuName;
    31   AString className;
    32   if (IS_INTRESOURCE(wndClass->lpszMenuName))
    33     wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName;
    34   else
    35   {
    36     menuName = GetSystemString(wndClass->lpszMenuName);
    37     wndClassA.lpszMenuName = menuName;
    38   }
    39   if (IS_INTRESOURCE(wndClass->lpszClassName))
    40     wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName;
    41   else
    42   {
    43     className = GetSystemString(wndClass->lpszClassName);
    44     wndClassA.lpszClassName = className;
    45   }
    46   return RegisterClassA(&wndClassA);
    47 }
    49 bool CWindow::Create(LPCWSTR className,
    50       LPCWSTR windowName, DWORD style,
    51       int x, int y, int width, int height,
    52       HWND parentWindow, HMENU idOrHMenu, 
    53       HINSTANCE instance, LPVOID createParam)
    54 {
    55   if (g_IsNT)
    56   {
    57     _window = ::CreateWindowW(className, windowName,
    58         style, x, y, width, height, parentWindow, 
    59         idOrHMenu, instance, createParam);
    60      return (_window != NULL);
    61   }
    62   return Create(GetSystemString(className), GetSystemString(windowName),
    63         style, x, y, width, height, parentWindow, 
    64         idOrHMenu, instance, createParam);
    65 }
    67 bool CWindow::CreateEx(DWORD exStyle, LPCWSTR className,
    68       LPCWSTR windowName, DWORD style,
    69       int x, int y, int width, int height,
    70       HWND parentWindow, HMENU idOrHMenu, 
    71       HINSTANCE instance, LPVOID createParam)
    72 {
    73   if (g_IsNT)
    74   {
    75     _window = ::CreateWindowExW(exStyle, className, windowName,
    76       style, x, y, width, height, parentWindow, 
    77       idOrHMenu, instance, createParam);
    78      return (_window != NULL);
    79   }
    80   AString classNameA;
    81   LPCSTR classNameP;
    82   if (IS_INTRESOURCE(className))
    83     classNameP = (LPCSTR)className;
    84   else
    85   {
    86     classNameA = GetSystemString(className);
    87     classNameP = classNameA;
    88   }
    89   AString windowNameA;
    90   LPCSTR windowNameP;
    91   if (IS_INTRESOURCE(windowName))
    92     windowNameP = (LPCSTR)windowName;
    93   else
    94   {
    95     windowNameA = GetSystemString(windowName);
    96     windowNameP = windowNameA;
    97   }
    98   return CreateEx(exStyle, classNameP, windowNameP,
    99       style, x, y, width, height, parentWindow, 
   100       idOrHMenu, instance, createParam);
   101 }
   103 #endif
   105 #ifndef _UNICODE
   106 bool MySetWindowText(HWND wnd, LPCWSTR s)
   107 { 
   108   if (g_IsNT)
   109     return BOOLToBool(::SetWindowTextW(wnd, s));
   110   return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s)));
   111 }
   112 #endif 
   114 bool CWindow::GetText(CSysString &s)
   115 {
   116   s.Empty();
   117   int length = GetTextLength();
   118   if (length == 0)
   119     return (::GetLastError() == ERROR_SUCCESS);
   120   length = GetText(s.GetBuffer(length), length + 1);
   121   s.ReleaseBuffer();
   122   if (length == 0)
   123     return (::GetLastError() != ERROR_SUCCESS);
   124   return true;
   125 }
   127 #ifndef _UNICODE
   128 bool CWindow::GetText(UString &s)
   129 {
   130   if (g_IsNT)
   131   {
   132     s.Empty();
   133     int length = GetWindowTextLengthW(_window);
   134     if (length == 0)
   135       return (::GetLastError() == ERROR_SUCCESS);
   136     length = GetWindowTextW(_window, s.GetBuffer(length), length + 1);
   137     s.ReleaseBuffer();
   138     if (length == 0)
   139       return (::GetLastError() == ERROR_SUCCESS);
   140     return true;
   141   }
   142   CSysString sysString;
   143   bool result = GetText(sysString);
   144   s = GetUnicodeString(sysString);
   145   return result;
   146 }
   147 #endif
   150 /*
   151 bool CWindow::ModifyStyleBase(int styleOffset,
   152   DWORD remove, DWORD add, UINT flags)
   153 {
   154   DWORD style = GetWindowLong(styleOffset);
   155   DWORD newStyle = (style & ~remove) | add;
   156   if (style == newStyle)
   157     return false; // it is not good 
   159   SetWindowLong(styleOffset, newStyle);
   160   if (flags != 0)
   161   {
   162     ::SetWindowPos(_window, NULL, 0, 0, 0, 0,
   163       SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | flags);
   164   }
   165   return TRUE;
   166 }
   167 */
   169 }

mercurial