| 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/chromeos/diagnostics/diagnostics_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "chromeos/dbus/debug_daemon_client.h" | 13 #include "chromeos/dbus/debug_daemon_client.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
| 17 #include "content/public/browser/web_ui_message_handler.h" | 17 #include "content/public/browser/web_ui_message_handler.h" |
| 18 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
| 19 #include "grit/generated_resources.h" |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // JS API callback names. | 25 // JS API callback names. |
| 25 const char kJsApiUpdateConnStatus[] = "updateConnectivityStatus"; | 26 const char kJsApiSetNetifStatus[] = "diag.DiagPage.setNetifStatus"; |
| 26 | 27 |
| 27 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| 28 // DiagnosticsHandler | 29 // DiagnosticsHandler |
| 29 | 30 |
| 30 // Class to handle messages from chrome://diagnostics. | 31 // Class to handle messages from chrome://diagnostics. |
| 31 class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { | 32 class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { |
| 32 public: | 33 public: |
| 33 DiagnosticsWebUIHandler() | 34 DiagnosticsWebUIHandler() |
| 34 : weak_ptr_factory_(this) { | 35 : weak_ptr_factory_(this) { |
| 35 } | 36 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 71 } |
| 71 | 72 |
| 72 void DiagnosticsWebUIHandler::OnGetNetworkInterfaces( | 73 void DiagnosticsWebUIHandler::OnGetNetworkInterfaces( |
| 73 bool succeeded, const std::string& status) { | 74 bool succeeded, const std::string& status) { |
| 74 if (!succeeded) | 75 if (!succeeded) |
| 75 return; | 76 return; |
| 76 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status)); | 77 scoped_ptr<Value> parsed_value(base::JSONReader::Read(status)); |
| 77 if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) { | 78 if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) { |
| 78 base::DictionaryValue* result = | 79 base::DictionaryValue* result = |
| 79 static_cast<DictionaryValue*>(parsed_value.get()); | 80 static_cast<DictionaryValue*>(parsed_value.get()); |
| 80 web_ui()->CallJavascriptFunction(kJsApiUpdateConnStatus, *result); | 81 web_ui()->CallJavascriptFunction(kJsApiSetNetifStatus, *result); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 } // namespace | 85 } // namespace |
| 85 | 86 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
| 87 // DiagnosticsUI | 88 // DiagnosticsUI |
| 88 | 89 |
| 89 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) | 90 DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) |
| 90 : WebUIController(web_ui) { | 91 : WebUIController(web_ui) { |
| 91 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler()); | 92 web_ui->AddMessageHandler(new DiagnosticsWebUIHandler()); |
| 92 | 93 |
| 93 ChromeWebUIDataSource* source = | 94 ChromeWebUIDataSource* source = |
| 94 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); | 95 new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); |
| 96 source->set_json_path("strings.js"); |
| 95 source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS); | 97 source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS); |
| 96 source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS); | 98 source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS); |
| 99 source->add_resource_path("fail.png", IDR_DIAGNOSTICS_IMAGES_FAIL); |
| 100 source->add_resource_path("tick.png", IDR_DIAGNOSTICS_IMAGES_TICK); |
| 101 source->add_resource_path("warning.png", IDR_DIAGNOSTICS_IMAGES_WARNING); |
| 102 source->AddLocalizedString("diagnostics", IDS_DIAGNOSTICS_DIAGNOSTICS_TITLE); |
| 103 source->AddLocalizedString("connectivity", |
| 104 IDS_DIAGNOSTICS_CONNECTIVITY_TITLE); |
| 105 source->AddLocalizedString("loading", IDS_DIAGNOSTICS_LOADING); |
| 106 source->AddLocalizedString("wlan0", IDS_DIAGNOSTICS_ADAPTER_WLAN0); |
| 107 source->AddLocalizedString("eth0", IDS_DIAGNOSTICS_ADAPTER_ETH0); |
| 108 source->AddLocalizedString("eth1", IDS_DIAGNOSTICS_ADAPTER_ETH1); |
| 109 source->AddLocalizedString("wwan0", IDS_DIAGNOSTICS_ADAPTER_WWAN0); |
| 110 source->AddLocalizedString("testing-hardware", |
| 111 IDS_DIAGNOSTICS_TESTING_HARDWARE); |
| 112 source->AddLocalizedString("testing-connection-to-router", |
| 113 IDS_DIAGNOSTICS_TESTING_CONNECTION_TO_ROUTER); |
| 114 source->AddLocalizedString("testing-connection-to-internet", |
| 115 IDS_DIAGNOSTICS_TESTING_CONNECTION_TO_INTERNET); |
| 116 source->AddLocalizedString("adapter-disabled", |
| 117 IDS_DIAGNOSTICS_ADAPTER_DISABLED); |
| 118 source->AddLocalizedString("adapter-no-ip", |
| 119 IDS_DIAGNOSTICS_ADAPTER_NO_IP); |
| 120 source->AddLocalizedString("enable-adapter", |
| 121 IDS_DIAGNOSTICS_ENABLE_ADAPTER); |
| 122 source->AddLocalizedString("fix-connection-to-router", |
| 123 IDS_DIAGNOSTICS_FIX_CONNECTION_TO_ROUTER); |
| 97 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); | 124 source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); |
| 98 | 125 |
| 99 Profile* profile = Profile::FromWebUI(web_ui); | 126 Profile* profile = Profile::FromWebUI(web_ui); |
| 100 ChromeURLDataManager::AddDataSource(profile, source); | 127 ChromeURLDataManager::AddDataSource(profile, source); |
| 101 } | 128 } |
| 102 | 129 |
| 103 } // namespace chromeos | 130 } // namespace chromeos |
| OLD | NEW |