Changes of Revision 130

lightspark.spec Changed
x
 
1
@@ -20,7 +20,7 @@
2
 %bcond_without librtmp
3
 
4
 Name:           lightspark
5
-Version:        0.7.2.99+git20161230.0848
6
+Version:        0.7.2.99+git20170104.1157
7
 Release:        0
8
 Summary:        Modern, free, open-source flash player implementation
9
 License:        LGPL-3.0+
10
lightspark.tar.xz/src/CMakeLists.txt Changed
10
 
1
@@ -210,8 +210,6 @@
2
   ENDIF()
3
 
4
   PACK_EXECUTABLE(lightspark)
5
-  INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.frag DESTINATION ${LSDATADIR})
6
-  INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.vert DESTINATION ${LSDATADIR})
7
   INSTALL(TARGETS lightspark RUNTIME DESTINATION ${BINDIR})
8
   IF(UNIX)
9
     INSTALL(FILES ${PROJECT_SOURCE_DIR}/docs/man/lightspark.1 DESTINATION ${MANUAL_DIRECTORY}/man1/)
10
lightspark.tar.xz/src/backends/audio.cpp Changed
19
 
1
@@ -124,10 +124,13 @@
2
 AudioManager::AudioManager():muteAllStreams(false),sdl_available(0),mixeropened(0)
3
 {
4
    sdl_available = 0;
5
-   if (SDL_WasInit(0)) // some part of SDL already was initialized
6
-       sdl_available = !SDL_InitSubSystem ( SDL_INIT_AUDIO );
7
-   else
8
-       sdl_available = !SDL_Init ( SDL_INIT_AUDIO );
9
+   if (EngineData::sdl_needinit)
10
+   {
11
+       if (SDL_WasInit(0)) // some part of SDL already was initialized
12
+           sdl_available = !SDL_InitSubSystem ( SDL_INIT_AUDIO );
13
+       else
14
+           sdl_available = !SDL_Init ( SDL_INIT_AUDIO );
15
+   }
16
    mixeropened = 0;
17
 }
18
 void AudioManager::muteAll()
19
lightspark.tar.xz/src/backends/config.cpp Changed
34
 
1
@@ -121,21 +121,21 @@
2
 #endif
3
 
4
    //If cache dir doesn't exist, create it
5
-   path cacheDirectoryP(cacheDirectory);
6
-   if(!is_directory(cacheDirectoryP))
7
+   try
8
    {
9
-       LOG(LOG_INFO, "Cache directory does not exist, trying to create");
10
-       try
11
+       path cacheDirectoryP(cacheDirectory);
12
+       if(!is_directory(cacheDirectoryP))
13
        {
14
-           create_directories(cacheDirectoryP);
15
-       }
16
-       catch(const filesystem_error& e)
17
-       {
18
-           LOG(LOG_INFO, _("Could not create cache directory, falling back to default cache directory: ") <<
19
-                   defaultCacheDirectory);
20
-           cacheDirectory = defaultCacheDirectory;
21
+           LOG(LOG_INFO, "Cache directory does not exist, trying to create");
22
+               create_directories(cacheDirectoryP);
23
        }
24
    }
25
+   catch(const filesystem_error& e)
26
+   {
27
+       LOG(LOG_INFO, _("Could not create cache directory, falling back to default cache directory: ") <<
28
+               defaultCacheDirectory);
29
+       cacheDirectory = defaultCacheDirectory;
30
+   }
31
 
32
 #ifdef _WIN32
33
    std::string regGnashPath = readRegistryEntry("GnashPath");
34
lightspark.tar.xz/src/backends/decoder.cpp Changed
27
 
1
@@ -1076,6 +1076,7 @@
2
        //NOTE: in FFMpeg 0.7 there is av_probe_input_buffer
3
        AVProbeData probeData;
4
        probeData.filename="lightspark_stream";
5
+       probeData.mime_type=NULL;
6
        probeData.buf=new uint8_t[8192+AVPROBE_PADDING_SIZE];
7
        memset(probeData.buf,0,8192+AVPROBE_PADDING_SIZE);
8
        stream.read((char*)probeData.buf,8192);
9
@@ -1083,7 +1084,7 @@
10
        if(read!=8192)
11
            LOG(LOG_ERROR,"Not sufficient data is available from the stream:"<<read);
12
        probeData.buf_size=read;
13
-   
14
+
15
        stream.seekg(0);
16
        fmt=av_probe_input_format(&probeData,1);
17
        delete[] probeData.buf;
18
@@ -1154,7 +1155,7 @@
19
 
20
    if(audioFound)
21
    {
22
-       if (format)
23
+       if (format && (format->codec != LS_AUDIO_CODEC::CODEC_NONE))
24
            customAudioDecoder=new FFMpegAudioDecoder(format->codec,format->sampleRate,format->channels,true);
25
        else
26
 #if LIBAVFORMAT_VERSION_MAJOR > 56
27
lightspark.tar.xz/src/backends/extscriptobject.cpp Changed
13
 
1
@@ -377,9 +377,9 @@
2
    if(!synchronous)
3
    {
4
        func->incRef();
5
-       funcEvent = _MR(new (getSys()->unaccountedMemory) ExternalCallEvent(_MR(func), asArgs, argc, &result, &exceptionThrown, &exception));
6
+       funcEvent = _MR(new (func->getSystemState()->unaccountedMemory) ExternalCallEvent(_MR(func), asArgs, argc, &result, &exceptionThrown, &exception));
7
        // Add the callback function event to the VM event queue
8
-       funcWasCalled=getVm(getSys())->addEvent(NullRef,funcEvent);
9
+       funcWasCalled=getVm(func->getSystemState())->addEvent(NullRef,funcEvent);
10
        if(!funcWasCalled)
11
            funcEvent = NullRef;
12
    }
13
lightspark.tar.xz/src/backends/rendering.cpp Changed
41
 
1
@@ -276,15 +276,11 @@
2
    //Create render program
3
    uint32_t f = engineData->exec_glCreateShader_GL_FRAGMENT_SHADER();
4
    
5
-   const char *fs = NULL;
6
-   fs = dataFileRead("lightspark.frag");
7
-   if(fs==NULL)
8
-   {
9
-       LOG(LOG_ERROR,_("Shader lightspark.frag not found"));
10
-       throw RunTimeException("Fragment shader code not found");
11
-   }
12
+   // directly include shader source to avoid filesystem access
13
+   const char *fs = 
14
+#include "lightspark.frag"
15
+;
16
    engineData->exec_glShaderSource(f, 1, &fs,NULL);
17
-   free((void*)fs);
18
    uint32_t g = engineData->exec_glCreateShader_GL_VERTEX_SHADER();
19
    
20
    bool ret=true;
21
@@ -300,14 +296,11 @@
22
        throw RunTimeException("Could not compile fragment shader");
23
    }
24
 
