OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 private: | 224 private: |
225 std::string name_; | 225 std::string name_; |
226 uint32 arg_count_; | 226 uint32 arg_count_; |
227 | 227 |
228 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); | 228 DISALLOW_COPY_AND_ASSIGN(BrowserPluginMethodBinding); |
229 }; | 229 }; |
230 | 230 |
231 class BrowserPluginBindingAttach: public BrowserPluginMethodBinding { | 231 class BrowserPluginBindingAttach: public BrowserPluginMethodBinding { |
232 public: | 232 public: |
233 BrowserPluginBindingAttach() | 233 BrowserPluginBindingAttach() |
234 : BrowserPluginMethodBinding( | 234 : BrowserPluginMethodBinding(browser_plugin::kMethodInternalAttach, 2) {} |
235 browser_plugin::kMethodInternalAttach, 1) { | |
236 } | |
237 | 235 |
238 virtual bool Invoke(BrowserPluginBindings* bindings, | 236 virtual bool Invoke(BrowserPluginBindings* bindings, |
239 const NPVariant* args, | 237 const NPVariant* args, |
240 NPVariant* result) OVERRIDE { | 238 NPVariant* result) OVERRIDE { |
241 if (!bindings->instance()->render_view()) | 239 if (!bindings->instance()->render_view()) |
242 return false; | 240 return false; |
243 | 241 |
| 242 int instance_id = IntFromNPVariant(args[0]); |
| 243 if (!instance_id) |
| 244 return false; |
| 245 |
244 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 246 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
245 v8::Handle<v8::Value> obj(blink::WebBindings::toV8Value(&args[0])); | 247 v8::Handle<v8::Value> obj(blink::WebBindings::toV8Value(&args[1])); |
246 scoped_ptr<base::Value> value( | 248 scoped_ptr<base::Value> value( |
247 converter->FromV8Value(obj, bindings->instance()->render_view()-> | 249 converter->FromV8Value(obj, bindings->instance()->render_view()-> |
248 GetWebView()->mainFrame()->mainWorldScriptContext())); | 250 GetWebView()->mainFrame()->mainWorldScriptContext())); |
249 if (!value) | 251 if (!value) |
250 return false; | 252 return false; |
251 | 253 |
252 if (!value->IsType(base::Value::TYPE_DICTIONARY)) | 254 if (!value->IsType(base::Value::TYPE_DICTIONARY)) |
253 return false; | 255 return false; |
254 | 256 |
255 scoped_ptr<base::DictionaryValue> extra_params( | 257 scoped_ptr<base::DictionaryValue> extra_params( |
256 static_cast<base::DictionaryValue*>(value.release())); | 258 static_cast<base::DictionaryValue*>(value.release())); |
257 bindings->instance()->Attach(extra_params.Pass()); | 259 bindings->instance()->Attach(instance_id, extra_params.Pass()); |
258 return true; | 260 return true; |
259 } | 261 } |
260 | 262 |
261 private: | 263 private: |
262 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingAttach); | 264 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingAttach); |
263 }; | 265 }; |
264 | 266 |
265 class BrowserPluginBindingAttachWindowTo : public BrowserPluginMethodBinding { | |
266 public: | |
267 BrowserPluginBindingAttachWindowTo() | |
268 : BrowserPluginMethodBinding( | |
269 browser_plugin::kMethodInternalAttachWindowTo, 2) { | |
270 } | |
271 | |
272 virtual bool Invoke(BrowserPluginBindings* bindings, | |
273 const NPVariant* args, | |
274 NPVariant* result) OVERRIDE { | |
275 blink::WebNode node; | |
276 WebBindings::getNode(NPVARIANT_TO_OBJECT(args[0]), &node); | |
277 int window_id = IntFromNPVariant(args[1]); | |
278 BOOLEAN_TO_NPVARIANT(BrowserPlugin::AttachWindowTo(node, window_id), | |
279 *result); | |
280 return true; | |
281 } | |
282 | |
283 private: | |
284 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingAttachWindowTo); | |
285 }; | |
286 | |
287 // BrowserPluginPropertyBinding ------------------------------------------------ | 267 // BrowserPluginPropertyBinding ------------------------------------------------ |
288 | 268 |
289 class BrowserPluginPropertyBinding { | 269 class BrowserPluginPropertyBinding { |
290 public: | 270 public: |
291 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {} | 271 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) {} |
292 virtual ~BrowserPluginPropertyBinding() {} | 272 virtual ~BrowserPluginPropertyBinding() {} |
293 const std::string& name() const { return name_; } | 273 const std::string& name() const { return name_; } |
294 bool MatchesName(NPIdentifier name) const { | 274 bool MatchesName(NPIdentifier name) const { |
295 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 275 return WebBindings::getStringIdentifier(name_.c_str()) == name; |
296 } | 276 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 : instance_(instance), | 644 : instance_(instance), |
665 np_object_(NULL), | 645 np_object_(NULL), |
666 weak_ptr_factory_(this) { | 646 weak_ptr_factory_(this) { |
667 NPObject* obj = | 647 NPObject* obj = |
668 WebBindings::createObject(instance->pluginNPP(), | 648 WebBindings::createObject(instance->pluginNPP(), |
669 &browser_plugin_message_class); | 649 &browser_plugin_message_class); |
670 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); | 650 np_object_ = static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(obj); |
671 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); | 651 np_object_->message_channel = weak_ptr_factory_.GetWeakPtr(); |
672 | 652 |
673 method_bindings_.push_back(new BrowserPluginBindingAttach); | 653 method_bindings_.push_back(new BrowserPluginBindingAttach); |
674 method_bindings_.push_back(new BrowserPluginBindingAttachWindowTo); | |
675 | 654 |
676 property_bindings_.push_back( | 655 property_bindings_.push_back( |
677 new BrowserPluginPropertyBindingAllowTransparency); | 656 new BrowserPluginPropertyBindingAllowTransparency); |
678 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); | 657 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); |
679 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 658 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); |
680 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); | 659 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); |
681 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); | 660 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); |
682 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); | 661 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); |
683 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); | 662 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); |
684 property_bindings_.push_back(new BrowserPluginPropertyBindingName); | 663 property_bindings_.push_back(new BrowserPluginPropertyBindingName); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 735 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
757 iter != property_bindings_.end(); | 736 iter != property_bindings_.end(); |
758 ++iter) { | 737 ++iter) { |
759 if ((*iter)->MatchesName(name)) | 738 if ((*iter)->MatchesName(name)) |
760 return (*iter)->GetProperty(this, result); | 739 return (*iter)->GetProperty(this, result); |
761 } | 740 } |
762 return false; | 741 return false; |
763 } | 742 } |
764 | 743 |
765 } // namespace content | 744 } // namespace content |
OLD | NEW |