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

Side by Side Diff: third_party/WebKit/Source/core/experiments/Experiments.cpp

Issue 1541983003: Force all experiment enabled checks to use ExperimentalFeatures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix link error under GN and rename entry method Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/experiments/Experiments.h" 5 #include "core/experiments/Experiments.h"
6 6
7 #include "core/dom/ElementTraversal.h" 7 #include "core/dom/ElementTraversal.h"
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/html/HTMLHeadElement.h" 9 #include "core/html/HTMLHeadElement.h"
10 #include "core/html/HTMLMetaElement.h" 10 #include "core/html/HTMLMetaElement.h"
(...skipping 10 matching lines...) Expand all
21 { 21 {
22 return executionContext->securityOrigin()->toString(); 22 return executionContext->securityOrigin()->toString();
23 } 23 }
24 24
25 String getDisabledMessage(const String& apiName) 25 String getDisabledMessage(const String& apiName)
26 { 26 {
27 // TODO(chasej): Update message with URL to experiments site, when live 27 // TODO(chasej): Update message with URL to experiments site, when live
28 return "The '" + apiName + "' API is currently enabled in limited experiment s. Please see [Chrome experiments website URL] for information on enabling this experiment on your site."; 28 return "The '" + apiName + "' API is currently enabled in limited experiment s. Please see [Chrome experiments website URL] for information on enabling this experiment on your site.";
29 } 29 }
30 30
31 bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, S tring& errorMessage) 31 bool hasValidAPIKey(ExecutionContext* executionContext, const String& apiName, S tring* errorMessage)
32 { 32 {
33 bool foundAnyKey = false; 33 bool foundAnyKey = false;
34 String origin = getCurrentOrigin(executionContext); 34 String origin = getCurrentOrigin(executionContext);
35 35
36 // When in a document, the API key is provided in a meta tag 36 // When in a document, the API key is provided in a meta tag
37 if (executionContext->isDocument()) { 37 if (executionContext->isDocument()) {
38 HTMLHeadElement* head = toDocument(executionContext)->head(); 38 HTMLHeadElement* head = toDocument(executionContext)->head();
39 for (HTMLMetaElement* metaElement = head ? Traversal<HTMLMetaElement>::f irstChild(*head) : 0; metaElement; metaElement = Traversal<HTMLMetaElement>::nex tSibling(*metaElement)) { 39 for (HTMLMetaElement* metaElement = head ? Traversal<HTMLMetaElement>::f irstChild(*head) : 0; metaElement; metaElement = Traversal<HTMLMetaElement>::nex tSibling(*metaElement)) {
40 if (equalIgnoringCase(metaElement->name(), kExperimentsMetaName)) { 40 if (equalIgnoringCase(metaElement->name(), kExperimentsMetaName)) {
41 foundAnyKey = true; 41 foundAnyKey = true;
42 if (equalIgnoringCase(metaElement->content(), apiName)) 42 if (equalIgnoringCase(metaElement->content(), apiName))
43 return true; 43 return true;
44 } 44 }
45 } 45 }
46 } 46 }
47 if (foundAnyKey) { 47
48 errorMessage = "The provided key(s) are not valid for the '" + apiName + "' API."; 48 if (errorMessage) {
iclelland 2016/01/08 15:11:28 Would the code be cleaner if you did the same thin
chasej 2016/01/08 17:37:06 I did consider that the code is less clean with th
iclelland 2016/01/08 17:50:09 Well, if you get to the point where you're calling
49 } else { 49 if (foundAnyKey) {
50 errorMessage = getDisabledMessage(apiName); 50 *errorMessage = "The provided key(s) are not valid for the '" + apiN ame + "' API.";
51 } else {
52 *errorMessage = getDisabledMessage(apiName);
53 }
51 } 54 }
52 return false; 55 return false;
53 } 56 }
54 57
55 } // namespace 58 } // namespace
56 59
57 bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName, String& errorMessage) 60 // static
61 bool Experiments::isApiEnabled(ExecutionContext* executionContext, const String& apiName, String* errorMessage)
58 { 62 {
59 if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) { 63 if (!RuntimeEnabledFeatures::experimentalFrameworkEnabled()) {
60 errorMessage = "Experimental Framework is not enabled."; 64 if (errorMessage) {
65 *errorMessage = "Experimental Framework is not enabled.";
66 }
61 return false; 67 return false;
62 } 68 }
63 69
64 if (!executionContext) { 70 if (!executionContext) {
65 ASSERT_NOT_REACHED(); 71 ASSERT_NOT_REACHED();
66 return false; 72 return false;
67 } 73 }
68 74
69 // Experiments are only enabled for secure origins 75 // Experiments are only enabled for secure origins
70 if (!executionContext->isSecureContext(errorMessage)) { 76 bool isSecure = errorMessage
77 ? executionContext->isSecureContext(*errorMessage)
78 : executionContext->isSecureContext();
79 if (!isSecure) {
71 return false; 80 return false;
72 } 81 }
73 82
74 return hasValidAPIKey(executionContext, apiName, errorMessage); 83 return hasValidAPIKey(executionContext, apiName, errorMessage);
75 } 84 }
76 85
86 // static
77 DOMException* Experiments::createApiDisabledException(const String& apiName) 87 DOMException* Experiments::createApiDisabledException(const String& apiName)
78 { 88 {
79 return DOMException::create(NotSupportedError, getDisabledMessage(apiName)); 89 return DOMException::create(NotSupportedError, getDisabledMessage(apiName));
80 } 90 }
81 91
82 } // namespace blink 92 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698