| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cryptotoken_private/cryptotoken_private_
api.h" | 5 #include "chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_
api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( | 35 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( |
| 36 "Security origin * is not a valid URL", params->security_origin))); | 36 "Security origin * is not a valid URL", params->security_origin))); |
| 37 } | 37 } |
| 38 const GURL app_id_url(params->app_id_url); | 38 const GURL app_id_url(params->app_id_url); |
| 39 if (!app_id_url.is_valid()) { | 39 if (!app_id_url.is_valid()) { |
| 40 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( | 40 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( |
| 41 "appId * is not a valid URL", params->app_id_url))); | 41 "appId * is not a valid URL", params->app_id_url))); |
| 42 } | 42 } |
| 43 | 43 |
| 44 if (origin_url == app_id_url) { | 44 if (origin_url == app_id_url) { |
| 45 return RespondNow( | 45 return RespondNow(OneArgument(base::MakeUnique<base::Value>(true))); |
| 46 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
| 47 } | 46 } |
| 48 | 47 |
| 49 // Fetch the eTLD+1 of both. | 48 // Fetch the eTLD+1 of both. |
| 50 const std::string origin_etldp1 = | 49 const std::string origin_etldp1 = |
| 51 net::registry_controlled_domains::GetDomainAndRegistry( | 50 net::registry_controlled_domains::GetDomainAndRegistry( |
| 52 origin_url, | 51 origin_url, |
| 53 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 52 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 54 if (origin_etldp1.empty()) { | 53 if (origin_etldp1.empty()) { |
| 55 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( | 54 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( |
| 56 "Could not find an eTLD for origin *", params->security_origin))); | 55 "Could not find an eTLD for origin *", params->security_origin))); |
| 57 } | 56 } |
| 58 const std::string app_id_etldp1 = | 57 const std::string app_id_etldp1 = |
| 59 net::registry_controlled_domains::GetDomainAndRegistry( | 58 net::registry_controlled_domains::GetDomainAndRegistry( |
| 60 app_id_url, | 59 app_id_url, |
| 61 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 60 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 62 if (app_id_etldp1.empty()) { | 61 if (app_id_etldp1.empty()) { |
| 63 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( | 62 return RespondNow(Error(extensions::ErrorUtils::FormatErrorMessage( |
| 64 "Could not find an eTLD for appId *", params->app_id_url))); | 63 "Could not find an eTLD for appId *", params->app_id_url))); |
| 65 } | 64 } |
| 66 if (origin_etldp1 == app_id_etldp1) { | 65 if (origin_etldp1 == app_id_etldp1) { |
| 67 return RespondNow( | 66 return RespondNow(OneArgument(base::MakeUnique<base::Value>(true))); |
| 68 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
| 69 } | 67 } |
| 70 // For legacy purposes, allow google.com origins to assert certain | 68 // For legacy purposes, allow google.com origins to assert certain |
| 71 // gstatic.com appIds. | 69 // gstatic.com appIds. |
| 72 // TODO(juanlang): remove when legacy constraints are removed. | 70 // TODO(juanlang): remove when legacy constraints are removed. |
| 73 if (origin_etldp1 == kGoogleDotCom) { | 71 if (origin_etldp1 == kGoogleDotCom) { |
| 74 for (size_t i = 0; | 72 for (size_t i = 0; |
| 75 i < sizeof(kGoogleGstaticAppIds) / sizeof(kGoogleGstaticAppIds[0]); | 73 i < sizeof(kGoogleGstaticAppIds) / sizeof(kGoogleGstaticAppIds[0]); |
| 76 i++) { | 74 i++) { |
| 77 if (params->app_id_url == kGoogleGstaticAppIds[i]) { | 75 if (params->app_id_url == kGoogleGstaticAppIds[i]) { |
| 78 return RespondNow( | 76 return RespondNow(OneArgument(base::MakeUnique<base::Value>(true))); |
| 79 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
| 80 } | 77 } |
| 81 } | 78 } |
| 82 } | 79 } |
| 83 return RespondNow( | 80 return RespondNow(OneArgument(base::MakeUnique<base::Value>(false))); |
| 84 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | |
| 85 } | 81 } |
| 86 | 82 |
| 87 } // namespace api | 83 } // namespace api |
| 88 } // namespace extensions | 84 } // namespace extensions |
| OLD | NEW |