diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 23:46:39 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 23:46:39 +0000 |
commit | 0070eab07191eaed49b945da7db9ba8e687612a5 (patch) | |
tree | fd0e54c831050a88393aa90c78af71ea6e259eb8 /base | |
parent | ca9b7dd291b73243b21c03c472544387f4886dae (diff) | |
download | chromium_src-0070eab07191eaed49b945da7db9ba8e687612a5.zip chromium_src-0070eab07191eaed49b945da7db9ba8e687612a5.tar.gz chromium_src-0070eab07191eaed49b945da7db9ba8e687612a5.tar.bz2 |
Give Mac plugin processes descriptive names for Activity Monitor
BUG=none
TEST=Open Activity Monitor, and visit a page with a plugin. The plugin process should show the name of the plugin.
Review URL: http://codereview.chromium.org/659007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39950 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/mac_util.h | 3 | ||||
-rw-r--r-- | base/mac_util.mm | 67 |
2 files changed, 70 insertions, 0 deletions
diff --git a/base/mac_util.h b/base/mac_util.h index 1a0a043..864bc24 100644 --- a/base/mac_util.h +++ b/base/mac_util.h @@ -113,6 +113,9 @@ CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, CFStringRef key, CFTypeID expected_type); +// Sets the process name as displayed in Activity Monitor to process_name. +void SetProcessName(CFStringRef process_name); + } // namespace mac_util #endif // BASE_MAC_UTIL_H_ diff --git a/base/mac_util.mm b/base/mac_util.mm index 2975b4e..79eb22b 100644 --- a/base/mac_util.mm +++ b/base/mac_util.mm @@ -318,4 +318,71 @@ CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, return value; } +void SetProcessName(CFStringRef process_name) { + // Warning: here be dragons! This is SPI reverse-engineered from WebKit's + // plugin host, and could break at any time (although realistically it's only + // likely to break in a new major release). + // When 10.7 is available, check that this still works, and update this + // comment for 10.8. + + // Private CFType used in these LaunchServices calls. + typedef CFTypeRef PrivateLSASN; + typedef PrivateLSASN (*LSGetCurrentApplicationASNType)(); + typedef OSStatus (*LSSetApplicationInformationItemType)(int, PrivateLSASN, + CFStringRef, + CFStringRef, + CFDictionaryRef*); + + static LSGetCurrentApplicationASNType ls_get_current_application_asn_func = + NULL; + static LSSetApplicationInformationItemType + ls_set_application_information_item_func = NULL; + static CFStringRef ls_display_name_key = NULL; + + static bool did_symbol_lookup = false; + if (!did_symbol_lookup) { + did_symbol_lookup = true; + CFBundleRef launch_services_bundle = + CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices")); + if (!launch_services_bundle) { + LOG(ERROR) << "Failed to look up LaunchServices bundle"; + return; + } + + ls_get_current_application_asn_func = + reinterpret_cast<LSGetCurrentApplicationASNType>( + CFBundleGetFunctionPointerForName( + launch_services_bundle, CFSTR("_LSGetCurrentApplicationASN"))); + if (!ls_get_current_application_asn_func) + LOG(ERROR) << "Could not find _LSGetCurrentApplicationASN"; + + ls_set_application_information_item_func = + reinterpret_cast<LSSetApplicationInformationItemType>( + CFBundleGetFunctionPointerForName( + launch_services_bundle, + CFSTR("_LSSetApplicationInformationItem"))); + if (!ls_set_application_information_item_func) + LOG(ERROR) << "Could not find _LSSetApplicationInformationItem"; + + const CFStringRef* key_pointer = reinterpret_cast<const CFStringRef*>( + CFBundleGetDataPointerForName(launch_services_bundle, + CFSTR("_kLSDisplayNameKey"))); + ls_display_name_key = key_pointer ? *key_pointer : NULL; + if (!ls_display_name_key) + LOG(ERROR) << "Could not find _kLSDisplayNameKey"; + } + if (!ls_get_current_application_asn_func || + !ls_set_application_information_item_func || + !ls_display_name_key) { + return; + } + + PrivateLSASN asn = ls_get_current_application_asn_func(); + // Constant used by WebKit; what exactly it means is unknown. + const int magic_session_constant = -2; + ls_set_application_information_item_func(magic_session_constant, asn, + ls_display_name_key, process_name, + NULL /* optional out param */); +} + } // namespace mac_util |