| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/stl_util.h" |
| 16 #include "content/browser/devtools/devtools_protocol.h" | 17 #include "content/browser/devtools/devtools_protocol.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 | 20 |
| 20 class DictionaryValue; | 21 class DictionaryValue; |
| 21 class MessageLoopProxy; | 22 class MessageLoopProxy; |
| 22 class Value; | 23 class Value; |
| 23 | 24 |
| 24 } // namespace base | 25 } // namespace base |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 class HttpServer; | 28 class HttpServer; |
| 28 } // namespace net | 29 } // namespace net |
| 29 | 30 |
| 30 namespace content { | 31 namespace content { |
| 31 | 32 |
| 32 // This class handles the "Browser" target for remote debugging. | 33 // This class handles the "Browser" target for remote debugging. |
| 33 class DevToolsBrowserTarget { | 34 class DevToolsBrowserTarget { |
| 34 public: | 35 public: |
| 35 typedef base::Callback<void(const std::string& method, | 36 class DomainHandler : public DevToolsProtocol::Handler { |
| 36 base::DictionaryValue* params)> Notifier; | |
| 37 | |
| 38 class DomainHandler { | |
| 39 public: | 37 public: |
| 40 typedef base::Callback<scoped_ptr<DevToolsProtocol::Response>( | |
| 41 DevToolsProtocol::Command* command)> CommandHandler; | |
| 42 virtual ~DomainHandler(); | 38 virtual ~DomainHandler(); |
| 43 | 39 |
| 44 // Returns the domain name for this handler. | 40 // Overridden from Handler: |
| 41 virtual scoped_ptr<DevToolsProtocol::Response> HandleCommand( |
| 42 DevToolsProtocol::Command* command) OVERRIDE; |
| 43 |
| 45 std::string domain() { return domain_; } | 44 std::string domain() { return domain_; } |
| 46 | 45 |
| 47 void RegisterCommandHandler(const std::string& command, | |
| 48 CommandHandler handler); | |
| 49 | |
| 50 protected: | 46 protected: |
| 51 explicit DomainHandler(const std::string& domain); | 47 DomainHandler(const DevToolsProtocol::Notifier& notifier, |
| 52 | 48 const std::string& domain); |
| 53 // |params| and |error_out| ownership is transferred to the | |
| 54 // caller. | |
| 55 virtual scoped_ptr<DevToolsProtocol::Response> HandleCommand( | |
| 56 DevToolsProtocol::Command* command); | |
| 57 | |
| 58 // Sends notification to the client. Takes ownership of |params|. | |
| 59 void SendNotification(const std::string& method, | |
| 60 base::DictionaryValue* params); | |
| 61 | 49 |
| 62 private: | 50 private: |
| 63 friend class DevToolsBrowserTarget; | |
| 64 void set_notifier(Notifier notifier) { notifier_ = notifier; } | |
| 65 | |
| 66 std::string domain_; | 51 std::string domain_; |
| 67 Notifier notifier_; | |
| 68 typedef std::map<std::string, CommandHandler> CommandHandlers; | |
| 69 CommandHandlers command_handlers_; | |
| 70 | 52 |
| 71 DISALLOW_COPY_AND_ASSIGN(DomainHandler); | 53 DISALLOW_COPY_AND_ASSIGN(DomainHandler); |
| 72 }; | 54 }; |
| 73 | 55 |
| 74 DevToolsBrowserTarget(base::MessageLoopProxy* message_loop_proxy, | 56 DevToolsBrowserTarget(base::MessageLoopProxy* message_loop_proxy, |
| 75 net::HttpServer* server, | 57 net::HttpServer* server, |
| 76 int connection_id); | 58 int connection_id); |
| 77 ~DevToolsBrowserTarget(); | 59 ~DevToolsBrowserTarget(); |
| 78 | 60 |
| 79 int connection_id() const { return connection_id_; } | 61 int connection_id() const { return connection_id_; } |
| 80 | 62 |
| 81 // Takes ownership of |handler|. | 63 // Takes ownership of |handler|. |
| 82 void RegisterDomainHandler(DomainHandler* handler); | 64 void RegisterDomainHandler(DomainHandler* handler); |
| 83 | 65 |
| 84 std::string HandleMessage(const std::string& data); | 66 std::string HandleMessage(const std::string& data); |
| 85 | 67 |
| 68 DevToolsProtocol::Notifier GetNotifier(); |
| 69 |
| 86 private: | 70 private: |
| 87 // Sends notification to the client. Passes ownership of |params|. | 71 |
| 88 void SendNotification(const std::string& method, | 72 void OnNotification(const std::string& message); |
| 89 base::DictionaryValue* params); | |
| 90 | 73 |
| 91 base::MessageLoopProxy* const message_loop_proxy_; | 74 base::MessageLoopProxy* const message_loop_proxy_; |
| 92 net::HttpServer* const http_server_; | 75 net::HttpServer* const http_server_; |
| 93 const int connection_id_; | 76 const int connection_id_; |
| 94 | 77 |
| 95 typedef std::map<std::string, DomainHandler*> DomainHandlerMap; | 78 typedef std::map<std::string, DomainHandler*> DomainHandlerMap; |
| 96 DomainHandlerMap handlers_; | 79 DomainHandlerMap handlers_; |
| 80 STLValueDeleter<DomainHandlerMap> handlers_deleter_; |
| 97 base::WeakPtrFactory<DevToolsBrowserTarget> weak_factory_; | 81 base::WeakPtrFactory<DevToolsBrowserTarget> weak_factory_; |
| 98 | 82 |
| 99 DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget); | 83 DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget); |
| 100 }; | 84 }; |
| 101 | 85 |
| 102 } // namespace content | 86 } // namespace content |
| 103 | 87 |
| 104 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ | 88 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |
| OLD | NEW |