What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2007, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_BASE_NPAPI_PLUGIN_H__
#define GEARS_BASE_NPAPI_PLUGIN_H__

#include "gears/base/common/base_class.h"
#include "gears/base/common/dispatcher.h"

class JsCallContext;

// This is a base class for the bridge between the JavaScript engine and the
// Gears class implementations. See ModuleWrapper for an example.
class PluginBase : public NPObject {
public:
// NPClass callbacks. The browser calls these functions when JavaScript
// interacts with a Gears object.
template<class PluginClass>
static NPObject* Allocate(NPP npp, NPClass *npclass) {
return new PluginClass(npp);
}
static void Deallocate(NPObject *npobj);
static bool HasMethod(NPObject *npobj, NPIdentifier name);
static bool Invoke(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t num_args,
NPVariant *result);
static bool HasProperty(NPObject *npobj, NPIdentifier name);
static bool GetProperty(NPObject *npobj, NPIdentifier name,
NPVariant *result);
static bool SetProperty(NPObject *npobj, NPIdentifier name,
const NPVariant *value);
PluginBase(NPP instance) : instance_(instance), dispatcher_(NULL) {}
virtual ~PluginBase() {}

// Secondary init function that requires more information than we have
// at object creation time.
void Init(DispatcherInterface *dispatcher) {
dispatcher_ = dispatcher;
}

protected:
NPP instance_;
DispatcherInterface *dispatcher_;

private:
DISALLOW_EVIL_CONSTRUCTORS(PluginBase);
};

// Get the NPClass for a Plugin type (the type must derive from PluginBase).
// Note that this just returns a temporary that can be used to initialize a
// global. The reason for not simply returning a static here is that this is a
// non-member inline function, which means different copies of the static may
// be created for the different compilation units that call this function.
template<class Plugin>
NPClass GetNPClassTemplate() {
NPClass plugin_class = {
NP_CLASS_STRUCT_VERSION,
PluginBase::Allocate<Plugin>,
PluginBase::Deallocate,
NULL, // PluginBase::Invalidate,
PluginBase::HasMethod,
PluginBase::Invoke,
NULL, // PluginBase::InvokeDefault,
PluginBase::HasProperty,
PluginBase::GetProperty,
PluginBase::SetProperty,
NULL, // PluginBase::RemoveProperty,
};

return plugin_class;
}

#endif // GEARS_BASE_NPAPI_PLUGIN_H__
Show details Hide details

Change log

r2268 by gears.daemon on Jul 07, 2008   Diff
[Author: mpcomplete]

Fix a bug with marshalling objects in
NPAPI, causing some Gears objects to be
misidentified as regular JS objects.

This is  Issue 570 .

BUG=1240457
R=nigeltao
CC=gears-eng@googlegroups.com
DELTA=17  (10 added, 0 deleted, 7 changed)
...
Go to: 
Project members, sign in to write a code review

Older revisions

r625 by gears.daemon on Dec 21, 2007   Diff
[Author: mpcomplete]

More refactoring of NPAPI wrapper
classes.  At Aaron's suggestion, I
moved the Register* calls out of the
...
r592 by gears.daemon on Dec 13, 2007   Diff
[Author: mpcomplete]

Use std::string instead of char* as
the type for my ThreadLocal keys, to
avoid creating a temporary for every
...
r562 by gears.daemon on Dec 10, 2007   Diff
[Author: mpcomplete]

NPAPI workerpool implementation.  Most
of the workerpool.cc/h code is forked
from IE for now.  This CL just
...
All revisions of this file

File info

Size: 3940 bytes, 95 lines