diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e228a064f413..8814057b9b99 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -418,6 +418,10 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { params.referrer = content::Referrer(http_referrer.GetAsReferrer(), blink::WebReferrerPolicyDefault); + std::string user_agent; + if (options.Get("useragent", &user_agent)) + this->SetUserAgent(user_agent); + 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/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 43f4d7c98c5f..a8c930278db6 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -58,8 +58,11 @@ createGuest = (embedder, params) -> max = width: params.maxwidth, height: params.maxheight @setAutoSize params.autosize, min, max if params.src - if params.httpreferrer - @loadUrl params.src, {httpreferrer: params.httpreferrer} + opts = {} + opts.httpreferrer = params.httpreferrer if params.httpreferrer + opts.useragent = params.useragent if params.useragent + if params.httpreferrer or params.useragent + @loadUrl params.src, opts else @loadUrl params.src if params.allowtransparency? diff --git a/atom/renderer/lib/web-view/web-view-attributes.coffee b/atom/renderer/lib/web-view/web-view-attributes.coffee index 080300d02bf8..bd00dc5322e9 100644 --- a/atom/renderer/lib/web-view/web-view-attributes.coffee +++ b/atom/renderer/lib/web-view/web-view-attributes.coffee @@ -158,13 +158,14 @@ class SrcAttribute extends WebViewAttribute return # Navigate to |this.src|. + opts = {} httpreferrer = @webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue() - urlOptions = if httpreferrer then {httpreferrer} else {} + if httpreferrer then opts.httpreferrer = httpreferrer - useragent = @webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue() + useragent = @webViewImpl.attributes[webViewConstants.ATTRIBUTE_USERAGENT].getValue() + if useragent then opts.useragent = useragent guestContents = remote.getGuestWebContents(@webViewImpl.guestInstanceId) - guestContents.setUserAgent(guestContents) if guestContents guestContents.loadUrl @getValue(), urlOptions # Attribute specifies HTTP referrer. @@ -175,7 +176,7 @@ class HttpReferrerAttribute extends WebViewAttribute # Attribute specifies HTTP referrer. class UserAgentAttribute extends WebViewAttribute constructor: (webViewImpl) -> - super webViewConstants.ATTRIBUTE_HTTPREFERRER, webViewImpl + super webViewConstants.ATTRIBUTE_USERAGENT, webViewImpl # Attribute that set preload script. class PreloadAttribute extends WebViewAttribute