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::WebPluginContainer; | 32 using WebKit::WebPluginContainer; |
33 using WebKit::WebSerializedScriptValue; | 33 using WebKit::WebSerializedScriptValue; |
34 using WebKit::WebString; | 34 using WebKit::WebString; |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kAddEventListener[] = "addEventListener"; | 40 const char kAddEventListener[] = "addEventListener"; |
41 const char kBackMethod[] = "back"; | 41 const char kBackMethod[] = "back"; |
| 42 const char kContentWindow[] = "contentWindow"; |
42 const char kForwardMethod[] = "forward"; | 43 const char kForwardMethod[] = "forward"; |
43 const char kGetProcessId[] = "getProcessId"; | 44 const char kGetProcessId[] = "getProcessId"; |
44 const char kGoMethod[] = "go"; | 45 const char kGoMethod[] = "go"; |
45 const char kPartitionAttribute[] = "partition"; | 46 const char kPartitionAttribute[] = "partition"; |
46 const char kReloadMethod[] = "reload"; | 47 const char kReloadMethod[] = "reload"; |
47 const char kRemoveEventListener[] = "removeEventListener"; | 48 const char kRemoveEventListener[] = "removeEventListener"; |
48 const char kSrcAttribute[] = "src"; | 49 const char kSrcAttribute[] = "src"; |
49 const char kStopMethod[] = "stop"; | 50 const char kStopMethod[] = "stop"; |
50 const char kTerminateMethod[] = "terminate"; | 51 const char kTerminateMethod[] = "terminate"; |
51 | 52 |
52 BrowserPluginBindings* GetBindings(NPObject* object) { | 53 BrowserPluginBindings* GetBindings(NPObject* object) { |
53 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 54 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
54 message_channel; | 55 message_channel; |
55 } | 56 } |
56 | 57 |
57 bool IdentifierIsAddEventListener(NPIdentifier identifier) { | 58 bool IdentifierIsAddEventListener(NPIdentifier identifier) { |
58 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; | 59 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; |
59 } | 60 } |
60 | 61 |
| 62 bool IdentifierIsContentWindow(NPIdentifier identifier) { |
| 63 return WebBindings::getStringIdentifier(kContentWindow) == identifier; |
| 64 } |
| 65 |
61 bool IdentifierIsBackMethod(NPIdentifier identifier) { | 66 bool IdentifierIsBackMethod(NPIdentifier identifier) { |
62 return WebBindings::getStringIdentifier(kBackMethod) == identifier; | 67 return WebBindings::getStringIdentifier(kBackMethod) == identifier; |
63 } | 68 } |
64 | 69 |
65 bool IdentifierIsForwardMethod(NPIdentifier identifier) { | 70 bool IdentifierIsForwardMethod(NPIdentifier identifier) { |
66 return WebBindings::getStringIdentifier(kForwardMethod) == identifier; | 71 return WebBindings::getStringIdentifier(kForwardMethod) == identifier; |
67 } | 72 } |
68 | 73 |
69 bool IdentifierIsGetProcessID(NPIdentifier identifier) { | 74 bool IdentifierIsGetProcessID(NPIdentifier identifier) { |
70 return WebBindings::getStringIdentifier(kGetProcessId) == identifier; | 75 return WebBindings::getStringIdentifier(kGetProcessId) == identifier; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, | 267 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, |
263 const NPVariant* args, | 268 const NPVariant* args, |
264 uint32 arg_count, | 269 uint32 arg_count, |
265 NPVariant* result) { | 270 NPVariant* result) { |
266 NOTIMPLEMENTED(); | 271 NOTIMPLEMENTED(); |
267 return false; | 272 return false; |
268 } | 273 } |
269 | 274 |
270 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { | 275 bool BrowserPluginBindingsHasProperty(NPObject* np_obj, NPIdentifier name) { |
271 return IdentifierIsSrcAttribute(name) || | 276 return IdentifierIsSrcAttribute(name) || |
| 277 IdentifierIsContentWindow(name) || |
272 IdentifierIsPartitionAttribute(name); | 278 IdentifierIsPartitionAttribute(name); |
273 } | 279 } |
274 | 280 |
275 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, | 281 bool BrowserPluginBindingsGetProperty(NPObject* np_obj, NPIdentifier name, |
276 NPVariant* result) { | 282 NPVariant* result) { |
277 if (!np_obj) | 283 if (!np_obj) |
278 return false; | 284 return false; |
279 | 285 |
280 if (!result) | 286 if (!result) |
281 return false; | 287 return false; |
282 | 288 |
283 // All attributes from here on rely on the bindings, so retrieve it once and | 289 // All attributes from here on rely on the bindings, so retrieve it once and |
284 // return on failure. | 290 // return on failure. |
285 BrowserPluginBindings* bindings = GetBindings(np_obj); | 291 BrowserPluginBindings* bindings = GetBindings(np_obj); |
286 if (!bindings) | 292 if (!bindings) |
287 return false; | 293 return false; |
288 | 294 |
289 if (IdentifierIsSrcAttribute(name)) { | 295 if (IdentifierIsSrcAttribute(name)) { |
290 std::string src = bindings->instance()->GetSrcAttribute(); | 296 std::string src = bindings->instance()->GetSrcAttribute(); |
291 return StringToNPVariant(src, result); | 297 return StringToNPVariant(src, result); |
292 } | 298 } |
293 | 299 |
| 300 if (IdentifierIsContentWindow(name)) { |
| 301 NPObject* obj = bindings->instance()->GetContentWindow(); |
| 302 if (obj) { |
| 303 result->type = NPVariantType_Object; |
| 304 result->value.objectValue = WebBindings::retainObject(obj); |
| 305 } |
| 306 return true; |
| 307 } |
| 308 |
294 if (IdentifierIsPartitionAttribute(name)) { | 309 if (IdentifierIsPartitionAttribute(name)) { |
295 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 310 std::string partition_id = bindings->instance()->GetPartitionAttribute(); |
296 return StringToNPVariant(partition_id, result); | 311 return StringToNPVariant(partition_id, result); |
297 } | 312 } |
298 | 313 |
299 return false; | 314 return false; |
300 } | 315 } |
301 | 316 |
302 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, | 317 bool BrowserPluginBindingsSetProperty(NPObject* np_obj, NPIdentifier name, |
303 const NPVariant* variant) { | 318 const NPVariant* variant) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 WebBindings::createObject(NULL, &browser_plugin_message_class); | 387 WebBindings::createObject(NULL, &browser_plugin_message_class); |
373 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 388 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
374 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 389 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
375 } | 390 } |
376 | 391 |
377 BrowserPluginBindings::~BrowserPluginBindings() { | 392 BrowserPluginBindings::~BrowserPluginBindings() { |
378 WebBindings::releaseObject(np_object_); | 393 WebBindings::releaseObject(np_object_); |
379 } | 394 } |
380 | 395 |
381 } // namespace content | 396 } // namespace content |
OLD | NEW |