View | Details | Raw Unified | Return to issue 121772
Collapse All | Expand All

(-)a/main/extensions/prj/build.lst (-1 / +13 lines)
Lines 1-4 Link Here
1
ex  extensions :  officecfg  L10N:l10n rdbmaker svx SANE:sane TWAIN:twain offuh stoc ZLIB:zlib CURL:curl LIBXSLT:libxslt NULL
1
ex  extensions :  officecfg  L10N:l10n rdbmaker svx SANE:sane TWAIN:twain offuh stoc ZLIB:zlib CURL:curl LIBXSLT:libxslt MOZ:moz SO:moz_prebuilt NULL
2
2
3
ex  extensions                                  usr1    -   all ex_mkout NULL
3
ex  extensions                                  usr1    -   all ex_mkout NULL
4
ex  extensions\inc                              nmake   -   all ex_inc NULL
4
ex  extensions\inc                              nmake   -   all ex_inc NULL
Lines 22-27 ex extensions\source\config\ldap nmake - all ex_ldap ex_inc N Link Here
22
ex  extensions\source\update\feed               nmake   -   all ex_updchkfeed ex_inc NULL
22
ex  extensions\source\update\feed               nmake   -   all ex_updchkfeed ex_inc NULL
23
ex  extensions\source\update\check              nmake   -   all ex_updchk ex_inc NULL
23
ex  extensions\source\update\check              nmake   -   all ex_updchk ex_inc NULL
24
ex  extensions\source\update\ui                 nmake   -   all ex_updchkui ex_inc NULL
24
ex  extensions\source\update\ui                 nmake   -   all ex_updchkui ex_inc NULL
25
26
27
ex  extensions\source\plugin\workben            get     -   all ex_plwkb ex_inc NULL
28
ex  extensions\source\plugin\inc\plugin\win     get     -   all ex_piwi ex_inc NULL
29
ex  extensions\source\plugin\inc\plugin\unx     get     -   all ex_piux ex_inc NULL
30
ex  extensions\source\plugin\aqua               nmake   -   u   ex_plaqua ex_plbase NULL
31
ex  extensions\source\plugin\base               nmake   -   all ex_plbase ex_inc NULL
32
ex  extensions\source\plugin\win                nmake   -   w   ex_plwin ex_plbase ex_inc NULL
33
ex  extensions\source\plugin\unx                nmake   -   u   ex_plunx ex_inc NULL
34
ex  extensions\source\plugin\util               nmake   -   all ex_plutil ex_plbase ex_plunx.u ex_plwin.w ex_plaqua.u ex_inc NULL
35
36
25
ex  extensions\util                             nmake   -   all ex_util ex_preload ex_abpilot ex_dbpilots ex_logging ex_ldap ex_propctrlr ex_bib ex_oooimprovecore NULL
37
ex  extensions\util                             nmake   -   all ex_util ex_preload ex_abpilot ex_dbpilots ex_logging ex_ldap ex_propctrlr ex_bib ex_oooimprovecore NULL
26
38
27
# Fails at the moment
39
# Fails at the moment
(-)a/main/extensions/prj/d.lst (+5 lines)
Lines 50-52 mkdir: %_DEST%\xml%_EXT%\registry\spool\org\openoffice\Office\Logging Link Here
50
..\%__SRC%\misc\updchk.component %_DEST%\xml%_EXT%\updchk.component
50
..\%__SRC%\misc\updchk.component %_DEST%\xml%_EXT%\updchk.component
51
..\%__SRC%\misc\updchk.uno.component %_DEST%\xml%_EXT%\updchk.uno.component
51
..\%__SRC%\misc\updchk.uno.component %_DEST%\xml%_EXT%\updchk.uno.component
52
..\%__SRC%\misc\xmx.component %_DEST%\xml%_EXT%\xmx.component
52
..\%__SRC%\misc\xmx.component %_DEST%\xml%_EXT%\xmx.component
53
54
55
..\%__SRC%\bin\pluginapp.bin %_DEST%\bin%_EXT%\pluginapp.bin
56
..\%__SRC%\misc\pl.component %_DEST%\xml%_EXT%\pl.component
57
(-)a/main/extensions/source/plugin/aqua/macmgr.cxx (+648 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
#include "rtl/ustrbuf.hxx"
25
#include "rtl/strbuf.hxx"
26
27
#include "plugin/impl.hxx"
28
#include "osl/file.h"
29
#include "osl/module.hxx"
30
31
using namespace rtl;
32
using rtl::OUStringBuffer;
33
using rtl::OUStringToOString;
34
using rtl::OString;
35
using rtl::OStringBuffer;
36
using rtl::OStringToOUString
37
38
using namespace std;
39
using namespace com::sun::star::uno;
40
using namespace com::sun::star::plugin;
41
42
namespace plugstringhelper
43
{
44
    
45
OUString getString( CFStringRef i_xString )
46
{
47
    OUStringBuffer aBuf;
48
    if( i_xString )
49
    {
50
        CFIndex nChars = CFStringGetLength( i_xString );
51
        CFRange aRange = { 0, nChars };
52
        aBuf.setLength( nChars );
53
        CFStringGetCharacters( i_xString, aRange, static_cast< UniChar* >(const_cast<sal_Unicode*>(aBuf.getStr())) );
54
    }
55
    return aBuf.makeStringAndClear();
56
}
57
58
OUString getString( CFURLRef i_xURL )
59
{
60
    CFStringRef xString = CFURLGetString( i_xURL );
61
    return getString( xString );
62
}
63
64
CFMutableStringRef createString( const OUString& i_rString )
65
{
66
    CFMutableStringRef xString = CFStringCreateMutable( NULL, 0 );
67
    if( xString )
68
        CFStringAppendCharacters( xString, i_rString.getStr(), i_rString.getLength() );
69
    return xString;
70
}
71
72
CFURLRef createURL( const OUString& i_rString )
73
{
74
    
75
    CFMutableStringRef xMutableString = createString( i_rString );
76
    CFURLRef xURL = CFURLCreateWithString( NULL, xMutableString, NULL );
77
    CFRelease( xMutableString );
78
    return xURL;
79
}
80
81
OUString getURLFromPath( const OUString& i_rPath )
82
{
83
    CFMutableStringRef xMutableString = createString( i_rPath );
84
    CFURLRef xURL = CFURLCreateWithFileSystemPath( NULL, xMutableString, kCFURLPOSIXPathStyle, true );
85
    CFRelease( xMutableString );
86
    CFStringRef xString = CFURLGetString( xURL );
87
    OUString aRet = getString( xString );
88
    CFRelease( xURL );
89
    return aRet;
90
}
91
92
CFURLRef createURLFromPath( const OUString& i_rPath )
93
{
94
    CFMutableStringRef xMutableString = createString( i_rPath );
95
    CFURLRef xURL = CFURLCreateWithFileSystemPath( NULL, xMutableString, kCFURLPOSIXPathStyle, true );
96
    return xURL;
97
}
98
99
OUString CFURLtoOSLURL( CFURLRef i_xURL )
100
{
101
    // make URL absolute
102
    CFURLRef xAbsURL = CFURLCopyAbsoluteURL( i_xURL );
103
    // copy system path
104
    CFStringRef xSysPath = CFURLCopyFileSystemPath( xAbsURL ? xAbsURL : i_xURL, kCFURLPOSIXPathStyle );
105
    if( xAbsURL )
106
        CFRelease( xAbsURL );
107
    OUString aSysPath( getString( xSysPath ) );
108
    CFRelease( xSysPath );
109
    OUString aFileURL;
110
    osl_getFileURLFromSystemPath( aSysPath.pData, &aFileURL.pData );
111
    return aFileURL;
112
}
113
114
}
115
116
using namespace plugstringhelper;
117
118
static int parsePlist( CFBundleRef i_xBundle, const OUString& i_rBundleURL , list< PluginDescription* >& io_rDescriptions )
119
{
120
    CFTypeRef xMimeDict = CFBundleGetValueForInfoDictionaryKey( i_xBundle, CFSTR("WebPluginMIMETypes"));
121
    int nMimetypes = 0;
122
    if( xMimeDict == 0 ||
123
        CFGetTypeID(xMimeDict) != CFDictionaryGetTypeID() ||
124
        (nMimetypes = CFDictionaryGetCount( static_cast<CFDictionaryRef>(xMimeDict))) <= 0 )
125
    {
126
        return 0;
127
    }
128
    
129
    // prepare an array of key and value refs
130
    std::vector< CFTypeRef > aKeys( nMimetypes, CFTypeRef(NULL) );
131
    std::vector< CFTypeRef > aValues( nMimetypes, CFTypeRef(NULL) );
132
    CFDictionaryGetKeysAndValues(static_cast<CFDictionaryRef>(xMimeDict), &aKeys[0], &aValues[0] );
133
    
134
    int nAdded = 0;
135
    for( int i = 0; i < nMimetypes; i++ )
136
    {
137
        // get the mimetype
138
        CFTypeRef xKey = aKeys[i];
139
        if( ! xKey || CFGetTypeID(xKey) != CFStringGetTypeID() )
140
            continue;
141
        OUString aMimetype = getString( (CFStringRef)xKey );
142
        
143
        // the correspoding value should be a dictionary
144
        CFTypeRef xDict = aValues[i];
145
        if( ! xDict || CFGetTypeID( xDict ) != CFDictionaryGetTypeID() )
146
            continue;
147
148
        // get the extension list
149
        CFTypeRef xExtArray = CFDictionaryGetValue( (CFDictionaryRef)xDict,  CFSTR("WebPluginExtensions" ) );
150
        if( !xExtArray || CFGetTypeID( xExtArray ) != CFArrayGetTypeID() )
151
            continue;
152
        
153
        OUStringBuffer aExtBuf;
154
        int nExtensions = CFArrayGetCount( (CFArrayRef)xExtArray );
155
        for( int n = 0; n < nExtensions; n++ )
156
        {
157
            CFTypeRef xExt = CFArrayGetValueAtIndex( (CFArrayRef)xExtArray, n );
158
            if( xExt && CFGetTypeID( xExt ) == CFStringGetTypeID() )
159
            {
160
                if( aExtBuf.getLength() > 0 )
161
                    aExtBuf.append( sal_Unicode(';') );
162
                OUString aExt( getString( (CFStringRef)xExt ) );
163
                if( aExt.indexOfAsciiL( "*.", 2 ) != 0 )
164
                    aExtBuf.appendAscii( "*." );
165
                aExtBuf.append( aExt );
166
            }
167
        }
168
        
169
        // get the description string
170
        CFTypeRef xDescString = CFDictionaryGetValue( (CFDictionaryRef)xDict,  CFSTR("WebPluginTypeDescription" ) );
171
        if( !xDescString || CFGetTypeID( xDescString ) != CFStringGetTypeID() )
172
            continue;
173
        OUString aDescription = getString( (CFStringRef)xDescString );
174
175
        PluginDescription* pNew = new PluginDescription;
176
        // set plugin name (path to library)
177
        pNew->PluginName	= i_rBundleURL;
178
        // set mimetype
179
        pNew->Mimetype 	= aMimetype;
180
        // set extension line
181
        pNew->Extension	= aExtBuf.makeStringAndClear();
182
        // set description
183
        pNew->Description= aDescription;
184
        
185
        io_rDescriptions.push_back( pNew );
186
        nAdded++;
187
188
#if OSL_DEBUG_LEVEL > 1
189
        fprintf( stderr,
190
                 "Inserting from PList:\n"
191
                 "    Mimetype: %s\n"
192
                 "    Extension: %s\n"
193
                 "    Description: %s\n",
194
                 OUStringToOString( pNew->Mimetype, RTL_TEXTENCODING_UTF8 ).getStr(),
195
                 OUStringToOString( pNew->Extension, RTL_TEXTENCODING_UTF8 ).getStr(),
196
                 OUStringToOString( pNew->Description, RTL_TEXTENCODING_UTF8 ).getStr()
197
                 );
198
#endif
199
        
200
    }
201
    
202
    return nAdded;
203
}
204
205
static int parseMimeString( const OUString& i_rBundleURL , list< PluginDescription* >& io_rDescriptions, const char* i_pMime )
206
{
207
    if( ! i_pMime )
208
        return 0;
209
    
210
    rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
211
    
212
    OStringBuffer aMIME;
213
    aMIME.append( i_pMime );
214
        
215
    if( aMIME.getLength() < 1 )
216
        return 0;
217
218
    OString aLine = aMIME.makeStringAndClear();
219
220
    int nAdded = 0;
221
    sal_Int32 nIndex = 0;
222
    while( nIndex != -1 )
223
    {
224
        OString aType = aLine.getToken( 0, ';', nIndex );
225
        
226
        sal_Int32 nTypeIndex = 0;
227
        OString aMimetype	= aType.getToken( 0, ':', nTypeIndex );
228
        OString aExtLine	= aType.getToken( 0, ':', nTypeIndex );
229
        if( nTypeIndex < 0 ) // ensure at least three tokens
230
            continue;
231
        OString aDesc		= aType.getToken( 0, ':', nTypeIndex );
232
        
233
        // create extension list string
234
        sal_Int32 nExtIndex = 0;
235
        OStringBuffer aExtension;
236
        while( nExtIndex != -1 )
237
        {
238
            OString aExt = aExtLine.getToken( 0, ',', nExtIndex);
239
            if( aExt.indexOf( "*." ) != 0 )
240
                aExtension.append( "*." );
241
            aExtension.append( aExt );
242
            if( nExtIndex != -1 )
243
                aExtension.append( ';' );
244
        }
245
        
246
        PluginDescription* pNew = new PluginDescription;
247
        // set plugin name (path to library)
248
        pNew->PluginName	= i_rBundleURL;
249
        // set mimetype
250
        pNew->Mimetype 	= OStringToOUString( aMimetype, aEncoding );
251
        // set extension line
252
        pNew->Extension	= OStringToOUString( aExtension.makeStringAndClear(), aEncoding );
253
        // set description
254
        pNew->Description= OStringToOUString( aDesc, aEncoding );
255
        io_rDescriptions.push_back( pNew );
256
        nAdded++;
257
        
258
#if OSL_DEBUG_LEVEL > 1
259
        fprintf( stderr,
260
                 "Inserting from mime string:\n"
261
                 "    Mimetype: %s\n"
262
                 "    Extension: %s\n"
263
                 "    Description: %s\n",
264
                 OUStringToOString( pNew->Mimetype, aEncoding ).getStr(),
265
                 OUStringToOString( pNew->Extension, aEncoding ).getStr(),
266
                 OUStringToOString( pNew->Description, aEncoding ).getStr()
267
                 );
268
#endif
269
    }
270
    return nAdded;
271
}
272
273
// this is so ugly it you want to tear your eyes out
274
static OUString GetNextPluginStringFromHandle(Handle h, short *index)
275
{
276
    char* pPascalBytes = (*h + *index);
277
    sal_uInt32 nLen = (unsigned char)pPascalBytes[0];
278
    OStringBuffer aBuf( nLen );
279
    aBuf.append( pPascalBytes+1, nLen );
280
    *index += nLen + 1;
281
    return OStringToOUString( aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
282
}
283
284
static int parseMimeResource( CFBundleRef i_xBundle,
285
                              oslModule& i_rMod,
286
                              const OUString& i_rBundleURL,
287
                              list< PluginDescription* >& io_rDescriptions )
288
{
289
    int nAdded = 0;
290
    // just to hurt our eyes more there is an alternative mimetype function plus the possibility
291
    // of a resource fork. Must be a case of think different.
292
    #if __LP64__
293
    int
294
    #else
295
    SInt16
296
    #endif
297
    xRes = 0;
298
    BPSupportedMIMETypes aMIMETypesStrangeStruct = {kBPSupportedMIMETypesStructVers_1, NULL, NULL};
299
    
300
    BP_GetSupportedMIMETypesUPP pBPGetSupp = (BP_GetSupportedMIMETypesUPP)osl_getAsciiFunctionSymbol( i_rMod, "BP_GetSupportedMIMETypes" );
301
    if( pBPGetSupp &&
302
        noErr == pBPGetSupp( &aMIMETypesStrangeStruct, 0 ) &&
303
        aMIMETypesStrangeStruct.typeStrings )
304
    {
305
        HLock( aMIMETypesStrangeStruct.typeStrings );
306
        if( aMIMETypesStrangeStruct.infoStrings )  // it's possible some plugins have infoStrings missing
307
            HLock( aMIMETypesStrangeStruct.infoStrings );
308
    }
309
    else // Try to get data from the resource fork
310
    {
311
        xRes = CFBundleOpenBundleResourceMap( i_xBundle );
312
        if( xRes > 0 )
313
        {
314
            aMIMETypesStrangeStruct.typeStrings = Get1Resource('STR#', 128);
315
            if( aMIMETypesStrangeStruct.typeStrings )
316
            {
317
                DetachResource( aMIMETypesStrangeStruct.typeStrings );
318
                HLock( aMIMETypesStrangeStruct.typeStrings );
319
                aMIMETypesStrangeStruct.infoStrings = Get1Resource('STR#', 127);
320
                if( aMIMETypesStrangeStruct.infoStrings )
321
                {
322
                    DetachResource( aMIMETypesStrangeStruct.infoStrings );
323
                    HLock( aMIMETypesStrangeStruct.infoStrings );
324
                }
325
            }
326
        }
327
    }
328
    
329
    if( aMIMETypesStrangeStruct.typeStrings && aMIMETypesStrangeStruct.infoStrings )
330
    {
331
        short nVariantCount = (**(short**)aMIMETypesStrangeStruct.typeStrings) / 2;
332
        // Fill in the info struct based on the data in the BPSupportedMIMETypes struct
333
        // this is an array of pascal string of unknown (!) encoding
334
        // whoever thought of this deserves a fair beating
335
        short mimeIndex = 2;
336
        short descriptionIndex = 2;
337
        for( int i = 0; i < nVariantCount; i++ )
338
        {
339
            OUString aMimetype = GetNextPluginStringFromHandle( aMIMETypesStrangeStruct.typeStrings, &mimeIndex );
340
            OUString aExtLine = GetNextPluginStringFromHandle( aMIMETypesStrangeStruct.typeStrings, &mimeIndex );
341
            OUString aDescription;
342
            if( aMIMETypesStrangeStruct.infoStrings )
343
                aDescription = GetNextPluginStringFromHandle( aMIMETypesStrangeStruct.infoStrings, &descriptionIndex );
344
345
            // create extension list string
346
            sal_Int32 nExtIndex = 0;
347
            OUStringBuffer aExtension;
348
            while( nExtIndex != -1 )
349
            {
350
                OUString aExt = aExtLine.getToken( 0, ',', nExtIndex);
351
                if( aExt.indexOfAsciiL( "*.", 2 ) != 0 )
352
                    aExtension.appendAscii( "*." );
353
                aExtension.append( aExt );
354
                if( nExtIndex != -1 )
355
                    aExtension.append( sal_Unicode(';') );
356
            }
357
            
358
            PluginDescription* pNew = new PluginDescription;
359
            // set plugin name (path to library)
360
            pNew->PluginName	= i_rBundleURL;
361
            // set mimetype
362
            pNew->Mimetype 	= aMimetype;
363
            // set extension line
364
            pNew->Extension	= aExtension.makeStringAndClear();
365
            // set description
366
            pNew->Description= aDescription;
367
            io_rDescriptions.push_back( pNew );
368
            nAdded++;
369
            
370
            #if OSL_DEBUG_LEVEL > 1
371
            fprintf( stderr,
372
                     "Inserting from resource:\n"
373
                     "    Mimetype: %s\n"
374
                     "    Extension: %s\n"
375
                     "    Description: %s\n",
376
                     OUStringToOString( pNew->Mimetype, RTL_TEXTENCODING_UTF8 ).getStr(),
377
                     OUStringToOString( pNew->Extension, RTL_TEXTENCODING_UTF8 ).getStr(),
378
                     OUStringToOString( pNew->Description, RTL_TEXTENCODING_UTF8 ).getStr()
379
                     );
380
            #endif
381
        }
382
    }
383
    
384
    
385
    // clean up
386
    if( aMIMETypesStrangeStruct.typeStrings )
387
    {
388
        HUnlock( aMIMETypesStrangeStruct.typeStrings );
389
        DisposeHandle( aMIMETypesStrangeStruct.typeStrings );
390
    }
391
    if( aMIMETypesStrangeStruct.infoStrings )
392
    {
393
        HUnlock( aMIMETypesStrangeStruct.infoStrings );
394
        DisposeHandle( aMIMETypesStrangeStruct.infoStrings );
395
    }
396
    if( xRes )
397
        CFBundleCloseBundleResourceMap( i_xBundle, xRes );
398
    
399
    return nAdded;
400
}
401
402
// check some known bad plugins to avoid crashes
403
static bool checkBlackList( CFBundleRef i_xBundle )
404
{
405
    OUString aBundleName;
406
    CFTypeRef bundlename = CFBundleGetValueForInfoDictionaryKey( i_xBundle, CFSTR("CFBundleName"));
407
    if( bundlename && CFGetTypeID(bundlename) == CFStringGetTypeID() )
408
        aBundleName = getString( static_cast<CFStringRef>(bundlename) );
409
410
    OUString aBundleVersion;
411
    CFTypeRef bundleversion = CFBundleGetValueForInfoDictionaryKey( i_xBundle, CFSTR("CFBundleVersion"));
412
    if( bundleversion && CFGetTypeID(bundleversion) == CFStringGetTypeID() )
413
        aBundleVersion = getString( static_cast<CFStringRef>(bundleversion) );
414
    
415
    bool bReject = false;
416
    // #i102735# VLC plugin prior to 1.0 tends to crash 
417
    if( aBundleName.equalsAscii( "VLC Plug-in" ) )
418
    {
419
        sal_Int32 nIndex = 0;
420
        OUString aMajor( aBundleVersion.getToken( 0, '.', nIndex ) );
421
        if( aMajor.toInt32() < 1 )
422
        {
423
            bReject = true;
424
        }
425
    }
426
    // #i103674# Garmin Communicator Plugin crashes
427
    else if( aBundleName.equalsAscii( "Garmin Communicator Plugin" ) )
428
    {
429
        bReject = true;
430
    }
431
    
432
    #if OSL_DEBUG_LEVEL > 1
433
    if( bReject )
434
        fprintf( stderr, "rejecting plugin \"%s\" version %s\n",
435
                 OUStringToOString( aBundleName, RTL_TEXTENCODING_UTF8 ).getStr(),
436
                 OUStringToOString( aBundleVersion, RTL_TEXTENCODING_UTF8 ).getStr()
437
                 );
438
    #endif
439
440
    return bReject;
441
}
442
443
static int getPluginDescriptions( CFBundleRef i_xBundle , list< PluginDescription* >& io_rDescriptions )
444
{
445
    int nDescriptions = 0;
446
    if( ! i_xBundle )
447
        return nDescriptions;
448
    
449
    if( checkBlackList( i_xBundle ) )
450
        return 0;
451
452
    OUString aPlugURL;
453
    CFURLRef xURL = CFBundleCopyBundleURL( i_xBundle );
454
    aPlugURL = getString( xURL );
455
    CFRelease( xURL );
456
    
457
    #if OSL_DEBUG_LEVEL > 1
458
    OUString aPlugName, aPlugDescription;
459
    CFTypeRef name = CFBundleGetValueForInfoDictionaryKey( i_xBundle, CFSTR("WebPluginName"));
460
    if( name && CFGetTypeID(name) == CFStringGetTypeID() )
461
      aPlugName = getString( static_cast<CFStringRef>(name) );
462
463
    CFTypeRef description = CFBundleGetValueForInfoDictionaryKey( i_xBundle, CFSTR("WebPluginDescription"));
464
    if( description && CFGetTypeID(description) == CFStringGetTypeID() )
465
        aPlugDescription = getString( static_cast<CFStringRef>(description) );
466
    
467
    fprintf( stderr, "URL: %s\nname: %s\ndescription: %s\n",
468
        OUStringToOString( aPlugURL, RTL_TEXTENCODING_UTF8 ).getStr(),
469
        OUStringToOString( aPlugName, RTL_TEXTENCODING_UTF8 ).getStr(),
470
        OUStringToOString( aPlugDescription, RTL_TEXTENCODING_UTF8 ).getStr()
471
        );
472
    #endif
473
    
474
    
475
    // get location of plugin library
476
    CFURLRef xLibURL = CFBundleCopyExecutableURL( i_xBundle );
477
    if( ! xLibURL )
478
        return 0;
479
    // get the file system path
480
    OUString aModuleURL( CFURLtoOSLURL( xLibURL ) );
481
    CFRelease( xLibURL );
482
    
483
    #if OSL_DEBUG_LEVEL > 1
484
    fprintf( stderr, "exec URL = %s\n", OUStringToOString( aModuleURL, RTL_TEXTENCODING_UTF8 ).getStr() );
485
    #endif
486
487
    /* TODO: originally the C++ wrapper for oslModule was used here, but that led to
488
       mysterious crashes in the event loop (pointing to heap corruption). Why using
489
       the C style oslModule should fix this is completely unknown. It may be that
490
       we have just hidden the heap corruption a little more.
491
    */
492
    oslModule aMod = osl_loadModule( aModuleURL.pData, SAL_LOADMODULE_DEFAULT );
493
    if( ! aMod )
494
        return 0;
495
496
    // check for at least the init function of a plugin
497
    if( ! osl_getAsciiFunctionSymbol( aMod, "NP_Initialize") &&
498
        ! osl_getAsciiFunctionSymbol( aMod, "NP_GetEntryPoints" ) )
499
    {
500
        return 0;
501
    }
502
503
    // ask the plist of the bundle for mimetypes
504
    nDescriptions = parsePlist( i_xBundle, aPlugURL, io_rDescriptions );
505
    if( nDescriptions )
506
    {
507
        osl_unloadModule( aMod );
508
        return nDescriptions;
509
    }
510
    
511
    // resolve the symbol that might get us the mimetypes
512
    const char* (*pGetMimeDescription)() = (const char*(*)())osl_getAsciiFunctionSymbol( aMod, "_NP_GetMIMEDescription" );
513
    if( pGetMimeDescription )
514
    {
515
        const char* pMime = pGetMimeDescription();
516
        if( pMime )
517
        {
518
            nDescriptions = parseMimeString( aPlugURL, io_rDescriptions, pMime );
519
            if( nDescriptions )
520
            {
521
                osl_unloadModule( aMod );
522
                return nDescriptions;
523
            }
524
        }
525
    }
526
    
527
    // and as last resort check the resource of the bundle
528
    nDescriptions = parseMimeResource( i_xBundle, aMod, aPlugURL, io_rDescriptions );
529
    osl_unloadModule( aMod );
530
531
    return nDescriptions;
532
}
533
534
// Unix specific implementation
535
static bool CheckPlugin( const OUString& rPath, list< PluginDescription* >& rDescriptions )
536
{
537
#if OSL_DEBUG_LEVEL > 1
538
    fprintf( stderr, "Trying path %s ... ", OUStringToOString( rPath, RTL_TEXTENCODING_UTF8 ).getStr() );
539
#endif
540
    CFURLRef xURL = createURL( rPath );    
541
    
542
    CFArrayRef xBundles = CFBundleCreateBundlesFromDirectory( NULL, xURL, CFSTR("plugin") );
543
    if( ! xBundles )
544
        return false;
545
    
546
    CFIndex nBundles = CFArrayGetCount( xBundles );
547
    
548
#if OSL_DEBUG_LEVEL > 1
549
    fprintf( stderr, "got %d bundles\n", (int)nBundles );
550
#endif
551
    
552
    int nDescriptions = 0;
553
    for( CFIndex i = 0; i < nBundles; i++ )
554
    {
555
        CFBundleRef xBundle = (CFBundleRef)CFArrayGetValueAtIndex( xBundles, i );
556
        nDescriptions += getPluginDescriptions( xBundle, rDescriptions );
557
        
558
        CFRelease( xBundle );
559
    }
560
    CFRelease( xBundles );
561
562
563
	return nDescriptions > 0;
564
}
565
566
static OUString FindFolderURL(  FSVolumeRefNum vRefNum, OSType folderType )
567
{
568
    OUString aRet;
569
570
    FSRef aFSRef;
571
    OSErr err = FSFindFolder( vRefNum, folderType, kDontCreateFolder, &aFSRef );
572
    if( err == noErr )
573
    {
574
        CFURLRef xURL = CFURLCreateFromFSRef( NULL, &aFSRef );
575
        aRet = getString( xURL );
576
        CFRelease( xURL );
577
    }
578
    
579
    return aRet;
580
}
581
582
Sequence<PluginDescription> XPluginManager_Impl::impl_getPluginDescriptions() throw()
583
{
584
	static Sequence<PluginDescription> aDescriptions;
585
	static sal_Bool bHavePlugins = sal_False;
586
	if( ! bHavePlugins )
587
	{
588
        std::list<PluginDescription*> aPlugins;
589
590
        static const char* pNPXPluginPath = getenv( "MOZ_PLUGIN_PATH" );
591
        
592
        // get directories
593
        std::list< OUString > aPaths;
594
        if( pNPXPluginPath )
595
        {
596
            CFMutableStringRef xMutableString = CFStringCreateMutable( NULL, 0 );
597
            CFStringAppendCString( xMutableString, pNPXPluginPath, kCFStringEncodingUTF8 );
598
            CFURLRef xURL = CFURLCreateWithFileSystemPath( NULL, xMutableString, kCFURLPOSIXPathStyle, true );
599
            CFRelease( xMutableString );
600
            aPaths.push_back( getString( xURL ) );
601
            CFRelease( xURL );
602
        }
603
        
604
        OUString aPath = FindFolderURL( kUserDomain, kInternetPlugInFolderType );
605
        if( aPath.getLength() )
606
            aPaths.push_back( aPath );
607
        aPath = FindFolderURL( kLocalDomain, kInternetPlugInFolderType );
608
        if( aPath.getLength() )
609
            aPaths.push_back( aPath );
610
        aPath = FindFolderURL( kOnAppropriateDisk, kInternetPlugInFolderType );
611
        if( aPath.getLength() )
612
            aPaths.push_back( aPath );
613
        
614
        
615
		const Sequence< ::OUString >& rPaths( PluginManager::getAdditionalSearchPaths() );
616
		for( sal_Int32 i = 0; i < rPaths.getLength(); i++ )
617
        {
618
            aPaths.push_back( getURLFromPath( rPaths.getConstArray()[i] ) );
619
        }
620
        
621
		for( std::list< OUString >::const_iterator it = aPaths.begin(); it != aPaths.end(); ++it )
622
		{
623
            OUString aPath( *it );
624
#if OSL_DEBUG_LEVEL > 1
625
            fprintf( stderr, "check path %s\n", OUStringToOString( *it, RTL_TEXTENCODING_UTF8 ).getStr() );
626
#endif
627
            CheckPlugin( aPath, aPlugins );
628
		}
629
        
630
        
631
        // create return value
632
		aDescriptions = Sequence<PluginDescription>( aPlugins.size() );
633
#if OSL_DEBUG_LEVEL > 1
634
        fprintf( stderr, "found %d plugins\n", (int)aPlugins.size() );
635
#endif
636
		list<PluginDescription*>::iterator iter;
637
        sal_Int32 nPlug = 0;
638
		for( iter = aPlugins.begin(); iter != aPlugins.end(); ++iter )
639
		{
640
			aDescriptions.getArray()[ nPlug++ ] = **iter;
641
			delete *iter;
642
		}
643
		aPlugins.clear();
644
		bHavePlugins = sal_True;
645
	}
646
	return aDescriptions;
647
}
648
(-)a/main/extensions/source/plugin/aqua/makefile.mk (+71 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
PRJ=..$/..$/..
24
25
PRJNAME=extensions
26
TARGET=plaqua
27
#ENABLE_EXCEPTIONS=TRUE
28
#TARGETTYPE=CUI
29
30
.INCLUDE :  ..$/util$/makefile.pmk
31
32
.IF "$(GUIBASE)"!="aqua" || "$(WITH_MOZILLA)"=="NO"
33
34
dummy:
35
	@echo "Nothing to build for GUIBASE $(GUIBASE)."
36
37
.ELSE
38
39
# --- Files --------------------------------------------------------
40
41
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/plugin
42
.IF "$(SOLAR_JAVA)" != ""
43
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/java
44
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/nspr
45
INCPRE+=-I$(SOLARINCDIR)$/npsdk
46
CDEFS+=-DOJI
47
.ENDIF
48
49
.IF "$(GUIBASE)"=="aqua"
50
CFLAGSCXX+=$(OBJCXXFLAGS)
51
.ENDIF  # "$(GUIBASE)"=="aqua"
52
53
SLOFILES=\
54
	$(SLO)$/macmgr.obj      \
55
    $(SLO)$/sysplug.obj
56
57
#APP1TARGET=pluginapp.bin
58
#APP1OBJS=$(OBJFILES)
59
#APP1STDLIBS=\
60
#	$(TOOLSLIB) 				\
61
#	$(VOSLIB)					\
62
#	$(SALLIB)
63
64
#APP1DEF=	$(MISC)$/$(TARGET).def
65
66
67
# --- Targets ------------------------------------------------------
68
69
.INCLUDE :	target.mk
70
71
.ENDIF # $(GUIBASE)==aqua
(-)a/main/extensions/source/plugin/aqua/sysplug.cxx (+804 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#include <cstdarg>
24
25
#include <sys/types.h>
26
#include <signal.h>
27
#include <sys/wait.h>
28
#include <osl/thread.h>
29
30
#include <plugin/impl.hxx>
31
32
extern NPNetscapeFuncs aNPNFuncs;
33
34
#include <tools/debug.hxx>
35
36
using namespace rtl;
37
using namespace plugstringhelper;
38
39
#if OSL_DEBUG_LEVEL > 1
40
void TRACE( char const * s );
41
void TRACEN( char const * s, long n );
42
#else
43
#define TRACE(x)
44
#define TRACEN(x,n)
45
#endif
46
47
struct FakeEventRecord : public EventRecord
48
{
49
    FakeEventRecord()
50
    {
51
        memset( this, 0, sizeof(EventRecord) );
52
        ::GetGlobalMouse( &where );
53
        when = ::TickCount();
54
        modifiers = ::GetCurrentEventKeyModifiers();
55
    }
56
};
57
58
59
@interface OOoPluginView : NSView
60
{
61
    XPlugin_Impl*   m_pImpl;
62
    MacPluginComm*  m_pCom;
63
}
64
-(id)initWithInstance: (XPlugin_Impl*)i_pImpl pluginComm: (MacPluginComm*)i_pCom frame: (NSRect)i_aRect;
65
-(void)drawRect: (NSRect)i_aRect;
66
-(BOOL)isOpaque;
67
-(BOOL)isFlipped;
68
69
// NSResponder
70
-(void)mouseMoved:   (NSEvent*)i_pEvent;
71
-(void)mouseDown:    (NSEvent*)i_pEvent;
72
-(void)mouseDragged: (NSEvent*)i_pEvent;
73
-(void)mouseUp:      (NSEvent*)i_pEvent;
74
-(void)rightMouseDown:    (NSEvent*)i_pEvent;
75
-(void)rightMouseDragged: (NSEvent*)i_pEvent;
76
-(void)rightMouseUp:      (NSEvent*)i_pEvent;
77
-(void)otherMouseDown:    (NSEvent*)i_pEvent;
78
-(void)otherMouseDragged: (NSEvent*)i_pEvent;
79
-(void)otherMouseUp:      (NSEvent*)i_pEvent;
80
-(void)mouseEntered: (NSEvent*)i_pEvent;
81
-(void)mouseExited:  (NSEvent*)i_pEvent;
82
@end
83
84
@implementation OOoPluginView
85
-(id)initWithInstance: (XPlugin_Impl*)i_pImpl pluginComm: (MacPluginComm*)i_pCom frame: (NSRect) i_aRect
86
{
87
    if( (self = [super initWithFrame: i_aRect]) )
88
    {
89
        m_pImpl = i_pImpl;
90
        m_pCom = i_pCom;
91
    }
92
    return self;
93
}
94
95
-(void)drawRect: (NSRect) i_aRect
96
{
97
    m_pCom->drawView( m_pImpl );
98
}
99
100
-(BOOL)isOpaque
101
{
102
    return NO;
103
}
104
105
-(BOOL)isFlipped
106
{
107
    return YES;
108
}
109
110
// NSResponder
111
-(void)mouseMoved:   (NSEvent*)i_pEvent
112
{
113
    FakeEventRecord aRec;
114
    aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
115
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
116
}
117
118
-(void)mouseDown:    (NSEvent*)i_pEvent;
119
{
120
    FakeEventRecord aRec;
121
    aRec.what = mouseDown;
122
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
123
}
124
125
-(void)mouseDragged: (NSEvent*)i_pEvent;
126
{
127
    FakeEventRecord aRec;
128
    aRec.what = aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
129
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
130
}
131
132
-(void)mouseUp:      (NSEvent*)i_pEvent;
133
{
134
    FakeEventRecord aRec;
135
    aRec.what = mouseUp;
136
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
137
}
138
139
-(void)rightMouseDown:    (NSEvent*)i_pEvent;
140
{
141
    FakeEventRecord aRec;
142
    aRec.what = mouseDown;
143
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
144
}
145
146
-(void)rightMouseDragged: (NSEvent*)i_pEvent;
147
{
148
    FakeEventRecord aRec;
149
    aRec.what = aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
150
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
151
}
152
153
-(void)rightMouseUp:      (NSEvent*)i_pEvent;
154
{
155
    FakeEventRecord aRec;
156
    aRec.what = mouseUp;
157
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
158
}
159
160
-(void)otherMouseDown:    (NSEvent*)i_pEvent;
161
{
162
    FakeEventRecord aRec;
163
    aRec.what = mouseDown;
164
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
165
}
166
167
-(void)otherMouseDragged: (NSEvent*)i_pEvent;
168
{
169
    FakeEventRecord aRec;
170
    aRec.what = aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
171
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
172
}
173
174
-(void)otherMouseUp:      (NSEvent*)i_pEvent;
175
{
176
    FakeEventRecord aRec;
177
    aRec.what = mouseUp;
178
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
179
}
180
181
-(void)mouseEntered: (NSEvent*)i_pEvent;
182
{
183
    FakeEventRecord aRec;
184
    aRec.what = aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
185
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
186
}
187
188
-(void)mouseExited:  (NSEvent*)i_pEvent;
189
{
190
    FakeEventRecord aRec;
191
    aRec.what = aRec.what = osEvt + 18; // NPEventType_AdjustCursorEvent
192
    m_pCom->NPP_HandleEvent( m_pImpl->getNPPInstance(), &aRec );
193
}
194
195
@end
196
197
//--------------------------------------------------------------------------------------------------
198
MacPluginComm::MacPluginComm( const rtl::OUString& i_rMimetype, const rtl::OUString& i_rBundle, NSView* i_pParent )
199
	: PluginComm( OUStringToOString( i_rBundle, RTL_TEXTENCODING_UTF8 ) ),
200
      m_xBundle( NULL ),
201
      m_hPlugLib( NULL ),
202
      m_pNullTimer( NULL )
203
{
204
	// initialize plugin function table
205
	memset( &m_aNPPfuncs, 0, sizeof( m_aNPPfuncs ) );
206
    
207
    // load the bundle
208
    CFURLRef xURL = createURL( i_rBundle );
209
    m_xBundle = CFBundleCreate( NULL, xURL );
210
    CFRelease( xURL );
211
    if( m_xBundle )
212
    {
213
        // ask the plugin library
214
        // first get its location
215
        CFURLRef xLibURL = CFBundleCopyExecutableURL( m_xBundle );
216
        if( xLibURL )
217
        {
218
            // get the file system path
219
            rtl::OUString aModuleURL( CFURLtoOSLURL( xLibURL ) );
220
            CFRelease( xLibURL );
221
            m_hPlugLib = osl_loadModule( aModuleURL.pData, SAL_LOADMODULE_DEFAULT );
222
            #if OSL_DEBUG_LEVEL > 1
223
            if( ! m_hPlugLib )
224
                fprintf( stderr, "module %s could not be loaded\n", OUStringToOString( aModuleURL, RTL_TEXTENCODING_UTF8 ).getStr() );
225
            #endif
226
        }
227
        #if OSL_DEBUG_LEVEL > 1
228
        else
229
            fprintf( stderr, "bundle %s has no exectutable URL\n", OUStringToOString( i_rBundle, RTL_TEXTENCODING_UTF8 ).getStr() );
230
        #endif
231
    }
232
    else
233
    {
234
        #if OSL_DEBUG_LEVEL > 1
235
        fprintf( stderr, "bundle %s could not be loaded\n", OUStringToOString( i_rBundle, RTL_TEXTENCODING_UTF8 ).getStr() );
236
        #endif
237
    }
238
239
    DBG_ASSERT( m_xBundle && m_hPlugLib, "loading plugin bundle failed!" );
240
241
242
    m_aNPPfuncs.size = sizeof( m_aNPPfuncs );
243
    m_aNPPfuncs.version = 0;
244
245
    
246
	m_eCall = eNP_Initialize;
247
	execute();
248
}
249
250
//--------------------------------------------------------------------------------------------------
251
MacPluginComm::~MacPluginComm()
252
{
253
	if( m_hPlugLib )
254
	{
255
		// NPP_Shutdown();
256
		NPError (*pShutdown)();
257
		if( retrieveFunction( "NP_Shutdown", (void**)&pShutdown ) )
258
		{
259
            NPError nErr = (*pShutdown)(); (void)nErr;
260
			DBG_ASSERT( nErr == NPERR_NO_ERROR, "NP_Shutdown() failed!" );
261
		}
262
        osl_unloadModule( m_hPlugLib );
263
	}
264
    if( m_xBundle )
265
        CFRelease( m_xBundle );
266
}
267
268
//--------------------------------------------------------------------------------------------------
269
sal_Bool MacPluginComm::retrieveFunction( const char* i_pName, void** o_ppFunc ) const
270
{
271
	if( ! m_hPlugLib || ! o_ppFunc )
272
		return sal_False;
273
274
	*o_ppFunc = (void*)osl_getAsciiFunctionSymbol( m_hPlugLib, i_pName );
275
  
276
    if( ! *o_ppFunc && m_xBundle )
277
    {
278
        rtl::OUString aName( OUString::createFromAscii( *i_pName == '_' ? i_pName+1 : i_pName ) );
279
        CFStringRef xName = createString( aName );
280
        if( xName )
281
        {
282
            *o_ppFunc =  CFBundleGetFunctionPointerForName( m_xBundle, xName );
283
            CFRelease( xName );
284
        }
285
    }
286
287
	return (*o_ppFunc != NULL);
288
}
289
290
IMPL_LINK( MacPluginComm, NullTimerHdl, void*, EMPTYARG )
291
{
292
    // note: this is a Timer handler, we are already protected by the SolarMutex
293
    
294
    FakeEventRecord aRec;
295
    aRec.what = nullEvent;
296
    aRec.where.h = aRec.where.v = 20000;
297
298
    for( std::list< XPlugin_Impl* >::iterator it = m_aNullEventClients.begin();
299
         it != m_aNullEventClients.end(); ++it )
300
    {
301
        SysPlugData& rPlugData( (*it)->getSysPlugData() );
302
        if( rPlugData.m_pPlugView ) // for safety do not dispatch null events before first NPP_SetWindow
303
            (*m_aNPPfuncs.event)( (*it)->getNPPInstance(), &aRec );
304
    }
305
    
306
    return 0;
307
}
308
309
//--------------------------------------------------------------------------------------------------
310
311
long MacPluginComm::doIt()
312
{
313
	long nRet = 0;
314
	switch( m_eCall )
315
	{
316
	case eNP_Initialize:
317
	{
318
        TRACE( "eNP_Initialize" );
319
        NPError (*pInit)( NPNetscapeFuncs* );
320
        if( retrieveFunction( "NP_Initialize", (void**)&pInit ) )
321
        {
322
            nRet = (*pInit)( &aNPNFuncs );
323
324
            NPError nErr = NPERR_NO_ERROR;
325
            NPError (*pEntry)( NPPluginFuncs* );
326
            retrieveFunction( "NP_GetEntryPoints", (void**)&pEntry );
327
            nErr = (*pEntry)( &m_aNPPfuncs );
328
        
329
            DBG_ASSERT( nErr == NPERR_NO_ERROR, "NP_GetEntryPoints() failed!" );            
330
        }
331
        else
332
        {
333
            nRet = NPERR_GENERIC_ERROR;
334
        }
335
        DBG_ASSERT( nRet == NPERR_NO_ERROR, "### NP_Initialize() failed!" );
336
	}
337
	break;
338
	case eNPP_Destroy:
339
        if( m_aNullEventClients.empty() )
340
            delete m_pNullTimer, m_pNullTimer = NULL;
341
        
342
        TRACE( "eNPP_Destroy" );
343
		nRet = (m_aNPPfuncs.destroy
344
				? (*m_aNPPfuncs.destroy)(
345
					(NPP)m_aArgs[0],
346
					(NPSavedData**)m_aArgs[1] )
347
				: NPERR_GENERIC_ERROR);
348
		break;
349
	case eNPP_DestroyStream:
350
        TRACE( "eNPP_DestroyStream" );
351
		nRet =  (m_aNPPfuncs.destroystream
352
				 ? (*m_aNPPfuncs.destroystream)(
353
					 (NPP)m_aArgs[0],
354
					 (NPStream*)m_aArgs[1],
355
					 (NPError)(sal_IntPtr)m_aArgs[2] )
356
				 : NPERR_GENERIC_ERROR);
357
		break;
358
	case eNPP_New:
359
        TRACE( "eNPP_New" );
360
		nRet = (m_aNPPfuncs.newp
361
				? (*m_aNPPfuncs.newp)(
362
					(NPMIMEType)m_aArgs[0],
363
					(NPP)m_aArgs[1],
364
					(uint16)(sal_IntPtr)m_aArgs[2],
365
					(int16)(sal_IntPtr)m_aArgs[3],
366
					(char**)m_aArgs[4],
367
					(char**)m_aArgs[5],
368
					(NPSavedData*)m_aArgs[6] )
369
				: NPERR_GENERIC_ERROR);
370
371
        if( ! m_pNullTimer && m_aNPPfuncs.event )
372
        {
373
            m_pNullTimer = new AutoTimer();
374
            m_pNullTimer->SetTimeout( 50 );
375
            m_pNullTimer->SetTimeoutHdl( LINK( this, MacPluginComm, NullTimerHdl ) );
376
            m_pNullTimer->Start();
377
        }
378
379
		break;
380
	case eNPP_NewStream:
381
        TRACE( "eNPP_NewStream" );
382
		nRet = (m_aNPPfuncs.newstream
383
				? (*m_aNPPfuncs.newstream)(
384
					(NPP)m_aArgs[0],
385
					(NPMIMEType)m_aArgs[1],
386
					(NPStream*)m_aArgs[2],
387
					(NPBool)(sal_IntPtr)m_aArgs[3],
388
					(uint16*)m_aArgs[4] )
389
				: NPERR_GENERIC_ERROR);
390
		break;
391
	case eNPP_Print:
392
        TRACE( "eNPP_Print" );
393
		if (m_aNPPfuncs.print)
394
			(*m_aNPPfuncs.print)(
395
				(NPP)m_aArgs[0],
396
				(NPPrint*)m_aArgs[1] );
397
		break;
398
	case eNPP_SetWindow:
399
    {
400
        TRACE( "eNPP_SetWindow" );
401
        nRet = (m_aNPPfuncs.setwindow
402
				? (*m_aNPPfuncs.setwindow)(
403
					(NPP)m_aArgs[0],
404
                    (NPWindow*)m_aArgs[1] )
405
				: NPERR_GENERIC_ERROR);
406
        
407
		break;
408
    }
409
	case eNPP_HandleEvent:
410
    {
411
        TRACE( "eNPP_HandleEvent" );
412
        nRet = (m_aNPPfuncs.event
413
				? (*m_aNPPfuncs.event)(
414
					(NPP)m_aArgs[0],
415
                    m_aArgs[1] )
416
				: NPERR_GENERIC_ERROR);
417
        
418
		break;
419
    }
420
	case eNPP_StreamAsFile:
421
        TRACE( "eNPP_StreamAsFile" );
422
		if (m_aNPPfuncs.asfile)
423
			(*m_aNPPfuncs.asfile)(
424
				(NPP)m_aArgs[0],
425
				(NPStream*)m_aArgs[1],
426
				(char*)m_aArgs[2] );
427
		break;
428
	case eNPP_URLNotify:
429
        TRACE( "eNPP_URLNotify" );
430
		if (m_aNPPfuncs.urlnotify)
431
			(*m_aNPPfuncs.urlnotify)(
432
				(NPP)m_aArgs[0],
433
				(char*)m_aArgs[1],
434
				(NPReason)(sal_IntPtr)m_aArgs[2],
435
				m_aArgs[3] );
436
		break;
437
	case eNPP_Write:
438
        TRACEN( "eNPP_Write n=", (int32)m_aArgs[3] );
439
		nRet = (m_aNPPfuncs.write
440
				? (*m_aNPPfuncs.write)(
441
					(NPP)m_aArgs[0],
442
					(NPStream*)m_aArgs[1],
443
					(int32)m_aArgs[2],
444
					(int32)m_aArgs[3],
445
					m_aArgs[4] )
446
				: 0);
447
		break;
448
	case eNPP_WriteReady:
449
        TRACE( "eNPP_WriteReady" );
450
		nRet = (m_aNPPfuncs.writeready
451
				? (*m_aNPPfuncs.writeready)(
452
					(NPP)m_aArgs[0],
453
					(NPStream*)m_aArgs[1] )
454
				: 0);
455
		break;
456
	case eNPP_GetValue:
457
        TRACE( "eNPP_GetValue" );
458
		nRet = (m_aNPPfuncs.getvalue
459
				? (*m_aNPPfuncs.getvalue)(
460
					(NPP)m_aArgs[0],
461
					(NPPVariable)(int)m_aArgs[1],
462
					m_aArgs[2] )
463
				: NPERR_GENERIC_ERROR);
464
		break;
465
	case eNPP_SetValue:
466
        TRACE( "eNPP_SetValue" );
467
		nRet = (m_aNPPfuncs.setvalue
468
				? (*m_aNPPfuncs.setvalue)(
469
					(NPP)m_aArgs[0],
470
					(NPNVariable)(int)m_aArgs[1],
471
					m_aArgs[2] )
472
				: NPERR_GENERIC_ERROR);
473
		break;
474
	case eNPP_Shutdown:
475
	{
476
        TRACE( "eNPP_Shutdown" );
477
		NPP_ShutdownUPP pFunc;
478
		if (retrieveFunction( "NPP_Shutdown", (void**)&pFunc ))
479
			(*pFunc)();
480
	}
481
	break;
482
    case eNPP_Initialize:
483
        TRACE( "eNPP_Initialize" );
484
        OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
485
	    break;
486
    case eNPP_GetJavaClass:
487
        TRACE( "eNPP_GetJavaClass" );
488
        OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
489
	    break;
490
	}
491
	return nRet;
492
}
493
494
//--------------------------------------------------------------------------------------------------
495
NPError MacPluginComm::NPP_Destroy( XPlugin_Impl* i_pImpl, NPSavedData** save )
496
{
497
    // remove from NullEvent timer
498
    m_aNullEventClients.remove( i_pImpl );
499
    
500
    NPError nErr = NPP_Destroy( i_pImpl->getNPPInstance(), save );
501
    
502
    // release plugin view
503
    SysPlugData& rPlugData( i_pImpl->getSysPlugData() );
504
    if( rPlugData.m_pPlugView )
505
    {
506
        [rPlugData.m_pPlugView removeFromSuperview];
507
        [rPlugData.m_pPlugView release];
508
        rPlugData.m_pPlugView = nil;
509
    }
510
    
511
    return nErr;
512
}
513
514
515
NPError MacPluginComm::NPP_Destroy( NPP instance, NPSavedData** save )
516
{
517
	DBG_ASSERT( m_aNPPfuncs.destroy, "### NPP_Destroy(): null pointer in NPP functions table!" );
518
	m_eCall = eNPP_Destroy;
519
	m_aArgs[0] = (void*)instance;
520
	m_aArgs[1] = (void*)save;
521
	return (NPError)execute();
522
}
523
524
//--------------------------------------------------------------------------------------------------
525
NPError MacPluginComm::NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason )
526
{
527
	DBG_ASSERT( m_aNPPfuncs.destroystream, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
528
	m_eCall = eNPP_DestroyStream;
529
	m_aArgs[0] = (void*)instance;
530
	m_aArgs[1] = (void*)stream;
531
	m_aArgs[2] = (void*)reason;
532
	return (NPError)execute();
533
}
534
535
//--------------------------------------------------------------------------------------------------
536
NPError MacPluginComm::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
537
								  char* argn[], char* argv[], NPSavedData *saved )
538
{
539
    XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
540
    DBG_ASSERT( pImpl, "no instance found" );
541
542
    if( pImpl ) // sanity check
543
        m_aNullEventClients.push_back( pImpl );
544
    
545
	DBG_ASSERT( m_aNPPfuncs.newp, "### NPP_New(): null pointer in NPP functions table!" );
546
    #if OSL_DEBUG_LEVEL > 1
547
    fprintf( stderr, "NPP_New( %s. %p, %d, %d",
548
             pluginType, instance, (int)mode, (int)argc );
549
    for( int16 i = 0; i < argc; i++ )
550
    fprintf( stderr, "\n%s = %s", argn[i], argv[i] );
551
    fprintf( stderr, ", %p )\n", saved );
552
    #endif
553
	m_eCall = eNPP_New;
554
	m_aArgs[0] = (void*)pluginType;
555
	m_aArgs[1] = (void*)instance;
556
	m_aArgs[2] = (void*)mode;
557
	m_aArgs[3] = (void*)argc;
558
	m_aArgs[4] = (void*)argn;
559
	m_aArgs[5] = (void*)argv;
560
	m_aArgs[6] = (void*)saved;
561
    
562
    return (NPError)execute();
563
}
564
565
//--------------------------------------------------------------------------------------------------
566
NPError MacPluginComm::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
567
										NPBool seekable, uint16* stype )
568
{
569
	DBG_ASSERT( m_aNPPfuncs.newstream, "### NPP_NewStream(): null pointer in NPP functions table!" );
570
	m_eCall = eNPP_NewStream;
571
	m_aArgs[0] = (void*)instance;
572
	m_aArgs[1] = (void*)type;
573
	m_aArgs[2] = (void*)stream;
574
	m_aArgs[3] = (void*)seekable;
575
	m_aArgs[4] = (void*)stype;
576
	return (NPError)execute();
577
}
578
579
//--------------------------------------------------------------------------------------------------
580
void MacPluginComm::NPP_Print( NPP instance, NPPrint* platformPrint )
581
{
582
	DBG_ASSERT( m_aNPPfuncs.print, "### NPP_Print(): null pointer in NPP functions table!" );
583
	m_eCall = eNPP_Print;
584
	m_aArgs[0] = (void*)instance;
585
	m_aArgs[1] = (void*)platformPrint;
586
	execute();
587
}
588
589
//--------------------------------------------------------------------------------------------------
590
NPError MacPluginComm::NPP_SetWindow( NPP instance, NPWindow* window )
591
{
592
	DBG_ASSERT( m_aNPPfuncs.setwindow, "### NPP_SetWindow(): null pointer in NPP functions table!" );
593
	m_eCall = eNPP_SetWindow;
594
	m_aArgs[0] = (void*)instance;
595
	m_aArgs[1] = (void*)window;
596
	return (NPError)execute();
597
}
598
599
//--------------------------------------------------------------------------------------------------
600
NPError MacPluginComm::NPP_HandleEvent( NPP instance, void* event )
601
{
602
	DBG_ASSERT( m_aNPPfuncs.event, "### NPP_HandleEvent(): null pointer in NPP functions table!" );
603
	m_eCall = eNPP_HandleEvent;
604
	m_aArgs[0] = (void*)instance;
605
	m_aArgs[1] = event;
606
	return (NPError)execute();
607
}
608
609
//--------------------------------------------------------------------------------------------------
610
void MacPluginComm::NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname )
611
{
612
	DBG_ASSERT( m_aNPPfuncs.asfile, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
613
	m_eCall = eNPP_StreamAsFile;
614
	m_aArgs[0] = (void*)instance;
615
	m_aArgs[1] = (void*)stream;
616
	m_aArgs[2] = (void*)fname;
617
	execute();
618
}
619
620
//--------------------------------------------------------------------------------------------------
621
void MacPluginComm::NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData )
622
{
623
	DBG_ASSERT( m_aNPPfuncs.urlnotify, "### NPP_URLNotify(): null pointer in NPP functions table!" );
624
	m_eCall = eNPP_URLNotify;
625
	m_aArgs[0] = (void*)instance;
626
	m_aArgs[1] = (void*)url;
627
	m_aArgs[2] = (void*)reason;
628
	m_aArgs[3] = notifyData;
629
	execute();
630
}
631
632
//--------------------------------------------------------------------------------------------------
633
int32 MacPluginComm::NPP_Write( NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer )
634
{
635
	DBG_ASSERT( m_aNPPfuncs.write, "### NPP_Write(): null pointer in NPP functions table!" );
636
	m_eCall = eNPP_Write;
637
	m_aArgs[0] = (void*)instance;
638
	m_aArgs[1] = (void*)stream;
639
	m_aArgs[2] = (void*)offset;
640
	m_aArgs[3] = (void*)len;
641
	m_aArgs[4] = buffer;
642
	return (NPError)execute();
643
}
644
645
//--------------------------------------------------------------------------------------------------
646
int32 MacPluginComm::NPP_WriteReady( NPP instance, NPStream* stream )
647
{
648
	DBG_ASSERT( m_aNPPfuncs.writeready, "### NPP_WriteReady(): null pointer in NPP functions table!" );
649
	m_eCall = eNPP_WriteReady;
650
	m_aArgs[0] = (void*)instance;
651
	m_aArgs[1] = (void*)stream;
652
	return execute();
653
}
654
655
//--------------------------------------------------------------------------------------------------
656
NPError MacPluginComm::NPP_GetValue( NPP instance, NPPVariable variable, void *ret_value )
657
{
658
	DBG_ASSERT( m_aNPPfuncs.getvalue, "### NPP_GetValue(): null pointer in NPP functions table!" );
659
	m_eCall = eNPP_GetValue;
660
	m_aArgs[0] = (void*)instance;
661
	m_aArgs[1] = (void*)variable;
662
	m_aArgs[2] = ret_value;
663
	return (NPError)execute();
664
}
665
666
//--------------------------------------------------------------------------------------------------
667
NPError MacPluginComm::NPP_SetValue( NPP instance, NPNVariable variable, void *set_value )
668
{
669
	DBG_ASSERT( m_aNPPfuncs.setvalue, "### NPP_SetValue(): null pointer in NPP functions table!" );
670
	m_eCall = eNPP_SetValue;
671
	m_aArgs[0] = (void*)instance;
672
	m_aArgs[1] = (void*)variable;
673
	m_aArgs[2] = set_value;
674
	return (NPError)execute();
675
}
676
677
//--------------------------------------------------------------------------------------------------
678
void * MacPluginComm::NPP_GetJavaClass()
679
{
680
	DBG_ERROR( "no java class available!" );
681
	return 0;
682
}
683
684
//--------------------------------------------------------------------------------------------------
685
NPError MacPluginComm::NPP_Initialize()
686
{
687
	return NPERR_NO_ERROR;
688
}
689
690
//--------------------------------------------------------------------------------------------------
691
void MacPluginComm::NPP_Shutdown()
692
{
693
	m_eCall = eNPP_Shutdown;
694
	execute();
695
}
696
697
//--------------------------------------------------------------------------------------------------
698
NPError MacPluginComm::NPP_SetWindow( XPlugin_Impl* i_pImpl )
699
{
700
    // update window NPWindow from view
701
    SysPlugData& rPlugData( i_pImpl->getSysPlugData() );        
702
703
    // update plug view
704
    NSRect aPlugRect = [rPlugData.m_pParentView frame];
705
    aPlugRect.origin.x = aPlugRect.origin.y = 0;
706
    if( ! rPlugData.m_pPlugView )
707
    {
708
        rPlugData.m_pPlugView = [[OOoPluginView alloc] initWithInstance: i_pImpl pluginComm: this frame: aPlugRect];
709
        [rPlugData.m_pParentView addSubview: rPlugData.m_pPlugView];
710
    }
711
    else
712
        [rPlugData.m_pPlugView setFrame: aPlugRect];
713
714
    NPWindow* pNPWin = i_pImpl->getNPWindow();
715
    NSWindow* pWin = [rPlugData.m_pPlugView window];
716
    NSRect aWinRect = [pWin frame];
717
    NSRect aBounds = [rPlugData.m_pPlugView frame];
718
    NSRect aVisibleBounds = [rPlugData.m_pPlugView visibleRect];
719
    
720
    #if OSL_DEBUG_LEVEL > 1
721
    fprintf( stderr, "visible bounds = %d+%d+%dx%d\n",
722
             (int)aVisibleBounds.origin.x, (int)aVisibleBounds.origin.y,
723
             (int)aVisibleBounds.size.width, (int)aVisibleBounds.size.height );
724
    #endif
725
    
726
    NSPoint aViewOrigin = [rPlugData.m_pPlugView convertPoint: NSZeroPoint toView: nil];
727
    // save view origin so we can notice movement of the view in drawView
728
    // in case of a moved view we need to reset the port/context
729
    rPlugData.m_aLastPlugViewOrigin = aViewOrigin;
730
    
731
    // convert view origin to topdown coordinates
732
    aViewOrigin.y = aWinRect.size.height - aViewOrigin.y;
733
    
734
    // same for clipping
735
    NSPoint aClipOrigin = [rPlugData.m_pPlugView convertPoint: aVisibleBounds.origin toView: nil];
736
    aClipOrigin.y = aWinRect.size.height - aClipOrigin.y;
737
    
738
    #if OSL_DEBUG_LEVEL > 1
739
    fprintf( stderr, "view origin: %d+%d, clip origin = %d+%d\n",
740
             (int)aViewOrigin.x, (int)aViewOrigin.y,
741
             (int)aClipOrigin.x, (int)aClipOrigin.y );
742
    #endif
743
    
744
    pNPWin->x                = aViewOrigin.x;
745
    pNPWin->y                = aViewOrigin.y;
746
    pNPWin->width            = aBounds.size.width;
747
    pNPWin->height           = aBounds.size.height;
748
    pNPWin->clipRect.left    = aClipOrigin.x;
749
    pNPWin->clipRect.top     = aClipOrigin.y;
750
    pNPWin->clipRect.right   = aClipOrigin.x + aVisibleBounds.size.width;
751
    pNPWin->clipRect.bottom  = aClipOrigin.y + aVisibleBounds.size.height;
752
753
    if( rPlugData.m_nDrawingModel == 1 )
754
    {        
755
        rPlugData.m_aCGContext.window = reinterpret_cast<WindowRef>([pWin windowRef]);
756
        pNPWin->window = &rPlugData.m_aCGContext;
757
        rPlugData.m_aCGContext.context = reinterpret_cast<CGContextRef>([[pWin graphicsContext] graphicsPort]);
758
        #if OSL_DEBUG_LEVEL > 1
759
        fprintf( stderr, "window is %p, context is %p\n",
760
                 rPlugData.m_aCGContext.window, rPlugData.m_aCGContext.context );
761
        #endif
762
    }
763
    else
764
    {
765
        rPlugData.m_aNPPort.port = GetWindowPort( reinterpret_cast<WindowRef>([pWin windowRef]) );
766
        rPlugData.m_aNPPort.portx = aClipOrigin.x;
767
        rPlugData.m_aNPPort.porty = aClipOrigin.y;
768
        pNPWin->window = &rPlugData.m_aNPPort;
769
        #if OSL_DEBUG_LEVEL > 1
770
        fprintf( stderr, "port is %p at (%d,%d)\n",
771
                 rPlugData.m_aNPPort.port, (int)rPlugData.m_aNPPort.portx, (int)rPlugData.m_aNPPort.porty );
772
        #endif
773
    }
774
    
775
    if( pNPWin->width == 0 || pNPWin->height == 0 || [rPlugData.m_pPlugView isHiddenOrHasHiddenAncestor] )
776
        rPlugData.m_bSetWindowOnDraw = true;
777
778
    NPError nErr = NPP_SetWindow( i_pImpl->getNPPInstance(), i_pImpl->getNPWindow() );
779
    
780
    return nErr;
781
}
782
783
void MacPluginComm::drawView( XPlugin_Impl* i_pImpl )
784
{
785
    SysPlugData& rPlugData( i_pImpl->getSysPlugData() );
786
787
    // check if the view was moved since the last SetWindow
788
    NSPoint aViewOrigin = [rPlugData.m_pPlugView convertPoint: NSZeroPoint toView: nil];
789
    if( rPlugData.m_bSetWindowOnDraw ||
790
        aViewOrigin.x != rPlugData.m_aLastPlugViewOrigin.x ||
791
        aViewOrigin.y != rPlugData.m_aLastPlugViewOrigin.y )
792
    {
793
        NPP_SetWindow( i_pImpl );
794
        rPlugData.m_bSetWindowOnDraw = false;
795
    }
796
797
    // send a paint event
798
    NSWindow* pWin = [rPlugData.m_pPlugView window];
799
    FakeEventRecord aRec;
800
    aRec.what       =  updateEvt;
801
    aRec.message    = (UInt32)[pWin windowRef];
802
    this->NPP_HandleEvent( i_pImpl->getNPPInstance(), &aRec );
803
}
804
(-)a/main/extensions/source/plugin/base/context.cxx (+352 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#if STLPORT_VERSION>=321
28
#include <cstdarg>
29
#include <cstdio>
30
#endif
31
32
#include <plugin/impl.hxx>
33
34
#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAGS_HPP_
35
#include <com/sun/star/frame/FrameSearchFlag.hpp>
36
#endif
37
#include <com/sun/star/frame/XComponentLoader.hpp>
38
#include <tools/fsys.hxx>
39
#include <tools/urlobj.hxx>
40
41
#include <cppuhelper/implbase1.hxx>
42
43
using namespace com::sun::star::io;
44
using rtl::OUString;
45
46
namespace ext_plug {
47
	
48
class FileSink : public ::cppu::WeakAggImplHelper1< ::com::sun::star::io::XOutputStream >
49
{
50
private:
51
	Reference< ::com::sun::star::uno::XComponentContext > 	m_xContext;
52
	FILE*					fp;
53
	Reference< ::com::sun::star::plugin::XPlugin > 				m_xPlugin;
54
	::rtl::OUString					m_aMIMEType;
55
	::rtl::OUString					m_aTarget;
56
	::rtl::OUString					m_aFileName;
57
58
public:
59
	FileSink( const Reference< ::com::sun::star::uno::XComponentContext > 	&,
60
			  const Reference< ::com::sun::star::plugin::XPlugin > & plugin,
61
			  const ::rtl::OUString& mimetype,
62
			  const ::rtl::OUString& target,
63
			  const Reference< ::com::sun::star::io::XActiveDataSource > & source );
64
	virtual ~FileSink();
65
66
	// ::com::sun::star::io::XOutputStream
67
	virtual void SAL_CALL writeBytes( const Sequence<sal_Int8>& ) throw();
68
	virtual void SAL_CALL flush() throw();
69
	virtual void SAL_CALL closeOutput() throw();
70
};
71
72
}
73
using namespace ext_plug;
74
75
class XPluginContext_Impl : public ::cppu::WeakAggImplHelper1< ::com::sun::star::plugin::XPluginContext >
76
{
77
	Reference< ::com::sun::star::uno::XComponentContext > 	m_xContext;
78
	rtl_TextEncoding										m_aEncoding;
79
public:
80
81
	XPluginContext_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & );
82
	virtual ~XPluginContext_Impl();
83
84
85
    virtual ::rtl::OUString SAL_CALL getValue(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, ::com::sun::star::plugin::PluginVariable variable) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
86
    virtual void SAL_CALL getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
87
    virtual void SAL_CALL getURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
88
    virtual void SAL_CALL postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
89
    virtual void SAL_CALL postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
90
    virtual void SAL_CALL newStream(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& mimetype, const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
91
    virtual void SAL_CALL displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& message) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
92
    virtual ::rtl::OUString SAL_CALL getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & plugin) throw( ::com::sun::star::plugin::PluginException, RuntimeException );
93
};
94
95
Reference< ::com::sun::star::plugin::XPluginContext >  XPluginManager_Impl::createPluginContext() throw()
96
{
97
	return new XPluginContext_Impl( m_xContext );
98
}
99
100
XPluginContext_Impl::XPluginContext_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext )
101
	: m_xContext( rxContext ),
102
	  m_aEncoding( gsl_getSystemTextEncoding() )
103
{
104
}
105
106
XPluginContext_Impl::~XPluginContext_Impl()
107
{
108
}
109
110
::rtl::OUString XPluginContext_Impl::getValue( const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/, ::com::sun::star::plugin::PluginVariable /*variable*/ )
111
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
112
{
113
	return ::rtl::OUString();
114
}
115
116
117
void XPluginContext_Impl::getURL(
118
    const Reference< ::com::sun::star::plugin::XPlugin > & plugin,
119
    const ::rtl::OUString& url,
120
    const ::rtl::OUString& target)
121
throw( ::com::sun::star::plugin::PluginException,
122
       RuntimeException )
123
{
124
    Reference< ::com::sun::star::frame::XComponentLoader >  xLoader(
125
        m_xContext->getServiceManager()->createInstanceWithContext(
126
            OUString( RTL_CONSTASCII_USTRINGPARAM(
127
                "com.sun.star.frame.Desktop" )), m_xContext ), UNO_QUERY );
128
	if( ! xLoader.is() )
129
		return;
130
131
	if( ! target.getLength() )
132
	{
133
		INetURLObject aURL;
134
		aURL.SetSmartProtocol( INET_PROT_FILE );
135
		aURL.SetSmartURL( ::rtl::OUStringToOString( url, m_aEncoding ) );
136
137
        rtl::OUString aUrl = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
138
		// the mimetype cannot be specified
139
		plugin->provideNewStream( ::rtl::OUString(),
140
								  Reference< XActiveDataSource >(),
141
								  aUrl,
142
								  0, 0, (sal_Bool)(aUrl.compareToAscii( "file:", 5 ) == 0) );
143
		return;
144
	}
145
	
146
	XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin );
147
148
	if( pPlugin )
149
	{
150
        try
151
        {
152
            ::com::sun::star::beans::PropertyValue aValue;
153
            aValue.Name		= ::rtl::OUString::createFromAscii( "Referer" );
154
            aValue.Value <<= pPlugin->getRefererURL();
155
            
156
            Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 );
157
            Reference< ::com::sun::star::lang::XComponent >  xComp =
158
                xLoader->loadComponentFromURL(
159
                                              url,
160
                                              target,
161
                                              ::com::sun::star::frame::FrameSearchFlag::PARENT          |
162
                                              ::com::sun::star::frame::FrameSearchFlag::SELF            |
163
                                              ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
164
                                              ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
165
                                              ::com::sun::star::frame::FrameSearchFlag::TASKS           |
166
                                              ::com::sun::star::frame::FrameSearchFlag::CREATE,
167
                                              aArgs
168
                                              );
169
        }
170
        catch(...)
171
        {
172
            throw ::com::sun::star::plugin::PluginException();
173
        }
174
	}
175
}
176
177
void XPluginContext_Impl::getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener )
178
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
179
{
180
	getURL( plugin, url, target );
181
	if( listener.is() )
182
		listener->disposing( ::com::sun::star::lang::EventObject() );
183
}
184
185
::rtl::OUString XPluginContext_Impl::getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/)
186
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
187
{
188
	return ::rtl::OUString::createFromAscii( "Mozilla 3.0" );
189
}
190
191
void XPluginContext_Impl::displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/, const ::rtl::OUString& /*message*/)
192
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
193
{
194
}
195
196
void XPluginContext_Impl::postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file)
197
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
198
{
199
	Sequence< sal_Int8 > aBuf;
200
201
	if( file )
202
	{
203
		String aFileName( (char*)buf.getConstArray(), m_aEncoding );
204
		INetURLObject aFilePath( aFileName );
205
		aFileName = aFilePath.PathToFileName();
206
		SvFileStream aStream( aFileName, STREAM_READ );
207
		if( aStream.IsOpen() )
208
		{
209
			int nBytes = 0;
210
			aStream.Seek( STREAM_SEEK_TO_END );
211
			aBuf = Sequence<sal_Int8>( nBytes = aStream.Tell() );
212
			aStream.Seek( STREAM_SEEK_TO_BEGIN );
213
			aStream.Read( aBuf.getArray(), nBytes );
214
			aStream.Close();
215
			DirEntry( aFileName ).Kill();
216
		}
217
	}
218
219
    Reference< ::com::sun::star::frame::XComponentLoader >  xLoader(
220
        m_xContext->getServiceManager()->createInstanceWithContext(
221
            OUString( RTL_CONSTASCII_USTRINGPARAM(
222
                "com.sun.star.frame.Desktop" )), m_xContext ), UNO_QUERY );
223
	if( ! xLoader.is() )
224
		return ;
225
226
	XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin );
227
	if( pPlugin )
228
	{
229
        try
230
        {
231
            ::com::sun::star::beans::PropertyValue aValues[2];
232
            aValues[0].Name	= ::rtl::OUString::createFromAscii( "Referer" );
233
            aValues[0].Value <<= pPlugin->getRefererURL();
234
            
235
            aValues[1].Name	= ::rtl::OUString::createFromAscii( "PostString" );
236
            aValues[1].Value <<= ::rtl::OStringToOUString( (char*)( file ? aBuf : buf ).getConstArray(), m_aEncoding );
237
            Sequence< ::com::sun::star::beans::PropertyValue > aArgs( aValues, 2 );
238
            Reference< ::com::sun::star::lang::XComponent >  xComp =
239
                xLoader->loadComponentFromURL(
240
                                              url,
241
                                              target,
242
                                              ::com::sun::star::frame::FrameSearchFlag::PARENT          |
243
                                              ::com::sun::star::frame::FrameSearchFlag::SELF            |
244
                                              ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
245
                                              ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
246
                                              ::com::sun::star::frame::FrameSearchFlag::TASKS           |
247
                                              ::com::sun::star::frame::FrameSearchFlag::CREATE,
248
                                              aArgs
249
                                              );
250
        }
251
        catch( ... )
252
        {
253
            throw ::com::sun::star::plugin::PluginException();
254
        }
255
	}
256
}
257
258
void XPluginContext_Impl::postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& url, const ::rtl::OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener )
259
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
260
{
261
	postURL( plugin, url, target, buf, file );
262
	if( listener.is() )
263
		listener->disposing( ::com::sun::star::lang::EventObject() );
264
}
265
266
void XPluginContext_Impl::newStream( const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const ::rtl::OUString& mimetype, const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source )
267
	throw( ::com::sun::star::plugin::PluginException, RuntimeException )
268
{
269
	FileSink*  pNewSink = new FileSink( m_xContext, plugin, mimetype, target, source );
270
	pNewSink->acquire();
271
}
272
273
274
275
FileSink::FileSink( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext, const Reference< ::com::sun::star::plugin::XPlugin > & plugin,
276
				    const ::rtl::OUString& mimetype,
277
					const ::rtl::OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source ) :
278
		m_xContext( rxContext ),
279
		m_xPlugin( plugin ),
280
		m_aMIMEType( mimetype ),
281
		m_aTarget( target )
282
{
283
	DirEntry aEntry;
284
	m_aFileName = aEntry.TempName().GetFull();
285
	::rtl::OString aFile = ::rtl::OUStringToOString( m_aFileName, gsl_getSystemTextEncoding() );
286
	fp = fopen( aFile.getStr() , "wb" );
287
288
	Reference< ::com::sun::star::io::XActiveDataControl >  xControl( source, UNO_QUERY );
289
290
	source->setOutputStream( Reference< ::com::sun::star::io::XOutputStream > ( this ) );
291
	if( xControl.is() )
292
		xControl->start();
293
}
294
295
FileSink::~FileSink()
296
{
297
	DirEntry aEntry( m_aFileName );
298
	aEntry.Kill();
299
}
300
301
void FileSink::closeOutput() throw()
302
{
303
	if( fp )
304
		fclose( fp );
305
306
    Reference< ::com::sun::star::frame::XComponentLoader >  xLoader(
307
        m_xContext->getServiceManager()->createInstanceWithContext(
308
            OUString( RTL_CONSTASCII_USTRINGPARAM(
309
                "com.sun.star.frame.Desktop" )), m_xContext ), UNO_QUERY );
310
311
	XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( m_xPlugin );
312
313
	if( xLoader.is() && pPlugin )
314
	{
315
        try
316
        {
317
            ::com::sun::star::beans::PropertyValue aValue;
318
            aValue.Name = ::rtl::OUString::createFromAscii( "Referer" );
319
            aValue.Value <<= pPlugin->getRefererURL();
320
            
321
            Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 );
322
            Reference< ::com::sun::star::lang::XComponent >  xComp =
323
                xLoader->loadComponentFromURL(
324
                                              m_aFileName,
325
                                              m_aTarget,
326
                                              ::com::sun::star::frame::FrameSearchFlag::PARENT          |
327
                                              ::com::sun::star::frame::FrameSearchFlag::SELF            |
328
                                              ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
329
                                              ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
330
                                              ::com::sun::star::frame::FrameSearchFlag::TASKS           |
331
                                              ::com::sun::star::frame::FrameSearchFlag::CREATE,
332
                                              aArgs
333
                                              );
334
        }
335
        catch( ... )
336
        {
337
        }
338
	}
339
	release();
340
}
341
342
void FileSink::writeBytes( const Sequence<sal_Int8>& Buffer ) throw()
343
{
344
	if( fp )
345
		fwrite( Buffer.getConstArray(), 1, Buffer.getLength(), fp );
346
}
347
348
void FileSink::flush() throw()
349
{
350
	if( fp )
351
		fflush( fp );
352
}
(-)a/main/extensions/source/plugin/base/evtlstnr.cxx (+60 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#if STLPORT_VERSION>=321
28
#include <cstdarg>
29
#endif
30
31
#include <plugin/impl.hxx>
32
33
PluginEventListener::PluginEventListener( XPlugin_Impl* pPlugin,
34
										  const char* url,
35
										  const char* normurl,
36
										  void* notifyData ) :
37
		m_pPlugin( pPlugin ),
38
		m_xPlugin( pPlugin ),
39
		m_pUrl( strdup( url ) ),
40
		m_pNormalizedUrl( strdup( normurl ) ),
41
		m_pNotifyData( notifyData )
42
{
43
}
44
45
PluginEventListener::~PluginEventListener()
46
{
47
	if( m_pUrl )
48
		free( m_pUrl );
49
	if( m_pNormalizedUrl )
50
		free( m_pNormalizedUrl );
51
}
52
53
void PluginEventListener::disposing( const ::com::sun::star::lang::EventObject& /*rEvt*/ ) throw()
54
{
55
	m_pPlugin->getPluginComm()->
56
		NPP_URLNotify( m_pPlugin->getNPPInstance(),
57
					   m_pUrl,
58
					   NPRES_DONE,
59
					   m_pNotifyData );
60
}
(-)a/main/extensions/source/plugin/base/makefile.mk (+66 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
PRJ=..$/..$/..
24
25
PRJNAME=extensions
26
TARGET=plbase
27
TARGETTYPE=GUI
28
ENABLE_EXCEPTIONS=TRUE
29
30
.INCLUDE :  ..$/util$/makefile.pmk
31
32
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/plugin
33
.IF "$(SOLAR_JAVA)" != ""
34
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/java
35
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/nspr
36
CDEFS+=-DOJI
37
.ENDIF
38
39
.IF "$(DISABLE_XAW)" != ""
40
CDEFS+=-DDISABLE_XAW
41
.ENDIF
42
43
.IF "$(WITH_MOZILLA)" != "NO"
44
45
.IF "$(GUIBASE)"=="aqua"
46
CFLAGSCXX+=$(OBJCXXFLAGS)
47
.ENDIF  # "$(GUIBASE)"=="aqua"
48
49
SLOFILES=		\
50
				$(SLO)$/plctrl.obj		\
51
				$(SLO)$/service.obj		\
52
				$(SLO)$/xplugin.obj		\
53
				$(SLO)$/nfuncs.obj		\
54
				$(SLO)$/manager.obj		\
55
				$(SLO)$/context.obj		\
56
				$(SLO)$/evtlstnr.obj	\
57
				$(SLO)$/plcom.obj		\
58
				$(SLO)$/multiplx.obj    \
59
				$(SLO)$/plmodel.obj
60
61
.ENDIF # $(WITH_MOZILLA) != "NO"
62
63
# --- Targets ------------------------------------------------------
64
65
.INCLUDE :  target.mk
66
(-)a/main/extensions/source/plugin/base/manager.cxx (+221 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#if STLPORT_VERSION>=321
28
#include <cstdarg>
29
#endif
30
31
#include "plugin/impl.hxx"
32
33
#include "osl/mutex.hxx"
34
#include "unotools/pathoptions.hxx"
35
#include "vcl/configsettings.hxx"
36
37
#include "com/sun/star/container/XEnumerationAccess.hpp"
38
#include "com/sun/star/container/XNameAccess.hpp"
39
#include "com/sun/star/container/XEnumeration.hpp"
40
#include "com/sun/star/container/XElementAccess.hpp"
41
#include "com/sun/star/container/XIndexAccess.hpp"
42
#include "com/sun/star/loader/XImplementationLoader.hpp"
43
#include "com/sun/star/loader/CannotActivateFactoryException.hpp"
44
45
PluginManager* PluginManager::pManager = NULL;
46
47
PluginManager& PluginManager::get()
48
{
49
	if( ! pManager )
50
		pManager = new PluginManager();
51
	return *pManager;
52
}
53
54
void PluginManager::setComponentContext( const Reference< ::com::sun::star::uno::XComponentContext >& xContext )
55
{
56
	PluginManager& rManager = get();
57
	if( ! rManager.m_xContext.is() )
58
		rManager.m_xContext = xContext;
59
}
60
61
PluginManager::PluginManager()
62
{
63
}
64
65
const Sequence< ::rtl::OUString >& PluginManager::getAdditionalSearchPaths()
66
{
67
	static Sequence< ::rtl::OUString > aPaths;
68
69
	if( ! aPaths.getLength() )
70
	{
71
		SvtPathOptions aOptions;
72
		String aPluginPath( aOptions.GetPluginPath() );
73
		if( aPluginPath.Len() )
74
		{
75
			sal_uInt16 nPaths = aPluginPath.GetTokenCount( ';' );
76
			aPaths.realloc( nPaths );
77
			for( sal_uInt16 i = 0; i < nPaths; i++ )
78
				aPaths.getArray()[i] = aPluginPath.GetToken( i, ';' );
79
		}
80
	}
81
82
	return aPaths;
83
}
84
85
//==================================================================================================
86
Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext ) throw( Exception )
87
{
88
	Reference< XInterface >  xService = *new XPluginManager_Impl( rxContext );
89
	return xService;
90
}
91
92
// ::com::sun::star::lang::XServiceInfo
93
::rtl::OUString XPluginManager_Impl::getImplementationName() throw(  )
94
95
{
96
	return getImplementationName_Static();
97
98
}
99
100
// ::com::sun::star::lang::XServiceInfo
101
sal_Bool XPluginManager_Impl::supportsService(const ::rtl::OUString& ServiceName) throw(  )
102
{
103
	Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
104
	const ::rtl::OUString * pArray = aSNL.getConstArray();
105
	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
106
		if( pArray[i] == ServiceName )
107
			return sal_True;
108
	return sal_False;
109
}
110
111
// ::com::sun::star::lang::XServiceInfo
112
Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames(void) throw(  )
113
{
114
	return getSupportedServiceNames_Static();
115
}
116
117
// XPluginManager_Impl
118
Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames_Static(void) throw(  )
119
{
120
	Sequence< ::rtl::OUString > aSNS( 1 );
121
	aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginManager" );
122
	return aSNS;
123
}
124
125
XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext )
126
: m_xContext( rxContext )
127
{
128
	PluginManager::setComponentContext( rxContext );
129
}
130
131
XPluginManager_Impl::~XPluginManager_Impl()
132
{
133
}
134
135
XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance )
136
{
137
	::std::list<XPlugin_Impl*>::iterator iter;
138
	for( iter = PluginManager::get().getPlugins().begin();
139
		 iter != PluginManager::get().getPlugins().end(); ++iter )
140
	{
141
		if( (*iter)->getNPPInstance() == instance )
142
			return *iter;
143
	}
144
145
	return NULL;
146
}
147
148
XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin )
149
{
150
	::std::list<XPlugin_Impl*>::iterator iter;
151
	for( iter = PluginManager::get().getPlugins().begin();
152
		 iter != PluginManager::get().getPlugins().end(); ++iter )
153
	{
154
		if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) )
155
			return *iter;
156
	}
157
158
	return NULL;
159
}
160
161
Sequence<com::sun::star::plugin::PluginDescription> XPluginManager_Impl::getPluginDescriptions() throw()
162
{
163
    Sequence<com::sun::star::plugin::PluginDescription> aRet;
164
165
    vcl::SettingsConfigItem* pCfg = vcl::SettingsConfigItem::get();
166
    rtl::OUString aVal( pCfg->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BrowserPlugins" ) ),
167
                                        rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Disabled" ) ) ) );
168
    if( ! aVal.toBoolean() )
169
    {
170
        aRet = impl_getPluginDescriptions();
171
    }
172
    return aRet;
173
}
174
175
Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPlugin( const Reference< ::com::sun::star::plugin::XPluginContext >& acontext, sal_Int16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const ::com::sun::star::plugin::PluginDescription& plugintype)
176
	throw( RuntimeException,::com::sun::star::plugin::PluginException )
177
{
178
	XPlugin_Impl* pImpl = new XPlugin_Impl( m_xContext );
179
	pImpl->setPluginContext( acontext );
180
181
	PluginManager::get().getPlugins().push_back( pImpl );
182
183
	pImpl->initInstance( plugintype,
184
						 argn,
185
						 argv,
186
						 mode );
187
188
	return pImpl;
189
}
190
191
Reference< ::com::sun::star::plugin::XPlugin >  XPluginManager_Impl::createPluginFromURL( const Reference< ::com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const Reference< ::com::sun::star::awt::XToolkit > & toolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & parent, const ::rtl::OUString& url ) throw()
192
{
193
	XPlugin_Impl* pImpl = new XPlugin_Impl( m_xContext );
194
	Reference< ::com::sun::star::plugin::XPlugin >  xRef = pImpl;
195
196
	pImpl->setPluginContext( acontext );
197
198
	PluginManager::get().getPlugins().push_back( pImpl );
199
200
201
	pImpl->initInstance( url,
202
						 argn,
203
						 argv,
204
						 mode );
205
206
	pImpl->createPeer( toolkit, parent );
207
208
    pImpl->provideNewStream( pImpl->getDescription().Mimetype,
209
                             Reference< com::sun::star::io::XActiveDataSource >(),
210
                             url,
211
                             0, 0, (sal_Bool)(url.compareToAscii( "file:", 5  ) == 0) );
212
213
	if( ! pImpl->getPluginComm() )
214
	{
215
		pImpl->dispose();
216
		xRef = NULL;
217
	}
218
219
	return xRef;
220
}
221
(-)a/main/extensions/source/plugin/base/multiplx.cxx (+328 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <vos/diagnose.hxx>
27
#include <plugin/multiplx.hxx>
28
29
//	---------------------------------------------------------------------
30
//	class MRCListenerMultiplexerHelper
31
//	---------------------------------------------------------------------
32
MRCListenerMultiplexerHelper::MRCListenerMultiplexerHelper
33
(
34
	  const Reference< ::com::sun::star::awt::XWindow >  & rControl
35
	, const Reference< ::com::sun::star::awt::XWindow >  & rPeer
36
)
37
	: xPeer( rPeer )
38
	, xControl( Reference< ::com::sun::star::awt::XControl >( rControl, UNO_QUERY ) )
39
	, aListenerHolder( aMutex )
40
{
41
}
42
43
44
void MRCListenerMultiplexerHelper::setPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer )
45
{
46
	::osl::Guard< ::osl::Mutex > aGuard( aMutex );
47
	if( xPeer != rPeer )
48
	{
49
		if( xPeer.is() )
50
		{
51
			// get all uiks from the listener added to the peer
52
			Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes();
53
			const Type* pArray = aContainedTypes.getConstArray();
54
			sal_Int32 nCount = aContainedTypes.getLength();
55
			// loop over all listener types and remove the listeners from the peer
56
			for( sal_Int32 i = 0; i < nCount; i++ )
57
				unadviseFromPeer( xPeer, pArray[i] );
58
		}
59
		xPeer = rPeer;
60
		if( xPeer.is() )
61
		{
62
			// get all uiks from the listener added to the peer
63
			Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes();
64
			const Type * pArray = aContainedTypes.getConstArray();
65
			sal_Int32 nCount = aContainedTypes.getLength();
66
			// loop over all listener types and add the listeners to the peer
67
			for( sal_Int32 i = 0; i < nCount; i++ )
68
				adviseToPeer( xPeer, pArray[i] );
69
		}
70
	}
71
}
72
73
// MRCListenerMultiplexerHelper
74
void MRCListenerMultiplexerHelper::disposeAndClear()
75
{
76
	::com::sun::star::lang::EventObject aEvt;
77
	aEvt.Source = xControl;
78
	aListenerHolder.disposeAndClear( aEvt );
79
}
80
81
// MRCListenerMultiplexerHelper
82
void MRCListenerMultiplexerHelper::adviseToPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type )
83
{
84
	// add a listener to the source (peer)
85
	if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) )
86
		rPeer->addWindowListener( this );
87
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) )
88
		rPeer->addKeyListener( this );
89
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) )
90
		rPeer->addFocusListener( this );
91
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) )
92
		rPeer->addMouseListener( this );
93
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) )
94
		rPeer->addMouseMotionListener( this );
95
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) )
96
		rPeer->addPaintListener( this );
97
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) )
98
	{
99
		Reference< ::com::sun::star::awt::XTopWindow >  xTop( rPeer, UNO_QUERY );
100
		if( xTop.is() )
101
			xTop->addTopWindowListener( this );
102
	}
103
	else
104
	{
105
		VOS_ENSHURE( sal_False, "unknown listener" );
106
	}
107
}
108
109
// MRCListenerMultiplexerHelper
110
void MRCListenerMultiplexerHelper::unadviseFromPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type )
111
{
112
	// the last listener is removed, remove the listener from the source (peer)
113
	if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) )
114
		rPeer->removeWindowListener( this );
115
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) )
116
		rPeer->removeKeyListener( this );
117
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) )
118
		rPeer->removeFocusListener( this );
119
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) )
120
		rPeer->removeMouseListener( this );
121
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) )
122
		rPeer->removeMouseMotionListener( this );
123
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) )
124
		rPeer->removePaintListener( this );
125
	else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) )
126
	{
127
		Reference< ::com::sun::star::awt::XTopWindow >  xTop( rPeer, UNO_QUERY );
128
		if( xTop.is() )
129
			xTop->removeTopWindowListener( this );
130
	}
131
	else
132
	{
133
		VOS_ENSHURE( sal_False, "unknown listener" );
134
	}
135
}
136
137
// MRCListenerMultiplexerHelper
138
void MRCListenerMultiplexerHelper::advise( const Type & type, const Reference< XInterface > & listener)
139
{
140
	::osl::Guard< ::osl::Mutex > aGuard( aMutex );
141
	if( 1 == aListenerHolder.addInterface( type, listener ) )
142
	{
143
		// the first listener is added
144
		if( xPeer.is() )
145
			adviseToPeer( xPeer, type );
146
	}
147
}
148
149
// MRCListenerMultiplexerHelper
150
void MRCListenerMultiplexerHelper::unadvise(const Type & type, const Reference< XInterface > & listener)
151
{
152
	::osl::Guard< ::osl::Mutex > aGuard( aMutex );
153
	::cppu::OInterfaceContainerHelper * pCont = aListenerHolder.getContainer( type );
154
	if( pCont )
155
	{
156
		if( 0 == pCont->removeInterface( listener ) && xPeer.is() )
157
			// the last listener is removed
158
			unadviseFromPeer( xPeer, type );
159
	}
160
}
161
162
// ::com::sun::star::lang::XEventListener
163
void MRCListenerMultiplexerHelper::disposing(const ::com::sun::star::lang::EventObject& ) throw()
164
{
165
	::osl::Guard< ::osl::Mutex > aGuard( aMutex );
166
	// peer is disposed, clear the reference
167
	xPeer = Reference< ::com::sun::star::awt::XWindow > ();
168
}
169
170
#define MULTIPLEX( InterfaceName, MethodName, EventName )					\
171
::cppu::OInterfaceContainerHelper * pCont;											\
172
pCont = aListenerHolder.getContainer( ::getCppuType((const Reference< InterfaceName >*)0) );		\
173
if( pCont )																	\
174
{																			\
175
	::cppu::OInterfaceIteratorHelper	aIt( *pCont );								\
176
	EventName aEvt = e;														\
177
	/* Remark: The control is the event source not the peer. We must change	*/	\
178
	/* the source of the event */												\
179
	aEvt.Source = xControl;\
180
	/*.is the control not destroyed */										\
181
	if( aEvt.Source.is() )													\
182
	{																		\
183
		if( aIt.hasMoreElements() )											\
184
		{																	\
185
			InterfaceName * pListener = (InterfaceName *)aIt.next();		\
186
			try																\
187
			{																\
188
				pListener->MethodName( aEvt );								\
189
			}																\
190
			catch( RuntimeException& )									\
191
			{																\
192
				/* ignore all usr system exceptions from the listener */	\
193
			}																\
194
		}																	\
195
	}																		\
196
}
197
198
// ::com::sun::star::awt::XFocusListener
199
void MRCListenerMultiplexerHelper::focusGained(const ::com::sun::star::awt::FocusEvent& e) throw()
200
{
201
	MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusGained, ::com::sun::star::awt::FocusEvent )
202
}
203
204
// ::com::sun::star::awt::XFocusListener
205
void MRCListenerMultiplexerHelper::focusLost(const ::com::sun::star::awt::FocusEvent& e) throw()
206
{
207
	MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusLost, ::com::sun::star::awt::FocusEvent )
208
}
209
210
// ::com::sun::star::awt::XWindowListener
211
void MRCListenerMultiplexerHelper::windowResized(const ::com::sun::star::awt::WindowEvent& e) throw()
212
{
213
	MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowResized, ::com::sun::star::awt::WindowEvent )
214
}
215
216
// ::com::sun::star::awt::XWindowListener
217
void MRCListenerMultiplexerHelper::windowMoved(const ::com::sun::star::awt::WindowEvent& e) throw()
218
{
219
	MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowMoved, ::com::sun::star::awt::WindowEvent )
220
}
221
222
// ::com::sun::star::awt::XWindowListener
223
void MRCListenerMultiplexerHelper::windowShown(const ::com::sun::star::lang::EventObject& e) throw()
224
{
225
	MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowShown, ::com::sun::star::lang::EventObject )
226
}
227
228
// ::com::sun::star::awt::XWindowListener
229
void MRCListenerMultiplexerHelper::windowHidden(const ::com::sun::star::lang::EventObject& e) throw()
230
{
231
	MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowHidden, ::com::sun::star::lang::EventObject )
232
}
233
234
// ::com::sun::star::awt::XKeyListener
235
void MRCListenerMultiplexerHelper::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw()
236
{
237
	MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyPressed, ::com::sun::star::awt::KeyEvent )
238
}
239
240
// ::com::sun::star::awt::XKeyListener
241
void MRCListenerMultiplexerHelper::keyReleased(const ::com::sun::star::awt::KeyEvent& e) throw()
242
{
243
	MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyReleased, ::com::sun::star::awt::KeyEvent )
244
}
245
246
// ::com::sun::star::awt::XMouseListener
247
void MRCListenerMultiplexerHelper::mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw()
248
{
249
	MULTIPLEX( ::com::sun::star::awt::XMouseListener, mousePressed, ::com::sun::star::awt::MouseEvent )
250
}
251
252
// ::com::sun::star::awt::XMouseListener
253
void MRCListenerMultiplexerHelper::mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw()
254
{
255
	MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseReleased, ::com::sun::star::awt::MouseEvent )
256
}
257
258
// ::com::sun::star::awt::XMouseListener
259
void MRCListenerMultiplexerHelper::mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw()
260
{
261
	MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseEntered, ::com::sun::star::awt::MouseEvent )
262
}
263
264
// ::com::sun::star::awt::XMouseListener
265
void MRCListenerMultiplexerHelper::mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw()
266
{
267
	MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseExited, ::com::sun::star::awt::MouseEvent )
268
}
269
270
// ::com::sun::star::awt::XMouseMotionListener
271
void MRCListenerMultiplexerHelper::mouseDragged(const ::com::sun::star::awt::MouseEvent& e) throw()
272
{
273
	MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseDragged, ::com::sun::star::awt::MouseEvent )
274
}
275
276
// ::com::sun::star::awt::XMouseMotionListener
277
void MRCListenerMultiplexerHelper::mouseMoved(const ::com::sun::star::awt::MouseEvent& e) throw()
278
{
279
	MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseMoved, ::com::sun::star::awt::MouseEvent )
280
}
281
282
// ::com::sun::star::awt::XPaintListener
283
void MRCListenerMultiplexerHelper::windowPaint(const ::com::sun::star::awt::PaintEvent& e) throw()
284
{
285
	MULTIPLEX( ::com::sun::star::awt::XPaintListener, windowPaint, ::com::sun::star::awt::PaintEvent )
286
}
287
288
// ::com::sun::star::awt::XTopWindowListener
289
void MRCListenerMultiplexerHelper::windowOpened(const ::com::sun::star::lang::EventObject& e) throw()
290
{
291
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowOpened, ::com::sun::star::lang::EventObject )
292
}
293
294
// ::com::sun::star::awt::XTopWindowListener
295
void MRCListenerMultiplexerHelper::windowClosing( const ::com::sun::star::lang::EventObject& e ) throw()
296
{
297
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosing, ::com::sun::star::lang::EventObject )
298
}
299
300
// ::com::sun::star::awt::XTopWindowListener
301
void MRCListenerMultiplexerHelper::windowClosed( const ::com::sun::star::lang::EventObject& e ) throw()
302
{
303
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosed, ::com::sun::star::lang::EventObject )
304
}
305
306
// ::com::sun::star::awt::XTopWindowListener
307
void MRCListenerMultiplexerHelper::windowMinimized( const ::com::sun::star::lang::EventObject& e ) throw()
308
{
309
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowMinimized, ::com::sun::star::lang::EventObject )
310
}
311
312
// ::com::sun::star::awt::XTopWindowListener
313
void MRCListenerMultiplexerHelper::windowNormalized( const ::com::sun::star::lang::EventObject& e ) throw()
314
{
315
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowNormalized, ::com::sun::star::lang::EventObject )
316
}
317
318
// ::com::sun::star::awt::XTopWindowListener
319
void MRCListenerMultiplexerHelper::windowActivated( const ::com::sun::star::lang::EventObject& e ) throw()
320
{
321
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowActivated, ::com::sun::star::lang::EventObject )
322
}
323
324
// ::com::sun::star::awt::XTopWindowListener
325
void MRCListenerMultiplexerHelper::windowDeactivated( const ::com::sun::star::lang::EventObject& e ) throw()
326
{
327
	MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowDeactivated, ::com::sun::star::lang::EventObject )
328
}
(-)a/main/extensions/source/plugin/base/nfuncs.cxx (+696 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#if STLPORT_VERSION>=321
28
#include <cstdarg>
29
#endif
30
31
#include <list>
32
33
#include <plugin/impl.hxx>
34
#include <vcl/svapp.hxx>
35
36
#if OSL_DEBUG_LEVEL > 1
37
#include <osl/thread.h>
38
#include <stdio.h>
39
static FILE * s_file = 0;
40
void TRACE( char const * s )
41
{
42
    if (! s_file)
43
        s_file = stderr;
44
    if (s_file)
45
    {
46
        oslThreadIdentifier t = osl_getThreadIdentifier(0);
47
        fprintf( s_file, "log [t_id=%"SAL_PRIuUINT32"]: %s\n", t, s );
48
        fflush( s_file );
49
    }
50
}
51
void TRACEN( char const * s, long n )
52
{
53
    if (! s_file)
54
        s_file = stderr;
55
    if (s_file)
56
    {
57
        oslThreadIdentifier t = osl_getThreadIdentifier(0);
58
        fprintf( s_file, "log [t_id=%"SAL_PRIuUINT32"]: %s%ld\n", t, s, n );
59
        fflush( s_file );
60
    }
61
}
62
void TRACES( char const* s, char const* s2 )
63
{
64
    if (! s_file)
65
        s_file = stderr;
66
    if (s_file)
67
    {
68
        oslThreadIdentifier t = osl_getThreadIdentifier(0);
69
        fprintf( s_file, "log [t_id=%"SAL_PRIuUINT32"]: %s %s\n", t, s, s2 );
70
        fflush( s_file );
71
    }
72
}
73
#else
74
#define TRACE(x)
75
#define TRACEN(x,n)
76
#define TRACES(x,s)
77
#endif
78
79
using namespace rtl;
80
using namespace com::sun::star::lang;
81
82
/*
83
warning: missing initializer for member '_NPNetscapeFuncs::getstringidentifier' [-Wmissing-field-initializers]
84
warning: missing initializer for member '_NPNetscapeFuncs::getstringidentifiers' [-Wmissing-field-initializers]
85
warning: missing initializer for member '_NPNetscapeFuncs::getintidentifier' [-Wmissing-field-initializers]
86
warning: missing initializer for member '_NPNetscapeFuncs::identifierisstring' [-Wmissing-field-initializers]
87
warning: missing initializer for member '_NPNetscapeFuncs::utf8fromidentifier' [-Wmissing-field-initializers]
88
warning: missing initializer for member '_NPNetscapeFuncs::intfromidentifier' [-Wmissing-field-initializers]
89
warning: missing initializer for member '_NPNetscapeFuncs::createobject' [-Wmissing-field-initializers]
90
warning: missing initializer for member '_NPNetscapeFuncs::retainobject' [-Wmissing-field-initializers]
91
warning: missing initializer for member '_NPNetscapeFuncs::releaseobject' [-Wmissing-field-initializers]
92
warning: missing initializer for member '_NPNetscapeFuncs::invoke' [-Wmissing-field-initializers]
93
warning: missing initializer for member '_NPNetscapeFuncs::invokeDefault' [-Wmissing-field-initializers]
94
warning: missing initializer for member '_NPNetscapeFuncs::evaluate' [-Wmissing-field-initializers]
95
warning: missing initializer for member '_NPNetscapeFuncs::getproperty' [-Wmissing-field-initializers]
96
warning: missing initializer for member '_NPNetscapeFuncs::setproperty' [-Wmissing-field-initializers]
97
warning: missing initializer for member '_NPNetscapeFuncs::removeproperty' [-Wmissing-field-initializers]
98
warning: missing initializer for member '_NPNetscapeFuncs::hasproperty' [-Wmissing-field-initializers]
99
warning: missing initializer for member '_NPNetscapeFuncs::hasmethod' [-Wmissing-field-initializers]
100
warning: missing initializer for member '_NPNetscapeFuncs::releasevariantvalue' [-Wmissing-field-initializers]
101
warning: missing initializer for member '_NPNetscapeFuncs::setexception' [-Wmissing-field-initializers]
102
warning: missing initializer for member '_NPNetscapeFuncs::pushpopupsenabledstate' [-Wmissing-field-initializers]
103
warning: missing initializer for member '_NPNetscapeFuncs::poppopupsenabledstate' [-Wmissing-field-initializers]
104
 */
105
NPNetscapeFuncs aNPNFuncs =
106
{
107
	sizeof( NPNetscapeFuncs ),
108
	(NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR,
109
	NPN_GetURL,
110
	NPN_PostURL,
111
	NPN_RequestRead,
112
	NPN_NewStream,
113
	NPN_Write,
114
	NPN_DestroyStream,
115
	NPN_Status,
116
	NPN_UserAgent,
117
	NPN_MemAlloc,
118
	NPN_MemFree,
119
	NPN_MemFlush,
120
	NPN_ReloadPlugins,
121
#ifdef OJI
122
	NPN_GetJavaEnv,
123
	NPN_GetJavaPeer,
124
#else
125
	0,
126
	0,
127
#endif
128
	NPN_GetURLNotify,
129
	NPN_PostURLNotify,
130
	NPN_GetValue,
131
	NPN_SetValue,
132
	NPN_InvalidateRect,
133
	NPN_InvalidateRegion,
134
	NPN_ForceRedraw
135
};
136
137
static ::rtl::OString normalizeURL( XPlugin_Impl* plugin, const ::rtl::OString& url )
138
{
139
	::rtl::OString aLoadURL;
140
	if( url.indexOf( ":" ) == -1 )
141
	{
142
		aLoadURL = ::rtl::OUStringToOString( plugin->getCreationURL(), plugin->getTextEncoding() );
143
		int nPos;
144
		if( ( nPos = aLoadURL.indexOf( "://" ) ) != -1 )
145
		{
146
			if( url.getLength() && (url.getStr()[ 0 ] == '/' || url.indexOf( '/' ) != -1) )
147
			{
148
				// this means same server but new path
149
				nPos = aLoadURL.indexOf( '/', nPos+3 );
150
151
				if( nPos != -1 )
152
					aLoadURL = aLoadURL.copy( 0, url.getStr()[0] == '/' ? nPos : nPos+1 );
153
			}
154
			else
155
			{
156
				// same server but new file
157
				nPos = aLoadURL.lastIndexOf( '/' );
158
				aLoadURL = aLoadURL.copy( 0, nPos+1 );
159
			}
160
			aLoadURL += url;
161
		}
162
		else
163
			aLoadURL = url;
164
	}
165
	else if( url.indexOf( ":/" ) != -1 )
166
		aLoadURL = url;
167
168
	return aLoadURL;
169
}
170
171
struct AsynchronousGetURL
172
{
173
    OUString						aUrl;
174
    OUString						aTarget;
175
    Reference< XEventListener >		xListener;
176
177
    DECL_LINK( getURL, XPlugin_Impl* );
178
};
179
180
IMPL_LINK( AsynchronousGetURL, getURL, XPlugin_Impl*, pImpl )
181
{
182
    try
183
    {
184
        pImpl->enterPluginCallback();
185
        if( xListener.is() )
186
			pImpl->getPluginContext()->
187
				getURLNotify( pImpl,
188
							  aUrl,
189
							  aTarget,
190
							  xListener );
191
        else
192
            pImpl->getPluginContext()->
193
                getURL( pImpl,
194
                        aUrl,
195
                        aTarget );
196
    }
197
    catch( ::com::sun::star::plugin::PluginException& e )
198
    {
199
        (void)e;
200
    }
201
    pImpl->leavePluginCallback();
202
    delete this;
203
    return 0;
204
}
205
206
207
extern "C" {
208
209
	void* SAL_CALL NP_LOADDS  NPN_MemAlloc( uint32 nBytes )
210
	{
211
		TRACE( "NPN_MemAlloc" );
212
		void* pMem = malloc( nBytes );
213
		return pMem;
214
	}
215
216
	void SAL_CALL NP_LOADDS  NPN_MemFree( void* pMem )
217
	{
218
		TRACE( "NPN_MemFree" );
219
		free( pMem );
220
	}
221
222
	uint32 SAL_CALL NP_LOADDS  NPN_MemFlush( uint32 /*nSize*/ )
223
	{
224
		TRACE( "NPN_MemFlush" );
225
		return 0;
226
	}
227
228
	NPError SAL_CALL NP_LOADDS  NPN_DestroyStream( NPP instance, NPStream* stream, NPError /*reason*/ )
229
	{
230
		TRACE( "NPN_DestroyStream" );
231
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
232
		if( ! pImpl )
233
			return NPERR_INVALID_INSTANCE_ERROR;
234
235
		PluginStream* pStream = pImpl->getStreamFromNPStream( stream );
236
		if( pStream )
237
        {
238
            if( pStream->getStreamType() == InputStream )
239
                static_cast<PluginInputStream*>(pStream)->releaseSelf();
240
            else
241
                delete pStream;
242
        }
243
244
		return NPERR_NO_ERROR;
245
	}
246
247
    #ifdef OJI
248
	const JRIEnvInterface** SAL_CALL NP_LOADDS  NPN_GetJavaEnv()
249
	{
250
		TRACE( "NPN_GetJavaEnv" );
251
		// no java in this program
252
		return NULL;
253
	}
254
255
	jref SAL_CALL NP_LOADDS  NPN_GetJavaPeer( NPP /*instance*/ )
256
	{
257
		TRACE( "NPN_GetJavaPeer" );
258
		return NULL;
259
	}
260
    #endif
261
262
	NPError SAL_CALL NP_LOADDS  NPN_GetURL( NPP instance, const char* url, const char* window )
263
	{
264
		TRACES( "NPN_GetURL", url );
265
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
266
		if( ! pImpl )
267
			return NPERR_INVALID_INSTANCE_ERROR;
268
269
        AsynchronousGetURL* pAsync = new AsynchronousGetURL();
270
271
		OString aLoadURL = normalizeURL( pImpl, url );
272
		TRACES( "NPN_GetURL", aLoadURL.getStr() );
273
        pAsync->aUrl = OStringToOUString( aLoadURL, pImpl->getTextEncoding() );
274
        pAsync->aTarget = OStringToOUString( window, pImpl->getTextEncoding() );
275
        pImpl->setLastGetUrl( aLoadURL );
276
        Application::PostUserEvent( LINK( pAsync, AsynchronousGetURL, getURL ), pImpl );
277
		return NPERR_NO_ERROR;
278
	}
279
280
	NPError SAL_CALL NP_LOADDS  NPN_GetURLNotify( NPP instance, const char* url, const char* target,
281
						  void* notifyData )
282
	{
283
		TRACES( "NPN_GetURLNotify", url );
284
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
285
		if( ! pImpl )
286
			return NPERR_INVALID_INSTANCE_ERROR;
287
288
		OString aLoadURL = normalizeURL( pImpl, url );
289
		if( !aLoadURL.getLength() )
290
			return NPERR_INVALID_URL;
291
292
        AsynchronousGetURL* pAsync = new AsynchronousGetURL();
293
		PluginEventListener* pListener =
294
			new PluginEventListener( pImpl, url, aLoadURL.getStr(), notifyData );
295
		if( ! target || ! *target )
296
		{
297
			// stream will be fed back to plugin,
298
			// notify immediately after destruction of stream
299
			pImpl->addPluginEventListener( pListener );
300
			pListener = NULL;
301
		}
302
        pAsync->aUrl		= OStringToOUString( aLoadURL, pImpl->getTextEncoding() );
303
        pAsync->aTarget		= OStringToOUString( target, pImpl->getTextEncoding() );
304
        pAsync->xListener	= pListener;
305
        pImpl->setLastGetUrl( aLoadURL );
306
        Application::PostUserEvent( LINK( pAsync, AsynchronousGetURL, getURL ), pImpl );
307
308
		return NPERR_NO_ERROR;
309
	}
310
311
	NPError SAL_CALL NP_LOADDS  NPN_NewStream( NPP instance, NPMIMEType type, const char* target,
312
						   NPStream** stream )
313
		// stream is a return value
314
	{
315
		TRACE( "NPN_NewStream" );
316
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
317
		if( ! pImpl )
318
			return NPERR_INVALID_INSTANCE_ERROR;
319
320
		PluginOutputStream* pStream = new PluginOutputStream( pImpl,
321
															  "", 0, 0 );
322
		*stream = pStream->getStream();
323
324
		try
325
		{
326
			pImpl->enterPluginCallback();
327
			pImpl->getPluginContext()->
328
				newStream(
329
					pImpl,
330
					::rtl::OStringToOUString( type, pImpl->getTextEncoding () ),
331
					::rtl::OStringToOUString( target, pImpl->getTextEncoding() ),
332
					::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSource > ( pStream->getOutputStream(), UNO_QUERY )
333
					);
334
			pImpl->leavePluginCallback();
335
		}
336
		catch( ::com::sun::star::plugin::PluginException& e )
337
		{
338
			pImpl->leavePluginCallback();
339
			return e.ErrorCode;
340
		}
341
342
		return NPERR_NO_ERROR;
343
	}
344
345
	NPError SAL_CALL NP_LOADDS  NPN_PostURLNotify( NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData )
346
	{
347
		TRACE( "NPN_PostURLNotify" );
348
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
349
		if( ! pImpl )
350
			return NPERR_INVALID_INSTANCE_ERROR;
351
352
		::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buf, len );
353
354
		::rtl::OString aPostURL = normalizeURL( pImpl, url );
355
		PluginEventListener* pListener =
356
			new PluginEventListener( pImpl, url, aPostURL.getStr(), notifyData );
357
358
		if( ! target || ! *target )
359
		{
360
			// stream will be fed back to plugin,
361
			// notify immediately after destruction of stream
362
			pImpl->addPluginEventListener( pListener );
363
			pListener = NULL;
364
		}
365
366
		try
367
		{
368
			pImpl->enterPluginCallback();
369
			pImpl->getPluginContext()->
370
				postURLNotify( pImpl,
371
							   ::rtl::OStringToOUString( aPostURL, pImpl->getTextEncoding() ),
372
							   ::rtl::OStringToOUString( target, pImpl->getTextEncoding() ),
373
							   Bytes,
374
							   file,
375
							   ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > ( pListener ) );
376
			pImpl->leavePluginCallback();
377
		}
378
		catch( ::com::sun::star::plugin::PluginException& e )
379
		{
380
			pImpl->leavePluginCallback();
381
			return e.ErrorCode;
382
		}
383
384
		return NPERR_NO_ERROR;
385
	}
386
387
	NPError SAL_CALL NP_LOADDS  NPN_PostURL( NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file )
388
	{
389
		TRACE( "NPN_PostURL" );
390
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
391
		if( ! pImpl )
392
			return NPERR_INVALID_INSTANCE_ERROR;
393
394
		::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buf, len );
395
		::rtl::OString aPostURL = normalizeURL( pImpl, url );
396
		try
397
		{
398
			pImpl->enterPluginCallback();
399
			pImpl->getPluginContext()->
400
				postURL( pImpl,
401
						 ::rtl::OStringToOUString( aPostURL, pImpl->getTextEncoding() ),
402
						 ::rtl::OStringToOUString( window, pImpl->getTextEncoding () ),
403
						 Bytes,
404
						 file );
405
			pImpl->leavePluginCallback();
406
		}
407
		catch( ::com::sun::star::plugin::PluginException& e )
408
		{
409
			pImpl->leavePluginCallback();
410
			return e.ErrorCode;
411
		}
412
413
		return NPERR_NO_ERROR;
414
	}
415
416
	NPError SAL_CALL NP_LOADDS  NPN_RequestRead( NPStream* stream, NPByteRange* rangeList )
417
	{
418
		TRACE( "NPN_RequestRead" );
419
		if( ! rangeList )
420
			return NPERR_NO_ERROR;
421
422
		::std::list<XPlugin_Impl*>& rList = PluginManager::get().getPlugins();
423
		::std::list<XPlugin_Impl*>::iterator iter;
424
		XPlugin_Impl* pPlugin = NULL;
425
		PluginStream* pStream = NULL;
426
		for( iter = rList.begin(); iter!= rList.end(); ++iter )
427
        {
428
            pStream = (*iter)->getStreamFromNPStream( stream );
429
			if( pStream )
430
			{
431
				pPlugin = *iter;
432
				break;
433
			}
434
        }
435
		if( ! pPlugin )
436
			return NPERR_INVALID_INSTANCE_ERROR;
437
		if( ! pStream || pStream->getStreamType() != InputStream )
438
			return NPERR_FILE_NOT_FOUND;
439
440
		PluginInputStream* pInputStream = (PluginInputStream*)pStream;
441
		sal_Int8* pBytes = NULL;
442
		int   nBytes = 0;
443
		pPlugin->enterPluginCallback();
444
		while( rangeList )
445
		{
446
			if( pBytes && nBytes < (int)rangeList->length )
447
			{
448
				delete [] pBytes;
449
                pBytes = NULL;
450
			}
451
			if( ! pBytes )
452
				pBytes = new sal_Int8[ nBytes = rangeList->length ];
453
			int nRead =
454
				pInputStream->read( rangeList->offset, pBytes, rangeList->length );
455
			int nPos = 0;
456
			int nNow;
457
			do
458
			{
459
				nNow = pPlugin->getPluginComm()->
460
					NPP_WriteReady( pPlugin->getNPPInstance(),
461
									stream );
462
				nNow = pPlugin->getPluginComm()->
463
					NPP_Write( pPlugin->getNPPInstance(),
464
							   stream,
465
							   rangeList->offset + nPos,
466
							   nNow,
467
							   pBytes+nPos );
468
				nPos += nNow;
469
				nRead -= nNow;
470
			} while( nRead > 0 && nNow );
471
			rangeList = rangeList->next;
472
		}
473
		pPlugin->leavePluginCallback();
474
475
		return NPERR_NO_ERROR;
476
	}
477
478
	void SAL_CALL NP_LOADDS  NPN_Status( NPP instance, const char* message )
479
	{
480
		TRACE( "NPN_Status" );
481
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
482
		if( ! pImpl )
483
			return;
484
485
		try
486
		{
487
			pImpl->enterPluginCallback();
488
			pImpl->getPluginContext()->
489
				displayStatusText( pImpl, ::rtl::OStringToOUString( message, pImpl->getTextEncoding() ) );
490
			pImpl->leavePluginCallback();
491
		}
492
		catch( ::com::sun::star::plugin::PluginException& )
493
		{
494
			pImpl->leavePluginCallback();
495
			return;
496
		}
497
	}
498
499
	const char* SAL_CALL NP_LOADDS  NPN_UserAgent( NPP instance )
500
	{
501
		static char* pAgent = strdup( "Mozilla 3.0" );
502
503
		XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
504
		if( pImpl )
505
        {
506
            rtl::OUString UserAgent;
507
            try
508
            {
509
                pImpl->enterPluginCallback();
510
                UserAgent = pImpl->getPluginContext()->
511
                    getUserAgent( pImpl );
512
                pImpl->leavePluginCallback();
513
                if( pAgent )
514
                    free( pAgent );
515
                pAgent = strdup( ::rtl::OUStringToOString( UserAgent, pImpl->getTextEncoding() ).getStr() );
516
            }
517
            catch( ::com::sun::star::plugin::PluginException& )
518
            {
519
                pImpl->leavePluginCallback();
520
            }
521
        }
522
523
		TRACES( "NPN_UserAgent: returning", pAgent );
524
525
		return pAgent;
526
	}
527
528
void SAL_CALL NP_LOADDS  NPN_Version( int* major, int* minor, int* net_major, int* net_minor )
529
{
530
	TRACE( "NPN_Version" );
531
	*major = 4;
532
	*minor = 0;
533
	*net_major = 4;
534
	*net_minor = 5;
535
}
536
537
int32 SAL_CALL NP_LOADDS  NPN_Write( NPP instance, NPStream* stream, int32 len,
538
				 void* buffer )
539
{
540
	TRACE( "NPN_Write" );
541
	XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
542
	if( ! pImpl )
543
		return 0;
544
545
	PluginStream* pStream = pImpl->getStreamFromNPStream( stream );
546
	if( ! pStream || pStream->getStreamType() != OutputStream )
547
		return 0;
548
549
	pImpl->enterPluginCallback();
550
	::com::sun::star::uno::Sequence<sal_Int8> Bytes( (sal_Int8*)buffer, len );
551
	((PluginOutputStream*)pStream)->getOutputStream()->writeBytes( Bytes );
552
	pImpl->leavePluginCallback();
553
554
	return len;
555
}
556
557
558
NPError SAL_CALL NP_LOADDS  NPN_GetValue( NPP instance, NPNVariable variable, void* value )
559
{
560
	TRACEN( "NPN_GetValue: ", variable );
561
	XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
562
563
	if( ! pImpl )
564
		return 0;
565
    
566
    NPError aResult( NPERR_NO_ERROR );
567
568
	switch( variable )
569
	{
570
		case NPNVxDisplay:
571
            // Unix only, handled in sysdep part
572
		case NPNVxtAppContext:
573
            // Unix only, handled in sysdep part
574
 		default:
575
            aResult = NPERR_INVALID_PARAM;
576
            break;
577
        #ifdef QUARTZ
578
        case 2000: // NPNVsupportsQuickDrawBool
579
            *(NPBool*)value = false;
580
            break;
581
        case 2001: // NPNVsupportsCoreGraphicsBool
582
            *(NPBool*)value = true;
583
            break;
584
        #endif
585
        case NPNVjavascriptEnabledBool:
586
            // no javascript
587
            *(NPBool*)value = false;
588
            break;
589
        case NPNVasdEnabledBool:
590
            // no SmartUpdate
591
            *(NPBool*)value = false;
592
            break;
593
        case NPNVisOfflineBool:
594
            // no offline browsing
595
            *(NPBool*)value = false;
596
            break;
597
	}
598
    /*
599
    provisional code should there ever be NPNVariables that we actually
600
    want to query from the PluginContext
601
	::rtl::OUString aValue;
602
	try
603
	{
604
		pImpl->enterPluginCallback();
605
		aValue = pImpl->getPluginContext()->
606
			getValue( pImpl, (::com::sun::star::plugin::PluginVariable)variable );
607
		pImpl->leavePluginCallback();
608
	}
609
	catch( ::com::sun::star::plugin::PluginException& e )
610
	{
611
		pImpl->leavePluginCallback();
612
		return e.ErrorCode;
613
	}
614
    */
615
616
	return aResult;
617
}
618
619
void SAL_CALL NP_LOADDS  NPN_ReloadPlugins(NPBool /*reloadPages*/)
620
{
621
	TRACE( "NPN_ReloadPlugins" );
622
}
623
624
625
NPError SAL_CALL NP_LOADDS  NPN_SetValue( NPP instance,
626
                                          NPPVariable variable,
627
                                          void* value )
628
{
629
    NPError nError = NPERR_NO_ERROR;
630
	TRACEN( "NPN_SetValue ", variable );
631
    switch( variable )
632
    {
633
    #ifdef QUARTZ
634
    case (NPPVariable)1000: // NPNVpluginDrawingModel
635
    {
636
        int nDrawingModel = (int)value; // ugly, but that's the way we need to do it
637
        
638
        TRACEN( "drawing model: ", nDrawingModel );
639
        
640
        XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
641
        if( pImpl )
642
            pImpl->getSysPlugData().m_nDrawingModel = nDrawingModel;
643
    }
644
    break;
645
    #endif
646
    case NPPVpluginNameString: // make the windows compiler happy, it needs at least one case statement
647
        break;
648
    default:
649
        break;
650
    }
651
    #ifndef QUARTZ
652
    (void)instance;
653
    (void)value;
654
    #endif
655
	return nError;
656
}
657
658
void SAL_CALL NP_LOADDS  NPN_InvalidateRect(NPP instance, NPRect* /*invalidRect*/)
659
{
660
	TRACE( "NPN_InvalidateRect" );
661
662
    #ifdef QUARTZ
663
    NPN_ForceRedraw( instance );
664
    #else
665
    (void)instance;
666
    #endif
667
}
668
669
void SAL_CALL NP_LOADDS  NPN_InvalidateRegion(NPP instance, NPRegion /*invalidRegion*/)
670
{
671
	TRACE( "NPN_InvalidateRegion" );
672
673
    #ifdef QUARTZ
674
    NPN_ForceRedraw( instance );
675
    #else
676
    (void)instance;
677
    #endif
678
}
679
680
void SAL_CALL NP_LOADDS  NPN_ForceRedraw(NPP instance)
681
{
682
	TRACE( "NPN_ForceRedraw" );
683
    #ifdef QUARTZ
684
    XPlugin_Impl* pImpl = XPluginManager_Impl::getXPluginFromNPP( instance );
685
    if( pImpl )
686
    {
687
        SysPlugData& rPlugData( pImpl->getSysPlugData() );
688
        if( rPlugData.m_pPlugView )
689
            [rPlugData.m_pPlugView setNeedsDisplay: YES];
690
    }
691
    #else
692
    (void)instance;
693
    #endif
694
}
695
696
}
(-)a/main/extensions/source/plugin/base/plcom.cxx (+67 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#ifdef SOLARIS
28
#include <limits>
29
#endif
30
31
#if STLPORT_VERSION>=321
32
#include <cstdarg>
33
#endif
34
35
#include <tools/fsys.hxx>
36
#include <plugin/impl.hxx>
37
38
PluginComm::PluginComm( const ::rtl::OString& rLibName, bool bReusable ) :
39
		m_nRefCount( 0 ),
40
		m_aLibName( rLibName )
41
{
42
    if( bReusable )
43
	    PluginManager::get().getPluginComms().push_back( this );
44
}
45
46
PluginComm::~PluginComm()
47
{
48
	PluginManager::get().getPluginComms().remove( this );
49
	while( m_aFilesToDelete.size() )
50
	{
51
		String aFile = m_aFilesToDelete.front();
52
		m_aFilesToDelete.pop_front();
53
		DirEntry aEntry( aFile );
54
		aEntry.Kill();
55
	}
56
}
57
58
NPError PluginComm::NPP_SetWindow( XPlugin_Impl* i_pImpl )
59
{
60
    return NPP_SetWindow( i_pImpl->getNPPInstance(), i_pImpl->getNPWindow() );
61
}
62
63
NPError PluginComm::NPP_Destroy( XPlugin_Impl* i_pImpl, NPSavedData** save )
64
{
65
    return NPP_Destroy( i_pImpl->getNPPInstance(), save );
66
}
67
(-)a/main/extensions/source/plugin/base/plctrl.cxx (+319 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <com/sun/star/awt/XAdjustmentListener.hpp>
27
#include <com/sun/star/awt/XActionListener.hpp>
28
#include <com/sun/star/awt/XTextListener.hpp>
29
#include <com/sun/star/awt/XSpinListener.hpp>
30
#include <com/sun/star/awt/XItemListener.hpp>
31
#include <com/sun/star/awt/XVclContainerListener.hpp>
32
33
#include <plugin/plctrl.hxx>
34
#include <vcl/syschild.hxx>
35
#include <toolkit/helper/vclunohelper.hxx>
36
37
38
//--------------------------------------------------------------------------------------------------
39
PluginControl_Impl::PluginControl_Impl() :
40
	_pMultiplexer( NULL )
41
	, _nX( 0 )
42
	, _nY( 0 )
43
	, _nWidth( 100 )
44
	, _nHeight( 100 )
45
	, _nFlags( WINDOW_POSSIZE_ALL )
46
	, _bVisible( sal_False )
47
	, _bInDesignMode( sal_False )
48
	, _bEnable( sal_True )
49
{
50
}
51
52
//--------------------------------------------------------------------------------------------------
53
PluginControl_Impl::~PluginControl_Impl()
54
{
55
}
56
57
MRCListenerMultiplexerHelper* PluginControl_Impl::getMultiplexer()
58
{
59
	if( ! _pMultiplexer )
60
		_pMultiplexer = new MRCListenerMultiplexerHelper( this, _xPeerWindow );
61
	return _pMultiplexer;
62
}
63
//==================================================================================================
64
65
void PluginControl_Impl::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l )
66
	throw( RuntimeException )
67
{
68
	_aDisposeListeners.push_back( l );
69
}
70
71
//---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
72
void PluginControl_Impl::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l )
73
	throw( RuntimeException )
74
{
75
	_aDisposeListeners.remove( l );
76
}
77
78
//---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
79
void PluginControl_Impl::dispose(void)
80
	throw( RuntimeException )
81
{
82
	// send disposing events
83
	::com::sun::star::lang::EventObject aEvt;
84
	if( getMultiplexer() )
85
		getMultiplexer()->disposeAndClear();
86
87
	// release context
88
	_xContext = Reference< XInterface > ();
89
	releasePeer();
90
}
91
92
93
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
94
void PluginControl_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags )
95
	throw( RuntimeException )
96
{
97
	_nX			= nX_ >=0 ? nX_ : 0;
98
	_nY			= nY_ >=0 ? nY_ : 0;
99
	_nWidth		= nWidth_ >=0 ? nWidth_ : 0;
100
	_nHeight	= nHeight_ >=0 ? nHeight_ : 0;
101
	_nFlags		= nFlags;
102
103
	if (_xPeerWindow.is())
104
		_xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, nFlags );
105
}
106
107
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
108
::com::sun::star::awt::Rectangle PluginControl_Impl::getPosSize(void)
109
	throw( RuntimeException )
110
{
111
	return _xPeerWindow->getPosSize();
112
}
113
114
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
115
void PluginControl_Impl::setVisible( sal_Bool bVisible )
116
	throw( RuntimeException )
117
{
118
	_bVisible = bVisible;
119
	if (_xPeerWindow.is())
120
		_xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
121
}
122
	
123
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
124
void PluginControl_Impl::setEnable( sal_Bool bEnable )
125
	throw( RuntimeException )
126
{
127
	_bEnable = bEnable;
128
	if (_xPeerWindow.is())
129
		_xPeerWindow->setEnable( _bEnable );
130
}
131
	
132
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
133
void PluginControl_Impl::setFocus(void) throw( RuntimeException )
134
{
135
	if (_xPeerWindow.is())
136
		_xPeerWindow->setFocus();
137
}
138
139
140
//--------------------------------------------------------------------------------------------------
141
void PluginControl_Impl::releasePeer()
142
{
143
	if (_xPeer.is())
144
	{
145
		_xParentWindow->removeFocusListener( this );
146
		_xPeerWindow->dispose();
147
		_pSysChild		= NULL;
148
		_xPeerWindow	= Reference< ::com::sun::star::awt::XWindow > ();
149
		_xPeer			= Reference< ::com::sun::star::awt::XWindowPeer > ();
150
		getMultiplexer()->setPeer( Reference< ::com::sun::star::awt::XWindow > () );
151
	}
152
}
153
154
//---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
155
void PluginControl_Impl::createPeer( const Reference< ::com::sun::star::awt::XToolkit > & /*xToolkit*/, const Reference< ::com::sun::star::awt::XWindowPeer >  & xParentPeer )
156
	throw( RuntimeException )
157
{
158
	if (_xPeer.is())
159
	{
160
		DBG_ERROR( "### Peer is already set!" );
161
		return;
162
    }
163
164
	_xParentPeer = xParentPeer;
165
	_xParentWindow = Reference< ::com::sun::star::awt::XWindow > ( xParentPeer, UNO_QUERY );
166
	DBG_ASSERT( _xParentWindow.is(), "### no parent peer window!" );
167
	
168
	Window* pImpl = VCLUnoHelper::GetWindow( xParentPeer );
169
	if (pImpl)
170
	{
171
        _pSysChild = new SystemChildWindow( pImpl, WB_CLIPCHILDREN );
172
        if (pImpl->HasFocus())
173
            _pSysChild->GrabFocus();
174
        
175
		// get peer
176
		_xPeer			= Reference< ::com::sun::star::awt::XWindowPeer > ( _pSysChild->GetComponentInterface() );
177
		_xPeerWindow	= Reference< ::com::sun::star::awt::XWindow > ( _xPeer, UNO_QUERY );
178
		// !_BOTH_ MUST BE VALID!
179
		DBG_ASSERT( (_xPeer.is() && _xPeerWindow.is()), "### no peer!" );
180
		
181
		_xParentWindow->addFocusListener( this );
182
		_xPeerWindow->setPosSize( _nX, _nY, _nWidth, _nHeight, _nFlags );
183
		_xPeerWindow->setEnable( _bEnable );
184
		_xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
185
	}
186
	else
187
	{
188
		DBG_ERROR( "### cannot get implementation of parent peer!" );
189
	}
190
191
	getMultiplexer()->setPeer( _xPeerWindow );
192
}
193
194
//---- ::com::sun::star::awt::XControl ------------------------------------------------------------------------------------
195
void PluginControl_Impl::setDesignMode( sal_Bool bOn )
196
	throw( RuntimeException )
197
{
198
	_bInDesignMode = bOn;
199
	if (_xPeerWindow.is())
200
		_xPeerWindow->setVisible( _bVisible && !_bInDesignMode );
201
}
202
203
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
204
void PluginControl_Impl::addPaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l )
205
	throw( RuntimeException )
206
{
207
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0), l );
208
}
209
210
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
211
void PluginControl_Impl::removePaintListener( const Reference< ::com::sun::star::awt::XPaintListener > & l )
212
	throw( RuntimeException )
213
{
214
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0), l );
215
}
216
217
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
218
void PluginControl_Impl::addWindowListener(	const Reference< ::com::sun::star::awt::XWindowListener > & l )
219
	throw( RuntimeException )
220
{
221
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0), l );
222
}
223
224
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
225
void PluginControl_Impl::removeWindowListener( const Reference< ::com::sun::star::awt::XWindowListener > & l )
226
	throw( RuntimeException )
227
{
228
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0), l );
229
}
230
231
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
232
void PluginControl_Impl::addFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l )
233
	throw( RuntimeException )
234
{
235
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0), l );
236
}
237
238
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
239
void PluginControl_Impl::removeFocusListener( const Reference< ::com::sun::star::awt::XFocusListener > & l )
240
	throw( RuntimeException )
241
{
242
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0), l );
243
}
244
245
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
246
void PluginControl_Impl::addKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l )
247
	throw( RuntimeException )
248
{
249
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0), l );
250
}
251
252
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
253
void PluginControl_Impl::removeKeyListener( const Reference< ::com::sun::star::awt::XKeyListener > & l )
254
	throw( RuntimeException )
255
{
256
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0), l );
257
}
258
259
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
260
void PluginControl_Impl::addMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l )
261
	throw( RuntimeException )
262
{
263
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0), l );
264
}
265
266
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
267
void PluginControl_Impl::removeMouseListener( const Reference< ::com::sun::star::awt::XMouseListener > & l )
268
	throw( RuntimeException )
269
{
270
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0), l );
271
}
272
273
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
274
void PluginControl_Impl::addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l )
275
	throw( RuntimeException )
276
{
277
	getMultiplexer()->advise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0), l );
278
}
279
280
//---- ::com::sun::star::awt::XWindow -------------------------------------------------------------------------------------
281
void PluginControl_Impl::removeMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l )
282
	throw( RuntimeException )
283
{
284
	getMultiplexer()->unadvise( ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0), l );
285
}
286
287
288
//---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
289
void PluginControl_Impl::draw( sal_Int32 /*x*/, sal_Int32 /*y*/ )
290
	throw( RuntimeException )
291
{
292
	// has to be done by further implementation of control
293
}
294
295
//---- ::com::sun::star::awt::XView ---------------------------------------------------------------------------------------
296
void PluginControl_Impl::setZoom( float /*ZoomX*/, float /*ZoomY*/ )
297
	throw( RuntimeException )
298
{
299
	// has to be done by further implementation of control
300
}
301
302
//---- ::com::sun::star::lang::XEventListener ------------------------------------------------------------------------------
303
void PluginControl_Impl::disposing( const ::com::sun::star::lang::EventObject & /*rSource*/ )
304
	throw( RuntimeException )
305
{
306
}
307
//---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
308
void PluginControl_Impl::focusGained( const ::com::sun::star::awt::FocusEvent & /*rEvt*/ )
309
	throw( RuntimeException )
310
{
311
	if (_xPeerWindow.is())
312
		_xPeerWindow->setFocus();
313
}
314
//---- ::com::sun::star::awt::XFocusListener ------------------------------------------------------------------------------
315
void PluginControl_Impl::focusLost( const ::com::sun::star::awt::FocusEvent & /*rEvt*/ )
316
	throw( RuntimeException )
317
{
318
}
319
(-)a/main/extensions/source/plugin/base/plmodel.cxx (+199 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <plugin/model.hxx>
27
#include <com/sun/star/beans/PropertyAttribute.hpp>
28
29
using namespace com::sun::star::uno;
30
31
//==================================================================================================
32
Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::uno::XComponentContext >  & ) throw( Exception )
33
{
34
	Reference< XInterface >  xService = *new PluginModel();
35
	return xService;
36
}
37
38
Any PluginModel::queryAggregation( const Type& type ) throw( RuntimeException )
39
{
40
	Any aRet( ::cppu::queryInterface( type,
41
									  static_cast< ::com::sun::star::lang::XComponent* >(this),
42
									  static_cast< ::com::sun::star::io::XPersistObject* >(this ),
43
									  static_cast< ::com::sun::star::awt::XControlModel* >(this),
44
									  static_cast< ::com::sun::star::beans::XPropertySet* >(this),
45
									  static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this),
46
									  static_cast< ::com::sun::star::beans::XFastPropertySet* >(this)
47
		) );
48
	return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type );
49
}
50
51
52
// XPluginManager_Impl
53
Sequence< ::rtl::OUString > PluginModel::getSupportedServiceNames_Static(void) throw()
54
{
55
	Sequence< ::rtl::OUString > aSNS( 1 );
56
	aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" );
57
	return aSNS;
58
}
59
60
61
static const char* aCreationURL = "URL";
62
static const char* aMime = "TYPE";
63
64
static ::osl::Mutex aPropertyMutex;
65
66
static ::com::sun::star::beans::Property aProps[] =
67
{
68
	::com::sun::star::beans::Property(
69
		::rtl::OUString::createFromAscii( aMime ),
70
		1,
71
		::getCppuType((const ::rtl::OUString*)0),
72
		::com::sun::star::beans::PropertyAttribute::BOUND ),
73
	::com::sun::star::beans::Property(
74
		::rtl::OUString::createFromAscii( aCreationURL ),
75
		2,
76
		::getCppuType((const ::rtl::OUString*)0),
77
		::com::sun::star::beans::PropertyAttribute::BOUND )
78
};
79
80
PluginModel::PluginModel() :
81
		BroadcasterHelperHolder( aPropertyMutex ),
82
		OPropertySetHelper( m_aHelper ),
83
		OPropertyArrayHelper( aProps, 2 )
84
{
85
}
86
87
PluginModel::PluginModel(const ::rtl::OUString& rURL, const rtl::OUString& rMimeType ) :
88
		BroadcasterHelperHolder( aPropertyMutex ),
89
		OPropertySetHelper( m_aHelper ),
90
		OPropertyArrayHelper( aProps, 2 ),
91
		m_aCreationURL( rURL ),
92
        m_aMimeType( rMimeType )
93
{
94
}
95
96
PluginModel::~PluginModel()
97
{
98
}
99
100
Reference< ::com::sun::star::beans::XPropertySetInfo >  PluginModel::getPropertySetInfo() throw()
101
{
102
	static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo =
103
		createPropertySetInfo( *this );
104
	return aInfo;
105
}
106
107
::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper()
108
{
109
	return *this;
110
}
111
112
sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue,
113
                                                Any & rOldValue, 
114
                                                sal_Int32 nHandle,
115
                                                const Any& rValue ) throw()
116
{
117
    if( nHandle == 1 || nHandle == 2 )
118
    {
119
        if( rValue.getValueTypeClass() == TypeClass_STRING )   
120
        {
121
            rConvertedValue = rValue;
122
            if( nHandle == 2 )
123
                rOldValue <<= m_aCreationURL;
124
            else if( nHandle == 1 )
125
                rOldValue <<= m_aMimeType;
126
            return sal_True;
127
        }
128
    }
129
	return sal_False;
130
}
131
132
void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
133
													const Any& rValue )
134
    throw(::com::sun::star::uno::Exception)
135
{
136
	if( rValue.getValueTypeClass() == TypeClass_STRING ) // FIXME wrong type!
137
138
	{
139
        if( nHandle == 2 )
140
            rValue >>= m_aCreationURL;
141
        else if( nHandle == 1 )
142
            rValue >>= m_aMimeType;
143
	}
144
	else
145
		throw ::com::sun::star::lang::IllegalArgumentException();
146
}
147
148
void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw()
149
{
150
    if( nHandle == 2 )
151
        rValue <<= m_aCreationURL;
152
    else if( nHandle == 1 )
153
        rValue <<= m_aMimeType;
154
}
155
156
//---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
157
void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
158
{
159
	m_aDisposeListeners.push_back( l );
160
}
161
162
//---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
163
void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
164
{
165
	m_aDisposeListeners.remove( l );
166
}
167
168
//---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
169
void PluginModel::dispose(void) throw()
170
{
171
	// send disposing events
172
	::com::sun::star::lang::EventObject aEvt;
173
	aEvt.Source = (::cppu::OWeakObject*)this;
174
	::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners;
175
	for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin();
176
		 it != aLocalListeners.end(); ++it )
177
		(*it)->disposing( aEvt );
178
179
	m_aDisposeListeners.clear();
180
	
181
	disposing();
182
}
183
184
185
// ::com::sun::star::io::XPersistObject
186
::rtl::OUString PluginModel::getServiceName() throw()
187
{
188
	return ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" );
189
}
190
191
void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) throw()
192
{
193
	OutStream->writeUTF( m_aCreationURL );
194
}
195
196
void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) throw()
197
{
198
	m_aCreationURL = InStream->readUTF();
199
}
(-)a/main/extensions/source/plugin/base/service.cxx (+74 lines)
Line 0 Link Here
1
/**************************************************************
2
 *
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 *
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 *
20
 *************************************************************/
21
22
// MARKER(update_precomp.py): autogen include statement, do not remove
23
#include "precompiled_extensions.hxx"
24
25
#include <plugin/impl.hxx>
26
#include <cppuhelper/factory.hxx>
27
#include <cppuhelper/implementationentry.hxx>
28
29
30
namespace pq_sdbc_driver
31
{
32
    void *SAL_CALL CreateDriverSingleton( void *pServiceManager );
33
34
    static struct cppu::ImplementationEntry g_entries[] =
35
    {
36
        {
37
            PluginManager_CreateInstance,
38
            XPluginManager_Impl::getImplementationName_Static,
39
            XPluginManager_Impl::getSupportedServiceNames_Static,
40
            cppu::createSingleComponentFactory,
41
            0,
42
            0
43
        },
44
        {
45
            PluginModel_CreateInstance,
46
            PluginModel::getImplementationName_Static,
47
            PluginModel::getSupportedServiceNames_Static,
48
            cppu::createSingleComponentFactory,
49
            0,
50
            0
51
        },
52
        { 0, 0, 0, 0, 0, 0 }
53
    };
54
}
55
56
extern "C"
57
{
58
    SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
59
        const sal_Char **ppEnvTypeName, uno_Environment **/*ppEnv*/ )
60
    {
61
        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
62
    }
63
64
    SAL_DLLPUBLIC_EXPORT void *SAL_CALL component_getFactory(
65
        const sal_Char *pImplName, void *pServiceManager, void *pRegistryKey )
66
    {
67
        return ::cppu::component_getFactoryHelper(
68
                pImplName,
69
                pServiceManager,
70
                pRegistryKey ,
71
                pq_sdbc_driver::g_entries );
72
    }
73
}
74
(-)a/main/extensions/source/plugin/base/xplugin.cxx (+1159 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
27
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
28
#include <com/sun/star/loader/XImplementationLoader.hpp>
29
#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
30
31
#include <plugin/impl.hxx>
32
#include <tools/fsys.hxx>
33
#include <ucbhelper/content.hxx>
34
#include <tools/urlobj.hxx>
35
#include <tools/string.hxx>
36
#include <vcl/svapp.hxx>
37
#include <vos/timer.hxx>
38
#include <osl/file.hxx>
39
40
#ifdef UNX
41
#include <sys/types.h>
42
#include <sys/socket.h>
43
#endif
44
45
#if OSL_DEBUG_LEVEL > 1
46
#include <stdio.h>
47
#endif
48
49
using namespace com::sun::star;
50
using namespace com::sun::star::io;
51
using namespace com::sun::star::beans;
52
using namespace com::sun::star::plugin;
53
using namespace rtl;
54
using namespace osl;
55
56
class PluginDisposer : public vos::OTimer
57
{
58
private:
59
    XPlugin_Impl*       m_pPlugin;
60
61
    virtual void SAL_CALL onShot();
62
public:
63
    PluginDisposer( XPlugin_Impl* pPlugin ) :
64
        OTimer( vos::TTimeValue( 2, 0 ),
65
                vos::TTimeValue( 2, 0 ) ),
66
        m_pPlugin( pPlugin )
67
        { start(); }
68
    ~PluginDisposer() {}
69
};
70
71
void PluginDisposer::onShot()
72
{
73
    if( m_pPlugin )
74
    {
75
        if( m_pPlugin->isDisposable() )
76
        {
77
            sal_uLong nEvent;
78
            Application::PostUserEvent( nEvent, LINK( m_pPlugin, XPlugin_Impl, secondLevelDispose ), (void*)m_pPlugin );
79
        }
80
    }
81
    else
82
        release();
83
}
84
85
//==================================================================================================
86
87
Any XPlugin_Impl::queryInterface( const Type& type ) throw( RuntimeException )
88
{
89
    return OWeakAggObject::queryInterface( type );
90
}
91
92
Any XPlugin_Impl::queryAggregation( const Type& type ) throw( RuntimeException )
93
{
94
    Any aRet( cppu::queryInterface( type, static_cast< XPlugin* >(this) ) );
95
    if( ! aRet.hasValue() )
96
        aRet = PluginControl_Impl::queryAggregation( type );
97
    return aRet;
98
}
99
100
101
XPlugin_Impl::XPlugin_Impl( const uno::Reference< com::sun::star::uno::XComponentContext >  & rxContext) :
102
        PluginControl_Impl(),
103
        m_xContext( rxContext ),
104
        m_pPluginComm( NULL ),
105
        m_aEncoding( gsl_getSystemTextEncoding() ),
106
        m_pArgv( NULL ),
107
        m_pArgn( NULL ),
108
        m_nArgs( 0 ),
109
        m_aPluginMode( NP_FULL ),
110
        m_nProvidingState( PROVIDING_NONE ),
111
        m_nCalledFromPlugin( 0 ),
112
        m_pDisposer( NULL ),
113
        m_bIsDisposed( sal_False )
114
{
115
    memset( &m_aInstance, 0, sizeof( m_aInstance ) );
116
    memset( &m_aNPWindow, 0, sizeof( m_aNPWindow ) );
117
    memset( &m_aSysPlugData, 0, sizeof( m_aSysPlugData ) );
118
119
    m_xModel = new PluginModel();
120
    uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
121
    xPS->addPropertyChangeListener( OUString(), this );
122
123
    Guard< Mutex > aGuard( PluginManager::get().getPluginMutex() );
124
    PluginManager::get().getPlugins().push_back( this );
125
}
126
127
void XPlugin_Impl::destroyInstance()
128
{
129
    Guard< Mutex > aGuard( m_aMutex );
130
131
    NPSavedData* pSavedData = NULL;
132
133
    destroyStreams();
134
    if( getPluginComm() )
135
    {
136
        getPluginComm()->NPP_Destroy( this, &pSavedData );
137
        getPluginComm()->decRef();
138
        m_pPluginComm = NULL;
139
    }
140
141
    freeArgs();
142
143
    while( m_aPEventListeners.size() )
144
    {
145
        delete *m_aPEventListeners.begin();
146
        m_aPEventListeners.pop_front();
147
    }
148
}
149
150
XPlugin_Impl::~XPlugin_Impl()
151
{
152
    destroyInstance();
153
}
154
155
void XPlugin_Impl::checkListeners( const char* normalizedURL )
156
{
157
    if( ! normalizedURL )
158
        return;
159
160
    Guard< Mutex > aGuard( m_aMutex );
161
162
    std::list<PluginEventListener*>::iterator iter;
163
    for( iter = m_aPEventListeners.begin();
164
         iter != m_aPEventListeners.end();
165
         ++iter )
166
    {
167
        if( ! strcmp( normalizedURL, (*iter)->getURL() ) ||
168
            ! strcmp( normalizedURL, (*iter)->getNormalizedURL() ) )
169
        {
170
            (*iter)->disposing( com::sun::star::lang::EventObject() );
171
            delete *iter;
172
            m_aPEventListeners.remove( *iter );
173
            return;
174
        }
175
    }
176
}
177
178
IMPL_LINK( XPlugin_Impl, secondLevelDispose, XPlugin_Impl*, /*pThis*/ )
179
{
180
    Guard< Mutex > aGuard( m_aMutex );
181
182
    // may have become undisposable between PostUserEvent and here
183
    // or may have disposed and receive a second UserEvent
184
    std::list<XPlugin_Impl*>& rList = PluginManager::get().getPlugins();
185
    std::list<XPlugin_Impl*>::iterator iter;
186
187
    {
188
        Guard< Mutex > aPluginGuard( PluginManager::get().getPluginMutex() );
189
        for( iter = rList.begin(); iter != rList.end(); ++iter )
190
        {
191
            if( *iter == this )
192
                break;
193
        }
194
        if( iter == rList.end() || ! isDisposable() )
195
            return 0;
196
    }
197
198
    if (m_pDisposer)
199
    {
200
        m_pDisposer->release();
201
        m_pDisposer = NULL;
202
    }
203
204
    uno::Reference< XPlugin >  xProtection( this );
205
    uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
206
    xPS->removePropertyChangeListener( OUString(), this );
207
    {
208
        Guard< Mutex > aPluginGuard( PluginManager::get().getPluginMutex() );
209
        rList.remove( this );
210
    }
211
    m_aNPWindow.window = NULL;
212
#ifndef UNX
213
    // acrobat does an unconditional XtParent on the windows widget
214
    getPluginComm()->NPP_SetWindow( this );
215
#endif
216
    destroyInstance();
217
    PluginControl_Impl::dispose();
218
    return 0;
219
}
220
221
void XPlugin_Impl::dispose() throw()
222
{
223
    Guard< Mutex > aGuard( m_aMutex );
224
225
    if (m_bIsDisposed || !getPluginComm())
226
        return;
227
    m_bIsDisposed = sal_True;
228
229
    if( isDisposable() )
230
        secondLevelDispose( this );
231
    else
232
    {
233
        m_pDisposer = new PluginDisposer( this );
234
        m_pDisposer->acquire();
235
    }
236
}
237
238
void XPlugin_Impl::initArgs( const Sequence< OUString >& argn,
239
                             const Sequence< OUString >& argv,
240
                             sal_Int16 mode )
241
{
242
    m_aPluginMode = mode;
243
244
    m_nArgs = argn.getLength();
245
    m_pArgn = new const char*[m_nArgs];
246
    m_pArgv = new const char*[m_nArgs];
247
    const OUString* pUArgn = argn.getConstArray();
248
    const OUString* pUArgv = argv.getConstArray();
249
    for( int i = 0; i < m_nArgs; i++ )
250
    {
251
        m_pArgn[i] = strdup(
252
            OUStringToOString( pUArgn[i], m_aEncoding ).getStr()
253
            );
254
        m_pArgv[i] = strdup(
255
            OUStringToOString( pUArgv[i], m_aEncoding ).getStr()
256
            );
257
    }
258
}
259
260
void XPlugin_Impl::freeArgs()
261
{
262
    if( m_nArgs > 0 )
263
    {
264
        for( ; m_nArgs--; )
265
        {
266
            free( (void*)m_pArgn[m_nArgs] );
267
            free( (void*)m_pArgv[m_nArgs] );
268
        }
269
        delete [] m_pArgn;
270
        delete [] m_pArgv;
271
    }
272
}
273
274
void XPlugin_Impl::prependArg( const char* pName, const char* pValue )
275
{
276
    const char** pNewNames		= new const char*[m_nArgs+1];
277
    const char** pNewValues	= new const char*[m_nArgs+1];
278
    
279
    pNewNames[0]		= strdup( pName );
280
    pNewValues[0]		= strdup( pValue );
281
    for( int nIndex = 0; nIndex < m_nArgs; ++nIndex )
282
    {
283
        pNewNames[nIndex+1]	= m_pArgn[nIndex];
284
        pNewValues[nIndex+1]= m_pArgv[nIndex];
285
    }
286
    // free old arrays
287
    delete [] m_pArgn;
288
    delete [] m_pArgv;
289
    // set new arrays
290
    m_pArgn = pNewNames;
291
    m_pArgv = pNewValues;
292
    // set new number of arguments
293
    m_nArgs++;
294
#if OSL_DEBUG_LEVEL > 1
295
    fprintf( stderr, "inserted %s=%s\n", pNewNames[0], pNewValues[0] );
296
#endif
297
}
298
299
void XPlugin_Impl::handleSpecialArgs()
300
{
301
    // special handling for real audio which needs a lot of parameters
302
    // or won't function at all
303
    if( ! m_aDescription.Mimetype.compareToAscii( "audio/x-pn-realaudio-plugin" ) && m_nArgs < 1 )
304
    {
305
        OUString aURL;
306
        if( m_xModel.is() )
307
        {
308
            try
309
            {
310
                uno::Reference< XPropertySet > xProp( m_xModel, UNO_QUERY );
311
                Any aProp = xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
312
                aProp >>= aURL;
313
            }
314
            catch( UnknownPropertyException )
315
            {
316
            }
317
        }
318
        
319
        if( aURL.getLength() )
320
        {
321
            // set new args, old args need not be freed as there were none set
322
            m_nArgs = 6;
323
            m_pArgn = new const char*[m_nArgs];
324
            m_pArgv = new const char*[m_nArgs];
325
326
            // SRC
327
            m_pArgn[0]		= strdup( "SRC" );
328
            m_pArgv[0]		= strdup( OUStringToOString( aURL, m_aEncoding ).getStr() );
329
            // WIDTH
330
            m_pArgn[1]		= strdup( "WIDTH" );
331
            m_pArgv[1]		= strdup( "200" );
332
            // HEIGHT
333
            m_pArgn[2]		= strdup( "HEIGHT" );
334
            m_pArgv[2]		= strdup( "200" );
335
            // CONTROLS
336
            m_pArgn[3]		= strdup( "CONTROLS" );
337
            m_pArgv[3]		= strdup( "PlayButton,StopButton,ImageWindow" );
338
            // AUTOSTART
339
            m_pArgn[4]		= strdup( "AUTOSTART" );
340
            m_pArgv[4]		= strdup( "TRUE" );
341
            // NOJAVA
342
            m_pArgn[5]		= strdup( "NOJAVA" );
343
            m_pArgv[5]		= strdup( "TRUE" );
344
        }
345
    }
346
    // #69333# special for pdf
347
    else if( ! m_aDescription.Mimetype.compareToAscii( "application/pdf" ) )
348
        m_aPluginMode = PluginMode::FULL;
349
350
    // see if we have a TYPE tag
351
    int nIndex;    
352
    for( nIndex = 0; nIndex < m_nArgs; ++nIndex )
353
        if( m_pArgn[nIndex][0] == 'T' &&
354
            m_pArgn[nIndex][1] == 'Y' &&
355
            m_pArgn[nIndex][2] == 'P' &&
356
            m_pArgn[nIndex][3] == 'E' &&
357
            m_pArgn[nIndex][4] == 0 )
358
            break;
359
    if( nIndex >= m_nArgs )
360
    {
361
        // TYPE
362
        prependArg( "TYPE", OUStringToOString( m_aDescription.Mimetype, m_aEncoding ).getStr() );
363
    }
364
365
    // see if we have a SRC tag
366
    for( nIndex = 0; nIndex < m_nArgs; ++nIndex )
367
        if( m_pArgn[nIndex][0] == 'S' &&
368
            m_pArgn[nIndex][1] == 'R' &&
369
            m_pArgn[nIndex][2] == 'C' &&
370
            m_pArgn[nIndex][3] == 0 )
371
            break;
372
    if( nIndex >= m_nArgs )
373
    {
374
        // need a SRC parameter (as all browser set one on the plugin
375
        OUString aURL;
376
        if( m_xModel.is() )
377
        {
378
            try
379
            {
380
                uno::Reference< XPropertySet > xProp( m_xModel, UNO_QUERY );
381
                Any aProp = xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
382
                aProp >>= aURL;
383
            }
384
            catch( UnknownPropertyException )
385
            {
386
            }
387
        }
388
389
        if( aURL.getLength() )
390
        {
391
            // SRC
392
            prependArg( "SRC", OUStringToOString( aURL, m_aEncoding ).getStr() );
393
        }
394
    }
395
}
396
397
void XPlugin_Impl::initInstance( const PluginDescription& rDescription,
398
                                 const Sequence< OUString >& argn,
399
                                 const Sequence< OUString >& argv,
400
                                 sal_Int16 mode )
401
{
402
    Guard< Mutex > aGuard( m_aMutex );
403
404
    m_aDescription = rDescription;
405
    initArgs( argn, argv, mode );
406
    handleSpecialArgs();
407
}
408
409
void XPlugin_Impl::initInstance( const OUString& rURL,
410
                                 const Sequence< OUString >& argn,
411
                                 const Sequence< OUString >& argv,
412
                                 sal_Int16 mode )
413
{
414
    Guard< Mutex > aGuard( m_aMutex );
415
416
    initArgs( argn, argv, mode );
417
    m_aDescription = fitDescription( rURL );
418
419
    m_xModel = new PluginModel( rURL, m_aDescription.Mimetype );
420
    handleSpecialArgs();
421
}
422
423
void XPlugin_Impl::modelChanged()
424
{
425
    Guard< Mutex > aGuard( m_aMutex );
426
427
    m_nProvidingState = PROVIDING_MODEL_UPDATE;
428
429
    destroyInstance();
430
431
    m_aDescription = fitDescription( getCreationURL() );
432
    if( !m_aDescription.Mimetype.getLength() )
433
    {
434
        m_nProvidingState = PROVIDING_NONE;
435
        return;
436
    }
437
438
    OUString aURL = getCreationURL();
439
    provideNewStream( m_aDescription.Mimetype,
440
                      uno::Reference< XActiveDataSource >(),
441
                      aURL,
442
                      0, 0, (sal_Bool)(aURL.compareToAscii( "file:", 5 ) == 0) );
443
    m_nProvidingState = PROVIDING_NONE;
444
}
445
446
OUString XPlugin_Impl::getCreationURL()
447
{
448
    Guard< Mutex > aGuard( m_aMutex );
449
450
    OUString aRet;
451
    uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
452
    if( xPS.is() )
453
    {
454
        Any aValue = xPS->getPropertyValue( OUString::createFromAscii( "URL" ) );
455
        aValue >>= aRet;
456
    }
457
    return aRet;
458
}
459
460
461
sal_Bool XPlugin_Impl::setModel( const uno::Reference< com::sun::star::awt::XControlModel > & Model )
462
    throw( RuntimeException )
463
{
464
    Guard< Mutex > aGuard( m_aMutex );
465
466
    uno::Reference< com::sun::star::beans::XPropertySet >  xPS( Model, UNO_QUERY );
467
    if( ! xPS.is() )
468
        return sal_False;
469
470
    if( getCreationURL().getLength() )
471
    {
472
        m_xModel = Model;
473
        modelChanged();
474
        xPS->addPropertyChangeListener( OUString(), this );
475
        return sal_True;
476
    }
477
    return sal_False;
478
}
479
480
void XPlugin_Impl::createPeer( const uno::Reference< com::sun::star::awt::XToolkit > & xToolkit, const uno::Reference< com::sun::star::awt::XWindowPeer > & Parent )
481
    throw( RuntimeException )
482
{
483
    Guard< Mutex > aGuard( m_aMutex );
484
485
    if( ! _xPeer.is() )
486
    {
487
        if( ! Parent.is() )
488
            throw  RuntimeException();
489
        PluginControl_Impl::createPeer( xToolkit, Parent );
490
    }
491
}
492
493
void XPlugin_Impl::loadPlugin()
494
{
495
    Guard< Mutex > aGuard( m_aMutex );
496
497
    std::list<PluginComm*>::iterator iter;
498
    for( iter = PluginManager::get().getPluginComms().begin();
499
         iter != PluginManager::get().getPluginComms().end(); ++iter )
500
    {
501
        if( OStringToOUString( (*iter)->getLibName(), m_aEncoding ) == m_aDescription.PluginName )
502
        {
503
            setPluginComm( *iter );
504
            break;
505
        }
506
    }
507
    const SystemEnvData* pEnvData = getSysChildSysData();
508
#if defined( UNX ) && !(defined(QUARTZ))
509
    XSync( (Display*)pEnvData->pDisplay, False );
510
#endif
511
    if( ! getPluginComm() )
512
    {
513
        if( m_aDescription.PluginName.getLength() )
514
        {
515
#if defined QUARTZ
516
            PluginComm* pComm = new MacPluginComm( m_aDescription.Mimetype,
517
                                                   m_aDescription.PluginName,
518
                                                   pEnvData->pView );
519
#elif defined UNX
520
            // need a new PluginComm
521
            PluginComm* pComm = NULL;
522
            int sv[2];
523
            if( !socketpair( AF_UNIX, SOCK_STREAM, 0, sv ) )
524
                pComm = new UnxPluginComm( m_aDescription.Mimetype,
525
                                           m_aDescription.PluginName,
526
                                           (XLIB_Window)pEnvData->aWindow,
527
                                           sv[0],
528
                                           sv[1]
529
                                           );
530
#elif (defined WNT || defined OS2)
531
            PluginComm* pComm = new PluginComm_Impl( m_aDescription.Mimetype,
532
                                                     m_aDescription.PluginName,
533
                                                     (HWND)pEnvData->hWnd );
534
#endif
535
            setPluginComm( pComm );
536
        }
537
        else
538
            return;
539
    }
540
541
    NPError aError = getPluginComm()->
542
        NPP_New( (char*)OUStringToOString( m_aDescription.Mimetype,
543
                                                  m_aEncoding).getStr(),
544
                 getNPPInstance(),
545
                 m_aPluginMode == PluginMode::FULL ? NP_FULL : NP_EMBED,
546
                 ::sal::static_int_cast< int16, int >( m_nArgs ),
547
                 (char**)(m_nArgs ? m_pArgn : NULL),
548
                 (char**)(m_nArgs ? m_pArgv : NULL),
549
                 NULL );
550
#ifdef QUARTZ
551
    // m_aNPWindow is set up in the MacPluginComm from the view
552
    m_aSysPlugData.m_pParentView = pEnvData->pView;
553
#elif defined( UNX )
554
    XSync( (Display*)pEnvData->pDisplay, False );
555
    m_aNPWindow.window      = (void*)pEnvData->aWindow;
556
    m_aNPWindow.ws_info     = NULL;
557
#else
558
    m_aNPWindow.window = (void*)pEnvData->hWnd;
559
#endif
560
    com::sun::star::awt::Rectangle aPosSize = getPosSize();
561
562
    for( int i = 0; i < m_nArgs; i++ )
563
    {
564
        OString aName( m_pArgn[i] );
565
        if( aName.equalsIgnoreAsciiCase( "width" ) )
566
        {
567
            OString aValue( m_pArgv[i] );
568
            aPosSize.Width = aValue.toInt32();
569
        }
570
        else if( aName.equalsIgnoreAsciiCase( "height" ) )
571
        {
572
            OString aValue( m_pArgv[i] );
573
            aPosSize.Height = aValue.toInt32();
574
        }
575
    }
576
577
    m_aNPWindow.clipRect.top        = 0;
578
    m_aNPWindow.clipRect.left       = 0;
579
    m_aNPWindow.clipRect.bottom     = ::sal::static_int_cast< uint16, sal_Int32 >( aPosSize.Height );
580
    m_aNPWindow.clipRect.right      = ::sal::static_int_cast< uint16, sal_Int32 >( aPosSize.Width );
581
    m_aNPWindow.type = NPWindowTypeWindow;
582
583
    m_aNPWindow.x       = 0;
584
    m_aNPWindow.y       = 0;
585
    m_aNPWindow.width   = aPosSize.Width ? aPosSize.Width : 600;
586
    m_aNPWindow.height  = aPosSize.Height ? aPosSize.Height : 600;
587
588
    aError = getPluginComm()->NPP_SetWindow( this );
589
    (void) aError;
590
}
591
592
void XPlugin_Impl::destroyStreams()
593
{
594
    Guard< Mutex > aGuard( m_aMutex );
595
596
    // streams remove themselves from this list when deleted
597
    while( m_aOutputStreams.size() )
598
        delete *m_aOutputStreams.begin();
599
600
    // input streams are XOutputStreams, they cannot be simply deleted
601
    std::list<PluginInputStream*> aLocalList( m_aInputStreams );
602
    for( std::list<PluginInputStream*>::iterator it = aLocalList.begin();
603
         it != aLocalList.end(); ++it )
604
        (*it)->setMode( -1 );
605
}
606
607
PluginStream* XPlugin_Impl::getStreamFromNPStream( NPStream* stream )
608
{
609
    Guard< Mutex > aGuard( m_aMutex );
610
611
    std::list<PluginInputStream*>::iterator iter;
612
    for( iter = m_aInputStreams.begin(); iter != m_aInputStreams.end(); ++iter )
613
        if( (*iter)->getStream() == stream )
614
            return *iter;
615
616
    std::list<PluginOutputStream*>::iterator iter2;
617
    for( iter2 = m_aOutputStreams.begin(); iter2 != m_aOutputStreams.end(); ++iter2 )
618
        if( (*iter2)->getStream() == stream )
619
            return *iter2;
620
621
    return NULL;
622
}
623
624
sal_Bool XPlugin_Impl::provideNewStream(const OUString& mimetype,
625
                                        const uno::Reference< com::sun::star::io::XActiveDataSource > & stream,
626
                                        const OUString& url, sal_Int32 length,
627
                                        sal_Int32 lastmodified, sal_Bool isfile) throw()
628
629
{
630
    Guard< Mutex > aGuard( m_aMutex );
631
    sal_Bool bRet = sal_False;
632
633
    if( m_nProvidingState != PROVIDING_NONE )
634
    {
635
        m_nProvidingState = PROVIDING_NOW;
636
        Any aAny;
637
        aAny <<= url;
638
        uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
639
        if( xPS.is() )
640
        {
641
            try
642
            {
643
                xPS->setPropertyValue( OUString::createFromAscii( "URL" ), aAny );
644
                aAny <<= mimetype;
645
                xPS->setPropertyValue( OUString::createFromAscii( "TYPE" ), aAny );
646
            }
647
            catch(...)
648
            {
649
            }
650
        }
651
    }
652
    m_nProvidingState = PROVIDING_NOW;
653
654
    OString aMIME;
655
    if( mimetype.getLength() )
656
        aMIME = OUStringToOString( mimetype, m_aEncoding );
657
    else
658
        aMIME = OUStringToOString( m_aDescription.Mimetype, m_aEncoding );
659
660
    OString aURL  = OUStringToOString( url, m_aEncoding );
661
662
    // check wether there is a notifylistener for this stream
663
    // this means that the strema is created from the plugin
664
    // via NPN_GetURLNotify or NPN_PostURLNotify
665
    std::list<PluginEventListener*>::iterator iter;
666
    for( iter = m_aPEventListeners.begin();
667
         iter != m_aPEventListeners.end();
668
         ++iter )
669
    {
670
        if( (*iter)->getNormalizedURL() == aURL )
671
        {
672
            aURL = (*iter)->getURL();
673
            break;
674
        }
675
    }
676
677
    if( ! m_pPluginComm )
678
    {
679
        loadPlugin();
680
        if( m_aLastGetUrl.getLength() && m_aLastGetUrl == aURL )
681
        {
682
            // plugin is pulling data, don't push the same stream;
683
            // this complicated method could have been avoided if
684
            // all plugins respected the SRC parameter; but e.g.
685
            // acrobat reader plugin does not
686
            m_nProvidingState = PROVIDING_NONE;
687
            return sal_True;
688
        }
689
    }
690
     if( ! m_pPluginComm )
691
        return sal_False;
692
693
     if( ! url.getLength() )
694
         // this is valid if the plugin is supposed to
695
         // pull data (via e.g. NPN_GetURL)
696
         return sal_True;
697
698
     // set mimetype on model
699
     {
700
         uno::Reference< com::sun::star::beans::XPropertySet >  xPS( m_xModel, UNO_QUERY );
701
         if( xPS.is() )
702
         {
703
             try
704
             {
705
                 Any aAny;
706
                 aAny <<= m_aDescription.Mimetype;
707
                 xPS->setPropertyValue( OUString::createFromAscii( "TYPE" ), aAny );
708
             }
709
             catch(...)
710
             {
711
             }
712
         }
713
     }
714
715
     // there may be plugins that can use the file length information,
716
     // but currently none are known. Since this file opening/seeking/closing
717
     // is rather costly, it is #if'ed out. If there are plugins known to
718
     // make use of the file length, simply put it in
719
#if 0
720
    if( isfile && ! length )
721
    {
722
        osl::File aFile( url );
723
        if( aFile.open( OpenFlag_Read ) == FileBase::E_None )
724
        {
725
            aFile.setPos( Pos_End, 0 );
726
            sal_uInt64 nPos = 0;
727
            if( aFile.getPos( nPos ) == FileBase::E_None )
728
                length = nPos;
729
            aFile.close();
730
        }
731
    }
732
#endif
733
734
     PluginInputStream* pStream = new PluginInputStream( this, aURL.getStr(),
735
                                                        length, lastmodified );
736
     uno::Reference< com::sun::star::io::XOutputStream > xNewStream( pStream );
737
738
     if( iter != m_aPEventListeners.end() )
739
         pStream->getStream()->notifyData = (*iter)->getNotifyData();
740
741
    uint16 stype = 0;
742
743
    // special handling acrobat reader
744
    // presenting a seekable stream to it does not seem to work correctly
745
    if( aMIME.equals( "application/pdf" ) )
746
        isfile = sal_False;
747
748
#if OSL_DEBUG_LEVEL > 1
749
    fprintf( stderr,
750
             "new stream \"%s\" of MIMEType \"%s\"\n"
751
             "for plugin \"%s\"\n"
752
             "seekable = %s, length = %"SAL_PRIdINT32"\n",
753
             aURL.getStr(), aMIME.getStr(), getPluginComm()->getLibName().getStr(),
754
             isfile ? "true" : "false", length );
755
756
#endif
757
    if( ! m_pPluginComm->NPP_NewStream( &m_aInstance,
758
                                        (char*)aMIME.getStr(),
759
                                        pStream->getStream(), isfile,
760
                                        &stype ) )
761
    {
762
#if OSL_DEBUG_LEVEL > 1
763
        const char* pType;
764
        switch( stype )
765
        {
766
            case NP_NORMAL:     pType = "NP_NORMAL";break;
767
            case NP_SEEK:       pType = "NP_SEEK";break;
768
            case NP_ASFILE:     pType = "NP_ASFILE";break;
769
            case NP_ASFILEONLY: pType = "NP_ASFILEONLY";break;
770
            default:            pType = "unknown!!!";
771
        }
772
        fprintf( stderr, "Plugin wants it in Mode %s\n", pType );
773
#endif
774
        if( isfile && stype == NP_ASFILEONLY )
775
        {
776
            OString aFileName;
777
            if( url.compareToAscii( "file:", 5 ) == 0 )
778
            {
779
                OUString aSysName;
780
                osl_getSystemPathFromFileURL( url.pData, &aSysName.pData );
781
                aFileName = OUStringToOString( aSysName, m_aEncoding );
782
            }
783
            else
784
                aFileName = OUStringToOString( url, m_aEncoding );
785
            m_pPluginComm->
786
                NPP_StreamAsFile( &m_aInstance,
787
                                  pStream->getStream(),
788
                                  aFileName.getStr() );
789
        }
790
        else
791
        {
792
            pStream->setMode( stype );
793
794
            if( ! stream.is() )
795
            {
796
                // stream has to be loaded by PluginStream itself via UCB
797
                pStream->load();
798
            }
799
            else
800
            {
801
                uno::Reference< com::sun::star::io::XConnectable > xConnectable( stream, UNO_QUERY );
802
                pStream->setPredecessor( xConnectable );
803
                if( xConnectable.is() )
804
                {
805
                    xConnectable->setSuccessor( static_cast< com::sun::star::io::XConnectable* >(pStream) );
806
                    while( xConnectable->getPredecessor().is() )
807
                        xConnectable = xConnectable->getPredecessor();
808
                }
809
                stream->setOutputStream( xNewStream );
810
                pStream->setSource( stream );
811
                uno::Reference< com::sun::star::io::XActiveDataControl > xController;
812
                if( xConnectable.is() )
813
                    xController = uno::Reference< com::sun::star::io::XActiveDataControl >( xConnectable, UNO_QUERY );
814
                else
815
                    xController = uno::Reference< com::sun::star::io::XActiveDataControl >( stream, UNO_QUERY );
816
817
                if( xController.is() )
818
                    xController->start();
819
            }
820
        }
821
        bRet = sal_True;
822
    }
823
824
    m_nProvidingState = PROVIDING_NONE;
825
826
    return bRet;
827
}
828
829
void XPlugin_Impl::disposing( const com::sun::star::lang::EventObject& /*rSource*/ ) throw()
830
{
831
}
832
833
void XPlugin_Impl::propertyChange( const com::sun::star::beans::PropertyChangeEvent& rEvent ) throw()
834
{
835
    Guard< Mutex > aGuard( m_aMutex );
836
837
    if( ! rEvent.PropertyName.compareToAscii( "URL" ) )
838
    {
839
        OUString aStr;
840
        rEvent.NewValue >>= aStr;
841
        if( m_nProvidingState == PROVIDING_NONE )
842
        {
843
            if( aStr != m_aURL )
844
            {
845
                m_aURL = aStr;
846
                modelChanged();
847
            }
848
        }
849
    }
850
}
851
852
void XPlugin_Impl::setPluginContext( const uno::Reference< XPluginContext > & rContext )
853
{
854
    m_rBrowserContext = rContext;
855
}
856
857
void XPlugin_Impl::setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags )
858
        throw( RuntimeException )
859
{
860
    Guard< Mutex > aGuard( m_aMutex );
861
862
#if OSL_DEBUG_LEVEL > 1
863
    fprintf( stderr, "XPlugin_Impl::setPosSize( %"SAL_PRIdINT32", %"SAL_PRIdINT32", %"SAL_PRIdINT32", %"SAL_PRIdINT32", %d )\n",
864
             nX_, nY_, nWidth_, nHeight_, nFlags );
865
#endif
866
867
    PluginControl_Impl::setPosSize(nX_, nY_, nWidth_, nHeight_, nFlags);
868
869
    m_aNPWindow.x       			= 0;
870
    m_aNPWindow.y       			= 0;
871
    m_aNPWindow.width   			= nWidth_;
872
    m_aNPWindow.height  			= nHeight_;
873
    m_aNPWindow.clipRect.top		= 0;
874
    m_aNPWindow.clipRect.left		= 0;
875
    m_aNPWindow.clipRect.right		= ::sal::static_int_cast< uint16, sal_Int32 >( nWidth_ );
876
    m_aNPWindow.clipRect.bottom		= ::sal::static_int_cast< uint16, sal_Int32 >( nHeight_ );
877
    
878
    if( getPluginComm() )
879
        getPluginComm()->NPP_SetWindow( this );
880
}
881
882
PluginDescription XPlugin_Impl::fitDescription( const OUString& rURL )
883
{
884
    uno::Reference< XPluginManager >  xPMgr(
885
        m_xContext->getServiceManager()->createInstanceWithContext(
886
            OUString( RTL_CONSTASCII_USTRINGPARAM(
887
                "com.sun.star.plugin.PluginManager" )), m_xContext ), UNO_QUERY );
888
    if( !xPMgr.is() )
889
    {
890
        m_nProvidingState = PROVIDING_NONE;
891
        return PluginDescription();
892
    }
893
894
    Sequence< PluginDescription > aDescrs = xPMgr->getPluginDescriptions();
895
    const PluginDescription* pDescrs = aDescrs.getConstArray();
896
897
    for( int nArg = 0; nArg < m_nArgs; nArg++ )
898
    {
899
        if( strncmp( m_pArgn[nArg], "TYPE", 4 ) == 0 &&
900
            m_pArgn[nArg][4] == 0 )
901
        {
902
            for( int i = 0; i < aDescrs.getLength(); i++ )
903
            {
904
                if( pDescrs[i].Mimetype.compareToAscii( m_pArgv[nArg] ) == 0 )
905
                    return pDescrs[i];
906
            }
907
        }
908
    }
909
910
    int nPos = rURL.lastIndexOf( (sal_Unicode)'.' );
911
    OUString aExt = rURL.copy( nPos ).toAsciiLowerCase();
912
    if( nPos != -1 )
913
    {
914
        for( int i = 0; i < aDescrs.getLength(); i++ )
915
        {
916
            OUString aThisExt = pDescrs[ i ].Extension.toAsciiLowerCase();
917
            if( aThisExt.indexOf( aExt ) != -1 )
918
            {
919
                return pDescrs[i];
920
            }
921
        }
922
    }
923
    return PluginDescription();
924
}
925
926
927
PluginStream::PluginStream( XPlugin_Impl* pPlugin,
928
                            const char* url, sal_uInt32 len, sal_uInt32 lastmod ) :
929
        m_pPlugin( pPlugin )
930
{
931
    memset( &m_aNPStream, 0, sizeof( m_aNPStream ) );
932
    m_aNPStream.url             = strdup( url );
933
    m_aNPStream.end             = len;
934
    m_aNPStream.lastmodified    = lastmod;
935
}
936
937
PluginStream::~PluginStream()
938
{
939
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
940
941
    if( m_pPlugin && m_pPlugin->getPluginComm() )
942
    {
943
        m_pPlugin->getPluginComm()->NPP_DestroyStream( m_pPlugin->getNPPInstance(),
944
                                                       &m_aNPStream, NPRES_DONE );
945
        m_pPlugin->checkListeners( m_aNPStream.url );
946
        m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
947
    }
948
    ::free( (void*)m_aNPStream.url );
949
}
950
951
PluginInputStream::PluginInputStream( XPlugin_Impl* pPlugin,
952
                                      const char* url,
953
                                      sal_uInt32 len,
954
                                      sal_uInt32 lastmod ) :
955
        PluginStream( pPlugin, url, len, lastmod ),
956
        m_pContent( NULL ),
957
        m_nMode( NP_NORMAL ),
958
        m_nWritePos( 0 )
959
{
960
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
961
962
    m_pPlugin->getInputStreams().push_back( this );
963
    DirEntry aEntry;
964
    aEntry = aEntry.TempName();
965
966
    // set correct extension, some plugins need that
967
    DirEntry aName( String( m_aNPStream.url, m_pPlugin->getTextEncoding() ) );
968
    String aExtension = aName.GetExtension();
969
    if( aExtension.Len() )
970
        aEntry.SetExtension( aExtension );
971
    m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE );
972
    if( ! m_aFileStream.IsOpen() )
973
    {
974
        // #74808# might be that the extension scrambled the whole filename
975
        aEntry = aEntry.TempName();
976
        m_aFileStream.Open( aEntry.GetFull(), STREAM_READ | STREAM_WRITE );
977
    }
978
}
979
980
PluginInputStream::~PluginInputStream()
981
{
982
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
983
984
    m_pPlugin->getInputStreams().remove( this );
985
986
    String aFile( m_aFileStream.GetFileName() );
987
988
    m_aFileStream.Close();
989
    if( m_pPlugin )
990
    {
991
        ByteString aFileName( aFile, m_pPlugin->getTextEncoding() );
992
        if( m_pPlugin->getPluginComm() && m_nMode != -1 )
993
            // mode -1 means either an error occured,
994
            // or the plugin is already disposing
995
        {
996
            m_pPlugin->getPluginComm()->addFileToDelete( aFile );
997
            if( m_nMode == NP_ASFILE )
998
            {
999
                m_pPlugin->getPluginComm()->
1000
                    NPP_StreamAsFile( m_pPlugin->getNPPInstance(),
1001
                                      &m_aNPStream,
1002
                                      aFileName.GetBuffer() );
1003
            }
1004
            m_pPlugin->getPluginComm()->NPP_SetWindow( m_pPlugin );
1005
            m_pPlugin->getInputStreams().remove( this );
1006
        }
1007
        else
1008
            DirEntry( m_aFileStream.GetFileName() ).Kill();
1009
    }
1010
    else
1011
        DirEntry( m_aFileStream.GetFileName() ).Kill();
1012
    if( m_pContent )
1013
        delete m_pContent;
1014
}
1015
1016
PluginStreamType PluginInputStream::getStreamType()
1017
{
1018
    return InputStream;
1019
}
1020
1021
void PluginInputStream::load()
1022
{
1023
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1024
1025
    INetURLObject aUrl;
1026
    aUrl.SetSmartProtocol( INET_PROT_FILE );
1027
    aUrl.SetSmartURL(
1028
        String( getStream()->url,
1029
                ::sal::static_int_cast< sal_uInt16, size_t >( strlen( getStream()->url ) ),
1030
                RTL_TEXTENCODING_MS_1252
1031
            ) );
1032
    try
1033
    {
1034
        m_pContent =
1035
            new ::ucbhelper::Content(
1036
                               aUrl.GetMainURL(INetURLObject::DECODE_TO_IURI),
1037
                               uno::Reference< com::sun::star::ucb::XCommandEnvironment >()
1038
                               );
1039
        m_pContent->openStream( static_cast< XOutputStream* >( this ) );
1040
    }
1041
    catch( com::sun::star::uno::Exception )
1042
    {
1043
    }
1044
}
1045
1046
void PluginInputStream::setMode( sal_Int32 nMode )
1047
{
1048
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1049
1050
    m_nMode = nMode;
1051
1052
    // invalidation by plugin
1053
    if( m_nMode == -1 && m_pPlugin )
1054
    {
1055
        m_pPlugin->getInputStreams().remove( this );
1056
        m_pPlugin = NULL;
1057
    }
1058
}
1059
1060
void PluginInputStream::writeBytes( const Sequence<sal_Int8>& Buffer ) throw()
1061
{
1062
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1063
1064
    m_aFileStream.Seek( STREAM_SEEK_TO_END );
1065
    m_aFileStream.Write( Buffer.getConstArray(), Buffer.getLength() );
1066
1067
    if( m_nMode == NP_SEEK )
1068
        // hold reference, streem gets destroyed in NPN_DestroyStream
1069
        m_xSelf = this;
1070
1071
    if( m_nMode == -1 || !m_pPlugin->getPluginComm() )
1072
        return;
1073
1074
    sal_uInt32 nPos = m_aFileStream.Tell();
1075
    sal_uInt32 nBytes = 0;
1076
    while( m_nMode != NP_ASFILEONLY &&
1077
           m_nWritePos < nPos &&
1078
           (nBytes = m_pPlugin->getPluginComm()-> NPP_WriteReady(
1079
               m_pPlugin->getNPPInstance(), &m_aNPStream )) > 0 )
1080
    {
1081
        nBytes = (nBytes > nPos - m_nWritePos) ? nPos - m_nWritePos : nBytes;
1082
1083
        char* pBuffer = new char[ nBytes ];
1084
        m_aFileStream.Seek( m_nWritePos );
1085
        nBytes = m_aFileStream.Read( pBuffer, nBytes );
1086
1087
        int32 nBytesRead = 0;
1088
        try
1089
        {
1090
            nBytesRead = m_pPlugin->getPluginComm()->NPP_Write(
1091
                m_pPlugin->getNPPInstance(), &m_aNPStream, m_nWritePos, nBytes, pBuffer );
1092
        }
1093
        catch( ... )
1094
        {
1095
            nBytesRead = 0;
1096
        }
1097
        delete [] pBuffer;
1098
1099
        if( nBytesRead < 0 )
1100
        {
1101
            m_nMode = -1;
1102
            return;
1103
        }
1104
1105
        m_nWritePos += nBytesRead;
1106
    }
1107
}
1108
1109
void PluginInputStream::closeOutput() throw()
1110
{
1111
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1112
1113
    flush();
1114
    m_xSource = uno::Reference< com::sun::star::io::XActiveDataSource >();
1115
}
1116
1117
sal_uInt32 PluginInputStream::read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size )
1118
{
1119
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1120
1121
    if( m_nMode != NP_SEEK )
1122
        return 0;
1123
1124
    m_aFileStream.Seek( offset );
1125
    return m_aFileStream.Read( buffer, size );
1126
}
1127
1128
void PluginInputStream::flush(void) throw()
1129
{
1130
}
1131
1132
PluginOutputStream::PluginOutputStream( XPlugin_Impl* pPlugin,
1133
                                        const char* url,
1134
                                        sal_uInt32 len,
1135
                                        sal_uInt32 lastmod ) :
1136
        PluginStream( pPlugin, url, len, lastmod ),
1137
        m_xStream( pPlugin->getComponentContext()
1138
            ->getServiceManager()->createInstanceWithContext(
1139
                OUString( RTL_CONSTASCII_USTRINGPARAM(
1140
                    "com.sun.star.io.DataOutputStream" )),
1141
                        pPlugin->getComponentContext() ), UNO_QUERY )
1142
{
1143
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1144
1145
    m_pPlugin->getOutputStreams().push_back( this );
1146
}
1147
1148
PluginOutputStream::~PluginOutputStream()
1149
{
1150
    Guard< Mutex > aGuard( m_pPlugin->getMutex() );
1151
1152
    m_pPlugin->getOutputStreams().remove( this );
1153
}
1154
1155
PluginStreamType PluginOutputStream::getStreamType()
1156
{
1157
    return OutputStream;
1158
}
1159
(-)a/main/extensions/source/plugin/inc/plugin/aqua/sysplug.hxx (+163 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLUGIN_INC_MACPLUG_HXX
24
#define __PLUGIN_INC_MACPLUG_HXX
25
26
#include <unistd.h>
27
28
#include <list>
29
#include <map>
30
#include <algorithm>
31
#include "premac.h"
32
#include <Carbon/Carbon.h>
33
#include <Security/cssmconfig.h>
34
#include "postmac.h"
35
#undef uint32
36
37
#define XP_MAC
38
#include <npapi.h>
39
#include <npupp.h>
40
41
#include "plugin/plcom.hxx"
42
#include "premac.h"
43
#include <Cocoa/Cocoa.h>
44
#include "postmac.h"
45
46
#include "vcl/sysdata.hxx"
47
#include "vcl/threadex.hxx"
48
#include "vcl/timer.hxx"
49
#include "osl/module.h"
50
51
class XPlugin_Impl;
52
53
namespace plugstringhelper
54
{
55
rtl::OUString           getString( CFStringRef i_xString );
56
rtl::OUString           getString( CFURLRef i_xURL );
57
CFMutableStringRef      createString( const rtl::OUString& i_rString );
58
CFURLRef                createURL( const rtl::OUString& i_rString );
59
rtl::OUString           getURLFromPath( const rtl::OUString& i_rPath );
60
CFURLRef                createURLFromPath( const rtl::OUString& i_rPath );
61
rtl::OUString           CFURLtoOSLURL( CFURLRef i_xURL );
62
}
63
64
//==================================================================================================
65
class MacPluginComm :
66
    public PluginComm,
67
	public ::vcl::SolarThreadExecutor
68
	
69
{
70
	enum CallType {
71
		eNPP_Destroy,
72
		eNPP_DestroyStream,
73
		eNPP_GetJavaClass,
74
		eNPP_Initialize,
75
		eNPP_New,
76
		eNPP_NewStream,
77
		eNPP_Print,
78
		eNPP_SetWindow,
79
		eNPP_Shutdown,
80
		eNPP_StreamAsFile,
81
		eNPP_URLNotify,
82
		eNPP_Write,
83
		eNPP_WriteReady,
84
		eNPP_GetValue,
85
		eNPP_SetValue,
86
        eNPP_HandleEvent,
87
		eNP_Initialize
88
	};
89
90
	void*				m_aArgs[ 8 ];
91
	CallType			m_eCall;
92
	
93
	virtual long		doIt();
94
public:
95
						MacPluginComm( const rtl::OUString& rMIME, const rtl::OUString& rName, NSView* pView );
96
	virtual				~MacPluginComm();
97
98
    // FIXME:
99
    // this actually should be from the NP headers
100
    // but currently we have too old a version
101
    // changes this when we have updated our headers
102
    typedef struct NP_CGContext
103
    {
104
        CGContextRef context;
105
        WindowRef window;
106
    } NP_CGContext;
107
108
public:
109
	virtual NPError		NPP_Destroy( NPP instance, NPSavedData** save );
110
	virtual NPError		NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason );
111
	virtual void *		NPP_GetJavaClass();
112
	virtual NPError		NPP_Initialize();
113
	virtual NPError		NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
114
								 char* argn[], char* argv[], NPSavedData *saved );
115
	virtual NPError		NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
116
									   NPBool seekable, uint16* stype );
117
	virtual void		NPP_Print( NPP instance, NPPrint* platformPrint );
118
	virtual NPError		NPP_SetWindow( NPP instance, NPWindow* window );
119
	virtual void		NPP_Shutdown();
120
	virtual void		NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname );
121
	virtual void		NPP_URLNotify( NPP instance, const char* url,
122
									   NPReason reason, void* notifyData );
123
	virtual int32		NPP_Write( NPP instance, NPStream* stream, int32 offset,
124
								   int32 len, void* buffer );
125
	virtual int32		NPP_WriteReady( NPP instance, NPStream* stream );
126
	virtual NPError		NPP_GetValue( NPP instance, NPPVariable variable, void *ret_value );
127
	virtual NPError		NPP_SetValue( NPP instance, NPNVariable variable, void *ret_value );
128
	virtual int16       NPP_HandleEvent( NPP instance, void* event );
129
130
    virtual NPError     NPP_SetWindow( XPlugin_Impl* );
131
    virtual NPError     NPP_Destroy( XPlugin_Impl*, NPSavedData** save );
132
    
133
    void                drawView( XPlugin_Impl* );
134
private:
135
	sal_Bool				retrieveFunction( const char* i_pName, void** i_ppFunc ) const;
136
    DECL_LINK( NullTimerHdl, void* );
137
    	
138
private:
139
    CFBundleRef         m_xBundle;
140
	oslModule			m_hPlugLib;
141
	NPPluginFuncs		m_aNPPfuncs;
142
143
    // timer for sending nullEvents
144
    AutoTimer*                      m_pNullTimer;
145
    std::list< XPlugin_Impl* >      m_aNullEventClients;
146
};
147
148
struct SysPlugData
149
{
150
    MacPluginComm::NP_CGContext m_aCGContext;
151
    NP_Port                     m_aNPPort;
152
    NSView*                     m_pParentView;
153
    NSView*                     m_pPlugView;
154
    int                         m_nDrawingModel;
155
    NSPoint                     m_aLastPlugViewOrigin;
156
    bool                        m_bSetWindowOnDraw;
157
};
158
159
160
161
#endif
162
163
(-)a/main/extensions/source/plugin/inc/plugin/impl.hxx (+426 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLUGIN_SOURCE_MGR_IMPL_HXX
24
#define __PLUGIN_SOURCE_MGR_IMPL_HXX
25
26
#ifdef SOLARIS
27
#include <limits>
28
#endif
29
30
#include "cppuhelper/weak.hxx"
31
32
#include "com/sun/star/awt/Key.hpp"
33
#include "com/sun/star/awt/KeyFunction.hpp"
34
#include "com/sun/star/beans/PropertyAttribute.hpp"
35
#include "com/sun/star/plugin/PluginMode.hpp"
36
#include "com/sun/star/plugin/PluginDescription.hpp"
37
#include "com/sun/star/plugin/PluginException.hpp"
38
#include "com/sun/star/plugin/PluginVariable.hpp"
39
#include "com/sun/star/plugin/XPlugin.hpp"
40
#include "com/sun/star/plugin/XPluginManager.hpp"
41
#include "com/sun/star/plugin/XPluginContext.hpp"
42
#include "com/sun/star/io/XConnectable.hpp"
43
#include "com/sun/star/io/XOutputStream.hpp"
44
#include "com/sun/star/io/XDataOutputStream.hpp"
45
#include "com/sun/star/io/XActiveDataControl.hpp"
46
#include "com/sun/star/io/XDataInputStream.hpp"
47
#include "com/sun/star/io/XMarkableStream.hpp"
48
#include "com/sun/star/io/XInputStream.hpp"
49
#include "com/sun/star/io/XStreamListener.hpp"
50
#include "com/sun/star/io/XActiveDataSink.hpp"
51
#include "com/sun/star/io/XActiveDataSource.hpp"
52
#include "com/sun/star/lang/XServiceName.hpp"
53
#include "com/sun/star/lang/XServiceInfo.hpp"
54
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
55
#include "com/sun/star/lang/XSingleServiceFactory.hpp"
56
#include "com/sun/star/awt/GradientStyle.hpp"
57
#include "com/sun/star/awt/RasterOperation.hpp"
58
#include "com/sun/star/awt/Gradient.hpp"
59
#include "com/sun/star/awt/XGraphics.hpp"
60
61
#include "cppuhelper/implbase3.hxx"
62
#include "cppuhelper/implbase2.hxx"
63
#include "cppuhelper/implbase1.hxx"
64
65
#include <list>
66
67
#ifdef WNT 
68
#include "plugin/win/sysplug.hxx"
69
#endif
70
71
#ifdef WNT 
72
#include <plugin/win/sysplug.hxx>
73
#elif defined(OS2)
74
#include "plugin/os2/sysplug.hxx"
75
#elif defined(QUARTZ)
76
#include "plugin/aqua/sysplug.hxx"
77
#elif defined(UNX)
78
#include "plugin/unx/sysplug.hxx"
79
#endif
80
81
#if ! defined (QUARTZ)
82
// the QUARTZ implementation needs special instance data
83
typedef int SysPlugData;
84
#endif
85
86
#include "plugin/plctrl.hxx"
87
#include "plugin/model.hxx"
88
89
#include "vcl/sysdata.hxx"
90
#include "vcl/syschild.hxx"
91
92
#include "tools/link.hxx"
93
#include "tools/stream.hxx"
94
95
96
using namespace com::sun::star::uno;
97
98
#define PROVIDING_NONE				0
99
#define PROVIDING_NOW				1
100
#define PROVIDING_MODEL_UPDATE		2
101
102
// forwards
103
namespace ucbhelper { class Content; }
104
class PluginStream;
105
class PluginInputStream;
106
class PluginOutputStream;
107
class XPlugin_Impl;
108
class PluginDisposer;
109
class PluginEventListener;
110
111
class XPlugin_Impl : public com::sun::star::plugin::XPlugin,
112
					 public PluginControl_Impl,
113
					 public com::sun::star::beans::XPropertyChangeListener
114
{
115
private:
116
	::osl::Mutex				m_aMutex;
117
	Reference< com::sun::star::uno::XComponentContext > 		m_xContext;
118
	Reference< com::sun::star::plugin::XPluginContext > 			m_rBrowserContext;
119
120
	PluginComm*					m_pPluginComm;
121
	NPP_t						m_aInstance;
122
	NPWindow					m_aNPWindow;
123
    SysPlugData                 m_aSysPlugData;
124
	rtl_TextEncoding			m_aEncoding;
125
126
	const char**				m_pArgv;
127
	const char**				m_pArgn;
128
	int							m_nArgs;
129
    rtl::OString				m_aLastGetUrl;
130
131
	Reference< com::sun::star::awt::XControlModel > 			m_xModel;
132
133
	::com::sun::star::plugin::PluginDescription			m_aDescription;
134
	sal_Int16						m_aPluginMode;
135
136
	int							m_nProvidingState;
137
	int							m_nCalledFromPlugin;
138
	PluginDisposer*				m_pDisposer;
139
140
	::std::list<PluginInputStream*>		m_aInputStreams;
141
	::std::list<PluginOutputStream*>	m_aOutputStreams;	
142
	::std::list<PluginEventListener*>	m_aPEventListeners;
143
	::rtl::OUString						m_aURL;
144
145
	sal_Bool						m_bIsDisposed;
146
147
    void prependArg( const char* pName, const char* pValue ); // arguments will be strdup'ed
148
    void initArgs( const Sequence< rtl::OUString >& argn,
149
                   const Sequence< rtl::OUString >& argv,
150
                   sal_Int16 mode );
151
    void freeArgs();
152
    void handleSpecialArgs();
153
    
154
	void loadPlugin();
155
	void destroyInstance();
156
	void modelChanged();
157
158
public:
159
	XPlugin_Impl( const Reference< com::sun::star::uno::XComponentContext >  & rxContext );
160
	virtual ~XPlugin_Impl();
161
162
	::osl::Mutex& getMutex() { return m_aMutex; }
163
	
164
	void destroyStreams();
165
166
    void setLastGetUrl( const rtl::OString& rUrl ) { m_aLastGetUrl = rUrl; }
167
168
    com::sun::star::plugin::PluginDescription fitDescription( const rtl::OUString& rURL );
169
170
	::std::list<PluginInputStream*>& getInputStreams() { return m_aInputStreams; }
171
	::std::list<PluginOutputStream*>& getOutputStreams() { return m_aOutputStreams; }
172
	PluginComm*		getPluginComm() { return m_pPluginComm; }
173
	void			setPluginComm( PluginComm* comm )
174
		{
175
			if( ! m_pPluginComm )
176
			{
177
				m_pPluginComm = comm;
178
				m_pPluginComm->addRef();
179
			}
180
		}
181
	Reference< com::sun::star::uno::XComponentContext > getComponentContext() { return m_xContext; }
182
    const com::sun::star::plugin::PluginDescription& getDescription() const { return m_aDescription; }
183
	rtl_TextEncoding getTextEncoding() { return m_aEncoding; }
184
	NPP				getNPPInstance() { return &m_aInstance; }
185
	NPWindow*		getNPWindow() { return &m_aNPWindow; }
186
    SysPlugData&    getSysPlugData() { return m_aSysPlugData; }
187
188
	void			enterPluginCallback() { m_nCalledFromPlugin++; }
189
	void			leavePluginCallback() { m_nCalledFromPlugin--; }
190
	sal_Bool			isDisposable() { return m_nCalledFromPlugin < 1 ? sal_True : sal_False; }
191
	DECL_LINK( secondLevelDispose, XPlugin_Impl* );	
192
193
	void addPluginEventListener( PluginEventListener* pListener  )
194
		{ m_aPEventListeners.push_back( pListener ); }
195
	void checkListeners( const char* normalizedURL );
196
	
197
	void			initInstance( 
198
		const com::sun::star::plugin::PluginDescription& rDescription,
199
		const Sequence< rtl::OUString >& argn,
200
		const Sequence< rtl::OUString >& argv,
201
		sal_Int16 mode );
202
	void			initInstance( 
203
		const rtl::OUString& rURL,
204
		const Sequence< rtl::OUString >& argn,
205
		const Sequence< rtl::OUString >& argv,
206
		sal_Int16 mode );
207
208
	const rtl::OUString&	getRefererURL() { return m_aURL; }
209
	::rtl::OUString	getCreationURL();
210
211
	PluginStream* getStreamFromNPStream( NPStream* );
212
213
	const SystemEnvData* getSysChildSysData()
214
		{ return _pSysChild->GetSystemData(); }
215
216
	const Reference< com::sun::star::plugin::XPluginContext > & getPluginContext() const
217
		{ return m_rBrowserContext; }
218
	void setPluginContext( const Reference< com::sun::star::plugin::XPluginContext > & );
219
220
	void secondLevelDispose();
221
	
222
//	static const Reference< com::sun::star::reflection::XIdlClass > &	staticGetIdlClass();
223
224
	// XInterface
225
	virtual Any	SAL_CALL queryInterface( const Type& ) throw( com::sun::star::uno::RuntimeException );
226
	virtual void SAL_CALL acquire()  throw()
227
    { OWeakAggObject::acquire(); }
228
	virtual void SAL_CALL release()  throw()
229
    { OWeakAggObject::release(); }
230
231
	// OWeakAggObject
232
	virtual Any SAL_CALL queryAggregation( const Type& )
233
        throw( com::sun::star::uno::RuntimeException );
234
235
	// PluginContol_Impl
236
	virtual void SAL_CALL dispose() throw();
237
	virtual void SAL_CALL createPeer( const Reference< com::sun::star::awt::XToolkit > & xToolkit, const Reference< com::sun::star::awt::XWindowPeer > & Parent) throw( RuntimeException );
238
239
    virtual sal_Bool SAL_CALL setModel( const Reference< com::sun::star::awt::XControlModel > & Model ) throw( RuntimeException );
240
    virtual Reference< com::sun::star::awt::XControlModel > SAL_CALL getModel()throw( RuntimeException )
241
    { return m_xModel; }
242
243
	virtual void SAL_CALL setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) throw( RuntimeException );
244
245
	// com::sun::star::plugin::XPlugin
246
    virtual sal_Bool SAL_CALL provideNewStream(const rtl::OUString& mimetype, const Reference< com::sun::star::io::XActiveDataSource > & stream, const rtl::OUString& url, sal_Int32 length, sal_Int32 lastmodified, sal_Bool isfile) throw();
247
248
	// com::sun::star::beans::XPropertyChangeListener
249
	virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& rSource ) throw();
250
	virtual void SAL_CALL propertyChange( const com::sun::star::beans::PropertyChangeEvent& rEvent ) throw();
251
};
252
253
class PluginManager
254
{
255
private:
256
	Reference< com::sun::star::uno::XComponentContext > 		m_xContext;
257
	::std::list<PluginComm*>		m_aPluginComms;
258
	::std::list<XPlugin_Impl*>		m_aAllPlugins;
259
	::osl::Mutex					m_aPluginMutex;
260
261
	static PluginManager*		pManager;
262
263
	PluginManager();
264
public:
265
266
	static PluginManager& get();
267
	static void setComponentContext( const Reference< com::sun::star::uno::XComponentContext >& xContext );
268
	static const Sequence< rtl::OUString >& getAdditionalSearchPaths();
269
270
	::std::list<PluginComm*>& getPluginComms() { return m_aPluginComms; }
271
	::std::list<XPlugin_Impl*>& getPlugins() { return m_aAllPlugins; }
272
	::osl::Mutex& getPluginMutex() { return m_aPluginMutex; }
273
};
274
275
class XPluginManager_Impl :
276
	public cppu::WeakAggImplHelper1< com::sun::star::plugin::XPluginManager >
277
{
278
	Reference< com::sun::star::uno::XComponentContext > 	m_xContext;
279
public:
280
	XPluginManager_Impl( const Reference< com::sun::star::uno::XComponentContext >  & );
281
	virtual ~XPluginManager_Impl();
282
283
	static XPlugin_Impl* getXPluginFromNPP( NPP );
284
	static XPlugin_Impl* getPluginImplementation( const Reference< com::sun::star::plugin::XPlugin >& plugin );
285
286
	virtual Reference< com::sun::star::plugin::XPluginContext > SAL_CALL createPluginContext() throw();
287
288
	// has to be implemented per system
289
    virtual Sequence< com::sun::star::plugin::PluginDescription > SAL_CALL impl_getPluginDescriptions(void) throw();
290
    // calls system specific impl_getPluginDescriptions
291
    // checks whether plugins are disabled
292
    virtual Sequence< com::sun::star::plugin::PluginDescription > SAL_CALL getPluginDescriptions(void) throw();
293
294
    virtual Reference< com::sun::star::plugin::XPlugin > SAL_CALL createPlugin( const Reference< com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< rtl::OUString >& argn, const Sequence< rtl::OUString >& argv, const com::sun::star::plugin::PluginDescription& plugintype) throw( RuntimeException,::com::sun::star::plugin::PluginException );
295
296
	virtual Reference< com::sun::star::plugin::XPlugin > SAL_CALL createPluginFromURL( const Reference< com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< rtl::OUString >& argn, const Sequence< rtl::OUString >& argv, const Reference< com::sun::star::awt::XToolkit > & toolkit, const Reference< com::sun::star::awt::XWindowPeer > & parent, const rtl::OUString& url ) throw();
297
298
    virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw();
299
	virtual rtl::OUString SAL_CALL getImplementationName() throw();
300
	
301
    Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw(  );
302
    static Sequence< rtl::OUString > getSupportedServiceNames_Static(void) throw(  );
303
	static rtl::OUString 				getImplementationName_Static() throw(  )
304
	{
305
		/** the soplayer uses this name in its source! maybe not after 5.2 */
306
		return rtl::OUString::createFromAscii( "com.sun.star.extensions.PluginManager" );
307
	}
308
};
309
Reference< XInterface >  SAL_CALL PluginManager_CreateInstance( const Reference< com::sun::star::uno::XComponentContext >  & ) throw( Exception );
310
311
enum PluginStreamType { InputStream, OutputStream };
312
313
class PluginStream
314
{
315
protected:
316
	XPlugin_Impl*		m_pPlugin;
317
	NPStream			m_aNPStream;
318
public:
319
	PluginStream( XPlugin_Impl* pPlugin,
320
				   const char* url, sal_uInt32 len, sal_uInt32 lastmod );
321
	virtual ~PluginStream();
322
323
	NPStream* getStream() { return &m_aNPStream; }
324
	XPlugin_Impl* getPlugin() { return m_pPlugin; }
325
326
	virtual PluginStreamType getStreamType() = 0;
327
};
328
329
class PluginInputStream :
330
	public PluginStream,
331
	public cppu::WeakAggImplHelper2<
332
				::com::sun::star::io::XOutputStream,
333
				::com::sun::star::io::XConnectable
334
				>
335
{
336
private:
337
	::ucbhelper::Content*		m_pContent;
338
	sal_Int32					m_nMode;
339
	sal_uInt32						m_nWritePos;
340
341
	Reference< com::sun::star::io::XActiveDataSource >	m_xSource;
342
	// hold a reference on input until closeOutput is called
343
	
344
	Reference< com::sun::star::io::XConnectable >			m_xPredecessor;
345
	Reference< com::sun::star::io::XConnectable >			m_xSuccessor;
346
347
    // needed to hold a reference to self in NP_SEEK mode
348
    Reference< com::sun::star::io::XOutputStream >			m_xSelf;
349
	
350
	SvFileStream				m_aFileStream;
351
public:
352
	PluginInputStream( XPlugin_Impl* pPlugin,
353
				   const char* url, sal_uInt32 len, sal_uInt32 lastmod );
354
355
	PluginInputStream() : PluginStream( NULL, NULL, 0, 0 ) {}
356
	
357
	virtual ~PluginInputStream();
358
359
	virtual PluginStreamType getStreamType();
360
361
	void setMode( sal_Int32 nMode );
362
	sal_uInt32 read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size );
363
	void setSource( const Reference< com::sun::star::io::XActiveDataSource >& xSource ) { m_xSource = xSource; }
364
	// get contents ot url via ucbhelper::Content
365
	void load();
366
367
    // clear reference
368
    bool releaseSelf() 
369
    { bool bRet = m_xSelf.is(); m_xSelf.clear();  return bRet; }
370
371
	// XOutputStream
372
	virtual void SAL_CALL writeBytes( const Sequence<sal_Int8>& ) throw();
373
	virtual void SAL_CALL flush() throw();
374
	virtual void SAL_CALL closeOutput() throw();
375
376
	// XConnectable
377
	virtual void SAL_CALL setPredecessor( const Reference< com::sun::star::io::XConnectable >& xPredecessor ) throw()
378
		{ m_xPredecessor = xPredecessor; }
379
	virtual Reference< com::sun::star::io::XConnectable > SAL_CALL getPredecessor() throw()
380
		{ return m_xPredecessor; }
381
382
	virtual void SAL_CALL setSuccessor( const Reference< com::sun::star::io::XConnectable >& xSuccessor ) throw()
383
		{ m_xSuccessor = xSuccessor; }
384
	virtual Reference< com::sun::star::io::XConnectable > SAL_CALL getSuccessor() throw()
385
		{ return m_xSuccessor; }
386
};
387
388
class PluginOutputStream : public PluginStream
389
{
390
private:
391
	Reference< com::sun::star::io::XOutputStream > 	m_xStream;
392
public:
393
	PluginOutputStream( XPlugin_Impl* pPlugin, const char* url,
394
						sal_uInt32 len, sal_uInt32 lastmod );
395
	virtual ~PluginOutputStream();
396
397
	virtual PluginStreamType getStreamType();
398
399
	Reference< com::sun::star::io::XOutputStream > & getOutputStream() { return m_xStream; }
400
};
401
402
class PluginEventListener :
403
	public cppu::WeakAggImplHelper1< com::sun::star::lang::XEventListener >
404
{
405
private:
406
	XPlugin_Impl*	m_pPlugin;
407
	Reference< com::sun::star::plugin::XPlugin > 		m_xPlugin; // just to hold the plugin
408
	char*			m_pUrl;
409
	char*			m_pNormalizedUrl;
410
	void*			m_pNotifyData;
411
public:
412
	PluginEventListener( XPlugin_Impl*,
413
						 const char* url,
414
						 const char* normurl,
415
						 void*  notifyData );
416
	virtual ~PluginEventListener();
417
418
	const char* getURL() { return m_pUrl; }
419
	const char* getNormalizedURL() { return m_pNormalizedUrl; }
420
	void*		getNotifyData() { return m_pNotifyData; }
421
	
422
	// com::sun::star::lang::XEventListener
423
	virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject&  Source ) throw();
424
};
425
426
#endif
(-)a/main/extensions/source/plugin/inc/plugin/model.hxx (+133 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLUGIN_MODEL_HXX
24
#define __PLUGIN_MODEL_HXX
25
26
#include <com/sun/star/io/XObjectInputStream.hpp>
27
#include <com/sun/star/io/XPersistObject.hpp>
28
#include <com/sun/star/io/XObjectOutputStream.hpp>
29
#include <com/sun/star/lang/XServiceName.hpp>
30
#include <com/sun/star/lang/XServiceInfo.hpp>
31
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
32
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
33
#include <com/sun/star/awt/XControlModel.hpp>
34
#include <com/sun/star/awt/XControl.hpp>
35
#include <com/sun/star/uno/XComponentContext.hpp>
36
37
#include <cppuhelper/propshlp.hxx>
38
#include <cppuhelper/weakagg.hxx>
39
#include <rtl/alloc.h>
40
41
#include <list>
42
43
using namespace com::sun::star::uno;
44
45
class BroadcasterHelperHolder
46
{
47
protected:
48
	::cppu::OBroadcastHelper  m_aHelper;
49
public:
50
	BroadcasterHelperHolder( osl::Mutex& rMutex ) :
51
			m_aHelper( rMutex ) {}
52
	~BroadcasterHelperHolder() {}
53
54
	::cppu::OBroadcastHelper& getHelper() { return m_aHelper; }
55
	
56
};
57
58
class PluginModel : public BroadcasterHelperHolder,
59
					public cppu::OPropertySetHelper,
60
					public cppu::OPropertyArrayHelper,
61
					public cppu::OWeakAggObject,
62
					public com::sun::star::lang::XComponent,
63
					public com::sun::star::io::XPersistObject,
64
					public com::sun::star::awt::XControlModel
65
{
66
  private:
67
	rtl::OUString m_aCreationURL;
68
    rtl::OUString m_aMimeType;
69
70
	std::list< Reference< com::sun::star::lang::XEventListener > >
71
    	m_aDisposeListeners;
72
  public:
73
	// these are here to force memory de/allocation to sal lib.
74
	static void * SAL_CALL operator new( size_t nSize ) throw()
75
		{ return rtl_allocateMemory( nSize ); }
76
	static void SAL_CALL operator delete( void * pMem ) throw()
77
		{ rtl_freeMemory( pMem ); }
78
79
	PluginModel();
80
	PluginModel( const rtl::OUString& rURL, const rtl::OUString& rMimeType );
81
	virtual ~PluginModel();
82
83
84
	const rtl::OUString& getCreationURL() { return m_aCreationURL; }
85
    void setMimeType( const rtl::OUString& rMime ) { m_aMimeType = rMime; }
86
87
	// XInterface
88
	virtual Any SAL_CALL queryInterface( const Type& rType ) throw( com::sun::star::uno::RuntimeException )
89
		{ return OWeakAggObject::queryInterface( rType ); }
90
	virtual void SAL_CALL acquire()  throw()
91
    { OWeakAggObject::acquire(); }
92
	virtual void SAL_CALL release()  throw()
93
    { OWeakAggObject::release(); }
94
95
	virtual Any SAL_CALL queryAggregation( const Type& ) throw( com::sun::star::uno::RuntimeException );
96
97
98
	// com::sun::star::lang::XTypeProvider
99
100
    static Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_Static(void) throw(  );
101
	static rtl::OUString SAL_CALL getImplementationName_Static() throw(  )
102
	{
103
		/** the soplayer uses this name in its source! maybe not after 5.2 */
104
		return rtl::OUString::createFromAscii( "com.sun.star.extensions.PluginModel" );
105
	}
106
107
	// OPropertySetHelper
108
	virtual cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
109
	virtual sal_Bool  SAL_CALL convertFastPropertyValue( Any & rConvertedValue,
110
														 Any & rOldValue, 
111
														 sal_Int32 nHandle,
112
														 const Any& rValue ) throw();
113
	virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
114
															const Any& rValue )
115
		throw(::com::sun::star::uno::Exception);
116
	virtual void SAL_CALL getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw();
117
	virtual Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw();
118
119
	// com::sun::star::io::XPersistObject
120
	virtual rtl::OUString SAL_CALL getServiceName() throw();
121
	virtual void SAL_CALL write(const Reference< com::sun::star::io::XObjectOutputStream > & OutStream) throw();
122
	virtual void SAL_CALL read(const Reference< com::sun::star::io::XObjectInputStream > & InStream) throw();
123
124
	// com::sun::star::lang::XComponent
125
    virtual void SAL_CALL addEventListener( const Reference< com::sun::star::lang::XEventListener > & l ) throw();
126
    virtual void SAL_CALL removeEventListener( const Reference< com::sun::star::lang::XEventListener > & l ) throw();
127
	virtual void SAL_CALL dispose() throw();
128
  private:
129
    using cppu::OPropertySetHelper::getFastPropertyValue;
130
};
131
Reference< XInterface >  SAL_CALL PluginModel_CreateInstance( const Reference< com::sun::star::uno::XComponentContext >  & ) throw( Exception );
132
133
#endif // __PLUGIN_MODEL_HXX
(-)a/main/extensions/source/plugin/inc/plugin/multiplx.hxx (+163 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef _MRC_MULTIPLX_HXX
24
#define _MRC_MULTIPLX_HXX
25
26
#include <com/sun/star/awt/XControl.hpp>
27
#include <com/sun/star/awt/XKeyListener.hpp>
28
#include <com/sun/star/awt/XPaintListener.hpp>
29
#include <com/sun/star/awt/KeyEvent.hpp>
30
#include <com/sun/star/awt/KeyModifier.hpp>
31
#include <com/sun/star/awt/XMouseMotionListener.hpp>
32
#include <com/sun/star/awt/FocusEvent.hpp>
33
#include <com/sun/star/awt/XWindowListener.hpp>
34
#include <com/sun/star/awt/XActivateListener.hpp>
35
#include <com/sun/star/awt/MouseEvent.hpp>
36
#include <com/sun/star/awt/XTopWindowListener.hpp>
37
#include <com/sun/star/awt/PaintEvent.hpp>
38
#include <com/sun/star/awt/InputEvent.hpp>
39
#include <com/sun/star/awt/KeyGroup.hpp>
40
#include <com/sun/star/awt/Key.hpp>
41
#include <com/sun/star/awt/WindowEvent.hpp>
42
#include <com/sun/star/awt/XMouseListener.hpp>
43
#include <com/sun/star/awt/KeyFunction.hpp>
44
#include <com/sun/star/awt/FocusChangeReason.hpp>
45
#include <com/sun/star/awt/MouseButton.hpp>
46
#include <com/sun/star/awt/XFocusListener.hpp>
47
#include <com/sun/star/awt/XTopWindow.hpp>
48
#include <com/sun/star/awt/XWindow.hpp>
49
#include <com/sun/star/awt/PosSize.hpp>
50
51
#include <cppuhelper/implbase7.hxx>
52
#include <cppuhelper/interfacecontainer.hxx>
53
54
using namespace com::sun::star::uno;
55
56
struct MRCListenerMultiplexerHelper_Mutex
57
{
58
	::osl::Mutex aMutex;
59
};
60
61
class MRCListenerMultiplexerHelper	:
62
	public MRCListenerMultiplexerHelper_Mutex,
63
64
	public ::cppu::WeakAggImplHelper7<
65
	  ::com::sun::star::awt::XFocusListener,
66
	  ::com::sun::star::awt::XWindowListener,
67
	  ::com::sun::star::awt::XKeyListener,
68
	  ::com::sun::star::awt::XMouseListener,
69
	  ::com::sun::star::awt::XMouseMotionListener,
70
	  ::com::sun::star::awt::XPaintListener,
71
	  ::com::sun::star::awt::XTopWindowListener >
72
{
73
public:
74
	/**
75
	 * Create a Multiplexer of XWindowEvents.
76
	 *
77
	 * @param rControl	The control. All listeners think that this is the original
78
	 *					broadcaster.
79
	 * @param rPeer		The peer from which the original events are dispatched. Null is
80
	 *					allowed.
81
	 */
82
	MRCListenerMultiplexerHelper( const Reference< ::com::sun::star::awt::XWindow >  & rControl, const Reference< ::com::sun::star::awt::XWindow >  & rPeer );
83
84
	/**
85
	 * Remove all listeners from the previous set peer and add the needed listeners to rPeer.
86
	 * @param rPeer		The peer from which the original events are dispatched. Null is
87
	 *					allowed.
88
	 */
89
	void setPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer );
90
91
	/**
92
	 * Remove all listeners and send a disposing message.
93
	 */
94
	void disposeAndClear();
95
96
	/**
97
	 * Add the specified listener to the source.
98
	 */
99
    void advise( const Type& type, const Reference< XInterface > & listener);
100
	/**
101
	 * Remove the specified listener from the source.
102
	 */
103
    void unadvise(const Type& type, const Reference< XInterface > & listener);
104
105
	// ::com::sun::star::lang::XEventListener
106
	void SAL_CALL	disposing(const ::com::sun::star::lang::EventObject& Source) throw();
107
	// ::com::sun::star::awt::XFocusListener
108
    void SAL_CALL	focusGained(const ::com::sun::star::awt::FocusEvent& e) throw();
109
    void SAL_CALL	focusLost(const ::com::sun::star::awt::FocusEvent& e) throw();
110
	// ::com::sun::star::awt::XWindowListener
111
    void SAL_CALL	windowResized(const ::com::sun::star::awt::WindowEvent& e) throw();
112
    void SAL_CALL	windowMoved(const ::com::sun::star::awt::WindowEvent& e) throw();
113
    void SAL_CALL	windowShown(const ::com::sun::star::lang::EventObject& e) throw();
114
    void SAL_CALL	windowHidden(const ::com::sun::star::lang::EventObject& e) throw();
115
	// ::com::sun::star::awt::XKeyListener
116
    void SAL_CALL	keyPressed( const ::com::sun::star::awt::KeyEvent& e ) throw();
117
    void SAL_CALL	keyReleased( const ::com::sun::star::awt::KeyEvent& e ) throw();
118
	// ::com::sun::star::awt::XMouseListener
119
    void SAL_CALL	mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw();
120
    void SAL_CALL	mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw();
121
    void SAL_CALL	mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw();
122
    void SAL_CALL	mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw();
123
	// ::com::sun::star::awt::XMouseMotionListener
124
    void SAL_CALL	mouseDragged(const ::com::sun::star::awt::MouseEvent& e) throw();
125
    void SAL_CALL	mouseMoved(const ::com::sun::star::awt::MouseEvent& e) throw();
126
	// ::com::sun::star::awt::XPaintListener
127
    void SAL_CALL	windowPaint(const ::com::sun::star::awt::PaintEvent& e) throw();
128
	// ::com::sun::star::awt::XTopWindowListener
129
	void SAL_CALL	windowOpened( const ::com::sun::star::lang::EventObject& e ) throw();
130
	void SAL_CALL	windowClosing( const ::com::sun::star::lang::EventObject& e ) throw();
131
    void SAL_CALL	windowClosed( const ::com::sun::star::lang::EventObject& e ) throw();
132
	void SAL_CALL	windowMinimized( const ::com::sun::star::lang::EventObject& e ) throw();
133
	void SAL_CALL	windowNormalized( const ::com::sun::star::lang::EventObject& e ) throw();
134
    void SAL_CALL	windowActivated( const ::com::sun::star::lang::EventObject& e ) throw();
135
    void SAL_CALL	windowDeactivated( const ::com::sun::star::lang::EventObject& e ) throw();
136
protected:
137
	/**
138
	 * Remove the listener with the uik rUik from the peer rPeer.
139
	 * @param rPeer	the peer from which the listener is removed.
140
	 * @param rUik	the listener uik, which specify the type of the listener.
141
	 */
142
	void		adviseToPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type );
143
	/**
144
	 * Add the listener with the uik rUik to the peer rPeer.
145
	 * @param rPeer	the peer to which the listener is added.
146
	 * @param rUik	the listener uik, which specify the type of the listener.
147
	 */
148
	void		unadviseFromPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type );
149
private:
150
	/** The source of the events. Normally this is the peer object.*/
151
	Reference< ::com::sun::star::awt::XWindow > 		xPeer;
152
	WeakReference< ::com::sun::star::awt::XControl >	xControl;
153
	::cppu::OMultiTypeInterfaceContainerHelper	aListenerHolder;
154
155
156
	MRCListenerMultiplexerHelper( const MRCListenerMultiplexerHelper & );
157
	MRCListenerMultiplexerHelper & operator = ( const MRCListenerMultiplexerHelper & );
158
};
159
160
#endif	// _MRC_MULTIPLX_HXX
161
162
163
(-)a/main/extensions/source/plugin/inc/plugin/plcom.hxx (+81 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLUGIN_INC_PLCOM_HXX
24
#define __PLUGIN_INC_PLCOM_HXX
25
26
#include <tools/string.hxx>
27
#include <list>
28
29
class XPlugin_Impl;
30
31
class PluginComm
32
{
33
protected:
34
	int							m_nRefCount;
35
	::rtl::OString				m_aLibName;
36
	std::list< String >			m_aFilesToDelete;
37
public:
38
	PluginComm( const ::rtl::OString& rLibName, bool bReusable = true );
39
	virtual ~PluginComm();
40
41
	int getRefCount() { return m_nRefCount; }
42
	void addRef() { m_nRefCount++; }
43
	void decRef() { m_nRefCount--; if( ! m_nRefCount ) delete this; }
44
45
	const ::rtl::OString& getLibName() { return m_aLibName; }
46
	void setLibName( const ::rtl::OString& rName ) { m_aLibName = rName; }
47
48
	void addFileToDelete( const String& filename )
49
		{ m_aFilesToDelete.push_back( filename ); }
50
51
	virtual NPError NPP_Destroy( NPP instance, NPSavedData** save ) = 0;
52
	virtual NPError NPP_DestroyStream( NPP instance, NPStream* stream,
53
							   NPError reason ) = 0;
54
	virtual void* NPP_GetJavaClass() = 0;
55
	virtual NPError NPP_Initialize() = 0;
56
	virtual NPError NPP_New( NPMIMEType pluginType, NPP instance,
57
							 uint16 mode, int16 argc,
58
							 char* argn[], char* argv[],
59
							 NPSavedData *saved ) = 0;
60
	virtual NPError NPP_NewStream( NPP instance, NPMIMEType type,
61
								   NPStream* stream,
62
								   NPBool seekable, uint16* stype ) = 0;
63
	virtual void NPP_Print( NPP instance, NPPrint* platformPrint ) = 0;
64
	virtual NPError NPP_SetWindow( NPP instance, NPWindow* window ) = 0;
65
	virtual void NPP_Shutdown() = 0;
66
	virtual void NPP_StreamAsFile( NPP instance, NPStream* stream,
67
								   const char* fname ) = 0;
68
	virtual void NPP_URLNotify( NPP instance, const char* url,
69
								NPReason reason, void* notifyData ) = 0;
70
	virtual int32 NPP_Write( NPP instance, NPStream* stream, int32 offset,
71
							 int32 len, void* buffer ) = 0;
72
	virtual int32 NPP_WriteReady( NPP instance, NPStream* stream ) = 0;
73
	virtual NPError NPP_GetValue( NPP instance, NPPVariable  variable, void* value ) = 0;
74
	virtual NPError NPP_SetValue( NPP instance, NPNVariable variable,
75
								 void *value) = 0;
76
    
77
    virtual NPError NPP_SetWindow( XPlugin_Impl* );
78
    virtual NPError NPP_Destroy( XPlugin_Impl*, NPSavedData** save );
79
};
80
81
#endif
(-)a/main/extensions/source/plugin/inc/plugin/plctrl.hxx (+177 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLCTRL_HXX
24
#define __PLCTRL_HXX
25
26
#include <tools/debug.hxx>
27
28
#include <cppuhelper/weak.hxx>
29
#include <plugin/multiplx.hxx>
30
#include <com/sun/star/beans/PropertyValues.hpp>
31
#include <com/sun/star/beans/XPropertySet.hpp>
32
#include <com/sun/star/beans/PropertyValue.hpp>
33
#include <com/sun/star/beans/PropertyState.hpp>
34
#include <com/sun/star/beans/XPropertySetInfo.hpp>
35
#include <com/sun/star/beans/XMultiPropertySet.hpp>
36
#include <com/sun/star/beans/XFastPropertySet.hpp>
37
#include <com/sun/star/beans/XVetoableChangeListener.hpp>
38
#include <com/sun/star/beans/XPropertyState.hpp>
39
#include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
40
#include <com/sun/star/beans/PropertyAttribute.hpp>
41
#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
42
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
43
#include <com/sun/star/beans/XPropertyAccess.hpp>
44
#include <com/sun/star/beans/XPropertyContainer.hpp>
45
#include <com/sun/star/beans/PropertyStateChangeEvent.hpp>
46
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
47
#include <com/sun/star/awt/XVclContainerPeer.hpp>
48
#include <com/sun/star/awt/XVclWindowPeer.hpp>
49
#include <com/sun/star/awt/XControlModel.hpp>
50
#include <com/sun/star/awt/XUnoControlContainer.hpp>
51
#include <com/sun/star/awt/XControlContainer.hpp>
52
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
53
#include <com/sun/star/awt/XVclContainer.hpp>
54
#include <com/sun/star/awt/XControl.hpp>
55
#include <com/sun/star/awt/XTopWindow.hpp>
56
#include <com/sun/star/awt/XWindow.hpp>
57
#include <com/sun/star/awt/PosSize.hpp>
58
59
#include <cppuhelper/implbase4.hxx>
60
61
#include <list>
62
63
class SystemChildWindow;
64
65
//==================================================================================================
66
class PluginControl_Impl : public ::cppu::WeakAggImplHelper4<
67
	  ::com::sun::star::awt::XControl,
68
	  ::com::sun::star::awt::XWindow,
69
	  ::com::sun::star::awt::XFocusListener,
70
	  ::com::sun::star::awt::XView >
71
{
72
public:
73
	// ::com::sun::star::awt::XControl
74
    virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & xContext ) throw( ::com::sun::star::uno::RuntimeException )
75
	{ _xContext = xContext; }
76
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getContext() throw( ::com::sun::star::uno::RuntimeException )
77
	{ return _xContext; }
78
	
79
    virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & Model ) throw( ::com::sun::star::uno::RuntimeException ) = 0;
80
//	{ DBG_ERROR( "### setModel() illegal on plugincontrol!" ); return sal_False; }
81
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > SAL_CALL getModel() throw( ::com::sun::star::uno::RuntimeException ) = 0;
82
83
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XView > SAL_CALL getView() throw( ::com::sun::star::uno::RuntimeException )
84
	{ return (::com::sun::star::awt::XView*)this; }
85
	
86
    virtual sal_Bool SAL_CALL isTransparent() throw( ::com::sun::star::uno::RuntimeException )
87
	{ return sal_False; }
88
	
89
    virtual void SAL_CALL setDesignMode( sal_Bool bOn ) throw( ::com::sun::star::uno::RuntimeException );
90
    virtual sal_Bool SAL_CALL isDesignMode() throw( ::com::sun::star::uno::RuntimeException )
91
	{ return _bInDesignMode; }
92
	
93
    virtual void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > & xToolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > & Parent) throw( ::com::sun::star::uno::RuntimeException );
94
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > SAL_CALL getPeer() throw( ::com::sun::star::uno::RuntimeException )
95
	{ return _xPeer; }
96
	
97
	// ::com::sun::star::awt::XWindow
98
    virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw( ::com::sun::star::uno::RuntimeException );
99
    virtual void SAL_CALL setEnable( sal_Bool bEnable ) throw( ::com::sun::star::uno::RuntimeException );
100
    virtual void SAL_CALL setFocus(void) throw( ::com::sun::star::uno::RuntimeException );
101
	
102
	virtual void SAL_CALL setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) throw( ::com::sun::star::uno::RuntimeException );
103
    virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize(void) throw( ::com::sun::star::uno::RuntimeException );
104
	
105
    virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
106
    virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
107
    virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
108
    virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
109
    virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
110
    virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
111
    virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
112
    virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
113
    virtual void SAL_CALL addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( RuntimeException );
114
    virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
115
    virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
116
    virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
117
118
	// ::com::sun::star::lang::XEventListener
119
	virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject & rSource ) throw( ::com::sun::star::uno::RuntimeException );
120
	// ::com::sun::star::awt::XFocusListener
121
	virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );
122
	virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );
123
	
124
	// ::com::sun::star::lang::XComponent
125
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
126
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
127
	
128
	virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
129
130
	// ::com::sun::star::awt::XView
131
    virtual sal_Bool SAL_CALL setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > & /*aDevice*/ ) throw( ::com::sun::star::uno::RuntimeException )
132
	{ return sal_False; }
133
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > SAL_CALL getGraphics(void) throw( ::com::sun::star::uno::RuntimeException )
134
	{ return ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > (); }
135
	
136
    virtual ::com::sun::star::awt::Size	SAL_CALL getSize(void) throw( ::com::sun::star::uno::RuntimeException )
137
	{ return ::com::sun::star::awt::Size(_nWidth, _nHeight); }
138
	
139
    virtual void SAL_CALL draw( sal_Int32 x, sal_Int32 y ) throw( ::com::sun::star::uno::RuntimeException );
140
	virtual void SAL_CALL setZoom( float ZoomX, float ZoomY ) throw( ::com::sun::star::uno::RuntimeException );
141
142
public:
143
								PluginControl_Impl();
144
	virtual						~PluginControl_Impl();
145
	
146
	MRCListenerMultiplexerHelper* getMultiplexer();
147
148
protected:
149
	void						releasePeer();
150
	
151
protected:
152
	::std::list< Reference< ::com::sun::star::lang::XEventListener > >	_aDisposeListeners;
153
	MRCListenerMultiplexerHelper*		_pMultiplexer;
154
155
	Reference< XInterface > 						_xContext;
156
	
157
	sal_Int32								_nX;
158
	sal_Int32								_nY;
159
	sal_Int32								_nWidth;
160
	sal_Int32								_nHeight;
161
	sal_Int16								_nFlags;
162
	
163
	sal_Bool								_bVisible;
164
	sal_Bool								_bInDesignMode;
165
	sal_Bool								_bEnable;
166
	
167
    SystemChildWindow*					_pSysChild;
168
	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > 						_xPeer;
169
	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > 							_xPeerWindow;
170
171
	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > 							_xParentWindow;
172
	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > 						_xParentPeer;
173
};
174
175
#endif
176
177
(-)a/main/extensions/source/plugin/inc/plugin/unx/mediator.hxx (+179 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef _MEDIATOR_HXX
24
#define _MEDIATOR_HXX
25
26
#include <string.h>
27
#include <stdarg.h>
28
#include <tools/string.hxx>
29
#include <tools/link.hxx>
30
#include <vos/pipe.hxx>
31
#include <vos/mutex.hxx>
32
#include <vos/conditn.hxx>
33
#include <vos/thread.hxx>
34
#if OSL_DEBUG_LEVEL > 1
35
#include <stdio.h>
36
#endif
37
38
#include <vector>
39
40
struct MediatorMessage
41
{
42
	sal_uLong	m_nID;
43
	sal_uLong	m_nBytes;
44
	char*	m_pBytes;
45
	char*	m_pRun;
46
47
	MediatorMessage() : m_nID( 0 ), m_nBytes( 0 ),
48
		m_pBytes( NULL ), m_pRun( NULL ) {}
49
	MediatorMessage( sal_uLong nID, sal_uLong nBytes, char* pBytes ) :
50
			m_nID( nID ),m_nBytes( nBytes ), m_pRun( NULL )
51
		{
52
			m_pBytes = new char[ m_nBytes ];
53
			memcpy( m_pBytes, pBytes, (size_t)m_nBytes );
54
		}
55
56
	~MediatorMessage()
57
		{
58
			if( m_pBytes )
59
				delete [] m_pBytes;
60
		}
61
62
	void Set( sal_uLong nBytes, char* pBytes )
63
		{
64
			if( m_pBytes )
65
				delete [] m_pBytes;
66
			m_nBytes = nBytes;
67
			m_pBytes = new char[ m_nBytes ];
68
			memcpy( m_pBytes, pBytes, (size_t)m_nBytes );
69
		}
70
71
	sal_uLong	ExtractULONG();
72
	char*	GetString();
73
	sal_uInt32	GetUINT32();
74
	void*	GetBytes( sal_uLong& );
75
	void*	GetBytes() { sal_uLong nBytes; return GetBytes( nBytes ); }
76
77
	void	Rewind() { m_pRun = NULL; }
78
};
79
80
class MediatorListener;
81
82
class Mediator
83
{
84
	friend class MediatorListener;
85
protected:
86
    int									m_nSocket;
87
88
    std::vector<MediatorMessage*>		m_aMessageQueue;
89
	vos::OMutex				m_aQueueMutex;
90
	vos::OMutex				m_aSendMutex;
91
	// only one thread can send a message at any given time
92
	vos::OCondition			m_aNewMessageCdtn;
93
	MediatorListener*					m_pListener;
94
	// thread to fill the queue
95
96
	sal_uLong								m_nCurrentID;
97
	// will be constantly increased with each message sent
98
	bool								m_bValid;
99
100
	Link								m_aConnectionLostHdl;
101
	Link								m_aNewMessageHdl;
102
public:
103
	Mediator( int nSocket );
104
	~Mediator();
105
106
	// mark mediator as invalid. No more messages will be processed,
107
	// SendMessage, WaitForMessage, TransactMessage will return immediatly
108
	// with error
109
	void invalidate() { m_bValid = false; }
110
111
	sal_uLong SendMessage( sal_uLong nBytes, const char* pBytes, sal_uLong nMessageID = 0 );
112
	sal_uLong SendMessage( const ByteString& rMessage, sal_uLong nMessageID = 0 )
113
		{
114
			return SendMessage( rMessage.Len(), rMessage.GetBuffer(), nMessageID );
115
		}
116
117
	sal_Bool WaitForMessage( sal_uLong nTimeOut = 5000 );
118
	// timeout in ms
119
	// TRUE:  Message came in
120
	// FALSE: timed out
121
	// if timeout is set, WaitForMessage will wait even if there are messages
122
	// in the queue
123
124
	virtual MediatorMessage* WaitForAnswer( sal_uLong nMessageID );
125
    // wait for an answer message ( ID >= 1 << 24 )
126
	// the message will be removed from the queue and returned
127
128
	MediatorMessage* TransactMessage( sal_uLong nBytes, char* pBytes );
129
	// sends a message and waits for an answer
130
131
	MediatorMessage* GetNextMessage( sal_Bool bWait = sal_False );
132
133
134
	Link SetConnectionLostHdl( const Link& rLink )
135
		{
136
			Link aRet = m_aConnectionLostHdl;
137
			m_aConnectionLostHdl = rLink;
138
			return aRet;
139
		}
140
141
	Link SetNewMessageHdl( const Link& rLink )
142
		{
143
			Link aRet = m_aNewMessageHdl;
144
			m_aNewMessageHdl = rLink;
145
			return aRet;
146
		}
147
};
148
149
class MediatorListener : public vos:: OThread 
150
{
151
	friend class Mediator;
152
  private:
153
	Mediator*		m_pMediator;
154
    ::vos::OMutex	m_aMutex;
155
156
	MediatorListener( Mediator* );
157
	~MediatorListener();
158
159
	virtual void run();
160
    virtual void onTerminated();
161
};
162
163
inline void medDebug( int condition, const char* pFormat, ... )
164
{
165
#if OSL_DEBUG_LEVEL > 1
166
	if( condition )
167
	{
168
		va_list ap;
169
		va_start( ap, pFormat );
170
		vfprintf( stderr, pFormat, ap );
171
		va_end( ap );
172
	}
173
#else
174
    (void)condition;
175
    (void)pFormat;
176
#endif
177
}
178
179
#endif // _MEDIATOR_HXX
(-)a/main/extensions/source/plugin/inc/plugin/unx/plugcon.hxx (+247 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef _PLUGCON_HXX
24
#define _PLUGCON_HXX
25
26
#include <stdarg.h>
27
#include <string.h>
28
29
#include <list>
30
#include <vector>
31
#include <plugin/unx/mediator.hxx>
32
33
#if defined SOLARIS
34
#define USE_MOTIF
35
#endif
36
37
#define Window		XLIB_Window
38
#define Font		XLIB_Font
39
#define KeyCode		XLIB_KeyCode
40
#define Time		XLIB_Time
41
#define Cursor		XLIB_Cursor
42
#define Region		XLIB_Region
43
#define String		XLIB_String
44
#define Boolean		XLIB_Boolean
45
#define XPointer	XLIB_XPointer
46
#include <X11/Xlib.h>
47
extern "C" {
48
#include <X11/Intrinsic.h>
49
}
50
#include <X11/Shell.h>
51
#include <X11/IntrinsicP.h>     /* Intrinsics Definitions*/
52
#include <X11/StringDefs.h>    /* Standard Name-String definitions*/
53
#if defined USE_MOTIF
54
#include <Xm/DrawingA.h>
55
#else
56
#  if defined DISABLE_XAW
57
#     include <X11/Composite.h>
58
#  else
59
#     include <X11/Xaw/Label.h>
60
#  endif
61
#endif
62
#include <X11/Xatom.h>
63
#ifndef XP_UNIX
64
#    define XP_UNIX
65
#endif
66
#define MOZ_X11
67
#include <stdio.h>
68
#ifdef SYSTEM_MOZILLA
69
#ifndef OJI
70
#  define OJI
71
#endif
72
#define MOZ_X11
73
#endif
74
75
//http://qa.openoffice.org/issues/show_bug.cgi?id=82545
76
//https://bugzilla.mozilla.org/show_bug.cgi?id=241262
77
#ifdef UNIX
78
#  ifndef _UINT32
79
#    if defined(__alpha) || defined(__LP64__)
80
       typedef unsigned int uint32;
81
#    else  /* __alpha */
82
       typedef unsigned long uint32;
83
#    endif
84
#    define _UINT32
85
#  endif
86
#  ifndef _INT32
87
#    if defined(__alpha) || defined(__LP64__)
88
       typedef int int32;
89
#    else  /* __alpha */
90
       typedef long int32;
91
#    endif
92
#    define _INT32
93
#  endif
94
#endif
95
96
#ifndef _NPAPI_H_
97
extern "C" {
98
#include <npupp.h>
99
}
100
#include <npapi.h>
101
102
#if NP_VERSION_MINOR < 17
103
// compatibility hack: compile with older NPN api header, but define
104
// some later introduced constants
105
// for gcc 3
106
#define NP_ABI_MASK 0x10000000
107
#define NPNVSupportsXEmbedBool ((NPNVariable)14)
108
#define NPPVpluginNeedsXEmbed  ((NPPVariable)14)
109
#define NPNVToolkit            ((int)(13 | NP_ABI_MASK))
110
#define NPNVGtk12 1
111
#define NPNVGtk2  2
112
#endif
113
#endif
114
115
#ifdef ENABLE_GTK
116
#include <gtk/gtk.h>
117
#include <gdk/gdkx.h>
118
#else
119
#define GtkWidget void
120
#endif
121
122
#undef Window
123
#undef Font
124
#undef KeyCode
125
#undef Time
126
#undef Cursor
127
#undef String
128
#undef Region
129
#undef Boolean
130
#undef XPointer
131
132
class ConnectorInstance
133
{
134
public:
135
	NPP							instance;
136
	NPWindow					window;
137
	NPSetWindowCallbackStruct	ws_info;
138
	char*						pMimeType;
139
	void*						pShell;
140
	void*						pWidget;
141
    void*						pForm;
142
    
143
    GtkWidget*                  pGtkWindow;
144
    GtkWidget*                  pGtkWidget;
145
    
146
    bool                        bShouldUseXEmbed;
147
148
	int nArg;
149
	char** argn;
150
	char** argv;
151
	char* pArgnBuf;
152
	char* pArgvBuf;
153
	NPSavedData aData;
154
155
	ConnectorInstance( NPP inst, char* type,
156
					   int args, char* pargnbuf, sal_uLong nargnbytes,
157
					   char* pargvbuf, sal_uLong nargvbytes,
158
					   char* savedata, sal_uLong savebytes );
159
	~ConnectorInstance();
160
};
161
162
class PluginConnector : public Mediator
163
{
164
protected:
165
	vos::OMutex               m_aUserEventMutex;
166
167
	static std::vector<PluginConnector*>  allConnectors;
168
	
169
	DECL_LINK( NewMessageHdl, Mediator* );
170
	DECL_LINK( WorkOnNewMessageHdl, Mediator* );
171
	
172
    std::vector<NPStream*>              m_aNPWrapStreams;
173
    std::vector<ConnectorInstance*>     m_aInstances;
174
	
175
	sal_uLong	FillBuffer( char*&, const char*, sal_uLong, va_list );
176
public:
177
	PluginConnector( int nSocket );
178
	~PluginConnector();
179
180
	virtual MediatorMessage* WaitForAnswer( sal_uLong nMessageID );
181
	MediatorMessage*	Transact( const char*, sal_uLong, ... );
182
	MediatorMessage*	Transact( sal_uInt32, ... );
183
	void				Respond( sal_uLong nID, char*, sal_uLong, ... );
184
	sal_uLong				Send( sal_uInt32, ... );
185
186
    static const sal_uInt32 UnknownStreamID = 0xffffffff;
187
    static const sal_uInt32 UnknownNPPID = 0xffffffff;
188
189
	sal_uInt32	GetStreamID( NPStream* pStream );
190
	sal_uInt32	GetNPPID( NPP );
191
192
    std::vector<NPStream*>& getStreamList() { return m_aNPWrapStreams; }
193
194
	NPError GetNPError( MediatorMessage* pMes )
195
	{
196
		NPError* pErr = (NPError*)pMes->GetBytes();
197
		NPError aErr = *pErr;
198
		delete [] pErr;
199
		return aErr;
200
	}
201
202
	void CallWorkHandler()
203
	{
204
		LINK( this, PluginConnector, WorkOnNewMessageHdl ).
205
			Call( (Mediator*)this );
206
	}
207
    
208
    ConnectorInstance* getInstance( NPP );
209
    ConnectorInstance* getInstanceById( sal_uInt32 );
210
};
211
212
enum CommandAtoms
213
{
214
        eNPN_GetURL,
215
        eNPN_GetURLNotify,
216
        eNPN_DestroyStream,
217
        eNPN_NewStream,
218
        eNPN_PostURLNotify,
219
        eNPN_PostURL,
220
        eNPN_RequestRead,
221
        eNPN_Status,
222
        eNPN_Version,
223
        eNPN_Write,
224
		eNPN_UserAgent,
225
226
        eNPP_DestroyStream,
227
        eNPP_Destroy,
228
        eNPP_DestroyPhase2,
229
        eNPP_NewStream,
230
        eNPP_New,
231
        eNPP_SetWindow,
232
        eNPP_StreamAsFile,
233
        eNPP_URLNotify,
234
        eNPP_WriteReady,
235
        eNPP_Write,
236
        eNPP_GetMIMEDescription,
237
        eNPP_Initialize,
238
        eNPP_Shutdown,
239
240
        eMaxCommand
241
};
242
243
const char* GetCommandName( CommandAtoms );
244
245
#define POST_STRING( x ) x ? x : const_cast<char*>(""), x ? strlen(x) : 1
246
247
#endif // _PLUGCON_HXX
(-)a/main/extensions/source/plugin/inc/plugin/unx/sysplug.hxx (+79 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
#ifndef __PLUGIN_INC_UNXPLUG_HXX
24
#define __PLUGIN_INC_UNXPLUG_HXX
25
26
#include <unistd.h>
27
28
#include <plugin/unx/plugcon.hxx>
29
#include <plugin/plcom.hxx>
30
#include <vcl/sysdata.hxx>
31
32
class UnxPluginComm : public PluginComm, public PluginConnector
33
{
34
private:
35
	static int	nConnCounter;
36
37
	pid_t		m_nCommPID;
38
public:
39
	UnxPluginComm( const String& mimetype,
40
                   const String& library,
41
                   XLIB_Window aParent,
42
                   int nDescriptor1,
43
                   int nDescriptor2
44
                   );
45
	virtual ~UnxPluginComm();
46
47
    using PluginComm::NPP_Destroy;
48
	virtual NPError NPP_Destroy( NPP instance, NPSavedData** save );
49
	virtual NPError NPP_DestroyStream( NPP instance, NPStream* stream,
50
									   NPError reason );
51
	virtual void* NPP_GetJavaClass();
52
	virtual NPError NPP_Initialize();
53
	virtual NPError NPP_New( NPMIMEType pluginType, NPP instance,
54
							 uint16 mode, int16 argc,
55
							 char* argn[], char* argv[], NPSavedData *saved );
56
	virtual NPError NPP_NewStream( NPP instance, NPMIMEType type,
57
								   NPStream* stream,
58
								   NPBool seekable, uint16* stype );
59
	virtual void NPP_Print( NPP instance, NPPrint* platformPrint );
60
61
    using PluginComm::NPP_SetWindow;
62
	virtual NPError NPP_SetWindow( NPP instance, NPWindow* window );
63
	virtual void NPP_Shutdown();
64
	virtual void NPP_StreamAsFile( NPP instance, NPStream* stream,
65
								   const char* fname );
66
	virtual void NPP_URLNotify( NPP instance, const char* url, NPReason reason,
67
								void* notifyData );
68
	virtual int32 NPP_Write( NPP instance, NPStream* stream, int32 offset,
69
							 int32 len, void* buffer );
70
	virtual int32 NPP_WriteReady( NPP instance, NPStream* stream );
71
	virtual char* NPP_GetMIMEDescription();
72
	virtual NPError NPP_GetValue( NPP instance, NPPVariable variable, void* value );
73
	virtual NPError NPP_SetValue( NPP instance, NPNVariable variable,
74
								 void *value);
75
76
    static bool getPluginappPath(rtl::OString * path);
77
};
78
79
#endif
(-)a/main/extensions/source/plugin/inc/plugin/win/sysplug.hxx (+121 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
#ifndef __PLUGIN_INC_WINPLUG_HXX
25
#define __PLUGIN_INC_WINPLUG_HXX
26
27
#pragma warning (push,1)
28
#pragma warning (disable:4005)
29
30
#include <tools/prewin.h>
31
32
#include <windows.h>
33
#include <tchar.h>
34
#include <winbase.h>
35
36
#include <tools/postwin.h>
37
38
#pragma pack( push, 8 )
39
#include <npapi.h>
40
#include <npupp.h>
41
#pragma pack( pop )
42
43
#pragma warning (pop)
44
45
#include <list>
46
#include <map>
47
#include <algorithm>
48
49
#include <plugin/plcom.hxx>
50
#include <vcl/threadex.hxx>
51
52
//==================================================================================================
53
class PluginComm_Impl :
54
    public PluginComm,
55
	public ::vcl::SolarThreadExecutor
56
	
57
{
58
	enum CallType {
59
		eNPP_Destroy,
60
		eNPP_DestroyStream,
61
		eNPP_GetJavaClass,
62
		eNPP_Initialize,
63
		eNPP_New,
64
		eNPP_NewStream,
65
		eNPP_Print,
66
		eNPP_SetWindow,
67
		eNPP_Shutdown,
68
		eNPP_StreamAsFile,
69
		eNPP_URLNotify,
70
		eNPP_Write,
71
		eNPP_WriteReady,
72
		eNPP_GetValue,
73
		eNPP_SetValue,
74
		eNP_Initialize
75
	};
76
77
	void*				m_aArgs[ 8 ];
78
	CallType			m_eCall;
79
	
80
	virtual long		doIt();
81
public:
82
						PluginComm_Impl( const rtl::OUString& rMIME, const rtl::OUString& rName, HWND hWnd );
83
	virtual				~PluginComm_Impl();
84
	
85
public:
86
    using PluginComm::NPP_Destroy;
87
	virtual NPError		NPP_Destroy( NPP instance, NPSavedData** save );
88
	virtual NPError		NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason );
89
	virtual void *		NPP_GetJavaClass();
90
	virtual NPError		NPP_Initialize();
91
	virtual NPError		NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
92
								 char* argn[], char* argv[], NPSavedData *saved );
93
	virtual NPError		NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
94
									   NPBool seekable, uint16* stype );
95
	virtual void		NPP_Print( NPP instance, NPPrint* platformPrint );
96
    
97
    using PluginComm::NPP_SetWindow;
98
	virtual NPError		NPP_SetWindow( NPP instance, NPWindow* window );
99
	virtual void		NPP_Shutdown();
100
	virtual void		NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname );
101
	virtual void		NPP_URLNotify( NPP instance, const char* url,
102
									   NPReason reason, void* notifyData );
103
	virtual int32		NPP_Write( NPP instance, NPStream* stream, int32 offset,
104
								   int32 len, void* buffer );
105
	virtual int32		NPP_WriteReady( NPP instance, NPStream* stream );
106
	virtual NPError		NPP_GetValue( NPP instance, NPPVariable variable, void *ret_alue );
107
	virtual NPError		NPP_SetValue( NPP instance, NPNVariable variable, void *ret_alue );
108
	
109
private:
110
	BOOL				retrieveFunction( TCHAR* pName, void** ppFunc ) const;
111
	
112
private:
113
	HINSTANCE			_plDLL;
114
115
	NPPluginFuncs		_NPPfuncs;
116
};
117
118
119
#endif
120
121
(-)a/main/extensions/source/plugin/unx/makefile.mk (+106 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
PRJ=..$/..$/..
24
25
PRJNAME=extensions
26
TARGET=plunx
27
TARGETTYPE=CUI
28
ENABLE_EXCEPTIONS=TRUE
29
30
.INCLUDE :  ..$/util$/makefile.pmk
31
32
.IF "$(GUIBASE)"=="aqua"
33
dummy:
34
    @echo "Nothing to build for GUIBASE aqua."
35
    
36
.ELSE
37
38
# --- Files --------------------------------------------------------
39
40
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/plugin
41
.IF "$(SOLAR_JAVA)" != ""
42
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/java
43
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/nspr
44
CDEFS+=-DOJI
45
.ENDIF
46
47
.IF "$(WITH_MOZILLA)" != "NO"
48
49
.IF "$(DISABLE_XAW)" == "TRUE"
50
CDEFS+=-DDISABLE_XAW
51
.ENDIF
52
53
SLOFILES=\
54
	$(SLO)$/nppapi.obj		\
55
	$(SLO)$/sysplug.obj		\
56
	$(SLO)$/mediator.obj	\
57
	$(SLO)$/plugcon.obj		\
58
	$(SLO)$/unxmgr.obj
59
60
OBJFILES=\
61
	$(OBJ)$/npwrap.obj		\
62
	$(OBJ)$/npnapi.obj		\
63
	$(OBJ)$/mediator.obj	\
64
	$(OBJ)$/plugcon.obj
65
66
APP1TARGET=pluginapp.bin
67
APP1OBJS=$(OBJFILES)
68
APP1STDLIBS=\
69
	$(VOSLIB)					\
70
	$(SALLIB)
71
.IF "$(OS)"=="SOLARIS" || "$(OS)"=="SCO" || "$(OS)"=="HPUX"
72
APP1STDLIBS+=-lXm -lXt $(X11LINK_DYNAMIC) -ldl
73
.ELSE
74
.IF "$(DISABLE_XAW)" != "TRUE"
75
APP1STDLIBS+=-lXaw 
76
.ENDIF
77
.IF "$(OS)"=="FREEBSD" || "$(OS)"=="NETBSD"
78
APP1STDLIBS+= -lXt -lXext -lX11
79
.ELSE
80
APP1STDLIBS+= -lXt $(X11LINK_DYNAMIC) -ldl
81
.ENDIF
82
.ENDIF
83
84
.IF "$(ENABLE_GTK)" == "TRUE"
85
# libs for gtk plugin
86
APP1STDLIBS+=$(PKGCONFIG_LIBS:s/ -lpangoxft-1.0//)
87
# hack for faked SO environment
88
.IF "$(PKGCONFIG_ROOT)"!=""
89
.IF "$(OS)" == "SOLARIS"
90
# don't ask, it's ugly
91
DIRECT :=-z nodefs $(DIRECT)
92
.ENDIF
93
.ENDIF          # "$(PKGCONFIG_ROOT)"!=""
94
.ENDIF
95
    
96
97
APP1DEF=	$(MISC)$/$(TARGET).def
98
99
.ENDIF # $(WITH_MOZILLA) != "NO"
100
101
.ENDIF # $(GUIBASE)==aqua
102
103
# --- Targets ------------------------------------------------------
104
105
.INCLUDE :	target.mk
106
(-)a/main/extensions/source/plugin/unx/mediator.cxx (+305 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <errno.h>
27
#include <unistd.h>
28
29
#include <plugin/unx/mediator.hxx>
30
#include <vcl/svapp.hxx>
31
32
#define MEDIATOR_MAGIC 0xf7a8d2f4
33
34
Mediator::Mediator( int nSocket ) :
35
        m_nSocket( nSocket ),
36
		m_pListener( NULL ),
37
		m_nCurrentID( 1 ),
38
		m_bValid( true )
39
{
40
	m_pListener = new MediatorListener( this );
41
	m_pListener->create();
42
}
43
44
Mediator::~Mediator()
45
{
46
	if( m_pListener )
47
	{
48
        {
49
            ::vos::OGuard aGuard( m_pListener->m_aMutex );
50
            m_pListener->m_pMediator = NULL;
51
        }
52
		m_pListener = NULL;
53
		if( m_bValid )
54
		{
55
			sal_uLong aHeader[3];
56
			aHeader[0] = 0;
57
			aHeader[1] = 0;
58
            aHeader[2] = MEDIATOR_MAGIC;
59
            write( m_nSocket, aHeader, sizeof( aHeader ) );
60
		}
61
        // kick the thread out of its run method; it deletes itself
62
        close( m_nSocket );
63
	}
64
    else
65
        close( m_nSocket );
66
    for( std::vector< MediatorMessage* >::iterator it = m_aMessageQueue.begin();
67
         it != m_aMessageQueue.end(); ++it )
68
    {
69
		delete *it;
70
    }
71
}
72
73
74
sal_uLong Mediator::SendMessage( sal_uLong nBytes, const char* pBytes, sal_uLong nMessageID )
75
{
76
    if( ! m_pListener )
77
        return 0;
78
79
	vos::OGuard aGuard( m_aSendMutex );
80
	if( ! nMessageID )
81
		nMessageID = m_nCurrentID;
82
83
	m_nCurrentID++;
84
	if( m_nCurrentID >= 1 << 24 ) // protection against overflow
85
		m_nCurrentID = 1;
86
87
    if( ! m_bValid )
88
        return nMessageID;
89
90
	sal_uLong* pBuffer = new sal_uLong[ (nBytes/sizeof(sal_uLong)) + 4 ];
91
	pBuffer[ 0 ] = nMessageID;
92
	pBuffer[ 1 ] = nBytes;
93
    pBuffer[ 2 ] = MEDIATOR_MAGIC;
94
	memcpy( &pBuffer[3], pBytes, (size_t)nBytes );
95
	write( m_nSocket, pBuffer, nBytes + 3*sizeof( sal_uLong ) );
96
	delete [] pBuffer;
97
98
	return nMessageID;
99
}
100
101
sal_Bool Mediator::WaitForMessage( sal_uLong nTimeOut )
102
{
103
    if( ! m_pListener )
104
        return sal_False;
105
106
	size_t nItems = m_aMessageQueue.size();
107
108
	if( ! nTimeOut && nItems > 0 )
109
		return sal_True;
110
111
	TimeValue aValue;
112
	aValue.Seconds = nTimeOut/1000;
113
	aValue.Nanosec = ( nTimeOut % 1000 ) * 1000;
114
115
	while( m_aMessageQueue.size() == nItems )
116
	{
117
		m_aNewMessageCdtn.wait( & aValue );
118
		m_aNewMessageCdtn.reset();
119
		if( nTimeOut && m_aMessageQueue.size() == nItems )
120
			return sal_False;
121
	}
122
	return sal_True;
123
}
124
125
MediatorMessage* Mediator::WaitForAnswer( sal_uLong nMessageID )
126
{
127
	nMessageID &= 0x00ffffff;
128
	while( m_pListener )
129
	{
130
		{
131
			vos::OGuard aGuard( m_aQueueMutex );
132
			for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
133
			{
134
                MediatorMessage* pMessage = m_aMessageQueue[ i ];
135
				sal_uLong nID = pMessage->m_nID;
136
				if(  ( nID & 0xff000000 ) &&
137
					 ( ( nID & 0x00ffffff ) == nMessageID ) )
138
                {
139
					m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
140
                    return pMessage;
141
                }
142
			}
143
		}
144
		WaitForMessage( 10 );
145
	}
146
	return NULL;
147
}
148
149
MediatorMessage* Mediator::GetNextMessage( sal_Bool bWait )
150
{
151
	while( m_pListener )
152
	{
153
		{
154
			// guard must be after WaitForMessage, else the listener
155
			// cannot insert a new one -> deadlock
156
			vos::OGuard aGuard( m_aQueueMutex );
157
			for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
158
            {
159
                MediatorMessage* pMessage = m_aMessageQueue[ i ];
160
				if( ! ( pMessage->m_nID & 0xff000000 ) )
161
                {
162
                    m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
163
					return pMessage;
164
                }
165
            }
166
			if( ! bWait )
167
				return NULL;
168
		}
169
		WaitForMessage();
170
	}
171
    return NULL;
172
}
173
174
MediatorMessage* Mediator::TransactMessage( sal_uLong nBytes, char* pBytes )
175
{
176
	sal_uLong nID = SendMessage( nBytes, pBytes );
177
	return WaitForAnswer( nID );
178
}
179
180
MediatorListener::MediatorListener( Mediator* pMediator ) :
181
		m_pMediator( pMediator )
182
{
183
}
184
185
MediatorListener::~MediatorListener()
186
{
187
}
188
189
void MediatorListener::run()
190
{
191
    bool bRun = true;
192
    while( schedule() && m_pMediator && bRun )
193
    {
194
        sal_uLong nHeader[ 3 ];
195
        int nBytes;
196
        
197
        if( m_pMediator && ( nBytes = read( m_pMediator->m_nSocket, nHeader, sizeof( nHeader ) ) ) == sizeof( nHeader ) && nHeader[2] == MEDIATOR_MAGIC)
198
        {
199
            if( nHeader[ 0 ] == 0 && nHeader[ 1 ] == 0 )
200
                return;
201
            char* pBuffer = new char[ nHeader[ 1 ] ];
202
            if( m_pMediator && (sal_uLong)read( m_pMediator->m_nSocket, pBuffer, nHeader[ 1 ] ) == nHeader[ 1 ] )
203
            {
204
                ::vos::OGuard aMyGuard( m_aMutex );
205
                {
206
                    vos::OGuard
207
                        aGuard( m_pMediator->m_aQueueMutex );
208
                    MediatorMessage* pMessage =
209
                        new MediatorMessage( nHeader[ 0 ], nHeader[ 1 ], pBuffer );
210
                    m_pMediator->m_aMessageQueue.push_back( pMessage );
211
                }
212
                m_pMediator->m_aNewMessageCdtn.set();
213
                m_pMediator->m_aNewMessageHdl.Call( m_pMediator );
214
            }
215
            else
216
            {
217
                medDebug( 1, "got incomplete MediatorMessage: { %d, %d, %*s }\n",
218
                          nHeader[0], nHeader[1], nHeader[1], pBuffer );
219
                bRun = false;
220
            }
221
            delete [] pBuffer;
222
        }
223
        else
224
        {
225
            medDebug( 1, "got incomplete message header of %d bytes ( nHeader = [ %u, %u ] ), errno is %d\n",
226
                      nBytes, nHeader[ 0 ], nHeader[ 1 ], (int)errno );
227
            bRun = false;
228
        }
229
    }
230
}
231
232
void MediatorListener::onTerminated()
233
{
234
    if( m_pMediator )
235
	{
236
		m_pMediator->m_aConnectionLostHdl.Call( m_pMediator );
237
		m_pMediator->m_pListener = NULL;
238
	}
239
    delete this;
240
}
241
242
sal_uLong MediatorMessage::ExtractULONG()
243
{
244
	if( ! m_pRun )
245
		m_pRun = m_pBytes;
246
247
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::ExtractULONG\n" );
248
	sal_uLong nCount;
249
	memcpy( &nCount, m_pRun, sizeof( sal_uLong ) );
250
	m_pRun += sizeof( sal_uLong );
251
	return nCount;
252
}
253
254
void* MediatorMessage::GetBytes( sal_uLong& rBytes )
255
{
256
	if( ! m_pRun )
257
		m_pRun = m_pBytes;
258
259
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetBytes\n" );
260
	sal_uLong nBytes = ExtractULONG();
261
262
	if( nBytes == 0 )
263
		return NULL;
264
265
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetBytes\n" );
266
	char* pBuffer = new char[ nBytes ];
267
	memcpy( pBuffer, m_pRun, nBytes );
268
	m_pRun += nBytes;
269
	rBytes = nBytes;
270
	return pBuffer;
271
}
272
273
char* MediatorMessage::GetString()
274
{
275
	if( ! m_pRun )
276
		m_pRun = m_pBytes;
277
278
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetString\n" );
279
	sal_uLong nBytes = ExtractULONG();
280
281
	if( nBytes == 0 )
282
		return NULL;
283
284
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetString\n" );
285
	char* pBuffer = new char[ nBytes+1 ];
286
	memcpy( pBuffer, m_pRun, nBytes );
287
	pBuffer[ nBytes ] = 0;
288
	m_pRun += nBytes;
289
	return pBuffer;
290
}
291
292
sal_uInt32 MediatorMessage::GetUINT32()
293
{
294
	if( ! m_pRun )
295
		m_pRun = m_pBytes;
296
297
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetUINT32\n" );
298
	sal_uLong nBytes = ExtractULONG();
299
	medDebug( nBytes != sizeof( sal_uInt32 ), "No sal_uInt32 in MediatorMessage::GetUINT32\n" );
300
	medDebug( (sal_uLong)(m_pRun - m_pBytes) >= m_nBytes, "Overflow in MediatorMessage::GetUINT32\n" );
301
	sal_uInt32 nRet;
302
	memcpy( &nRet, m_pRun, sizeof( nRet ) );
303
	m_pRun += sizeof( sal_uInt32 );
304
	return nRet;
305
}
(-)a/main/extensions/source/plugin/unx/npnapi.cxx (+913 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <plugin/unx/plugcon.hxx>
27
28
#include <unistd.h>
29
#include <dlfcn.h>
30
31
#include <osl/module.h>
32
33
extern PluginConnector* pConnector;
34
extern XtAppContext app_context;
35
extern int wakeup_fd[];
36
extern Widget topLevel, topBox;
37
extern Display* pAppDisplay;
38
extern Display* pXtAppDisplay;
39
extern int nAppArguments;
40
extern char** pAppArguments;
41
42
void* CreateNewShell( void**, XLIB_Window );
43
44
// begin Netscape plugin api calls
45
extern "C" {
46
47
static void* l_NPN_MemAlloc( uint32 nBytes )
48
{
49
	void* pMem = new char[nBytes];
50
    return pMem;
51
}
52
    
53
static void l_NPN_MemFree( void* pMem )
54
{
55
    delete [] (char*)pMem;
56
}
57
    
58
static uint32 l_NPN_MemFlush( uint32 /*nSize*/ )
59
{
60
    return 0;
61
}
62
63
static NPError l_NPN_DestroyStream( NPP instance, NPStream* stream, NPError reason )
64
{
65
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
66
    if( nInstance == PluginConnector::UnknownNPPID )
67
        return NPERR_GENERIC_ERROR;
68
    
69
	sal_uInt32 nFileID = pConnector->GetStreamID( stream );
70
	MediatorMessage* pMes=
71
		pConnector->
72
		Transact( eNPN_DestroyStream,
73
				  &nInstance, sizeof( nInstance ),
74
				  &nFileID, sizeof( nFileID ),
75
				  POST_STRING( stream->url ),
76
				  &reason, sizeof( reason ),
77
				  NULL );
78
79
	if( ! pMes )
80
		return NPERR_GENERIC_ERROR;
81
82
    for( std::vector< NPStream* >::iterator it = pConnector->getStreamList().begin();
83
         it != pConnector->getStreamList().end(); ++it )
84
    {
85
        if( *it == stream )
86
        {
87
            pConnector->getStreamList().erase( it );
88
            break;
89
        }
90
    }
91
	delete [] stream->url;
92
	delete stream;
93
	// returns NPError
94
	NPError aRet = pConnector->GetNPError( pMes );
95
	delete pMes;
96
	return aRet;
97
}
98
99
#ifdef OJI
100
static JRIEnv* l_NPN_GetJavaEnv()
101
{
102
	// no java in this program
103
    medDebug( 1, "SNI: NPN_GetJavaEnv\n" );
104
	return NULL;
105
}
106
107
static jref l_NPN_GetJavaPeer( NPP /*instance*/ )
108
{
109
    medDebug( 1, "SNI: NPN_GetJavaPeer\n" );
110
	return NULL;
111
}
112
#endif
113
114
static NPError l_NPN_GetURL( NPP instance, const char* url, const char* window )
115
{
116
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
117
    if( nInstance == PluginConnector::UnknownNPPID )
118
        return NPERR_GENERIC_ERROR;
119
    
120
	MediatorMessage* pMes=
121
		pConnector->
122
		Transact( eNPN_GetURL,
123
				  &nInstance, sizeof( nInstance ),
124
				  POST_STRING(url),
125
				  POST_STRING(window),
126
				  NULL );	
127
    medDebug( !pMes, "geturl: message unaswered\n" );
128
	if( ! pMes )
129
		return NPERR_GENERIC_ERROR;
130
131
	// returns NPError
132
	NPError aRet = pConnector->GetNPError( pMes );
133
    medDebug( aRet, "geturl returns %d\n", (int)aRet );
134
	delete pMes;
135
	return aRet;
136
}
137
138
static NPError l_NPN_GetURLNotify( NPP instance, const char* url, const char* target,
139
                            void* notifyData )
140
{
141
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
142
    if( nInstance == PluginConnector::UnknownNPPID )
143
        return NPERR_GENERIC_ERROR;
144
145
	MediatorMessage* pMes=
146
		pConnector->
147
		Transact( eNPN_GetURLNotify,
148
				  &nInstance, sizeof( nInstance ),
149
				  POST_STRING(url),
150
				  POST_STRING(target),
151
				  &notifyData, sizeof( void* ), // transmit the actual pointer
152
				  // since it is a pointer to private data fed back
153
				  // by NPP_URLNotify; this can be thought of as an ID
154
				  NULL );
155
	if( ! pMes )
156
		return NPERR_GENERIC_ERROR;
157
158
	// returns NPError
159
	NPError aRet = pConnector->GetNPError( pMes );
160
	delete pMes;
161
	return aRet;
162
}
163
164
static NPError l_NPN_NewStream( NPP instance, NPMIMEType type, const char* target,
165
                         NPStream** stream )
166
    // stream is a return value
167
{
168
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
169
    if( nInstance == PluginConnector::UnknownNPPID )
170
        return NPERR_GENERIC_ERROR;
171
172
	MediatorMessage* pMes=
173
		pConnector->
174
		Transact( eNPN_NewStream,
175
				  &nInstance, sizeof( nInstance ),
176
				  POST_STRING(type),
177
				  POST_STRING(target),
178
				  NULL );
179
	if( ! pMes )
180
		return NPERR_GENERIC_ERROR;
181
182
	// returns a new NPStream and an error
183
	NPError aRet = pConnector->GetNPError( pMes );
184
	if( ! aRet )
185
	{
186
		NPStream* pStream = new NPStream;
187
		pStream->url = pMes->GetString();
188
		pStream->end = pMes->GetUINT32();
189
		pStream->lastmodified = pMes->GetUINT32();
190
        pStream->ndata = pStream->pdata = pStream->notifyData = NULL;
191
        
192
		pConnector->getStreamList().push_back( pStream );
193
		*stream = pStream;
194
	}
195
196
	delete pMes;
197
	return aRet;
198
}
199
200
static NPError l_NPN_PostURLNotify( NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData )
201
{
202
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
203
    if( nInstance == PluginConnector::UnknownNPPID )
204
        return NPERR_GENERIC_ERROR;
205
206
	MediatorMessage* pMes = pConnector->
207
		Transact( eNPN_PostURLNotify,
208
				  &nInstance, sizeof( nInstance ),
209
				  POST_STRING( url ),
210
				  POST_STRING( target ),
211
				  &len, sizeof( len ),
212
				  buf, len,
213
				  &file, sizeof( NPBool ),
214
				  &notifyData, sizeof( void* ), // send the real pointer
215
				  NULL );
216
217
	if( ! pMes )
218
		return NPERR_GENERIC_ERROR;
219
220
	NPError aRet = pConnector->GetNPError( pMes );
221
	delete pMes;
222
	return aRet;
223
}
224
225
static NPError l_NPN_PostURL( NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file )
226
{
227
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
228
    if( nInstance == PluginConnector::UnknownNPPID )
229
        return NPERR_GENERIC_ERROR;
230
231
	MediatorMessage* pMes = pConnector->
232
		Transact( eNPN_PostURL,
233
				  &nInstance, sizeof( nInstance ),
234
				  POST_STRING( url ),
235
				  POST_STRING( window ),
236
				  &len, sizeof( len ),
237
				  buf, len,
238
				  &file, sizeof( NPBool ),
239
				  NULL );
240
	if( ! pMes )
241
		return NPERR_GENERIC_ERROR;
242
243
	NPError aRet = pConnector->GetNPError( pMes );
244
	delete pMes;
245
	return aRet;
246
}
247
248
static NPError l_NPN_RequestRead( NPStream* stream, NPByteRange* rangeList )
249
{
250
    medDebug( 1, "pluginapp: NPN_RequestRead\n" );
251
252
	NPByteRange* pRange = rangeList;
253
	sal_uInt32 nRanges = 0;
254
	while( pRange )
255
	{
256
		nRanges++;
257
		pRange = pRange->next;
258
	}
259
	
260
	sal_uInt32* pArray = new sal_uInt32[ 2 * nRanges ];
261
	pRange = rangeList;
262
	sal_uInt32 n = 0;
263
	while( pRange )
264
	{
265
		pArray[ 2*n    ] = (sal_uInt32)pRange->offset;
266
		pArray[ 2*n + 1] = (sal_uInt32)pRange->length;
267
		n++;
268
		pRange = pRange->next;
269
	}
270
	sal_uInt32 nFileID = pConnector->GetStreamID( stream );
271
	MediatorMessage* pMes = pConnector->
272
		Transact( eNPN_RequestRead,
273
				  &nFileID, sizeof( nFileID ),
274
				  &nRanges, sizeof( nRanges ),
275
				  pArray, sizeof( sal_uInt32 ) * 2 * nRanges,
276
				  NULL );
277
278
	if( ! pMes )
279
		return NPERR_GENERIC_ERROR;
280
281
	NPError aRet = pConnector->GetNPError( pMes );
282
	delete [] pArray;
283
	delete pMes;
284
	return aRet;
285
}
286
287
static void l_NPN_Status( NPP instance, const char* message )
288
{
289
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
290
    if( nInstance == PluginConnector::UnknownNPPID )
291
        return;
292
293
	pConnector->Send( eNPN_Status,
294
					  &nInstance, sizeof( nInstance ),
295
					  POST_STRING( message ),
296
					  NULL ); 
297
}
298
299
static const char* l_NPN_UserAgent( NPP instance )
300
{
301
	static char* pAgent = NULL;
302
303
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
304
    if( nInstance == PluginConnector::UnknownNPPID )
305
    {
306
        if( instance )
307
            return "Mozilla 3.0";
308
        else // e.g. flashplayer calls NPN_UserAgent with NULL
309
            nInstance = 0;
310
    }
311
312
	MediatorMessage* pMes = pConnector->
313
		Transact( eNPN_UserAgent,
314
				  &nInstance, sizeof( nInstance ),
315
				  NULL );
316
317
	if( ! pMes )
318
		return pAgent;
319
320
	if( pAgent )
321
		delete [] pAgent;
322
	pAgent = pMes->GetString();
323
324
	delete pMes;
325
326
    medDebug( 1, "NPN_UserAgent returns %s\n", pAgent );
327
328
	return pAgent;
329
}
330
331
#if 0
332
static void l_NPN_Version( int* major, int* minor, int* net_major, int* net_minor )
333
{
334
	MediatorMessage* pMes = pConnector->
335
		Transact( eNPN_Version,
336
				  NULL );
337
338
	if( ! pMes )
339
		return;
340
341
	*major = pMes->GetUINT32();
342
	*minor = pMes->GetUINT32();
343
	*net_major = pMes->GetUINT32();
344
	*net_minor = pMes->GetUINT32();
345
346
    medDebug( 1, "pluginapp: NPN_Version: results %d %d, %d %d\n", *major, *minor, *net_major, *net_minor );
347
348
	delete pMes;
349
}
350
#endif
351
352
static int32 l_NPN_Write( NPP instance, NPStream* stream, int32 len, void* buffer )
353
{
354
	sal_uInt32 nFileID = pConnector->GetStreamID( stream );
355
    if( nFileID == PluginConnector::UnknownStreamID )
356
        return NPERR_GENERIC_ERROR;
357
	sal_uInt32 nInstance = pConnector->GetNPPID( instance );
358
    if( nInstance == PluginConnector::UnknownNPPID )
359
        return NPERR_GENERIC_ERROR;
360
361
	MediatorMessage* pMes = pConnector->
362
		Transact( eNPN_Write,
363
				  &nInstance, sizeof( nInstance ),
364
				  &nFileID, sizeof( nFileID ),
365
				  &len, sizeof( len ),
366
				  buffer, len,
367
				  NULL );
368
369
	if( ! pMes )
370
		return 0;
371
372
	sal_Int32 nRet = pMes->GetUINT32();
373
	return nRet;  
374
}
375
376
static void l_NPN_ReloadPlugins( NPBool /*reloadPages*/ )
377
{
378
	medDebug( 1, "NPN_ReloadPlugins: SNI\n" );
379
}
380
381
static NPError l_NPN_GetValue( NPP, NPNVariable variable, void* value )
382
{
383
	/*
384
	 * We want to handle values injected into a NPNVariable which aren't in
385
	 * the old enum we build against, but that we know are in the new enum
386
	 * we want to support
387
         */
388
	switch( (int)variable )
389
	{
390
        case NPNVxDisplay:
391
            *((Display**)value) = pXtAppDisplay;
392
			medDebug( 1, "Display requested\n" );
393
            break;
394
        case NPNVxtAppContext:
395
            *((XtAppContext*)value) = app_context;
396
			medDebug( 1, "AppContext requested\n" );
397
            break;
398
        case NPNVjavascriptEnabledBool:
399
            // no javascript
400
            *(NPBool*)value = false;
401
			medDebug( 1, "javascript enabled requested\n" );
402
            break;
403
        case NPNVasdEnabledBool:
404
            // no SmartUpdate
405
            *(NPBool*)value = false;
406
			medDebug( 1, "smart update enabled requested\n" );
407
            break;
408
        case NPNVisOfflineBool:
409
            // no offline browsing
410
            *(NPBool*)value = false;
411
			medDebug( 1, "offline browsing requested\n" );
412
            break;
413
        case NPNVSupportsXEmbedBool:
414
            // asking xembed
415
            *(int*)value = true;
416
			medDebug( 1, "xembed requested\n" );
417
            break;
418
        case NPNVToolkit:
419
#           ifdef ENABLE_GTK
420
            *(int*)value = NPNVGtk2;
421
#           else
422
            *(int*)value = 0;
423
#           endif
424
			medDebug( 1, "toolkit requested\n" );
425
            break;
426
        default:
427
			medDebug( 1, "unknown NPNVariable %x requested\n", variable );
428
            return NPERR_INVALID_PARAM;
429
	}
430
	return NPERR_NO_ERROR;
431
}
432
433
static NPError l_NPN_SetValue(NPP /*instance*/, NPPVariable variable, void *value)
434
{
435
    medDebug( 1, "NPN_SetValue %d=%p\n", variable, value );
436
	return 0;
437
}
438
439
static void l_NPN_InvalidateRect(NPP /*instance*/, NPRect* /*invalidRect*/)
440
{
441
    medDebug( 1, "NPN_InvalidateRect\n" );
442
}
443
444
static void l_NPN_InvalidateRegion(NPP /*instance*/, NPRegion /*invalidRegion*/)
445
{
446
    medDebug( 1, "NPN_InvalidateRegion\n" );
447
}
448
449
static void l_NPN_ForceRedraw(NPP /*instance*/)
450
{
451
    medDebug( 1, "NPN_ForceRedraw\n" );
452
}
453
454
}
455
456
static NPNetscapeFuncs aNetscapeFuncs =
457
{
458
	sizeof(aNetscapeFuncs),
459
	(NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR,
460
	l_NPN_GetURL,
461
	l_NPN_PostURL,
462
	l_NPN_RequestRead,
463
	l_NPN_NewStream,
464
	l_NPN_Write,
465
	l_NPN_DestroyStream,
466
	l_NPN_Status,
467
	l_NPN_UserAgent,
468
	l_NPN_MemAlloc,
469
	l_NPN_MemFree,
470
	l_NPN_MemFlush,
471
	l_NPN_ReloadPlugins,
472
#   ifdef OJI
473
	l_NPN_GetJavaEnv,
474
	l_NPN_GetJavaPeer,
475
#   else
476
    NULL,
477
    NULL,
478
#   endif
479
	l_NPN_GetURLNotify,
480
	l_NPN_PostURLNotify,
481
	l_NPN_GetValue,
482
	l_NPN_SetValue,
483
	l_NPN_InvalidateRect,
484
	l_NPN_InvalidateRegion,
485
	l_NPN_ForceRedraw
486
};
487
488
static NPPluginFuncs aPluginFuncs =
489
{
490
	sizeof(aPluginFuncs),
491
	(NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR,
492
    NULL,
493
    NULL,
494
    NULL,
495
    NULL,
496
    NULL,
497
    NULL,
498
    NULL,
499
    NULL,
500
    NULL,
501
    NULL,
502
    NULL,
503
    NULL,
504
    NULL,
505
    NULL
506
};
507
508
509
oslModule pPluginLib = NULL;
510
char*(*pNPP_GetMIMEDescription)()								= NULL;
511
NPError (*pNP_Initialize)(NPNetscapeFuncs*,NPPluginFuncs*)		= NULL;
512
NPError (*pNP_Shutdown)()										= NULL;
513
514
std::vector< PluginConnector* > PluginConnector::allConnectors;
515
516
PluginConnector::PluginConnector( int nSocket ) :
517
		Mediator( nSocket )
518
{
519
	SetNewMessageHdl( LINK( this, PluginConnector, NewMessageHdl ) );
520
}
521
522
PluginConnector::~PluginConnector()
523
{
524
}
525
526
IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ )
527
{
528
	MediatorMessage* pMessage;
529
	CommandAtoms nCommand;
530
	while( (pMessage = GetNextMessage( sal_False )) )
531
	{
532
		nCommand = (CommandAtoms)pMessage->GetUINT32();
533
		medDebug( 1, "pluginapp: %s\n", GetCommandName( nCommand ) );
534
		switch( nCommand )
535
		{
536
			case eNPP_DestroyStream:
537
			{
538
				sal_uInt32 nInstance	= pMessage->GetUINT32();
539
				NPP instance		= m_aInstances[ nInstance ]->instance;
540
				sal_uInt32 nFileID		= pMessage->GetUINT32();
541
				NPStream* pStream	= m_aNPWrapStreams[ nFileID ];
542
				NPError aReason		= GetNPError( pMessage );
543
                m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID );
544
545
				aReason = aPluginFuncs.destroystream( instance, pStream, aReason );
546
				Respond( pMessage->m_nID,
547
						 (char*)&aReason, sizeof( aReason ),
548
						 NULL );
549
550
                delete [] pStream->url;
551
                delete pStream;
552
			}
553
			break;
554
			case eNPP_Destroy:
555
			{
556
				sal_uInt32 nInstance	= pMessage->GetUINT32();
557
				ConnectorInstance* pInst= m_aInstances[ nInstance ];
558
559
                // some plugin rely on old netscapes behaviour
560
                // to first destroy the widget and then destroy
561
                // the instance, so mimic that behaviour here
562
                if( pInst->pShell )
563
                    XtDestroyWidget( (Widget)pInst->pShell );
564
                
565
                pInst->pWidget = pInst->pShell = NULL;
566
                
567
                // the other side will call eNPP_DestroyPhase2 after this
568
                NPError aReason = NPERR_NO_ERROR;
569
                Respond( pMessage->m_nID, (char*)&aReason, sizeof( aReason ), NULL );
570
            }
571
            break;
572
            case eNPP_DestroyPhase2:
573
            {
574
                // now really destroy the instance
575
				sal_uInt32 nInstance	= pMessage->GetUINT32();
576
				ConnectorInstance* pInst= m_aInstances[ nInstance ];
577
				NPP instance		= pInst->instance;
578
				NPSavedData* pSave = NULL;
579
580
				NPError aRet = aPluginFuncs.destroy( instance, &pSave );
581
				if( pSave )
582
                {
583
					Respond( pMessage->m_nID,
584
							 (char*)&aRet, sizeof( aRet ),
585
							 pSave->buf, pSave->len,
586
							 NULL );
587
                    delete [] (char*)pSave->buf;
588
                }
589
				else
590
					Respond( pMessage->m_nID,
591
							 (char*)&aRet, sizeof( aRet ),
592
							 "0000", 4,
593
							 NULL );
594
595
                #ifdef ENABLE_GTK
596
                if( pInst->pGtkWindow )
597
                    g_object_unref( G_OBJECT(pInst->pGtkWindow) );
598
                if( pInst->pGtkWidget )
599
                    g_object_unref( G_OBJECT(pInst->pGtkWidget) );
600
                #endif
601
602
				m_aInstances.erase( m_aInstances.begin() + nInstance );
603
                delete pInst;
604
				delete instance;
605
                medDebug( 1, "destroyed instance (returning %d)\n", aRet );
606
			}
607
			break;
608
			case eNPP_NewStream:
609
			{
610
				sal_uInt32 nInstance		= pMessage->GetUINT32();
611
				NPP instance			= m_aInstances[ nInstance ]->instance;
612
				char* pType				= pMessage->GetString();
613
				NPStream* pStream		= new NPStream;
614
				pStream->url			= pMessage->GetString();
615
				pStream->end			= pMessage->GetUINT32();
616
				pStream->lastmodified	= pMessage->GetUINT32();
617
                pStream->pdata = pStream->ndata = pStream->notifyData = NULL;
618
				NPBool* pSeekable		= (NPBool*)pMessage->GetBytes();
619
				m_aNPWrapStreams.push_back( pStream );
620
				uint16 nStype = NP_ASFILE;
621
				NPError aRet = aPluginFuncs.newstream( instance, pType, pStream,
622
                                                       *pSeekable, &nStype );
623
				medDebug( 1, "pluginapp: NPP_NewStream( %p, %s, %p, %s, %p ) returns %d\n"
624
                          "stream = { pdata = %p, ndata = %p, url = %s, end = %d, lastmodified = %d, notifyData = %p }\n",
625
                          instance, pType, pStream, *pSeekable ? "seekable" : "not seekable", &nStype, (int)aRet,
626
                          pStream->pdata, pStream->ndata, pStream->url, pStream->end, pStream->lastmodified, pStream->notifyData );
627
				Respond( pMessage->m_nID,
628
						 (char*)&aRet, sizeof( aRet ),
629
						 &nStype, sizeof( nStype ),
630
						 NULL );
631
				delete [] pType;
632
                delete [] pSeekable;
633
			}
634
			break;
635
			case eNPP_New:
636
			{
637
				char* pType		= pMessage->GetString();
638
				uint16* pMode	= (uint16*)pMessage->GetBytes();
639
				int16*  pArgc	= (int16*)pMessage->GetBytes();
640
				NPP instance	= new NPP_t;
641
				instance->pdata = instance->ndata = NULL;
642
				sal_uLong nArgnBytes, nArgvBytes;
643
				char* pArgn = (char*)pMessage->GetBytes( nArgnBytes );
644
				char* pArgv = (char*)pMessage->GetBytes( nArgvBytes );
645
				sal_uLong nSaveBytes;
646
				char* pSavedData = (char*)pMessage->GetBytes( nSaveBytes );
647
				ConnectorInstance* pInst =
648
					new ConnectorInstance( instance, pType,
649
										   *pArgc,
650
										   pArgn, nArgnBytes,
651
										   pArgv, nArgvBytes,
652
										   pSavedData, nSaveBytes );
653
				m_aInstances.push_back( pInst );
654
				NPError aRet;
655
				aRet = aPluginFuncs.newp( pInst->pMimeType, instance, *pMode, *pArgc,
656
                                          pInst->nArg ? pInst->argn : NULL,
657
                                          pInst->nArg ? pInst->argv : NULL,
658
                                          ( nSaveBytes == 4 && *(sal_uInt32*)pSavedData == 0 ) ?
659
                                          &(pInst->aData) : NULL );
660
				medDebug( 1, "pluginapp: NPP_New( %s, %p, %d, %d, %p, %p, %p ) returns %d\n",
661
                          pInst->pMimeType,
662
                          instance, *pMode, pInst->nArg, pInst->argn, pInst->argv, &pInst->aData,
663
                          (int) aRet );
664
#if OSL_DEBUG_LEVEL > 1
665
                for( int i = 0; i < pInst->nArg; i++ )
666
                    medDebug( 1, "   \"%s\"=\"%s\"\n", pInst->argn[i], pInst->argv[i] );
667
#endif
668
669
                #ifdef ENABLE_GTK
670
                // check if XEMBED is to be used
671
                // ask for Bool. there seems to be no clear definition whether the
672
                // return value should be an int or unsigned char
673
                // int can hold both and will be nonzero in case of "true"
674
                if( aPluginFuncs.getvalue )
675
                {
676
                    int bNeedsXEmbed = 0;
677
                    NPError error = aPluginFuncs.getvalue( instance, NPPVpluginNeedsXEmbed, (void *)&bNeedsXEmbed );
678
                    if( error == NPERR_NO_ERROR )
679
                        pInst->bShouldUseXEmbed = (bNeedsXEmbed != 0);
680
                    medDebug( 1, "should use xembed = %s\n", pInst->bShouldUseXEmbed ? "true" : "false" );
681
                }
682
                #endif
683
                
684
				Respond( pMessage->m_nID,
685
						 (char*)&aRet, sizeof( aRet ),
686
						 NULL );
687
				delete [] pMode;
688
				delete [] pArgc;
689
				delete [] pType;
690
			}
691
			break;
692
			case eNPP_SetWindow:
693
			{
694
				sal_uInt32 nInstance		= pMessage->GetUINT32();
695
				ConnectorInstance* pInst= m_aInstances[ nInstance ];
696
				NPWindow* pWindow		= (NPWindow*)pMessage->GetBytes();
697
                
698
                if( pWindow->width < 1 )
699
                    pWindow->width = 1;
700
                if( pWindow->height < 1 )
701
                    pWindow->height = 1;
702
703
                #ifdef ENABLE_GTK
704
                if( pInst->bShouldUseXEmbed )
705
                {
706
                    if( ! pInst->pGtkWidget )
707
                    {
708
                        medDebug( 1, "creating gtk plug and socket\n" );
709
                        
710
                        pInst->pGtkWindow = gtk_plug_new((GdkNativeWindow)reinterpret_cast<sal_uIntPtr>(pWindow->window));
711
                        gtk_widget_show( pInst->pGtkWindow );
712
                        pInst->pGtkWidget = gtk_socket_new();
713
                        gtk_widget_show( pInst->pGtkWidget );
714
                        gtk_container_add( GTK_CONTAINER(pInst->pGtkWindow), pInst->pGtkWidget );
715
                        gtk_widget_show_all( pInst->pGtkWindow );
716
                        pInst->window.window = (void *)gtk_socket_get_id( GTK_SOCKET(pInst->pGtkWidget ) );
717
718
                        XSync( pAppDisplay, False );
719
720
                        XMapWindow( pAppDisplay, GDK_WINDOW_XWINDOW(pInst->pGtkWindow->window) );
721
722
                        XSync( pAppDisplay, False );
723
                    }
724
                    
725
                    // update widget size; alas out parent is not yet really XEMBED conformant
726
                    gtk_widget_set_size_request( pInst->pGtkWidget, pWindow->width, pWindow->height );
727
                    gtk_window_resize( GTK_WINDOW(pInst->pGtkWindow), pWindow->width, pWindow->height );
728
                    
729
                    GdkScreen* pGdkScreen = gtk_widget_get_screen( pInst->pGtkWidget );
730
                    Screen* pScreen = ScreenOfDisplay( pAppDisplay, gdk_screen_get_number( pGdkScreen ) );
731
732
                    pInst->window.x					= 0;
733
                    pInst->window.y					= 0;
734
                    pInst->window.width				= pWindow->width;
735
                    pInst->window.height			= pWindow->height;
736
                    pInst->window.clipRect.left		= 0;
737
                    pInst->window.clipRect.top		= 0;
738
                    pInst->window.clipRect.right	= pWindow->width;
739
                    pInst->window.clipRect.bottom	= pWindow->height;
740
                    pInst->window.ws_info			= &pInst->ws_info;
741
                    pInst->window.type				= NPWindowTypeWindow;
742
                    pInst->ws_info.type				= NP_SETWINDOW;
743
                    pInst->ws_info.display			= pAppDisplay;
744
                    pInst->ws_info.visual			= DefaultVisualOfScreen( pScreen );
745
                    pInst->ws_info.colormap			= DefaultColormapOfScreen( pScreen );
746
                    pInst->ws_info.depth			= DefaultDepthOfScreen( pScreen );
747
                }
748
                else
749
                #endif
750
                {
751
                    if( ! pInst->pWidget )
752
                    {
753
                        pInst->pWidget = CreateNewShell( &(pInst->pShell), (XLIB_Window)pWindow->window );					
754
                    }
755
    
756
                    // fill in NPWindow and NPCallbackStruct
757
                    pInst->window.window			= (void*)XtWindow( (Widget)pInst->pWidget );
758
                    pInst->window.x					= 0;
759
                    pInst->window.y					= 0;
760
                    pInst->window.width				= pWindow->width;
761
                    pInst->window.height			= pWindow->height;
762
                    pInst->window.clipRect.left		= 0;
763
                    pInst->window.clipRect.top		= 0;
764
                    pInst->window.clipRect.right	= pWindow->width;
765
                    pInst->window.clipRect.bottom	= pWindow->height;
766
                    pInst->window.ws_info			= &pInst->ws_info;
767
                    pInst->window.type				= NPWindowTypeWindow;
768
                    pInst->ws_info.type				= NP_SETWINDOW;
769
                    pInst->ws_info.display			= XtDisplay( (Widget)pInst->pWidget );
770
                    pInst->ws_info.visual			= DefaultVisualOfScreen( XtScreen( (Widget)pInst->pWidget ) );
771
                    pInst->ws_info.colormap			= DefaultColormapOfScreen( XtScreen( (Widget)pInst->pWidget ) );
772
                    pInst->ws_info.depth			= DefaultDepthOfScreen( XtScreen( (Widget)pInst->pWidget ) );
773
    
774
                    XtResizeWidget( (Widget)pInst->pShell,
775
                                    pInst->window.width,
776
                                    pInst->window.height,
777
                                    0 );
778
                    XtResizeWidget( (Widget)pInst->pWidget,
779
                                    pInst->window.width,
780
                                    pInst->window.height,
781
                                    0 );
782
                }
783
784
				NPError aRet = aPluginFuncs.setwindow( pInst->instance, &pInst->window );
785
				medDebug( 1, "pluginapp: NPP_SetWindow returns %d\n", (int) aRet );
786
				Respond( pMessage->m_nID,
787
						 (char*)&aRet, sizeof( aRet ),
788
						 NULL );
789
				delete [] (char*)pWindow;
790
			}
791
			break;
792
			case eNPP_StreamAsFile:
793
			{
794
				sal_uInt32 nInstance		= pMessage->GetUINT32();
795
				NPP instance			= m_aInstances[ nInstance ]->instance;
796
				sal_uInt32 nFileID			= pMessage->GetUINT32();
797
				NPStream* pStream		= m_aNPWrapStreams[ nFileID ];
798
				char* fname				= pMessage->GetString();
799
				medDebug( 1, "pluginapp: NPP_StreamAsFile %s\n", fname );
800
				aPluginFuncs.asfile( instance, pStream, fname );
801
				delete [] fname;
802
			}
803
			break;
804
			case eNPP_URLNotify:
805
			{
806
				sal_uInt32 nInstance		= pMessage->GetUINT32();
807
				NPP instance			= m_aInstances[ nInstance ]->instance;
808
				char* url				= pMessage->GetString();
809
				NPReason* pReason		= (NPReason*)pMessage->GetBytes();
810
				void** notifyData		= (void**)pMessage->GetBytes();
811
				aPluginFuncs.urlnotify( instance, url, *pReason, *notifyData );
812
				delete [] url;
813
				delete [] pReason;
814
				delete [] notifyData;
815
			}
816
			break;
817
			case eNPP_WriteReady:
818
			{
819
				sal_uInt32 nInstance		= pMessage->GetUINT32();
820
				NPP instance			= m_aInstances[ nInstance ]->instance;
821
				sal_uInt32 nFileID			= pMessage->GetUINT32();
822
				NPStream* pStream		= m_aNPWrapStreams[ nFileID ];
823
				int32 nRet = aPluginFuncs.writeready( instance, pStream );
824
                
825
                medDebug( 1, "pluginapp: NPP_WriteReady( %p, %p ) (stream id = %d) returns %d\n",
826
                          instance, pStream, nFileID, nRet );
827
                
828
				Respond( pMessage->m_nID,
829
						 (char*)&nRet, sizeof( nRet ),
830
						 NULL );
831
			}
832
			break;
833
			case eNPP_Write:
834
			{
835
				sal_uInt32 nInstance		= pMessage->GetUINT32();
836
				NPP instance			= m_aInstances[ nInstance ]->instance;
837
				sal_uInt32 nFileID			= pMessage->GetUINT32();
838
				NPStream* pStream		= m_aNPWrapStreams[ nFileID ];
839
				int32 offset			= pMessage->GetUINT32();
840
				sal_uLong len;
841
				char* buffer			= (char*)pMessage->GetBytes( len );
842
				int32 nRet = aPluginFuncs.write( instance, pStream, offset, len, buffer );
843
                
844
                medDebug( 1,"pluginapp: NPP_Write( %p, %p, %d, %d, %p ) returns %d\n"
845
                          "stream = { pdata = %p, ndata = %p, url = %s, end = %d, lastmodified = %d, notifyData = %p }\n",
846
                          instance, pStream, offset, len, buffer, nRet,
847
                          pStream->pdata, pStream->ndata, pStream->url, pStream->end, pStream->lastmodified, pStream->notifyData );
848
849
				Respond( pMessage->m_nID,
850
						 (char*)&nRet, sizeof( nRet ),
851
						 NULL );
852
				delete [] buffer;
853
			}
854
			break;
855
			case eNPP_GetMIMEDescription:
856
			{
857
				if( ! pNPP_GetMIMEDescription )
858
					pNPP_GetMIMEDescription = (char*(*)())
859
                        osl_getAsciiFunctionSymbol( pPluginLib, "NPP_GetMIMEDescription" );
860
				char* pMIME = pNPP_GetMIMEDescription();
861
				Respond( pMessage->m_nID,
862
						 POST_STRING( pMIME ),
863
						 NULL );
864
			}
865
			break;
866
			case eNPP_Initialize:
867
			{
868
869
				pNP_Initialize =
870
					(NPError(*)(NPNetscapeFuncs*, NPPluginFuncs*))
871
					osl_getAsciiFunctionSymbol( pPluginLib, "NP_Initialize" );
872
                medDebug( !pNP_Initialize, "no NP_Initialize, %s\n", dlerror() );
873
                pNP_Shutdown = (NPError(*)())
874
                    osl_getAsciiFunctionSymbol( pPluginLib, "NP_Shutdown" );
875
                medDebug( !pNP_Initialize, "no NP_Shutdown, %s\n", dlerror() );
876
877
                medDebug( 1, "entering NP_Initialize\n" );
878
				NPError aRet = pNP_Initialize( &aNetscapeFuncs, &aPluginFuncs );
879
				medDebug( 1, "pluginapp: NP_Initialize returns %d\n", (int) aRet );
880
				Respond( pMessage->m_nID, (char*)&aRet, sizeof( aRet ), NULL );
881
			}
882
			break;
883
			case eNPP_Shutdown:
884
			{
885
                write( wakeup_fd[1], "xxxx", 4 );
886
			}
887
			break;
888
			default:
889
				medDebug( 1, "caught unknown NPP request %d\n", nCommand );
890
                break;
891
		}
892
		delete pMessage;
893
	}
894
	return 0;
895
}
896
897
void LoadAdditionalLibs( const char* _pPluginLib )
898
{
899
    medDebug( 1, "LoadAdditionalLibs %s\n", _pPluginLib );
900
901
    if( ! strncmp( _pPluginLib, "libflashplayer.so", 17 ) )
902
    {
903
        /*  #b4951312# flash 7 implicitly assumes a gtk application
904
         *  if the API version is greater or equal to 12 (probably
905
         *  because they think they run in mozilla then). In that
906
         *  case they try to find gtk within the process and crash
907
         *  when they don't find it.
908
         */
909
        aNetscapeFuncs.version = 11;
910
        aPluginFuncs.version = 11;
911
    }
912
}
913
(-)a/main/extensions/source/plugin/unx/nppapi.cxx (+617 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#if STLPORT_VERSION>=321
28
#include <cstdarg>
29
#endif
30
31
#include <plugin/impl.hxx>
32
#include <vcl/svapp.hxx>
33
34
std::vector<PluginConnector*> PluginConnector::allConnectors;
35
36
PluginConnector::PluginConnector( int nSocket ) :
37
		Mediator( nSocket )
38
{
39
	allConnectors.push_back( this );
40
	SetNewMessageHdl( LINK( this, PluginConnector, NewMessageHdl ) );
41
}
42
43
PluginConnector::~PluginConnector()
44
{
45
	vos::OGuard aGuard( m_aUserEventMutex );
46
    for( std::vector< PluginConnector* >::iterator it = allConnectors.begin();
47
         it != allConnectors.end(); ++it )
48
    {
49
        if( *it == this )
50
        {
51
            allConnectors.erase( it );
52
            break;
53
        }
54
    }
55
}
56
57
IMPL_LINK( PluginConnector, NewMessageHdl, Mediator*, /*pMediator*/ )
58
{
59
	vos::OGuard aGuard( m_aUserEventMutex );
60
    bool bFound = false;
61
    for( std::vector< PluginConnector* >::iterator it = allConnectors.begin();
62
         it != allConnectors.end() && bFound == false; ++it )
63
    {
64
        if( *it == this )
65
            bFound = true;
66
    }
67
	if( ! bFound )
68
		return 0;
69
    Application::PostUserEvent( LINK( this, PluginConnector, WorkOnNewMessageHdl ) );
70
	return 0;
71
}
72
73
IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ )
74
{
75
    bool bFound = false;
76
    for( std::vector< PluginConnector* >::iterator it = allConnectors.begin();
77
         it != allConnectors.end() && bFound == false; ++it )
78
    {
79
        if( *it == this )
80
            bFound = true;
81
    }
82
	if( ! bFound )
83
		return 0;
84
/*
85
    {
86
		vos::OGuard aGuard( m_aUserEventMutex );
87
		m_aUserEventIDs.pop_front();
88
	}
89
*/
90
91
	MediatorMessage* pMessage;
92
	CommandAtoms nCommand;
93
	while( (pMessage = GetNextMessage( sal_False )) )
94
	{
95
		nCommand = (CommandAtoms)pMessage->GetUINT32();
96
		medDebug( 1, "%s\n", GetCommandName( nCommand ) );
97
		switch( nCommand )
98
		{
99
			case eNPN_GetURL:
100
			{
101
				sal_uInt32 nInstance	= pMessage->GetUINT32();
102
				NPP instance		= m_aInstances[ nInstance ]->instance;
103
				char* pUrl			= pMessage->GetString();
104
				char* pWindow		= pMessage->GetString();
105
				NPError aRet = NPN_GetURL( instance, pUrl, pWindow );
106
				Respond( pMessage->m_nID,
107
						 (char*)(&aRet), sizeof( NPError ), NULL );
108
				delete [] pUrl;
109
				delete [] pWindow;
110
			}
111
			break;
112
			case eNPN_GetURLNotify:
113
			{
114
				sal_uInt32 nInstance	= pMessage->GetUINT32();
115
				NPP instance		= m_aInstances[ nInstance ]->instance;
116
				char* pUrl			= pMessage->GetString();
117
				char* pWindow		= pMessage->GetString();
118
				void** pNotifyData	= (void**)pMessage->GetBytes();
119
				NPError aRet = NPN_GetURLNotify( instance, pUrl, pWindow,
120
												 *pNotifyData );
121
				Respond( pMessage->m_nID,
122
						 (char*)(&aRet), sizeof( NPError ), NULL );
123
				delete [] pUrl;
124
				delete [] pWindow;
125
				delete [] pNotifyData;
126
			}
127
			break;
128
			case eNPN_DestroyStream:
129
			{
130
				sal_uInt32 nInstance	= pMessage->GetUINT32();
131
				NPP instance		= m_aInstances[ nInstance ]->instance;
132
				sal_uInt32 nFileID		= pMessage->GetUINT32();
133
				char* pUrl			= pMessage->GetString();
134
				NPError* pReason	= (NPError*)pMessage->GetBytes();
135
				NPError aRet = NPERR_FILE_NOT_FOUND;
136
				if( nFileID < static_cast<sal_uInt32>(m_aNPWrapStreams.size()) )
137
				{
138
					if( ! strcmp( m_aNPWrapStreams[ nFileID ]->url, pUrl ) )
139
					{
140
						aRet =
141
							NPN_DestroyStream( instance, m_aNPWrapStreams[ nFileID ],
142
											   *pReason );
143
						m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID );
144
					}
145
					else
146
						medDebug( 1, "StreamID %d has incoherent urls %s and %s\n",
147
								  nFileID, pUrl, m_aNPWrapStreams[ nFileID ]->url );
148
				}
149
				else
150
					medDebug( 1, "Nonexistent StreamID %d\n", nFileID );
151
152
				Respond( pMessage->m_nID,
153
						 (char*)(&aRet), sizeof( NPError ), NULL );
154
155
				delete [] pUrl;
156
				delete [] pReason;
157
			}
158
			break;
159
			case eNPN_NewStream:
160
			{
161
				sal_uInt32 nInstance	= pMessage->GetUINT32();
162
				NPP instance		= m_aInstances[ nInstance ]->instance;
163
				NPMIMEType pType	= pMessage->GetString();
164
				char* pTarget		= pMessage->GetString();
165
166
				NPStream* pStream = NULL;
167
168
				NPError aRet = NPN_NewStream( instance, pType, pTarget, &pStream );
169
170
				if( aRet != NPERR_NO_ERROR )
171
				{
172
                    sal_uInt32 nDummy = 0;
173
                    Respond( pMessage->m_nID,
174
                             (char*)&aRet, sizeof( aRet ),
175
                             "", 0,
176
                             &nDummy, sizeof(sal_uInt32),
177
                             &nDummy, sizeof(sal_uInt32),
178
                             NULL );
179
				}
180
				else
181
                {
182
					m_aNPWrapStreams.push_back( pStream );
183
184
                    sal_uLong nLen = strlen( pStream->url );
185
                    Respond( pMessage->m_nID,
186
                             (char*)&aRet, sizeof( aRet ),
187
                             pStream->url, nLen,
188
                             &pStream->end, sizeof(sal_uInt32),
189
                             &pStream->lastmodified, sizeof(sal_uInt32),
190
                             NULL );
191
                }
192
                
193
				delete [] pTarget;
194
				delete [] pType;
195
			}
196
			break;
197
			case eNPN_PostURLNotify:
198
			{
199
				sal_uInt32 nInstance	= pMessage->GetUINT32();
200
				NPP instance		= m_aInstances[ nInstance ]->instance;
201
				char* pUrl		= pMessage->GetString();
202
				char* pTarget	= pMessage->GetString();
203
				sal_uInt32 nLen		= pMessage->GetUINT32();
204
				char* pBuf		= (char*)pMessage->GetBytes();
205
				NPBool* pFile	= (NPBool*)pMessage->GetBytes();
206
				void** pNData	= (void**)pMessage->GetBytes();
207
				NPError aRet =
208
					NPN_PostURLNotify( instance, pUrl, pTarget, nLen, pBuf, *pFile, *pNData );
209
				Respond( pMessage->m_nID, (char*)&aRet, sizeof( aRet ), NULL );
210
				delete [] pUrl;
211
				delete [] pTarget;
212
				delete [] pBuf;
213
				delete [] pFile;
214
				delete [] pNData;
215
			}
216
			break;
217
			case eNPN_PostURL:
218
			{
219
				sal_uInt32 nInstance	= pMessage->GetUINT32();
220
				NPP instance		= m_aInstances[ nInstance ]->instance;
221
				char* pUrl		= pMessage->GetString();
222
				char* pWindow	= pMessage->GetString();
223
				sal_uInt32 nLen		= pMessage->GetUINT32();
224
				char* pBuf		= (char*)pMessage->GetBytes();
225
				NPBool* pFile	= (NPBool*)pMessage->GetBytes();
226
				NPError aRet =
227
					NPN_PostURL( instance, pUrl, pWindow, nLen, pBuf, *pFile );
228
				Respond( pMessage->m_nID, (char*)&aRet, sizeof( aRet ), NULL );
229
				delete [] pUrl;
230
				delete [] pWindow;
231
				delete [] pBuf;
232
				delete [] pFile;
233
			}
234
			break;
235
			case eNPN_RequestRead:
236
			{
237
				sal_uInt32 nFileID		= pMessage->GetUINT32();
238
				NPStream* pStream	= m_aNPWrapStreams[ nFileID ];
239
				sal_uInt32 nRanges		= pMessage->GetUINT32();
240
				sal_uInt32* pArray		= (sal_uInt32*)pMessage->GetBytes();
241
				// build ranges table
242
				NPByteRange* pFirst = new NPByteRange;
243
				NPByteRange* pRun	= pFirst;
244
				for( sal_uInt32 n = 0; n < nRanges; n++ )
245
				{
246
					pRun->offset = pArray[ 2*n ];
247
					pRun->length = pArray[ 2*n+1 ];
248
					pRun->next = n < nRanges-1 ? new NPByteRange : NULL;
249
					pRun = pRun->next;
250
				}
251
				NPError aRet = NPN_RequestRead( pStream, pFirst );
252
				Respond( pMessage->m_nID, (char*)&aRet, sizeof( aRet ), NULL );
253
				while( pFirst )
254
				{
255
					pRun = pFirst->next;
256
					delete pFirst;
257
					pFirst = pRun;
258
				}
259
				delete [] pArray;
260
			}
261
			break;
262
			case eNPN_Status:
263
			{
264
				sal_uInt32 nInstance	= pMessage->GetUINT32();
265
				NPP instance		= m_aInstances[ nInstance ]->instance;
266
				char* pString	= pMessage->GetString();
267
				NPN_Status( instance, pString );
268
				delete [] pString;
269
			}
270
			break;
271
			case eNPN_Version:
272
			{
273
				int major, minor, net_major, net_minor;
274
				NPN_Version( &major, &minor, &net_major, &net_minor );
275
				Respond( pMessage->m_nID,
276
						 (char*)&major, sizeof( int ),
277
						 &minor, sizeof( int ),
278
						 &net_major, sizeof( int ),
279
						 &net_minor, sizeof( int ),
280
						 NULL );
281
			}
282
			break;
283
			case eNPN_Write:
284
			{
285
				sal_uInt32 nInstance	= pMessage->GetUINT32();
286
				NPP instance		= m_aInstances[ nInstance ]->instance;
287
				sal_uInt32 nFileID		= pMessage->GetUINT32();
288
				NPStream* pStream	= m_aNPWrapStreams[ nFileID ];
289
				sal_Int32 nLen			= pMessage->GetUINT32();
290
				void* pBuffer		= pMessage->GetBytes();
291
				sal_Int32 nRet = NPN_Write( instance, pStream, nLen, pBuffer );
292
				Respond( pMessage->m_nID,
293
						 (char*)&nRet, sizeof( nRet ),
294
						 NULL );
295
				delete [] (char*)pBuffer;
296
				delete instance;
297
			}
298
			break;
299
			case eNPN_UserAgent:
300
			{
301
				sal_uInt32 nInstance	= pMessage->GetUINT32();
302
				NPP instance		= m_aInstances[ nInstance ]->instance;
303
				const char* pAnswer = NPN_UserAgent( instance );
304
				Respond( pMessage->m_nID,
305
						 (char*)pAnswer, strlen( pAnswer ),
306
						 NULL );
307
			}
308
			break;
309
			default:
310
				medDebug( 1, "caught unknown NPN request %d\n", nCommand );
311
		}
312
		
313
		delete pMessage;
314
	}
315
	return 0;
316
}
317
318
#define GET_INSTANCE() \
319
	sal_uInt32 nInstance;  \
320
	nInstance = GetNPPID( instance );
321
322
#define GET_INSTANCE_RET( err ) \
323
	GET_INSTANCE() \
324
    if( nInstance == PluginConnector::UnknownNPPID ) \
325
		return err
326
327
328
#define POST_INSTANCE() (char*)&nInstance, sizeof( nInstance )
329
330
NPError UnxPluginComm::NPP_Destroy( NPP instance, NPSavedData** save )
331
{
332
	NPError aRet = NPERR_GENERIC_ERROR;
333
	GET_INSTANCE_RET( aRet );
334
	MediatorMessage* pMes = 
335
		Transact( eNPP_Destroy,
336
				  POST_INSTANCE(),
337
				  NULL );
338
	if( ! pMes )
339
		return NPERR_GENERIC_ERROR;
340
	delete pMes;
341
342
	pMes = Transact( eNPP_DestroyPhase2,
343
                     POST_INSTANCE(),
344
                     NULL );
345
	if( ! pMes )
346
		return NPERR_GENERIC_ERROR;
347
348
	aRet = GetNPError( pMes );
349
	sal_uLong nSaveBytes;
350
	void* pSaveData = pMes->GetBytes( nSaveBytes );
351
	if( nSaveBytes == 4 && *(sal_uInt32*)pSaveData == 0 )
352
		*save = NULL;
353
	else
354
	{
355
		*save = new NPSavedData;
356
		(*save)->len = nSaveBytes;
357
		(*save)->buf = pSaveData;
358
	}
359
	delete pMes;
360
361
	return aRet;
362
}
363
364
NPError UnxPluginComm::NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason )
365
{
366
	NPError aRet = NPERR_GENERIC_ERROR;
367
	GET_INSTANCE_RET( aRet );
368
	sal_uInt32 nFileID = GetStreamID( stream );
369
    if( nFileID == PluginConnector::UnknownStreamID )
370
        return NPERR_GENERIC_ERROR;
371
    
372
	MediatorMessage* pMes = 
373
		Transact( eNPP_DestroyStream,
374
				  POST_INSTANCE(),
375
				  &nFileID, sizeof( nFileID ),
376
				  &reason, sizeof( reason ),
377
				  NULL );
378
	m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID );
379
	if( ! pMes )
380
		return NPERR_GENERIC_ERROR;
381
382
	aRet = GetNPError( pMes );
383
	delete pMes;
384
	return aRet;
385
}
386
387
void* UnxPluginComm::NPP_GetJavaClass()
388
{
389
	return NULL;
390
}
391
392
NPError UnxPluginComm::NPP_Initialize()
393
{
394
	MediatorMessage* pMes = 
395
		Transact( eNPP_Initialize,
396
				  NULL );
397
	if( ! pMes )
398
		return NPERR_GENERIC_ERROR;
399
400
	NPError aRet = GetNPError( pMes );
401
	delete pMes;
402
	return aRet;
403
}
404
405
NPError UnxPluginComm::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
406
				 char* argn[], char* argv[], NPSavedData *saved )
407
{
408
	m_aInstances.push_back(
409
		new ConnectorInstance( instance, pluginType, 0,
410
							   NULL, 0, NULL, 0,
411
							   saved ? (char*)saved->buf : NULL,
412
							   saved ? saved->len : 0 ) );
413
414
	char *pArgnBuf, *pArgvBuf;
415
	size_t nArgnLen = 0, nArgvLen = 0;
416
	int i;
417
	for( i = 0; i < argc; i++ )
418
	{
419
		nArgnLen += strlen( argn[i] ) +1;
420
		nArgvLen += strlen( argv[i] ) +1;
421
	}
422
	pArgnBuf = new char[ nArgnLen ];
423
	pArgvBuf = new char[ nArgvLen ];
424
	char* pRunArgn = pArgnBuf;
425
	char* pRunArgv = pArgvBuf;
426
	for( i = 0; i < argc; i++ )
427
	{
428
		strcpy( pRunArgn, argn[i] );
429
		strcpy( pRunArgv, argv[i] );
430
		pRunArgn += strlen( argn[i] ) +1;
431
		pRunArgv += strlen( argv[i] ) +1;
432
	}
433
434
	MediatorMessage* pMes;
435
	if( saved )
436
		pMes = 
437
			Transact( eNPP_New,
438
					  pluginType, strlen( pluginType ),
439
					  &mode, sizeof( mode ),
440
					  &argc, sizeof( argc ),
441
					  pArgnBuf, nArgnLen,
442
					  pArgvBuf, nArgvLen,
443
					  saved->buf, static_cast<size_t>(saved->len),
444
					  NULL );
445
	else
446
		pMes = 
447
			Transact( eNPP_New,
448
					  pluginType, strlen( pluginType ),
449
					  &mode, sizeof( mode ),
450
					  &argc, sizeof( argc ),
451
					  pArgnBuf, nArgnLen,
452
					  pArgvBuf, nArgvLen,
453
					  "0000", size_t(4),
454
					  NULL );
455
	delete [] pArgnBuf;
456
	delete [] pArgvBuf;
457
	if( ! pMes )
458
		return NPERR_GENERIC_ERROR;
459
460
	NPError aRet = GetNPError( pMes );
461
	delete pMes;
462
463
	return aRet;
464
}
465
466
NPError UnxPluginComm::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
467
					   NPBool seekable, uint16* stype )
468
{
469
	NPError aRet = NPERR_GENERIC_ERROR;
470
	GET_INSTANCE_RET( aRet );
471
472
	m_aNPWrapStreams.push_back( stream );
473
	MediatorMessage* pMes = 
474
		Transact( eNPP_NewStream,
475
				  POST_INSTANCE(),
476
				  type, strlen( type ),
477
				  stream->url, strlen( stream->url ),
478
				  &stream->end, sizeof( stream->end ),
479
				  &stream->lastmodified, sizeof( stream->lastmodified ),
480
				  &seekable, sizeof( seekable ),
481
				  NULL );
482
483
	if( ! pMes )
484
		return NPERR_GENERIC_ERROR;
485
486
	aRet = GetNPError( pMes );
487
	uint16* pSType = (uint16*)pMes->GetBytes();
488
	*stype = *pSType;
489
490
	delete [] pSType;
491
	delete pMes;
492
	return aRet;
493
}
494
495
void UnxPluginComm::NPP_Print( NPP /*instance*/, NPPrint* /*platformPrint*/ )
496
{
497
} 
498
499
NPError UnxPluginComm::NPP_SetWindow( NPP instance, NPWindow* window )
500
{
501
	NPError aRet = NPERR_GENERIC_ERROR;
502
	GET_INSTANCE_RET( aRet );
503
504
	MediatorMessage* pMes = 
505
		Transact( eNPP_SetWindow,
506
				  POST_INSTANCE(),
507
				  window, sizeof( NPWindow ),
508
				  NULL );
509
	if( ! pMes )
510
		return NPERR_GENERIC_ERROR;
511
512
	aRet = GetNPError( pMes );
513
	delete pMes;
514
	return aRet;
515
}
516
517
void UnxPluginComm::NPP_Shutdown()
518
{
519
	Send( eNPP_Shutdown, NULL );
520
}
521
522
void UnxPluginComm::NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname )
523
{
524
	GET_INSTANCE();
525
	sal_uInt32 nFileID = GetStreamID( stream );
526
    if( nFileID == PluginConnector::UnknownStreamID )
527
        return;
528
529
    Send( eNPP_StreamAsFile,
530
          POST_INSTANCE(),
531
          &nFileID, sizeof( nFileID ),
532
          fname, strlen( fname ),
533
          NULL );
534
}
535
536
void UnxPluginComm::NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData )
537
{
538
	GET_INSTANCE();
539
	
540
    Send( eNPP_URLNotify,
541
          POST_INSTANCE(),
542
          url, strlen( url ),
543
          &reason, sizeof( reason ),
544
          &notifyData, sizeof( void* ),
545
          NULL );
546
}
547
548
int32 UnxPluginComm::NPP_Write( NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer )
549
{
550
	GET_INSTANCE_RET( -1 );
551
	sal_uInt32 nFileID = GetStreamID( stream );
552
    if( nFileID == PluginConnector::UnknownStreamID )
553
        return -1;
554
555
	MediatorMessage* pMes = 
556
		Transact( eNPP_Write,
557
				  POST_INSTANCE(),
558
				  &nFileID, sizeof( nFileID ),
559
				  &offset, sizeof( offset ),
560
				  buffer, static_cast<size_t>(len),
561
				  NULL );
562
	if( ! pMes )
563
		return 0;
564
565
	int32 aRet = pMes->GetUINT32();
566
	delete pMes;
567
    
568
	return aRet;
569
}
570
571
int32 UnxPluginComm::NPP_WriteReady( NPP instance, NPStream* stream )
572
{
573
	GET_INSTANCE_RET( -1 );
574
	sal_uInt32 nFileID = GetStreamID( stream );
575
    if( nFileID == PluginConnector::UnknownStreamID )
576
        return -1;
577
578
	MediatorMessage* pMes = 
579
		Transact( eNPP_WriteReady,
580
				  POST_INSTANCE(),
581
				  &nFileID, sizeof( nFileID ),
582
				  NULL );
583
584
	if( ! pMes )
585
		return 0;
586
587
	int32 aRet = pMes->GetUINT32();
588
	delete pMes;
589
    
590
	return aRet;
591
}
592
593
char* UnxPluginComm::NPP_GetMIMEDescription()
594
{
595
	static char* pDesc = NULL;
596
	MediatorMessage* pMes = 
597
		Transact( eNPP_GetMIMEDescription,
598
				  NULL );
599
	if( ! pMes )
600
		return (char*)"";
601
602
	if( pDesc )
603
		delete [] pDesc;
604
	pDesc = pMes->GetString();
605
	delete pMes;
606
	return pDesc;
607
}
608
609
NPError UnxPluginComm::NPP_GetValue( NPP /*instance*/, NPPVariable /*variable*/, void* /*value*/ )
610
{
611
	return 0;
612
}
613
614
NPError UnxPluginComm::NPP_SetValue( NPP /*instance*/, NPNVariable /*variable*/, void* /*value*/ )
615
{
616
	return 0;
617
}
(-)a/main/extensions/source/plugin/unx/npwrap.cxx (+511 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <errno.h>
27
#include <dlfcn.h>
28
#include <unistd.h>
29
#include <sys/poll.h>
30
#include <fcntl.h>
31
#include <signal.h>
32
33
#include <plugin/unx/plugcon.hxx>
34
35
#include <osl/file.h>
36
#include <osl/module.h>
37
38
PluginConnector* pConnector = NULL;
39
40
int			nAppArguments = 0;
41
char**		pAppArguments = NULL;
42
Display*	pAppDisplay = NULL;
43
Display*    pXtAppDisplay = NULL;
44
45
extern oslModule pPluginLib;
46
extern NPError (*pNP_Shutdown)();
47
48
void LoadAdditionalLibs(const char*);
49
50
XtAppContext app_context;
51
Widget topLevel = NULL, topBox = NULL;
52
int wakeup_fd[2] = { 0, 0 };
53
static bool bPluginAppQuit = false;
54
55
static long GlobalConnectionLostHdl( void* /*pInst*/, void* /*pArg*/ )
56
{
57
	medDebug( 1, "pluginapp exiting due to connection lost\n" );
58
    
59
    write( wakeup_fd[1], "xxxx", 4 );
60
	return 0;
61
}
62
63
extern "C"
64
{
65
    static int plugin_x_error_handler( Display*, XErrorEvent* )
66
    {
67
        return 0;
68
    }
69
    
70
    #ifndef ENABLE_GTK
71
    static void ThreadEventHandler( XtPointer /*client_data*/, int* /*source*/, XtInputId* id )
72
    {
73
        char buf[256];
74
        // clear pipe
75
        int len, nLast = -1;
76
        
77
        while( (len = read( wakeup_fd[0], buf, sizeof( buf ) ) ) > 0 )
78
            nLast = len-1;
79
        if( ! bPluginAppQuit )
80
        {
81
            if( ( nLast == -1  || buf[nLast] != 'x' ) && pConnector )
82
                pConnector->CallWorkHandler();
83
            else
84
            {
85
                // it seems you can use XtRemoveInput only
86
                // safely from within the callback
87
                // why is that ?
88
                medDebug( 1, "removing wakeup pipe\n" );
89
                XtRemoveInput( *id );
90
                XtAppSetExitFlag( app_context );
91
                bPluginAppQuit = true;
92
93
                delete pConnector;
94
                pConnector = NULL;
95
            }
96
        }
97
    }
98
    #endif
99
}
100
101
102
IMPL_LINK( PluginConnector, NewMessageHdl, Mediator*, /*pMediator*/ )
103
{
104
    medDebug( 1, "new message handler\n" );
105
    write( wakeup_fd[1], "cccc", 4 );
106
    return 0;
107
    
108
}
109
110
Widget createSubWidget( char* /*pPluginText*/, Widget shell, XLIB_Window aParentWindow )
111
{
112
	Widget newWidget = XtVaCreateManagedWidget(
113
#if defined USE_MOTIF
114
  		"drawingArea",
115
		xmDrawingAreaWidgetClass,
116
#else
117
        "",
118
#  if defined DISABLE_XAW
119
		compositeWidgetClass,
120
#  else
121
		labelWidgetClass,
122
#  endif
123
#endif
124
  		shell,
125
        XtNwidth, 200,
126
        XtNheight, 200,
127
  		(char *)NULL );
128
    XtRealizeWidget( shell );
129
    XtRealizeWidget( newWidget );
130
131
    medDebug( 1, "Reparenting new widget %x to %x\n", XtWindow( newWidget ), aParentWindow );
132
    XReparentWindow( pXtAppDisplay,
133
                     XtWindow( shell ),
134
                     aParentWindow,
135
                     0, 0 );
136
    XtMapWidget( shell );
137
    XtMapWidget( newWidget );
138
    XRaiseWindow( pXtAppDisplay, XtWindow( shell ) ); 
139
    XSync( pXtAppDisplay, False );
140
141
	return newWidget;
142
}
143
144
void* CreateNewShell( void** pShellReturn, XLIB_Window aParentWindow )
145
{
146
    XLIB_String n, c;
147
    XtGetApplicationNameAndClass(pXtAppDisplay, &n, &c);
148
149
	Widget newShell =
150
		XtVaAppCreateShell( "pane", c,
151
							topLevelShellWidgetClass,
152
							pXtAppDisplay,
153
                            XtNwidth, 200,
154
                            XtNheight, 200,
155
                            XtNoverrideRedirect, True,
156
							(char *)NULL );
157
	*pShellReturn = newShell;
158
159
	char pText[1024];
160
	sprintf( pText, "starting plugin %s ...", pAppArguments[2] );
161
162
    Widget newWidget = createSubWidget( pText, newShell, aParentWindow );
163
164
	return newWidget;
165
}
166
167
static oslModule LoadModule( const char* pPath )
168
{
169
    ::rtl::OUString sSystemPath( ::rtl::OUString::createFromAscii( pPath ) );
170
    ::rtl::OUString sFileURL;
171
    osl_getFileURLFromSystemPath( sSystemPath.pData, &sFileURL.pData );
172
173
    oslModule pLib = osl_loadModule( sFileURL.pData, SAL_LOADMODULE_LAZY );
174
	if( ! pLib )
175
    {
176
        medDebug( 1, "could not open %s: %s\n", pPath, dlerror() );
177
    }
178
    return pLib;
179
}
180
181
// Unix specific implementation
182
static void CheckPlugin( const char* pPath )
183
{
184
    oslModule pLib = LoadModule( pPath );
185
    
186
	char*(*pNP_GetMIMEDescription)() = (char*(*)())
187
        osl_getAsciiFunctionSymbol( pLib, "NP_GetMIMEDescription" );
188
	if( pNP_GetMIMEDescription )
189
        printf( "%s\n", pNP_GetMIMEDescription() );
190
    else
191
        medDebug( 1, "could not get symbol NP_GetMIMEDescription %s\n", dlerror() );
192
193
    osl_unloadModule( pLib );
194
}
195
196
#if OSL_DEBUG_LEVEL > 1 && defined LINUX
197
#include <execinfo.h>
198
#endif
199
200
extern "C" {
201
202
static void signal_handler( int nSig )
203
{
204
#if OSL_DEBUG_LEVEL > 1
205
    fprintf( stderr, "caught signal %d, exiting\n", nSig );
206
#ifdef LINUX
207
    void* pStack[64];
208
    int nStackLevels = backtrace( pStack, sizeof(pStack)/sizeof(pStack[0]) );
209
    backtrace_symbols_fd( pStack, nStackLevels, STDERR_FILENO );
210
#endif
211
#endif
212
    if( pConnector )
213
    {
214
        // ensure that a read on the other side will wakeup
215
        delete pConnector;
216
        pConnector = NULL;
217
    }
218
219
    _exit(nSig);
220
}
221
222
#ifdef ENABLE_GTK
223
224
static gboolean noClosure( gpointer )
225
{
226
    return sal_True;
227
}
228
229
// Xt events
230
static gboolean prepareXtEvent( GSource*, gint* )
231
{
232
    int nMask = XtAppPending( app_context );
233
    return (nMask & XtIMAll) != 0;
234
}
235
236
static gboolean checkXtEvent( GSource* )
237
{
238
    int nMask = XtAppPending( app_context );
239
    return (nMask & XtIMAll) != 0;
240
}
241
242
static gboolean dispatchXtEvent( GSource*, GSourceFunc, gpointer )
243
{
244
    XtAppProcessEvent( app_context, XtIMAll );
245
    return sal_True;
246
}
247
248
static GSourceFuncs aXtEventFuncs =
249
{
250
  prepareXtEvent,
251
  checkXtEvent,
252
  dispatchXtEvent,
253
  NULL,
254
  noClosure,
255
  NULL
256
};
257
258
static gboolean pollXtTimerCallback(gpointer)
259
{
260
    for(int i = 0; i < 5; i++)
261
    {
262
        if( (XtAppPending(app_context) & (XtIMAll & ~XtIMXEvent)) == 0 )
263
            break;
264
        XtAppProcessEvent(app_context, XtIMAll & ~XtIMXEvent);
265
    }
266
    return sal_True;
267
}
268
269
static gboolean prepareWakeupEvent( GSource*, gint* )
270
{
271
    struct pollfd aPoll = { wakeup_fd[0], POLLIN, 0 };
272
    poll( &aPoll, 1, 0 );    
273
    return (aPoll.revents & POLLIN ) != 0;
274
}
275
276
static gboolean checkWakeupEvent( GSource* pSource )
277
{
278
    gint nDum = 0;
279
    return prepareWakeupEvent( pSource, &nDum );
280
}
281
282
static gboolean dispatchWakeupEvent( GSource*, GSourceFunc, gpointer )
283
{
284
    char buf[256];
285
    // clear pipe
286
    int len, nLast = -1;
287
    
288
    while( (len = read( wakeup_fd[0], buf, sizeof( buf ) ) ) > 0 )
289
        nLast = len-1;
290
    if( ( nLast == -1  || buf[nLast] != 'x' ) && pConnector )
291
        pConnector->CallWorkHandler();
292
    else
293
    {
294
        XtAppSetExitFlag( app_context );
295
        bPluginAppQuit = true;
296
297
        delete pConnector;
298
        pConnector = NULL;
299
    }
300
    
301
    return sal_True;
302
}
303
304
static GSourceFuncs aWakeupEventFuncs = {
305
  prepareWakeupEvent,
306
  checkWakeupEvent,
307
  dispatchWakeupEvent,
308
  NULL,
309
  noClosure,
310
  NULL
311
};
312
313
#endif // GTK
314
315
}
316
317
int main( int argc, char **argv)
318
{
319
    struct sigaction aSigAction;
320
    aSigAction.sa_handler = signal_handler;
321
    sigemptyset( &aSigAction.sa_mask );
322
    aSigAction.sa_flags = SA_NOCLDSTOP;
323
    sigaction( SIGSEGV, &aSigAction, NULL );
324
    sigaction( SIGBUS, &aSigAction, NULL );
325
    sigaction( SIGABRT, &aSigAction, NULL );
326
    sigaction( SIGTERM, &aSigAction, NULL );
327
    sigaction( SIGILL, &aSigAction, NULL );
328
329
    int nArg = (argc < 3) ? 1 : 2;
330
    char* pBaseName = argv[nArg] + strlen(argv[nArg]);
331
    while( pBaseName > argv[nArg] && pBaseName[-1] != '/' )
332
        pBaseName--;
333
    LoadAdditionalLibs( pBaseName );
334
335
    if( argc == 2 )
336
    {
337
        CheckPlugin(argv[1]);
338
        exit(0);
339
    }
340
	nAppArguments = argc;
341
	pAppArguments = argv;
342
343
    XSetErrorHandler( plugin_x_error_handler );
344
345
    if( pipe( wakeup_fd ) )
346
    {
347
        medDebug( 1, "could not pipe()\n" );
348
        return 1;
349
    }
350
    // initialize 'wakeup' pipe.
351
    int flags;
352
    
353
    // set close-on-exec descriptor flag.
354
    if ((flags = fcntl (wakeup_fd[0], F_GETFD)) != -1)
355
    {
356
        flags |= FD_CLOEXEC;
357
        fcntl (wakeup_fd[0], F_SETFD, flags);
358
    }
359
    if ((flags = fcntl (wakeup_fd[1], F_GETFD)) != -1)
360
    {
361
        flags |= FD_CLOEXEC;
362
        fcntl (wakeup_fd[1], F_SETFD, flags);
363
    }
364
    
365
    // set non-blocking I/O flag.
366
    if ((flags = fcntl (wakeup_fd[0], F_GETFL)) != -1)
367
    {
368
        flags |= O_NONBLOCK;
369
        fcntl (wakeup_fd[0], F_SETFL, flags);
370
    }
371
    if ((flags = fcntl (wakeup_fd[1], F_GETFL)) != -1)
372
    {
373
        flags |= O_NONBLOCK;
374
        fcntl (wakeup_fd[1], F_SETFL, flags);
375
    }
376
377
    pPluginLib = LoadModule( argv[2] );
378
	if( ! pPluginLib )
379
	{
380
		exit(255);
381
	}
382
    int nSocket = atol( argv[1] );
383
    
384
    #ifdef ENABLE_GTK
385
    g_thread_init(NULL);
386
    gtk_init(&argc, &argv);
387
    #endif
388
389
 	pConnector = new PluginConnector( nSocket );
390
 	pConnector->SetConnectionLostHdl( Link( NULL, GlobalConnectionLostHdl ) );
391
392
	XtSetLanguageProc( NULL, NULL, NULL );
393
394
    XtToolkitInitialize();
395
    app_context = XtCreateApplicationContext();
396
    pXtAppDisplay = XtOpenDisplay( app_context, NULL, "SOPlugin", "SOPlugin", NULL, 0, &argc, argv );
397
398
399
    #ifdef ENABLE_GTK
400
    // integrate Xt events into GTK event loop
401
    GPollFD aXtPollDesc, aWakeupPollDesc;
402
403
    GSource* pXTSource = g_source_new( &aXtEventFuncs, sizeof(GSource) );
404
    if( !pXTSource )
405
    {
406
        medDebug( 1, "could not get Xt GSource" );
407
        return 1;
408
    }
409
    
410
    g_source_set_priority( pXTSource, GDK_PRIORITY_EVENTS );
411
    g_source_set_can_recurse( pXTSource, sal_True );
412
    g_source_attach( pXTSource, NULL );
413
    aXtPollDesc.fd = ConnectionNumber( pXtAppDisplay );
414
    aXtPollDesc.events = G_IO_IN;
415
    aXtPollDesc.revents = 0;
416
    g_source_add_poll( pXTSource, &aXtPollDesc );
417
    
418
    gint xt_polling_timer_id = g_timeout_add( 25, pollXtTimerCallback, NULL);
419
    // Initialize wakeup events listener
420
    GSource *pWakeupSource = g_source_new( &aWakeupEventFuncs, sizeof(GSource) );
421
    if ( pWakeupSource == NULL )
422
    {
423
        medDebug( 1, "could not get wakeup source" );
424
        return 1;
425
    }
426
    g_source_set_priority( pWakeupSource, GDK_PRIORITY_EVENTS);
427
    g_source_attach( pWakeupSource, NULL );
428
    aWakeupPollDesc.fd = wakeup_fd[0];
429
    aWakeupPollDesc.events = G_IO_IN;
430
    aWakeupPollDesc.revents = 0;
431
    g_source_add_poll( pWakeupSource, &aWakeupPollDesc );
432
433
    pAppDisplay = gdk_x11_display_get_xdisplay( gdk_display_get_default() );
434
    #else
435
    pAppDisplay = pXtAppDisplay;
436
    XtAppAddInput( app_context,
437
                   wakeup_fd[0],
438
                   (XtPointer)XtInputReadMask,
439
                   ThreadEventHandler, NULL );
440
    #endif
441
442
 	// send that we are ready to go
443
    MediatorMessage* pMessage =
444
        pConnector->Transact( "init req", 8,
445
                              NULL );
446
    delete pMessage;
447
448
#if OSL_DEBUG_LEVEL > 3
449
    int nPID = getpid();
450
    int nChild = fork();
451
    if( nChild == 0 )
452
    {
453
        char pidbuf[16];
454
        char* pArgs[] = { "xterm", "-sl", "2000", "-sb", "-e", "gdb", "pluginapp.bin", pidbuf, NULL };
455
        sprintf( pidbuf, "%d", nPID );
456
        execvp( pArgs[0], pArgs );
457
        _exit(255);
458
    }
459
    else
460
        sleep( 10 );
461
#endif
462
463
	/*
464
	 *  Loop for events.
465
	 */
466
    // for some reason XtAppSetExitFlag won't quit the application
467
    // in ThreadEventHandler most of times; Xt will hang in select
468
    // (hat is in XtAppNextEvent). Have our own mainloop instead
469
    // of XtAppMainLoop
470
    do
471
    {
472
        #ifdef ENABLE_GTK
473
        g_main_context_iteration( NULL, sal_True );
474
        #else
475
        XtAppProcessEvent( app_context, XtIMAll );
476
        #endif
477
    } while( ! XtAppGetExitFlag( app_context ) && ! bPluginAppQuit );
478
479
    medDebug( 1, "left plugin app main loop\n" );
480
481
    #ifdef ENABLE_GTK
482
    g_source_remove(xt_polling_timer_id);
483
    #endif
484
    
485
    pNP_Shutdown();
486
    medDebug( 1, "NP_Shutdown done\n" );
487
    osl_unloadModule( pPluginLib );
488
    medDebug( 1, "plugin close\n" );
489
490
    close( wakeup_fd[0] );
491
    close( wakeup_fd[1] );
492
493
    return 0;
494
}
495
496
#ifdef GCC
497
extern "C" {
498
    void __pure_virtual()
499
    {}
500
501
    void* __builtin_new( int nBytes )
502
    { return malloc(nBytes); }
503
    void* __builtin_vec_new( int nBytes )
504
    { return malloc(nBytes); }
505
    void __builtin_delete( char* pMem )
506
    { free(pMem); }
507
    void __builtin_vec_delete( char* pMem )
508
    { free(pMem); }
509
}
510
#endif
511
(-)a/main/extensions/source/plugin/unx/plugcon.cxx (+278 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <plugin/unx/plugcon.hxx>
27
28
#include <cstdarg>
29
#include <vector>
30
31
sal_uInt32 PluginConnector::GetStreamID( NPStream* pStream )
32
{
33
    size_t nLen = m_aNPWrapStreams.size();
34
	for( size_t i = 0; i < nLen; i++ )
35
		if( m_aNPWrapStreams[ i ] == pStream )
36
			return static_cast<sal_uInt32>(i);
37
	medDebug( 1, "Error: NPStream has no ID\n" );
38
	return UnknownStreamID;
39
}
40
41
sal_uInt32 PluginConnector::GetNPPID( NPP instance )
42
{
43
    size_t nLen = m_aInstances.size();
44
	for( size_t i=0; i <nLen; i++ )
45
		if( m_aInstances[ i ]->instance == instance )
46
			return static_cast<sal_uInt32>(i);
47
	medDebug( 1, "Error: NPP has no ID\n" );
48
49
	return UnknownNPPID;
50
}
51
52
ConnectorInstance* PluginConnector::getInstance( NPP instance )
53
{
54
    size_t nLen = m_aInstances.size();
55
	for( size_t i=0; i <nLen; i++ )
56
    {
57
        ConnectorInstance* pInst = m_aInstances[i];
58
        if( pInst->instance == instance )
59
            return pInst;
60
    }
61
    return NULL;
62
}
63
64
ConnectorInstance* PluginConnector::getInstanceById( sal_uInt32 nInstanceID )
65
{
66
    return nInstanceID < static_cast<sal_uInt32>(m_aInstances.size()) ? m_aInstances[ nInstanceID ] : NULL;
67
}
68
69
struct PtrStruct
70
{
71
	char* pData;
72
	sal_uLong nBytes;
73
    
74
    PtrStruct( char* i_pData, sal_uLong i_nBytes )
75
    : pData( i_pData ), nBytes( i_nBytes ) {}
76
};
77
78
sal_uLong PluginConnector::FillBuffer( char*& rpBuffer,
79
								   const char* pFunction,
80
								   sal_uLong nFunctionLen,
81
								   va_list ap )
82
{
83
    std::vector< PtrStruct > aList;
84
    aList.reserve( 5 );
85
    
86
	sal_uLong nDataSize = nFunctionLen + sizeof( sal_uLong );
87
	char* pNext;
88
89
	do {
90
		pNext = va_arg( ap, char* );
91
		if( pNext )
92
		{
93
            aList.push_back( PtrStruct( pNext, va_arg( ap, sal_uLong ) ) );
94
			nDataSize += aList.back().nBytes + sizeof(sal_uLong);
95
		}
96
	} while( pNext );
97
98
	rpBuffer = new char[ nDataSize ];
99
	char* pRun = rpBuffer;
100
	memcpy( pRun, &nFunctionLen, sizeof( nFunctionLen ) );
101
	pRun += sizeof( nFunctionLen );
102
	memcpy( pRun, pFunction, nFunctionLen );
103
	pRun += nFunctionLen;
104
105
	for( std::vector<PtrStruct>::const_iterator it = aList.begin(); it != aList.end(); ++it )
106
	{
107
		memcpy( pRun, &it->nBytes, sizeof( sal_uLong ) );
108
		pRun += sizeof( sal_uLong );
109
		memcpy( pRun, it->pData, it->nBytes );
110
		pRun += it->nBytes;
111
	}
112
	return nDataSize;
113
}
114
115
MediatorMessage* PluginConnector::Transact( const char* pFunction,
116
											sal_uLong nFunctionLen, ... )
117
{
118
	va_list ap;
119
	char* pBuffer;
120
121
	va_start( ap, nFunctionLen );
122
	sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
123
	va_end( ap );
124
	return TransactMessage( nSize, pBuffer );
125
}
126
127
MediatorMessage* PluginConnector::Transact( sal_uInt32 nFunction, ... )
128
{
129
	va_list ap;
130
	char* pBuffer;
131
132
	va_start( ap, nFunction );
133
	sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
134
	va_end( ap );
135
	return TransactMessage( nSize, pBuffer );
136
}
137
138
sal_uLong PluginConnector::Send( sal_uInt32 nFunction, ... )
139
{
140
	va_list ap;
141
	char* pBuffer;
142
143
	va_start( ap, nFunction );
144
	sal_uLong nSize = FillBuffer( pBuffer, (char*)&nFunction, sizeof( nFunction ), ap );
145
	va_end( ap );
146
	return SendMessage( nSize, pBuffer );
147
}
148
149
void PluginConnector::Respond( sal_uLong nID,
150
							   char* pFunction,
151
							   sal_uLong nFunctionLen, ... )
152
{
153
	va_list ap;
154
	char* pBuffer;
155
	
156
	va_start( ap, nFunctionLen );
157
	sal_uLong nSize = FillBuffer( pBuffer, pFunction, nFunctionLen, ap );
158
	va_end( ap );
159
	SendMessage( nSize, pBuffer, nID | ( 1 << 24 ) );
160
}
161
162
MediatorMessage* PluginConnector::WaitForAnswer( sal_uLong nMessageID )
163
{
164
	if( ! m_bValid )
165
		return NULL;
166
167
	nMessageID &= 0x00ffffff;
168
	while( m_pListener )
169
	{
170
		{
171
			vos::OGuard aGuard( m_aQueueMutex );
172
			for( size_t i = 0; i < m_aMessageQueue.size(); i++ )
173
			{
174
                MediatorMessage* pMessage = m_aMessageQueue[ i ];
175
				sal_uLong nID = pMessage->m_nID;
176
				if(  ( nID & 0xff000000 ) &&
177
					 ( ( nID & 0x00ffffff ) == nMessageID ) )
178
                {
179
                    m_aMessageQueue.erase( m_aMessageQueue.begin() + i );
180
					return pMessage;
181
                }
182
			}
183
		}
184
		if( ! m_aMessageQueue.empty() )
185
			CallWorkHandler();
186
		WaitForMessage( 2000 );
187
	}
188
	return NULL;
189
}
190
191
ConnectorInstance::ConnectorInstance( NPP inst, char* type,
192
									  int args, char* pargnbuf, sal_uLong nargnbytes,
193
									  char* pargvbuf, sal_uLong nargvbytes,
194
									  char* savedata, sal_uLong savebytes ) :
195
		instance( inst ),
196
		pShell( NULL ),
197
		pWidget( NULL ),
198
        pForm( NULL ),
199
        pGtkWindow( NULL ),
200
        pGtkWidget( NULL ),
201
        bShouldUseXEmbed( false ),
202
		nArg( args ),
203
		pArgnBuf( pargnbuf ),
204
		pArgvBuf( pargvbuf )
205
{
206
	memset( &window, 0, sizeof(window) );
207
	pMimeType = new char[ strlen( type ) + 1 ];
208
	strcpy( pMimeType, type );
209
	aData.len = savebytes;
210
	aData.buf = savedata;
211
	argn = new char*[ nArg ];
212
	argv = new char*[ nArg ];
213
	int i;
214
	char* pRun = pArgnBuf;
215
	for( i = 0; i < nArg; i++ )
216
	{
217
		argn[i] = pRun;
218
		while( *pRun != 0 && (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
219
			pRun++;
220
		if( (sal_uLong)(pRun - pArgnBuf) < nargnbytes )
221
			pRun++;
222
	}
223
	pRun = pArgvBuf;
224
	for( i = 0; i < nArg; i++ )
225
	{
226
		argv[i] = pRun;
227
		while( *pRun != 0 && (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
228
			pRun++;
229
		if( (sal_uLong)(pRun - pArgvBuf) < nargvbytes )
230
			pRun++;
231
	}
232
}
233
234
ConnectorInstance::~ConnectorInstance()
235
{
236
	delete [] pMimeType;
237
	delete [] argn;
238
	delete [] argv;
239
	delete [] pArgnBuf;
240
	delete [] pArgvBuf;
241
	delete [] (char*)aData.buf;
242
}
243
244
const char* GetCommandName( CommandAtoms eCommand )
245
{
246
	switch( eCommand )
247
	{
248
        case eNPN_GetURL:				return "NPN_GetURL";
249
        case eNPN_GetURLNotify:			return "NPN_GetURLNotify";
250
        case eNPN_DestroyStream:		return "NPN_DestroyStream";
251
        case eNPN_NewStream:			return "NPN_NewStream";
252
        case eNPN_PostURLNotify:		return "NPN_PostURLNotify";
253
        case eNPN_PostURL:				return "NPN_PostURL";
254
        case eNPN_RequestRead:			return "NPN_RequestRead";
255
        case eNPN_Status:				return "NPN_Status";
256
        case eNPN_Version:				return "NPN_Version";
257
        case eNPN_Write:				return "NPN_Write";
258
		case eNPN_UserAgent:			return "NPN_UserAgent";
259
260
        case eNPP_DestroyStream:		return "NPP_DestroyStream";
261
        case eNPP_Destroy:				return "NPP_Destroy";
262
        case eNPP_DestroyPhase2:		return "NPP_DestroyPhase2";
263
        case eNPP_NewStream:			return "NPP_NewStream";
264
        case eNPP_New:					return "NPP_New";
265
        case eNPP_SetWindow:			return "NPP_SetWindow";
266
        case eNPP_StreamAsFile:			return "NPP_StreamAsFile";
267
        case eNPP_URLNotify:			return "NPP_URLNotify";
268
        case eNPP_WriteReady:			return "NPP_WriteReady";
269
        case eNPP_Write:				return "NPP_Write";
270
        case eNPP_GetMIMEDescription:	return "NPP_GetMIMEDescription";
271
        case eNPP_Initialize:			return "NPP_Initialize";
272
        case eNPP_Shutdown:				return "NPP_Shutdown";
273
274
		case eMaxCommand:				return "eMaxCommand";
275
		default:						return "unknown command";
276
	}
277
	return NULL;
278
}
(-)a/main/extensions/source/plugin/unx/sysplug.cxx (+127 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <cstdarg>
27
28
#include <sys/types.h>
29
#include <signal.h>
30
#include <sys/wait.h>
31
#include <osl/file.hxx>
32
#include <osl/thread.h>
33
#include <rtl/bootstrap.hxx>
34
35
#include <plugin/impl.hxx>
36
37
int UnxPluginComm::nConnCounter = 0;
38
39
UnxPluginComm::UnxPluginComm(
40
                             const String& /*mimetype*/,
41
                             const String& library,
42
                             XLIB_Window aParent,
43
                             int nDescriptor1,
44
                             int nDescriptor2
45
                             ) :
46
        PluginComm( ::rtl::OUStringToOString( library, osl_getThreadTextEncoding() ), false ),
47
        PluginConnector( nDescriptor2 )
48
{
49
    char pDesc[32];
50
	char pWindow[32];
51
	sprintf( pWindow, "%d", (int)aParent );
52
    sprintf( pDesc, "%d", nDescriptor1 );
53
	ByteString aLib( library, osl_getThreadTextEncoding() );
54
    rtl::OString path;
55
    if (!getPluginappPath(&path)) {
56
        fprintf( stderr, "cannot construct path to pluginapp.bin\n" );
57
        m_nCommPID = -1;
58
        return;
59
    }
60
61
	char const* pArgs[5];
62
	pArgs[0] = path.getStr();
63
	pArgs[1] = pDesc;
64
	pArgs[2] = aLib.GetBuffer();
65
	pArgs[3] = pWindow;
66
	pArgs[4] = NULL;
67
68
#if OSL_DEBUG_LEVEL > 1
69
	m_nCommPID = 10;
70
	fprintf( stderr, "Try to launch: %s %s %s %s, descriptors are %d, %d\n", pArgs[0], pArgs[1], pArgs[2], pArgs[3], nDescriptor1, nDescriptor2 );
71
#endif
72
73
	if( ! ( m_nCommPID = fork() ) )
74
  	{
75
 		execvp( pArgs[0], const_cast< char ** >(pArgs) );
76
  		fprintf( stderr, "Error: could not exec %s\n", pArgs[0] );
77
  		_exit(255);
78
  	}
79
80
	if( m_nCommPID != -1 )
81
	{
82
		// wait for pluginapp.bin to start up
83
		if( ! WaitForMessage( 5000 ) )
84
		{
85
			fprintf( stderr, "Timeout on command: %s %s %s %s\n", pArgs[0], pArgs[1], pArgs[2], pArgs[3] );
86
			invalidate();
87
		}
88
		else
89
		{
90
			MediatorMessage* pMessage = GetNextMessage( sal_True );
91
			Respond( pMessage->m_nID,
92
					 const_cast<char*>("init ack"),8,
93
					 NULL );
94
			delete pMessage;
95
			NPP_Initialize();
96
		}
97
	}
98
}
99
100
UnxPluginComm::~UnxPluginComm()
101
{
102
	NPP_Shutdown();
103
	if( m_nCommPID != -1 && m_nCommPID != 0 )
104
    {
105
        int status = 16777216;
106
        pid_t nExit = waitpid( m_nCommPID, &status, WUNTRACED );
107
#if OSL_DEBUG_LEVEL > 1
108
        fprintf( stderr, "child %d (plugin app child %d) exited with status %d\n", (int)nExit, (int)m_nCommPID, (int)WEXITSTATUS(status) );
109
#else
110
        (void)nExit;
111
#endif
112
    }
113
}
114
115
bool UnxPluginComm::getPluginappPath(rtl::OString * path) {
116
    OSL_ASSERT(path != NULL);
117
    rtl::OUString p(
118
        RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/pluginapp.bin"));
119
    rtl::Bootstrap::expandMacros(p);
120
    return
121
        (osl::FileBase::getSystemPathFromFileURL(p, p) ==
122
         osl::FileBase::E_None) &&
123
        p.convertToString(
124
            path, osl_getThreadTextEncoding(),
125
            (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
126
             RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR));
127
}
(-)a/main/extensions/source/plugin/unx/unxmgr.cxx (+311 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
#include <cstdarg>
27
#include <sys/stat.h>
28
#include <sys/types.h>
29
#include <dirent.h>
30
#include <osl/thread.h>
31
#include <rtl/strbuf.hxx>
32
#include <tools/appendunixshellword.hxx>
33
34
#include <vcl/svapp.hxx>
35
#include <plugin/impl.hxx>
36
37
using namespace rtl;
38
using namespace std;
39
using namespace com::sun::star::uno;
40
using namespace com::sun::star::plugin;
41
42
// Unix specific implementation
43
static bool CheckPlugin( const ByteString& rPath, list< PluginDescription* >& rDescriptions )
44
{
45
#if OSL_DEBUG_LEVEL > 1
46
    fprintf( stderr, "Trying plugin %s ... ", rPath.GetBuffer() );
47
#endif
48
49
    xub_StrLen nPos = rPath.SearchBackward( '/' );
50
    if( nPos == STRING_NOTFOUND )
51
    {
52
#if OSL_DEBUG_LEVEL > 1
53
        fprintf( stderr, "no absolute path to plugin\n" );
54
#endif
55
        return false;
56
    }
57
58
    ByteString aBaseName = rPath.Copy( nPos+1 );
59
    if( aBaseName.Equals( "libnullplugin.so" ) )
60
    {
61
#if OSL_DEBUG_LEVEL > 1
62
        fprintf( stderr, "don't like %s\n", aBaseName.GetBuffer() );
63
#endif
64
        return false;
65
    }
66
67
    struct stat aStat;
68
    if( stat( rPath.GetBuffer(), &aStat ) || ! S_ISREG( aStat.st_mode ) )
69
    {
70
#if OSL_DEBUG_LEVEL > 1
71
        fprintf( stderr, "%s is not a regular file\n", rPath.GetBuffer() );
72
#endif
73
        return false;
74
    }
75
76
77
    rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
78
79
    rtl::OString path;
80
    if (!UnxPluginComm::getPluginappPath(&path)) {
81
#if OSL_DEBUG_LEVEL > 1
82
        fprintf( stderr, "cannot construct path to pluginapp.bin\n" );
83
#endif
84
        return false;
85
    }
86
    rtl::OStringBuffer cmd;
87
    tools::appendUnixShellWord(&cmd, path);
88
    cmd.append(' ');
89
    tools::appendUnixShellWord(&cmd, rPath);
90
    rtl::OString aCommand(cmd.makeStringAndClear());
91
92
    FILE* pResult = popen( aCommand.getStr(), "r" );
93
    int nDescriptions = 0;
94
    if( pResult )
95
    {
96
		OStringBuffer aMIME;
97
        char buf[256];
98
        while( fgets( buf, sizeof( buf ), pResult ) )
99
        {
100
            for( size_t i = 0; i < sizeof(buf) && buf[i]; ++i )
101
            {
102
                if( buf[i] == '\n' )
103
                    buf[i] = ';';
104
            }
105
            aMIME.append( buf );
106
        }
107
        pclose( pResult );
108
109
        if( aMIME.getLength() > 0 )
110
        {
111
            OString aLine = aMIME.makeStringAndClear();
112
            
113
            sal_Int32 nIndex = 0;
114
            while( nIndex != -1 )
115
            {
116
                OString aType = aLine.getToken( 0, ';', nIndex );
117
118
                sal_Int32 nTypeIndex = 0;
119
                OString aMimetype	= aType.getToken( 0, ':', nTypeIndex );
120
                OString aExtLine	= aType.getToken( 0, ':', nTypeIndex );
121
                if( nTypeIndex < 0 ) // ensure at least three tokens
122
                    continue;
123
                OString aDesc		= aType.getToken( 0, ':', nTypeIndex );
124
125
                // create extension list string
126
                sal_Int32 nExtIndex = 0;
127
                OStringBuffer aExtension;
128
                while( nExtIndex != -1 )
129
                {
130
                    OString aExt = aExtLine.getToken( 0, ',', nExtIndex);
131
                    if( aExt.indexOf( "*." ) != 0 )
132
                        aExtension.append( "*." );
133
                    aExtension.append( aExt );
134
                    if( nExtIndex != -1 )
135
                        aExtension.append( ';' );
136
                }
137
138
                PluginDescription* pNew = new PluginDescription;
139
                // set plugin name (path to library)
140
                pNew->PluginName	= OStringToOUString( rPath, aEncoding );
141
                // set mimetype
142
                pNew->Mimetype 	= OStringToOUString( aMimetype, aEncoding );
143
                // set extension line
144
                pNew->Extension	= OStringToOUString( aExtension.makeStringAndClear(), aEncoding );
145
                // set description
146
                pNew->Description= OStringToOUString( aDesc, aEncoding );
147
                rDescriptions.push_back( pNew );
148
#if OSL_DEBUG_LEVEL > 1
149
                fprintf( stderr, "Mimetype: %s\nExtension: %s\n"
150
                         "Description: %s\n",
151
                         OUStringToOString( pNew->Mimetype, aEncoding ).getStr(),
152
                         OUStringToOString( pNew->Extension, aEncoding ).getStr(),
153
                         OUStringToOString( pNew->Description, aEncoding ).getStr()
154
                         );
155
#endif
156
            }
157
        }
158
#if OSL_DEBUG_LEVEL > 1
159
        else
160
            fprintf( stderr, "result of \"%s\" contains no mimtype\n",
161
                     aCommand.getStr() );
162
#endif
163
	}
164
#if OSL_DEBUG_LEVEL > 1
165
    else
166
        fprintf( stderr, "command \"%s\" failed\n", aCommand.getStr() );
167
#endif
168
	return nDescriptions > 0;
169
}
170
171
union maxDirent
172
{
173
    char aBuffer[ sizeof( struct dirent ) + _PC_NAME_MAX +1 ];
174
    struct dirent asDirent;
175
};
176
177
static void CheckPluginRegistryFiles( const rtl::OString& rPath, list< PluginDescription* >& rDescriptions )
178
{
179
    rtl::OStringBuffer aPath( 1024 );
180
    aPath.append( rPath );
181
    aPath.append( "/pluginreg.dat" );
182
    FILE* fp = fopen( aPath.getStr(), "r" );
183
    if( fp )
184
    {
185
#if OSL_DEBUG_LEVEL > 1
186
        fprintf( stderr, "parsing %s\n", aPath.getStr() );
187
#endif
188
        char aLine[1024];
189
        while( fgets( aLine, sizeof( aLine ), fp ) )
190
        {
191
            int nLineLen = strlen( aLine );
192
            int nDotPos;
193
            for( nDotPos = nLineLen-1; nDotPos > 0 && aLine[nDotPos] != ':'; nDotPos-- )
194
                ;
195
            if( aLine[0] == '/' && aLine[nDotPos] == ':' && aLine[nDotPos+1] == '$' )
196
                CheckPlugin( ByteString( aLine, nDotPos ), rDescriptions );
197
        }
198
        fclose( fp );
199
    }
200
    
201
    // check subdirectories
202
    DIR* pDIR = opendir( rPath.getStr() );
203
    struct dirent* pDirEnt = NULL;
204
    struct stat aStat;
205
    maxDirent u;
206
    while( pDIR && ! readdir_r( pDIR, &u.asDirent, &pDirEnt ) && pDirEnt )
207
    {
208
        char* pBaseName = u.asDirent.d_name;
209
        if( rtl_str_compare( ".", pBaseName ) && rtl_str_compare( "..", pBaseName ) )
210
        {
211
            rtl::OStringBuffer aBuf( 1024 );
212
            aBuf.append( rPath );
213
            aBuf.append( '/' );
214
            aBuf.append( pBaseName );
215
            
216
            if( ! stat( aBuf.getStr(), &aStat ) )
217
            {
218
                if( S_ISDIR( aStat.st_mode ) )
219
                    CheckPluginRegistryFiles( aBuf.makeStringAndClear(), rDescriptions );
220
            }
221
        }
222
    }
223
    if( pDIR )
224
        closedir( pDIR );
225
}
226
227
Sequence<PluginDescription> XPluginManager_Impl::impl_getPluginDescriptions() throw()
228
{
229
	static Sequence<PluginDescription> aDescriptions;
230
	static sal_Bool bHavePlugins = sal_False;
231
	if( ! bHavePlugins )
232
	{
233
        rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
234
		list<PluginDescription*> aPlugins;
235
		int i;
236
237
		// unix: search for plugins in /usr/lib/netscape/plugins,
238
		//       ~/.netscape/plugins und NPX_PLUGIN_PATH
239
		// additionally: search in PluginsPath
240
        static const char* pHome = getenv( "HOME" );
241
        static const char* pNPXPluginPath = getenv( "NPX_PLUGIN_PATH" );
242
243
		ByteString aSearchPath( "/usr/lib/netscape/plugins" );
244
        if( pHome )
245
        {
246
            aSearchPath.Append( ':' );
247
            aSearchPath.Append( pHome );
248
            aSearchPath += "/.netscape/plugins";
249
        }
250
        if( pNPXPluginPath )
251
        {
252
            aSearchPath.Append( ':' );
253
            aSearchPath += pNPXPluginPath;
254
        }
255
256
		const Sequence< ::rtl::OUString >& rPaths( PluginManager::getAdditionalSearchPaths() );
257
		for( i = 0; i < rPaths.getLength(); i++ )
258
		{
259
			aSearchPath += ":";
260
			aSearchPath += ByteString( String( rPaths.getConstArray()[i] ), aEncoding );
261
		}
262
263
		int nPaths = aSearchPath.GetTokenCount( ':' );
264
        maxDirent u;
265
		for( i = 0; i < nPaths; i++ )
266
		{
267
			ByteString aPath( aSearchPath.GetToken( i, ':' ) );
268
			if( aPath.Len() )
269
			{
270
                DIR* pDIR = opendir( aPath.GetBuffer() );
271
                struct dirent* pDirEnt = NULL;
272
                while( pDIR && ! readdir_r( pDIR, &u.asDirent, &pDirEnt ) && pDirEnt )
273
                {
274
                    char* pBaseName = u.asDirent.d_name;
275
                    if( pBaseName[0] != '.' ||
276
                        pBaseName[1] != '.' ||
277
                        pBaseName[2] != 0 )
278
                    {
279
                        ByteString aFileName( aPath );
280
                        aFileName += "/";
281
                        aFileName += pBaseName;
282
                        CheckPlugin( aFileName, aPlugins );
283
                    }
284
				}
285
                if( pDIR )
286
                    closedir( pDIR );
287
			}
288
		}
289
290
        // try ~/.mozilla/pluginreg.dat
291
        rtl::OStringBuffer aBuf(256);
292
        aBuf.append( pHome );
293
        aBuf.append( "/.mozilla" );
294
        CheckPluginRegistryFiles( aBuf.makeStringAndClear(), aPlugins );
295
296
        // create return value
297
		aDescriptions = Sequence<PluginDescription>( aPlugins.size() );
298
#if OSL_DEBUG_LEVEL > 1
299
        fprintf( stderr, "found %d plugins\n", (int)aPlugins.size() );
300
#endif
301
		list<PluginDescription*>::iterator iter;
302
		for( iter = aPlugins.begin(), i=0; iter != aPlugins.end(); ++iter ,i++ )
303
		{
304
			aDescriptions.getArray()[ i ] = **iter;
305
			delete *iter;
306
		}
307
		aPlugins.clear();
308
		bHavePlugins = sal_True;
309
	}
310
	return aDescriptions;
311
}
(-)a/main/extensions/source/plugin/util/makefile.mk (+113 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
PRJ=..$/..$/..
24
25
PRJNAME=extensions
26
TARGET=pl
27
TARGETTYPE=GUI
28
29
# --- Settings -----------------------------------------------------
30
31
.INCLUDE :  settings.mk
32
33
# --- Files --------------------------------------------------------
34
35
.IF "$(WITH_MOZILLA)" != "NO"
36
37
LIB1TARGET = $(SLB)$/plall.lib
38
LIB1FILES  = \
39
	$(SLB)$/plbase.lib	\
40
	$(SHL1LINKLIB)
41
42
.IF "$(GUI)" == "UNX"
43
.IF "$(GUIBASE)"=="aqua"
44
.IF "$(WITH_MOZILLA)"=="YES"
45
SHL1LINKLIB = $(SLB)$/plaqua.lib
46
.ENDIF
47
.ELSE
48
SHL1LINKLIB = $(SLB)$/plunx.lib
49
.ENDIF # $(GUIBASE)==aqua
50
.IF "$(OS)" == "SOLARIS"
51
SHL1OWNLIBS = -lsocket
52
.ENDIF # SOLARIS
53
.ENDIF # UNX
54
55
.IF "$(GUI)" == "WNT"
56
SHL1LINKLIB = $(SLB)$/plwin.lib
57
SHL1OWNLIBS = \
58
	$(VERSIONLIB)	\
59
	$(OLE32LIB)	\
60
	$(ADVAPI32LIB)
61
.ENDIF # WNT
62
63
SHL1TARGET= $(TARGET)$(DLLPOSTFIX)
64
SHL1IMPLIB= i$(TARGET)
65
66
SHL1VERSIONMAP=$(SOLARENV)/src/component.map
67
SHL1DEF=$(MISC)$/$(SHL1TARGET).def
68
DEF1NAME=$(SHL1TARGET)
69
70
SHL1LIBS=$(LIB1TARGET)
71
72
.IF "$(OS)"=="MACOSX"
73
SHL1STDLIBS= \
74
	$(LIBSTLPORT)		\
75
	$(TKLIB)
76
.ELSE
77
SHL1STDLIBS= \
78
	$(TKLIB)
79
.ENDIF
80
81
SHL1STDLIBS+= \
82
	$(VCLLIB)			\
83
	$(SVLLIB)			\
84
        $(UNOTOOLSLIB)                     \
85
	$(TOOLSLIB)			\
86
	$(VOSLIB)			\
87
	$(UCBHELPERLIB)		\
88
	$(CPPUHELPERLIB)	\
89
	$(CPPULIB)			\
90
	$(SALLIB)
91
92
.IF "$(GUIBASE)"=="unx"
93
SHL1STDLIBS+=$(X11LINK_DYNAMIC)
94
.ENDIF
95
96
SHL1STDLIBS+=$(SHL1OWNLIBS)
97
98
.ENDIF # $(WITH_MOZILLA) != "NO"
99
100
# --- Targets ------------------------------------------------------
101
102
.INCLUDE :  target.mk
103
104
105
106
107
ALLTAR : $(MISC)/pl.component
108
109
$(MISC)/pl.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
110
        pl.component
111
    $(XSLTPROC) --nonet --stringparam uri \
112
        '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \
113
        $(SOLARENV)/bin/createcomponent.xslt pl.component
(-)a/main/extensions/source/plugin/util/makefile.pmk (+44 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
NOUNODOC=true
24
25
.INCLUDE :  settings.mk
26
27
.IF "$(SYSTEM_MOZILLA)" == "YES"
28
CFLAGS+=-DSYSTEM_MOZILLA
29
PKGCONFIG_MODULES+=$(MOZ_FLAVOUR)-plugin
30
.ENDIF
31
32
.IF "$(GUIBASE)" == "unx" && "$(ENABLE_GTK)" == "TRUE"
33
CDEFS+=-DENABLE_GTK
34
PKGCONFIG_MODULES+=gtk+-2.0 gthread-2.0
35
.ENDIF
36
37
.IF "$(GUIBASE)" == "aqua"
38
CFLAGS += -I$(FRAMEWORKSHOME)/ApplicationServices.framework/Versions/Current/Frameworks/QD.framework/Headers\
39
          -I$(FRAMEWORKSHOME)/Carbon.framework/Versions/Current/Frameworks/HIToolbox.framework/Versions/Current/Headers
40
.ENDIF
41
42
.IF "$(PKGCONFIG_MODULES)" != ""
43
.INCLUDE : pkg_config.mk
44
.ENDIF
(-)a/main/extensions/source/plugin/util/pl.component (+33 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--***********************************************************
3
 * 
4
 * Licensed to the Apache Software Foundation (ASF) under one
5
 * or more contributor license agreements.  See the NOTICE file
6
 * distributed with this work for additional information
7
 * regarding copyright ownership.  The ASF licenses this file
8
 * to you under the Apache License, Version 2.0 (the
9
 * "License"); you may not use this file except in compliance
10
 * with the License.  You may obtain a copy of the License at
11
 * 
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 * 
14
 * Unless required by applicable law or agreed to in writing,
15
 * software distributed under the License is distributed on an
16
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
 * KIND, either express or implied.  See the License for the
18
 * specific language governing permissions and limitations
19
 * under the License.
20
 * 
21
 ***********************************************************-->
22
23
24
25
<component loader="com.sun.star.loader.SharedLibrary"
26
    xmlns="http://openoffice.org/2010/uno-components">
27
  <implementation name="com.sun.star.extensions.PluginManager">
28
    <service name="com.sun.star.plugin.PluginManager"/>
29
  </implementation>
30
  <implementation name="com.sun.star.extensions.PluginModel">
31
    <service name="com.sun.star.plugin.PluginModel"/>
32
  </implementation>
33
</component>
(-)a/main/extensions/source/plugin/win/makefile.mk (+61 lines)
Line 0 Link Here
1
#**************************************************************
2
#  
3
#  Licensed to the Apache Software Foundation (ASF) under one
4
#  or more contributor license agreements.  See the NOTICE file
5
#  distributed with this work for additional information
6
#  regarding copyright ownership.  The ASF licenses this file
7
#  to you under the Apache License, Version 2.0 (the
8
#  "License"); you may not use this file except in compliance
9
#  with the License.  You may obtain a copy of the License at
10
#  
11
#    http://www.apache.org/licenses/LICENSE-2.0
12
#  
13
#  Unless required by applicable law or agreed to in writing,
14
#  software distributed under the License is distributed on an
15
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
#  KIND, either express or implied.  See the License for the
17
#  specific language governing permissions and limitations
18
#  under the License.
19
#  
20
#**************************************************************
21
22
23
24
PRJ=..$/..$/..
25
26
PRJNAME=extensions
27
TARGET=plwin
28
ENABLE_EXCEPTIONS=TRUE
29
30
# --- Settings -----------------------------------------------------
31
.IF "$(GUI)" == "WNT"
32
33
.INCLUDE :  ..$/util$/makefile.pmk
34
35
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/plugin
36
.IF "$(SOLAR_JAVA)" != ""
37
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/java
38
INCPRE+=-I$(SOLARINCDIR)$/mozilla$/nspr
39
CDEFS+=-DOJI
40
.ENDIF
41
42
# --- Types -------------------------------------
43
44
.IF "$(WITH_MOZILLA)" != "NO"
45
46
#UNOUCROUT=$(OUT)$/inc$/$(PRJNAME)
47
#INCPRE+=$(UNOUCROUT)
48
49
# --- Types -------------------------------------
50
51
SLOFILES =	$(SLO)$/winmgr.obj	\
52
			$(SLO)$/sysplug.obj
53
54
.ENDIF # $(WITH_MOZILLA) != "NO"
55
.ENDIF
56
57
# ------------------------------------------------------------------
58
59
60
.INCLUDE :  target.mk
61
(-)a/main/extensions/source/plugin/win/sysplug.cxx (+439 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#include <plugin/impl.hxx>
28
29
#pragma warning (push,1)
30
#pragma warning (disable:4005)
31
32
    #include <tools/prewin.h>
33
34
    #include <windows.h>
35
    #include <string.h>
36
    #include <tchar.h>
37
    #include <winreg.h>
38
    #include <winbase.h>
39
    #include <objbase.h>
40
41
    #include <tools/postwin.h>
42
43
#pragma warning (pop)
44
45
#include <list>
46
#include <map>
47
#include <algorithm>
48
49
50
extern NPNetscapeFuncs aNPNFuncs;
51
52
#include <tools/debug.hxx>
53
54
using namespace rtl;
55
56
#if OSL_DEBUG_LEVEL > 1
57
void TRACE( char const * s );
58
void TRACEN( char const * s, long n );
59
#else
60
#define TRACE(x)
61
#define TRACEN(x,n)
62
#endif
63
64
65
//--------------------------------------------------------------------------------------------------
66
PluginComm_Impl::PluginComm_Impl( const OUString& /*rMIME*/, const OUString& rName, HWND /*hWnd*/ )
67
	: PluginComm( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) )
68
{
69
	// initialize plugin function table
70
	memset( &_NPPfuncs, 0, sizeof( _NPPfuncs ) );
71
#ifdef UNICODE
72
	_plDLL = ::LoadLibrary( rName.getStr() );
73
#else
74
	OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) );
75
	_plDLL = ::LoadLibrary( aStr.getStr() );
76
#endif
77
	DBG_ASSERT( _plDLL, "### loading plugin dll failed!" );
78
79
    NPError nErr = NPERR_NO_ERROR;
80
    NPError (WINAPI * pEntry)( NPPluginFuncs* );
81
    retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry );
82
83
    _NPPfuncs.size = sizeof( _NPPfuncs );
84
    _NPPfuncs.version = 0;
85
    nErr = (*pEntry)( &_NPPfuncs );
86
87
    DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_GetEntryPoints() failed!" );
88
    DBG_ASSERT( (_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR,
89
                "### version failure!" );
90
91
	m_eCall = eNP_Initialize;
92
	execute();
93
}
94
95
//--------------------------------------------------------------------------------------------------
96
PluginComm_Impl::~PluginComm_Impl()
97
{
98
	if (_plDLL)
99
	{
100
//			NPP_Shutdown();
101
102
		NPError (WINAPI * pShutdown)();
103
		if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown ))
104
		{
105
            NPError nErr = (*pShutdown)(); (void)nErr;
106
			DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_Shutdown() failed!" );
107
		}
108
109
        BOOL bRet = (BOOL)::FreeLibrary( _plDLL ); (void)bRet;
110
		DBG_ASSERT( bRet, "### unloading plugin dll failed!" );
111
		_plDLL = NULL;
112
	}
113
}
114
115
//--------------------------------------------------------------------------------------------------
116
BOOL PluginComm_Impl::retrieveFunction( TCHAR* pName, void** ppFunc ) const
117
{
118
	if( ! _plDLL )
119
		return FALSE;
120
121
	*ppFunc = (void*)::GetProcAddress( _plDLL, pName );
122
123
	return (*ppFunc != NULL);
124
}
125
126
//--------------------------------------------------------------------------------------------------
127
128
long PluginComm_Impl::doIt()
129
{
130
	long nRet = 0;
131
	switch( m_eCall )
132
	{
133
	case eNP_Initialize:
134
	{
135
        TRACE( "eNP_Initialize" );
136
        NPError (WINAPI * pInit)( NPNetscapeFuncs* );
137
        if ((_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR &&
138
            (retrieveFunction( _T("NP_Initialize"), (void**)&pInit ) ||
139
             retrieveFunction( _T("NP_PluginInit"), (void**)&pInit )))
140
        {
141
            nRet = (*pInit)( &aNPNFuncs );
142
        }
143
        else
144
        {
145
            nRet = NPERR_GENERIC_ERROR;
146
        }
147
        DBG_ASSERT( nRet == NPERR_NO_ERROR, "### NP_Initialize() failed!" );
148
	}
149
	break;
150
	case eNPP_Destroy:
151
        TRACE( "eNPP_Destroy" );
152
		nRet = (_NPPfuncs.destroy
153
				? (*_NPPfuncs.destroy)(
154
					(NPP)m_aArgs[0],
155
					(NPSavedData**)m_aArgs[1] )
156
				: NPERR_GENERIC_ERROR);
157
		break;
158
	case eNPP_DestroyStream:
159
        TRACE( "eNPP_DestroyStream" );
160
		nRet =  (_NPPfuncs.destroystream
161
				 ? (*_NPPfuncs.destroystream)(
162
					 (NPP)m_aArgs[0],
163
					 (NPStream*)m_aArgs[1],
164
					 (NPError)(sal_IntPtr)m_aArgs[2] )
165
				 : NPERR_GENERIC_ERROR);
166
		break;
167
	case eNPP_New:
168
        TRACE( "eNPP_New" );
169
		nRet = (_NPPfuncs.newp
170
				? (*_NPPfuncs.newp)(
171
					(NPMIMEType)m_aArgs[0],
172
					(NPP)m_aArgs[1],
173
					(uint16)(sal_IntPtr)m_aArgs[2],
174
					(int16)(sal_IntPtr)m_aArgs[3],
175
					(char**)m_aArgs[4],
176
					(char**)m_aArgs[5],
177
					(NPSavedData*)m_aArgs[6] )
178
				: NPERR_GENERIC_ERROR);
179
		break;
180
	case eNPP_NewStream:
181
        TRACE( "eNPP_NewStream" );
182
		nRet = (_NPPfuncs.newstream
183
				? (*_NPPfuncs.newstream)(
184
					(NPP)m_aArgs[0],
185
					(NPMIMEType)m_aArgs[1],
186
					(NPStream*)m_aArgs[2],
187
					(NPBool)(sal_IntPtr)m_aArgs[3],
188
					(uint16*)m_aArgs[4] )
189
				: NPERR_GENERIC_ERROR);
190
		break;
191
	case eNPP_Print:
192
        TRACE( "eNPP_Print" );
193
		if (_NPPfuncs.print)
194
			(*_NPPfuncs.print)(
195
				(NPP)m_aArgs[0],
196
				(NPPrint*)m_aArgs[1] );
197
		break;
198
	case eNPP_SetWindow:
199
    {
200
        TRACE( "eNPP_SetWindow" );
201
        nRet = (_NPPfuncs.setwindow
202
				? (*_NPPfuncs.setwindow)(
203
					(NPP)m_aArgs[0],
204
                    (NPWindow*)m_aArgs[1] )
205
				: NPERR_GENERIC_ERROR);
206
		break;
207
    }
208
	case eNPP_StreamAsFile:
209
        TRACE( "eNPP_StreamAsFile" );
210
		if (_NPPfuncs.asfile)
211
			(*_NPPfuncs.asfile)(
212
				(NPP)m_aArgs[0],
213
				(NPStream*)m_aArgs[1],
214
				(char*)m_aArgs[2] );
215
		break;
216
	case eNPP_URLNotify:
217
        TRACE( "eNPP_URLNotify" );
218
		if (_NPPfuncs.urlnotify)
219
			(*_NPPfuncs.urlnotify)(
220
				(NPP)m_aArgs[0],
221
				(char*)m_aArgs[1],
222
				(NPReason)(sal_IntPtr)m_aArgs[2],
223
				m_aArgs[3] );
224
		break;
225
	case eNPP_Write:
226
        TRACEN( "eNPP_Write n=", (int32)m_aArgs[3] );
227
		nRet = (_NPPfuncs.write
228
				? (*_NPPfuncs.write)(
229
					(NPP)m_aArgs[0],
230
					(NPStream*)m_aArgs[1],
231
					(int32)m_aArgs[2],
232
					(int32)m_aArgs[3],
233
					m_aArgs[4] )
234
				: 0);
235
		break;
236
	case eNPP_WriteReady:
237
        TRACE( "eNPP_WriteReady" );
238
		nRet = (_NPPfuncs.writeready
239
				? (*_NPPfuncs.writeready)(
240
					(NPP)m_aArgs[0],
241
					(NPStream*)m_aArgs[1] )
242
				: 0);
243
		break;
244
	case eNPP_GetValue:
245
        TRACE( "eNPP_GetValue" );
246
		nRet = (_NPPfuncs.getvalue
247
				? (*_NPPfuncs.getvalue)(
248
					(NPP)m_aArgs[0],
249
					(NPPVariable)(int)m_aArgs[1],
250
					m_aArgs[2] )
251
				: NPERR_GENERIC_ERROR);
252
		break;
253
	case eNPP_SetValue:
254
        TRACE( "eNPP_SetValue" );
255
		nRet = (_NPPfuncs.setvalue
256
				? (*_NPPfuncs.setvalue)(
257
					(NPP)m_aArgs[0],
258
					(NPNVariable)(int)m_aArgs[1],
259
					m_aArgs[2] )
260
				: NPERR_GENERIC_ERROR);
261
		break;
262
	case eNPP_Shutdown:
263
	{
264
        TRACE( "eNPP_Shutdown" );
265
		NPP_ShutdownUPP pFunc;
266
		if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc ))
267
			(*pFunc)();
268
	}
269
	break;
270
    case eNPP_Initialize:
271
        TRACE( "eNPP_Initialize" );
272
        OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
273
	    break;
274
    case eNPP_GetJavaClass:
275
        TRACE( "eNPP_GetJavaClass" );
276
        OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
277
	    break;
278
	}
279
	return nRet;
280
}
281
282
//--------------------------------------------------------------------------------------------------
283
NPError PluginComm_Impl::NPP_Destroy( NPP instance, NPSavedData** save )
284
{
285
	DBG_ASSERT( _NPPfuncs.destroy, "### NPP_Destroy(): null pointer in NPP functions table!" );
286
	m_eCall = eNPP_Destroy;
287
	m_aArgs[0] = (void*)instance;
288
	m_aArgs[1] = (void*)save;
289
	return (NPError)execute();
290
}
291
292
//--------------------------------------------------------------------------------------------------
293
NPError PluginComm_Impl::NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason )
294
{
295
	DBG_ASSERT( _NPPfuncs.destroystream, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
296
	m_eCall = eNPP_DestroyStream;
297
	m_aArgs[0] = (void*)instance;
298
	m_aArgs[1] = (void*)stream;
299
	m_aArgs[2] = (void*)reason;
300
	return (NPError)execute();
301
}
302
303
//--------------------------------------------------------------------------------------------------
304
NPError PluginComm_Impl::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
305
								  char* argn[], char* argv[], NPSavedData *saved )
306
{
307
	DBG_ASSERT( _NPPfuncs.newp, "### NPP_New(): null pointer in NPP functions table!" );
308
	m_eCall = eNPP_New;
309
	m_aArgs[0] = (void*)pluginType;
310
	m_aArgs[1] = (void*)instance;
311
	m_aArgs[2] = (void*)mode;
312
	m_aArgs[3] = (void*)argc;
313
	m_aArgs[4] = (void*)argn;
314
	m_aArgs[5] = (void*)argv;
315
	m_aArgs[6] = (void*)saved;
316
	return (NPError)execute();
317
}
318
319
//--------------------------------------------------------------------------------------------------
320
NPError PluginComm_Impl::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
321
										NPBool seekable, uint16* stype )
322
{
323
	DBG_ASSERT( _NPPfuncs.newstream, "### NPP_NewStream(): null pointer in NPP functions table!" );
324
	m_eCall = eNPP_NewStream;
325
	m_aArgs[0] = (void*)instance;
326
	m_aArgs[1] = (void*)type;
327
	m_aArgs[2] = (void*)stream;
328
	m_aArgs[3] = (void*)seekable;
329
	m_aArgs[4] = (void*)stype;
330
	return (NPError)execute();
331
}
332
333
//--------------------------------------------------------------------------------------------------
334
void PluginComm_Impl::NPP_Print( NPP instance, NPPrint* platformPrint )
335
{
336
	DBG_ASSERT( _NPPfuncs.print, "### NPP_Print(): null pointer in NPP functions table!" );
337
	m_eCall = eNPP_Print;
338
	m_aArgs[0] = (void*)instance;
339
	m_aArgs[1] = (void*)platformPrint;
340
	execute();
341
}
342
343
//--------------------------------------------------------------------------------------------------
344
NPError PluginComm_Impl::NPP_SetWindow( NPP instance, NPWindow* window )
345
{
346
	DBG_ASSERT( _NPPfuncs.setwindow, "### NPP_SetWindow(): null pointer in NPP functions table!" );
347
	m_eCall = eNPP_SetWindow;
348
	m_aArgs[0] = (void*)instance;
349
	m_aArgs[1] = (void*)window;
350
	return (NPError)execute();
351
}
352
353
//--------------------------------------------------------------------------------------------------
354
void PluginComm_Impl::NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname )
355
{
356
	DBG_ASSERT( _NPPfuncs.asfile, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
357
	m_eCall = eNPP_StreamAsFile;
358
	m_aArgs[0] = (void*)instance;
359
	m_aArgs[1] = (void*)stream;
360
	m_aArgs[2] = (void*)fname;
361
	execute();
362
}
363
364
//--------------------------------------------------------------------------------------------------
365
void PluginComm_Impl::NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData )
366
{
367
	DBG_ASSERT( _NPPfuncs.urlnotify, "### NPP_URLNotify(): null pointer in NPP functions table!" );
368
	m_eCall = eNPP_URLNotify;
369
	m_aArgs[0] = (void*)instance;
370
	m_aArgs[1] = (void*)url;
371
	m_aArgs[2] = (void*)reason;
372
	m_aArgs[3] = notifyData;
373
	execute();
374
}
375
376
//--------------------------------------------------------------------------------------------------
377
int32 PluginComm_Impl::NPP_Write( NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer )
378
{
379
	DBG_ASSERT( _NPPfuncs.write, "### NPP_Write(): null pointer in NPP functions table!" );
380
	m_eCall = eNPP_Write;
381
	m_aArgs[0] = (void*)instance;
382
	m_aArgs[1] = (void*)stream;
383
	m_aArgs[2] = (void*)offset;
384
	m_aArgs[3] = (void*)len;
385
	m_aArgs[4] = buffer;
386
	return (NPError)execute();
387
}
388
389
//--------------------------------------------------------------------------------------------------
390
int32 PluginComm_Impl::NPP_WriteReady( NPP instance, NPStream* stream )
391
{
392
	DBG_ASSERT( _NPPfuncs.writeready, "### NPP_WriteReady(): null pointer in NPP functions table!" );
393
	m_eCall = eNPP_WriteReady;
394
	m_aArgs[0] = (void*)instance;
395
	m_aArgs[1] = (void*)stream;
396
	return execute();
397
}
398
399
//--------------------------------------------------------------------------------------------------
400
NPError PluginComm_Impl::NPP_GetValue( NPP instance, NPPVariable variable, void *ret_value )
401
{
402
	DBG_ASSERT( _NPPfuncs.getvalue, "### NPP_GetValue(): null pointer in NPP functions table!" );
403
	m_eCall = eNPP_GetValue;
404
	m_aArgs[0] = (void*)instance;
405
	m_aArgs[1] = (void*)variable;
406
	m_aArgs[2] = ret_value;
407
	return (NPError)execute();
408
}
409
410
//--------------------------------------------------------------------------------------------------
411
NPError PluginComm_Impl::NPP_SetValue( NPP instance, NPNVariable variable, void *set_value )
412
{
413
	DBG_ASSERT( _NPPfuncs.setvalue, "### NPP_SetValue(): null pointer in NPP functions table!" );
414
	m_eCall = eNPP_SetValue;
415
	m_aArgs[0] = (void*)instance;
416
	m_aArgs[1] = (void*)variable;
417
	m_aArgs[2] = set_value;
418
	return (NPError)execute();
419
}
420
421
//--------------------------------------------------------------------------------------------------
422
void * PluginComm_Impl::NPP_GetJavaClass()
423
{
424
	DBG_ERROR( "no java class available!" );
425
	return 0;
426
}
427
428
//--------------------------------------------------------------------------------------------------
429
NPError PluginComm_Impl::NPP_Initialize()
430
{
431
	return NPERR_NO_ERROR;
432
}
433
434
//--------------------------------------------------------------------------------------------------
435
void PluginComm_Impl::NPP_Shutdown()
436
{
437
	m_eCall = eNPP_Shutdown;
438
	execute();
439
}
(-)a/main/extensions/source/plugin/win/winmgr.cxx (+479 lines)
Line 0 Link Here
1
/**************************************************************
2
 * 
3
 * Licensed to the Apache Software Foundation (ASF) under one
4
 * or more contributor license agreements.  See the NOTICE file
5
 * distributed with this work for additional information
6
 * regarding copyright ownership.  The ASF licenses this file
7
 * to you under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in compliance
9
 * with the License.  You may obtain a copy of the License at
10
 * 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
12
 * 
13
 * Unless required by applicable law or agreed to in writing,
14
 * software distributed under the License is distributed on an
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
 * KIND, either express or implied.  See the License for the
17
 * specific language governing permissions and limitations
18
 * under the License.
19
 * 
20
 *************************************************************/
21
22
23
24
// MARKER(update_precomp.py): autogen include statement, do not remove
25
#include "precompiled_extensions.hxx"
26
27
#include "vcl/svapp.hxx"
28
#include "tools/fsys.hxx"
29
#include "tools/urlobj.hxx"
30
#include "osl/mutex.hxx"
31
32
#include "rtl/string.hxx"
33
#include "rtl/ustring.hxx"
34
#include "rtl/ustrbuf.hxx"
35
36
#include "plugin/impl.hxx"
37
38
#pragma warning (push,1)
39
#pragma warning (disable:4005)
40
41
    #include "tools/prewin.h"
42
43
    #include <windows.h>
44
    #include <string.h>
45
    #include <tchar.h>
46
    #include <winreg.h>
47
    #include <winbase.h>
48
    #include <objbase.h>
49
50
    #include "tools/postwin.h"
51
52
#pragma warning (pop)
53
54
#include <list>
55
#include <map>
56
#include <algorithm>
57
58
59
using namespace rtl;
60
using namespace std;
61
using namespace osl;
62
using namespace com::sun::star::uno;
63
using namespace com::sun::star::plugin;
64
65
typedef map< OString, OUString, less< OString > > PluginLocationMap;
66
67
68
#if OSL_DEBUG_LEVEL > 1
69
#include <stdio.h>
70
71
static void logPlugin( OUString const & path_ )
72
{
73
    static FILE * pFile = 0;
74
    if (! pFile)
75
    {
76
        WCHAR sFile[MAX_PATH];
77
        if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_PROFILE, NULL, 0, sFile ) )
78
        {
79
            if ( SUCCEEDED( StringCchCatW( sFile, MAX_PATH, L"plugins.log" ) ) )
80
            {
81
                pFile = _wfopen( sFile, L"a+" );
82
            }
83
        }
84
    }
85
86
    if ( pFile )
87
    {
88
        OString path( OUStringToOString( path_, RTL_TEXTENCODING_ASCII_US ) );
89
        fprintf( pFile, "%s\n", path.getStr() );
90
    }
91
}
92
#endif
93
94
//__________________________________________________________________________________________________
95
static void addPluginsFromPath( const TCHAR * pPluginsPath, PluginLocationMap & rPlugins )
96
{
97
	// append dll name pattern we are looking for
98
	TCHAR arPluginsPath[MAX_PATH];
99
	arPluginsPath[0] = 0;
100
101
	if (::rtl_str_indexOfStr( pPluginsPath, "%programfiles%" ) == 0)
102
	{
103
		const char * p = ::getenv( "ProgramFiles" );
104
		if (p)
105
		{
106
			::lstrcpy( arPluginsPath, p );
107
			pPluginsPath += 14;
108
		}
109
	}
110
	::lstrcat( arPluginsPath, pPluginsPath );
111
	::lstrcat( arPluginsPath, _T("\\") );
112
113
	TCHAR arPluginsPattern[MAX_PATH];
114
	::lstrcpy( arPluginsPattern, arPluginsPath );
115
	::lstrcat( arPluginsPattern, _T("NP*.DLL") );
116
117
	WIN32_FIND_DATA aFindData;
118
	HANDLE hFind = ::FindFirstFile( arPluginsPattern, &aFindData );
119
120
	while (hFind != INVALID_HANDLE_VALUE)
121
	{
122
		OString aName( aFindData.cFileName );
123
		aName.toAsciiLowerCase();
124
125
		// no netscape default plugin anymore...
126
		// and no double plugin dlls
127
		if ( !aName.equals( "npnul32.dll" ) &&
128
			 ! aName.equals( "npnrvp.dll" ) &&
129
			 rPlugins.find( aName ) == rPlugins.end())
130
		{
131
			TCHAR arComplete[MAX_PATH];
132
			::lstrcpy( arComplete, arPluginsPath );
133
			::lstrcat( arComplete, aFindData.cFileName );
134
135
			OUString path( OStringToOUString( arComplete, RTL_TEXTENCODING_MS_1252 ) );
136
			rPlugins[ aName ] = path;
137
#if OSL_DEBUG_LEVEL > 1
138
            logPlugin( path );
139
#endif
140
		}
141
142
		if (! ::FindNextFile( hFind, &aFindData ))
143
			break;
144
	}
145
146
	if (hFind != INVALID_HANDLE_VALUE)
147
		::FindClose( hFind );
148
}
149
//__________________________________________________________________________________________________
150
static void addPluginsFromPath( const OUString & rPath, PluginLocationMap & rPlugins )
151
{
152
	TCHAR arPluginsPath[MAX_PATH];
153
	DWORD dwPluginsPathSize = sizeof(arPluginsPath);
154
    arPluginsPath[dwPluginsPathSize-1] = 0;
155
156
	OString aStr( OUStringToOString( rPath, RTL_TEXTENCODING_MS_1252 ) );
157
	::strncpy( arPluginsPath, aStr.getStr(), dwPluginsPathSize );
158
159
	addPluginsFromPath( arPluginsPath, rPlugins );
160
}
161
162
163
//__________________________________________________________________________________________________
164
static void add_IE_Plugins( PluginLocationMap & rPlugins )
165
{
166
	HKEY hKey;
167
	TCHAR arCurrent[MAX_PATH];
168
	DWORD dwType, dwCurrentSize = sizeof(arCurrent);
169
170
	if (::RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\IE4\\SETUP"),
171
						0, KEY_READ, &hKey ) == ERROR_SUCCESS)
172
	{
173
		if (::RegQueryValueEx( hKey, _T("Path"), NULL, &dwType,
174
							   (LPBYTE)arCurrent, &dwCurrentSize ) == ERROR_SUCCESS &&
175
			(dwType == REG_SZ || dwType == REG_EXPAND_SZ))
176
		{
177
			// add \\Plugins
178
			::lstrcat( arCurrent, _T("\\Plugins") );
179
180
			addPluginsFromPath( arCurrent, rPlugins );
181
		}
182
		::RegCloseKey( hKey );
183
	}
184
}
185
186
//--------------------------------------------------------------------------------------------------
187
static void add_NS_keys( HKEY hKey, PluginLocationMap & rPlugins )
188
{
189
	TCHAR value[MAX_PATH];
190
	DWORD dwType, size = sizeof(value);
191
192
    // 4.7
193
    size = sizeof(value);
194
    if (::RegQueryValueEx(
195
        hKey, _T("Plugins Directory"), NULL, &dwType,
196
        (LPBYTE)value, &size ) == ERROR_SUCCESS &&
197
        (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
198
    {
199
        addPluginsFromPath( value, rPlugins );
200
    }
201
    // 6
202
    size = sizeof(value);
203
    if (::RegQueryValueEx(
204
        hKey, _T("Install Directory"), NULL, &dwType,
205
        (LPBYTE)value, &size ) == ERROR_SUCCESS &&
206
        (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
207
    {
208
        int n = size / sizeof (TCHAR);
209
        if ('\\' != value[ n -2 ])
210
        {
211
            value[ n -1 ] = '\\';
212
            value[ n ] = 0;
213
        }
214
        addPluginsFromPath( ::lstrcat( value, _T("Plugins") ), rPlugins );
215
    }
216
    size = sizeof(value);
217
    if (::RegQueryValueEx(
218
        hKey, _T("Plugins"), NULL, &dwType,
219
        (LPBYTE)value, &size ) == ERROR_SUCCESS &&
220
        (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
221
    {
222
        addPluginsFromPath( value, rPlugins );
223
    }
224
}
225
//--------------------------------------------------------------------------------------------------
226
static void add_NS_lookupRecursive( HKEY hKey, PluginLocationMap & rPlugins )
227
{
228
    add_NS_keys( hKey, rPlugins );
229
230
	TCHAR keyName[MAX_PATH];
231
    DWORD dwIndex = 0, size = sizeof (keyName);
232
233
    while (::RegEnumKeyEx( hKey, dwIndex, keyName, &size, NULL, NULL, NULL, NULL ) == ERROR_SUCCESS)
234
    {
235
        size = sizeof (keyName);
236
        HKEY hSubKey;
237
        if (::RegOpenKeyEx( hKey, keyName, 0, KEY_READ, &hSubKey ) == ERROR_SUCCESS)
238
        {
239
            add_NS_lookupRecursive( hSubKey, rPlugins );
240
            ::RegCloseKey( hSubKey );
241
        }
242
        ++dwIndex;
243
    }
244
}
245
//__________________________________________________________________________________________________
246
static void add_MozPlugin( HKEY hKey, PluginLocationMap & rPlugins )
247
{
248
	TCHAR value[MAX_PATH];
249
	DWORD dwType, size = sizeof(value);
250
251
    size = sizeof(value);
252
    if (::RegQueryValueEx(
253
        hKey, _T("Path"), NULL, &dwType,
254
        (LPBYTE)value, &size ) == ERROR_SUCCESS &&
255
        (dwType == REG_SZ || dwType == REG_EXPAND_SZ))
256
    {
257
		OUString aUPath( OStringToOUString( value, RTL_TEXTENCODING_MS_1252 ) );
258
		INetURLObject aURL( aUPath );
259
		OString aName( OUStringToOString( aURL.GetName().toAsciiLowerCase(), RTL_TEXTENCODING_MS_1252 ) );
260
261
		// no netscape default plugin anymore...
262
		// and no double plugin dlls
263
		if ( !aName.equals( "npnul32.dll" ) &&
264
			 ! aName.equals( "npnrvp.dll" ) &&
265
			 rPlugins.find( aName ) == rPlugins.end())
266
		{
267
			rPlugins[ aName ] = aUPath;
268
#if OSL_DEBUG_LEVEL > 1
269
            logPlugin( aUPath );
270
#endif
271
		}
272
    }
273
}
274
static void add_MozillaPlugin( HKEY hKey, PluginLocationMap & rPlugins )
275
{
276
	TCHAR keyName[MAX_PATH];
277
    DWORD dwIndex = 0, size = sizeof (keyName);
278
279
    while (::RegEnumKeyEx( hKey, dwIndex, keyName, &size, NULL, NULL, NULL, NULL ) == ERROR_SUCCESS)
280
    {
281
        size = sizeof (keyName);
282
        HKEY hSubKey;
283
        if (::RegOpenKeyEx( hKey, keyName, 0, KEY_READ, &hSubKey ) == ERROR_SUCCESS)
284
        {
285
            add_MozPlugin( hSubKey, rPlugins );
286
            ::RegCloseKey( hSubKey );
287
        }
288
        ++dwIndex;
289
    }
290
}
291
//__________________________________________________________________________________________________
292
static void add_NS_Plugins( PluginLocationMap & rPlugins )
293
{
294
	HKEY hKey;
295
    // Netscape
296
	if (::RegOpenKeyEx(
297
        HKEY_LOCAL_MACHINE, _T("Software\\Netscape"),
298
        0, KEY_READ, &hKey ) == ERROR_SUCCESS)
299
	{
300
        add_NS_lookupRecursive( hKey, rPlugins );
301
		::RegCloseKey( hKey );
302
    }
303
    // Mozilla
304
	if (::RegOpenKeyEx(
305
        HKEY_LOCAL_MACHINE, _T("Software\\Mozilla"),
306
        0, KEY_READ, &hKey ) == ERROR_SUCCESS)
307
	{
308
        add_NS_lookupRecursive( hKey, rPlugins );
309
		::RegCloseKey( hKey );
310
    }
311
    // Mozilla - plugins
312
	if (::RegOpenKeyEx(
313
        HKEY_LOCAL_MACHINE, _T("Software\\MozillaPlugins"),
314
        0, KEY_READ, &hKey ) == ERROR_SUCCESS)
315
	{
316
        add_MozillaPlugin( hKey, rPlugins );
317
		::RegCloseKey( hKey );
318
    }
319
}
320
321
//__________________________________________________________________________________________________
322
static void add_SO_Plugins( PluginLocationMap & rPlugins )
323
{
324
	const Sequence< OUString > & rPaths = PluginManager::getAdditionalSearchPaths();
325
326
	const OUString * pPaths = rPaths.getConstArray();
327
	for ( UINT32 nPos = rPaths.getLength(); nPos--; )
328
	{
329
		addPluginsFromPath( pPaths[nPos], rPlugins );
330
	}
331
}
332
333
//__________________________________________________________________________________________________
334
Sequence< PluginDescription > XPluginManager_Impl::impl_getPluginDescriptions(void) throw()
335
{
336
	Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
337
	static Sequence<PluginDescription > s_aDescriptions( 0 );
338
	static bool s_bInit = FALSE;
339
340
	if (! s_bInit)
341
	{
342
		// collect all distinct plugin dlls
343
		PluginLocationMap aPlugins;
344
		add_SO_Plugins( aPlugins );
345
		add_NS_Plugins( aPlugins );
346
		add_IE_Plugins( aPlugins );
347
348
		// collect mime types of plugin dlls
349
		for ( PluginLocationMap::iterator iPos( aPlugins.begin() );
350
			  iPos != aPlugins.end();
351
			  ++iPos )
352
		{
353
			TCHAR arFileName[MAX_PATH];
354
			DWORD dwDummy, dwSize;
355
356
			// DLL name
357
			OUString aName( (*iPos).second.getStr() );
358
359
			OString aStr( OUStringToOString( aName, RTL_TEXTENCODING_MS_1252 ) );
360
			::strcpy( arFileName, aStr.getStr() );
361
			dwSize = ::GetFileVersionInfoSize( arFileName, &dwDummy );
362
363
            if ( !dwSize )
364
                continue;
365
366
			char * pVersionData = new char[dwSize];
367
			if (pVersionData && ::GetFileVersionInfo( arFileName, 0, dwSize, pVersionData ))
368
			{
369
				// optional comment
370
				OUString aComment;
371
372
				TCHAR * pInfo = NULL, * pInfo2 = NULL;
373
				UINT nSize = 0;
374
				if (::VerQueryValue( pVersionData, _T("\\StringFileInfo\\040904E4\\ProductName"),
375
									 (void**)&pInfo, &nSize ) && pInfo)
376
				{
377
					aComment.operator=( OStringToOUString( OString(pInfo), RTL_TEXTENCODING_MS_1252 ) );
378
				}
379
380
				// mandatory mime type and file extensions
381
				if (::VerQueryValue( pVersionData, _T("\\StringFileInfo\\040904E4\\MIMEType"),
382
									 (void**)&pInfo, &nSize ) && pInfo &&
383
					::VerQueryValue( pVersionData, _T("\\StringFileInfo\\040904E4\\FileExtents"),
384
									 (void**)&pInfo2, &nSize ) && pInfo2)
385
				{
386
					OString aStr2( pInfo2 );
387
					OString aExt( aStr2 );
388
					OString aStr( pInfo );
389
					OString aMIME( aStr );
390
					aMIME.trim();
391
392
                    // count mime tokens
393
					USHORT nToken = 0;
394
                    if (aMIME.getLength())
395
                    {
396
                        ++nToken;
397
                        for ( sal_Int32 n = aMIME.getLength(); n--; )
398
                        {
399
                            if (aMIME[ n ] == '|')
400
                            {
401
                                ++nToken;
402
                            }
403
                        }
404
                    }
405
                    sal_Int32 nIndex = 0, nIndex2 = 0;
406
407
					UINT32 nStart = s_aDescriptions.getLength();
408
					s_aDescriptions.realloc( nStart + nToken );
409
					PluginDescription* pDescriptions = s_aDescriptions.getArray();
410
					// for every MIME Type
411
                    sal_Int32 nTok = 0;
412
                    while (true)
413
					{
414
                        if (nIndex < 0 || nIndex2 < 0)
415
                            break;
416
417
						PluginDescription & rDescr = pDescriptions[nStart+nTok];
418
                        OString aMIMEToken( aMIME.getToken( 0, '|', nIndex ) );
419
                        OString aExtToken2( aExt.getToken( 0, '|', nIndex2 ) );
420
                        if( aMIMEToken.getLength() == 0 || aExtToken2.getLength() == 0 )
421
                            continue;
422
                        
423
						rDescr.Mimetype = OUString(
424
                            aMIMEToken.getStr(), aMIMEToken.getLength(), RTL_TEXTENCODING_MS_1252 );
425
                        if (! rDescr.Mimetype.getLength())
426
                            break;
427
428
						OUString aExtToken( aExtToken2.getStr(), aExtToken2.getLength(), RTL_TEXTENCODING_MS_1252 );
429
						rDescr.PluginName = aName;
430
						rDescr.Description = aComment;
431
432
						sal_Int32 nPos = 0, nLen = aExtToken.getLength();
433
						OUString aExtensions( OUString::createFromAscii( nLen ? "*." : "*.*" ) );
434
435
						for ( ; nPos < nLen; ++nPos )
436
						{
437
							sal_Unicode c = aExtToken[nPos];
438
							switch (c)
439
							{
440
							case ',':
441
							case ';':
442
								aExtensions += OUString::createFromAscii( ";*." );
443
							case ' ':
444
								break;
445
							case '*':
446
								if (nPos < (nLen-1) && aExtToken[ nPos+1 ] == '.')
447
								{
448
									++nPos;
449
									break;
450
								}
451
							default:
452
								aExtensions += OUString( &c, 1 );
453
							}
454
						}
455
						rDescr.Extension = aExtensions;
456
457
                        ++nTok;
458
					}
459
460
                    if (nToken != nTok)
461
                    {
462
                        s_aDescriptions.realloc( nTok );
463
                    }
464
				}
465
#if OSL_DEBUG_LEVEL > 1
466
				else
467
					DBG_ERROR( "### cannot get MIME type or extensions!" );
468
#endif
469
			}
470
			if (pVersionData)
471
				delete[] pVersionData;
472
		}
473
474
		s_bInit = TRUE;
475
	}
476
	return s_aDescriptions;
477
}
478
479
(-)a/main/postprocess/packcomponents/makefile.mk (+1 lines)
Lines 288-293 my_components += ldapbe2 Link Here
288
288
289
.IF "$(WITH_MOZILLA)" != "NO"
289
.IF "$(WITH_MOZILLA)" != "NO"
290
my_components += \
290
my_components += \
291
    pl \
291
    xmlsecurity \
292
    xmlsecurity \
292
    xsec_fw \
293
    xsec_fw \
293
    xsec_xmlsec
294
    xsec_xmlsec
(-)a/main/scp2/source/ooo/file_library_ooo.scp (-1 / +6 lines)
Lines 1144-1149 STD_LIB_FILE(gid_File_Lib_DeploymentMisc, deplmisc) Link Here
1144
STD_LIB_FILE(gid_File_Lib_DeploymentMisc, deploymentmisc)
1144
STD_LIB_FILE(gid_File_Lib_DeploymentMisc, deploymentmisc)
1145
#endif
1145
#endif
1146
1146
1147
1148
#ifndef WITHOUT_MOZILLA
1149
STD_LIB_FILE( gid_File_Lib_Pl , pl)
1150
#endif
1151
1152
1147
#ifdef OS2
1153
#ifdef OS2
1148
STD_LIB_FILE( gid_File_Lib_Preload, preloadg)
1154
STD_LIB_FILE( gid_File_Lib_Preload, preloadg)
1149
#else
1155
#else
1150
- 

Return to issue 121772