OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/extensions/guest_view_internal_custom_bindings.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "chrome/common/extensions/chrome_extension_messages.h" |
| 11 #include "content/public/renderer/render_view.h" |
| 12 #include "content/public/renderer/v8_value_converter.h" |
| 13 #include "extensions/common/extension.h" |
| 14 #include "extensions/renderer/script_context.h" |
| 15 #include "third_party/WebKit/public/web/WebBindings.h" |
| 16 #include "third_party/WebKit/public/web/WebNode.h" |
| 17 #include "v8/include/v8.h" |
| 18 |
| 19 using content::V8ValueConverter; |
| 20 |
| 21 namespace { |
| 22 |
| 23 // TODO(lazyboy): abarth@ needs to review this. |
| 24 // Returns true on success. |
| 25 bool GetWebNodeFromValue(v8::Handle<v8::Value> value, blink::WebNode* node) { |
| 26 NPVariant result; |
| 27 blink::WebBindings::toNPVariant(value, NULL, &result); |
| 28 if (result.type != NPVariantType_Object) |
| 29 return false; |
| 30 NPObject* obj = result.value.objectValue; |
| 31 return blink::WebBindings::getNode(obj, node); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 namespace extensions { |
| 37 |
| 38 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( |
| 39 ScriptContext* context) |
| 40 : ObjectBackedNativeHandler(context) { |
| 41 RouteFunction("AttachPlugin", |
| 42 base::Bind(&GuestViewInternalCustomBindings::AttachPlugin, |
| 43 base::Unretained(this))); |
| 44 } |
| 45 |
| 46 void GuestViewInternalCustomBindings::AttachPlugin( |
| 47 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 48 content::RenderView* render_view = context()->GetRenderView(); |
| 49 if (!render_view) |
| 50 return; |
| 51 |
| 52 if (args.Length() < 3 || !args[0]->IsInt32() || !args[1]->IsInt32() || |
| 53 !args[2]->IsObject()) { |
| 54 return; |
| 55 } |
| 56 |
| 57 int guest_instance_id = args[0]->Int32Value(); |
| 58 int element_instance_id = args[1]->Int32Value(); |
| 59 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 60 scoped_ptr<base::Value> params_value( |
| 61 converter->FromV8Value(args[2], context()->v8_context())); |
| 62 if (base::Value::TYPE_DICTIONARY != params_value->GetType()) { |
| 63 return; |
| 64 } |
| 65 |
| 66 // <element> |
| 67 blink::WebNode node; |
| 68 if (!GetWebNodeFromValue(args[3], &node)) |
| 69 return; |
| 70 |
| 71 // Step 1, send the attach params to chrome/. |
| 72 scoped_ptr<base::DictionaryValue> params_dictionary( |
| 73 static_cast<base::DictionaryValue*>(params_value.release())); |
| 74 render_view->Send(new ChromeExtensionHostMsg_GuestViewSetAttachParams( |
| 75 render_view->GetRoutingID(), |
| 76 element_instance_id, |
| 77 guest_instance_id, |
| 78 *params_dictionary)); |
| 79 |
| 80 // Step 2, attach plugin through content/. |
| 81 render_view->AttachToBrowserPlugin(node); |
| 82 |
| 83 v8::Isolate* isolate = args.GetIsolate(); |
| 84 args.GetReturnValue().Set(v8::Boolean::New(isolate, true)); |
| 85 } |
| 86 |
| 87 } // namespace extensions |
OLD | NEW |