25
-   fs = dataFileRead("lightspark.vert");
26
-   if(fs==NULL)
27
-   {
28
-       LOG(LOG_ERROR,_("Shader lightspark.vert not found"));
29
-       throw RunTimeException("Vertex shader code not found");
30
-   }
31
-   engineData->exec_glShaderSource(g, 1, &fs,NULL);
32
-   free((void*)fs);
33
+   // directly include shader source to avoid filesystem access
34
+   const char *fs2 = 
35
+#include "lightspark.vert"
36
+;
37
+   engineData->exec_glShaderSource(g, 1, &fs2,NULL);
38
 
39
    engineData->exec_glGetShaderInfoLog(g,1024,&a,str);
40
    LOG(LOG_INFO,_("Vertex shader compilation ") << str);
41
lightspark.tar.xz/src/backends/streamcache.cpp Changed
21
 
1
@@ -66,7 +66,6 @@
2
 
3
    handleAppend(buffer, length);
4
 
5
-   if (notifyLoader)
6
    {
7
        Locker locker(stateMutex);
8
        receivedLength += length;
9
@@ -175,6 +174,11 @@
10
    return new MemoryStreamCache::Reader(_MR(this));
11
 }
12
 
13
+void MemoryStreamCache::openForWriting()
14
+{
15
+   LOG(LOG_ERROR,"openForWriting not implemented in MemoryStreamCache");
16
+}
17
+
18
 MemoryStreamCache::Reader::Reader(_R<MemoryStreamCache> b) :
19
    buffer(b), chunkIndex(0), chunkStartOffset(0)
20
 {
21
lightspark.tar.xz/src/backends/streamcache.h Changed
37
 
1
@@ -43,7 +43,7 @@
2
  */
3
 class DLL_PUBLIC StreamCache : public RefCountable {
4
 protected:
5
-   StreamCache() DLL_LOCAL;
6
+   StreamCache();
7
 
8
    // stateMutex must be held while receivedLength, failed or
9
    // terminated are accessed
10
@@ -60,7 +60,7 @@
11
 
12
    // Wait until more than currentOffset bytes has been received
13
    // or until terminated
14
-   void waitForData(size_t currentOffset) DLL_LOCAL;
15
+   void waitForData(size_t currentOffset);
16
 
17
    // Derived class implements this to store received data
18
    virtual void handleAppend(const unsigned char* buffer, size_t length)=0;
19
@@ -96,6 +96,8 @@
20
    // thread). Every call returns a new, independent streambuf.
21
    // The caller must delete the returned value.
22
    virtual std::streambuf *createReader()=0;
23
+   
24
+   virtual void openForWriting() = 0;
25
 };
26
 
27
 class MemoryChunk;
28
@@ -151,6 +153,8 @@
29
    virtual void reserve(size_t expectedLength);
30
 
31
    virtual std::streambuf *createReader();
32
+   
33
+   void openForWriting();
34
 };
35
 
36
 /*
37
lightspark.tar.xz/src/lightspark.frag Changed
11
 
1
@@ -1,3 +1,4 @@
2
+R"(
3
 #ifdef GL_ES
4
 precision highp float;
5
 #endif
6
@@ -30,3 +31,4 @@
7
        gl_FragColor=(vbase*(1.0-yuv))+(val*yuv);
8
    }
9
 }
10
+)"
11
lightspark.tar.xz/src/lightspark.vert Changed
11
 
1
@@ -1,3 +1,4 @@
2
+R"(
3
 attribute vec4 ls_Color;
4
 attribute vec2 ls_Vertex;
5
 attribute vec2 ls_TexCoord;
6
@@ -18,3 +19,4 @@
7
    ls_TexCoords[0]=vec4(ls_TexCoord, 0, 1);
8
    ls_TexCoords[1]=t;
9
 }
10
+)"
11
lightspark.tar.xz/src/platforms/engineutils.cpp Changed
44
 
1
@@ -39,6 +39,7 @@
2
 uint32_t EngineData::userevent = (uint32_t)-1;
3
 Thread* EngineData::mainLoopThread = NULL;
4
 bool EngineData::mainthread_running = false;
5
+bool EngineData::sdl_needinit = true;
6
 Semaphore EngineData::mainthread_initialized(0);
7
 EngineData::EngineData() : currentPixelBuffer(0),currentPixelBufferOffset(0),currentPixelBufPtr(NULL),pixelBufferWidth(0),pixelBufferHeight(0),widget(0), width(0), height(0),needrenderthread(true),windowID(0),visual(0)
8
 {
9
@@ -108,12 +109,16 @@
10
 /* main loop handling */
11
 static void mainloop_runner()
