Bug 1181395 - Avoid runtime conversion or copy of names of window classes on Windows. r=jimm
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 09 Jul 2015 08:00:33 +1000
changeset 285280 64077f01ac1650c87831986897ac6c13057405e3
parent 285279 14c4e4aded9f739bb95260022dcbc92faecc7326
child 285281 a0bac7e9d49efab7857b8e9230dc5296dbade6ad
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1181395
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1181395 - Avoid runtime conversion or copy of names of window classes on Windows. r=jimm
widget/windows/nsUXThemeData.cpp
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
widget/windows/nsWindowDefs.h
--- a/widget/windows/nsUXThemeData.cpp
+++ b/widget/windows/nsUXThemeData.cpp
@@ -168,37 +168,35 @@ nsUXThemeData::UpdateTitlebarInfo(HWND a
     }
   }
 
   if (sTitlebarInfoPopulatedThemed)
     return;
 
   // Query a temporary, visible window with command buttons to get
   // the right metrics. 
-  nsAutoString className;
-  className.AssignLiteral(kClassNameTemp);
   WNDCLASSW wc;
   wc.style         = 0;
   wc.lpfnWndProc   = ::DefWindowProcW;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = nsToolkit::mDllInstance;
   wc.hIcon         = nullptr;
   wc.hCursor       = nullptr;
   wc.hbrBackground = nullptr;
   wc.lpszMenuName  = nullptr;
-  wc.lpszClassName = className.get();
+  wc.lpszClassName = kClassNameTemp;
   ::RegisterClassW(&wc);
 
   // Create a transparent descendant of the window passed in. This
   // keeps the window from showing up on the desktop or the taskbar.
   // Note the parent (browser) window is usually still hidden, we
   // don't want to display it, so we can't query it directly.
   HWND hWnd = CreateWindowExW(WS_EX_LAYERED,
-                              className.get(), L"",
+                              kClassNameTemp, L"",
                               WS_OVERLAPPEDWINDOW,
                               0, 0, 0, 0, aWnd, nullptr,
                               nsToolkit::mDllInstance, nullptr);
   NS_ASSERTION(hWnd, "UpdateTitlebarInfo window creation failed.");
 
   ShowWindow(hWnd, SW_SHOW);
   TITLEBARINFOEX info = {0};
   info.cbSize = sizeof(TITLEBARINFOEX);
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -240,19 +240,16 @@ POINT           nsWindow::sLastMousePoin
 POINT           nsWindow::sLastMouseMovePoint     = {0};
 LONG            nsWindow::sLastMouseDownTime      = 0L;
 LONG            nsWindow::sLastClickCount         = 0L;
 BYTE            nsWindow::sLastMouseButton        = 0;
 
 // Trim heap on minimize. (initialized, but still true.)
 int             nsWindow::sTrimOnMinimize         = 2;
 
-// Default value for general window class (used when the pref is the empty string).
-const char*     nsWindow::sDefaultMainWindowClass = kClassNameGeneral;
-
 TriStateBool nsWindow::sHasBogusPopupsDropShadowOnMultiMonitor = TRI_UNKNOWN;
 
 DWORD           nsWindow::sFirstEventTime = 0;
 TimeStamp       nsWindow::sFirstEventTimeStamp = TimeStamp();
 
 /**************************************************************
  *
  * SECTION: globals variables
@@ -535,17 +532,17 @@ nsWindow::Create(nsIWidget *aParent,
     } else {
       style &= ~WS_CLIPCHILDREN;
     }
     if (aInitData->clipSiblings) {
       style |= WS_CLIPSIBLINGS;
     }
   }
 
-  nsAutoString className;
+  nsString className;
   if (aInitData->mDropShadow) {
     GetWindowPopupClass(className);
   } else {
     GetWindowClass(className);
   }
   // Plugins are created in the disabled state so that they can't
   // steal focus away from our main window.  This is especially
   // important if the plugin has loaded in a background tab.
@@ -2924,17 +2921,17 @@ nsWindow::MakeFullScreen(bool aFullScree
  *
  * Set or clear native data based on a constant.
  *
  **************************************************************/
 
 // Return some native data according to aDataType
 void* nsWindow::GetNativeData(uint32_t aDataType)
 {
-  nsAutoString className;
+  nsString className;
   switch (aDataType) {
     case NS_NATIVE_TMP_WINDOW:
       GetWindowClass(className);
       return (void*)::CreateWindowExW(mIsRTL ? WS_EX_LAYOUTRTL : 0,
                                       className.get(),
                                       L"",
                                       WS_CHILD,
                                       CW_USEDEFAULT,
@@ -7557,17 +7554,17 @@ bool nsWindow::CanTakeFocus()
   return false;
 }
 
 void nsWindow::GetMainWindowClass(nsAString& aClass)
 {
   NS_PRECONDITION(aClass.IsEmpty(), "aClass should be empty string");
   nsresult rv = Preferences::GetString("ui.window_class_override", &aClass);
   if (NS_FAILED(rv) || aClass.IsEmpty()) {
-    aClass.AssignASCII(sDefaultMainWindowClass);
+    aClass.AssignLiteral(kClassNameGeneral);
   }
 }
 
 LPARAM nsWindow::lParamToScreen(LPARAM lParam)
 {
   POINT pt;
   pt.x = GET_X_LPARAM(lParam);
   pt.y = GET_Y_LPARAM(lParam);
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -494,17 +494,16 @@ protected:
   static BOOL           sIsOleInitialized;
   static HCURSOR        sHCursor;
   static imgIContainer* sCursorImgContainer;
   static bool           sSwitchKeyboardLayout;
   static bool           sJustGotDeactivate;
   static bool           sJustGotActivate;
   static bool           sIsInMouseCapture;
   static int            sTrimOnMinimize;
-  static const char*    sDefaultMainWindowClass;
 
   // Always use the helper method to read this property.  See bug 603793.
   static TriStateBool   sHasBogusPopupsDropShadowOnMultiMonitor;
   static bool           HasBogusPopupsDropShadowOnMultiMonitor();
 
   // Non-client margin settings
   // Pre-calculated outward offset applied to default frames
   nsIntMargin           mNonClientOffset;
--- a/widget/windows/nsWindowDefs.h
+++ b/widget/windows/nsWindowDefs.h
@@ -208,21 +208,21 @@ typedef enum
  *
  * ::: IMPORTANT :::
  *
  * External apps and drivers depend on window class names.
  * For example, changing the window classes could break
  * touchpad scrolling or screen readers.
  */
 const uint32_t kMaxClassNameLength   = 40;
-const char kClassNameHidden[]        = "MozillaHiddenWindowClass";
-const char kClassNameGeneral[]       = "MozillaWindowClass";
-const char kClassNameDialog[]        = "MozillaDialogClass";
-const char kClassNameDropShadow[]    = "MozillaDropShadowWindowClass";
-const char kClassNameTemp[]          = "MozillaTempWindowClass";
+const wchar_t kClassNameHidden[]     = L"MozillaHiddenWindowClass";
+const wchar_t kClassNameGeneral[]    = L"MozillaWindowClass";
+const wchar_t kClassNameDialog[]     = L"MozillaDialogClass";
+const wchar_t kClassNameDropShadow[] = L"MozillaDropShadowWindowClass";
+const wchar_t kClassNameTemp[]       = L"MozillaTempWindowClass";
 
 /**************************************************************
  *
  * SECTION: structs
  * 
  **************************************************************/
 
 // Used for synthesizing events