OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/dom_ui/network_menu_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/network_menu_ui.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
10 #include "chrome/browser/chromeos/status/network_menu.h" | 11 #include "chrome/browser/chromeos/status/network_menu.h" |
11 #include "chrome/browser/chromeos/views/native_menu_domui.h" | 12 #include "chrome/browser/chromeos/views/native_menu_domui.h" |
12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
14 #include "grit/browser_resources.h" | 15 #include "grit/browser_resources.h" |
15 #include "views/controls/menu/menu_2.h" | 16 #include "views/controls/menu/menu_2.h" |
16 | 17 |
17 namespace { | 18 namespace { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 -1))) { | 79 -1))) { |
79 NetworkMenuHandler* handler = new NetworkMenuHandler(); | 80 NetworkMenuHandler* handler = new NetworkMenuHandler(); |
80 AddMessageHandler((handler)->Attach(this)); | 81 AddMessageHandler((handler)->Attach(this)); |
81 } | 82 } |
82 | 83 |
83 void NetworkMenuUI::AddCustomConfigValues(DictionaryValue* config) const { | 84 void NetworkMenuUI::AddCustomConfigValues(DictionaryValue* config) const { |
84 } | 85 } |
85 | 86 |
86 void NetworkMenuUI::ModelAction(const menus::MenuModel* model, | 87 void NetworkMenuUI::ModelAction(const menus::MenuModel* model, |
87 const ListValue* values) { | 88 const ListValue* values) { |
88 //const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model); | 89 const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model); |
89 // Invoke model methods here. | 90 std::string action; |
| 91 bool success = values->GetString(0, &action); |
| 92 if (!success) { |
| 93 LOG(WARNING) << "ModelAction called with no arguments from: " |
| 94 << chrome::kChromeUINetworkMenu; |
| 95 return; |
| 96 } |
| 97 int index; |
| 98 std::string index_str; |
| 99 success = values->GetString(1, &index_str); |
| 100 success = success && base::StringToInt(index_str, &index); |
| 101 if (!success) { |
| 102 LOG(WARNING) << "ModelAction called with no index from: " |
| 103 << chrome::kChromeUINetworkMenu; |
| 104 return; |
| 105 } |
| 106 std::string passphrase; |
| 107 values->GetString(2, &passphrase); // Optional |
| 108 std::string identity; |
| 109 values->GetString(3, &identity); // Optional |
| 110 if (action == "connect" || action == "reconnect") { |
| 111 network_menu->ConnectToNetworkAt(index, passphrase, identity); |
| 112 } else { |
| 113 LOG(WARNING) << "Unrecognized action: " << action |
| 114 << " from: " << chrome::kChromeUINetworkMenu; |
| 115 } |
90 } | 116 } |
91 | 117 |
92 DictionaryValue* NetworkMenuUI::CreateMenuItem(const menus::MenuModel* model, | 118 DictionaryValue* NetworkMenuUI::CreateMenuItem(const menus::MenuModel* model, |
93 int index, | 119 int index, |
94 const char* type, | 120 const char* type, |
95 int* max_icon_width, | 121 int* max_icon_width, |
96 bool* has_accel) const { | 122 bool* has_accel) const { |
97 // Create a MenuUI menu item, then append network specific values. | 123 // Create a MenuUI menu item, then append network specific values. |
98 DictionaryValue* item = MenuUI::CreateMenuItem(model, | 124 DictionaryValue* item = MenuUI::CreateMenuItem(model, |
99 index, | 125 index, |
(...skipping 16 matching lines...) Expand all Loading... |
116 } | 142 } |
117 | 143 |
118 views::Menu2* NetworkMenuUI::CreateMenu2(menus::MenuModel* model) { | 144 views::Menu2* NetworkMenuUI::CreateMenu2(menus::MenuModel* model) { |
119 views::Menu2* menu = new views::Menu2(model); | 145 views::Menu2* menu = new views::Menu2(model); |
120 NativeMenuDOMUI::SetMenuURL( | 146 NativeMenuDOMUI::SetMenuURL( |
121 menu, GURL(StringPrintf("chrome://%s", chrome::kChromeUINetworkMenu))); | 147 menu, GURL(StringPrintf("chrome://%s", chrome::kChromeUINetworkMenu))); |
122 return menu; | 148 return menu; |
123 } | 149 } |
124 | 150 |
125 } // namespace chromeos | 151 } // namespace chromeos |
OLD | NEW |