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