1 // Copyright 2013 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.
5 #include "content/renderer/pepper/resource_converter.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/public/renderer/renderer_ppapi_host.h"
10 #include "ipc/ipc_message.h"
11 #include "ppapi/shared_impl/resource_var.h"
12 #include "ppapi/shared_impl/scoped_pp_var.h"
17 const base::Callback
<void(bool)>& callback
,
18 const std::vector
<scoped_refptr
<content::HostResourceVar
> >& browser_vars
,
19 const std::vector
<int>& pending_host_ids
) {
20 CHECK(browser_vars
.size() == pending_host_ids
.size());
21 for (size_t i
= 0; i
< browser_vars
.size(); ++i
) {
22 browser_vars
[i
]->set_pending_browser_host_id(pending_host_ids
[i
]);
31 ResourceConverter::~ResourceConverter() {}
33 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance
,
34 RendererPpapiHost
* host
)
35 : instance_(instance
),
39 ResourceConverterImpl::~ResourceConverterImpl() {
40 // Verify Flush() was called.
41 DCHECK(browser_host_create_messages_
.empty());
42 DCHECK(browser_vars
.empty());
45 bool ResourceConverterImpl::FromV8Value(v8::Handle
<v8::Object
> val
,
46 v8::Handle
<v8::Context
> context
,
49 v8::Context::Scope
context_scope(context
);
50 v8::HandleScope
handle_scope(context
->GetIsolate());
52 *was_resource
= false;
53 // TODO(mgiuca): There are currently no values which can be converted to
59 void ResourceConverterImpl::Flush(const base::Callback
<void(bool)>& callback
) {
60 host_
->CreateBrowserResourceHosts(
62 browser_host_create_messages_
,
63 base::Bind(&FlushComplete
, callback
, browser_vars
));
64 browser_host_create_messages_
.clear();
68 scoped_refptr
<HostResourceVar
> ResourceConverterImpl::CreateResourceVar(
69 int pending_renderer_id
,
70 const IPC::Message
& create_message
) {
71 return new HostResourceVar(pending_renderer_id
, create_message
);
74 scoped_refptr
<HostResourceVar
>
75 ResourceConverterImpl::CreateResourceVarWithBrowserHost(
76 int pending_renderer_id
,
77 const IPC::Message
& create_message
,
78 const IPC::Message
& browser_host_create_message
) {
79 scoped_refptr
<HostResourceVar
> result
=
80 CreateResourceVar(pending_renderer_id
, create_message
);
81 browser_host_create_messages_
.push_back(browser_host_create_message
);
82 browser_vars
.push_back(result
);
86 } // namespace content