| 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
| 12 #include "chrome/browser/chromeos/status/network_menu.h" | 12 #include "chrome/browser/chromeos/status/network_menu.h" |
| 13 #include "chrome/browser/chromeos/views/domui_menu_widget.h" |
| 13 #include "chrome/browser/chromeos/views/native_menu_domui.h" | 14 #include "chrome/browser/chromeos/views/native_menu_domui.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 16 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 18 #include "views/controls/menu/menu_2.h" | 20 #include "views/controls/menu/menu_2.h" |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 23 // | 25 // |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 | 45 |
| 44 void NetworkMenuHandler::RegisterMessages() { | 46 void NetworkMenuHandler::RegisterMessages() { |
| 45 dom_ui_->RegisterMessageCallback( | 47 dom_ui_->RegisterMessageCallback( |
| 46 "action", | 48 "action", |
| 47 NewCallback(this, | 49 NewCallback(this, |
| 48 &NetworkMenuHandler::HandleAction)); | 50 &NetworkMenuHandler::HandleAction)); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void NetworkMenuHandler::HandleAction(const ListValue* values) { | 53 void NetworkMenuHandler::HandleAction(const ListValue* values) { |
| 52 menus::MenuModel* model = GetMenuModel(); | 54 menus::MenuModel* model = GetMenuModel(); |
| 53 if (model) | 55 if (model) { |
| 54 static_cast<chromeos::NetworkMenuUI*>(dom_ui_)->ModelAction(model, values); | 56 chromeos::NetworkMenuUI* network_menu_ui = |
| 57 static_cast<chromeos::NetworkMenuUI*>(dom_ui_); |
| 58 bool close_menu = network_menu_ui->ModelAction(model, values); |
| 59 if (close_menu) { |
| 60 chromeos::DOMUIMenuWidget* widget |
| 61 = chromeos::DOMUIMenuWidget::FindDOMUIMenuWidget( |
| 62 dom_ui_->tab_contents()->GetNativeView()); |
| 63 if (widget) { |
| 64 chromeos::NativeMenuDOMUI* domui_menu = widget->domui_menu(); |
| 65 if (domui_menu) |
| 66 domui_menu->Hide(); |
| 67 } |
| 68 } |
| 69 } |
| 55 } | 70 } |
| 56 | 71 |
| 57 NetworkMenuHandler::NetworkMenuHandler() { | 72 NetworkMenuHandler::NetworkMenuHandler() { |
| 58 } | 73 } |
| 59 | 74 |
| 60 NetworkMenuHandler::~NetworkMenuHandler() { | 75 NetworkMenuHandler::~NetworkMenuHandler() { |
| 61 } | 76 } |
| 62 | 77 |
| 63 } // namespace | 78 } // namespace |
| 64 | 79 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 localized_strings->SetString("reconnect", l10n_util::GetStringUTF16( | 108 localized_strings->SetString("reconnect", l10n_util::GetStringUTF16( |
| 94 IDS_NETWORK_RECONNECT_TITLE)); | 109 IDS_NETWORK_RECONNECT_TITLE)); |
| 95 localized_strings->SetString("remeber_this_network", | 110 localized_strings->SetString("remeber_this_network", |
| 96 l10n_util::GetStringUTF16(IDS_NETWORK_REMEMBER_THIS_NETWORK_TITLE)); | 111 l10n_util::GetStringUTF16(IDS_NETWORK_REMEMBER_THIS_NETWORK_TITLE)); |
| 97 localized_strings->SetString("ssid_prompt", | 112 localized_strings->SetString("ssid_prompt", |
| 98 l10n_util::GetStringUTF16(IDS_NETWORK_SSID_HINT)); | 113 l10n_util::GetStringUTF16(IDS_NETWORK_SSID_HINT)); |
| 99 localized_strings->SetString("pass_prompt", | 114 localized_strings->SetString("pass_prompt", |
| 100 l10n_util::GetStringUTF16(IDS_NETWORK_PASSWORD_HINT)); | 115 l10n_util::GetStringUTF16(IDS_NETWORK_PASSWORD_HINT)); |
| 101 } | 116 } |
| 102 | 117 |
| 103 void NetworkMenuUI::ModelAction(const menus::MenuModel* model, | 118 bool NetworkMenuUI::ModelAction(const menus::MenuModel* model, |
| 104 const ListValue* values) { | 119 const ListValue* values) { |
| 105 const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model); | 120 const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model); |
| 106 std::string action; | 121 std::string action; |
| 107 bool success = values->GetString(0, &action); | 122 bool success = values->GetString(0, &action); |
| 123 bool close_menu = true; |
| 108 if (!success) { | 124 if (!success) { |
| 109 LOG(WARNING) << "ModelAction called with no arguments from: " | 125 LOG(WARNING) << "ModelAction called with no arguments from: " |
| 110 << chrome::kChromeUINetworkMenu; | 126 << chrome::kChromeUINetworkMenu; |
| 111 return; | 127 return close_menu; |
| 112 } | 128 } |
| 113 int index; | 129 int index; |
| 114 std::string index_str; | 130 std::string index_str; |
| 115 success = values->GetString(1, &index_str); | 131 success = values->GetString(1, &index_str); |
| 116 success = success && base::StringToInt(index_str, &index); | 132 success = success && base::StringToInt(index_str, &index); |
| 117 if (!success) { | 133 if (!success) { |
| 118 LOG(WARNING) << "ModelAction called with no index from: " | 134 LOG(WARNING) << "ModelAction called with no index from: " |
| 119 << chrome::kChromeUINetworkMenu; | 135 << chrome::kChromeUINetworkMenu; |
| 120 return; | 136 return close_menu; |
| 121 } | 137 } |
| 122 std::string passphrase; | 138 std::string passphrase; |
| 123 values->GetString(2, &passphrase); // Optional | 139 values->GetString(2, &passphrase); // Optional |
| 124 std::string identity; | 140 std::string ssid; |
| 125 values->GetString(3, &identity); // Optional | 141 values->GetString(3, &ssid); // Optional |
| 142 int remember = -1; // -1 indicates not set |
| 143 std::string remember_str; |
| 144 if (values->GetString(4, &remember_str)) // Optional |
| 145 base::StringToInt(remember_str, &remember); |
| 146 |
| 126 if (action == "connect" || action == "reconnect") { | 147 if (action == "connect" || action == "reconnect") { |
| 127 network_menu->ConnectToNetworkAt(index, passphrase, identity); | 148 close_menu = network_menu->ConnectToNetworkAt(index, passphrase, ssid, |
| 149 remember); |
| 128 } else { | 150 } else { |
| 129 LOG(WARNING) << "Unrecognized action: " << action | 151 LOG(WARNING) << "Unrecognized action: " << action |
| 130 << " from: " << chrome::kChromeUINetworkMenu; | 152 << " from: " << chrome::kChromeUINetworkMenu; |
| 131 } | 153 } |
| 154 return close_menu; |
| 132 } | 155 } |
| 133 | 156 |
| 134 DictionaryValue* NetworkMenuUI::CreateMenuItem(const menus::MenuModel* model, | 157 DictionaryValue* NetworkMenuUI::CreateMenuItem(const menus::MenuModel* model, |
| 135 int index, | 158 int index, |
| 136 const char* type, | 159 const char* type, |
| 137 int* max_icon_width, | 160 int* max_icon_width, |
| 138 bool* has_accel) const { | 161 bool* has_accel) const { |
| 139 // Create a MenuUI menu item, then append network specific values. | 162 // Create a MenuUI menu item, then append network specific values. |
| 140 DictionaryValue* item = MenuUI::CreateMenuItem(model, | 163 DictionaryValue* item = MenuUI::CreateMenuItem(model, |
| 141 index, | 164 index, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 158 } | 181 } |
| 159 | 182 |
| 160 views::Menu2* NetworkMenuUI::CreateMenu2(menus::MenuModel* model) { | 183 views::Menu2* NetworkMenuUI::CreateMenu2(menus::MenuModel* model) { |
| 161 views::Menu2* menu = new views::Menu2(model); | 184 views::Menu2* menu = new views::Menu2(model); |
| 162 NativeMenuDOMUI::SetMenuURL( | 185 NativeMenuDOMUI::SetMenuURL( |
| 163 menu, GURL(StringPrintf("chrome://%s", chrome::kChromeUINetworkMenu))); | 186 menu, GURL(StringPrintf("chrome://%s", chrome::kChromeUINetworkMenu))); |
| 164 return menu; | 187 return menu; |
| 165 } | 188 } |
| 166 | 189 |
| 167 } // namespace chromeos | 190 } // namespace chromeos |
| OLD | NEW |