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