| Index: chrome/renderer/extensions/guest_view_internal_custom_bindings.cc
|
| diff --git a/chrome/renderer/extensions/guest_view_internal_custom_bindings.cc b/chrome/renderer/extensions/guest_view_internal_custom_bindings.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1cbabee8b15affb8f995506a7f89d8bd76d83791
|
| --- /dev/null
|
| +++ b/chrome/renderer/extensions/guest_view_internal_custom_bindings.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/renderer/extensions/guest_view_internal_custom_bindings.h"
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/bind.h"
|
| +#include "chrome/common/extensions/chrome_extension_messages.h"
|
| +#include "content/public/renderer/render_view.h"
|
| +#include "content/public/renderer/v8_value_converter.h"
|
| +#include "extensions/common/extension.h"
|
| +#include "extensions/renderer/script_context.h"
|
| +#include "third_party/WebKit/public/web/WebBindings.h"
|
| +#include "third_party/WebKit/public/web/WebNode.h"
|
| +#include "v8/include/v8.h"
|
| +
|
| +using content::V8ValueConverter;
|
| +
|
| +namespace {
|
| +
|
| +// TODO(lazyboy): abarth@ needs to review this.
|
| +// Returns true on success.
|
| +bool GetWebNodeFromValue(v8::Handle<v8::Value> value, blink::WebNode* node) {
|
| + NPVariant result;
|
| + blink::WebBindings::toNPVariant(value, NULL, &result);
|
| + if (result.type != NPVariantType_Object)
|
| + return false;
|
| + NPObject* obj = result.value.objectValue;
|
| + return blink::WebBindings::getNode(obj, node);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace extensions {
|
| +
|
| +GuestViewInternalCustomBindings::GuestViewInternalCustomBindings(
|
| + ScriptContext* context)
|
| + : ObjectBackedNativeHandler(context) {
|
| + RouteFunction("AttachPlugin",
|
| + base::Bind(&GuestViewInternalCustomBindings::AttachPlugin,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +void GuestViewInternalCustomBindings::AttachPlugin(
|
| + const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| + content::RenderView* render_view = context()->GetRenderView();
|
| + if (!render_view)
|
| + return;
|
| +
|
| + if (args.Length() < 3 || !args[0]->IsInt32() || !args[1]->IsInt32() ||
|
| + !args[2]->IsObject()) {
|
| + return;
|
| + }
|
| +
|
| + int guest_instance_id = args[0]->Int32Value();
|
| + int element_instance_id = args[1]->Int32Value();
|
| + scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
|
| + scoped_ptr<base::Value> params_value(
|
| + converter->FromV8Value(args[2], context()->v8_context()));
|
| + if (base::Value::TYPE_DICTIONARY != params_value->GetType()) {
|
| + return;
|
| + }
|
| +
|
| + // <element>
|
| + blink::WebNode node;
|
| + if (!GetWebNodeFromValue(args[3], &node))
|
| + return;
|
| +
|
| + // Step 1, send the attach params to chrome/.
|
| + scoped_ptr<base::DictionaryValue> params_dictionary(
|
| + static_cast<base::DictionaryValue*>(params_value.release()));
|
| + render_view->Send(new ChromeExtensionHostMsg_GuestViewSetAttachParams(
|
| + render_view->GetRoutingID(),
|
| + element_instance_id,
|
| + guest_instance_id,
|
| + *params_dictionary));
|
| +
|
| + // Step 2, attach plugin through content/.
|
| + render_view->AttachToBrowserPlugin(node);
|
| +
|
| + v8::Isolate* isolate = args.GetIsolate();
|
| + args.GetReturnValue().Set(v8::Boolean::New(isolate, true));
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|