-
Notifications
You must be signed in to change notification settings - Fork 3k
/
LibraryViewController+LibraryPanelDelegate.swift
41 lines (35 loc) · 1.78 KB
/
LibraryViewController+LibraryPanelDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Storage
import Shared
extension LibraryViewController: LibraryPanelDelegate {
func libraryPanelDidRequestToSignIn() {
self.dismiss(animated: false, completion: nil)
delegate?.libraryPanelDidRequestToSignIn()
}
func libraryPanelDidRequestToCreateAccount() {
self.dismiss(animated: false, completion: nil)
delegate?.libraryPanelDidRequestToCreateAccount()
}
func libraryPanelDidRequestToOpenInNewTab(_ url: URL, isPrivate: Bool) {
delegate?.libraryPanelDidRequestToOpenInNewTab(url, isPrivate: isPrivate)
}
func libraryPanel(didSelectURL url: URL, visitType: VisitType) {
delegate?.libraryPanel(didSelectURL: url, visitType: visitType)
dismiss(animated: true, completion: nil)
}
func libraryPanel(didSelectURLString url: String, visitType: VisitType) {
// If we can't get a real URL out of what should be a URL, we let the user's
// default search engine give it a shot.
// Typically we'll be in this state if the user has tapped a bookmarked search template
// (e.g., "http://foo.com/bar/?query=%s"), and this will get them the same behavior as if
// they'd copied and pasted into the URL bar.
// See BrowserViewController.urlBar:didSubmitText:.
guard let url = URIFixup.getURL(url) ?? profile.searchEngines.defaultEngine.searchURLForQuery(url) else {
Logger.browserLogger.warning("Invalid URL, and couldn't generate a search URL for it.")
return
}
return self.libraryPanel(didSelectURL: url, visitType: visitType)
}
}