Inheritance: ScriptObject
Exemplo n.º 1
0
		static HtmlPage ()
		{
			scriptableTypes = new Dictionary<string, Type> ();

			if (PluginHost.Handle != IntPtr.Zero) {
				// we don't call RegisterScriptableObject since we're registering a private type
				ScriptObject services = new ManagedObject (HostServices.Services);
				NativeMethods.moonlight_scriptable_object_register (PluginHost.Handle, "services", services.Handle);
			}
		}
Exemplo n.º 2
0
		static HtmlPage ()
		{
			if (PluginHost.Handle != IntPtr.Zero) {
				// we don't call RegisterScriptableObject since we're registering a private type
				ScriptObject services = new ManagedObject (HostServices.Current);
				NativeMethods.moonlight_scriptable_object_register (PluginHost.Handle, "services", services.Handle);
			}

			// IsRunningOutOfBrowser and EnableHTMLAccess must be run on the main thread
			// but IsEnabled can be called from any thread and it's value won't change
			enabled = !Application.Current.IsRunningOutOfBrowser && Application.Current.Host.Settings.EnableHTMLAccess;
		}
Exemplo n.º 3
0
        static HtmlPage()
        {
            if (PluginHost.Handle != IntPtr.Zero)
            {
                // we don't call RegisterScriptableObject since we're registering a private type
                ScriptObject services = new ManagedObject(HostServices.Current);
                NativeMethods.moonlight_scriptable_object_register(PluginHost.Handle, "services", services.Handle);
            }

            // IsRunningOutOfBrowser and EnableHTMLAccess must be run on the main thread
            // but IsEnabled can be called from any thread and it's value won't change
            enabled = !Application.Current.IsRunningOutOfBrowser && Application.Current.Host.Settings.EnableHTMLAccess;
        }
Exemplo n.º 4
0
        public ScriptObject CreateObject(Type type, object obj = null)
        {
            if (obj == null)
            {
                return(ManagedObject.GetManagedObject(Activator.CreateInstance(type)));
            }

            if (obj is double || obj is int)
            {
                int  size = int.Parse(obj.ToString());
                Type t    = type.GetElementType();
                if (t == null)
                {
                    return(null);
                }
                return(ManagedObject.GetManagedObject(Array.CreateInstance(t, size)));
            }
            return(ManagedObject.GetManagedObject(JsonDeserialize(obj, type)));
        }
Exemplo n.º 5
0
        protected internal override object ConvertTo(Type targetType, bool allowSerialization)
        {
            if (targetType.IsAssignableFrom(ManagedObject.GetType()))
            {
                return(ManagedObject);
            }

            if (typeof(ScriptObject).IsAssignableFrom(targetType))
            {
                return(this);
            }

            if (allowSerialization)
            {
                return(HostServices.Current.JsonDeserialize(ManagedObject, targetType));
            }

            return(null);
        }
Exemplo n.º 6
0
        internal static ManagedObject GetManagedObject(object o)
        {
            ManagedObject obj = null;
            WeakReference wref;

            lock (cachedObjects) {
                cachedObjects.TryGetValue(o, out wref);
                if (wref != null)
                {
                    if (wref.IsAlive)
                    {
                        obj = wref.Target as ManagedObject;
                    }
                }
                else
                {
                    obj = new ManagedObject(o);
                }
            }

            return(obj);
        }
Exemplo n.º 7
0
        public static void RegisterCreateableType(string scriptAlias, Type type)
        {
#if !ANDROID_HACK
            CheckThread();
            // no call to CheckHtmlAccess(); -- see DRT365
            CheckName(scriptAlias, "scriptAlias");
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!ManagedObject.IsCreateable(type))
            {
                throw new ArgumentException(type.ToString(), "type");
            }

            if (HostServices.Current.CreateableTypes.ContainsKey(scriptAlias))
            {
                throw new ArgumentException("scriptAlias");
            }

            HostServices.Current.CreateableTypes [scriptAlias] = type;
#endif
        }
Exemplo n.º 8
0
		public static void RegisterScriptableObject (string scriptKey, object instance)
		{
			CheckThread ();
			// no call to CheckHtmlAccess(); -- see DRT364
			CheckName (scriptKey, "scriptKey");
			if (instance == null)
				throw new ArgumentNullException ("instance");
			Type t = instance.GetType ();
			if (!t.IsPublic && !t.IsNestedPublic)
				throw new InvalidOperationException ("'instance' type is not public.");

			if (!ManagedObject.IsScriptable (t))
				throw new ArgumentException ("No public [ScriptableMember] method was found.", "instance");

			ScriptObject sobj = instance as ScriptObject;
			if (sobj == null)
				sobj = new ManagedObject (instance);

			NativeMethods.moonlight_scriptable_object_register (PluginHost.Handle, scriptKey, sobj.Handle);
		}
Exemplo n.º 9
0
		public bool TryChangeType (object value, Type type, CultureInfo culture, out object ret)
		{
			ScriptObject script_object;
			
			ret = value;

			if (value == null)
				return true;

			if (value.GetType() == type)
				return true;

			// we need to do this before the ScriptObject
			// block because we might be passing
			// ManagedObject arguments to a method that
			// takes ScriptObjects, and therefore we
			// shouldn't "unwrap" the ScriptObject's
			// ManagedObject field.
			if (type.IsAssignableFrom (value.GetType ()))
				return true;

			script_object = value as ScriptObject;
			if (script_object != null) {
				value = script_object.ManagedObject;
				if (value == null && type == typeof(HtmlElement))
					value = new HtmlElement (script_object.Handle);
				ret = value;
				if (value.GetType () == type)
					return true;
			}

			if (type.IsAssignableFrom (value.GetType ()))
				return true;

			if (type == typeof (ScriptObject)) {
				ret = new ManagedObject (value);
				return true;
			}

			if (type.IsEnum) {
				try {
					ret = Enum.Parse (type, value.ToString(), true);
					return true;
				} catch {
					return false;
				}
			}

			/* the set of source types for JS functions is
			 * very, very small, so we switch over the
			 * parameter type first */
			try {
				ret = Convert.ChangeType (value, type, culture);
				return true;
			}
			catch {
				// no clue if this is right.. if we
				// fail to convert, what do we return?

				switch (Type.GetTypeCode (type))
				{
				case TypeCode.Char:
				case TypeCode.Byte:
				case TypeCode.SByte:
				case TypeCode.Int16:
				case TypeCode.Int32:
				case TypeCode.Int64:
				case TypeCode.UInt16:
				case TypeCode.UInt32:
				case TypeCode.UInt64:
				case TypeCode.Single:
				case TypeCode.Double:
					ret = Convert.ChangeType (0, type, culture);
					return true;
				case TypeCode.String:
					ret = "";
					return true;

				case TypeCode.Boolean:
					ret = false;
					return true;
				}
			}

			return false;
		}
Exemplo n.º 10
0
 public EventOps(ManagedObject obj)
 {
     this.obj = obj;
 }
Exemplo n.º 11
0
			public EventOps (ManagedObject obj)
			{
				this.obj = obj;
			}