tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GeckoView.swift (1365B)


      1 // This Source Code Form is subject to the terms of the Mozilla Public
      2 // License, v. 2.0. If a copy of the MPL was not distributed with this
      3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import UIKit
      6 
      7 public class GeckoView: UIView {
      8    public var session: GeckoSession? {
      9        didSet {
     10            // FIXME: Suspend old view, unsuspend new view, etc.
     11 
     12            // Remove all subviews from this view, to clean up any previous state.
     13            for view in subviews {
     14                view.removeFromSuperview()
     15            }
     16 
     17            // Add the new session's view under this GeckoView, and size it to fill this view.
     18            guard let sessionView = session?.window?.view() else { return }
     19 
     20            if sessionView.superview != nil {
     21                fatalError("attempt to assign GeckoSession to multiple GeckoView instances")
     22            }
     23 
     24            sessionView.translatesAutoresizingMaskIntoConstraints = false
     25            addSubview(sessionView)
     26 
     27            NSLayoutConstraint.activate([
     28                sessionView.topAnchor.constraint(equalTo: topAnchor),
     29                sessionView.leadingAnchor.constraint(equalTo: leadingAnchor),
     30                sessionView.bottomAnchor.constraint(equalTo: bottomAnchor),
     31                sessionView.trailingAnchor.constraint(equalTo: trailingAnchor),
     32            ])
     33        }
     34    }
     35 }