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.
This commit is contained in:
Frank Hale 2014-11-06 14:29:41 -05:00
parent fea5559fbc
commit f56d1ea7b4
6 changed files with 61 additions and 16 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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()