| Index: chrome/browser/plugin_database_handler.cc
|
| diff --git a/chrome/default_plugin/plugin_database_handler.cc b/chrome/browser/plugin_database_handler.cc
|
| similarity index 63%
|
| rename from chrome/default_plugin/plugin_database_handler.cc
|
| rename to chrome/browser/plugin_database_handler.cc
|
| index d265931964fe20f882563cbda265cece1d6716ba..ac12742c251e9881a7a1df8eeee33abb7edd9238 100644
|
| --- a/chrome/default_plugin/plugin_database_handler.cc
|
| +++ b/chrome/browser/plugin_database_handler.cc
|
| @@ -2,11 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -// For WinDDK ATL compatibility, these ATL headers must come first.
|
| -#include <atlbase.h>
|
| -#include <atlwin.h>
|
| -
|
| -#include "chrome/default_plugin/plugin_database_handler.h"
|
| +#include "chrome/browser/plugin_database_handler.h"
|
|
|
| #include "libxml/parser.h"
|
| #include "libxml/xpath.h"
|
| @@ -18,28 +14,22 @@
|
| #include "base/string_util.h"
|
| #include "base/time.h"
|
| #include "base/utf_string_conversions.h"
|
| -#include "chrome/default_plugin/plugin_impl.h"
|
| -#include "chrome/default_plugin/plugin_main.h"
|
|
|
| using base::Time;
|
| using base::TimeDelta;
|
|
|
| -PluginDatabaseHandler::PluginDatabaseHandler(
|
| - PluginInstallerImpl& plugin_installer_instance)
|
| - : plugin_downloads_file_(INVALID_HANDLE_VALUE),
|
| - plugin_installer_instance_(plugin_installer_instance),
|
| +PluginDatabaseHandler::PluginDatabaseHandler()
|
| + : plugin_downloads_file_(base::kInvalidPlatformFileValue),
|
| ignore_plugin_db_data_(false) {
|
| }
|
|
|
| PluginDatabaseHandler::~PluginDatabaseHandler() {
|
| - if (plugin_downloads_file_ != INVALID_HANDLE_VALUE) {
|
| - ::CloseHandle(plugin_downloads_file_);
|
| - plugin_downloads_file_ = INVALID_HANDLE_VALUE;
|
| - }
|
| + Close(false);
|
| }
|
|
|
| bool PluginDatabaseHandler::DownloadPluginsFileIfNeeded(
|
| - const std::string& plugin_finder_url) {
|
| + const std::string& plugin_finder_url,
|
| + PluginDatabaseHandler::Client* client) {
|
| DCHECK(!plugin_finder_url.empty());
|
| // The time in days for which the plugins list is cached.
|
| // TODO(iyengar) Make this configurable.
|
| @@ -49,29 +39,26 @@ bool PluginDatabaseHandler::DownloadPluginsFileIfNeeded(
|
|
|
| FilePath module_path;
|
| PathService::Get(base::DIR_MODULE, &module_path);
|
| - plugins_file_ = module_path.Append(L"chrome_plugins_file.xml").value();
|
| + plugins_file_ = module_path.Append(
|
| + FILE_PATH_LITERAL("chrome_plugins_file.xml"));
|
|
|
| bool initiate_download = false;
|
| - if (!file_util::PathExists(FilePath(plugins_file_))) {
|
| + base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| + base::PlatformFile file = base::CreatePlatformFile(
|
| + plugins_file_, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
|
| + NULL, &error);
|
| + if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
|
| initiate_download = true;
|
| } else {
|
| - SYSTEMTIME creation_system_time = {0};
|
| - if (!file_util::GetFileCreationLocalTime(plugins_file_,
|
| - &creation_system_time)) {
|
| + base::PlatformFileInfo file_info;
|
| + if (!base::GetPlatformFileInfo(file, &file_info)) {
|
| NOTREACHED();
|
| return false;
|
| }
|
|
|
| - FILETIME creation_file_time = {0};
|
| - ::SystemTimeToFileTime(&creation_system_time, &creation_file_time);
|
| -
|
| - FILETIME current_time = {0};
|
| - ::GetSystemTimeAsFileTime(¤t_time);
|
| + Time current_time = Time::Now();
|
|
|
| - Time file_time = Time::FromFileTime(creation_file_time);
|
| - Time current_system_time = Time::FromFileTime(current_time);
|
| -
|
| - TimeDelta time_diff = file_time - current_system_time;
|
| + TimeDelta time_diff = file_info.creation_time - current_time; // ???
|
| if (time_diff.InDays() > kPluginsListCacheTimeInDays) {
|
| initiate_download = true;
|
| }
|
| @@ -79,32 +66,24 @@ bool PluginDatabaseHandler::DownloadPluginsFileIfNeeded(
|
|
|
| if (initiate_download) {
|
| DVLOG(1) << "Initiating GetURLNotify on the plugin finder URL "
|
| - << plugin_finder_url.c_str();
|
| -
|
| - plugin_installer_instance_.set_plugin_installer_state(
|
| - PluginListDownloadInitiated);
|
| + << plugin_finder_url;
|
|
|
| - DCHECK(default_plugin::g_browser->geturlnotify);
|
| - default_plugin::g_browser->geturlnotify(
|
| - plugin_installer_instance_.instance(), plugin_finder_url.c_str(),
|
| - NULL, NULL);
|
| + client->DownloadPluginList(plugin_finder_url);
|
| } else {
|
| - DVLOG(1) << "Plugins file " << plugins_file_ << " already exists";
|
| - plugin_downloads_file_ = ::CreateFile(plugins_file_.c_str(), GENERIC_READ,
|
| - FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
| - FILE_ATTRIBUTE_NORMAL, NULL);
|
| - if (plugin_downloads_file_ == INVALID_HANDLE_VALUE) {
|
| - DVLOG(1) << "Failed to open plugins file " << plugins_file_
|
| - << " Error " << ::GetLastError();
|
| + DVLOG(1) << "Plugins file " << plugins_file_.value() << " already exists";
|
| + base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| + plugin_downloads_file_ = base::CreatePlatformFile(
|
| + plugins_file_,
|
| + base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
|
| + NULL,
|
| + &error);
|
| + if (error != base::PLATFORM_FILE_OK) {
|
| + DVLOG(1) << "Failed to open plugins file " << plugins_file_.value()
|
| + << " Error " << error;
|
| NOTREACHED();
|
| return false;
|
| }
|
| - // The URLNotify function contains all handling needed to parse the plugins
|
| - // file and display the UI accordingly.
|
| - plugin_installer_instance_.set_plugin_installer_state(
|
| - PluginListDownloadInitiated);
|
| - plugin_installer_instance_.URLNotify(plugin_finder_url.c_str(),
|
| - NPRES_DONE);
|
| + client->OnPluginListDownloaded();
|
| }
|
| return true;
|
| }
|
| @@ -115,39 +94,40 @@ int32 PluginDatabaseHandler::Write(NPStream* stream, int32 offset,
|
| return buffer_length;
|
| }
|
|
|
| - if (plugin_downloads_file_ == INVALID_HANDLE_VALUE) {
|
| - DVLOG(1) << "About to create plugins file " << plugins_file_;
|
| - plugin_downloads_file_ = CreateFile(plugins_file_.c_str(),
|
| - GENERIC_READ | GENERIC_WRITE,
|
| - FILE_SHARE_READ, NULL, CREATE_ALWAYS,
|
| - FILE_ATTRIBUTE_NORMAL, NULL);
|
| - if (plugin_downloads_file_ == INVALID_HANDLE_VALUE) {
|
| - DWORD error = ::GetLastError();
|
| - if (error == ERROR_SHARING_VIOLATION) {
|
| + if (plugin_downloads_file_ == base::kInvalidPlatformFileValue) {
|
| + DVLOG(1) << "About to create plugins file " << plugins_file_.value();
|
| + base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| + plugin_downloads_file_ = base::CreatePlatformFile(
|
| + plugins_file_,
|
| + base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE,
|
| + NULL,
|
| + &error);
|
| + if (error != base::PLATFORM_FILE_OK) {
|
| + if (error == base::PLATFORM_FILE_ERROR_IN_USE) {
|
| // File may have been downloaded by another plugin instance on this
|
| // page.
|
| - plugin_downloads_file_ = ::CreateFile(
|
| - plugins_file_.c_str(), GENERIC_READ,
|
| - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
| - FILE_ATTRIBUTE_NORMAL, NULL);
|
| - if (plugin_downloads_file_ != INVALID_HANDLE_VALUE) {
|
| + plugin_downloads_file_ = base::CreatePlatformFile(
|
| + plugins_file_, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
|
| + NULL, &error);
|
| + if (error == base::PLATFORM_FILE_OK) {
|
| ignore_plugin_db_data_ = true;
|
| return buffer_length;
|
| }
|
| }
|
|
|
| - DLOG(ERROR) << "Failed to create plugins file " << plugins_file_
|
| - << " Error " << ::GetLastError();
|
| + DLOG(ERROR) << "Failed to create plugins file " << plugins_file_.value()
|
| + << " Error " << error;
|
| return 0;
|
| }
|
| }
|
|
|
| - DWORD bytes_written = 0;
|
| - if (0 == lstrcmpiA(stream->url, plugin_finder_url_.c_str())) {
|
| - DCHECK(plugin_downloads_file_ != INVALID_HANDLE_VALUE);
|
| + int bytes_written = 0;
|
| + if (plugin_finder_url_ == stream->url) {
|
| + DCHECK(plugin_downloads_file_ != base::kInvalidPlatformFileValue);
|
|
|
| - WriteFile(plugin_downloads_file_, buffer, buffer_length, &bytes_written,
|
| - NULL);
|
| + bytes_written = base::WritePlatformFile(plugin_downloads_file_, 0,
|
| + static_cast<const char*>(buffer),
|
| + buffer_length);
|
| DCHECK_EQ(buffer_length, static_cast<int32>(bytes_written));
|
| }
|
| return bytes_written;
|
| @@ -155,7 +135,7 @@ int32 PluginDatabaseHandler::Write(NPStream* stream, int32 offset,
|
|
|
|
|
| bool PluginDatabaseHandler::ParsePluginList() {
|
| - if (plugin_downloads_file_ == INVALID_HANDLE_VALUE) {
|
| + if (plugin_downloads_file_ == base::kInvalidPlatformFileValue) {
|
| DLOG(WARNING) << "Invalid plugins file";
|
| NOTREACHED();
|
| return false;
|
| @@ -163,10 +143,15 @@ bool PluginDatabaseHandler::ParsePluginList() {
|
|
|
| bool parse_result = false;
|
|
|
| - std::string plugins_file = WideToUTF8(plugins_file_.c_str());
|
| + std::string plugins_file;
|
| +#if defined OS_WIN
|
| + plugins_file = WideToUTF8(plugins_file_.value());
|
| +#else
|
| + plugins_file = plugins_file_.value();
|
| +#endif
|
| xmlDocPtr plugin_downloads_doc = xmlParseFile(plugins_file.c_str());
|
| if (plugin_downloads_doc == NULL) {
|
| - DLOG(WARNING) << "Failed to parse plugins file " << plugins_file.c_str();
|
| + DLOG(WARNING) << "Failed to parse plugins file " << plugins_file_.value();
|
| return parse_result;
|
| }
|
|
|
| @@ -218,10 +203,10 @@ bool PluginDatabaseHandler::ParsePluginList() {
|
| }
|
|
|
| bool PluginDatabaseHandler::GetPluginDetailsForMimeType(
|
| - const char* mime_type, const char* language,
|
| - std::string* download_url, std::wstring* plugin_name,
|
| + const std::string& mime_type, const std::string& language,
|
| + std::string* download_url, string16* plugin_name,
|
| bool* download_url_for_display) {
|
| - if (!mime_type || !language || !download_url || !plugin_name ||
|
| + if (mime_type.empty() || language.empty() || !download_url || !plugin_name ||
|
| !download_url_for_display) {
|
| NOTREACHED();
|
| return false;
|
| @@ -237,8 +222,8 @@ bool PluginDatabaseHandler::GetPluginDetailsForMimeType(
|
| for (mime_type_index = current_plugin.mime_types.begin();
|
| mime_type_index != current_plugin.mime_types.end();
|
| ++mime_type_index) {
|
| - if ((0 == lstrcmpiA(mime_type, (*mime_type_index).c_str())) &&
|
| - (0 == lstrcmpiA(language, current_plugin.language.c_str()))) {
|
| + if ((*mime_type_index == mime_type) &&
|
| + (current_plugin.language == language)) {
|
| *download_url = current_plugin.download_url;
|
| *plugin_name = current_plugin.display_name;
|
| *download_url_for_display = current_plugin.download_url_for_display;
|
| @@ -250,18 +235,20 @@ bool PluginDatabaseHandler::GetPluginDetailsForMimeType(
|
| }
|
|
|
| void PluginDatabaseHandler::Close(bool delete_file) {
|
| - if (plugin_downloads_file_ != INVALID_HANDLE_VALUE) {
|
| - ::CloseHandle(plugin_downloads_file_);
|
| - plugin_downloads_file_ = INVALID_HANDLE_VALUE;
|
| + if (plugin_downloads_file_ != base::kInvalidPlatformFileValue) {
|
| + base::ClosePlatformFile(plugin_downloads_file_);
|
| + plugin_downloads_file_ = base::kInvalidPlatformFileValue;
|
| if (delete_file) {
|
| - ::DeleteFile(plugins_file_.c_str());
|
| - plugins_file_.clear();
|
| + bool result = file_util::Delete(plugins_file_, false);
|
| + DCHECK(result);
|
| + plugins_file_ = FilePath();
|
| }
|
| }
|
| }
|
|
|
| -bool PluginDatabaseHandler::ReadPluginInfo(_xmlNode* plugin_node,
|
| - PluginDetail* plugin_detail) {
|
| +bool PluginDatabaseHandler::ReadPluginInfo(
|
| + _xmlNode* plugin_node,
|
| + PluginDatabaseHandler::PluginDetail* plugin_detail) {
|
| static const char kMimeTypeSeparator = ';';
|
|
|
| if (!plugin_node) {
|
| @@ -343,7 +330,7 @@ bool PluginDatabaseHandler::ReadPluginInfo(_xmlNode* plugin_node,
|
| }
|
|
|
| plugin_detail->display_name =
|
| - UTF8ToWide(reinterpret_cast<const char*>(plugin_name_val->content));
|
| + UTF8ToUTF16(reinterpret_cast<const char*>(plugin_name_val->content));
|
| plugin_detail->download_url =
|
| reinterpret_cast<const char*>(plugin_download_url_val->content);
|
|
|
| @@ -356,3 +343,9 @@ bool PluginDatabaseHandler::ReadPluginInfo(_xmlNode* plugin_node,
|
|
|
| return true;
|
| }
|
| +
|
| +PluginDatabaseHandler::PluginDetail::PluginDetail() {
|
| +}
|
| +
|
| +PluginDatabaseHandler::PluginDetail::~PluginDetail() {
|
| +}
|
|
|