From ce185864d3ef3d2a3fd40ae93300a5858f961c94 Mon Sep 17 00:00:00 2001 From: "nsylvain@chromium.org" Date: Wed, 8 Jul 2009 20:16:38 +0000 Subject: Revert change 20173 because it breaks the ui_tests, plugin_tests and most likely some page cyclers. Review URL: http://codereview.chromium.org/155236 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20180 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/breakpad_win.cc | 10 +- chrome/chrome.gyp | 10 +- chrome/common/child_process_logging.h | 55 -------- chrome/common/child_process_logging_linux.cc | 22 ---- chrome/common/child_process_logging_mac.mm | 71 ----------- .../common/child_process_logging_mac_unittest.mm | 138 --------------------- chrome/common/child_process_logging_win.cc | 31 ----- chrome/common/plugin_messages.h | 5 - chrome/plugin/npobject_proxy.cc | 31 ++--- chrome/plugin/npobject_proxy.h | 10 +- chrome/plugin/npobject_stub.cc | 28 ++--- chrome/plugin/npobject_stub.h | 7 +- chrome/plugin/npobject_util.cc | 12 +- chrome/plugin/npobject_util.h | 13 +- chrome/plugin/webplugin_delegate_stub.cc | 14 +-- chrome/plugin/webplugin_delegate_stub.h | 5 +- chrome/plugin/webplugin_proxy.cc | 21 ++-- chrome/plugin/webplugin_proxy.h | 6 +- chrome/renderer/render_view.cc | 6 +- chrome/renderer/renderer_logging.h | 55 ++++++++ chrome/renderer/renderer_logging_linux.cc | 24 ++++ chrome/renderer/renderer_logging_mac.mm | 71 +++++++++++ chrome/renderer/renderer_logging_mac_unittest.mm | 138 +++++++++++++++++++++ chrome/renderer/renderer_logging_win.cc | 33 +++++ chrome/renderer/webplugin_delegate_proxy.cc | 17 +-- chrome/renderer/webplugin_delegate_proxy.h | 5 +- 26 files changed, 385 insertions(+), 453 deletions(-) delete mode 100644 chrome/common/child_process_logging.h delete mode 100644 chrome/common/child_process_logging_linux.cc delete mode 100644 chrome/common/child_process_logging_mac.mm delete mode 100644 chrome/common/child_process_logging_mac_unittest.mm delete mode 100644 chrome/common/child_process_logging_win.cc create mode 100644 chrome/renderer/renderer_logging.h create mode 100644 chrome/renderer/renderer_logging_linux.cc create mode 100644 chrome/renderer/renderer_logging_mac.mm create mode 100644 chrome/renderer/renderer_logging_mac_unittest.mm create mode 100644 chrome/renderer/renderer_logging_win.cc (limited to 'chrome') diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc index 05e60fd..3f0e1ae 100644 --- a/chrome/app/breakpad_win.cc +++ b/chrome/app/breakpad_win.cc @@ -78,10 +78,10 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& dll_path, google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); google_breakpad::CustomInfoEntry type_entry(L"ptype", type.c_str()); - if (type == L"renderer" || type == L"plugin") { - // 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. + 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""); @@ -181,7 +181,7 @@ long WINAPI ChromeExceptionFilter(EXCEPTION_POINTERS* info) { return EXCEPTION_EXECUTE_HANDLER; } -extern "C" void __declspec(dllexport) __cdecl SetActiveURL( +extern "C" void __declspec(dllexport) __cdecl SetActiveRendererURL( const wchar_t* url_cstring) { DCHECK(url_cstring); if (!g_url_chunks) diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 6bb20a5..5e86d99 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -325,10 +325,6 @@ 'common/child_process_host.h', 'common/child_process_info.cc', 'common/child_process_info.h', - 'common/child_process_logging.h', - 'common/child_process_logging_linux.cc', - 'common/child_process_logging_mac.mm', - 'common/child_process_logging_win.cc', 'common/child_thread.cc', 'common/child_thread.h', 'common/chrome_constants.cc', @@ -2328,6 +2324,10 @@ 'renderer/renderer_glue.cc', 'renderer/renderer_histogram_snapshots.cc', 'renderer/renderer_histogram_snapshots.h', + 'renderer/renderer_logging.h', + 'renderer/renderer_logging_linux.cc', + 'renderer/renderer_logging_mac.mm', + 'renderer/renderer_logging_win.cc', 'renderer/renderer_main.cc', 'renderer/renderer_main_platform_delegate.h', 'renderer/renderer_main_platform_delegate_linux.cc', @@ -3587,7 +3587,6 @@ 'browser/webdata/web_database_unittest.cc', 'browser/window_sizer_unittest.cc', 'common/bzip2_unittest.cc', - 'common/child_process_logging_mac_unittest.mm', 'common/chrome_plugin_unittest.cc', 'common/extensions/extension_unittest.cc', 'common/extensions/url_pattern_unittest.cc', @@ -3619,6 +3618,7 @@ 'renderer/render_thread_unittest.cc', 'renderer/render_view_unittest.cc', 'renderer/render_widget_unittest.cc', + 'renderer/renderer_logging_mac_unittest.mm', 'renderer/renderer_main_unittest.cc', 'test/browser_with_test_window_test.cc', 'test/browser_with_test_window_test.h', diff --git a/chrome/common/child_process_logging.h b/chrome/common/child_process_logging.h deleted file mode 100644 index 43b34d2..0000000 --- a/chrome/common/child_process_logging.h +++ /dev/null @@ -1,55 +0,0 @@ -// 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_COMMON_CHILD_PROCESS_LOGGING_H_ -#define CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ - -#include "base/basictypes.h" -#include "googleurl/src/gurl.h" - -namespace child_process_logging { - -// Sets the URL that is logged if the child process crashes. Use GURL() to clear -// the URL. -void SetActiveURL(const GURL& url); - -// Simple wrapper class that sets the active URL in it's constructor and clears -// the active URL in the destructor. -class ScopedActiveURLSetter { - public: - explicit ScopedActiveURLSetter(const GURL& url) { - SetActiveURL(url); - } - - ~ScopedActiveURLSetter() { - SetActiveURL(GURL()); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter); -}; - -} // namespace child_process_logging - -#if defined(OS_MACOSX) && __OBJC__ -// Exported for testing purposes. - -@class NSString; - -typedef void (*SetCrashKeyValueFuncPtr)(NSString*, NSString*); -typedef void (*ClearCrashKeyValueFuncPtr)(NSString*); - -namespace child_process_logging { -void SetActiveURLImpl(const GURL& url, - SetCrashKeyValueFuncPtr set_key_func, - ClearCrashKeyValueFuncPtr clear_key_func); - -extern const int kMaxNumCrashURLChunks; -extern const int kMaxNumURLChunkValueLength; -extern const char *kUrlChunkFormatStr; -} // namespace child_process_logging - -#endif // defined(OS_MACOSX) && __OBJC__ - -#endif // CHROME_COMMON_CHILD_PROCESS_LOGGING_H_ diff --git a/chrome/common/child_process_logging_linux.cc b/chrome/common/child_process_logging_linux.cc deleted file mode 100644 index 59b16f6..0000000 --- a/chrome/common/child_process_logging_linux.cc +++ /dev/null @@ -1,22 +0,0 @@ -// 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/common/child_process_logging.h" - -#include - -#include "base/logging.h" -#include "googleurl/src/gurl.h" - -namespace child_process_logging { - -// We use a static string to hold the most recent active url. If we crash, the -// crash handler code will send the contents of this string to the browser. -std::string active_url; - -void SetActiveURL(const GURL& url) { - active_url = url.possibly_invalid_spec(); -} - -} // namespace child_process_logging diff --git a/chrome/common/child_process_logging_mac.mm b/chrome/common/child_process_logging_mac.mm deleted file mode 100644 index a05b79d..0000000 --- a/chrome/common/child_process_logging_mac.mm +++ /dev/null @@ -1,71 +0,0 @@ -// 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/common/child_process_logging.h" - -#import - -#include "base/string_util.h" -#include "googleurl/src/gurl.h" -#import "chrome/app/breakpad_mac.h" - -namespace child_process_logging { - -const int kMaxNumCrashURLChunks = 8; -const int kMaxNumURLChunkValueLength = 255; -const char *kUrlChunkFormatStr = "url-chunk-%d"; - -void SetActiveURLImpl(const GURL& url, - SetCrashKeyValueFuncPtr set_key_func, - ClearCrashKeyValueFuncPtr clear_key_func) { - - NSString *kUrlChunkFormatStr_utf8 = [NSString - stringWithUTF8String:kUrlChunkFormatStr]; - - // First remove any old url chunks we might have lying around. - for (int i = 0; i < kMaxNumCrashURLChunks; i++) { - // On Windows the url-chunk items are 1-based, so match that. - NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; - clear_key_func(key); - } - - const std::string& raw_url_utf8 = url.possibly_invalid_spec(); - NSString *raw_url = [NSString stringWithUTF8String:raw_url_utf8.c_str()]; - size_t raw_url_length = [raw_url length]; - - // Bail on zero-length URLs. - if (raw_url_length == 0) { - return; - } - - // Parcel the URL up into up to 8, 255 byte segments. - size_t start_ofs = 0; - for (int i = 0; - i < kMaxNumCrashURLChunks && start_ofs < raw_url_length; - ++i) { - - // On Windows the url-chunk items are 1-based, so match that. - NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; - NSRange range; - range.location = start_ofs; - range.length = std::min((size_t)kMaxNumURLChunkValueLength, - raw_url_length - start_ofs); - NSString *value = [raw_url substringWithRange:range]; - set_key_func(key, value); - - // Next chunk. - start_ofs += kMaxNumURLChunkValueLength; - } -} - -void SetActiveURL(const GURL& url) { - // If Breakpad isn't initialized then bail. - if (IsCrashReporterDisabled()) { - return; - } - - SetActiveURLImpl(url, SetCrashKeyValue, ClearCrashKeyValue); -} - -} // namespace child_process_logging diff --git a/chrome/common/child_process_logging_mac_unittest.mm b/chrome/common/child_process_logging_mac_unittest.mm deleted file mode 100644 index 276f19b..0000000 --- a/chrome/common/child_process_logging_mac_unittest.mm +++ /dev/null @@ -1,138 +0,0 @@ -// 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/common/child_process_logging.h" - -#import - -#include "base/logging.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/platform_test.h" - -typedef PlatformTest ChildProcessLoggingTest; - -namespace { - -// Class to mock breakpad's setkeyvalue/clearkeyvalue functions needed for -// SetActiveRendererURLImpl. -// The Keys are stored in a static dictionary and methods are provided to -// verify correctness. -class MockBreakpadKeyValueStore { - public: - MockBreakpadKeyValueStore() { - // Only one of these objects can be active at once. - DCHECK(dict == NULL); - dict = [[NSMutableDictionary alloc] init]; - } - - ~MockBreakpadKeyValueStore() { - // Only one of these objects can be active at once. - DCHECK(dict != NULL); - [dict release]; - dict = NULL; - } - - static void SetKeyValue(NSString* key, NSString* value) { - DCHECK(dict != NULL); - [dict setObject:value forKey:key]; - } - - static void ClearKeyValue(NSString *key) { - DCHECK(dict != NULL); - [dict removeObjectForKey:key]; - } - - int CountDictionaryEntries() { - return [dict count]; - } - - bool VerifyDictionaryContents(const std::string &url) { - using child_process_logging::kMaxNumCrashURLChunks; - using child_process_logging::kMaxNumURLChunkValueLength; - using child_process_logging::kUrlChunkFormatStr; - - int num_url_chunks = CountDictionaryEntries(); - EXPECT_TRUE(num_url_chunks <= kMaxNumCrashURLChunks); - - NSString *kUrlChunkFormatStr_utf8 = [NSString - stringWithUTF8String:kUrlChunkFormatStr]; - - NSString *accumulated_url = @""; - for (int i = 0; i < num_url_chunks; ++i) { - // URL chunk names are 1-based. - NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; - EXPECT_TRUE(key != NULL); - NSString *value = [dict objectForKey:key]; - EXPECT_TRUE([value length] > 0); - EXPECT_TRUE([value length] <= (unsigned)kMaxNumURLChunkValueLength); - accumulated_url = [accumulated_url stringByAppendingString:value]; - } - - NSString *expected_url = [NSString stringWithUTF8String:url.c_str()]; - return([accumulated_url isEqualToString:expected_url]); - } - - private: - static NSMutableDictionary* dict; - DISALLOW_COPY_AND_ASSIGN(MockBreakpadKeyValueStore); -}; - -} // namespace - -// Call through to SetActiveURLImpl using the functions from -// MockBreakpadKeyValueStore. -void SetActiveURLWithMock(const GURL& url) { - using child_process_logging::SetActiveURLImpl; - - SetCrashKeyValueFuncPtr setFunc = MockBreakpadKeyValueStore::SetKeyValue; - ClearCrashKeyValueFuncPtr clearFunc = - MockBreakpadKeyValueStore::ClearKeyValue; - - SetActiveURLImpl(url, setFunc, clearFunc); -} - -TEST_F(ChildProcessLoggingTest, TestUrlSplitting) { - using child_process_logging::kMaxNumCrashURLChunks; - using child_process_logging::kMaxNumURLChunkValueLength; - - const std::string short_url("http://abc/"); - std::string long_url("http://"); - std::string overflow_url("http://"); - - long_url += std::string(kMaxNumURLChunkValueLength * 2, 'a'); - long_url += "/"; - - int max_num_chars_stored_in_dump = kMaxNumURLChunkValueLength * - kMaxNumCrashURLChunks; - overflow_url += std::string(max_num_chars_stored_in_dump + 1, 'a'); - overflow_url += "/"; - - // Check that Clearing NULL URL works. - MockBreakpadKeyValueStore mock; - SetActiveURLWithMock(GURL()); - EXPECT_EQ(mock.CountDictionaryEntries(), 0); - - // Check that we can set a URL. - SetActiveURLWithMock(GURL(short_url.c_str())); - EXPECT_TRUE(mock.VerifyDictionaryContents(short_url)); - EXPECT_EQ(mock.CountDictionaryEntries(), 1); - SetActiveURLWithMock(GURL()); - EXPECT_EQ(mock.CountDictionaryEntries(), 0); - - // Check that we can replace a long url with a short url. - SetActiveURLWithMock(GURL(long_url.c_str())); - EXPECT_TRUE(mock.VerifyDictionaryContents(long_url)); - SetActiveURLWithMock(GURL(short_url.c_str())); - EXPECT_TRUE(mock.VerifyDictionaryContents(short_url)); - SetActiveURLWithMock(GURL()); - EXPECT_EQ(mock.CountDictionaryEntries(), 0); - - - // Check that overflow works correctly. - SetActiveURLWithMock(GURL(overflow_url.c_str())); - EXPECT_TRUE(mock.VerifyDictionaryContents( - overflow_url.substr(0, max_num_chars_stored_in_dump))); - SetActiveURLWithMock(GURL()); - EXPECT_EQ(mock.CountDictionaryEntries(), 0); -} diff --git a/chrome/common/child_process_logging_win.cc b/chrome/common/child_process_logging_win.cc deleted file mode 100644 index 2221713..0000000 --- a/chrome/common/child_process_logging_win.cc +++ /dev/null @@ -1,31 +0,0 @@ -// 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/common/child_process_logging.h" - -#include - -#include "base/string_util.h" -#include "chrome/common/chrome_constants.h" -#include "googleurl/src/gurl.h" - -namespace child_process_logging { - -typedef void (__cdecl *MainSetActiveURL)(const wchar_t*); - -void SetActiveURL(const GURL& url) { - HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); - if (!exe_module) - return; - - MainSetActiveURL set_active_url = - reinterpret_cast( - GetProcAddress(exe_module, "SetActiveURL")); - if (!set_active_url) - return; - - (set_active_url)(UTF8ToWide(url.possibly_invalid_spec()).c_str()); -} - -} // namespace child_process_logging diff --git a/chrome/common/plugin_messages.h b/chrome/common/plugin_messages.h index 3b43b8b..111a7db 100644 --- a/chrome/common/plugin_messages.h +++ b/chrome/common/plugin_messages.h @@ -32,7 +32,6 @@ struct PluginMsg_Init_Params { gfx::NativeViewId containing_window; GURL url; - GURL page_url; std::vector arg_names; std::vector arg_values; #if defined(OS_WIN) @@ -110,7 +109,6 @@ struct ParamTraits { static void Write(Message* m, const param_type& p) { WriteParam(m, p.containing_window); WriteParam(m, p.url); - WriteParam(m, p.page_url); DCHECK(p.arg_names.size() == p.arg_values.size()); WriteParam(m, p.arg_names); WriteParam(m, p.arg_values); @@ -122,7 +120,6 @@ struct ParamTraits { static bool Read(const Message* m, void** iter, param_type* p) { return ReadParam(m, iter, &p->containing_window) && ReadParam(m, iter, &p->url) && - ReadParam(m, iter, &p->page_url) && ReadParam(m, iter, &p->arg_names) && ReadParam(m, iter, &p->arg_values) && #if defined(OS_WIN) @@ -136,8 +133,6 @@ struct ParamTraits { l->append(L", "); LogParam(p.url, l); l->append(L", "); - LogParam(p.page_url, l); - l->append(L", "); LogParam(p.arg_names, l); l->append(L", "); LogParam(p.arg_values, l); diff --git a/chrome/plugin/npobject_proxy.cc b/chrome/plugin/npobject_proxy.cc index acb3cc5..f56832a 100644 --- a/chrome/plugin/npobject_proxy.cc +++ b/chrome/plugin/npobject_proxy.cc @@ -49,13 +49,11 @@ NPObjectProxy::NPObjectProxy( PluginChannelBase* channel, int route_id, intptr_t npobject_ptr, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url) + base::WaitableEvent* modal_dialog_event) : channel_(channel), route_id_(route_id), npobject_ptr_(npobject_ptr), - modal_dialog_event_(modal_dialog_event), - page_url_(page_url) { + modal_dialog_event_(modal_dialog_event) { channel_->AddRoute(route_id, this, true); } @@ -70,12 +68,11 @@ NPObjectProxy::~NPObjectProxy() { NPObject* NPObjectProxy::Create(PluginChannelBase* channel, int route_id, intptr_t npobject_ptr, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url) { + base::WaitableEvent* modal_dialog_event) { NPObjectWrapper* obj = reinterpret_cast( NPN_CreateObject(0, &npclass_proxy_)); obj->proxy = new NPObjectProxy( - channel, route_id, npobject_ptr, modal_dialog_event, page_url); + channel, route_id, npobject_ptr, modal_dialog_event); return reinterpret_cast(obj); } @@ -169,8 +166,7 @@ bool NPObjectProxy::NPInvokePrivate(NPP npp, for (unsigned int i = 0; i < arg_count; ++i) { NPVariant_Param param; CreateNPVariantParam( - args[i], channel_copy, ¶m, false, proxy->modal_dialog_event_, - proxy->page_url_); + args[i], channel_copy, ¶m, false, proxy->modal_dialog_event_); args_param.push_back(param); } @@ -197,8 +193,7 @@ bool NPObjectProxy::NPInvokePrivate(NPP npp, return false; CreateNPVariant( - param_result, channel_copy, np_result, modal_dialog_event_handle, - proxy->page_url_); + param_result, channel_copy, np_result, modal_dialog_event_handle); return true; } @@ -256,8 +251,7 @@ bool NPObjectProxy::NPGetProperty(NPObject *obj, return false; CreateNPVariant( - param, channel.get(), np_result, modal_dialog_event_handle, - proxy->page_url_); + param, channel.get(), np_result, modal_dialog_event_handle); return true; } @@ -277,7 +271,7 @@ bool NPObjectProxy::NPSetProperty(NPObject *obj, NPVariant_Param value_param; CreateNPVariantParam( *value, proxy->channel(), &value_param, false, - proxy->modal_dialog_event_, proxy->page_url_); + proxy->modal_dialog_event_); proxy->Send(new NPObjectMsg_SetProperty( proxy->route_id(), name_param, value_param, &result)); @@ -364,8 +358,7 @@ bool NPObjectProxy::NPNConstruct(NPObject *obj, for (unsigned int i = 0; i < arg_count; ++i) { NPVariant_Param param; CreateNPVariantParam( - args[i], channel_copy, ¶m, false, proxy->modal_dialog_event_, - proxy->page_url_); + args[i], channel_copy, ¶m, false, proxy->modal_dialog_event_); args_param.push_back(param); } @@ -387,8 +380,7 @@ bool NPObjectProxy::NPNConstruct(NPObject *obj, return false; CreateNPVariant( - param_result, channel_copy, np_result, modal_dialog_event_handle, - proxy->page_url_); + param_result, channel_copy, np_result, modal_dialog_event_handle); return true; } @@ -433,8 +425,7 @@ bool NPObjectProxy::NPNEvaluate(NPP npp, return false; CreateNPVariant( - result_param, channel.get(), result_var, modal_dialog_event_handle, - proxy->page_url_); + result_param, channel.get(), result_var, modal_dialog_event_handle); return true; } diff --git a/chrome/plugin/npobject_proxy.h b/chrome/plugin/npobject_proxy.h index afeb207..3cdae9e 100644 --- a/chrome/plugin/npobject_proxy.h +++ b/chrome/plugin/npobject_proxy.h @@ -10,7 +10,6 @@ #include "base/ref_counted.h" #include "chrome/common/ipc_channel.h" -#include "googleurl/src/gurl.h" #include "third_party/npapi/bindings/npruntime.h" class PluginChannelBase; @@ -37,8 +36,7 @@ class NPObjectProxy : public IPC::Channel::Listener, static NPObject* Create(PluginChannelBase* channel, int route_id, intptr_t npobject_ptr, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url); + base::WaitableEvent* modal_dialog_event); // IPC::Message::Sender implementation: bool Send(IPC::Message* msg); @@ -103,8 +101,7 @@ class NPObjectProxy : public IPC::Channel::Listener, NPObjectProxy(PluginChannelBase* channel, int route_id, intptr_t npobject_ptr, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url); + base::WaitableEvent* modal_dialog_event); // IPC::Channel::Listener implementation: void OnMessageReceived(const IPC::Message& msg); @@ -121,9 +118,6 @@ class NPObjectProxy : public IPC::Channel::Listener, int route_id_; intptr_t npobject_ptr_; base::WaitableEvent* modal_dialog_event_; - - // The url of the main frame hosting the plugin. - GURL page_url_; }; #endif // CHROME_PLUGIN_NPOBJECT_PROXY_H_ diff --git a/chrome/plugin/npobject_stub.cc b/chrome/plugin/npobject_stub.cc index 4345d37..c5f14f5 100644 --- a/chrome/plugin/npobject_stub.cc +++ b/chrome/plugin/npobject_stub.cc @@ -4,7 +4,6 @@ #include "chrome/plugin/npobject_stub.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/plugin_messages.h" #include "chrome/plugin/npobject_util.h" #include "chrome/plugin/plugin_channel_base.h" @@ -16,15 +15,13 @@ NPObjectStub::NPObjectStub( NPObject* npobject, PluginChannelBase* channel, int route_id, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url) + base::WaitableEvent* modal_dialog_event) : npobject_(npobject), channel_(channel), route_id_(route_id), valid_(true), web_plugin_delegate_proxy_(NULL), - modal_dialog_event_(modal_dialog_event), - page_url_(page_url) { + modal_dialog_event_(modal_dialog_event) { channel_->AddRoute(route_id, this, true); // We retain the object just as PluginHost does if everything was in-process. @@ -45,8 +42,6 @@ bool NPObjectStub::Send(IPC::Message* msg) { } void NPObjectStub::OnMessageReceived(const IPC::Message& msg) { - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - if (!valid_) { if (msg.is_sync()) { // The object could be garbage because the frame has gone away, so @@ -122,8 +117,7 @@ void NPObjectStub::OnInvoke(bool is_default, NPVariant* args_var = new NPVariant[arg_count]; for (int i = 0; i < arg_count; ++i) { CreateNPVariant( - args[i], local_channel, &(args_var[i]), modal_dialog_event_, - page_url_); + args[i], local_channel, &(args_var[i]), modal_dialog_event_); } if (is_default) { @@ -159,8 +153,7 @@ void NPObjectStub::OnInvoke(bool is_default, delete[] args_var; CreateNPVariantParam( - result_var, local_channel, &result_param, true, modal_dialog_event_, - page_url_); + result_var, local_channel, &result_param, true, modal_dialog_event_); NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); local_channel->Send(reply_msg); } @@ -197,7 +190,7 @@ void NPObjectStub::OnGetProperty(const NPIdentifier_Param& name, } CreateNPVariantParam( - result_var, channel_, property, true, modal_dialog_event_, page_url_); + result_var, channel_, property, true, modal_dialog_event_); } void NPObjectStub::OnSetProperty(const NPIdentifier_Param& name, @@ -207,8 +200,7 @@ void NPObjectStub::OnSetProperty(const NPIdentifier_Param& name, VOID_TO_NPVARIANT(result_var); NPIdentifier id = CreateNPIdentifier(name); NPVariant property_var; - CreateNPVariant( - property, channel_, &property_var, modal_dialog_event_, page_url_); + CreateNPVariant(property, channel_, &property_var, modal_dialog_event_); if (IsPluginProcess()) { if (npobject_->_class->setProperty) { @@ -289,7 +281,7 @@ void NPObjectStub::OnConstruct(const std::vector& args, NPVariant* args_var = new NPVariant[arg_count]; for (int i = 0; i < arg_count; ++i) { CreateNPVariant( - args[i], local_channel, &(args_var[i]), modal_dialog_event_, page_url_); + args[i], local_channel, &(args_var[i]), modal_dialog_event_); } if (IsPluginProcess()) { @@ -310,8 +302,7 @@ void NPObjectStub::OnConstruct(const std::vector& args, delete[] args_var; CreateNPVariantParam( - result_var, local_channel, &result_param, true, modal_dialog_event_, - page_url_); + result_var, local_channel, &result_param, true, modal_dialog_event_); NPObjectMsg_Invoke::WriteReplyParams(reply_msg, result_param, return_value); local_channel->Send(reply_msg); } @@ -340,8 +331,7 @@ void NPObjectStub::OnEvaluate(const std::string& script, NPVariant_Param result_param; CreateNPVariantParam( - result_var, local_channel, &result_param, true, modal_dialog_event_, - page_url_); + result_var, local_channel, &result_param, true, modal_dialog_event_); NPObjectMsg_Evaluate::WriteReplyParams(reply_msg, result_param, return_value); local_channel->Send(reply_msg); } diff --git a/chrome/plugin/npobject_stub.h b/chrome/plugin/npobject_stub.h index acfd7727..94bf2b1 100644 --- a/chrome/plugin/npobject_stub.h +++ b/chrome/plugin/npobject_stub.h @@ -12,7 +12,6 @@ #include "base/ref_counted.h" #include "chrome/common/ipc_channel.h" -#include "googleurl/src/gurl.h" namespace base { class WaitableEvent; @@ -33,8 +32,7 @@ class NPObjectStub : public IPC::Channel::Listener, NPObjectStub(NPObject* npobject, PluginChannelBase* channel, int route_id, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url); + base::WaitableEvent* modal_dialog_event); ~NPObjectStub(); // IPC::Message::Sender implementation: @@ -92,9 +90,6 @@ class NPObjectStub : public IPC::Channel::Listener, WebPluginDelegateProxy* web_plugin_delegate_proxy_; base::WaitableEvent* modal_dialog_event_; - - // The url of the main frame hosting the plugin. - GURL page_url_; }; #endif // CHROME_PLUGIN_NPOBJECT_STUB_H_ diff --git a/chrome/plugin/npobject_util.cc b/chrome/plugin/npobject_util.cc index ecf5606..ececfa2 100644 --- a/chrome/plugin/npobject_util.cc +++ b/chrome/plugin/npobject_util.cc @@ -138,8 +138,7 @@ void CreateNPVariantParam(const NPVariant& variant, PluginChannelBase* channel, NPVariant_Param* param, bool release, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url) { + base::WaitableEvent* modal_dialog_event) { switch (variant.type) { case NPVariantType_Void: param->type = NPVARIANT_PARAM_VOID; @@ -184,8 +183,7 @@ void CreateNPVariantParam(const NPVariant& variant, param->type = NPVARIANT_PARAM_OBJECT_ROUTING_ID; int route_id = channel->GenerateRouteID(); new NPObjectStub( - variant.value.objectValue, channel, route_id, modal_dialog_event, - page_url); + variant.value.objectValue, channel, route_id, modal_dialog_event); param->npobject_routing_id = route_id; param->npobject_pointer = reinterpret_cast(variant.value.objectValue); @@ -206,8 +204,7 @@ void CreateNPVariantParam(const NPVariant& variant, void CreateNPVariant(const NPVariant_Param& param, PluginChannelBase* channel, NPVariant* result, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url) { + base::WaitableEvent* modal_dialog_event) { switch (param.type) { case NPVARIANT_PARAM_VOID: result->type = NPVariantType_Void; @@ -240,8 +237,7 @@ void CreateNPVariant(const NPVariant_Param& param, NPObjectProxy::Create(channel, param.npobject_routing_id, param.npobject_pointer, - modal_dialog_event, - page_url); + modal_dialog_event); break; case NPVARIANT_PARAM_OBJECT_POINTER: result->type = NPVariantType_Object; diff --git a/chrome/plugin/npobject_util.h b/chrome/plugin/npobject_util.h index 861d591..9a2907b 100644 --- a/chrome/plugin/npobject_util.h +++ b/chrome/plugin/npobject_util.h @@ -15,15 +15,12 @@ #include "chrome/plugin/npobject_stub.h" -class GURL; +struct _NPVariant; +typedef _NPVariant NPVariant; class NPObjectProxy; class PluginChannelBase; - -struct _NPVariant; struct NPIdentifier_Param; struct NPVariant_Param; - -typedef _NPVariant NPVariant; typedef void *NPIdentifier; namespace base { @@ -53,15 +50,13 @@ void CreateNPVariantParam(const NPVariant& variant, PluginChannelBase* channel, NPVariant_Param* param, bool release, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url); + base::WaitableEvent* modal_dialog_event); // Creates an NPVariant from the marshalled object. void CreateNPVariant(const NPVariant_Param& param, PluginChannelBase* channel, NPVariant* result, - base::WaitableEvent* modal_dialog_event, - const GURL& page_url); + base::WaitableEvent* modal_dialog_event); #if defined(OS_WIN) // Given a plugin's HWND, returns an event associated with the TabContents diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index 4d18012..3bfd002 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -7,7 +7,6 @@ #include "build/build_config.h" #include "base/command_line.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/plugin_messages.h" #include "chrome/plugin/npobject_stub.h" @@ -50,8 +49,6 @@ WebPluginDelegateStub::WebPluginDelegateStub( } WebPluginDelegateStub::~WebPluginDelegateStub() { - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - if (channel_->in_send()) { // The delegate or an npobject is in the callstack, so don't delete it // right away. @@ -67,8 +64,6 @@ WebPluginDelegateStub::~WebPluginDelegateStub() { } void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - // A plugin can execute a script to delete itself in any of its NPP methods. // Hold an extra reference to ourself so that if this does occur and we're // handling a sync message, we don't crash when attempting to send a reply. @@ -115,9 +110,6 @@ bool WebPluginDelegateStub::Send(IPC::Message* msg) { void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, bool* result) { - page_url_ = params.page_url; - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - *result = false; int argc = static_cast(params.arg_names.size()); if (argc != static_cast(params.arg_values.size())) { @@ -147,8 +139,7 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, delegate_ = WebPluginDelegate::Create(path, mime_type_, parent); if (delegate_) { - webplugin_ = new WebPluginProxy( - channel_, instance_id_, delegate_, page_url_); + webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_); #if defined(OS_WIN) if (!webplugin_->SetModalDialogEvent(params.modal_dialog_event)) return; @@ -287,8 +278,7 @@ void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, // The stub will delete itself when the proxy tells it that it's released, or // otherwise when the channel is closed. new NPObjectStub( - object, channel_.get(), *route_id, webplugin_->modal_dialog_event(), - page_url_); + object, channel_.get(), *route_id, webplugin_->modal_dialog_event()); // Release ref added by GetPluginScriptableObject (our stub holds its own). NPN_ReleaseObject(object); diff --git a/chrome/plugin/webplugin_delegate_stub.h b/chrome/plugin/webplugin_delegate_stub.h index 10ac7a4..b09038c 100644 --- a/chrome/plugin/webplugin_delegate_stub.h +++ b/chrome/plugin/webplugin_delegate_stub.h @@ -13,9 +13,9 @@ #include "base/task.h" #include "chrome/common/ipc_channel.h" #include "chrome/common/transport_dib.h" -#include "googleurl/src/gurl.h" #include "third_party/npapi/bindings/npapi.h" +class GURL; class PluginChannel; class WebPluginProxy; class WebPluginDelegate; @@ -105,9 +105,6 @@ class WebPluginDelegateStub : public IPC::Channel::Listener, WebPluginDelegate* delegate_; WebPluginProxy* webplugin_; - // The url of the main frame hosting the plugin. - GURL page_url_; - DISALLOW_IMPLICIT_CONSTRUCTORS(WebPluginDelegateStub); }; diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index b2fe778..3d6a6ac 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -13,7 +13,6 @@ #include "base/singleton.h" #include "base/waitable_event.h" #include "build/build_config.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/url_constants.h" #include "chrome/plugin/npobject_proxy.h" @@ -36,8 +35,7 @@ static ContextMap& GetContextMap() { WebPluginProxy::WebPluginProxy( PluginChannel* channel, int route_id, - WebPluginDelegate* delegate, - const GURL& page_url) + WebPluginDelegate* delegate) : channel_(channel), route_id_(route_id), cp_browsing_context_(0), @@ -45,7 +43,6 @@ WebPluginProxy::WebPluginProxy( plugin_element_(NULL), delegate_(delegate), waiting_for_paint_(false), - page_url_(page_url), ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)) { } @@ -162,9 +159,10 @@ NPObject* WebPluginProxy::GetWindowScriptNPObject() { if (!success) return NULL; - window_npobject_ = NPObjectProxy::Create( - channel_, npobject_route_id, npobject_ptr, modal_dialog_event_.get(), - page_url_); + window_npobject_ = NPObjectProxy::Create(channel_, + npobject_route_id, + npobject_ptr, + modal_dialog_event_.get()); return window_npobject_; } @@ -181,9 +179,10 @@ NPObject* WebPluginProxy::GetPluginElement() { if (!success) return NULL; - plugin_element_ = NPObjectProxy::Create( - channel_, npobject_route_id, npobject_ptr, modal_dialog_event_.get(), - page_url_); + plugin_element_ = NPObjectProxy::Create(channel_, + npobject_route_id, + npobject_ptr, + modal_dialog_event_.get()); return plugin_element_; } @@ -519,8 +518,6 @@ void WebPluginProxy::InitiateHTTPRangeRequest(const char* url, } void WebPluginProxy::OnPaint(const gfx::Rect& damaged_rect) { - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - Paint(damaged_rect); Send(new PluginHostMsg_InvalidateRect(route_id_, damaged_rect)); } diff --git a/chrome/plugin/webplugin_proxy.h b/chrome/plugin/webplugin_proxy.h index 103be5c..0388514 100644 --- a/chrome/plugin/webplugin_proxy.h +++ b/chrome/plugin/webplugin_proxy.h @@ -16,7 +16,6 @@ #include "chrome/common/ipc_message.h" #include "chrome/common/chrome_plugin_api.h" #include "chrome/common/transport_dib.h" -#include "googleurl/src/gurl.h" #include "webkit/glue/webplugin.h" namespace base { @@ -34,8 +33,7 @@ class WebPluginProxy : public WebPlugin { // marshalled WebPlugin calls. WebPluginProxy(PluginChannel* channel, int route_id, - WebPluginDelegate* delegate, - const GURL& page_url); + WebPluginDelegate* delegate); ~WebPluginProxy(); // WebPlugin overrides @@ -158,8 +156,6 @@ class WebPluginProxy : public WebPlugin { gfx::Rect damaged_rect_; bool waiting_for_paint_; scoped_ptr modal_dialog_event_; - // The url of the main frame hosting the plugin. - GURL page_url_; #if defined(OS_WIN) // Variables used for desynchronized windowless plugin painting. See note in diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index d94f484..c960798 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -23,7 +23,6 @@ #include "base/string_util.h" #include "build/build_config.h" #include "chrome/common/bindings_policy.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/jstemplate_builder.h" @@ -43,6 +42,7 @@ #include "chrome/renderer/navigation_state.h" #include "chrome/renderer/print_web_view_helper.h" #include "chrome/renderer/render_process.h" +#include "chrome/renderer/renderer_logging.h" #include "chrome/renderer/user_script_slave.h" #include "chrome/renderer/visitedlink_slave.h" #include "chrome/renderer/webplugin_delegate_proxy.h" @@ -325,7 +325,7 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd, void RenderView::OnMessageReceived(const IPC::Message& message) { WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL; - child_process_logging::ScopedActiveURLSetter url_setter( + renderer_logging::ScopedActiveRenderingURLSetter url_setter( main_frame ? main_frame->GetURL() : GURL()); // If this is developer tools renderer intercept tools messages first. @@ -626,7 +626,7 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { if (!webview()) return; - child_process_logging::ScopedActiveURLSetter url_setter(params.url); + renderer_logging::ScopedActiveRenderingURLSetter url_setter(params.url); AboutHandler::MaybeHandle(params.url); diff --git a/chrome/renderer/renderer_logging.h b/chrome/renderer/renderer_logging.h new file mode 100644 index 0000000..d7c91a5 --- /dev/null +++ b/chrome/renderer/renderer_logging.h @@ -0,0 +1,55 @@ +// 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" +#include "googleurl/src/gurl.h" + +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) { + SetActiveRendererURL(url); + } + + ~ScopedActiveRenderingURLSetter() { + SetActiveRendererURL(GURL()); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedActiveRenderingURLSetter); +}; + +} // namespace renderer_logging + +#if defined(OS_MACOSX) && __OBJC__ +// Exported for testing purposes. + +@class NSString; + +typedef void (*SetCrashKeyValueFuncPtr)(NSString*, NSString*); +typedef void (*ClearCrashKeyValueFuncPtr)(NSString*); + +namespace renderer_logging { +void SetActiveRendererURLImpl(const GURL& url, + SetCrashKeyValueFuncPtr set_key_func, + ClearCrashKeyValueFuncPtr clear_key_func); + +extern const int kMaxNumCrashURLChunks; +extern const int kMaxNumURLChunkValueLength; +extern const char *kUrlChunkFormatStr; +} // namespace renderer_logging + +#endif // defined(OS_MACOSX) && __OBJC__ + +#endif // CHROME_RENDERER_RENDERER_LOGGING_H_ diff --git a/chrome/renderer/renderer_logging_linux.cc b/chrome/renderer/renderer_logging_linux.cc new file mode 100644 index 0000000..7812da1 --- /dev/null +++ b/chrome/renderer/renderer_logging_linux.cc @@ -0,0 +1,24 @@ +// 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 + +#include "base/logging.h" +#include "googleurl/src/gurl.h" + +namespace renderer_logging { + +// We use a static string to hold the most recent active url. If we crash, the +// crash handler code will send the contents of this string to the browser. +std::string active_url; + +// Sets the URL that is logged if the renderer crashes. Use GURL() to clear +// the URL. +void SetActiveRendererURL(const GURL& url) { + active_url = url.possibly_invalid_spec(); +} + +} // namespace renderer_logging diff --git a/chrome/renderer/renderer_logging_mac.mm b/chrome/renderer/renderer_logging_mac.mm new file mode 100644 index 0000000..bb0ea92 --- /dev/null +++ b/chrome/renderer/renderer_logging_mac.mm @@ -0,0 +1,71 @@ +// 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" + +#import + +#include "base/string_util.h" +#include "googleurl/src/gurl.h" +#import "chrome/app/breakpad_mac.h" + +namespace renderer_logging { + +const int kMaxNumCrashURLChunks = 8; +const int kMaxNumURLChunkValueLength = 255; +const char *kUrlChunkFormatStr = "url-chunk-%d"; + +void SetActiveRendererURLImpl(const GURL& url, + SetCrashKeyValueFuncPtr set_key_func, + ClearCrashKeyValueFuncPtr clear_key_func) { + + NSString *kUrlChunkFormatStr_utf8 = [NSString + stringWithUTF8String:kUrlChunkFormatStr]; + + // First remove any old url chunks we might have lying around. + for (int i = 0; i < kMaxNumCrashURLChunks; i++) { + // On Windows the url-chunk items are 1-based, so match that. + NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; + clear_key_func(key); + } + + const std::string& raw_url_utf8 = url.possibly_invalid_spec(); + NSString *raw_url = [NSString stringWithUTF8String:raw_url_utf8.c_str()]; + size_t raw_url_length = [raw_url length]; + + // Bail on zero-length URLs. + if (raw_url_length == 0) { + return; + } + + // Parcel the URL up into up to 8, 255 byte segments. + size_t start_ofs = 0; + for (int i = 0; + i < kMaxNumCrashURLChunks && start_ofs < raw_url_length; + ++i) { + + // On Windows the url-chunk items are 1-based, so match that. + NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; + NSRange range; + range.location = start_ofs; + range.length = std::min((size_t)kMaxNumURLChunkValueLength, + raw_url_length - start_ofs); + NSString *value = [raw_url substringWithRange:range]; + set_key_func(key, value); + + // Next chunk. + start_ofs += kMaxNumURLChunkValueLength; + } +} + +void SetActiveRendererURL(const GURL& url) { + // If Breakpad isn't initialized then bail. + if (IsCrashReporterDisabled()) { + return; + } + + SetActiveRendererURLImpl(url, SetCrashKeyValue, ClearCrashKeyValue); +} + +} // namespace renderer_logging diff --git a/chrome/renderer/renderer_logging_mac_unittest.mm b/chrome/renderer/renderer_logging_mac_unittest.mm new file mode 100644 index 0000000..6aece64 --- /dev/null +++ b/chrome/renderer/renderer_logging_mac_unittest.mm @@ -0,0 +1,138 @@ +// 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" + +#import + +#include "base/logging.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +typedef PlatformTest RendererLoggingTest; + +namespace { + +// Class to mock breakpad's setkeyvalue/clearkeyvalue functions needed for +// SetActiveRendererURLImpl. +// The Keys are stored in a static dictionary and methods are provided to +// verify correctness. +class MockBreakpadKeyValueStore { + public: + MockBreakpadKeyValueStore() { + // Only one of these objects can be active at once. + DCHECK(dict == NULL); + dict = [[NSMutableDictionary alloc] init]; + } + + ~MockBreakpadKeyValueStore() { + // Only one of these objects can be active at once. + DCHECK(dict != NULL); + [dict release]; + dict = NULL; + } + + static void SetKeyValue(NSString* key, NSString* value) { + DCHECK(dict != NULL); + [dict setObject:value forKey:key]; + } + + static void ClearKeyValue(NSString *key) { + DCHECK(dict != NULL); + [dict removeObjectForKey:key]; + } + + int CountDictionaryEntries() { + return [dict count]; + } + + bool VerifyDictionaryContents(const std::string &url) { + using renderer_logging::kMaxNumCrashURLChunks; + using renderer_logging::kMaxNumURLChunkValueLength; + using renderer_logging::kUrlChunkFormatStr; + + int num_url_chunks = CountDictionaryEntries(); + EXPECT_TRUE(num_url_chunks <= kMaxNumCrashURLChunks); + + NSString *kUrlChunkFormatStr_utf8 = [NSString + stringWithUTF8String:kUrlChunkFormatStr]; + + NSString *accumulated_url = @""; + for (int i = 0; i < num_url_chunks; ++i) { + // URL chunk names are 1-based. + NSString *key = [NSString stringWithFormat:kUrlChunkFormatStr_utf8, i+1]; + EXPECT_TRUE(key != NULL); + NSString *value = [dict objectForKey:key]; + EXPECT_TRUE([value length] > 0); + EXPECT_TRUE([value length] <= (unsigned)kMaxNumURLChunkValueLength); + accumulated_url = [accumulated_url stringByAppendingString:value]; + } + + NSString *expected_url = [NSString stringWithUTF8String:url.c_str()]; + return([accumulated_url isEqualToString:expected_url]); + } + + private: + static NSMutableDictionary* dict; + DISALLOW_COPY_AND_ASSIGN(MockBreakpadKeyValueStore); +}; + +} // namespace + +// Call through to SetActiveRendererURLImpl using the functions from +// MockBreakpadKeyValueStore. +void SetActiveRendererURLWithMock(const GURL& url) { + using renderer_logging::SetActiveRendererURLImpl; + + SetCrashKeyValueFuncPtr setFunc = MockBreakpadKeyValueStore::SetKeyValue; + ClearCrashKeyValueFuncPtr clearFunc = + MockBreakpadKeyValueStore::ClearKeyValue; + + SetActiveRendererURLImpl(url, setFunc, clearFunc); +} + +TEST_F(RendererLoggingTest, TestUrlSplitting) { + using renderer_logging::kMaxNumCrashURLChunks; + using renderer_logging::kMaxNumURLChunkValueLength; + + const std::string short_url("http://abc/"); + std::string long_url("http://"); + std::string overflow_url("http://"); + + long_url += std::string(kMaxNumURLChunkValueLength * 2, 'a'); + long_url += "/"; + + int max_num_chars_stored_in_dump = kMaxNumURLChunkValueLength * + kMaxNumCrashURLChunks; + overflow_url += std::string(max_num_chars_stored_in_dump + 1, 'a'); + overflow_url += "/"; + + // Check that Clearing NULL URL works. + MockBreakpadKeyValueStore mock; + SetActiveRendererURLWithMock(GURL()); + EXPECT_EQ(mock.CountDictionaryEntries(), 0); + + // Check that we can set a URL. + SetActiveRendererURLWithMock(GURL(short_url.c_str())); + EXPECT_TRUE(mock.VerifyDictionaryContents(short_url)); + EXPECT_EQ(mock.CountDictionaryEntries(), 1); + SetActiveRendererURLWithMock(GURL()); + EXPECT_EQ(mock.CountDictionaryEntries(), 0); + + // Check that we can replace a long url with a short url. + SetActiveRendererURLWithMock(GURL(long_url.c_str())); + EXPECT_TRUE(mock.VerifyDictionaryContents(long_url)); + SetActiveRendererURLWithMock(GURL(short_url.c_str())); + EXPECT_TRUE(mock.VerifyDictionaryContents(short_url)); + SetActiveRendererURLWithMock(GURL()); + EXPECT_EQ(mock.CountDictionaryEntries(), 0); + + + // Check that overflow works correctly. + SetActiveRendererURLWithMock(GURL(overflow_url.c_str())); + EXPECT_TRUE(mock.VerifyDictionaryContents( + overflow_url.substr(0, max_num_chars_stored_in_dump))); + SetActiveRendererURLWithMock(GURL()); + EXPECT_EQ(mock.CountDictionaryEntries(), 0); +} diff --git a/chrome/renderer/renderer_logging_win.cc b/chrome/renderer/renderer_logging_win.cc new file mode 100644 index 0000000..6d1b758 --- /dev/null +++ b/chrome/renderer/renderer_logging_win.cc @@ -0,0 +1,33 @@ +// 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 + +#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( + GetProcAddress(exe_module, "SetActiveRendererURL")); + if (!set_active_renderer_url) + return; + + (set_active_renderer_url)(UTF8ToWide(url.possibly_invalid_spec()).c_str()); +} + +} // namespace renderer_logging diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index e7650a7..ad70db1 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -19,7 +19,6 @@ #include "base/gfx/size.h" #include "base/gfx/native_widget_types.h" #include "chrome/app/chrome_dll_resource.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/render_messages.h" #include "chrome/plugin/npobject_proxy.h" @@ -27,6 +26,7 @@ #include "chrome/plugin/npobject_util.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" +#include "googleurl/src/gurl.h" #include "grit/generated_resources.h" #include "net/base/mime_util.h" #include "printing/native_metafile.h" @@ -170,8 +170,7 @@ WebPluginDelegateProxy::WebPluginDelegateProxy(const std::string& mime_type, window_script_object_(NULL), sad_plugin_(NULL), invalidate_pending_(false), - transparent_(false), - page_url_(render_view_->webview()->GetMainFrame()->GetURL()) { + transparent_(false) { } WebPluginDelegateProxy::~WebPluginDelegateProxy() { @@ -246,7 +245,6 @@ bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn, PluginMsg_Init_Params params; params.containing_window = render_view_->host_window(); params.url = url; - params.page_url = page_url_; for (int i = 0; i < argc; ++i) { params.arg_names.push_back(argn[i]); params.arg_values.push_back(argv[i]); @@ -331,8 +329,6 @@ void WebPluginDelegateProxy::InstallMissingPlugin() { } void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { - child_process_logging::ScopedActiveURLSetter url_setter(page_url_); - IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) #if defined(OS_LINUX) @@ -612,7 +608,7 @@ NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() { npobject_ = NPObjectProxy::Create( channel_host_.get(), route_id, npobject_ptr, - render_view_->modal_dialog_event(), page_url_); + render_view_->modal_dialog_event()); return NPN_RetainObject(npobject_); } @@ -702,7 +698,7 @@ void WebPluginDelegateProxy::OnGetWindowScriptNPObject( // otherwise when the channel is closed. NPObjectStub* stub = new NPObjectStub( npobject, channel_host_.get(), route_id, - render_view_->modal_dialog_event(), page_url_); + render_view_->modal_dialog_event()); window_script_object_ = stub; window_script_object_->set_proxy(this); *success = true; @@ -722,7 +718,7 @@ void WebPluginDelegateProxy::OnGetPluginElement( // otherwise when the channel is closed. new NPObjectStub( npobject, channel_host_.get(), route_id, - render_view_->modal_dialog_event(), page_url_); + render_view_->modal_dialog_event()); *success = true; *npobject_ptr = reinterpret_cast(npobject); } @@ -813,8 +809,7 @@ void WebPluginDelegateProxy::OnGetDragData(const NPVariant_Param& object, for (size_t i = 0; i < arraysize(results); ++i) { values->push_back(NPVariant_Param()); - CreateNPVariantParam( - results[i], NULL, &values->back(), false, NULL, page_url_); + CreateNPVariantParam(results[i], NULL, &values->back(), false, NULL); } *success = true; diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index b665015..e720815 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -14,11 +14,11 @@ #include "base/ref_counted.h" #include "chrome/common/ipc_message.h" #include "chrome/renderer/plugin_channel_host.h" -#include "googleurl/src/gurl.h" #include "skia/ext/platform_canvas.h" #include "webkit/glue/webplugin.h" #include "webkit/glue/webplugin_delegate.h" +class GURL; struct NPObject; class NPObjectStub; struct NPVariant_Param; @@ -204,9 +204,6 @@ class WebPluginDelegateProxy : public WebPluginDelegate, // This lets us know which portion of the backing store has been painted into. gfx::Rect backing_store_painted_; - // The url of the main frame hosting the plugin. - GURL page_url_; - DISALLOW_EVIL_CONSTRUCTORS(WebPluginDelegateProxy); }; -- cgit v1.1