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
 *