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/strings/string_split.h" | 14 #include "base/strings/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" |
17 #include "content/renderer/browser_plugin/browser_plugin_constants.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_constants.h" |
18 #include "third_party/npapi/bindings/npapi.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_impl.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
27 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
28 | 29 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 NPUTF8 *chars = static_cast<NPUTF8 *>(malloc(length)); | 65 NPUTF8 *chars = static_cast<NPUTF8 *>(malloc(length)); |
65 if (!chars) { | 66 if (!chars) { |
66 VOID_TO_NPVARIANT(*variant); | 67 VOID_TO_NPVARIANT(*variant); |
67 return false; | 68 return false; |
68 } | 69 } |
69 memcpy(chars, in.c_str(), length); | 70 memcpy(chars, in.c_str(), length); |
70 STRINGN_TO_NPVARIANT(chars, length, *variant); | 71 STRINGN_TO_NPVARIANT(chars, length, *variant); |
71 return true; | 72 return true; |
72 } | 73 } |
73 | 74 |
| 75 bool MatchesName(const std::string& value, NPIdentifier name) { |
| 76 return WebKit::WebBindings::getStringIdentifier(value.c_str()) == name; |
| 77 } |
| 78 |
74 //------------------------------------------------------------------------------ | 79 //------------------------------------------------------------------------------ |
75 // Implementations of NPClass functions. These are here to: | 80 // Implementations of NPClass functions. These are here to: |
76 // - Implement src attribute. | 81 // - Implement src attribute. |
77 //------------------------------------------------------------------------------ | 82 //------------------------------------------------------------------------------ |
78 NPObject* BrowserPluginBindingsAllocate(NPP npp, NPClass* the_class) { | 83 NPObject* BrowserPluginBindingsAllocate(NPP npp, NPClass* the_class) { |
79 return new BrowserPluginBindings::BrowserPluginNPObject; | 84 return new BrowserPluginBindings::BrowserPluginNPObject; |
80 } | 85 } |
81 | 86 |
82 void BrowserPluginBindingsDeallocate(NPObject* object) { | 87 void BrowserPluginBindingsDeallocate(NPObject* object) { |
83 BrowserPluginBindings::BrowserPluginNPObject* instance = | 88 BrowserPluginBindings::BrowserPluginNPObject* instance = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 &BrowserPluginBindingsInvokeDefault, | 185 &BrowserPluginBindingsInvokeDefault, |
181 &BrowserPluginBindingsHasProperty, | 186 &BrowserPluginBindingsHasProperty, |
182 &BrowserPluginBindingsGetProperty, | 187 &BrowserPluginBindingsGetProperty, |
183 &BrowserPluginBindingsSetProperty, | 188 &BrowserPluginBindingsSetProperty, |
184 NULL, | 189 NULL, |
185 &BrowserPluginBindingsEnumerate, | 190 &BrowserPluginBindingsEnumerate, |
186 }; | 191 }; |
187 | 192 |
188 } // namespace | 193 } // namespace |
189 | 194 |
190 // BrowserPluginMethodBinding -------------------------------------------------- | 195 // Method Bindings ------------------------------------------------------------ |
191 | 196 |
192 class BrowserPluginMethodBinding { | 197 class BrowserPluginMethodBindingImpl : public BrowserPluginMethodBinding { |
193 public: | 198 public: |
194 BrowserPluginMethodBinding(const char name[], uint32 arg_count) | 199 BrowserPluginMethodBindingImpl(BrowserPluginImpl* browser_plugin, |
195 : name_(name), | 200 const char name[], |
| 201 uint32 arg_count) |
| 202 : browser_plugin_(browser_plugin), |
| 203 name_(name), |
196 arg_count_(arg_count) { | 204 arg_count_(arg_count) { |
197 } | 205 } |
198 | 206 |
199 virtual ~BrowserPluginMethodBinding() {} | 207 virtual ~BrowserPluginMethodBindingImpl() {} |
200 | 208 |
201 bool MatchesName(NPIdentifier name) const { | 209 BrowserPluginImpl* browser_plugin() const { return browser_plugin_; } |
202 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 210 |
| 211 virtual const std::string& GetName() const OVERRIDE { |
| 212 return name_; |
203 } | 213 } |
204 | 214 virtual uint32 GetArgCount() const OVERRIDE { return arg_count_; } |
205 uint32 arg_count() const { return arg_count_; } | |
206 | |
207 virtual bool Invoke(BrowserPluginBindings* bindings, | |
208 const NPVariant* args, | |
209 NPVariant* result) = 0; | |
210 | 215 |
211 private: | 216 private: |
| 217 BrowserPluginImpl* browser_plugin_; |
212 std::string name_; | 218 std::string name_; |
213 uint32 arg_count_; | 219 uint32 arg_count_; |
214 | 220 |
215 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); | 221 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBindingImpl); |
216 }; | 222 }; |
217 | 223 |
218 class BrowserPluginBindingBack : public BrowserPluginMethodBinding { | 224 class BrowserPluginBindingBack : public BrowserPluginMethodBindingImpl { |
219 public: | 225 public: |
220 BrowserPluginBindingBack() | 226 BrowserPluginBindingBack(BrowserPluginImpl* browser_plugin) |
221 : BrowserPluginMethodBinding(browser_plugin::kMethodBack, 0) { | 227 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 228 browser_plugin::kMethodBack, 0) { |
222 } | 229 } |
223 | 230 |
224 virtual bool Invoke(BrowserPluginBindings* bindings, | 231 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
225 const NPVariant* args, | 232 browser_plugin()->Back(); |
226 NPVariant* result) OVERRIDE { | |
227 bindings->instance()->Back(); | |
228 return true; | 233 return true; |
229 } | 234 } |
230 | 235 |
231 private: | 236 private: |
232 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); | 237 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingBack); |
233 }; | 238 }; |
234 | 239 |
235 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBinding { | 240 class BrowserPluginBindingCanGoBack : public BrowserPluginMethodBindingImpl { |
236 public: | 241 public: |
237 BrowserPluginBindingCanGoBack() | 242 BrowserPluginBindingCanGoBack(BrowserPluginImpl* browser_plugin) |
238 : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoBack, 0) { | 243 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 244 browser_plugin::kMethodCanGoBack, 0) { |
239 } | 245 } |
240 | 246 |
241 virtual bool Invoke(BrowserPluginBindings* bindings, | 247 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
242 const NPVariant* args, | 248 BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoBack(), *result); |
243 NPVariant* result) OVERRIDE { | |
244 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoBack(), *result); | |
245 return true; | 249 return true; |
246 } | 250 } |
247 | 251 |
248 private: | 252 private: |
249 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); | 253 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoBack); |
250 }; | 254 }; |
251 | 255 |
252 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBinding { | 256 class BrowserPluginBindingCanGoForward : public BrowserPluginMethodBindingImpl { |
253 public: | 257 public: |
254 BrowserPluginBindingCanGoForward() | 258 BrowserPluginBindingCanGoForward(BrowserPluginImpl* browser_plugin) |
255 : BrowserPluginMethodBinding(browser_plugin::kMethodCanGoForward, 0) { | 259 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 260 browser_plugin::kMethodCanGoForward, 0) { |
256 } | 261 } |
257 | 262 |
258 virtual bool Invoke(BrowserPluginBindings* bindings, | 263 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
259 const NPVariant* args, | 264 BOOLEAN_TO_NPVARIANT(browser_plugin()->CanGoForward(), *result); |
260 NPVariant* result) OVERRIDE { | |
261 BOOLEAN_TO_NPVARIANT(bindings->instance()->CanGoForward(), *result); | |
262 return true; | 265 return true; |
263 } | 266 } |
264 | 267 |
265 private: | 268 private: |
266 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); | 269 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingCanGoForward); |
267 }; | 270 }; |
268 | 271 |
269 class BrowserPluginBindingForward : public BrowserPluginMethodBinding { | 272 class BrowserPluginBindingForward : public BrowserPluginMethodBindingImpl { |
270 public: | 273 public: |
271 BrowserPluginBindingForward() | 274 BrowserPluginBindingForward(BrowserPluginImpl* browser_plugin) |
272 : BrowserPluginMethodBinding(browser_plugin::kMethodForward, 0) { | 275 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 276 browser_plugin::kMethodForward, 0) { |
273 } | 277 } |
274 | 278 |
275 virtual bool Invoke(BrowserPluginBindings* bindings, | 279 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
276 const NPVariant* args, | 280 browser_plugin()->Forward(); |
277 NPVariant* result) OVERRIDE { | |
278 bindings->instance()->Forward(); | |
279 return true; | 281 return true; |
280 } | 282 } |
281 | 283 |
282 private: | 284 private: |
283 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); | 285 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingForward); |
284 }; | 286 }; |
285 | 287 |
286 // Note: This is a method that is used internally by the <webview> shim only. | 288 // Note: This is a method that is used internally by the <webview> shim only. |
287 // This should not be exposed to developers. | 289 // This should not be exposed to developers. |
288 class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBinding { | 290 class BrowserPluginBindingGetRouteID : public BrowserPluginMethodBindingImpl { |
289 public: | 291 public: |
290 BrowserPluginBindingGetRouteID() | 292 BrowserPluginBindingGetRouteID(BrowserPluginImpl* browser_plugin) |
291 : BrowserPluginMethodBinding(browser_plugin::kMethodGetRouteId, 0) { | 293 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 294 browser_plugin::kMethodGetRouteId, 0) { |
292 } | 295 } |
293 | 296 |
294 virtual bool Invoke(BrowserPluginBindings* bindings, | 297 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
295 const NPVariant* args, | 298 INT32_TO_NPVARIANT(browser_plugin()->guest_route_id(), *result); |
296 NPVariant* result) OVERRIDE { | |
297 int route_id = bindings->instance()->guest_route_id(); | |
298 INT32_TO_NPVARIANT(route_id, *result); | |
299 return true; | 299 return true; |
300 } | 300 } |
301 | 301 |
302 private: | 302 private: |
303 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetRouteID); | 303 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetRouteID); |
304 }; | 304 }; |
305 | 305 |
306 class BrowserPluginBindingGetProcessID : public BrowserPluginMethodBinding { | 306 class BrowserPluginBindingGetProcessID : |
| 307 public BrowserPluginMethodBindingImpl { |
307 public: | 308 public: |
308 BrowserPluginBindingGetProcessID() | 309 BrowserPluginBindingGetProcessID(BrowserPluginImpl* browser_plugin) |
309 : BrowserPluginMethodBinding(browser_plugin::kMethodGetProcessId, 0) { | 310 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 311 browser_plugin::kMethodGetProcessId, 0) { |
310 } | 312 } |
311 | 313 |
312 virtual bool Invoke(BrowserPluginBindings* bindings, | 314 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
313 const NPVariant* args, | 315 INT32_TO_NPVARIANT(browser_plugin()->guest_process_id(), *result); |
314 NPVariant* result) OVERRIDE { | |
315 int process_id = bindings->instance()->guest_process_id(); | |
316 INT32_TO_NPVARIANT(process_id, *result); | |
317 return true; | 316 return true; |
318 } | 317 } |
319 | 318 |
320 private: | 319 private: |
321 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); | 320 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGetProcessID); |
322 }; | 321 }; |
323 | 322 |
324 class BrowserPluginBindingGo : public BrowserPluginMethodBinding { | 323 class BrowserPluginBindingGo : public BrowserPluginMethodBindingImpl { |
325 public: | 324 public: |
326 BrowserPluginBindingGo() | 325 BrowserPluginBindingGo(BrowserPluginImpl* browser_plugin) |
327 : BrowserPluginMethodBinding(browser_plugin::kMethodGo, 1) { | 326 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 327 browser_plugin::kMethodGo, 1) { |
328 } | 328 } |
329 | 329 |
330 virtual bool Invoke(BrowserPluginBindings* bindings, | 330 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
331 const NPVariant* args, | 331 browser_plugin()->Go(Int32FromNPVariant(args[0])); |
332 NPVariant* result) OVERRIDE { | |
333 bindings->instance()->Go(Int32FromNPVariant(args[0])); | |
334 return true; | 332 return true; |
335 } | 333 } |
336 | 334 |
337 private: | 335 private: |
338 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); | 336 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingGo); |
339 }; | 337 }; |
340 | 338 |
341 class BrowserPluginBindingReload : public BrowserPluginMethodBinding { | 339 class BrowserPluginBindingReload : public BrowserPluginMethodBindingImpl { |
342 public: | 340 public: |
343 BrowserPluginBindingReload() | 341 BrowserPluginBindingReload(BrowserPluginImpl* browser_plugin) |
344 : BrowserPluginMethodBinding(browser_plugin::kMethodReload, 0) { | 342 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 343 browser_plugin::kMethodReload, 0) { |
345 } | 344 } |
346 | 345 |
347 virtual bool Invoke(BrowserPluginBindings* bindings, | 346 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
348 const NPVariant* args, | 347 browser_plugin()->Reload(); |
349 NPVariant* result) OVERRIDE { | |
350 bindings->instance()->Reload(); | |
351 return true; | 348 return true; |
352 } | 349 } |
353 | 350 |
354 private: | 351 private: |
355 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); | 352 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingReload); |
356 }; | 353 }; |
357 | 354 |
358 class BrowserPluginBindingStop : public BrowserPluginMethodBinding { | 355 class BrowserPluginBindingStop : public BrowserPluginMethodBindingImpl { |
359 public: | 356 public: |
360 BrowserPluginBindingStop() | 357 BrowserPluginBindingStop(BrowserPluginImpl* browser_plugin) |
361 : BrowserPluginMethodBinding(browser_plugin::kMethodStop, 0) { | 358 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 359 browser_plugin::kMethodStop, 0) { |
362 } | 360 } |
363 | 361 |
364 virtual bool Invoke(BrowserPluginBindings* bindings, | 362 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
365 const NPVariant* args, | 363 browser_plugin()->Stop(); |
366 NPVariant* result) OVERRIDE { | |
367 bindings->instance()->Stop(); | |
368 return true; | 364 return true; |
369 } | 365 } |
370 | 366 |
371 private: | 367 private: |
372 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); | 368 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingStop); |
373 }; | 369 }; |
374 | 370 |
375 class BrowserPluginBindingTerminate : public BrowserPluginMethodBinding { | 371 class BrowserPluginBindingTerminate : public BrowserPluginMethodBindingImpl { |
376 public: | 372 public: |
377 BrowserPluginBindingTerminate() | 373 BrowserPluginBindingTerminate(BrowserPluginImpl* browser_plugin) |
378 : BrowserPluginMethodBinding(browser_plugin::kMethodTerminate, 0) { | 374 : BrowserPluginMethodBindingImpl(browser_plugin, |
| 375 browser_plugin::kMethodTerminate, 0) { |
379 } | 376 } |
380 | 377 |
381 virtual bool Invoke(BrowserPluginBindings* bindings, | 378 virtual bool Invoke(const NPVariant* args, NPVariant* result) OVERRIDE { |
382 const NPVariant* args, | 379 browser_plugin()->TerminateGuest(); |
383 NPVariant* result) OVERRIDE { | |
384 bindings->instance()->TerminateGuest(); | |
385 return true; | 380 return true; |
386 } | 381 } |
387 | 382 |
388 private: | 383 private: |
389 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); | 384 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); |
390 }; | 385 }; |
391 | 386 |
392 // BrowserPluginPropertyBinding ------------------------------------------------ | 387 // Property Bindings ---------------------------------------------------------- |
393 | 388 |
394 class BrowserPluginPropertyBinding { | 389 class BrowserPluginPropertyBindingImpl : public BrowserPluginPropertyBinding { |
395 public: | 390 public: |
396 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {} | 391 BrowserPluginPropertyBindingImpl(BrowserPluginImpl* browser_plugin, |
397 virtual ~BrowserPluginPropertyBinding() {} | 392 const char name[]) |
398 const std::string& name() const { return name_; } | 393 : browser_plugin_(browser_plugin), |
399 bool MatchesName(NPIdentifier name) const { | 394 name_(name) {} |
400 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 395 |
| 396 virtual ~BrowserPluginPropertyBindingImpl() {} |
| 397 |
| 398 BrowserPluginImpl* browser_plugin() const { |
| 399 return browser_plugin_; |
401 } | 400 } |
402 virtual bool GetProperty(BrowserPluginBindings* bindings, | 401 |
403 NPVariant* result) = 0; | 402 // BrowserPluginPropertyBinding implementation. |
404 virtual bool SetProperty(BrowserPluginBindings* bindings, | 403 virtual const std::string& GetName() const OVERRIDE { |
405 NPObject* np_obj, | 404 return name_; |
406 const NPVariant* variant) = 0; | 405 } |
407 virtual void RemoveProperty(BrowserPluginBindings* bindings, | |
408 NPObject* np_obj) = 0; | |
409 // Updates the DOM Attribute value with the current property value. | 406 // Updates the DOM Attribute value with the current property value. |
410 void UpdateDOMAttribute(BrowserPluginBindings* bindings, | 407 void UpdateDOMAttribute(std::string new_value) { |
411 std::string new_value) { | 408 browser_plugin_->UpdateDOMAttribute(name_, new_value); |
412 bindings->instance()->UpdateDOMAttribute(name(), new_value); | |
413 } | 409 } |
414 protected: | 410 protected: |
415 // Depending on where the attribute comes from it could be a string, int32, | 411 // Depending on where the attribute comes from it could be a string, int32, |
416 // or a double. Javascript tends to produce an Int32 or a String, but setting | 412 // or a double. Javascript tends to produce an Int32 or a String, but setting |
417 // the value from the developer tools console may also produce a Double... | 413 // the value from the developer tools console may also produce a Double... |
418 int IntFromNPVariant(const NPVariant* variant) { | 414 int IntFromNPVariant(const NPVariant* variant) { |
419 int value; | 415 int value; |
420 switch (variant->type) { | 416 switch (variant->type) { |
421 case NPVariantType_Double: | 417 case NPVariantType_Double: |
422 case NPVariantType_Int32: | 418 case NPVariantType_Int32: |
423 value = Int32FromNPVariant(*variant); | 419 value = Int32FromNPVariant(*variant); |
424 break; | 420 break; |
425 case NPVariantType_String: | 421 case NPVariantType_String: |
426 base::StringToInt(StringFromNPVariant(*variant), &value); | 422 base::StringToInt(StringFromNPVariant(*variant), &value); |
427 break; | 423 break; |
428 default: | 424 default: |
429 value = 0; | 425 value = 0; |
430 break; | 426 break; |
431 } | 427 } |
432 return value; | 428 return value; |
433 } | 429 } |
434 private: | 430 |
| 431 private: |
| 432 BrowserPluginImpl* browser_plugin_; |
435 std::string name_; | 433 std::string name_; |
436 | 434 |
437 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); | 435 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingImpl); |
438 }; | 436 }; |
439 | 437 |
440 class BrowserPluginPropertyBindingAutoSize | 438 class BrowserPluginPropertyBindingAutoSize |
441 : public BrowserPluginPropertyBinding { | 439 : public BrowserPluginPropertyBindingImpl { |
442 public: | 440 public: |
443 BrowserPluginPropertyBindingAutoSize() | 441 BrowserPluginPropertyBindingAutoSize(BrowserPluginImpl* browser_plugin) : |
444 : BrowserPluginPropertyBinding(browser_plugin::kAttributeAutoSize) { | 442 BrowserPluginPropertyBindingImpl(browser_plugin, |
445 } | 443 browser_plugin::kAttributeAutoSize) { |
446 virtual bool GetProperty(BrowserPluginBindings* bindings, | 444 } |
447 NPVariant* result) OVERRIDE { | 445 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
448 bool auto_size = bindings->instance()->GetAutoSizeAttribute(); | 446 BOOLEAN_TO_NPVARIANT(browser_plugin()->GetAutoSizeAttribute(), *result); |
449 BOOLEAN_TO_NPVARIANT(auto_size, *result); | 447 return true; |
450 return true; | 448 } |
451 } | 449 virtual bool SetProperty(NPObject* np_obj, |
452 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
453 NPObject* np_obj, | |
454 const NPVariant* variant) OVERRIDE { | 450 const NPVariant* variant) OVERRIDE { |
455 std::string value = StringFromNPVariant(*variant); | 451 std::string value = StringFromNPVariant(*variant); |
456 if (!bindings->instance()->HasDOMAttribute(name())) { | 452 if (!browser_plugin()->HasDOMAttribute(GetName())) { |
457 UpdateDOMAttribute(bindings, value); | 453 UpdateDOMAttribute(value); |
458 bindings->instance()->ParseAutoSizeAttribute(); | 454 browser_plugin()->ParseAutoSizeAttribute(); |
459 } else { | 455 } else { |
460 UpdateDOMAttribute(bindings, value); | 456 UpdateDOMAttribute(value); |
461 } | 457 } |
462 return true; | 458 return true; |
463 } | 459 } |
464 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 460 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
465 NPObject* np_obj) OVERRIDE { | 461 browser_plugin()->RemoveDOMAttribute(GetName()); |
466 bindings->instance()->RemoveDOMAttribute(name()); | 462 browser_plugin()->ParseAutoSizeAttribute(); |
467 bindings->instance()->ParseAutoSizeAttribute(); | |
468 } | 463 } |
469 private: | 464 private: |
470 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | 465 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); |
471 }; | 466 }; |
472 | 467 |
473 class BrowserPluginPropertyBindingContentWindow | 468 class BrowserPluginPropertyBindingContentWindow |
474 : public BrowserPluginPropertyBinding { | 469 : public BrowserPluginPropertyBindingImpl { |
475 public: | 470 public: |
476 BrowserPluginPropertyBindingContentWindow() | 471 BrowserPluginPropertyBindingContentWindow(BrowserPluginImpl* browser_plugin) : |
477 : BrowserPluginPropertyBinding(browser_plugin::kAttributeContentWindow) { | 472 BrowserPluginPropertyBindingImpl( |
478 } | 473 browser_plugin, |
479 virtual bool GetProperty(BrowserPluginBindings* bindings, | 474 browser_plugin::kAttributeContentWindow) { |
480 NPVariant* result) OVERRIDE { | 475 } |
481 NPObject* obj = bindings->instance()->GetContentWindow(); | 476 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
| 477 NPObject* obj = browser_plugin()->GetContentWindow(); |
482 if (obj) { | 478 if (obj) { |
483 result->type = NPVariantType_Object; | 479 result->type = NPVariantType_Object; |
484 result->value.objectValue = WebBindings::retainObject(obj); | 480 result->value.objectValue = WebBindings::retainObject(obj); |
485 } | 481 } |
486 return true; | 482 return true; |
487 } | 483 } |
488 virtual bool SetProperty(BrowserPluginBindings* bindings, | 484 virtual bool SetProperty(NPObject* np_obj, |
489 NPObject* np_obj, | |
490 const NPVariant* variant) OVERRIDE { | 485 const NPVariant* variant) OVERRIDE { |
491 return false; | 486 return false; |
492 } | 487 } |
493 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 488 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE {} |
494 NPObject* np_obj) OVERRIDE {} | |
495 private: | 489 private: |
496 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 490 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
497 }; | 491 }; |
498 | 492 |
499 class BrowserPluginPropertyBindingMaxHeight | 493 class BrowserPluginPropertyBindingMaxHeight |
500 : public BrowserPluginPropertyBinding { | 494 : public BrowserPluginPropertyBindingImpl { |
501 public: | 495 public: |
502 BrowserPluginPropertyBindingMaxHeight() | 496 BrowserPluginPropertyBindingMaxHeight(BrowserPluginImpl* browser_plugin) : |
503 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxHeight) { | 497 BrowserPluginPropertyBindingImpl(browser_plugin, |
504 } | 498 browser_plugin::kAttributeMaxHeight) { |
505 virtual bool GetProperty(BrowserPluginBindings* bindings, | 499 } |
506 NPVariant* result) OVERRIDE { | 500 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
507 int max_height = bindings->instance()->GetMaxHeightAttribute(); | 501 INT32_TO_NPVARIANT(browser_plugin()->GetMaxHeightAttribute(), *result); |
508 INT32_TO_NPVARIANT(max_height, *result); | 502 return true; |
509 return true; | 503 } |
510 } | 504 virtual bool SetProperty(NPObject* np_obj, |
511 virtual bool SetProperty(BrowserPluginBindings* bindings, | 505 const NPVariant* variant) OVERRIDE { |
512 NPObject* np_obj, | 506 int new_value = IntFromNPVariant(variant); |
513 const NPVariant* variant) OVERRIDE { | 507 if (browser_plugin()->GetMaxHeightAttribute() != new_value) { |
514 int new_value = IntFromNPVariant(variant); | 508 UpdateDOMAttribute(base::IntToString(new_value)); |
515 if (bindings->instance()->GetMaxHeightAttribute() != new_value) { | 509 browser_plugin()->ParseSizeContraintsChanged(); |
516 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 510 } |
517 bindings->instance()->ParseSizeContraintsChanged(); | 511 return true; |
518 } | 512 } |
519 return true; | 513 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
520 } | 514 browser_plugin()->RemoveDOMAttribute(GetName()); |
521 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 515 browser_plugin()->ParseSizeContraintsChanged(); |
522 NPObject* np_obj) OVERRIDE { | |
523 bindings->instance()->RemoveDOMAttribute(name()); | |
524 bindings->instance()->ParseSizeContraintsChanged(); | |
525 } | 516 } |
526 private: | 517 private: |
527 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | 518 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); |
528 }; | 519 }; |
529 | 520 |
530 class BrowserPluginPropertyBindingMaxWidth | 521 class BrowserPluginPropertyBindingMaxWidth |
531 : public BrowserPluginPropertyBinding { | 522 : public BrowserPluginPropertyBindingImpl { |
532 public: | 523 public: |
533 BrowserPluginPropertyBindingMaxWidth() | 524 BrowserPluginPropertyBindingMaxWidth(BrowserPluginImpl* browser_plugin) : |
534 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMaxWidth) { | 525 BrowserPluginPropertyBindingImpl(browser_plugin, |
535 } | 526 browser_plugin::kAttributeMaxWidth) { |
536 virtual bool GetProperty(BrowserPluginBindings* bindings, | 527 } |
537 NPVariant* result) OVERRIDE { | 528 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
538 int max_width = bindings->instance()->GetMaxWidthAttribute(); | 529 INT32_TO_NPVARIANT(browser_plugin()->GetMaxWidthAttribute(), *result); |
539 INT32_TO_NPVARIANT(max_width, *result); | 530 return true; |
540 return true; | 531 } |
541 } | 532 virtual bool SetProperty(NPObject* np_obj, |
542 virtual bool SetProperty(BrowserPluginBindings* bindings, | 533 const NPVariant* variant) OVERRIDE { |
543 NPObject* np_obj, | 534 int new_value = IntFromNPVariant(variant); |
544 const NPVariant* variant) OVERRIDE { | 535 if (browser_plugin()->GetMaxWidthAttribute() != new_value) { |
545 int new_value = IntFromNPVariant(variant); | 536 UpdateDOMAttribute(base::IntToString(new_value)); |
546 if (bindings->instance()->GetMaxWidthAttribute() != new_value) { | 537 browser_plugin()->ParseSizeContraintsChanged(); |
547 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 538 } |
548 bindings->instance()->ParseSizeContraintsChanged(); | 539 return true; |
549 } | 540 } |
550 return true; | 541 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
551 } | 542 browser_plugin()->RemoveDOMAttribute(GetName()); |
552 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 543 browser_plugin()->ParseSizeContraintsChanged(); |
553 NPObject* np_obj) OVERRIDE { | |
554 bindings->instance()->RemoveDOMAttribute(name()); | |
555 bindings->instance()->ParseSizeContraintsChanged(); | |
556 } | 544 } |
557 private: | 545 private: |
558 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | 546 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); |
559 }; | 547 }; |
560 | 548 |
561 class BrowserPluginPropertyBindingMinHeight | 549 class BrowserPluginPropertyBindingMinHeight |
562 : public BrowserPluginPropertyBinding { | 550 : public BrowserPluginPropertyBindingImpl { |
563 public: | 551 public: |
564 BrowserPluginPropertyBindingMinHeight() | 552 BrowserPluginPropertyBindingMinHeight(BrowserPluginImpl* browser_plugin) : |
565 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinHeight) { | 553 BrowserPluginPropertyBindingImpl(browser_plugin, |
566 } | 554 browser_plugin::kAttributeMinHeight) { |
567 virtual bool GetProperty(BrowserPluginBindings* bindings, | 555 } |
568 NPVariant* result) OVERRIDE { | 556 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
569 int min_height = bindings->instance()->GetMinHeightAttribute(); | 557 INT32_TO_NPVARIANT(browser_plugin()->GetMinHeightAttribute(), *result); |
570 INT32_TO_NPVARIANT(min_height, *result); | 558 return true; |
571 return true; | 559 } |
572 } | 560 virtual bool SetProperty(NPObject* np_obj, |
573 virtual bool SetProperty(BrowserPluginBindings* bindings, | 561 const NPVariant* variant) OVERRIDE { |
574 NPObject* np_obj, | 562 int new_value = IntFromNPVariant(variant); |
575 const NPVariant* variant) OVERRIDE { | 563 if (browser_plugin()->GetMinHeightAttribute() != new_value) { |
576 int new_value = IntFromNPVariant(variant); | 564 UpdateDOMAttribute(base::IntToString(new_value)); |
577 if (bindings->instance()->GetMinHeightAttribute() != new_value) { | 565 browser_plugin()->ParseSizeContraintsChanged(); |
578 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 566 } |
579 bindings->instance()->ParseSizeContraintsChanged(); | 567 return true; |
580 } | 568 } |
581 return true; | 569 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
582 } | 570 browser_plugin()->RemoveDOMAttribute(GetName()); |
583 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 571 browser_plugin()->ParseSizeContraintsChanged(); |
584 NPObject* np_obj) OVERRIDE { | |
585 bindings->instance()->RemoveDOMAttribute(name()); | |
586 bindings->instance()->ParseSizeContraintsChanged(); | |
587 } | 572 } |
588 private: | 573 private: |
589 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | 574 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); |
590 }; | 575 }; |
591 | 576 |
592 class BrowserPluginPropertyBindingMinWidth | 577 class BrowserPluginPropertyBindingMinWidth |
593 : public BrowserPluginPropertyBinding { | 578 : public BrowserPluginPropertyBindingImpl { |
594 public: | 579 public: |
595 BrowserPluginPropertyBindingMinWidth() | 580 BrowserPluginPropertyBindingMinWidth(BrowserPluginImpl* browser_plugin) : |
596 : BrowserPluginPropertyBinding(browser_plugin::kAttributeMinWidth) { | 581 BrowserPluginPropertyBindingImpl(browser_plugin, |
597 } | 582 browser_plugin::kAttributeMinWidth) { |
598 virtual bool GetProperty(BrowserPluginBindings* bindings, | 583 } |
599 NPVariant* result) OVERRIDE { | 584 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
600 int min_width = bindings->instance()->GetMinWidthAttribute(); | 585 INT32_TO_NPVARIANT(browser_plugin()->GetMinWidthAttribute(), *result); |
601 INT32_TO_NPVARIANT(min_width, *result); | 586 return true; |
602 return true; | 587 } |
603 } | 588 virtual bool SetProperty(NPObject* np_obj, |
604 virtual bool SetProperty(BrowserPluginBindings* bindings, | 589 const NPVariant* variant) OVERRIDE { |
605 NPObject* np_obj, | 590 int new_value = IntFromNPVariant(variant); |
606 const NPVariant* variant) OVERRIDE { | 591 if (browser_plugin()->GetMinWidthAttribute() != new_value) { |
607 int new_value = IntFromNPVariant(variant); | 592 UpdateDOMAttribute(base::IntToString(new_value)); |
608 if (bindings->instance()->GetMinWidthAttribute() != new_value) { | 593 browser_plugin()->ParseSizeContraintsChanged(); |
609 UpdateDOMAttribute(bindings, base::IntToString(new_value)); | 594 } |
610 bindings->instance()->ParseSizeContraintsChanged(); | 595 return true; |
611 } | 596 } |
612 return true; | 597 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
613 } | 598 browser_plugin()->RemoveDOMAttribute(GetName()); |
614 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 599 browser_plugin()->ParseSizeContraintsChanged(); |
615 NPObject* np_obj) OVERRIDE { | |
616 bindings->instance()->RemoveDOMAttribute(name()); | |
617 bindings->instance()->ParseSizeContraintsChanged(); | |
618 } | 600 } |
619 private: | 601 private: |
620 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 602 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
621 }; | 603 }; |
622 | 604 |
623 class BrowserPluginPropertyBindingName | 605 class BrowserPluginPropertyBindingName |
624 : public BrowserPluginPropertyBinding { | 606 : public BrowserPluginPropertyBindingImpl { |
625 public: | 607 public: |
626 BrowserPluginPropertyBindingName() | 608 BrowserPluginPropertyBindingName(BrowserPluginImpl* browser_plugin) : |
627 : BrowserPluginPropertyBinding(browser_plugin::kAttributeName) { | 609 BrowserPluginPropertyBindingImpl(browser_plugin, |
628 } | 610 browser_plugin::kAttributeName) { |
629 virtual bool GetProperty(BrowserPluginBindings* bindings, | 611 } |
630 NPVariant* result) OVERRIDE { | 612 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
631 std::string name = bindings->instance()->GetNameAttribute(); | 613 StringToNPVariant(browser_plugin()->GetNameAttribute(), result); |
632 return StringToNPVariant(name, result); | 614 return true; |
633 return true; | 615 } |
634 } | 616 virtual bool SetProperty(NPObject* np_obj, |
635 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
636 NPObject* np_obj, | |
637 const NPVariant* variant) OVERRIDE { | 617 const NPVariant* variant) OVERRIDE { |
638 std::string new_value = StringFromNPVariant(*variant); | 618 std::string new_value = StringFromNPVariant(*variant); |
639 if (bindings->instance()->GetNameAttribute() != new_value) { | 619 if (browser_plugin()->GetNameAttribute() != new_value) { |
640 UpdateDOMAttribute(bindings, new_value); | 620 UpdateDOMAttribute(new_value); |
641 bindings->instance()->ParseNameAttribute(); | 621 browser_plugin()->ParseNameAttribute(); |
642 } | 622 } |
643 return true; | 623 return true; |
644 } | 624 } |
645 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 625 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
646 NPObject* np_obj) OVERRIDE { | 626 browser_plugin()->RemoveDOMAttribute(GetName()); |
647 bindings->instance()->RemoveDOMAttribute(name()); | 627 browser_plugin()->ParseNameAttribute(); |
648 bindings->instance()->ParseNameAttribute(); | |
649 } | 628 } |
650 private: | 629 private: |
651 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); | 630 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); |
652 }; | 631 }; |
653 | 632 |
654 class BrowserPluginPropertyBindingPartition | 633 class BrowserPluginPropertyBindingPartition |
655 : public BrowserPluginPropertyBinding { | 634 : public BrowserPluginPropertyBindingImpl { |
656 public: | 635 public: |
657 BrowserPluginPropertyBindingPartition() | 636 BrowserPluginPropertyBindingPartition(BrowserPluginImpl* browser_plugin) : |
658 : BrowserPluginPropertyBinding(browser_plugin::kAttributePartition) { | 637 BrowserPluginPropertyBindingImpl(browser_plugin, |
659 } | 638 browser_plugin::kAttributePartition) { |
660 virtual bool GetProperty(BrowserPluginBindings* bindings, | 639 } |
661 NPVariant* result) OVERRIDE { | 640 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
662 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 641 return StringToNPVariant(browser_plugin()->GetPartitionAttribute(), result); |
663 return StringToNPVariant(partition_id, result); | 642 } |
664 } | 643 virtual bool SetProperty(NPObject* np_obj, |
665 virtual bool SetProperty(BrowserPluginBindings* bindings, | |
666 NPObject* np_obj, | |
667 const NPVariant* variant) OVERRIDE { | 644 const NPVariant* variant) OVERRIDE { |
668 std::string new_value = StringFromNPVariant(*variant); | 645 std::string new_value = StringFromNPVariant(*variant); |
669 std::string old_value = bindings->instance()->GetPartitionAttribute(); | 646 std::string old_value = browser_plugin()->GetPartitionAttribute(); |
670 if (old_value != new_value) { | 647 if (old_value != new_value) { |
671 UpdateDOMAttribute(bindings, new_value); | 648 UpdateDOMAttribute(new_value); |
672 std::string error_message; | 649 std::string error_message; |
673 if (!bindings->instance()->ParsePartitionAttribute(&error_message)) { | 650 if (!browser_plugin()->ParsePartitionAttribute(&error_message)) { |
674 WebBindings::setException( | 651 WebBindings::setException( |
675 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 652 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
676 // Reset to old value on error. | 653 // Reset to old value on error. |
677 UpdateDOMAttribute(bindings, old_value); | 654 UpdateDOMAttribute(old_value); |
678 return false; | 655 return false; |
679 } | 656 } |
680 } | 657 } |
681 return true; | 658 return true; |
682 } | 659 } |
683 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 660 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
684 NPObject* np_obj) OVERRIDE { | |
685 std::string error_message; | 661 std::string error_message; |
686 if (bindings->instance()->CanRemovePartitionAttribute(&error_message)) { | 662 if (browser_plugin()->CanRemovePartitionAttribute(&error_message)) { |
687 bindings->instance()->RemoveDOMAttribute(name()); | 663 browser_plugin()->RemoveDOMAttribute(GetName()); |
688 } else { | 664 } else { |
689 WebBindings::setException( | 665 WebBindings::setException( |
690 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 666 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
691 } | 667 } |
692 } | 668 } |
693 private: | 669 private: |
694 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); | 670 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); |
695 }; | 671 }; |
696 | 672 |
697 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { | 673 class BrowserPluginPropertyBindingSrc : |
| 674 public BrowserPluginPropertyBindingImpl { |
698 public: | 675 public: |
699 BrowserPluginPropertyBindingSrc() | 676 BrowserPluginPropertyBindingSrc(BrowserPluginImpl* browser_plugin) : |
700 : BrowserPluginPropertyBinding(browser_plugin::kAttributeSrc) { | 677 BrowserPluginPropertyBindingImpl(browser_plugin, |
| 678 browser_plugin::kAttributeSrc) { |
701 } | 679 } |
702 virtual bool GetProperty(BrowserPluginBindings* bindings, | 680 virtual bool GetProperty(NPVariant* result) OVERRIDE { |
703 NPVariant* result) OVERRIDE { | 681 return StringToNPVariant(browser_plugin()->GetSrcAttribute(), result); |
704 std::string src = bindings->instance()->GetSrcAttribute(); | |
705 return StringToNPVariant(src, result); | |
706 } | 682 } |
707 virtual bool SetProperty(BrowserPluginBindings* bindings, | 683 virtual bool SetProperty(NPObject* np_obj, |
708 NPObject* np_obj, | |
709 const NPVariant* variant) OVERRIDE { | 684 const NPVariant* variant) OVERRIDE { |
710 std::string new_value = StringFromNPVariant(*variant); | 685 std::string new_value = StringFromNPVariant(*variant); |
711 // We should not be issuing navigation IPCs if we attempt to set the | 686 // We should not be issuing navigation IPCs if we attempt to set the |
712 // src property to the empty string. Instead, we want to simply restore | 687 // src property to the empty string. Instead, we want to simply restore |
713 // the src attribute back to its old value. | 688 // the src attribute back to its old value. |
714 if (new_value.empty()) { | 689 if (new_value.empty()) { |
715 RemoveProperty(bindings, np_obj); | 690 RemoveProperty(np_obj); |
716 return true; | 691 return true; |
717 } | 692 } |
718 std::string old_value = bindings->instance()->GetSrcAttribute(); | 693 std::string old_value = browser_plugin()->GetSrcAttribute(); |
719 bool guest_crashed = bindings->instance()->guest_crashed(); | 694 bool guest_crashed = browser_plugin()->guest_crashed(); |
720 if ((old_value != new_value) || guest_crashed) { | 695 if ((old_value != new_value) || guest_crashed) { |
721 // If the new value was empty then we're effectively resetting the | 696 // If the new value was empty then we're effectively resetting the |
722 // attribute to the old value here. This will be picked up by <webview>'s | 697 // attribute to the old value here. This will be picked up by <webview>'s |
723 // mutation observer and will restore the src attribute after it has been | 698 // mutation observer and will restore the src attribute after it has been |
724 // removed. | 699 // removed. |
725 UpdateDOMAttribute(bindings, new_value); | 700 UpdateDOMAttribute(new_value); |
726 std::string error_message; | 701 std::string error_message; |
727 if (!bindings->instance()->ParseSrcAttribute(&error_message)) { | 702 if (!browser_plugin()->ParseSrcAttribute(&error_message)) { |
728 WebBindings::setException( | 703 WebBindings::setException( |
729 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 704 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
730 // Reset to old value on error. | 705 // Reset to old value on error. |
731 UpdateDOMAttribute(bindings, old_value); | 706 UpdateDOMAttribute(old_value); |
732 return false; | 707 return false; |
733 } | 708 } |
734 } | 709 } |
735 return true; | 710 return true; |
736 } | 711 } |
737 virtual void RemoveProperty(BrowserPluginBindings* bindings, | 712 virtual void RemoveProperty(NPObject* np_obj) OVERRIDE { |
738 NPObject* np_obj) OVERRIDE { | 713 std::string old_value = browser_plugin()->GetSrcAttribute(); |
739 std::string old_value = bindings->instance()->GetSrcAttribute(); | |
740 // Remove the DOM attribute to trigger the mutation observer when it is | 714 // Remove the DOM attribute to trigger the mutation observer when it is |
741 // restored to its original value again. | 715 // restored to its original value again. |
742 bindings->instance()->RemoveDOMAttribute(name()); | 716 browser_plugin()->RemoveDOMAttribute(GetName()); |
743 UpdateDOMAttribute(bindings, old_value); | 717 UpdateDOMAttribute(old_value); |
744 } | 718 } |
745 private: | 719 private: |
746 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); | 720 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); |
747 }; | 721 }; |
748 | 722 |
749 | 723 |
750 // BrowserPluginBindings ------------------------------------------------------ | 724 // BrowserPluginBindings ------------------------------------------------------ |
751 | 725 |
752 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 726 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
753 } | 727 } |
754 | 728 |
755 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { | 729 BrowserPluginBindings::BrowserPluginNPObject::~BrowserPluginNPObject() { |
756 } | 730 } |
757 | 731 |
758 BrowserPluginBindings::BrowserPluginBindings(BrowserPlugin* instance) | 732 BrowserPluginBindings::BrowserPluginBindings(BrowserPluginImpl* instance) |
759 : instance_(instance), | 733 : instance_(instance), |
760 np_object_(NULL), | 734 np_object_(NULL), |
761 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 735 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
762 NPObject* obj = | 736 NPObject* obj = |
763 WebBindings::createObject(NULL, &browser_plugin_message_class); | 737 WebBindings::createObject(NULL, &browser_plugin_message_class); |
764 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 738 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
765 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 739 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
766 | 740 |
767 method_bindings_.push_back(new BrowserPluginBindingBack); | 741 method_bindings_.push_back(new BrowserPluginBindingBack(instance)); |
768 method_bindings_.push_back(new BrowserPluginBindingCanGoBack); | 742 method_bindings_.push_back(new BrowserPluginBindingCanGoBack(instance)); |
769 method_bindings_.push_back(new BrowserPluginBindingCanGoForward); | 743 method_bindings_.push_back(new BrowserPluginBindingCanGoForward(instance)); |
770 method_bindings_.push_back(new BrowserPluginBindingForward); | 744 method_bindings_.push_back(new BrowserPluginBindingForward(instance)); |
771 method_bindings_.push_back(new BrowserPluginBindingGetProcessID); | 745 method_bindings_.push_back(new BrowserPluginBindingGetProcessID(instance)); |
772 method_bindings_.push_back(new BrowserPluginBindingGetRouteID); | 746 method_bindings_.push_back(new BrowserPluginBindingGetRouteID(instance)); |
773 method_bindings_.push_back(new BrowserPluginBindingGo); | 747 method_bindings_.push_back(new BrowserPluginBindingGo(instance)); |
774 method_bindings_.push_back(new BrowserPluginBindingReload); | 748 method_bindings_.push_back(new BrowserPluginBindingReload(instance)); |
775 method_bindings_.push_back(new BrowserPluginBindingStop); | 749 method_bindings_.push_back(new BrowserPluginBindingStop(instance)); |
776 method_bindings_.push_back(new BrowserPluginBindingTerminate); | 750 method_bindings_.push_back(new BrowserPluginBindingTerminate(instance)); |
777 | 751 |
778 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); | 752 property_bindings_.push_back( |
779 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 753 new BrowserPluginPropertyBindingAutoSize(instance)); |
780 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); | 754 property_bindings_.push_back( |
781 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); | 755 new BrowserPluginPropertyBindingContentWindow(instance)); |
782 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); | 756 property_bindings_.push_back( |
783 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); | 757 new BrowserPluginPropertyBindingMaxHeight(instance)); |
784 property_bindings_.push_back(new BrowserPluginPropertyBindingName); | 758 property_bindings_.push_back( |
785 property_bindings_.push_back(new BrowserPluginPropertyBindingPartition); | 759 new BrowserPluginPropertyBindingMaxWidth(instance)); |
786 property_bindings_.push_back(new BrowserPluginPropertyBindingSrc); | 760 property_bindings_.push_back( |
| 761 new BrowserPluginPropertyBindingMinHeight(instance)); |
| 762 property_bindings_.push_back( |
| 763 new BrowserPluginPropertyBindingMinWidth(instance)); |
| 764 property_bindings_.push_back( |
| 765 new BrowserPluginPropertyBindingName(instance)); |
| 766 property_bindings_.push_back( |
| 767 new BrowserPluginPropertyBindingPartition(instance)); |
| 768 property_bindings_.push_back( |
| 769 new BrowserPluginPropertyBindingSrc(instance)); |
787 } | 770 } |
788 | 771 |
789 BrowserPluginBindings::~BrowserPluginBindings() { | 772 BrowserPluginBindings::~BrowserPluginBindings() { |
790 WebBindings::releaseObject(np_object_); | 773 WebBindings::releaseObject(np_object_); |
791 } | 774 } |
792 | 775 |
793 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { | 776 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
794 for (BindingList::const_iterator iter = method_bindings_.begin(); | 777 for (BindingList::const_iterator iter = method_bindings_.begin(); |
795 iter != method_bindings_.end(); | 778 iter != method_bindings_.end(); |
796 ++iter) { | 779 ++iter) { |
797 if ((*iter)->MatchesName(name)) | 780 BrowserPluginMethodBinding* method = *iter; |
| 781 if (MatchesName(method->GetName(), name)) |
798 return true; | 782 return true; |
799 } | 783 } |
800 return false; | 784 return false; |
801 } | 785 } |
802 | 786 |
803 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, | 787 bool BrowserPluginBindings::InvokeMethod(NPIdentifier name, |
804 const NPVariant* args, | 788 const NPVariant* args, |
805 uint32 arg_count, | 789 uint32 arg_count, |
806 NPVariant* result) { | 790 NPVariant* result) { |
807 for (BindingList::iterator iter = method_bindings_.begin(); | 791 for (BindingList::iterator iter = method_bindings_.begin(); |
808 iter != method_bindings_.end(); | 792 iter != method_bindings_.end(); |
809 ++iter) { | 793 ++iter) { |
810 if ((*iter)->MatchesName(name) && (*iter)->arg_count() == arg_count) | 794 BrowserPluginMethodBinding* method = *iter; |
811 return (*iter)->Invoke(this, args, result); | 795 if (MatchesName(method->GetName(), name) && |
| 796 method->GetArgCount() == arg_count) |
| 797 return method->Invoke(args, result); |
812 } | 798 } |
813 return false; | 799 return false; |
814 } | 800 } |
815 | 801 |
816 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { | 802 bool BrowserPluginBindings::HasProperty(NPIdentifier name) const { |
817 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); | 803 for (PropertyBindingList::const_iterator iter = property_bindings_.begin(); |
818 iter != property_bindings_.end(); | 804 iter != property_bindings_.end(); |
819 ++iter) { | 805 ++iter) { |
820 if ((*iter)->MatchesName(name)) | 806 BrowserPluginPropertyBinding* property = *iter; |
| 807 if (MatchesName(property->GetName(), name)) |
821 return true; | 808 return true; |
822 } | 809 } |
823 return false; | 810 return false; |
824 } | 811 } |
825 | 812 |
826 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, | 813 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, |
827 NPIdentifier name, | 814 NPIdentifier name, |
828 const NPVariant* variant) { | 815 const NPVariant* variant) { |
829 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 816 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
830 iter != property_bindings_.end(); | 817 iter != property_bindings_.end(); |
831 ++iter) { | 818 ++iter) { |
832 if ((*iter)->MatchesName(name)) { | 819 BrowserPluginPropertyBinding* property = *iter; |
833 if ((*iter)->SetProperty(this, np_obj, variant)) { | 820 if (MatchesName(property->GetName(), name)) { |
| 821 if (property->SetProperty(np_obj, variant)) |
834 return true; | 822 return true; |
835 } | |
836 break; | 823 break; |
837 } | 824 } |
838 } | 825 } |
839 return false; | 826 return false; |
840 } | 827 } |
841 | 828 |
842 bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj, | 829 bool BrowserPluginBindings::RemoveProperty(NPObject* np_obj, |
843 NPIdentifier name) { | 830 NPIdentifier name) { |
844 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 831 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
845 iter != property_bindings_.end(); | 832 iter != property_bindings_.end(); |
846 ++iter) { | 833 ++iter) { |
847 if ((*iter)->MatchesName(name)) { | 834 BrowserPluginPropertyBinding* property = *iter; |
848 (*iter)->RemoveProperty(this, np_obj); | 835 if (MatchesName(property->GetName(), name)) { |
| 836 property->RemoveProperty(np_obj); |
849 return true; | 837 return true; |
850 } | 838 } |
851 } | 839 } |
852 return false; | 840 return false; |
853 } | 841 } |
854 | 842 |
855 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { | 843 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { |
856 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 844 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
857 iter != property_bindings_.end(); | 845 iter != property_bindings_.end(); |
858 ++iter) { | 846 ++iter) { |
859 if ((*iter)->MatchesName(name)) | 847 BrowserPluginPropertyBinding* property = *iter; |
860 return (*iter)->GetProperty(this, result); | 848 if (MatchesName(property->GetName(), name)) |
| 849 return property->GetProperty(result); |
861 } | 850 } |
862 return false; | 851 return false; |
863 } | 852 } |
864 | 853 |
| 854 void BrowserPluginBindings::AddMethodBinding( |
| 855 BrowserPluginMethodBinding* method_binding) { |
| 856 method_bindings_.push_back(method_binding); |
| 857 } |
| 858 |
| 859 void BrowserPluginBindings::AddPropertyBinding( |
| 860 BrowserPluginPropertyBinding* property_binding) { |
| 861 property_bindings_.push_back(property_binding); |
| 862 } |
| 863 |
865 } // namespace content | 864 } // namespace content |
OLD | NEW |