| 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/login/network_dropdown.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 9 #include <utility> |
| 8 | 10 |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 16 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 15 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_state_handler.h" |
| 16 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 17 #include "ui/base/models/menu_model.h" | 19 #include "ui/base/models/menu_model.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 82 |
| 81 base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) { | 83 base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) { |
| 82 base::ListValue* list = new base::ListValue(); | 84 base::ListValue* list = new base::ListValue(); |
| 83 for (int i = 0; i < model->GetItemCount(); ++i) { | 85 for (int i = 0; i < model->GetItemCount(); ++i) { |
| 84 ui::MenuModel::ItemType type = model->GetTypeAt(i); | 86 ui::MenuModel::ItemType type = model->GetTypeAt(i); |
| 85 int id; | 87 int id; |
| 86 if (type == ui::MenuModel::TYPE_SEPARATOR) | 88 if (type == ui::MenuModel::TYPE_SEPARATOR) |
| 87 id = -2; | 89 id = -2; |
| 88 else | 90 else |
| 89 id = model->GetCommandIdAt(i); | 91 id = model->GetCommandIdAt(i); |
| 90 base::DictionaryValue* item = new base::DictionaryValue(); | 92 std::unique_ptr<base::DictionaryValue> item(new base::DictionaryValue()); |
| 91 item->SetInteger("id", id); | 93 item->SetInteger("id", id); |
| 92 base::string16 label = model->GetLabelAt(i); | 94 base::string16 label = model->GetLabelAt(i); |
| 93 base::ReplaceSubstringsAfterOffset(&label, 0, base::ASCIIToUTF16("&&"), | 95 base::ReplaceSubstringsAfterOffset(&label, 0, base::ASCIIToUTF16("&&"), |
| 94 base::ASCIIToUTF16("&")); | 96 base::ASCIIToUTF16("&")); |
| 95 item->SetString("label", label); | 97 item->SetString("label", label); |
| 96 gfx::Image icon; | 98 gfx::Image icon; |
| 97 if (model->GetIconAt(i, &icon)) { | 99 if (model->GetIconAt(i, &icon)) { |
| 98 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation( | 100 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation( |
| 99 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); | 101 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); |
| 100 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap)); | 102 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap)); |
| 101 } | 103 } |
| 102 if (id >= 0) { | 104 if (id >= 0) { |
| 103 item->SetBoolean("enabled", model->IsEnabledAt(i)); | 105 item->SetBoolean("enabled", model->IsEnabledAt(i)); |
| 104 const gfx::FontList* font_list = model->GetLabelFontListAt(i); | 106 const gfx::FontList* font_list = model->GetLabelFontListAt(i); |
| 105 if (font_list) | 107 if (font_list) |
| 106 item->SetBoolean("bold", | 108 item->SetBoolean("bold", |
| 107 font_list->GetFontWeight() == gfx::Font::Weight::BOLD); | 109 font_list->GetFontWeight() == gfx::Font::Weight::BOLD); |
| 108 } | 110 } |
| 109 if (type == ui::MenuModel::TYPE_SUBMENU) | 111 if (type == ui::MenuModel::TYPE_SUBMENU) |
| 110 item->Set("sub", ConvertMenuModel(model->GetSubmenuModelAt(i))); | 112 item->Set("sub", ConvertMenuModel(model->GetSubmenuModelAt(i))); |
| 111 list->Append(item); | 113 list->Append(std::move(item)); |
| 112 } | 114 } |
| 113 return list; | 115 return list; |
| 114 } | 116 } |
| 115 | 117 |
| 116 // NetworkDropdown ------------------------------------------------------------- | 118 // NetworkDropdown ------------------------------------------------------------- |
| 117 | 119 |
| 118 NetworkDropdown::NetworkDropdown(Actor* actor, | 120 NetworkDropdown::NetworkDropdown(Actor* actor, |
| 119 content::WebUI* web_ui, | 121 content::WebUI* web_ui, |
| 120 bool oobe) | 122 bool oobe) |
| 121 : actor_(actor), | 123 : actor_(actor), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle", | 207 web_ui_->CallJavascriptFunctionUnsafe("cr.ui.DropDown.updateNetworkTitle", |
| 206 title, icon); | 208 title, icon); |
| 207 } | 209 } |
| 208 | 210 |
| 209 void NetworkDropdown::RequestNetworkScan() { | 211 void NetworkDropdown::RequestNetworkScan() { |
| 210 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 212 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
| 211 Refresh(); | 213 Refresh(); |
| 212 } | 214 } |
| 213 | 215 |
| 214 } // namespace chromeos | 216 } // namespace chromeos |
| OLD | NEW |