OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ |
6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ | 6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "mojo/public/cpp/bindings/associated_binding_set.h" | 16 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
17 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 17 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
18 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 18 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class RenderFrameHost; | 22 class RenderFrameHost; |
23 class WebContentsImpl; | 23 class WebContentsImpl; |
24 | 24 |
25 // Base class for something which owns a mojo::AssociatedBindingSet on behalf | 25 // Base class for something which owns a mojo::AssociatedBindingSet on behalf |
26 // of a WebContents. See WebContentsFrameBindingSet<T> below. | 26 // of a WebContents. See WebContentsFrameBindingSet<T> below. |
27 class CONTENT_EXPORT WebContentsBindingSet { | 27 class CONTENT_EXPORT WebContentsBindingSet { |
28 protected: | 28 public: |
29 class CONTENT_EXPORT Binder { | 29 class CONTENT_EXPORT Binder { |
30 public: | 30 public: |
31 virtual ~Binder() {} | 31 virtual ~Binder() {} |
32 | 32 |
33 virtual void OnRequestForFrame( | 33 virtual void OnRequestForFrame( |
34 RenderFrameHost* render_frame_host, | 34 RenderFrameHost* render_frame_host, |
35 mojo::ScopedInterfaceEndpointHandle handle); | 35 mojo::ScopedInterfaceEndpointHandle handle); |
36 }; | 36 }; |
37 | 37 |
| 38 void SetBinderForTesting(std::unique_ptr<Binder> binder) { |
| 39 binder_for_testing_ = std::move(binder); |
| 40 } |
| 41 |
| 42 protected: |
38 WebContentsBindingSet(WebContents* web_contents, | 43 WebContentsBindingSet(WebContents* web_contents, |
39 const std::string& interface_name, | 44 const std::string& interface_name, |
40 std::unique_ptr<Binder> binder); | 45 std::unique_ptr<Binder> binder); |
41 ~WebContentsBindingSet(); | 46 ~WebContentsBindingSet(); |
42 | 47 |
43 private: | 48 private: |
44 friend class WebContentsImpl; | 49 friend class WebContentsImpl; |
45 | 50 |
46 void CloseAllBindings(); | 51 void CloseAllBindings(); |
47 void OnRequestForFrame(RenderFrameHost* render_frame_host, | 52 void OnRequestForFrame(RenderFrameHost* render_frame_host, |
48 mojo::ScopedInterfaceEndpointHandle handle); | 53 mojo::ScopedInterfaceEndpointHandle handle); |
49 | 54 |
50 const base::Closure remove_callback_; | 55 const base::Closure remove_callback_; |
51 std::unique_ptr<Binder> binder_; | 56 std::unique_ptr<Binder> binder_; |
| 57 std::unique_ptr<Binder> binder_for_testing_; |
52 | 58 |
53 DISALLOW_COPY_AND_ASSIGN(WebContentsBindingSet); | 59 DISALLOW_COPY_AND_ASSIGN(WebContentsBindingSet); |
54 }; | 60 }; |
55 | 61 |
56 // Owns a set of Channel-associated interface bindings with frame context on | 62 // Owns a set of Channel-associated interface bindings with frame context on |
57 // message dispatch. | 63 // message dispatch. |
58 // | 64 // |
59 // To use this, a |mojom::Foo| implementation need only own an instance of | 65 // To use this, a |mojom::Foo| implementation need only own an instance of |
60 // WebContentsFrameBindingSet<mojom::Foo>. This allows remote RenderFrames to | 66 // WebContentsFrameBindingSet<mojom::Foo>. This allows remote RenderFrames to |
61 // acquire handles to the |mojom::Foo| interface via | 67 // acquire handles to the |mojom::Foo| interface via |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 153 } |
148 | 154 |
149 RenderFrameHost* current_target_frame_ = nullptr; | 155 RenderFrameHost* current_target_frame_ = nullptr; |
150 | 156 |
151 DISALLOW_COPY_AND_ASSIGN(WebContentsFrameBindingSet); | 157 DISALLOW_COPY_AND_ASSIGN(WebContentsFrameBindingSet); |
152 }; | 158 }; |
153 | 159 |
154 } // namespace content | 160 } // namespace content |
155 | 161 |
156 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ | 162 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_BINDING_SET_H_ |
OLD | NEW |