Gnash  0.8.10
ExternalInterface.h
Go to the documentation of this file.
00001 // ExternalInterface.h:  ActionScript "ExternalInterface" support
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 
00021 #ifndef GNASH_EXTERNALINTERFACE_H
00022 #define GNASH_EXTERNALINTERFACE_H
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 #include <set>
00028 #include <boost/shared_ptr.hpp>
00029 
00030 #include "dsodefs.h" /* For DSOEXPORT */
00031 
00032 namespace gnash {
00033     class as_object;
00034     class as_value;
00035     struct ObjectURI;
00036     class Global_as;
00037     class movie_root;
00038     class IOChannel;
00039 }
00040 
00041 namespace gnash {
00042 
00043 struct DSOEXPORT ExternalInterface
00044 {
00045     struct DSOLOCAL invoke_t {
00046         std::string name;
00047         std::string type;
00048         std::vector<as_value> args;
00049     };
00050 
00052     static std::string toXML(const as_value &obj) {
00053         ExternalInterface ei;
00054         return ei._toXML(obj);
00055     }
00056     
00057     static as_value parseXML(const std::string &xml);
00058     static std::vector<as_value> parseArguments(const std::string &xml);
00059 
00060     // Parse the XML Invoke message.
00061     static boost::shared_ptr<invoke_t> parseInvoke(const std::string &str);
00062     // Check for data from the browser and parse it.
00063     DSOEXPORT static boost::shared_ptr<invoke_t> ExternalEventCheck(int fd);
00064 
00065     // These methods are for constructing Invoke messages.
00066     // Create an Invoke message for the standalone Gnash
00067     DSOEXPORT static std::string makeInvoke (const std::string &method,
00068                                              const std::vector<as_value> &args);
00069     
00070     static std::string makeString (const std::string &str) {
00071         return "<string>" + str + "</string>";
00072     }
00073 
00074     DSOEXPORT static size_t writeBrowser(int fd, const std::string &xml);
00075     DSOEXPORT static std::string readBrowser(int fd);
00076 
00077 private:
00078 
00079     DSOEXPORT std::string _toXML(const as_value &obj);
00080     DSOEXPORT std::string _objectToXML(as_object* obj);
00081     DSOEXPORT std::string _arrayToXML(as_object *obj);
00082 
00083     std::set<as_object*> _visited;
00084 };
00085 
00086 } // end of gnash namespace
00087 
00088 #endif
00089 
00090 // local Variables:
00091 // mode: C++
00092 // indent-tabs-mode: nil
00093 // End: