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/extension_action/extension_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 bool ExtensionActionFunction::ExtractDataFromArguments() { | 365 bool ExtensionActionFunction::ExtractDataFromArguments() { |
366 // There may or may not be details (depends on the function). | 366 // There may or may not be details (depends on the function). |
367 // The tabId might appear in details (if it exists), as the first | 367 // The tabId might appear in details (if it exists), as the first |
368 // argument besides the action type (depends on the function), or be omitted | 368 // argument besides the action type (depends on the function), or be omitted |
369 // entirely. | 369 // entirely. |
370 base::Value* first_arg = NULL; | 370 base::Value* first_arg = NULL; |
371 if (!args_->Get(0, &first_arg)) | 371 if (!args_->Get(0, &first_arg)) |
372 return true; | 372 return true; |
373 | 373 |
374 switch (first_arg->GetType()) { | 374 switch (first_arg->GetType()) { |
375 case base::Value::TYPE_INTEGER: | 375 case base::Value::Type::INTEGER: |
376 CHECK(first_arg->GetAsInteger(&tab_id_)); | 376 CHECK(first_arg->GetAsInteger(&tab_id_)); |
377 break; | 377 break; |
378 | 378 |
379 case base::Value::TYPE_DICTIONARY: { | 379 case base::Value::Type::DICTIONARY: { |
380 // Found the details argument. | 380 // Found the details argument. |
381 details_ = static_cast<base::DictionaryValue*>(first_arg); | 381 details_ = static_cast<base::DictionaryValue*>(first_arg); |
382 // Still need to check for the tabId within details. | 382 // Still need to check for the tabId within details. |
383 base::Value* tab_id_value = NULL; | 383 base::Value* tab_id_value = NULL; |
384 if (details_->Get("tabId", &tab_id_value)) { | 384 if (details_->Get("tabId", &tab_id_value)) { |
385 switch (tab_id_value->GetType()) { | 385 switch (tab_id_value->GetType()) { |
386 case base::Value::TYPE_NULL: | 386 case base::Value::Type::NONE: |
387 // OK; tabId is optional, leave it default. | 387 // OK; tabId is optional, leave it default. |
388 return true; | 388 return true; |
389 case base::Value::TYPE_INTEGER: | 389 case base::Value::Type::INTEGER: |
390 CHECK(tab_id_value->GetAsInteger(&tab_id_)); | 390 CHECK(tab_id_value->GetAsInteger(&tab_id_)); |
391 return true; | 391 return true; |
392 default: | 392 default: |
393 // Boom. | 393 // Boom. |
394 return false; | 394 return false; |
395 } | 395 } |
396 } | 396 } |
397 // Not found; tabId is optional, leave it default. | 397 // Not found; tabId is optional, leave it default. |
398 break; | 398 break; |
399 } | 399 } |
400 | 400 |
401 case base::Value::TYPE_NULL: | 401 case base::Value::Type::NONE: |
402 // The tabId might be an optional argument. | 402 // The tabId might be an optional argument. |
403 break; | 403 break; |
404 | 404 |
405 default: | 405 default: |
406 return false; | 406 return false; |
407 } | 407 } |
408 | 408 |
409 return true; | 409 return true; |
410 } | 410 } |
411 | 411 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 NotifyChange(); | 495 NotifyChange(); |
496 return RespondNow(NoArguments()); | 496 return RespondNow(NoArguments()); |
497 } | 497 } |
498 | 498 |
499 ExtensionFunction::ResponseAction | 499 ExtensionFunction::ResponseAction |
500 ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() { | 500 ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() { |
501 EXTENSION_FUNCTION_VALIDATE(details_); | 501 EXTENSION_FUNCTION_VALIDATE(details_); |
502 base::Value* color_value = NULL; | 502 base::Value* color_value = NULL; |
503 EXTENSION_FUNCTION_VALIDATE(details_->Get("color", &color_value)); | 503 EXTENSION_FUNCTION_VALIDATE(details_->Get("color", &color_value)); |
504 SkColor color = 0; | 504 SkColor color = 0; |
505 if (color_value->IsType(base::Value::TYPE_LIST)) { | 505 if (color_value->IsType(base::Value::Type::LIST)) { |
506 base::ListValue* list = NULL; | 506 base::ListValue* list = NULL; |
507 EXTENSION_FUNCTION_VALIDATE(details_->GetList("color", &list)); | 507 EXTENSION_FUNCTION_VALIDATE(details_->GetList("color", &list)); |
508 EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); | 508 EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); |
509 | 509 |
510 int color_array[4] = {0}; | 510 int color_array[4] = {0}; |
511 for (size_t i = 0; i < arraysize(color_array); ++i) { | 511 for (size_t i = 0; i < arraysize(color_array); ++i) { |
512 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); | 512 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); |
513 } | 513 } |
514 | 514 |
515 color = SkColorSetARGB(color_array[3], color_array[0], | 515 color = SkColorSetARGB(color_array[3], color_array[0], |
516 color_array[1], color_array[2]); | 516 color_array[1], color_array[2]); |
517 } else if (color_value->IsType(base::Value::TYPE_STRING)) { | 517 } else if (color_value->IsType(base::Value::Type::STRING)) { |
518 std::string color_string; | 518 std::string color_string; |
519 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); | 519 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); |
520 if (!image_util::ParseCssColorString(color_string, &color)) | 520 if (!image_util::ParseCssColorString(color_string, &color)) |
521 return RespondNow(Error(kInvalidColorError)); | 521 return RespondNow(Error(kInvalidColorError)); |
522 } | 522 } |
523 | 523 |
524 extension_action_->SetBadgeBackgroundColor(tab_id_, color); | 524 extension_action_->SetBadgeBackgroundColor(tab_id_, color); |
525 NotifyChange(); | 525 NotifyChange(); |
526 return RespondNow(NoArguments()); | 526 return RespondNow(NoArguments()); |
527 } | 527 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 627 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
628 host->extension()->id() != extension_->id()) | 628 host->extension()->id() != extension_->id()) |
629 return; | 629 return; |
630 | 630 |
631 SendResponse(true); | 631 SendResponse(true); |
632 response_sent_ = true; | 632 response_sent_ = true; |
633 registrar_.RemoveAll(); | 633 registrar_.RemoveAll(); |
634 } | 634 } |
635 | 635 |
636 } // namespace extensions | 636 } // namespace extensions |
OLD | NEW |