1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svtools.hxx" 24 25 #include <com/sun/star/document/XLinkAuthorizer.hpp> 26 #include <com/sun/star/frame/XController.hpp> 27 #include <com/sun/star/frame/XDesktop.hpp> 28 #include <com/sun/star/frame/XFrame.hpp> 29 #include <com/sun/star/frame/XModel.hpp> 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 #include <com/sun/star/uno/Reference.hxx> 32 #include <ucbhelper/contentbroker.hxx> 33 34 #include <svtools/linkpolicy.hxx> 35 36 using namespace ::com::sun::star; 37 38 namespace svt { namespace linkpolicy { 39 mayFollowDocumentLink(::rtl::OUString const & rUrl)40bool mayFollowDocumentLink( ::rtl::OUString const & rUrl ) 41 { 42 if ( rUrl.getLength() == 0 ) 43 return false; 44 45 // These schemes reach process state or the object model; no permission 46 // makes them a sensible target for document content. 47 if ( isVendorUrl( rUrl ) ) 48 return false; 49 50 /* Ask the current document, which needs a ServiceManager to reach. 51 Because utl::UcbStreamHelper relies on the ::ucbhelper::ContentBroker 52 instance, use its ServiceManager. */ 53 ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); 54 if ( pBroker ) 55 { 56 uno::Reference< lang::XMultiServiceFactory > xFactory = 57 pBroker->getServiceManager(); 58 if ( xFactory.is() ) 59 { 60 uno::Any desktop( xFactory->createInstance( 61 ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ) ); 62 uno::Reference< frame::XDesktop > xDesktop( desktop, uno::UNO_QUERY ); 63 if ( xDesktop.is() ) 64 { 65 uno::Reference< frame::XFrame > xFrame( xDesktop->getCurrentFrame() ); 66 if ( xFrame.is() ) 67 { 68 uno::Reference< frame::XController > xController( 69 xFrame->getController() ); 70 if ( xController.is() ) 71 { 72 uno::Reference< frame::XModel > xModel( 73 xController->getModel() ); 74 if ( xModel.is() ) 75 { 76 uno::Reference< document::XLinkAuthorizer > 77 xLinkAuthorizer( xModel, uno::UNO_QUERY ); 78 if ( xLinkAuthorizer.is() ) 79 return xLinkAuthorizer->authorizeLinks( rUrl ); 80 } 81 } 82 } 83 } 84 } 85 } 86 87 // No document to ask: behave as the linked-graphic loader always has. 88 return true; 89 } 90 91 } } 92