OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 WebServicePortProvider_h |
| 6 #define WebServicePortProvider_h |
| 7 |
| 8 #include "public/platform/WebCallbacks.h" |
| 9 #include "public/platform/WebMessagePortChannel.h" |
| 10 #include "public/platform/WebVector.h" |
| 11 #include "public/platform/modules/navigator_services/WebServicePort.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class WebString; |
| 16 class WebURL; |
| 17 |
| 18 using WebServicePortConnectCallbacks = WebCallbacks<WebServicePortID, void>; |
| 19 |
| 20 // One instance of this class is associated with each ServicePortCollection. |
| 21 // When a ServicePortCollection is destroyed the WebServicePortProvider |
| 22 // associated with it is also destroyed. All communication from ServicePorts and |
| 23 // the ServicePortCollection to embedding code goes via this interface. |
| 24 class WebServicePortProvider { |
| 25 public: |
| 26 virtual void destroy() { BLINK_ASSERT_NOT_REACHED(); } |
| 27 |
| 28 // Initiates a connection from the given origin to the given URL. When |
| 29 // successful the service can communicate with the client over the given |
| 30 // channel. The origin isn't passed as WebSecurityOrigin because that would |
| 31 // be a layering violation (platform/ code shouldn't depend on web/ code). |
| 32 // Ownership of the WebServicePortConnectCallbacks is transferred to the pro
vider. |
| 33 virtual void connect(const WebURL&, const WebString& origin, WebServicePortC
onnectCallbacks*) { BLINK_ASSERT_NOT_REACHED(); } |
| 34 |
| 35 // Called when javascript code calls postMessage on a ServicePort that is ow
ned |
| 36 // by the ServicePortCollection this provider is associated with. |
| 37 // Passes ownership of WebMessagePortChannelArray. |
| 38 virtual void postMessage(WebServicePortID, const WebString&, WebMessagePortC
hannelArray*) { BLINK_ASSERT_NOT_REACHED(); } |
| 39 |
| 40 // Called when a ServicePort owned by the ServicePortCollection this |
| 41 // provider is associated with is closed (explicitly or via garbage |
| 42 // collection). |
| 43 virtual void closePort(WebServicePortID) { BLINK_ASSERT_NOT_REACHED(); } |
| 44 |
| 45 protected: |
| 46 virtual ~WebServicePortProvider() {} |
| 47 }; |
| 48 |
| 49 } // namespace blink |
| 50 |
| 51 #if INSIDE_BLINK |
| 52 |
| 53 namespace WTF { |
| 54 |
| 55 template<typename T> struct OwnedPtrDeleter; |
| 56 template<> struct OwnedPtrDeleter<blink::WebServicePortProvider> { |
| 57 static void deletePtr(blink::WebServicePortProvider* provider) |
| 58 { |
| 59 if (provider) |
| 60 provider->destroy(); |
| 61 } |
| 62 }; |
| 63 |
| 64 } // namespace WTF |
| 65 |
| 66 #endif // INSIDE_BLINK |
| 67 |
| 68 #endif // WebServicePortProvider_h |
OLD | NEW |