Various fixes of #801

This commit is contained in:
Cheng Zhao 2014-11-12 10:28:50 +08:00
parent 993c52dcd5
commit fbd74c0e2d
5 changed files with 24 additions and 29 deletions

View file

@ -289,11 +289,10 @@ bool WebContents::IsAlive() const {
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
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);
GURL http_referrer;
if (options.Get("httpreferrer", &http_referrer))
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
blink::WebReferrerPolicyDefault);
params.transition_type = content::PAGE_TRANSITION_TYPED;
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
@ -445,14 +444,14 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
.SetMethod("destroy", &WebContents::Destroy)
.SetMethod("isAlive", &WebContents::IsAlive)
.SetMethod("loadUrl", &WebContents::LoadURL)
.SetMethod("_loadUrl", &WebContents::LoadURL)
.SetMethod("getUrl", &WebContents::GetURL)
.SetMethod("getTitle", &WebContents::GetTitle)
.SetMethod("isLoading", &WebContents::IsLoading)
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
.SetMethod("stop", &WebContents::Stop)
.SetMethod("reload", &WebContents::Reload)
.SetMethod("reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
.SetMethod("_reload", &WebContents::Reload)
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
.SetMethod("canGoBack", &WebContents::CanGoBack)
.SetMethod("canGoForward", &WebContents::CanGoForward)
.SetMethod("canGoToOffset", &WebContents::CanGoToOffset)

View file

@ -84,15 +84,14 @@ BrowserWindow.fromId = (id) ->
BrowserWindow.windows.get id
# Helpers.
BrowserWindow::loadUrl = (url, urlOptions={}) -> @webContents.loadUrl url, urlOptions
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
# Be compatible with old API.
BrowserWindow::restart = -> @webContents.reload()
BrowserWindow::getUrl = -> @webContents.getUrl()
BrowserWindow::reload = (urlOptions={}) -> @webContents.reload(urlOptions)
BrowserWindow::reloadIgnoringCache = (urlOptions={}) -> @webContents.reloadIgnoringCache(urlOptions)
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache.apply @webContents, arguments
BrowserWindow::getPageTitle = -> @webContents.getTitle()
BrowserWindow::isLoading = -> @webContents.isLoading()
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()

View file

@ -26,12 +26,10 @@ module.exports.wrap = (webContents) ->
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
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)
# Provide a default parameter for |urlOptions|.
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.
webContents.on '-new-window', (args..., disposition) ->

View file

@ -47,7 +47,10 @@ createGuest = (embedder, params) ->
max = width: params.maxwidth, height: params.maxheight
@setAutoSize params.autosize, min, max
if params.src
@loadUrl params.src, params.urlOptions
if params.httpreferrer
@loadUrl params.src, {httpreferrer: params.httpreferrer}
else
@loadUrl params.src
if params.allowtransparency?
@setAllowTransparency params.allowtransparency

View file

@ -94,8 +94,6 @@ class WebView
# on* Event handlers.
@on = {}
@urlOptions = {}
@browserPluginNode = @createBrowserPluginNode()
shadowRoot = @webviewNode.createShadowRoot()
@partition = new Partition()
@ -199,9 +197,9 @@ class WebView
# No setter.
enumerable: true
@httpReferrer = @webviewNode.getAttribute 'httpreferrer'
@httpreferrer = @webviewNode.getAttribute 'httpreferrer'
Object.defineProperty @webviewNode, 'httpreferrer',
get: => @httpReferrer
get: => @httpreferrer
set: (value) => @webviewNode.setAttribute 'httpreferrer', value
enumerable: true
@ -260,7 +258,7 @@ class WebView
if newValue == '' and oldValue != ''
@webviewNode.setAttribute 'httpreferrer', oldValue
@httpReferrer = newValue
@httpreferrer = newValue
result = {}
# If the httpreferrer changes treat it as though the src changes and reload
@ -386,11 +384,9 @@ class WebView
@createGuest()
return
if @httpReferrer
@urlOptions = { "httpreferrer": @httpReferrer }
# Navigate to |this.src|.
remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions
urlOptions = if @httpreferrer then {@httpreferrer} else {}
remote.getGuestWebContents(@guestInstanceId).loadUrl @src, urlOptions
parseAttributes: ->
return unless @elementAttached
@ -473,7 +469,7 @@ class WebView
# set via this.onAttach().
storagePartitionId: @partition.toAttribute()
userAgentOverride: @userAgentOverride
urlOptions: @urlOptions
httpreferrer: @httpreferrer
attachWindow: (guestInstanceId, isNewWindow) ->
@guestInstanceId = guestInstanceId