| 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void ExtensionActionAPI::DispatchOldPageActionEvent( | 339 void ExtensionActionAPI::DispatchOldPageActionEvent( |
| 340 Profile* profile, | 340 Profile* profile, |
| 341 const std::string& extension_id, | 341 const std::string& extension_id, |
| 342 const std::string& page_action_id, | 342 const std::string& page_action_id, |
| 343 int tab_id, | 343 int tab_id, |
| 344 const std::string& url, | 344 const std::string& url, |
| 345 int button) { | 345 int button) { |
| 346 scoped_ptr<base::ListValue> args(new base::ListValue()); | 346 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 347 args->Append(new base::StringValue(page_action_id)); | 347 args->Append(new base::StringValue(page_action_id)); |
| 348 | 348 |
| 349 DictionaryValue* data = new DictionaryValue(); | 349 base::DictionaryValue* data = new base::DictionaryValue(); |
| 350 data->Set(page_actions_keys::kTabIdKey, new base::FundamentalValue(tab_id)); | 350 data->Set(page_actions_keys::kTabIdKey, new base::FundamentalValue(tab_id)); |
| 351 data->Set(page_actions_keys::kTabUrlKey, new base::StringValue(url)); | 351 data->Set(page_actions_keys::kTabUrlKey, new base::StringValue(url)); |
| 352 data->Set(page_actions_keys::kButtonKey, | 352 data->Set(page_actions_keys::kButtonKey, |
| 353 new base::FundamentalValue(button)); | 353 new base::FundamentalValue(button)); |
| 354 args->Append(data); | 354 args->Append(data); |
| 355 | 355 |
| 356 DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass()); | 356 DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass()); |
| 357 } | 357 } |
| 358 | 358 |
| 359 // static | 359 // static |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 case ActionInfo::TYPE_SCRIPT_BADGE: | 372 case ActionInfo::TYPE_SCRIPT_BADGE: |
| 373 event_name = "scriptBadge.onClicked"; | 373 event_name = "scriptBadge.onClicked"; |
| 374 break; | 374 break; |
| 375 case ActionInfo::TYPE_SYSTEM_INDICATOR: | 375 case ActionInfo::TYPE_SYSTEM_INDICATOR: |
| 376 // The System Indicator handles its own clicks. | 376 // The System Indicator handles its own clicks. |
| 377 break; | 377 break; |
| 378 } | 378 } |
| 379 | 379 |
| 380 if (event_name) { | 380 if (event_name) { |
| 381 scoped_ptr<base::ListValue> args(new base::ListValue()); | 381 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 382 DictionaryValue* tab_value = extensions::ExtensionTabUtil::CreateTabValue( | 382 base::DictionaryValue* tab_value = |
| 383 web_contents); | 383 extensions::ExtensionTabUtil::CreateTabValue(web_contents); |
| 384 args->Append(tab_value); | 384 args->Append(tab_value); |
| 385 | 385 |
| 386 DispatchEventToExtension(profile, | 386 DispatchEventToExtension(profile, |
| 387 extension_action.extension_id(), | 387 extension_action.extension_id(), |
| 388 event_name, | 388 event_name, |
| 389 args.Pass()); | 389 args.Pass()); |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 // | 393 // |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 bool ExtensionActionFunction::ExtractDataFromArguments() { | 551 bool ExtensionActionFunction::ExtractDataFromArguments() { |
| 552 // There may or may not be details (depends on the function). | 552 // There may or may not be details (depends on the function). |
| 553 // The tabId might appear in details (if it exists), as the first | 553 // The tabId might appear in details (if it exists), as the first |
| 554 // argument besides the action type (depends on the function), or be omitted | 554 // argument besides the action type (depends on the function), or be omitted |
| 555 // entirely. | 555 // entirely. |
| 556 base::Value* first_arg = NULL; | 556 base::Value* first_arg = NULL; |
| 557 if (!args_->Get(0, &first_arg)) | 557 if (!args_->Get(0, &first_arg)) |
| 558 return true; | 558 return true; |
| 559 | 559 |
| 560 switch (first_arg->GetType()) { | 560 switch (first_arg->GetType()) { |
| 561 case Value::TYPE_INTEGER: | 561 case base::Value::TYPE_INTEGER: |
| 562 CHECK(first_arg->GetAsInteger(&tab_id_)); | 562 CHECK(first_arg->GetAsInteger(&tab_id_)); |
| 563 break; | 563 break; |
| 564 | 564 |
| 565 case Value::TYPE_DICTIONARY: { | 565 case base::Value::TYPE_DICTIONARY: { |
| 566 // Found the details argument. | 566 // Found the details argument. |
| 567 details_ = static_cast<base::DictionaryValue*>(first_arg); | 567 details_ = static_cast<base::DictionaryValue*>(first_arg); |
| 568 // Still need to check for the tabId within details. | 568 // Still need to check for the tabId within details. |
| 569 base::Value* tab_id_value = NULL; | 569 base::Value* tab_id_value = NULL; |
| 570 if (details_->Get("tabId", &tab_id_value)) { | 570 if (details_->Get("tabId", &tab_id_value)) { |
| 571 switch (tab_id_value->GetType()) { | 571 switch (tab_id_value->GetType()) { |
| 572 case Value::TYPE_NULL: | 572 case base::Value::TYPE_NULL: |
| 573 // OK; tabId is optional, leave it default. | 573 // OK; tabId is optional, leave it default. |
| 574 return true; | 574 return true; |
| 575 case Value::TYPE_INTEGER: | 575 case base::Value::TYPE_INTEGER: |
| 576 CHECK(tab_id_value->GetAsInteger(&tab_id_)); | 576 CHECK(tab_id_value->GetAsInteger(&tab_id_)); |
| 577 return true; | 577 return true; |
| 578 default: | 578 default: |
| 579 // Boom. | 579 // Boom. |
| 580 return false; | 580 return false; |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 // Not found; tabId is optional, leave it default. | 583 // Not found; tabId is optional, leave it default. |
| 584 break; | 584 break; |
| 585 } | 585 } |
| 586 | 586 |
| 587 case Value::TYPE_NULL: | 587 case base::Value::TYPE_NULL: |
| 588 // The tabId might be an optional argument. | 588 // The tabId might be an optional argument. |
| 589 break; | 589 break; |
| 590 | 590 |
| 591 default: | 591 default: |
| 592 return false; | 592 return false; |
| 593 } | 593 } |
| 594 | 594 |
| 595 return true; | 595 return true; |
| 596 } | 596 } |
| 597 | 597 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 EXTENSION_FUNCTION_VALIDATE(details_); | 756 EXTENSION_FUNCTION_VALIDATE(details_); |
| 757 std::string badge_text; | 757 std::string badge_text; |
| 758 EXTENSION_FUNCTION_VALIDATE(details_->GetString("text", &badge_text)); | 758 EXTENSION_FUNCTION_VALIDATE(details_->GetString("text", &badge_text)); |
| 759 extension_action_->SetBadgeText(tab_id_, badge_text); | 759 extension_action_->SetBadgeText(tab_id_, badge_text); |
| 760 NotifyChange(); | 760 NotifyChange(); |
| 761 return true; | 761 return true; |
| 762 } | 762 } |
| 763 | 763 |
| 764 bool ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() { | 764 bool ExtensionActionSetBadgeBackgroundColorFunction::RunExtensionAction() { |
| 765 EXTENSION_FUNCTION_VALIDATE(details_); | 765 EXTENSION_FUNCTION_VALIDATE(details_); |
| 766 Value* color_value = NULL; | 766 base::Value* color_value = NULL; |
| 767 EXTENSION_FUNCTION_VALIDATE(details_->Get("color", &color_value)); | 767 EXTENSION_FUNCTION_VALIDATE(details_->Get("color", &color_value)); |
| 768 SkColor color = 0; | 768 SkColor color = 0; |
| 769 if (color_value->IsType(Value::TYPE_LIST)) { | 769 if (color_value->IsType(base::Value::TYPE_LIST)) { |
| 770 base::ListValue* list = NULL; | 770 base::ListValue* list = NULL; |
| 771 EXTENSION_FUNCTION_VALIDATE(details_->GetList("color", &list)); | 771 EXTENSION_FUNCTION_VALIDATE(details_->GetList("color", &list)); |
| 772 EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); | 772 EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); |
| 773 | 773 |
| 774 int color_array[4] = {0}; | 774 int color_array[4] = {0}; |
| 775 for (size_t i = 0; i < arraysize(color_array); ++i) { | 775 for (size_t i = 0; i < arraysize(color_array); ++i) { |
| 776 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); | 776 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i])); |
| 777 } | 777 } |
| 778 | 778 |
| 779 color = SkColorSetARGB(color_array[3], color_array[0], | 779 color = SkColorSetARGB(color_array[3], color_array[0], |
| 780 color_array[1], color_array[2]); | 780 color_array[1], color_array[2]); |
| 781 } else if (color_value->IsType(Value::TYPE_STRING)) { | 781 } else if (color_value->IsType(base::Value::TYPE_STRING)) { |
| 782 std::string color_string; | 782 std::string color_string; |
| 783 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); | 783 EXTENSION_FUNCTION_VALIDATE(details_->GetString("color", &color_string)); |
| 784 if (!ParseCSSColorString(color_string, &color)) | 784 if (!ParseCSSColorString(color_string, &color)) |
| 785 return false; | 785 return false; |
| 786 } | 786 } |
| 787 | 787 |
| 788 extension_action_->SetBadgeBackgroundColor(tab_id_, color); | 788 extension_action_->SetBadgeBackgroundColor(tab_id_, color); |
| 789 NotifyChange(); | 789 NotifyChange(); |
| 790 return true; | 790 return true; |
| 791 } | 791 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 899 |
| 900 PageActionsFunction::PageActionsFunction() { | 900 PageActionsFunction::PageActionsFunction() { |
| 901 } | 901 } |
| 902 | 902 |
| 903 PageActionsFunction::~PageActionsFunction() { | 903 PageActionsFunction::~PageActionsFunction() { |
| 904 } | 904 } |
| 905 | 905 |
| 906 bool PageActionsFunction::SetPageActionEnabled(bool enable) { | 906 bool PageActionsFunction::SetPageActionEnabled(bool enable) { |
| 907 std::string extension_action_id; | 907 std::string extension_action_id; |
| 908 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id)); | 908 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_action_id)); |
| 909 DictionaryValue* action = NULL; | 909 base::DictionaryValue* action = NULL; |
| 910 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action)); | 910 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action)); |
| 911 | 911 |
| 912 int tab_id; | 912 int tab_id; |
| 913 EXTENSION_FUNCTION_VALIDATE(action->GetInteger( | 913 EXTENSION_FUNCTION_VALIDATE(action->GetInteger( |
| 914 page_actions_keys::kTabIdKey, &tab_id)); | 914 page_actions_keys::kTabIdKey, &tab_id)); |
| 915 std::string url; | 915 std::string url; |
| 916 EXTENSION_FUNCTION_VALIDATE(action->GetString( | 916 EXTENSION_FUNCTION_VALIDATE(action->GetString( |
| 917 page_actions_keys::kUrlKey, &url)); | 917 page_actions_keys::kUrlKey, &url)); |
| 918 | 918 |
| 919 std::string title; | 919 std::string title; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 return true; | 958 return true; |
| 959 } | 959 } |
| 960 | 960 |
| 961 bool EnablePageActionsFunction::RunImpl() { | 961 bool EnablePageActionsFunction::RunImpl() { |
| 962 return SetPageActionEnabled(true); | 962 return SetPageActionEnabled(true); |
| 963 } | 963 } |
| 964 | 964 |
| 965 bool DisablePageActionsFunction::RunImpl() { | 965 bool DisablePageActionsFunction::RunImpl() { |
| 966 return SetPageActionEnabled(false); | 966 return SetPageActionEnabled(false); |
| 967 } | 967 } |
| OLD | NEW |