gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r12169: merge from branch. Make Exte


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12169: merge from branch. Make ExternalInterface::available based on if AllowScriptAccess was passed in the parameters.
Date: Wed, 21 Apr 2010 18:36:43 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12169 [merge]
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Wed 2010-04-21 18:36:43 -0600
message:
  merge from branch. Make ExternalInterface::available based on if 
AllowScriptAccess was passed in the parameters.
modified:
  gui/Player.cpp
  gui/gui.cpp
  libcore/asobj/flash/external/ExternalInterface_as.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  plugin/npapi/pluginScriptObject.cpp
  testsuite/actionscript.all/ExternalInterface.as
=== modified file 'gui/Player.cpp'
--- a/gui/Player.cpp    2010-04-21 02:54:52 +0000
+++ b/gui/Player.cpp    2010-04-22 00:36:43 +0000
@@ -262,17 +262,13 @@
     }
 
     try {
-        if ( _infile == "-" )
-        {
+        if ( _infile == "-" ) {
             std::auto_ptr<IOChannel> in (
-                    noseek_fd_adapter::make_stream(fileno(stdin)));
+                noseek_fd_adapter::make_stream(fileno(stdin)));
             md = MovieFactory::makeMovie(in, _url, *_runResources, false);
-        }
-        else
-        {
+        } else {
             URL url(_infile);
-            if ( url.protocol() == "file" )
-            {
+            if ( url.protocol() == "file" ) {
                 std::string path = url.path();
                 // We'll need to allow load of the file, no matter virtual url
                 // specified...
@@ -294,8 +290,7 @@
         md = NULL;
     }
 
-    if ( ! md )
-    {
+    if ( ! md ) {
         fprintf(stderr, "Could not load movie '%s'\n", _infile.c_str());
         return NULL;
     }
@@ -483,17 +478,38 @@
         root.setStageAlignment(align);
     }
 
+    it = params.find("allowscriptaccess");
+    if (it != params.end()) {
+        std::string access = it->second;
+        StringNoCaseEqual noCaseCompare;
+        const std::string& str = it->second;
+                
+        movie_root::AllowScriptAccessMode mode = movie_root::sameDomain;
+        if (noCaseCompare(str, "never")) {
+            mode = movie_root::never;
+        } else if (noCaseCompare(str, "sameDomain")) {
+            mode = movie_root::sameDomain;
+        } else if (noCaseCompare(str, "always")) {
+            mode = movie_root::always;
+        }
+        log_debug("Setting allowscriptaccess to %s", mode);
+        root.setAllowScriptAccess(mode);
+    }
+
     it = params.find("scale");
-    if (it != params.end()) {
-                
+    if (it != params.end()) {                
         StringNoCaseEqual noCaseCompare;
         const std::string& str = it->second;
                 
         movie_root::ScaleMode mode = movie_root::showAll;
-
-                if (noCaseCompare(str, "noScale")) mode = movie_root::noScale;
-                else if (noCaseCompare(str, "exactFit")) mode = 
movie_root::exactFit;
-                else if (noCaseCompare(str, "noBorder")) mode = 
movie_root::noBorder;
+        
+        if (noCaseCompare(str, "noScale")) {
+            mode = movie_root::noScale;
+        } else if (noCaseCompare(str, "exactFit")) {
+            mode = movie_root::exactFit;
+        } else if (noCaseCompare(str, "noBorder")) {
+            mode = movie_root::noBorder;
+        }
 
         log_debug("Setting scale mode");
             root.setStageScaleMode(mode);

=== modified file 'gui/gui.cpp'
--- a/gui/gui.cpp       2010-04-05 10:49:02 +0000
+++ b/gui/gui.cpp       2010-04-21 23:14:08 +0000
@@ -202,11 +202,15 @@
 }
 
 void
-Gui::quit() {
+Gui::quit()
+{
+    log_debug(__PRETTY_FUNCTION__);
+
     // Take a screenshot of the last frame if required.
     if (_screenShotter.get()) {
         _screenShotter->last();
     }
+    
     quitUI();
 }
 

=== modified file 'libcore/asobj/flash/external/ExternalInterface_as.cpp'
--- a/libcore/asobj/flash/external/ExternalInterface_as.cpp     2010-04-21 
22:07:20 +0000
+++ b/libcore/asobj/flash/external/ExternalInterface_as.cpp     2010-04-22 
00:30:22 +0000
@@ -21,6 +21,7 @@
 #include <map>
 #include <sstream>
 
+#include "StringPredicates.h"
 #include "Relay.h" // for inheritance
 #include "ExternalInterface_as.h"
 #include "as_object.h" // for inheritance
@@ -31,6 +32,7 @@
 #include "builtin_function.h" // need builtin_function
 #include "GnashException.h" // for ActionException
 #include "VM.h"
+#include "rc.h"
 #include "as_value.h"
 #include "as_object.h"
 #include "xml/XMLDocument_as.h"
@@ -38,6 +40,7 @@
 #include "namedStrings.h"
 #include "Global_as.h"
 #include "PropertyList.h"
+#include "movie_root.h"
 
 namespace gnash {
 
@@ -205,7 +208,6 @@
                   gl.createFunction(externalinterface_uToXML), swf8Flags);
     o.init_member("_unescapeXML",
                   gl.createFunction(externalinterface_uUnescapeXML), 
swf8Flags);
-
 }
 
 as_value
@@ -250,12 +252,46 @@
 }
 
 as_value
-externalinterface_available(const fn_call& /* fn */)
+externalinterface_available(const fn_call& fn)
 {
 //    GNASH_REPORT_FUNCTION;
-    
-    // Yes, Gnash supports the ExternalInterface
-    return as_value(true);
+    movie_root& m = getRoot(fn);
+    bool mode = false;
+    
+    switch (m.getAllowScriptAccess()) {
+      case movie_root::never:
+          mode = false;
+          break;
+      case movie_root::sameDomain:
+      {
+          const std::string& baseurl = m.getOriginalURL();
+          const int MAXHOSTNAMELEN = 128;
+          char hostname[MAXHOSTNAMELEN];
+          if (gethostname(hostname, MAXHOSTNAMELEN) != 0) {
+              mode = false;
+          }
+          // The hostname is empty if running the standalone Gnash from
+          // a terminal, so we can assume the default of sameDomain applies.
+          URL localPath(hostname, baseurl);
+          if (localPath.hostname().empty()) {
+              mode = true;
+          } else {
+              StringNoCaseEqual noCaseCompare;
+              if (!noCaseCompare(localPath.hostname(), hostname)) {
+                  log_security(_("ExternalInterface path %s is outside the SWF 
domain "
+                                 "%s. Cannot access this object."), localPath, 
+                               hostname);
+                  mode = false;
+              }
+          }
+          break;
+      }
+      case movie_root::always:
+          mode = true;
+          break;
+    };
+    
+    return as_value(mode);
 }
 
 as_value
@@ -265,8 +301,8 @@
     
     // No, don't pass exception up to the broswer
     if (fn.nargs) {
-        ExternalInterface_as* ptr = ensure<ThisIsNative<ExternalInterface_as> 
>(fn);
-        ptr->marshallExceptions(fn.arg(0).to_bool());
+        // ExternalInterface_as* ptr = 
ensure<ThisIsNative<ExternalInterface_as> >(fn);
+        // ptr->marshallExceptions(fn.arg(0).to_bool());
     } else {
         return as_value(true);
     }

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2010-04-19 23:10:08 +0000
+++ b/libcore/movie_root.cpp    2010-04-22 00:25:00 +0000
@@ -134,6 +134,7 @@
     _hostfd(-1),
     _quality(QUALITY_HIGH),
     _alignMode(0),
+    _allowScriptAccess(sameDomain),
     _showMenu(true),
     _scaleMode(showAll),
     _displayState(DISPLAYSTATE_NORMAL),
@@ -1262,12 +1263,24 @@
     callInterface("Stage.align");
 }
 
+/// The mode is one of never, always, with sameDomain the default
+void
+movie_root::setAllowScriptAccess(AllowScriptAccessMode mode)
+{
+    _allowScriptAccess = mode;
+}
+
+movie_root::AllowScriptAccessMode
+movie_root::getAllowScriptAccess()
+{
+    return _allowScriptAccess;
+}
+
 /// Returns a pair of enum values giving the actual alignment
 /// of the stage after align mode flags are evaluated.
 movie_root::StageAlign
 movie_root::getStageAlignment() const
 {
-
     /// L takes precedence over R. Default is centred.
     StageHorizontalAlign ha = STAGE_H_ALIGN_C;
     if (_alignMode.test(STAGE_ALIGN_L)) ha = STAGE_H_ALIGN_L;
@@ -1303,7 +1316,6 @@
     callInterface("Stage.showMenu", (_showMenu) ? "true" : "false");  //or 
this?
 }
 
-
 /// Returns the string representation of the current align mode,
 /// which must always be in the order: LTRB
 std::string
@@ -1396,7 +1408,6 @@
 
 }
 
-
 int
 movie_root::minPopulatedPriorityQueue() const
 {

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2010-04-21 19:27:23 +0000
+++ b/libcore/movie_root.h      2010-04-22 00:25:00 +0000
@@ -564,6 +564,13 @@
         STAGE_ALIGN_B
     };
 
+    /// The possibile values of AllowScriptAccess
+    enum AllowScriptAccessMode {
+       never,
+       sameDomain,
+       always
+    };
+
     /// Set the current display quality of the entire SWF.
     void setQuality(Quality q);
 
@@ -574,19 +581,22 @@
     /// of the three possible positions for each dimension.
     void setStageAlignment(short s);
 
+    void setAllowScriptAccess(AllowScriptAccessMode mode);
+    AllowScriptAccessMode getAllowScriptAccess();
+
     typedef std::pair<StageHorizontalAlign, StageVerticalAlign> StageAlign;
 
     /// Returns the current alignment of the stage (left/right/centre, top/
     /// bottom/centre) as a std::pair
     StageAlign getStageAlignment() const;
 
-       /// Returns the current value of _showMenu which instructs the gui about
-       /// how much to display in the context menu
-       bool getShowMenuState() const;
-
-       /// Sets the value of _showMenu and calls the fscommand handler for the
-       /// current gui
-       void setShowMenuState( bool state );
+    /// Returns the current value of _showMenu which instructs the gui about
+    /// how much to display in the context menu
+    bool getShowMenuState() const;
+    
+    /// Sets the value of _showMenu and calls the fscommand handler for the
+    /// current gui
+    void setShowMenuState( bool state );
 
     /// Sets the Stage object's align mode.
     void setStageScaleMode(ScaleMode sm);
@@ -605,10 +615,10 @@
 
     /// Action priority levels
     enum ActionPriorityLevel {
-
+       
         /// Init actions, Init event handlers
         apINIT=0,
-
+       
         /// Construct event handlers
         apCONSTRUCT=1,
 
@@ -1150,43 +1160,39 @@
 
     /// This is set to true if execution of scripts
     /// aborted due to action limit set or whatever else
-    bool _disableScripts;
-
-    int _processingActionLevel;
+    bool               _disableScripts;
+    int                        _processingActionLevel;
     
     /// filedescriptor to write to for host application requests
     //
     /// -1 if none
-    int _hostfd;
-    int _controlfd;
+    int                        _hostfd;
+    int                        _controlfd;
 
     /// The display quality of the entire movie.
     //
     /// This is here, not just in the Renderer, so that AS compatibility
     /// does not rely on the presence of a renderer.
-    Quality _quality;
-
-    std::bitset<4u> _alignMode;
-
-    bool _showMenu;
-    
-    ScaleMode _scaleMode;
-    
-    DisplayState _displayState;
+    Quality            _quality;
+    std::bitset<4u>    _alignMode;
+    AllowScriptAccessMode _allowScriptAccess;
+    bool               _showMenu;
+    ScaleMode          _scaleMode;
+    DisplayState       _displayState;
     
     // The maximum number of recursions e.g. when finding
     // 'super', set in the ScriptLimits tag.
-    boost::uint16_t _recursionLimit;
+    boost::uint16_t    _recursionLimit;
 
     // The timeout in seconds for script execution, in the
     // ScriptLimits tag.    
-    boost::uint16_t _timeoutLimit;
+    boost::uint16_t    _timeoutLimit;
 
     // delay between movie advancement, in milliseconds
-    unsigned int _movieAdvancementDelay;
+    unsigned int       _movieAdvancementDelay;
 
     // time of last movie advancement, in milliseconds
-    unsigned int _lastMovieAdvancement;
+    unsigned int       _lastMovieAdvancement;
 
     size_t _unnamedInstance;
 

=== modified file 'plugin/npapi/pluginScriptObject.cpp'
--- a/plugin/npapi/pluginScriptObject.cpp       2010-04-21 19:46:03 +0000
+++ b/plugin/npapi/pluginScriptObject.cpp       2010-04-21 23:14:08 +0000
@@ -166,9 +166,12 @@
     AddProperty("$version", "10,1,r999");
     // id and name appear to be the same tag, but differeing browsers access
     // one or the other, or both.
+    // name=send_this_page_swf
     AddProperty("name", "Hello World");
+    // id=send_this_page_swf
     AddProperty("id", "Hello World");
 
+    // http://s.ytimg.com/yt/swf/watch-vfl161193.swf
     AddProperty("src", "example");
     AddProperty("align", "middle");
     AddProperty("quality", "high");

=== modified file 'testsuite/actionscript.all/ExternalInterface.as'
--- a/testsuite/actionscript.all/ExternalInterface.as   2010-04-21 22:08:59 
+0000
+++ b/testsuite/actionscript.all/ExternalInterface.as   2010-04-22 00:30:22 
+0000
@@ -55,7 +55,8 @@
     fail("ExternalInterface::available() doesn't exist");
 }
 
-// this should always be true now that Gnash supports this class
+// this should always be true now that Gnash supports this class,
+// and sameDomain is the default when running standalone.
 if (EI.available == true) {
     pass("ExternalInterface::available is correct");
 } else {


reply via email to

[Prev in Thread] Current Thread [Next in Thread]