Secure contexts: remove user-data-dir requirement.

Requiring developers to create a new profile in order to debug features
that need secure contexts is overkill. Let's loosen that requirement.

Bug: 757631
Change-Id: Ic8edf5172f11f6e2bdff94b9d45b1bd9fbbacf7d
Reviewed-on: https://chromium-review.googlesource.com/625094
Reviewed-by: Steven Holte <holte@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Emily Stark <estark@chromium.org>
Commit-Queue: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#497417}
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 31707c6..78eef16 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -727,10 +727,10 @@
 const char kUnlimitedStorage[]              = "unlimited-storage";
 
 // Treat given (insecure) origins as secure origins. Multiple origins can be
-// supplied. Has no effect unless --user-data-dir is also supplied.
+// supplied as a comma-separated list.
+//
 // Example:
 // --unsafely-treat-insecure-origin-as-secure=http://a.test,http://b.test
-// --user-data-dir=/test/only/profile/dir
 const char kUnsafelyTreatInsecureOriginAsSecure[] =
     "unsafely-treat-insecure-origin-as-secure";
 
diff --git a/chrome/common/secure_origin_whitelist.cc b/chrome/common/secure_origin_whitelist.cc
index 6d35beb..6d34b1e 100644
--- a/chrome/common/secure_origin_whitelist.cc
+++ b/chrome/common/secure_origin_whitelist.cc
@@ -5,19 +5,18 @@
 #include "chrome/common/secure_origin_whitelist.h"
 
 #include "base/command_line.h"
+#include "base/metrics/histogram_macros.h"
 #include "base/strings/string_split.h"
 #include "chrome/common/chrome_switches.h"
 #include "extensions/common/constants.h"
 
 std::vector<GURL> GetSecureOriginWhitelist() {
   std::vector<GURL> origins;
-  // If kUnsafelyTreatInsecureOriginAsSecure option is given and
-  // kUserDataDir is present, add the given origins as trustworthy
-  // for whitelisting.
+  // If kUnsafelyTreatInsecureOriginAsSecure option is given, then treat the
+  // value as a comma-separated list of origins:
   const base::CommandLine& command_line =
       *base::CommandLine::ForCurrentProcess();
-  if (command_line.HasSwitch(switches::kUnsafelyTreatInsecureOriginAsSecure) &&
-      command_line.HasSwitch(switches::kUserDataDir)) {
+  if (command_line.HasSwitch(switches::kUnsafelyTreatInsecureOriginAsSecure)) {
     std::string origins_str = command_line.GetSwitchValueASCII(
         switches::kUnsafelyTreatInsecureOriginAsSecure);
     for (const std::string& origin : base::SplitString(
@@ -25,6 +24,9 @@
       origins.push_back(GURL(origin));
   }
 
+  UMA_HISTOGRAM_COUNTS_100("Security.TreatInsecureOriginAsSecure",
+                           origins.size());
+
   return origins;
 }
 
diff --git a/chrome/common/secure_origin_whitelist_unittest.cc b/chrome/common/secure_origin_whitelist_unittest.cc
index 1c8e175..3293c97 100644
--- a/chrome/common/secure_origin_whitelist_unittest.cc
+++ b/chrome/common/secure_origin_whitelist_unittest.cc
@@ -34,7 +34,6 @@
   command_line->AppendSwitchASCII(
       switches::kUnsafelyTreatInsecureOriginAsSecure,
       "http://example.com,http://127.example.com");
-  command_line->AppendSwitch(switches::kUserDataDir);
   content::ResetSchemesAndOriginsWhitelist();
 
   // They should be now white-listed.
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index ae737ba..11cc435 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -71482,6 +71482,15 @@
   </summary>
 </histogram>
 
+<histogram name="Security.TreatInsecureOriginAsSecure">
+  <owner>mkwst@chromium.org</owner>
+  <summary>
+    Records the number of origins which will be treated as secure based on their
+    presence in the '--unsafely-treat-insecure-origin-as-secure' command-line
+    flag.
+  </summary>
+</histogram>
+
 <histogram name="Security.XFrameOptions" enum="XFrameOptions">
   <owner>mkwst@chromium.org</owner>
   <owner>arthursonzogni@chromium.org</owner>