Permalink
Browse files

Should be able to pass refer to browser.open and such.

  • Loading branch information...
assaf committed Nov 30, 2012
1 parent 409a531 commit e873514cc5f68cb835d54a4afa275b37422322b3
Showing with 32 additions and 29 deletions.
  1. +8 −7 lib/zombie/browser.coffee
  2. +16 −17 lib/zombie/history.coffee
  3. +4 −2 lib/zombie/tabs.coffee
  4. +4 −3 lib/zombie/window.coffee
View
@@ -224,9 +224,11 @@ class Browser extends EventEmitter
@prototype.__defineGetter__ "window", ->
return @tabs.current
- # Open new browser window. Options are undocumented, use at your own peril.
+ # Open new browser window.
open: (options)->
- return @tabs.open(options)
+ if options
+ { url, name, referer } = options
+ return @tabs.open(url: url, name: name, referer: referer)
# ### browser.error => Error
#
@@ -458,17 +460,16 @@ class Browser extends EventEmitter
[callback, options] = [options, null]
deferred = Q.defer()
- reset_options = @withOptions(options)
+ resetOptions = @withOptions(options)
if site = @site
site = "http://#{site}" unless /^(https?:|file:)/i.test(site)
url = URL.resolve(site, URL.parse(URL.format(url)))
if @window
- @window.location = url
- else
- this.open(url: url)
+ @tabs.close(@window)
+ @tabs.open(url: url, referer: @referer)
@wait options, (error)=>
- reset_options()
+ resetOptions()
if error
deferred.reject(error)
else
View
@@ -98,9 +98,11 @@ class History
@first = @current = null
# Opens the first window and returns it.
- open: ({ name, opener, parent, url })->
- window = createWindow(browser: @browser, history: this, name: name, opener: opener, parent: parent, url: url)
- @addEntry(window, url)
+ open: (options)->
+ options.browser = @browser
+ options.history = this
+ window = createWindow(options)
+ @addEntry(window, options.url)
return window
# Dispose of all windows in history
@@ -147,19 +149,15 @@ class History
enumerable: true
# Form submission
- submit: ({ url, method, encoding, params })->
- window = @current.window
- newWindow = createWindow(
- browser: @browser
- history: this
- name: window.name
- parent: parentFrom(window)
- url: url
- method: method
- encoding: encoding
- params: params
- )
- @addEntry(newWindow, url)
+ submit: (options)->
+ options.browser = @browser
+ options.history = this
+ if window = @current.window
+ options.name = window.name
+ options.parent = parentFrom(window)
+ options.referer = window.URL
+ newWindow = createWindow(options)
+ @addEntry(newWindow, options.url)
# Returns current URL.
@prototype.__defineGetter__ "url", ->
@@ -212,7 +210,8 @@ class History
reload: ->
if window = @current.window
url = window.location.href
- newWindow = createWindow(browser: @browser, history: this, name: window.name, url: url, parent: parentFrom(window))
+ newWindow = createWindow(browser: @browser, history: this, name: window.name, url: url,
+ parent: parentFrom(window), referer: window.referrer)
@replaceEntry(newWindow, url)
# This method is available from Location.
View
@@ -39,10 +39,11 @@ createTabs = (browser)->
#
# name - Window name (optional)
# opener - Opening window (window.open call)
+ # referer - Referrer
# url - Set document location to this URL upon opening
open:
value: (options = {})->
- { name, opener, url } = options
+ { name, url } = options
# If name window in open tab, reuse that tab. Otherwise, open new window.
if name && window = @find(name.toString())
# Select this as the currenly open tab. Changing the location would then
@@ -70,7 +71,8 @@ createTabs = (browser)->
browser.eventLoop.setActiveWindow(window)
open = createHistory(browser, focus)
- window = open(name: name, opener: opener, url: url)
+ options.url = url
+ window = open(options)
@push(window)
if name && (Object.propertyIsEnumerable(name) || !this[name])
this[name] = window
View
@@ -27,8 +27,9 @@ inContext = null
# name - Window name (optional)
# opener - Opening window (window.open call)
# parent - Parent window (for frames)
+# referer - Use this as referer
# url - Set document location to this URL upon opening
-createWindow = ({ browser, params, encoding, history, method, name, opener, parent, url })->
+createWindow = ({ browser, params, encoding, history, method, name, opener, parent, referer, url })->
name ||= ""
url ||= "about:blank"
@@ -45,7 +46,7 @@ createWindow = ({ browser, params, encoding, history, method, name, opener, pare
# -- Document --
# Each window has its own document
- document = createDocument(browser, window, history.url || browser.referer)
+ document = createDocument(browser, window, referer || history.url)
Object.defineProperty window, "document",
value: document
enumerable: true
@@ -213,7 +214,7 @@ createWindow = ({ browser, params, encoding, history, method, name, opener, pare
# Open one window from another.
window.open = (url, name, features)->
url = url && HTML.resourceLoader.resolve(document, url)
- return browser.open(name: name, url: url, opener: window)
+ return browser.tabs.open(name: name, url: url, opener: window)
# Indicates if window was closed
Object.defineProperty window, "closed",

0 comments on commit e873514

Please sign in to comment.