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" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 313 } |
314 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 314 virtual void RemoveProperty(BrowserPluginBindings* bindings, |
315 NPObject* np_obj) OVERRIDE { | 315 NPObject* np_obj) OVERRIDE { |
316 bindings->instance()->RemoveDOMAttribute(name()); | 316 bindings->instance()->RemoveDOMAttribute(name()); |
317 bindings->instance()->ParseAllowTransparencyAttribute(); | 317 bindings->instance()->ParseAllowTransparencyAttribute(); |
318 } | 318 } |
319 private: | 319 private: |
320 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAllowTransparency); | 320 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAllowTransparency); |
321 }; | 321 }; |
322 | 322 |
323 class BrowserPluginPropertyBindingAutoSize | |
324 : public BrowserPluginPropertyBinding { | |
325 public: | |
326 BrowserPluginPropertyBindingAutoSize() | |
327 : BrowserPluginPropertyBinding(browser_plugin::kAttributeAutoSize) { | |
328 } | |
329 virtual bool GetProperty(BrowserPluginBindings* bindings, | |
330 NPVariant* result) OVERRIDE { | |
331 bool auto_size = bindings->instance()->GetAutoSizeAttribute(); | |
332 BOOLEAN_TO_NPVARIANT(auto_size, *result); | |
333 return true; | |
334 } | |
335 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
336 NPObject* np_obj, | |
337 const NPVariant* variant) OVERRIDE { | |
338 std::string value = StringFromNPVariant(*variant); | |
339 if (!bindings->instance()->HasDOMAttribute(name())) { | |
340 UpdateDOMAttribute(bindings, value); | |
341 bindings->instance()->ParseAutoSizeAttribute(); | |
342 } else { | |
343 UpdateDOMAttribute(bindings, value); | |
344 } | |
345 return true; | |
346 } | |
347 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
348 NPObject* np_obj) OVERRIDE { | |
349 bindings->instance()->RemoveDOMAttribute(name()); | |
350 bindings->instance()->ParseAutoSizeAttribute(); | |
351 } | |
352 private: | |
353 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | |
354 }; | |
355 | |
356 class BrowserPluginPropertyBindingContentWindow | 323 class BrowserPluginPropertyBindingContentWindow |
357 : public BrowserPluginPropertyBinding { | 324 : public BrowserPluginPropertyBinding { |
358 public: | 325 public: |
359 BrowserPluginPropertyBindingContentWindow() | 326 BrowserPluginPropertyBindingContentWindow() |
360 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { | 327 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { |
361 } | 328 } |
362 virtual bool GetProperty(BrowserPluginBindings* bindings, | 329 virtual bool GetProperty(BrowserPluginBindings* bindings, |
363 NPVariant* result) OVERRIDE { | 330 NPVariant* result) OVERRIDE { |
364 NPObject* obj = bindings->instance()->GetContentWindow(); | 331 NPObject* obj = bindings->instance()->GetContentWindow(); |
365 if (obj) { | 332 if (obj) { |
366 result->type = NPVariantType_Object; | 333 result->type = NPVariantType_Object; |
367 result->value.objectValue = WebBindings::retainObject(obj); | 334 result->value.objectValue = WebBindings::retainObject(obj); |
368 } | 335 } |
369 return true; | 336 return true; |
370 } | 337 } |
371 virtual bool SetProperty(BrowserPluginBindings* bindings, | 338 virtual bool SetProperty(BrowserPluginBindings* bindings, |
372 NPObject* np_obj, | 339 NPObject* np_obj, |
373 const NPVariant* variant) OVERRIDE { | 340 const NPVariant* variant) OVERRIDE { |
374 return false; | 341 return false; |
375 } | 342 } |
376 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 343 virtual void RemoveProperty(BrowserPluginBindings* bindings, |
377 NPObject* np_obj) OVERRIDE {} | 344 NPObject* np_obj) OVERRIDE {} |
378 private: | 345 private: |
379 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 346 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
380 }; | 347 }; |
381 | 348 |
382 class BrowserPluginPropertyBindingMaxHeight | |
383 : public BrowserPluginPropertyBinding { | |
384 public: | |
385 BrowserPluginPropertyBindingMaxHeight() | |
386 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxHeight) { | |
387 } | |
388 virtual bool GetProperty(BrowserPluginBindings* bindings, | |
389 NPVariant* result) OVERRIDE { | |
390 int max_height = bindings->instance()->GetMaxHeightAttribute(); | |
391 INT32_TO_NPVARIANT(max_height, *result); | |
392 return true; | |
393 } | |
394 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
395 NPObject* np_obj, | |
396 const NPVariant* variant) OVERRIDE { | |
397 int new_value = IntFromNPVariant(*variant); | |
398 if (bindings->instance()->GetMaxHeightAttribute() != new_value) { | |
399 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | |
400 bindings->instance()->ParseSizeContraintsChanged(); | |
401 } | |
402 return true; | |
403 } | |
404 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
405 NPObject* np_obj) OVERRIDE { | |
406 bindings->instance()->RemoveDOMAttribute(name()); | |
407 bindings->instance()->ParseSizeContraintsChanged(); | |
408 } | |
409 private: | |
410 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | |
411 }; | |
412 | |
413 class BrowserPluginPropertyBindingMaxWidth | |
414 : public BrowserPluginPropertyBinding { | |
415 public: | |
416 BrowserPluginPropertyBindingMaxWidth() | |
417 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxWidth) { | |
418 } | |
419 virtual bool GetProperty(BrowserPluginBindings* bindings, | |
420 NPVariant* result) OVERRIDE { | |
421 int max_width = bindings->instance()->GetMaxWidthAttribute(); | |
422 INT32_TO_NPVARIANT(max_width, *result); | |
423 return true; | |
424 } | |
425 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
426 NPObject* np_obj, | |
427 const NPVariant* variant) OVERRIDE { | |
428 int new_value = IntFromNPVariant(*variant); | |
429 if (bindings->instance()->GetMaxWidthAttribute() != new_value) { | |
430 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | |
431 bindings->instance()->ParseSizeContraintsChanged(); | |
432 } | |
433 return true; | |
434 } | |
435 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
436 NPObject* np_obj) OVERRIDE { | |
437 bindings->instance()->RemoveDOMAttribute(name()); | |
438 bindings->instance()->ParseSizeContraintsChanged(); | |
439 } | |
440 private: | |
441 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | |
442 }; | |
443 | |
444 class BrowserPluginPropertyBindingMinHeight | |
445 : public BrowserPluginPropertyBinding { | |
446 public: | |
447 BrowserPluginPropertyBindingMinHeight() | |
448 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinHeight) { | |
449 } | |
450 virtual bool GetProperty(BrowserPluginBindings* bindings, | |
451 NPVariant* result) OVERRIDE { | |
452 int min_height = bindings->instance()->GetMinHeightAttribute(); | |
453 INT32_TO_NPVARIANT(min_height, *result); | |
454 return true; | |
455 } | |
456 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
457 NPObject* np_obj, | |
458 const NPVariant* variant) OVERRIDE { | |
459 int new_value = IntFromNPVariant(*variant); | |
460 if (bindings->instance()->GetMinHeightAttribute() != new_value) { | |
461 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | |
462 bindings->instance()->ParseSizeContraintsChanged(); | |
463 } | |
464 return true; | |
465 } | |
466 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
467 NPObject* np_obj) OVERRIDE { | |
468 bindings->instance()->RemoveDOMAttribute(name()); | |
469 bindings->instance()->ParseSizeContraintsChanged(); | |
470 } | |
471 private: | |
472 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | |
473 }; | |
474 | |
475 class BrowserPluginPropertyBindingMinWidth | |
476 : public BrowserPluginPropertyBinding { | |
477 public: | |
478 BrowserPluginPropertyBindingMinWidth() | |
479 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinWidth) { | |
480 } | |
481 virtual bool GetProperty(BrowserPluginBindings* bindings, | |
482 NPVariant* result) OVERRIDE { | |
483 int min_width = bindings->instance()->GetMinWidthAttribute(); | |
484 INT32_TO_NPVARIANT(min_width, *result); | |
485 return true; | |
486 } | |
487 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
488 NPObject* np_obj, | |
489 const NPVariant* variant) OVERRIDE { | |
490 int new_value = IntFromNPVariant(*variant); | |
491 if (bindings->instance()->GetMinWidthAttribute() != new_value) { | |
492 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | |
493 bindings->instance()->ParseSizeContraintsChanged(); | |
494 } | |
495 return true; | |
496 } | |
497 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
498 NPObject* np_obj) OVERRIDE { | |
499 bindings->instance()->RemoveDOMAttribute(name()); | |
500 bindings->instance()->ParseSizeContraintsChanged(); | |
501 } | |
502 private: | |
503 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | |
504 }; | |
505 | |
506 | 349 |
507 // BrowserPluginBindings ------------------------------------------------------ | 350 // BrowserPluginBindings ------------------------------------------------------ |
508 | 351 |
509 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 352 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
510 } | 353 } |
511 | 354 |
512 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 355 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
513 } | 356 } |
514 | 357 |
515 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 358 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) |
516 : instance_(instance), | 359 : instance_(instance), |
517 np_object_(NULL), | 360 np_object_(NULL), |
518 weak_ptr_factory_(this) { | 361 weak_ptr_factory_(this) { |
519 NPObject* obj = | 362 NPObject* obj = |
520 WebBindings::createObject(instance->pluginNPP(), | 363 WebBindings::createObject(instance->pluginNPP(), |
521 &browser_plugin_message_class); | 364 &browser_plugin_message_class); |
522 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 365 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
523 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 366 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
524 | 367 |
525 method_bindings_.push_back(new BrowserPluginBindingAttach); | 368 method_bindings_.push_back(new BrowserPluginBindingAttach); |
526 | 369 |
527 property_bindings_.push_back( | 370 property_bindings_.push_back( |
528 new BrowserPluginPropertyBindingAllowTransparency); | 371 new BrowserPluginPropertyBindingAllowTransparency); |
529 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); | |
530 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 372 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); |
531 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); | |
532 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); | |
533 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); | |
534 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); | |
535 } | 373 } |
536 | 374 |
537 BrowserPluginBindings::~BrowserPluginBindings() { | 375 BrowserPluginBindings::~BrowserPluginBindings() { |
538 WebBindings::releaseObject(np_object_); | 376 WebBindings::releaseObject(np_object_); |
539 } | 377 } |
540 | 378 |
541 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { | 379 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
542 for (BindingList::const_iterator iter = method_bindings_.begin(); | 380 for (BindingList::const_iterator iter = method_bindings_.begin(); |
543 iter != method_bindings_.end(); | 381 iter != method_bindings_.end(); |
544 ++iter) { | 382 ++iter) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 442 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
605 iter != property_bindings_.end(); | 443 iter != property_bindings_.end(); |
606 ++iter) { | 444 ++iter) { |
607 if ((*iter)->MatchesName(name)) | 445 if ((*iter)->MatchesName(name)) |
608 return (*iter)->GetProperty(this, result); | 446 return (*iter)->GetProperty(this, result); |
609 } | 447 } |
610 return false; | 448 return false; |
611 } | 449 } |
612 | 450 |
613 } // namespace content | 451 } // namespace content |
OLD | NEW |