OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_bindings.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/renderer/browser_plugin/browser_plugin.h" | 16 #include "content/public/renderer/browser_plugin/browser_plugin_method_binding.h
" |
| 17 #include "content/public/renderer/browser_plugin/browser_plugin_property_binding
.h" |
17 #include "content/renderer/browser_plugin/browser_plugin_constants.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_constants.h" |
| 19 #include "content/renderer/browser_plugin/browser_plugin_impl.h" |
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
26 #include "third_party/npapi/bindings/npapi.h" | 28 #include "third_party/npapi/bindings/npapi.h" |
27 #include "v8/include/v8.h" | 29 #include "v8/include/v8.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 NPUTF8 *chars = static_cast<NPUTF8 *>(malloc(length)); | 66 NPUTF8 *chars = static_cast<NPUTF8 *>(malloc(length)); |
65 if (!chars) { | 67 if (!chars) { |
66 VOID_TO_NPVARIANT(*variant); | 68 VOID_TO_NPVARIANT(*variant); |
67 return false; | 69 return false; |
68 } | 70 } |
69 memcpy(chars, in.c_str(), length); | 71 memcpy(chars, in.c_str(), length); |
70 STRINGN_TO_NPVARIANT(chars, length, *variant); | 72 STRINGN_TO_NPVARIANT(chars, length, *variant); |
71 return true; | 73 return true; |
72 } | 74 } |
73 | 75 |
| 76 bool MatchesName(const std::string& value, NPIdentifier name) { |
| 77 return WebKit::WebBindings::getStringIdentifier(value.c_str()) == name; |
| 78 } |
| 79 |
74 //------------------------------------------------------------------------------ | 80 //------------------------------------------------------------------------------ |
75 // Implementations of NPClass functions. These are here to: | 81 // Implementations of NPClass functions. These are here to: |
76 // - Implement src attribute. | 82 // - Implement src attribute. |
77 //------------------------------------------------------------------------------ | 83 //------------------------------------------------------------------------------ |
78 NPObject* BrowserPluginBindingsAllocate(NPP npp, NPClass* the_class) { | 84 NPObject* BrowserPluginBindingsAllocate(NPP npp, NPClass* the_class) { |
79 return new BrowserPluginBindings::BrowserPluginNPObject; | 85 return new BrowserPluginBindings::BrowserPluginNPObject; |
80 } | 86 } |
81 | 87 |
82 void BrowserPluginBindingsDeallocate(NPObject* object) { | 88 void BrowserPluginBindingsDeallocate(NPObject* object) { |
83 BrowserPluginBindings::BrowserPluginNPObject* instance = | 89 BrowserPluginBindings::BrowserPluginNPObject* instance = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 &BrowserPluginBindingsInvokeDefault, | 186 &BrowserPluginBindingsInvokeDefault, |
181 &BrowserPluginBindingsHasProperty, | 187 &BrowserPluginBindingsHasProperty, |
182 &BrowserPluginBindingsGetProperty, | 188 &BrowserPluginBindingsGetProperty, |
183 &BrowserPluginBindingsSetProperty, | 189 &BrowserPluginBindingsSetProperty, |
184 NULL, | 190 NULL, |
185 &BrowserPluginBindingsEnumerate, | 191 &BrowserPluginBindingsEnumerate, |
186 }; | 192 }; |
187 | 193 |
188 } // namespace | 194 } // namespace |
189 | 195 |
190 // BrowserPluginMethodBinding -------------------------------------------------- | 196 // Method Bindings ------------------------------------------------------------ |
191 | 197 |
192 class BrowserPluginMethodBinding { | 198 class BrowserPluginMethodBindingImpl : public BrowserPluginMethodBinding { |
193 public: | 199 public: |
194 BrowserPluginMethodBinding(const char name[], uint32 arg_count) | 200 BrowserPluginMethodBindingImpl(BrowserPluginImpl* browser_plugin, |
195 : name_(name), | 201 const char name[], |
| 202 uint32 arg_count) |
| 203 : browser_plugin_(browser_plugin), |
| 204 name_(name), |
196 arg_count_(arg_count) { | 205 arg_count_(arg_count) { |
197 } | 206 } |
198 | 207 |
199 virtual ~BrowserPluginMethodBinding() {} | 208 virtual ~BrowserPluginMethodBindingImpl() {} |
200 | 209 |
201 bool MatchesName(NPIdentifier name) const { | 210 BrowserPluginImpl* browser_plugin() const { return browser_plugin_; } |
202 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 211 |
| 212 virtual const std::string& GetName() const OVERRIDE { |
| 213 return name_; |
203 } | 214 } |
204 | 215 virtual uint32 GetArgCount() const OVERRIDE { return arg_count_; } |
205 uint32 arg_count() const { return arg_count_; } | |
206 | |
207 virtual bool Invoke(BrowserPluginBindings* bindings, | |
208 const NPVariant* args, | |
209 NPVariant* result) = 0; | |
210 | 216 |
211 private: | 217 private: |
| 218 BrowserPluginImpl* browser_plugin_; |
212 std::string name_; | 219 std::string name_; |
213 uint32 arg_count_; | 220 uint32 arg_count_; |
214 | 221 |
215 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); | 222 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBindingImpl); |
216 }; | 223 }; |
217 | 224 |
218 class BrowserPluginBindingBack : public BrowserPluginMethodBinding { | 225 class BrowserPluginBindingBack : public BrowserPluginMethodBindingImpl { |
219 public: | 226 public: |
220 BrowserPluginBindingBack() | 227 BrowserPluginBindingBack(BrowserPluginImpl* browser_plugin) |
221 : BrowserPluginMethodBinding(browser_plugin::kMethodBack, 0) { | 228 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 229 browser_plugin::kMethodBack, 0) { |
222 } | 230 } |
223 | 231 |
224 virtual bool Invoke(BrowserPluginBindings* bindings, | 232 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
225 const NPVariant* args, | 233 browser_plugin()->Back(); |
226 NPVariant* result) OVERRIDE { | |
227 bindings->instance()->Back(); | |
228 return true; | 234 return true; |
229 } | 235 } |
230 | 236 |
231 private: | 237 private: |
232 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); | 238 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); |
233 }; | 239 }; |
234 | 240 |
235 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding { | 241 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBindingImpl { |
236 public: | 242 public: |
237 BrowserPluginBindingCanGoBack() | 243 BrowserPluginBindingCanGoBack(BrowserPluginImpl* browser_plugin) |
238 : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoBack, 0) { | 244 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 245 browser_plugin::kMethodCanGoBack, 0) { |
239 } | 246 } |
240 | 247 |
241 virtual bool Invoke(BrowserPluginBindings* bindings, | 248 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
242 const NPVariant* args, | 249 BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoBack(), *result); |
243 NPVariant* result) OVERRIDE { | |
244 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoBack(), *result); | |
245 return true; | 250 return true; |
246 } | 251 } |
247 | 252 |
248 private: | 253 private: |
249 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); | 254 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); |
250 }; | 255 }; |
251 | 256 |
252 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding { | 257 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBindingImpl { |
253 public: | 258 public: |
254 BrowserPluginBindingCanGoForward() | 259 BrowserPluginBindingCanGoForward(BrowserPluginImpl* browser_plugin) |
255 : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoForward, 0) { | 260 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 261 browser_plugin::kMethodCanGoForward, 0) { |
256 } | 262 } |
257 | 263 |
258 virtual bool Invoke(BrowserPluginBindings* bindings, | 264 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
259 const NPVariant* args, | 265 BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoForward(), *result); |
260 NPVariant* result) OVERRIDE { | |
261 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoForward(), *result); | |
262 return true; | 266 return true; |
263 } | 267 } |
264 | 268 |
265 private: | 269 private: |
266 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); | 270 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); |
267 }; | 271 }; |
268 | 272 |
269 class BrowserPluginBindingForward : public BrowserPluginMethodBinding { | 273 class BrowserPluginBindingForward : public BrowserPluginMethodBindingImpl { |
270 public: | 274 public: |
271 BrowserPluginBindingForward() | 275 BrowserPluginBindingForward(BrowserPluginImpl* browser_plugin) |
272 : BrowserPluginMethodBinding(browser_plugin::kMethodForward, 0) { | 276 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 277 browser_plugin::kMethodForward, 0) { |
273 } | 278 } |
274 | 279 |
275 virtual bool Invoke(BrowserPluginBindings* bindings, | 280 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
276 const NPVariant* args, | 281 browser_plugin()->Forward(); |
277 NPVariant* result) OVERRIDE { | |
278 bindings->instance()->Forward(); | |
279 return true; | 282 return true; |
280 } | 283 } |
281 | 284 |
282 private: | 285 private: |
283 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); | 286 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); |
284 }; | 287 }; |
285 | 288 |
286 // Note: This is a method that is used internally by the <webview> shim only. | 289 // Note: This is a method that is used internally by the <webview> shim only. |
287 // This should not be exposed to developers. | 290 // This should not be exposed to developers. |
288 class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBinding { | 291 class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBindingImpl { |
289 public: | 292 public: |
290 BrowserPluginBindingGetRouteID() | 293 BrowserPluginBindingGetRouteID(BrowserPluginImpl* browser_plugin) |
291 : BrowserPluginMethodBinding(browser_plugin::kMethodGetRouteId, 0) { | 294 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 295 browser_plugin::kMethodGetRouteId, 0) { |
292 } | 296 } |
293 | 297 |
294 virtual bool Invoke(BrowserPluginBindings* bindings, | 298 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
295 const NPVariant* args, | 299 INT32_TO_NPVARIANT(browser_plugin()->guest_route_id(), *result); |
296 NPVariant* result) OVERRIDE { | |
297 int route_id = bindings->instance()->guest_route_id(); | |
298 INT32_TO_NPVARIANT(route_id, *result); | |
299 return true; | 300 return true; |
300 } | 301 } |
301 | 302 |
302 private: | 303 private: |
303 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetRouteID); | 304 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetRouteID); |
304 }; | 305 }; |
305 | 306 |
306 class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding { | 307 class BrowserPluginBindingGetProcessID : |
| 308 public BrowserPluginMethodBindingImpl { |
307 public: | 309 public: |
308 BrowserPluginBindingGetProcessID() | 310 BrowserPluginBindingGetProcessID(BrowserPluginImpl* browser_plugin) |
309 : BrowserPluginMethodBinding(browser_plugin::kMethodGetProcessId, 0) { | 311 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 312 browser_plugin::kMethodGetProcessId, 0) { |
310 } | 313 } |
311 | 314 |
312 virtual bool Invoke(BrowserPluginBindings* bindings, | 315 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
313 const NPVariant* args, | 316 INT32_TO_NPVARIANT(browser_plugin()->guest_process_id(), *result); |
314 NPVariant* result) OVERRIDE { | |
315 int process_id = bindings->instance()->guest_process_id(); | |
316 INT32_TO_NPVARIANT(process_id, *result); | |
317 return true; | 317 return true; |
318 } | 318 } |
319 | 319 |
320 private: | 320 private: |
321 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); | 321 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); |
322 }; | 322 }; |
323 | 323 |
324 class BrowserPluginBindingGo : public BrowserPluginMethodBinding { | 324 class BrowserPluginBindingGo : public BrowserPluginMethodBindingImpl { |
325 public: | 325 public: |
326 BrowserPluginBindingGo() | 326 BrowserPluginBindingGo(BrowserPluginImpl* browser_plugin) |
327 : BrowserPluginMethodBinding(browser_plugin::kMethodGo, 1) { | 327 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 328 browser_plugin::kMethodGo, 1) { |
328 } | 329 } |
329 | 330 |
330 virtual bool Invoke(BrowserPluginBindings* bindings, | 331 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
331 const NPVariant* args, | 332 browser_plugin()->Go(Int32FromNPVariant(args[0])); |
332 NPVariant* result) OVERRIDE { | |
333 bindings->instance()->Go(Int32FromNPVariant(args[0])); | |
334 return true; | 333 return true; |
335 } | 334 } |
336 | 335 |
337 private: | 336 private: |
338 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); | 337 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); |
339 }; | 338 }; |
340 | 339 |
341 // Note: This is a method that is used internally by the <webview> shim only. | 340 // Note: This is a method that is used internally by the <webview> shim only. |
342 // This should not be exposed to developers. | 341 // This should not be exposed to developers. |
343 class BrowserPluginBindingPersistRequestObject | 342 class BrowserPluginBindingPersistRequestObject |
344 : public BrowserPluginMethodBinding { | 343 : public BrowserPluginMethodBindingImpl { |
345 public: | 344 public: |
346 BrowserPluginBindingPersistRequestObject() | 345 BrowserPluginBindingPersistRequestObject(BrowserPluginImpl* browser_plugin) |
347 : BrowserPluginMethodBinding(browser_plugin::kMethodInternalPersistObject, | 346 : BrowserPluginMethodBindingImpl( |
348 3) { | 347 browser_plugin, browser_plugin::kMethodInternalPersistObject, 3) { |
349 } | 348 } |
350 | 349 |
351 virtual bool Invoke(BrowserPluginBindings* bindings, | 350 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
352 const NPVariant* args, | 351 browser_plugin()->PersistRequestObject( |
353 NPVariant* result) OVERRIDE { | |
354 bindings->instance()->PersistRequestObject( | |
355 args, StringFromNPVariant(args[1]), Int32FromNPVariant(args[2])); | 352 args, StringFromNPVariant(args[1]), Int32FromNPVariant(args[2])); |
356 return true; | 353 return true; |
357 } | 354 } |
358 | 355 |
359 private: | 356 private: |
360 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingPersistRequestObject); | 357 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingPersistRequestObject); |
361 }; | 358 }; |
362 | 359 |
363 class BrowserPluginBindingReload : public BrowserPluginMethodBinding { | 360 class BrowserPluginBindingReload : public BrowserPluginMethodBindingImpl { |
364 public: | 361 public: |
365 BrowserPluginBindingReload() | 362 BrowserPluginBindingReload(BrowserPluginImpl* browser_plugin) |
366 : BrowserPluginMethodBinding(browser_plugin::kMethodReload, 0) { | 363 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 364 browser_plugin::kMethodReload, 0) { |
367 } | 365 } |
368 | 366 |
369 virtual bool Invoke(BrowserPluginBindings* bindings, | 367 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
370 const NPVariant* args, | 368 browser_plugin()->Reload(); |
371 NPVariant* result) OVERRIDE { | |
372 bindings->instance()->Reload(); | |
373 return true; | 369 return true; |
374 } | 370 } |
375 | 371 |
376 private: | 372 private: |
377 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); | 373 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); |
378 }; | 374 }; |
379 | 375 |
380 class BrowserPluginBindingStop : public BrowserPluginMethodBinding { | 376 class BrowserPluginBindingStop : public BrowserPluginMethodBindingImpl { |
381 public: | 377 public: |
382 BrowserPluginBindingStop() | 378 BrowserPluginBindingStop(BrowserPluginImpl* browser_plugin) |
383 : BrowserPluginMethodBinding(browser_plugin::kMethodStop, 0) { | 379 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 380 browser_plugin::kMethodStop, 0) { |
384 } | 381 } |
385 | 382 |
386 virtual bool Invoke(BrowserPluginBindings* bindings, | 383 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
387 const NPVariant* args, | 384 browser_plugin()->Stop(); |
388 NPVariant* result) OVERRIDE { | |
389 bindings->instance()->Stop(); | |
390 return true; | 385 return true; |
391 } | 386 } |
392 | 387 |
393 private: | 388 private: |
394 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); | 389 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); |
395 }; | 390 }; |
396 | 391 |
397 // Note: This is a method that is used internally by the <webview> shim only. | 392 // Note: This is a method that is used internally by the <webview> shim only. |
398 // This should not be exposed to developers. | 393 // This should not be exposed to developers. |
399 class BrowserPluginBindingSetPermission : public BrowserPluginMethodBinding { | 394 class BrowserPluginBindingSetPermission |
| 395 : public BrowserPluginMethodBindingImpl { |
400 public: | 396 public: |
401 BrowserPluginBindingSetPermission() | 397 BrowserPluginBindingSetPermission(BrowserPluginImpl* browser_plugin) |
402 : BrowserPluginMethodBinding( | 398 : BrowserPluginMethodBindingImpl( |
403 browser_plugin::kMethodInternalSetPermission, 2) { | 399 browser_plugin, browser_plugin::kMethodInternalSetPermission, 2) { |
404 } | 400 } |
405 | 401 |
406 virtual bool Invoke(BrowserPluginBindings* bindings, | 402 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
407 const NPVariant* args, | |
408 NPVariant* result) OVERRIDE { | |
409 int request_id = Int32FromNPVariant(args[0]); | 403 int request_id = Int32FromNPVariant(args[0]); |
410 bool allow = NPVARIANT_TO_BOOLEAN(args[1]); | 404 bool allow = NPVARIANT_TO_BOOLEAN(args[1]); |
411 bindings->instance()->OnEmbedderDecidedPermission(request_id, allow); | 405 browser_plugin()->OnEmbedderDecidedPermission(request_id, allow); |
412 return true; | 406 return true; |
413 } | 407 } |
414 | 408 |
415 private: | 409 private: |
416 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingSetPermission); | 410 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingSetPermission); |
417 }; | 411 }; |
418 | 412 |
419 class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding { | 413 class BrowserPluginBindingTerminate : public BrowserPluginMethodBindingImpl { |
420 public: | 414 public: |
421 BrowserPluginBindingTerminate() | 415 BrowserPluginBindingTerminate(BrowserPluginImpl* browser_plugin) |
422 : BrowserPluginMethodBinding(browser_plugin::kMethodTerminate, 0) { | 416 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 417 browser_plugin::kMethodTerminate, 0) { |
423 } | 418 } |
424 | 419 |
425 virtual bool Invoke(BrowserPluginBindings* bindings, | 420 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
426 const NPVariant* args, | 421 browser_plugin()->TerminateGuest(); |
427 NPVariant* result) OVERRIDE { | |
428 bindings->instance()->TerminateGuest(); | |
429 return true; | 422 return true; |
430 } | 423 } |
431 | 424 |
432 private: | 425 private: |
433 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); | 426 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); |
434 }; | 427 }; |
435 | 428 |
436 // BrowserPluginPropertyBinding ------------------------------------------------ | 429 // Property Bindings ---------------------------------------------------------- |
437 | 430 |
438 class BrowserPluginPropertyBinding { | 431 class BrowserPluginPropertyBindingImpl : public BrowserPluginPropertyBinding { |
439 public: | 432 public: |
440 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {} | 433 BrowserPluginPropertyBindingImpl(BrowserPluginImpl* browser_plugin, |
441 virtual ~BrowserPluginPropertyBinding() {} | 434 const char name[]) |
442 const std::string& name() const { return name_; } | 435 : browser_plugin_(browser_plugin), |
443 bool MatchesName(NPIdentifier name) const { | 436 name_(name) {} |
444 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 437 |
| 438 virtual ~BrowserPluginPropertyBindingImpl() {} |
| 439 |
| 440 BrowserPluginImpl* browser_plugin() const { |
| 441 return browser_plugin_; |
445 } | 442 } |
446 virtual bool GetProperty(BrowserPluginBindings* bindings, | 443 |
447 NPVariant* result) = 0; | 444 // BrowserPluginPropertyBinding implementation. |
448 virtual bool SetProperty(BrowserPluginBindings* bindings, | 445 virtual const std::string& GetName() const OVERRIDE { |
449 NPObject* np_obj, | 446 return name_; |
450 const NPVariant* variant) = 0; | 447 } |
451 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
452 NPObject* np_obj) = 0; | |
453 // Updates the DOM Attribute value with the current property value. | 448 // Updates the DOM Attribute value with the current property value. |
454 void UpdateDOMAttribute(BrowserPluginBindings* bindings, | 449 void UpdateDOMAttribute(std::string new_value) { |
455 std::string new_value) { | 450 browser_plugin_->UpdateDOMAttribute(name_, new_value); |
456 bindings->instance()->UpdateDOMAttribute(name(), new_value); | |
457 } | 451 } |
458 protected: | 452 protected: |
459 // Depending on where the attribute comes from it could be a string, int32, | 453 // Depending on where the attribute comes from it could be a string, int32, |
460 // or a double. Javascript tends to produce an Int32 or a String, but setting | 454 // or a double. Javascript tends to produce an Int32 or a String, but setting |
461 // the value from the developer tools console may also produce a Double... | 455 // the value from the developer tools console may also produce a Double... |
462 int IntFromNPVariant(const NPVariant* variant) { | 456 int IntFromNPVariant(const NPVariant* variant) { |
463 int value; | 457 int value; |
464 switch (variant->type) { | 458 switch (variant->type) { |
465 case NPVariantType_Double: | 459 case NPVariantType_Double: |
466 case NPVariantType_Int32: | 460 case NPVariantType_Int32: |
467 value = Int32FromNPVariant(*variant); | 461 value = Int32FromNPVariant(*variant); |
468 break; | 462 break; |
469 case NPVariantType_String: | 463 case NPVariantType_String: |
470 base::StringToInt(StringFromNPVariant(*variant), &value); | 464 base::StringToInt(StringFromNPVariant(*variant), &value); |
471 break; | 465 break; |
472 default: | 466 default: |
473 value = 0; | 467 value = 0; |
474 break; | 468 break; |
475 } | 469 } |
476 return value; | 470 return value; |
477 } | 471 } |
478 private: | 472 |
| 473 private: |
| 474 BrowserPluginImpl* browser_plugin_; |
479 std::string name_; | 475 std::string name_; |
480 | 476 |
481 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); | 477 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingImpl); |
482 }; | 478 }; |
483 | 479 |
484 class BrowserPluginPropertyBindingAutoSize | 480 class BrowserPluginPropertyBindingAutoSize |
485 : public BrowserPluginPropertyBinding { | 481 : public BrowserPluginPropertyBindingImpl { |
486 public: | 482 public: |
487 BrowserPluginPropertyBindingAutoSize() | 483 BrowserPluginPropertyBindingAutoSize(BrowserPluginImpl* browser_plugin) : |
488 : BrowserPluginPropertyBinding(browser_plugin::kAttributeAutoSize) { | 484 BrowserPluginPropertyBindingImpl(browser_plugin, |
489 } | 485 browser_plugin::kAttributeAutoSize) { |
490 virtual bool GetProperty(BrowserPluginBindings* bindings, | 486 } |
491 NPVariant* result) OVERRIDE { | 487 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
492 bool auto_size = bindings->instance()->GetAutoSizeAttribute(); | 488 BOOLEAN_TO_NPVARIANT(browser_plugin()->GetAutoSizeAttribute(), *result); |
493 BOOLEAN_TO_NPVARIANT(auto_size, *result); | 489 return true; |
494 return true; | 490 } |
495 } | 491 virtual bool SetProperty(NPObject* np_obj, |
496 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
497 NPObject* np_obj, | |
498 const NPVariant* variant) OVERRIDE { | 492 const NPVariant* variant) OVERRIDE { |
499 std::string value = StringFromNPVariant(*variant); | 493 std::string value = StringFromNPVariant(*variant); |
500 if (!bindings->instance()->HasDOMAttribute(name())) { | 494 if (!browser_plugin()->HasDOMAttribute(GetName())) { |
501 UpdateDOMAttribute(bindings, value); | 495 UpdateDOMAttribute(value); |
502 bindings->instance()->ParseAutoSizeAttribute(); | 496 browser_plugin()->ParseAutoSizeAttribute(); |
503 } else { | 497 } else { |
504 UpdateDOMAttribute(bindings, value); | 498 UpdateDOMAttribute(value); |
505 } | 499 } |
506 return true; | 500 return true; |
507 } | 501 } |
508 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 502 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
509 NPObject* np_obj) OVERRIDE { | 503 browser_plugin()->RemoveDOMAttribute(GetName()); |
510 bindings->instance()->RemoveDOMAttribute(name()); | 504 browser_plugin()->ParseAutoSizeAttribute(); |
511 bindings->instance()->ParseAutoSizeAttribute(); | |
512 } | 505 } |
513 private: | 506 private: |
514 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | 507 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); |
515 }; | 508 }; |
516 | 509 |
517 class BrowserPluginPropertyBindingContentWindow | 510 class BrowserPluginPropertyBindingContentWindow |
518 : public BrowserPluginPropertyBinding { | 511 : public BrowserPluginPropertyBindingImpl { |
519 public: | 512 public: |
520 BrowserPluginPropertyBindingContentWindow() | 513 BrowserPluginPropertyBindingContentWindow(BrowserPluginImpl* browser_plugin) : |
521 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { | 514 BrowserPluginPropertyBindingImpl( |
522 } | 515 browser_plugin, |
523 virtual bool GetProperty(BrowserPluginBindings* bindings, | 516 browser_plugin::kAttributeContentWindow) { |
524 NPVariant* result) OVERRIDE { | 517 } |
525 NPObject* obj = bindings->instance()->GetContentWindow(); | 518 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
| 519 NPObject* obj = browser_plugin()->GetContentWindow(); |
526 if (obj) { | 520 if (obj) { |
527 result->type = NPVariantType_Object; | 521 result->type = NPVariantType_Object; |
528 result->value.objectValue = WebBindings::retainObject(obj); | 522 result->value.objectValue = WebBindings::retainObject(obj); |
529 } | 523 } |
530 return true; | 524 return true; |
531 } | 525 } |
532 virtual bool SetProperty(BrowserPluginBindings* bindings, | 526 virtual bool SetProperty(NPObject* np_obj, |
533 NPObject* np_obj, | |
534 const NPVariant* variant) OVERRIDE { | 527 const NPVariant* variant) OVERRIDE { |
535 return false; | 528 return false; |
536 } | 529 } |
537 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 530 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {} |
538 NPObject* np_obj) OVERRIDE {} | |
539 private: | 531 private: |
540 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 532 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
541 }; | 533 }; |
542 | 534 |
543 class BrowserPluginPropertyBindingMaxHeight | 535 class BrowserPluginPropertyBindingMaxHeight |
544 : public BrowserPluginPropertyBinding { | 536 : public BrowserPluginPropertyBindingImpl { |
545 public: | 537 public: |
546 BrowserPluginPropertyBindingMaxHeight() | 538 BrowserPluginPropertyBindingMaxHeight(BrowserPluginImpl* browser_plugin) : |
547 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxHeight) { | 539 BrowserPluginPropertyBindingImpl(browser_plugin, |
548 } | 540 browser_plugin::kAttributeMaxHeight) { |
549 virtual bool GetProperty(BrowserPluginBindings* bindings, | 541 } |
550 NPVariant* result) OVERRIDE { | 542 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
551 int max_height = bindings->instance()->GetMaxHeightAttribute(); | 543 INT32_TO_NPVARIANT(browser_plugin()->GetMaxHeightAttribute(), *result); |
552 INT32_TO_NPVARIANT(max_height, *result); | 544 return true; |
553 return true; | 545 } |
554 } | 546 virtual bool SetProperty(NPObject* np_obj, |
555 virtual bool SetProperty(BrowserPluginBindings* bindings, | 547 const NPVariant* variant) OVERRIDE { |
556 NPObject* np_obj, | 548 int new_value = IntFromNPVariant(variant); |
557 const NPVariant* variant) OVERRIDE { | 549 if (browser_plugin()->GetMaxHeightAttribute() != new_value) { |
558 int new_value = IntFromNPVariant(variant); | 550 UpdateDOMAttribute(base::IntToString(new_value)); |
559 if (bindings->instance()->GetMaxHeightAttribute() != new_value) { | 551 browser_plugin()->ParseSizeContraintsChanged(); |
560 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 552 } |
561 bindings->instance()->ParseSizeContraintsChanged(); | 553 return true; |
562 } | 554 } |
563 return true; | 555 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
564 } | 556 browser_plugin()->RemoveDOMAttribute(GetName()); |
565 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 557 browser_plugin()->ParseSizeContraintsChanged(); |
566 NPObject* np_obj) OVERRIDE { | |
567 bindings->instance()->RemoveDOMAttribute(name()); | |
568 bindings->instance()->ParseSizeContraintsChanged(); | |
569 } | 558 } |
570 private: | 559 private: |
571 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | 560 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); |
572 }; | 561 }; |
573 | 562 |
574 class BrowserPluginPropertyBindingMaxWidth | 563 class BrowserPluginPropertyBindingMaxWidth |
575 : public BrowserPluginPropertyBinding { | 564 : public BrowserPluginPropertyBindingImpl { |
576 public: | 565 public: |
577 BrowserPluginPropertyBindingMaxWidth() | 566 BrowserPluginPropertyBindingMaxWidth(BrowserPluginImpl* browser_plugin) : |
578 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxWidth) { | 567 BrowserPluginPropertyBindingImpl(browser_plugin, |
579 } | 568 browser_plugin::kAttributeMaxWidth) { |
580 virtual bool GetProperty(BrowserPluginBindings* bindings, | 569 } |
581 NPVariant* result) OVERRIDE { | 570 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
582 int max_width = bindings->instance()->GetMaxWidthAttribute(); | 571 INT32_TO_NPVARIANT(browser_plugin()->GetMaxWidthAttribute(), *result); |
583 INT32_TO_NPVARIANT(max_width, *result); | 572 return true; |
584 return true; | 573 } |
585 } | 574 virtual bool SetProperty(NPObject* np_obj, |
586 virtual bool SetProperty(BrowserPluginBindings* bindings, | 575 const NPVariant* variant) OVERRIDE { |
587 NPObject* np_obj, | 576 int new_value = IntFromNPVariant(variant); |
588 const NPVariant* variant) OVERRIDE { | 577 if (browser_plugin()->GetMaxWidthAttribute() != new_value) { |
589 int new_value = IntFromNPVariant(variant); | 578 UpdateDOMAttribute(base::IntToString(new_value)); |
590 if (bindings->instance()->GetMaxWidthAttribute() != new_value) { | 579 browser_plugin()->ParseSizeContraintsChanged(); |
591 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 580 } |
592 bindings->instance()->ParseSizeContraintsChanged(); | 581 return true; |
593 } | 582 } |
594 return true; | 583 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
595 } | 584 browser_plugin()->RemoveDOMAttribute(GetName()); |
596 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 585 browser_plugin()->ParseSizeContraintsChanged(); |
597 NPObject* np_obj) OVERRIDE { | |
598 bindings->instance()->RemoveDOMAttribute(name()); | |
599 bindings->instance()->ParseSizeContraintsChanged(); | |
600 } | 586 } |
601 private: | 587 private: |
602 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | 588 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); |
603 }; | 589 }; |
604 | 590 |
605 class BrowserPluginPropertyBindingMinHeight | 591 class BrowserPluginPropertyBindingMinHeight |
606 : public BrowserPluginPropertyBinding { | 592 : public BrowserPluginPropertyBindingImpl { |
607 public: | 593 public: |
608 BrowserPluginPropertyBindingMinHeight() | 594 BrowserPluginPropertyBindingMinHeight(BrowserPluginImpl* browser_plugin) : |
609 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinHeight) { | 595 BrowserPluginPropertyBindingImpl(browser_plugin, |
610 } | 596 browser_plugin::kAttributeMinHeight) { |
611 virtual bool GetProperty(BrowserPluginBindings* bindings, | 597 } |
612 NPVariant* result) OVERRIDE { | 598 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
613 int min_height = bindings->instance()->GetMinHeightAttribute(); | 599 INT32_TO_NPVARIANT(browser_plugin()->GetMinHeightAttribute(), *result); |
614 INT32_TO_NPVARIANT(min_height, *result); | 600 return true; |
615 return true; | 601 } |
616 } | 602 virtual bool SetProperty(NPObject* np_obj, |
617 virtual bool SetProperty(BrowserPluginBindings* bindings, | 603 const NPVariant* variant) OVERRIDE { |
618 NPObject* np_obj, | 604 int new_value = IntFromNPVariant(variant); |
619 const NPVariant* variant) OVERRIDE { | 605 if (browser_plugin()->GetMinHeightAttribute() != new_value) { |
620 int new_value = IntFromNPVariant(variant); | 606 UpdateDOMAttribute(base::IntToString(new_value)); |
621 if (bindings->instance()->GetMinHeightAttribute() != new_value) { | 607 browser_plugin()->ParseSizeContraintsChanged(); |
622 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 608 } |
623 bindings->instance()->ParseSizeContraintsChanged(); | 609 return true; |
624 } | 610 } |
625 return true; | 611 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
626 } | 612 browser_plugin()->RemoveDOMAttribute(GetName()); |
627 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 613 browser_plugin()->ParseSizeContraintsChanged(); |
628 NPObject* np_obj) OVERRIDE { | |
629 bindings->instance()->RemoveDOMAttribute(name()); | |
630 bindings->instance()->ParseSizeContraintsChanged(); | |
631 } | 614 } |
632 private: | 615 private: |
633 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | 616 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); |
634 }; | 617 }; |
635 | 618 |
636 class BrowserPluginPropertyBindingMinWidth | 619 class BrowserPluginPropertyBindingMinWidth |
637 : public BrowserPluginPropertyBinding { | 620 : public BrowserPluginPropertyBindingImpl { |
638 public: | 621 public: |
639 BrowserPluginPropertyBindingMinWidth() | 622 BrowserPluginPropertyBindingMinWidth(BrowserPluginImpl* browser_plugin) : |
640 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinWidth) { | 623 BrowserPluginPropertyBindingImpl(browser_plugin, |
641 } | 624 browser_plugin::kAttributeMinWidth) { |
642 virtual bool GetProperty(BrowserPluginBindings* bindings, | 625 } |
643 NPVariant* result) OVERRIDE { | 626 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
644 int min_width = bindings->instance()->GetMinWidthAttribute(); | 627 INT32_TO_NPVARIANT(browser_plugin()->GetMinWidthAttribute(), *result); |
645 INT32_TO_NPVARIANT(min_width, *result); | 628 return true; |
646 return true; | 629 } |
647 } | 630 virtual bool SetProperty(NPObject* np_obj, |
648 virtual bool SetProperty(BrowserPluginBindings* bindings, | 631 const NPVariant* variant) OVERRIDE { |
649 NPObject* np_obj, | 632 int new_value = IntFromNPVariant(variant); |
650 const NPVariant* variant) OVERRIDE { | 633 if (browser_plugin()->GetMinWidthAttribute() != new_value) { |
651 int new_value = IntFromNPVariant(variant); | 634 UpdateDOMAttribute(base::IntToString(new_value)); |
652 if (bindings->instance()->GetMinWidthAttribute() != new_value) { | 635 browser_plugin()->ParseSizeContraintsChanged(); |
653 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 636 } |
654 bindings->instance()->ParseSizeContraintsChanged(); | 637 return true; |
655 } | 638 } |
656 return true; | 639 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
657 } | 640 browser_plugin()->RemoveDOMAttribute(GetName()); |
658 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 641 browser_plugin()->ParseSizeContraintsChanged(); |
659 NPObject* np_obj) OVERRIDE { | |
660 bindings->instance()->RemoveDOMAttribute(name()); | |
661 bindings->instance()->ParseSizeContraintsChanged(); | |
662 } | 642 } |
663 private: | 643 private: |
664 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 644 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
665 }; | 645 }; |
666 | 646 |
667 class BrowserPluginPropertyBindingName | 647 class BrowserPluginPropertyBindingName |
668 : public BrowserPluginPropertyBinding { | 648 : public BrowserPluginPropertyBindingImpl { |
669 public: | 649 public: |
670 BrowserPluginPropertyBindingName() | 650 BrowserPluginPropertyBindingName(BrowserPluginImpl* browser_plugin) : |
671 : BrowserPluginPropertyBinding(browser_plugin::kAttributeName) { | 651 BrowserPluginPropertyBindingImpl(browser_plugin, |
672 } | 652 browser_plugin::kAttributeName) { |
673 virtual bool GetProperty(BrowserPluginBindings* bindings, | 653 } |
674 NPVariant* result) OVERRIDE { | 654 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
675 std::string name = bindings->instance()->GetNameAttribute(); | 655 StringToNPVariant(browser_plugin()->GetNameAttribute(), result); |
676 return StringToNPVariant(name, result); | 656 return true; |
677 return true; | 657 } |
678 } | 658 virtual bool SetProperty(NPObject* np_obj, |
679 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
680 NPObject* np_obj, | |
681 const NPVariant* variant) OVERRIDE { | 659 const NPVariant* variant) OVERRIDE { |
682 std::string new_value = StringFromNPVariant(*variant); | 660 std::string new_value = StringFromNPVariant(*variant); |
683 if (bindings->instance()->GetNameAttribute() != new_value) { | 661 if (browser_plugin()->GetNameAttribute() != new_value) { |
684 UpdateDOMAttribute(bindings, new_value); | 662 UpdateDOMAttribute(new_value); |
685 bindings->instance()->ParseNameAttribute(); | 663 browser_plugin()->ParseNameAttribute(); |
686 } | 664 } |
687 return true; | 665 return true; |
688 } | 666 } |
689 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 667 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
690 NPObject* np_obj) OVERRIDE { | 668 browser_plugin()->RemoveDOMAttribute(GetName()); |
691 bindings->instance()->RemoveDOMAttribute(name()); | 669 browser_plugin()->ParseNameAttribute(); |
692 bindings->instance()->ParseNameAttribute(); | |
693 } | 670 } |
694 private: | 671 private: |
695 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); | 672 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); |
696 }; | 673 }; |
697 | 674 |
698 class BrowserPluginPropertyBindingPartition | 675 class BrowserPluginPropertyBindingPartition |
699 : public BrowserPluginPropertyBinding { | 676 : public BrowserPluginPropertyBindingImpl { |
700 public: | 677 public: |
701 BrowserPluginPropertyBindingPartition() | 678 BrowserPluginPropertyBindingPartition(BrowserPluginImpl* browser_plugin) : |
702 : BrowserPluginPropertyBinding(browser_plugin::kAttributePartition) { | 679 BrowserPluginPropertyBindingImpl(browser_plugin, |
703 } | 680 browser_plugin::kAttributePartition) { |
704 virtual bool GetProperty(BrowserPluginBindings* bindings, | 681 } |
705 NPVariant* result) OVERRIDE { | 682 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
706 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 683 return StringToNPVariant(browser_plugin()->GetPartitionAttribute(), result); |
707 return StringToNPVariant(partition_id, result); | 684 } |
708 } | 685 virtual bool SetProperty(NPObject* np_obj, |
709 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
710 NPObject* np_obj, | |
711 const NPVariant* variant) OVERRIDE { | 686 const NPVariant* variant) OVERRIDE { |
712 std::string new_value = StringFromNPVariant(*variant); | 687 std::string new_value = StringFromNPVariant(*variant); |
713 std::string old_value = bindings->instance()->GetPartitionAttribute(); | 688 std::string old_value = browser_plugin()->GetPartitionAttribute(); |
714 if (old_value != new_value) { | 689 if (old_value != new_value) { |
715 UpdateDOMAttribute(bindings, new_value); | 690 UpdateDOMAttribute(new_value); |
716 std::string error_message; | 691 std::string error_message; |
717 if (!bindings->instance()->ParsePartitionAttribute(&error_message)) { | 692 if (!browser_plugin()->ParsePartitionAttribute(&error_message)) { |
718 WebBindings::setException( | 693 WebBindings::setException( |
719 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 694 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
720 // Reset to old value on error. | 695 // Reset to old value on error. |
721 UpdateDOMAttribute(bindings, old_value); | 696 UpdateDOMAttribute(old_value); |
722 return false; | 697 return false; |
723 } | 698 } |
724 } | 699 } |
725 return true; | 700 return true; |
726 } | 701 } |
727 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 702 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
728 NPObject* np_obj) OVERRIDE { | |
729 std::string error_message; | 703 std::string error_message; |
730 if (bindings->instance()->CanRemovePartitionAttribute(&error_message)) { | 704 if (browser_plugin()->CanRemovePartitionAttribute(&error_message)) { |
731 bindings->instance()->RemoveDOMAttribute(name()); | 705 browser_plugin()->RemoveDOMAttribute(GetName()); |
732 } else { | 706 } else { |
733 WebBindings::setException( | 707 WebBindings::setException( |
734 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 708 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
735 } | 709 } |
736 } | 710 } |
737 private: | 711 private: |
738 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); | 712 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); |
739 }; | 713 }; |
740 | 714 |
741 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { | 715 class BrowserPluginPropertyBindingSrc : |
| 716 public BrowserPluginPropertyBindingImpl { |
742 public: | 717 public: |
743 BrowserPluginPropertyBindingSrc() | 718 BrowserPluginPropertyBindingSrc(BrowserPluginImpl* browser_plugin) : |
744 : BrowserPluginPropertyBinding(browser_plugin::kAttributeSrc) { | 719 BrowserPluginPropertyBindingImpl(browser_plugin, |
| 720 browser_plugin::kAttributeSrc) { |
745 } | 721 } |
746 virtual bool GetProperty(BrowserPluginBindings* bindings, | 722 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
747 NPVariant* result) OVERRIDE { | 723 return StringToNPVariant(browser_plugin()->GetSrcAttribute(), result); |
748 std::string src = bindings->instance()->GetSrcAttribute(); | |
749 return StringToNPVariant(src, result); | |
750 } | 724 } |
751 virtual bool SetProperty(BrowserPluginBindings* bindings, | 725 virtual bool SetProperty(NPObject* np_obj, |
752 NPObject* np_obj, | |
753 const NPVariant* variant) OVERRIDE { | 726 const NPVariant* variant) OVERRIDE { |
754 std::string new_value = StringFromNPVariant(*variant); | 727 std::string new_value = StringFromNPVariant(*variant); |
755 // We should not be issuing navigation IPCs if we attempt to set the | 728 // We should not be issuing navigation IPCs if we attempt to set the |
756 // src property to the empty string. Instead, we want to simply restore | 729 // src property to the empty string. Instead, we want to simply restore |
757 // the src attribute back to its old value. | 730 // the src attribute back to its old value. |
758 if (new_value.empty()) { | 731 if (new_value.empty()) { |
759 RemoveProperty(bindings, np_obj); | 732 RemoveProperty(np_obj); |
760 return true; | 733 return true; |
761 } | 734 } |
762 std::string old_value = bindings->instance()->GetSrcAttribute(); | 735 std::string old_value = browser_plugin()->GetSrcAttribute(); |
763 bool guest_crashed = bindings->instance()->guest_crashed(); | 736 bool guest_crashed = browser_plugin()->guest_crashed(); |
764 if ((old_value != new_value) || guest_crashed) { | 737 if ((old_value != new_value) || guest_crashed) { |
765 // If the new value was empty then we're effectively resetting the | 738 // If the new value was empty then we're effectively resetting the |
766 // attribute to the old value here. This will be picked up by <webview>'s | 739 // attribute to the old value here. This will be picked up by <webview>'s |
767 // mutation observer and will restore the src attribute after it has been | 740 // mutation observer and will restore the src attribute after it has been |
768 // removed. | 741 // removed. |
769 UpdateDOMAttribute(bindings, new_value); | 742 UpdateDOMAttribute(new_value); |
770 std::string error_message; | 743 std::string error_message; |
771 if (!bindings->instance()->ParseSrcAttribute(&error_message)) { | 744 if (!browser_plugin()->ParseSrcAttribute(&error_message)) { |
772 WebBindings::setException( | 745 WebBindings::setException( |
773 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 746 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
774 // Reset to old value on error. | 747 // Reset to old value on error. |
775 UpdateDOMAttribute(bindings, old_value); | 748 UpdateDOMAttribute(old_value); |
776 return false; | 749 return false; |
777 } | 750 } |
778 } | 751 } |
779 return true; | 752 return true; |
780 } | 753 } |
781 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 754 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
782 NPObject* np_obj) OVERRIDE { | 755 std::string old_value = browser_plugin()->GetSrcAttribute(); |
783 std::string old_value = bindings->instance()->GetSrcAttribute(); | |
784 // Remove the DOM attribute to trigger the mutation observer when it is | 756 // Remove the DOM attribute to trigger the mutation observer when it is |
785 // restored to its original value again. | 757 // restored to its original value again. |
786 bindings->instance()->RemoveDOMAttribute(name()); | 758 browser_plugin()->RemoveDOMAttribute(GetName()); |
787 UpdateDOMAttribute(bindings, old_value); | 759 UpdateDOMAttribute(old_value); |
788 } | 760 } |
789 private: | 761 private: |
790 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); | 762 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); |
791 }; | 763 }; |
792 | 764 |
793 | 765 |
794 // BrowserPluginBindings ------------------------------------------------------ | 766 // BrowserPluginBindings ------------------------------------------------------ |
795 | 767 |
796 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 768 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
797 } | 769 } |
798 | 770 |
799 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 771 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
800 } | 772 } |
801 | 773 |
802 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 774 BrowserPluginBindings::BrowserPluginBindings(BrowserPluginImpl* instance) |
803 : instance_(instance), | 775 : instance_(instance), |
804 np_object_(NULL), | 776 np_object_(NULL), |
805 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 777 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
806 NPObject* obj = | 778 NPObject* obj = |
807 WebBindings::createObject(NULL, &browser_plugin_message_class); | 779 WebBindings::createObject(NULL, &browser_plugin_message_class); |
808 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 780 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
809 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 781 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
810 | 782 |
811 method_bindings_.push_back(new BrowserPluginBindingBack); | 783 method_bindings_.push_back(new BrowserPluginBindingBack(instance)); |
812 method_bindings_.push_back(new BrowserPluginBindingCanGoBack); | 784 method_bindings_.push_back(new BrowserPluginBindingCanGoBack(instance)); |
813 method_bindings_.push_back(new BrowserPluginBindingCanGoForward); | 785 method_bindings_.push_back(new BrowserPluginBindingCanGoForward(instance)); |
814 method_bindings_.push_back(new BrowserPluginBindingForward); | 786 method_bindings_.push_back(new BrowserPluginBindingForward(instance)); |
815 method_bindings_.push_back(new BrowserPluginBindingGetProcessID); | 787 method_bindings_.push_back(new BrowserPluginBindingGetProcessID(instance)); |
816 method_bindings_.push_back(new BrowserPluginBindingGetRouteID); | 788 method_bindings_.push_back(new BrowserPluginBindingGetRouteID(instance)); |
817 method_bindings_.push_back(new BrowserPluginBindingGo); | 789 method_bindings_.push_back(new BrowserPluginBindingGo(instance)); |
818 method_bindings_.push_back(new BrowserPluginBindingPersistRequestObject); | 790 method_bindings_.push_back( |
819 method_bindings_.push_back(new BrowserPluginBindingReload); | 791 new BrowserPluginBindingPersistRequestObject(instance)); |
820 method_bindings_.push_back(new BrowserPluginBindingSetPermission); | 792 method_bindings_.push_back(new BrowserPluginBindingReload(instance)); |
821 method_bindings_.push_back(new BrowserPluginBindingStop); | 793 method_bindings_.push_back(new BrowserPluginBindingSetPermission(instance)); |
822 method_bindings_.push_back(new BrowserPluginBindingTerminate); | 794 method_bindings_.push_back(new BrowserPluginBindingStop(instance)); |
| 795 method_bindings_.push_back(new BrowserPluginBindingTerminate(instance)); |
823 | 796 |
824 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); | 797 property_bindings_.push_back( |
825 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 798 new BrowserPluginPropertyBindingAutoSize(instance)); |
826 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); | 799 property_bindings_.push_back( |
827 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); | 800 new BrowserPluginPropertyBindingContentWindow(instance)); |
828 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); | 801 property_bindings_.push_back( |
829 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); | 802 new BrowserPluginPropertyBindingMaxHeight(instance)); |
830 property_bindings_.push_back(new BrowserPluginPropertyBindingName); | 803 property_bindings_.push_back( |
831 property_bindings_.push_back(new BrowserPluginPropertyBindingPartition); | 804 new BrowserPluginPropertyBindingMaxWidth(instance)); |
832 property_bindings_.push_back(new BrowserPluginPropertyBindingSrc); | 805 property_bindings_.push_back( |
| 806 new BrowserPluginPropertyBindingMinHeight(instance)); |
| 807 property_bindings_.push_back( |
| 808 new BrowserPluginPropertyBindingMinWidth(instance)); |
| 809 property_bindings_.push_back( |
| 810 new BrowserPluginPropertyBindingName(instance)); |
| 811 property_bindings_.push_back( |
| 812 new BrowserPluginPropertyBindingPartition(instance)); |
| 813 property_bindings_.push_back( |
| 814 new BrowserPluginPropertyBindingSrc(instance)); |
833 } | 815 } |
834 | 816 |
835 BrowserPluginBindings::~BrowserPluginBindings() { | 817 BrowserPluginBindings::~BrowserPluginBindings() { |
836 WebBindings::releaseObject(np_object_); | 818 WebBindings::releaseObject(np_object_); |
837 } | 819 } |
838 | 820 |
839 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { | 821 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
840 for (BindingList::const_iterator iter = method_bindings_.begin(); | 822 for (BindingList::const_iterator iter = method_bindings_.begin(); |
841 iter != method_bindings_.end(); | 823 iter != method_bindings_.end(); |
842 ++iter) { | 824 ++iter) { |
843 if ((*iter)->MatchesName(name)) | 825 BrowserPluginMethodBinding* method = *iter; |
| 826 if (MatchesName(method->GetName(), name)) |
844 return true; | 827 return true; |
845 } | 828 } |
846 return false; | 829 return false; |
847 } | 830 } |
848 | 831 |
849 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, | 832 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, |
850 const NPVariant* args, | 833 const NPVariant* args, |
851 uint32 arg_count, | 834 uint32 arg_count, |
852 NPVariant* result) { | 835 NPVariant* result) { |
853 for (BindingList::iterator iter = method_bindings_.begin(); | 836 for (BindingList::iterator iter = method_bindings_.begin(); |
854 iter != method_bindings_.end(); | 837 iter != method_bindings_.end(); |
855 ++iter) { | 838 ++iter) { |
856 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) | 839 BrowserPluginMethodBinding* method = *iter; |
857 return (*iter)->Invoke(this, args, result); | 840 if (MatchesName(method->GetName(), name) && |
| 841 method->GetArgCount() == arg_count) |
| 842 return method->Invoke(args, result); |
858 } | 843 } |
859 return false; | 844 return false; |
860 } | 845 } |
861 | 846 |
862 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { | 847 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { |
863 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); | 848 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); |
864 iter != property_bindings_.end(); | 849 iter != property_bindings_.end(); |
865 ++iter) { | 850 ++iter) { |
866 if ((*iter)->MatchesName(name)) | 851 BrowserPluginPropertyBinding* property = *iter; |
| 852 if (MatchesName(property->GetName(), name)) |
867 return true; | 853 return true; |
868 } | 854 } |
869 return false; | 855 return false; |
870 } | 856 } |
871 | 857 |
872 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, | 858 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, |
873 NPIdentifier name, | 859 NPIdentifier name, |
874 const NPVariant* variant) { | 860 const NPVariant* variant) { |
875 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 861 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
876 iter != property_bindings_.end(); | 862 iter != property_bindings_.end(); |
877 ++iter) { | 863 ++iter) { |
878 if ((*iter)->MatchesName(name)) { | 864 BrowserPluginPropertyBinding* property = *iter; |
879 if ((*iter)->SetProperty(this, np_obj, variant)) { | 865 if (MatchesName(property->GetName(), name)) { |
| 866 if (property->SetProperty(np_obj, variant)) |
880 return true; | 867 return true; |
881 } | |
882 break; | 868 break; |
883 } | 869 } |
884 } | 870 } |
885 return false; | 871 return false; |
886 } | 872 } |
887 | 873 |
888 bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj, | 874 bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj, |
889 NPIdentifier name) { | 875 NPIdentifier name) { |
890 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 876 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
891 iter != property_bindings_.end(); | 877 iter != property_bindings_.end(); |
892 ++iter) { | 878 ++iter) { |
893 if ((*iter)->MatchesName(name)) { | 879 BrowserPluginPropertyBinding* property = *iter; |
894 (*iter)->RemoveProperty(this, np_obj); | 880 if (MatchesName(property->GetName(), name)) { |
| 881 property->RemoveProperty(np_obj); |
895 return true; | 882 return true; |
896 } | 883 } |
897 } | 884 } |
898 return false; | 885 return false; |
899 } | 886 } |
900 | 887 |
901 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { | 888 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { |
902 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 889 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
903 iter != property_bindings_.end(); | 890 iter != property_bindings_.end(); |
904 ++iter) { | 891 ++iter) { |
905 if ((*iter)->MatchesName(name)) | 892 BrowserPluginPropertyBinding* property = *iter; |
906 return (*iter)->GetProperty(this, result); | 893 if (MatchesName(property->GetName(), name)) |
| 894 return property->GetProperty(result); |
907 } | 895 } |
908 return false; | 896 return false; |
909 } | 897 } |
910 | 898 |
| 899 void BrowserPluginBindings::AddMethodBinding( |
| 900 BrowserPluginMethodBinding* method_binding) { |
| 901 method_bindings_.push_back(method_binding); |
| 902 } |
| 903 |
| 904 void BrowserPluginBindings::AddPropertyBinding( |
| 905 BrowserPluginPropertyBinding* property_binding) { |
| 906 property_bindings_.push_back(property_binding); |
| 907 } |
| 908 |
911 } // namespace content | 909 } // namespace content |
OLD | NEW |