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