12
 {
13
-   bool sdl_available = false;
14
-   if (SDL_WasInit(0)) // some part of SDL already was initialized
15
-       sdl_available = SDL_InitSubSystem ( SDL_INIT_VIDEO );
16
-   else
17
-       sdl_available = SDL_Init ( SDL_INIT_VIDEO );
18
-   if (sdl_available)
19
+   bool sdl_available = !EngineData::sdl_needinit;
20
+   
21
+   if (EngineData::sdl_needinit)
22
+   {
23
+       if (SDL_WasInit(0)) // some part of SDL already was initialized
24
+           sdl_available = !SDL_InitSubSystem ( SDL_INIT_VIDEO );
25
+       else
26
+           sdl_available = !SDL_Init ( SDL_INIT_VIDEO );
27
+   }
28
+   if (!sdl_available)
29
    {
30
        LOG(LOG_ERROR,"Unable to initialize SDL:"<<SDL_GetError());
31
        EngineData::mainthread_initialized.signal();
32
@@ -221,6 +226,11 @@
33
        LOG(LOG_ERROR, "copying text to clipboard failed:"<<SDL_GetError());
34
 }
35
 
36
+StreamCache *EngineData::createFileStreamCache()
37
+{
38
+   return new FileStreamCache();
39
+}
40
+
41
 bool EngineData::getGLError(uint32_t &errorCode) const
42
 {
43
    errorCode=glGetError();
44
lightspark.tar.xz/src/platforms/engineutils.h Changed
35
 
1
@@ -37,6 +37,8 @@
2
 #define LS_USEREVENT_EXEC EngineData::userevent+1
3
 #define LS_USEREVENT_QUIT EngineData::userevent+2
4
 class SystemState;
5
+class StreamCache;
6
+
7
 class DLL_PUBLIC EngineData
8
 {
9
    friend class RenderThread;
10
@@ -69,7 +71,7 @@
11
    /* you may not call getWindowForGnash and showWindow on the same EngineData! */
12
    virtual uint32_t getWindowForGnash()=0;
13
    /* Runs 'func' in the mainLoopThread */
14
-   static void runInMainThread(void (*func) (SystemState*) )
15
+   virtual void runInMainThread(SystemState* sys, void (*func) (SystemState*) )
16
    {
17
        SDL_Event event;
18
        SDL_zero(event);
19
@@ -88,6 +90,7 @@
20
    virtual void grabFocus()=0;
21
    virtual void openPageInBrowser(const tiny_string& url, const tiny_string& window)=0;
22
 
23
+   static bool sdl_needinit;
24
    static bool mainthread_running;
25
    static Semaphore mainthread_initialized;
26
    static bool startSDLMain();
27
@@ -102,6 +105,7 @@
28
    virtual void setClipboardText(const std::string txt);
29
    virtual bool getScreenData(SDL_DisplayMode* screen) = 0;
30
    virtual double getScreenDPI() = 0;
31
+   virtual StreamCache* createFileStreamCache();
32
    
33
    virtual void SwapBuffers() = 0;
34
    virtual void InitOpenGL() = 0;
35
lightspark.tar.xz/src/plugin_ppapi/plugin.cpp Changed
647
 
1
@@ -19,9 +19,8 @@
2
 
3
 
4
 // TODO
5
-// - download
6
 // - sound
7
-// - run within sandbox
8
+// - font loading
9
 // - register as separate plugin
10
 
11
 #include "version.h"
12
@@ -34,7 +33,6 @@
13
 #include <algorithm>
14
 #include <SDL2/SDL.h>
15
 #include "threading.h"
16
-#include "scripting/toplevel/JSON.h"
17
 #include "plugin_ppapi/plugin.h"
18
 #include "plugin_ppapi/ppextscriptobject.h"
19
 
20
@@ -63,6 +61,10 @@
21
 #include "ppapi/c/ppb_graphics_3d.h"
22
 #include "ppapi/c/ppb_input_event.h"
23
 #include "ppapi/c/private/ppb_flash_clipboard.h"
24
+#include "ppapi/c/ppb_file_io.h"
25
+#include "ppapi/c/ppb_file_ref.h"
26
+#include "ppapi/c/ppb_file_system.h"
27
+
28
 #include "GLES2/gl2.h"
29
 
30
 //The interpretation of texture data change with the endianness
31
@@ -93,7 +95,158 @@
32
 static const PPB_KeyboardInputEvent* g_keyboardinputevent_interface = NULL;
33
 static const PPB_WheelInputEvent* g_wheelinputevent_interface = NULL;
34
 static const PPB_Flash_Clipboard* g_flashclipboard_interface = NULL;
35
+static const PPB_FileIO* g_fileio_interface = NULL;
36
+static const PPB_FileRef* g_fileref_interface = NULL;
37
+static const PPB_FileSystem* g_filesystem_interface = NULL;
38
+
39
+
40
+
41
+ppFileStreamCache::ppFileStreamCache(ppPluginInstance* instance):cache(0),cacheref(0),writeoffset(0),m_instance(instance)
42
+{
43
+}
44
+
45
+ppFileStreamCache::~ppFileStreamCache()
46
+{
47
+   if (cache != 0)
48
+   {
49
+       g_fileio_interface->Close(cache);
50
+       g_fileref_interface->Delete(cacheref,PP_MakeCompletionCallback(NULL,NULL));
51
+   }
52
+}
53
+
54
+void ppFileStreamCache::handleAppend(const unsigned char* buffer, size_t length)
55
+{
56
+   if (cache == 0)
57
+       openCache();
58
+
59
+   int written = g_fileio_interface->Write(cache,writeoffset,(const char*)buffer,length,PP_MakeCompletionCallback(NULL,NULL));
60
+   if (written < 0)
61
+   {
62
+       LOG(LOG_ERROR,"writing cache file failed, error code:"<<written);
63
+       return;
64
+   }
65
+   writeoffset += written;
66
+}
67
+
68
+/**
69
+ * \brief Creates & opens a temporary cache file
70
+ *
71
+ * Creates a temporary cache file in /tmp and calls \c openExistingCache() with that file.
72
+ * Waits for mutex at start and releases mutex when finished.
73
+ * \throw RunTimeException Temporary file could not be created
74
+ * \throw RunTimeException Called when  the cache is already open
75
+ * \see Downloader::openExistingCache()
76
+ */
77
+void ppFileStreamCache::openCache()
78
+{
79
+   if (cache != 0)
80
+   {
81
+       markFinished(true);
82
+       throw RunTimeException("ppFileStreamCache::openCache called twice");
83
+   }
84
+
85
+   //Create a temporary file(name)
86
+   
87
+   cacheref = m_instance->createCacheFileRef();
88
+   cache = g_fileio_interface->Create(m_instance->getFileSystem());
89
+   int res = g_fileio_interface->Open(cache,cacheref,PP_FileOpenFlags::PP_FILEOPENFLAG_READ|PP_FileOpenFlags::PP_FILEOPENFLAG_WRITE,PP_MakeCompletionCallback(NULL,NULL));
90
+   if (res != PP_OK)
91
+   {
92
+       LOG(LOG_ERROR,"opening cache file failed, error code:"<<res);
93
+       cache = 0;
94
+   }
95
+
96
+}
97
+
98
+void ppFileStreamCache::openForWriting()
99
+{
100
+   if (cache != 0)
101
+       return;
102
+   openCache();
103
+}
104
+
105
+bool ppFileStreamCache::waitForCache()
106
+{
107
+   if (cache != 0)
108
+       return true;
109
+
110
+   // Cache file will be opened when the first byte is received
111
+   waitForData(0);
112
 
113
+   return cache != 0;
114
+}
115
+
116
+std::streambuf *ppFileStreamCache::createReader()
117
+{
118
+   if (!waitForCache())
119
+   {
120
+       LOG(LOG_ERROR,"could not open cache file");
121
+       return NULL;
122
+   }
123
+
124
+   incRef();
125
+   ppFileStreamCache::ppFileStreamCacheReader *fbuf = new ppFileStreamCache::ppFileStreamCacheReader(_MR(this));
126
+   return fbuf;
127
+}
128
+
129
+ppFileStreamCache::ppFileStreamCacheReader::ppFileStreamCacheReader(_R<ppFileStreamCache> b) : curpos(-1),buffer(b)
130
+{
131
+}
132
+
133
+int ppFileStreamCache::ppFileStreamCacheReader::underflow()
134
+{
135
+   if (!buffer->hasTerminated())
136
+       buffer->waitForData(seekoff(0, ios_base::cur, ios_base::in));
137
+
138
+   return streambuf::underflow();
139
+}
140
+
141
+streamsize ppFileStreamCache::ppFileStreamCacheReader::xsgetn(char* s, streamsize n)
142
+{
143
+   streamsize read= g_fileio_interface->Read(buffer->cache,curpos,s,n,PP_MakeCompletionCallback(NULL,NULL));
144
+   curpos += read;
145
+   // If not enough data was available, wait for writer
146
+   while (read < n)
147
+   {
148
+       buffer->waitForData(seekoff(0, ios_base::cur, ios_base::in));
149
+
150
+       streamsize b = g_fileio_interface->Read(buffer->cache,curpos,s+read,n-read,PP_MakeCompletionCallback(NULL,NULL));
151
+       curpos += b;
152
+
153
+       // No more data after waiting, this must be EOF
154
+       if (b == 0)
155
+           return read;
156
+
157
+       read += b;
158
+   }
159
+
160
+   return read;
161
+}
162
+
163
+streampos ppFileStreamCache::ppFileStreamCacheReader::seekoff(streamoff off, ios_base::seekdir way, ios_base::openmode which)
164
+{
165
+   switch (way)
166
+   {
167
+       case ios_base::beg:
168
+           curpos = off;
169
+           break;
170
+       case ios_base::cur:
171
+           curpos += off;
172
+           break;
173
+       case ios_base::end:
174
+           curpos = buffer->getReceivedLength() + off;
175
+           break;
176
+       default:
177
+           break;
178
+   }
179
+   return curpos;
180
+}
181
+
182
+streampos ppFileStreamCache::ppFileStreamCacheReader::seekpos(streampos sp, ios_base::openmode which)
183
+{
184
+   curpos = sp;
185
+   return curpos;
186
+}
187
 
188
 
189
 ppVariantObject::ppVariantObject(std::map<int64_t, std::unique_ptr<ExtObject> > &objectsMap, PP_Var& other)
190
@@ -306,7 +459,7 @@
191
    return result;
192
 }
193
 
194
-ppDownloadManager::ppDownloadManager(PP_Instance _instance, SystemState *sys):instance(_instance),m_sys(sys)
195
+ppDownloadManager::ppDownloadManager(ppPluginInstance *_instance, SystemState *sys):m_instance(_instance),m_sys(sys)
196
 {
197
    type = NPAPI;
198
 }
199
@@ -328,7 +481,7 @@
200
    LOG(LOG_INFO, _("NET: PLUGIN: DownloadManager::download '") << url.getParsedURL() << 
201
            "'" << (cached ? _(" - cached") : ""));
202
    //Register this download
203
-   ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, instance, owner);
204
+   ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, m_instance, owner);
205
    addDownloader(downloader);
206
    return downloader;
207
 }
