summaryrefslogtreecommitdiffstats
path: root/gpu/np_utils/dynamic_np_object.cc
blob: e037fdcacc44d8b56caecd7a68224302c310fea5 (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
// 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/dynamic_np_object.h"

namespace np_utils {

DynamicNPObject::DynamicNPObject(NPP npp) {
}

void DynamicNPObject::Invalidate() {
  for (PropertyMap::iterator it = properties_.begin();
       it != properties_.end();
       ++it) {
    it->second.Invalidate();
  }
}

bool DynamicNPObject::HasProperty(NPIdentifier name) {
  PropertyMap::iterator it = properties_.find(name);
  return it != properties_.end();
}

bool DynamicNPObject::GetProperty(NPIdentifier name, NPVariant* result) {
  PropertyMap::iterator it = properties_.find(name);
  if (it == properties_.end())
    return false;

  it->second.CopyTo(result);
  return true;
}

bool DynamicNPObject::SetProperty(NPIdentifier name, const NPVariant* value) {
  properties_[name] = *value;
  return true;
}

bool DynamicNPObject::RemoveProperty(NPIdentifier name) {
  properties_.erase(name);
  return false;
}

bool DynamicNPObject::Enumerate(NPIdentifier** names, uint32_t* count) {
  *names = static_cast<NPIdentifier*>(
      NPBrowser::get()->MemAlloc(properties_.size() * sizeof(*names)));
  *count = properties_.size();

  int i = 0;
  for (PropertyMap::iterator it = properties_.begin();
       it != properties_.end();
       ++it) {
    (*names)[i] = it->first;
    ++i;
  }

  return true;
}
}  // namespace np_utils