2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
25 #include "swfdec_net_connection.h"
26 #include "swfdec_as_context.h"
27 #include "swfdec_as_native_function.h"
28 #include "swfdec_as_object.h"
29 #include "swfdec_as_strings.h"
30 #include "swfdec_debug.h"
31 #include "swfdec_internal.h"
33 /*** SwfdecNetConnection ***/
35 G_DEFINE_TYPE (SwfdecNetConnection
, swfdec_net_connection
, SWFDEC_TYPE_AS_OBJECT
)
38 swfdec_net_connection_dispose (GObject
*object
)
40 SwfdecNetConnection
*net_connection
= SWFDEC_NET_CONNECTION (object
);
42 g_free (net_connection
->url
);
43 net_connection
->url
= NULL
;
45 G_OBJECT_CLASS (swfdec_net_connection_parent_class
)->dispose (object
);
49 swfdec_net_connection_class_init (SwfdecNetConnectionClass
*klass
)
51 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
53 object_class
->dispose
= swfdec_net_connection_dispose
;
57 swfdec_net_connection_init (SwfdecNetConnection
*net_connection
)
62 swfdec_net_connection_onstatus (SwfdecNetConnection
*conn
, const char *code
,
63 const char *level
, const char *description
)
68 info
= swfdec_as_object_new (SWFDEC_AS_OBJECT (conn
)->context
);
71 SWFDEC_AS_VALUE_SET_STRING (&value
, code
);
72 swfdec_as_object_set_variable (info
, SWFDEC_AS_STR_code
, &value
);
73 SWFDEC_AS_VALUE_SET_STRING (&value
, level
);
74 swfdec_as_object_set_variable (info
, SWFDEC_AS_STR_level
, &value
);
76 SWFDEC_AS_VALUE_SET_STRING (&value
, description
);
77 swfdec_as_object_set_variable (info
, SWFDEC_AS_STR_description
, &value
);
79 SWFDEC_AS_VALUE_SET_OBJECT (&value
, info
);
80 swfdec_as_object_call (SWFDEC_AS_OBJECT (conn
), SWFDEC_AS_STR_onStatus
, 1, &value
, NULL
);
84 swfdec_net_connection_new (SwfdecAsContext
*context
)
86 SwfdecNetConnection
*conn
;
88 g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context
), NULL
);
90 if (!swfdec_as_context_use_mem (context
, sizeof (SwfdecNetConnection
)))
92 conn
= g_object_new (SWFDEC_TYPE_NET_CONNECTION
, NULL
);
93 swfdec_as_object_add (SWFDEC_AS_OBJECT (conn
), context
, sizeof (SwfdecNetConnection
));
99 swfdec_net_connection_connect (SwfdecNetConnection
*conn
, const char *url
)
101 g_return_if_fail (SWFDEC_IS_NET_CONNECTION (conn
));
104 conn
->url
= g_strdup (url
);
106 SWFDEC_ERROR ("FIXME: using NetConnection with non-null URLs is not implemented");
108 swfdec_net_connection_onstatus (conn
, SWFDEC_AS_STR_NetConnection_Connect_Success
,
109 SWFDEC_AS_STR_status
, NULL
);
115 swfdec_net_connection_do_connect (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
116 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
118 SwfdecNetConnection
*conn
= SWFDEC_NET_CONNECTION (obj
);
121 if (SWFDEC_AS_VALUE_IS_STRING (&argv
[0])) {
122 url
= SWFDEC_AS_VALUE_GET_STRING (&argv
[0]);
123 } else if (SWFDEC_AS_VALUE_IS_NULL (&argv
[0])) {
126 SWFDEC_FIXME ("untested argument to NetConnection.connect: type %u", argv
[0].type
);
129 swfdec_net_connection_connect (conn
, url
);
133 swfdec_net_connection_init_context (SwfdecPlayer
*player
, guint version
)
135 SwfdecAsContext
*context
;
136 SwfdecAsObject
*conn
, *proto
;
139 g_return_if_fail (SWFDEC_IS_PLAYER (player
));
141 context
= SWFDEC_AS_CONTEXT (player
);
142 proto
= swfdec_as_object_new_empty (context
);
145 conn
= SWFDEC_AS_OBJECT (swfdec_as_object_add_constructor (context
->global
,
146 SWFDEC_AS_STR_NetConnection
, SWFDEC_TYPE_NET_CONNECTION
,
147 SWFDEC_TYPE_NET_CONNECTION
, NULL
, 0, proto
));
150 /* set the right properties on the NetConnection.prototype object */
151 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_connect
, SWFDEC_TYPE_NET_CONNECTION
,
152 swfdec_net_connection_do_connect
, 1);
153 SWFDEC_AS_VALUE_SET_OBJECT (&val
, conn
);
154 swfdec_as_object_set_variable_and_flags (proto
, SWFDEC_AS_STR_constructor
,
155 &val
, SWFDEC_AS_VARIABLE_HIDDEN
| SWFDEC_AS_VARIABLE_PERMANENT
);
156 SWFDEC_AS_VALUE_SET_OBJECT (&val
, context
->Object_prototype
);
157 swfdec_as_object_set_variable_and_flags (proto
, SWFDEC_AS_STR___proto__
,
158 &val
, SWFDEC_AS_VARIABLE_HIDDEN
| SWFDEC_AS_VARIABLE_PERMANENT
);