Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: content/browser/devtools/devtools_browser_target.h

Issue 12218134: Introduce intercepting and handling devtools messages in the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
13 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/stl_util.h"
16 #include "content/browser/devtools/devtools_protocol.h" 16 #include "content/browser/devtools/devtools_protocol.h"
17 17
18 namespace base { 18 namespace base {
19
20 class DictionaryValue; 19 class DictionaryValue;
21 class MessageLoopProxy; 20 class MessageLoopProxy;
22 class Value; 21 class Value;
23
24 } // namespace base 22 } // namespace base
25 23
26 namespace net { 24 namespace net {
27 class HttpServer; 25 class HttpServer;
28 } // namespace net 26 } // namespace net
29 27
30 namespace content { 28 namespace content {
31 29
32 // This class handles the "Browser" target for remote debugging. 30 // This class handles the "Browser" target for remote debugging.
33 class DevToolsBrowserTarget { 31 class DevToolsBrowserTarget {
34 public: 32 public:
35 typedef base::Callback<void(const std::string& method,
36 base::DictionaryValue* params)> Notifier;
37
38 class DomainHandler {
39 public:
40 typedef base::Callback<scoped_ptr<DevToolsProtocol::Response>(
41 DevToolsProtocol::Command* command)> CommandHandler;
42 virtual ~DomainHandler();
43
44 // Returns the domain name for this handler.
45 std::string domain() { return domain_; }
46
47 void RegisterCommandHandler(const std::string& command,
48 CommandHandler handler);
49
50 protected:
51 explicit DomainHandler(const std::string& domain);
52
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
62 private:
63 friend class DevToolsBrowserTarget;
64 void set_notifier(Notifier notifier) { notifier_ = notifier; }
65
66 std::string domain_;
67 Notifier notifier_;
68 typedef std::map<std::string, CommandHandler> CommandHandlers;
69 CommandHandlers command_handlers_;
70
71 DISALLOW_COPY_AND_ASSIGN(DomainHandler);
72 };
73
74 DevToolsBrowserTarget(base::MessageLoopProxy* message_loop_proxy, 33 DevToolsBrowserTarget(base::MessageLoopProxy* message_loop_proxy,
75 net::HttpServer* server, 34 net::HttpServer* server,
76 int connection_id); 35 int connection_id);
77 ~DevToolsBrowserTarget(); 36 ~DevToolsBrowserTarget();
78 37
79 int connection_id() const { return connection_id_; } 38 int connection_id() const { return connection_id_; }
80 39
81 // Takes ownership of |handler|. 40 // Takes ownership of |handler|.
82 void RegisterDomainHandler(DomainHandler* handler); 41 void RegisterDomainHandler(const std::string& domain,
42 DevToolsProtocol::Handler* handler);
83 43
84 std::string HandleMessage(const std::string& data); 44 std::string HandleMessage(const std::string& data);
85 45
86 private: 46 private:
87 // Sends notification to the client. Passes ownership of |params|. 47 void OnNotification(const std::string& message);
88 void SendNotification(const std::string& method,
89 base::DictionaryValue* params);
90 48
91 base::MessageLoopProxy* const message_loop_proxy_; 49 base::MessageLoopProxy* const message_loop_proxy_;
92 net::HttpServer* const http_server_; 50 net::HttpServer* const http_server_;
93 const int connection_id_; 51 const int connection_id_;
94 52
95 typedef std::map<std::string, DomainHandler*> DomainHandlerMap; 53 typedef std::map<std::string, DevToolsProtocol::Handler*> DomainHandlerMap;
96 DomainHandlerMap handlers_; 54 DomainHandlerMap handlers_;
55 STLValueDeleter<DomainHandlerMap> handlers_deleter_;
97 base::WeakPtrFactory<DevToolsBrowserTarget> weak_factory_; 56 base::WeakPtrFactory<DevToolsBrowserTarget> weak_factory_;
98 57
99 DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget); 58 DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget);
100 }; 59 };
101 60
102 } // namespace content 61 } // namespace content
103 62
104 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ 63 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/debugger/background.js ('k') | content/browser/devtools/devtools_browser_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698