Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_SWF_IMPORTASSETSTAG_H
00020 #define GNASH_SWF_IMPORTASSETSTAG_H
00021
00022 #include <vector>
00023 #include <utility>
00024 #include <string>
00025 #include <memory>
00026
00027 #include "ControlTag.h"
00028 #include "Movie.h"
00029 #include "MovieClip.h"
00030 #include "SWFStream.h"
00031 #include "MovieFactory.h"
00032 #include "log.h"
00033
00034 namespace gnash {
00035 namespace SWF {
00036
00037 class ImportAssetsTag : public ControlTag
00038 {
00039 public:
00040
00041 typedef std::pair<int, std::string> Import;
00042 typedef std::vector<Import> Imports;
00043
00044 static void loader(SWFStream& in, TagType tag, movie_definition& m,
00045 const RunResources& r)
00046 {
00047 assert(tag == SWF::IMPORTASSETS || tag == SWF::IMPORTASSETS2);
00048
00049 std::auto_ptr<ControlTag> p(new ImportAssetsTag(tag, in, m, r));
00050 m.addControlTag(p.release());
00051 }
00052
00053
00055
00059 virtual void executeState(MovieClip* m, DisplayList& ) const {
00060 Movie* mov = m->get_root();
00061 for (Imports::const_iterator it = _imports.begin(), e = _imports.end();
00062 it != e; ++it) {
00063 mov->addCharacter(it->first);
00064 }
00065 }
00066
00067 private:
00068
00069 ImportAssetsTag(TagType t, SWFStream& in, movie_definition& m,
00070 const RunResources& r)
00071 {
00072 read(t, in, m, r);
00073 }
00074
00075 void read(TagType t, SWFStream& in, movie_definition& m,
00076 const RunResources& r) {
00077
00078 std::string source_url;
00079 in.read_string(source_url);
00080
00081
00082 URL abs_url(source_url, r.baseURL());
00083
00084 unsigned char import_version = 0;
00085
00086 if (t == SWF::IMPORTASSETS2) {
00087 in.ensureBytes(2);
00088 import_version = in.read_uint(8);
00089 boost::uint8_t reserved = in.read_uint(8);
00090 UNUSED(reserved);
00091 }
00092
00093 in.ensureBytes(2);
00094 const boost::uint16_t count = in.read_u16();
00095
00096 IF_VERBOSE_PARSE(
00097 log_parse(_(" import: version = %u, source_url = %s (%s), "
00098 "count = %d"), import_version, abs_url.str(), source_url,
00099 count);
00100 );
00101
00102
00103 boost::intrusive_ptr<movie_definition> source_movie;
00104
00105 try {
00106 source_movie = MovieFactory::makeMovie(abs_url, r);
00107 }
00108 catch (gnash::GnashException& e) {
00109 log_error(_("Exception: %s"), e.what());
00110 }
00111
00112 if (!source_movie) {
00113
00114 log_error(_("can't import movie from url %s"), abs_url.str());
00115 return;
00116 }
00117
00118
00119
00120 if (source_movie == &m) {
00121 IF_VERBOSE_MALFORMED_SWF(
00122 log_swferror(_("Movie attempts to import symbols from "
00123 "itself."));
00124 );
00125 return;
00126 }
00127
00128
00129 for (size_t i = 0; i < count; ++i)
00130 {
00131 in.ensureBytes(2);
00132 const boost::uint16_t id = in.read_u16();
00133
00134
00135 if (!id) continue;
00136
00137 std::string symbolName;
00138 in.read_string(symbolName);
00139 IF_VERBOSE_PARSE (
00140 log_parse(_(" import: id = %d, name = %s"), id, symbolName);
00141 );
00142 _imports.push_back(std::make_pair(id, symbolName));
00143 }
00144
00145 m.importResources(source_movie, _imports);
00146 }
00147
00148 private:
00149
00150 Imports _imports;
00151
00152 };
00153
00154 }
00155 }
00156
00157 #endif