* Add a ampdoc factory to the extension currently being registered. This is a * restricted method and it's allowed to be called only during the overall * extension registration. * @param {function(!./ampdoc-impl.AmpDoc)} factory * @param {string=} opt_forName * @restricted
(factory, opt_forName)
| 426 | * @restricted |
| 427 | */ |
| 428 | addDocFactory(factory, opt_forName) { |
| 429 | const holder = this.getCurrentExtensionHolder_(opt_forName); |
| 430 | holder.docFactories.push(factory); |
| 431 | |
| 432 | // If a single-doc mode, run factory right away if it's included by the doc. |
| 433 | if (this.currentExtensionId_ && this.ampdocService_.isSingleDoc()) { |
| 434 | const ampdoc = this.ampdocService_.getAmpDoc(this.win.document); |
| 435 | const extensionId = dev().assertString(this.currentExtensionId_); |
| 436 | const version = dev().assertString(this.currentExtensionVersion_); |
| 437 | const latest = this.currentExtensionLatest_ || false; |
| 438 | // Note that this won't trigger for FIE extensions that are not present |
| 439 | // in the parent doc. |
| 440 | if ( |
| 441 | ampdoc.declaresExtension(extensionId, version) || |
| 442 | (latest && ampdoc.declaresExtension(extensionId, LATEST_VERSION)) || |
| 443 | holder.auto |
| 444 | ) { |
| 445 | factory(ampdoc); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Preinstalls built-ins and legacy elements in the emebedded ampdoc. |
no test coverage detected