~ubuntu-branches/ubuntu/intrepid/xulrunner-1.9/intrepid

« back to all changes in this revision

Viewing changes to mozilla/modules/plugin/samples/default/mac/NullPlugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Fabien Tassin
  • Date: 2008-02-13 11:47:21 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080213114721-7om0mgzngvuk9czv
Tags: 1.9~b3+nobinonly-0ubuntu1
* release FIREFOX_3_0b3_RELEASE

[ Alexander Sack ]
* submit patch that ships xpcshell to bugzilla
  - rename debian/patches/ship_xpcshell.patch =>
           debian/patches/bz410617_att295212_ship_xpcshell.patch
  - update debian/patches/series
* fix tooltip in epiphany: previously displayed out of screen bounds
  (LP: #37507)
  - add debian/patches/bz233371_att297343_fix_outofscreen_embed_tooltip.patch
  - update debian/patches/series
* use default upstream gcc tweaks for improved performance - especially of the
  javascript engine
  - update debian/rules
* update global extension/plugin patch to apply cleanly against latest code
  - update debian/patches/bzXXX_gre_extension_plugin_support.patch
* fix pyxpcom build failure introduced by recent commit
  - add debian/patches/bzXXX_fix_pyxpcom_build_failure.patch
  - update debian/patches/series
* add distro independent global install locations for extensions,
  /usr/lib/mozilla/extensions and /usr/share/mozilla/extensions
  - update debian/xulrunner-1.9.dirs
* support embedded tarball layout when either there is a *.tar.bz2 in orig tarball
  or if DEBIAN_MOZCLIENT_EMBEDDED is not unset (you will need this to produce embedded
  tarballs during |get-orig-source|
  - update debian/rules
* bump minimum libnss3-dev build requirements to >= 3.12.0~1.9b3
  - update debian/control
* bump minimum libnspr4-dev build requirements to >= 4.7.0~1.9b3
  - update debian/control

[ Fabien Tassin ]
* Drop patches applied upstream
  - drop debian/patches/bz410617_att295212_ship_xpcshell.patch
  - drop debian/patches/bz404634_att294921.patch
  - drop debian/patches/bz386610_python2.5_ftbfs_amd64.patch
  - drop debian/patches/bz373918_att295042.patch
  - drop debian/patches/bz408062_unstable_pc.patch
  - drop debian/patches/bz384304_fix_recursive_symlinks.patch
  - update debian/patches/series
* Refresh diverged patches:
  - update debian/patches/bzXXX_pc_honour_system_nspr_nss.patch
  - update debian/patches/rename_venkman_addon.patch
  - update debian/patches/bz344818_cairo_xrender.patch
* Install links for all .so libs in the -dev package
  - update debian/patches/dont_install_so_in_dev.patch
* Bump gtk requirement to 2.12 as per Mozilla bug 412432
  - update debian/control
* Add #DEBHELPER# token to postinst/prerm scripts
  - update debian/xulrunner-1.9.{postinst,prerm}
* Install previously missed libdbusservice.so
  - update debian/xulrunner-1.9.install
* Update venkman patch to also rename locales
  - update debian/patches/rename_venkman_addon.patch
* Bump requirement for system cairo to >= 1.5.8 as we now need
  the newly added cairo_path_extents()
  - update debian/rules
* Include mozilla-devscripts file using -include so ifneq could be omitted
  - update debian/rules
* Fix missing .so symlinks regression
  - update debian/patches/dont_install_so_in_dev.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
 
/* ***** BEGIN LICENSE BLOCK *****
3
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 
 *
5
 
 * The contents of this file are subject to the Mozilla Public License Version
6
 
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 
 * the License. You may obtain a copy of the License at
8
 
 * http://www.mozilla.org/MPL/
9
 
 *
10
 
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 
 * for the specific language governing rights and limitations under the
13
 
 * License.
14
 
 *
15
 
 * The Original Code is Mozilla Communicator client code.
16
 
 *
17
 
 * The Initial Developer of the Original Code is
18
 
 * Netscape Communications Corporation.
19
 
 * Portions created by the Initial Developer are Copyright (C) 1998
20
 
 * the Initial Developer. All Rights Reserved.
21
 
 *
22
 
 * Contributor(s):
23
 
 *  Josh Aas <josh@mozilla.com>
24
 
 *
25
 
 * Alternatively, the contents of this file may be used under the terms of
26
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
27
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
29
 
 * of those above. If you wish to allow use of your version of this file only
30
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
31
 
 * use your version of this file under the terms of the MPL, indicate your
32
 
 * decision by deleting the provisions above and replace them with the notice
33
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
34
 
 * the provisions above, a recipient may use your version of this file under
35
 
 * the terms of any one of the MPL, the GPL or the LGPL.
36
 
 *
37
 
 * ***** END LICENSE BLOCK ***** */
38
 
 
39
 
 
40
 
#include "npapi.h"
41
 
 
42
 
#include <Carbon/Carbon.h>
43
 
#include <CoreFoundation/CoreFoundation.h>
44
 
 
45
 
#include <string.h>
46
 
#include <ctype.h>
47
 
#include <stdio.h>
48
 
 
49
 
#define PLUGINFINDER_COMMAND_BEGINNING "javascript:window.open(\""
50
 
#define PLUGINFINDER_COMMAND_END "\",\"plugin\",\"toolbar=no,status=no,resizable=no,scrollbars=no,height=252,width=626\");"
51
 
#define PLUGINFINDER_COMMAND_END2 "\",\"plugin\",\"toolbar=no,status=no,resizable=yes,scrollbars=yes,height=252,width=626\");"
52
 
 
53
 
 
54
 
// Instance state information about the plugin.
55
 
class CPlugin
56
 
{
57
 
public:
58
 
  enum HiliteState { kUnhilited = 0, kHilited = 1 };  
59
 
 
60
 
  static NPError Initialize();
61
 
  static void Shutdown();
62
 
 
63
 
  // no ctor because CPlugin is allocated and constructed by hand.
64
 
  // ideally, this should use placement |new|.
65
 
 
66
 
  void Constructor(NPP instance, NPMIMEType type, uint16 mode, int16 argc, char* argn[], char* argv[]);
67
 
  void Destructor();
68
 
 
69
 
  void SetWindow(NPWindow* window);
70
 
  void Print(NPPrint* printInfo);
71
 
  Boolean HandleEvent(EventRecord*);
72
 
 
73
 
protected:
74
 
  void Draw(HiliteState hilite);
75
 
  void DrawString(const unsigned char* text, short width, short height, short centerX, Rect drawRect);
76
 
  void MouseDown();
77
 
 
78
 
  Boolean FocusDraw();
79
 
  void RestoreDraw();
80
 
      
81
 
  void DetermineURL(int16 argc, char* argn[], char* argv[]);
82
 
  char* MakeDefaultURL(void);
83
 
  void AddMimeTypeToList(StringPtr cTypeString);
84
 
  Boolean CheckMimeTypes();
85
 
  void AskAndLoadURL();
86
 
  void RefreshPluginPage();
87
 
      
88
 
  Ptr New(UInt32 size);
89
 
  void Delete(Ptr ptr);
90
 
 
91
 
  Boolean IsPluginHidden(int16 argc, char* argn[], char* argv[]);
92
 
 
93
 
private:
94
 
  static CIconHandle sIconHandle;
95
 
  static CursHandle sHandCursor;
96
 
  static char* sAltText;
97
 
  static char* sInstallCommand;
98
 
  static char* sDefaultPage;
99
 
  static char* sRefreshText;
100
 
  static char* sJavaScriptPage;
101
 
 
102
 
  NPP fInstance;
103
 
  NPWindow* fWindow;
104
 
  uint16 fMode;
105
 
  NPMIMEType fType;
106
 
  char* fPageURL;
107
 
  char* fFileURL;
108
 
  NPBool m_bOffline;
109
 
  NPBool m_bJavaScript;
110
 
 
111
 
  GrafPtr fSavePort;
112
 
  RgnHandle fSaveClip;
113
 
  Rect fRevealedRect;
114
 
  short fSavePortTop;
115
 
  short fSavePortLeft;
116
 
  Boolean fUserInstalledPlugin;
117
 
  Boolean fHiddenPlugin;
118
 
  Boolean fAskedLoadURL;
119
 
};
120
 
 
121
 
CIconHandle CPlugin::sIconHandle = NULL;
122
 
CursHandle CPlugin::sHandCursor = NULL;
123
 
char* CPlugin::sAltText = NULL;
124
 
char* CPlugin::sInstallCommand = NULL; 
125
 
char* CPlugin::sDefaultPage = NULL;
126
 
char* CPlugin::sRefreshText = NULL;
127
 
char* CPlugin::sJavaScriptPage = NULL;
128
 
 
129
 
extern short gResFile;
130
 
 
131
 
// 'cicn'
132
 
const short rBrokenPluginIcon = 326;
133
 
 
134
 
// 'CURS'
135
 
const short rHandCursor = 128;
136
 
 
137
 
// 'STR '
138
 
const short rDefaultPluginURL = 128;
139
 
const short rAltTextString = 129;
140
 
const short rJavaScriptInstallCommand = 130;
141
 
const short rRefreshTextString = 131;
142
 
const short rJavaScriptPageURL = 132;
143
 
 
144
 
// 'STR#'
145
 
const short rTypeListStrings = 129;
146
 
 
147
 
static const char szPluginFinderCommandBeginning[] = PLUGINFINDER_COMMAND_BEGINNING;
148
 
static const char szPluginFinderCommandEnd[] = PLUGINFINDER_COMMAND_END;
149
 
 
150
 
 
151
 
NPError NPP_Initialize(void)
152
 
{
153
 
  return CPlugin::Initialize();
154
 
}
155
 
 
156
 
 
157
 
void NPP_Shutdown(void)
158
 
{
159
 
  CPlugin::Shutdown();
160
 
}
161
 
 
162
 
 
163
 
NPError NPP_New(NPMIMEType type, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData*)
164
 
{
165
 
  if (!instance)
166
 
    return NPERR_INVALID_INSTANCE_ERROR;
167
 
    
168
 
  CPlugin* This = (CPlugin*) (char*)NPN_MemAlloc(sizeof(CPlugin));
169
 
  instance->pdata = This;
170
 
  if (This) {
171
 
    This->Constructor(instance, type, mode, argc, argn, argv);
172
 
    return NPERR_NO_ERROR;
173
 
  }
174
 
  else {
175
 
    return NPERR_OUT_OF_MEMORY_ERROR;
176
 
  }
177
 
}
178
 
 
179
 
 
180
 
NPError NP_LOADDS
181
 
NPP_Destroy(NPP instance, NPSavedData** /*save*/)
182
 
{
183
 
  if (!instance)
184
 
    return NPERR_INVALID_INSTANCE_ERROR;
185
 
 
186
 
  CPlugin* This = (CPlugin*) instance->pdata;
187
 
  if (This) {
188
 
    This->Destructor();
189
 
    NPN_MemFree(This);
190
 
    instance->pdata = NULL;
191
 
  }
192
 
 
193
 
  return NPERR_NO_ERROR;
194
 
}
195
 
 
196
 
 
197
 
NPError NPP_SetWindow(NPP instance, NPWindow* window)
198
 
{
199
 
  if (!instance)
200
 
    return NPERR_INVALID_INSTANCE_ERROR;
201
 
 
202
 
  CPlugin* This = (CPlugin*) instance->pdata;
203
 
  if (This)
204
 
    This->SetWindow(window);
205
 
 
206
 
  return NPERR_NO_ERROR;
207
 
}
208
 
 
209
 
 
210
 
NPError NP_LOADDS
211
 
NPP_NewStream(NPP instance,
212
 
              NPMIMEType /*type*/,
213
 
              NPStream* /*stream*/, 
214
 
              NPBool /*seekable*/,
215
 
              uint16* /*stype*/)
216
 
{
217
 
  if (!instance)
218
 
    return NPERR_INVALID_INSTANCE_ERROR;
219
 
 
220
 
  return NPERR_NO_ERROR;
221
 
}
222
 
 
223
 
 
224
 
int32 STREAMBUFSIZE = 0X0FFFFFFF;   // If we are reading from a file in NPAsFile
225
 
                                    // mode so we can take any size stream in our
226
 
                                    // write call (since we ignore it)
227
 
 
228
 
 
229
 
int32 NP_LOADDS
230
 
NPP_WriteReady(NPP /*instance*/, NPStream* /*stream*/)
231
 
{
232
 
  return STREAMBUFSIZE; // Number of bytes ready to accept in NPP_Write()
233
 
}
234
 
 
235
 
 
236
 
int32 NP_LOADDS
237
 
NPP_Write(NPP /*instance*/, NPStream* /*stream*/, int32 /*offset*/, int32 len, void* /*buffer*/)
238
 
{
239
 
  return len; // The number of bytes accepted
240
 
}
241
 
 
242
 
 
243
 
NPError NP_LOADDS
244
 
NPP_DestroyStream(NPP instance, NPStream* /*stream*/, NPError /*reason*/)
245
 
{
246
 
  if (!instance)
247
 
    return NPERR_INVALID_INSTANCE_ERROR;
248
 
 
249
 
  return NPERR_NO_ERROR;
250
 
}
251
 
 
252
 
 
253
 
void NP_LOADDS
254
 
NPP_StreamAsFile(NPP /*instance*/, NPStream */*stream*/, const char* /*fname*/)
255
 
{
256
 
}
257
 
 
258
 
 
259
 
void NP_LOADDS
260
 
NPP_Print(NPP instance, NPPrint* printInfo)
261
 
{
262
 
  if (!printInfo)
263
 
    return;
264
 
 
265
 
  if (instance) {
266
 
    if (printInfo->mode == NP_FULL) {
267
 
      printInfo->print.fullPrint.pluginPrinted = FALSE; // Do the default
268
 
    }
269
 
    else { // If not fullscreen, we must be embedded
270
 
      CPlugin* This = (CPlugin*)instance->pdata;
271
 
      if (This)
272
 
        This->Print(printInfo);
273
 
    }
274
 
  }
275
 
}
276
 
 
277
 
 
278
 
// Mac-only
279
 
int16 NPP_HandleEvent(NPP instance, void* event)
280
 
{
281
 
  if (instance) {
282
 
    CPlugin* This = (CPlugin*) instance->pdata;
283
 
    if (This && event)
284
 
      return This->HandleEvent((EventRecord*) event);
285
 
  }
286
 
 
287
 
  return FALSE;
288
 
}
289
 
 
290
 
 
291
 
void NPP_URLNotify(NPP /*instance*/, const char* /*url*/, NPReason /*reason*/, void* /*notifyData*/)
292
 
{
293
 
}
294
 
 
295
 
 
296
 
#ifdef OJI
297
 
jref NPP_GetJavaClass(void)
298
 
{
299
 
  return NULL;
300
 
}
301
 
#endif /* OJI */
302
 
 
303
 
 
304
 
NPError CPlugin::Initialize()
305
 
{
306
 
  Handle string;
307
 
  short saveResFile = CurResFile();
308
 
 
309
 
  UseResFile(gResFile);
310
 
 
311
 
  // Get Resources
312
 
  CPlugin::sIconHandle = GetCIcon(rBrokenPluginIcon);
313
 
  CPlugin::sHandCursor = GetCursor(rHandCursor);
314
 
 
315
 
  // Get "alt text" string
316
 
  string = Get1Resource('STR ', rAltTextString);
317
 
  if (string && *string) {
318
 
    short stringLen = (*string)[0];
319
 
    CPlugin::sAltText = (char*)NPN_MemAlloc(stringLen +1);
320
 
    if (CPlugin::sAltText) {
321
 
      short src = 1;
322
 
      short dest = 0;
323
 
      while (src <= stringLen)
324
 
        CPlugin::sAltText[dest++] = (*string)[src++];
325
 
      CPlugin::sAltText[dest++] = 0;
326
 
    }
327
 
  }
328
 
  ReleaseResource(string);
329
 
 
330
 
  // Get "refresh text" string
331
 
  string = Get1Resource('STR ', rRefreshTextString);
332
 
  if (string && *string) {
333
 
    short stringLen = (*string)[0];
334
 
    CPlugin::sRefreshText = (char*)NPN_MemAlloc(stringLen + 1);
335
 
    if (CPlugin::sRefreshText) {
336
 
      short src = 1;
337
 
      short dest = 0;
338
 
      while (src <= stringLen)
339
 
        CPlugin::sRefreshText[dest++] = (*string)[src++];
340
 
      CPlugin::sRefreshText[dest++] = 0;
341
 
    }
342
 
  }
343
 
  ReleaseResource(string);
344
 
 
345
 
  // Get JavaScript install command string
346
 
  string = Get1Resource('STR ', rJavaScriptInstallCommand);
347
 
  if (string && *string) {
348
 
    short stringLen = (*string)[0];
349
 
    CPlugin::sInstallCommand = (char*)NPN_MemAlloc(stringLen + 1);
350
 
    if (CPlugin::sInstallCommand) {
351
 
      short src = 1;
352
 
      short dest = 0;
353
 
      while (src <= stringLen)
354
 
        CPlugin::sInstallCommand[dest++] = (*string)[src++];
355
 
      CPlugin::sInstallCommand[dest++] = 0;
356
 
    }
357
 
  }
358
 
  ReleaseResource(string);
359
 
 
360
 
  // Get default plug-in page URL
361
 
  string = Get1Resource('STR ', rDefaultPluginURL);
362
 
  if (string && *string) {
363
 
    short stringLen = (*string)[0];
364
 
    CPlugin::sDefaultPage = (char*)NPN_MemAlloc(stringLen + 1);
365
 
    if (CPlugin::sDefaultPage) {
366
 
      short src = 1;
367
 
      short dest = 0;
368
 
      while (src <= stringLen)
369
 
        CPlugin::sDefaultPage[dest++] = (*string)[src++];
370
 
      CPlugin::sDefaultPage[dest++] = 0;
371
 
    }
372
 
  }
373
 
  ReleaseResource(string);
374
 
 
375
 
  // Get javascript plug-in page URL
376
 
  string = Get1Resource('STR ', rJavaScriptPageURL);
377
 
  if (string && *string) {
378
 
    short stringLen = (*string)[0];
379
 
    CPlugin::sJavaScriptPage = (char*)NPN_MemAlloc(stringLen + 1);
380
 
    if (CPlugin::sJavaScriptPage) {
381
 
      short src = 1;
382
 
      short dest = 0;
383
 
      while (src <= stringLen)
384
 
        CPlugin::sJavaScriptPage[dest++] = (*string)[src++];
385
 
      CPlugin::sJavaScriptPage[dest++] = 0;
386
 
    }
387
 
  }
388
 
  ReleaseResource(string);
389
 
 
390
 
  UseResFile(saveResFile);
391
 
 
392
 
  return NPERR_NO_ERROR;
393
 
}
394
 
 
395
 
 
396
 
void CPlugin::Shutdown()
397
 
{
398
 
  if (CPlugin::sIconHandle)
399
 
    ::ReleaseResource((Handle) CPlugin::sIconHandle);
400
 
  if (CPlugin::sHandCursor)
401
 
    ::ReleaseResource((Handle) CPlugin::sHandCursor);
402
 
 
403
 
  if (CPlugin::sAltText)
404
 
    NPN_MemFree(CPlugin::sAltText);
405
 
  if (CPlugin::sInstallCommand)
406
 
    NPN_MemFree(CPlugin::sInstallCommand);
407
 
  if (CPlugin::sDefaultPage)
408
 
    NPN_MemFree(CPlugin::sDefaultPage);
409
 
  if (CPlugin::sRefreshText)
410
 
    NPN_MemFree(CPlugin::sRefreshText);
411
 
}
412
 
 
413
 
 
414
 
void CPlugin::Constructor(NPP instance, NPMIMEType type, uint16 mode, int16 argc, char* argn[], char* argv[])
415
 
{
416
 
  fWindow = NULL;
417
 
  fPageURL = NULL;
418
 
  fFileURL = NULL;
419
 
  fInstance = instance;
420
 
  fMode = mode; // Mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h)
421
 
  fAskedLoadURL = false;
422
 
  fUserInstalledPlugin = false;
423
 
  
424
 
  // Save a copy of our mime type string
425
 
  short typeLength = strlen(type);
426
 
  fType = (char*)NPN_MemAlloc(typeLength+1);
427
 
  if (fType)
428
 
    strcpy(fType, type);
429
 
  
430
 
  // Make a handy region for use in FocusDraw
431
 
  fSaveClip = NewRgn();
432
 
 
433
 
  // determine if the plugin is specified as HIDDEN
434
 
  fHiddenPlugin = IsPluginHidden(argc, argn, argv);
435
 
 
436
 
  // Get some information about our environment
437
 
  NPN_GetValue(fInstance, NPNVisOfflineBool, (void *)&m_bOffline);
438
 
  NPN_GetValue(fInstance, NPNVjavascriptEnabledBool, (void *)&m_bJavaScript);
439
 
 
440
 
  // Figure out what URL we will go to
441
 
  DetermineURL(argc, argn, argv);
442
 
}
443
 
 
444
 
 
445
 
void CPlugin::Destructor()
446
 
{
447
 
  if (fSaveClip)
448
 
    DisposeRgn(fSaveClip);
449
 
  
450
 
  if (fType)
451
 
    NPN_MemFree(fType);
452
 
  if (fFileURL)
453
 
    NPN_MemFree(fFileURL);
454
 
  if (fPageURL)
455
 
    NPN_MemFree(fPageURL);
456
 
}    
457
 
 
458
 
 
459
 
void CPlugin::SetWindow(NPWindow* window)
460
 
{
461
 
  fWindow = window;
462
 
}
463
 
 
464
 
 
465
 
// To print, we need to retrieve the printing window from the printInfo,
466
 
// temporarily make it our window, draw into it, and restore the window.
467
 
void CPlugin::Print(NPPrint* printInfo)
468
 
{
469
 
  NPWindow* printWindow = &(printInfo->print.embedPrint.window);
470
 
 
471
 
  NPWindow* oldWindow = fWindow;
472
 
  fWindow = printWindow;
473
 
 
474
 
  if (FocusDraw()) {
475
 
    Draw(kUnhilited);
476
 
    RestoreDraw();
477
 
  }
478
 
 
479
 
  fWindow = oldWindow;
480
 
}
481
 
 
482
 
 
483
 
Boolean CPlugin::HandleEvent(EventRecord* ev)
484
 
{
485
 
  Boolean eventHandled = false;
486
 
  
487
 
  switch (ev->what)
488
 
  {
489
 
    case mouseDown:
490
 
      MouseDown();
491
 
      eventHandled = true;
492
 
      break;
493
 
 
494
 
    case updateEvt:
495
 
      if (FocusDraw()) {
496
 
        Draw(kUnhilited);
497
 
        RestoreDraw();
498
 
      }
499
 
      eventHandled = true;
500
 
      break;
501
 
 
502
 
    case NPEventType_AdjustCursorEvent:
503
 
      if (CPlugin::sHandCursor)
504
 
        SetCursor(*CPlugin::sHandCursor);
505
 
      if (fUserInstalledPlugin) {
506
 
        if (CPlugin::sRefreshText)
507
 
          NPN_Status(fInstance, CPlugin::sRefreshText);        
508
 
      }
509
 
      else {
510
 
        if (CPlugin::sAltText)
511
 
          NPN_Status(fInstance, CPlugin::sAltText);
512
 
      }
513
 
      eventHandled = true;
514
 
      break;
515
 
 
516
 
    case nullEvent:
517
 
      // NOTE: We have to wait until idle time
518
 
      // to ask the user if they want to visit
519
 
      // the URL to avoid reentering XP code.
520
 
      if (!fAskedLoadURL) {
521
 
        if (CheckMimeTypes())
522
 
          AskAndLoadURL();
523
 
        fAskedLoadURL = true;
524
 
      }
525
 
      break;
526
 
    default:
527
 
      break;
528
 
  }
529
 
 
530
 
  return eventHandled;
531
 
}
532
 
 
533
 
 
534
 
void CPlugin::Draw(HiliteState hilite)
535
 
{
536
 
  UInt8 *pTheText;
537
 
  SInt32 height = fWindow->height;
538
 
  SInt32 width = fWindow->width;
539
 
  SInt32 centerX = (width) >> 1;
540
 
  SInt32 centerY = (height) >> 1;
541
 
  Rect drawRect;
542
 
  RGBColor black = { 0x0000, 0x0000, 0x0000 };
543
 
  RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF };
544
 
  RGBColor hiliteColor = { 0x0000, 0x0000, 0x0000 };
545
 
  short transform;
546
 
 
547
 
  drawRect.top = 0;
548
 
  drawRect.left = 0;
549
 
  drawRect.bottom = height;
550
 
  drawRect.right = width;
551
 
 
552
 
  if (height < 4 && width < 4)
553
 
    return;
554
 
 
555
 
  PenNormal();
556
 
  RGBForeColor(&black);
557
 
  RGBBackColor(&white);
558
 
 
559
 
  Pattern qdWhite;
560
 
  FillRect(&drawRect, GetQDGlobalsWhite(&qdWhite));
561
 
 
562
 
  if (hilite == kHilited) {
563
 
    hiliteColor.red = 0xFFFF;
564
 
    transform = ttSelected;
565
 
  }
566
 
  else {
567
 
    hiliteColor.blue = 0xFFFF;
568
 
    transform = ttNone;
569
 
  }
570
 
 
571
 
  RGBForeColor(&hiliteColor);
572
 
  FrameRect(&drawRect);
573
 
 
574
 
  if (height > 32 && width > 32 && CPlugin::sIconHandle) {
575
 
    drawRect.top = centerY - 16;
576
 
    drawRect.bottom = centerY + 16;
577
 
    drawRect.left = centerX - 16;
578
 
    drawRect.right = centerX + 16;
579
 
    PlotCIconHandle(&drawRect, atAbsoluteCenter, transform, CPlugin::sIconHandle);
580
 
  }
581
 
 
582
 
  if (fUserInstalledPlugin) {
583
 
    pTheText = (unsigned char*)CPlugin::sRefreshText;
584
 
  }
585
 
  else {
586
 
    pTheText = (unsigned char*)CPlugin::sAltText;
587
 
  }
588
 
  DrawString(pTheText, width, height, centerX, drawRect);
589
 
}
590
 
 
591
 
 
592
 
// Track the click in our plugin by drawing the icon enabled or disabled
593
 
// as the user moves the mouse in and out with the button held down.  If
594
 
// they let up the mouse while still inside, get the URL.
595
 
void  CPlugin::MouseDown()
596
 
{
597
 
  if (FocusDraw()) {
598
 
    Draw(kHilited);
599
 
    Boolean inside = true;
600
 
  
601
 
    // evil CPU-hogging loop on Mac OS X!
602
 
    while (StillDown()) {
603
 
      Point localMouse;
604
 
      GetMouse(&localMouse);
605
 
      Boolean insideNow = ::PtInRect(localMouse, &fRevealedRect);
606
 
 
607
 
      if (insideNow != inside) {
608
 
        Draw(insideNow ? kHilited : kUnhilited);
609
 
        inside = insideNow;
610
 
      }
611
 
    }
612
 
    
613
 
    if (inside) {
614
 
      Draw(kUnhilited);
615
 
      if (!fUserInstalledPlugin)
616
 
        AskAndLoadURL();
617
 
      else
618
 
        RefreshPluginPage();
619
 
    }
620
 
 
621
 
    RestoreDraw();
622
 
  }
623
 
}
624
 
 
625
 
 
626
 
Boolean CPlugin::FocusDraw()
627
 
{
628
 
  if (!fWindow)
629
 
    return false;
630
 
    
631
 
  NP_Port* npport = (NP_Port*) fWindow->window;
632
 
  CGrafPtr ourPort = npport->port;
633
 
  
634
 
  if (fWindow->clipRect.left < fWindow->clipRect.right) {
635
 
    GetPort(&fSavePort);
636
 
    SetPort((GrafPtr) ourPort);
637
 
    Rect portRect;
638
 
    GetPortBounds(ourPort, &portRect);
639
 
    fSavePortTop = portRect.top;
640
 
    fSavePortLeft = portRect.left;
641
 
    GetClip(fSaveClip);
642
 
    
643
 
    fRevealedRect.top = fWindow->clipRect.top + npport->porty;
644
 
    fRevealedRect.left = fWindow->clipRect.left + npport->portx;
645
 
    fRevealedRect.bottom = fWindow->clipRect.bottom + npport->porty;
646
 
    fRevealedRect.right = fWindow->clipRect.right + npport->portx;
647
 
    SetOrigin(npport->portx, npport->porty);
648
 
    ClipRect(&fRevealedRect);
649
 
 
650
 
    return true;
651
 
  }
652
 
  else {
653
 
    return false;
654
 
  }
655
 
}
656
 
 
657
 
 
658
 
void CPlugin::RestoreDraw()
659
 
{
660
 
  SetOrigin(fSavePortLeft, fSavePortTop);
661
 
  SetClip(fSaveClip);
662
 
  SetPort(fSavePort);
663
 
}
664
 
 
665
 
 
666
 
// Get a URL from either the parameters passed from the EMBED.
667
 
// Append "?" and our mime type and save for later use.
668
 
void CPlugin::DetermineURL(int16 argc, char* argn[], char* argv[])
669
 
{
670
 
  char* url;
671
 
  SInt32 additionalLength = 0;
672
 
  SInt32 i;
673
 
 
674
 
  // Appended to the URL will be a "?" and the mime type of this instance.  This lets the server
675
 
  // do something intelligent with a CGI script.
676
 
 
677
 
  if (fType)
678
 
    additionalLength += (strlen(fType) + 1); // Add 1 for '?'
679
 
 
680
 
  // The page designer can specify a URL where the plugin for this type can be downloaded.  Here
681
 
  // we scan the arguments for this attribute and save it away if we
682
 
  // find it for later use by LoadPluginURL().
683
 
  for (i = 0; i < argc; i++) {
684
 
    if ((strcasecmp(argn[i], "PLUGINSPAGE") == 0) || (strcasecmp(argn[i], "CODEBASE") == 0)) {
685
 
      url = argv[i];
686
 
      fPageURL = (char*)NPN_MemAlloc(strlen(url) + 1 + additionalLength);  // Add 1 for '\0'
687
 
      if (fPageURL) {
688
 
        if (additionalLength > 0) {
689
 
          sprintf(fPageURL, "%s?%s", url, fType);
690
 
        }
691
 
        else {
692
 
          strcpy(fPageURL, url);  
693
 
        }
694
 
      }
695
 
      break;
696
 
    } else if ((strcasecmp(argn[i], "PLUGINURL") == 0) || (strcasecmp(argn[i], "CLASSID") == 0)) {
697
 
      url = argv[i];
698
 
      if (CPlugin::sInstallCommand) {
699
 
        // Allocate a new string
700
 
        fFileURL = (char*)NPN_MemAlloc(strlen(CPlugin::sInstallCommand) + 1 + strlen(url));  
701
 
        if (fFileURL)
702
 
          sprintf(fFileURL, CPlugin::sInstallCommand, url);
703
 
      }
704
 
      break;
705
 
    }
706
 
  }
707
 
}
708
 
 
709
 
 
710
 
 
711
 
// Get a URL from our resources.  Append "?" and our mime type and save for later use.
712
 
char *CPlugin::MakeDefaultURL(void)
713
 
{
714
 
  char *pDefURL = NULL;
715
 
  SInt32 additionalLength = 0;
716
 
 
717
 
  // Appended to the URL will be a "?" and the mime type of this instance.  This lets the server
718
 
  // do something intelligent with a CGI script.
719
 
 
720
 
  if (fType)
721
 
    additionalLength += (strlen(fType) + 1);    // Add 1 for '?'
722
 
 
723
 
  if (!m_bJavaScript) {
724
 
    if (CPlugin::sDefaultPage) {
725
 
      pDefURL = (char*)NPN_MemAlloc(strlen(CPlugin::sDefaultPage) + 1 + additionalLength);
726
 
      if (pDefURL) {
727
 
        if (additionalLength > 0) {
728
 
          sprintf(pDefURL, "%s?%s", CPlugin::sDefaultPage, fType);
729
 
        }
730
 
        else {
731
 
          strcpy(pDefURL, CPlugin::sDefaultPage);  
732
 
        }
733
 
      }
734
 
    }
735
 
  }
736
 
  else {
737
 
    if (CPlugin::sJavaScriptPage) {
738
 
      pDefURL = (char*)NPN_MemAlloc(strlen(szPluginFinderCommandBeginning) +
739
 
            strlen(CPlugin::sJavaScriptPage) +
740
 
            additionalLength + strlen(szPluginFinderCommandEnd) + 1);
741
 
      if (pDefURL) {
742
 
        sprintf(pDefURL, "%s%s%s%s", szPluginFinderCommandBeginning,
743
 
            CPlugin::sJavaScriptPage, fType, szPluginFinderCommandEnd);
744
 
      }
745
 
    }
746
 
  }
747
 
  return(pDefURL);
748
 
}
749
 
 
750
 
 
751
 
 
752
 
// Check the mime type of this instance against our list
753
 
// of types we�ve seen before.  If we find our type in the
754
 
// list, return false; otherwise, return true.
755
 
//
756
 
// type 'STR#' {
757
 
//      integer = $$Countof(StringArray);
758
 
//      array StringArray {
759
 
//              pstring;
760
 
//      };
761
 
void CPlugin::AddMimeTypeToList(StringPtr cTypeString)
762
 
{
763
 
  CFStringRef pluginKey = CFSTR("DefaultPluginSeenTypes"); // don't release this
764
 
  CFStringRef mimeType = ::CFStringCreateWithPascalString(kCFAllocatorDefault, cTypeString, kCFStringEncodingASCII);
765
 
  CFArrayRef prefsList = (CFArrayRef)::CFPreferencesCopyAppValue(pluginKey, kCFPreferencesCurrentApplication);
766
 
  Boolean foundType = false;
767
 
 
768
 
  if (!prefsList) {
769
 
    CFStringRef stringArray[1];
770
 
    stringArray[0] = mimeType;
771
 
 
772
 
    prefsList = ::CFArrayCreate(kCFAllocatorDefault, (const void **)stringArray, 1, &kCFTypeArrayCallBacks);
773
 
    if (prefsList) {
774
 
      ::CFPreferencesSetAppValue(pluginKey, prefsList, kCFPreferencesCurrentApplication);
775
 
      ::CFRelease(prefsList);
776
 
    }
777
 
  }
778
 
  else {
779
 
    if (::CFGetTypeID(prefsList) == ::CFArrayGetTypeID()) {
780
 
      // first make sure it's not in the list
781
 
      CFIndex count = ::CFArrayGetCount(prefsList);
782
 
      for (CFIndex i = 0; i < count; i ++) {
783
 
        CFStringRef item = (CFStringRef)::CFArrayGetValueAtIndex(prefsList, i); // does not retain
784
 
        if (item && (::CFGetTypeID(item) == ::CFStringGetTypeID()) &&
785
 
            (::CFStringCompareWithOptions(item, mimeType,
786
 
                                          CFRangeMake(0, ::CFStringGetLength(item)), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
787
 
          foundType = true;
788
 
          break;
789
 
        }
790
 
      }
791
 
 
792
 
      if (!foundType && !fHiddenPlugin) {
793
 
        CFMutableArrayRef typesArray = ::CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, (CFArrayRef)prefsList);
794
 
        if (typesArray) {
795
 
          ::CFArrayAppendValue(typesArray, mimeType);
796
 
          ::CFPreferencesSetAppValue(pluginKey, typesArray, kCFPreferencesCurrentApplication);
797
 
        }
798
 
      }
799
 
    }
800
 
    ::CFRelease(prefsList);
801
 
  }
802
 
  ::CFRelease(mimeType);
803
 
}
804
 
 
805
 
 
806
 
// Check the mime type of this instance against our list
807
 
// of types we�ve seen before.  If we find our type in the
808
 
// list, return false; otherwise, return true.
809
 
//
810
 
// type 'STR#' {
811
 
//      integer = $$Countof(StringArray);
812
 
//      array StringArray {
813
 
//              pstring;
814
 
//      };
815
 
Boolean CPlugin::CheckMimeTypes()
816
 
{
817
 
  Boolean failedToFind = true;
818
 
 
819
 
  CFStringRef pluginKey = CFSTR("DefaultPluginSeenTypes"); // don't release this
820
 
  CFStringRef mimeType  = ::CFStringCreateWithCString(kCFAllocatorDefault, fType, kCFStringEncodingASCII);
821
 
  CFArrayRef prefsList = (CFArrayRef)::CFPreferencesCopyAppValue(pluginKey, kCFPreferencesCurrentApplication);
822
 
  if (prefsList) {
823
 
    if (::CFGetTypeID(prefsList) == ::CFArrayGetTypeID()) {
824
 
      CFIndex count = ::CFArrayGetCount(prefsList);
825
 
      for (CFIndex i = 0; i < count; i ++) {
826
 
        CFStringRef item = (CFStringRef)::CFArrayGetValueAtIndex(prefsList, i); // does not retain
827
 
        if (item &&
828
 
            (::CFGetTypeID(item) == ::CFStringGetTypeID()) &&
829
 
            (::CFStringCompareWithOptions(item, mimeType,
830
 
                                          CFRangeMake(0, ::CFStringGetLength(item)), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
831
 
          failedToFind = false;
832
 
          break;
833
 
        }
834
 
      }
835
 
    }
836
 
    ::CFRelease(prefsList);
837
 
  }
838
 
  ::CFRelease(mimeType);
839
 
  return failedToFind;
840
 
}
841
 
 
842
 
 
843
 
void CPlugin::AskAndLoadURL()
844
 
{
845
 
  char *pTheURL;
846
 
  SInt32 dwLen;
847
 
  Str255 ourType;
848
 
 
849
 
  if (!m_bOffline) {
850
 
    // Convert the mime-type C string to a Pascal string.
851
 
    dwLen = strlen(fType);
852
 
    if (dwLen > 255) {    // don't blow out the Str255
853
 
      dwLen = 255;
854
 
    }
855
 
    BlockMoveData(fType, &ourType[1], dwLen);
856
 
    ourType[0] = dwLen;
857
 
 
858
 
    // NOTE: We need to set the cursor because almost always we will have set it to the
859
 
    // hand cursor before we get here.
860
 
    Cursor qdArrow;
861
 
    SetCursor(GetQDGlobalsArrow(&qdArrow));
862
 
 
863
 
    // Now that we�ve queried the user about this mime type,
864
 
    // add it to our list so we won�t bug them again.
865
 
    AddMimeTypeToList(ourType);
866
 
    
867
 
    // If the user clicked "Get the Plug-in", either execute the
868
 
    // JavaScript file-installation URL, or ask Netscape to open
869
 
    // a new window with the page URL.  The title of the window
870
 
    // is arbitrary since it has nothing to do with the actual
871
 
    // window title shown to the user (it�s only used internally).
872
 
    NPN_PushPopupsEnabledState(fInstance, true);
873
 
 
874
 
    if (fFileURL) {
875
 
      (void) NPN_GetURL(fInstance, fFileURL, "_current");
876
 
    }
877
 
    else if (fPageURL) {
878
 
      NPN_GetURL(fInstance, fPageURL, "_blank");
879
 
    }
880
 
    else {
881
 
      pTheURL = MakeDefaultURL();
882
 
      if (!m_bJavaScript)
883
 
        NPN_GetURL(fInstance, pTheURL, "_blank");
884
 
      else
885
 
        NPN_GetURL(fInstance, pTheURL, NULL);
886
 
      NPN_MemFree(pTheURL);
887
 
    }
888
 
 
889
 
    NPN_PopPopupsEnabledState(fInstance);
890
 
 
891
 
    fUserInstalledPlugin = true;
892
 
    if (FocusDraw()) {
893
 
      Draw(kUnhilited);
894
 
      RestoreDraw();
895
 
    }
896
 
  }
897
 
}
898
 
 
899
 
 
900
 
void CPlugin::RefreshPluginPage()
901
 
{
902
 
  (void)NPN_GetURL(fInstance, "javascript:navigator.plugins.refresh(true);", "_self");
903
 
}
904
 
 
905
 
 
906
 
void CPlugin::DrawString(const unsigned char* text, short width, short height, short centerX, Rect drawRect)
907
 
{
908
 
  short length, textHeight, textWidth;
909
 
 
910
 
  if (!text)
911
 
    return;
912
 
 
913
 
  length = strlen((char*)text);
914
 
  TextFont(20);
915
 
  TextFace(underline);
916
 
  TextMode(srcCopy);
917
 
  TextSize(10);
918
 
 
919
 
  FontInfo fontInfo;
920
 
  GetFontInfo(&fontInfo);
921
 
 
922
 
  textHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
923
 
  textWidth = TextWidth(text, 0, length);
924
 
 
925
 
  if (width > textWidth && height > textHeight + 32) {
926
 
    MoveTo(centerX - (textWidth >> 1), drawRect.bottom + textHeight);
927
 
    DrawText(text, 0, length);
928
 
  }    
929
 
}
930
 
 
931
 
 
932
 
Boolean CPlugin::IsPluginHidden(int16 argc, char* argn[], char* argv[])
933
 
{
934
 
  for (int i = 0; i < argc; i++) {
935
 
    if (!strcasecmp(argn[i], "HIDDEN")) {
936
 
      if (!strcasecmp(argv[i], "TRUE"))
937
 
        return true;
938
 
    }
939
 
  }
940
 
  return false;
941
 
}