| OLD | NEW |
| 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 #include "chrome/browser/ui/webui/inspect_ui.h" | 5 #include "chrome/browser/ui/webui/inspect_ui.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/devtools/devtools_target_impl.h" | 9 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 10 #include "chrome/browser/devtools/devtools_targets_ui.h" | 10 #include "chrome/browser/devtools/devtools_targets_ui.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kInitUICommand[] = "init-ui"; | 36 const char kInitUICommand[] = "init-ui"; |
| 37 const char kInspectCommand[] = "inspect"; | 37 const char kInspectCommand[] = "inspect"; |
| 38 const char kActivateCommand[] = "activate"; | 38 const char kActivateCommand[] = "activate"; |
| 39 const char kCloseCommand[] = "close"; | 39 const char kCloseCommand[] = "close"; |
| 40 const char kReloadCommand[] = "reload"; | 40 const char kReloadCommand[] = "reload"; |
| 41 const char kOpenCommand[] = "open"; | 41 const char kOpenCommand[] = "open"; |
| 42 const char kInspectBrowser[] = "inspect-browser"; | 42 const char kInspectBrowser[] = "inspect-browser"; |
| 43 const char kTraceBrowser[] = "trace-browser"; |
| 43 const char kLocalHost[] = "localhost"; | 44 const char kLocalHost[] = "localhost"; |
| 44 | 45 |
| 45 const char kDiscoverUsbDevicesEnabledCommand[] = | 46 const char kDiscoverUsbDevicesEnabledCommand[] = |
| 46 "set-discover-usb-devices-enabled"; | 47 "set-discover-usb-devices-enabled"; |
| 47 const char kPortForwardingEnabledCommand[] = | 48 const char kPortForwardingEnabledCommand[] = |
| 48 "set-port-forwarding-enabled"; | 49 "set-port-forwarding-enabled"; |
| 49 const char kPortForwardingConfigCommand[] = "set-port-forwarding-config"; | 50 const char kPortForwardingConfigCommand[] = "set-port-forwarding-config"; |
| 50 | 51 |
| 51 const char kPortForwardingDefaultPort[] = "8080"; | 52 const char kPortForwardingDefaultPort[] = "8080"; |
| 52 const char kPortForwardingDefaultLocation[] = "localhost:8080"; | 53 const char kPortForwardingDefaultLocation[] = "localhost:8080"; |
| 53 | 54 |
| 54 class InspectMessageHandler : public WebUIMessageHandler { | 55 class InspectMessageHandler : public WebUIMessageHandler { |
| 55 public: | 56 public: |
| 56 explicit InspectMessageHandler(InspectUI* inspect_ui) | 57 explicit InspectMessageHandler(InspectUI* inspect_ui) |
| 57 : inspect_ui_(inspect_ui) {} | 58 : inspect_ui_(inspect_ui) {} |
| 58 virtual ~InspectMessageHandler() {} | 59 virtual ~InspectMessageHandler() {} |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 // WebUIMessageHandler implementation. | 62 // WebUIMessageHandler implementation. |
| 62 virtual void RegisterMessages() OVERRIDE; | 63 virtual void RegisterMessages() OVERRIDE; |
| 63 | 64 |
| 64 void HandleInitUICommand(const base::ListValue* args); | 65 void HandleInitUICommand(const base::ListValue* args); |
| 65 void HandleInspectCommand(const base::ListValue* args); | 66 void HandleInspectCommand(const base::ListValue* args); |
| 66 void HandleActivateCommand(const base::ListValue* args); | 67 void HandleActivateCommand(const base::ListValue* args); |
| 67 void HandleCloseCommand(const base::ListValue* args); | 68 void HandleCloseCommand(const base::ListValue* args); |
| 68 void HandleReloadCommand(const base::ListValue* args); | 69 void HandleReloadCommand(const base::ListValue* args); |
| 69 void HandleOpenCommand(const base::ListValue* args); | 70 void HandleOpenCommand(const base::ListValue* args); |
| 70 void HandleInspectBrowserCommand(const base::ListValue* args); | 71 void HandleInspectBrowserCommand(const base::ListValue* args); |
| 72 void HandleTraceBrowserCommand(const base::ListValue* args); |
| 71 void HandleBooleanPrefChanged(const char* pref_name, | 73 void HandleBooleanPrefChanged(const char* pref_name, |
| 72 const base::ListValue* args); | 74 const base::ListValue* args); |
| 73 void HandlePortForwardingConfigCommand(const base::ListValue* args); | 75 void HandlePortForwardingConfigCommand(const base::ListValue* args); |
| 74 | 76 |
| 75 InspectUI* inspect_ui_; | 77 InspectUI* inspect_ui_; |
| 76 | 78 |
| 77 DISALLOW_COPY_AND_ASSIGN(InspectMessageHandler); | 79 DISALLOW_COPY_AND_ASSIGN(InspectMessageHandler); |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 void InspectMessageHandler::RegisterMessages() { | 82 void InspectMessageHandler::RegisterMessages() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 103 base::Unretained(this))); | 105 base::Unretained(this))); |
| 104 web_ui()->RegisterMessageCallback(kReloadCommand, | 106 web_ui()->RegisterMessageCallback(kReloadCommand, |
| 105 base::Bind(&InspectMessageHandler::HandleReloadCommand, | 107 base::Bind(&InspectMessageHandler::HandleReloadCommand, |
| 106 base::Unretained(this))); | 108 base::Unretained(this))); |
| 107 web_ui()->RegisterMessageCallback(kOpenCommand, | 109 web_ui()->RegisterMessageCallback(kOpenCommand, |
| 108 base::Bind(&InspectMessageHandler::HandleOpenCommand, | 110 base::Bind(&InspectMessageHandler::HandleOpenCommand, |
| 109 base::Unretained(this))); | 111 base::Unretained(this))); |
| 110 web_ui()->RegisterMessageCallback(kInspectBrowser, | 112 web_ui()->RegisterMessageCallback(kInspectBrowser, |
| 111 base::Bind(&InspectMessageHandler::HandleInspectBrowserCommand, | 113 base::Bind(&InspectMessageHandler::HandleInspectBrowserCommand, |
| 112 base::Unretained(this))); | 114 base::Unretained(this))); |
| 115 web_ui()->RegisterMessageCallback(kTraceBrowser, |
| 116 base::Bind(&InspectMessageHandler::HandleTraceBrowserCommand, |
| 117 base::Unretained(this))); |
| 113 } | 118 } |
| 114 | 119 |
| 115 void InspectMessageHandler::HandleInitUICommand(const base::ListValue*) { | 120 void InspectMessageHandler::HandleInitUICommand(const base::ListValue*) { |
| 116 inspect_ui_->InitUI(); | 121 inspect_ui_->InitUI(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 static bool ParseStringArgs(const base::ListValue* args, | 124 static bool ParseStringArgs(const base::ListValue* args, |
| 120 std::string* arg0, | 125 std::string* arg0, |
| 121 std::string* arg1, | 126 std::string* arg1, |
| 122 std::string* arg2 = 0) { | 127 std::string* arg2 = 0) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 const base::ListValue* args) { | 171 const base::ListValue* args) { |
| 167 std::string source_id; | 172 std::string source_id; |
| 168 std::string browser_id; | 173 std::string browser_id; |
| 169 std::string front_end; | 174 std::string front_end; |
| 170 if (ParseStringArgs(args, &source_id, &browser_id, &front_end)) { | 175 if (ParseStringArgs(args, &source_id, &browser_id, &front_end)) { |
| 171 inspect_ui_->InspectBrowserWithCustomFrontend( | 176 inspect_ui_->InspectBrowserWithCustomFrontend( |
| 172 source_id, browser_id, GURL(front_end)); | 177 source_id, browser_id, GURL(front_end)); |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 | 180 |
| 181 void InspectMessageHandler::HandleTraceBrowserCommand( |
| 182 const base::ListValue* args) { |
| 183 std::string source_id; |
| 184 std::string browser_id; |
| 185 if (ParseStringArgs(args, &source_id, &browser_id)) { |
| 186 inspect_ui_->InspectBrowserWithCustomFrontend( |
| 187 source_id, browser_id, GURL(std::string(content::kChromeUIScheme) |
| 188 + "://" + content::kChromeUITracingHost)); |
| 189 } |
| 190 } |
| 191 |
| 176 void InspectMessageHandler::HandleBooleanPrefChanged( | 192 void InspectMessageHandler::HandleBooleanPrefChanged( |
| 177 const char* pref_name, | 193 const char* pref_name, |
| 178 const base::ListValue* args) { | 194 const base::ListValue* args) { |
| 179 Profile* profile = Profile::FromWebUI(web_ui()); | 195 Profile* profile = Profile::FromWebUI(web_ui()); |
| 180 if (!profile) | 196 if (!profile) |
| 181 return; | 197 return; |
| 182 | 198 |
| 183 bool enabled; | 199 bool enabled; |
| 184 if (args->GetSize() == 1 && args->GetBoolean(0, &enabled)) | 200 if (args->GetSize() == 1 && args->GetBoolean(0, &enabled)) |
| 185 profile->GetPrefs()->SetBoolean(pref_name, enabled); | 201 profile->GetPrefs()->SetBoolean(pref_name, enabled); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 scoped_ptr<base::Value> source_value(base::Value::CreateStringValue(source)); | 492 scoped_ptr<base::Value> source_value(base::Value::CreateStringValue(source)); |
| 477 web_ui()->CallJavascriptFunction( | 493 web_ui()->CallJavascriptFunction( |
| 478 "populateTargets", | 494 "populateTargets", |
| 479 *source_value.get(), | 495 *source_value.get(), |
| 480 *targets.get()); | 496 *targets.get()); |
| 481 } | 497 } |
| 482 | 498 |
| 483 void InspectUI::PopulatePortStatus(const base::Value& status) { | 499 void InspectUI::PopulatePortStatus(const base::Value& status) { |
| 484 web_ui()->CallJavascriptFunction("populatePortStatus", status); | 500 web_ui()->CallJavascriptFunction("populatePortStatus", status); |
| 485 } | 501 } |
| OLD | NEW |