     }
 }
 
+extension UIView {
+    public class func viewOrientationForSize(size: CGSize) -> UIInterfaceOrientation {
+        return size.width > size.height ? UIInterfaceOrientation.LandscapeRight : UIInterfaceOrientation.Portrait
+    }
+}
+
 class TopSitesPanel: UIViewController {
     weak var homePanelDelegate: HomePanelDelegate?
 


private class TopSitesLayout: UICollectionViewLayout {
    private var thumbnailRows: Int {
        return Int((self.collectionView?.frame.height ?? self.thumbnailHeight) / self.thumbnailHeight)
    }

    private var thumbnailCols = 2


    let profile: Profile

    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
        self.refreshHistory(self.layout.thumbnailCount)
        self.layout.setupForOrientation(UIView.viewOrientationForSize(size))
    }

    override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
    }

    init(profile: Profile) {
        self.profile = profile
        super.init(nibName: nil, bundle: nil)
