From f56d1ea7b486828351f31682ea1fb71dd394f851 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Thu, 6 Nov 2014 14:29:41 -0500 Subject: [PATCH 01/11] Add support for setting http referrer - Add url option to specify the http referrer - Add httpReferrer attribute to webview NOTE: This is still not complete. Some love has to be done to guest-view-manager.coffee and very likely the function calls called createGuest and to the code that uses them. --- atom/browser/api/atom_api_web_contents.cc | 16 +++++++--- atom/browser/api/atom_api_web_contents.h | 6 ++-- atom/browser/api/lib/browser-window.coffee | 17 +++++++++-- atom/browser/lib/guest-view-manager.coffee | 2 +- atom/browser/lib/guest-window-manager.coffee | 4 +-- atom/renderer/lib/web-view.coffee | 32 ++++++++++++++++++-- 6 files changed, 61 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 5045efae2a37..983d37d502f2 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -286,8 +286,14 @@ bool WebContents::IsAlive() const { 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); + + 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.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; web_contents()->GetController().LoadURLWithParams(params); @@ -313,15 +319,15 @@ void WebContents::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 // because normal reloading will break our node integration. // This is done by AtomBrowserClient::ShouldSwapProcessesForNavigation. - LoadURL(GetURL()); + LoadURL(GetURL(), options); } -void WebContents::ReloadIgnoringCache() { - Reload(); +void WebContents::ReloadIgnoringCache(const mate::Dictionary& options) { + Reload(options); } bool WebContents::CanGoBack() const { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index c29221008c89..7f6a6971901d 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -41,14 +41,14 @@ class WebContents : public mate::EventEmitter, void Destroy(); bool IsAlive() const; - void LoadURL(const GURL& url); + void LoadURL(const GURL& url, const mate::Dictionary& options); GURL GetURL() const; base::string16 GetTitle() const; bool IsLoading() const; bool IsWaitingForResponse() const; void Stop(); - void Reload(); - void ReloadIgnoringCache(); + void Reload(const mate::Dictionary& options); + void ReloadIgnoringCache(const mate::Dictionary& options); bool CanGoBack() const; bool CanGoForward() const; bool CanGoToOffset(int offset) const; diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index e855a93524fc..a25672e28e13 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -11,6 +11,8 @@ BrowserWindow::__proto__ = EventEmitter.prototype BrowserWindow.windows = new IDWeakMap BrowserWindow::_init = -> + @urlOptions = {} + # Simulate the application menu on platforms other than OS X. if process.platform isnt 'darwin' menu = app.getApplicationMenu() @@ -84,14 +86,23 @@ BrowserWindow.fromId = (id) -> BrowserWindow.windows.get id # Helpers. -BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments +BrowserWindow::loadUrl = -> + args = [].slice.call arguments + unless args.length > 1 + args.push @urlOptions + + #TODO: This needs fixing! + @urlOptions = args[1] + + @webContents.loadUrl.apply @webContents, args + BrowserWindow::send = -> @webContents.send.apply @webContents, arguments # Be compatible with old API. BrowserWindow::restart = -> @webContents.reload() BrowserWindow::getUrl = -> @webContents.getUrl() -BrowserWindow::reload = -> @webContents.reload() -BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache() +BrowserWindow::reload = -> @webContents.reload(@urlOptions) +BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache(@urlOptions) BrowserWindow::getPageTitle = -> @webContents.getTitle() BrowserWindow::isLoading = -> @webContents.isLoading() BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse() diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index a5c5d021f401..5b6377847a37 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -47,7 +47,7 @@ createGuest = (embedder, params) -> max = width: params.maxwidth, height: params.maxheight @setAutoSize params.autosize, min, max if params.src - @loadUrl params.src + @loadUrl params.src, params.urlOptions if params.allowtransparency? @setAllowTransparency params.allowtransparency diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index 123c3898a9d4..abd2d1b8729d 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -7,11 +7,11 @@ frameToGuest = {} createGuest = (embedder, url, frameName, options) -> guest = frameToGuest[frameName] if frameName and guest? - guest.loadUrl url + guest.loadUrl url {} return guest.id guest = new BrowserWindow(options) - guest.loadUrl url + guest.loadUrl url {} # When |embedder| is destroyed we should also destroy attached guest, and if # guest is closed by user then we should prevent |embedder| from double diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index ee11683d9a52..1c35c163ffe5 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -94,6 +94,8 @@ class WebView # on* Event handlers. @on = {} + @urlOptions = {} + @browserPluginNode = @createBrowserPluginNode() shadowRoot = @webviewNode.createShadowRoot() @partition = new Partition() @@ -197,6 +199,12 @@ class WebView # No setter. 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 # 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 @@ -211,7 +219,7 @@ class WebView params = attributes: true, attributeOldValue: true, - attributeFilter: ['src', 'partition'] + attributeFilter: ['src', 'partition', 'httpReferrer'] @srcAndPartitionObserver.observe @webviewNode, params # This observer monitors mutations to attributes of the and @@ -245,6 +253,22 @@ class WebView return unless @guestInstanceId guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency + else if name is 'httpReferrer' + oldValue ?= '' + newValue ?= '' + + if newValue == '' and oldValue != '' + @webviewNode.setAttribute 'httpReferrer', oldValue + + @httpReferrer = newValue + + result = {} + # I think the right thing to do if you change your referrer is to reload + # the src since I've bundled the referrer in with the parseSrcAttribute. + # I think it makes sense to do that. + @parseSrcAttribute result + + throw result.error if result.error? else if name is 'src' # We treat null attribute (attribute removed) and the empty string as # one case. @@ -363,8 +387,11 @@ class WebView @createGuest() return + if @httpReferrer + @urlOptions = { "httpReferrer": @httpReferrer } + # Navigate to |this.src|. - remote.getGuestWebContents(@guestInstanceId).loadUrl @src + remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions parseAttributes: -> return unless @elementAttached @@ -447,6 +474,7 @@ class WebView # set via this.onAttach(). storagePartitionId: @partition.toAttribute() userAgentOverride: @userAgentOverride + urlOptions: @urlOptions attachWindow: (guestInstanceId, isNewWindow) -> @guestInstanceId = guestInstanceId From 4b20ac3dc63821223aa776326fc99770c501dc61 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Fri, 7 Nov 2014 13:13:12 -0500 Subject: [PATCH 02/11] Fix Windows min/max animation on frameless windows - Frameless windows disappeared or appears when minimized and maximized on Windows. This commit fixes that. --- atom/browser/native_window_views.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 0a17b1787b52..af069191b83d 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -226,6 +226,13 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, options.Get(switches::kUseContentSize, &use_content_size_) && use_content_size_) bounds = ContentBoundsToWindowBounds(bounds); + #if defined(OS_WIN) + else { + // set Window style so that we get a minimize and maximize animation when frameless + DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION; + ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style); + } + #endif window_->UpdateWindowIcon(); window_->CenterWindow(bounds.size()); From 24f8c5195986ef991ba949bec4b2da9deaf3ef23 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Fri, 7 Nov 2014 13:34:52 -0500 Subject: [PATCH 03/11] Make sure frame is frameless --- atom/browser/native_window_views.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index af069191b83d..35c0f1c65681 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -226,13 +226,14 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, options.Get(switches::kUseContentSize, &use_content_size_) && use_content_size_) bounds = ContentBoundsToWindowBounds(bounds); - #if defined(OS_WIN) - else { + +#if defined(OS_WIN) + if (!has_frame_) { // set Window style so that we get a minimize and maximize animation when frameless DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION; ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style); } - #endif +#endif window_->UpdateWindowIcon(); window_->CenterWindow(bounds.size()); From ef255db069a52e8bfd53b3234a5217ab96e0c9a0 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Fri, 7 Nov 2014 21:54:36 -0500 Subject: [PATCH 04/11] Making Http Referrer addition better! - Code cleanup --- atom/browser/api/atom_api_web_contents.cc | 2 +- atom/browser/api/lib/browser-window.coffee | 16 +++------------- atom/browser/lib/guest-window-manager.coffee | 4 ++-- atom/renderer/lib/web-view.coffee | 19 +++++++++---------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 983d37d502f2..cf40de96e488 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -291,7 +291,7 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { base::string16 http_referrer_; - if(options.Get("httpReferrer", &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; diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index a25672e28e13..243ad1ac3c75 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -11,8 +11,6 @@ BrowserWindow::__proto__ = EventEmitter.prototype BrowserWindow.windows = new IDWeakMap BrowserWindow::_init = -> - @urlOptions = {} - # Simulate the application menu on platforms other than OS X. if process.platform isnt 'darwin' menu = app.getApplicationMenu() @@ -86,23 +84,15 @@ BrowserWindow.fromId = (id) -> BrowserWindow.windows.get id # Helpers. -BrowserWindow::loadUrl = -> - args = [].slice.call arguments - unless args.length > 1 - args.push @urlOptions - - #TODO: This needs fixing! - @urlOptions = args[1] - - @webContents.loadUrl.apply @webContents, args +BrowserWindow::loadUrl = (url, urlOptions={}) -> @webContents.loadUrl url, urlOptions BrowserWindow::send = -> @webContents.send.apply @webContents, arguments # Be compatible with old API. BrowserWindow::restart = -> @webContents.reload() BrowserWindow::getUrl = -> @webContents.getUrl() -BrowserWindow::reload = -> @webContents.reload(@urlOptions) -BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache(@urlOptions) +BrowserWindow::reload = (urlOptions={}) -> @webContents.reload(urlOptions) +BrowserWindow::reloadIgnoringCache = (urlOptions={}) -> @webContents.reloadIgnoringCache(urlOptions) BrowserWindow::getPageTitle = -> @webContents.getTitle() BrowserWindow::isLoading = -> @webContents.isLoading() BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse() diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index abd2d1b8729d..123c3898a9d4 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -7,11 +7,11 @@ frameToGuest = {} createGuest = (embedder, url, frameName, options) -> guest = frameToGuest[frameName] if frameName and guest? - guest.loadUrl url {} + guest.loadUrl url return guest.id guest = new BrowserWindow(options) - guest.loadUrl url {} + guest.loadUrl url # When |embedder| is destroyed we should also destroy attached guest, and if # guest is closed by user then we should prevent |embedder| from double diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index 1c35c163ffe5..96abb4865728 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -199,10 +199,10 @@ class WebView # No setter. enumerable: true - @httpReferrer = @webviewNode.getAttribute 'httpReferrer' - Object.defineProperty @webviewNode, 'httpReferrer', + @httpReferrer = @webviewNode.getAttribute 'httpreferrer' + Object.defineProperty @webviewNode, 'httpreferrer', get: => @httpReferrer - set: (value) => @webviewNode.setAttribute 'httpReferrer', value + set: (value) => @webviewNode.setAttribute 'httpreferrer', value enumerable: true # The purpose of this mutation observer is to catch assignment to the src @@ -219,7 +219,7 @@ class WebView params = attributes: true, attributeOldValue: true, - attributeFilter: ['src', 'partition', 'httpReferrer'] + attributeFilter: ['src', 'partition', 'httpreferrer'] @srcAndPartitionObserver.observe @webviewNode, params # This observer monitors mutations to attributes of the and @@ -253,19 +253,18 @@ class WebView return unless @guestInstanceId guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency - else if name is 'httpReferrer' + else if name is 'httpreferrer' oldValue ?= '' newValue ?= '' if newValue == '' and oldValue != '' - @webviewNode.setAttribute 'httpReferrer', oldValue + @webviewNode.setAttribute 'httpreferrer', oldValue @httpReferrer = newValue result = {} - # I think the right thing to do if you change your referrer is to reload - # the src since I've bundled the referrer in with the parseSrcAttribute. - # I think it makes sense to do that. + # 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? @@ -388,7 +387,7 @@ class WebView return if @httpReferrer - @urlOptions = { "httpReferrer": @httpReferrer } + @urlOptions = { "httpreferrer": @httpReferrer } # Navigate to |this.src|. remote.getGuestWebContents(@guestInstanceId).loadUrl @src, @urlOptions From b92d5071fa8c3047cf2d15a0d9ba61a9c4de2d15 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 7 Nov 2014 15:05:55 +0800 Subject: [PATCH 05/11] views: Make auto-hide-menu-bar work when NumLock is on, fixes #796 --- atom/browser/native_window_views.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index dc1d684ea2b6..9a7e6d528be0 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -113,9 +113,12 @@ bool IsAltKey(const content::NativeWebKeyboardEvent& event) { bool IsAltModifier(const content::NativeWebKeyboardEvent& event) { typedef content::NativeWebKeyboardEvent::Modifiers Modifiers; - return (event.modifiers == Modifiers::AltKey) || - (event.modifiers == (Modifiers::AltKey | Modifiers::IsLeft)) || - (event.modifiers == (Modifiers::AltKey | Modifiers::IsRight)); + int modifiers = event.modifiers; + modifiers &= ~Modifiers::NumLockOn; + modifiers &= ~Modifiers::CapsLockOn; + return (modifiers == Modifiers::AltKey) || + (modifiers == (Modifiers::AltKey | Modifiers::IsLeft)) || + (modifiers == (Modifiers::AltKey | Modifiers::IsRight)); } class NativeWindowClientView : public views::ClientView { From 716037544ae1ce08265f9bba9d09cd21bedbc43b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 7 Nov 2014 15:20:16 +0800 Subject: [PATCH 06/11] views: Fix showing menu bar when pressing Alt for a long time --- atom/browser/native_window_views.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 9a7e6d528be0..0a17b1787b52 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -719,8 +719,7 @@ void NativeWindowViews::HandleKeyboardEvent( return; // Toggle the menu bar only when a single Alt is released. - if (event.type == blink::WebInputEvent::RawKeyDown && IsAltKey(event) && - IsAltModifier(event)) { + if (event.type == blink::WebInputEvent::RawKeyDown && IsAltKey(event)) { // When a single Alt is pressed: menu_bar_alt_pressed_ = true; } else if (event.type == blink::WebInputEvent::KeyUp && IsAltKey(event) && From e0dae4054ac49046eb6afbb3cd334efcbb9e5305 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Tue, 11 Nov 2014 13:09:54 -0500 Subject: [PATCH 07/11] Fix code style to be <= 80 lines --- atom/browser/native_window_views.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 35c0f1c65681..6a105ab7dca1 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -229,8 +229,10 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, #if defined(OS_WIN) if (!has_frame_) { - // set Window style so that we get a minimize and maximize animation when frameless - DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION; + // Set Window style so that we get a minimize and maximize animation when + // frameless. + DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | + WS_CAPTION; ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style); } #endif From 747698fe9b5589222e9beeea04bcb25c6d089b3d Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Tue, 11 Nov 2014 13:33:15 -0500 Subject: [PATCH 08/11] Fix code style formatting - Fix code style formatting to be <= 80 lines - Add default parameter for urlOptions to loadUrl, reload and reloadIgnoringCache functions to be compatible with old API. --- atom/browser/api/atom_api_web_contents.cc | 5 +++-- atom/browser/api/lib/web-contents.coffee | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index cf40de96e488..8bb6a358169c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -289,10 +289,11 @@ bool WebContents::IsAlive() const { void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { content::NavigationController::LoadURLParams params(url); - base::string16 http_referrer_; + base::string16 http_referrer; if (options.Get("httpreferrer", &http_referrer_)) - params.referrer = content::Referrer(GURL(http_referrer_).GetAsReferrer(), blink::WebReferrerPolicyDefault); + params.referrer = content::Referrer(GURL(http_referrer_).GetAsReferrer(), + blink::WebReferrerPolicyDefault); params.transition_type = content::PAGE_TRANSITION_TYPED; params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE; diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index e22d5e01c2b7..a0c8a00e7c52 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -26,6 +26,13 @@ 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) + # Translate |disposition| to string for 'new-window' event. webContents.on '-new-window', (args..., disposition) -> disposition = From fbd74c0e2debbddd667709e029dc29afe7a66cd1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 10:28:50 +0800 Subject: [PATCH 09/11] Various fixes of #801 --- atom/browser/api/atom_api_web_contents.cc | 15 +++++++-------- atom/browser/api/lib/browser-window.coffee | 7 +++---- atom/browser/api/lib/web-contents.coffee | 10 ++++------ atom/browser/lib/guest-view-manager.coffee | 5 ++++- atom/renderer/lib/web-view.coffee | 16 ++++++---------- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 8bb6a358169c..9115cbc82ad1 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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) diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index 243ad1ac3c75..3d89659444c6 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -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() diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index a0c8a00e7c52..5ed80a54ab01 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -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) -> diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 5b6377847a37..db8ed44848eb 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -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 diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index 96abb4865728..f27be54ab556 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -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 From 57bfc63d2308a38fa937197a21852984ba96b98d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 10:34:54 +0800 Subject: [PATCH 10/11] docs: "httpreferrer" attribute of --- docs/api/web-view-tag.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 0b5f63973843..d4650b683f51 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -104,6 +104,14 @@ When the guest page doesn't have node integration this script will still have access to all Node APIs, but global objects injected by Node will be deleted after this script has done execution. +### httpreferrer + +```html + +``` + +Sets the referrer URL for the guest page. + ## Methods ### ``.getUrl() From db8361a0a9ef6722f645de2691bafd410477f7f1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 10:39:15 +0800 Subject: [PATCH 11/11] spec: "httpreferrer" attribute of --- spec/fixtures/pages/referrer.html | 7 +++++++ spec/webview-spec.coffee | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 spec/fixtures/pages/referrer.html diff --git a/spec/fixtures/pages/referrer.html b/spec/fixtures/pages/referrer.html new file mode 100644 index 000000000000..673b244ce165 --- /dev/null +++ b/spec/fixtures/pages/referrer.html @@ -0,0 +1,7 @@ + + + + + diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index 71c4854d5ff9..f14cee53c998 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -58,6 +58,18 @@ describe ' tag', -> webview.src = "file://#{fixtures}/pages/e.html" document.body.appendChild webview + describe 'httpreferrer attribute', -> + it 'sets the referrer url', (done) -> + referrer = 'http://github.com/' + listener = (e) -> + assert.equal e.message, referrer + webview.removeEventListener 'console-message', listener + done() + webview.addEventListener 'console-message', listener + webview.setAttribute 'httpreferrer', referrer + webview.src = "file://#{fixtures}/pages/referrer.html" + document.body.appendChild webview + describe 'new-window event', -> it 'emits when window.open is called', (done) -> webview.addEventListener 'new-window', (e) ->