OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h" | 5 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "content/public/renderer/render_frame.h" | |
11 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
12 #include "content/public/renderer/v8_value_converter.h" | 11 #include "content/public/renderer/v8_value_converter.h" |
13 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
14 #include "extensions/common/extension_messages.h" | 13 #include "extensions/common/extension_messages.h" |
14 #include "extensions/renderer/guest_view/guest_view_container.h" | |
15 #include "extensions/renderer/script_context.h" | 15 #include "extensions/renderer/script_context.h" |
16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
17 | 17 |
18 using content::V8ValueConverter; | 18 using content::V8ValueConverter; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( | 22 GuestViewInternalCustomBindings::GuestViewInternalCustomBindings( |
23 ScriptContext* context) | 23 ScriptContext* context) |
24 : ObjectBackedNativeHandler(context) { | 24 : ObjectBackedNativeHandler(context) { |
25 RouteFunction("AttachGuest", | 25 RouteFunction("AttachGuest", |
26 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, | 26 base::Bind(&GuestViewInternalCustomBindings::AttachGuest, |
27 base::Unretained(this))); | 27 base::Unretained(this))); |
28 } | 28 } |
29 | 29 |
30 void GuestViewInternalCustomBindings::AttachGuest( | 30 void GuestViewInternalCustomBindings::AttachGuest( |
31 const v8::FunctionCallbackInfo<v8::Value>& args) { | 31 const v8::FunctionCallbackInfo<v8::Value>& args) { |
32 CHECK(args.Length() == 3 && args[0]->IsInt32() && args[1]->IsInt32() && | 32 CHECK(args.Length() >= 3); |
lazyboy
2014/09/17 18:24:01
I'd document the args here a bit as they are growi
Fady Samuel
2014/09/17 20:25:46
Done.
| |
33 args[2]->IsObject()); | 33 CHECK(args[0]->IsInt32()); |
34 CHECK(args[1]->IsInt32()); | |
35 CHECK(args[2]->IsObject()); | |
36 CHECK(args.Length() < 4 || args[3]->IsFunction()); | |
34 | 37 |
35 content::RenderFrame* render_frame = context()->GetRenderFrame(); | 38 int element_instance_id = args[0]->Int32Value(); |
36 if (!render_frame) | 39 GuestViewContainer* guest_view_container = |
40 GuestViewContainer::FromID(context()->GetRenderView()->GetRoutingID(), | |
41 element_instance_id); | |
42 if (!guest_view_container) | |
37 return; | 43 return; |
38 | 44 |
39 int element_instance_id = args[0]->Int32Value(); | |
40 int guest_instance_id = args[1]->Int32Value(); | 45 int guest_instance_id = args[1]->Int32Value(); |
41 | 46 |
42 scoped_ptr<base::DictionaryValue> params; | 47 scoped_ptr<base::DictionaryValue> params; |
43 { | 48 { |
44 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 49 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
45 scoped_ptr<base::Value> params_as_value( | 50 scoped_ptr<base::Value> params_as_value( |
46 converter->FromV8Value(args[2], context()->v8_context())); | 51 converter->FromV8Value(args[2], context()->v8_context())); |
47 CHECK(params_as_value->IsType(base::Value::TYPE_DICTIONARY)); | 52 CHECK(params_as_value->IsType(base::Value::TYPE_DICTIONARY)); |
48 params.reset( | 53 params.reset( |
49 static_cast<base::DictionaryValue*>(params_as_value.release())); | 54 static_cast<base::DictionaryValue*>(params_as_value.release())); |
50 } | 55 } |
51 | 56 |
52 // Step 1, send the attach params to chrome/. | 57 guest_view_container->AttachGuest( |
53 render_frame->Send(new ExtensionHostMsg_AttachGuest( | |
54 render_frame->GetRenderView()->GetRoutingID(), | |
55 element_instance_id, | 58 element_instance_id, |
56 guest_instance_id, | 59 guest_instance_id, |
57 *params)); | 60 params.Pass(), |
58 | 61 args.Length() == 4 ? args[3].As<v8::Function>() : |
59 // Step 2, attach plugin through content/. | 62 v8::Handle<v8::Function>(), |
60 render_frame->AttachGuest(element_instance_id); | 63 args.GetIsolate()); |
61 | 64 |
62 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); | 65 args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true)); |
63 } | 66 } |
64 | 67 |
65 } // namespace extensions | 68 } // namespace extensions |
OLD | NEW |