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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_WEBUI_INSPECT_UI_H_ 6 #define CHROME_BROWSER_UI_WEBUI_INSPECT_UI_H_ 7 8 #include <map> 9 10 #include "base/memory/ref_counted.h" 11 #include "base/memory/weak_ptr.h" 12 #include "base/prefs/pref_change_registrar.h" 13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/web_ui_controller.h" 16 #include "content/public/browser/web_ui_data_source.h" 17 18 namespace base { 19 class Value; 20 class ListValue; 21 } 22 23 class Browser; 24 class DevToolsRemoteTargetsUIHandler; 25 class DevToolsTargetsUIHandler; 26 27 class InspectUI : public content::WebUIController, 28 public content::NotificationObserver { 29 public: 30 explicit InspectUI(content::WebUI* web_ui); 31 virtual ~InspectUI(); 32 33 void InitUI(); 34 void Inspect(const std::string& source_id, const std::string& target_id); 35 void Activate(const std::string& source_id, const std::string& target_id); 36 void Close(const std::string& source_id, const std::string& target_id); 37 void Reload(const std::string& source_id, const std::string& target_id); 38 void Open(const std::string& source_id, 39 const std::string& browser_id, 40 const std::string& url); 41 42 static void InspectDevices(Browser* browser); 43 44 private: 45 // content::NotificationObserver overrides. 46 virtual void Observe(int type, 47 const content::NotificationSource& source, 48 const content::NotificationDetails& details) OVERRIDE; 49 50 void StartListeningNotifications(); 51 void StopListeningNotifications(); 52 53 content::WebUIDataSource* CreateInspectUIHTMLSource(); 54 55 void UpdateDiscoverUsbDevicesEnabled(); 56 void UpdatePortForwardingEnabled(); 57 void UpdatePortForwardingConfig(); 58 59 void SetPortForwardingDefaults(); 60 61 const base::Value* GetPrefValue(const char* name); 62 63 void AddTargetUIHandler( 64 scoped_ptr<DevToolsTargetsUIHandler> handler); 65 void AddRemoteTargetUIHandler( 66 scoped_ptr<DevToolsRemoteTargetsUIHandler> handler); 67 68 DevToolsTargetsUIHandler* FindTargetHandler(const std::string& source_id); 69 DevToolsRemoteTargetsUIHandler* FindRemoteTargetHandler( 70 const std::string& source_id); 71 72 void PopulateTargets(const std::string& source_id, 73 scoped_ptr<base::ListValue> targets); 74 75 // A scoped container for notification registries. 76 content::NotificationRegistrar notification_registrar_; 77 78 // A scoped container for preference change registries. 79 PrefChangeRegistrar pref_change_registrar_; 80 81 typedef std::map<std::string, DevToolsTargetsUIHandler*> TargetHandlerMap; 82 TargetHandlerMap target_handlers_; 83 84 typedef std::map<std::string, DevToolsRemoteTargetsUIHandler*> 85 RemoteTargetHandlerMap; 86 RemoteTargetHandlerMap remote_target_handlers_; 87 88 DISALLOW_COPY_AND_ASSIGN(InspectUI); 89 }; 90 91 #endif // CHROME_BROWSER_UI_WEBUI_INSPECT_UI_H_ 92