Chromium Code Reviews| Index: chrome/renderer/app_categorizer.cc |
| diff --git a/chrome/renderer/app_categorizer.cc b/chrome/renderer/app_categorizer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b82b2415c4438b6d08e721ec77a057fab7eb3dc3 |
| --- /dev/null |
| +++ b/chrome/renderer/app_categorizer.cc |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/renderer/app_categorizer.h" |
| + |
| +#include "base/macros.h" |
| +#include "base/strings/string_util.h" |
| +#include "url/gurl.h" |
| + |
| +namespace { |
| +// Note: all domain names here must be in lowercase (see GURL::DomainIs, which |
| +// properly handles sub-domains). |
| + |
| +const char* const kPredefinedHangoutsDomains[] = { |
| + "hangouts.google.com", |
| + "meet.google.com", |
| + "talkgadget.google.com", |
| + "plus.google.com", |
| + "plus.sandbox.google.com" |
| +}; |
| + |
| +const char* const kPredefinedPlusDomains[] = { |
| + "plus.google.com", |
| + "plus.sandbox.google.com" |
| +}; |
| + |
| +bool isInWhitelistedDomain( |
|
sky
2016/05/20 19:21:42
is->Is
AlexZ
2016/05/20 20:30:54
Done.
|
| + 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.
|
| + for (size_t i = 0; i < numberOfDomains; ++i) { |
| + if (url.DomainIs(domains[i])) { |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace app_categorizer { |
| +// Whitelisted apps must be served over https. |
| + |
| +bool IsHangoutsUrl(const GURL& url) { |
| + return url.SchemeIsCryptographic() && |
| + base::StartsWith(url.path(), "/hangouts/", |
| + base::CompareCase::INSENSITIVE_ASCII) && |
| + isInWhitelistedDomain( |
| + url, |
| + kPredefinedHangoutsDomains, |
| + arraysize(kPredefinedHangoutsDomains)); |
| +} |
| + |
| +bool IsWhitelistedApp(const GURL& manifest_url, const GURL& app_url) { |
| + if (!app_url.SchemeIsCryptographic()) |
| + return false; |
| + |
| + std::string manifest_url_path = manifest_url.path(); |
| + bool is_photo_app = |
| + manifest_url.SchemeIsCryptographic() && |
| + manifest_url.DomainIs("ssl.gstatic.com") && |
| + (base::StartsWith(manifest_url_path, "/s2/oz/nacl/", |
| + base::CompareCase::SENSITIVE) || |
| + base::StartsWith(manifest_url_path, "/photos/nacl/", |
| + base::CompareCase::SENSITIVE)) && |
| + isInWhitelistedDomain( |
| + app_url, |
| + kPredefinedPlusDomains, |
| + arraysize(kPredefinedPlusDomains)); |
| + |
| + bool is_hangouts_app = |
| + manifest_url.SchemeIsFileSystem() && |
| + manifest_url.inner_url() != NULL && |
| + manifest_url.inner_url()->SchemeIsCryptographic() && |
| + // The manifest must be loaded from the host's FileSystem. |
| + (manifest_url.inner_url()->host() == app_url.host()) && |
| + IsHangoutsUrl(app_url); |
| + |
| + return is_photo_app || is_hangouts_app; |
| +} |
| + |
| +} // namespace app_categorizer |