Made WinLauncher have better error handling, crash reporting, and modifiability.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2013 20:37:53 +0000 (20:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2013 20:37:53 +0000 (20:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122319

Patch by Alex Christensen <achristensen@webkit.org> on 2013-10-04
Reviewed by Brent Fulgham.

* WinLauncher/WinLauncher.cpp:
(WinLauncherWebHost::didFailProvisionalLoadWithError):
Don't display the numerous "Cancelled" messages that are obviously from the user.
(createCrashReport): Added.
(dllLauncherEntryPoint):
Made main loop back into while loop and write a crash report if it crashes.
* WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj:
* WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj.filters:
Added WinLauncherReplace.h.
* WinLauncher/WinLauncher.vcxproj/WinLauncherLibCommon.props:
Added linking to DbgHelp.lib.
* WinLauncher/WinLauncherReplace.h:
Added to make modifying WinLauncher behaviour and appearance easy.
(processCrashDump): Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156911 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WinLauncher/WinLauncher.cpp
Tools/WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj
Tools/WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj.filters
Tools/WinLauncher/WinLauncher.vcxproj/WinLauncherLibCommon.props
Tools/WinLauncher/WinLauncherReplace.h [new file with mode: 0644]

index 144dbff730687175b1bc76d4226de4cf7e558cb8..7ed7f4aac9bc9d94ceb627087c657a66ce928206 100644 (file)
@@ -1,3 +1,25 @@
+2013-10-04  Alex Christensen  <achristensen@webkit.org>
+
+        Made WinLauncher have better error handling, crash reporting, and modifiability.
+        https://bugs.webkit.org/show_bug.cgi?id=122319
+
+        Reviewed by Brent Fulgham.
+
+        * WinLauncher/WinLauncher.cpp:
+        (WinLauncherWebHost::didFailProvisionalLoadWithError):
+        Don't display the numerous "Cancelled" messages that are obviously from the user.
+        (createCrashReport): Added.
+        (dllLauncherEntryPoint):
+        Made main loop back into while loop and write a crash report if it crashes.
+        * WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj:
+        * WinLauncher/WinLauncher.vcxproj/WinLauncherLib.vcxproj.filters:
+        Added WinLauncherReplace.h.
+        * WinLauncher/WinLauncher.vcxproj/WinLauncherLibCommon.props:
+        Added linking to DbgHelp.lib.
+        * WinLauncher/WinLauncherReplace.h:
+        Added to make modifying WinLauncher behaviour and appearance easy.
+        (processCrashDump): Added.
+
 2013-10-04  Dirk Pranke  <dpranke@chromium.org>
 
         remove dpranke from webkitpy watchlist
index 90a3845bf7376903e7a489cd57ac86fb61367aab..76b02bdf3e9a1f084d25fd661e8fce8b7798e1ae 100644 (file)
@@ -33,6 +33,7 @@
 #include "DOMDefaultImpl.h"
 #include "PrintWebUIDelegate.h"
 #include "WinLauncherLibResource.h"
+#include "WinLauncherReplace.h"
 #include <WebKit/WebKitCOMAPI.h>
 #include <wtf/ExportMacros.h>
 #include <wtf/Platform.h>
 #include <commctrl.h>
 #include <commdlg.h>
 #include <comutil.h>
+#include <dbghelp.h>
 #include <functional>
 #include <objbase.h>
 #include <shellapi.h>
+#include <shlobj.h>
 #include <shlwapi.h>
 #include <string>
 #include <vector>
@@ -180,7 +183,8 @@ HRESULT WinLauncherWebHost::didFailProvisionalLoadWithError(IWebView*, IWebError
     if (FAILED(hr))
         errorDescription = L"Failed to load page and to localize error description.";
 
-    ::MessageBoxW(0, static_cast<LPCWSTR>(errorDescription), L"Error", MB_APPLMODAL | MB_OK);
+    if (_wcsicmp(errorDescription, L"Cancelled"))
+        ::MessageBoxW(0, static_cast<LPCWSTR>(errorDescription), L"Error", MB_APPLMODAL | MB_OK);
 
     return S_OK;
 }
@@ -408,11 +412,40 @@ static bool setToDefaultPreferences()
     return true;
 }
 
+void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
+{
+    wchar_t appDataDirectory[MAX_PATH];
+    if (FAILED(SHGetFolderPathW(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataDirectory)))
+        return;
 
-#if USE(CF)
-extern "C" void _CFRunLoopSetWindowsMessageQueueMask(CFRunLoopRef, uint32_t, CFStringRef);
+    std::wstring directory = std::wstring(appDataDirectory) + L"\\WinLauncher";
+    if (::SHCreateDirectoryEx(0, directory.c_str(), 0) != ERROR_SUCCESS
+        && ::GetLastError() != ERROR_FILE_EXISTS
+        && ::GetLastError() != ERROR_ALREADY_EXISTS)
+        return;
+
+    std::wstring fileName = directory + L"\\CrashReport.dmp";
+    HANDLE miniDumpFile = ::CreateFile(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+
+    if (miniDumpFile && miniDumpFile != INVALID_HANDLE_VALUE) {
+
+        MINIDUMP_EXCEPTION_INFORMATION mdei;
+        mdei.ThreadId = ::GetCurrentThreadId();
+        mdei.ExceptionPointers  = exceptionPointers;
+        mdei.ClientPointers = 0;
+
+#ifdef _DEBUG
+        MINIDUMP_TYPE dumpType = MiniDumpWithFullMemory;
+#else
+        MINIDUMP_TYPE dumpType = MiniDumpNormal;
 #endif
 
+        ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), miniDumpFile, dumpType, &mdei, 0, 0);
+        ::CloseHandle(miniDumpFile);
+        processCrashReport(fileName.c_str());
+    }
+}
+
 extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HINSTANCE, LPTSTR, int nCmdShow)
 {
 #ifdef _CRTDBG_MAP_ALLOC
@@ -539,8 +572,7 @@ extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HIN
         if (FAILED(hr))
             goto exit;
 
-        _bstr_t defaultHTML(L"<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>");
-        frame->loadHTMLString(defaultHTML.GetBSTR(), 0);
+        frame->loadHTMLString(_bstr_t(defaultHTML).GetBSTR(), 0);
     }
 
     hr = gWebViewPrivate->setTransparent(usesLayeredWebView());
