| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 const char kRemoveEventListener[] = "removeEventListener"; | 49 const char kRemoveEventListener[] = "removeEventListener"; |
| 50 const char kSrcAttribute[] = "src"; | 50 const char kSrcAttribute[] = "src"; |
| 51 const char kStopMethod[] = "stop"; | 51 const char kStopMethod[] = "stop"; |
| 52 const char kTerminateMethod[] = "terminate"; | 52 const char kTerminateMethod[] = "terminate"; |
| 53 | 53 |
| 54 BrowserPluginBindings* GetBindings(NPObject* object) { | 54 BrowserPluginBindings* GetBindings(NPObject* object) { |
| 55 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 55 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
| 56 message_channel; | 56 message_channel; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool IdentifierIsAddEventListener(NPIdentifier identifier) { | |
| 60 return WebBindings::getStringIdentifier(kAddEventListener) == identifier; | |
| 61 } | |
| 62 | |
| 63 bool IdentifierIsBackMethod(NPIdentifier identifier) { | |
| 64 return WebBindings::getStringIdentifier(kBackMethod) == identifier; | |
| 65 } | |
| 66 | |
| 67 bool IdentifierIsCanGoBack(NPIdentifier identifier) { | |
| 68 return WebBindings::getStringIdentifier(kCanGoBack) == identifier; | |
| 69 } | |
| 70 | |
| 71 bool IdentifierIsCanGoForward(NPIdentifier identifier) { | |
| 72 return WebBindings::getStringIdentifier(kCanGoForward) == identifier; | |
| 73 } | |
| 74 | |
| 75 bool IdentifierIsForwardMethod(NPIdentifier identifier) { | |
| 76 return WebBindings::getStringIdentifier(kForwardMethod) == identifier; | |
| 77 } | |
| 78 | |
| 79 bool IdentifierIsGetProcessID(NPIdentifier identifier) { | |
| 80 return WebBindings::getStringIdentifier(kGetProcessId) == identifier; | |
| 81 } | |
| 82 | |
| 83 bool IdentifierIsGoMethod(NPIdentifier identifier) { | |
| 84 return WebBindings::getStringIdentifier(kGoMethod) == identifier; | |
| 85 } | |
| 86 | |
| 87 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) { | 59 bool IdentifierIsPartitionAttribute(NPIdentifier identifier) { |
| 88 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier; | 60 return WebBindings::getStringIdentifier(kPartitionAttribute) == identifier; |
| 89 } | 61 } |
| 90 | 62 |
| 91 bool IdentifierIsReload(NPIdentifier identifier) { | |
| 92 return WebBindings::getStringIdentifier(kReloadMethod) == identifier; | |
| 93 } | |
| 94 | |
| 95 bool IdentifierIsRemoveEventListener(NPIdentifier identifier) { | |
| 96 return WebBindings::getStringIdentifier(kRemoveEventListener) == identifier; | |
| 97 } | |
| 98 | |
| 99 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { | 63 bool IdentifierIsSrcAttribute(NPIdentifier identifier) { |
| 100 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; | 64 return WebBindings::getStringIdentifier(kSrcAttribute) == identifier; |
| 101 } | 65 } |
| 102 | 66 |
| 103 bool IdentifierIsStop(NPIdentifier identifier) { | |
| 104 return WebBindings::getStringIdentifier(kStopMethod) == identifier; | |
| 105 } | |
| 106 | |
| 107 bool IdentifierIsTerminate(NPIdentifier identifier) { | |
| 108 return WebBindings::getStringIdentifier(kTerminateMethod) == identifier; | |
| 109 } | |
| 110 | |
| 111 int Int32FromNPVariant(const NPVariant& variant) { | 67 int Int32FromNPVariant(const NPVariant& variant) { |
| 112 if (NPVARIANT_IS_INT32(variant)) | 68 if (NPVARIANT_IS_INT32(variant)) |
| 113 return NPVARIANT_TO_INT32(variant); | 69 return NPVARIANT_TO_INT32(variant); |
| 114 | 70 |
| 115 if (NPVARIANT_IS_DOUBLE(variant)) | 71 if (NPVARIANT_IS_DOUBLE(variant)) |
| 116 return NPVARIANT_TO_DOUBLE(variant); | 72 return NPVARIANT_TO_DOUBLE(variant); |
| 117 | 73 |
| 118 return 0; | 74 return 0; |
| 119 } | 75 } |
| 120 | 76 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 148 void BrowserPluginBindingsDeallocate(NPObject* object) { | 104 void BrowserPluginBindingsDeallocate(NPObject* object) { |
| 149 BrowserPluginBindings::BrowserPluginNPObject* instance = | 105 BrowserPluginBindings::BrowserPluginNPObject* instance = |
| 150 static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object); | 106 static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object); |
| 151 delete instance; | 107 delete instance; |
| 152 } | 108 } |
| 153 | 109 |
| 154 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { | 110 bool BrowserPluginBindingsHasMethod(NPObject* np_obj, NPIdentifier name) { |
| 155 if (!np_obj) | 111 if (!np_obj) |
| 156 return false; | 112 return false; |
| 157 | 113 |
| 158 if (IdentifierIsAddEventListener(name)) | 114 BrowserPluginBindings* bindings = GetBindings(np_obj); |
| 159 return true; | 115 if (!bindings) |
| 116 return false; |
| 160 | 117 |
| 161 if (IdentifierIsBackMethod(name)) | 118 return bindings->HasMethod(name); |
| 162 return true; | |
| 163 | |
| 164 if (IdentifierIsCanGoBack(name)) | |
| 165 return true; | |
| 166 | |
| 167 if (IdentifierIsCanGoForward(name)) | |
| 168 return true; | |
| 169 | |
| 170 if (IdentifierIsForwardMethod(name)) | |
| 171 return true; | |
| 172 | |
| 173 if (IdentifierIsGetProcessID(name)) | |
| 174 return true; | |
| 175 | |
| 176 if (IdentifierIsGoMethod(name)) | |
| 177 return true; | |
| 178 | |
| 179 if (IdentifierIsReload(name)) | |
| 180 return true; | |
| 181 | |
| 182 if (IdentifierIsRemoveEventListener(name)) | |
| 183 return true; | |
| 184 | |
| 185 if (IdentifierIsStop(name)) | |
| 186 return true; | |
| 187 | |
| 188 if (IdentifierIsTerminate(name)) | |
| 189 return true; | |
| 190 | |
| 191 return false; | |
| 192 } | 119 } |
| 193 | 120 |
| 194 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, | 121 bool BrowserPluginBindingsInvoke(NPObject* np_obj, NPIdentifier name, |
| 195 const NPVariant* args, uint32 arg_count, | 122 const NPVariant* args, uint32 arg_count, |
| 196 NPVariant* result) { | 123 NPVariant* result) { |
| 197 if (!np_obj) | 124 if (!np_obj) |
| 198 return false; | 125 return false; |
| 199 | 126 |
| 200 BrowserPluginBindings* bindings = GetBindings(np_obj); | 127 BrowserPluginBindings* bindings = GetBindings(np_obj); |
| 201 if (!bindings) | 128 if (!bindings) |
| 202 return false; | 129 return false; |
| 203 | 130 |
| 204 if (IdentifierIsAddEventListener(name) && (arg_count == 2)) { | 131 return bindings->InvokeMethod(name, args, arg_count, result); |
| 205 std::string event_name = StringFromNPVariant(args[0]); | |
| 206 if (event_name.empty()) | |
| 207 return false; | |
| 208 | |
| 209 v8::Local<v8::Value> value = | |
| 210 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); | |
| 211 if (value.IsEmpty() || !value->IsFunction()) | |
| 212 return false; | |
| 213 | |
| 214 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | |
| 215 result->type = NPVariantType_Bool; | |
| 216 result->value.boolValue = | |
| 217 bindings->instance()->AddEventListener(event_name, function); | |
| 218 return true; | |
| 219 } | |
| 220 | |
| 221 if (IdentifierIsBackMethod(name) && !arg_count) { | |
| 222 bindings->instance()->Back(); | |
| 223 return true; | |
| 224 } | |
| 225 | |
| 226 if (IdentifierIsCanGoBack(name) && !arg_count) { | |
| 227 result->type = NPVariantType_Bool; | |
| 228 result->value.boolValue = bindings->instance()->CanGoBack(); | |
| 229 return true; | |
| 230 } | |
| 231 | |
| 232 if (IdentifierIsCanGoForward(name) && !arg_count) { | |
| 233 result->type = NPVariantType_Bool; | |
| 234 result->value.boolValue = bindings->instance()->CanGoForward(); | |
| 235 return true; | |
| 236 } | |
| 237 | |
| 238 if (IdentifierIsForwardMethod(name) && !arg_count) { | |
| 239 bindings->instance()->Forward(); | |
| 240 return true; | |
| 241 } | |
| 242 | |
| 243 if (IdentifierIsGetProcessID(name) && !arg_count) { | |
| 244 int process_id = bindings->instance()->process_id(); | |
| 245 result->type = NPVariantType_Int32; | |
| 246 result->value.intValue = process_id; | |
| 247 return true; | |
| 248 } | |
| 249 | |
| 250 if (IdentifierIsGoMethod(name) && arg_count == 1) { | |
| 251 bindings->instance()->Go(Int32FromNPVariant(args[0])); | |
| 252 return true; | |
| 253 } | |
| 254 | |
| 255 if (IdentifierIsReload(name) && !arg_count) { | |
| 256 bindings->instance()->Reload(); | |
| 257 return true; | |
| 258 } | |
| 259 | |
| 260 if (IdentifierIsRemoveEventListener(name) && arg_count == 2) { | |
| 261 std::string event_name = StringFromNPVariant(args[0]); | |
| 262 if (event_name.empty()) | |
| 263 return false; | |
| 264 | |
| 265 v8::Local<v8::Value> value = | |
| 266 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); | |
| 267 | |
| 268 if (value.IsEmpty() || !value->IsFunction()) | |
| 269 return false; | |
| 270 | |
| 271 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | |
| 272 result->type = NPVariantType_Bool; | |
| 273 result->value.boolValue = | |
| 274 bindings->instance()->RemoveEventListener(event_name, function); | |
| 275 return true; | |
| 276 } | |
| 277 | |
| 278 if (IdentifierIsStop(name) && !arg_count) { | |
| 279 bindings->instance()->Stop(); | |
| 280 return true; | |
| 281 } | |
| 282 | |
| 283 if (IdentifierIsTerminate(name)) { | |
| 284 bindings->instance()->TerminateGuest(); | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 288 return false; | |
| 289 } | 132 } |
| 290 | 133 |
| 291 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, | 134 bool BrowserPluginBindingsInvokeDefault(NPObject* np_obj, |
| 292 const NPVariant* args, | 135 const NPVariant* args, |
| 293 uint32 arg_count, | 136 uint32 arg_count, |
| 294 NPVariant* result) { | 137 NPVariant* result) { |
| 295 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
| 296 return false; | 139 return false; |
| 297 } | 140 } |
| 298 | 141 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 &BrowserPluginBindingsInvokeDefault, | 221 &BrowserPluginBindingsInvokeDefault, |
| 379 &BrowserPluginBindingsHasProperty, | 222 &BrowserPluginBindingsHasProperty, |
| 380 &BrowserPluginBindingsGetProperty, | 223 &BrowserPluginBindingsGetProperty, |
| 381 &BrowserPluginBindingsSetProperty, | 224 &BrowserPluginBindingsSetProperty, |
| 382 NULL, | 225 NULL, |
| 383 &BrowserPluginBindingsEnumerate, | 226 &BrowserPluginBindingsEnumerate, |
| 384 }; | 227 }; |
| 385 | 228 |
| 386 } // namespace | 229 } // namespace |
| 387 | 230 |
| 231 namespace internal { |
| 232 |
| 233 class BrowserPluginMethodBinding { |
| 234 public: |
| 235 BrowserPluginMethodBinding(const char name[], uint32 arg_count) |
| 236 : name_(name), |
| 237 arg_count_(arg_count) { |
| 238 } |
| 239 |
| 240 virtual ~BrowserPluginMethodBinding() {} |
| 241 |
| 242 bool MatchesName(NPIdentifier name) const { |
| 243 return WebBindings::getStringIdentifier(name_.c_str()) == name; |
| 244 } |
| 245 |
| 246 uint32 arg_count() const { return arg_count_; } |
| 247 |
| 248 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 249 const NPVariant* args, |
| 250 NPVariant* result) = 0; |
| 251 |
| 252 private: |
| 253 std::string name_; |
| 254 uint32 arg_count_; |
| 255 |
| 256 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); |
| 257 }; |
| 258 |
| 259 class BrowserPluginBindingAddListener : public BrowserPluginMethodBinding { |
| 260 public: |
| 261 BrowserPluginBindingAddListener() |
| 262 : BrowserPluginMethodBinding(kAddEventListener, 2) { |
| 263 } |
| 264 |
| 265 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 266 const NPVariant* args, |
| 267 NPVariant* result) OVERRIDE { |
| 268 std::string event_name = StringFromNPVariant(args[0]); |
| 269 if (event_name.empty()) |
| 270 return false; |
| 271 |
| 272 v8::Local<v8::Value> value = |
| 273 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); |
| 274 if (value.IsEmpty() || !value->IsFunction()) |
| 275 return false; |
| 276 |
| 277 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
| 278 BOOLEAN_TO_NPVARIANT( |
| 279 bindings->instance()->AddEventListener(event_name, function), *result); |
| 280 return true; |
| 281 } |
| 282 |
| 283 private: |
| 284 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingAddListener); |
| 285 }; |
| 286 |
| 287 class BrowserPluginBindingBack : public BrowserPluginMethodBinding { |
| 288 public: |
| 289 BrowserPluginBindingBack() |
| 290 : BrowserPluginMethodBinding(kBackMethod, 0) { |
| 291 } |
| 292 |
| 293 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 294 const NPVariant* args, |
| 295 NPVariant* result) OVERRIDE { |
| 296 bindings->instance()->Back(); |
| 297 return true; |
| 298 } |
| 299 |
| 300 private: |
| 301 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); |
| 302 }; |
| 303 |
| 304 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding { |
| 305 public: |
| 306 BrowserPluginBindingCanGoBack() |
| 307 : BrowserPluginMethodBinding(kCanGoBack, 0) { |
| 308 } |
| 309 |
| 310 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 311 const NPVariant* args, |
| 312 NPVariant* result) OVERRIDE { |
| 313 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoBack(), *result); |
| 314 return true; |
| 315 } |
| 316 |
| 317 private: |
| 318 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); |
| 319 }; |
| 320 |
| 321 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding { |
| 322 public: |
| 323 BrowserPluginBindingCanGoForward() |
| 324 : BrowserPluginMethodBinding(kCanGoForward, 0) { |
| 325 } |
| 326 |
| 327 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 328 const NPVariant* args, |
| 329 NPVariant* result) OVERRIDE { |
| 330 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoForward(), *result); |
| 331 return true; |
| 332 } |
| 333 |
| 334 private: |
| 335 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); |
| 336 }; |
| 337 |
| 338 class BrowserPluginBindingForward : public BrowserPluginMethodBinding { |
| 339 public: |
| 340 BrowserPluginBindingForward() |
| 341 : BrowserPluginMethodBinding(kForwardMethod, 0) { |
| 342 } |
| 343 |
| 344 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 345 const NPVariant* args, |
| 346 NPVariant* result) OVERRIDE { |
| 347 bindings->instance()->Forward(); |
| 348 return true; |
| 349 } |
| 350 |
| 351 private: |
| 352 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); |
| 353 }; |
| 354 |
| 355 class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding { |
| 356 public: |
| 357 BrowserPluginBindingGetProcessID() |
| 358 : BrowserPluginMethodBinding(kGetProcessId, 0) { |
| 359 } |
| 360 |
| 361 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 362 const NPVariant* args, |
| 363 NPVariant* result) OVERRIDE { |
| 364 int process_id = bindings->instance()->process_id(); |
| 365 INT32_TO_NPVARIANT(process_id, *result); |
| 366 return true; |
| 367 } |
| 368 |
| 369 private: |
| 370 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); |
| 371 }; |
| 372 |
| 373 class BrowserPluginBindingGo : public BrowserPluginMethodBinding { |
| 374 public: |
| 375 BrowserPluginBindingGo() |
| 376 : BrowserPluginMethodBinding(kGoMethod, 1) { |
| 377 } |
| 378 |
| 379 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 380 const NPVariant* args, |
| 381 NPVariant* result) OVERRIDE { |
| 382 bindings->instance()->Go(Int32FromNPVariant(args[0])); |
| 383 return true; |
| 384 } |
| 385 |
| 386 private: |
| 387 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); |
| 388 }; |
| 389 |
| 390 class BrowserPluginBindingReload : public BrowserPluginMethodBinding { |
| 391 public: |
| 392 BrowserPluginBindingReload() |
| 393 : BrowserPluginMethodBinding(kReloadMethod, 0) { |
| 394 } |
| 395 |
| 396 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 397 const NPVariant* args, |
| 398 NPVariant* result) OVERRIDE { |
| 399 bindings->instance()->Reload(); |
| 400 return true; |
| 401 } |
| 402 |
| 403 private: |
| 404 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); |
| 405 }; |
| 406 |
| 407 class BrowserPluginBindingRemoveListener : public BrowserPluginMethodBinding { |
| 408 public: |
| 409 BrowserPluginBindingRemoveListener() |
| 410 : BrowserPluginMethodBinding(kRemoveEventListener, 2) { |
| 411 } |
| 412 |
| 413 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 414 const NPVariant* args, |
| 415 NPVariant* result) OVERRIDE { |
| 416 std::string event_name = StringFromNPVariant(args[0]); |
| 417 if (event_name.empty()) |
| 418 return false; |
| 419 |
| 420 v8::Local<v8::Value> value = |
| 421 v8::Local<v8::Value>::New(WebBindings::toV8Value(&args[1])); |
| 422 |
| 423 if (value.IsEmpty() || !value->IsFunction()) |
| 424 return false; |
| 425 |
| 426 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
| 427 BOOLEAN_TO_NPVARIANT( |
| 428 bindings->instance()->RemoveEventListener(event_name, function), |
| 429 *result); |
| 430 return true; |
| 431 } |
| 432 |
| 433 private: |
| 434 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingRemoveListener); |
| 435 }; |
| 436 |
| 437 class BrowserPluginBindingStop : public BrowserPluginMethodBinding { |
| 438 public: |
| 439 BrowserPluginBindingStop() |
| 440 : BrowserPluginMethodBinding(kStopMethod, 0) { |
| 441 } |
| 442 |
| 443 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 444 const NPVariant* args, |
| 445 NPVariant* result) OVERRIDE { |
| 446 bindings->instance()->Stop(); |
| 447 return true; |
| 448 } |
| 449 |
| 450 private: |
| 451 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); |
| 452 }; |
| 453 |
| 454 class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding { |
| 455 public: |
| 456 BrowserPluginBindingTerminate() |
| 457 : BrowserPluginMethodBinding(kTerminateMethod, 0) { |
| 458 } |
| 459 |
| 460 virtual bool Invoke(BrowserPluginBindings* bindings, |
| 461 const NPVariant* args, |
| 462 NPVariant* result) OVERRIDE { |
| 463 bindings->instance()->TerminateGuest(); |
| 464 return true; |
| 465 } |
| 466 |
| 467 private: |
| 468 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); |
| 469 }; |
| 470 |
| 471 } // namespace internal |
| 472 |
| 388 // BrowserPluginBindings ------------------------------------------------------ | 473 // BrowserPluginBindings ------------------------------------------------------ |
| 389 | 474 |
| 390 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 475 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
| 391 } | 476 } |
| 392 | 477 |
| 393 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 478 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
| 394 } | 479 } |
| 395 | 480 |
| 396 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 481 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) |
| 397 : instance_(instance), | 482 : instance_(instance), |
| 398 np_object_(NULL), | 483 np_object_(NULL), |
| 399 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 484 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 400 NPObject* obj = | 485 NPObject* obj = |
| 401 WebBindings::createObject(NULL, &browser_plugin_message_class); | 486 WebBindings::createObject(NULL, &browser_plugin_message_class); |
| 402 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 487 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
| 403 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 488 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
| 489 |
| 490 method_bindings_.push_back(new internal::BrowserPluginBindingAddListener); |
| 491 method_bindings_.push_back(new internal::BrowserPluginBindingBack); |
| 492 method_bindings_.push_back(new internal::BrowserPluginBindingCanGoBack); |
| 493 method_bindings_.push_back(new internal::BrowserPluginBindingCanGoForward); |
| 494 method_bindings_.push_back(new internal::BrowserPluginBindingForward); |
| 495 method_bindings_.push_back(new internal::BrowserPluginBindingGetProcessID); |
| 496 method_bindings_.push_back(new internal::BrowserPluginBindingGo); |
| 497 method_bindings_.push_back(new internal::BrowserPluginBindingReload); |
| 498 method_bindings_.push_back(new internal::BrowserPluginBindingRemoveListener); |
| 499 method_bindings_.push_back(new internal::BrowserPluginBindingStop); |
| 500 method_bindings_.push_back(new internal::BrowserPluginBindingTerminate); |
| 404 } | 501 } |
| 405 | 502 |
| 406 BrowserPluginBindings::~BrowserPluginBindings() { | 503 BrowserPluginBindings::~BrowserPluginBindings() { |
| 407 WebBindings::releaseObject(np_object_); | 504 WebBindings::releaseObject(np_object_); |
| 408 } | 505 } |
| 409 | 506 |
| 507 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
| 508 for (BindingList::const_iterator iter = method_bindings_.begin(); |
| 509 iter != method_bindings_.end(); |
| 510 ++iter) { |
| 511 if ((*iter)->MatchesName(name)) |
| 512 return true; |
| 513 } |
| 514 return false; |
| 515 } |
| 516 |
| 517 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, |
| 518 const NPVariant* args, |
| 519 uint32 arg_count, |
| 520 NPVariant* result) { |
| 521 for (BindingList::iterator iter = method_bindings_.begin(); |
| 522 iter != method_bindings_.end(); |
| 523 ++iter) { |
| 524 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) |
| 525 return (*iter)->Invoke(this, args, result); |
| 526 } |
| 527 return false; |
| 528 } |
| 529 |
| 410 } // namespace content | 530 } // namespace content |
| OLD | NEW |