diff options
Diffstat (limited to 'chrome/renderer')
-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 |
3 files changed, 80 insertions, 0 deletions
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_ |