208
@@ -344,7 +497,7 @@
209
 
210
    LOG(LOG_INFO, _("NET: PLUGIN: DownloadManager::downloadWithData '") << url.getParsedURL());
211
    //Register this download
212
-   ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, data, headers, instance, owner);
213
+   ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, data, headers, m_instance, owner);
214
    addDownloader(downloader);
215
    return downloader;
216
 }
217
@@ -375,6 +528,8 @@
218
 void ppDownloader::dlStartCallback(void* userdata,int result)
219
 {
220
    ppDownloader* th = (ppDownloader*)userdata;
221
+   setTLSSys(th->m_sys);
222
+   
223
    if (result < 0)
224
    {
225
        LOG(LOG_ERROR,"download failed:"<<result<<" "<<th->getURL());
226
@@ -386,7 +541,6 @@
227
    uint32_t len;
228
    v = g_urlresponseinfo_interface->GetProperty(response,PP_URLRESPONSEPROPERTY_HEADERS);
229
    tiny_string headers = g_var_interface->VarToUtf8(v,&len);
230
-   LOG(LOG_INFO,"headers:"<<len<<" "<<headers);
231
    th->parseHeaders(headers.raw_buf(),true);
232
    
233
    if (th->isMainClipDownloader)
234
@@ -400,20 +554,23 @@
235
        
236
        th->m_sys->mainClip->setBaseURL(url);
237
    }
238
-    
239
-   struct PP_CompletionCallback cb;
240
-   cb.func = dlReadResponseCallback;
241
-   cb.flags = 0;
242
-   cb.user_data = th;
243
-   g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,cb);
244
+   if (th->hasEmptyAnswer())
245
+   {
246
+       th->setFinished();
247
+       g_urlloader_interface->Close(th->ppurlloader);
248
+       return;
249
+   }
250
+   g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,PP_MakeCompletionCallback(dlReadResponseCallback,th));
251
 }
252
 void ppDownloader::dlReadResponseCallback(void* userdata,int result)
253
 {
254
    ppDownloader* th = (ppDownloader*)userdata;
255
+   setTLSSys(th->m_sys);
256
    if (result < 0)
257
    {
258
        LOG(LOG_ERROR,"download failed:"<<result<<" "<<th->getURL()<<" "<<th->downloadedlength<<"/"<<th->getLength());
259
        th->setFailed();
260
+       g_urlloader_interface->Close(th->ppurlloader);
261
        return;
262
    }
263
    th->append(th->buffer,result);
264
@@ -421,65 +578,82 @@
265
        th->m_pluginInstance->startMainParser();
266
    th->downloadedlength += result;
267
    
268
-   if (th->downloadedlength == th->getLength())
269
+   if (result == 0)
270
    {
271
        th->setFinished();
272
-       LOG(LOG_INFO,"download done:"<<th->getURL()<<" "<<th->downloadedlength<<" "<<th->getLength());
273
+       g_urlloader_interface->Close(th->ppurlloader);
274
+       LOG_CALL("download done:"<<th->getURL()<<" "<<th->downloadedlength<<" "<<th->getLength());
275
        return;
276
    }
277
-   struct PP_CompletionCallback cb;
278
-   cb.func = dlReadResponseCallback;
279
-   cb.flags = 0;
280
-   cb.user_data = th;
281
-   g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,cb);
282
+   g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,PP_MakeCompletionCallback(dlReadResponseCallback,th));
283
 }
284
-ppDownloader::ppDownloader(const lightspark::tiny_string& _url, PP_Instance _instance, lightspark::ILoadable* owner, ppPluginInstance *ppinstance):
285
-   Downloader(_url, _MR(new MemoryStreamCache), owner),isMainClipDownloader(true),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT)
286
+void ppDownloader::dlStartDownloadCallback(void* userdata,int result)
287
 {
288
-   ppurlloader = g_urlloader_interface->Create(_instance);
289
-   g_urlloadedtrusted_interface->GrantUniversalAccess(ppurlloader);
290
-   PP_Resource pprequest_info = g_urlrequestinfo_interface->Create(_instance);
291
-   PP_Var url = g_var_interface->VarFromUtf8(_url.raw_buf(),_url.numBytes());
292
+   ppDownloader* th = (ppDownloader*)userdata;
293
+   setTLSSys(th->m_sys);
294
+   const tiny_string strurl = th->getURL();
295
+   th->ppurlloader = g_urlloader_interface->Create(th->m_pluginInstance->getppInstance());
296
+   g_urlloadedtrusted_interface->GrantUniversalAccess(th->ppurlloader);
297
+   PP_Resource pprequest_info = g_urlrequestinfo_interface->Create(th->m_pluginInstance->getppInstance());
298
+   PP_Var url = g_var_interface->VarFromUtf8(strurl.raw_buf(),strurl.numBytes());
299
    g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_URL,url);
300
    g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS,PP_MakeBool(PP_TRUE));
301
-   LOG(LOG_INFO,"constructing downloader:"<<_url);
302
-
303
-   struct PP_CompletionCallback cb;
304
-   cb.func = dlStartCallback;
305
-   cb.flags = 0;
306
-   cb.user_data = this;
307
    
