| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/timer.h" | 9 #include "base/timer.h" |
| 10 #include "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
| 11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 13 #include "net/base/address_list.h" |
| 13 | 14 |
| 15 namespace net { |
| 16 class SingleRequestHostResolver; |
| 17 } |
| 18 |
| 19 // Base class for web socket proxy functions. |
| 14 class WebSocketProxyPrivate | 20 class WebSocketProxyPrivate |
| 15 : public AsyncExtensionFunction, public content::NotificationObserver { | 21 : public AsyncExtensionFunction, public content::NotificationObserver { |
| 16 public: | 22 public: |
| 17 WebSocketProxyPrivate(); | 23 WebSocketProxyPrivate(); |
| 18 | |
| 19 virtual ~WebSocketProxyPrivate(); | 24 virtual ~WebSocketProxyPrivate(); |
| 20 | 25 |
| 21 // Finalizes async operation. | 26 protected: |
| 22 virtual void Finalize(); | 27 // Custom finalization. |
| 28 virtual void CustomFinalize() = 0; |
| 23 | 29 |
| 24 protected: | |
| 25 // content::NotificationObserver implementation. | |
| 26 virtual void Observe( | |
| 27 int type, const content::NotificationSource& source, | |
| 28 const content::NotificationDetails& details) OVERRIDE; | |
| 29 | |
| 30 // Whether already finalized. | |
| 31 bool is_finalized_; | |
| 32 | |
| 33 // Used to signal timeout (when waiting for proxy initial launch). | |
| 34 base::OneShotTimer<WebSocketProxyPrivate> timer_; | |
| 35 | |
| 36 content::NotificationRegistrar registrar_; | |
| 37 | |
| 38 // Proxy accepts websocket connections on this port. | |
| 39 int listening_port_; | |
| 40 }; | |
| 41 | |
| 42 class WebSocketProxyPrivateGetURLForTCPFunction | |
| 43 : public WebSocketProxyPrivate { | |
| 44 private: | |
| 45 // ExtensionFunction implementation. | 30 // ExtensionFunction implementation. |
| 46 virtual bool RunImpl() OVERRIDE; | 31 virtual bool RunImpl() OVERRIDE; |
| 47 | 32 |
| 48 // content::NotificationObserver implementation. | 33 // content::NotificationObserver implementation. |
| 49 virtual void Observe( | 34 virtual void Observe( |
| 50 int type, const content::NotificationSource& source, | 35 int type, const content::NotificationSource& source, |
| 51 const content::NotificationDetails& details) OVERRIDE; | 36 const content::NotificationDetails& details) OVERRIDE; |
| 52 | 37 |
| 53 // Finalizes async operation. | 38 // Destination hostname. |
| 54 virtual void Finalize() OVERRIDE; | 39 std::string hostname_; |
| 40 // Destination IP address. |
| 41 net::AddressList addr_; |
| 42 // Destination port. |
| 43 int port_; |
| 44 // Proxy accepts websocket connections on this port. |
| 45 int listening_port_; |
| 46 // Whether TLS should be used. |
| 47 bool do_tls_; |
| 48 // Requested parameters of connection. |
| 49 std::map<std::string, std::string> map_; |
| 55 | 50 |
| 56 // Query component of resulting URL. | 51 private: |
| 57 std::string query_; | 52 // Finalizes and sends respond. Overwrite 'CustomFinalize' in inherited |
| 53 // classes. |
| 54 void Finalize(); |
| 58 | 55 |
| 59 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getURLForTCP") | 56 // Callback for DNS resolution. |
| 57 void OnHostResolution(int result); |
| 58 |
| 59 // Executes on IO thread. Performs DNS resolution. |
| 60 void ResolveHost(); |
| 61 |
| 62 // Used to signal timeout (when waiting for proxy initial launch). |
| 63 base::OneShotTimer<WebSocketProxyPrivate> timer_; |
| 64 // Used to register for notifications. |
| 65 content::NotificationRegistrar registrar_; |
| 66 // Used to cancel host resolution when out of scope. |
| 67 scoped_ptr<net::SingleRequestHostResolver> resolver_; |
| 68 // Callback which is called when host is resolved. |
| 69 bool is_finalized_; |
| 60 }; | 70 }; |
| 61 | 71 |
| 62 // Legacy, deprecated, to be eliminated. | 72 // New API function for web socket proxy, which should be used. |
| 63 class WebSocketProxyPrivateGetPassportForTCPFunction | 73 class WebSocketProxyPrivateGetURLForTCPFunction |
| 64 : public WebSocketProxyPrivate { | 74 : public WebSocketProxyPrivate { |
| 65 public: | 75 public: |
| 66 WebSocketProxyPrivateGetPassportForTCPFunction(); | 76 WebSocketProxyPrivateGetURLForTCPFunction(); |
| 77 virtual ~WebSocketProxyPrivateGetURLForTCPFunction(); |
| 67 | 78 |
| 68 private: | 79 private: |
| 69 // ExtensionFunction implementation. | 80 // ExtensionFunction implementation. |
| 70 virtual bool RunImpl() OVERRIDE; | 81 virtual bool RunImpl() OVERRIDE; |
| 71 | 82 |
| 83 // WebSocketProxyPrivate implementation: |
| 84 virtual void CustomFinalize() OVERRIDE; |
| 85 |
| 86 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getURLForTCP") |
| 87 }; |
| 88 |
| 89 // Legacy API function for web socket proxy, to be eliminated. |
| 90 class WebSocketProxyPrivateGetPassportForTCPFunction |
| 91 : public WebSocketProxyPrivate { |
| 92 public: |
| 93 WebSocketProxyPrivateGetPassportForTCPFunction(); |
| 94 virtual ~WebSocketProxyPrivateGetPassportForTCPFunction(); |
| 95 |
| 96 private: |
| 97 // WebSocketProxyPrivate implementation: |
| 98 virtual void CustomFinalize() OVERRIDE; |
| 99 |
| 72 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getPassportForTCP") | 100 DECLARE_EXTENSION_FUNCTION_NAME("webSocketProxyPrivate.getPassportForTCP") |
| 73 }; | 101 }; |
| 74 | 102 |
| 75 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_SOCKET_PROXY_PRIVATE_API_H_ |
| OLD | NEW |