Merge pull request #801 from frankhale/http-referrer
Add http referrer to LoadUrl and Webview
This commit is contained in:
commit
993c52dcd5
6 changed files with 56 additions and 14 deletions
|
@ -286,8 +286,15 @@ bool WebContents::IsAlive() const {
|
||||||
return web_contents() != NULL;
|
return web_contents() != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::LoadURL(const GURL& url) {
|
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||||
content::NavigationController::LoadURLParams params(url);
|
content::NavigationController::LoadURLParams params(url);
|
||||||
|
|
||||||
|
base::string16 http_referrer;
|
||||||
|
|
||||||
|
if (options.Get("httpreferrer", &http_referrer_))
|
||||||
|
params.referrer = content::Referrer(GURL(http_referrer_).GetAsReferrer(),
|
||||||
|
blink::WebReferrerPolicyDefault);
|
||||||
|
|
||||||
params.transition_type = content::PAGE_TRANSITION_TYPED;
|
params.transition_type = content::PAGE_TRANSITION_TYPED;
|
||||||
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
||||||
web_contents()->GetController().LoadURLWithParams(params);
|
web_contents()->GetController().LoadURLWithParams(params);
|
||||||
|
@ -313,15 +320,15 @@ void WebContents::Stop() {
|
||||||
web_contents()->Stop();
|
web_contents()->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Reload() {
|
void WebContents::Reload(const mate::Dictionary& options) {
|
||||||
// Navigating to a URL would always restart the renderer process, we want this
|
// Navigating to a URL would always restart the renderer process, we want this
|
||||||
// because normal reloading will break our node integration.
|
// because normal reloading will break our node integration.
|
||||||
// This is done by AtomBrowserClient::ShouldSwapProcessesForNavigation.
|
// This is done by AtomBrowserClient::ShouldSwapProcessesForNavigation.
|
||||||
LoadURL(GetURL());
|
LoadURL(GetURL(), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::ReloadIgnoringCache() {
|
void WebContents::ReloadIgnoringCache(const mate::Dictionary& options) {
|
||||||
Reload();
|
Reload(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::CanGoBack() const {
|
bool WebContents::CanGoBack() const {
|
||||||
|
|
|
@ -41,14 +41,14 @@ class WebContents : public mate::EventEmitter,
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
bool IsAlive() const;
|
bool IsAlive() const;
|
||||||
void LoadURL(const GURL& url);
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||||
GURL GetURL() const;
|
GURL GetURL() const;
|
||||||
base::string16 GetTitle() const;
|
base::string16 GetTitle() const;
|
||||||
bool IsLoading() const;
|
bool IsLoading() const;
|
||||||
bool IsWaitingForResponse() const;
|
bool IsWaitingForResponse() const;
|
||||||
void Stop();
|
void Stop();
|
||||||
void Reload();
|
void Reload(const mate::Dictionary& options);
|
||||||
void ReloadIgnoringCache();
|
void ReloadIgnoringCache(const mate::Dictionary& options);
|
||||||
bool CanGoBack() const;
|
bool CanGoBack() const;
|
||||||
bool CanGoForward() const;
|
bool CanGoForward() const;
|
||||||
bool CanGoToOffset(int offset) const;
|
bool CanGoToOffset(int offset) const;
|
||||||
|
|
|
@ -84,14 +84,15 @@ BrowserWindow.fromId = (id) ->
|
||||||
BrowserWindow.windows.get id
|
BrowserWindow.windows.get id
|
||||||
|
|
||||||
# Helpers.
|
# Helpers.
|
||||||
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
BrowserWindow::loadUrl = (url, urlOptions={}) -> @webContents.loadUrl url, urlOptions
|
||||||
|
|
||||||
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
||||||
|
|
||||||
# Be compatible with old API.
|
# Be compatible with old API.
|
||||||
BrowserWindow::restart = -> @webContents.reload()
|
BrowserWindow::restart = -> @webContents.reload()
|
||||||
BrowserWindow::getUrl = -> @webContents.getUrl()
|
BrowserWindow::getUrl = -> @webContents.getUrl()
|
||||||
BrowserWindow::reload = -> @webContents.reload()
|
BrowserWindow::reload = (urlOptions={}) -> @webContents.reload(urlOptions)
|
||||||
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache()
|
BrowserWindow::reloadIgnoringCache = (urlOptions={}) -> @webContents.reloadIgnoringCache(urlOptions)
|
||||||
BrowserWindow::getPageTitle = -> @webContents.getTitle()
|
BrowserWindow::getPageTitle = -> @webContents.getTitle()
|
||||||
BrowserWindow::isLoading = -> @webContents.isLoading()
|
BrowserWindow::isLoading = -> @webContents.isLoading()
|
||||||
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
|
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
|
||||||
|
|
|
@ -26,6 +26,13 @@ module.exports.wrap = (webContents) ->
|
||||||
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
||||||
webContents.equal = (other) -> @getId() is other.getId()
|
webContents.equal = (other) -> @getId() is other.getId()
|
||||||
|
|
||||||
|
# Provide a default parameter for urlOptions to be compatible with the old
|
||||||
|
# API.
|
||||||
|
webContents::loadUrl = (url, urlOptions={}) -> loadUrl url, urlOptions
|
||||||
|
webContents::reload = (urlOptions={}) -> reload(urlOptions)
|
||||||
|
webContents::reloadIgnoringCache = (urlOptions={}) ->
|
||||||
|
reloadIgnoringCache(urlOptions)
|
||||||
|
|
||||||
# Translate |disposition| to string for 'new-window' event.
|
# Translate |disposition| to string for 'new-window' event.
|
||||||
webContents.on '-new-window', (args..., disposition) ->
|
webContents.on '-new-window', (args..., disposition) ->
|
||||||
disposition =
|
disposition =
|
||||||
|
|
|
@ -47,7 +47,7 @@ createGuest = (embedder, params) ->
|
||||||
max = width: params.maxwidth, height: params.maxheight
|
max = width: params.maxwidth, height: params.maxheight
|
||||||
@setAutoSize params.autosize, min, max
|
@setAutoSize params.autosize, min, max
|
||||||
if params.src
|
if params.src
|
||||||
@loadUrl params.src
|
@loadUrl params.src, params.urlOptions
|
||||||
if params.allowtransparency?
|
if params.allowtransparency?
|
||||||
@setAllowTransparency params.allowtransparency
|
@setAllowTransparency params.allowtransparency
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,8 @@ class WebView
|
||||||
# on* Event handlers.
|
# on* Event handlers.
|
||||||
@on = {}
|
@on = {}
|
||||||
|
|
||||||
|
@urlOptions = {}
|
||||||
|
|
||||||
@browserPluginNode = @createBrowserPluginNode()
|
@browserPluginNode = @createBrowserPluginNode()
|
||||||
shadowRoot = @webviewNode.createShadowRoot()
|
shadowRoot = @webviewNode.createShadowRoot()
|
||||||
@partition = new Partition()
|
@partition = new Partition()
|
||||||
|
@ -197,6 +199,12 @@ class WebView
|
||||||
# No setter.
|
# No setter.
|
||||||
enumerable: true
|
enumerable: true
|
||||||
|
|
||||||
|
@httpReferrer = @webviewNode.getAttribute 'httpreferrer'
|
||||||
|
Object.defineProperty @webviewNode, 'httpreferrer',
|
||||||
|
get: => @httpReferrer
|
||||||
|
set: (value) => @webviewNode.setAttribute 'httpreferrer', value
|
||||||
|
enumerable: true
|
||||||
|
|
||||||
# The purpose of this mutation observer is to catch assignment to the src
|
# The purpose of this mutation observer is to catch assignment to the src
|
||||||
# attribute without any changes to its value. This is useful in the case
|
# attribute without any changes to its value. This is useful in the case
|
||||||
# where the webview guest has crashed and navigating to the same address
|
# where the webview guest has crashed and navigating to the same address
|
||||||
|
@ -211,7 +219,7 @@ class WebView
|
||||||
params =
|
params =
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeOldValue: true,
|
attributeOldValue: true,
|
||||||
attributeFilter: ['src', 'partition']
|
attributeFilter: ['src', 'partition', 'httpreferrer']
|
||||||
@srcAndPartitionObserver.observe @webviewNode, params
|
@srcAndPartitionObserver.observe @webviewNode, params
|
||||||
|
|
||||||
# This observer monitors mutations to attributes of the <webview> and
|
# This observer monitors mutations to attributes of the <webview> and
|
||||||
|
@ -245,6 +253,21 @@ class WebView
|
||||||
return unless @guestInstanceId
|
return unless @guestInstanceId
|
||||||
|
|
||||||
guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
|
guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
|
||||||
|
else if name is 'httpreferrer'
|
||||||
|
oldValue ?= ''
|
||||||
|
newValue ?= ''
|
||||||
|
|
||||||
|
if newValue == '' and oldValue != ''
|
||||||
|
@webviewNode.setAttribute 'httpreferrer', oldValue
|
||||||
|
|
||||||
|
@httpReferrer = newValue
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
# If the httpreferrer changes treat it as though the src changes and reload
|
||||||
|
# the page with the new httpreferrer.
|
||||||
|
@parseSrcAttribute result
|
||||||
|
|
||||||
|
throw result.error if result.error?
|
||||||
else if name is 'src'
|
else if name is 'src'
|
||||||
# We treat null attribute (attribute removed) and the empty string as
|
# We treat null attribute (attribute removed) and the empty string as
|
||||||
# one case.
|
# one case.
|
||||||
|
@ -363,8 +386,11 @@ class WebView
|
||||||
@createGuest()
|
@createGuest()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if @httpReferrer
|
||||||
|
@urlOptions = { "httpreferrer": @httpReferrer }
|
||||||
|
|
||||||
# Navigate to |this.src|.
|
# Navigate to |this.src|.
|
||||||
remote.getGuestWebContents(@guestInstanceId).loadUrl @src
|
remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions
|
||||||
|
|
||||||
parseAttributes: ->
|
parseAttributes: ->
|
||||||
return unless @elementAttached
|
return unless @elementAttached
|
||||||
|
@ -447,6 +473,7 @@ class WebView
|
||||||
# set via this.onAttach().
|
# set via this.onAttach().
|
||||||
storagePartitionId: @partition.toAttribute()
|
storagePartitionId: @partition.toAttribute()
|
||||||
userAgentOverride: @userAgentOverride
|
userAgentOverride: @userAgentOverride
|
||||||
|
urlOptions: @urlOptions
|
||||||
|
|
||||||
attachWindow: (guestInstanceId, isNewWindow) ->
|
attachWindow: (guestInstanceId, isNewWindow) ->
|
||||||
@guestInstanceId = guestInstanceId
|
@guestInstanceId = guestInstanceId
|
||||||
|
|
Loading…
Reference in a new issue