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 |
323 class BrowserPluginPropertyBindingContentWindow | 356 class BrowserPluginPropertyBindingContentWindow |
324 : public BrowserPluginPropertyBinding { | 357 : public BrowserPluginPropertyBinding { |
325 public: | 358 public: |
326 BrowserPluginPropertyBindingContentWindow() | 359 BrowserPluginPropertyBindingContentWindow() |
327 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { | 360 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { |
328 } | 361 } |
329 virtual bool GetProperty(BrowserPluginBindings* bindings, | 362 virtual bool GetProperty(BrowserPluginBindings* bindings, |
330 NPVariant* result) OVERRIDE { | 363 NPVariant* result) OVERRIDE { |
331 NPObject* obj = bindings->instance()->GetContentWindow(); | 364 NPObject* obj = bindings->instance()->GetContentWindow(); |
332 if (obj) { | 365 if (obj) { |
333 result->type = NPVariantType_Object; | 366 result->type = NPVariantType_Object; |
334 result->value.objectValue = WebBindings::retainObject(obj); | 367 result->value.objectValue = WebBindings::retainObject(obj); |
335 } | 368 } |
336 return true; | 369 return true; |
337 } | 370 } |
338 virtual bool SetProperty(BrowserPluginBindings* bindings, | 371 virtual bool SetProperty(BrowserPluginBindings* bindings, |
339 NPObject* np_obj, | 372 NPObject* np_obj, |
340 const NPVariant* variant) OVERRIDE { | 373 const NPVariant* variant) OVERRIDE { |
341 return false; | 374 return false; |
342 } | 375 } |
343 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 376 virtual void RemoveProperty(BrowserPluginBindings* bindings, |
344 NPObject* np_obj) OVERRIDE {} | 377 NPObject* np_obj) OVERRIDE {} |
345 private: | 378 private: |
346 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 379 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
347 }; | 380 }; |
348 | 381 |
| 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 |
349 | 506 |
350 // BrowserPluginBindings ------------------------------------------------------ | 507 // BrowserPluginBindings ------------------------------------------------------ |
351 | 508 |
352 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 509 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
353 } | 510 } |
354 | 511 |
355 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 512 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
356 } | 513 } |
357 | 514 |
358 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 515 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) |
359 : instance_(instance), | 516 : instance_(instance), |
360 np_object_(NULL), | 517 np_object_(NULL), |
361 weak_ptr_factory_(this) { | 518 weak_ptr_factory_(this) { |
362 NPObject* obj = | 519 NPObject* obj = |
363 WebBindings::createObject(instance->pluginNPP(), | 520 WebBindings::createObject(instance->pluginNPP(), |
364 &browser_plugin_message_class); | 521 &browser_plugin_message_class); |
365 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 522 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
366 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 523 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
367 | 524 |
368 method_bindings_.push_back(new BrowserPluginBindingAttach); | 525 method_bindings_.push_back(new BrowserPluginBindingAttach); |
369 | 526 |
370 property_bindings_.push_back( | 527 property_bindings_.push_back( |
371 new BrowserPluginPropertyBindingAllowTransparency); | 528 new BrowserPluginPropertyBindingAllowTransparency); |
| 529 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); |
372 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 530 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); |
373 } | 535 } |
374 | 536 |
375 BrowserPluginBindings::~BrowserPluginBindings() { | 537 BrowserPluginBindings::~BrowserPluginBindings() { |
376 WebBindings::releaseObject(np_object_); | 538 WebBindings::releaseObject(np_object_); |
377 } | 539 } |
378 | 540 |
379 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { | 541 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
380 for (BindingList::const_iterator iter = method_bindings_.begin(); | 542 for (BindingList::const_iterator iter = method_bindings_.begin(); |
381 iter != method_bindings_.end(); | 543 iter != method_bindings_.end(); |
382 ++iter) { | 544 ++iter) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 604 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
443 iter != property_bindings_.end(); | 605 iter != property_bindings_.end(); |
444 ++iter) { | 606 ++iter) { |
445 if ((*iter)->MatchesName(name)) | 607 if ((*iter)->MatchesName(name)) |
446 return (*iter)->GetProperty(this, result); | 608 return (*iter)->GetProperty(this, result); |
447 } | 609 } |
448 return false; | 610 return false; |
449 } | 611 } |
450 | 612 |
451 } // namespace content | 613 } // namespace content |
OLD | NEW |