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 18namespace base { 19class Value; 20class ListValue; 21} 22 23class Browser; 24class DevToolsTargetsUIHandler; 25class DevToolsTargetImpl; 26class PortForwardingStatusSerializer; 27 28class InspectUI : public content::WebUIController, 29 public content::NotificationObserver { 30 public: 31 explicit InspectUI(content::WebUI* web_ui); 32 virtual ~InspectUI(); 33 34 void InitUI(); 35 void Inspect(const std::string& source_id, const std::string& target_id); 36 void Activate(const std::string& source_id, const std::string& target_id); 37 void Close(const std::string& source_id, const std::string& target_id); 38 void Reload(const std::string& source_id, const std::string& target_id); 39 void Open(const std::string& source_id, 40 const std::string& browser_id, 41 const std::string& url); 42 void InspectBrowserWithCustomFrontend( 43 const std::string& source_id, 44 const std::string& browser_id, 45 const GURL& frontend_url); 46 47 static void InspectDevices(Browser* browser); 48 49 // WebUIController implementation. 50 virtual bool OverrideHandleWebUIMessage(const GURL& source_url, 51 const std::string& message, 52 const base::ListValue& args) OVERRIDE; 53 54 // We forward these to |serviceworker_webui_|. 55 virtual void RenderViewCreated( 56 content::RenderViewHost* render_view_host) OVERRIDE; 57 virtual void RenderViewReused( 58 content::RenderViewHost* render_view_host) OVERRIDE; 59 60 private: 61 // content::NotificationObserver overrides. 62 virtual void Observe(int type, 63 const content::NotificationSource& source, 64 const content::NotificationDetails& details) OVERRIDE; 65 66 void StartListeningNotifications(); 67 void StopListeningNotifications(); 68 69 content::WebUIDataSource* CreateInspectUIHTMLSource(); 70 71 void UpdateDiscoverUsbDevicesEnabled(); 72 void UpdatePortForwardingEnabled(); 73 void UpdatePortForwardingConfig(); 74 75 void SetPortForwardingDefaults(); 76 77 const base::Value* GetPrefValue(const char* name); 78 79 void AddTargetUIHandler( 80 scoped_ptr<DevToolsTargetsUIHandler> handler); 81 82 DevToolsTargetsUIHandler* FindTargetHandler( 83 const std::string& source_id); 84 DevToolsTargetImpl* FindTarget(const std::string& source_id, 85 const std::string& target_id); 86 87 void PopulateTargets(const std::string& source_id, 88 scoped_ptr<base::ListValue> targets); 89 90 void PopulatePortStatus(const base::Value& status); 91 92 void ShowIncognitoWarning(); 93 94 // A scoped container for notification registries. 95 content::NotificationRegistrar notification_registrar_; 96 97 // A scoped container for preference change registries. 98 PrefChangeRegistrar pref_change_registrar_; 99 100 typedef std::map<std::string, DevToolsTargetsUIHandler*> TargetHandlerMap; 101 TargetHandlerMap target_handlers_; 102 103 scoped_ptr<PortForwardingStatusSerializer> port_status_serializer_; 104 105 scoped_ptr<content::WebUI> serviceworker_webui_; 106 107 DISALLOW_COPY_AND_ASSIGN(InspectUI); 108}; 109 110#endif // CHROME_BROWSER_UI_WEBUI_INSPECT_UI_H_ 111