/src/libreoffice/embeddedobj/source/msole/xolefactory.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <com/sun/star/embed/EntryInitModes.hpp> |
21 | | #include <com/sun/star/beans/PropertyValue.hpp> |
22 | | #include <com/sun/star/container/XNameAccess.hpp> |
23 | | #include <com/sun/star/embed/Aspects.hpp> |
24 | | #include <com/sun/star/io/IOException.hpp> |
25 | | #include <com/sun/star/lang/NoSupportException.hpp> |
26 | | #include <com/sun/star/lang/IllegalArgumentException.hpp> |
27 | | |
28 | | #include "xolefactory.hxx" |
29 | | #include <oleembobj.hxx> |
30 | | |
31 | | #include <cppuhelper/supportsservice.hxx> |
32 | | #include <cppuhelper/weak.hxx> |
33 | | |
34 | | #include <officecfg/Office/Common.hxx> |
35 | | |
36 | | using namespace ::com::sun::star; |
37 | | |
38 | | // TODO: do not create OLE objects that represent OOo documents |
39 | | |
40 | | |
41 | | uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry( |
42 | | const uno::Reference< embed::XStorage >& xStorage, |
43 | | const OUString& sEntName, |
44 | | const uno::Sequence< beans::PropertyValue >& aMedDescr, |
45 | | const uno::Sequence< beans::PropertyValue >& lObjArgs ) |
46 | 0 | { |
47 | 0 | if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() ) |
48 | 0 | throw lang::NoSupportException(u"Active OLE content is disabled!"_ustr); |
49 | 0 | if ( !xStorage.is() ) |
50 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
51 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
52 | 0 | 1 ); |
53 | | |
54 | 0 | if ( sEntName.isEmpty() ) |
55 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
56 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
57 | 0 | 2 ); |
58 | | |
59 | 0 | uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW ); |
60 | | |
61 | | // detect entry existence |
62 | 0 | if ( !xNameAccess->hasByName( sEntName ) ) |
63 | 0 | throw container::NoSuchElementException(); |
64 | | |
65 | 0 | if ( !xStorage->isStreamElement( sEntName ) ) |
66 | 0 | { |
67 | | // if it is not an OLE object throw an exception |
68 | 0 | throw io::IOException(); // TODO: |
69 | 0 | } |
70 | | |
71 | 0 | uno::Reference< uno::XInterface > xResult( |
72 | 0 | static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, false ) ), |
73 | 0 | uno::UNO_QUERY ); |
74 | |
|
75 | 0 | uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); |
76 | 0 | xPersist->setPersistentEntry( xStorage, |
77 | 0 | sEntName, |
78 | 0 | embed::EntryInitModes::DEFAULT_INIT, |
79 | 0 | aMedDescr, |
80 | 0 | lObjArgs ); |
81 | |
|
82 | 0 | for ( beans::PropertyValue const & prop : lObjArgs ) |
83 | 0 | { |
84 | 0 | if ( prop.Name == "CloneFrom" ) |
85 | 0 | { |
86 | 0 | try |
87 | 0 | { |
88 | 0 | uno::Reference < embed::XEmbeddedObject > xObj; |
89 | 0 | uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY ); |
90 | 0 | prop.Value >>= xObj; |
91 | 0 | if ( xObj.is() ) |
92 | 0 | xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) ); |
93 | 0 | } |
94 | 0 | catch ( const uno::Exception& ) {} |
95 | 0 | break; |
96 | 0 | } |
97 | 0 | } |
98 | | |
99 | 0 | return xResult; |
100 | 0 | } |
101 | | |
102 | | |
103 | | uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor( |
104 | | const uno::Reference< embed::XStorage >& xStorage, |
105 | | const OUString& sEntName, |
106 | | const uno::Sequence< beans::PropertyValue >& aMediaDescr, |
107 | | const uno::Sequence< beans::PropertyValue >& lObjArgs ) |
108 | 0 | { |
109 | 0 | if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() ) |
110 | 0 | throw lang::NoSupportException(u"Active OLE content is disabled!"_ustr); |
111 | 0 | if ( !xStorage.is() ) |
112 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
113 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
114 | 0 | 1 ); |
115 | | |
116 | 0 | if ( sEntName.isEmpty() ) |
117 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
118 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
119 | 0 | 2 ); |
120 | | |
121 | 0 | uno::Reference< uno::XInterface > xResult( |
122 | 0 | static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, false ) ), |
123 | 0 | uno::UNO_QUERY ); |
124 | |
|
125 | 0 | uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); |
126 | 0 | xPersist->setPersistentEntry( xStorage, |
127 | 0 | sEntName, |
128 | 0 | embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT, |
129 | 0 | aMediaDescr, |
130 | 0 | lObjArgs ); |
131 | |
|
132 | 0 | return xResult; |
133 | 0 | } |
134 | | |
135 | | |
136 | | uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew( |
137 | | const uno::Sequence< sal_Int8 >& aClassID, |
138 | | const OUString& aClassName, |
139 | | const uno::Reference< embed::XStorage >& xStorage, |
140 | | const OUString& sEntName, |
141 | | const uno::Sequence< beans::PropertyValue >& lObjArgs ) |
142 | 57 | { |
143 | 57 | if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() ) |
144 | 0 | throw lang::NoSupportException(u"Active OLE content is disabled!"_ustr); |
145 | 57 | if ( !xStorage.is() ) |
146 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
147 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
148 | 0 | 3 ); |
149 | | |
150 | 57 | if ( sEntName.isEmpty() ) |
151 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
152 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
153 | 0 | 4 ); |
154 | | |
155 | 57 | uno::Reference< uno::XInterface > xResult( |
156 | 57 | static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, aClassID, aClassName ) ), |
157 | 57 | uno::UNO_QUERY ); |
158 | | |
159 | 57 | uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); |
160 | 57 | xPersist->setPersistentEntry( xStorage, |
161 | 57 | sEntName, |
162 | 57 | embed::EntryInitModes::TRUNCATE_INIT, |
163 | 57 | uno::Sequence< beans::PropertyValue >(), |
164 | 57 | lObjArgs ); |
165 | | |
166 | 57 | return xResult; |
167 | 57 | } |
168 | | |
169 | | |
170 | | uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink( |
171 | | const uno::Reference< embed::XStorage >& xStorage, |
172 | | const OUString& sEntName, |
173 | | const uno::Sequence< beans::PropertyValue >& aMediaDescr, |
174 | | const uno::Sequence< beans::PropertyValue >& lObjArgs ) |
175 | 0 | { |
176 | 0 | if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() ) |
177 | 0 | throw lang::NoSupportException(u"Active OLE content is disabled!"_ustr); |
178 | 0 | if ( !xStorage.is() ) |
179 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
180 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
181 | 0 | 1 ); |
182 | | |
183 | 0 | if ( sEntName.isEmpty() ) |
184 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
185 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
186 | 0 | 2 ); |
187 | | |
188 | 0 | uno::Reference< uno::XInterface > xResult( |
189 | 0 | static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, true ) ), |
190 | 0 | uno::UNO_QUERY ); |
191 | |
|
192 | 0 | uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); |
193 | 0 | xPersist->setPersistentEntry( xStorage, |
194 | 0 | sEntName, |
195 | 0 | embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT, |
196 | 0 | aMediaDescr, |
197 | 0 | lObjArgs ); |
198 | |
|
199 | 0 | return xResult; |
200 | 0 | } |
201 | | |
202 | | |
203 | | uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit( |
204 | | const uno::Sequence< sal_Int8 >& aClassID, |
205 | | const OUString& aClassName, |
206 | | const uno::Reference< embed::XStorage >& xStorage, |
207 | | const OUString& sEntName, |
208 | | sal_Int32 /*nEntryConnectionMode*/, |
209 | | const uno::Sequence< beans::PropertyValue >& /*lArguments*/, |
210 | | const uno::Sequence< beans::PropertyValue >& lObjArgs ) |
211 | 0 | { |
212 | 0 | if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()) |
213 | 0 | throw lang::NoSupportException(u"Active OLE content is disabled!"_ustr); |
214 | | // the initialization is completely controlled by user |
215 | 0 | if ( !xStorage.is() ) |
216 | 0 | throw lang::IllegalArgumentException( u"No parent storage is provided!"_ustr, |
217 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
218 | 0 | 1 ); |
219 | | |
220 | 0 | if ( sEntName.isEmpty() ) |
221 | 0 | throw lang::IllegalArgumentException( u"Empty element name is provided!"_ustr, |
222 | 0 | static_cast< ::cppu::OWeakObject* >(this), |
223 | 0 | 2 ); |
224 | | |
225 | 0 | uno::Reference< uno::XInterface > xResult( |
226 | 0 | static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, aClassID, aClassName ) ), |
227 | 0 | uno::UNO_QUERY ); |
228 | |
|
229 | 0 | uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); |
230 | 0 | xPersist->setPersistentEntry( xStorage, |
231 | 0 | sEntName, |
232 | 0 | embed::EntryInitModes::DEFAULT_INIT, |
233 | 0 | uno::Sequence< beans::PropertyValue >(), |
234 | 0 | lObjArgs ); |
235 | |
|
236 | 0 | return xResult; |
237 | 0 | } |
238 | | |
239 | | |
240 | | OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName() |
241 | 0 | { |
242 | 0 | return u"com.sun.star.comp.embed.OLEEmbeddedObjectFactory"_ustr; |
243 | 0 | } |
244 | | |
245 | | sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName ) |
246 | 0 | { |
247 | 0 | return cppu::supportsService(this, ServiceName); |
248 | 0 | } |
249 | | |
250 | | |
251 | | uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames() |
252 | 0 | { |
253 | 0 | return { u"com.sun.star.embed.OLEEmbeddedObjectFactory"_ustr, |
254 | 0 | u"com.sun.star.comp.embed.OLEEmbeddedObjectFactory"_ustr }; |
255 | 0 | } |
256 | | |
257 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
258 | | embeddedobj_OleEmbeddedObjectFactory_get_implementation( |
259 | | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) |
260 | 2 | { |
261 | 2 | return cppu::acquire(new OleEmbeddedObjectFactory(context)); |
262 | 2 | } |
263 | | |
264 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |