-
Notifications
You must be signed in to change notification settings - Fork 7
/
nsPluginInstanceOverwolfSample.cpp
87 lines (71 loc) · 2.2 KB
/
nsPluginInstanceOverwolfSample.cpp
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
/*
Overwolf Sample Plugin
Copyright (c) 2014 Ovefwolf Ltd.
*/
#include "nsPluginInstanceOverwolfSample.h"
#include "nsScriptableObjectOverwolfSample.h" // our specific API
// we use this to force our plugin container to shut down
// when no one is using it. Browsers try to keep the plugin
// open for optimization reasons - we don't want it
int nsPluginInstanceOverwolfSample::ref_count_ = 0;
////////////////////////////////////////
//
// nsPluginInstanceOverwolfSample class implementation
//
nsPluginInstanceOverwolfSample::nsPluginInstanceOverwolfSample(NPP instance) :
nsPluginInstanceBase(),
instance_(instance),
initialized_(FALSE),
scriptable_object_(nullptr) {
nsPluginInstanceOverwolfSample::ref_count_++;
}
nsPluginInstanceOverwolfSample::~nsPluginInstanceOverwolfSample() {
nsPluginInstanceOverwolfSample::ref_count_--;
if (0 == nsPluginInstanceOverwolfSample::ref_count_) {
PostQuitMessage(0);
}
}
// NOTE:
// ------
// Overwolf plugins should not implement windows - NPAPI will
// probably be removed in the near feature and will be changed
// by a different method that will only support non-visual
// plugins
NPBool nsPluginInstanceOverwolfSample::init(NPWindow* window) {
// no GUI to init in windowless case
initialized_ = TRUE;
return TRUE;
}
void nsPluginInstanceOverwolfSample::shut() {
if (nullptr != scriptable_object_) {
NPN_ReleaseObject(scriptable_object_);
}
initialized_ = FALSE;
}
NPBool nsPluginInstanceOverwolfSample::isInitialized() {
return initialized_;
}
// here we supply our scriptable object
NPError nsPluginInstanceOverwolfSample::GetValue(
NPPVariable variable, void* ret_value) {
NPError rv = NPERR_INVALID_PARAM;
switch (variable) {
case NPPVpluginScriptableNPObject:
{
if (nullptr == scriptable_object_) {
scriptable_object_ =
NPN_CreateObject(
instance_,
GET_NPOBJECT_CLASS(nsScriptableObjectOverwolfSample));
NPN_RetainObject(scriptable_object_);
((nsScriptableObjectOverwolfSample*)scriptable_object_)->Init();
*(NPObject **)ret_value = scriptable_object_;
}
rv = NPERR_NO_ERROR;
return rv;
}
default:
break;
}
return rv;
}