diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 62384dfa845a..83fe76e6bb7b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -993,6 +993,12 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { params.load_type = content::NavigationController::LOAD_TYPE_HTTP_POST; } + GURL base_url_for_data_url; + if (options.Get("baseURLForDataURL", &base_url_for_data_url)) { + params.base_url_for_data_url = base_url_for_data_url; + params.load_type = content::NavigationController::LOAD_TYPE_DATA; + } + params.transition_type = ui::PAGE_TRANSITION_TYPED; params.should_clear_history_list = true; params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 398dd3b74649..9463ee0cca1d 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1004,6 +1004,7 @@ Same as `webContents.capturePage([rect, ]callback)`. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) + * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Same as `webContents.loadURL(url[, options])`. diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index b35bbdee7d4c..5e3e8dd697a4 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -541,6 +541,7 @@ that can't be set via `` attributes. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) + * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Loads the `url` in the window. The `url` must contain the protocol prefix, e.g. the `http://` or `file://`. If the load should bypass http cache then diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index abfd5a16824d..5efc225a1d65 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -312,6 +312,7 @@ webview.addEventListener('dom-ready', () => { * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) + * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Loads the `url` in the webview, the `url` must contain the protocol prefix, e.g. the `http://` or `file://`. diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index c9fe34aef8f4..4ee9c5b583dc 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -283,6 +283,14 @@ describe('BrowserWindow module', function () { w.loadURL(server.url) }) }) + + it('should support support base url for data urls', (done) => { + ipcMain.once('answer', function (event, test) { + assert.equal(test, 'test') + done() + }) + w.loadURL('data:text/html,', {baseURLForDataURL: `file://${path.join(fixtures, 'api')}${path.sep}`}) + }) }) describe('will-navigate event', function () { diff --git a/spec/fixtures/api/loaded-from-dataurl.js b/spec/fixtures/api/loaded-from-dataurl.js new file mode 100644 index 000000000000..c4dbdd044bdb --- /dev/null +++ b/spec/fixtures/api/loaded-from-dataurl.js @@ -0,0 +1 @@ +require('electron').ipcRenderer.send('answer', 'test')