@@ -568,18 +600,20 @@ extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HIN
     if (requestedURL.length())
         loadURL(requestedURL.GetBSTR());
 
+#pragma warning(disable:4509)
+
     // Main message loop:
+    __try {
+        while (GetMessage(&msg, 0, 0, 0)) {
 #if USE(CF)
-    _CFRunLoopSetWindowsMessageQueueMask(CFRunLoopGetMain(), QS_ALLINPUT | QS_ALLPOSTMESSAGE, kCFRunLoopDefaultMode);
-    CFRunLoopRun();
-#else
-    while (GetMessage(&msg, NULL, 0, 0)) {
-        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
-            TranslateMessage(&msg);
-            DispatchMessage(&msg);
-        }
-    }
+            CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
 #endif
+            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
+                TranslateMessage(&msg);
+                DispatchMessage(&msg);
+            }
+        }
+    } __except(createCrashReport(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { }
 
 exit:
     gPrintDelegate->Release();
index 3351001215dff8456d6a554ae01869326b70504c..b5686e0ea909be5b38faa806df064763495ad7e0 100644 (file)
     <ClInclude Include="..\PrintWebUIDelegate.h" />\r
     <ClInclude Include="..\stdafx.h" />\r
     <ClInclude Include="..\WinLauncher.h" />\r
+    <ClInclude Include="..\WinLauncherReplace.h" />\r
     <ClInclude Include="WinLauncherLibResource.h" />\r
   </ItemGroup>\r
   <ItemGroup>\r
index 5177031f33145171ef499b92fce6b0c4870aa247..3faa66b112303290e3fbcfdbcb027c9141489d40 100644 (file)
@@ -57,6 +57,9 @@
     <ClInclude Include="..\AccessibilityDelegate.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\WinLauncherReplace.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ResourceCompile Include="WinLauncherLib.rc">\r
index ff370d13c8c501afa9bce1bc80cbb7cc073f674c..3708e703fd5bae3c22c0c2c9f7339e1cf3c74f4b 100644 (file)
@@ -10,7 +10,7 @@
       <PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
     <Link>\r
-      <AdditionalDependencies>comdlg32.lib;comsuppw.lib;gdi32.lib;comctl32.lib;shlwapi.lib;user32.lib;ole32.lib;oleaut32.lib;WebKitGUID$(DebugSuffix).lib;WebKit$(DebugSuffix).lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalDependencies>DbgHelp.lib;comdlg32.lib;comsuppw.lib;gdi32.lib;comctl32.lib;shlwapi.lib;user32.lib;ole32.lib;oleaut32.lib;WebKitGUID$(DebugSuffix).lib;WebKit$(DebugSuffix).lib;%(AdditionalDependencies)</AdditionalDependencies>\r
     </Link>\r
   </ItemDefinitionGroup>\r
 </Project>
\ No newline at end of file
diff --git a/Tools/WinLauncher/WinLauncherReplace.h b/Tools/WinLauncher/WinLauncherReplace.h
new file mode 100644 (file)
index 0000000..86754f1
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013 Alex Christensen. All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This file is to make it easier for users to manage changes to the internals of WinLauncher
+
+const wchar_t* defaultHTML = L"<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>";
+
+void processCrashReport(const wchar_t* fileName) { ::MessageBox(0, fileName, L"Crash Report", MB_OK); }