Bug 1123966 - Use FILE_FLAG_DELETE_ON_CLOSE instead of RemoveFile. r=aklotz, a=sledru
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sun, 25 Jan 2015 15:37:39 +0900
changeset 243061 6fe6b2e779ef
parent 243060 c7db1d42b4b6
child 243062 852ac927b731
push id4378
push userryanvm@gmail.com
push date2015-01-27 15:46 +0000
treeherdermozilla-beta@f91cc6838063 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz, sledru
bugs1123966
milestone36.0
Bug 1123966 - Use FILE_FLAG_DELETE_ON_CLOSE instead of RemoveFile. r=aklotz, a=sledru
dom/plugins/ipc/PluginModuleChild.cpp
dom/plugins/ipc/PluginModuleChild.h
--- a/dom/plugins/ipc/PluginModuleChild.cpp
+++ b/dom/plugins/ipc/PluginModuleChild.cpp
@@ -79,17 +79,16 @@ static PRLibrary *sGtkLib = nullptr;
 // Hooking CreateFileW for protected-mode magic
 static WindowsDllInterceptor sKernel32Intercept;
 typedef HANDLE (WINAPI *CreateFileWPtr)(LPCWSTR fname, DWORD access,
                                         DWORD share,
                                         LPSECURITY_ATTRIBUTES security,
                                         DWORD creation, DWORD flags,
                                         HANDLE ftemplate);
 static CreateFileWPtr sCreateFileWStub = nullptr;
-static WCHAR* sReplacementConfigFile;
 
 // Used with fix for flash fullscreen window loosing focus.
 static bool gDelayFlashFocusReplyUntilEval = false;
 // Used to fix GetWindowInfo problems with internal flash settings dialogs
 static WindowsDllInterceptor sUser32Intercept;
 typedef BOOL (WINAPI *GetWindowInfoPtr)(HWND hwnd, PWINDOWINFO pwi);
 static GetWindowInfoPtr sGetWindowInfoPtrStub = nullptr;
 static HWND sBrowserHwnd = nullptr;
@@ -1904,20 +1903,16 @@ PluginModuleChild::AnswerNP_Initialize(c
     *_retval = mInitializeFunc(&sBrowserFuncs, &mFunctions);
     return true;
 #elif defined(OS_WIN) || defined(OS_MACOSX)
     *_retval = mInitializeFunc(&sBrowserFuncs);
     return true;
 #else
 #  error Please implement me for your platform
 #endif
-
-#ifdef XP_WIN
-    CleanupProtectedModeHook();
-#endif
 }
 
 #if defined(XP_WIN)
 
 HANDLE WINAPI
 CreateFileHookFn(LPCWSTR fname, DWORD access, DWORD share,
                  LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags,
                  HANDLE ftemplate)
@@ -1941,17 +1936,18 @@ CreateFileHookFn(LPCWSTR fname, DWORD ac
         }
         WCHAR tempFile[MAX_PATH+1];
         if (GetTempFileNameW(tempPath, L"fx", 0, tempFile) == 0) {
             break;
         }
         HANDLE replacement =
             sCreateFileWStub(tempFile, GENERIC_READ | GENERIC_WRITE, share,
                              security, TRUNCATE_EXISTING,
-                             FILE_ATTRIBUTE_TEMPORARY,
+                             FILE_ATTRIBUTE_TEMPORARY |
+                               FILE_FLAG_DELETE_ON_CLOSE,
                              NULL);
         if (replacement == INVALID_HANDLE_VALUE) {
             break;
         }
 
         HANDLE original = sCreateFileWStub(fname, access, share, security,
                                            creation, flags, ftemplate);
         if (original != INVALID_HANDLE_VALUE) {
@@ -1971,42 +1967,31 @@ CreateFileHookFn(LPCWSTR fname, DWORD ac
             }
             CloseHandle(original);
         }
         static const char kSettingString[] = "\nProtectedMode=0\n";
         DWORD wbytes;
         WriteFile(replacement, static_cast<const void*>(kSettingString),
                   sizeof(kSettingString) - 1, &wbytes, NULL);
         SetFilePointer(replacement, 0, NULL, FILE_BEGIN);
-        sReplacementConfigFile = _wcsdup(tempFile);
         return replacement;
     }
     return sCreateFileWStub(fname, access, share, security, creation, flags,
                             ftemplate);
 }
 
 void
 PluginModuleChild::HookProtectedMode()
 {
     sKernel32Intercept.Init("kernel32.dll");
     sKernel32Intercept.AddHook("CreateFileW",
                                reinterpret_cast<intptr_t>(CreateFileHookFn),
                                (void**) &sCreateFileWStub);
 }
 
-void
-PluginModuleChild::CleanupProtectedModeHook()
-{
-    if (sReplacementConfigFile) {
-        DeleteFile(sReplacementConfigFile);
-        free(sReplacementConfigFile);
-        sReplacementConfigFile = nullptr;
-    }
-}
-
 BOOL WINAPI
 PMCGetWindowInfoHook(HWND hWnd, PWINDOWINFO pwi)
 {
   if (!pwi)
       return FALSE;
 
   if (!sGetWindowInfoPtrStub) {
      NS_ASSERTION(FALSE, "Something is horribly wrong in PMCGetWindowInfoHook!");
--- a/dom/plugins/ipc/PluginModuleChild.h
+++ b/dom/plugins/ipc/PluginModuleChild.h
@@ -297,17 +297,16 @@ private:
       mQuirks |= quirk;
     }
     void InitQuirksModes(const nsCString& aMimeType);
     bool InitGraphics();
     void DeinitGraphics();
 
 #if defined(OS_WIN)
     void HookProtectedMode();
-    void CleanupProtectedModeHook();
 #endif
 
 #if defined(MOZ_WIDGET_GTK)
     static gboolean DetectNestedEventLoop(gpointer data);
     static gboolean ProcessBrowserEvents(gpointer data);
 
     virtual void EnteredCxxStack() MOZ_OVERRIDE;
     virtual void ExitedCxxStack() MOZ_OVERRIDE;