| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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 WEBKIT_DEFAULT_PLUGIN_PLUGIN_IMPL_GTK_H_ |
| 6 #define WEBKIT_DEFAULT_PLUGIN_PLUGIN_IMPL_GTK_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include <gtk/gtk.h> |
| 12 |
| 13 #include "gfx/native_widget_types.h" |
| 14 #include "third_party/npapi/bindings/npapi.h" |
| 15 |
| 16 // Possible plugin installer states. |
| 17 enum PluginInstallerState { |
| 18 PluginInstallerStateUndefined, |
| 19 PluginListDownloadInitiated, |
| 20 PluginListDownloaded, |
| 21 PluginListDownloadedPluginNotFound, |
| 22 PluginListDownloadFailed, |
| 23 PluginDownloadInitiated, |
| 24 PluginDownloadCompleted, |
| 25 PluginDownloadFailed, |
| 26 PluginInstallerLaunchSuccess, |
| 27 PluginInstallerLaunchFailure |
| 28 }; |
| 29 |
| 30 class PluginInstallDialog; |
| 31 class PluginDatabaseHandler; |
| 32 |
| 33 // Provides the plugin installation functionality. This class is |
| 34 // instantiated with the information like the mime type of the |
| 35 // target plugin, the display mode, etc. |
| 36 class PluginInstallerImpl { |
| 37 public: |
| 38 // mode is the plugin instantiation mode, i.e. whether it is a full |
| 39 // page plugin (NP_FULL) or an embedded plugin (NP_EMBED) |
| 40 explicit PluginInstallerImpl(int16 mode); |
| 41 virtual ~PluginInstallerImpl(); |
| 42 |
| 43 // Initializes the plugin with the instance information, mime type |
| 44 // and the list of parameters passed down to the plugin from the webpage. |
| 45 // |
| 46 // Parameters: |
| 47 // module_handle |
| 48 // The handle to the dll in which this object is instantiated. |
| 49 // instance |
| 50 // The plugins opaque instance handle. |
| 51 // mime_type |
| 52 // Identifies the third party plugin which would be eventually installed. |
| 53 // argc |
| 54 // Indicates the count of arguments passed in from the webpage. |
| 55 // argv |
| 56 // Pointer to the arguments. |
| 57 // Returns true on success. |
| 58 bool Initialize(void* module_handle, NPP instance, NPMIMEType mime_type, |
| 59 int16 argc, char* argn[], char* argv[]); |
| 60 |
| 61 // Informs the plugin of its window information. |
| 62 // |
| 63 // Parameters: |
| 64 // window_info |
| 65 // The window info passed to npapi. |
| 66 bool NPP_SetWindow(NPWindow* window_info); |
| 67 |
| 68 // Destroys the install dialog. |
| 69 void Shutdown(); |
| 70 |
| 71 // Starts plugin download. Spawns the plugin installer after it is |
| 72 // downloaded. |
| 73 void DownloadPlugin(); |
| 74 |
| 75 // Indicates that the plugin download was cancelled. |
| 76 void DownloadCancelled(); |
| 77 |
| 78 // Initializes the plugin download stream. |
| 79 // |
| 80 // Parameters: |
| 81 // stream |
| 82 // Pointer to the new stream being created. |
| 83 void NewStream(NPStream* stream); |
| 84 |
| 85 // Uninitializes the plugin download stream. |
| 86 // |
| 87 // Parameters: |
| 88 // stream |
| 89 // Pointer to the stream being destroyed. |
| 90 // reason |
| 91 // Indicates why the stream is being destroyed. |
| 92 // |
| 93 void DestroyStream(NPStream* stream, NPError reason); |
| 94 |
| 95 // Determines whether the plugin is ready to accept data. |
| 96 // We only accept data when we have initiated a download for the plugin |
| 97 // database. |
| 98 // |
| 99 // Parameters: |
| 100 // stream |
| 101 // Pointer to the stream being destroyed. |
| 102 // Returns true if the plugin is ready to accept data. |
| 103 bool WriteReady(NPStream* stream); |
| 104 |
| 105 // Delivers data to the plugin instance. |
| 106 // |
| 107 // Parameters: |
| 108 // stream |
| 109 // Pointer to the stream being destroyed. |
| 110 // offset |
| 111 // Indicates the data offset. |
| 112 // buffer_length |
| 113 // Indicates the length of the data buffer. |
| 114 // buffer |
| 115 // Pointer to the actual buffer. |
| 116 // Returns the number of bytes actually written, 0 on error. |
| 117 int32 Write(NPStream* stream, int32 offset, int32 buffer_length, |
| 118 void* buffer); |
| 119 |
| 120 // Handles notifications received in response to GetURLNotify calls issued |
| 121 // by the plugin. |
| 122 // |
| 123 // Parameters: |
| 124 // url |
| 125 // Pointer to the URL. |
| 126 // reason |
| 127 // Describes why the notification was sent. |
| 128 void URLNotify(const char* url, NPReason reason); |
| 129 |
| 130 // Used by the renderer to indicate plugin install through the infobar. |
| 131 int16 NPP_HandleEvent(void* event); |
| 132 |
| 133 const std::string& mime_type() const { return mime_type_; } |
| 134 |
| 135 // Replaces a resource string with the placeholder passed in as an argument |
| 136 // |
| 137 // Parameters: |
| 138 // message_id_with_placeholders |
| 139 // The resource id of the string with placeholders. This is only used if |
| 140 // the placeholder string (the replacement_string) parameter is valid. |
| 141 // message_id_without_placeholders |
| 142 // The resource id of the string to be returned if the placeholder is |
| 143 // empty. |
| 144 // replacement_string |
| 145 // The placeholder which replaces tokens in the string identified by |
| 146 // resource id message_id_with_placeholders. |
| 147 // Returns a string which has the placeholders replaced, or the string |
| 148 // without placeholders. |
| 149 static std::wstring ReplaceStringForPossibleEmptyReplacement( |
| 150 int message_id_with_placeholders, int message_id_without_placeholders, |
| 151 const std::wstring& replacement_string); |
| 152 |
| 153 // Setter/getter combination to set and retreieve the current |
| 154 // state of the plugin installer. |
| 155 void set_plugin_installer_state(PluginInstallerState new_state) { |
| 156 plugin_installer_state_ = new_state; |
| 157 } |
| 158 |
| 159 PluginInstallerState plugin_installer_state() const { |
| 160 return plugin_installer_state_; |
| 161 } |
| 162 |
| 163 // Getter for the NPP instance member. |
| 164 const NPP instance() const { |
| 165 return instance_; |
| 166 } |
| 167 |
| 168 // Returns whether or not the UI layout is right-to-left (such as Hebrew or |
| 169 // Arabic). |
| 170 bool IsRTLLayout() const; |
| 171 |
| 172 protected: |
| 173 // Displays the plugin install confirmation dialog. |
| 174 void ShowInstallDialog(); |
| 175 |
| 176 // Clears the current display state. |
| 177 void ClearDisplay(); |
| 178 |
| 179 // Displays the status message identified by the message resource id |
| 180 // passed in. |
| 181 // |
| 182 // Parameters: |
| 183 // message_resource_id parameter |
| 184 // The resource id of the message to be displayed. |
| 185 void DisplayStatus(int message_resource_id); |
| 186 |
| 187 // Displays status information for the third party plugin which is needed |
| 188 // by the page. |
| 189 void DisplayAvailablePluginStatus(); |
| 190 |
| 191 // Displays information related to third party plugin download failure. |
| 192 void DisplayPluginDownloadFailedStatus(); |
| 193 |
| 194 // Enables the plugin window if required and initiates an update of the |
| 195 // the plugin window. |
| 196 void RefreshDisplay(); |
| 197 |
| 198 // Create tooltip window. |
| 199 bool CreateToolTip(); |
| 200 |
| 201 // Update ToolTip text with the message shown inside the default plugin. |
| 202 void UpdateToolTip(); |
| 203 |
| 204 // Resolves the relative URL (could be already an absolute URL too) to return |
| 205 // full URL based on current document's URL and base. |
| 206 // |
| 207 // Parameters: |
| 208 // instance |
| 209 // The plugins opaque instance handle. |
| 210 // relative_url |
| 211 // The URL to be resolved. |
| 212 // Returns the resolved URL. |
| 213 std::string ResolveURL(NPP instance, const std::string& relative_url); |
| 214 |
| 215 // Initializes resources like the icon, fonts, etc needed by the plugin |
| 216 // installer |
| 217 // |
| 218 // Parameters: |
| 219 // module_handle |
| 220 // Handle to the dll in which this object is instantiated. |
| 221 // Returns true on success. |
| 222 bool InitializeResources(void *module_handle); |
| 223 |
| 224 // Parses the plugin instantiation arguments. This includes checking for |
| 225 // whether this is an activex install and reading the appropriate |
| 226 // arguments like codebase, etc. For plugin installs we download the |
| 227 // plugin finder URL and initalize the mime type and the plugin instance |
| 228 // info. |
| 229 // |
| 230 // Parameters: |
| 231 // module_handle |
| 232 // The handle to the dll in which this object is instantiated. |
| 233 // instance |
| 234 // The plugins opaque instance handle. |
| 235 // mime_type |
| 236 // Identifies the third party plugin which would be eventually installed. |
| 237 // argc |
| 238 // Indicates the count of arguments passed in from the webpage. |
| 239 // argv |
| 240 // Pointer to the arguments. |
| 241 // raw_activex_clsid |
| 242 // Output parameter which contains the CLSID of the Activex plugin needed. |
| 243 // This is only applicable if the webpage specifically requests an ActiveX |
| 244 // control. |
| 245 // Returns true on success. |
| 246 bool ParseInstantiationArguments(NPMIMEType mime_type, NPP instance, |
| 247 int16 argc, char* argn[], char* argv[], |
| 248 std::string* raw_activex_clsid); |
| 249 |
| 250 // Paints user action messages to the plugin window. These include messages |
| 251 // like whether the user should click on the plugin window to download the |
| 252 // plugin, etc. |
| 253 // |
| 254 // Parameters: |
| 255 // paint_dc |
| 256 // The device context returned in BeginPaint. |
| 257 // x_origin |
| 258 // Horizontal reference point indicating where the text is to be displayed. |
| 259 // y_origin |
| 260 // Vertical reference point indicating where the text is to be displayed. |
| 261 // |
| 262 void PaintUserActionInformation(gfx::NativeDrawingContext paint_dc, |
| 263 int x_origin, int y_origin); |
| 264 |
| 265 private: |
| 266 // Notify the renderer that plugin is available to download. |
| 267 void NotifyPluginStatus(int status); |
| 268 |
| 269 // The plugins opaque instance handle |
| 270 NPP instance_; |
| 271 // The current stream. |
| 272 NPStream* plugin_install_stream_; |
| 273 // The desired mime type. |
| 274 std::string mime_type_; |
| 275 // The current state of the plugin installer. |
| 276 PluginInstallerState plugin_installer_state_; |
| 277 // GtkPlug containing everything in the plugin. |
| 278 GtkWidget* container_; |
| 279 |
| 280 DISALLOW_COPY_AND_ASSIGN(PluginInstallerImpl); |
| 281 }; |
| 282 |
| 283 #endif // WEBKIT_DEFAULT_PLUGIN_PLUGIN_IMPL_GTK_H_ |
| OLD | NEW |