mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-02 08:40:08 +01:00
formatting
This commit is contained in:
parent
836bd56ce4
commit
318370b46c
@ -1,11 +1,3 @@
|
|||||||
//
|
|
||||||
// SafariExtensionHandler.swift
|
|
||||||
// safari
|
|
||||||
//
|
|
||||||
// Created by Kyle Spearrin on 8/1/19.
|
|
||||||
// Copyright © 2019 8bit Solutions LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SafariServices
|
import SafariServices
|
||||||
|
|
||||||
class SafariExtensionHandler: SFSafariExtensionHandler {
|
class SafariExtensionHandler: SFSafariExtensionHandler {
|
||||||
@ -15,10 +7,10 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String: Any]?) {
|
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String: Any]?) {
|
||||||
// This method will be called when a content script provided by your extension calls safari.extension.dispatchMessage("message").
|
// This method will be called when a content script provided by your extension
|
||||||
|
// calls safari.extension.dispatchMessage("message").
|
||||||
if messageName == "bitwarden" {
|
if messageName == "bitwarden" {
|
||||||
page.getPropertiesWithCompletionHandler { properties in
|
page.getPropertiesWithCompletionHandler { properties in
|
||||||
// NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))")
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
makeSenderTabObject(page: page, props: properties, complete: { senderTab in
|
makeSenderTabObject(page: page, props: properties, complete: { senderTab in
|
||||||
self.sendMessage(msg: userInfo, sender: senderTab)
|
self.sendMessage(msg: userInfo, sender: senderTab)
|
||||||
@ -30,11 +22,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
|||||||
|
|
||||||
override func toolbarItemClicked(in _: SFSafariWindow) {
|
override func toolbarItemClicked(in _: SFSafariWindow) {
|
||||||
// This method will be called when your toolbar item is clicked.
|
// This method will be called when your toolbar item is clicked.
|
||||||
// NSLog("The extension's toolbar item was clicked")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func validateToolbarItem(in _: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) {
|
override func validateToolbarItem(in _: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) {
|
||||||
// This is called when Safari's state changed in some way that would require the extension's toolbar item to be validated again.
|
// This is called when Safari's state changed in some way that would require the extension's
|
||||||
|
// toolbar item to be validated again.
|
||||||
validationHandler(true, "")
|
validationHandler(true, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
//
|
|
||||||
// SafariExtensionViewController.swift
|
|
||||||
// safari
|
|
||||||
//
|
|
||||||
// Created by Kyle Spearrin on 8/1/19.
|
|
||||||
// Copyright © 2019 8bit Solutions LLC. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SafariServices
|
import SafariServices
|
||||||
import WebKit
|
import WebKit
|
||||||
|
|
||||||
@ -35,7 +27,8 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
|||||||
webViewConfig.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
|
webViewConfig.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
|
||||||
webViewConfig.preferences.setValue(true, forKey: "developerExtrasEnabled")
|
webViewConfig.preferences.setValue(true, forKey: "developerExtrasEnabled")
|
||||||
webViewConfig.userContentController.add(self, name: "bitwardenApp")
|
webViewConfig.userContentController.add(self, name: "bitwardenApp")
|
||||||
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: parentWidth, height: parentHeight), configuration: webViewConfig)
|
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: parentWidth, height: parentHeight),
|
||||||
|
configuration: webViewConfig)
|
||||||
webView.navigationDelegate = self
|
webView.navigationDelegate = self
|
||||||
webView.allowsLinkPreview = false
|
webView.allowsLinkPreview = false
|
||||||
webView.loadFileURL(url!, allowingReadAccessTo: bundleURL)
|
webView.loadFileURL(url!, allowingReadAccessTo: bundleURL)
|
||||||
@ -65,7 +58,6 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
|||||||
// print(messageBody)
|
// print(messageBody)
|
||||||
let m: AppMessage? = jsonDeserialize(json: messageBody)
|
let m: AppMessage? = jsonDeserialize(json: messageBody)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
// print("m is nil")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let command = m!.command
|
let command = m!.command
|
||||||
@ -216,7 +208,8 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co
|
|||||||
if activeTab != nil && activeTab == tab {
|
if activeTab != nil && activeTab == tab {
|
||||||
let windowIndex = wins.firstIndex(of: win) ?? -100
|
let windowIndex = wins.firstIndex(of: win) ?? -100
|
||||||
let tabIndex = allTabs.firstIndex(of: tab) ?? -1
|
let tabIndex = allTabs.firstIndex(of: tab) ?? -1
|
||||||
makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex, tabIndex: tabIndex, complete: { t in
|
makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex,
|
||||||
|
tabIndex: tabIndex, complete: { t in
|
||||||
newTabs.append(t)
|
newTabs.append(t)
|
||||||
tabGroup.leave()
|
tabGroup.leave()
|
||||||
})
|
})
|
||||||
@ -226,7 +219,8 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co
|
|||||||
} else {
|
} else {
|
||||||
let windowIndex = wins.firstIndex(of: win) ?? -100
|
let windowIndex = wins.firstIndex(of: win) ?? -100
|
||||||
let tabIndex = allTabs.firstIndex(of: tab) ?? -1
|
let tabIndex = allTabs.firstIndex(of: tab) ?? -1
|
||||||
makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex, tabIndex: tabIndex, complete: { t in
|
makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex,
|
||||||
|
tabIndex: tabIndex, complete: { t in
|
||||||
newTabs.append(t)
|
newTabs.append(t)
|
||||||
tabGroup.leave()
|
tabGroup.leave()
|
||||||
})
|
})
|
||||||
@ -243,7 +237,8 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTabObject(tab: SFSafariTab, activeTab: SFSafariTab?, windowIndex: Int, tabIndex: Int, complete: @escaping (Tab) -> Void) {
|
func makeTabObject(tab: SFSafariTab, activeTab: SFSafariTab?, windowIndex: Int, tabIndex: Int,
|
||||||
|
complete: @escaping (Tab) -> Void) {
|
||||||
let t = Tab()
|
let t = Tab()
|
||||||
t.active = activeTab != nil && tab == activeTab
|
t.active = activeTab != nil && tab == activeTab
|
||||||
t.windowId = windowIndex
|
t.windowId = windowIndex
|
||||||
|
Loading…
Reference in New Issue
Block a user