OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 if (mojo && mojo.internal) { | 7 if (mojo && mojo.internal) { |
8 throw new Error('The Mojo bindings library has been initialized.'); | 8 throw new Error('The Mojo bindings library has been initialized.'); |
9 } | 9 } |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 // http://example.org/scripts/b/c/foo.mojom.js | 27 // http://example.org/scripts/b/c/foo.mojom.js |
28 // then the URL of bar.mojom.js will be: | 28 // then the URL of bar.mojom.js will be: |
29 // http://example.org/scripts/b/d/bar.mojom.js | 29 // http://example.org/scripts/b/d/bar.mojom.js |
30 // | 30 // |
31 // If you would like bar.mojom.js to live at a different location, you need | 31 // If you would like bar.mojom.js to live at a different location, you need |
32 // to turn off |autoLoadMojomDeps| before loading foo.mojom.js, and manually | 32 // to turn off |autoLoadMojomDeps| before loading foo.mojom.js, and manually |
33 // load bar.mojom.js yourself. Similarly, you need to turn off the option if | 33 // load bar.mojom.js yourself. Similarly, you need to turn off the option if |
34 // you merge bar.mojom.js and foo.mojom.js into a single file. | 34 // you merge bar.mojom.js and foo.mojom.js into a single file. |
35 // | 35 // |
36 // Performance tip: Avoid loading the same mojom.js file multiple times. | 36 // Performance tip: Avoid loading the same mojom.js file multiple times. |
37 // Assume that |autoLoadMojomDeps| is set to true: | 37 // Assume that |autoLoadMojomDeps| is set to true, |
38 // <!-- No duplicate loading; recommended. --> | 38 // |
| 39 // <!-- |
| 40 // (This comment tag is necessary on IOS to avoid interpreting the closing |
| 41 // script tags in the example.) |
| 42 // |
| 43 // No duplicate loading; recommended: |
39 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> | 44 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> |
40 // | 45 // |
41 // <!-- No duplicate loading, although unnecessary. --> | 46 // No duplicate loading, although unnecessary: |
42 // <script src="http://example.org/scripts/b/d/bar.mojom.js"></script> | 47 // <script src="http://example.org/scripts/b/d/bar.mojom.js"></script> |
43 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> | 48 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> |
44 // | 49 // |
45 // <!-- Load bar.mojom.js twice; should be avoided. --> | 50 // Load bar.mojom.js twice; should be avoided: |
46 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> | 51 // <script src="http://example.org/scripts/b/c/foo.mojom.js"></script> |
47 // <script src="http://example.org/scripts/b/d/bar.mojom.js"></script> | 52 // <script src="http://example.org/scripts/b/d/bar.mojom.js"></script> |
| 53 // |
| 54 // --> |
48 autoLoadMojomDeps: true | 55 autoLoadMojomDeps: true |
49 }; | 56 }; |
50 | 57 |
51 (function() { | 58 (function() { |
52 var internal = mojo.internal; | 59 var internal = mojo.internal; |
53 | 60 |
54 var LoadState = { | 61 var LoadState = { |
55 PENDING_LOAD: 1, | 62 PENDING_LOAD: 1, |
56 LOADED: 2 | 63 LOADED: 2 |
57 }; | 64 }; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 mojomRegistry.set(id, LoadState.LOADED); | 99 mojomRegistry.set(id, LoadState.LOADED); |
93 } | 100 } |
94 | 101 |
95 function loadMojomIfNecessary(id, url) { | 102 function loadMojomIfNecessary(id, url) { |
96 if (mojomRegistry.has(id)) { | 103 if (mojomRegistry.has(id)) { |
97 return; | 104 return; |
98 } | 105 } |
99 | 106 |
100 markMojomPendingLoad(id); | 107 markMojomPendingLoad(id); |
101 internal.global.document.write('<script type="text/javascript" src="' + | 108 internal.global.document.write('<script type="text/javascript" src="' + |
102 url + '"></script>'); | 109 url + '"><' + '/script>'); |
103 } | 110 } |
104 | 111 |
105 internal.exposeNamespace = exposeNamespace; | 112 internal.exposeNamespace = exposeNamespace; |
106 internal.isMojomPendingLoad = isMojomPendingLoad; | 113 internal.isMojomPendingLoad = isMojomPendingLoad; |
107 internal.isMojomLoaded = isMojomLoaded; | 114 internal.isMojomLoaded = isMojomLoaded; |
108 internal.markMojomPendingLoad = markMojomPendingLoad; | 115 internal.markMojomPendingLoad = markMojomPendingLoad; |
109 internal.markMojomLoaded = markMojomLoaded; | 116 internal.markMojomLoaded = markMojomLoaded; |
110 internal.loadMojomIfNecessary = loadMojomIfNecessary; | 117 internal.loadMojomIfNecessary = loadMojomIfNecessary; |
111 })(); | 118 })(); |
OLD | NEW |