Merge "Fix plugin .url() calculation when loaded from bundle"

This commit is contained in:
viktard
2018-12-21 00:00:42 +00:00
committed by Gerrit Code Review
2 changed files with 10 additions and 5 deletions

View File

@@ -441,11 +441,11 @@ limitations under the License.
test('installing preloaded plugin', () => {
let plugin;
window.ASSETS_PATH = 'http://blips.com/chitz/';
window.ASSETS_PATH = 'http://blips.com/chitz';
Gerrit.install(p => { plugin = p; }, '0.1', 'preloaded:foo');
assert.strictEqual(plugin.getPluginName(), 'foo');
assert.strictEqual(plugin.url('/some/thing.html'),
'http://blips.com/plugins/foo/some/thing.html');
'http://blips.com/chitz/plugins/foo/some/thing.html');
delete window.ASSETS_PATH;
});

View File

@@ -217,9 +217,14 @@
};
Plugin.prototype.url = function(opt_path) {
const base = Gerrit.BaseUrlBehavior.getBaseUrl();
return this._url.origin + base + '/plugins/' +
this._name + (opt_path || '/');
const relPath = '/plugins/' + this._name + (opt_path || '/');
if (window.location.origin === this._url.origin) {
// Plugin loaded from the same origin as gr-app, getBaseUrl in effect.
return this._url.origin + Gerrit.BaseUrlBehavior.getBaseUrl() + relPath;
} else {
// Plugin loaded from assets bundle, expect assets placed along with it.
return this._url.href.split('/plugins/' + this._name)[0] + relPath;
}
};
Plugin.prototype.screenUrl = function(opt_screenName) {