Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: ppapi/proxy/extensions_common_resource.cc

Issue 13080002: Apps V2 in Pepper: introduce singleton resource ExtensionsCommon. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/extensions_common_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "ppapi/proxy/extensions_common_resource.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/resource_message_params.h"
15 #include "ppapi/shared_impl/tracked_callback.h"
16 #include "ppapi/shared_impl/var_value_conversions.h"
17
18 namespace ppapi {
19 namespace proxy {
20
21 ExtensionsCommonResource::ExtensionsCommonResource(Connection connection,
22 PP_Instance instance)
23 : PluginResource(connection, instance) {
24 SendCreate(RENDERER, PpapiHostMsg_ExtensionsCommon_Create());
25 }
26
27 ExtensionsCommonResource::~ExtensionsCommonResource() {
28 }
29
30 thunk::ExtensionsCommon_API*
31 ExtensionsCommonResource::AsExtensionsCommon_API() {
32 return this;
33 }
34
35 int32_t ExtensionsCommonResource::Call(
36 const std::string& request_name,
37 const std::vector<PP_Var>& input_args,
38 const std::vector<PP_Var*>& output_args,
39 scoped_refptr<TrackedCallback> callback) {
40 // TODO(yzshen): CreateValueFromVar() doesn't generate null fields for
41 // dictionary values. That is the expected behavior for most APIs. If later we
42 // want to support APIs that require to preserve null fields in dictionaries,
43 // we should change the behavior to always preserve null fields at the plugin
44 // side, and figure out whether they should be stripped at the renderer side.
45 scoped_ptr<base::ListValue> input_args_value(
46 CreateListValueFromVarVector(input_args));
47 if (!input_args_value.get()) {
48 LOG(WARNING) << "Failed to convert PP_Var input arguments.";
49 return PP_ERROR_BADARGUMENT;
50 }
51
52 PluginResource::Call<PpapiPluginMsg_ExtensionsCommon_CallReply>(
53 RENDERER,
54 PpapiHostMsg_ExtensionsCommon_Call(request_name, *input_args_value),
55 base::Bind(&ExtensionsCommonResource::OnPluginMsgCallReply,
56 base::Unretained(this), output_args, callback));
57 return PP_OK_COMPLETIONPENDING;
58 }
59
60 void ExtensionsCommonResource::Post(const std::string& request_name,
61 const std::vector<PP_Var>& args) {
62 scoped_ptr<base::ListValue> args_value(CreateListValueFromVarVector(args));
63 if (!args_value.get()) {
64 LOG(WARNING) << "Failed to convert PP_Var input arguments.";
65 return;
66 }
67
68 PluginResource::Post(
69 RENDERER, PpapiHostMsg_ExtensionsCommon_Post(request_name, *args_value));
70 }
71
72 void ExtensionsCommonResource::OnPluginMsgCallReply(
73 const std::vector<PP_Var*>& output_args,
74 scoped_refptr<TrackedCallback> callback,
75 const ResourceMessageReplyParams& params,
76 const base::ListValue& output) {
77 // |output_args| may be invalid and shouldn't be accessed if the callback has
78 // been called.
79 if (!TrackedCallback::IsPending(callback))
80 return;
81
82 int32_t result = params.result();
83 if (result == PP_OK) {
84 // If the size doesn't match, something must be really wrong.
85 CHECK_EQ(output_args.size(), output.GetSize());
86
87 std::vector<PP_Var> output_vars;
88 if (CreateVarVectorFromListValue(output, &output_vars)) {
89 DCHECK_EQ(output_args.size(), output_vars.size());
90 std::vector<PP_Var>::const_iterator src_iter = output_vars.begin();
91 std::vector<PP_Var*>::const_iterator dest_iter = output_args.begin();
92 for (; src_iter != output_vars.end() && dest_iter != output_args.end();
93 ++src_iter, ++dest_iter) {
94 **dest_iter = *src_iter;
95 }
96 } else {
97 result = PP_ERROR_FAILED;
98 }
99 }
100
101 callback->Run(result);
102 }
103
104 } // namespace proxy
105 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/extensions_common_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698