| 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 "extensions/browser/api/web_request/web_request_api.h" | 5 #include "extensions/browser/api/web_request/web_request_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 case ExtensionWebRequestEventRouter::kOnAuthRequired: | 1612 case ExtensionWebRequestEventRouter::kOnAuthRequired: |
| 1613 return helpers::CalculateOnAuthRequiredDelta( | 1613 return helpers::CalculateOnAuthRequiredDelta( |
| 1614 response->extension_id, response->extension_install_time, | 1614 response->extension_id, response->extension_install_time, |
| 1615 response->cancel, &response->auth_credentials); | 1615 response->cancel, &response->auth_credentials); |
| 1616 default: | 1616 default: |
| 1617 NOTREACHED(); | 1617 NOTREACHED(); |
| 1618 return nullptr; | 1618 return nullptr; |
| 1619 } | 1619 } |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 base::Value* SerializeResponseHeaders(const helpers::ResponseHeaders& headers) { | 1622 std::unique_ptr<base::Value> SerializeResponseHeaders( |
| 1623 std::unique_ptr<base::ListValue> serialized_headers(new base::ListValue()); | 1623 const helpers::ResponseHeaders& headers) { |
| 1624 auto serialized_headers = base::MakeUnique<base::ListValue>(); |
| 1624 for (const auto& it : headers) { | 1625 for (const auto& it : headers) { |
| 1625 serialized_headers->Append( | 1626 serialized_headers->Append( |
| 1626 helpers::CreateHeaderDictionary(it.first, it.second)); | 1627 helpers::CreateHeaderDictionary(it.first, it.second)); |
| 1627 } | 1628 } |
| 1628 return serialized_headers.release(); | 1629 return std::move(serialized_headers); |
| 1629 } | 1630 } |
| 1630 | 1631 |
| 1631 // Convert a RequestCookieModifications/ResponseCookieModifications object to a | 1632 // Convert a RequestCookieModifications/ResponseCookieModifications object to a |
| 1632 // base::ListValue which summarizes the changes made. This is templated since | 1633 // base::ListValue which summarizes the changes made. This is templated since |
| 1633 // the two types (request/response) are different but contain essentially the | 1634 // the two types (request/response) are different but contain essentially the |
| 1634 // same fields. | 1635 // same fields. |
| 1635 template <typename CookieType> | 1636 template <typename CookieType> |
| 1636 base::ListValue* SummarizeCookieModifications( | 1637 std::unique_ptr<base::ListValue> SummarizeCookieModifications( |
| 1637 const std::vector<linked_ptr<CookieType>>& modifications) { | 1638 const std::vector<linked_ptr<CookieType>>& modifications) { |
| 1638 std::unique_ptr<base::ListValue> cookie_modifications(new base::ListValue()); | 1639 auto cookie_modifications = base::MakeUnique<base::ListValue>(); |
| 1639 for (const auto& it : modifications) { | 1640 for (const auto& it : modifications) { |
| 1640 std::unique_ptr<base::DictionaryValue> summary(new base::DictionaryValue()); | 1641 auto summary = base::MakeUnique<base::DictionaryValue>(); |
| 1641 const CookieType& mod = *(it.get()); | 1642 const CookieType& mod = *(it.get()); |
| 1642 switch (mod.type) { | 1643 switch (mod.type) { |
| 1643 case helpers::ADD: | 1644 case helpers::ADD: |
| 1644 summary->SetString(activity_log::kCookieModificationTypeKey, | 1645 summary->SetString(activity_log::kCookieModificationTypeKey, |
| 1645 activity_log::kCookieModificationAdd); | 1646 activity_log::kCookieModificationAdd); |
| 1646 break; | 1647 break; |
| 1647 case helpers::EDIT: | 1648 case helpers::EDIT: |
| 1648 summary->SetString(activity_log::kCookieModificationTypeKey, | 1649 summary->SetString(activity_log::kCookieModificationTypeKey, |
| 1649 activity_log::kCookieModificationEdit); | 1650 activity_log::kCookieModificationEdit); |
| 1650 break; | 1651 break; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1668 summary->SetString(activity_log::kCookieModDomainKey, | 1669 summary->SetString(activity_log::kCookieModDomainKey, |
| 1669 *mod.modification->name); | 1670 *mod.modification->name); |
| 1670 } | 1671 } |
| 1671 if (mod.modification->domain) { | 1672 if (mod.modification->domain) { |
| 1672 summary->SetString(activity_log::kCookieModDomainKey, | 1673 summary->SetString(activity_log::kCookieModDomainKey, |
| 1673 *mod.modification->name); | 1674 *mod.modification->name); |
| 1674 } | 1675 } |
| 1675 } | 1676 } |
| 1676 cookie_modifications->Append(std::move(summary)); | 1677 cookie_modifications->Append(std::move(summary)); |
| 1677 } | 1678 } |
| 1678 return cookie_modifications.release(); | 1679 return cookie_modifications; |
| 1679 } | 1680 } |
| 1680 | 1681 |
| 1681 // Converts an EventResponseDelta object to a dictionary value suitable for the | 1682 // Converts an EventResponseDelta object to a dictionary value suitable for the |
| 1682 // activity log. | 1683 // activity log. |
| 1683 std::unique_ptr<base::DictionaryValue> SummarizeResponseDelta( | 1684 std::unique_ptr<base::DictionaryValue> SummarizeResponseDelta( |
| 1684 const std::string& event_name, | 1685 const std::string& event_name, |
| 1685 const helpers::EventResponseDelta& delta) { | 1686 const helpers::EventResponseDelta& delta) { |
| 1686 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); | 1687 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue()); |
| 1687 if (delta.cancel) | 1688 if (delta.cancel) |
| 1688 details->SetBoolean(activity_log::kCancelKey, true); | 1689 details->SetBoolean(activity_log::kCancelKey, true); |
| 1689 if (!delta.new_url.is_empty()) | 1690 if (!delta.new_url.is_empty()) |
| 1690 details->SetString(activity_log::kNewUrlKey, delta.new_url.spec()); | 1691 details->SetString(activity_log::kNewUrlKey, delta.new_url.spec()); |
| 1691 | 1692 |
| 1692 std::unique_ptr<base::ListValue> modified_headers(new base::ListValue()); | 1693 std::unique_ptr<base::ListValue> modified_headers(new base::ListValue()); |
| 1693 net::HttpRequestHeaders::Iterator iter(delta.modified_request_headers); | 1694 net::HttpRequestHeaders::Iterator iter(delta.modified_request_headers); |
| 1694 while (iter.GetNext()) { | 1695 while (iter.GetNext()) { |
| 1695 modified_headers->Append( | 1696 modified_headers->Append( |
| 1696 helpers::CreateHeaderDictionary(iter.name(), iter.value())); | 1697 helpers::CreateHeaderDictionary(iter.name(), iter.value())); |
| 1697 } | 1698 } |
| 1698 if (!modified_headers->empty()) { | 1699 if (!modified_headers->empty()) { |
| 1699 details->Set(activity_log::kModifiedRequestHeadersKey, | 1700 details->Set(activity_log::kModifiedRequestHeadersKey, |
| 1700 modified_headers.release()); | 1701 std::move(modified_headers)); |
| 1701 } | 1702 } |
| 1702 | 1703 |
| 1703 std::unique_ptr<base::ListValue> deleted_headers(new base::ListValue()); | 1704 std::unique_ptr<base::ListValue> deleted_headers(new base::ListValue()); |
| 1704 deleted_headers->AppendStrings(delta.deleted_request_headers); | 1705 deleted_headers->AppendStrings(delta.deleted_request_headers); |
| 1705 if (!deleted_headers->empty()) { | 1706 if (!deleted_headers->empty()) { |
| 1706 details->Set(activity_log::kDeletedRequestHeadersKey, | 1707 details->Set(activity_log::kDeletedRequestHeadersKey, |
| 1707 deleted_headers.release()); | 1708 std::move(deleted_headers)); |
| 1708 } | 1709 } |
| 1709 | 1710 |
| 1710 if (!delta.added_response_headers.empty()) { | 1711 if (!delta.added_response_headers.empty()) { |
| 1711 details->Set(activity_log::kAddedRequestHeadersKey, | 1712 details->Set(activity_log::kAddedRequestHeadersKey, |
| 1712 SerializeResponseHeaders(delta.added_response_headers)); | 1713 SerializeResponseHeaders(delta.added_response_headers)); |
| 1713 } | 1714 } |
| 1714 if (!delta.deleted_response_headers.empty()) { | 1715 if (!delta.deleted_response_headers.empty()) { |
| 1715 details->Set(activity_log::kDeletedResponseHeadersKey, | 1716 details->Set(activity_log::kDeletedResponseHeadersKey, |
| 1716 SerializeResponseHeaders(delta.deleted_response_headers)); | 1717 SerializeResponseHeaders(delta.deleted_response_headers)); |
| 1717 } | 1718 } |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2444 // Since EventListeners are segmented by browser_context, check that | 2445 // Since EventListeners are segmented by browser_context, check that |
| 2445 // last, as it is exceedingly unlikely to be different. | 2446 // last, as it is exceedingly unlikely to be different. |
| 2446 return extension_id == that.extension_id && | 2447 return extension_id == that.extension_id && |
| 2447 sub_event_name == that.sub_event_name && | 2448 sub_event_name == that.sub_event_name && |
| 2448 web_view_instance_id == that.web_view_instance_id && | 2449 web_view_instance_id == that.web_view_instance_id && |
| 2449 embedder_process_id == that.embedder_process_id && | 2450 embedder_process_id == that.embedder_process_id && |
| 2450 browser_context == that.browser_context; | 2451 browser_context == that.browser_context; |
| 2451 } | 2452 } |
| 2452 | 2453 |
| 2453 } // namespace extensions | 2454 } // namespace extensions |
| OLD | NEW |