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