diff options
47 files changed, 314 insertions, 242 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index 45f6e327..9a645b0 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -74,7 +74,7 @@ bool FilePath::IsSeparator(CharType character) { } // libgen's dirname and basename aren't guaranteed to be thread-safe and aren't -// guaranteed to not modify their input strings, and in fact are implmeneted +// guaranteed to not modify their input strings, and in fact are implemented // differently in this regard on different platforms. Don't use them, but // adhere to their behavior. FilePath FilePath::DirName() const { diff --git a/base/file_path.h b/base/file_path.h index cadf2cf..7beb40e 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -69,10 +69,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" - -#if defined(COMPILER_GCC) #include "base/hash_tables.h" -#endif // Windows-style drive letter support and pathname separator characters can be // enabled and disabled independently, to aid testing. These #defines are @@ -204,8 +201,8 @@ class FilePath { #define FILE_PATH_LITERAL(x) L ## x #endif // OS_WIN -#if defined(COMPILER_GCC) // Implement hash function so that we can use FilePaths in hashsets and maps. +#if defined(COMPILER_GCC) namespace __gnu_cxx { template<> @@ -216,6 +213,14 @@ struct hash<FilePath> { }; } // namespace __gnu_cxx -#endif // defined(COMPILER_GCC) +#elif defined(COMPILER_MSVC) +namespace stdext { + +inline size_t hash_value(const FilePath& f) { + return hash_value(f.value()); +} + +} // namespace stdext +#endif // COMPILER #endif // BASE_FILE_PATH_H_ diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 6b0e025..0687e4f 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -566,7 +566,7 @@ void AboutMemoryHandler::AppendProcess(ListValue* renderers, renderer->SetString(L"renderer_id", label); FileVersionInfo* version_info = FileVersionInfo::CreateFileVersionInfo( - (*plugins())[index].dll_path); + (*plugins())[index].plugin_path); if (version_info) name = version_info->product_name(); ListValue* titles = new ListValue(); diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index fe58ec0..0ad784d 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -81,7 +81,7 @@ void MemoryDetails::CollectPluginInformation() { PluginProcessInformation info; info.pid = base::GetProcId(plugin->process()); if (info.pid != 0) { - info.dll_path = plugin->dll_path(); + info.plugin_path = plugin->plugin_path(); plugins_.push_back(info); } } diff --git a/chrome/browser/memory_details.h b/chrome/browser/memory_details.h index 8f0f03b..0a542cc 100644 --- a/chrome/browser/memory_details.h +++ b/chrome/browser/memory_details.h @@ -9,6 +9,7 @@ #include <string> #include <vector> +#include "base/file_path.h" #include "base/process_util.h" #include "base/ref_counted.h" @@ -44,7 +45,7 @@ typedef std::vector<ProcessMemoryInformation> ProcessMemoryInformationList; // Information that we need about a plugin process. struct PluginProcessInformation { int pid; - std::wstring dll_path; + FilePath plugin_path; }; typedef std::vector<PluginProcessInformation> PluginProcessInformationList; diff --git a/chrome/browser/metrics_log.cc b/chrome/browser/metrics_log.cc index 24e94e5..60851bf 100644 --- a/chrome/browser/metrics_log.cc +++ b/chrome/browser/metrics_log.cc @@ -445,7 +445,7 @@ void MetricsLog::WritePluginList( // Plugin name and filename are hashed for the privacy of those // testing unreleased new extensions. WriteAttribute("name", CreateBase64Hash(WideToUTF8((*iter).name))); - std::wstring filename = file_util::GetFilenameFromPath((*iter).file); + std::wstring filename = (*iter).file.BaseName().ToWStringHack(); WriteAttribute("filename", CreateBase64Hash(WideToUTF8(filename))); WriteAttribute("version", WideToUTF8((*iter).version)); diff --git a/chrome/browser/metrics_service.cc b/chrome/browser/metrics_service.cc index ec374de..acc9933 100644 --- a/chrome/browser/metrics_service.cc +++ b/chrome/browser/metrics_service.cc @@ -158,6 +158,7 @@ #include "chrome/browser/metrics_service.h" +#include "base/file_path.h" #include "base/histogram.h" #include "base/path_service.h" #include "base/string_util.h" @@ -1507,7 +1508,7 @@ void MetricsService::LogRendererHang() { void MetricsService::LogPluginChange(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - std::wstring plugin = Details<PluginProcessInfo>(details)->dll_path(); + FilePath plugin = Details<PluginProcessInfo>(details)->plugin_path(); if (plugin_stats_buffer_.find(plugin) == plugin_stats_buffer_.end()) { plugin_stats_buffer_[plugin] = PluginStats(); @@ -1591,13 +1592,14 @@ void MetricsService::RecordPluginChanges(PrefService* pref) { } DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*value_iter); - std::wstring plugin_path; - plugin_dict->GetString(prefs::kStabilityPluginPath, &plugin_path); - if (plugin_path.empty()) { + FilePath::StringType plugin_path_str; + plugin_dict->GetString(prefs::kStabilityPluginPath, &plugin_path_str); + if (plugin_path_str.empty()) { NOTREACHED(); continue; } + FilePath plugin_path(plugin_path_str); if (plugin_stats_buffer_.find(plugin_path) == plugin_stats_buffer_.end()) continue; @@ -1626,14 +1628,14 @@ void MetricsService::RecordPluginChanges(PrefService* pref) { // Now go through and add dictionaries for plugins that didn't already have // reports in Local State. - for (std::map<std::wstring, PluginStats>::iterator cache_iter = + for (std::map<FilePath, PluginStats>::iterator cache_iter = plugin_stats_buffer_.begin(); cache_iter != plugin_stats_buffer_.end(); ++cache_iter) { - std::wstring plugin_path = cache_iter->first; + FilePath plugin_path = cache_iter->first; PluginStats stats = cache_iter->second; DictionaryValue* plugin_dict = new DictionaryValue; - plugin_dict->SetString(prefs::kStabilityPluginPath, plugin_path); + plugin_dict->SetString(prefs::kStabilityPluginPath, plugin_path.value()); plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, stats.process_launches); plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, diff --git a/chrome/browser/metrics_service.h b/chrome/browser/metrics_service.h index fe8ce9b..137b534 100644 --- a/chrome/browser/metrics_service.h +++ b/chrome/browser/metrics_service.h @@ -15,6 +15,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/histogram.h" #include "base/scoped_ptr.h" #include "base/values.h" @@ -422,7 +423,7 @@ class MetricsService : public NotificationObserver, // Buffer of plugin notifications for quick access. See PluginStats // documentation above for more details. - std::map<std::wstring, PluginStats> plugin_stats_buffer_; + std::map<FilePath, PluginStats> plugin_stats_buffer_; ScopedRunnableMethodFactory<MetricsService> log_sender_factory_; ScopedRunnableMethodFactory<MetricsService> state_saver_factory_; diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc index 4dcb107..351d586 100644 --- a/chrome/browser/plugin_process_host.cc +++ b/chrome/browser/plugin_process_host.cc @@ -48,20 +48,20 @@ static const char kDefaultPluginFinderURL[] = class PluginNotificationTask : public Task { public: PluginNotificationTask(NotificationType notification_type, - std::wstring dll_path, + FilePath dll_path, HANDLE process); virtual void Run(); private: NotificationType notification_type_; - std::wstring dll_path_; + FilePath dll_path_; HANDLE process_; }; PluginNotificationTask::PluginNotificationTask( NotificationType notification_type, - std::wstring dll_path, + FilePath dll_path, HANDLE process) : notification_type_(notification_type), process_(process), @@ -361,12 +361,12 @@ PluginProcessHost::~PluginProcessHost() { } } -bool PluginProcessHost::Init(const std::wstring& dll, +bool PluginProcessHost::Init(const FilePath& dll, const std::string& activex_clsid, const std::wstring& locale) { DCHECK(channel_.get() == NULL); - dll_path_ = dll; + plugin_path_ = dll; channel_id_ = GenerateRandomChannelID(this); channel_.reset(new IPC::Channel(channel_id_, IPC::Channel::MODE_SERVER, @@ -439,7 +439,7 @@ bool PluginProcessHost::Init(const std::wstring& dll, CommandLine::AppendSwitchWithValue(&cmd_line, switches::kPluginPath, - dll); + dll.ToWStringHack()); bool in_sandbox = !browser_command_line.HasSwitch(switches::kNoSandbox) && browser_command_line.HasSwitch(switches::kSafePlugins); @@ -492,12 +492,11 @@ bool PluginProcessHost::Init(const std::wstring& dll, watcher_.StartWatching(process_.handle(), this); - std::wstring gears_path; - std::wstring dll_lc = dll; + FilePath gears_path; if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) { - StringToLowerASCII(&gears_path); - StringToLowerASCII(&dll_lc); - if (dll_lc == gears_path) { + FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value()); + FilePath::StringType dll_lc = StringToLowerASCII(dll.value()); + if (dll_lc == gears_path_lc) { // Give Gears plugins "background" priority. See // http://b/issue?id=1280317. process_.SetProcessBackgrounded(true); @@ -528,12 +527,12 @@ void PluginProcessHost::OnObjectSignaled(HANDLE object) { // Report that this plugin crashed. plugin_service_->main_message_loop()->PostTask(FROM_HERE, new PluginNotificationTask(NOTIFY_PLUGIN_PROCESS_CRASHED, - dll_path(), object)); + plugin_path(), object)); } // Notify in the main loop of the disconnection. plugin_service_->main_message_loop()->PostTask(FROM_HERE, new PluginNotificationTask(NOTIFY_PLUGIN_PROCESS_HOST_DISCONNECTED, - dll_path(), object)); + plugin_path(), object)); // Cancel all requests for plugin processes. // TODO(mpcomplete): use a real process ID when http://b/issue?id=1210062 is @@ -601,7 +600,7 @@ void PluginProcessHost::OnChannelConnected(int32 peer_pid) { // Notify in the main loop of the connection. plugin_service_->main_message_loop()->PostTask(FROM_HERE, new PluginNotificationTask(NOTIFY_PLUGIN_PROCESS_HOST_CONNECTED, - dll_path(), process())); + plugin_path(), process())); } void PluginProcessHost::OnChannelError() { @@ -609,7 +608,7 @@ void PluginProcessHost::OnChannelError() { for (size_t i = 0; i < pending_requests_.size(); ++i) { ReplyToRenderer(pending_requests_[i].renderer_message_filter_.get(), std::wstring(), - std::wstring(), + FilePath(), pending_requests_[i].reply_msg); } @@ -623,7 +622,7 @@ void PluginProcessHost::OpenChannelToPlugin( // Notify in the main loop of the instantiation. plugin_service_->main_message_loop()->PostTask(FROM_HERE, new PluginNotificationTask(NOTIFY_PLUGIN_INSTANCE_CREATED, - dll_path(), process())); + plugin_path(), process())); if (opening_channel_) { pending_requests_.push_back( @@ -633,7 +632,7 @@ void PluginProcessHost::OpenChannelToPlugin( if (!channel_.get()) { // There was an error opening the channel, tell the renderer. - ReplyToRenderer(renderer_message_filter, std::wstring(), std::wstring(), + ReplyToRenderer(renderer_message_filter, std::wstring(), FilePath(), reply_msg); return; } @@ -732,7 +731,7 @@ void PluginProcessHost::OnResolveProxy(const GURL& url, void PluginProcessHost::ReplyToRenderer( ResourceMessageFilter* renderer_message_filter, - const std::wstring& channel, const std::wstring& plugin_path, + const std::wstring& channel, const FilePath& plugin_path, IPC::Message* reply_msg) { ViewHostMsg_OpenChannelToPlugin::WriteReplyParams(reply_msg, channel, plugin_path); @@ -765,7 +764,7 @@ void PluginProcessHost::RequestPluginChannel( sent_requests_.push_back(ChannelRequest(renderer_message_filter, mime_type, reply_msg)); } else { - ReplyToRenderer(renderer_message_filter, std::wstring(), std::wstring(), + ReplyToRenderer(renderer_message_filter, std::wstring(), FilePath(), reply_msg); } } @@ -777,7 +776,7 @@ void PluginProcessHost::OnChannelCreated(int process_id, == process_id) { ReplyToRenderer(sent_requests_[i].renderer_message_filter_.get(), channel_name, - dll_path(), + plugin_path(), sent_requests_[i].reply_msg); sent_requests_.erase(sent_requests_.begin() + i); @@ -825,7 +824,7 @@ void PluginProcessHost::OnPluginMessage( DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - ChromePluginLib *chrome_plugin = ChromePluginLib::Find(dll_path_); + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path_); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h index a61d8d0..fb9dfe8 100644 --- a/chrome/browser/plugin_process_host.h +++ b/chrome/browser/plugin_process_host.h @@ -43,7 +43,7 @@ class PluginProcessHost : public IPC::Channel::Listener, // be called before the object can be used. If dll is the ActiveX-shim, then // activex_clsid is the class id of ActiveX control, otherwise activex_clsid // is ignored. - bool Init(const std::wstring& dll, + bool Init(const FilePath& dll, const std::string& activex_clsid, const std::wstring& locale); @@ -68,13 +68,13 @@ class PluginProcessHost : public IPC::Channel::Listener, const std::string& mime_type, IPC::Message* reply_msg); - const std::wstring& dll_path() const { return dll_path_; } + const FilePath& plugin_path() const { return plugin_path_; } // Sends the reply to an open channel request to the renderer with the given // channel name. static void ReplyToRenderer(ResourceMessageFilter* renderer_message_filter, const std::wstring& channel, - const std::wstring& plugin_path, + const FilePath& plugin_path, IPC::Message* reply_msg); // This function is called on the IO thread once we receive a reply from the @@ -150,8 +150,8 @@ class PluginProcessHost : public IPC::Channel::Listener, // IPC Channel's id. std::wstring channel_id_; - // Path to the DLL of that plugin. - std::wstring dll_path_; + // Path to the file of that plugin. + FilePath plugin_path_; PluginService* plugin_service_; diff --git a/chrome/browser/plugin_process_info.h b/chrome/browser/plugin_process_info.h index badc902..90fc4f0 100644 --- a/chrome/browser/plugin_process_info.h +++ b/chrome/browser/plugin_process_info.h @@ -14,15 +14,17 @@ #include <string> #include "windows.h" +#include "base/file_path.h" + class PluginProcessInfo { public: - PluginProcessInfo(std::wstring dll_path, HANDLE process) - : dll_path_(dll_path), + PluginProcessInfo(FilePath plugin_path, HANDLE process) + : plugin_path_(plugin_path), process_(process) { } PluginProcessInfo(const PluginProcessInfo& ppi) { - dll_path_ = ppi.dll_path_; + plugin_path_ = ppi.plugin_path_; process_ = ppi.process_; } @@ -31,7 +33,7 @@ class PluginProcessInfo { PluginProcessInfo& PluginProcessInfo::operator=(const PluginProcessInfo& ppi) { if (this != &ppi) { - dll_path_ = ppi.dll_path_; + plugin_path_ = ppi.plugin_path_; process_ = ppi.process_; } return *this; @@ -42,19 +44,19 @@ class PluginProcessInfo { bool operator <(const PluginProcessInfo& rhs) const { if (process_ != rhs.process_) return process_ < rhs.process_; - return dll_path_ < rhs.dll_path_; + return plugin_path_ < rhs.plugin_path_; } bool operator ==(const PluginProcessInfo& rhs) const { - return (process_ == rhs.process_) && (dll_path_ == rhs.dll_path_); + return (process_ == rhs.process_) && (plugin_path_ == rhs.plugin_path_); } - std::wstring dll_path() const { return dll_path_; } + FilePath plugin_path() const { return plugin_path_; } HANDLE process() const { return process_; } private: - std::wstring dll_path_; + FilePath plugin_path_; HANDLE process_; }; diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index ac2a3aa..a58787c 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -59,11 +59,11 @@ const std::wstring& PluginService::GetUILocale() { return ui_locale_; } -PluginProcessHost* PluginService::FindPluginProcess(const std::wstring& dll) { +PluginProcessHost* PluginService::FindPluginProcess(const FilePath& dll) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - if (dll.empty()) { + if (dll.value().empty()) { NOTREACHED() << "should only be called if we have a plugin dll to load"; return NULL; } @@ -75,7 +75,7 @@ PluginProcessHost* PluginService::FindPluginProcess(const std::wstring& dll) { } PluginProcessHost* PluginService::FindOrStartPluginProcess( - const std::wstring& dll, + const FilePath& dll, const std::string& clsid) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); @@ -106,14 +106,14 @@ void PluginService::OpenChannelToPlugin( const std::wstring& locale, IPC::Message* reply_msg) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - std::wstring dll = GetPluginPath(url, mime_type, clsid, NULL); + FilePath dll = GetPluginPath(url, mime_type, clsid, NULL); PluginProcessHost* plugin_host = FindOrStartPluginProcess(dll, clsid); if (plugin_host) { plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); } else { PluginProcessHost::ReplyToRenderer(renderer_msg_filter, std::wstring(), - std::wstring(), + FilePath(), reply_msg); } } @@ -143,10 +143,10 @@ void PluginService::RemoveHost(PluginProcessHost* host) { } } -std::wstring PluginService::GetPluginPath(const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type) { +FilePath PluginService::GetPluginPath(const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type) { AutoLock lock(lock_); bool allow_wildcard = true; WebPluginInfo info; @@ -156,7 +156,7 @@ std::wstring PluginService::GetPluginPath(const GURL& url, return info.file; } -bool PluginService::GetPluginInfoByDllPath(const std::wstring& dll_path, +bool PluginService::GetPluginInfoByDllPath(const FilePath& dll_path, WebPluginInfo* info) { AutoLock lock(lock_); return NPAPI::PluginList::Singleton()->GetPluginInfoByDllPath(dll_path, info); diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h index a28b502..e34552a 100644 --- a/chrome/browser/plugin_service.h +++ b/chrome/browser/plugin_service.h @@ -57,13 +57,13 @@ class PluginService { // Returns the plugin process host corresponding to the plugin process that // has been started by this service. Returns NULL if no process has been // started. - PluginProcessHost* FindPluginProcess(const std::wstring& dll); + PluginProcessHost* FindPluginProcess(const FilePath& dll); // Returns the plugin process host corresponding to the plugin process that // has been started by this service. This will start a process to host the // 'dll' if needed. If the process fails to start, the return value is NULL. // Must be called on the IO thread. - PluginProcessHost* FindOrStartPluginProcess(const std::wstring& dll, + PluginProcessHost* FindOrStartPluginProcess(const FilePath& dll, const std::string& clsid); // Opens a channel to a plugin process for the given mime type, starting @@ -85,13 +85,13 @@ class PluginService { bool HavePluginFor(const std::string& mime_type, bool allow_wildcard); - std::wstring GetPluginPath(const GURL& url, - const std::string& mime_type, - const std::string& clsid, - std::string* actual_mime_type); + FilePath GetPluginPath(const GURL& url, + const std::string& mime_type, + const std::string& clsid, + std::string* actual_mime_type); // Get plugin info by matching full dll path. - bool GetPluginInfoByDllPath(const std::wstring& dll_path, + bool GetPluginInfoByDllPath(const FilePath& dll_path, WebPluginInfo* info); // Returns true if the plugin's mime-type supports a given mime-type. @@ -121,7 +121,7 @@ class PluginService { void OnShutdown(); // mapping between plugin dll path and PluginProcessHost - typedef base::hash_map<std::wstring, PluginProcessHost*> PluginMap; + typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; PluginMap plugin_hosts_; // The main thread's message loop. diff --git a/chrome/browser/render_view_host_delegate.h b/chrome/browser/render_view_host_delegate.h index f0c4b0e..4cb7dcc 100644 --- a/chrome/browser/render_view_host_delegate.h +++ b/chrome/browser/render_view_host_delegate.h @@ -335,7 +335,7 @@ class RenderViewHostDelegate { virtual void OnMissingPluginStatus(int status) { } // Notification from the renderer that a plugin instance has crashed. - virtual void OnCrashedPlugin(const std::wstring& plugin_path) { } + virtual void OnCrashedPlugin(const FilePath& plugin_path) { } // Notification from the renderer that JS runs out of memory. virtual void OnJSOutOfMemory() { } diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc index e4e8409..76b7fe4 100644 --- a/chrome/browser/resource_message_filter.cc +++ b/chrome/browser/resource_message_filter.cc @@ -308,12 +308,12 @@ void ResourceMessageFilter::OnGetDataDir(std::wstring* data_dir) { *data_dir = plugin_service_->GetChromePluginDataDir(); } -void ResourceMessageFilter::OnPluginMessage(const std::wstring& dll_path, +void ResourceMessageFilter::OnPluginMessage(const FilePath& plugin_path, const std::vector<uint8>& data) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - ChromePluginLib *chrome_plugin = ChromePluginLib::Find(dll_path); + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); @@ -321,13 +321,13 @@ void ResourceMessageFilter::OnPluginMessage(const std::wstring& dll_path, } } -void ResourceMessageFilter::OnPluginSyncMessage(const std::wstring& dll_path, +void ResourceMessageFilter::OnPluginSyncMessage(const FilePath& plugin_path, const std::vector<uint8>& data, std::vector<uint8> *retval) { DCHECK(MessageLoop::current() == ChromeThread::GetMessageLoop(ChromeThread::IO)); - ChromePluginLib *chrome_plugin = ChromePluginLib::Find(dll_path); + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); @@ -398,7 +398,7 @@ void ResourceMessageFilter::OnGetPlugins(bool refresh, void ResourceMessageFilter::OnGetPluginPath(const GURL& url, const std::string& mime_type, const std::string& clsid, - std::wstring* filename, + FilePath* filename, std::string* url_mime_type) { *filename = plugin_service_->GetPluginPath(url, mime_type, clsid, url_mime_type); diff --git a/chrome/browser/resource_message_filter.h b/chrome/browser/resource_message_filter.h index 44f0fd2..e2d67ca 100644 --- a/chrome/browser/resource_message_filter.h +++ b/chrome/browser/resource_message_filter.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H__ #include "base/clipboard.h" +#include "base/file_path.h" #include "base/gfx/rect.h" #include "base/gfx/native_widget_types.h" #include "base/ref_counted.h" @@ -92,9 +93,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetCookies(const GURL& url, const GURL& policy_url, std::string* cookies); void OnGetDataDir(std::wstring* data_dir); - void OnPluginMessage(const std::wstring& dll_path, + void OnPluginMessage(const FilePath& plugin_path, const std::vector<uint8>& message); - void OnPluginSyncMessage(const std::wstring& dll_path, + void OnPluginSyncMessage(const FilePath& plugin_path, const std::vector<uint8>& message, std::vector<uint8> *retval); @@ -107,7 +108,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetPluginPath(const GURL& url, const std::string& mime_type, const std::string& clsid, - std::wstring* filename, + FilePath* filename, std::string* actual_mime_type); void OnOpenChannelToPlugin(const GURL& url, const std::string& mime_type, diff --git a/chrome/browser/sandbox_policy.cc b/chrome/browser/sandbox_policy.cc index 5b9dcc8..5e0e999 100644 --- a/chrome/browser/sandbox_policy.cc +++ b/chrome/browser/sandbox_policy.cc @@ -70,10 +70,10 @@ const wchar_t* const kTroublesomeDlls[] = { } // namespace PluginPolicyCategory GetPolicyCategoryForPlugin( - const std::wstring& dll, + const FilePath& dll, const std::wstring& clsid, const std::wstring& list) { - std::wstring filename = file_util::GetFilenameFromPath(dll); + std::wstring filename = dll.BaseName().value(); std::wstring plugin_dll = StringToLowerASCII(filename); std::wstring trusted_plugins = StringToLowerASCII(list); std::wstring activex_clsid = StringToLowerASCII(clsid); @@ -297,7 +297,7 @@ bool ApplyPolicyForUntrustedPlugin(sandbox::TargetPolicy* policy) { return true; } -bool AddPolicyForPlugin(const std::wstring &plugin_dll, +bool AddPolicyForPlugin(const FilePath &plugin_dll, const std::string &activex_clsid, const std::wstring &trusted_plugins, sandbox::TargetPolicy* policy) { diff --git a/chrome/browser/sandbox_policy.h b/chrome/browser/sandbox_policy.h index 3beafdd..3711073 100644 --- a/chrome/browser/sandbox_policy.h +++ b/chrome/browser/sandbox_policy.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_SANDBOX_POLICY_H_ #include <string> + +#include "base/file_path.h" #include "sandbox/src/sandbox.h" #include "webkit/activex_shim/activex_shared.h" @@ -23,7 +25,7 @@ bool AddPolicyForGearsInRenderer(sandbox::TargetPolicy* policy); // |trusted_plugins| contains the comma separate list of plugins that should // not be sandboxed. The plugin in the list can be either the plugin dll name // of the class id if it's an ActiveX. -bool AddPolicyForPlugin(const std::wstring &plugin_dll, +bool AddPolicyForPlugin(const FilePath &plugin_dll, const std::string &activex_clsid, const std::wstring &trusted_plugins, sandbox::TargetPolicy* policy); @@ -35,7 +37,7 @@ enum PluginPolicyCategory { // Returns the policy category for the plugin dll. PluginPolicyCategory GetPolicyCategoryForPlugin( - const std::wstring& plugin_dll, + const FilePath& plugin_dll, const std::wstring& activex_clsid, const std::wstring& trusted_plugins); diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 6e62e7a..71ed524 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -249,7 +249,7 @@ std::wstring TaskManagerPluginProcessResource::GetTitle() const { std::wstring plugin_name; WebPluginInfo info; if (PluginService::GetInstance()-> - GetPluginInfoByDllPath(plugin_process_.dll_path(), &info)) + GetPluginInfoByDllPath(plugin_process_.plugin_path(), &info)) plugin_name = info.name; else plugin_name = l10n_util::GetString(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); @@ -406,7 +406,7 @@ void TaskManagerPluginProcessResourceProvider::RetrievePluginProcessInfo() { for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { PluginProcessHost* plugin = const_cast<PluginProcessHost*>(*iter); DCHECK(plugin->process()); - PluginProcessInfo plugin_info(plugin->dll_path(), plugin->process()); + PluginProcessInfo plugin_info(plugin->plugin_path(), plugin->process()); existing_plugin_process_info.push_back(plugin_info); } // Now notify the UI thread that we have retrieved the PluginProcessHosts. diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 5f1c124..cef4558 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -1257,10 +1257,10 @@ void WebContents::OnMissingPluginStatus(int status) { GetPluginInstaller()->OnMissingPluginStatus(status); } -void WebContents::OnCrashedPlugin(const std::wstring& plugin_path) { - DCHECK(!plugin_path.empty()); +void WebContents::OnCrashedPlugin(const FilePath& plugin_path) { + DCHECK(!plugin_path.value().empty()); - std::wstring plugin_name = plugin_path; + std::wstring plugin_name = plugin_path.ToWStringHack(); scoped_ptr<FileVersionInfo> version_info( FileVersionInfo::CreateFileVersionInfo(plugin_path)); if (version_info.get()) { diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index 359a294..b14d07a 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -288,7 +288,7 @@ class WebContents : public TabContents, virtual GURL GetAlternateErrorPageURL() const; virtual WebPreferences GetWebkitPrefs(); virtual void OnMissingPluginStatus(int status); - virtual void OnCrashedPlugin(const std::wstring& plugin_path); + virtual void OnCrashedPlugin(const FilePath& plugin_path); virtual void OnJSOutOfMemory(); virtual void ShouldClosePage(bool proceed) { render_manager_.ShouldClosePage(proceed); diff --git a/chrome/common/chrome_plugin_lib.cc b/chrome/common/chrome_plugin_lib.cc index 642c623..d9848c9 100644 --- a/chrome/common/chrome_plugin_lib.cc +++ b/chrome/common/chrome_plugin_lib.cc @@ -25,7 +25,7 @@ const TCHAR ChromePluginLib::kRegistryChromePlugins[] = static const TCHAR kRegistryLoadOnStartup[] = _T("LoadOnStartup"); static const TCHAR kRegistryPath[] = _T("Path"); -typedef base::hash_map<std::wstring, scoped_refptr<ChromePluginLib> > +typedef base::hash_map<FilePath, scoped_refptr<ChromePluginLib> > PluginMap; // A map of all the instantiated plugins. @@ -43,7 +43,7 @@ static bool IsSingleProcessMode() { } // static -ChromePluginLib* ChromePluginLib::Create(const std::wstring& filename, +ChromePluginLib* ChromePluginLib::Create(const FilePath& filename, const CPBrowserFuncs* bfuncs) { // Keep a map of loaded plugins to ensure we only load each library once. if (!g_loaded_libs) { @@ -53,8 +53,13 @@ ChromePluginLib* ChromePluginLib::Create(const std::wstring& filename, } DCHECK(IsPluginThread()); - // Lower case to match how PluginList::LoadPlugin stores the path. - std::wstring filename_lc = StringToLowerASCII(filename); +#if defined(OS_WIN) + // Lower case to match how PluginLib::CreatePluginLib stores the path. See + // there for the rationale behind this. + FilePath filename_lc(StringToLowerASCII(filename.value())); +#else + FilePath filename_lc = filename; +#endif // OS_WIN PluginMap::const_iterator iter = g_loaded_libs->find(filename_lc); if (iter != g_loaded_libs->end()) @@ -69,7 +74,7 @@ ChromePluginLib* ChromePluginLib::Create(const std::wstring& filename, } // static -ChromePluginLib* ChromePluginLib::Find(const std::wstring& filename) { +ChromePluginLib* ChromePluginLib::Find(const FilePath& filename) { if (g_loaded_libs) { PluginMap::const_iterator iter = g_loaded_libs->find(filename); if (iter != g_loaded_libs->end()) @@ -79,7 +84,7 @@ ChromePluginLib* ChromePluginLib::Find(const std::wstring& filename) { } // static -void ChromePluginLib::Destroy(const std::wstring& filename) { +void ChromePluginLib::Destroy(const FilePath& filename) { DCHECK(g_loaded_libs); PluginMap::iterator iter = g_loaded_libs->find(filename); if (iter != g_loaded_libs->end()) { @@ -104,7 +109,7 @@ void ChromePluginLib::RegisterPluginsWithNPAPI() { if (IsSingleProcessMode()) return; - std::wstring path; + FilePath path; if (!PathService::Get(chrome::FILE_GEARS_PLUGIN, &path)) return; // Note: we can only access the NPAPI list because the PluginService has done @@ -127,7 +132,7 @@ void ChromePluginLib::LoadChromePlugins(const CPBrowserFuncs* bfuncs) { if (IsSingleProcessMode()) return; - std::wstring path; + FilePath path; if (!PathService::Get(chrome::FILE_GEARS_PLUGIN, &path)) return; @@ -177,7 +182,7 @@ const CPPluginFuncs& ChromePluginLib::functions() const { return plugin_funcs_; } -ChromePluginLib::ChromePluginLib(const std::wstring& filename) +ChromePluginLib::ChromePluginLib(const FilePath& filename) : filename_(filename), module_(0), initialized_(false), @@ -229,7 +234,7 @@ int ChromePluginLib::CP_Test(void* param) { bool ChromePluginLib::Load() { DCHECK(module_ == 0); - module_ = LoadLibrary(filename_.c_str()); + module_ = LoadLibrary(filename_.value().c_str()); if (module_ == 0) return false; diff --git a/chrome/common/chrome_plugin_lib.h b/chrome/common/chrome_plugin_lib.h index f58b9c8..eb2e95f 100644 --- a/chrome/common/chrome_plugin_lib.h +++ b/chrome/common/chrome_plugin_lib.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/common/chrome_plugin_api.h" @@ -20,10 +21,10 @@ class MessageLoop; // issues a NOTIFY_CHROME_PLUGIN_UNLOADED notification. class ChromePluginLib : public base::RefCounted<ChromePluginLib> { public: - static ChromePluginLib* Create(const std::wstring& filename, + static ChromePluginLib* Create(const FilePath& filename, const CPBrowserFuncs* bfuncs); - static ChromePluginLib* Find(const std::wstring& filename); - static void Destroy(const std::wstring& filename); + static ChromePluginLib* Find(const FilePath& filename); + static void Destroy(const FilePath& filename); static bool IsPluginThread(); static MessageLoop* GetPluginThreadLoop(); @@ -49,7 +50,7 @@ class ChromePluginLib : public base::RefCounted<ChromePluginLib> { CPID cpid() { return reinterpret_cast<CPID>(this); } - const std::wstring& filename() { return filename_; } + const FilePath& filename() { return filename_; } // Plugin API functions @@ -62,7 +63,7 @@ class ChromePluginLib : public base::RefCounted<ChromePluginLib> { private: friend class base::RefCounted<ChromePluginLib>; - ChromePluginLib(const std::wstring& filename); + ChromePluginLib(const FilePath& filename); ~ChromePluginLib(); // Method to initialize a Plugin. @@ -79,20 +80,20 @@ class ChromePluginLib : public base::RefCounted<ChromePluginLib> { // Unloading the plugin DLL. void Unload(); - std::wstring filename_; // the path to the DLL - HMODULE module_; // the opened DLL handle - bool initialized_; // is the plugin initialized + FilePath filename_; // the path to the DLL + HMODULE module_; // the opened DLL handle + bool initialized_; // is the plugin initialized // DLL exports, looked up by name. - CP_VersionNegotiateFunc CP_VersionNegotiate_; - CP_InitializeFunc CP_Initialize_; + CP_VersionNegotiateFunc CP_VersionNegotiate_; + CP_InitializeFunc CP_Initialize_; // Additional function pointers provided by the plugin. - CPPluginFuncs plugin_funcs_; + CPPluginFuncs plugin_funcs_; // Used for unit tests. typedef int (STDCALL *CP_TestFunc)(void*); - CP_TestFunc CP_Test_; + CP_TestFunc CP_Test_; DISALLOW_COPY_AND_ASSIGN(ChromePluginLib); }; diff --git a/chrome/common/chrome_plugin_unittest.cc b/chrome/common/chrome_plugin_unittest.cc index 1465f1a..09ae2f4 100644 --- a/chrome/common/chrome_plugin_unittest.cc +++ b/chrome/common/chrome_plugin_unittest.cc @@ -17,7 +17,8 @@ namespace { const wchar_t kDocRoot[] = L"chrome/test/data"; -const wchar_t kPluginFilename[] = L"test_chrome_plugin.dll"; +const FilePath::CharType kPluginFilename[] = + FILE_PATH_LITERAL("test_chrome_plugin.dll"); class ChromePluginTest : public testing::Test, public URLRequest::Delegate { public: @@ -117,9 +118,9 @@ static void STDCALL CPT_InvokeLater(TestFuncParams::CallbackFunc callback, } void ChromePluginTest::LoadPlugin() { - std::wstring path; + FilePath path; PathService::Get(base::DIR_EXE, &path); - file_util::AppendToPath(&path, kPluginFilename); + path = path.Append(kPluginFilename); plugin_ = ChromePluginLib::Create(path, GetCPBrowserFuncsForBrowser()); // Exchange test APIs with the plugin. diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index 476d7f9..39bb231 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -9,6 +9,7 @@ #include <vector> #include <map> +#include "base/file_path.h" #include "base/string_util.h" #include "base/tuple.h" #include "chrome/common/ipc_sync_message.h" @@ -604,6 +605,24 @@ struct ParamTraits<POINT> { #endif // defined(OS_WIN) template <> +struct ParamTraits<FilePath> { + typedef FilePath param_type; + static void Write(Message* m, const param_type& p) { + ParamTraits<FilePath::StringType>::Write(m, p.value()); + } + static bool Read(const Message* m, void** iter, param_type* r) { + FilePath::StringType value; + if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value)) + return false; + *r = FilePath(value); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + ParamTraits<FilePath::StringType>::Log(p.value(), l); + } +}; + +template <> struct ParamTraits<gfx::Point> { typedef gfx::Point param_type; static void Write(Message* m, const param_type& p); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 64a76b2..e2b7c26 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -55,7 +55,7 @@ IPC_BEGIN_MESSAGES(View, 1) // Allows a chrome plugin loaded in the browser process to send arbitrary // data to an instance of the same plugin loaded in a renderer process. IPC_MESSAGE_CONTROL2(ViewMsg_PluginMessage, - std::wstring /* dll_path of plugin */, + FilePath /* plugin_path of plugin */, std::vector<uint8> /* opaque data */) #if defined(OS_WIN) @@ -703,7 +703,7 @@ IPC_BEGIN_MESSAGES(ViewHost, 2) GURL /* url */, std::string /* mime_type */, std::string /* clsid */, - std::wstring /* filename */, + FilePath /* filename */, std::string /* actual mime type for url */) // Retrieve the data directory associated with the renderer's profile. @@ -713,13 +713,13 @@ IPC_BEGIN_MESSAGES(ViewHost, 2) // Allows a chrome plugin loaded in a renderer process to send arbitrary // data to an instance of the same plugin loaded in the browser process. IPC_MESSAGE_CONTROL2(ViewHostMsg_PluginMessage, - std::wstring /* dll_path of plugin */, + FilePath /* plugin_path of plugin */, std::vector<uint8> /* opaque data */) // Allows a chrome plugin loaded in a renderer process to send arbitrary // data to an instance of the same plugin loaded in the browser process. IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_PluginSyncMessage, - std::wstring /* dll_path of plugin */, + FilePath /* plugin_path of plugin */, std::vector<uint8> /* opaque data */, std::vector<uint8> /* opaque data */) @@ -811,7 +811,7 @@ IPC_BEGIN_MESSAGES(ViewHost, 2) std::string /* clsid */, std::wstring /* locale */, std::wstring /* channel_name */, - std::wstring /* plugin_path */) + FilePath /* plugin_path */) // Clipboard IPC messages @@ -991,7 +991,7 @@ IPC_BEGIN_MESSAGES(ViewHost, 2) // Sent by the renderer process to indicate that a plugin instance has // crashed. IPC_MESSAGE_ROUTED1(ViewHostMsg_CrashedPlugin, - std::wstring /* plugin_path */) + FilePath /* plugin_path */) // Dsiplays a JavaScript out-of-memory message in the infobar. IPC_MESSAGE_ROUTED0(ViewHostMsg_JSOutOfMemory) diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc index 84aa0b5..b925a01 100644 --- a/chrome/plugin/plugin_main.cc +++ b/chrome/plugin/plugin_main.cc @@ -50,8 +50,9 @@ int PluginMain(CommandLine &parsed_command_line, std::wstring channel_name = parsed_command_line.GetSwitchValue(switches::kProcessChannelID); - std::wstring plugin_path = - parsed_command_line.GetSwitchValue(switches::kPluginPath); + FilePath plugin_path = + FilePath::FromWStringHack( + parsed_command_line.GetSwitchValue(switches::kPluginPath)); if (PluginProcess::GlobalInit(channel_name, plugin_path)) { if (!no_sandbox && target_services) { target_services->LowerToken(); diff --git a/chrome/plugin/plugin_process.cc b/chrome/plugin/plugin_process.cc index 23f9948..fe19b9b 100644 --- a/chrome/plugin/plugin_process.cc +++ b/chrome/plugin/plugin_process.cc @@ -16,7 +16,7 @@ // Custom factory to allow us to pass additional ctor arguments. class PluginProcessFactory : public ChildProcessFactoryInterface { public: - explicit PluginProcessFactory(const std::wstring& plugin_path) + explicit PluginProcessFactory(const FilePath& plugin_path) : plugin_path_(plugin_path) { } @@ -24,7 +24,7 @@ class PluginProcessFactory : public ChildProcessFactoryInterface { return new PluginProcess(channel_name, plugin_path_); } - const std::wstring& plugin_path_; + const FilePath& plugin_path_; }; // How long to wait after there are no more plugin instances before killing the @@ -40,7 +40,7 @@ template <> struct RunnableMethodTraits<PluginProcess> { }; PluginProcess::PluginProcess(const std::wstring& channel_name, - const std::wstring& plugin_path) : + const FilePath& plugin_path) : plugin_path_(plugin_path), #pragma warning(suppress: 4355) // Okay to pass "this" here. plugin_thread_(this, channel_name) { @@ -50,7 +50,7 @@ PluginProcess::~PluginProcess() { } bool PluginProcess::GlobalInit(const std::wstring &channel_name, - const std::wstring &plugin_path) { + const FilePath &plugin_path) { PluginProcessFactory factory(plugin_path); return ChildProcess::GlobalInit(channel_name, &factory); } diff --git a/chrome/plugin/plugin_process.h b/chrome/plugin/plugin_process.h index 444d597..c7c0b78 100644 --- a/chrome/plugin/plugin_process.h +++ b/chrome/plugin/plugin_process.h @@ -14,7 +14,7 @@ class PluginProcess : public ChildProcess { public: static bool GlobalInit(const std::wstring& channel_name, - const std::wstring& plugin_path); + const FilePath& plugin_path); // Invoked with the response from the browser indicating whether it is // ok to shutdown the plugin process. @@ -26,19 +26,19 @@ class PluginProcess : public ChildProcess { static void BrowserShutdown(); // File path of the plugin dll this process hosts. - const std::wstring& plugin_path() { return plugin_path_; } + const FilePath& plugin_path() { return plugin_path_; } private: friend class PluginProcessFactory; PluginProcess(const std::wstring& channel_name, - const std::wstring& plugin_path); + const FilePath& plugin_path); virtual ~PluginProcess(); virtual void OnFinalRelease(); void Shutdown(); void OnProcessShutdownTimeout(); - const std::wstring plugin_path_; + const FilePath plugin_path_; // The thread where plugin instances live. Since NPAPI plugins weren't // created with multi-threading in mind, running multiple instances on diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index 4fb4454..e9c1ecd 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -77,7 +77,7 @@ void PluginThread::Init() { // Preload the dll to avoid loading, unloading then reloading preloaded_plugin_module_ = NPAPI::PluginLib::LoadPluginHelper( - plugin_process_->plugin_path().c_str()); + plugin_process_->plugin_path()); ChromePluginLib::Create(plugin_process_->plugin_path(), GetCPBrowserFuncsForPlugin()); diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index daebf40..6d9cfe6 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -124,7 +124,8 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, } CommandLine command_line; - std::wstring path = command_line.GetSwitchValue(switches::kPluginPath); + FilePath path = + FilePath(command_line.GetSwitchValue(switches::kPluginPath)); delegate_ = WebPluginDelegateImpl::Create( path, mime_type_, params.containing_window); if (delegate_) { diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index c5be113..5aa1dc6 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -175,10 +175,10 @@ void RenderThread::OnMessageReceived(const IPC::Message& msg) { } } -void RenderThread::OnPluginMessage(const std::wstring& dll_path, +void RenderThread::OnPluginMessage(const FilePath& plugin_path, const std::vector<uint8>& data) { CHECK(ChromePluginLib::IsPluginThread()); - ChromePluginLib *chrome_plugin = ChromePluginLib::Find(dll_path); + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index ae94815..c9dbea4 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -5,6 +5,7 @@ #ifndef CHROME_RENDERER_RENDER_THREAD_H_ #define CHROME_RENDERER_RENDER_THREAD_H_ +#include "base/file_path.h" #include "base/ref_counted.h" #include "base/shared_memory.h" #include "base/task.h" @@ -97,7 +98,7 @@ class RenderThread : public IPC::Channel::Listener, void OnUpdateVisitedLinks(base::SharedMemoryHandle table); void OnUpdateGreasemonkeyScripts(base::SharedMemoryHandle table); - void OnPluginMessage(const std::wstring& dll_path, + void OnPluginMessage(const FilePath& plugin_path, const std::vector<uint8>& data); void OnSetNextPageID(int32 next_page_id); void OnCreateNewView(HWND parent_hwnd, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index fdbee76..c94e430 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -235,7 +235,7 @@ void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) { first_default_plugin_ = NULL; } -void RenderView::PluginCrashed(const std::wstring& plugin_path) { +void RenderView::PluginCrashed(const FilePath& plugin_path) { Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); } @@ -1843,11 +1843,11 @@ WebPluginDelegate* RenderView::CreatePluginDelegate( std::string* actual_mime_type) { bool is_gears = false; if (ShouldLoadPluginInProcess(mime_type, &is_gears)) { - std::wstring path; + FilePath path; render_thread_->Send( new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path, actual_mime_type)); - if (path.empty()) + if (path.value().empty()) return NULL; std::string mime_type_to_use; @@ -1858,7 +1858,8 @@ WebPluginDelegate* RenderView::CreatePluginDelegate( if (is_gears) ChromePluginLib::Create(path, GetCPBrowserFuncsForRenderer()); - return WebPluginDelegateImpl::Create(path, mime_type_to_use, host_window_); + return WebPluginDelegateImpl::Create(path, + mime_type_to_use, host_window_); } WebPluginDelegateProxy* proxy = diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 24f8f9b..23fd8b6 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -288,7 +288,7 @@ class RenderView : public RenderWidget, void PluginDestroyed(WebPluginDelegateProxy* proxy); // Called when a plugin is crashed. - void PluginCrashed(const std::wstring& plugin_path); + void PluginCrashed(const FilePath& plugin_path); // Called from JavaScript window.external.AddSearchProvider() to add a // keyword for a provider described in the given OpenSearch document. diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index b5c92a5..5a70548 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -207,7 +207,8 @@ bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn, char** argv, int argc, WebPlugin* plugin, bool load_manually) { - std::wstring channel_name, plugin_path; + std::wstring channel_name; + FilePath plugin_path; if (!g_render_thread->Send(new ViewHostMsg_OpenChannelToPlugin( url, mime_type_, clsid_, webkit_glue::GetWebKitLocale(), &channel_name, &plugin_path))) @@ -308,7 +309,7 @@ void WebPluginDelegateProxy::DidManualLoadFail() { Send(new PluginMsg_DidManualLoadFail(instance_id_)); } -std::wstring WebPluginDelegateProxy::GetPluginPath() { +FilePath WebPluginDelegateProxy::GetPluginPath() { return plugin_path_; } diff --git a/chrome/renderer/webplugin_delegate_proxy.h b/chrome/renderer/webplugin_delegate_proxy.h index 38e65e6..4f8b757 100644 --- a/chrome/renderer/webplugin_delegate_proxy.h +++ b/chrome/renderer/webplugin_delegate_proxy.h @@ -83,7 +83,7 @@ class WebPluginDelegateProxy : public WebPluginDelegate, virtual void DidReceiveManualData(const char* buffer, int length); virtual void DidFinishManualLoading(); virtual void DidManualLoadFail(); - virtual std::wstring GetPluginPath(); + virtual FilePath GetPluginPath(); virtual void InstallMissingPlugin(); virtual WebPluginResourceClient* CreateResourceClient(int resource_id, const std::string &url, @@ -154,7 +154,7 @@ class WebPluginDelegateProxy : public WebPluginDelegate, std::string mime_type_; std::string clsid_; int instance_id_; - std::wstring plugin_path_; + FilePath plugin_path_; gfx::Rect plugin_rect_; gfx::Rect deferred_clip_rect_; diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc index c75ab15..4e29dfc 100644 --- a/webkit/glue/chromium_bridge_impl.cc +++ b/webkit/glue/chromium_bridge_impl.cc @@ -323,8 +323,12 @@ bool ChromiumBridge::plugins(bool refresh, Vector<PluginInfo*>* results) { const WebPluginInfo& plugin = glue_plugins[i]; rv->name = webkit_glue::StdWStringToString(plugin.name); rv->desc = webkit_glue::StdWStringToString(plugin.desc); - rv->file = webkit_glue::StdWStringToString( - file_util::GetFilenameFromPath(plugin.file)); + rv->file = +#if defined(OS_WIN) + webkit_glue::StdWStringToString(plugin.file.BaseName().value()); +#elif defined(OS_POSIX) + webkit_glue::StdStringToString(plugin.file.BaseName().value()); +#endif for (size_t j = 0; j < plugin.mime_types.size(); ++ j) { MimeClassInfo* new_mime = new MimeClassInfo(); const WebPluginMimeType& mime_type = plugin.mime_types[j]; diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc index 12e6330..3be9304 100644 --- a/webkit/glue/plugins/plugin_host.cc +++ b/webkit/glue/plugins/plugin_host.cc @@ -759,7 +759,8 @@ NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { // to worry about future standard change that may conflict with the // variable definition. scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); - if (plugin->plugin_lib()->plugin_info().file == kDefaultPluginDllName) + if (plugin->plugin_lib()->plugin_info().file.value() == + kDefaultPluginDllName) plugin->webplugin()->OnMissingPluginStatus( variable - default_plugin::kMissingPluginStatusStart); break; diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc index 96296dc..5936747 100644 --- a/webkit/glue/plugins/plugin_lib.cc +++ b/webkit/glue/plugins/plugin_lib.cc @@ -15,6 +15,7 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/task.h" +#include "net/base/mime_util.h" #include "webkit/activex_shim/npp_impl.h" #include "webkit/default_plugin/plugin_main.h" #include "webkit/glue/glue_util.h" @@ -23,7 +24,6 @@ #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_host.h" #include "webkit/glue/plugins/plugin_list.h" -#include "net/base/mime_util.h" namespace NPAPI @@ -34,14 +34,22 @@ const char kPluginInstancesActiveCounter[] = "PluginInstancesActive"; PluginLib::PluginMap* PluginLib::loaded_libs_; -PluginLib* PluginLib::CreatePluginLib(const std::wstring& filename) { +PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { + // For Windows we have a bit of a problem in that we might have the same path + // cased differently for two different plugin load paths. Therefore we do a + // quick lowercase for canonicalization's sake. WARNING: If you clone this + // file for other platforms, remove this lowercasing. This is *wrong* for + // other platforms (and arguably the wrong way to do it for Windows too, but + // let's not get into that here). + FilePath filename_lc(StringToLowerASCII(filename.value())); + // We can only have one PluginLib object per plugin as it controls the per // instance function calls (i.e. NP_Initialize and NP_Shutdown). So we keep // a (non-ref counted) map of PluginLib objects. if (!loaded_libs_) loaded_libs_ = new PluginMap(); - PluginMap::const_iterator iter = loaded_libs_->find(filename); + PluginMap::const_iterator iter = loaded_libs_->find(filename_lc); if (iter != loaded_libs_->end()) return iter->second; @@ -91,23 +99,24 @@ PluginLib* PluginLib::CreatePluginLib(const std::wstring& filename) { WebPluginInfo* info = NULL; const InternalPluginInfo* internal_plugin_info = NULL; - if (!_wcsicmp(filename.c_str(), + if (!_wcsicmp(filename.value().c_str(), activex_shim_info_generic.version_info.file_name.c_str())) { info = CreateWebPluginInfo(activex_shim_info_generic.version_info); internal_plugin_info = &activex_shim_info_generic; - } else if (!_wcsicmp(filename.c_str(), + } else if (!_wcsicmp(filename.value().c_str(), activex_shim_wmplayer.version_info.file_name.c_str())) { info = CreateWebPluginInfo(activex_shim_wmplayer.version_info); internal_plugin_info = &activex_shim_wmplayer; } else if (!_wcsicmp( - filename.c_str(), + filename.value().c_str(), default_plugin_info.version_info.file_name.c_str())) { info = CreateWebPluginInfo(default_plugin_info.version_info); internal_plugin_info = &default_plugin_info; } else { - info = ReadWebPluginInfo(filename); + info = ReadWebPluginInfo(filename_lc); if (!info) { - DLOG(INFO) << "This file isn't a valid NPAPI plugin: " << filename; + DLOG(INFO) << "This file isn't a valid NPAPI plugin: " + << filename.value(); return NULL; } } @@ -281,21 +290,20 @@ bool PluginLib::Load() { return rv; } -HMODULE PluginLib::LoadPluginHelper(const std::wstring plugin_file) { +HMODULE PluginLib::LoadPluginHelper(const FilePath plugin_file) { // Switch the current directory to the plugin directory as the plugin // may have dependencies on dlls in this directory. bool restore_directory = false; std::wstring current_directory; if (PathService::Get(base::DIR_CURRENT, ¤t_directory)) { - std::wstring plugin_path = file_util::GetDirectoryFromPath( - plugin_file); - if (!plugin_path.empty()) { - PathService::SetCurrentDirectory(plugin_path); + FilePath plugin_path = plugin_file.DirName(); + if (!plugin_path.value().empty()) { + PathService::SetCurrentDirectory(plugin_path.value()); restore_directory = true; } } - HMODULE module = LoadLibrary(plugin_file.c_str()); + HMODULE module = LoadLibrary(plugin_file.value().c_str()); if (restore_directory) PathService::SetCurrentDirectory(current_directory); @@ -376,7 +384,7 @@ WebPluginInfo* PluginLib::CreateWebPluginInfo(const PluginVersionInfo& pvi) { info->name = pvi.product_name; info->desc = pvi.file_description; info->version = pvi.file_version; - info->file = StringToLowerASCII(pvi.file_name); + info->file = FilePath(pvi.file_name); for (size_t i = 0; i < mime_types.size(); ++i) { WebPluginMimeType mime_type; @@ -403,14 +411,14 @@ WebPluginInfo* PluginLib::CreateWebPluginInfo(const PluginVersionInfo& pvi) { return info; } -WebPluginInfo* PluginLib::ReadWebPluginInfo(const std::wstring &filename) { +WebPluginInfo* PluginLib::ReadWebPluginInfo(const FilePath &filename) { // On windows, the way we get the mime types for the library is // to check the version information in the DLL itself. This // will be a string of the format: <type1>|<type2>|<type3>|... // For example: // video/quicktime|audio/aiff|image/jpeg scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfo(filename)); + FileVersionInfo::CreateFileVersionInfo(filename.value())); if (!version_info.get()) return NULL; @@ -421,7 +429,7 @@ WebPluginInfo* PluginLib::ReadWebPluginInfo(const std::wstring &filename) { pvi.product_name = version_info->product_name(); pvi.file_description = version_info->file_description(); pvi.file_version = version_info->file_version(); - pvi.file_name = filename; + pvi.file_name = filename.value(); return CreateWebPluginInfo(pvi); } diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h index 06b7ef9..11b3498 100644 --- a/webkit/glue/plugins/plugin_lib.h +++ b/webkit/glue/plugins/plugin_lib.h @@ -10,6 +10,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/hash_tables.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -49,7 +50,7 @@ struct InternalPluginInfo { class PluginLib : public base::RefCounted<PluginLib> { public: virtual ~PluginLib(); - static PluginLib* CreatePluginLib(const std::wstring& filename); + static PluginLib* CreatePluginLib(const FilePath& filename); // Unloads all the loaded plugin dlls and cleans up the plugin map. static void UnloadAllPlugins(); @@ -88,7 +89,7 @@ class PluginLib : public base::RefCounted<PluginLib> { #if defined(OS_WIN) // Helper function to load a plugin. // Returns the module handle on success. - static HMODULE LoadPluginHelper(const std::wstring plugin_file); + static HMODULE LoadPluginHelper(const FilePath plugin_file); #endif int instance_count() const { return instance_count_; } @@ -112,7 +113,7 @@ class PluginLib : public base::RefCounted<PluginLib> { // Returns a WebPluginInfo structure given a plugin's path. Returns NULL if // the dll couldn't be found, or if it's not a plugin. - static WebPluginInfo* ReadWebPluginInfo(const std::wstring &filename); + static WebPluginInfo* ReadWebPluginInfo(const FilePath &filename); // Creates WebPluginInfo structure based on read in or built in // PluginVersionInfo. static WebPluginInfo* CreateWebPluginInfo(const PluginVersionInfo& info); @@ -127,8 +128,8 @@ class PluginLib : public base::RefCounted<PluginLib> { NPSavedData *saved_data_; // persisted plugin info for NPAPI int instance_count_; // count of plugins in use - // A map of all the insantiated plugins. - typedef base::hash_map<std::wstring, scoped_refptr<PluginLib> > PluginMap; + // A map of all the instantiated plugins. + typedef base::hash_map<FilePath, scoped_refptr<PluginLib> > PluginMap; static PluginMap* loaded_libs_; // C-style function pointers diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index 7ef4b92..a41f800 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -52,8 +52,8 @@ static const TCHAR kRegistryBrowserJavaVersion[] = _T("BrowserJavaVersion"); static const TCHAR kRegistryCurrentJavaVersion[] = _T("CurrentVersion"); static const TCHAR kRegistryJavaHome[] = _T("JavaHome"); -// Extra registry paths to search. -static std::vector<std::wstring>* extra_plugin_paths_ = NULL; +// Extra paths to search. +static std::vector<FilePath>* extra_plugin_paths_ = NULL; PluginList* PluginList::Singleton() { if (singleton_.get() == NULL) { @@ -64,11 +64,11 @@ PluginList* PluginList::Singleton() { return singleton_; } -void PluginList::AddExtraPluginPath(const std::wstring& plugin_path) { +void PluginList::AddExtraPluginPath(const FilePath& plugin_path) { DCHECK(!singleton_.get() || !singleton_->plugins_loaded_); if (!extra_plugin_paths_) - extra_plugin_paths_ = new std::vector<std::wstring>; + extra_plugin_paths_ = new std::vector<FilePath>; extra_plugin_paths_->push_back(plugin_path); } @@ -123,7 +123,7 @@ void PluginList::LoadPlugins(bool refresh) { if (webkit_glue::IsDefaultPluginEnabled()) { scoped_refptr<PluginLib> default_plugin = PluginLib::CreatePluginLib( - kDefaultPluginDllName); + FilePath(kDefaultPluginDllName)); plugins_.push_back(default_plugin); } @@ -132,11 +132,11 @@ void PluginList::LoadPlugins(bool refresh) { DLOG(INFO) << "Loaded plugin list in " << elapsed.InMilliseconds() << " ms."; } -void PluginList::LoadPlugins(const std::wstring &path) { +void PluginList::LoadPlugins(const FilePath &path) { WIN32_FIND_DATA find_file_data; HANDLE find_handle; - std::wstring dir = path; + std::wstring dir = path.value(); // FindFirstFile requires that you specify a wildcard for directories. dir.append(L"\\NP*.DLL"); @@ -146,10 +146,7 @@ void PluginList::LoadPlugins(const std::wstring &path) { do { if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - std::wstring filename = path; - filename.append(L"\\"); - filename.append(find_file_data.cFileName); - + FilePath filename = path.Append(find_file_data.cFileName); LoadPlugin(filename); } } while (FindNextFile(find_handle, &find_file_data) != 0); @@ -158,12 +155,11 @@ void PluginList::LoadPlugins(const std::wstring &path) { FindClose(find_handle); } -void PluginList::LoadPlugin(const std::wstring &path) { - std::wstring path_lc = StringToLowerASCII(path); - if (!ShouldLoadPlugin(file_util::GetFilenameFromPath(path_lc))) +void PluginList::LoadPlugin(const FilePath &path) { + if (!ShouldLoadPlugin(path.BaseName())) return; - scoped_refptr<PluginLib> new_plugin = PluginLib::CreatePluginLib(path_lc); + scoped_refptr<PluginLib> new_plugin = PluginLib::CreatePluginLib(path); if (!new_plugin.get()) return; @@ -176,7 +172,7 @@ void PluginList::LoadPlugin(const std::wstring &path) { if (mime_type == "*" ) { #ifndef NDEBUG // Make an exception for NPSPY. - if (plugin_info.file.find(L"npspy.dll") != std::wstring::npos) { + if (plugin_info.file.value().find(L"npspy.dll") != std::wstring::npos) { // Put it at the beginning so it's used before the real plugin. plugins_.insert(plugins_.begin(), new_plugin.get()); } @@ -184,36 +180,41 @@ void PluginList::LoadPlugin(const std::wstring &path) { continue; } - if (!SupportsType(mime_type)) + if (!SupportsType(mime_type)) { plugins_.push_back(new_plugin); + return; + } } } -bool PluginList::ShouldLoadPlugin(const std::wstring& filename) { +bool PluginList::ShouldLoadPlugin(const FilePath& filename) { + // Canonicalize names. + std::wstring filename_lc = StringToLowerASCII(filename.value()); + // Depends on XPCOM. - if (filename == kMozillaActiveXPlugin) + if (filename_lc == kMozillaActiveXPlugin) return false; // Disable the yahoo application state plugin as it crashes the plugin // process on return from NPObjectStub::OnInvoke. Please refer to // http://b/issue?id=1372124 for more information. - if (filename == kYahooApplicationStatePlugin) + if (filename_lc == kYahooApplicationStatePlugin) return false; // We will use activex shim to handle embeded wmp media. if (use_internal_activex_shim_) { - if (filename == kNewWMPPlugin || filename == kOldWMPPlugin) + if (filename_lc == kNewWMPPlugin || filename_lc == kOldWMPPlugin) return false; } else { // If both the new and old WMP plugins exist, only load the new one. - if (filename == kNewWMPPlugin) { + if (filename_lc == kNewWMPPlugin) { if (dont_load_new_wmp_) return false; int old_plugin = FindPluginFile(kOldWMPPlugin); if (old_plugin != -1) plugins_.erase(plugins_.begin() + old_plugin); - } else if (filename == kOldWMPPlugin) { + } else if (filename_lc == kOldWMPPlugin) { if (FindPluginFile(kNewWMPPlugin) != -1) return false; } @@ -225,19 +226,21 @@ bool PluginList::ShouldLoadPlugin(const std::wstring& filename) { void PluginList::LoadInternalPlugins() { if (use_internal_activex_shim_) { scoped_refptr<PluginLib> new_plugin = PluginLib::CreatePluginLib( - kActiveXShimFileName); + FilePath(kActiveXShimFileName)); plugins_.push_back(new_plugin); new_plugin = PluginLib::CreatePluginLib( - kActivexShimFileNameForMediaPlayer); + FilePath(kActivexShimFileNameForMediaPlayer)); plugins_.push_back(new_plugin); } } int PluginList::FindPluginFile(const std::wstring& filename) { + std::string filename_narrow = WideToASCII(filename); for (size_t i = 0; i < plugins_.size(); ++i) { - if (file_util::GetFilenameFromPath(plugins_[i]->plugin_info().file) == - filename) { + if (LowerCaseEqualsASCII( + plugins_[i]->plugin_info().file.BaseName().value(), + filename_narrow.c_str())) { return static_cast<int>(i); } } @@ -253,7 +256,7 @@ PluginLib* PluginList::FindPlugin(const std::string& mime_type, for (size_t idx = 0; idx < plugins_.size(); ++idx) { if (plugins_[idx]->SupportsType(mime_type, allow_wildcard)) { if (!clsid.empty() && - plugins_[idx]->plugin_info().file == kActiveXShimFileName) { + plugins_[idx]->plugin_info().file.value() == kActiveXShimFileName) { // Special handling for ActiveX shim. If ActiveX is not installed, we // should use the default plugin to show the installation UI. if (!activex_shim::IsActiveXInstalled(clsid)) @@ -270,7 +273,7 @@ PluginLib* PluginList::FindPlugin(const GURL &url, std::string* actual_mime_type std::wstring path = base::SysNativeMBToWide(url.path()); std::wstring extension_wide = file_util::GetFileExtensionFromPath(path); if (extension_wide.empty()) - return NULL;; + return NULL; std::string extension = StringToLowerASCII(base::SysWideToNativeMB(extension_wide)); @@ -329,7 +332,8 @@ bool PluginList::GetPluginInfo(const GURL& url, allow_wildcard); if (plugin.get() == NULL || - (plugin->plugin_info().file == kDefaultPluginDllName && clsid.empty())) { + (plugin->plugin_info().file.value() == kDefaultPluginDllName + && clsid.empty())) { scoped_refptr<PluginLib> default_plugin = plugin; plugin = FindPlugin(url, actual_mime_type); // url matches may not return the default plugin if no match is found. @@ -344,11 +348,11 @@ bool PluginList::GetPluginInfo(const GURL& url, return true; } -bool PluginList::GetPluginInfoByDllPath(const std::wstring& dll_path, +bool PluginList::GetPluginInfoByDllPath(const FilePath& dll_path, WebPluginInfo* info) { for (size_t i = 0; i < plugins_.size(); ++i) { - if (wcsicmp(plugins_[i]->plugin_info().file.c_str(), - dll_path.c_str()) == 0) { + if (wcsicmp(plugins_[i]->plugin_info().file.value().c_str(), + dll_path.value().c_str()) == 0) { *info = plugins_[i]->plugin_info(); return true; } @@ -361,35 +365,43 @@ void PluginList::Shutdown() { // TODO } -std::wstring PluginList::GetPluginAppDirectory() { +FilePath PluginList::GetPluginAppDirectory() { std::wstring app_path; + // TODO(avi): use PathService directly if (webkit_glue::GetApplicationDirectory(&app_path)) app_path.append(L"\\plugins"); - return app_path; + return FilePath(app_path); } -std::wstring PluginList::GetPluginExeDirectory() { +FilePath PluginList::GetPluginExeDirectory() { std::wstring exe_path; + // TODO(avi): use PathService directly if (webkit_glue::GetExeDirectory(&exe_path)) exe_path.append(L"\\plugins"); - return exe_path; + return FilePath(exe_path); } // Gets the installed path for a registered app. -static bool GetInstalledPath(const TCHAR* app, std::wstring* out) { +static bool GetInstalledPath(const TCHAR* app, FilePath* out) { std::wstring reg_path(kRegistryApps); reg_path.append(L"\\"); reg_path.append(app); RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str()); - return key.ReadValue(kRegistryPath, out); + std::wstring path; + if (key.ReadValue(kRegistryPath, &path)) { + *out = FilePath(path); + return true; + } + + return false; } // Enumerate through the registry key to find all installed FireFox paths. // FireFox 3 beta and version 2 can coexist. See bug: 1025003 -static void GetFirefoxInstalledPaths(std::vector<std::wstring>* out) { +static void GetFirefoxInstalledPaths(std::vector<FilePath>* out) { RegistryKeyIterator it(HKEY_LOCAL_MACHINE, kRegistryFirefoxInstalled); for (; it.Valid(); ++it) { std::wstring full_path = std::wstring(kRegistryFirefoxInstalled) + L"\\" + @@ -398,15 +410,15 @@ static void GetFirefoxInstalledPaths(std::vector<std::wstring>* out) { std::wstring install_dir; if (!key.ReadValue(L"Install Directory", &install_dir)) continue; - out->push_back(install_dir); + out->push_back(FilePath(install_dir)); } } void PluginList::LoadFirefoxPlugins() { - std::vector<std::wstring> paths; + std::vector<FilePath> paths; GetFirefoxInstalledPaths(&paths); for (unsigned int i = 0; i < paths.size(); ++i) { - std::wstring path = paths[i] + L"\\plugins"; + FilePath path = paths[i].Append(L"plugins"); LoadPlugins(path); } @@ -416,31 +428,31 @@ void PluginList::LoadFirefoxPlugins() { std::wstring firefox_app_data_plugin_path; if (PathService::Get(base::DIR_APP_DATA, &firefox_app_data_plugin_path)) { firefox_app_data_plugin_path += L"\\Mozilla\\plugins"; - LoadPlugins(firefox_app_data_plugin_path); + LoadPlugins(FilePath(firefox_app_data_plugin_path)); } } void PluginList::LoadAcrobatPlugins() { - std::wstring path; + FilePath path; if (!GetInstalledPath(kRegistryAcrobatReader, &path) && !GetInstalledPath(kRegistryAcrobat, &path)) { return; } - path.append(L"\\Browser"); + path = path.Append(L"Browser"); LoadPlugins(path); } void PluginList::LoadQuicktimePlugins() { - std::wstring path; + FilePath path; if (GetInstalledPath(kRegistryQuickTime, &path)) { - path.append(L"\\plugins"); + path = path.Append(L"plugins"); LoadPlugins(path); } } void PluginList::LoadWindowsMediaPlugins() { - std::wstring path; + FilePath path; if (GetInstalledPath(kRegistryWindowsMedia, &path)) { LoadPlugins(path); } @@ -471,7 +483,7 @@ void PluginList::LoadJavaPlugin() { // 5. We don't know the exact name of the DLL but it's in the form // NP*.dll so just invoke LoadPlugins on this path. - LoadPlugins(java_plugin_directory); + LoadPlugins(FilePath(java_plugin_directory)); } } } @@ -489,7 +501,7 @@ void PluginList::LoadPluginsInRegistryFolder( std::wstring path; if (key.ReadValue(kRegistryPath, &path)) - LoadPlugin(path); + LoadPlugin(FilePath(path)); } } diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h index 43cc46d..d2cab7d 100644 --- a/webkit/glue/plugins/plugin_list.h +++ b/webkit/glue/plugins/plugin_list.h @@ -53,7 +53,7 @@ class PluginList : public base::RefCounted<PluginList> { // Add an extra plugin to load when we actually do the loading. This is // static because we want to be able to add to it without searching the disk // for plugins. Must be called before the plugins have been loaded. - static void AddExtraPluginPath(const std::wstring& plugin_path); + static void AddExtraPluginPath(const FilePath& plugin_path); virtual ~PluginList(); @@ -104,7 +104,7 @@ class PluginList : public base::RefCounted<PluginList> { // Get plugin info by plugin dll path. Returns true if the plugin is found and // WebPluginInfo has been filled in |info| - bool GetPluginInfoByDllPath(const std::wstring& dll_path, + bool GetPluginInfoByDllPath(const FilePath& dll_path, WebPluginInfo* info); private: // Constructors are private for singletons @@ -114,27 +114,26 @@ class PluginList : public base::RefCounted<PluginList> { void LoadPlugins(bool refresh); // Load all plugins from a specific directory - void LoadPlugins(const std::wstring &path); + void LoadPlugins(const FilePath& path); - // Load a specific plugin with full path. filename can be mixed case. - void LoadPlugin(const std::wstring &filename); + // Load a specific plugin with full path. + void LoadPlugin(const FilePath& filename); // Returns true if we should load the given plugin, or false otherwise. - // filename must be lower case. - bool ShouldLoadPlugin(const std::wstring& filename); + bool ShouldLoadPlugin(const FilePath& filename); // Load internal plugins. Right now there is only one: activex_shim. void LoadInternalPlugins(); // Find a plugin by filename. Returns -1 if it's not found, otherwise its - // index in plugins_. filename needs to be lower case. + // index in plugins_. int FindPluginFile(const std::wstring& filename); // The application path where we expect to find plugins. - static std::wstring GetPluginAppDirectory(); + static FilePath GetPluginAppDirectory(); // The executable path where we expect to find plugins. - static std::wstring GetPluginExeDirectory(); + static FilePath GetPluginExeDirectory(); // Load plugins from the Firefox install path. This is kind of // a kludge, but it helps us locate the flash player for users that diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index a48d7ed..655a37a 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -51,7 +51,7 @@ bool WebPluginDelegateImpl::track_popup_menu_patched_ = false; iat_patch::IATPatchFunction WebPluginDelegateImpl::iat_patch_helper_; WebPluginDelegateImpl* WebPluginDelegateImpl::Create( - const std::wstring& filename, + const FilePath& filename, const std::string& mime_type, gfx::NativeView containing_view) { scoped_refptr<NPAPI::PluginLib> plugin = @@ -145,7 +145,7 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( memset(&window_, 0, sizeof(window_)); const WebPluginInfo& plugin_info = instance_->plugin_lib()->plugin_info(); - std::wstring filename = file_util::GetFilenameFromPath(plugin_info.file); + std::wstring filename = plugin_info.file.BaseName().value(); if (instance_->mime_type() == "application/x-shockwave-flash" || filename == L"npswf32.dll") { @@ -365,7 +365,7 @@ void WebPluginDelegateImpl::DidManualLoadFail() { instance()->DidManualLoadFail(); } -std::wstring WebPluginDelegateImpl::GetPluginPath() { +FilePath WebPluginDelegateImpl::GetPluginPath() { return instance()->plugin_lib()->plugin_info().file; } diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index db3d8f3..a89189c 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -8,12 +8,13 @@ #include <string> #include <list> +#include "base/file_path.h" #include "base/gfx/native_widget_types.h" #include "base/iat_patch.h" #include "base/ref_counted.h" #include "base/task.h" -#include "webkit/glue/webplugin_delegate.h" #include "third_party/npapi/bindings/npapi.h" +#include "webkit/glue/webplugin_delegate.h" #include "webkit/glue/webcursor.h" namespace NPAPI { @@ -24,7 +25,7 @@ namespace NPAPI { // the plugin process. class WebPluginDelegateImpl : public WebPluginDelegate { public: - static WebPluginDelegateImpl* Create(const std::wstring& filename, + static WebPluginDelegateImpl* Create(const FilePath& filename, const std::string& mime_type, gfx::NativeView containing_view); static bool IsPluginDelegateWindow(HWND window); @@ -70,7 +71,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { virtual void DidReceiveManualData(const char* buffer, int length); virtual void DidFinishManualLoading(); virtual void DidManualLoadFail(); - virtual std::wstring GetPluginPath(); + virtual FilePath GetPluginPath(); virtual void InstallMissingPlugin(); virtual WebPluginResourceClient* CreateResourceClient(int resource_id, const std::string &url, diff --git a/webkit/glue/webplugin.h b/webkit/glue/webplugin.h index 8124857..96807fb 100644 --- a/webkit/glue/webplugin.h +++ b/webkit/glue/webplugin.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/gfx/rect.h" typedef struct HWND__* HWND; @@ -38,13 +39,13 @@ struct WebPluginInfo { // The name of the plugin (i.e. Flash). std::wstring name; - // The path to the dll. - std::wstring file; + // The path to the plugin file (DLL/bundle/library). + FilePath file; // The version number of the plugin file (may be OS-specific) std::wstring version; - // A description of the plugin that we get from it's version info. + // A description of the plugin that we get from its version info. std::wstring desc; // A list of all the mime types that this plugin supports. diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index df5716a..bfa462a 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/gfx/native_widget_types.h" #include "base/gfx/rect.h" #include "third_party/npapi/bindings/npapi.h" @@ -104,7 +105,7 @@ class WebPluginDelegate { virtual void DidManualLoadFail() = 0; // Only Available after Initialize is called. - virtual std::wstring GetPluginPath() = 0; + virtual FilePath GetPluginPath() = 0; // Only Supported when the plugin is the default plugin. virtual void InstallMissingPlugin() = 0; |