OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome_frame/chrome_frame_npapi.h" | 5 #include "chrome_frame/chrome_frame_npapi.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 COMPILE_ASSERT(arraysize(plugin_method_identifier_names_) == | 79 COMPILE_ASSERT(arraysize(plugin_method_identifier_names_) == |
80 arraysize(plugin_methods_), | 80 arraysize(plugin_methods_), |
81 you_must_add_both_plugin_method_and_name); | 81 you_must_add_both_plugin_method_and_name); |
82 | 82 |
83 COMPILE_ASSERT(arraysize(plugin_property_identifier_names_) == | 83 COMPILE_ASSERT(arraysize(plugin_property_identifier_names_) == |
84 arraysize(plugin_property_identifiers_), | 84 arraysize(plugin_property_identifiers_), |
85 you_must_add_both_plugin_property_and_name); | 85 you_must_add_both_plugin_property_and_name); |
86 } | 86 } |
87 | 87 |
88 static const int kMaxBytesForPluginConsumption = 0x7FFFFFFF; | |
89 | |
90 static const char kPluginSrcAttribute[] = "src"; | 88 static const char kPluginSrcAttribute[] = "src"; |
91 static const char kPluginForceFullPageAttribute[] = "force_full_page"; | 89 static const char kPluginForceFullPageAttribute[] = "force_full_page"; |
92 static const char kPluginOnloadAttribute[] = "onload"; | 90 static const char kPluginOnloadAttribute[] = "onload"; |
93 static const char kPluginOnErrorAttribute[] = "onloaderror"; | 91 static const char kPluginOnErrorAttribute[] = "onloaderror"; |
94 static const char kPluginOnMessageAttribute[] = "onmessage"; | 92 static const char kPluginOnMessageAttribute[] = "onmessage"; |
95 static const char kPluginOnPrivateMessageAttribute[] = "onprivatemessage"; | 93 static const char kPluginOnPrivateMessageAttribute[] = "onprivatemessage"; |
96 // These properties can only be set in arguments at control instantiation. | 94 // These properties can only be set in arguments at control instantiation. |
97 // When the privileged_mode property is provided and set to true, the control | 95 // When the privileged_mode property is provided and set to true, the control |
98 // will probe for whether its hosting document has the system principal, in | 96 // will probe for whether its hosting document has the system principal, in |
99 // which case privileged mode will be enabled. | 97 // which case privileged mode will be enabled. |
100 static const char kPluginPrivilegedModeAttribute[] = "privileged_mode"; | 98 static const char kPluginPrivilegedModeAttribute[] = "privileged_mode"; |
101 // If privileged mode is enabled, the string value of this argument will | 99 // If privileged mode is enabled, the string value of this argument will |
102 // be appended to the chrome.exe command line. | 100 // be appended to the chrome.exe command line. |
103 static const char kPluginChromeExtraArguments[] = "chrome_extra_arguments"; | 101 static const char kPluginChromeExtraArguments[] = "chrome_extra_arguments"; |
104 // If privileged mode is enabled, the string value of this argument will | 102 // If privileged mode is enabled, the string value of this argument will |
105 // be used as the profile name for our chrome.exe instance. | 103 // be used as the profile name for our chrome.exe instance. |
106 static const char kPluginChromeProfileName[] = "chrome_profile_name"; | 104 static const char kPluginChromeProfileName[] = "chrome_profile_name"; |
107 // If privileged mode is enabled, this argument will be taken as a | 105 // If privileged mode is enabled, this argument will be taken as a |
108 // comma-separated list of API function calls to automate. | 106 // comma-separated list of API function calls to automate. |
109 static const char kPluginChromeFunctionsAutomatedAttribute[] = | 107 static const char kPluginChromeFunctionsAutomatedAttribute[] = |
110 "chrome_functions_automated"; | 108 "chrome_functions_automated"; |
111 // If chrome network stack is to be used | 109 // If chrome network stack is to be used |
112 static const char kPluginUseChromeNetwork[] = "usechromenetwork"; | 110 static const char kPluginUseChromeNetwork[] = "usechromenetwork"; |
113 | 111 |
114 | |
115 NPError NPP_New(NPMIMEType plugin_type, NPP instance, uint16 mode, int16 argc, | |
116 char* argn[], char* argv[], NPSavedData* saved) { | |
117 if (instance == NULL) | |
118 return NPERR_INVALID_INSTANCE_ERROR; | |
119 | |
120 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj = | |
121 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
122 npapi::CreateObject(instance, ChromeFrameNPAPI::PluginClass())); | |
123 DCHECK(chrome_frame_npapi_obj != NULL); | |
124 | |
125 ChromeFrameNPAPI* plugin_instance = | |
126 chrome_frame_npapi_obj->chrome_frame_plugin_instance; | |
127 DCHECK(plugin_instance != NULL); | |
128 | |
129 // Note that we MUST set instance->pdata BEFORE calling Initialize. This is | |
130 // because Initialize can call back into the NPAPI host which will need the | |
131 // pdata field to be set. | |
132 chrome_frame_npapi_obj->chrome_frame_plugin_instance = | |
133 plugin_instance; | |
134 instance->pdata = chrome_frame_npapi_obj; | |
135 | |
136 bool init = plugin_instance->Initialize(plugin_type, instance, | |
137 mode, argc, argn, argv); | |
138 DCHECK(init); | |
139 | |
140 return NPERR_NO_ERROR; | |
141 } | |
142 | |
143 NPError NPP_Destroy(NPP instance, NPSavedData** save) { | |
144 // Takes ownership and releases the object at the end of scope. | |
145 ScopedNpObject<ChromeFrameNPAPI::ChromeFrameNPObject> chrome_frame_npapi_obj( | |
146 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
147 instance->pdata)); | |
148 | |
149 if (chrome_frame_npapi_obj.get()) { | |
150 ChromeFrameNPAPI* plugin_instance = | |
151 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
152 | |
153 plugin_instance->Uninitialize(); | |
154 instance->pdata = NULL; | |
155 } | |
156 | |
157 return NPERR_NO_ERROR; | |
158 } | |
159 | |
160 NPError NPP_SetWindow(NPP instance, NPWindow* window_info) { | |
161 if (window_info == NULL) { | |
162 NOTREACHED(); | |
163 return NPERR_GENERIC_ERROR; | |
164 } | |
165 | |
166 ChromeFrameNPAPI* plugin_instance = | |
167 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
168 | |
169 if (plugin_instance == NULL) { | |
170 return NPERR_INVALID_INSTANCE_ERROR; | |
171 } | |
172 | |
173 plugin_instance->SetWindow(window_info); | |
174 return NPERR_NO_ERROR; | |
175 } | |
176 | |
177 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, | |
178 NPBool seekable, uint16* stream_type) { | |
179 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest( | |
180 instance, stream->notifyData); | |
181 if (url_request) { | |
182 if (!url_request->OnStreamCreated(type, stream)) | |
183 return NPERR_GENERIC_ERROR; | |
184 } | |
185 | |
186 // We need to return the requested stream mode if we are returning a success | |
187 // code. If we don't do this it causes Opera to blow up. | |
188 *stream_type = NP_NORMAL; | |
189 return NPERR_NO_ERROR; | |
190 } | |
191 | |
192 NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) { | |
193 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest( | |
194 instance, stream->notifyData); | |
195 if (url_request) { | |
196 url_request->OnStreamDestroyed(reason); | |
197 } | |
198 | |
199 return NPERR_NO_ERROR; | |
200 } | |
201 | |
202 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) { | |
203 if (variable == NPPVpluginScriptableNPObject) { | |
204 void** plugin = reinterpret_cast<void**>(value); | |
205 ChromeFrameNPAPI::ChromeFrameNPObject* chrome_frame_npapi_obj = | |
206 reinterpret_cast<ChromeFrameNPAPI::ChromeFrameNPObject*>( | |
207 instance->pdata); | |
208 // Return value is expected to be retained | |
209 npapi::RetainObject(reinterpret_cast<NPObject*>(chrome_frame_npapi_obj)); | |
210 *plugin = chrome_frame_npapi_obj; | |
211 return NPERR_NO_ERROR; | |
212 } | |
213 return NPERR_GENERIC_ERROR; | |
214 } | |
215 | |
216 NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) { | |
217 return NPERR_GENERIC_ERROR; | |
218 } | |
219 | |
220 int32 NPP_WriteReady(NPP instance, NPStream* stream) { | |
221 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest( | |
222 instance, stream->notifyData); | |
223 if (url_request) { | |
224 return url_request->OnWriteReady(); | |
225 } | |
226 | |
227 return kMaxBytesForPluginConsumption; | |
228 } | |
229 | |
230 int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, | |
231 void* buffer) { | |
232 NPAPIUrlRequest* url_request = ChromeFrameNPAPI::ValidateRequest( | |
233 instance, stream->notifyData); | |
234 if (url_request) { | |
235 return url_request->OnWrite(buffer, len); | |
236 } | |
237 | |
238 return len; | |
239 } | |
240 | |
241 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, | |
242 void* notifyData) { | |
243 ChromeFrameNPAPI* plugin_instance = | |
244 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
245 if (plugin_instance) { | |
246 plugin_instance->UrlNotify(url, reason, notifyData); | |
247 } | |
248 } | |
249 | |
250 void NPP_Print(NPP instance, NPPrint* print_info) { | |
251 ChromeFrameNPAPI* plugin_instance = | |
252 ChromeFrameNPAPI::ChromeFrameInstanceFromPluginInstance(instance); | |
253 | |
254 if (plugin_instance == NULL) { | |
255 NOTREACHED(); | |
256 return; | |
257 } | |
258 | |
259 plugin_instance->Print(print_info); | |
260 } | |
261 | |
262 // ChromeFrameNPAPI member defines. | 112 // ChromeFrameNPAPI member defines. |
263 | 113 |
264 // TODO(tommi): remove ignore_setfocus_ since that's not how focus is | 114 // TODO(tommi): remove ignore_setfocus_ since that's not how focus is |
265 // handled anymore. | 115 // handled anymore. |
266 | 116 |
267 ChromeFrameNPAPI::ChromeFrameNPAPI() | 117 ChromeFrameNPAPI::ChromeFrameNPAPI() |
268 : instance_(NULL), | 118 : instance_(NULL), |
269 mode_(NP_EMBED), | 119 mode_(NP_EMBED), |
270 force_full_page_plugin_(false), | 120 force_full_page_plugin_(false), |
271 ready_state_(READYSTATE_LOADING), | 121 ready_state_(READYSTATE_LOADING), |
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 return request; | 1455 return request; |
1606 } | 1456 } |
1607 | 1457 |
1608 bool ChromeFrameNPAPI::HandleContextMenuCommand(UINT cmd, | 1458 bool ChromeFrameNPAPI::HandleContextMenuCommand(UINT cmd, |
1609 const IPC::ContextMenuParams& params) { | 1459 const IPC::ContextMenuParams& params) { |
1610 if (cmd == IDC_ABOUT_CHROME_FRAME) { | 1460 if (cmd == IDC_ABOUT_CHROME_FRAME) { |
1611 // TODO: implement "About Chrome Frame" | 1461 // TODO: implement "About Chrome Frame" |
1612 } | 1462 } |
1613 return false; | 1463 return false; |
1614 } | 1464 } |
OLD | NEW |