Fork a Polymer 2 version of gr-app The webserver can then serve both versions depending on e.g. a URL parameter. Change-Id: I385a1937357077a6c8fa1d54818ab0afb827728b
diff --git a/polygerrit-ui/app/elements/gr-app-p2.html b/polygerrit-ui/app/elements/gr-app-p2.html new file mode 100644 index 0000000..2ce5ed8 --- /dev/null +++ b/polygerrit-ui/app/elements/gr-app-p2.html
@@ -0,0 +1,40 @@ +<!-- +@license +Copyright (C) 2019 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<script> + window.Gerrit = window.Gerrit || {}; +</script> + +<link rel="import" href="/bower_components/polymer/polymer.html"> +<link rel="import" href="/bower_components/polymer-resin/polymer-resin.html"> +<link rel="import" href="/bower_components/polymer/lib/legacy/legacy-data-mixin.html"> +<link rel="import" href="/bower_components/shadycss/apply-shim.html"> +<link rel="import" href="../behaviors/safe-types-behavior/safe-types-behavior.html"> +<script> + security.polymer_resin.install({ + allowedIdentifierPrefixes: [''], + reportHandler: security.polymer_resin.CONSOLE_LOGGING_REPORT_HANDLER, + safeTypesBridge: Gerrit.SafeTypes.safeTypesBridge, + }); +</script> + +<link rel="import" href="./gr-app-element.html"> +<dom-module id="gr-app-p2"> + <template> + <gr-app-element id="app-element"></gr-app-element> + </template> + <script src="gr-app-p2.js" crossorigin="anonymous"></script> +</dom-module>
diff --git a/polygerrit-ui/app/elements/gr-app-p2.js b/polygerrit-ui/app/elements/gr-app-p2.js new file mode 100644 index 0000000..2163c02 --- /dev/null +++ b/polygerrit-ui/app/elements/gr-app-p2.js
@@ -0,0 +1,23 @@ +/** + * @license + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function() { + 'use strict'; + + Polymer({ + is: 'gr-app-p2', + }); +})();
diff --git a/polygerrit-ui/app/elements/gr-app.html b/polygerrit-ui/app/elements/gr-app.html index 1a31d4c..e2d2680 100644 --- a/polygerrit-ui/app/elements/gr-app.html +++ b/polygerrit-ui/app/elements/gr-app.html
@@ -15,25 +15,22 @@ limitations under the License. --> <script> - if (!window.POLYMER2) { - // This must be set prior to loading Polymer for the first time. - if (localStorage.getItem('USE_SHADOW_DOM') === 'true') { - window.Polymer = { - dom: 'shadow', - passiveTouchGestures: true, - }; - } else if (!window.Polymer) { - window.Polymer = { - passiveTouchGestures: true, - }; - } + // This must be set prior to loading Polymer for the first time. + if (localStorage.getItem('USE_SHADOW_DOM') === 'true') { + window.Polymer = { + dom: 'shadow', + passiveTouchGestures: true, + }; + } else if (!window.Polymer) { + window.Polymer = { + passiveTouchGestures: true, + }; } window.Gerrit = window.Gerrit || {}; </script> <link rel="import" href="/bower_components/polymer/polymer.html"> <link rel="import" href="/bower_components/polymer-resin/standalone/polymer-resin.html"> -<link rel="import" href="/bower_components/polymer/lib/legacy/legacy-data-mixin.html"> <link rel="import" href="../behaviors/safe-types-behavior/safe-types-behavior.html"> <script> security.polymer_resin.install({
diff --git a/polygerrit-ui/app/elements/gr-app.js b/polygerrit-ui/app/elements/gr-app.js index 2298b2f..5c74659 100644 --- a/polygerrit-ui/app/elements/gr-app.js +++ b/polygerrit-ui/app/elements/gr-app.js
@@ -21,9 +21,7 @@ // requestAnimationFrame.) // @see https://github.com/Polymer/polymer/issues/3851 // @see Issue 4699 - if (!window.POLYMER2) { - Polymer.RenderStatus._makeReady(); - } + Polymer.RenderStatus._makeReady(); Polymer({ is: 'gr-app',
diff --git a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy index bca05db..c907ae9 100644 --- a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy +++ b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
@@ -79,7 +79,13 @@ <link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff" as="font" type="font/woff" crossorigin="anonymous">{\n} <link rel="stylesheet" href="{$staticResourcePath}/styles/fonts.css">{\n} <link rel="stylesheet" href="{$staticResourcePath}/styles/main.css">{\n} - <script src="{$staticResourcePath}/bower_components/webcomponentsjs/webcomponents-lite.js"></script>{\n} + + {if $polymer2} + <script src="{$staticResourcePath}/bower_components/webcomponentsjs-p2/webcomponents-lite.js"></script>{\n} + {else} + <script src="{$staticResourcePath}/bower_components/webcomponentsjs/webcomponents-lite.js"></script>{\n} + {/if} + // Content between webcomponents-lite and the load of the main app element // run before polymer-resin is installed so may have security consequences. // Contact your local security engineer if you have any questions, and @@ -90,9 +96,18 @@ <link rel="import" href="{$assetsPath}/{$assetsBundle}">{\n} {/if} - <link rel="preload" href="{$staticResourcePath}/elements/gr-app.js" as="script" crossorigin="anonymous">{\n} - <link rel="import" href="{$staticResourcePath}/elements/gr-app.html">{\n} + {if $polymer2} + <link rel="preload" href="{$staticResourcePath}/elements/gr-app-p2.js" as="script" crossorigin="anonymous">{\n} + <link rel="import" href="{$staticResourcePath}/elements/gr-app-p2.html">{\n} + {else} + <link rel="preload" href="{$staticResourcePath}/elements/gr-app.js" as="script" crossorigin="anonymous">{\n} + <link rel="import" href="{$staticResourcePath}/elements/gr-app.html">{\n} + {/if} <body unresolved>{\n} - <gr-app id="app"></gr-app>{\n} + {if $polymer2} + <gr-app-p2 id="app"></gr-app-p2>{\n} + {else} + <gr-app id="app"></gr-app>{\n} + {/if} {/template}