1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
22
23 #include "DefaultTagLoaders.h"
24
25 #include <set>
26
27 #include "SWF.h"
28 #include "TagLoadersTable.h"
29 #include "tag_loaders.h"
30 #include "ScriptLimitsTag.h"
31 #include "DefineFontAlignZonesTag.h"
32 #include "DefineShapeTag.h"
33 #include "DefineButtonCxformTag.h"
34 #include "CSMTextSettingsTag.h"
35 #include "DefineFontTag.h"
36 #include "DefineButtonTag.h"
37 #include "DefineScalingGridTag.h"
38 #include "DefineTextTag.h"
39 #include "PlaceObject2Tag.h"
40 #include "RemoveObjectTag.h"
41 #include "DoActionTag.h"
42 #include "DoInitActionTag.h"
43 #include "DefineEditTextTag.h"
44 #include "SetBackgroundColorTag.h"
45 #include "SetTabIndexTag.h"
46 #include "StartSoundTag.h"
47 #include "StreamSoundBlockTag.h"
48 #include "DefineBitsTag.h"
49 #include "DefineButtonSoundTag.h"
50 #include "DefineMorphShapeTag.h"
51 #include "DefineVideoStreamTag.h"
52 #include "DefineFontNameTag.h"
53 #include "VideoFrameTag.h"
54 #include "ImportAssetsTag.h"
55 #include "ExportAssetsTag.h"
56 #include "SoundStreamHeadTag.h"
57 #ifdef ENABLE_AVM2
58 # include "SymbolClassTag.h"
59 # include "DoABCTag.h"
60 # include "DefineSceneAndFrameLabelDataTag.h"
61 #endif
62
63 namespace gnash {
64 namespace SWF {
65
66
67 namespace {
68
69 typedef TagLoadersTable::Loaders::value_type TagPair;
70
71 class AddLoader
72 {
73 public:
74
AddLoader(TagLoadersTable & table)75 AddLoader(TagLoadersTable& table)
76 :
77 _table(table)
78 {}
79
operator ()(const TagPair & p)80 void operator()(const TagPair& p) {
81 _table.registerLoader(p.first, p.second);
82 }
83 private:
84 TagLoadersTable& _table;
85 };
86
87 // This is only for tags mentioned in documentation but thought to to exist.
88 void
unexpected(SWFStream &,TagType tag,movie_definition &,const RunResources &)89 unexpected(SWFStream&, TagType tag, movie_definition&, const RunResources&)
90 {
91 static std::set<TagType> warned;
92 if (warned.insert(tag).second) {
93 log_unimpl(_("Undocumented tag %s encountered. Please report this to "
94 "the Gnash developers!"), tag);
95 }
96 }
97
98 // Silently ignore the contents of this tag.
99 void
ignore(SWFStream &,TagType,movie_definition &,const RunResources &)100 ignore(SWFStream&, TagType, movie_definition&, const RunResources&)
101 {
102 }
103
104 } // unnamed namespace
105
106 void
addDefaultLoaders(TagLoadersTable & table)107 addDefaultLoaders(TagLoadersTable& table)
108 {
109
110 // Note: all the tags given an 'unexpected' here are
111 // expected not to be used. They are generally documented
112 // by Alexis to exist (without any known structure), but not
113 // by Adobe.
114 const std::vector<TagPair> tags = {
115 // 01: nothing to do for an end tag.
116 {SWF::END,ignore},
117 // 02
118 {SWF::DEFINESHAPE,DefineShapeTag::loader},
119 // 03
120 {SWF::FREECHARACTER,unexpected},
121 {SWF::PLACEOBJECT,PlaceObject2Tag::loader},
122 {SWF::REMOVEOBJECT,RemoveObjectTag::loader},// 05
123 {SWF::DEFINEBITS,DefineBitsTag::loader},
124 {SWF::DEFINEBUTTON,DefineButtonTag::loader},
125 {SWF::JPEGTABLES,jpeg_tables_loader},
126 {SWF::SETBACKGROUNDCOLOR,SetBackgroundColorTag::loader},
127 {SWF::DEFINEFONT,DefineFontTag::loader},
128 {SWF::DEFINETEXT,DefineTextTag::loader},
129 {SWF::DOACTION,DoActionTag::loader},
130 {SWF::DEFINEFONTINFO,DefineFontInfoTag::loader},
131 {SWF::DEFINESOUND,define_sound_loader},
132 {SWF::STARTSOUND,StartSoundTag::loader},
133 {SWF::STOPSOUND,unexpected},// 16
134 // 17
135 {SWF::DEFINEBUTTONSOUND,DefineButtonSoundTag::loader},
136 // 18
137 {SWF::SOUNDSTREAMHEAD,SoundStreamHeadTag::loader},
138 // 19
139 {SWF::SOUNDSTREAMBLOCK,StreamSoundBlockTag::loader},
140 {SWF::DEFINELOSSLESS,DefineBitsTag::loader},
141 {SWF::DEFINEBITSJPEG2,DefineBitsTag::loader},
142 {SWF::DEFINESHAPE2,DefineShapeTag::loader},
143 {SWF::DEFINEBUTTONCXFORM,DefineButtonCxformTag::loader},// 23
144 {SWF::PROTECT,ignore},
145 {SWF::PATHSAREPOSTSCRIPT,unexpected},// 25
146 {SWF::PLACEOBJECT2,PlaceObject2Tag::loader},
147 // 28
148 {SWF::REMOVEOBJECT2,RemoveObjectTag::loader},
149 {SWF::SYNCFRAME,unexpected},// 29
150 {SWF::FREEALL,unexpected},// 31
151 {SWF::DEFINESHAPE3,DefineShapeTag::loader},
152 {SWF::DEFINETEXT2,DefineText2Tag::loader},
153 // 37
154 {SWF::DEFINEBUTTON2,DefineButton2Tag::loader},
155 {SWF::DEFINEBITSJPEG3,DefineBitsTag::loader},
156 {SWF::DEFINELOSSLESS2,DefineBitsTag::loader},
157 {SWF::DEFINEEDITTEXT,DefineEditTextTag::loader},
158 {SWF::DEFINEVIDEO,unexpected},// 38
159 {SWF::DEFINESPRITE,sprite_loader},
160 {SWF::NAMECHARACTER,unexpected},// 40
161 {SWF::SERIALNUMBER,serialnumber_loader},// 41
162 {SWF::DEFINETEXTFORMAT,unexpected},// 42
163 {SWF::FRAMELABEL,frame_label_loader},// 43
164 {SWF::DEFINEBEHAVIOR,unexpected},// 44
165 // 45
166 {SWF::SOUNDSTREAMHEAD2,SoundStreamHeadTag::loader},
167 // 46
168 {SWF::DEFINEMORPHSHAPE,DefineMorphShapeTag::loader},
169 // 47
170 {SWF::FRAMETAG,unexpected},
171 // 48
172 {SWF::DEFINEFONT2,DefineFontTag::loader},
173 {SWF::GENCOMMAND,unexpected},// 49
174 {SWF::DEFINECOMMANDOBJ,unexpected},// 50
175 {SWF::CHARACTERSET,unexpected},// 51
176 {SWF::FONTREF,unexpected},// 52
177 {SWF::DEFINEFUNCTION,unexpected},// 53
178 {SWF::PLACEFUNCTION,unexpected},// 54
179 {SWF::GENTAGOBJECT,unexpected},// 55
180 {SWF::EXPORTASSETS,ExportAssetsTag::loader},// 56
181 {SWF::IMPORTASSETS,ImportAssetsTag::loader},// 57
182 {SWF::ENABLEDEBUGGER,ignore}, // 58
183 // 59
184 {SWF::INITACTION,DoInitActionTag::loader},
185 // 60
186 {SWF::DEFINEVIDEOSTREAM,DefineVideoStreamTag::loader},
187 // 61
188 {SWF::VIDEOFRAME,VideoFrameTag::loader},
189 // 62
190 {SWF::DEFINEFONTINFO2,DefineFontInfoTag::loader},
191 // 63
192 {SWF::DEBUGID,ignore},
193 // 64
194 {SWF::ENABLEDEBUGGER2,ignore},
195 {SWF::SCRIPTLIMITS,ScriptLimitsTag::loader},//65
196 {SWF::SETTABINDEX,SetTabIndexTag::loader},//66
197 // TODO: Alexis reference says these are 83,84. The 67,68 comes from
198 // Tamarin. Figure out which one is correct (possibly both are).
199 // 67
200 {SWF::DEFINESHAPE4_,DefineShapeTag::loader},
201 // 68
202 {SWF::DEFINEMORPHSHAPE2_,DefineMorphShapeTag::loader},
203 // 69
204 {SWF::FILEATTRIBUTES,file_attributes_loader},
205 // 70
206 {SWF::PLACEOBJECT3,PlaceObject2Tag::loader},
207 // 71
208 {SWF::IMPORTASSETS2,ImportAssetsTag::loader},
209 // 73
210 {SWF::DEFINEALIGNZONES,DefineFontAlignZonesTag::loader},
211 // 74
212 {SWF::CSMTEXTSETTINGS,CSMTextSettingsTag::loader},
213 // 75
214 {SWF::DEFINEFONT3,DefineFontTag::loader},
215 // 77
216 {SWF::METADATA,metadata_loader},
217 // 78
218 {SWF::DEFINESCALINGGRID,DefineScalingGridTag::loader},
219 // 83
220 {SWF::DEFINESHAPE4,DefineShapeTag::loader},
221 // 84
222 {SWF::DEFINEMORPHSHAPE2,DefineMorphShapeTag::loader},
223 // 88
224 {SWF::DEFINEFONTNAME,DefineFontNameTag::loader},
225 // 89
226 {SWF::STARTSOUND2,StartSound2Tag::loader},
227 // 90
228 {SWF::DEFINEBITSJPEG4,DefineBitsTag::loader},
229 // 777
230 {SWF::REFLEX,reflex_loader}
231 #ifdef ENABLE_AVM2
232 // The following tags are AVM2 only.
233 // 72 -- AS3 codeblock.
234 ,{SWF::DOABC,DoABCTag::loader},
235 // 76
236 {SWF::SYMBOLCLASS,SymbolClassTag::loader},
237 // 82
238 {SWF::DOABCDEFINE,DoABCTag::loader},
239 // 86
240 {SWF::DEFINESCENEANDFRAMELABELDATA,
241 DefineSceneAndFrameLabelDataTag::loader}
242 #endif
243 };
244
245 std::for_each(tags.begin(), tags.end(), AddLoader(table));
246
247 }
248
249 } // namespace SWF
250 } // namespace gnash
251
252