308
-   int res = g_urlloader_interface->Open(ppurlloader,pprequest_info,cb);
309
+   if (th->data.size() > 0)
310
+   {
311
+       PP_Var v = g_var_interface->VarFromUtf8("POST",4);
312
+       g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_METHOD,v);
313
+       g_urlrequestinfo_interface->AppendDataToBody(pprequest_info,&th->data.front(),th->data.size());
314
+   }
315
+   LOG_CALL("starting download:"<<th->data.size()<<" "<<strurl);
316
+
317
+   int res = g_urlloader_interface->Open(th->ppurlloader,pprequest_info,PP_MakeCompletionCallback(dlStartCallback,th));
318
    if (res != PP_OK_COMPLETIONPENDING)
319
-       LOG(LOG_ERROR,"url opening failed:"<<res<<" "<<_url);
320
+       LOG(LOG_ERROR,"url opening failed:"<<res<<" "<<strurl);
321
+}
322
+void ppDownloader::startDownload()
323
+{
324
+   if (!g_core_interface->IsMainThread())
325
+       g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(dlStartDownloadCallback,this),0);
326
+   else
327
+       dlStartDownloadCallback(this,0);
328
+   
329
+}
330
+ppDownloader::ppDownloader(const lightspark::tiny_string& _url, lightspark::ILoadable* owner, ppPluginInstance *ppinstance):
331
+   Downloader(_url, _MR(new MemoryStreamCache), owner),isMainClipDownloader(true),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT)
332
+{
333
+   startDownload();
334
 }
335
 
336
-ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache, PP_Instance _instance, lightspark::ILoadable* owner):
337
-   Downloader(_url, _cache, owner),isMainClipDownloader(false),m_sys(NULL),m_pluginInstance(NULL),downloadedlength(0),state(INIT)
338
+ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache, ppPluginInstance *ppinstance, lightspark::ILoadable* owner):
339
+   Downloader(_url, _cache, owner),isMainClipDownloader(false),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT)
340
 {
341
-   LOG(LOG_ERROR,"Download constructor2 not implemented");
342
-   ppurlloader = g_urlloader_interface->Create(_instance);
343
+   startDownload();
344
 }
345
 
346
 ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache,
347
        const std::vector<uint8_t>& _data,
348
-       const std::list<tiny_string>& headers, PP_Instance _instance, lightspark::ILoadable* owner):
349
-   Downloader(_url, _cache, _data, headers, owner),isMainClipDownloader(false),m_sys(NULL),m_pluginInstance(NULL),downloadedlength(0),state(INIT)
350
+       const std::list<tiny_string>& headers, ppPluginInstance *ppinstance, lightspark::ILoadable* owner):
351
+   Downloader(_url, _cache, _data, headers, owner),isMainClipDownloader(false),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT)
352
 {
353
-   LOG(LOG_ERROR,"Download constructor3 not implemented");
354
-   ppurlloader = g_urlloader_interface->Create(_instance);
355
+   startDownload();
356
+}
357
+void openfilesystem_callback(void* userdata,int result)
358
+{
359
+   LOG(LOG_INFO,"filesystem opened");
360
 }
361
-
362
 ppPluginInstance::ppPluginInstance(PP_Instance instance, int16_t argc, const char *argn[], const char *argv[]) : 
363
    m_ppinstance(instance),
364
    mainDownloaderStreambuf(NULL),mainDownloaderStream(NULL),
365
    mainDownloader(NULL),
366
    m_pt(NULL)
367
 {
368
+   m_cachefilesystem = g_filesystem_interface->Create(instance,PP_FileSystemType::PP_FILESYSTEMTYPE_LOCALTEMPORARY);
369
+   m_cachefilename = 0;
370
+   g_filesystem_interface->Open(m_cachefilesystem, 1024*1024,PP_MakeCompletionCallback(openfilesystem_callback,NULL));
371
    m_last_size.width = 0;
372
    m_last_size.height = 0;
373
    m_graphics = 0;
374
-   LOG(LOG_INFO, "Lightspark version " << VERSION << " Copyright 2009-2013 Alessandro Pignotti and others");
375
    setTLSSys( NULL );
376
    m_sys=new lightspark::SystemState(0, lightspark::SystemState::FLASH);
377
    //Files running in the plugin have REMOTE sandbox
378
@@ -508,10 +682,11 @@
379
    }
380
    if (!swffile.empty())
381
    {
382
-       m_sys->downloadManager=new ppDownloadManager(m_ppinstance,m_sys);
383
+       m_sys->downloadManager=new ppDownloadManager(this,m_sys);
384
    
385
-       EngineData::startSDLMain();
386
-       mainDownloader=new ppDownloader(swffile,m_ppinstance,m_sys->mainClip->loaderInfo.getPtr(),this);
387
+       //EngineData::startSDLMain();
388
+       EngineData::mainthread_running = true;
389
+       mainDownloader=new ppDownloader(swffile,m_sys->mainClip->loaderInfo.getPtr(),this);
390
        // loader is notified through parsethread
391
        mainDownloader->getCache()->setNotifyLoader(false);
392
    }
393
@@ -527,6 +702,13 @@
394
    
395
 }
396
 
397
+PP_Resource ppPluginInstance::createCacheFileRef()
398
+{
399
+   char filenamebuf[100];
400
+   sprintf(filenamebuf,"/tmp%d",++m_cachefilename);
401
+   return g_fileref_interface->Create(getFileSystem(),filenamebuf);
402
+}
403
+
404
 ppPluginInstance::~ppPluginInstance()
