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

Side by Side Diff: plugins/update/npapi/npfunction_host.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2010 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/plugins/update/npapi/npfunction_host.h"
17
18 #include "omaha/base/debug.h"
19 #include "omaha/base/utils.h"
20 #include "omaha/plugins/update/npapi/variant_utils.h"
21
22 namespace omaha {
23
24 typedef CComObject<NpFunctionHost> CComNpFuncHost;
25 typedef scoped_any<CComNpFuncHost*, close_release_com, null_t> scoped_host;
26
27 HRESULT NpFunctionHost::Create(NPP npp, NPObject* npobj, IDispatch** host) {
28 ASSERT1(npobj);
29 ASSERT1(host);
30
31 if (!npobj || !host) {
32 return E_INVALIDARG;
33 }
34
35 // Create the host and hand off the NPObject to it.
36 scoped_host comobj;
37 HRESULT hr = CComNpFuncHost::CreateInstance(address(comobj));
38 if (FAILED(hr)) {
39 return hr;
40 }
41 get(comobj)->AddRef();
42
43 comobj->npp_ = npp;
44 comobj->obj_ = npobj;
45 NPN_RetainObject(npobj);
46
47 return comobj->QueryInterface(host);
48 }
49
50 STDMETHODIMP NpFunctionHost::GetTypeInfoCount(UINT* pctinfo) {
51 if (pctinfo == NULL) {
52 return E_INVALIDARG;
53 }
54 *pctinfo = 0;
55 return S_OK;
56 }
57
58 STDMETHODIMP NpFunctionHost::GetTypeInfo(UINT iTInfo,
59 LCID lcid,
60 ITypeInfo** ppTInfo) {
61 UNREFERENCED_PARAMETER(iTInfo);
62 UNREFERENCED_PARAMETER(lcid);
63 UNREFERENCED_PARAMETER(ppTInfo);
64
65 return E_NOTIMPL;
66 }
67
68 STDMETHODIMP NpFunctionHost::GetIDsOfNames(REFIID riid,
69 LPOLESTR* rgszNames,
70 UINT cNames,
71 LCID lcid,
72 DISPID* rgDispId) {
73 UNREFERENCED_PARAMETER(riid);
74 UNREFERENCED_PARAMETER(rgszNames);
75 UNREFERENCED_PARAMETER(cNames);
76 UNREFERENCED_PARAMETER(lcid);
77 UNREFERENCED_PARAMETER(rgDispId);
78
79 return E_NOTIMPL;
80 }
81
82 STDMETHODIMP NpFunctionHost::Invoke(DISPID dispIdMember,
83 REFIID riid,
84 LCID lcid,
85 WORD wFlags,
86 DISPPARAMS* pDispParams,
87 VARIANT* pVarResult,
88 EXCEPINFO* pExcepInfo,
89 UINT* puArgErr) {
90 UNREFERENCED_PARAMETER(dispIdMember);
91 UNREFERENCED_PARAMETER(riid);
92 UNREFERENCED_PARAMETER(lcid);
93 UNREFERENCED_PARAMETER(pExcepInfo);
94 UNREFERENCED_PARAMETER(puArgErr);
95
96 if (wFlags != DISPATCH_METHOD) {
97 return DISP_E_MEMBERNOTFOUND;
98 }
99
100 uint32_t num_args = 0;
101 scoped_array<NPVariant> arguments;
102 if (pDispParams) {
103 // Javascript doesn't officially support named args, so the current
104 // implementation ignores any named args that are supplied. However,
105 // you can cast a function object to a string and it will hold the
106 // argument names as used in the function definition. Thus, if we
107 // need to support named arguments in the future, we may be able to
108 // get the argument names indirectly using NPN_Evaluate() and emulate.
109 if (pDispParams->cNamedArgs != 0) {
110 return DISP_E_NONAMEDARGS;
111 }
112 if (pDispParams->cArgs != 0) {
113 num_args = pDispParams->cArgs;
114 arguments.reset(new NPVariant[num_args]);
115 for (uint32_t i = 0; i < num_args; ++i) {
116 // Arguments are stored in rgvarg in reverse order.
117 VariantToNPVariant(npp_,
118 pDispParams->rgvarg[num_args - 1 - i],
119 &arguments[i]);
120 }
121 }
122 }
123
124 NPVariant retval;
125 VOID_TO_NPVARIANT(retval);
126
127 bool result = NPN_InvokeDefault(npp_,
128 obj_,
129 arguments.get(),
130 num_args,
131 &retval);
132 if (result && pVarResult) {
133 NPVariantToVariant(npp_, retval, pVarResult);
134 }
135 NPN_ReleaseVariantValue(&retval);
136
137 return result ? S_OK : E_FAIL;
138 }
139
140 void NpFunctionHost::FinalRelease() {
141 ASSERT1(obj_);
142 if (obj_) {
143 NPN_ReleaseObject(obj_);
144 obj_ = NULL;
145 }
146 }
147
148 NpFunctionHost::NpFunctionHost() : npp_(NULL), obj_(NULL) {}
149
150 } // namespace omaha
151
OLDNEW
« no previous file with comments | « plugins/update/npapi/npfunction_host.h ('k') | plugins/update/npapi/npfunction_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698