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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/renderer/browser_plugin/browser_plugin.h" | 16 #include "content/public/renderer/browser_plugin/browser_plugin_method_binding.h " |
17 #include "content/public/renderer/browser_plugin/browser_plugin_property_binding .h" | |
18 #include "content/renderer/browser_plugin/browser_plugin_impl.h" | |
17 #include "third_party/npapi/bindings/npapi.h" | 19 #include "third_party/npapi/bindings/npapi.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
26 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 &BrowserPluginBindingsInvokeDefault, | 199 &BrowserPluginBindingsInvokeDefault, |
198 &BrowserPluginBindingsHasProperty, | 200 &BrowserPluginBindingsHasProperty, |
199 &BrowserPluginBindingsGetProperty, | 201 &BrowserPluginBindingsGetProperty, |
200 &BrowserPluginBindingsSetProperty, | 202 &BrowserPluginBindingsSetProperty, |
201 NULL, | 203 NULL, |
202 &BrowserPluginBindingsEnumerate, | 204 &BrowserPluginBindingsEnumerate, |
203 }; | 205 }; |
204 | 206 |
205 } // namespace | 207 } // namespace |
206 | 208 |
207 // BrowserPluginMethodBinding -------------------------------------------------- | 209 // Method Bindings ------------------------------------------------------------ |
208 | 210 |
209 class BrowserPluginMethodBinding { | 211 class BrowserPluginMethodBindingImpl : public BrowserPluginMethodBinding { |
210 public: | 212 public: |
211 BrowserPluginMethodBinding(const char name[], uint32 arg_count) | 213 BrowserPluginMethodBindingImpl(const char name[], uint32 arg_count) |
212 : name_(name), | 214 : name_(name), |
213 arg_count_(arg_count) { | 215 arg_count_(arg_count) { |
214 } | 216 } |
215 | 217 |
216 virtual ~BrowserPluginMethodBinding() {} | 218 virtual ~BrowserPluginMethodBindingImpl() {} |
217 | 219 |
218 bool MatchesName(NPIdentifier name) const { | 220 virtual bool MatchesName(const NPIdentifier& name) const OVERRIDE { |
219 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 221 return WebKit::WebBindings::getStringIdentifier(name_.c_str()) == name; |
220 } | 222 } |
221 | 223 |
222 uint32 arg_count() const { return arg_count_; } | 224 virtual uint32 GetArgCount() const OVERRIDE { return arg_count_; } |
223 | |
224 virtual bool Invoke(BrowserPluginBindings* bindings, | |
225 const NPVariant* args, | |
226 NPVariant* result) = 0; | |
227 | 225 |
228 private: | 226 private: |
229 std::string name_; | 227 std::string name_; |
230 uint32 arg_count_; | 228 uint32 arg_count_; |
231 | 229 |
232 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); | 230 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBindingImpl); |
233 }; | 231 }; |
234 | 232 |
235 class BrowserPluginBindingBack : public BrowserPluginMethodBinding { | 233 class BrowserPluginBindingBack : public BrowserPluginMethodBindingImpl { |
236 public: | 234 public: |
237 BrowserPluginBindingBack() | 235 BrowserPluginBindingBack() |
238 : BrowserPluginMethodBinding(kMethodBack, 0) { | 236 : BrowserPluginMethodBindingImpl(kMethodBack, 0) { |
239 } | 237 } |
240 | 238 |
241 virtual bool Invoke(BrowserPluginBindings* bindings, | 239 virtual bool Invoke(BrowserPlugin* browser_plugin, |
242 const NPVariant* args, | 240 const NPVariant* args, |
243 NPVariant* result) OVERRIDE { | 241 NPVariant* result) OVERRIDE { |
244 bindings->instance()->Back(); | 242 static_cast<BrowserPluginImpl*>(browser_plugin)->Back(); |
245 return true; | 243 return true; |
246 } | 244 } |
247 | 245 |
248 private: | 246 private: |
249 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); | 247 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); |
250 }; | 248 }; |
251 | 249 |
252 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding { | 250 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBindingImpl { |
253 public: | 251 public: |
254 BrowserPluginBindingCanGoBack() | 252 BrowserPluginBindingCanGoBack() |
255 : BrowserPluginMethodBinding(kMethodCanGoBack, 0) { | 253 : BrowserPluginMethodBindingImpl(kMethodCanGoBack, 0) { |
256 } | 254 } |
257 | 255 |
258 virtual bool Invoke(BrowserPluginBindings* bindings, | 256 virtual bool Invoke(BrowserPlugin* browser_plugin, |
259 const NPVariant* args, | 257 const NPVariant* args, |
260 NPVariant* result) OVERRIDE { | 258 NPVariant* result) OVERRIDE { |
261 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoBack(), *result); | 259 BOOLEAN_TO_NPVARIANT( |
260 static_cast<BrowserPluginImpl*>(browser_plugin)->CanGoBack(), *result); | |
262 return true; | 261 return true; |
263 } | 262 } |
264 | 263 |
265 private: | 264 private: |
266 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); | 265 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); |
267 }; | 266 }; |
268 | 267 |
269 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding { | 268 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBindingImpl { |
270 public: | 269 public: |
271 BrowserPluginBindingCanGoForward() | 270 BrowserPluginBindingCanGoForward() |
272 : BrowserPluginMethodBinding(kMethodCanGoForward, 0) { | 271 : BrowserPluginMethodBindingImpl(kMethodCanGoForward, 0) { |
273 } | 272 } |
274 | 273 |
275 virtual bool Invoke(BrowserPluginBindings* bindings, | 274 virtual bool Invoke(BrowserPlugin* browser_plugin, |
276 const NPVariant* args, | 275 const NPVariant* args, |
277 NPVariant* result) OVERRIDE { | 276 NPVariant* result) OVERRIDE { |
278 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoForward(), *result); | 277 BOOLEAN_TO_NPVARIANT( |
278 static_cast<BrowserPluginImpl*>(browser_plugin)->CanGoForward(), | |
279 *result); | |
279 return true; | 280 return true; |
280 } | 281 } |
281 | 282 |
282 private: | 283 private: |
283 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); | 284 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); |
284 }; | 285 }; |
285 | 286 |
286 class BrowserPluginBindingForward : public BrowserPluginMethodBinding { | 287 class BrowserPluginBindingForward : public BrowserPluginMethodBindingImpl { |
287 public: | 288 public: |
288 BrowserPluginBindingForward() | 289 BrowserPluginBindingForward() |
289 : BrowserPluginMethodBinding(kMethodForward, 0) { | 290 : BrowserPluginMethodBindingImpl(kMethodForward, 0) { |
290 } | 291 } |
291 | 292 |
292 virtual bool Invoke(BrowserPluginBindings* bindings, | 293 virtual bool Invoke(BrowserPlugin* browser_plugin, |
293 const NPVariant* args, | 294 const NPVariant* args, |
294 NPVariant* result) OVERRIDE { | 295 NPVariant* result) OVERRIDE { |
295 bindings->instance()->Forward(); | 296 static_cast<BrowserPluginImpl*>(browser_plugin)->Forward(); |
296 return true; | 297 return true; |
297 } | 298 } |
298 | 299 |
299 private: | 300 private: |
300 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); | 301 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); |
301 }; | 302 }; |
302 | 303 |
303 class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding { | 304 class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBindingImpl { |
304 public: | 305 public: |
305 BrowserPluginBindingGetProcessID() | 306 BrowserPluginBindingGetProcessID() |
306 : BrowserPluginMethodBinding(kMethodGetProcessId, 0) { | 307 : BrowserPluginMethodBindingImpl(kMethodGetProcessId, 0) { |
307 } | 308 } |
308 | 309 |
309 virtual bool Invoke(BrowserPluginBindings* bindings, | 310 virtual bool Invoke(BrowserPlugin* browser_plugin, |
310 const NPVariant* args, | 311 const NPVariant* args, |
311 NPVariant* result) OVERRIDE { | 312 NPVariant* result) OVERRIDE { |
312 int process_id = bindings->instance()->process_id(); | 313 int process_id = static_cast<BrowserPluginImpl*>( |
314 browser_plugin)->process_id(); | |
313 INT32_TO_NPVARIANT(process_id, *result); | 315 INT32_TO_NPVARIANT(process_id, *result); |
314 return true; | 316 return true; |
315 } | 317 } |
316 | 318 |
317 private: | 319 private: |
318 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); | 320 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); |
319 }; | 321 }; |
320 | 322 |
321 class BrowserPluginBindingGo : public BrowserPluginMethodBinding { | 323 class BrowserPluginBindingGo : public BrowserPluginMethodBindingImpl { |
322 public: | 324 public: |
323 BrowserPluginBindingGo() | 325 BrowserPluginBindingGo() |
324 : BrowserPluginMethodBinding(kMethodGo, 1) { | 326 : BrowserPluginMethodBindingImpl(kMethodGo, 1) { |
325 } | 327 } |
326 | 328 |
327 virtual bool Invoke(BrowserPluginBindings* bindings, | 329 virtual bool Invoke(BrowserPlugin* browser_plugin, |
328 const NPVariant* args, | 330 const NPVariant* args, |
329 NPVariant* result) OVERRIDE { | 331 NPVariant* result) OVERRIDE { |
330 bindings->instance()->Go(Int32FromNPVariant(args[0])); | 332 static_cast<BrowserPluginImpl*>(browser_plugin)->Go( |
333 Int32FromNPVariant(args[0])); | |
331 return true; | 334 return true; |
332 } | 335 } |
333 | 336 |
334 private: | 337 private: |
335 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); | 338 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); |
336 }; | 339 }; |
337 | 340 |
338 class BrowserPluginBindingReload : public BrowserPluginMethodBinding { | 341 class BrowserPluginBindingReload : public BrowserPluginMethodBindingImpl { |
339 public: | 342 public: |
340 BrowserPluginBindingReload() | 343 BrowserPluginBindingReload() |
341 : BrowserPluginMethodBinding(kMethodReload, 0) { | 344 : BrowserPluginMethodBindingImpl(kMethodReload, 0) { |
342 } | 345 } |
343 | 346 |
344 virtual bool Invoke(BrowserPluginBindings* bindings, | 347 virtual bool Invoke(BrowserPlugin* browser_plugin, |
345 const NPVariant* args, | 348 const NPVariant* args, |
346 NPVariant* result) OVERRIDE { | 349 NPVariant* result) OVERRIDE { |
347 bindings->instance()->Reload(); | 350 static_cast<BrowserPluginImpl*>(browser_plugin)->Reload(); |
348 return true; | 351 return true; |
349 } | 352 } |
350 | 353 |
351 private: | 354 private: |
352 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); | 355 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); |
353 }; | 356 }; |
354 | 357 |
355 class BrowserPluginBindingStop : public BrowserPluginMethodBinding { | 358 class BrowserPluginBindingStop : public BrowserPluginMethodBindingImpl { |
356 public: | 359 public: |
357 BrowserPluginBindingStop() | 360 BrowserPluginBindingStop() |
358 : BrowserPluginMethodBinding(kMethodStop, 0) { | 361 : BrowserPluginMethodBindingImpl(kMethodStop, 0) { |
359 } | 362 } |
360 | 363 |
361 virtual bool Invoke(BrowserPluginBindings* bindings, | 364 virtual bool Invoke(BrowserPlugin* browser_plugin, |
362 const NPVariant* args, | 365 const NPVariant* args, |
363 NPVariant* result) OVERRIDE { | 366 NPVariant* result) OVERRIDE { |
364 bindings->instance()->Stop(); | 367 static_cast<BrowserPluginImpl*>(browser_plugin)->Stop(); |
365 return true; | 368 return true; |
366 } | 369 } |
367 | 370 |
368 private: | 371 private: |
369 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); | 372 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); |
370 }; | 373 }; |
371 | 374 |
372 class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding { | 375 class BrowserPluginBindingTerminate : public BrowserPluginMethodBindingImpl { |
373 public: | 376 public: |
374 BrowserPluginBindingTerminate() | 377 BrowserPluginBindingTerminate() |
375 : BrowserPluginMethodBinding(kMethodTerminate, 0) { | 378 : BrowserPluginMethodBindingImpl(kMethodTerminate, 0) { |
376 } | 379 } |
377 | 380 |
378 virtual bool Invoke(BrowserPluginBindings* bindings, | 381 virtual bool Invoke(BrowserPlugin* browser_plugin, |
379 const NPVariant* args, | 382 const NPVariant* args, |
380 NPVariant* result) OVERRIDE { | 383 NPVariant* result) OVERRIDE { |
381 bindings->instance()->TerminateGuest(); | 384 static_cast<BrowserPluginImpl*>(browser_plugin)->TerminateGuest(); |
sadrul
2013/01/09 15:21:54
no-op comment: All these static_casts seem a bit a
Fady Samuel
2013/01/09 17:41:24
Sigh, neither can I :-(
| |
382 return true; | 385 return true; |
383 } | 386 } |
384 | 387 |
385 private: | 388 private: |
386 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); | 389 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); |
387 }; | 390 }; |
388 | 391 |
389 // BrowserPluginPropertyBinding ------------------------------------------------ | 392 // Property Bindings ---------------------------------------------------------- |
390 | 393 |
391 class BrowserPluginPropertyBinding { | 394 class BrowserPluginPropertyBindingImpl : public BrowserPluginPropertyBinding { |
392 public: | 395 public: |
393 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { | 396 explicit BrowserPluginPropertyBindingImpl(const char name[]) : name_(name) { |
394 } | 397 } |
395 virtual ~BrowserPluginPropertyBinding() {} | 398 |
396 const std::string& name() const { return name_; } | 399 virtual ~BrowserPluginPropertyBindingImpl() {} |
397 bool MatchesName(NPIdentifier name) const { | 400 |
398 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 401 virtual const std::string& GetName() const OVERRIDE { |
402 return name_; | |
399 } | 403 } |
400 virtual bool GetProperty(BrowserPluginBindings* bindings, | 404 |
401 NPVariant* result) = 0; | 405 virtual bool MatchesName(NPIdentifier name) const OVERRIDE { |
402 virtual bool SetProperty(BrowserPluginBindings* bindings, | 406 return WebKit::WebBindings::getStringIdentifier(name_.c_str()) == name; |
403 NPObject* np_obj, | |
404 const NPVariant* variant) = 0; | |
405 virtual std::string GetDOMAttributeValue(BrowserPlugin* browser_plugin) = 0; | |
406 // Updates the DOM Attribute value with the current property value. | |
407 void UpdateDOMAttribute(BrowserPluginBindings* bindings) { | |
408 bindings->instance()->UpdateDOMAttribute(name(), | |
409 GetDOMAttributeValue(bindings->instance())); | |
410 } | 407 } |
408 | |
411 private: | 409 private: |
412 std::string name_; | 410 std::string name_; |
413 | 411 |
414 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); | 412 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingImpl); |
415 }; | 413 }; |
416 | 414 |
417 class BrowserPluginPropertyBindingAutoSize | 415 class BrowserPluginPropertyBindingAutoSize |
418 : public BrowserPluginPropertyBinding { | 416 : public BrowserPluginPropertyBindingImpl { |
419 public: | 417 public: |
420 BrowserPluginPropertyBindingAutoSize() : | 418 BrowserPluginPropertyBindingAutoSize() : |
421 BrowserPluginPropertyBinding(kAttributeAutoSize) { | 419 BrowserPluginPropertyBindingImpl(kAttributeAutoSize) { |
422 } | 420 } |
423 virtual bool GetProperty(BrowserPluginBindings* bindings, | 421 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
424 NPVariant* result) OVERRIDE { | 422 NPVariant* result) OVERRIDE { |
425 bool auto_size = bindings->instance()->auto_size_attribute(); | 423 bool auto_size = static_cast<BrowserPluginImpl*>( |
424 browser_plugin)->auto_size_attribute(); | |
426 BOOLEAN_TO_NPVARIANT(auto_size, *result); | 425 BOOLEAN_TO_NPVARIANT(auto_size, *result); |
427 return true; | 426 return true; |
428 } | 427 } |
429 virtual bool SetProperty(BrowserPluginBindings* bindings, | 428 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
430 NPObject* np_obj, | 429 NPObject* np_obj, |
431 const NPVariant* variant) OVERRIDE { | 430 const NPVariant* variant) OVERRIDE { |
432 bool auto_size = NPVARIANT_TO_BOOLEAN(*variant); | 431 bool auto_size = NPVARIANT_TO_BOOLEAN(*variant); |
433 bindings->instance()->SetAutoSizeAttribute(auto_size); | 432 static_cast<BrowserPluginImpl*>(browser_plugin)-> |
433 SetAutoSizeAttribute(auto_size); | |
434 return true; | 434 return true; |
435 } | 435 } |
436 virtual std::string GetDOMAttributeValue( | 436 virtual std::string GetDOMAttributeValue( |
437 BrowserPlugin* browser_plugin) OVERRIDE { | 437 BrowserPlugin* browser_plugin) OVERRIDE { |
438 return browser_plugin->auto_size_attribute() ? "true" : "false"; | 438 return static_cast<BrowserPluginImpl*>(browser_plugin)-> |
439 auto_size_attribute() ? "true" : "false"; | |
439 } | 440 } |
440 private: | 441 private: |
441 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | 442 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); |
442 }; | 443 }; |
443 | 444 |
444 class BrowserPluginPropertyBindingContentWindow | 445 class BrowserPluginPropertyBindingContentWindow |
445 : public BrowserPluginPropertyBinding { | 446 : public BrowserPluginPropertyBindingImpl { |
446 public: | 447 public: |
447 BrowserPluginPropertyBindingContentWindow() : | 448 BrowserPluginPropertyBindingContentWindow() : |
448 BrowserPluginPropertyBinding(kAttributeContentWindow) { | 449 BrowserPluginPropertyBindingImpl(kAttributeContentWindow) { |
449 } | 450 } |
450 virtual bool GetProperty(BrowserPluginBindings* bindings, | 451 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
451 NPVariant* result) OVERRIDE { | 452 NPVariant* result) OVERRIDE { |
452 NPObject* obj = bindings->instance()->GetContentWindow(); | 453 NPObject* obj = static_cast<BrowserPluginImpl*>( |
454 browser_plugin)->GetContentWindow(); | |
453 if (obj) { | 455 if (obj) { |
454 result->type = NPVariantType_Object; | 456 result->type = NPVariantType_Object; |
455 result->value.objectValue = WebBindings::retainObject(obj); | 457 result->value.objectValue = WebBindings::retainObject(obj); |
456 } | 458 } |
457 return true; | 459 return true; |
458 } | 460 } |
459 virtual bool SetProperty(BrowserPluginBindings* bindings, | 461 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
460 NPObject* np_obj, | 462 NPObject* np_obj, |
461 const NPVariant* variant) OVERRIDE { | 463 const NPVariant* variant) OVERRIDE { |
462 return false; | 464 return false; |
463 } | 465 } |
464 virtual std::string GetDOMAttributeValue(BrowserPlugin* browser_plugin) { | 466 virtual std::string GetDOMAttributeValue(BrowserPlugin* browser_plugin) { |
465 return std::string(); | 467 return std::string(); |
466 } | 468 } |
467 private: | 469 private: |
468 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 470 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
469 }; | 471 }; |
470 | 472 |
471 class BrowserPluginPropertyBindingMaxHeight | 473 class BrowserPluginPropertyBindingMaxHeight |
472 : public BrowserPluginPropertyBinding { | 474 : public BrowserPluginPropertyBindingImpl { |
473 public: | 475 public: |
474 BrowserPluginPropertyBindingMaxHeight() : | 476 BrowserPluginPropertyBindingMaxHeight() : |
475 BrowserPluginPropertyBinding(kAttributeMaxHeight) { | 477 BrowserPluginPropertyBindingImpl(kAttributeMaxHeight) { |
476 } | 478 } |
477 virtual bool GetProperty(BrowserPluginBindings* bindings, | 479 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
478 NPVariant* result) OVERRIDE { | 480 NPVariant* result) OVERRIDE { |
479 int max_height = bindings->instance()->max_height_attribute(); | 481 int max_height = static_cast<BrowserPluginImpl*>( |
482 browser_plugin)->max_height_attribute(); | |
480 INT32_TO_NPVARIANT(max_height, *result); | 483 INT32_TO_NPVARIANT(max_height, *result); |
481 return true; | 484 return true; |
482 } | 485 } |
483 virtual bool SetProperty(BrowserPluginBindings* bindings, | 486 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
484 NPObject* np_obj, | 487 NPObject* np_obj, |
485 const NPVariant* variant) OVERRIDE { | 488 const NPVariant* variant) OVERRIDE { |
486 int max_height = Int32FromNPVariant(*variant); | 489 int max_height = Int32FromNPVariant(*variant); |
487 bindings->instance()->SetMaxHeightAttribute(max_height); | 490 static_cast<BrowserPluginImpl*>(browser_plugin)-> |
491 SetMaxHeightAttribute(max_height); | |
488 return true; | 492 return true; |
489 } | 493 } |
490 virtual std::string GetDOMAttributeValue( | 494 virtual std::string GetDOMAttributeValue( |
491 BrowserPlugin* browser_plugin) OVERRIDE { | 495 BrowserPlugin* browser_plugin) OVERRIDE { |
492 return base::IntToString(browser_plugin->max_height_attribute()); | 496 return base::IntToString(static_cast<BrowserPluginImpl*>(browser_plugin)-> |
497 max_height_attribute()); | |
493 } | 498 } |
494 private: | 499 private: |
495 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | 500 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); |
496 }; | 501 }; |
497 | 502 |
498 class BrowserPluginPropertyBindingMaxWidth | 503 class BrowserPluginPropertyBindingMaxWidth |
499 : public BrowserPluginPropertyBinding { | 504 : public BrowserPluginPropertyBindingImpl { |
500 public: | 505 public: |
501 BrowserPluginPropertyBindingMaxWidth() : | 506 BrowserPluginPropertyBindingMaxWidth() : |
502 BrowserPluginPropertyBinding(kAttributeMaxWidth) { | 507 BrowserPluginPropertyBindingImpl(kAttributeMaxWidth) { |
503 } | 508 } |
504 virtual bool GetProperty(BrowserPluginBindings* bindings, | 509 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
505 NPVariant* result) OVERRIDE { | 510 NPVariant* result) OVERRIDE { |
506 int max_width = bindings->instance()->max_width_attribute(); | 511 int max_width = static_cast<BrowserPluginImpl*>( |
512 browser_plugin)->max_width_attribute(); | |
507 INT32_TO_NPVARIANT(max_width, *result); | 513 INT32_TO_NPVARIANT(max_width, *result); |
508 return true; | 514 return true; |
509 } | 515 } |
510 virtual bool SetProperty(BrowserPluginBindings* bindings, | 516 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
511 NPObject* np_obj, | 517 NPObject* np_obj, |
512 const NPVariant* variant) OVERRIDE { | 518 const NPVariant* variant) OVERRIDE { |
513 int max_width = Int32FromNPVariant(*variant); | 519 int max_width = Int32FromNPVariant(*variant); |
514 bindings->instance()->SetMaxWidthAttribute(max_width); | 520 static_cast<BrowserPluginImpl*>(browser_plugin)-> |
521 SetMaxWidthAttribute(max_width); | |
515 return true; | 522 return true; |
516 } | 523 } |
517 virtual std::string GetDOMAttributeValue( | 524 virtual std::string GetDOMAttributeValue( |
518 BrowserPlugin* browser_plugin) OVERRIDE { | 525 BrowserPlugin* browser_plugin) OVERRIDE { |
519 return base::IntToString(browser_plugin->max_width_attribute()); | 526 return base::IntToString(static_cast<BrowserPluginImpl*>(browser_plugin)-> |
527 max_width_attribute()); | |
520 } | 528 } |
521 private: | 529 private: |
522 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | 530 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); |
523 }; | 531 }; |
524 | 532 |
525 class BrowserPluginPropertyBindingMinHeight | 533 class BrowserPluginPropertyBindingMinHeight |
526 : public BrowserPluginPropertyBinding { | 534 : public BrowserPluginPropertyBindingImpl { |
527 public: | 535 public: |
528 BrowserPluginPropertyBindingMinHeight() : | 536 BrowserPluginPropertyBindingMinHeight() : |
529 BrowserPluginPropertyBinding(kAttributeMinHeight) { | 537 BrowserPluginPropertyBindingImpl(kAttributeMinHeight) { |
530 } | 538 } |
531 virtual bool GetProperty(BrowserPluginBindings* bindings, | 539 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
532 NPVariant* result) OVERRIDE { | 540 NPVariant* result) OVERRIDE { |
533 int min_height = bindings->instance()->min_height_attribute(); | 541 int min_height = static_cast<BrowserPluginImpl*>( |
542 browser_plugin)->min_height_attribute(); | |
534 INT32_TO_NPVARIANT(min_height, *result); | 543 INT32_TO_NPVARIANT(min_height, *result); |
535 return true; | 544 return true; |
536 } | 545 } |
537 virtual bool SetProperty(BrowserPluginBindings* bindings, | 546 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
538 NPObject* np_obj, | 547 NPObject* np_obj, |
539 const NPVariant* variant) OVERRIDE { | 548 const NPVariant* variant) OVERRIDE { |
540 int min_height = Int32FromNPVariant(*variant); | 549 int min_height = Int32FromNPVariant(*variant); |
541 bindings->instance()->SetMinHeightAttribute(min_height); | 550 static_cast<BrowserPluginImpl*>(browser_plugin)-> |
551 SetMinHeightAttribute(min_height); | |
542 return true; | 552 return true; |
543 } | 553 } |
544 virtual std::string GetDOMAttributeValue( | 554 virtual std::string GetDOMAttributeValue( |
545 BrowserPlugin* browser_plugin) OVERRIDE { | 555 BrowserPlugin* browser_plugin) OVERRIDE { |
546 return base::IntToString(browser_plugin->min_height_attribute()); | 556 return base::IntToString(static_cast<BrowserPluginImpl*>( |
557 browser_plugin)->min_height_attribute()); | |
547 } | 558 } |
548 private: | 559 private: |
549 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | 560 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); |
550 }; | 561 }; |
551 | 562 |
552 class BrowserPluginPropertyBindingMinWidth | 563 class BrowserPluginPropertyBindingMinWidth |
553 : public BrowserPluginPropertyBinding { | 564 : public BrowserPluginPropertyBindingImpl { |
554 public: | 565 public: |
555 BrowserPluginPropertyBindingMinWidth() : | 566 BrowserPluginPropertyBindingMinWidth() : |
556 BrowserPluginPropertyBinding(kAttributeMinWidth) { | 567 BrowserPluginPropertyBindingImpl(kAttributeMinWidth) { |
557 } | 568 } |
558 virtual bool GetProperty(BrowserPluginBindings* bindings, | 569 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
559 NPVariant* result) OVERRIDE { | 570 NPVariant* result) OVERRIDE { |
560 int min_width = bindings->instance()->min_width_attribute(); | 571 int min_width = static_cast<BrowserPluginImpl*>( |
572 browser_plugin)->min_width_attribute(); | |
561 INT32_TO_NPVARIANT(min_width, *result); | 573 INT32_TO_NPVARIANT(min_width, *result); |
562 return true; | 574 return true; |
563 } | 575 } |
564 virtual bool SetProperty(BrowserPluginBindings* bindings, | 576 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
565 NPObject* np_obj, | 577 NPObject* np_obj, |
566 const NPVariant* variant) OVERRIDE { | 578 const NPVariant* variant) OVERRIDE { |
567 int min_width = Int32FromNPVariant(*variant); | 579 int min_width = Int32FromNPVariant(*variant); |
568 bindings->instance()->SetMinWidthAttribute(min_width); | 580 static_cast<BrowserPluginImpl*>(browser_plugin)-> |
581 SetMinWidthAttribute(min_width); | |
569 return true; | 582 return true; |
570 } | 583 } |
571 virtual std::string GetDOMAttributeValue( | 584 virtual std::string GetDOMAttributeValue( |
572 BrowserPlugin* browser_plugin) OVERRIDE { | 585 BrowserPlugin* browser_plugin) OVERRIDE { |
573 return base::IntToString(browser_plugin->min_width_attribute()); | 586 return base::IntToString(static_cast<BrowserPluginImpl*>( |
587 browser_plugin)->min_width_attribute()); | |
574 } | 588 } |
575 private: | 589 private: |
576 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 590 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
577 }; | 591 }; |
578 | 592 |
579 class BrowserPluginPropertyBindingPartition | 593 class BrowserPluginPropertyBindingPartition |
580 : public BrowserPluginPropertyBinding { | 594 : public BrowserPluginPropertyBindingImpl { |
581 public: | 595 public: |
582 BrowserPluginPropertyBindingPartition() : | 596 BrowserPluginPropertyBindingPartition() : |
583 BrowserPluginPropertyBinding(kAttributePartition) { | 597 BrowserPluginPropertyBindingImpl(kAttributePartition) { |
584 } | 598 } |
585 virtual bool GetProperty(BrowserPluginBindings* bindings, | 599 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
586 NPVariant* result) OVERRIDE { | 600 NPVariant* result) OVERRIDE { |
587 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 601 std::string partition_id = static_cast<BrowserPluginImpl*>( |
602 browser_plugin)->GetPartitionAttribute(); | |
588 return StringToNPVariant(partition_id, result); | 603 return StringToNPVariant(partition_id, result); |
589 } | 604 } |
590 virtual bool SetProperty(BrowserPluginBindings* bindings, | 605 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
591 NPObject* np_obj, | 606 NPObject* np_obj, |
592 const NPVariant* variant) OVERRIDE { | 607 const NPVariant* variant) OVERRIDE { |
593 std::string partition_id = StringFromNPVariant(*variant); | 608 std::string partition_id = StringFromNPVariant(*variant); |
594 std::string error_message; | 609 std::string error_message; |
595 if (!bindings->instance()->SetPartitionAttribute(partition_id, | 610 if (!static_cast<BrowserPluginImpl*>(browser_plugin)-> |
596 &error_message)) { | 611 SetPartitionAttribute(partition_id, &error_message)) { |
597 WebBindings::setException( | 612 WebBindings::setException( |
598 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 613 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
599 return false; | 614 return false; |
600 } | 615 } |
601 return true; | 616 return true; |
602 } | 617 } |
603 virtual std::string GetDOMAttributeValue( | 618 virtual std::string GetDOMAttributeValue( |
604 BrowserPlugin* browser_plugin) OVERRIDE { | 619 BrowserPlugin* browser_plugin) OVERRIDE { |
605 return browser_plugin->GetPartitionAttribute(); | 620 return static_cast<BrowserPluginImpl*>(browser_plugin)-> |
621 GetPartitionAttribute(); | |
606 } | 622 } |
607 private: | 623 private: |
608 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); | 624 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); |
609 }; | 625 }; |
610 | 626 |
611 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { | 627 class BrowserPluginPropertyBindingSrc : |
628 public BrowserPluginPropertyBindingImpl { | |
612 public: | 629 public: |
613 BrowserPluginPropertyBindingSrc() : | 630 BrowserPluginPropertyBindingSrc() : |
614 BrowserPluginPropertyBinding(kAttributeSrc) { | 631 BrowserPluginPropertyBindingImpl(kAttributeSrc) { |
615 } | 632 } |
616 virtual bool GetProperty(BrowserPluginBindings* bindings, | 633 virtual bool GetProperty(BrowserPlugin* browser_plugin, |
617 NPVariant* result) OVERRIDE { | 634 NPVariant* result) OVERRIDE { |
618 std::string src = bindings->instance()->src_attribute(); | 635 std::string src = static_cast<BrowserPluginImpl*>( |
636 browser_plugin)->src_attribute(); | |
619 return StringToNPVariant(src, result); | 637 return StringToNPVariant(src, result); |
620 } | 638 } |
621 virtual bool SetProperty(BrowserPluginBindings* bindings, | 639 virtual bool SetProperty(BrowserPlugin* browser_plugin, |
622 NPObject* np_obj, | 640 NPObject* np_obj, |
623 const NPVariant* variant) OVERRIDE { | 641 const NPVariant* variant) OVERRIDE { |
624 std::string src = StringFromNPVariant(*variant); | 642 std::string src = StringFromNPVariant(*variant); |
625 std::string error_message; | 643 std::string error_message; |
626 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { | 644 if (!static_cast<BrowserPluginImpl*>(browser_plugin)-> |
645 SetSrcAttribute(src, &error_message)) { | |
627 WebBindings::setException( | 646 WebBindings::setException( |
628 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 647 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
629 return false; | 648 return false; |
630 } | 649 } |
631 return true; | 650 return true; |
632 } | 651 } |
633 virtual std::string GetDOMAttributeValue( | 652 virtual std::string GetDOMAttributeValue( |
634 BrowserPlugin* browser_plugin) OVERRIDE { | 653 BrowserPlugin* browser_plugin) OVERRIDE { |
635 return browser_plugin->src_attribute(); | 654 return static_cast<BrowserPluginImpl*>(browser_plugin)->src_attribute(); |
636 } | 655 } |
637 private: | 656 private: |
638 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); | 657 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); |
639 }; | 658 }; |
640 | 659 |
641 | 660 |
642 // BrowserPluginBindings ------------------------------------------------------ | 661 // BrowserPluginBindings ------------------------------------------------------ |
643 | 662 |
644 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 663 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
645 } | 664 } |
646 | 665 |
647 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 666 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
648 } | 667 } |
649 | 668 |
650 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 669 BrowserPluginBindings::BrowserPluginBindings(BrowserPluginImpl* instance) |
651 : instance_(instance), | 670 : instance_(instance), |
652 np_object_(NULL), | 671 np_object_(NULL), |
653 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 672 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
654 NPObject* obj = | 673 NPObject* obj = |
655 WebBindings::createObject(NULL, &browser_plugin_message_class); | 674 WebBindings::createObject(NULL, &browser_plugin_message_class); |
656 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 675 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
657 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 676 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
658 | 677 |
659 method_bindings_.push_back(new BrowserPluginBindingBack); | 678 method_bindings_.push_back(new BrowserPluginBindingBack); |
660 method_bindings_.push_back(new BrowserPluginBindingCanGoBack); | 679 method_bindings_.push_back(new BrowserPluginBindingCanGoBack); |
(...skipping 29 matching lines...) Expand all Loading... | |
690 return false; | 709 return false; |
691 } | 710 } |
692 | 711 |
693 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, | 712 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, |
694 const NPVariant* args, | 713 const NPVariant* args, |
695 uint32 arg_count, | 714 uint32 arg_count, |
696 NPVariant* result) { | 715 NPVariant* result) { |
697 for (BindingList::iterator iter = method_bindings_.begin(); | 716 for (BindingList::iterator iter = method_bindings_.begin(); |
698 iter != method_bindings_.end(); | 717 iter != method_bindings_.end(); |
699 ++iter) { | 718 ++iter) { |
700 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) | 719 if ((*iter)->MatchesName(name) && (*iter)->GetArgCount() == arg_count) |
701 return (*iter)->Invoke(this, args, result); | 720 return (*iter)->Invoke(instance(), args, result); |
702 } | 721 } |
703 return false; | 722 return false; |
704 } | 723 } |
705 | 724 |
706 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { | 725 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { |
707 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); | 726 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); |
708 iter != property_bindings_.end(); | 727 iter != property_bindings_.end(); |
709 ++iter) { | 728 ++iter) { |
710 if ((*iter)->MatchesName(name)) | 729 if ((*iter)->MatchesName(name)) |
711 return true; | 730 return true; |
712 } | 731 } |
713 return false; | 732 return false; |
714 } | 733 } |
715 | 734 |
716 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, | 735 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, |
717 NPIdentifier name, | 736 NPIdentifier name, |
718 const NPVariant* variant) { | 737 const NPVariant* variant) { |
719 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 738 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
720 iter != property_bindings_.end(); | 739 iter != property_bindings_.end(); |
721 ++iter) { | 740 ++iter) { |
722 if ((*iter)->MatchesName(name)) { | 741 BrowserPluginPropertyBinding* property = *iter; |
723 if ((*iter)->SetProperty(this, np_obj, variant)) { | 742 if (property->MatchesName(name)) { |
724 (*iter)->UpdateDOMAttribute(this); | 743 if (property->SetProperty(instance(), np_obj, variant)) { |
744 instance()->UpdateDOMAttribute( | |
745 property->GetName(), property->GetDOMAttributeValue(instance())); | |
725 return true; | 746 return true; |
726 } | 747 } |
727 break; | 748 break; |
728 } | 749 } |
729 } | 750 } |
730 return false; | 751 return false; |
731 } | 752 } |
732 | 753 |
733 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { | 754 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { |
734 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 755 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
735 iter != property_bindings_.end(); | 756 iter != property_bindings_.end(); |
736 ++iter) { | 757 ++iter) { |
737 if ((*iter)->MatchesName(name)) | 758 if ((*iter)->MatchesName(name)) |
738 return (*iter)->GetProperty(this, result); | 759 return (*iter)->GetProperty(instance(), result); |
739 } | 760 } |
740 return false; | 761 return false; |
741 } | 762 } |
742 | 763 |
764 void BrowserPluginBindings::AddMethodBinding( | |
765 BrowserPluginMethodBinding* method_binding) { | |
766 method_bindings_.push_back(method_binding); | |
767 } | |
768 | |
769 void BrowserPluginBindings::AddPropertyBinding( | |
770 BrowserPluginPropertyBinding* property_binding) { | |
771 property_bindings_.push_back(property_binding); | |
772 } | |
773 | |
743 } // namespace content | 774 } // namespace content |
OLD | NEW |