| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/extension_action_manager.h" | 18 #include "chrome/browser/extensions/extension_action_manager.h" |
| 18 #include "chrome/browser/extensions/extension_action_runner.h" | 19 #include "chrome/browser/extensions/extension_action_runner.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return false; | 524 return false; |
| 524 } | 525 } |
| 525 } | 526 } |
| 526 | 527 |
| 527 extension_action_->SetBadgeBackgroundColor(tab_id_, color); | 528 extension_action_->SetBadgeBackgroundColor(tab_id_, color); |
| 528 NotifyChange(); | 529 NotifyChange(); |
| 529 return true; | 530 return true; |
| 530 } | 531 } |
| 531 | 532 |
| 532 bool ExtensionActionGetTitleFunction::RunExtensionAction() { | 533 bool ExtensionActionGetTitleFunction::RunExtensionAction() { |
| 533 SetResult(new base::StringValue(extension_action_->GetTitle(tab_id_))); | 534 SetResult(base::MakeUnique<base::StringValue>( |
| 535 extension_action_->GetTitle(tab_id_))); |
| 534 return true; | 536 return true; |
| 535 } | 537 } |
| 536 | 538 |
| 537 bool ExtensionActionGetPopupFunction::RunExtensionAction() { | 539 bool ExtensionActionGetPopupFunction::RunExtensionAction() { |
| 538 SetResult( | 540 SetResult(base::MakeUnique<base::StringValue>( |
| 539 new base::StringValue(extension_action_->GetPopupUrl(tab_id_).spec())); | 541 extension_action_->GetPopupUrl(tab_id_).spec())); |
| 540 return true; | 542 return true; |
| 541 } | 543 } |
| 542 | 544 |
| 543 bool ExtensionActionGetBadgeTextFunction::RunExtensionAction() { | 545 bool ExtensionActionGetBadgeTextFunction::RunExtensionAction() { |
| 544 SetResult(new base::StringValue(extension_action_->GetBadgeText(tab_id_))); | 546 SetResult(base::MakeUnique<base::StringValue>( |
| 547 extension_action_->GetBadgeText(tab_id_))); |
| 545 return true; | 548 return true; |
| 546 } | 549 } |
| 547 | 550 |
| 548 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 551 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
| 549 base::ListValue* list = new base::ListValue(); | 552 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 550 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 553 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
| 551 list->Append( | 554 list->Append( |
| 552 new base::FundamentalValue(static_cast<int>(SkColorGetR(color)))); | 555 new base::FundamentalValue(static_cast<int>(SkColorGetR(color)))); |
| 553 list->Append( | 556 list->Append( |
| 554 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); | 557 new base::FundamentalValue(static_cast<int>(SkColorGetG(color)))); |
| 555 list->Append( | 558 list->Append( |
| 556 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); | 559 new base::FundamentalValue(static_cast<int>(SkColorGetB(color)))); |
| 557 list->Append( | 560 list->Append( |
| 558 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); | 561 new base::FundamentalValue(static_cast<int>(SkColorGetA(color)))); |
| 559 SetResult(list); | 562 SetResult(std::move(list)); |
| 560 return true; | 563 return true; |
| 561 } | 564 } |
| 562 | 565 |
| 563 BrowserActionOpenPopupFunction::BrowserActionOpenPopupFunction() | 566 BrowserActionOpenPopupFunction::BrowserActionOpenPopupFunction() |
| 564 : response_sent_(false) { | 567 : response_sent_(false) { |
| 565 } | 568 } |
| 566 | 569 |
| 567 bool BrowserActionOpenPopupFunction::RunAsync() { | 570 bool BrowserActionOpenPopupFunction::RunAsync() { |
| 568 // We only allow the popup in the active window. | 571 // We only allow the popup in the active window. |
| 569 Profile* profile = GetProfile(); | 572 Profile* profile = GetProfile(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 635 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
| 633 host->extension()->id() != extension_->id()) | 636 host->extension()->id() != extension_->id()) |
| 634 return; | 637 return; |
| 635 | 638 |
| 636 SendResponse(true); | 639 SendResponse(true); |
| 637 response_sent_ = true; | 640 response_sent_ = true; |
| 638 registrar_.RemoveAll(); | 641 registrar_.RemoveAll(); |
| 639 } | 642 } |
| 640 | 643 |
| 641 } // namespace extensions | 644 } // namespace extensions |
| OLD | NEW |