Fix merge conflict with native_window_views.cc
This commit is contained in:
commit
246a145930
10 changed files with 90 additions and 16 deletions
|
@ -286,8 +286,14 @@ 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);
|
||||||
|
|
||||||
|
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.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 +319,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 {
|
||||||
|
@ -438,14 +444,14 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||||
.SetMethod("destroy", &WebContents::Destroy)
|
.SetMethod("destroy", &WebContents::Destroy)
|
||||||
.SetMethod("isAlive", &WebContents::IsAlive)
|
.SetMethod("isAlive", &WebContents::IsAlive)
|
||||||
.SetMethod("loadUrl", &WebContents::LoadURL)
|
.SetMethod("_loadUrl", &WebContents::LoadURL)
|
||||||
.SetMethod("getUrl", &WebContents::GetURL)
|
.SetMethod("getUrl", &WebContents::GetURL)
|
||||||
.SetMethod("getTitle", &WebContents::GetTitle)
|
.SetMethod("getTitle", &WebContents::GetTitle)
|
||||||
.SetMethod("isLoading", &WebContents::IsLoading)
|
.SetMethod("isLoading", &WebContents::IsLoading)
|
||||||
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
||||||
.SetMethod("stop", &WebContents::Stop)
|
.SetMethod("stop", &WebContents::Stop)
|
||||||
.SetMethod("reload", &WebContents::Reload)
|
.SetMethod("_reload", &WebContents::Reload)
|
||||||
.SetMethod("reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
||||||
.SetMethod("canGoBack", &WebContents::CanGoBack)
|
.SetMethod("canGoBack", &WebContents::CanGoBack)
|
||||||
.SetMethod("canGoForward", &WebContents::CanGoForward)
|
.SetMethod("canGoForward", &WebContents::CanGoForward)
|
||||||
.SetMethod("canGoToOffset", &WebContents::CanGoToOffset)
|
.SetMethod("canGoToOffset", &WebContents::CanGoToOffset)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -90,8 +90,8 @@ 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 = -> @webContents.reload.apply @webContents, arguments
|
||||||
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache()
|
BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache.apply @webContents, arguments
|
||||||
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,11 @@ 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|.
|
||||||
|
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,10 @@ 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
|
if params.httpreferrer
|
||||||
|
@loadUrl params.src, {httpreferrer: params.httpreferrer}
|
||||||
|
else
|
||||||
|
@loadUrl params.src
|
||||||
if params.allowtransparency?
|
if params.allowtransparency?
|
||||||
@setAllowTransparency params.allowtransparency
|
@setAllowTransparency params.allowtransparency
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,16 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||||
use_content_size_)
|
use_content_size_)
|
||||||
bounds = ContentBoundsToWindowBounds(bounds);
|
bounds = ContentBoundsToWindowBounds(bounds);
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
if(has_frame_) {
|
if(has_frame_) {
|
||||||
window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
|
window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
|
||||||
window_->FrameTypeChanged();
|
window_->FrameTypeChanged();
|
||||||
|
|
|
@ -197,6 +197,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 +217,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 +251,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.
|
||||||
|
@ -364,7 +385,8 @@ class WebView
|
||||||
return
|
return
|
||||||
|
|
||||||
# Navigate to |this.src|.
|
# Navigate to |this.src|.
|
||||||
remote.getGuestWebContents(@guestInstanceId).loadUrl @src
|
urlOptions = if @httpreferrer then {@httpreferrer} else {}
|
||||||
|
remote.getGuestWebContents(@guestInstanceId).loadUrl @src, urlOptions
|
||||||
|
|
||||||
parseAttributes: ->
|
parseAttributes: ->
|
||||||
return unless @elementAttached
|
return unless @elementAttached
|
||||||
|
@ -447,6 +469,7 @@ class WebView
|
||||||
# set via this.onAttach().
|
# set via this.onAttach().
|
||||||
storagePartitionId: @partition.toAttribute()
|
storagePartitionId: @partition.toAttribute()
|
||||||
userAgentOverride: @userAgentOverride
|
userAgentOverride: @userAgentOverride
|
||||||
|
httpreferrer: @httpreferrer
|
||||||
|
|
||||||
attachWindow: (guestInstanceId, isNewWindow) ->
|
attachWindow: (guestInstanceId, isNewWindow) ->
|
||||||
@guestInstanceId = guestInstanceId
|
@guestInstanceId = guestInstanceId
|
||||||
|
|
|
@ -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
|
access to all Node APIs, but global objects injected by Node will be deleted
|
||||||
after this script has done execution.
|
after this script has done execution.
|
||||||
|
|
||||||
|
### httpreferrer
|
||||||
|
|
||||||
|
```html
|
||||||
|
<webview src="https://www.github.com/" httpreferrer="http://cheng.guru"></webview>
|
||||||
|
```
|
||||||
|
|
||||||
|
Sets the referrer URL for the guest page.
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### `<webview>`.getUrl()
|
### `<webview>`.getUrl()
|
||||||
|
|
7
spec/fixtures/pages/referrer.html
vendored
Normal file
7
spec/fixtures/pages/referrer.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
console.log(document.referrer);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -58,6 +58,18 @@ describe '<webview> tag', ->
|
||||||
webview.src = "file://#{fixtures}/pages/e.html"
|
webview.src = "file://#{fixtures}/pages/e.html"
|
||||||
document.body.appendChild webview
|
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', ->
|
describe 'new-window event', ->
|
||||||
it 'emits when window.open is called', (done) ->
|
it 'emits when window.open is called', (done) ->
|
||||||
webview.addEventListener 'new-window', (e) ->
|
webview.addEventListener 'new-window', (e) ->
|
||||||
|
|
Loading…
Reference in a new issue