405
 {
406
    //Shutdown the system
407
@@ -553,12 +735,13 @@
408
 void swapbuffer_callback(void* userdata,int result)
409
 {
410
    ppPluginEngineData* data = (ppPluginEngineData*)userdata;
411
-   RELEASE_WRITE(data->inRendering,false);
412
+   data->swapbuffer_rendering.signal();
413
 }
414
 
415
 
416
 void ppPluginInstance::handleResize(PP_Resource view)
417
 {
418
+   setTLSSys(m_sys);
419
    struct PP_Rect position;
420
    if (g_view_interface->GetRect(view, &position) == PP_FALSE)
421
    {
422
@@ -587,11 +770,6 @@
423
            g_graphics_3d_interface->ResizeBuffers(m_graphics,position.size.width, position.size.height);
424
            m_sys->getRenderThread()->SetEngineData(m_sys->getEngineData());
425
            m_sys->getRenderThread()->init();
426
-           struct PP_CompletionCallback cb;
427
-           cb.func = swapbuffer_callback;
428
-           cb.flags = 0;
429
-           cb.user_data = m_sys->getEngineData();
430
-           g_graphics_3d_interface->SwapBuffers(m_graphics,cb);
431
        }
432
        else
433
        {
434
@@ -750,6 +928,7 @@
435
 
436
 PP_Bool ppPluginInstance::handleInputEvent(PP_Resource input_event)
437
 {
438
+   setTLSSys(m_sys);
439
    SDL_Event ev;
440
    switch (g_inputevent_interface->GetType(input_event))
441
    {
442
@@ -858,14 +1037,11 @@
443
 }
444
 void ppPluginInstance::executeScriptAsync(ExtScriptObject::HOST_CALL_DATA *data)
445
 {
446
-   struct PP_CompletionCallback cb;
447
-   cb.func = executescript_callback;
448
-   cb.flags = 0;
449
-   cb.user_data = data;
450
-   g_core_interface->CallOnMainThread(0,cb,0);
451
+   g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(executescript_callback,data),0);
452
 }
453
 bool ppPluginInstance::executeScript(const std::string script, const ExtVariant **args, uint32_t argc, ASObject **result)
454
 {
455
+   setTLSSys(m_sys);
456
    PP_Var scr = g_var_interface->VarFromUtf8(script.c_str(),script.length());
457
    PP_Var exception = PP_MakeUndefined();
458
    PP_Var func = g_instance_private_interface->ExecuteScript(m_ppinstance,scr,&exception);
459
@@ -944,6 +1120,8 @@
460
 
461
 static bool PPP_Class_HasProperty(void* object,struct PP_Var name,struct PP_Var* exception)
462
 {
463
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
464
+   LOG_CALL("PPP_Class_HasProperty");
465
    uint32_t len;
466
    switch (name.type)
467
    {
468
@@ -960,6 +1138,8 @@
469
 }
470
 static bool PPP_Class_HasMethod(void* object,struct PP_Var name,struct PP_Var* exception)
471
 {
472
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
473
+   LOG_CALL("PPP_Class_Method");
474
    uint32_t len;
475
    switch (name.type)
476
    {
477
@@ -975,6 +1155,8 @@
478
 }
479
 static struct PP_Var PPP_Class_GetProperty(void* object,struct PP_Var name,struct PP_Var* exception)
480
 {
481
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
482
+   LOG_CALL("PPP_Class_GetProperty");
483
    ExtVariant v;
484
    uint32_t len;
485
    switch (name.type)
486
@@ -996,6 +1178,8 @@
487
 }
488
 static void PPP_Class_GetAllPropertyNames(void* object,uint32_t* property_count,struct PP_Var** properties,struct PP_Var* exception)
489
 {
490
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
491
+   LOG_CALL("PPP_Class_GetAllPropertyNames");
492
    ExtIdentifier** ids = NULL;
493
    bool success = ((ppExtScriptObject*)object)->enumerate(&ids, property_count);
494
    if(success)
495
@@ -1027,6 +1211,8 @@
496
 
497
 static void PPP_Class_SetProperty(void* object,struct PP_Var name,struct PP_Var value,struct PP_Var* exception)
498
 {
499
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
500
+   LOG_CALL("PPP_Class_SetProperty");
501
    uint32_t len;
502
    std::map<int64_t, std::unique_ptr<ExtObject>> objectsMap;
503
    switch (name.type)
504
@@ -1045,6 +1231,8 @@
505
 
506
 static void PPP_Class_RemoveProperty(void* object,struct PP_Var name,struct PP_Var* exception)
507
 {
508
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
509
+   LOG_CALL("PPP_Class_RemoveProperty");
510
    uint32_t len;
511
    switch (name.type)
512
    {
513
@@ -1062,6 +1250,7 @@
514
 
515
 static struct PP_Var PPP_Class_Call(void* object,struct PP_Var name,uint32_t argc,struct PP_Var* argv,struct PP_Var* exception)
516
 {
517
+   setTLSSys(((ppExtScriptObject*)object)->getSystemState());
518
    PP_Var objResult = PP_MakeUndefined();
519
    uint32_t len;
520
    ExtIdentifier method_name;
521
@@ -1077,6 +1266,7 @@
522
            LOG(LOG_NOT_IMPLEMENTED,"PPP_Class_Call for method name type "<<(int)name.type);
523
            return PP_MakeUndefined();
524
    }
525
+   LOG_CALL("PPP_Class_Call:"<<((ppExtScriptObject*)object)->getInstance()->getSystemState()<<" "<< method_name.getString());
526
    std::map<int64_t, std::unique_ptr<ExtObject>> objectsMap;
527
    const ExtVariant** objArgs = g_newa(const ExtVariant*,argc);
528
    for (uint32_t i = 0; i < argc; i++)
529
@@ -1085,6 +1275,7 @@
530
    }
531
    ((ppExtScriptObject*)object)->invoke(method_name,argc,objArgs,&objResult);
532
        
533
+   LOG_CALL("PPP_Class_Call done:"<<method_name.getString());
534
    return objResult;
535
 }
536
 
537
@@ -1169,6 +1360,7 @@
538
            Log::redirect(envvar);
539
        
540
        Log::setLogLevel(log_level);
541
+       EngineData::sdl_needinit = false;
542
        lightspark::SystemState::staticInit();
543
        
544
        LOG(LOG_INFO, "Lightspark version " << VERSION << " Copyright 2009-2013 Alessandro Pignotti and others");
545
@@ -1190,6 +1382,9 @@
546
        g_keyboardinputevent_interface = (const PPB_KeyboardInputEvent*)get_browser_interface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
547
        g_wheelinputevent_interface = (const PPB_WheelInputEvent*)get_browser_interface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
548
        g_flashclipboard_interface = (const PPB_Flash_Clipboard*)get_browser_interface(PPB_FLASH_CLIPBOARD_INTERFACE);
549
+       g_fileio_interface = (const PPB_FileIO*)get_browser_interface(PPB_FILEIO_INTERFACE);
550
+       g_fileref_interface = (const PPB_FileRef*)get_browser_interface(PPB_FILEREF_INTERFACE);
551
+       g_filesystem_interface = (const PPB_FileSystem*)get_browser_interface(PPB_FILESYSTEM_INTERFACE);
552
        
553
        if (!g_core_interface ||
554
                !g_instance_interface || 
555
@@ -1207,7 +1402,10 @@
556
                !g_mouseinputevent_interface ||
557
                !g_keyboardinputevent_interface ||
558
                !g_wheelinputevent_interface ||
559
-               !g_flashclipboard_interface)
560
+               !g_flashclipboard_interface ||
561
+               !g_fileio_interface ||
562
+               !g_fileref_interface ||
563
+               !g_filesystem_interface)
564
        {
565
            LOG(LOG_ERROR,"get_browser_interface failed:"
566
                << g_core_interface <<" "
567
@@ -1226,7 +1424,10 @@
568
                << g_mouseinputevent_interface<<" "
569
                << g_keyboardinputevent_interface<<" "
570
                << g_wheelinputevent_interface<<" "
571
-               << g_flashclipboard_interface);
572
+               << g_flashclipboard_interface<<" "
573
+               << g_fileio_interface<<" "
574
+               << g_fileref_interface<<" "
575
+               << g_filesystem_interface);
576
            return PP_ERROR_NOINTERFACE;
577
        }
578
        return PP_OK;
579
@@ -1272,6 +1473,30 @@
580
 // return instance->mWindow;
581
    return 0;
582
 }
583
+struct userevent_callbackdata
584
+{
585
+   void (*func) (SystemState*);
586
+   SystemState* sys;
587
+};
588
+
589
+void exec_ppPluginEngineData_callback(void* userdata,int result)
590
+{
591
+   userevent_callbackdata* data= (userevent_callbackdata*)userdata;
592
+   data->func(data->sys);
593
+   delete data;
594
+}
595
+void ppPluginEngineData::runInMainThread(SystemState* sys, void (*func) (SystemState*) )
596
+{
597
+   userevent_callbackdata* ue = new userevent_callbackdata;
598
+   ue->func=func;
599
+   ue->sys=sys;
600
+   if (!g_core_interface->IsMainThread())
601
+   {
602
+       g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(exec_ppPluginEngineData_callback,ue),0);
603
+   }
604
+   else
605
+       exec_ppPluginEngineData_callback(ue,0);
606
+}
607
 
608
 void ppPluginEngineData::openPageInBrowser(const tiny_string& url, const tiny_string& window)
609
 {
610
@@ -1316,28 +1541,23 @@
611
    return 96.0;
612
 }
613
 
614
+StreamCache *ppPluginEngineData::createFileStreamCache()
615
+{
616
+   return new ppFileStreamCache(instance);
617
+}
618
+
619
 void swapbuffer_ppPluginEngineData_callback(void* userdata,int result)
620
 {
621
    ppPluginEngineData* data = (ppPluginEngineData*)userdata;
622
-   if (ACQUIRE_READ(data->inRendering))
623
-       return;
624
-   RELEASE_WRITE(data->inRendering,true);
625
-   struct PP_CompletionCallback cb;
626
-   cb.func = swapbuffer_callback;
627
-   cb.flags = 0;
628
-   cb.user_data = userdata;
629
-   g_graphics_3d_interface->SwapBuffers(data->getGraphics(),cb);
630
+   g_graphics_3d_interface->SwapBuffers(data->getGraphics(),PP_MakeCompletionCallback(swapbuffer_callback,userdata));
631
    
632
 }
633
 void ppPluginEngineData::SwapBuffers()
634
 {
635
    if (!g_core_interface->IsMainThread())
636
    {
637
-       struct PP_CompletionCallback cb;
638
-       cb.func = swapbuffer_ppPluginEngineData_callback;
639
-       cb.flags = 0;
640
-       cb.user_data = this;
641
-       g_core_interface->CallOnMainThread(0,cb,0);
642
+       g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(swapbuffer_ppPluginEngineData_callback,this),0);
643
+       swapbuffer_rendering.wait();
644
    }
645
    else
646
        swapbuffer_ppPluginEngineData_callback(this,0);
647
lightspark.tar.xz/src/plugin_ppapi/plugin.h Changed
136
 
1
@@ -4,20 +4,59 @@
2
 #include "swf.h"
3
 #include "ppapi/c/ppp_instance.h"
4
 #include "ppapi/c/pp_var.h"
5
+#include "ppapi/c/pp_resource.h"
6
 
7
 namespace lightspark
8
 {
9
-
10
 class ppDownloader;
11
 class ppPluginInstance;
12
 
13
+
14
+class ppFileStreamCache : public StreamCache {
15
+private:
16
+   class ppFileStreamCacheReader : public std::streambuf {
17
+   private:
18
+       std::streampos curpos;
19
+       _R<ppFileStreamCache> buffer;
20
+       virtual int underflow();
21
+       virtual std::streamsize xsgetn(char* s, std::streamsize n);
22
+       
23
+       std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,std::ios_base::openmode which);
24
+       std::streampos seekpos (std::streampos sp, std::ios_base::openmode which);
25
+   public:
26
+       ppFileStreamCacheReader(_R<ppFileStreamCache> buffer);
27
+   };
28
+
29
+   //Cache filename
30
+   PP_Resource cache;
31
+   PP_Resource cacheref;
32
+   int64_t writeoffset;
33
+   ppPluginInstance* m_instance;
34
+
35
+   void openCache();
36
+   void openExistingCache(const tiny_string& filename, bool forWriting=true);
37
+
38
+   // Block until the cache file is opened by the writer stream
39
+   bool waitForCache();
40
+
41
+   virtual void handleAppend(const unsigned char* buffer, size_t length);
42
+
43
+public:
44
+   ppFileStreamCache(ppPluginInstance* instance);
45
+   virtual ~ppFileStreamCache();
46
+
47
+   virtual std::streambuf *createReader();
48
+
49
+   void openForWriting();
50
+};
51
+
52
 class ppDownloadManager: public StandaloneDownloadManager
53
 {
54
 private:
55
-   PP_Instance instance;
56
+   ppPluginInstance* m_instance;
57
    SystemState* m_sys;
58
 public:
59
-   ppDownloadManager(PP_Instance _instance,SystemState* sys);
60
+   ppDownloadManager(ppPluginInstance* _instance,SystemState* sys);
61
    Downloader* download(const URLInfo& url,
62
                     _R<StreamCache> cache,
63
                     ILoadable* owner);
64
@@ -39,14 +78,16 @@
65
    
66
    static void dlStartCallback(void* userdata,int result);
67
    static void dlReadResponseCallback(void* userdata,int result);
68
+   static void dlStartDownloadCallback(void* userdata,int result);
69
+   void startDownload();
70
 public:
71
    enum STATE { INIT=0, STREAM_DESTROYED, ASYNC_DESTROY };
72
    STATE state;
73
    //Constructor used for the main file
74
-   ppDownloader(const tiny_string& _url, PP_Instance _instance, ILoadable* owner, ppPluginInstance* ppinstance);
75
-   ppDownloader(const tiny_string& _url, _R<StreamCache> cache, PP_Instance _instance, ILoadable* owner);
76
+   ppDownloader(const tiny_string& _url, ILoadable* owner, ppPluginInstance* ppinstance);
77
+   ppDownloader(const tiny_string& _url, _R<StreamCache> cache, ppPluginInstance* ppinstance, ILoadable* owner);
78
    ppDownloader(const tiny_string& _url, _R<StreamCache> cache, const std::vector<uint8_t>& _data,
79
-           const std::list<tiny_string>& headers, PP_Instance _instance, ILoadable* owner);
80
+           const std::list<tiny_string>& headers, ppPluginInstance* ppinstance, ILoadable* owner);
81
 };
82
 
83
 class ppVariantObject : public ExtVariant
84
@@ -72,11 +113,14 @@
85
    PP_Instance m_ppinstance;
86
    struct PP_Size m_last_size;
87
    PP_Resource m_graphics;
88
+   PP_Resource m_cachefilesystem;
89
+   ATOMIC_INT32(m_cachefilename);
90
    SystemState* m_sys;
91
    std::streambuf *mainDownloaderStreambuf;
92
    std::istream mainDownloaderStream;
93
    ppDownloader* mainDownloader;
94
    ParseThread* m_pt;
95
+   
96
 public:
97
    ppPluginInstance(PP_Instance instance, int16_t argc,const char* argn[],const char* argv[]);
98
    virtual ~ppPluginInstance();
99
@@ -87,6 +131,8 @@
100
    SystemState* getSystemState() const { return m_sys;}
101
    void startMainParser();
102
    PP_Instance getppInstance() { return m_ppinstance; }
103
+   PP_Resource getFileSystem() { return m_cachefilesystem; }
104
+   PP_Resource createCacheFileRef();
105
 };
106
 
107
 class ppPluginEngineData: public EngineData
108
@@ -95,8 +141,8 @@
109
    ppPluginInstance* instance;
110
 public:
111
    SystemState* sys;
112
-   ACQUIRE_RELEASE_FLAG(inRendering);
113
-   ppPluginEngineData(ppPluginInstance* i, uint32_t w, uint32_t h,SystemState* _sys) : EngineData(), instance(i),sys(_sys),inRendering(false)
114
+   Semaphore swapbuffer_rendering;
115
+   ppPluginEngineData(ppPluginInstance* i, uint32_t w, uint32_t h,SystemState* _sys) : EngineData(), instance(i),sys(_sys),swapbuffer_rendering(0)
116
    {
117
        width = w;
118
        height = h;
119
@@ -106,6 +152,7 @@
120
    void stopMainDownload();
121
    bool isSizable() const { return false; }
122
    uint32_t getWindowForGnash();
123
+   void runInMainThread(SystemState* sys, void (*func) (SystemState*) );
124
    /* must be called within mainLoopThread */
125
    SDL_Window* createWidget(uint32_t w,uint32_t h);
126
    /* must be called within mainLoopThread */
127
@@ -114,6 +161,8 @@
128
    void setClipboardText(const std::string txt);
129
    bool getScreenData(SDL_DisplayMode* screen);
130
    double getScreenDPI();
131
+   StreamCache* createFileStreamCache();
132
+   
133
    void SwapBuffers();
134
    void InitOpenGL();
135
    void DeinitOpenGL();
136
lightspark.tar.xz/src/scripting/flash/net/flashnet.cpp Changed
28
 
1
@@ -1330,7 +1330,7 @@
2
    // Parameter Null means data is generated by calls to "appendBytes"
3
    if (args[0]->is<Null>())
4
    {
5
-       th->datagenerationfile = new FileStreamCache;
6
+       th->datagenerationfile = th->getSystemState()->getEngineData()->createFileStreamCache();
7
        th->datagenerationfile->openForWriting();
8
        th->streamTime=0;
9
        return NULL;
10
@@ -1393,7 +1393,7 @@
11
    }
12
    else //The URL is valid so we can start the download and add ourself as a job
13
    {
14
-       StreamCache *cache = new FileStreamCache;
15
+       StreamCache *cache = th->getSystemState()->getEngineData()->createFileStreamCache();
16
        th->downloader=getSys()->downloadManager->download(th->url, _MR(cache), NULL);
17
        th->streamTime=0;
18
        //To be decreffed in jobFence
19
@@ -1658,7 +1658,7 @@
20
        LOG(LOG_INFO,"resetBegin");
21
        if (th->datagenerationfile)
22
            delete th->datagenerationfile;
23
-       th->datagenerationfile = new FileStreamCache;
24
+       th->datagenerationfile = th->getSystemState()->getEngineData()->createFileStreamCache();
25
        th->datagenerationfile->openForWriting();
26
        th->datagenerationbuffer->setLength(0);
27
        th->datagenerationthreadstarted = false;
28
lightspark.tar.xz/src/scripting/flash/net/flashnet.h Changed
10
 
1
@@ -264,7 +264,7 @@
2
    AudioDecoder* audioDecoder;
3
    AudioStream *audioStream;
4
    // only used when in DataGenerationMode
5
-   FileStreamCache* datagenerationfile;
6
+   StreamCache* datagenerationfile;
7
    bool datagenerationthreadstarted;
8
    Mutex mutex;
9
    Mutex countermutex;
10
lightspark.tar.xz/src/swf.cpp Changed
76
 
1
@@ -268,11 +268,14 @@
2
    inputThread=new InputThread(this);
3
 
4
    EngineData::userevent = SDL_RegisterEvents(3);
5
-   SDL_Event event;
6
-   SDL_zero(event);
7
-   event.type = LS_USEREVENT_INIT;
8
-   event.user.data1 = this;
9
-   SDL_PushEvent(&event);
10
+   if (EngineData::sdl_needinit)
11
+   {
12
+       SDL_Event event;
13
+       SDL_zero(event);
14
+       event.type = LS_USEREVENT_INIT;
15
+       event.user.data1 = this;
16
+       SDL_PushEvent(&event);
17
+   }
18
 }
19
 
20
 void SystemState::setDownloadedPath(const tiny_string& p)
21
@@ -782,7 +785,7 @@
22
    }
23
 
24
    //The engines must be created in the context of the main thread
25
-   engineData->runInMainThread(&SystemState::delayedCreation);
26
+   engineData->runInMainThread(this,&SystemState::delayedCreation);
27
 
28
    //Wait for delayedCreation to finish so it is protected by our 'mutex'
29
    //Otherwise SystemState::destroy may delete this object before delayedCreation is scheduled.
30
@@ -1395,18 +1398,18 @@
31
            return;
32
        }
33
        //Check if this clip is the main clip then honour its FileAttributesTag
34
-       if(root == getSys()->mainClip)
35
+       if(root == root->getSystemState()->mainClip)
36
        {
37
-           getSys()->needsAVM2(fat->ActionScript3);
38
+           root->getSystemState()->needsAVM2(fat->ActionScript3);
39
            if(!fat->ActionScript3)
40
            {
41
-                                delete fat;
42
+               delete fat;
43
                return; /* no more parsing necessary, handled by fallback */
44
-                        }
45
+           }
46
            if(fat->UseNetwork
47
-           && getSys()->securityManager->getSandboxType() == SecurityManager::LOCAL_WITH_FILE)
48
+                   && root->getSystemState()->securityManager->getSandboxType() == SecurityManager::LOCAL_WITH_FILE)
49
            {
50
-               getSys()->securityManager->setSandboxType(SecurityManager::LOCAL_WITH_NETWORK);
51
+               root->getSystemState()->securityManager->setSandboxType(SecurityManager::LOCAL_WITH_NETWORK);
52
                LOG(LOG_INFO, _("Switched to local-with-networking sandbox by FileAttributesTag"));
53
            }
54
        }
55
@@ -1512,7 +1515,7 @@
56
                    delete tag;
57
                    break;
58
            }
59
-           if(getSys()->shouldTerminate() || threadAborting)
60
+           if(root->getSystemState()->shouldTerminate() || threadAborting)
61
                break;
62
        }
63
    }
64
@@ -1961,9 +1964,9 @@
65
 void SystemState::showMouseCursor(bool visible)
66
 {
67
    if (visible)
68
-       EngineData::runInMainThread(&EngineData::showMouseCursor);
69
+       engineData->runInMainThread(this,&EngineData::showMouseCursor);
70
    else
71
-       EngineData::runInMainThread(&EngineData::hideMouseCursor);
72
+       engineData->runInMainThread(this,&EngineData::hideMouseCursor);
73
 }
74
 
75
 void SystemState::waitRendering()
76