OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 using WebKit::WebDOMMessageEvent; | 32 using WebKit::WebDOMMessageEvent; |
33 using WebKit::WebPluginContainer; | 33 using WebKit::WebPluginContainer; |
34 using WebKit::WebSerializedScriptValue; | 34 using WebKit::WebSerializedScriptValue; |
35 using WebKit::WebString; | 35 using WebKit::WebString; |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kAddEventListener[] = "addEventListener"; | 41 const char kAddEventListener[] = "addEventListener"; |
| 42 const char kGetProcessId[] = "getProcessId"; |
42 const char kReloadMethod[] = "reload"; | 43 const char kReloadMethod[] = "reload"; |
43 const char kRemoveEventListener[] = "removeEventListener"; | 44 const char kRemoveEventListener[] = "removeEventListener"; |
44 const char kSrcAttribute[] = "src"; | 45 const char kSrcAttribute[] = "src"; |
45 const char kStopMethod[] = "stop"; | 46 const char kStopMethod[] = "stop"; |
46 | 47 |
47 BrowserPluginBindings* GetBindings(NPObject* object) { | 48 BrowserPluginBindings* GetBindings(NPObject* object) { |
48 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 49 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
49 message_channel; | 50 message_channel; |
50 } | 51 } |
51 | 52 |
52 bool IdentifierIsReload(NPIdentifier identifier) { | 53 bool IdentifierIsReload(NPIdentifier identifier) { |
53 return WebBindings::getStringIdentifier(kReloadMethod) == identifier; | 54 return WebBindings::getStringIdentifier(kReloadMethod) == identifier; |
54 } | 55 } |
55 | 56 |
56 bool IdentifierIsStop(NPIdentifier identifier) { | 57 bool IdentifierIsStop(NPIdentifier identifier) { |
57 return WebBindings::getStringIdentifier(kStopMethod) == identifier; | 58 return WebBindings::getStringIdentifier(kStopMethod) == identifier; |
58 } | 59 } |
59 | 60 |
60 bool IdentifierIsAddEventListener(NPIdentifier identifier) { | 61 bool IdentifierIsAddEventListener(NPIdentifier identifier) { |
61 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; | 62 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; |
62 } | 63 } |
63 | 64 |
64 bool IdentifierIsRemoveEventListener(NPIdentifier identifier) { | 65 bool IdentifierIsRemoveEventListener(NPIdentifier identifier) { |
65 return WebBindings::getStringIdentifier(kRemoveEventListener) == identifier; | 66 return WebBindings::getStringIdentifier(kRemoveEventListener) == identifier; |
66 } | 67 } |
67 | 68 |
| 69 bool IdentifierIsGetProcessID(NPIdentifier identifier) { |
| 70 return WebBindings::getStringIdentifier(kGetProcessId) == identifier; |
| 71 } |
| 72 |
68 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { | 73 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { |
69 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; | 74 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; |
70 } | 75 } |
71 | 76 |
72 std::string StringFromNPVariant(const NPVariant& variant) { | 77 std::string StringFromNPVariant(const NPVariant& variant) { |
73 if (!NPVARIANT_IS_STRING(variant)) | 78 if (!NPVARIANT_IS_STRING(variant)) |
74 return std::string(); | 79 return std::string(); |
75 const NPString& np_string = NPVARIANT_TO_STRING(variant); | 80 const NPString& np_string = NPVARIANT_TO_STRING(variant); |
76 return std::string(np_string.UTF8Characters, np_string.UTF8Length); | 81 return std::string(np_string.UTF8Characters, np_string.UTF8Length); |
77 } | 82 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 delete instance; | 117 delete instance; |
113 } | 118 } |
114 | 119 |
115 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { | 120 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { |
116 if (!np_obj) | 121 if (!np_obj) |
117 return false; | 122 return false; |
118 | 123 |
119 if (IdentifierIsAddEventListener(name)) | 124 if (IdentifierIsAddEventListener(name)) |
120 return true; | 125 return true; |
121 | 126 |
| 127 if (IdentifierIsGetProcessID(name)) |
| 128 return true; |
| 129 |
| 130 if (IdentifierIsReload(name)) |
| 131 return true; |
| 132 |
122 if (IdentifierIsRemoveEventListener(name)) | 133 if (IdentifierIsRemoveEventListener(name)) |
123 return true; | 134 return true; |
124 | 135 |
125 if (IdentifierIsStop(name)) | 136 if (IdentifierIsStop(name)) |
126 return true; | 137 return true; |
127 | 138 |
128 if (IdentifierIsReload(name)) | |
129 return true; | |
130 | |
131 return false; | 139 return false; |
132 } | 140 } |
133 | 141 |
134 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, | 142 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, |
135 const NPVariant* args, uint32 arg_count, | 143 const NPVariant* args, uint32 arg_count, |
136 NPVariant* result) { | 144 NPVariant* result) { |
137 if (!np_obj) | 145 if (!np_obj) |
138 return false; | 146 return false; |
139 | 147 |
140 BrowserPluginBindings* bindings = GetBindings(np_obj); | 148 BrowserPluginBindings* bindings = GetBindings(np_obj); |
141 if (!bindings) | 149 if (!bindings) |
142 return false; | 150 return false; |
143 | 151 |
144 if (IdentifierIsAddEventListener(name) && (arg_count == 2)) { | 152 if (IdentifierIsAddEventListener(name) && (arg_count == 2)) { |
145 std::string event_name = StringFromNPVariant(args[0]); | 153 std::string event_name = StringFromNPVariant(args[0]); |
146 if (event_name.empty()) | 154 if (event_name.empty()) |
147 return false; | 155 return false; |
148 | 156 |
149 v8::Local<v8::Value> value = | 157 v8::Local<v8::Value> value = |
150 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); | 158 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); |
151 if (value.IsEmpty() || !value->IsFunction()) | 159 if (value.IsEmpty() || !value->IsFunction()) |
152 return false; | 160 return false; |
153 | 161 |
154 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 162 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
155 return bindings->instance()->AddEventListener(event_name, function); | 163 return bindings->instance()->AddEventListener(event_name, function); |
156 } | 164 } |
157 | 165 |
| 166 if (IdentifierIsGetProcessID(name) && !arg_count) { |
| 167 int process_id = bindings->instance()->process_id(); |
| 168 result->type = NPVariantType_Int32; |
| 169 result->value.intValue = process_id; |
| 170 return true; |
| 171 } |
| 172 |
| 173 if (IdentifierIsReload(name) && !arg_count) { |
| 174 bindings->instance()->Reload(); |
| 175 return true; |
| 176 } |
| 177 |
158 if (IdentifierIsRemoveEventListener(name) && arg_count == 2) { | 178 if (IdentifierIsRemoveEventListener(name) && arg_count == 2) { |
159 std::string event_name = StringFromNPVariant(args[0]); | 179 std::string event_name = StringFromNPVariant(args[0]); |
160 if (event_name.empty()) | 180 if (event_name.empty()) |
161 return false; | 181 return false; |
162 | 182 |
163 v8::Local<v8::Value> value = | 183 v8::Local<v8::Value> value = |
164 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); | 184 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); |
165 | 185 |
166 if (value.IsEmpty() || !value->IsFunction()) | 186 if (value.IsEmpty() || !value->IsFunction()) |
167 return false; | 187 return false; |
168 | 188 |
169 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 189 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
170 return bindings->instance()->RemoveEventListener(event_name, function); | 190 return bindings->instance()->RemoveEventListener(event_name, function); |
171 } | 191 } |
172 | 192 |
173 if (IdentifierIsStop(name) && !arg_count) { | 193 if (IdentifierIsStop(name) && !arg_count) { |
174 bindings->instance()->Stop(); | 194 bindings->instance()->Stop(); |
175 return true; | 195 return true; |
176 } | 196 } |
177 | 197 |
178 if (IdentifierIsReload(name) && !arg_count) { | |
179 bindings->instance()->Reload(); | |
180 return true; | |
181 } | |
182 | |
183 return false; | 198 return false; |
184 } | 199 } |
185 | 200 |
186 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, | 201 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, |
187 const NPVariant* args, | 202 const NPVariant* args, |
188 uint32 arg_count, | 203 uint32 arg_count, |
189 NPVariant* result) { | 204 NPVariant* result) { |
190 NOTIMPLEMENTED(); | 205 NOTIMPLEMENTED(); |
191 return false; | 206 return false; |
192 } | 207 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 WebBindings::createObject(NULL, &browser_plugin_message_class); | 285 WebBindings::createObject(NULL, &browser_plugin_message_class); |
271 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 286 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
272 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 287 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
273 } | 288 } |
274 | 289 |
275 BrowserPluginBindings::~BrowserPluginBindings() { | 290 BrowserPluginBindings::~BrowserPluginBindings() { |
276 WebBindings::releaseObject(np_object_); | 291 WebBindings::releaseObject(np_object_); |
277 } | 292 } |
278 | 293 |
279 } // namespace content | 294 } // namespace content |
OLD | NEW |