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