Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1504)

Unified Diff: content/common/origin_util.cc

Issue 1101033003: Move IsOriginSecure() into //content and use it in ServiceWorker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added disallow copy/assign Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/origin_util.cc
diff --git a/content/common/origin_util.cc b/content/common/origin_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ae7bece7ec4dd58ad64fa523621d70e8ecb5429
--- /dev/null
+++ b/content/common/origin_util.cc
@@ -0,0 +1,62 @@
+// Copyright 2015 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 "content/public/common/origin_util.h"
+
+#include "base/lazy_instance.h"
+#include "base/stl_util.h"
+#include "content/public/common/content_client.h"
+#include "net/base/net_util.h"
+#include "url/gurl.h"
+
+namespace content {
+
+namespace {
+
+class SecureSchemeAndOriginSet {
+ public:
+ SecureSchemeAndOriginSet() { Reset(); }
+ ~SecureSchemeAndOriginSet() {}
+
+ void Reset() {
+ GetContentClient()->AddSecureSchemesAndOrigins(&schemes_, &origins_);
+ }
+
+ const std::set<std::string>& schemes() const { return schemes_; }
+ const std::set<GURL>& origins() const { return origins_; }
+
+ private:
+ std::set<std::string> schemes_;
+ std::set<GURL> origins_;
+ DISALLOW_COPY_AND_ASSIGN(SecureSchemeAndOriginSet);
+};
+
+base::LazyInstance<SecureSchemeAndOriginSet>::Leaky g_trustworthy_whitelist =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+bool IsOriginSecure(const GURL& url) {
+ if (url.SchemeIsCryptographic() || url.SchemeIsFile())
+ return true;
+
+ if (url.SchemeIsFileSystem() && url.inner_url() &&
+ IsOriginSecure(*url.inner_url())) {
+ return true;
+ }
+
+ std::string hostname = url.HostNoBrackets();
+ if (net::IsLocalhost(hostname))
+ return true;
+
+ if (ContainsKey(g_trustworthy_whitelist.Get().schemes(), url.scheme()))
+ return true;
+
+ if (ContainsKey(g_trustworthy_whitelist.Get().origins(), url.GetOrigin()))
+ return true;
+
+ return false;
+}
+
+} // namespace content
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.cc ('k') | content/common/origin_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698