diff options
-rw-r--r-- | chrome/app/breakpad.cc | 71 | ||||
-rw-r--r-- | chrome/renderer/renderer.vcproj | 8 | ||||
-rw-r--r-- | chrome/renderer/renderer_logging.cc | 41 | ||||
-rw-r--r-- | chrome/renderer/renderer_logging.h | 31 |
4 files changed, 145 insertions, 6 deletions
diff --git a/chrome/app/breakpad.cc b/chrome/app/breakpad.cc index 19071ac..ae16adc 100644 --- a/chrome/app/breakpad.cc +++ b/chrome/app/breakpad.cc @@ -6,6 +6,7 @@ #include <windows.h> #include <tchar.h> +#include <vector> #include "base/base_switches.h" #include "base/command_line.h" @@ -30,8 +31,10 @@ const wchar_t kSystemPrincipalSid[] =L"S-1-5-18"; google_breakpad::ExceptionHandler* g_breakpad = NULL; +std::vector<wchar_t*>* url_chunks = NULL; + // Dumps the current process memory. - extern "C" void __declspec(dllexport) __cdecl DumpProcess() { +extern "C" void __declspec(dllexport) __cdecl DumpProcess() { if (g_breakpad) g_breakpad->WriteMinidump(); } @@ -57,10 +60,38 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& dll_path, version = L"0.0.0.0-devel"; } - static google_breakpad::CustomInfoEntry ver_entry(L"ver", version.c_str()); - static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); - static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); - static google_breakpad::CustomInfoEntry type_entry(L"ptype", type.c_str()); + google_breakpad::CustomInfoEntry ver_entry(L"ver", version.c_str()); + google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); + google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); + google_breakpad::CustomInfoEntry type_entry(L"ptype", type.c_str()); + + if (type == L"renderer") { + // If we're a renderer create entries for the URL. Currently we only allow + // each chunk to be 64 characters, which isn't enough for a URL. As a hack + // we create 8 entries and split the URL across the entries. + google_breakpad::CustomInfoEntry url1(L"url-chunk-1", L""); + google_breakpad::CustomInfoEntry url2(L"url-chunk-2", L""); + google_breakpad::CustomInfoEntry url3(L"url-chunk-3", L""); + google_breakpad::CustomInfoEntry url4(L"url-chunk-4", L""); + google_breakpad::CustomInfoEntry url5(L"url-chunk-5", L""); + google_breakpad::CustomInfoEntry url6(L"url-chunk-6", L""); + google_breakpad::CustomInfoEntry url7(L"url-chunk-7", L""); + google_breakpad::CustomInfoEntry url8(L"url-chunk-8", L""); + + static google_breakpad::CustomInfoEntry entries[] = + { ver_entry, prod_entry, plat_entry, type_entry, url1, url2, url3, + url4, url5, url6, url7, url8 }; + + std::vector<wchar_t*>* tmp_url_chunks = new std::vector<wchar_t*>(8); + for (size_t i = 0; i < 8; ++i) + (*tmp_url_chunks)[i] = entries[4 + i].value; + url_chunks = tmp_url_chunks; + + static google_breakpad::CustomClientInfo custom_info = {entries, + arraysize(entries)}; + + return &custom_info; + } static google_breakpad::CustomInfoEntry entries[] = {ver_entry, prod_entry, plat_entry, @@ -121,6 +152,35 @@ long WINAPI ChromeExceptionFilter(EXCEPTION_POINTERS* info) { return EXCEPTION_EXECUTE_HANDLER; } +extern "C" void __declspec(dllexport) __cdecl SetActiveRendererURL( + const wchar_t* url_cstring) { + DCHECK(url_cstring); + if (!url_chunks) + return; + + std::wstring url(url_cstring); + size_t num_chunks = url_chunks->size(); + size_t chunk_index = 0; + size_t url_size = url.size(); + + // Split the url across all the chunks. + for (size_t url_offset = 0; + chunk_index < num_chunks && url_offset < url_size; ++chunk_index) { + size_t current_chunk_size = std::min(url_size - url_offset, + static_cast<size_t>( + google_breakpad::CustomInfoEntry::kValueMaxLength - 1)); + url._Copy_s((*url_chunks)[chunk_index], + google_breakpad::CustomInfoEntry::kValueMaxLength, + current_chunk_size, url_offset); + (*url_chunks)[chunk_index][current_chunk_size] = L'\0'; + url_offset += current_chunk_size; + } + + // And null terminate any unneeded chunks. + for (; chunk_index < num_chunks; ++chunk_index) + (*url_chunks)[chunk_index][0] = L'\0'; +} + } // namespace // This function is executed by the child process that DumpDoneCallback() @@ -270,4 +330,3 @@ void InitCrashReporter(const std::wstring& dll_path) { } } } - diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj index a566716f..4f15e7f 100644 --- a/chrome/renderer/renderer.vcproj +++ b/chrome/renderer/renderer.vcproj @@ -298,6 +298,14 @@ > </File> <File + RelativePath=".\renderer_logging.cc" + > + </File> + <File + RelativePath=".\renderer_logging.h" + > + </File> + <File RelativePath=".\render_process.cc" > </File> diff --git a/chrome/renderer/renderer_logging.cc b/chrome/renderer/renderer_logging.cc new file mode 100644 index 0000000..2c708bf --- /dev/null +++ b/chrome/renderer/renderer_logging.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/renderer/renderer_logging.h" + +#include <windows.h> + +#include "base/string_util.h" +#include "chrome/common/chrome_constants.h" +#include "googleurl/src/gurl.h" + +namespace renderer_logging { + +typedef void (__cdecl *MainSetActiveRendererURL)(const wchar_t*); + +// Sets the URL that is logged if the renderer crashes. Use GURL() to clear +// the URL. +void SetActiveRendererURL(const GURL& url) { + HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); + if (!exe_module) + return; + + MainSetActiveRendererURL set_active_renderer_url = + reinterpret_cast<MainSetActiveRendererURL>( + GetProcAddress(exe_module, "SetActiveRendererURL")); + if (!set_active_renderer_url) + return; + + (set_active_renderer_url)(UTF8ToWide(url.possibly_invalid_spec()).c_str()); +} + +ScopedActiveRenderingURLSetter::ScopedActiveRenderingURLSetter(const GURL& url) { + SetActiveRendererURL(url); +} + +ScopedActiveRenderingURLSetter::~ScopedActiveRenderingURLSetter() { + SetActiveRendererURL(GURL()); +} + +} diff --git a/chrome/renderer/renderer_logging.h b/chrome/renderer/renderer_logging.h new file mode 100644 index 0000000..6be45de --- /dev/null +++ b/chrome/renderer/renderer_logging.h @@ -0,0 +1,31 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_RENDERER_RENDERER_LOGGING_H_ +#define CHROME_RENDERER_RENDERER_LOGGING_H_ + +#include "base/basictypes.h" + +class GURL; + +namespace renderer_logging { + +// Sets the URL that is logged if the renderer crashes. Use GURL() to clear +// the URL. +void SetActiveRendererURL(const GURL& url); + +// Simple wrapper class that sets the active rendering URL in it's constructor +// and clears the active rendering URL in the destructor. +class ScopedActiveRenderingURLSetter { + public: + explicit ScopedActiveRenderingURLSetter(const GURL& url); + ~ScopedActiveRenderingURLSetter(); + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedActiveRenderingURLSetter); +}; + +} // namespace renderer_logging + +#endif // CHROME_RENDERER_RENDERER_LOGGING_H_ |