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