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

Side by Side Diff: docs/origin_trials_integration.md

Issue 2693503002: Add documentation for Origin Trials integration (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Integrating a feature with the Origin Trials framework
2
3 To expose your feature via the origin trials framework, there are a few code
4 changes required.
5
6 [TOC]
7
8 ## Code Changes
9
10 ### Runtime Enabled Features
11
12 First, you’ll need to configure [RuntimeEnabledFeatures.json5]. This is
13 explained in the file, but you use `origin_trial_feature_name` to associate your
14 runtime feature flag with a name for your origin trial. The name can be the
15 same as your runtime feature flag, or different. Eventually, this configured
16 name will be used in the Origin Trials developer console (still under
17 development). You can have both `status: experimental` and
18 `origin_trial_feature_name` if you want your feature to be enabled either by
19 using the `--enable-experimental-web-platform-features` flag **or** the origin
20 trial.
21
22 You may have a feature that is not available on all platforms, or need to limit
23 the trial to specific platforms. Use `origin_trial_os: [list]` to specify which
24 platforms will allow the trial to be enabled.
iclelland 2017/02/10 19:41:28 Can we list the valid values for that list here? "
chasej 2017/02/10 20:24:41 I intentionally omitted the list of valid values.
25
26 #### Examples
27
28 Flag name and trial name are the same:
29 ```
30 {
31 name: "MyFeature",
32 origin_trial_feature_name: "MyFeature",
33 status: "experimental",
34 },
35 ```
36 Flag name and trial name are different:
37 ```
38 {
39 name: "MyFeature",
40 origin_trial_feature_name: "MyFeatureTrial",
41 status: "experimental",
42 },
43 ```
44 Trial limited to specific platform:
45 ``` json
46 {
47 name: "MyFeature",
48 origin_trial_feature_name: "MyFeature",
49 origin_trial_os: ["android"],
50 status: "experimental",
51 },
52 ```
53
54 ### Gating Access
55
56 Once configured, there are two mechanisms to gate access to your feature behind
57 an origin trial. You can use either mechanism, or both, as appropriate to your
58 feature implementation.
59
60 1. A native C++ method that you can call in Blink code at runtime to expose your
61 feature: `bool OriginTrials::myFeatureEnabled()`
62 2. An IDL attribute \[[OriginTrialEnabled]\] that you can use to automatically
63 expose and hide JavaScript methods/attributes/objects. This attribute works
64 very similar to \[RuntimeEnabled\].
65 ```
66 [OriginTrialEnabled=MyFeature]
67 partial interface Navigator {
68 readonly attribute MyFeatureManager myFeature;
69 }
70 ```
71
72 **NOTE:** Your feature implementation must not persist the result of the enabled
73 check. Your code should simply call `OriginTrials::myFeatureEnabled()` as often
74 as necessary to gate access to your feature.
75
76 ### IDL Bindings
77
78 When using the \[OriginTrialEnabled\] IDL attribute, you'll need to manually
79 install the appropriate methods in the V8 bindings code. Based on the
80 \[OriginTrialEnabled\] attribute, there will be one or more `installMyFeature`
81 methods generated in the bindings code. These methods must be manually
82 installed:
83
84 - Find the relevant methods by doing a code search for `installMyFeature`:
iclelland 2017/02/10 19:41:27 I didn't realise this was best practise :) I suppo
chasej 2017/02/10 20:24:41 You could do that. I had tested with a few example
85 - e.g. V8WindowPartial::installMyFeature,
86 V8NavigatorPartial::installMyFeature
87 - Determine which bindings code needs to be updated:
88 - [ConditionalFeatures.cpp]: Your feature lives in `core` (i.e. generated
89 methods are found under .../bindings/core/...)
90 - [ConditionalFeaturesForModules.cpp]: Your feature lives under `modules`
91 (i.e. generated methods are found under .../bindings/modules/...)
92 - Update `installConditionalFeatures[Core|ForModules]()`:
93 - These methods are broken down by type.
94 - Add/update the logic for each type to call the corresponding
95 `<type>::installMyFeature()` methods.
96 - Update `installPendingConditionalFeature[Core|ForModules]()`:
97 - These methods are broken down by trial/feature.
98 - Add/update the logic for each feature to call all of the
99 `installMyFeature()` methods.
100
101 Eventually, the V8 bindings code will be generated automatically (See
102 [crbug.com/615060]).
103
104
105 ## Limitations
106
107 What you can't do, because of the nature of these Origin Trials, is know at
108 either browser or renderer startup time whether your feature is going to be used
109 in the current page/context. This means that if you require lots of expensive
110 processing to begin (say you index the user's hard drive, or scan an entire city
111 for interesting weather patterns,) that you will have to either do it on browser
112 startup for *all* users, just in case it's used, or do it on first access. (If
113 you go with first access, then only people trying the experiment will notice the
114 delay, and hopefully only the first time they use it.). We are investigating
115 providing a method like `OriginTrials::myFeatureShouldInitialize()` that will
116 hint if you should do startup initialization. For example, this could include
117 checks for trials that have been revoked (or throttled) due to usage, if the
118 entire origin trials framework has been disabled, etc. The method would be
119 conservative and assume initialization is required, but it could avoid expensive
120 startup in some known scenarios.
121
122 Similarly, if you need to know in the browser process whether a feature should
123 be enabled, then you will have to either have the renderer inform it at runtime,
124 or else just assume that it's always enabled, and gate access to the feature
125 from the renderer.
126
127 ## Testing
128
129 If you want to test your code's interactions with the framework, you'll need to
130 generate some tokens of your own. To generate your own tokens, use
131 [/tools/origin_trials/generate_token.py]. You can generate signed tokens for
iclelland 2017/02/10 19:41:27 Why is this reference using the complete path as i
chasej 2017/02/10 20:24:41 The source document had the complete path as its t
132 localhost, or for 127.0.0.1, or for any origin that you need to help you test.
133 For example:
134
135 ```
136 tools/origin_trials/generate_token.py http://localhost:8000 MyFeature
137 ```
138
139 The file `tools/origin_trials/eftest.key` is used by default as the private key
140 for the test keypair used by Origin Trials unit tests (tokens generated with
141 this key will **not** work in the browser by default; see the [Developer Guide]
iclelland 2017/02/10 19:41:27 We could mention that they *do* work in content sh
chasej 2017/02/10 20:24:41 Done.
142 for instructions on creating real tokens). To use a test token with the browser,
143 run Chrome with the command-line flag:
144
145 ```
146 --origin-trial-public-key=dRCs+TocuKkocNKa0AtZ4awrt9XKH2SQCI6o4FY6BNA=
147 ```
148
149 This is the public key associated with `eftest.key`. If it doesn't work, see
iclelland 2017/02/10 19:41:28 ...is the base64 encoding of the public key...
chasej 2017/02/10 20:24:41 Done.
150 [trial_token_unittest.cc]. If you cannot set command-line switches (e.g., on
151 Chrome OS), you can also directly modify [chrome_origin_trial_policy.cc].
152
153 [chrome_origin_trial_policy.cc]: /chrome/common/origin_trials/chrome_origin_tria l_policy.cc
154 [crbug.com/615060]: https://bugs.chromium.org/p/chromium/issues/detail?id=615060
155 [ConditionalFeatures.cpp]: /third_party/WebKit/Source/bindings/core/v8/Condition alFeatures.cpp
156 [ConditionalFeaturesForModules.cpp]: /third_party/WebKit/Source/bindings/modules /v8/ConditionalFeaturesForModules.cpp
157 [Developer Guide]: https://github.com/jpchase/OriginTrials/blob/gh-pages/develop er-guide.md
158 [OriginTrialEnabled]: /third_party/WebKit/Source/bindings/IDLExtendedAttributes. md#_OriginTrialEnabled_i_m_a_c_
159 [RuntimeEnabledFeatures.json5]: /third_party/WebKit/Source/platform/RuntimeEnabl edFeatures.json5
160 [/tools/origin_trials/generate_token.py]: /tools/origin_trials/generate_token.py
161 [trial_token_unittest.cc]: /content/common/origin_trials/trial_token_unittest.cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698