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

Side by Side Diff: docs/origin_trials_integration.md

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