| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_DEFAULT_PLUGIN_PLUGIN_DATABASE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_PLUGIN_DATABASE_HANDLER_H_ |
| 6 #define CHROME_DEFAULT_PLUGIN_PLUGIN_DATABASE_HANDLER_H_ | 6 #define CHROME_BROWSER_PLUGIN_DATABASE_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | |
| 10 #include <string> | 9 #include <string> |
| 11 #include <vector> | 10 #include <vector> |
| 12 | 11 |
| 13 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/platform_file.h" |
| 14 #include "third_party/npapi/bindings/npapi.h" | 14 #include "third_party/npapi/bindings/npapi.h" |
| 15 | 15 |
| 16 // Individual plugin details | |
| 17 struct PluginDetail { | |
| 18 // List of mime types supported by the plugin. | |
| 19 std::vector<std::string> mime_types; | |
| 20 // The URL where the plugin can be downloaded from. | |
| 21 std::string download_url; | |
| 22 // The display name for the plugin. | |
| 23 std::wstring display_name; | |
| 24 // Language of the plugin installer. (en-us, etc). | |
| 25 std::string language; | |
| 26 // Indicates if the download URL points to an exe or to a URL which | |
| 27 // needs to be displayed in a tab. | |
| 28 bool download_url_for_display; | |
| 29 }; | |
| 30 | |
| 31 typedef std::vector<PluginDetail> PluginList; | |
| 32 | |
| 33 class PluginInstallerImpl; | |
| 34 struct _xmlNode; | 16 struct _xmlNode; |
| 35 | 17 |
| 36 // This class handles download of the plugins database file from the plugin | 18 // This class handles download of the plugins database file from the plugin |
| 37 // finder URL passed in. It also provides functionality to parse the plugins | 19 // finder URL passed in. It also provides functionality to parse the plugins |
| 38 // file and to locate the desired plugin mime type in the parsed plugin list. | 20 // file and to locate the desired plugin mime type in the parsed plugin list. |
| 39 // The format of the plugins databse file is as below:- | 21 // The format of the plugins databse file is as below:- |
| 40 // <plugins> | 22 // <plugins> |
| 41 // <plugin> | 23 // <plugin> |
| 42 // <mime_types> </mime_types> (semicolon separated list of mime types | 24 // <mime_types> </mime_types> (semicolon separated list of mime types |
| 43 // supported by the plugin) | 25 // supported by the plugin) |
| 44 // <lang> </lang> (Supported language) | 26 // <lang> </lang> (Supported language) |
| 45 // <url> </url> (Link to the plugin installer) | 27 // <url> </url> (Link to the plugin installer) |
| 46 // <displayurl> 0 </displayurl> (Indicates if the URL is a display URL. | 28 // <displayurl> 0 </displayurl> (Indicates if the URL is a display URL. |
| 47 // defaults to 0. | 29 // defaults to 0. |
| 48 // </plugin> | 30 // </plugin> |
| 49 // <plugin> | 31 // <plugin> |
| 50 // </plugins> | 32 // </plugins> |
| 51 class PluginDatabaseHandler { | 33 class PluginDatabaseHandler { |
| 52 public: | 34 public: |
| 35 class Client { |
| 36 public: |
| 37 virtual void DownloadPluginList(const std::string& plugin_finder_url) = 0; |
| 38 virtual void OnPluginListDownloaded() = 0; |
| 39 }; |
| 40 |
| 53 // plugin_installer_instance is a reference maintained to the current | 41 // plugin_installer_instance is a reference maintained to the current |
| 54 // PluginInstallerImpl instance. | 42 // PluginInstallerImpl instance. |
| 55 explicit PluginDatabaseHandler( | 43 explicit PluginDatabaseHandler(); |
| 56 PluginInstallerImpl& plugin_installer_instance); | |
| 57 | 44 |
| 58 virtual ~PluginDatabaseHandler(); | 45 ~PluginDatabaseHandler(); |
| 59 | 46 |
| 60 // Downloads the plugins database file if needed. | 47 // Downloads the plugins database file if needed. |
| 61 // | 48 // |
| 62 // Parameters: | 49 // Parameters: |
| 63 // plugin_finder_url | 50 // plugin_finder_url |
| 64 // Specifies the http/https location of the chrome plugin finder. | 51 // Specifies the http/https location of the chrome plugin finder. |
| 65 // Returns true on success. | 52 // Returns true on success. |
| 66 bool DownloadPluginsFileIfNeeded(const std::string& plugin_finder_url); | 53 bool DownloadPluginsFileIfNeeded(const std::string& plugin_finder_url, |
| 54 Client* client); |
| 67 | 55 |
| 68 // Writes data to the plugins database file. | 56 // Writes data to the plugins database file. |
| 69 // | 57 // |
| 70 // Parameters: | 58 // Parameters: |
| 71 // stream | 59 // stream |
| 72 // Pointer to the current stream. | 60 // Pointer to the current stream. |
| 73 // offset | 61 // offset |
| 74 // Indicates the data offset. | 62 // Indicates the data offset. |
| 75 // buffer_length | 63 // buffer_length |
| 76 // Specifies the length of the data buffer. | 64 // Specifies the length of the data buffer. |
| 77 // buffer | 65 // buffer |
| 78 // Pointer to the actual buffer. | 66 // Pointer to the actual buffer. |
| 79 // Returns the number of bytes actually written, 0 on error. | 67 // Returns the number of bytes actually written, 0 on error. |
| 80 int32 Write(NPStream* stream, int32 offset, int32 buffer_length, | 68 int32 Write(NPStream* stream, int32 offset, int32 buffer_length, |
| 81 void* buffer); | 69 void* buffer); |
| 82 | 70 |
| 83 const std::wstring& plugins_file() const { | 71 const FilePath& plugins_file() const { |
| 84 return plugins_file_; | 72 return plugins_file_; |
| 85 } | 73 } |
| 86 | 74 |
| 87 // Parses the XML file containing the list of available third-party | 75 // Parses the XML file containing the list of available third-party |
| 88 // plugins and adds them to a list. | 76 // plugins and adds them to a list. |
| 89 // Returns true on success | 77 // Returns true on success |
| 90 bool ParsePluginList(); | 78 bool ParsePluginList(); |
| 91 | 79 |
| 92 // Returns the plugin details for the third party plugin mime type passed in. | 80 // Returns the plugin details for the third party plugin mime type passed in. |
| 93 // | 81 // |
| 94 // Parameters: | 82 // Parameters: |
| 95 // mime_type | 83 // mime_type |
| 96 // Specifies the mime type of the desired third party plugin. | 84 // Specifies the mime type of the desired third party plugin. |
| 97 // language | 85 // language |
| 98 // Specifies the desired plugin language. | 86 // Specifies the desired plugin language. |
| 99 // download_url | 87 // download_url |
| 100 // Output parameter which contans the plugin download URL on success. | 88 // Output parameter which contans the plugin download URL on success. |
| 101 // display_name | 89 // display_name |
| 102 // Output parameter which contains the display name of the plugin on | 90 // Output parameter which contains the display name of the plugin on |
| 103 // success. | 91 // success. |
| 104 // download_url_for_display | 92 // download_url_for_display |
| 105 // Output parameter which indicates if the plugin URL points to an exe | 93 // Output parameter which indicates if the plugin URL points to an exe |
| 106 // or not. | 94 // or not. |
| 107 // Returns true if the plugin details were found. | 95 // Returns true if the plugin details were found. |
| 108 bool GetPluginDetailsForMimeType(const char* mime_type, | 96 bool GetPluginDetailsForMimeType(const std::string& mime_type, |
| 109 const char* language, | 97 const std::string& language, |
| 110 std::string* download_url, | 98 std::string* download_url, |
| 111 std::wstring* display_name, | 99 string16* display_name, |
| 112 bool* download_url_for_display); | 100 bool* download_url_for_display); |
| 113 | 101 |
| 114 // Closes the handle to the plugin database file. | 102 // Closes the handle to the plugin database file. |
| 115 // | 103 // |
| 116 // Parameters: | 104 // Parameters: |
| 117 // delete_file | 105 // delete_file |
| 118 // Indicates if the plugin database file should be deleted. | 106 // Indicates if the plugin database file should be deleted. |
| 119 void Close(bool delete_file); | 107 void Close(bool delete_file); |
| 120 | 108 |
| 121 protected: | 109 protected: |
| 110 // Individual plugin details |
| 111 struct PluginDetail { |
| 112 PluginDetail(); |
| 113 ~PluginDetail(); |
| 114 |
| 115 // List of mime types supported by the plugin. |
| 116 std::vector<std::string> mime_types; |
| 117 // The URL where the plugin can be downloaded from. |
| 118 std::string download_url; |
| 119 // The display name for the plugin. |
| 120 string16 display_name; |
| 121 // Language of the plugin installer. (en-us, etc). |
| 122 std::string language; |
| 123 // Indicates if the download URL points to an exe or to a URL which |
| 124 // needs to be displayed in a tab. |
| 125 bool download_url_for_display; |
| 126 }; |
| 127 |
| 122 // Reads plugin information off an individual XML node. | 128 // Reads plugin information off an individual XML node. |
| 123 // | 129 // |
| 124 // Parameters: | 130 // Parameters: |
| 125 // plugin_node | 131 // plugin_node |
| 126 // Pointer to the plugin XML node. | 132 // Pointer to the plugin XML node. |
| 127 // plugin_detail | 133 // plugin_detail |
| 128 // Output parameter which contains the details of the plugin on success. | 134 // Output parameter which contains the details of the plugin on success. |
| 129 // Returns true on success. | 135 // Returns true on success. |
| 130 bool ReadPluginInfo(_xmlNode* plugin_node, PluginDetail* plugin_detail); | 136 bool ReadPluginInfo(_xmlNode* plugin_node, PluginDetail* plugin_detail); |
| 131 | 137 |
| 132 private: | 138 private: |
| 139 typedef std::vector<PluginDetail> PluginList; |
| 140 |
| 133 // Contains the full path of the downloaded plugins file containing | 141 // Contains the full path of the downloaded plugins file containing |
| 134 // information about available third party plugin downloads. | 142 // information about available third party plugin downloads. |
| 135 std::wstring plugins_file_; | 143 FilePath plugins_file_; |
| 136 // Handle to the downloaded plugins file. | 144 // Handle to the downloaded plugins file. |
| 137 HANDLE plugin_downloads_file_; | 145 base::PlatformFile plugin_downloads_file_; |
| 138 // List of downloaded plugins. This is generated the first time the | 146 // List of downloaded plugins. This is generated the first time the |
| 139 // plugins file is downloaded and parsed. Each item in the list is | 147 // plugins file is downloaded and parsed. Each item in the list is |
| 140 // of the type PluginDetail, and contains information about the third | 148 // of the type PluginDetail, and contains information about the third |
| 141 // party plugin like it's mime type, download link, etc. | 149 // party plugin like it's mime type, download link, etc. |
| 142 PluginList downloaded_plugins_list_; | 150 PluginList downloaded_plugins_list_; |
| 143 // We maintain a reference to the PluginInstallerImpl instance to be able | |
| 144 // to achieve plugin installer state changes and to notify the instance | |
| 145 // about download completions. | |
| 146 PluginInstallerImpl& plugin_installer_instance_; | |
| 147 // The plugin finder url | 151 // The plugin finder url |
| 148 std::string plugin_finder_url_; | 152 std::string plugin_finder_url_; |
| 149 // Set if the current instance should ignore plugin data. This is required | 153 // Set if the current instance should ignore plugin data. This is required |
| 150 // if multiple null plugin instances attempt to download the plugin | 154 // if multiple null plugin instances attempt to download the plugin |
| 151 // database. In this case the first instance to create the plugins database | 155 // database. In this case the first instance to create the plugins database |
| 152 // file locally writes to the file. The remaining instances ignore the | 156 // file locally writes to the file. The remaining instances ignore the |
| 153 // downloaded data. | 157 // downloaded data. |
| 154 bool ignore_plugin_db_data_; | 158 bool ignore_plugin_db_data_; |
| 155 }; | 159 }; |
| 156 | 160 |
| 157 #endif // CHROME_DEFAULT_PLUGIN_PLUGIN_DATABASE_HANDLER_H_ | 161 #endif // CHROME_BROWSER_PLUGIN_DATABASE_HANDLER_H_ |
| OLD | NEW |