OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gpu/np_utils/np_dispatcher.h" | |
6 | |
7 namespace np_utils { | |
8 | |
9 bool DispatcherHasMethodHelper(BaseNPDispatcher* chain, | |
10 NPObject* object, | |
11 NPIdentifier name) { | |
12 for (BaseNPDispatcher* dispatcher = chain; | |
13 dispatcher; | |
14 dispatcher = dispatcher->next()) { | |
15 if (dispatcher->name() == name) { | |
16 return true; | |
17 } | |
18 } | |
19 | |
20 return false; | |
21 } | |
22 | |
23 bool DispatcherInvokeHelper(BaseNPDispatcher* chain, | |
24 NPObject* object, | |
25 NPIdentifier name, | |
26 const NPVariant* args, | |
27 uint32_t num_args, | |
28 NPVariant* result) { | |
29 VOID_TO_NPVARIANT(*result); | |
30 | |
31 for (BaseNPDispatcher* dispatcher = chain; | |
32 dispatcher; | |
33 dispatcher = dispatcher->next()) { | |
34 if (dispatcher->name() == name && | |
35 dispatcher->num_args() == static_cast<int>(num_args)) { | |
36 if (dispatcher->Invoke(object, args, num_args, result)) | |
37 return true; | |
38 } | |
39 } | |
40 | |
41 return false; | |
42 } | |
43 | |
44 bool DispatcherEnumerateHelper(BaseNPDispatcher* chain, | |
45 NPObject* object, | |
46 NPIdentifier** names, | |
47 uint32_t* num_names) { | |
48 // Count the number of names. | |
49 *num_names = 0; | |
50 for (BaseNPDispatcher* dispatcher = chain; | |
51 dispatcher; | |
52 dispatcher = dispatcher->next()) { | |
53 ++(*num_names); | |
54 } | |
55 | |
56 // Copy names into the array. | |
57 *names = static_cast<NPIdentifier*>( | |
58 NPBrowser::get()->MemAlloc((*num_names) * sizeof(**names))); | |
59 int i = 0; | |
60 for (BaseNPDispatcher* dispatcher = chain; | |
61 dispatcher; | |
62 dispatcher = dispatcher->next()) { | |
63 (*names)[i] = dispatcher->name(); | |
64 ++i; | |
65 } | |
66 | |
67 return true; | |
68 } | |
69 | |
70 BaseNPDispatcher::BaseNPDispatcher(BaseNPDispatcher* next, const NPUTF8* name) | |
71 : next_(next) { | |
72 // Convert first character to lower case if it is the ASCII range. | |
73 // TODO(apatrick): do this correctly for non-ASCII characters. | |
74 std::string java_script_style_name(name); | |
75 if (isupper(java_script_style_name[0])) { | |
76 java_script_style_name[0] = tolower(java_script_style_name[0]); | |
77 } | |
78 | |
79 name_ = NPBrowser::get()->GetStringIdentifier( | |
80 java_script_style_name.c_str()); | |
81 } | |
82 | |
83 BaseNPDispatcher::~BaseNPDispatcher() { | |
84 } | |
85 | |
86 } // namespace np_utils | |
OLD | NEW |