1 // Copyright 2017 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 #ifndef CONTENT_BROWSER_INTERFACE_PROVIDER_FILTERING_H_ 6 #define CONTENT_BROWSER_INTERFACE_PROVIDER_FILTERING_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "base/strings/string_piece.h" 12 #include "content/common/content_export.h" 13 #include "mojo/public/cpp/bindings/pending_receiver.h" 14 #include "services/service_manager/public/mojom/interface_provider.mojom.h" 15 16 namespace content { 17 18 // Filters interface requests received from an execution context of the type 19 // corresponding to |spec| in the renderer process with ID |process_id|. 20 // |receiver| is the PendingReceiver<InterfaceProvider> from the renderer; an 21 // equivalent PendingReceiver<InterfaceProvider> where GetInterface receivers 22 // have been filtered. 23 // 24 // If |process_id| does not refer to a renderer process or if that renderer's 25 // BrowserContext does not have a Connector, the connection is broken instead; 26 // that is, |receiver| and the mojo::PendingRemote<Interface> corresponding 27 // to the returned receiver are both closed. 28 mojo::PendingReceiver<service_manager::mojom::InterfaceProvider> 29 FilterRendererExposedInterfaces( 30 const char* spec, 31 int process_id, 32 mojo::PendingReceiver<service_manager::mojom::InterfaceProvider> receiver); 33 34 namespace test { 35 36 // Allows through all interface requests while in scope. For testing only. 37 // 38 // TODO(https://crbug.com/792407): See if browser tests can just set up the 39 // service_Manager::Connector properly instead of this heavy-handed solution. 40 class CONTENT_EXPORT ScopedInterfaceFilterBypass { 41 public: 42 ScopedInterfaceFilterBypass(); 43 ~ScopedInterfaceFilterBypass(); 44 45 private: 46 DISALLOW_COPY_AND_ASSIGN(ScopedInterfaceFilterBypass); 47 }; 48 49 } // namespace test 50 51 } // namespace content 52 53 #endif // CONTENT_BROWSER_INTERFACE_PROVIDER_FILTERING_H_ 54