 	}
 
 	func userContentController(userContentController:  WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
-		switch message.name {
-			case "jsBridge":
-				if let input = message.body as? NSDictionary {
-					if let action = input["action"] as? String {
-						handleJSMessage(action, data: input["data"], callback: input["callback"] as? String)
-					}
-				}
-		default:
-			print("Unhandled JS message: \(message.name)!!!")
-			
-		}
+		handleJSMessage(message)
 	}
 
 	// Mark: AlertViewDelegate

            if let telemetrySignal = data as? [String: AnyObject] {
                TelemetryLogger.sharedInstance.logEvent(.JavaScriptsignal(telemetrySignal))
            }
		default:
            print("Unhandles JS action: \(action)")
		}
	}

	private func loadExtension() {
		//		let url = NSURL(string: "http://localhost:3005/extension/index.html")
		let url = NSURL(string: "http://cdn.cliqz.com/mobile/beta/index.html")
		self.webView!.loadRequest(NSURLRequest(URL: url!))
	}

	private func stopLoadingAnimation() {
		self.spinnerView.removeFromSuperview()
		self.spinnerView.stopAnimating()
	}

}

		animateSearchEnginesWithKeyboard(state)
	}

	private func loadExtension() {
		//		let url = NSURL(string: "http://localhost:3005/extension/index.html")
		let url = NSURL(string: "http://cdn.cliqz.com/mobile/beta/index.html")
		self.webView!.loadRequest(NSURLRequest(URL: url!))
	}

	private func stopLoadingAnimation() {
		self.spinnerView.removeFromSuperview()
		self.spinnerView.stopAnimating()
	}

}

// Handling communications with JavaScript
extension CliqzSearchViewController {
    private func handleJSMessage(message: WKScriptMessage) {
        
        switch message.name {
        case "jsBridge":
            if let input = message.body as? NSDictionary {
                if let action = input["action"] as? String {
                    handleJSAction(action, data: input["data"], callback: input["callback"] as? String)
                }
            }
        default:
            print("Unhandled JS message: \(message.name)!!!")
            
        }
    }
    
    private func handleJSAction(action: String, data: AnyObject?, callback: String?) {
        
        switch action {
        case "searchHistory":
            let fullResults = NSDictionary(objects: [getHistory(), self.searchQuery!], forKeys: ["results", "query"])
            callJSMethod(callback, parameter: fullResults)
            
        case "openLink":
            if let url = data as? String {
                delegate?.searchView(self, didSelectUrl: NSURL(string: url)!)
