| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_DEBUGGER_DEVTOOLS_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
| 6 #define CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 6 #define CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/debugger/devtools_client_host.h" |
| 12 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 13 | 14 |
| 14 namespace IPC { | 15 namespace IPC { |
| 15 class Message; | 16 class Message; |
| 16 } | 17 } |
| 17 | 18 |
| 18 class DevToolsInstanceDescriptor; | 19 class DevToolsClientHost; |
| 19 class DevToolsInstanceDescriptorImpl; | |
| 20 class DevToolsWindow; | |
| 21 class DevToolsWindowFactory; | |
| 22 class NavigationController; | 20 class NavigationController; |
| 23 class NotificationRegistrar; | 21 class NotificationRegistrar; |
| 24 class RenderViewHost; | 22 class RenderViewHost; |
| 25 class WebContents; | 23 class WebContents; |
| 26 | 24 |
| 27 // This class is a singleton that manages DevToolsWindow instances and routes | 25 // This class is a singleton that manages DevToolsClientHost instances and |
| 28 // messages between developer tools clients and agents. | 26 // routes messages between developer tools clients and agents. |
| 29 class DevToolsManager : public NotificationObserver { | 27 class DevToolsManager : public NotificationObserver, |
| 28 public DevToolsClientHost::CloseListener { |
| 30 public: | 29 public: |
| 31 // If the factory is NULL, this will create DevToolsWindow objects using | 30 DevToolsManager(); |
| 32 // DevToolsWindow::Create static method. | |
| 33 DevToolsManager(DevToolsWindowFactory* factory); | |
| 34 virtual ~DevToolsManager(); | 31 virtual ~DevToolsManager(); |
| 35 | 32 |
| 36 // Opend developer tools window for |web_contents|. If there is already | 33 // Returns DevToolsClientHost registered for |web_contents| or NULL if |
| 37 // one it will be revealed otherwise a new instance will be created. The | 34 // there is no alive DevToolsClientHost registered for |web_contents|. |
| 38 // devtools window is actually opened for the tab owning |web_contents|. If | 35 DevToolsClientHost* GetDevToolsClientHostFor(const WebContents& web_contents); |
| 39 // navigation occurs in it causing change of contents in the tab the devtools | |
| 40 // window will attach to the new contents. When the tab is closed the manager | |
| 41 // will close related devtools window. | |
| 42 void ShowDevToolsForWebContents(WebContents* web_contents); | |
| 43 | 36 |
| 44 void ForwardToDevToolsAgent(RenderViewHost* from, | 37 // Registers new DevToolsClientHost for |web_contents|. There must be no |
| 38 // other DevToolsClientHosts registered for the WebContents at the moment. |
| 39 void RegisterDevToolsClientHostFor(const WebContents& web_contents, |
| 40 DevToolsClientHost* client_host); |
| 41 |
| 42 void ForwardToDevToolsAgent(const RenderViewHost& client_rvh, |
| 45 const IPC::Message& message); | 43 const IPC::Message& message); |
| 46 void ForwardToDevToolsClient(RenderViewHost* from, | 44 void ForwardToDevToolsAgent(const DevToolsClientHost& from, |
| 45 const IPC::Message& message); |
| 46 void ForwardToDevToolsClient(const RenderViewHost& from, |
| 47 const IPC::Message& message); | 47 const IPC::Message& message); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // Creates a DevToolsWindow using devtools_window_factory_ or by calling | |
| 51 // DevToolsWindow::Create, if the factory is NULL. All DevToolsWindows should | |
| 52 // be created by means of this method. | |
| 53 DevToolsWindow* CreateDevToolsWindow(DevToolsInstanceDescriptor* descriptor); | |
| 54 | |
| 55 // NotificationObserver override. | 50 // NotificationObserver override. |
| 56 virtual void Observe(NotificationType type, | 51 virtual void Observe(NotificationType type, |
| 57 const NotificationSource& source, | 52 const NotificationSource& source, |
| 58 const NotificationDetails& details); | 53 const NotificationDetails& details); |
| 59 | 54 |
| 60 friend class DevToolsInstanceDescriptorImpl; | 55 // DevToolsClientHost::CloseListener override. |
| 56 // This method will remove all references from the manager to the |
| 57 // DevToolsClientHost and unregister all listeners related to the |
| 58 // DevToolsClientHost. |
| 59 virtual void ClientHostClosing(DevToolsClientHost* host); |
| 61 | 60 |
| 62 // This method is called by DevToolsInstanceDescriptorImpl when it's about | 61 // Returns NavigationController for the tab that is inspected by devtools |
| 63 // to be destroyed. It will remove all references from the manager to the | 62 // client hosted by DevToolsClientHost. |
| 64 // descriptor and unregister all listeners related to the descriptor. | 63 NavigationController* GetDevToolsAgentNavigationController( |
| 65 void RemoveDescriptor(DevToolsInstanceDescriptorImpl* descriptor); | 64 const DevToolsClientHost& client_host); |
| 66 | 65 |
| 67 void StartListening(NavigationController* navigation_controller); | 66 void StartListening(NavigationController* navigation_controller); |
| 68 void StopListening(NavigationController* navigation_controller); | 67 void StopListening(NavigationController* navigation_controller); |
| 69 | 68 |
| 70 // This object is not NULL iff there is at least one open DevToolsWindow. | 69 // This object is not NULL iff there is at least one registered |
| 70 // DevToolsClientHost. |
| 71 scoped_ptr<NotificationRegistrar> web_contents_listeners_; | 71 scoped_ptr<NotificationRegistrar> web_contents_listeners_; |
| 72 | 72 |
| 73 // This maps is for tracking devtools instances opened for browser tabs. It | 73 // These two maps are for tracking dependencies between inspected tabs and |
| 74 // allows us to have at most one devtools window per tab. | 74 // their DevToolsClientHosts. They are usful for routing devtools messages |
| 75 // We use NavigationController* as key because it survives crosee-site | 75 // and allow us to have at most one devtools client host per tab. We use |
| 76 // navigation in cases when tab contents may change. | 76 // NavigationController* as key because it survives crosee-site navigation in |
| 77 // cases when tab contents may change. |
| 77 // | 78 // |
| 78 // This map doesn't own its values but DevToolsInstanceDescriptorImpl is | 79 // DevToolsManager start listening to DevToolsClientHosts when they are put |
| 79 // expected to call RemoveDescriptor before dying to remove itself from the | 80 // into these maps and removes them when they are closing. |
| 80 // map. | 81 typedef std::map<const NavigationController*, |
| 81 typedef std::map<NavigationController*, | 82 DevToolsClientHost*> ClientHostMap; |
| 82 DevToolsInstanceDescriptorImpl*> DescriptorMap; | 83 ClientHostMap navcontroller_to_client_host_; |
| 83 DescriptorMap navcontroller_to_descriptor_; | 84 |
| 84 DevToolsWindowFactory* devtools_window_factory_; | 85 typedef std::map<const DevToolsClientHost*, |
| 86 NavigationController*> NavControllerMap; |
| 87 NavControllerMap client_host_to_navcontroller_; |
| 85 | 88 |
| 86 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); | 89 DISALLOW_COPY_AND_ASSIGN(DevToolsManager); |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 | |
| 90 // Incapsulates information about devtools window instance necessary for | |
| 91 // routing devtools messages and managing the window. It should be initialized | |
| 92 // by DevToolsWindow concrete implementation. | |
| 93 class DevToolsInstanceDescriptor { | |
| 94 public: | |
| 95 DevToolsInstanceDescriptor() {} | |
| 96 | |
| 97 virtual void SetDevToolsHost(RenderViewHost* render_view_host) = 0; | |
| 98 virtual void SetDevToolsWindow(DevToolsWindow* window) = 0; | |
| 99 | |
| 100 // This method is called when DevToolsWindow is closing and the descriptor | |
| 101 // becomes invalid. It will clean up DevToolsManager and delete this instance. | |
| 102 virtual void Destroy() = 0; | |
| 103 | |
| 104 protected: | |
| 105 // This method should be called from Destroy only. | |
| 106 virtual ~DevToolsInstanceDescriptor() {} | |
| 107 | |
| 108 private: | |
| 109 DISALLOW_COPY_AND_ASSIGN(DevToolsInstanceDescriptor); | |
| 110 }; | |
| 111 | |
| 112 #endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ | 92 #endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_MANAGER_H_ |
| OLD | NEW |