Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_bindings.cc

Issue 11418261: Browser Plugin: Update DOM Node attributes when properties are updated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed spacing Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_split.h" 14 #include "base/string_split.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "content/renderer/browser_plugin/browser_plugin.h" 16 #include "content/renderer/browser_plugin/browser_plugin.h"
16 #include "third_party/npapi/bindings/npapi.h" 17 #include "third_party/npapi/bindings/npapi.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); 386 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate);
386 }; 387 };
387 388
388 // BrowserPluginPropertyBinding ------------------------------------------------ 389 // BrowserPluginPropertyBinding ------------------------------------------------
389 390
390 class BrowserPluginPropertyBinding { 391 class BrowserPluginPropertyBinding {
391 public: 392 public:
392 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { 393 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {
393 } 394 }
394 virtual ~BrowserPluginPropertyBinding() {} 395 virtual ~BrowserPluginPropertyBinding() {}
396 const std::string& name() const { return name_; }
395 bool MatchesName(NPIdentifier name) const { 397 bool MatchesName(NPIdentifier name) const {
396 return WebBindings::getStringIdentifier(name_.c_str()) == name; 398 return WebBindings::getStringIdentifier(name_.c_str()) == name;
397 } 399 }
398 virtual bool GetProperty(BrowserPluginBindings* bindings, 400 virtual bool GetProperty(BrowserPluginBindings* bindings,
399 NPVariant* result) = 0; 401 NPVariant* result) = 0;
400 virtual bool SetProperty(BrowserPluginBindings* bindings, 402 virtual bool SetProperty(BrowserPluginBindings* bindings,
401 NPObject* np_obj, 403 NPObject* np_obj,
402 const NPVariant* variant) = 0; 404 const NPVariant* variant) = 0;
405 virtual std::string GetDOMAttributeValue(BrowserPlugin* browser_plugin) {
406 return std::string();
sadrul 2012/12/04 01:28:46 Like SetProperty/GetProperty, keep this pure here.
Fady Samuel 2012/12/04 01:57:30 Done. I agree, making this pure virtual is better
407 }
408 // Updates the DOM Attribute value with the current property value.
409 void UpdateDOMAttribute(BrowserPluginBindings* bindings) {
410 bindings->instance()->UpdateDOMAttribute(name(),
411 GetDOMAttributeValue(bindings->instance()));
412 }
403 private: 413 private:
404 std::string name_; 414 std::string name_;
405 415
406 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); 416 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding);
407 }; 417 };
408 418
409 class BrowserPluginPropertyBindingAutoSize 419 class BrowserPluginPropertyBindingAutoSize
410 : public BrowserPluginPropertyBinding { 420 : public BrowserPluginPropertyBinding {
411 public: 421 public:
412 BrowserPluginPropertyBindingAutoSize() : 422 BrowserPluginPropertyBindingAutoSize() :
413 BrowserPluginPropertyBinding(kAttributeAutoSize) { 423 BrowserPluginPropertyBinding(kAttributeAutoSize) {
414 } 424 }
415 virtual bool GetProperty(BrowserPluginBindings* bindings, 425 virtual bool GetProperty(BrowserPluginBindings* bindings,
416 NPVariant* result) OVERRIDE { 426 NPVariant* result) OVERRIDE {
417 bool autosize = bindings->instance()->auto_size_attribute(); 427 bool auto_size = bindings->instance()->auto_size_attribute();
418 BOOLEAN_TO_NPVARIANT(autosize, *result); 428 BOOLEAN_TO_NPVARIANT(auto_size, *result);
419 return true; 429 return true;
420 } 430 }
421 virtual bool SetProperty(BrowserPluginBindings* bindings, 431 virtual bool SetProperty(BrowserPluginBindings* bindings,
422 NPObject* np_obj, 432 NPObject* np_obj,
423 const NPVariant* variant) OVERRIDE { 433 const NPVariant* variant) OVERRIDE {
424 bool autosize = NPVARIANT_TO_BOOLEAN(*variant); 434 bool auto_size = NPVARIANT_TO_BOOLEAN(*variant);
425 bindings->instance()->SetAutoSizeAttribute(autosize); 435 bindings->instance()->SetAutoSizeAttribute(auto_size);
426 return true; 436 return true;
427 } 437 }
438 virtual std::string GetDOMAttributeValue(
439 BrowserPlugin* browser_plugin) OVERRIDE {
440 return browser_plugin->auto_size_attribute() ? "true" : "false";
441 }
428 private: 442 private:
429 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); 443 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize);
430 }; 444 };
431 445
432 class BrowserPluginPropertyBindingContentWindow 446 class BrowserPluginPropertyBindingContentWindow
433 : public BrowserPluginPropertyBinding { 447 : public BrowserPluginPropertyBinding {
434 public: 448 public:
435 BrowserPluginPropertyBindingContentWindow() : 449 BrowserPluginPropertyBindingContentWindow() :
436 BrowserPluginPropertyBinding(kAttributeContentWindow) { 450 BrowserPluginPropertyBinding(kAttributeContentWindow) {
437 } 451 }
(...skipping 27 matching lines...) Expand all
465 INT32_TO_NPVARIANT(max_height, *result); 479 INT32_TO_NPVARIANT(max_height, *result);
466 return true; 480 return true;
467 } 481 }
468 virtual bool SetProperty(BrowserPluginBindings* bindings, 482 virtual bool SetProperty(BrowserPluginBindings* bindings,
469 NPObject* np_obj, 483 NPObject* np_obj,
470 const NPVariant* variant) OVERRIDE { 484 const NPVariant* variant) OVERRIDE {
471 int max_height = Int32FromNPVariant(*variant); 485 int max_height = Int32FromNPVariant(*variant);
472 bindings->instance()->SetMaxHeightAttribute(max_height); 486 bindings->instance()->SetMaxHeightAttribute(max_height);
473 return true; 487 return true;
474 } 488 }
489 virtual std::string GetDOMAttributeValue(
490 BrowserPlugin* browser_plugin) OVERRIDE {
491 return base::IntToString(browser_plugin->max_height_attribute());
492 }
475 private: 493 private:
476 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); 494 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight);
477 }; 495 };
478 496
479 class BrowserPluginPropertyBindingMaxWidth 497 class BrowserPluginPropertyBindingMaxWidth
480 : public BrowserPluginPropertyBinding { 498 : public BrowserPluginPropertyBinding {
481 public: 499 public:
482 BrowserPluginPropertyBindingMaxWidth() : 500 BrowserPluginPropertyBindingMaxWidth() :
483 BrowserPluginPropertyBinding(kAttributeMaxWidth) { 501 BrowserPluginPropertyBinding(kAttributeMaxWidth) {
484 } 502 }
485 virtual bool GetProperty(BrowserPluginBindings* bindings, 503 virtual bool GetProperty(BrowserPluginBindings* bindings,
486 NPVariant* result) OVERRIDE { 504 NPVariant* result) OVERRIDE {
487 int max_width = bindings->instance()->max_width_attribute(); 505 int max_width = bindings->instance()->max_width_attribute();
488 INT32_TO_NPVARIANT(max_width, *result); 506 INT32_TO_NPVARIANT(max_width, *result);
489 return true; 507 return true;
490 } 508 }
491 virtual bool SetProperty(BrowserPluginBindings* bindings, 509 virtual bool SetProperty(BrowserPluginBindings* bindings,
492 NPObject* np_obj, 510 NPObject* np_obj,
493 const NPVariant* variant) OVERRIDE { 511 const NPVariant* variant) OVERRIDE {
494 int max_width = Int32FromNPVariant(*variant); 512 int max_width = Int32FromNPVariant(*variant);
495 bindings->instance()->SetMaxWidthAttribute(max_width); 513 bindings->instance()->SetMaxWidthAttribute(max_width);
496 return true; 514 return true;
497 } 515 }
516 virtual std::string GetDOMAttributeValue(
517 BrowserPlugin* browser_plugin) OVERRIDE {
518 return base::IntToString(browser_plugin->max_width_attribute());
519 }
498 private: 520 private:
499 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); 521 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth);
500 }; 522 };
501 523
502 class BrowserPluginPropertyBindingMinHeight 524 class BrowserPluginPropertyBindingMinHeight
503 : public BrowserPluginPropertyBinding { 525 : public BrowserPluginPropertyBinding {
504 public: 526 public:
505 BrowserPluginPropertyBindingMinHeight() : 527 BrowserPluginPropertyBindingMinHeight() :
506 BrowserPluginPropertyBinding(kAttributeMinHeight) { 528 BrowserPluginPropertyBinding(kAttributeMinHeight) {
507 } 529 }
508 virtual bool GetProperty(BrowserPluginBindings* bindings, 530 virtual bool GetProperty(BrowserPluginBindings* bindings,
509 NPVariant* result) OVERRIDE { 531 NPVariant* result) OVERRIDE {
510 int min_height = bindings->instance()->min_height_attribute(); 532 int min_height = bindings->instance()->min_height_attribute();
511 INT32_TO_NPVARIANT(min_height, *result); 533 INT32_TO_NPVARIANT(min_height, *result);
512 return true; 534 return true;
513 } 535 }
514 virtual bool SetProperty(BrowserPluginBindings* bindings, 536 virtual bool SetProperty(BrowserPluginBindings* bindings,
515 NPObject* np_obj, 537 NPObject* np_obj,
516 const NPVariant* variant) OVERRIDE { 538 const NPVariant* variant) OVERRIDE {
517 int min_height = Int32FromNPVariant(*variant); 539 int min_height = Int32FromNPVariant(*variant);
518 bindings->instance()->SetMinHeightAttribute(min_height); 540 bindings->instance()->SetMinHeightAttribute(min_height);
519 return true; 541 return true;
520 } 542 }
543 virtual std::string GetDOMAttributeValue(
544 BrowserPlugin* browser_plugin) OVERRIDE {
545 return base::IntToString(browser_plugin->min_height_attribute());
546 }
521 private: 547 private:
522 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); 548 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight);
523 }; 549 };
524 550
525 class BrowserPluginPropertyBindingMinWidth 551 class BrowserPluginPropertyBindingMinWidth
526 : public BrowserPluginPropertyBinding { 552 : public BrowserPluginPropertyBinding {
527 public: 553 public:
528 BrowserPluginPropertyBindingMinWidth() : 554 BrowserPluginPropertyBindingMinWidth() :
529 BrowserPluginPropertyBinding(kAttributeMinWidth) { 555 BrowserPluginPropertyBinding(kAttributeMinWidth) {
530 } 556 }
531 virtual bool GetProperty(BrowserPluginBindings* bindings, 557 virtual bool GetProperty(BrowserPluginBindings* bindings,
532 NPVariant* result) OVERRIDE { 558 NPVariant* result) OVERRIDE {
533 int min_width = bindings->instance()->min_width_attribute(); 559 int min_width = bindings->instance()->min_width_attribute();
534 INT32_TO_NPVARIANT(min_width, *result); 560 INT32_TO_NPVARIANT(min_width, *result);
535 return true; 561 return true;
536 } 562 }
537 virtual bool SetProperty(BrowserPluginBindings* bindings, 563 virtual bool SetProperty(BrowserPluginBindings* bindings,
538 NPObject* np_obj, 564 NPObject* np_obj,
539 const NPVariant* variant) OVERRIDE { 565 const NPVariant* variant) OVERRIDE {
540 int min_width = Int32FromNPVariant(*variant); 566 int min_width = Int32FromNPVariant(*variant);
541 bindings->instance()->SetMinWidthAttribute(min_width); 567 bindings->instance()->SetMinWidthAttribute(min_width);
542 return true; 568 return true;
543 } 569 }
570 virtual std::string GetDOMAttributeValue(
571 BrowserPlugin* browser_plugin) OVERRIDE {
572 return base::IntToString(browser_plugin->min_width_attribute());
573 }
544 private: 574 private:
545 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); 575 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth);
546 }; 576 };
547 577
548 class BrowserPluginPropertyBindingPartition 578 class BrowserPluginPropertyBindingPartition
549 : public BrowserPluginPropertyBinding { 579 : public BrowserPluginPropertyBinding {
550 public: 580 public:
551 BrowserPluginPropertyBindingPartition() : 581 BrowserPluginPropertyBindingPartition() :
552 BrowserPluginPropertyBinding(kAttributePartition) { 582 BrowserPluginPropertyBinding(kAttributePartition) {
553 } 583 }
554 virtual bool GetProperty(BrowserPluginBindings* bindings, 584 virtual bool GetProperty(BrowserPluginBindings* bindings,
555 NPVariant* result) OVERRIDE { 585 NPVariant* result) OVERRIDE {
556 std::string partition_id = bindings->instance()->GetPartitionAttribute(); 586 std::string partition_id = bindings->instance()->GetPartitionAttribute();
557 return StringToNPVariant(partition_id, result); 587 return StringToNPVariant(partition_id, result);
558 } 588 }
559 virtual bool SetProperty(BrowserPluginBindings* bindings, 589 virtual bool SetProperty(BrowserPluginBindings* bindings,
560 NPObject* np_obj, 590 NPObject* np_obj,
561 const NPVariant* variant) OVERRIDE { 591 const NPVariant* variant) OVERRIDE {
562 std::string partition_id = StringFromNPVariant(*variant); 592 std::string partition_id = StringFromNPVariant(*variant);
563 std::string error_message; 593 std::string error_message;
564 if (!bindings->instance()->SetPartitionAttribute(partition_id, 594 if (!bindings->instance()->SetPartitionAttribute(partition_id,
565 &error_message)) { 595 &error_message)) {
566 WebBindings::setException( 596 WebBindings::setException(
567 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); 597 np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
568 return false; 598 return false;
569 } 599 }
570 return true; 600 return true;
571 } 601 }
602 virtual std::string GetDOMAttributeValue(
603 BrowserPlugin* browser_plugin) OVERRIDE {
604 return browser_plugin->GetPartitionAttribute();
605 }
572 private: 606 private:
573 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); 607 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition);
574 }; 608 };
575 609
576 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { 610 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding {
577 public: 611 public:
578 BrowserPluginPropertyBindingSrc() : 612 BrowserPluginPropertyBindingSrc() :
579 BrowserPluginPropertyBinding(kAttributeSrc) { 613 BrowserPluginPropertyBinding(kAttributeSrc) {
580 } 614 }
581 virtual bool GetProperty(BrowserPluginBindings* bindings, 615 virtual bool GetProperty(BrowserPluginBindings* bindings,
582 NPVariant* result) OVERRIDE { 616 NPVariant* result) OVERRIDE {
583 std::string src = bindings->instance()->src_attribute(); 617 std::string src = bindings->instance()->src_attribute();
584 return StringToNPVariant(src, result); 618 return StringToNPVariant(src, result);
585 } 619 }
586 virtual bool SetProperty(BrowserPluginBindings* bindings, 620 virtual bool SetProperty(BrowserPluginBindings* bindings,
587 NPObject* np_obj, 621 NPObject* np_obj,
588 const NPVariant* variant) OVERRIDE { 622 const NPVariant* variant) OVERRIDE {
589 std::string src = StringFromNPVariant(*variant); 623 std::string src = StringFromNPVariant(*variant);
590 std::string error_message; 624 std::string error_message;
591 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { 625 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) {
592 WebBindings::setException( 626 WebBindings::setException(
593 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); 627 np_obj, static_cast<const NPUTF8 *>(error_message.c_str()));
594 return false; 628 return false;
595 } 629 }
596 return true; 630 return true;
597 } 631 }
632 virtual std::string GetDOMAttributeValue(
633 BrowserPlugin* browser_plugin) OVERRIDE {
634 return browser_plugin->src_attribute();
635 }
598 private: 636 private:
599 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); 637 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc);
600 }; 638 };
601 639
602 640
603 // BrowserPluginBindings ------------------------------------------------------ 641 // BrowserPluginBindings ------------------------------------------------------
604 642
605 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { 643 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() {
606 } 644 }
607 645
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 } 711 }
674 return false; 712 return false;
675 } 713 }
676 714
677 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, 715 bool BrowserPluginBindings::SetProperty(NPObject* np_obj,
678 NPIdentifier name, 716 NPIdentifier name,
679 const NPVariant* variant) { 717 const NPVariant* variant) {
680 for (PropertyBindingList::iterator iter = property_bindings_.begin(); 718 for (PropertyBindingList::iterator iter = property_bindings_.begin();
681 iter != property_bindings_.end(); 719 iter != property_bindings_.end();
682 ++iter) { 720 ++iter) {
683 if ((*iter)->MatchesName(name)) 721 if ((*iter)->MatchesName(name)) {
684 return (*iter)->SetProperty(this, np_obj, variant); 722 if ((*iter)->SetProperty(this, np_obj, variant)) {
723 (*iter)->UpdateDOMAttribute(this);
724 return true;
725 }
726 break;
727 }
685 } 728 }
686 return false; 729 return false;
687 } 730 }
688 731
689 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { 732 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) {
690 for (PropertyBindingList::iterator iter = property_bindings_.begin(); 733 for (PropertyBindingList::iterator iter = property_bindings_.begin();
691 iter != property_bindings_.end(); 734 iter != property_bindings_.end();
692 ++iter) { 735 ++iter) {
693 if ((*iter)->MatchesName(name)) 736 if ((*iter)->MatchesName(name))
694 return (*iter)->GetProperty(this, result); 737 return (*iter)->GetProperty(this, result);
695 } 738 }
696 return false; 739 return false;
697 } 740 }
698 741
699 } // namespace content 742 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698