Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/app_categorizer.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "url/gurl.h" | |
| 10 | |
| 11 namespace { | |
| 12 // Note: all domain names here must be in lowercase (see GURL::DomainIs, which | |
| 13 // properly handles sub-domains). | |
| 14 | |
| 15 const char* const kPredefinedHangoutsDomains[] = { | |
| 16 "hangouts.google.com", | |
| 17 "meet.google.com", | |
| 18 "talkgadget.google.com", | |
| 19 "plus.google.com", | |
| 20 "plus.sandbox.google.com" | |
| 21 }; | |
| 22 | |
| 23 const char* const kPredefinedPlusDomains[] = { | |
| 24 "plus.google.com", | |
| 25 "plus.sandbox.google.com" | |
| 26 }; | |
| 27 | |
| 28 bool isInWhitelistedDomain( | |
|
sky
2016/05/20 19:21:42
is->Is
AlexZ
2016/05/20 20:30:54
Done.
| |
| 29 const GURL& url, const char* const domains[], size_t numberOfDomains) { | |
|
sky
2016/05/20 19:21:42
number_of_domains
AlexZ
2016/05/20 20:30:54
Done.
| |
| 30 for (size_t i = 0; i < numberOfDomains; ++i) { | |
| 31 if (url.DomainIs(domains[i])) { | |
| 32 return true; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 return false; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 namespace app_categorizer { | |
| 42 // Whitelisted apps must be served over https. | |
| 43 | |
| 44 bool IsHangoutsUrl(const GURL& url) { | |
| 45 return url.SchemeIsCryptographic() && | |
| 46 base::StartsWith(url.path(), "/hangouts/", | |
| 47 base::CompareCase::INSENSITIVE_ASCII) && | |
| 48 isInWhitelistedDomain( | |
| 49 url, | |
| 50 kPredefinedHangoutsDomains, | |
| 51 arraysize(kPredefinedHangoutsDomains)); | |
| 52 } | |
| 53 | |
| 54 bool IsWhitelistedApp(const GURL& manifest_url, const GURL& app_url) { | |
| 55 if (!app_url.SchemeIsCryptographic()) | |
| 56 return false; | |
| 57 | |
| 58 std::string manifest_url_path = manifest_url.path(); | |
| 59 bool is_photo_app = | |
| 60 manifest_url.SchemeIsCryptographic() && | |
| 61 manifest_url.DomainIs("ssl.gstatic.com") && | |
| 62 (base::StartsWith(manifest_url_path, "/s2/oz/nacl/", | |
| 63 base::CompareCase::SENSITIVE) || | |
| 64 base::StartsWith(manifest_url_path, "/photos/nacl/", | |
| 65 base::CompareCase::SENSITIVE)) && | |
| 66 isInWhitelistedDomain( | |
| 67 app_url, | |
| 68 kPredefinedPlusDomains, | |
| 69 arraysize(kPredefinedPlusDomains)); | |
| 70 | |
| 71 bool is_hangouts_app = | |
| 72 manifest_url.SchemeIsFileSystem() && | |
| 73 manifest_url.inner_url() != NULL && | |
| 74 manifest_url.inner_url()->SchemeIsCryptographic() && | |
| 75 // The manifest must be loaded from the host's FileSystem. | |
| 76 (manifest_url.inner_url()->host() == app_url.host()) && | |
| 77 IsHangoutsUrl(app_url); | |
| 78 | |
| 79 return is_photo_app || is_hangouts_app; | |
| 80 } | |
| 81 | |
| 82 } // namespace app_categorizer | |
| OLD | NEW |