summaryrefslogtreecommitdiffstats
path: root/gpu/np_utils/np_browser_stub.cc
blob: 2e1c757d9360082221e5626efc3adfef076827bd (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/np_utils/np_browser_stub.h"
#include "base/logging.h"
#include "base/message_loop.h"

namespace np_utils {

StubNPBrowser::StubNPBrowser() : NPBrowser(NULL) {
}

StubNPBrowser::~StubNPBrowser() {
}

NPIdentifier StubNPBrowser::GetStringIdentifier(const NPUTF8* name) {
  static std::set<std::string> names;
  std::set<std::string>::iterator it = names.find(name);
  if (it == names.end()) {
    it = names.insert(name).first;
  }
  return const_cast<NPUTF8*>((*it).c_str());
}

void* StubNPBrowser::MemAlloc(size_t size) {
  return malloc(size);
}

void StubNPBrowser::MemFree(void* p) {
  free(p);
}

NPObject* StubNPBrowser::CreateObject(NPP npp, const NPClass* cl) {
  NPObject* object = cl->allocate(npp, const_cast<NPClass*>(cl));
  object->referenceCount = 1;
  object->_class = const_cast<NPClass*>(cl);
  return object;
}

NPObject* StubNPBrowser::RetainObject(NPObject* object) {
  ++object->referenceCount;
  return object;
}

void StubNPBrowser::ReleaseObject(NPObject* object) {
  DCHECK_GE(object->referenceCount, 0u);
  --object->referenceCount;
  if (object->referenceCount == 0) {
    object->_class->deallocate(object);
  }
}

void StubNPBrowser::ReleaseVariantValue(NPVariant* variant) {
  if (NPVARIANT_IS_STRING(*variant)) {
    MemFree(const_cast<NPUTF8*>(variant->value.stringValue.UTF8Characters));
  } else if (NPVARIANT_IS_OBJECT(*variant)) {
    ReleaseObject(NPVARIANT_TO_OBJECT(*variant));
  }
}

bool StubNPBrowser::HasProperty(NPP npp,
                                NPObject* object,
                                NPIdentifier name) {
  return object->_class->hasProperty(object, name);
}

bool StubNPBrowser::GetProperty(NPP npp,
                         NPObject* object,
                         NPIdentifier name,
                         NPVariant* result) {
  return object->_class->getProperty(object, name, result);
}

bool StubNPBrowser::SetProperty(NPP npp,
                            NPObject* object,
                            NPIdentifier name,
                            const NPVariant* result) {
  return object->_class->setProperty(object, name, result);
}

bool StubNPBrowser::RemoveProperty(NPP npp,
                                   NPObject* object,
                                   NPIdentifier name) {
  return object->_class->removeProperty(object, name);
}

bool StubNPBrowser::HasMethod(NPP npp,
                              NPObject* object,
                              NPIdentifier name) {
  return object->_class->hasMethod(object, name);
}

bool StubNPBrowser::Invoke(NPP npp,
                    NPObject* object,
                    NPIdentifier name,
                    const NPVariant* args,
                    uint32_t num_args,
                    NPVariant* result) {
  return object->_class->invoke(object, name, args, num_args, result);
}

NPObject* StubNPBrowser::GetWindowNPObject(NPP npp) {
  return NULL;
}

void StubNPBrowser::PluginThreadAsyncCall(
    NPP npp,
    PluginThreadAsyncCallProc callback,
    void* data) {
  MessageLoop::current()->PostTask(FROM_HERE,
                                   NewRunnableFunction(callback, data));
}

uint32 StubNPBrowser::ScheduleTimer(NPP npp,
                                    uint32 interval,
                                    bool repeat,
                                    TimerProc callback) {
  return 0;
}

void StubNPBrowser::UnscheduleTimer(NPP npp, uint32 timer_id) {
}

}  // namespace np_utils