| 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/extensions/api/autotest_private/autotest_private_api.h" | 5 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 base::ListValue* permissions = new base::ListValue; | 59 base::ListValue* permissions = new base::ListValue; |
| 60 std::set<std::string> perm_list = | 60 std::set<std::string> perm_list = |
| 61 ext->permissions_data()->active_permissions().GetAPIsAsStrings(); | 61 ext->permissions_data()->active_permissions().GetAPIsAsStrings(); |
| 62 for (std::set<std::string>::const_iterator perm = perm_list.begin(); | 62 for (std::set<std::string>::const_iterator perm = perm_list.begin(); |
| 63 perm != perm_list.end(); ++perm) { | 63 perm != perm_list.end(); ++perm) { |
| 64 permissions->AppendString(perm->c_str()); | 64 permissions->AppendString(perm->c_str()); |
| 65 } | 65 } |
| 66 return permissions; | 66 return permissions; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool IsTestMode(Profile* profile) { | 69 bool IsTestMode(content::BrowserContext* context) { |
| 70 return AutotestPrivateAPI::GetFactoryInstance()->Get(profile)->test_mode(); | 70 return AutotestPrivateAPI::GetFactoryInstance()->Get(context)->test_mode(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 bool AutotestPrivateLogoutFunction::RunSync() { | 75 ExtensionFunction::ResponseAction AutotestPrivateLogoutFunction::Run() { |
| 76 DVLOG(1) << "AutotestPrivateLogoutFunction"; | 76 DVLOG(1) << "AutotestPrivateLogoutFunction"; |
| 77 if (!IsTestMode(GetProfile())) | 77 if (!IsTestMode(browser_context())) |
| 78 chrome::AttemptUserExit(); | 78 chrome::AttemptUserExit(); |
| 79 return true; | 79 return RespondNow(NoArguments()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool AutotestPrivateRestartFunction::RunSync() { | 82 ExtensionFunction::ResponseAction AutotestPrivateRestartFunction::Run() { |
| 83 DVLOG(1) << "AutotestPrivateRestartFunction"; | 83 DVLOG(1) << "AutotestPrivateRestartFunction"; |
| 84 if (!IsTestMode(GetProfile())) | 84 if (!IsTestMode(browser_context())) |
| 85 chrome::AttemptRestart(); | 85 chrome::AttemptRestart(); |
| 86 return true; | 86 return RespondNow(NoArguments()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool AutotestPrivateShutdownFunction::RunSync() { | 89 ExtensionFunction::ResponseAction AutotestPrivateShutdownFunction::Run() { |
| 90 std::unique_ptr<api::autotest_private::Shutdown::Params> params( | 90 std::unique_ptr<api::autotest_private::Shutdown::Params> params( |
| 91 api::autotest_private::Shutdown::Params::Create(*args_)); | 91 api::autotest_private::Shutdown::Params::Create(*args_)); |
| 92 EXTENSION_FUNCTION_VALIDATE(params.get()); | 92 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 93 | 93 |
| 94 DVLOG(1) << "AutotestPrivateShutdownFunction " << params->force; | 94 DVLOG(1) << "AutotestPrivateShutdownFunction " << params->force; |
| 95 | 95 |
| 96 if (!IsTestMode(GetProfile())) | 96 if (!IsTestMode(browser_context())) |
| 97 chrome::AttemptExit(); | 97 chrome::AttemptExit(); |
| 98 return true; | 98 return RespondNow(NoArguments()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool AutotestPrivateLoginStatusFunction::RunSync() { | 101 ExtensionFunction::ResponseAction AutotestPrivateLoginStatusFunction::Run() { |
| 102 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; | 102 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; |
| 103 | 103 |
| 104 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 104 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
| 105 #if defined(OS_CHROMEOS) | 105 #if defined(OS_CHROMEOS) |
| 106 const user_manager::UserManager* user_manager = | 106 const user_manager::UserManager* user_manager = |
| 107 user_manager::UserManager::Get(); | 107 user_manager::UserManager::Get(); |
| 108 const bool is_screen_locked = | 108 const bool is_screen_locked = |
| 109 !!chromeos::ScreenLocker::default_screen_locker(); | 109 !!chromeos::ScreenLocker::default_screen_locker(); |
| 110 | 110 |
| 111 if (user_manager) { | 111 if (user_manager) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 default: | 135 default: |
| 136 user_image = base::IntToString(user->image_index()); | 136 user_image = base::IntToString(user->image_index()); |
| 137 break; | 137 break; |
| 138 } | 138 } |
| 139 result->SetString("userImage", user_image); | 139 result->SetString("userImage", user_image); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 #endif | 142 #endif |
| 143 | 143 |
| 144 SetResult(std::move(result)); | 144 return RespondNow(OneArgument(std::move(result))); |
| 145 return true; | |
| 146 } | 145 } |
| 147 | 146 |
| 148 bool AutotestPrivateLockScreenFunction::RunSync() { | 147 ExtensionFunction::ResponseAction AutotestPrivateLockScreenFunction::Run() { |
| 149 DVLOG(1) << "AutotestPrivateLockScreenFunction"; | 148 DVLOG(1) << "AutotestPrivateLockScreenFunction"; |
| 150 #if defined(OS_CHROMEOS) | 149 #if defined(OS_CHROMEOS) |
| 151 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> | 150 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 152 RequestLockScreen(); | 151 RequestLockScreen(); |
| 153 #endif | 152 #endif |
| 154 return true; | 153 return RespondNow(NoArguments()); |
| 155 } | 154 } |
| 156 | 155 |
| 157 bool AutotestPrivateGetExtensionsInfoFunction::RunSync() { | 156 ExtensionFunction::ResponseAction |
| 157 AutotestPrivateGetExtensionsInfoFunction::Run() { |
| 158 DVLOG(1) << "AutotestPrivateGetExtensionsInfoFunction"; | 158 DVLOG(1) << "AutotestPrivateGetExtensionsInfoFunction"; |
| 159 | 159 |
| 160 ExtensionService* service = | 160 ExtensionService* service = |
| 161 ExtensionSystem::Get(GetProfile())->extension_service(); | 161 ExtensionSystem::Get(browser_context())->extension_service(); |
| 162 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); | 162 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); |
| 163 const ExtensionSet& extensions = registry->enabled_extensions(); | 163 const ExtensionSet& extensions = registry->enabled_extensions(); |
| 164 const ExtensionSet& disabled_extensions = registry->disabled_extensions(); | 164 const ExtensionSet& disabled_extensions = registry->disabled_extensions(); |
| 165 ExtensionActionManager* extension_action_manager = | 165 ExtensionActionManager* extension_action_manager = |
| 166 ExtensionActionManager::Get(GetProfile()); | 166 ExtensionActionManager::Get(browser_context()); |
| 167 | 167 |
| 168 base::ListValue* extensions_values = new base::ListValue; | 168 base::ListValue* extensions_values = new base::ListValue; |
| 169 ExtensionList all; | 169 ExtensionList all; |
| 170 all.insert(all.end(), extensions.begin(), extensions.end()); | 170 all.insert(all.end(), extensions.begin(), extensions.end()); |
| 171 all.insert(all.end(), disabled_extensions.begin(), disabled_extensions.end()); | 171 all.insert(all.end(), disabled_extensions.begin(), disabled_extensions.end()); |
| 172 for (ExtensionList::const_iterator it = all.begin(); | 172 for (ExtensionList::const_iterator it = all.begin(); |
| 173 it != all.end(); ++it) { | 173 it != all.end(); ++it) { |
| 174 const Extension* extension = it->get(); | 174 const Extension* extension = it->get(); |
| 175 std::string id = extension->id(); | 175 std::string id = extension->id(); |
| 176 std::unique_ptr<base::DictionaryValue> extension_value( | 176 std::unique_ptr<base::DictionaryValue> extension_value( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 193 | 193 |
| 194 Manifest::Location location = extension->location(); | 194 Manifest::Location location = extension->location(); |
| 195 extension_value->SetBoolean("isComponent", | 195 extension_value->SetBoolean("isComponent", |
| 196 location == Manifest::COMPONENT); | 196 location == Manifest::COMPONENT); |
| 197 extension_value->SetBoolean("isInternal", | 197 extension_value->SetBoolean("isInternal", |
| 198 location == Manifest::INTERNAL); | 198 location == Manifest::INTERNAL); |
| 199 extension_value->SetBoolean("isUserInstalled", | 199 extension_value->SetBoolean("isUserInstalled", |
| 200 location == Manifest::INTERNAL || | 200 location == Manifest::INTERNAL || |
| 201 Manifest::IsUnpackedLocation(location)); | 201 Manifest::IsUnpackedLocation(location)); |
| 202 extension_value->SetBoolean("isEnabled", service->IsExtensionEnabled(id)); | 202 extension_value->SetBoolean("isEnabled", service->IsExtensionEnabled(id)); |
| 203 extension_value->SetBoolean("allowedInIncognito", | 203 extension_value->SetBoolean( |
| 204 util::IsIncognitoEnabled(id, GetProfile())); | 204 "allowedInIncognito", util::IsIncognitoEnabled(id, browser_context())); |
| 205 extension_value->SetBoolean( | 205 extension_value->SetBoolean( |
| 206 "hasPageAction", | 206 "hasPageAction", |
| 207 extension_action_manager->GetPageAction(*extension) != NULL); | 207 extension_action_manager->GetPageAction(*extension) != NULL); |
| 208 | 208 |
| 209 extensions_values->Append(std::move(extension_value)); | 209 extensions_values->Append(std::move(extension_value)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 std::unique_ptr<base::DictionaryValue> return_value( | 212 std::unique_ptr<base::DictionaryValue> return_value( |
| 213 new base::DictionaryValue); | 213 new base::DictionaryValue); |
| 214 return_value->Set("extensions", extensions_values); | 214 return_value->Set("extensions", extensions_values); |
| 215 SetResult(std::move(return_value)); | 215 return RespondNow(OneArgument(std::move(return_value))); |
| 216 return true; | |
| 217 } | 216 } |
| 218 | 217 |
| 219 static int AccessArray(const volatile int arr[], const volatile int *index) { | 218 static int AccessArray(const volatile int arr[], const volatile int *index) { |
| 220 return arr[*index]; | 219 return arr[*index]; |
| 221 } | 220 } |
| 222 | 221 |
| 223 bool AutotestPrivateSimulateAsanMemoryBugFunction::RunSync() { | 222 ExtensionFunction::ResponseAction |
| 223 AutotestPrivateSimulateAsanMemoryBugFunction::Run() { |
| 224 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction"; | 224 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction"; |
| 225 if (!IsTestMode(GetProfile())) { | 225 if (!IsTestMode(browser_context())) { |
| 226 // This array is volatile not to let compiler optimize us out. | 226 // This array is volatile not to let compiler optimize us out. |
| 227 volatile int testarray[3] = {0, 0, 0}; | 227 volatile int testarray[3] = {0, 0, 0}; |
| 228 | 228 |
| 229 // Cause Address Sanitizer to abort this process. | 229 // Cause Address Sanitizer to abort this process. |
| 230 volatile int index = 5; | 230 volatile int index = 5; |
| 231 AccessArray(testarray, &index); | 231 AccessArray(testarray, &index); |
| 232 } | 232 } |
| 233 return true; | 233 return RespondNow(NoArguments()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool AutotestPrivateSetTouchpadSensitivityFunction::RunSync() { | 236 ExtensionFunction::ResponseAction |
| 237 AutotestPrivateSetTouchpadSensitivityFunction::Run() { |
| 237 std::unique_ptr<api::autotest_private::SetTouchpadSensitivity::Params> params( | 238 std::unique_ptr<api::autotest_private::SetTouchpadSensitivity::Params> params( |
| 238 api::autotest_private::SetTouchpadSensitivity::Params::Create(*args_)); | 239 api::autotest_private::SetTouchpadSensitivity::Params::Create(*args_)); |
| 239 EXTENSION_FUNCTION_VALIDATE(params.get()); | 240 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 240 | 241 |
| 241 DVLOG(1) << "AutotestPrivateSetTouchpadSensitivityFunction " << params->value; | 242 DVLOG(1) << "AutotestPrivateSetTouchpadSensitivityFunction " << params->value; |
| 242 | 243 |
| 243 #if defined(OS_CHROMEOS) | 244 #if defined(OS_CHROMEOS) |
| 244 chromeos::system::InputDeviceSettings::Get()->SetTouchpadSensitivity( | 245 chromeos::system::InputDeviceSettings::Get()->SetTouchpadSensitivity( |
| 245 params->value); | 246 params->value); |
| 246 #endif | 247 #endif |
| 247 return true; | 248 return RespondNow(NoArguments()); |
| 248 } | 249 } |
| 249 | 250 |
| 250 bool AutotestPrivateSetTapToClickFunction::RunSync() { | 251 ExtensionFunction::ResponseAction AutotestPrivateSetTapToClickFunction::Run() { |
| 251 std::unique_ptr<api::autotest_private::SetTapToClick::Params> params( | 252 std::unique_ptr<api::autotest_private::SetTapToClick::Params> params( |
| 252 api::autotest_private::SetTapToClick::Params::Create(*args_)); | 253 api::autotest_private::SetTapToClick::Params::Create(*args_)); |
| 253 EXTENSION_FUNCTION_VALIDATE(params.get()); | 254 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 254 | 255 |
| 255 DVLOG(1) << "AutotestPrivateSetTapToClickFunction " << params->enabled; | 256 DVLOG(1) << "AutotestPrivateSetTapToClickFunction " << params->enabled; |
| 256 | 257 |
| 257 #if defined(OS_CHROMEOS) | 258 #if defined(OS_CHROMEOS) |
| 258 chromeos::system::InputDeviceSettings::Get()->SetTapToClick(params->enabled); | 259 chromeos::system::InputDeviceSettings::Get()->SetTapToClick(params->enabled); |
| 259 #endif | 260 #endif |
| 260 return true; | 261 return RespondNow(NoArguments()); |
| 261 } | 262 } |
| 262 | 263 |
| 263 bool AutotestPrivateSetThreeFingerClickFunction::RunSync() { | 264 ExtensionFunction::ResponseAction |
| 265 AutotestPrivateSetThreeFingerClickFunction::Run() { |
| 264 std::unique_ptr<api::autotest_private::SetThreeFingerClick::Params> params( | 266 std::unique_ptr<api::autotest_private::SetThreeFingerClick::Params> params( |
| 265 api::autotest_private::SetThreeFingerClick::Params::Create(*args_)); | 267 api::autotest_private::SetThreeFingerClick::Params::Create(*args_)); |
| 266 EXTENSION_FUNCTION_VALIDATE(params.get()); | 268 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 267 | 269 |
| 268 DVLOG(1) << "AutotestPrivateSetThreeFingerClickFunction " << params->enabled; | 270 DVLOG(1) << "AutotestPrivateSetThreeFingerClickFunction " << params->enabled; |
| 269 | 271 |
| 270 #if defined(OS_CHROMEOS) | 272 #if defined(OS_CHROMEOS) |
| 271 chromeos::system::InputDeviceSettings::Get()->SetThreeFingerClick( | 273 chromeos::system::InputDeviceSettings::Get()->SetThreeFingerClick( |
| 272 params->enabled); | 274 params->enabled); |
| 273 #endif | 275 #endif |
| 274 return true; | 276 return RespondNow(NoArguments()); |
| 275 } | 277 } |
| 276 | 278 |
| 277 bool AutotestPrivateSetTapDraggingFunction::RunSync() { | 279 ExtensionFunction::ResponseAction AutotestPrivateSetTapDraggingFunction::Run() { |
| 278 std::unique_ptr<api::autotest_private::SetTapDragging::Params> params( | 280 std::unique_ptr<api::autotest_private::SetTapDragging::Params> params( |
| 279 api::autotest_private::SetTapDragging::Params::Create(*args_)); | 281 api::autotest_private::SetTapDragging::Params::Create(*args_)); |
| 280 EXTENSION_FUNCTION_VALIDATE(params.get()); | 282 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 281 | 283 |
| 282 DVLOG(1) << "AutotestPrivateSetTapDraggingFunction " << params->enabled; | 284 DVLOG(1) << "AutotestPrivateSetTapDraggingFunction " << params->enabled; |
| 283 | 285 |
| 284 #if defined(OS_CHROMEOS) | 286 #if defined(OS_CHROMEOS) |
| 285 chromeos::system::InputDeviceSettings::Get()->SetTapDragging(params->enabled); | 287 chromeos::system::InputDeviceSettings::Get()->SetTapDragging(params->enabled); |
| 286 #endif | 288 #endif |
| 287 return true; | 289 return RespondNow(NoArguments()); |
| 288 } | 290 } |
| 289 | 291 |
| 290 bool AutotestPrivateSetNaturalScrollFunction::RunSync() { | 292 ExtensionFunction::ResponseAction |
| 293 AutotestPrivateSetNaturalScrollFunction::Run() { |
| 291 std::unique_ptr<api::autotest_private::SetNaturalScroll::Params> params( | 294 std::unique_ptr<api::autotest_private::SetNaturalScroll::Params> params( |
| 292 api::autotest_private::SetNaturalScroll::Params::Create(*args_)); | 295 api::autotest_private::SetNaturalScroll::Params::Create(*args_)); |
| 293 EXTENSION_FUNCTION_VALIDATE(params.get()); | 296 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 294 | 297 |
| 295 DVLOG(1) << "AutotestPrivateSetNaturalScrollFunction " << params->enabled; | 298 DVLOG(1) << "AutotestPrivateSetNaturalScrollFunction " << params->enabled; |
| 296 | 299 |
| 297 #if defined(OS_CHROMEOS) | 300 #if defined(OS_CHROMEOS) |
| 298 chromeos::system::InputDeviceSettings::Get()->SetNaturalScroll( | 301 chromeos::system::InputDeviceSettings::Get()->SetNaturalScroll( |
| 299 params->enabled); | 302 params->enabled); |
| 300 #endif | 303 #endif |
| 301 return true; | 304 return RespondNow(NoArguments()); |
| 302 } | 305 } |
| 303 | 306 |
| 304 bool AutotestPrivateSetMouseSensitivityFunction::RunSync() { | 307 ExtensionFunction::ResponseAction |
| 308 AutotestPrivateSetMouseSensitivityFunction::Run() { |
| 305 std::unique_ptr<api::autotest_private::SetMouseSensitivity::Params> params( | 309 std::unique_ptr<api::autotest_private::SetMouseSensitivity::Params> params( |
| 306 api::autotest_private::SetMouseSensitivity::Params::Create(*args_)); | 310 api::autotest_private::SetMouseSensitivity::Params::Create(*args_)); |
| 307 EXTENSION_FUNCTION_VALIDATE(params.get()); | 311 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 308 | 312 |
| 309 DVLOG(1) << "AutotestPrivateSetMouseSensitivityFunction " << params->value; | 313 DVLOG(1) << "AutotestPrivateSetMouseSensitivityFunction " << params->value; |
| 310 | 314 |
| 311 #if defined(OS_CHROMEOS) | 315 #if defined(OS_CHROMEOS) |
| 312 chromeos::system::InputDeviceSettings::Get()->SetMouseSensitivity( | 316 chromeos::system::InputDeviceSettings::Get()->SetMouseSensitivity( |
| 313 params->value); | 317 params->value); |
| 314 #endif | 318 #endif |
| 315 return true; | 319 return RespondNow(NoArguments()); |
| 316 } | 320 } |
| 317 | 321 |
| 318 bool AutotestPrivateSetPrimaryButtonRightFunction::RunSync() { | 322 ExtensionFunction::ResponseAction |
| 323 AutotestPrivateSetPrimaryButtonRightFunction::Run() { |
| 319 std::unique_ptr<api::autotest_private::SetPrimaryButtonRight::Params> params( | 324 std::unique_ptr<api::autotest_private::SetPrimaryButtonRight::Params> params( |
| 320 api::autotest_private::SetPrimaryButtonRight::Params::Create(*args_)); | 325 api::autotest_private::SetPrimaryButtonRight::Params::Create(*args_)); |
| 321 EXTENSION_FUNCTION_VALIDATE(params.get()); | 326 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 322 | 327 |
| 323 DVLOG(1) << "AutotestPrivateSetPrimaryButtonRightFunction " << params->right; | 328 DVLOG(1) << "AutotestPrivateSetPrimaryButtonRightFunction " << params->right; |
| 324 | 329 |
| 325 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 326 chromeos::system::InputDeviceSettings::Get()->SetPrimaryButtonRight( | 331 chromeos::system::InputDeviceSettings::Get()->SetPrimaryButtonRight( |
| 327 params->right); | 332 params->right); |
| 328 #endif | 333 #endif |
| 329 return true; | 334 return RespondNow(NoArguments()); |
| 330 } | 335 } |
| 331 | 336 |
| 332 // static | 337 // static |
| 333 std::string AutotestPrivateGetVisibleNotificationsFunction::ConvertToString( | 338 std::string AutotestPrivateGetVisibleNotificationsFunction::ConvertToString( |
| 334 message_center::NotificationType type) { | 339 message_center::NotificationType type) { |
| 335 #if defined(OS_CHROMEOS) | 340 #if defined(OS_CHROMEOS) |
| 336 switch (type) { | 341 switch (type) { |
| 337 case message_center::NOTIFICATION_TYPE_SIMPLE: | 342 case message_center::NOTIFICATION_TYPE_SIMPLE: |
| 338 return "simple"; | 343 return "simple"; |
| 339 case message_center::NOTIFICATION_TYPE_BASE_FORMAT: | 344 case message_center::NOTIFICATION_TYPE_BASE_FORMAT: |
| 340 return "base_format"; | 345 return "base_format"; |
| 341 case message_center::NOTIFICATION_TYPE_IMAGE: | 346 case message_center::NOTIFICATION_TYPE_IMAGE: |
| 342 return "image"; | 347 return "image"; |
| 343 case message_center::NOTIFICATION_TYPE_MULTIPLE: | 348 case message_center::NOTIFICATION_TYPE_MULTIPLE: |
| 344 return "multiple"; | 349 return "multiple"; |
| 345 case message_center::NOTIFICATION_TYPE_PROGRESS: | 350 case message_center::NOTIFICATION_TYPE_PROGRESS: |
| 346 return "progress"; | 351 return "progress"; |
| 347 case message_center::NOTIFICATION_TYPE_CUSTOM: | 352 case message_center::NOTIFICATION_TYPE_CUSTOM: |
| 348 return "custom"; | 353 return "custom"; |
| 349 } | 354 } |
| 350 #endif | 355 #endif |
| 351 return "unknown"; | 356 return "unknown"; |
| 352 } | 357 } |
| 353 | 358 |
| 354 bool AutotestPrivateGetVisibleNotificationsFunction::RunSync() { | 359 ExtensionFunction::ResponseAction |
| 360 AutotestPrivateGetVisibleNotificationsFunction::Run() { |
| 355 DVLOG(1) << "AutotestPrivateGetVisibleNotificationsFunction"; | 361 DVLOG(1) << "AutotestPrivateGetVisibleNotificationsFunction"; |
| 356 std::unique_ptr<base::ListValue> values(new base::ListValue); | 362 std::unique_ptr<base::ListValue> values(new base::ListValue); |
| 357 #if defined(OS_CHROMEOS) | 363 #if defined(OS_CHROMEOS) |
| 358 for (auto* notification : | 364 for (auto* notification : |
| 359 message_center::MessageCenter::Get()->GetVisibleNotifications()) { | 365 message_center::MessageCenter::Get()->GetVisibleNotifications()) { |
| 360 base::DictionaryValue* result(new base::DictionaryValue); | 366 base::DictionaryValue* result(new base::DictionaryValue); |
| 361 result->SetString("id", notification->id()); | 367 result->SetString("id", notification->id()); |
| 362 result->SetString("type", ConvertToString(notification->type())); | 368 result->SetString("type", ConvertToString(notification->type())); |
| 363 result->SetString("title", notification->title()); | 369 result->SetString("title", notification->title()); |
| 364 result->SetString("message", notification->message()); | 370 result->SetString("message", notification->message()); |
| 365 result->SetInteger("priority", notification->priority()); | 371 result->SetInteger("priority", notification->priority()); |
| 366 result->SetInteger("progress", notification->progress()); | 372 result->SetInteger("progress", notification->progress()); |
| 367 values->Append(result); | 373 values->Append(result); |
| 368 } | 374 } |
| 369 | 375 |
| 370 #endif | 376 #endif |
| 371 SetResult(std::move(values)); | 377 return RespondNow(OneArgument(std::move(values))); |
| 372 return true; | |
| 373 } | 378 } |
| 374 | 379 |
| 375 static base::LazyInstance<BrowserContextKeyedAPIFactory<AutotestPrivateAPI> > | 380 static base::LazyInstance<BrowserContextKeyedAPIFactory<AutotestPrivateAPI> > |
| 376 g_factory = LAZY_INSTANCE_INITIALIZER; | 381 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 377 | 382 |
| 378 // static | 383 // static |
| 379 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>* | 384 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>* |
| 380 AutotestPrivateAPI::GetFactoryInstance() { | 385 AutotestPrivateAPI::GetFactoryInstance() { |
| 381 return g_factory.Pointer(); | 386 return g_factory.Pointer(); |
| 382 } | 387 } |
| 383 | 388 |
| 384 template <> | 389 template <> |
| 385 KeyedService* | 390 KeyedService* |
| 386 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor( | 391 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor( |
| 387 content::BrowserContext* context) const { | 392 content::BrowserContext* context) const { |
| 388 return new AutotestPrivateAPI(); | 393 return new AutotestPrivateAPI(); |
| 389 } | 394 } |
| 390 | 395 |
| 391 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { | 396 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { |
| 392 } | 397 } |
| 393 | 398 |
| 394 AutotestPrivateAPI::~AutotestPrivateAPI() { | 399 AutotestPrivateAPI::~AutotestPrivateAPI() { |
| 395 } | 400 } |
| 396 | 401 |
| 397 } // namespace extensions | 402 } // namespace extensions |
| OLD | NEW |