Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 13 #include "chromeos/network/network_state_handler.h" | 14 #include "chromeos/network/network_state_handler.h" |
| 14 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 15 #include "ui/base/models/menu_model.h" | 16 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/base/webui/web_ui_util.h" | 17 #include "ui/base/webui/web_ui_util.h" |
| 17 #include "ui/chromeos/network/network_icon.h" | 18 #include "ui/chromeos/network/network_icon.h" |
| 18 #include "ui/chromeos/network/network_icon_animation.h" | 19 #include "ui/chromeos/network/network_icon_animation.h" |
| 19 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
| 20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Timeout between consecutive requests to network library for network | 26 // Timeout between consecutive requests to network library for network |
| 26 // scan. | 27 // scan. |
| 27 const int kNetworkScanIntervalSecs = 60; | 28 const int kNetworkScanIntervalSecs = 60; |
| 28 | 29 |
| 30 base::string16 UnescapeAmpersands(const base::string16& input) { | |
| 31 base::string16 str = input; | |
| 32 size_t found = str.find(base::ASCIIToUTF16("&&")); | |
| 33 while (found != base::string16::npos) { | |
| 34 str.replace(found, 2, base::ASCIIToUTF16("&")); | |
| 35 found = str.find(base::ASCIIToUTF16("&&"), found + 1); | |
| 36 } | |
| 37 return str; | |
| 38 } | |
| 39 | |
| 29 } // namespace | 40 } // namespace |
| 30 | 41 |
| 31 namespace chromeos { | 42 namespace chromeos { |
| 32 | 43 |
| 33 // WebUI specific implementation of the NetworkMenu class. | 44 // WebUI specific implementation of the NetworkMenu class. |
| 34 class NetworkMenuWebUI : public NetworkMenu { | 45 class NetworkMenuWebUI : public NetworkMenu { |
| 35 public: | 46 public: |
| 36 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); | 47 NetworkMenuWebUI(NetworkMenu::Delegate* delegate, content::WebUI* web_ui); |
| 37 | 48 |
| 38 // NetworkMenu override: | 49 // NetworkMenu override: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 base::ListValue* list = new base::ListValue(); | 90 base::ListValue* list = new base::ListValue(); |
| 80 for (int i = 0; i < model->GetItemCount(); ++i) { | 91 for (int i = 0; i < model->GetItemCount(); ++i) { |
| 81 ui::MenuModel::ItemType type = model->GetTypeAt(i); | 92 ui::MenuModel::ItemType type = model->GetTypeAt(i); |
| 82 int id; | 93 int id; |
| 83 if (type == ui::MenuModel::TYPE_SEPARATOR) | 94 if (type == ui::MenuModel::TYPE_SEPARATOR) |
| 84 id = -2; | 95 id = -2; |
| 85 else | 96 else |
| 86 id = model->GetCommandIdAt(i); | 97 id = model->GetCommandIdAt(i); |
| 87 base::DictionaryValue* item = new base::DictionaryValue(); | 98 base::DictionaryValue* item = new base::DictionaryValue(); |
| 88 item->SetInteger("id", id); | 99 item->SetInteger("id", id); |
| 89 item->SetString("label", model->GetLabelAt(i)); | 100 item->SetString("label", UnescapeAmpersands(model->GetLabelAt(i))); |
|
Nikita (slow)
2015/04/28 11:58:51
Are these escaped while being part of MenuModel?
Nikita (slow)
2015/04/28 11:58:51
ReplaceSubstringsAfterOffset(&string, 0, "&&", "&"
Dmitry Polukhin
2015/04/28 13:23:09
Done. Yes this escaping is required for real MenuM
| |
| 90 gfx::Image icon; | 101 gfx::Image icon; |
| 91 if (model->GetIconAt(i, &icon)) { | 102 if (model->GetIconAt(i, &icon)) { |
| 92 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation( | 103 SkBitmap icon_bitmap = icon.ToImageSkia()->GetRepresentation( |
| 93 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); | 104 web_ui_->GetDeviceScaleFactor()).sk_bitmap(); |
| 94 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap)); | 105 item->SetString("icon", webui::GetBitmapDataUrl(icon_bitmap)); |
| 95 } | 106 } |
| 96 if (id >= 0) { | 107 if (id >= 0) { |
| 97 item->SetBoolean("enabled", model->IsEnabledAt(i)); | 108 item->SetBoolean("enabled", model->IsEnabledAt(i)); |
| 98 const gfx::FontList* font_list = model->GetLabelFontListAt(i); | 109 const gfx::FontList* font_list = model->GetLabelFontListAt(i); |
| 99 if (font_list) | 110 if (font_list) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", | 209 web_ui_->CallJavascriptFunction("cr.ui.DropDown.updateNetworkTitle", |
| 199 title, icon); | 210 title, icon); |
| 200 } | 211 } |
| 201 | 212 |
| 202 void NetworkDropdown::RequestNetworkScan() { | 213 void NetworkDropdown::RequestNetworkScan() { |
| 203 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 214 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
| 204 Refresh(); | 215 Refresh(); |
| 205 } | 216 } |
| 206 | 217 |
| 207 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |