Added
Link Here
|
1 |
commit 6b81d0b99f20 |
2 |
Author: Nicholas Nethercote <nnethercote@mozilla.com> |
3 |
Date: Thu Mar 8 15:47:24 2018 +1100 |
4 |
|
5 |
Bug 1436911 - Avoid the early/late prefs split. r=glandium |
6 |
|
7 |
All prefs that need to be sent to a new content process are now put into the |
8 |
shared memory segment, and they are identified by the pref name instead of an |
9 |
index into a list. The old IPC used at process startup (in XPCOMInitData) is |
10 |
removed. |
11 |
|
12 |
Benefits: |
13 |
|
14 |
- It removes the need for the early prefs list |
15 |
(dom/ipc/ContentProcesses.{h,cpp}) and the associated checking, which is ugly |
16 |
and often trips people up (e.g. bug 1432979, bug 1439406). |
17 |
|
18 |
- Using prefnames instead of indices fixes some fragility (fixing bug 1419432). |
19 |
|
20 |
- It fixes the problem of early prefs being installed as unlocked default |
21 |
values even if they are locked and/or have user values. |
22 |
|
23 |
MozReview-Commit-ID: FRIzHF8Tjd |
24 |
--- |
25 |
dom/ipc/ContentChild.cpp | 2 - |
26 |
dom/ipc/ContentParent.cpp | 4 +- |
27 |
dom/ipc/ContentPrefs.cpp | 357 ------------------------------ |
28 |
dom/ipc/ContentPrefs.h | 27 --- |
29 |
dom/ipc/ContentProcess.cpp | 5 +- |
30 |
dom/ipc/PContent.ipdl | 7 +- |
31 |
dom/ipc/moz.build | 2 - |
32 |
layout/style/nsCSSProps.h | 2 +- |
33 |
modules/libpref/Preferences.cpp | 470 ++++++++++++++++++++++------------------ |
34 |
modules/libpref/Preferences.h | 15 +- |
35 |
10 files changed, 278 insertions(+), 613 deletions(-) |
36 |
|
37 |
diff --git dom/ipc/ContentChild.cpp dom/ipc/ContentChild.cpp |
38 |
index f61ab07b81e2..af1ef9cf4c7e 100644 |
39 |
--- dom/ipc/ContentChild.cpp |
40 |
+++ dom/ipc/ContentChild.cpp |
41 |
@@ -1185,8 +1185,6 @@ void |
42 |
ContentChild::InitXPCOM(const XPCOMInitData& aXPCOMInit, |
43 |
const mozilla::dom::ipc::StructuredCloneData& aInitialData) |
44 |
{ |
45 |
- Preferences::SetLatePreferences(&aXPCOMInit.prefs()); |
46 |
- |
47 |
// Do this as early as possible to get the parent process to initialize the |
48 |
// background thread since we'll likely need database information very soon. |
49 |
BackgroundChild::Startup(); |
50 |
diff --git dom/ipc/ContentParent.cpp dom/ipc/ContentParent.cpp |
51 |
index 208bb47a970b..4ce5c6bf23d5 100644 |
52 |
--- dom/ipc/ContentParent.cpp |
53 |
+++ dom/ipc/ContentParent.cpp |
54 |
@@ -197,7 +197,6 @@ |
55 |
|
56 |
#include "nsLayoutStylesheetCache.h" |
57 |
|
58 |
-#include "ContentPrefs.h" |
59 |
#include "mozilla/Sprintf.h" |
60 |
|
61 |
#ifdef MOZ_WEBRTC |
62 |
@@ -2009,7 +2008,7 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR |
63 |
|
64 |
// Serialize the early prefs. |
65 |
nsAutoCStringN<1024> prefs; |
66 |
- Preferences::SerializeEarlyPreferences(prefs); |
67 |
+ Preferences::SerializePreferences(prefs); |
68 |
|
69 |
// Set up the shared memory. |
70 |
base::SharedMemory shm; |
71 |
@@ -2228,7 +2227,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority) |
72 |
|
73 |
XPCOMInitData xpcomInit; |
74 |
|
75 |
- Preferences::GetPreferences(&xpcomInit.prefs()); |
76 |
nsCOMPtr<nsIIOService> io(do_GetIOService()); |
77 |
MOZ_ASSERT(io, "No IO service?"); |
78 |
DebugOnly<nsresult> rv = io->GetOffline(&xpcomInit.isOffline()); |
79 |
diff --git dom/ipc/ContentPrefs.cpp dom/ipc/ContentPrefs.cpp |
80 |
deleted file mode 100644 |
81 |
index 808b797d9bee..000000000000 |
82 |
--- dom/ipc/ContentPrefs.cpp |
83 |
+++ /dev/null |
84 |
@@ -1,360 +0,0 @@ |
85 |
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
86 |
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
87 |
-/* This Source Code Form is subject to the terms of the Mozilla Public |
88 |
- * License, v. 2.0. If a copy of the MPL was not distributed with this |
89 |
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
90 |
- |
91 |
-#include "ContentPrefs.h" |
92 |
- |
93 |
-/****************************************************************************** |
94 |
- * |
95 |
- * DO NOT ADD PREFS TO THIS LIST WITHOUT DOM PEER REVIEW |
96 |
- * |
97 |
- * This is the list of preferences that are sent to the content process on |
98 |
- * startup. Only prefs that are required immediately upon startup should be |
99 |
- * listed here. The first IPC message received in the content process will |
100 |
- * contain all the other prefs. Prefs should only be listed here if they must be |
101 |
- * read before the first IPC message is received. |
102 |
- * |
103 |
- ******************************************************************************/ |
104 |
- |
105 |
-const char* mozilla::dom::ContentPrefs::gEarlyPrefs[] = { |
106 |
- "accessibility.monoaudio.enable", |
107 |
- "accessibility.mouse_focuses_formcontrol", |
108 |
- "accessibility.tabfocus_applies_to_xul", |
109 |
- "app.update.channel", |
110 |
- "browser.autofocus", |
111 |
- "browser.dom.window.dump.enabled", |
112 |
- "browser.sessionhistory.max_entries", |
113 |
- "browser.sessionhistory.max_total_viewers", |
114 |
-#if defined(NIGHTLY_BUILD) || defined(DEBUG) |
115 |
- "browser.startup.record", |
116 |
-#endif |
117 |
-#if defined(ANDROID) |
118 |
- "consoleservice.logcat", |
119 |
-#endif |
120 |
- "content.cors.disable", |
121 |
- "content.cors.no_private_data", |
122 |
- "content.notify.backoffcount", |
123 |
- "content.notify.interval", |
124 |
- "content.notify.ontimer", |
125 |
- "content.sink.enable_perf_mode", |
126 |
- "content.sink.event_probe_rate", |
127 |
- "content.sink.initial_perf_time", |
128 |
- "content.sink.interactive_deflect_count", |
129 |
- "content.sink.interactive_parse_time", |
130 |
- "content.sink.interactive_time", |
131 |
- "content.sink.pending_event_mode", |
132 |
- "content.sink.perf_deflect_count", |
133 |
- "content.sink.perf_parse_time", |
134 |
- "device.storage.prompt.testing", |
135 |
- "device.storage.writable.name", |
136 |
- "devtools.enabled", |
137 |
- "dom.allow_XUL_XBL_for_file", |
138 |
- "dom.allow_cut_copy", |
139 |
- "dom.animations-api.core.enabled", |
140 |
- "dom.animations-api.element-animate.enabled", |
141 |
- "dom.animations-api.pending-member.enabled", |
142 |
- "dom.enable_frame_timing", |
143 |
- "dom.enable_performance", |
144 |
- "dom.enable_performance_navigation_timing", |
145 |
- "dom.enable_resource_timing", |
146 |
- "dom.event.handling-user-input-time-limit", |
147 |
- "dom.event.touch.coalescing.enabled", |
148 |
- "dom.forms.autocomplete.formautofill", |
149 |
- "dom.forms.inputmode", |
150 |
- "dom.input.skip_cursor_move_for_same_value_set", |
151 |
- "dom.ipc.processPriorityManager.backgroundGracePeriodMS", |
152 |
- "dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS", |
153 |
- "dom.ipc.useNativeEventProcessing.content", |
154 |
- "dom.max_chrome_script_run_time", |
155 |
- "dom.max_ext_content_script_run_time", |
156 |
- "dom.max_script_run_time", |
157 |
- "dom.mozBrowserFramesEnabled", |
158 |
- "dom.performance.enable_notify_performance_timing", |
159 |
- "dom.performance.enable_user_timing_logging", |
160 |
- "dom.placeholder.show_on_focus", |
161 |
- "dom.requestIdleCallback.enabled", |
162 |
- "dom.script_loader.bytecode_cache.enabled", |
163 |
- "dom.script_loader.bytecode_cache.strategy", |
164 |
- "dom.storage.testing", |
165 |
- "dom.url.encode_decode_hash", |
166 |
- "dom.url.getters_decode_hash", |
167 |
- "dom.use_watchdog", |
168 |
- "dom.vibrator.enabled", |
169 |
- "dom.vibrator.max_vibrate_list_len", |
170 |
- "dom.vibrator.max_vibrate_ms", |
171 |
- "dom.webcomponents.customelements.enabled", |
172 |
- "dom.webcomponents.shadowdom.enabled", |
173 |
- "focusmanager.testmode", |
174 |
- "font.size.inflation.disabledInMasterProcess", |
175 |
- "font.size.inflation.emPerLine", |
176 |
- "font.size.inflation.forceEnabled", |
177 |
- "font.size.inflation.lineThreshold", |
178 |
- "font.size.inflation.mappingIntercept", |
179 |
- "font.size.inflation.maxRatio", |
180 |
- "font.size.inflation.minTwips", |
181 |
- "font.size.systemFontScale", |
182 |
- "full-screen-api.allow-trusted-requests-only", |
183 |
- "full-screen-api.enabled", |
184 |
- "full-screen-api.unprefix.enabled", |
185 |
-#ifdef FUZZING |
186 |
- "fuzzing.enabled", |
187 |
-#endif |
188 |
- "gfx.font_rendering.opentype_svg.enabled", |
189 |
- "hangmonitor.timeout", |
190 |
- "html5.flushtimer.initialdelay", |
191 |
- "html5.flushtimer.subsequentdelay", |
192 |
- "html5.offmainthread", |
193 |
- "intl.charset.fallback.tld", |
194 |
- "intl.charset.fallback.utf8_for_file", |
195 |
- "intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition", |
196 |
- "javascript.enabled", |
197 |
- "javascript.options.array_prototype_values", |
198 |
- "javascript.options.asmjs", |
199 |
- "javascript.options.asyncstack", |
200 |
- "javascript.options.baselinejit", |
201 |
- "javascript.options.baselinejit.threshold", |
202 |
- "javascript.options.baselinejit.unsafe_eager_compilation", |
203 |
- "javascript.options.discardSystemSource", |
204 |
- "javascript.options.dump_stack_on_debuggee_would_run", |
205 |
- "javascript.options.gczeal", |
206 |
- "javascript.options.gczeal.frequency", |
207 |
- "javascript.options.ion", |
208 |
- "javascript.options.ion.offthread_compilation", |
209 |
- "javascript.options.ion.threshold", |
210 |
- "javascript.options.ion.unsafe_eager_compilation", |
211 |
- "javascript.options.jit.full_debug_checks", |
212 |
- "javascript.options.native_regexp", |
213 |
- "javascript.options.parallel_parsing", |
214 |
- "javascript.options.shared_memory", |
215 |
- "javascript.options.spectre.index_masking", |
216 |
- "javascript.options.spectre.jit_to_C++_calls", |
217 |
- "javascript.options.spectre.object_mitigations.barriers", |
218 |
- "javascript.options.spectre.object_mitigations.misc", |
219 |
- "javascript.options.spectre.string_mitigations", |
220 |
- "javascript.options.spectre.value_masking", |
221 |
- "javascript.options.streams", |
222 |
- "javascript.options.strict", |
223 |
- "javascript.options.strict.debug", |
224 |
- "javascript.options.throw_on_asmjs_validation_failure", |
225 |
- "javascript.options.throw_on_debuggee_would_run", |
226 |
- "javascript.options.wasm", |
227 |
- "javascript.options.wasm_baselinejit", |
228 |
- "javascript.options.wasm_ionjit", |
229 |
- "javascript.options.werror", |
230 |
- "javascript.use_us_english_locale", |
231 |
- "jsloader.shareGlobal", |
232 |
- "layout.css.all-shorthand.enabled", |
233 |
- "layout.css.background-blend-mode.enabled", |
234 |
- "layout.css.box-decoration-break.enabled", |
235 |
- "layout.css.color-adjust.enabled", |
236 |
- "layout.css.column-span.enabled", |
237 |
- "layout.css.contain.enabled", |
238 |
- "layout.css.control-characters.visible", |
239 |
- "layout.css.emulate-moz-box-with-flex", |
240 |
- "layout.css.expensive-style-struct-assertions.enabled", |
241 |
- "layout.css.float-logical-values.enabled", |
242 |
- "layout.css.font-display.enabled", |
243 |
- "layout.css.font-variations.enabled", |
244 |
- "layout.css.frames-timing.enabled", |
245 |
- "layout.css.getBoxQuads.enabled", |
246 |
- "layout.css.grid-template-subgrid-value.enabled", |
247 |
- "layout.css.grid.enabled", |
248 |
- "layout.css.image-orientation.enabled", |
249 |
- "layout.css.individual-transform.enabled", |
250 |
- "layout.css.initial-letter.enabled", |
251 |
- "layout.css.isolation.enabled", |
252 |
- "layout.css.mix-blend-mode.enabled", |
253 |
- "layout.css.moz-document.content.enabled", |
254 |
- "layout.css.osx-font-smoothing.enabled", |
255 |
- "layout.css.overflow-clip-box.enabled", |
256 |
- "layout.css.overscroll-behavior.enabled", |
257 |
- "layout.css.prefixes.animations", |
258 |
- "layout.css.prefixes.border-image", |
259 |
- "layout.css.prefixes.box-sizing", |
260 |
- "layout.css.prefixes.device-pixel-ratio-webkit", |
261 |
- "layout.css.prefixes.font-features", |
262 |
- "layout.css.prefixes.gradients", |
263 |
- "layout.css.prefixes.transforms", |
264 |
- "layout.css.prefixes.transitions", |
265 |
- "layout.css.prefixes.webkit", |
266 |
- "layout.css.scope-pseudo.enabled", |
267 |
- "layout.css.scoped-style.enabled", |
268 |
- "layout.css.scroll-behavior.property-enabled", |
269 |
- "layout.css.scroll-snap.enabled", |
270 |
-#ifdef MOZ_STYLO |
271 |
- "layout.css.servo.chrome.enabled", |
272 |
- "layout.css.servo.enabled", |
273 |
-#endif |
274 |
- "layout.css.shape-outside.enabled", |
275 |
- "layout.css.text-align-unsafe-value.enabled", |
276 |
- "layout.css.text-combine-upright-digits.enabled", |
277 |
- "layout.css.text-combine-upright.enabled", |
278 |
- "layout.css.text-justify.enabled", |
279 |
- "layout.css.touch_action.enabled", |
280 |
- "layout.css.visited_links_enabled", |
281 |
- "layout.idle_period.required_quiescent_frames", |
282 |
- "layout.idle_period.time_limit", |
283 |
- "layout.interruptible-reflow.enabled", |
284 |
- "mathml.disabled", |
285 |
- "media.audio-max-decode-error", |
286 |
- "media.cache_readahead_limit", |
287 |
- "media.cache_resume_threshold", |
288 |
- "media.cache_size", |
289 |
- "media.clearkey.persistent-license.enabled", |
290 |
- "media.cubeb.backend", |
291 |
- "media.cubeb.sandbox", |
292 |
- "media.cubeb_latency_msg_frames", |
293 |
- "media.cubeb_latency_playback_ms", |
294 |
- "media.decoder-doctor.wmf-disabled-is-failure", |
295 |
- "media.decoder.recycle.enabled", |
296 |
- "media.decoder.skip-to-next-key-frame.enabled", |
297 |
- "media.dormant-on-pause-timeout-ms", |
298 |
- "media.eme.audio.blank", |
299 |
- "media.eme.chromium-api.video-shmems", |
300 |
- "media.eme.enabled", |
301 |
- "media.eme.video.blank", |
302 |
- "media.ffmpeg.enabled", |
303 |
- "media.ffmpeg.low-latency.enabled", |
304 |
- "media.ffvpx.enabled", |
305 |
- "media.ffvpx.low-latency.enabled", |
306 |
- "media.flac.enabled", |
307 |
- "media.forcestereo.enabled", |
308 |
- "media.gmp.decoder.enabled", |
309 |
- "media.gmp.insecure.allow", |
310 |
- "media.gpu-process-decoder", |
311 |
- "media.hls.enabled", |
312 |
- "media.libavcodec.allow-obsolete", |
313 |
- "media.memory_cache_max_size", |
314 |
- "media.memory_caches_combined_limit_kb", |
315 |
- "media.memory_caches_combined_limit_pc_sysmem", |
316 |
- "media.mp4.enabled", |
317 |
- "media.navigator.mediadatadecoder_enabled", |
318 |
- "media.ogg.enabled", |
319 |
- "media.ogg.flac.enabled", |
320 |
- "media.playback.warnings-as-errors", |
321 |
- "media.playback.warnings-as-errors.stagefright-vs-rust", |
322 |
- "media.resampling.enabled", |
323 |
- "media.resume-bkgnd-video-on-tabhover", |
324 |
- "media.ruin-av-sync.enabled", |
325 |
- "media.rust.mp4parser", |
326 |
- "media.rust.test_mode", |
327 |
- "media.seamless-looping", |
328 |
- "media.suspend-bkgnd-video.delay-ms", |
329 |
- "media.suspend-bkgnd-video.enabled", |
330 |
- "media.use-blank-decoder", |
331 |
- "media.video-max-decode-error", |
332 |
- "media.video_stats.enabled", |
333 |
- "media.videocontrols.lock-video-orientation", |
334 |
- "media.volume_scale", |
335 |
- "media.webspeech.recognition.enable", |
336 |
- "media.webspeech.recognition.force_enable", |
337 |
- "media.webspeech.synth.force_global_queue", |
338 |
- "media.webspeech.test.enable", |
339 |
- "media.webspeech.test.fake_fsm_events", |
340 |
- "media.webspeech.test.fake_recognition_service", |
341 |
- "media.wmf.allow-unsupported-resolutions", |
342 |
- "media.wmf.enabled", |
343 |
- "media.wmf.skip-blacklist", |
344 |
- "media.wmf.vp9.enabled", |
345 |
- "network.IDN.blacklist_chars", |
346 |
- "network.IDN.restriction_profile", |
347 |
- "network.IDN.use_whitelist", |
348 |
- "network.IDN_show_punycode", |
349 |
- "network.buffer.cache.count", |
350 |
- "network.buffer.cache.size", |
351 |
- "network.captive-portal-service.enabled", |
352 |
- "network.cookie.cookieBehavior", |
353 |
- "network.cookie.lifetimePolicy", |
354 |
- "network.dns.disablePrefetch", |
355 |
- "network.dns.disablePrefetchFromHTTPS", |
356 |
- "network.http.tailing.enabled", |
357 |
- "network.jar.block-remote-files", |
358 |
- "network.loadinfo.skip_type_assertion", |
359 |
- "network.notify.changed", |
360 |
- "network.offline-mirrors-connectivity", |
361 |
- "network.protocol-handler.external.jar", |
362 |
- "network.proxy.type", |
363 |
- "network.security.ports.banned", |
364 |
- "network.security.ports.banned.override", |
365 |
- "network.standard-url.enable-rust", |
366 |
- "network.standard-url.max-length", |
367 |
- "network.standard-url.punycode-host", |
368 |
- "network.sts.max_time_for_events_between_two_polls", |
369 |
- "network.sts.max_time_for_pr_close_during_shutdown", |
370 |
- "network.tcp.keepalive.enabled", |
371 |
- "network.tcp.keepalive.idle_time", |
372 |
- "network.tcp.keepalive.probe_count", |
373 |
- "network.tcp.keepalive.retry_interval", |
374 |
- "network.tcp.sendbuffer", |
375 |
- "nglayout.debug.invalidation", |
376 |
- "privacy.donottrackheader.enabled", |
377 |
- "privacy.firstparty.isolate", |
378 |
- "privacy.firstparty.isolate.restrict_opener_access", |
379 |
- "privacy.reduceTimerPrecision", |
380 |
- "privacy.resistFingerprinting", |
381 |
- "privacy.resistFingerprinting.autoDeclineNoUserInputCanvasPrompts", |
382 |
- "privacy.resistFingerprinting.reduceTimerPrecision.jitter", |
383 |
- "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", |
384 |
- "privacy.resistFingerprinting.target_video_res", |
385 |
- "privacy.resistFingerprinting.video_dropped_ratio", |
386 |
- "privacy.resistFingerprinting.video_frames_per_sec", |
387 |
- "privacy.trackingprotection.lower_network_priority", |
388 |
- "privacy.window.maxInnerHeight", |
389 |
- "privacy.window.maxInnerWidth", |
390 |
- "security.csp.enable", |
391 |
- "security.data_uri.block_toplevel_data_uri_navigations", |
392 |
- "security.data_uri.unique_opaque_origin", |
393 |
- "security.fileuri.strict_origin_policy", |
394 |
- "security.mixed_content.block_active_content", |
395 |
- "security.mixed_content.block_display_content", |
396 |
- "security.mixed_content.block_object_subrequest", |
397 |
- "security.mixed_content.hsts_priming_cache_timeout", |
398 |
- "security.mixed_content.send_hsts_priming", |
399 |
- "security.mixed_content.upgrade_display_content", |
400 |
- "security.mixed_content.use_hsts", |
401 |
- "security.sandbox.content.level", |
402 |
- "security.sandbox.content.tempDirSuffix", |
403 |
- "security.sandbox.logging.enabled", |
404 |
- "security.sandbox.mac.track.violations", |
405 |
- "security.sandbox.windows.log.stackTraceDepth", |
406 |
- "svg.disabled", |
407 |
- "svg.display-lists.hit-testing.enabled", |
408 |
- "svg.display-lists.painting.enabled", |
409 |
- "svg.new-getBBox.enabled", |
410 |
- "svg.path-caching.enabled", |
411 |
- "svg.transform-box.enabled", |
412 |
- "toolkit.asyncshutdown.crash_timeout", |
413 |
- "toolkit.asyncshutdown.log", |
414 |
- "toolkit.osfile.log", |
415 |
- "toolkit.osfile.log.redirect", |
416 |
- "toolkit.telemetry.enabled", |
417 |
- "toolkit.telemetry.idleTimeout", |
418 |
- "toolkit.telemetry.initDelay", |
419 |
- "toolkit.telemetry.log.dump", |
420 |
- "toolkit.telemetry.log.level", |
421 |
- "toolkit.telemetry.minSubsessionLength", |
422 |
- "toolkit.telemetry.scheduler.idleTickInterval", |
423 |
- "toolkit.telemetry.scheduler.tickInterval", |
424 |
- "toolkit.telemetry.testing.overridePreRelease", |
425 |
- "toolkit.telemetry.unified", |
426 |
- "ui.key.menuAccessKeyFocuses", |
427 |
- "ui.popup.disable_autohide", |
428 |
- "ui.use_activity_cursor", |
429 |
- "view_source.editor.external", |
430 |
- "zoom.maxPercent", |
431 |
- "zoom.minPercent" |
432 |
-}; |
433 |
- |
434 |
-const char** mozilla::dom::ContentPrefs::GetEarlyPrefs(size_t* aCount) |
435 |
-{ |
436 |
- *aCount = ArrayLength(ContentPrefs::gEarlyPrefs); |
437 |
- return gEarlyPrefs; |
438 |
-} |
439 |
- |
440 |
-const char* mozilla::dom::ContentPrefs::GetEarlyPref(size_t aIndex) |
441 |
-{ |
442 |
- MOZ_ASSERT(aIndex < ArrayLength(ContentPrefs::gEarlyPrefs)); |
443 |
- return gEarlyPrefs[aIndex]; |
444 |
-} |
445 |
diff --git dom/ipc/ContentPrefs.h dom/ipc/ContentPrefs.h |
446 |
deleted file mode 100644 |
447 |
index 72ce8d236c11..000000000000 |
448 |
--- dom/ipc/ContentPrefs.h |
449 |
+++ /dev/null |
450 |
@@ -1,27 +0,0 @@ |
451 |
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
452 |
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
453 |
-/* This Source Code Form is subject to the terms of the Mozilla Public |
454 |
- * License, v. 2.0. If a copy of the MPL was not distributed with this |
455 |
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
456 |
- |
457 |
-#ifndef mozilla_dom_ContentPrefs_h |
458 |
-#define mozilla_dom_ContentPrefs_h |
459 |
- |
460 |
-// See the comment in ContentPrefs.cpp for more information. |
461 |
- |
462 |
-namespace mozilla { |
463 |
-namespace dom { |
464 |
- |
465 |
-class ContentPrefs { |
466 |
-public: |
467 |
- static const char** GetEarlyPrefs(size_t* aCount); |
468 |
- static const char* GetEarlyPref(size_t aIndex); |
469 |
- |
470 |
-private: |
471 |
- static const char* gEarlyPrefs[]; |
472 |
-}; |
473 |
- |
474 |
-} |
475 |
-} |
476 |
- |
477 |
-#endif |
478 |
diff --git dom/ipc/ContentProcess.cpp dom/ipc/ContentProcess.cpp |
479 |
index 2441c8cb9224..c00283dc5084 100644 |
480 |
--- dom/ipc/ContentProcess.cpp |
481 |
+++ dom/ipc/ContentProcess.cpp |
482 |
@@ -7,7 +7,6 @@ |
483 |
#include "mozilla/ipc/IOThreadChild.h" |
484 |
|
485 |
#include "ContentProcess.h" |
486 |
-#include "ContentPrefs.h" |
487 |
#include "base/shared_memory.h" |
488 |
#include "mozilla/Preferences.h" |
489 |
#include "mozilla/Scheduler.h" |
490 |
@@ -226,8 +225,8 @@ ContentProcess::Init(int aArgc, char* aArgv[]) |
491 |
NS_ERROR("failed to map shared memory in the child"); |
492 |
return false; |
493 |
} |
494 |
- Preferences::DeserializeEarlyPreferences(static_cast<char*>(shm.memory()), |
495 |
- prefsLen); |
496 |
+ Preferences::DeserializePreferences(static_cast<char*>(shm.memory()), |
497 |
+ prefsLen); |
498 |
|
499 |
Scheduler::SetPrefs(schedulerPrefs); |
500 |
mContent.Init(IOThreadChild::message_loop(), |
501 |
diff --git dom/ipc/PContent.ipdl dom/ipc/PContent.ipdl |
502 |
index 5d077976569a..fb967ffc53a9 100644 |
503 |
--- dom/ipc/PContent.ipdl |
504 |
+++ dom/ipc/PContent.ipdl |
505 |
@@ -155,6 +155,12 @@ union MaybePrefValue { |
506 |
null_t; |
507 |
}; |
508 |
|
509 |
+// This serialization form mirrors that used in mozilla::Pref in |
510 |
+// Preferences.cpp. The two should be kept in sync, e.g. if something is added |
511 |
+// to one it should also be added to the other. |
512 |
+// |
513 |
+// Note: there is no need to pass the isSticky attribute because that's an |
514 |
+// immutable attribute obtained from file at startup. |
515 |
struct Pref { |
516 |
nsCString name; |
517 |
bool isLocked; |
518 |
@@ -273,7 +279,6 @@ struct XPCOMInitData |
519 |
ClipboardCapabilities clipboardCaps; |
520 |
DomainPolicyClone domainPolicy; |
521 |
OptionalURIParams userContentSheetURL; |
522 |
- Pref[] prefs; |
523 |
GfxVarUpdate[] gfxNonDefaultVarUpdates; |
524 |
ContentDeviceData contentDeviceData; |
525 |
GfxInfoFeatureStatus[] gfxFeatureStatus; |
526 |
diff --git dom/ipc/moz.build dom/ipc/moz.build |
527 |
index 3c5541c7791b..5e92a0d52b5d 100644 |
528 |
--- dom/ipc/moz.build |
529 |
+++ dom/ipc/moz.build |
530 |
@@ -26,7 +26,6 @@ EXPORTS.mozilla.dom += [ |
531 |
'ContentBridgeParent.h', |
532 |
'ContentChild.h', |
533 |
'ContentParent.h', |
534 |
- 'ContentPrefs.h', |
535 |
'ContentProcess.h', |
536 |
'ContentProcessHost.h', |
537 |
'ContentProcessManager.h', |
538 |
@@ -59,7 +58,6 @@ UNIFIED_SOURCES += [ |
539 |
'ContentBridgeChild.cpp', |
540 |
'ContentBridgeParent.cpp', |
541 |
'ContentParent.cpp', |
542 |
- 'ContentPrefs.cpp', |
543 |
'ContentProcess.cpp', |
544 |
'ContentProcessHost.cpp', |
545 |
'ContentProcessManager.cpp', |
546 |
diff --git layout/style/nsCSSProps.h layout/style/nsCSSProps.h |
547 |
index dce44bf61b35..80288336a08b 100644 |
548 |
--- layout/style/nsCSSProps.h |
549 |
+++ layout/style/nsCSSProps.h |
550 |
@@ -645,7 +645,7 @@ public: |
551 |
// In the child process, assert that we're not trying to parse stylesheets |
552 |
// before we've gotten all our prefs. |
553 |
MOZ_ASSERT_IF(!XRE_IsParentProcess(), |
554 |
- mozilla::Preferences::AreAllPrefsSetInContentProcess()); |
555 |
+ mozilla::Preferences::ArePrefsInitedInContentProcess()); |
556 |
return gPropertyEnabled[aProperty]; |
557 |
} |
558 |
|
559 |
diff --git modules/libpref/Preferences.cpp modules/libpref/Preferences.cpp |
560 |
index fe780686f2eb..488095f49236 100644 |
561 |
--- modules/libpref/Preferences.cpp |
562 |
+++ modules/libpref/Preferences.cpp |
563 |
@@ -15,7 +15,6 @@ |
564 |
#include "mozilla/ArenaAllocator.h" |
565 |
#include "mozilla/ArrayUtils.h" |
566 |
#include "mozilla/Attributes.h" |
567 |
-#include "mozilla/dom/ContentPrefs.h" |
568 |
#include "mozilla/dom/PContent.h" |
569 |
#include "mozilla/HashFunctions.h" |
570 |
#include "mozilla/Logging.h" |
571 |
@@ -131,6 +130,29 @@ enum class PrefType : uint8_t |
572 |
Bool = 3, |
573 |
}; |
574 |
|
575 |
+// This is used for pref names and string pref values. We encode the string |
576 |
+// length, then a '/', then the string chars. This encoding means there are no |
577 |
+// special chars that are forbidden or require escaping. |
578 |
+static void |
579 |
+SerializeAndAppendString(const char* aChars, nsCString& aStr) |
580 |
+{ |
581 |
+ aStr.AppendInt(uint32_t(strlen(aChars))); |
582 |
+ aStr.Append('/'); |
583 |
+ aStr.Append(aChars); |
584 |
+} |
585 |
+ |
586 |
+static char* |
587 |
+DeserializeString(char* aChars, nsCString& aStr) |
588 |
+{ |
589 |
+ char* p = aChars; |
590 |
+ uint32_t length = strtol(p, &p, 10); |
591 |
+ MOZ_ASSERT(p[0] == '/'); |
592 |
+ p++; // move past the '/' |
593 |
+ aStr.Assign(p, length); |
594 |
+ p += length; // move past the string itself |
595 |
+ return p; |
596 |
+} |
597 |
+ |
598 |
// Keep this in sync with PrefValue in prefs_parser/src/lib.rs. |
599 |
union PrefValue { |
600 |
const char* mStringVal; |
601 |
@@ -223,6 +245,64 @@ union PrefValue { |
602 |
MOZ_CRASH(); |
603 |
} |
604 |
} |
605 |
+ |
606 |
+ void SerializeAndAppend(PrefType aType, nsCString& aStr) |
607 |
+ { |
608 |
+ switch (aType) { |
609 |
+ case PrefType::Bool: |
610 |
+ aStr.Append(mBoolVal ? 'T' : 'F'); |
611 |
+ break; |
612 |
+ |
613 |
+ case PrefType::Int: |
614 |
+ aStr.AppendInt(mIntVal); |
615 |
+ break; |
616 |
+ |
617 |
+ case PrefType::String: { |
618 |
+ SerializeAndAppendString(mStringVal, aStr); |
619 |
+ break; |
620 |
+ } |
621 |
+ |
622 |
+ case PrefType::None: |
623 |
+ default: |
624 |
+ MOZ_CRASH(); |
625 |
+ } |
626 |
+ } |
627 |
+ |
628 |
+ static char* Deserialize(PrefType aType, |
629 |
+ char* aStr, |
630 |
+ dom::MaybePrefValue* aDomValue) |
631 |
+ { |
632 |
+ char* p = aStr; |
633 |
+ |
634 |
+ switch (aType) { |
635 |
+ case PrefType::Bool: |
636 |
+ if (*p == 'T') { |
637 |
+ *aDomValue = true; |
638 |
+ } else if (*p == 'F') { |
639 |
+ *aDomValue = false; |
640 |
+ } else { |
641 |
+ *aDomValue = false; |
642 |
+ NS_ERROR("bad bool pref value"); |
643 |
+ } |
644 |
+ p++; |
645 |
+ return p; |
646 |
+ |
647 |
+ case PrefType::Int: { |
648 |
+ *aDomValue = int32_t(strtol(p, &p, 10)); |
649 |
+ return p; |
650 |
+ } |
651 |
+ |
652 |
+ case PrefType::String: { |
653 |
+ nsCString str; |
654 |
+ p = DeserializeString(p, str); |
655 |
+ *aDomValue = str; |
656 |
+ return p; |
657 |
+ } |
658 |
+ |
659 |
+ default: |
660 |
+ MOZ_CRASH(); |
661 |
+ } |
662 |
+ } |
663 |
}; |
664 |
|
665 |
#ifdef DEBUG |
666 |
@@ -694,6 +774,159 @@ public: |
667 |
return false; |
668 |
} |
669 |
|
670 |
+ // Prefs are serialized in a manner that mirrors dom::Pref. The two should be |
671 |
+ // kept in sync. E.g. if something is added to one it should also be added to |
672 |
+ // the other. (It would be nice to be able to use the code generated from |
673 |
+ // IPDL for serializing dom::Pref here instead of writing by hand this |
674 |
+ // serialization/deserialization. Unfortunately, that generated code is |
675 |
+ // difficult to use directly, outside of the IPDL IPC code.) |
676 |
+ // |
677 |
+ // The grammar for the serialized prefs has the following form. |
678 |
+ // |
679 |
+ // <pref> = <type> <locked> ':' <name> ':' <value>? ':' <value>? '\n' |
680 |
+ // <type> = 'B' | 'I' | 'S' |
681 |
+ // <locked> = 'L' | '-' |
682 |
+ // <name> = <string-value> |
683 |
+ // <value> = <bool-value> | <int-value> | <string-value> |
684 |
+ // <bool-value> = 'T' | 'F' |
685 |
+ // <int-value> = an integer literal accepted by strtol() |
686 |
+ // <string-value> = <int-value> '/' <chars> |
687 |
+ // <chars> = any char sequence of length dictated by the preceding |
688 |
+ // <int-value>. |
689 |
+ // |
690 |
+ // No whitespace is tolerated between tokens. <type> must match the types of |
691 |
+ // the values. |
692 |
+ // |
693 |
+ // The serialization is text-based, rather than binary, for the following |
694 |
+ // reasons. |
695 |
+ // |
696 |
+ // - The size difference wouldn't be much different between text-based and |
697 |
+ // binary. Most of the space is for strings (pref names and string pref |
698 |
+ // values), which would be the same in both styles. And other differences |
699 |
+ // would be minimal, e.g. small integers are shorter in text but long |
700 |
+ // integers are longer in text. |
701 |
+ // |
702 |
+ // - Likewise, speed differences should be negligible. |
703 |
+ // |
704 |
+ // - It's much easier to debug a text-based serialization. E.g. you can |
705 |
+ // print it and inspect it easily in a debugger. |
706 |
+ // |
707 |
+ // Examples of unlocked boolean prefs: |
708 |
+ // - "B-:8/my.bool1:F:T\n" |
709 |
+ // - "B-:8/my.bool2:F:\n" |
710 |
+ // - "B-:8/my.bool3::T\n" |
711 |
+ // |
712 |
+ // Examples of locked integer prefs: |
713 |
+ // - "IL:7/my.int1:0:1\n" |
714 |
+ // - "IL:7/my.int2:123:\n" |
715 |
+ // - "IL:7/my.int3::-99\n" |
716 |
+ // |
717 |
+ // Examples of unlocked string prefs: |
718 |
+ // - "S-:10/my.string1:3/abc:4/wxyz\n" |
719 |
+ // - "S-:10/my.string2:5/1.234:\n" |
720 |
+ // - "S-:10/my.string3::7/string!\n" |
721 |
+ |
722 |
+ void SerializeAndAppend(nsCString& aStr) |
723 |
+ { |
724 |
+ switch (Type()) { |
725 |
+ case PrefType::Bool: |
726 |
+ aStr.Append('B'); |
727 |
+ break; |
728 |
+ |
729 |
+ case PrefType::Int: |
730 |
+ aStr.Append('I'); |
731 |
+ break; |
732 |
+ |
733 |
+ case PrefType::String: { |
734 |
+ aStr.Append('S'); |
735 |
+ break; |
736 |
+ } |
737 |
+ |
738 |
+ case PrefType::None: |
739 |
+ default: |
740 |
+ MOZ_CRASH(); |
741 |
+ } |
742 |
+ |
743 |
+ aStr.Append(mIsLocked ? 'L' : '-'); |
744 |
+ aStr.Append(':'); |
745 |
+ |
746 |
+ SerializeAndAppendString(mName, aStr); |
747 |
+ aStr.Append(':'); |
748 |
+ |
749 |
+ if (mHasDefaultValue) { |
750 |
+ mDefaultValue.SerializeAndAppend(Type(), aStr); |
751 |
+ } |
752 |
+ aStr.Append(':'); |
753 |
+ |
754 |
+ if (mHasUserValue) { |
755 |
+ mUserValue.SerializeAndAppend(Type(), aStr); |
756 |
+ } |
757 |
+ aStr.Append('\n'); |
758 |
+ } |
759 |
+ |
760 |
+ static char* Deserialize(char* aStr, dom::Pref* aDomPref) |
761 |
+ { |
762 |
+ char* p = aStr; |
763 |
+ |
764 |
+ // The type. |
765 |
+ PrefType type; |
766 |
+ if (*p == 'B') { |
767 |
+ type = PrefType::Bool; |
768 |
+ } else if (*p == 'I') { |
769 |
+ type = PrefType::Int; |
770 |
+ } else if (*p == 'S') { |
771 |
+ type = PrefType::String; |
772 |
+ } else { |
773 |
+ NS_ERROR("bad pref type"); |
774 |
+ type = PrefType::None; |
775 |
+ } |
776 |
+ p++; // move past the type char |
777 |
+ |
778 |
+ // Locked? |
779 |
+ bool isLocked; |
780 |
+ if (*p == 'L') { |
781 |
+ isLocked = true; |
782 |
+ } else if (*p == '-') { |
783 |
+ isLocked = false; |
784 |
+ } else { |
785 |
+ NS_ERROR("bad pref locked status"); |
786 |
+ isLocked = false; |
787 |
+ } |
788 |
+ p++; // move past the isLocked char |
789 |
+ |
790 |
+ MOZ_ASSERT(*p == ':'); |
791 |
+ p++; // move past the ':' |
792 |
+ |
793 |
+ // The pref name. |
794 |
+ nsCString name; |
795 |
+ p = DeserializeString(p, name); |
796 |
+ |
797 |
+ MOZ_ASSERT(*p == ':'); |
798 |
+ p++; // move past the ':' preceding the default value |
799 |
+ |
800 |
+ dom::MaybePrefValue maybeDefaultValue; |
801 |
+ if (*p != ':') { |
802 |
+ dom::PrefValue defaultValue; |
803 |
+ p = PrefValue::Deserialize(type, p, &maybeDefaultValue); |
804 |
+ } |
805 |
+ |
806 |
+ MOZ_ASSERT(*p == ':'); |
807 |
+ p++; // move past the ':' between the default and user values |
808 |
+ |
809 |
+ dom::MaybePrefValue maybeUserValue; |
810 |
+ if (*p != '\n') { |
811 |
+ dom::PrefValue userValue; |
812 |
+ p = PrefValue::Deserialize(type, p, &maybeUserValue); |
813 |
+ } |
814 |
+ |
815 |
+ MOZ_ASSERT(*p == '\n'); |
816 |
+ p++; // move past the '\n' following the user value |
817 |
+ |
818 |
+ *aDomPref = dom::Pref(name, isLocked, maybeDefaultValue, maybeUserValue); |
819 |
+ |
820 |
+ return p; |
821 |
+ } |
822 |
+ |
823 |
void AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, PrefsSizes& aSizes) |
824 |
{ |
825 |
// Note: mName is allocated in gPrefNameArena, measured elsewhere. |
826 |
@@ -880,41 +1113,9 @@ pref_savePrefs() |
827 |
|
828 |
#ifdef DEBUG |
829 |
|
830 |
-// For content processes, what prefs have been initialized? |
831 |
-enum class ContentProcessPhase |
832 |
-{ |
833 |
- eNoPrefsSet, |
834 |
- eEarlyPrefsSet, |
835 |
- eEarlyAndLatePrefsSet, |
836 |
-}; |
837 |
- |
838 |
// Note that this never changes in the parent process, and is only read in |
839 |
// content processes. |
840 |
-static ContentProcessPhase gPhase = ContentProcessPhase::eNoPrefsSet; |
841 |
- |
842 |
-struct StringComparator |
843 |
-{ |
844 |
- const char* mPrefName; |
845 |
- |
846 |
- explicit StringComparator(const char* aPrefName) |
847 |
- : mPrefName(aPrefName) |
848 |
- { |
849 |
- } |
850 |
- |
851 |
- int operator()(const char* aPrefName) const |
852 |
- { |
853 |
- return strcmp(mPrefName, aPrefName); |
854 |
- } |
855 |
-}; |
856 |
- |
857 |
-static bool |
858 |
-IsEarlyPref(const char* aPrefName) |
859 |
-{ |
860 |
- size_t prefsLen; |
861 |
- size_t found; |
862 |
- const char** list = mozilla::dom::ContentPrefs::GetEarlyPrefs(&prefsLen); |
863 |
- return BinarySearchIf(list, 0, prefsLen, StringComparator(aPrefName), &found); |
864 |
-} |
865 |
+static bool gContentProcessPrefsAreInited = false; |
866 |
|
867 |
#endif // DEBUG |
868 |
|
869 |
@@ -923,23 +1124,7 @@ pref_HashTableLookupInner(const char* aPrefName) |
870 |
{ |
871 |
MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal()); |
872 |
|
873 |
-#ifdef DEBUG |
874 |
- if (!XRE_IsParentProcess()) { |
875 |
- if (gPhase == ContentProcessPhase::eNoPrefsSet) { |
876 |
- MOZ_CRASH_UNSAFE_PRINTF("accessing pref %s before early prefs are set", |
877 |
- aPrefName); |
878 |
- } |
879 |
- |
880 |
- if (gPhase == ContentProcessPhase::eEarlyPrefsSet && |
881 |
- !IsEarlyPref(aPrefName)) { |
882 |
- // If you hit this crash, you have an early access of a non-early pref. |
883 |
- // Consider moving the access later or add the pref to the whitelist of |
884 |
- // early prefs in ContentPrefs.cpp and get review from a DOM peer. |
885 |
- MOZ_CRASH_UNSAFE_PRINTF( |
886 |
- "accessing non-early pref %s before late prefs are set", aPrefName); |
887 |
- } |
888 |
- } |
889 |
-#endif |
890 |
+ MOZ_ASSERT_IF(!XRE_IsParentProcess(), gContentProcessPrefsAreInited); |
891 |
|
892 |
return static_cast<PrefEntry*>(gHashTable->Search(aPrefName)); |
893 |
} |
894 |
@@ -2932,8 +3117,8 @@ public: |
895 |
|
896 |
} // namespace |
897 |
|
898 |
-// A list of prefs sent early from the parent, via shared memory. |
899 |
-static InfallibleTArray<dom::Pref>* gEarlyDomPrefs; |
900 |
+// A list of changed prefs sent from the parent via shared memory. |
901 |
+static InfallibleTArray<dom::Pref>* gChangedDomPrefs; |
902 |
|
903 |
static const char kTelemetryPref[] = "toolkit.telemetry.enabled"; |
904 |
static const char kChannelPref[] = "app.update.channel"; |
905 |
@@ -3050,12 +3235,12 @@ Preferences::GetInstanceForService() |
906 |
} |
907 |
|
908 |
if (!XRE_IsParentProcess()) { |
909 |
- MOZ_ASSERT(gEarlyDomPrefs); |
910 |
- for (unsigned int i = 0; i < gEarlyDomPrefs->Length(); i++) { |
911 |
- Preferences::SetPreference(gEarlyDomPrefs->ElementAt(i)); |
912 |
+ MOZ_ASSERT(gChangedDomPrefs); |
913 |
+ for (unsigned int i = 0; i < gChangedDomPrefs->Length(); i++) { |
914 |
+ Preferences::SetPreference(gChangedDomPrefs->ElementAt(i)); |
915 |
} |
916 |
- delete gEarlyDomPrefs; |
917 |
- gEarlyDomPrefs = nullptr; |
918 |
+ delete gChangedDomPrefs; |
919 |
+ gChangedDomPrefs = nullptr; |
920 |
|
921 |
} else { |
922 |
// Check if there is a deployment configuration file. If so, set up the |
923 |
@@ -3179,149 +3364,44 @@ NS_IMPL_ISUPPORTS(Preferences, |
924 |
nsISupportsWeakReference) |
925 |
|
926 |
/* static */ void |
927 |
-Preferences::SerializeEarlyPreferences(nsCString& aStr) |
928 |
+Preferences::SerializePreferences(nsCString& aStr) |
929 |
{ |
930 |
MOZ_RELEASE_ASSERT(InitStaticMembers()); |
931 |
|
932 |
- nsAutoCStringN<256> boolPrefs, intPrefs, stringPrefs; |
933 |
- size_t numEarlyPrefs; |
934 |
- dom::ContentPrefs::GetEarlyPrefs(&numEarlyPrefs); |
935 |
- |
936 |
- for (unsigned int i = 0; i < numEarlyPrefs; i++) { |
937 |
- const char* prefName = dom::ContentPrefs::GetEarlyPref(i); |
938 |
- MOZ_ASSERT_IF(i > 0, |
939 |
- strcmp(prefName, dom::ContentPrefs::GetEarlyPref(i - 1)) > 0); |
940 |
- |
941 |
- Pref* pref = pref_HashTableLookup(prefName); |
942 |
- if (!pref || !pref->MustSendToContentProcesses()) { |
943 |
- continue; |
944 |
- } |
945 |
+ aStr.Truncate(); |
946 |
|
947 |
- switch (pref->Type()) { |
948 |
- case PrefType::Bool: |
949 |
- boolPrefs.Append( |
950 |
- nsPrintfCString("%u:%d|", i, Preferences::GetBool(prefName))); |
951 |
- break; |
952 |
- case PrefType::Int: |
953 |
- intPrefs.Append( |
954 |
- nsPrintfCString("%u:%d|", i, Preferences::GetInt(prefName))); |
955 |
- break; |
956 |
- case PrefType::String: { |
957 |
- nsAutoCString value; |
958 |
- Preferences::GetCString(prefName, value); |
959 |
- stringPrefs.Append( |
960 |
- nsPrintfCString("%u:%d;%s|", i, value.Length(), value.get())); |
961 |
- } break; |
962 |
- case PrefType::None: |
963 |
- break; |
964 |
- default: |
965 |
- printf_stderr("preference type: %d\n", int(pref->Type())); |
966 |
- MOZ_CRASH(); |
967 |
+ for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) { |
968 |
+ Pref* pref = static_cast<PrefEntry*>(iter.Get())->mPref; |
969 |
+ if (pref->MustSendToContentProcesses() && pref->HasAdvisablySizedValues()) { |
970 |
+ pref->SerializeAndAppend(aStr); |
971 |
} |
972 |
} |
973 |
|
974 |
- aStr.Truncate(); |
975 |
- aStr.Append(boolPrefs); |
976 |
- aStr.Append('\n'); |
977 |
- aStr.Append(intPrefs); |
978 |
- aStr.Append('\n'); |
979 |
- aStr.Append(stringPrefs); |
980 |
- aStr.Append('\n'); |
981 |
aStr.Append('\0'); |
982 |
} |
983 |
|
984 |
/* static */ void |
985 |
-Preferences::DeserializeEarlyPreferences(char* aStr, size_t aStrLen) |
986 |
+Preferences::DeserializePreferences(char* aStr, size_t aPrefsLen) |
987 |
{ |
988 |
MOZ_ASSERT(!XRE_IsParentProcess()); |
989 |
|
990 |
- MOZ_ASSERT(!gEarlyDomPrefs); |
991 |
- gEarlyDomPrefs = new InfallibleTArray<dom::Pref>(); |
992 |
+ MOZ_ASSERT(!gChangedDomPrefs); |
993 |
+ gChangedDomPrefs = new InfallibleTArray<dom::Pref>(); |
994 |
|
995 |
char* p = aStr; |
996 |
- |
997 |
- // XXX: we assume these pref values are default values, which may not be |
998 |
- // true. We also assume they are unlocked. Fortunately, these prefs get reset |
999 |
- // properly by the first IPC message. |
1000 |
- |
1001 |
- // Get the bool prefs. |
1002 |
- while (*p != '\n') { |
1003 |
- int32_t index = strtol(p, &p, 10); |
1004 |
- MOZ_ASSERT(p[0] == ':'); |
1005 |
- p++; |
1006 |
- int v = strtol(p, &p, 10); |
1007 |
- MOZ_ASSERT(v == 0 || v == 1); |
1008 |
- dom::MaybePrefValue value(dom::PrefValue(!!v)); |
1009 |
- MOZ_ASSERT(p[0] == '|'); |
1010 |
- p++; |
1011 |
- dom::Pref pref(nsCString(dom::ContentPrefs::GetEarlyPref(index)), |
1012 |
- /* isLocked */ false, |
1013 |
- value, |
1014 |
- dom::MaybePrefValue()); |
1015 |
- gEarlyDomPrefs->AppendElement(pref); |
1016 |
- } |
1017 |
- p++; |
1018 |
- |
1019 |
- // Get the int prefs. |
1020 |
- while (*p != '\n') { |
1021 |
- int32_t index = strtol(p, &p, 10); |
1022 |
- MOZ_ASSERT(p[0] == ':'); |
1023 |
- p++; |
1024 |
- dom::MaybePrefValue value( |
1025 |
- dom::PrefValue(static_cast<int32_t>(strtol(p, &p, 10)))); |
1026 |
- MOZ_ASSERT(p[0] == '|'); |
1027 |
- p++; |
1028 |
- dom::Pref pref(nsCString(dom::ContentPrefs::GetEarlyPref(index)), |
1029 |
- /* isLocked */ false, |
1030 |
- value, |
1031 |
- dom::MaybePrefValue()); |
1032 |
- gEarlyDomPrefs->AppendElement(pref); |
1033 |
- } |
1034 |
- p++; |
1035 |
- |
1036 |
- // Get the string prefs. |
1037 |
- while (*p != '\n') { |
1038 |
- int32_t index = strtol(p, &p, 10); |
1039 |
- MOZ_ASSERT(p[0] == ':'); |
1040 |
- p++; |
1041 |
- int32_t length = strtol(p, &p, 10); |
1042 |
- MOZ_ASSERT(p[0] == ';'); |
1043 |
- p++; |
1044 |
- dom::MaybePrefValue value(dom::PrefValue(nsCString(p, length))); |
1045 |
- dom::Pref pref(nsCString(dom::ContentPrefs::GetEarlyPref(index)), |
1046 |
- /* isLocked */ false, |
1047 |
- value, |
1048 |
- dom::MaybePrefValue()); |
1049 |
- gEarlyDomPrefs->AppendElement(pref); |
1050 |
- p += length + 1; |
1051 |
- MOZ_ASSERT(*(p - 1) == '|'); |
1052 |
- } |
1053 |
- p++; |
1054 |
- |
1055 |
- MOZ_ASSERT(*p == '\0'); |
1056 |
+ while (*p != '\0') { |
1057 |
+ dom::Pref pref; |
1058 |
+ p = Pref::Deserialize(p, &pref); |
1059 |
+ gChangedDomPrefs->AppendElement(pref); |
1060 |
+ } |
1061 |
|
1062 |
// We finished parsing on a '\0'. That should be the last char in the shared |
1063 |
- // memory. |
1064 |
- MOZ_ASSERT(aStr + aStrLen - 1 == p); |
1065 |
- |
1066 |
-#ifdef DEBUG |
1067 |
- MOZ_ASSERT(gPhase == ContentProcessPhase::eNoPrefsSet); |
1068 |
- gPhase = ContentProcessPhase::eEarlyPrefsSet; |
1069 |
-#endif |
1070 |
-} |
1071 |
- |
1072 |
-/* static */ void |
1073 |
-Preferences::SetLatePreferences(const nsTArray<dom::Pref>* aDomPrefs) |
1074 |
-{ |
1075 |
- MOZ_ASSERT(!XRE_IsParentProcess()); |
1076 |
- |
1077 |
- for (unsigned int i = 0; i < aDomPrefs->Length(); i++) { |
1078 |
- Preferences::SetPreference(aDomPrefs->ElementAt(i)); |
1079 |
- } |
1080 |
+ // memory. (aPrefsLen includes the '\0'.) |
1081 |
+ MOZ_ASSERT(p == aStr + aPrefsLen - 1); |
1082 |
|
1083 |
#ifdef DEBUG |
1084 |
- MOZ_ASSERT(gPhase == ContentProcessPhase::eEarlyPrefsSet); |
1085 |
- gPhase = ContentProcessPhase::eEarlyAndLatePrefsSet; |
1086 |
+ MOZ_ASSERT(!gContentProcessPrefsAreInited); |
1087 |
+ gContentProcessPrefsAreInited = true; |
1088 |
#endif |
1089 |
} |
1090 |
|
1091 |
@@ -3558,36 +3638,12 @@ Preferences::GetPreference(dom::Pref* aDomPref) |
1092 |
} |
1093 |
} |
1094 |
|
1095 |
-void |
1096 |
-Preferences::GetPreferences(InfallibleTArray<dom::Pref>* aDomPrefs) |
1097 |
-{ |
1098 |
- MOZ_ASSERT(XRE_IsParentProcess()); |
1099 |
- MOZ_ASSERT(NS_IsMainThread()); |
1100 |
- |
1101 |
- aDomPrefs->SetCapacity(gHashTable->EntryCount()); |
1102 |
- for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) { |
1103 |
- Pref* pref = static_cast<PrefEntry*>(iter.Get())->mPref; |
1104 |
- |
1105 |
- if (!pref->MustSendToContentProcesses()) { |
1106 |
- // The pref value hasn't changed since it was initialized at startup. |
1107 |
- // Don't bother sending it, because the content process will initialize |
1108 |
- // it the same way. |
1109 |
- continue; |
1110 |
- } |
1111 |
- |
1112 |
- if (pref->HasAdvisablySizedValues()) { |
1113 |
- dom::Pref* setting = aDomPrefs->AppendElement(); |
1114 |
- pref->ToDomPref(setting); |
1115 |
- } |
1116 |
- } |
1117 |
-} |
1118 |
- |
1119 |
#ifdef DEBUG |
1120 |
bool |
1121 |
-Preferences::AreAllPrefsSetInContentProcess() |
1122 |
+Preferences::ArePrefsInitedInContentProcess() |
1123 |
{ |
1124 |
MOZ_ASSERT(!XRE_IsParentProcess()); |
1125 |
- return gPhase == ContentProcessPhase::eEarlyAndLatePrefsSet; |
1126 |
+ return gContentProcessPrefsAreInited; |
1127 |
} |
1128 |
#endif |
1129 |
|
1130 |
diff --git modules/libpref/Preferences.h modules/libpref/Preferences.h |
1131 |
index 0d976483daae..901425b5b663 100644 |
1132 |
--- modules/libpref/Preferences.h |
1133 |
+++ modules/libpref/Preferences.h |
1134 |
@@ -328,15 +328,10 @@ public: |
1135 |
const char* aPref, |
1136 |
float aDefault = 0.0f); |
1137 |
|
1138 |
- // When a content process is created these methods are used to pass prefs in |
1139 |
- // bulk from the parent process. "Early" preferences are ones that are needed |
1140 |
- // very early on in the content process's lifetime; they are passed via a |
1141 |
- // special shared memory segment. "Late" preferences are the remainder, which |
1142 |
- // are passed via a standard IPC message. |
1143 |
- static void SerializeEarlyPreferences(nsCString& aStr); |
1144 |
- static void DeserializeEarlyPreferences(char* aStr, size_t aStrLen); |
1145 |
- static void GetPreferences(InfallibleTArray<dom::Pref>* aSettings); |
1146 |
- static void SetLatePreferences(const nsTArray<dom::Pref>* aSettings); |
1147 |
+ // When a content process is created these methods are used to pass changed |
1148 |
+ // prefs in bulk from the parent process, via shared memory. |
1149 |
+ static void SerializePreferences(nsCString& aStr); |
1150 |
+ static void DeserializePreferences(char* aStr, size_t aPrefsLen); |
1151 |
|
1152 |
// When a single pref is changed in the parent process, these methods are |
1153 |
// used to pass the update to content processes. |
1154 |
@@ -344,7 +339,7 @@ public: |
1155 |
static void SetPreference(const dom::Pref& aPref); |
1156 |
|
1157 |
#ifdef DEBUG |
1158 |
- static bool AreAllPrefsSetInContentProcess(); |
1159 |
+ static bool ArePrefsInitedInContentProcess(); |
1160 |
#endif |
1161 |
|
1162 |
static void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |