OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/network_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/network_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/options/network_config_view.h" |
12 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
13 #include "chrome/browser/ui/webui/settings/md_settings_localized_strings_provide
r.h" | 14 #include "chrome/browser/ui/webui/settings/md_settings_localized_strings_provide
r.h" |
14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
16 #include "chromeos/network/device_state.h" | 17 #include "chromeos/network/device_state.h" |
17 #include "chromeos/network/network_configuration_handler.h" | 18 #include "chromeos/network/network_configuration_handler.h" |
18 #include "chromeos/network/network_state.h" | 19 #include "chromeos/network/network_state.h" |
19 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
20 #include "components/device_event_log/device_event_log.h" | 21 #include "components/device_event_log/device_event_log.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 public: | 72 public: |
72 NetworkConfigMessageHandler() : weak_ptr_factory_(this) {} | 73 NetworkConfigMessageHandler() : weak_ptr_factory_(this) {} |
73 ~NetworkConfigMessageHandler() override {} | 74 ~NetworkConfigMessageHandler() override {} |
74 | 75 |
75 // WebUIMessageHandler implementation. | 76 // WebUIMessageHandler implementation. |
76 void RegisterMessages() override { | 77 void RegisterMessages() override { |
77 web_ui()->RegisterMessageCallback( | 78 web_ui()->RegisterMessageCallback( |
78 "getShillProperties", | 79 "getShillProperties", |
79 base::Bind(&NetworkConfigMessageHandler::GetShillProperties, | 80 base::Bind(&NetworkConfigMessageHandler::GetShillProperties, |
80 base::Unretained(this))); | 81 base::Unretained(this))); |
| 82 web_ui()->RegisterMessageCallback( |
| 83 "addNetwork", |
| 84 base::Bind(&NetworkConfigMessageHandler::AddNetwork, |
| 85 base::Unretained(this))); |
81 } | 86 } |
82 | 87 |
83 private: | 88 private: |
84 void GetShillProperties(const base::ListValue* arg_list) { | 89 void GetShillProperties(const base::ListValue* arg_list) { |
85 std::string guid; | 90 std::string guid; |
86 if (!arg_list->GetString(0, &guid)) { | 91 if (!arg_list->GetString(0, &guid)) { |
87 NOTREACHED(); | 92 NOTREACHED(); |
88 ErrorCallback(guid, "Missing GUID in arg list", nullptr); | 93 ErrorCallback(guid, "Missing GUID in arg list", nullptr); |
89 return; | 94 return; |
90 } | 95 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 NET_LOG(ERROR) << "Shill Error: " << error_name << " guid=" << guid; | 130 NET_LOG(ERROR) << "Shill Error: " << error_name << " guid=" << guid; |
126 base::ListValue return_arg_list; | 131 base::ListValue return_arg_list; |
127 std::unique_ptr<base::DictionaryValue> dictionary; | 132 std::unique_ptr<base::DictionaryValue> dictionary; |
128 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid); | 133 dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid); |
129 dictionary->SetStringWithoutPathExpansion("ShillError", error_name); | 134 dictionary->SetStringWithoutPathExpansion("ShillError", error_name); |
130 return_arg_list.Append(dictionary.release()); | 135 return_arg_list.Append(dictionary.release()); |
131 web_ui()->CallJavascriptFunctionUnsafe("NetworkUI.getShillPropertiesResult", | 136 web_ui()->CallJavascriptFunctionUnsafe("NetworkUI.getShillPropertiesResult", |
132 return_arg_list); | 137 return_arg_list); |
133 } | 138 } |
134 | 139 |
| 140 void AddNetwork(const base::ListValue* args) { |
| 141 std::string onc_type; |
| 142 args->GetString(0, &onc_type); |
| 143 std::string shill_type = (onc_type == ::onc::network_type::kVPN) |
| 144 ? shill::kTypeVPN |
| 145 : shill::kTypeWifi; |
| 146 NetworkConfigView::ShowForType( |
| 147 shill_type, web_ui()->GetWebContents()->GetTopLevelNativeWindow()); |
| 148 } |
| 149 |
135 base::WeakPtrFactory<NetworkConfigMessageHandler> weak_ptr_factory_; | 150 base::WeakPtrFactory<NetworkConfigMessageHandler> weak_ptr_factory_; |
136 | 151 |
137 DISALLOW_COPY_AND_ASSIGN(NetworkConfigMessageHandler); | 152 DISALLOW_COPY_AND_ASSIGN(NetworkConfigMessageHandler); |
138 }; | 153 }; |
139 | 154 |
140 } // namespace | 155 } // namespace |
141 | 156 |
142 // static | 157 // static |
143 void NetworkUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { | 158 void NetworkUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) { |
144 localized_strings->SetString("titleText", | 159 localized_strings->SetString("titleText", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 html->SetDefaultResource(IDR_NETWORK_UI_HTML); | 217 html->SetDefaultResource(IDR_NETWORK_UI_HTML); |
203 | 218 |
204 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), | 219 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), |
205 html); | 220 html); |
206 } | 221 } |
207 | 222 |
208 NetworkUI::~NetworkUI() { | 223 NetworkUI::~NetworkUI() { |
209 } | 224 } |
210 | 225 |
211 } // namespace chromeos | 226 } // namespace chromeos |
OLD | NEW |