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

Side by Side Diff: webkit/plugins/ppapi/var.cc

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « webkit/plugins/ppapi/var.h ('k') | webkit/plugins/ppapi/var_object_class.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_var.h" 5 #include "webkit/plugins/ppapi/var.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "ppapi/c/dev/ppb_var_deprecated.h" 12 #include "ppapi/c/dev/ppb_var_deprecated.h"
13 #include "ppapi/c/ppb_var.h" 13 #include "ppapi/c/ppb_var.h"
14 #include "ppapi/c/pp_var.h" 14 #include "ppapi/c/pp_var.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h"
16 #include "webkit/glue/plugins/pepper_common.h" 16 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/glue/plugins/pepper_plugin_instance.h" 17 #include "webkit/plugins/ppapi/plugin_instance.h"
18 #include "webkit/glue/plugins/pepper_plugin_module.h" 18 #include "webkit/plugins/ppapi/plugin_module.h"
19 #include "webkit/glue/plugins/pepper_plugin_object.h" 19 #include "webkit/plugins/ppapi/plugin_object.h"
20 #include "v8/include/v8.h" 20 #include "v8/include/v8.h"
21 21
22 using WebKit::WebBindings; 22 using WebKit::WebBindings;
23 23
24 namespace pepper { 24 namespace webkit {
25 namespace ppapi {
25 26
26 namespace { 27 namespace {
27 28
28 const char kInvalidObjectException[] = "Error: Invalid object"; 29 const char kInvalidObjectException[] = "Error: Invalid object";
29 const char kInvalidPropertyException[] = "Error: Invalid property"; 30 const char kInvalidPropertyException[] = "Error: Invalid property";
30 const char kInvalidValueException[] = "Error: Invalid value"; 31 const char kInvalidValueException[] = "Error: Invalid value";
31 const char kUnableToGetPropertyException[] = "Error: Unable to get property"; 32 const char kUnableToGetPropertyException[] = "Error: Unable to get property";
32 const char kUnableToSetPropertyException[] = "Error: Unable to set property"; 33 const char kUnableToSetPropertyException[] = "Error: Unable to set property";
33 const char kUnableToRemovePropertyException[] = 34 const char kUnableToRemovePropertyException[] =
34 "Error: Unable to remove property"; 35 "Error: Unable to remove property";
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } // namespace 646 } // namespace
646 647
647 // Var ------------------------------------------------------------------------- 648 // Var -------------------------------------------------------------------------
648 649
649 Var::Var(PluginModule* module) : Resource(module) { 650 Var::Var(PluginModule* module) : Resource(module) {
650 } 651 }
651 652
652 Var::~Var() { 653 Var::~Var() {
653 } 654 }
654 655
656 Var* Var::AsVar() {
657 return this;
658 }
659
655 // static 660 // static
656 PP_Var Var::NPVariantToPPVar(PluginModule* module, const NPVariant* variant) { 661 PP_Var Var::NPVariantToPPVar(PluginModule* module, const NPVariant* variant) {
657 switch (variant->type) { 662 switch (variant->type) {
658 case NPVariantType_Void: 663 case NPVariantType_Void:
659 return PP_MakeUndefined(); 664 return PP_MakeUndefined();
660 case NPVariantType_Null: 665 case NPVariantType_Null:
661 return PP_MakeNull(); 666 return PP_MakeNull();
662 case NPVariantType_Bool: 667 case NPVariantType_Bool:
663 return BoolToPPVar(NPVARIANT_TO_BOOLEAN(*variant)); 668 return BoolToPPVar(NPVARIANT_TO_BOOLEAN(*variant));
664 case NPVariantType_Int32: 669 case NPVariantType_Int32:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 return StringVar::StringToPPVar(module, string_value); 708 return StringVar::StringToPPVar(module, string_value);
704 709
705 return PP_MakeInt32(int_value); 710 return PP_MakeInt32(int_value);
706 } 711 }
707 712
708 // static 713 // static
709 void Var::PluginAddRefPPVar(PP_Var var) { 714 void Var::PluginAddRefPPVar(PP_Var var) {
710 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { 715 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
711 // TODO(brettw) consider checking that the ID is actually a var ID rather 716 // TODO(brettw) consider checking that the ID is actually a var ID rather
712 // than some random other resource ID. 717 // than some random other resource ID.
713 if (!ResourceTracker::Get()->AddRefResource(var.value.as_id)) 718 PP_Resource resource = static_cast<PP_Resource>(var.value.as_id);
719 if (!ResourceTracker::Get()->AddRefResource(resource))
714 DLOG(WARNING) << "AddRefVar()ing a nonexistant string/object var."; 720 DLOG(WARNING) << "AddRefVar()ing a nonexistant string/object var.";
715 } 721 }
716 } 722 }
717 723
718 // static 724 // static
719 void Var::PluginReleasePPVar(PP_Var var) { 725 void Var::PluginReleasePPVar(PP_Var var) {
720 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) { 726 if (var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT) {
721 // TODO(brettw) consider checking that the ID is actually a var ID rather 727 // TODO(brettw) consider checking that the ID is actually a var ID rather
722 // than some random other resource ID. 728 // than some random other resource ID.
723 if (!ResourceTracker::Get()->UnrefResource(var.value.as_id)) 729 PP_Resource resource = static_cast<PP_Resource>(var.value.as_id);
730 if (!ResourceTracker::Get()->UnrefResource(resource))
724 DLOG(WARNING) << "ReleaseVar()ing a nonexistant string/object var."; 731 DLOG(WARNING) << "ReleaseVar()ing a nonexistant string/object var.";
725 } 732 }
726 } 733 }
727 734
728 // static 735 // static
729 const PPB_Var_Deprecated* Var::GetDeprecatedInterface() { 736 const PPB_Var_Deprecated* Var::GetDeprecatedInterface() {
730 return &var_deprecated_interface; 737 return &var_deprecated_interface;
731 } 738 }
732 739
733 const PPB_Var* Var::GetInterface() { 740 const PPB_Var* Var::GetInterface() {
734 return &var_interface; 741 return &var_interface;
735 } 742 }
736 743
737 // StringVar ------------------------------------------------------------------- 744 // StringVar -------------------------------------------------------------------
738 745
739 StringVar::StringVar(PluginModule* module, const char* str, uint32 len) 746 StringVar::StringVar(PluginModule* module, const char* str, uint32 len)
740 : Var(module), 747 : Var(module),
741 value_(str, len) { 748 value_(str, len) {
742 } 749 }
743 750
744 StringVar::~StringVar() { 751 StringVar::~StringVar() {
745 } 752 }
746 753
754 StringVar* StringVar::AsStringVar() {
755 return this;
756 }
757
747 // static 758 // static
748 PP_Var StringVar::StringToPPVar(PluginModule* module, const std::string& var) { 759 PP_Var StringVar::StringToPPVar(PluginModule* module, const std::string& var) {
749 return StringToPPVar(module, var.c_str(), var.size()); 760 return StringToPPVar(module, var.c_str(), var.size());
750 } 761 }
751 762
752 // static 763 // static
753 PP_Var StringVar::StringToPPVar(PluginModule* module, 764 PP_Var StringVar::StringToPPVar(PluginModule* module,
754 const char* data, uint32 len) { 765 const char* data, uint32 len) {
755 scoped_refptr<StringVar> str(new StringVar(module, data, len)); 766 scoped_refptr<StringVar> str(new StringVar(module, data, len));
756 if (!str || !IsStringUTF8(str->value())) 767 if (!str || !IsStringUTF8(str->value()))
757 return PP_MakeNull(); 768 return PP_MakeNull();
758 769
759 PP_Var ret; 770 PP_Var ret;
760 ret.type = PP_VARTYPE_STRING; 771 ret.type = PP_VARTYPE_STRING;
761 772
762 // The caller takes ownership now. 773 // The caller takes ownership now.
763 ret.value.as_id = str->GetReference(); 774 ret.value.as_id = str->GetReference();
764 return ret; 775 return ret;
765 } 776 }
766 777
767 // static 778 // static
768 scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) { 779 scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) {
769 if (var.type != PP_VARTYPE_STRING) 780 if (var.type != PP_VARTYPE_STRING)
770 return scoped_refptr<StringVar>(NULL); 781 return scoped_refptr<StringVar>(NULL);
771 return Resource::GetAs<StringVar>(var.value.as_id); 782 PP_Resource resource = static_cast<PP_Resource>(var.value.as_id);
783 return Resource::GetAs<StringVar>(resource);
772 } 784 }
773 785
774 // ObjectVar ------------------------------------------------------------- 786 // ObjectVar -------------------------------------------------------------
775 787
776 ObjectVar::ObjectVar(PluginModule* module, NPObject* np_object) 788 ObjectVar::ObjectVar(PluginModule* module, NPObject* np_object)
777 : Var(module), 789 : Var(module),
778 np_object_(np_object) { 790 np_object_(np_object) {
779 WebBindings::retainObject(np_object_); 791 WebBindings::retainObject(np_object_);
780 module->AddNPObjectVar(this); 792 module->AddNPObjectVar(this);
781 } 793 }
782 794
783 ObjectVar::~ObjectVar() { 795 ObjectVar::~ObjectVar() {
784 module()->RemoveNPObjectVar(this); 796 module()->RemoveNPObjectVar(this);
785 WebBindings::releaseObject(np_object_); 797 WebBindings::releaseObject(np_object_);
786 } 798 }
787 799
800 ObjectVar* ObjectVar::AsObjectVar() {
801 return this;
802 }
803
788 // static 804 // static
789 PP_Var ObjectVar::NPObjectToPPVar(PluginModule* module, NPObject* object) { 805 PP_Var ObjectVar::NPObjectToPPVar(PluginModule* module, NPObject* object) {
790 scoped_refptr<ObjectVar> object_var(module->ObjectVarForNPObject(object)); 806 scoped_refptr<ObjectVar> object_var(module->ObjectVarForNPObject(object));
791 if (!object_var) // No object for this module yet, make a new one. 807 if (!object_var) // No object for this module yet, make a new one.
792 object_var = new ObjectVar(module, object); 808 object_var = new ObjectVar(module, object);
793 809
794 if (!object_var) 810 if (!object_var)
795 return PP_MakeUndefined(); 811 return PP_MakeUndefined();
796 812
797 // Convert to a PP_Var, GetReference will AddRef for us. 813 // Convert to a PP_Var, GetReference will AddRef for us.
798 PP_Var result; 814 PP_Var result;
799 result.type = PP_VARTYPE_OBJECT; 815 result.type = PP_VARTYPE_OBJECT;
800 result.value.as_id = object_var->GetReference(); 816 result.value.as_id = object_var->GetReference();
801 return result; 817 return result;
802 } 818 }
803 819
804 // static 820 // static
805 scoped_refptr<ObjectVar> ObjectVar::FromPPVar(PP_Var var) { 821 scoped_refptr<ObjectVar> ObjectVar::FromPPVar(PP_Var var) {
806 if (var.type != PP_VARTYPE_OBJECT) 822 if (var.type != PP_VARTYPE_OBJECT)
807 return scoped_refptr<ObjectVar>(NULL); 823 return scoped_refptr<ObjectVar>(NULL);
808 return Resource::GetAs<ObjectVar>(var.value.as_id); 824 PP_Resource resource = static_cast<PP_Resource>(var.value.as_id);
825 return Resource::GetAs<ObjectVar>(resource);
809 } 826 }
810 827
811 // TryCatch -------------------------------------------------------------------- 828 // TryCatch --------------------------------------------------------------------
812 829
813 TryCatch::TryCatch(PluginModule* module, PP_Var* exception) 830 TryCatch::TryCatch(PluginModule* module, PP_Var* exception)
814 : module_(module), 831 : module_(module),
815 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED), 832 has_exception_(exception && exception->type != PP_VARTYPE_UNDEFINED),
816 exception_(exception) { 833 exception_(exception) {
817 WebBindings::pushExceptionHandler(&TryCatch::Catch, this); 834 WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
818 } 835 }
(...skipping 24 matching lines...) Expand all
843 if (exception_) 860 if (exception_)
844 *exception_ = PP_MakeInt32(1); 861 *exception_ = PP_MakeInt32(1);
845 } 862 }
846 } 863 }
847 864
848 // static 865 // static
849 void TryCatch::Catch(void* self, const char* message) { 866 void TryCatch::Catch(void* self, const char* message) {
850 static_cast<TryCatch*>(self)->SetException(message); 867 static_cast<TryCatch*>(self)->SetException(message);
851 } 868 }
852 869
853 } // namespace pepper 870 } // namespace ppapi
871 } // namespace webkit
872
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/var.h ('k') | webkit/plugins/ppapi/var_object_class.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698