├── project ├── build.properties └── plugins.sbt ├── examples ├── project │ ├── build.properties │ └── plugins.sbt ├── app │ └── src │ │ └── main │ │ ├── resources │ │ ├── _locales │ │ │ └── en │ │ │ │ └── messages.json │ │ └── icons │ │ │ └── 256 │ │ │ └── app.png │ │ └── scala │ │ └── Main.scala └── extension │ └── src │ └── main │ ├── resources │ └── icons │ │ └── 256 │ │ └── app.png │ └── scala │ └── Main.scala ├── .gitignore ├── bindings └── src │ └── main │ └── scala │ └── chrome │ ├── sockets │ ├── tcp │ │ ├── bindings │ │ │ ├── package.scala │ │ │ ├── CreateInfo.scala │ │ │ ├── SendInfo.scala │ │ │ ├── ReceiveErrorEvent.scala │ │ │ ├── ReceiveEvent.scala │ │ │ ├── SecureOptions.scala │ │ │ ├── SocketInfo.scala │ │ │ ├── SocketProperties.scala │ │ │ ├── TLSVersionBounds.scala │ │ │ └── TCP.scala │ │ └── Socket.scala │ └── tcpServer │ │ ├── bindings │ │ ├── package.scala │ │ ├── CreateInfo.scala │ │ ├── AcceptErrorEvent.scala │ │ ├── AcceptEvent.scala │ │ ├── SocketInfo.scala │ │ ├── SocketProperties.scala │ │ └── TCPServer.scala │ │ ├── Socket.scala │ │ └── TCPServer.scala │ ├── sessions │ └── bindings │ │ └── Session.scala │ ├── ChromeAPI.scala │ ├── runtime │ └── bindings │ │ ├── DirectoryEntry.scala │ │ ├── Error.scala │ │ ├── OnUpdateAvailableDetails.scala │ │ ├── SendMessageOptions.scala │ │ ├── ConnectInfo.scala │ │ ├── MessageSender.scala │ │ ├── Port.scala │ │ ├── OnInstalledDetails.scala │ │ ├── PlatformInfo.scala │ │ └── Manifest.scala │ ├── downloads │ ├── bindings │ │ ├── HttpMethod.scala │ │ ├── Delta.scala │ │ ├── Suggestion.scala │ │ ├── State.scala │ │ ├── FileIconOptions.scala │ │ ├── FilenameConflictAction.scala │ │ ├── DangerType.scala │ │ ├── DownloadDelta.scala │ │ ├── HttpHeader.scala │ │ ├── DownloadItem.scala │ │ ├── DownloadOptions.scala │ │ ├── Downloads.scala │ │ └── InterruptReason.scala │ └── Downloads.scala │ ├── management │ └── bindings │ │ ├── IconInfo.scala │ │ ├── Management.scala │ │ └── ExtensionInfo.scala │ ├── processes │ ├── bindings │ │ ├── Cache.scala │ │ ├── Processes.scala │ │ └── Process.scala │ └── Processes.scala │ ├── webRequest │ ├── bindings │ │ ├── WebAuthChallenger.scala │ │ ├── AuthCredentials.scala │ │ ├── WebRequestDetails.scala │ │ ├── WebRedirectionResponseDetails.scala │ │ ├── WebRequestBodyDetails.scala │ │ ├── WebRequestHeadersDetails.scala │ │ ├── WebResponseErrorDetails.scala │ │ ├── HttpHeader.scala │ │ ├── WebResponseHeadersDetails.scala │ │ ├── UploadData.scala │ │ ├── WebResponseCacheDetails.scala │ │ ├── WebResponseDetails.scala │ │ ├── WebRequestEvent.scala │ │ ├── WebAuthenticationChallengeDetails.scala │ │ ├── WebRequestBody.scala │ │ ├── RequestFilter.scala │ │ ├── ResourceRequest.scala │ │ └── BlockingResponse.scala │ └── BlockingRequestEventSource.scala │ ├── idle │ ├── bindings │ │ ├── package.scala │ │ └── Idle.scala │ └── Idle.scala │ ├── events │ ├── MappedEventSource.scala │ ├── FilteredEventSource.scala │ ├── bindings │ │ └── Event.scala │ ├── EventSource.scala │ └── EventSourceImplicits.scala │ ├── system │ ├── memory │ │ ├── bindings │ │ │ ├── MemoryInfo.scala │ │ │ └── Memory.scala │ │ └── Memory.scala │ ├── network │ │ ├── Interface.scala │ │ ├── bindings │ │ │ ├── NetworkInterface.scala │ │ │ └── Network.scala │ │ └── Network.scala │ ├── cpu │ │ ├── bindings │ │ │ ├── CPU.scala │ │ │ ├── CPUInfo.scala │ │ │ ├── package.scala │ │ │ └── Processor.scala │ │ └── CPU.scala │ └── display │ │ ├── bindings │ │ ├── Bounds.scala │ │ ├── Insets.scala │ │ ├── Display.scala │ │ ├── DisplayInfo.scala │ │ └── DisplayProperties.scala │ │ └── Display.scala │ ├── alarms │ ├── bindings │ │ ├── Alarm.scala │ │ ├── AlarmInfo.scala │ │ └── Alarms.scala │ └── Alarms.scala │ ├── tabs │ └── bindings │ │ ├── ActiveInfo.scala │ │ ├── AttachInfo.scala │ │ ├── DetachInfo.scala │ │ ├── RemoveInfo.scala │ │ ├── HighlightInfo.scala │ │ ├── MoveInfo.scala │ │ ├── ZoomChangeInfo.scala │ │ ├── ChangeInfo.scala │ │ ├── CaptureOptions.scala │ │ ├── MessageOptions.scala │ │ ├── ReloadProperties.scala │ │ ├── MoveProperties.scala │ │ ├── ConnectInfo.scala │ │ ├── ZoomSettings.scala │ │ ├── UpdateProperties.scala │ │ ├── Tab.scala │ │ ├── TabCreateProperties.scala │ │ ├── CodeInjectionOptions.scala │ │ └── TabQuery.scala │ ├── commands │ ├── bindings │ │ ├── Command.scala │ │ └── Commands.scala │ └── Commands.scala │ ├── filesystem │ └── bindings │ │ └── FileEntry.scala │ ├── wallpaper │ ├── bindings │ │ ├── package.scala │ │ └── Wallpaper.scala │ └── Wallpaper.scala │ ├── app │ ├── runtime │ │ ├── bindings │ │ │ ├── Request.scala │ │ │ ├── Runtime.scala │ │ │ └── LaunchData.scala │ │ └── Runtime.scala │ └── window │ │ ├── bindings │ │ ├── ContentBounds.scala │ │ ├── FrameOptions.scala │ │ ├── Bounds.scala │ │ ├── Window.scala │ │ ├── AppWindow.scala │ │ ├── BoundsSpecification.scala │ │ └── CreateWindowOptions.scala │ │ └── Window.scala │ ├── audio │ ├── bindings │ │ ├── InputInfo.scala │ │ ├── OutputInfo.scala │ │ ├── Properties.scala │ │ └── Audio.scala │ └── Audio.scala │ ├── browser │ ├── bindings │ │ ├── Browser.scala │ │ └── OpenTabOptions.scala │ └── Browser.scala │ ├── utils │ ├── ErrorHandling.scala │ └── ChromeApp.scala │ ├── desktopCapture │ ├── bindings │ │ ├── package.scala │ │ └── DesktopCapture.scala │ └── DesktopCapture.scala │ ├── power │ ├── Power.scala │ └── bindings │ │ └── Power.scala │ ├── browserAction │ ├── bindings │ │ ├── TabIdDetails.scala │ │ ├── PopupDetails.scala │ │ ├── TitleDetails.scala │ │ ├── BadgeTextDetails.scala │ │ ├── BadgeBackgroundColorDetails.scala │ │ ├── BrowserAction.scala │ │ └── IconDetails.scala │ └── BrowserAction.scala │ ├── omnibox │ ├── bindings │ │ ├── DefaultSuggestion.scala │ │ ├── SuggestResult.scala │ │ ├── package.scala │ │ └── Omnibox.scala │ └── Omnibox.scala │ ├── webNavigation │ └── bindings │ │ ├── GetAllFramesOptions.scala │ │ ├── OnTabReplacedDetails.scala │ │ ├── FrameDetails.scala │ │ ├── OnCompletedDetails.scala │ │ ├── AllFramesDetails.scala │ │ ├── OnDOMContentLoadedDetails.scala │ │ ├── GetFrameOptions.scala │ │ ├── OnErrorOccurredDetails.scala │ │ ├── OnCreatedNavigationTargetDetails.scala │ │ ├── OnCommittedDetails.scala │ │ ├── OnBeforeNavigateDetails.scala │ │ └── WebNavigation.scala │ ├── notifications │ ├── bindings │ │ ├── package.scala │ │ ├── Notifications.scala │ │ └── NotificationOptions.scala │ └── Notifications.scala │ ├── i18n │ ├── bindings │ │ └── I18N.scala │ └── I18N.scala │ ├── tts │ ├── bindings │ │ ├── TTSVoice.scala │ │ ├── TTS.scala │ │ ├── TTSEvent.scala │ │ └── SpeakOptions.scala │ └── TTS.scala │ ├── storage │ ├── bindings │ │ └── Storage.scala │ └── Storage.scala │ ├── windows │ ├── bindings │ │ └── Window.scala │ └── Windows.scala │ ├── permissions │ ├── bindings │ │ └── Permissions.scala │ └── Permissions.scala │ ├── pageAction │ ├── PageAction.scala │ └── bindings │ │ └── PageAction.scala │ └── contextMenus │ ├── ContextMenus.scala │ └── bindings │ └── ContextMenus.scala ├── .travis.yml ├── shared └── src │ └── main │ └── scala │ └── chrome │ └── Sockets.scala ├── LICENSE ├── sbt-plugin └── src │ └── main │ └── scala │ └── net │ └── lullabyte │ ├── Chrome.scala │ └── ChromeSbtPlugin.scala └── interop └── monix └── src └── main └── scala └── chrome └── interop └── monix └── package.scala /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.2.6 2 | -------------------------------------------------------------------------------- /examples/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.2.1 2 | 3 | -------------------------------------------------------------------------------- /examples/app/src/main/resources/_locales/en/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .classpath 3 | .idea/ 4 | .project 5 | .settings 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /examples/app/src/main/resources/icons/256/app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucidd/scala-js-chrome/HEAD/examples/app/src/main/resources/icons/256/app.png -------------------------------------------------------------------------------- /examples/extension/src/main/resources/icons/256/app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucidd/scala-js-chrome/HEAD/examples/extension/src/main/resources/icons/256/app.png -------------------------------------------------------------------------------- /examples/extension/src/main/scala/Main.scala: -------------------------------------------------------------------------------- 1 | object Main { 2 | 3 | def main(args: Array[String]): Unit = { 4 | println("Hello world!") 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp 2 | 3 | package object bindings { 4 | 5 | type SocketId = Int 6 | 7 | } 8 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sessions/bindings/Session.scala: -------------------------------------------------------------------------------- 1 | package chrome.sessions.bindings 2 | 3 | class Session {} 4 | 5 | object Session { 6 | type Id = String 7 | } 8 | -------------------------------------------------------------------------------- /examples/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | lazy val sbtPlugin = ProjectRef(file("../../."), "plugin") 3 | lazy val root = project.in( file(".") ).dependsOn(sbtPlugin) 4 | 5 | 6 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/ChromeAPI.scala: -------------------------------------------------------------------------------- 1 | package chrome 2 | 3 | import chrome.permissions.Permission.API 4 | 5 | trait ChromeAPI { 6 | val requiredPermissions: Set[API] 7 | } 8 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer 2 | 3 | package object bindings { 4 | 5 | type SocketId = Int 6 | 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | before_script: 3 | script: 4 | - sbt +bindings/compile 5 | - sbt plugin/compile 6 | - (cd examples; sbt chromeUnpackedOpt) 7 | jdk: 8 | - oraclejdk8 9 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/DirectoryEntry.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | //TODO implement DirectoryEntry facade 6 | @js.native 7 | trait DirectoryEntry extends js.Object {} 8 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/Error.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Error extends js.Object { 7 | 8 | def message: js.UndefOr[String] = js.native 9 | 10 | } 11 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/CreateInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait CreateInfo extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | } 11 | -------------------------------------------------------------------------------- /examples/app/src/main/scala/Main.scala: -------------------------------------------------------------------------------- 1 | import chrome.app.runtime.bindings.LaunchData 2 | import chrome.utils.ChromeApp 3 | 4 | object Main extends ChromeApp { 5 | override def onLaunched(launchData: LaunchData): Unit = { 6 | println("Hello World!") 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/CreateInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait CreateInfo extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | } 11 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/HttpMethod.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | sealed trait HttpMethod 4 | object HttpMethod { 5 | val GET: HttpMethod = "GET".asInstanceOf[HttpMethod] 6 | val POST: HttpMethod = "POST".asInstanceOf[HttpMethod] 7 | } 8 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/OnUpdateAvailableDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait OnUpdateAvailableDetails extends js.Object { 7 | 8 | val version: String = js.native 9 | 10 | } 11 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/Delta.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scalajs.js 4 | 5 | @js.native 6 | trait Delta[T] extends js.Object { 7 | def previous: js.UndefOr[T] = js.native 8 | def current: js.UndefOr[T] = js.native 9 | } 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/management/bindings/IconInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.management.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait IconInfo extends js.Object { 7 | 8 | val size: Int = js.native 9 | val url: String = js.native 10 | 11 | } 12 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/processes/bindings/Cache.scala: -------------------------------------------------------------------------------- 1 | package chrome.processes.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Cache extends js.Object { 7 | 8 | val size: Double = js.native 9 | val liveSize: Double = js.native 10 | 11 | } 12 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/Suggestion.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scalajs.js 4 | 5 | @js.native 6 | trait Suggestion extends js.Object { 7 | def filename: String 8 | def conflictAction: js.UndefOr[FilenameConflictAction] 9 | } 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebAuthChallenger.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebAuthChallenger extends js.Object { 7 | val host: String = js.native 8 | val port: Int = js.native 9 | } 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/SendMessageOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SendMessageOptions extends js.Object { 7 | 8 | val includeTlsChannelId: js.UndefOr[Boolean] = js.native 9 | 10 | } 11 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/AuthCredentials.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait AuthCredentials extends js.Object { 7 | val username: String = js.native 8 | val password: String = js.native 9 | } 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRequestDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRequestDetails extends ResourceRequest { 7 | /** Standard HTTP method. */ 8 | val method: String = js.native 9 | } 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/idle/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.idle 2 | 3 | package object bindings { 4 | 5 | type State = String 6 | 7 | object State { 8 | val ACTIVE: State = "active" 9 | val IDLE: State = "idle" 10 | val LOCKED: State = "locked" 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/events/MappedEventSource.scala: -------------------------------------------------------------------------------- 1 | package chrome.events 2 | 3 | class MappedEventSource[A, B](source: EventSource[A], map: A => B) 4 | extends EventSource[B] { 5 | 6 | def listen(fn: B => Unit): Subscription = { 7 | source.listen(map.andThen(fn)) 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/SendInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SendInfo extends js.Object { 7 | 8 | def resultCode: Int = js.native 9 | 10 | def bytesSent: js.UndefOr[Int] = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/memory/bindings/MemoryInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.memory.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait MemoryInfo extends js.Object { 7 | 8 | def capacity: Double = js.native 9 | 10 | def availableCapacity: Double = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/ReceiveErrorEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ReceiveErrorEvent extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | def resultCode: Int = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/State.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | sealed trait State 4 | object State { 5 | val in_progress: State = "in_progress".asInstanceOf[State] 6 | val interrupted: State = "interrupted".asInstanceOf[State] 7 | val complete: State = "complete".asInstanceOf[State] 8 | } 9 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/ConnectInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ConnectInfo extends js.Object { 7 | 8 | def name: js.UndefOr[String] = js.native 9 | 10 | def includeTlsChannelId: js.UndefOr[Boolean] = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/AcceptErrorEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait AcceptErrorEvent extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | def resultCode: Int = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/network/Interface.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.network 2 | 3 | import chrome.system.network.Interface.Config 4 | 5 | case class Interface(name: String, configurations: List[Config]) 6 | 7 | object Interface { 8 | 9 | case class Config(address: String, prefixLength: Int) 10 | 11 | } 12 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/alarms/bindings/Alarm.scala: -------------------------------------------------------------------------------- 1 | package chrome.alarms.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Alarm extends js.Object { 7 | 8 | def name: String = js.native 9 | def scheduledTime: Double = js.native 10 | def periodInMinutes: js.UndefOr[Double] = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ActiveInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait ActiveInfo extends js.Object { 9 | 10 | def tabId: Tab.Id = js.native 11 | 12 | def windowId: Window.Id = js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/AttachInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait AttachInfo extends js.Object { 9 | 10 | def newWindowId: Window.Id = js.native 11 | 12 | def newPosition: Int = js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/DetachInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait DetachInfo extends js.Object { 9 | 10 | def oldWindowId: Window.Id = js.native 11 | 12 | def oldPosition: Int = js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRedirectionResponseDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRedirectionResponseDetails extends WebResponseCacheDetails { 7 | /** 8 | * The new URL. 9 | */ 10 | val redirectUrl: String = js.native 11 | } 12 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/network/bindings/NetworkInterface.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.network.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait NetworkInterface extends js.Object { 7 | 8 | val name: String = js.native 9 | val address: String = js.native 10 | val prefixLength: Int = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/RemoveInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait RemoveInfo extends js.Object { 9 | 10 | def windowId: Window.Id = js.native 11 | 12 | def isWindowClosing: Boolean = js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/AcceptEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait AcceptEvent extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | def clientSocketId: chrome.sockets.tcp.bindings.SocketId = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/HighlightInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait HighlightInfo extends js.Object { 9 | 10 | def windowId: Window.Id = js.native 11 | 12 | def tabIds: js.Array[Tab.Id] = js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/commands/bindings/Command.scala: -------------------------------------------------------------------------------- 1 | package chrome.commands.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Command extends js.Object { 7 | 8 | val name: js.UndefOr[String] = js.native 9 | val description: js.UndefOr[String] = js.native 10 | val shortcut: js.UndefOr[String] = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/ReceiveEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.typedarray.ArrayBuffer 5 | 6 | @js.native 7 | trait ReceiveEvent extends js.Object { 8 | 9 | def socketId: SocketId = js.native 10 | 11 | def data: ArrayBuffer = js.native 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/cpu/bindings/CPU.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.cpu.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | @JSGlobal("chrome.system.cpu") 8 | object CPU extends js.Object { 9 | 10 | def getInfo(callback: js.Function1[CPUInfo, _]): Unit = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/events/FilteredEventSource.scala: -------------------------------------------------------------------------------- 1 | package chrome.events 2 | 3 | class FilteredEventSource[A](source: EventSource[A], filter: A => Boolean) 4 | extends EventSource[A] { 5 | 6 | def listen(fn: A => Unit): Subscription = { 7 | source.listen((event) => { 8 | if (filter(event)) fn(event) 9 | }) 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/filesystem/bindings/FileEntry.scala: -------------------------------------------------------------------------------- 1 | package chrome.filesystem.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait FileEntry extends js.Object { 7 | 8 | val fullPath: String = js.native 9 | val isDirectory: Boolean = js.native 10 | val isFile: Boolean = js.native 11 | val name: String = js.native 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/MoveInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait MoveInfo extends js.Object { 9 | 10 | def windowId: Window.Id = js.native 11 | 12 | def fromIndex: Int = js.native 13 | 14 | def toIndex: Int = js.native 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/memory/bindings/Memory.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.memory.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | @JSGlobal("chrome.system.memory") 8 | object Memory extends js.Object { 9 | 10 | def getInfo(callback: js.Function1[MemoryInfo, _]): Unit = js.native 11 | 12 | } 13 | -------------------------------------------------------------------------------- /shared/src/main/scala/chrome/Sockets.scala: -------------------------------------------------------------------------------- 1 | package chrome 2 | 3 | case class Udp(bind: Set[String] = Set(), 4 | send: Set[String] = Set(), 5 | multicastMembership: Set[String] = Set()) 6 | 7 | case class Tcp(connect: Set[String] = Set(), listen: Set[String] = Set()) 8 | 9 | case class Sockets(udp: Option[Udp] = None, tcp: Option[Tcp] = None) 10 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/wallpaper/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.wallpaper 2 | 3 | package object bindings { 4 | 5 | type WallpaperLayout = String 6 | 7 | object WallpaperLayout { 8 | val STRETCH: WallpaperLayout = "STRETCH" 9 | val CENTER: WallpaperLayout = "CENTER" 10 | val CENTER_CROPPED: WallpaperLayout = "CENTER_CROPPED" 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/runtime/bindings/Request.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Request extends js.Object { 7 | 8 | def embedderId: String = js.native 9 | 10 | def data: js.UndefOr[js.Any] = js.native 11 | 12 | def allow(url: String): Unit = js.native 13 | 14 | def deny(): Unit = js.native 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/ContentBounds.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ContentBounds extends js.Object { 7 | 8 | var left: js.UndefOr[Int] = js.native 9 | var top: js.UndefOr[Int] = js.native 10 | var width: js.UndefOr[Int] = js.native 11 | var height: js.UndefOr[Int] = js.native 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ZoomChangeInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ZoomChangeInfo extends js.Object { 7 | 8 | def tabId: Tab.Id = js.native 9 | 10 | def oldZoomFactor: Double = js.native 11 | 12 | def newZoomFactor: Double = js.native 13 | 14 | def zoomSettings: ZoomSettings = js.native 15 | 16 | } 17 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25") 2 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") 3 | addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") 4 | addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2") 5 | addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3") 6 | resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/" 7 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/audio/bindings/InputInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.audio.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait InputInfo extends js.Object { 7 | 8 | def id: Audio.DeviceID = js.native 9 | 10 | def name: String = js.native 11 | 12 | def isActive: Boolean = js.native 13 | 14 | def isMuted: Boolean = js.native 15 | 16 | def gain: Double = js.native 17 | 18 | } 19 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/audio/bindings/OutputInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.audio.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait OutputInfo extends js.Object { 7 | 8 | def id: Audio.DeviceID = js.native 9 | 10 | def name: String = js.native 11 | 12 | def isActive: Boolean = js.native 13 | 14 | def isMuted: Boolean = js.native 15 | 16 | def volume: Double = js.native 17 | 18 | } 19 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/network/bindings/Network.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.network.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | @JSGlobal("chrome.system.network") 8 | object Network extends js.Object { 9 | 10 | def getNetworkInterfaces( 11 | callback: js.Function1[js.Array[NetworkInterface], _]): Unit = js.native 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ChangeInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ChangeInfo extends js.Object { 7 | 8 | def status: js.UndefOr[Tab.Status] = js.native 9 | 10 | def url: js.UndefOr[String] = js.native 11 | 12 | def pinned: js.UndefOr[Boolean] = js.native 13 | 14 | def favIconUrl: js.UndefOr[String] = js.native 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browser/bindings/Browser.scala: -------------------------------------------------------------------------------- 1 | package chrome.browser.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | @JSGlobal("chrome.browser") 8 | object Browser extends js.Object { 9 | 10 | def openTab(options: OpenTabOptions, 11 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 12 | js.native 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/events/bindings/Event.scala: -------------------------------------------------------------------------------- 1 | package chrome.events.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Event[-T <: js.Function] extends js.Object { 7 | 8 | def addListener(callback: T): Unit = js.native 9 | def removeListener(callback: T): Unit = js.native 10 | def hasListener(callback: T): Boolean = js.native 11 | def hasListeners(): Boolean = js.native 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRequestBodyDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRequestBodyDetails extends WebRequestDetails { 7 | /** 8 | * Contains the HTTP request body data. Only provided if extraInfoSpec contains 'requestBody'. 9 | * @since Chrome 23. 10 | */ 11 | val requestBody: WebRequestBody = js.native 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRequestHeadersDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRequestHeadersDetails extends WebRequestDetails { 7 | /** 8 | * Optional: 9 | * The HTTP request headers that are going to be sent out with this request. 10 | */ 11 | val requestHeaders: js.UndefOr[js.Array[HttpHeader]] = js.native 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/FileIconOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | 4 | import scalajs.js 5 | 6 | @js.native 7 | trait FileIconOptions extends js.Object { 8 | def size: js.UndefOr[Int] 9 | } 10 | 11 | object FileIconOptions { 12 | def apply(size: js.UndefOr[Int] = js.undefined): FileIconOptions = { 13 | js.Dynamic.literal( 14 | size = size 15 | ).asInstanceOf[FileIconOptions] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/cpu/bindings/CPUInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.cpu.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait CPUInfo extends js.Object { 7 | 8 | def numOfProcessors: Int = js.native 9 | 10 | def archName: String = js.native 11 | 12 | def modelName: String = js.native 13 | 14 | def features: js.Array[Feature] = js.native 15 | 16 | def processors: js.Array[Processor] = js.native 17 | 18 | } 19 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/FilenameConflictAction.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | sealed trait FilenameConflictAction 4 | object FilenameConflictAction { 5 | val uniquify: FilenameConflictAction = "uniquify".asInstanceOf[FilenameConflictAction] 6 | val overwrite: FilenameConflictAction = "overwrite".asInstanceOf[FilenameConflictAction] 7 | val prompt: FilenameConflictAction = "prompt".asInstanceOf[FilenameConflictAction] 8 | } 9 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browser/bindings/OpenTabOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.browser.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait OpenTabOptions extends js.Object { 7 | val url: String = js.native 8 | } 9 | 10 | object OpenTabOptions { 11 | 12 | def apply(url: String): OpenTabOptions = { 13 | js.Dynamic 14 | .literal( 15 | url = url 16 | ) 17 | .asInstanceOf[OpenTabOptions] 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/utils/ErrorHandling.scala: -------------------------------------------------------------------------------- 1 | package chrome.utils 2 | 3 | import chrome.runtime.bindings.Runtime 4 | 5 | import scala.util.{Failure, Success, Try} 6 | 7 | object ErrorHandling { 8 | 9 | def lastErrorOrValue[T](value: => T): Try[T] = { 10 | Runtime.lastError 11 | .filter(_ != null) 12 | .map { x => 13 | Failure(new Exception(x.message.getOrElse(""))) 14 | }.getOrElse(Success(value)) 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebResponseErrorDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebResponseErrorDetails extends WebResponseCacheDetails { 7 | /** 8 | * The error description. This string is not guaranteed to remain backwards compatible between releases. You must 9 | * not parse and act based upon its content. 10 | */ 11 | val error: String = js.native 12 | } 13 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/desktopCapture/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.desktopCapture 2 | 3 | package object bindings { 4 | 5 | type DesktopMediaRequestId = Int 6 | type StreamId = String 7 | 8 | type DesktopCaptureSourceType = String 9 | 10 | object DesktopCaptureSourceType { 11 | val SCREEN: DesktopCaptureSourceType = "screen" 12 | val WINDOW: DesktopCaptureSourceType = "window" 13 | val TAB: DesktopCaptureSourceType = "tab" 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/power/Power.scala: -------------------------------------------------------------------------------- 1 | package chrome.power 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.power.bindings._ 6 | 7 | object Power extends ChromeAPI { 8 | 9 | val requiredPermissions: Set[API] = Set(API.Power) 10 | 11 | def requestKeepAwake(level: Level.Level): Unit = 12 | bindings.Power.requestKeepAwake(level) 13 | 14 | def releaseKeepAwake(): Unit = bindings.Power.releaseKeepAwake() 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/TabIdDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait TabIdDetails extends js.Object { 7 | val tabId: js.UndefOr[Int] = js.native 8 | } 9 | 10 | object TabIdDetails { 11 | def apply(tabId: js.UndefOr[Int] = js.undefined): TabIdDetails = { 12 | js.Dynamic 13 | .literal( 14 | tabId = tabId 15 | ) 16 | .asInstanceOf[TabIdDetails] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/CaptureOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object CaptureOptions { 6 | 7 | type ImageFormat = String 8 | 9 | val JPEG: ImageFormat = "jpeg" 10 | val PNG: ImageFormat = "png" 11 | 12 | } 13 | 14 | @js.native 15 | trait CaptureOptions extends js.Object { 16 | 17 | def format: js.UndefOr[CaptureOptions.ImageFormat] = js.native 18 | 19 | def quality: js.UndefOr[Int] = js.native 20 | 21 | } 22 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/MessageSender.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import chrome.tabs.bindings.Tab 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait MessageSender extends js.Object { 9 | 10 | def id: js.UndefOr[String] = js.native 11 | 12 | def url: js.UndefOr[String] = js.native 13 | 14 | def tlsChannelId: js.UndefOr[String] = js.native 15 | 16 | def tab: js.UndefOr[Tab] = js.native 17 | 18 | def frameId: js.UndefOr[Int] = js.native 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/cpu/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.cpu 2 | 3 | package object bindings { 4 | 5 | type Feature = String 6 | 7 | object Features { 8 | 9 | val MMX: Feature = "mmx" 10 | val SSE: Feature = "sse" 11 | val SSE2: Feature = "sse2" 12 | val SSE3: Feature = "sse3" 13 | val SSSE3: Feature = "ssse3" 14 | val SSE4_1: Feature = "sse4_1" 15 | val SSE4_2: Feature = "sse4_2" 16 | val AVX: Feature = "avx" 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/runtime/Runtime.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.runtime 2 | 3 | import chrome.app.runtime.bindings.{LaunchData, Request} 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | 7 | object Runtime { 8 | 9 | val onEmbedRequested: EventSource[Request] = 10 | bindings.Runtime.onEmbedRequested 11 | val onLaunched: EventSource[LaunchData] = bindings.Runtime.onLaunched 12 | val onRestarted: EventSource[Unit] = bindings.Runtime.onRestarted 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/HttpHeader.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.typedarray.ArrayBuffer 5 | 6 | /** 7 | * An HTTP Header, represented as an object containing a key and either a value or a binaryValue. 8 | */ 9 | @js.native 10 | trait HttpHeader extends js.Object { 11 | val name: String = js.native 12 | val value: js.UndefOr[String] = js.native 13 | val binaryValue: js.UndefOr[ArrayBuffer] = js.native 14 | } 15 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/commands/bindings/Commands.scala: -------------------------------------------------------------------------------- 1 | package chrome.commands.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.commands") 10 | object Commands extends js.Object { 11 | 12 | val onCommand: Event[js.Function1[String, _]] = js.native 13 | 14 | def getAll(callback: js.UndefOr[js.Function1[js.Array[Command], _]] = 15 | js.undefined): Unit = js.native 16 | 17 | } 18 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/omnibox/bindings/DefaultSuggestion.scala: -------------------------------------------------------------------------------- 1 | package chrome.omnibox.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait DefaultSuggestion extends js.Object { 7 | 8 | val description: String = js.native 9 | 10 | } 11 | 12 | object DefaultSuggestion { 13 | 14 | def apply(description: String): DefaultSuggestion = { 15 | js.Dynamic 16 | .literal( 17 | description = description 18 | ) 19 | .asInstanceOf[DefaultSuggestion] 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/PopupDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait PopupDetails extends TabIdDetails { 7 | val popup: String = js.native 8 | } 9 | 10 | object PopupDetails { 11 | def apply(popup: String, tabId: js.UndefOr[Int] = js.undefined): PopupDetails = { 12 | js.Dynamic 13 | .literal( 14 | popup = popup, 15 | tabId = tabId 16 | ) 17 | .asInstanceOf[PopupDetails] 18 | } 19 | } -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/TitleDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait TitleDetails extends TabIdDetails { 7 | val title: String = js.native 8 | } 9 | 10 | object TitleDetails { 11 | def apply(title: String, tabId: js.UndefOr[Int] = js.undefined): TitleDetails = { 12 | js.Dynamic 13 | .literal( 14 | title = title, 15 | tabId = tabId 16 | ) 17 | .asInstanceOf[TitleDetails] 18 | } 19 | } -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/SocketInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SocketInfo extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | def persistent: Boolean = js.native 11 | 12 | def name: js.UndefOr[String] = js.native 13 | 14 | def paused: Boolean = js.native 15 | 16 | def localAddress: js.UndefOr[String] = js.native 17 | 18 | def localPort: js.UndefOr[Int] = js.native 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/cpu/bindings/Processor.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.cpu.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Processor extends js.Object { 7 | 8 | def usage: Processor.Usage = js.native 9 | 10 | } 11 | 12 | object Processor { 13 | 14 | @js.native 15 | trait Usage extends js.Object { 16 | 17 | val user: Double = js.native 18 | val kernel: Double = js.native 19 | val idle: Double = js.native 20 | val total: Double = js.native 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/runtime/bindings/Runtime.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.runtime.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.app.runtime") 10 | object Runtime extends js.Object { 11 | 12 | val onEmbedRequested: Event[js.Function1[Request, _]] = js.native 13 | val onLaunched: Event[js.Function1[LaunchData, _]] = js.native 14 | val onRestarted: Event[js.Function0[_]] = js.native 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/MessageOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object MessageOptions { 6 | def apply(frameId: js.UndefOr[ConnectInfo.FrameID] = js.undefined) 7 | : MessageOptions = { 8 | js.Dynamic 9 | .literal( 10 | frameId = frameId 11 | ) 12 | .asInstanceOf[MessageOptions] 13 | } 14 | } 15 | 16 | @js.native 17 | trait MessageOptions extends js.Object { 18 | def frameId: js.UndefOr[ConnectInfo.FrameID] = js.native 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/GetAllFramesOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import chrome.tabs.bindings.Tab 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait GetAllFramesOptions extends js.Object { 9 | /** 10 | * The ID of the tab. 11 | */ 12 | val tabId: Tab.Id 13 | } 14 | 15 | object GetAllFramesOptions { 16 | def apply(tabId: Tab.Id): GetAllFramesOptions = 17 | js.Dynamic.literal( 18 | tabId = tabId 19 | ).asInstanceOf[GetAllFramesOptions] 20 | } -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebResponseHeadersDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebResponseHeadersDetails extends WebResponseDetails { 7 | /** 8 | * Optional: 9 | * The HTTP response headers that have been received with this response. 10 | */ 11 | val responseHeaders: js.UndefOr[js.Array[HttpHeader]] = js.native 12 | 13 | /** standard HTTP method i.e. GET, POST, PUT, etc. */ 14 | val method: String = js.native 15 | } 16 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/power/bindings/Power.scala: -------------------------------------------------------------------------------- 1 | package chrome.power.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | @JSGlobal("chrome.power") 8 | object Power extends js.Object { 9 | 10 | def requestKeepAwake(level: Level.Level): Unit = js.native 11 | 12 | def releaseKeepAwake(): Unit = js.native 13 | 14 | } 15 | 16 | object Level { 17 | 18 | type Level = String 19 | 20 | val SYSTEM: Level = "system" 21 | val DISPLAY: Level = "display" 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/BadgeTextDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait BadgeTextDetails extends TabIdDetails { 7 | val text: String = js.native 8 | } 9 | 10 | object BadgeTextDetails { 11 | def apply(text: String, tabId: js.UndefOr[Int] = js.undefined): BadgeTextDetails = { 12 | js.Dynamic 13 | .literal( 14 | text = text, 15 | tabId = tabId 16 | ) 17 | .asInstanceOf[BadgeTextDetails] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/notifications/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.notifications 2 | 3 | package object bindings { 4 | 5 | type TemplateType = String 6 | object TemplateType { 7 | val BASIC: TemplateType = "basic" 8 | val IMAGE: TemplateType = "image" 9 | val LIST: TemplateType = "list" 10 | val PROGRESS: TemplateType = "progress" 11 | } 12 | 13 | type PermissionLevel = String 14 | object PermissionLevel { 15 | val GRANTED: PermissionLevel = "granted" 16 | val DENIED: PermissionLevel = "denied" 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ReloadProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ReloadProperties extends js.Object { 7 | 8 | def bypassCache: js.UndefOr[Boolean] = js.native 9 | 10 | } 11 | 12 | object ReloadProperties { 13 | 14 | def apply( 15 | bypassCache: js.UndefOr[Boolean] = js.undefined): ReloadProperties = { 16 | js.Dynamic 17 | .literal( 18 | bypassCache = bypassCache 19 | ) 20 | .asInstanceOf[ReloadProperties] 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/UploadData.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.typedarray.ArrayBuffer 5 | 6 | 7 | /** 8 | * Contains data uploaded in a URL request. 9 | * 10 | * @since Chrome 23. 11 | */ 12 | @js.native 13 | trait UploadData extends js.Object { 14 | /** Optional. An ArrayBuffer with a copy of the data. */ 15 | val bytes: js.UndefOr[ArrayBuffer] 16 | 17 | /** Optional. A string with the file's path and name. */ 18 | val file: js.UndefOr[String] 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/SecureOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SecureOptions extends js.Object { 7 | 8 | def tlsVersion: js.UndefOr[TLSVersionBounds] = js.native 9 | 10 | } 11 | 12 | object SecureOptions { 13 | 14 | def apply(tlsVersion: js.UndefOr[TLSVersionBounds] = js.undefined) 15 | : SecureOptions = { 16 | js.Dynamic 17 | .literal( 18 | tlsVersion = tlsVersion 19 | ) 20 | .asInstanceOf[SecureOptions] 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/FrameOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait FrameOptions extends js.Object { 7 | 8 | val `type`: js.UndefOr[FrameOptions.Type] = js.native 9 | val color: js.UndefOr[String] = js.native 10 | val activeColor: js.UndefOr[String] = js.native 11 | val inactiveColor: js.UndefOr[String] = js.native 12 | 13 | } 14 | 15 | object FrameOptions { 16 | 17 | type Type = String 18 | 19 | val NONE: Type = "none" 20 | val CHROME: Type = "chrome" 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebResponseCacheDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebResponseCacheDetails extends WebResponseHeadersDetails { 7 | /** 8 | * Optional: 9 | * The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address. 10 | */ 11 | val ip: js.UndefOr[String] = js.native 12 | 13 | /** 14 | * Indicates if this response was fetched from disk cache. 15 | */ 16 | val fromCache: Boolean = js.native 17 | } 18 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/idle/bindings/Idle.scala: -------------------------------------------------------------------------------- 1 | package chrome.idle.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.idle") 10 | object Idle extends js.Object { 11 | 12 | val onStateChanged: Event[js.Function1[State, _]] = js.native 13 | 14 | def queryState(detectionIntervalInSeconds: Int, 15 | callback: js.Function1[State, _]): Unit = js.native 16 | 17 | def setDetectionInterval(intervalInSeconds: Int): Unit = js.native 18 | 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/omnibox/bindings/SuggestResult.scala: -------------------------------------------------------------------------------- 1 | package chrome.omnibox.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SuggestResult extends js.Object { 7 | 8 | val content: String = js.native 9 | val description: String = js.native 10 | 11 | } 12 | 13 | object SuggestResult { 14 | 15 | def apply(content: String, description: String): SuggestResult = { 16 | js.Dynamic 17 | .literal( 18 | content = content, 19 | description = description 20 | ) 21 | .asInstanceOf[SuggestResult] 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebResponseDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebResponseDetails extends ResourceRequest { 7 | /** 8 | * HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that 9 | * lack a status line). 10 | */ 11 | val statusLine: String = js.native 12 | 13 | /** 14 | * Standard HTTP status code returned by the server. 15 | * @since Chrome 43. 16 | */ 17 | val statusCode: Int = js.native 18 | } 19 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/utils/ChromeApp.scala: -------------------------------------------------------------------------------- 1 | package chrome.utils 2 | 3 | import chrome.app.runtime.Runtime 4 | import chrome.app.runtime.bindings.{LaunchData, Request} 5 | 6 | trait ChromeApp { 7 | 8 | def main(args: Array[String]): Unit = { 9 | Runtime.onLaunched.listen(onLaunched) 10 | Runtime.onRestarted.listen((_) => onRestart) 11 | Runtime.onEmbedRequested.listen(onEmbedRequested) 12 | } 13 | 14 | def onLaunched(launchData: LaunchData): Unit = {} 15 | 16 | def onRestart(): Unit = {} 17 | 18 | def onEmbedRequested(request: Request): Unit = {} 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRequestEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRequestEvent[-T <: js.Function] extends js.Object { 7 | 8 | def addListener(callback: T, 9 | filter: RequestFilter, 10 | opt_extraInfoSpec: js.UndefOr[js.Array[String]] = js.undefined): Unit = js.native 11 | 12 | def removeListener(callback: T): Unit = js.native 13 | 14 | def hasListener(callback: T): Boolean = js.native 15 | 16 | def hasListeners(): Boolean = js.native 17 | } 18 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnTabReplacedDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnTabReplacedDetails extends js.Object { 8 | /** 9 | * The ID of the tab that was replaced. 10 | */ 11 | val replacedTabId: Int = native 12 | /** 13 | * The ID of the tab that replaced the old tab. 14 | */ 15 | val tabId: Int = native 16 | /** 17 | * The time when the replacement happened, in milliseconds since the epoch. 18 | */ 19 | val timeStamp: Double = native 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/i18n/bindings/I18N.scala: -------------------------------------------------------------------------------- 1 | package chrome.i18n.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | import scala.scalajs.js.| 6 | 7 | @js.native 8 | @JSGlobal("chrome.i18n") 9 | object I18N extends js.Object { 10 | 11 | def getAcceptLanguages(callback: js.Function1[js.Array[String], _]): Unit = 12 | js.native 13 | 14 | def getMessage(messageName: String, 15 | substitutions: js.UndefOr[String | js.Array[String]] = js.undefined): js.UndefOr[String] = js.native 16 | 17 | def getUILanguage(): String = js.native 18 | 19 | } 20 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/cpu/CPU.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.cpu 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.system.cpu.bindings._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | 10 | object CPU extends ChromeAPI { 11 | 12 | val requiredPermissions: Set[API] = Set(API.System.CPU) 13 | 14 | def getInfo: Future[CPUInfo] = { 15 | val promise = Promise[CPUInfo]() 16 | bindings.CPU.getInfo((info: CPUInfo) => { 17 | promise.complete(lastErrorOrValue(info)) 18 | }) 19 | promise.future 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/Port.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait Port extends js.Object { 9 | 10 | val name: String = js.native 11 | val onDisconnect: Event[js.Function0[_]] = js.native 12 | //TODO: find out how the callback function for onMessage looks 13 | val onMessage: Event[js.Function2[js.Any, MessageSender, _]] = js.native 14 | 15 | def disconnect(): Unit = js.native 16 | 17 | def postMessage(message: js.Any): Unit = js.native 18 | 19 | def sender: js.UndefOr[MessageSender] = js.native 20 | 21 | } 22 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/bindings/Bounds.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Bounds extends js.Object { 7 | 8 | val left: Int = js.native 9 | val top: Int = js.native 10 | val width: Int = js.native 11 | val height: Int = js.native 12 | 13 | } 14 | 15 | object Bounds { 16 | 17 | def apply(left: Int, top: Int, width: Int, height: Int): Bounds = { 18 | js.Dynamic 19 | .literal( 20 | left = left, 21 | top = top, 22 | width = width, 23 | height = height 24 | ) 25 | .asInstanceOf[Bounds] 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/bindings/Insets.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Insets extends js.Object { 7 | 8 | val left: Int = js.native 9 | val top: Int = js.native 10 | val right: Int = js.native 11 | val bottom: Int = js.native 12 | 13 | } 14 | 15 | object Insets { 16 | 17 | def apply(left: Int, top: Int, right: Int, bottom: Int): Insets = { 18 | js.Dynamic 19 | .literal( 20 | left = left, 21 | top = top, 22 | right = right, 23 | bottom = bottom 24 | ) 25 | .asInstanceOf[Insets] 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/memory/Memory.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.memory 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.system.memory.bindings._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | 10 | object Memory extends ChromeAPI { 11 | 12 | val requiredPermissions: Set[API] = Set(API.System.Memory) 13 | 14 | def getInfo: Future[MemoryInfo] = { 15 | val promise = Promise[MemoryInfo]() 16 | bindings.Memory.getInfo((info: MemoryInfo) => { 17 | promise.complete(lastErrorOrValue(info)) 18 | }) 19 | promise.future 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/DangerType.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | sealed trait DangerType 4 | object DangerType { 5 | val file: DangerType = "file".asInstanceOf[DangerType] 6 | val url: DangerType = "url".asInstanceOf[DangerType] 7 | val content: DangerType = "content".asInstanceOf[DangerType] 8 | val uncommon: DangerType = "uncommon".asInstanceOf[DangerType] 9 | val host: DangerType = "host".asInstanceOf[DangerType] 10 | val unwanted: DangerType = "unwanted".asInstanceOf[DangerType] 11 | val safe: DangerType = "safe".asInstanceOf[DangerType] 12 | val accepted: DangerType = "accepted".asInstanceOf[DangerType] 13 | } 14 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/desktopCapture/bindings/DesktopCapture.scala: -------------------------------------------------------------------------------- 1 | package chrome.desktopCapture.bindings 2 | 3 | import chrome.tabs.bindings.Tab 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.desktopCapture") 10 | object DesktopCapture extends js.Object { 11 | 12 | def chooseDesktopMedia( 13 | sources: js.Array[DesktopCaptureSourceType], 14 | targetTab: js.UndefOr[Tab], 15 | callback: js.Function1[StreamId, _]): DesktopMediaRequestId = js.native 16 | 17 | def cancelChooseDesktopMedia( 18 | desktopMediaRequestId: DesktopMediaRequestId): Unit = js.native 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/MoveProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | object MoveProperties { 8 | 9 | def apply(windowId: js.UndefOr[Window.Id] = js.undefined, 10 | index: Int): MoveProperties = { 11 | js.Dynamic 12 | .literal( 13 | windowId = windowId, 14 | index = index 15 | ) 16 | .asInstanceOf[MoveProperties] 17 | } 18 | 19 | } 20 | 21 | @js.native 22 | trait MoveProperties extends js.Object { 23 | 24 | def windowId: js.UndefOr[Window.Id] = js.native 25 | 26 | def index: Int = js.native 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/omnibox/bindings/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.omnibox 2 | 3 | package object bindings { 4 | 5 | type DescriptionStyleType = String 6 | 7 | object DescriptionStyleType { 8 | val URL: DescriptionStyleType = "url" 9 | val MATCH: DescriptionStyleType = "match" 10 | val DIM: DescriptionStyleType = "dim" 11 | } 12 | 13 | type OnInputEnteredDisposition = String 14 | 15 | object OnInputEnteredDisposition { 16 | val CURRENT_TAB: OnInputEnteredDisposition = "currentTab" 17 | val NEW_FOREGROUND_TAB: OnInputEnteredDisposition = "newForegroundTab" 18 | val NEW_BACKGROUND_TAB: OnInputEnteredDisposition = "newBackgroundTab" 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/SocketProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SocketProperties extends js.Object { 7 | 8 | def persistent: js.UndefOr[Boolean] = js.native 9 | 10 | def name: js.UndefOr[String] = js.native 11 | 12 | } 13 | 14 | object SocketProperties { 15 | 16 | def apply(persistent: js.UndefOr[Boolean] = js.undefined, 17 | name: js.UndefOr[String] = js.undefined): SocketProperties = { 18 | js.Dynamic 19 | .literal( 20 | persistent = persistent, 21 | name = name 22 | ) 23 | .asInstanceOf[SocketProperties] 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browser/Browser.scala: -------------------------------------------------------------------------------- 1 | package chrome.browser 2 | 3 | import chrome.ChromeAPI 4 | import chrome.browser.bindings.OpenTabOptions 5 | import chrome.permissions.Permission.API 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object Browser extends ChromeAPI { 12 | 13 | val requiredPermissions: Set[API] = Set(API.Browser) 14 | 15 | def openTab(url: String): Future[Unit] = { 16 | val promise = Promise[Unit]() 17 | bindings.Browser 18 | .openTab(OpenTabOptions(url = url), js.Any.fromFunction0(() => { 19 | promise.complete(lastErrorOrValue(())) 20 | })) 21 | promise.future 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/SocketInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SocketInfo extends js.Object { 7 | 8 | def socketId: SocketId = js.native 9 | 10 | def persistent: Boolean = js.native 11 | 12 | def name: js.UndefOr[String] = js.native 13 | 14 | def bufferSize: js.UndefOr[Int] = js.native 15 | 16 | def paused: Boolean = js.native 17 | 18 | def connected: Boolean = js.native 19 | 20 | def localAddress: js.UndefOr[String] = js.native 21 | 22 | def localPort: js.UndefOr[Int] = js.native 23 | 24 | def peerAddress: js.UndefOr[String] = js.native 25 | 26 | def peerPort: js.UndefOr[Int] = js.native 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ConnectInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object ConnectInfo { 6 | 7 | //TODO: find a better place for this 8 | type FrameID = Int 9 | 10 | def apply(name: js.UndefOr[String] = js.undefined, 11 | frameId: js.UndefOr[FrameID] = js.undefined): ConnectInfo = { 12 | js.Dynamic 13 | .literal( 14 | name = name, 15 | frameId = frameId 16 | ) 17 | .asInstanceOf[ConnectInfo] 18 | } 19 | 20 | } 21 | 22 | @js.native 23 | trait ConnectInfo extends js.Object { 24 | 25 | def name: js.UndefOr[String] = js.native 26 | 27 | def frameId: js.UndefOr[ConnectInfo.FrameID] = js.native 28 | 29 | } 30 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/bindings/Display.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.{UndefOr, native, undefined} 8 | 9 | @js.native 10 | @JSGlobal("chrome.system.display") 11 | object Display extends js.Object { 12 | 13 | type ID = String 14 | val onDisplayChanged: Event[js.Function0[_]] = native 15 | 16 | def getInfo(callback: js.Function1[js.Array[DisplayInfo], _]): Unit = native 17 | 18 | def setDisplayProperties( 19 | id: ID, 20 | info: DisplayProperties, 21 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tts/bindings/TTSVoice.scala: -------------------------------------------------------------------------------- 1 | package chrome.tts.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object TTSVoice { 6 | 7 | type Gender = String 8 | 9 | object Genders { 10 | val MALE: Gender = "male" 11 | val FEMALE: Gender = "female" 12 | } 13 | 14 | } 15 | 16 | @js.native 17 | trait TTSVoice extends js.Object { 18 | 19 | def voiceName: js.UndefOr[String] = js.native 20 | 21 | def lang: js.UndefOr[String] = js.native 22 | 23 | def gender: js.UndefOr[TTSVoice.Gender] = js.native 24 | 25 | def remote: js.UndefOr[Boolean] = js.native 26 | 27 | def extensionId: js.UndefOr[String] = js.native 28 | 29 | def eventTypes: js.UndefOr[js.Array[TTSEvent.Type]] = js.native 30 | 31 | } 32 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/audio/bindings/Properties.scala: -------------------------------------------------------------------------------- 1 | package chrome.audio.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object Properties { 6 | 7 | def apply(isMuted: Boolean, 8 | volume: js.UndefOr[Double] = js.undefined, 9 | gain: js.UndefOr[Double] = js.undefined): Properties = { 10 | js.Dynamic 11 | .literal( 12 | isMuted = isMuted, 13 | volume = volume, 14 | gain = gain 15 | ) 16 | .asInstanceOf[Properties] 17 | } 18 | 19 | } 20 | 21 | @js.native 22 | trait Properties extends js.Object { 23 | 24 | def isMuted: Boolean = js.native 25 | 26 | def volume: js.UndefOr[Double] = js.native 27 | 28 | def gain: js.UndefOr[Double] = js.native 29 | 30 | } 31 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/commands/Commands.scala: -------------------------------------------------------------------------------- 1 | package chrome.commands 2 | 3 | import chrome.commands.bindings.Command 4 | import chrome.events.{EventSource, EventSource1Impl} 5 | import chrome.utils.ErrorHandling._ 6 | 7 | import scala.concurrent.{Future, Promise} 8 | import scala.scalajs.js 9 | 10 | object Commands { 11 | 12 | val onCommand: EventSource[String] = new EventSource1Impl( 13 | bindings.Commands.onCommand) 14 | 15 | def getAll: Future[List[Command]] = { 16 | val promise = Promise[List[Command]] 17 | bindings.Commands.getAll( 18 | js.Any.fromFunction1((commands: js.Array[Command]) => { 19 | promise.complete(lastErrorOrValue(commands.toList)) 20 | })) 21 | promise.future 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/bindings/DisplayInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait DisplayInfo extends js.Object { 7 | 8 | def id: Display.ID = js.native 9 | 10 | def name: String = js.native 11 | 12 | def mirroringSourceId: Display.ID = js.native 13 | 14 | def isPrimary: Boolean = js.native 15 | 16 | def isInternal: Boolean = js.native 17 | 18 | def isEnabled: Boolean = js.native 19 | 20 | def dpiX: Double = js.native 21 | 22 | def dpiY: Double = js.native 23 | 24 | def rotation: Int = js.native 25 | 26 | def bounds: Bounds = js.native 27 | 28 | def overscan: Insets = js.native 29 | 30 | def workArea: Bounds = js.native 31 | 32 | } 33 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/OnInstalledDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object OnInstalledDetails { 6 | 7 | type InstallReason = String 8 | 9 | object InstallReasons { 10 | 11 | val INSTALL: InstallReason = "install" 12 | val UPDATE: InstallReason = "update" 13 | val CHROME_UPDATE: InstallReason = "chrome_update" 14 | val SHARED_MODULE_UPDATE: InstallReason = "shared_module_update" 15 | 16 | } 17 | 18 | } 19 | 20 | @js.native 21 | trait OnInstalledDetails extends js.Object { 22 | 23 | val reason: OnInstalledDetails.InstallReason = js.native 24 | val previousVersion: js.UndefOr[String] = js.native 25 | val id: js.UndefOr[String] = js.native 26 | 27 | } 28 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/omnibox/bindings/Omnibox.scala: -------------------------------------------------------------------------------- 1 | package chrome.omnibox.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.omnibox") 10 | object Omnibox extends js.Object { 11 | 12 | val onInputStarted: Event[js.Function0[_]] = js.native 13 | val onInputChanged: Event[ 14 | js.Function2[String, js.Function1[js.Array[SuggestResult], _], _]] = 15 | js.native 16 | val onInputEntered: Event[js.Function2[String, OnInputEnteredDisposition, _]] = 17 | js.native 18 | val onInputCancelled: Event[js.Function0[_]] = js.native 19 | 20 | def setDefaultSuggestion(suggestion: DefaultSuggestion): Unit = js.native 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/wallpaper/Wallpaper.scala: -------------------------------------------------------------------------------- 1 | package chrome.wallpaper 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.utils.ErrorHandling._ 6 | import chrome.wallpaper.bindings.WallpaperDetails 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object Wallpaper extends ChromeAPI { 12 | 13 | val requiredPermissions: Set[API] = Set(API.Wallpaper) 14 | 15 | def setWallpaper(details: WallpaperDetails): Future[Option[Any]] = { 16 | val promise = Promise[Option[Any]]() 17 | bindings.Wallpaper 18 | .setWallpaper(details, (thumbnail: js.UndefOr[js.Any]) => { 19 | promise.complete(lastErrorOrValue(thumbnail.toOption)) 20 | }) 21 | promise.future 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebAuthenticationChallengeDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebAuthenticationChallengeDetails extends WebResponseHeadersDetails { 7 | /** 8 | * The authentication scheme, e.g. Basic or Digest. 9 | */ 10 | val scheme: String = js.native 11 | 12 | /** 13 | * The authentication realm provided by the server, if there is one. 14 | */ 15 | val realm: js.UndefOr[String] = js.native 16 | 17 | /** 18 | * The server requesting authentication. 19 | */ 20 | val challenger: WebAuthChallenger = js.native 21 | 22 | /** 23 | * True for Proxy-Authenticate, false for WWW-Authenticate. 24 | */ 25 | val isProxy: Boolean = js.native 26 | } 27 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/DownloadDelta.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scalajs.js 4 | 5 | trait DownloadDelta { 6 | def id: Int 7 | def url: js.UndefOr[Delta[String]] 8 | def finalUrl: js.UndefOr[Delta[String]] 9 | def filename: js.UndefOr[Delta[String]] 10 | def danger: js.UndefOr[Delta[String]] 11 | def mime: js.UndefOr[Delta[String]] 12 | def startTime: js.UndefOr[Delta[String]] 13 | def endTime: js.UndefOr[Delta[String]] 14 | def state: js.UndefOr[Delta[String]] 15 | def canResume: js.UndefOr[Delta[Boolean]] 16 | def paused: js.UndefOr[Delta[Boolean]] 17 | def error: js.UndefOr[Delta[String]] 18 | def totalBytes: js.UndefOr[Delta[Double]] 19 | def fileSize: js.UndefOr[Delta[Double]] 20 | def exists: js.UndefOr[Delta[Boolean]] 21 | } 22 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/Bounds.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait Bounds extends js.Object { 7 | 8 | var left: Int = js.native 9 | var top: Int = js.native 10 | var width: Int = js.native 11 | var height: Int = js.native 12 | 13 | var minWidth: js.UndefOr[Int] = js.native 14 | var minHeight: js.UndefOr[Int] = js.native 15 | var maxWidth: js.UndefOr[Int] = js.native 16 | var maxHeight: js.UndefOr[Int] = js.native 17 | 18 | def setPosition(top: Int, left: Int): Unit = js.native 19 | 20 | def setSize(width: Int, height: Int): Unit = js.native 21 | 22 | def setMinimumSize(minWidth: Int, minHeight: Int): Unit = js.native 23 | 24 | def setMaximumSize(maxWidth: Int, maxHeight: Int): Unit = js.native 25 | 26 | } 27 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/audio/bindings/Audio.scala: -------------------------------------------------------------------------------- 1 | package chrome.audio.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.audio") 10 | object Audio extends js.Object { 11 | 12 | type DeviceID = String 13 | val onDeviceChanged: Event[js.Function0[_]] = js.native 14 | 15 | def getInfo( 16 | callback: js.Function2[js.Array[OutputInfo], js.Array[InputInfo], _]) 17 | : Unit = js.native 18 | 19 | def setActiveDevice(ids: js.Array[DeviceID], 20 | callback: js.Function0[_]): Unit = js.native 21 | 22 | def setProperties(id: DeviceID, 23 | properties: Properties, 24 | callback: js.Function0[_]): Unit = js.native 25 | 26 | } 27 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/alarms/bindings/AlarmInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.alarms.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object AlarmInfo { 6 | 7 | def apply(when: js.UndefOr[Double] = js.undefined, 8 | delayInMinutes: js.UndefOr[Double] = js.undefined, 9 | periodInMinutes: js.UndefOr[Double] = js.undefined): AlarmInfo = { 10 | js.Dynamic 11 | .literal( 12 | when = when, 13 | delayInMinutes = delayInMinutes, 14 | periodInMinutes = periodInMinutes 15 | ) 16 | .asInstanceOf[AlarmInfo] 17 | } 18 | 19 | } 20 | 21 | @js.native 22 | trait AlarmInfo extends js.Object { 23 | 24 | def when: js.UndefOr[Double] = js.native 25 | def delayInMinutes: js.UndefOr[Double] = js.native 26 | def periodInMinutes: js.UndefOr[Double] = js.native 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tts/bindings/TTS.scala: -------------------------------------------------------------------------------- 1 | package chrome.tts.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | import scala.scalajs.js.{UndefOr, native, undefined} 6 | 7 | @js.native 8 | @JSGlobal("chrome.tts") 9 | object TTS extends js.Object { 10 | 11 | def speak(utterance: String, 12 | options: UndefOr[SpeakOptions] = undefined, 13 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 14 | 15 | def stop(): Unit = native 16 | 17 | def pause(): Unit = native 18 | 19 | def resume(): Unit = native 20 | 21 | def isSpeaking( 22 | callback: UndefOr[js.Function1[Boolean, _]] = undefined): Unit = native 23 | 24 | def getVoices(callback: UndefOr[js.Function1[js.Array[TTSVoice], _]] = 25 | undefined): Unit = native 26 | 27 | } 28 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tts/bindings/TTSEvent.scala: -------------------------------------------------------------------------------- 1 | package chrome.tts.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object TTSEvent { 6 | 7 | type Type = String 8 | 9 | object Types { 10 | 11 | val START: Type = "start" 12 | val END: Type = "end" 13 | val WORD: Type = "word" 14 | val SENTENCE: Type = "sentence" 15 | val MARKER: Type = "marker" 16 | val INTERRUPTED: Type = "interrupted" 17 | val CANCELLED: Type = "cancelled" 18 | val ERROR: Type = "error" 19 | val PAUSE: Type = "pause" 20 | val RESUME: Type = "resume" 21 | 22 | } 23 | 24 | } 25 | 26 | @js.native 27 | trait TTSEvent extends js.Object { 28 | 29 | val `type`: TTSEvent.Type = js.native 30 | 31 | def charIndex: js.UndefOr[Double] = js.native 32 | 33 | def errorMessage: js.UndefOr[String] = js.native 34 | 35 | } 36 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/HttpHeader.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | sealed trait HttpHeader extends js.Object 7 | @js.native 8 | trait Header extends HttpHeader { 9 | def name: String 10 | def value: String 11 | } 12 | object Header { 13 | def apply(name: String, value: String): Header = { 14 | js.Dynamic.literal( 15 | name = name, 16 | value = value 17 | ).asInstanceOf[Header] 18 | } 19 | } 20 | @js.native 21 | trait BinaryHeader extends HttpHeader { 22 | def name: String 23 | def binaryValue: String 24 | } 25 | object BinaryHeader { 26 | def apply(name: String, binaryValue: String): Header = { 27 | js.Dynamic.literal( 28 | name = name, 29 | binaryValue = binaryValue 30 | ).asInstanceOf[Header] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/SocketProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait SocketProperties extends js.Object { 7 | 8 | def persistent: js.UndefOr[Boolean] = js.native 9 | 10 | def name: js.UndefOr[String] = js.native 11 | 12 | def bufferSize: js.UndefOr[Int] = js.native 13 | 14 | } 15 | 16 | object SocketProperties { 17 | 18 | def apply(persistent: js.UndefOr[Boolean] = js.undefined, 19 | name: js.UndefOr[String] = js.undefined, 20 | bufferSize: js.UndefOr[Int] = js.undefined): SocketProperties = { 21 | js.Dynamic 22 | .literal( 23 | persistent = persistent, 24 | name = name, 25 | bufferSize = bufferSize 26 | ) 27 | .asInstanceOf[SocketProperties] 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/TLSVersionBounds.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait TLSVersionBounds extends js.Object { 7 | 8 | def min: js.UndefOr[TLSVersionBounds.Version] = js.native 9 | 10 | def max: js.UndefOr[TLSVersionBounds.Version] = js.native 11 | 12 | } 13 | 14 | object TLSVersionBounds { 15 | 16 | type Version = String 17 | 18 | val SSL3: Version = "ssl3" 19 | val TLS1: Version = "tls1" 20 | val TLS1_1: Version = "tls1.1" 21 | val TLS1_2: Version = "tls1.2" 22 | 23 | def apply(min: js.UndefOr[Version] = js.undefined, 24 | max: js.UndefOr[Version] = js.undefined): TLSVersionBounds = { 25 | js.Dynamic 26 | .literal( 27 | min = min, 28 | max = max 29 | ) 30 | .asInstanceOf[TLSVersionBounds] 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/BadgeBackgroundColorDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.| 5 | import scala.scalajs.js.|.Evidence 6 | 7 | @js.native 8 | trait BadgeBackgroundColorDetails extends TabIdDetails { 9 | val color: String | js.Array[Int] = js.native 10 | } 11 | 12 | object BadgeBackgroundColorDetails { 13 | // implicitly summon evidence that our union type subclasses js.Any 14 | implicit val colorEvidence: Evidence[String | js.Array[Int], js.Any] = implicitly 15 | 16 | def apply(color: String | js.Array[Int], tabId: js.UndefOr[Int] = js.undefined): BadgeBackgroundColorDetails = { 17 | js.Dynamic 18 | .literal( 19 | color = color.merge[js.Any], 20 | tabId = tabId 21 | ) 22 | .asInstanceOf[BadgeBackgroundColorDetails] 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/FrameDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.native 5 | 6 | @js.native 7 | trait FrameDetails extends js.Object { 8 | /** 9 | * True if the last navigation in this frame was interrupted by an error, i.e. the onErrorOccurred event fired. 10 | */ 11 | val errorOccurred: Boolean = native 12 | /** 13 | * The URL currently associated with this frame, 14 | * if the frame identified by the frameId existed at one point in the given tab. 15 | * The fact that an URL is associated with a given frameId does not imply that the corresponding frame still exists. 16 | */ 17 | val url: String = native 18 | /** 19 | * ID of frame that wraps the frame. Set to -1 if no parent frame exists. 20 | */ 21 | val frameParentId: Int = native 22 | } 23 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/omnibox/Omnibox.scala: -------------------------------------------------------------------------------- 1 | package chrome.omnibox 2 | 3 | import chrome.events.EventSource 4 | import chrome.events.EventSourceImplicits._ 5 | import chrome.omnibox.bindings.OnInputEnteredDisposition 6 | 7 | import scala.scalajs.js 8 | import bindings._ 9 | 10 | object Omnibox { 11 | 12 | val onInputStarted: EventSource[Unit] = bindings.Omnibox.onInputStarted 13 | val onInputChanged: EventSource[(String, 14 | js.Function1[js.Array[SuggestResult], _])] = 15 | bindings.Omnibox.onInputChanged 16 | val onInputEntered: EventSource[(String, OnInputEnteredDisposition)] = 17 | bindings.Omnibox.onInputEntered 18 | val onInputCancelled: EventSource[Unit] = bindings.Omnibox.onInputCancelled 19 | 20 | def setDefaultSuggestion(suggestion: DefaultSuggestion): Unit = 21 | bindings.Omnibox.setDefaultSuggestion(suggestion) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/alarms/bindings/Alarms.scala: -------------------------------------------------------------------------------- 1 | package chrome.alarms.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.alarms") 10 | object Alarms extends js.Object { 11 | 12 | val onAlarm: Event[js.Function1[Alarm, _]] = js.native 13 | 14 | def create(name: String = "", alarmInfo: AlarmInfo): Unit = js.native 15 | 16 | def get(name: String = "", 17 | callback: js.Function1[js.UndefOr[Alarm], _]): Unit = js.native 18 | 19 | def getAll(callback: js.Function1[js.Array[Alarm], _]): Unit = js.native 20 | 21 | def clear( 22 | name: String = "", 23 | callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit = 24 | js.native 25 | 26 | def clearAll( 27 | callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit = 28 | js.native 29 | 30 | } 31 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/idle/Idle.scala: -------------------------------------------------------------------------------- 1 | package chrome.idle 2 | 3 | import chrome.ChromeAPI 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import bindings._ 7 | import chrome.permissions.Permission.API 8 | import chrome.utils.ErrorHandling._ 9 | 10 | import scala.concurrent.{Promise, Future} 11 | 12 | object Idle extends ChromeAPI { 13 | 14 | val requiredPermissions: Set[API] = Set(API.Idle) 15 | 16 | val onStateChanged: EventSource[State] = bindings.Idle.onStateChanged 17 | 18 | def queryState(detectionIntervalInSeconds: Int): Future[State] = { 19 | val promise = Promise[State]() 20 | bindings.Idle.queryState(detectionIntervalInSeconds, (state: State) => { 21 | promise.complete(lastErrorOrValue(state)) 22 | }) 23 | promise.future 24 | } 25 | 26 | def setDetectionInterval(intervalInSeconds: Int): Unit = 27 | bindings.Idle.setDetectionInterval(intervalInSeconds) 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnCompletedDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnCompletedDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation occurs. 10 | */ 11 | val tabId: Int = native 12 | val url: String = native 13 | /** 14 | * The ID of the process that runs the renderer for this frame. 15 | * 16 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 17 | */ 18 | val processId: js.UndefOr[Int] = native 19 | /** 20 | * 0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. 21 | * Frame IDs are unique within a tab. 22 | */ 23 | val frameId: Int = native 24 | /** 25 | * The time when the document finished loading, in milliseconds since the epoch. 26 | */ 27 | val timeStamp: Double = native 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/AllFramesDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.native 5 | 6 | @js.native 7 | trait AllFramesDetails extends js.Object { 8 | /** 9 | * True if the last navigation in this frame was interrupted by an error, i.e. the onErrorOccurred event fired. 10 | */ 11 | val errorOccurred: Boolean = native 12 | /** 13 | * The ID of the process that runs the renderer for this frame. 14 | */ 15 | val processId: js.UndefOr[Int] = native 16 | /** 17 | * The ID of the frame. 0 indicates that this is the main frame; a positive value indicates the ID of a subframe. 18 | */ 19 | val frameId: Int = native 20 | /** 21 | * ID of frame that wraps the frame. Set to -1 if no parent frame exists. 22 | */ 23 | val frameParentId: Int = native 24 | /** 25 | * The URL currently associated with this frame. 26 | */ 27 | val url: String = native 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/network/Network.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.network 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.utils.ErrorHandling._ 6 | 7 | import scala.concurrent.{Future, Promise} 8 | import scala.scalajs.js 9 | 10 | object Network extends ChromeAPI { 11 | 12 | val requiredPermissions: Set[API] = Set(API.System.Network) 13 | 14 | def getNetworkInterfaces: Future[List[Interface]] = { 15 | val promise = Promise[List[Interface]]() 16 | bindings.Network.getNetworkInterfaces( 17 | (interfaces: js.Array[bindings.NetworkInterface]) => { 18 | promise.complete(lastErrorOrValue { 19 | (for ((name, interfaces) <- interfaces.groupBy(_.name)) yield { 20 | val configs = interfaces.map(x => 21 | new Interface.Config(x.address, x.prefixLength)) 22 | new Interface(name, configs.toList) 23 | }).toList 24 | }) 25 | }) 26 | promise.future 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnDOMContentLoadedDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnDOMContentLoadedDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation occurs. 10 | */ 11 | val tabId: Int = native 12 | val url: String = native 13 | /** 14 | * The ID of the process that runs the renderer for this frame. 15 | * 16 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 17 | */ 18 | val processId: js.UndefOr[Int] = native 19 | /** 20 | * 0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. 21 | * Frame IDs are unique within a tab. 22 | */ 23 | val frameId: Int = native 24 | /** 25 | * The time when the page's DOM was fully constructed, in milliseconds since the epoch. 26 | */ 27 | val timeStamp: Double = native 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/ZoomSettings.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ZoomSettings extends js.Object { 7 | 8 | def mode: js.UndefOr[ZoomSettings.Mode] = js.native 9 | 10 | def scope: js.UndefOr[ZoomSettings.Scope] = js.native 11 | 12 | } 13 | 14 | object ZoomSettings { 15 | 16 | type Mode = String 17 | type Scope = String 18 | 19 | def apply( 20 | mode: js.UndefOr[ZoomSettings.Mode] = js.undefined, 21 | scope: js.UndefOr[ZoomSettings.Scope] = js.undefined): ZoomSettings = { 22 | js.Dynamic 23 | .literal( 24 | mode = mode, 25 | scope = scope 26 | ) 27 | .asInstanceOf[ZoomSettings] 28 | } 29 | 30 | object Modes { 31 | val AUTOMATIC: Mode = "automatic" 32 | val MANUAL: Mode = "manual" 33 | val DISABLED: Mode = "disabled" 34 | } 35 | 36 | object Scopes { 37 | val PER_ORIGIN: Mode = "per-origin" 38 | val PER_TAB: Mode = "per-tab" 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/GetFrameOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import chrome.tabs.bindings.Tab 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait GetFrameOptions extends js.Object { 9 | /** 10 | * The ID of the tab in which the frame is. 11 | */ 12 | val tabId: Tab.Id 13 | /** 14 | * Deprecated since Chrome 49. Frames are now uniquely identified by their tab ID and frame ID; 15 | * the process ID is no longer needed and therefore ignored. 16 | * The ID of the process that runs the renderer for this tab. 17 | */ 18 | val processId: js.UndefOr[Int] 19 | /** 20 | * The ID of the frame in the given tab. 21 | */ 22 | val frameId: Int 23 | } 24 | 25 | object GetFrameOptions { 26 | def apply(tabId: Tab.Id, processId: js.UndefOr[Int] = js.undefined, frameId: Int): GetFrameOptions = 27 | js.Dynamic.literal( 28 | tabId = tabId, processId = processId, frameId = frameId 29 | ).asInstanceOf[GetFrameOptions] 30 | } -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/i18n/I18N.scala: -------------------------------------------------------------------------------- 1 | package chrome.i18n 2 | 3 | import scala.concurrent.{Future, Promise} 4 | import scala.scalajs.js 5 | import chrome.utils.ErrorHandling._ 6 | 7 | import js.JSConverters._ 8 | import scala.scalajs.js.| 9 | 10 | object I18N { 11 | 12 | def getAcceptLanguages: Future[js.Array[String]] = { 13 | val promise = Promise[js.Array[String]]() 14 | bindings.I18N.getAcceptLanguages((languages: js.Array[String]) => { 15 | promise.complete(lastErrorOrValue(languages)) 16 | }) 17 | promise.future 18 | } 19 | 20 | def getMessage(messageName: String, substitutions: String*): js.UndefOr[String] = { 21 | if(substitutions.isEmpty) { 22 | bindings.I18N.getMessage(messageName) 23 | } else { 24 | val jsArraySubstitutions = substitutions.toJSArray.asInstanceOf[String | js.Array[String]] 25 | bindings.I18N.getMessage(messageName, Some(jsArraySubstitutions).orUndefined) 26 | } 27 | } 28 | 29 | def getUILanguage: String = bindings.I18N.getUILanguage() 30 | 31 | } 32 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnErrorOccurredDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnErrorOccurredDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation occurs. 10 | */ 11 | val tabId: Int = native 12 | val url: String = native 13 | /** 14 | * The ID of the process that runs the renderer for this frame. 15 | * 16 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 17 | */ 18 | val processId: js.UndefOr[Int] = native 19 | /** 20 | * 0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. 21 | * Frame IDs are unique within a tab. 22 | */ 23 | val frameId: Int = native 24 | /** 25 | * The error description. 26 | */ 27 | val error: String = native 28 | /** 29 | * The time when the error occurred, in milliseconds since the epoch. 30 | */ 31 | val timeStamp: Double = native 32 | } 33 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/PlatformInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSName 5 | 6 | object PlatformInfo { 7 | 8 | type OperatingSystem = String 9 | type Architecture = String 10 | 11 | object OperatingSystems { 12 | 13 | val MAC: OperatingSystem = "mac" 14 | val WIN: OperatingSystem = "win" 15 | val ANDROID: OperatingSystem = "android" 16 | val CROS: OperatingSystem = "cros" 17 | val LINUX: OperatingSystem = "linux" 18 | val OPENBSD: OperatingSystem = "openbsd" 19 | 20 | } 21 | 22 | object Architectures { 23 | 24 | val ARM: OperatingSystem = "arm" 25 | val X86_32: OperatingSystem = "x86-32" 26 | val X86_64: OperatingSystem = "x86-64" 27 | 28 | } 29 | 30 | } 31 | 32 | @js.native 33 | trait PlatformInfo extends js.Object { 34 | 35 | def os: PlatformInfo.OperatingSystem = js.native 36 | 37 | def arch: PlatformInfo.Architecture = js.native 38 | 39 | @JSName("nacl_arch") 40 | def naclArch: PlatformInfo.Architecture = js.native 41 | 42 | } 43 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/UpdateProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object UpdateProperties { 6 | 7 | def apply( 8 | url: js.UndefOr[String] = js.undefined, 9 | active: js.UndefOr[Boolean] = js.undefined, 10 | highlighted: js.UndefOr[Boolean] = js.undefined, 11 | pinned: js.UndefOr[Boolean] = js.undefined, 12 | openerTabId: js.UndefOr[Tab.Id] = js.undefined): UpdateProperties = { 13 | js.Dynamic 14 | .literal( 15 | url = url, 16 | active = active, 17 | highlighted = highlighted, 18 | pinned = pinned, 19 | openerTabId = openerTabId 20 | ) 21 | .asInstanceOf[UpdateProperties] 22 | } 23 | 24 | } 25 | 26 | @js.native 27 | trait UpdateProperties extends js.Object { 28 | 29 | def url: js.UndefOr[String] = js.native 30 | 31 | def active: js.UndefOr[Boolean] = js.native 32 | 33 | def highlighted: js.UndefOr[Boolean] = js.native 34 | 35 | def pinned: js.UndefOr[Boolean] = js.native 36 | 37 | def openerTabId: js.UndefOr[Tab.Id] = js.native 38 | 39 | } 40 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/Window.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.{UndefOr, native, undefined} 8 | 9 | @js.native 10 | @JSGlobal("chrome.app.window") 11 | object Window extends js.Object { 12 | 13 | val onBoundsChanged: Event[js.Function0[_]] = native 14 | val onClosed: Event[js.Function0[_]] = native 15 | val onFullscreened: Event[js.Function0[_]] = native 16 | val onMaximized: Event[js.Function0[_]] = native 17 | val onMinimized: Event[js.Function0[_]] = native 18 | val onRestored: Event[js.Function0[_]] = native 19 | 20 | def current(): AppWindow = native 21 | 22 | def create(url: String, 23 | options: UndefOr[CreateWindowOptions] = undefined, 24 | callback: UndefOr[js.Function1[AppWindow, _]] = undefined): Unit = 25 | native 26 | 27 | def getAll(): js.Array[AppWindow] = native 28 | 29 | def get(id: AppWindow.Id): AppWindow = native 30 | 31 | def canSetVisibleOnAllWorkspaces(): Boolean = native 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/DownloadItem.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scalajs.js 4 | 5 | @js.native 6 | trait DownloadItem extends js.Object { 7 | def id: Int = js.native 8 | def url: String = js.native 9 | def finalUrl: String = js.native 10 | def referrer: String = js.native 11 | def filename: String = js.native 12 | def incognito: Boolean = js.native 13 | def danger: DangerType = js.native 14 | def mime: String = js.native 15 | def startTime: String = js.native 16 | def endTime: js.UndefOr[String] = js.native 17 | def estimatedEndTime: js.UndefOr[String] = js.native 18 | def state: State = js.native 19 | def paused: Boolean = js.native 20 | def canResume: Boolean = js.native 21 | def error: js.UndefOr[InterruptReason] = js.native 22 | def bytesReceived: Double = js.native 23 | def totalBytes: Double = js.native 24 | def fileSize: Double = js.native 25 | def exists: Boolean = js.native 26 | def byExtensionId: js.UndefOr[String] = js.native 27 | def byExtensionName: js.UndefOr[String] = js.native 28 | } 29 | object DownloadItem { 30 | type Id = Int 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015 Kevin Walter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnCreatedNavigationTargetDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnCreatedNavigationTargetDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation is triggered. 10 | */ 11 | val sourceTabId: Int = native 12 | /** 13 | * The ID of the process that runs the renderer for the source frame. 14 | * 15 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 16 | */ 17 | val sourceProcessId: js.UndefOr[Int] = native 18 | /** 19 | * The ID of the frame with sourceTabId in which the navigation is triggered. 0 indicates the main frame. 20 | */ 21 | val sourceFrameId: Int = native 22 | /** 23 | * The URL to be opened in the new window. 24 | */ 25 | val url: String = native 26 | /** 27 | * The ID of the tab in which the url is opened. 28 | */ 29 | val tabId: Int = native 30 | /** 31 | * The time when the browser was about to create a new view, in milliseconds since the epoch. 32 | */ 33 | val timeStamp: Double = native 34 | } 35 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnCommittedDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnCommittedDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation occurs. 10 | */ 11 | val tabId: Int = native 12 | val url: String = native 13 | /** 14 | * The ID of the process that runs the renderer for this frame. 15 | * 16 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 17 | */ 18 | val processId: js.UndefOr[Int] = native 19 | /** 20 | * 0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. 21 | * Frame IDs are unique within a tab. 22 | */ 23 | val frameId: Int = native 24 | /** 25 | * Cause of the navigation. 26 | */ 27 | val transitionType: String 28 | /** 29 | * A list of transition qualifiers. 30 | */ 31 | val transitionQualifiers: js.Array[String] 32 | /** 33 | * The time when the navigation was committed, in milliseconds since the epoch. 34 | */ 35 | val timeStamp: Double = native 36 | 37 | } 38 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/WebRequestBody.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait WebRequestBody extends js.Object { 7 | /** 8 | * Optional: 9 | * Errors when obtaining request body data. 10 | */ 11 | val error: js.UndefOr[String] = js.native 12 | 13 | /** 14 | * Optional: 15 | * If the request method is POST and the body is a sequence of key-value pairs encoded in UTF8, encoded as either 16 | * multipart/form-data, or application/x-www-form-urlencoded, this dictionary is present and for each key contains 17 | * the list of all values for that key. If the data is of another media type, or if it is malformed, the dictionary 18 | * is not present. An example value of this dictionary is {'key': ['value1', 'value2']}. 19 | */ 20 | val formData: js.UndefOr[js.Dictionary[js.Array[String]]] = js.native 21 | 22 | /** 23 | * Optional: 24 | * If the request method is PUT or POST, and the body is not already parsed in formData, then the unparsed request 25 | * body elements are contained in this array. 26 | */ 27 | val raw: js.UndefOr[js.Array[UploadData]] = js.native 28 | } 29 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/desktopCapture/DesktopCapture.scala: -------------------------------------------------------------------------------- 1 | package chrome.desktopCapture 2 | 3 | import bindings._ 4 | import chrome.tabs.bindings.Tab 5 | import chrome.utils.ErrorHandling._ 6 | import scala.concurrent.{Promise, Future} 7 | import scala.scalajs.js 8 | import scala.scalajs.js.JSConverters._ 9 | 10 | class DesktopMediaRequest(id: DesktopMediaRequestId, 11 | val result: Future[StreamId]) { 12 | def cancel(): Unit = DesktopCapture.cancelChooseDesktopMedia(id) 13 | } 14 | 15 | object DesktopCapture { 16 | 17 | def chooseDesktopMedia(sources: List[DesktopCaptureSourceType], 18 | targetTab: js.UndefOr[Tab]): DesktopMediaRequest = { 19 | val promise = Promise[StreamId]() 20 | val id = bindings.DesktopCapture.chooseDesktopMedia( 21 | sources.toJSArray, 22 | targetTab, 23 | (streamId: StreamId) => { 24 | promise.complete(lastErrorOrValue(streamId)) 25 | }) 26 | new DesktopMediaRequest(id, promise.future) 27 | } 28 | 29 | def cancelChooseDesktopMedia( 30 | desktopMediaRequestId: DesktopMediaRequestId): Unit = 31 | bindings.DesktopCapture.cancelChooseDesktopMedia(desktopMediaRequestId) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/DownloadOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait DownloadOptions extends js.Object { 7 | def url: String 8 | def filename: js.UndefOr[String] 9 | def conflictAction: js.UndefOr[FilenameConflictAction] 10 | def saveAs: js.UndefOr[Boolean] 11 | def method: js.UndefOr[HttpMethod] 12 | def headers: js.UndefOr[js.Array[js.Object]] 13 | def body: js.UndefOr[String] 14 | } 15 | 16 | object DownloadOptions { 17 | 18 | def apply( 19 | url: String, 20 | filename: js.UndefOr[String] = js.undefined, 21 | conflictAction: js.UndefOr[FilenameConflictAction] = js.undefined, 22 | saveAs: js.UndefOr[Boolean] = js.undefined, 23 | method: js.UndefOr[HttpMethod] = js.undefined, 24 | headers: js.UndefOr[js.Array[HttpHeader]] = js.undefined, 25 | body: js.UndefOr[String] = js.undefined 26 | ): DownloadOptions = { 27 | js.Dynamic.literal( 28 | url = url, 29 | filename = filename, 30 | conflictAction = conflictAction.asInstanceOf[String], 31 | saveAs = saveAs, 32 | method = method.asInstanceOf[String], 33 | headers = headers, 34 | body = body 35 | ).asInstanceOf[DownloadOptions] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/Tab.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.sessions.bindings.Session 4 | import chrome.windows.bindings.Window 5 | 6 | import scala.scalajs.js 7 | 8 | @js.native 9 | trait Tab extends js.Object { 10 | 11 | def id: js.UndefOr[Tab.Id] = js.native 12 | 13 | def index: Int = js.native 14 | 15 | def windowId: Window.Id = js.native 16 | 17 | def openerTabId: js.UndefOr[Tab.Id] = js.native 18 | 19 | def highlighted: Boolean = js.native 20 | 21 | def active: Boolean = js.native 22 | 23 | def pinned: Boolean = js.native 24 | 25 | def url: js.UndefOr[String] = js.native 26 | 27 | def title: js.UndefOr[String] = js.native 28 | 29 | def favIconUrl: js.UndefOr[String] = js.native 30 | 31 | def status: js.UndefOr[Tab.Status] = js.native 32 | 33 | def incognito: Boolean = js.native 34 | 35 | def width: js.UndefOr[Int] = js.native 36 | 37 | def height: js.UndefOr[Int] = js.native 38 | 39 | def sessionId: js.UndefOr[Session.Id] = js.native 40 | 41 | } 42 | 43 | object Tab { 44 | 45 | type Status = String 46 | type Id = Int 47 | 48 | object StatusValues { 49 | 50 | val LOADING: Status = "loading" 51 | val COMPLETE: Status = "complete" 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/processes/bindings/Processes.scala: -------------------------------------------------------------------------------- 1 | package chrome.processes.bindings 2 | 3 | import chrome.events.bindings.Event 4 | import chrome.tabs.bindings.Tab 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js.annotation.JSGlobal 8 | 9 | @js.native 10 | @JSGlobal("chrome.processes") 11 | object Processes extends js.Object { 12 | 13 | val onUpdated: Event[js.Function1[Map[Process.Id, Process], _]] = js.native 14 | val onUpdatedWithMemory: Event[js.Function1[Map[Process.Id, Process], _]] = 15 | js.native 16 | val onCreated: Event[js.Function1[Process, _]] = js.native 17 | val onUnresponsive: Event[js.Function1[Process, _]] = js.native 18 | val onExited: Event[ 19 | js.Function3[Process.Id, Process.ExitType, js.UndefOr[Int], _]] = 20 | js.native 21 | 22 | def terminate( 23 | processId: Process.Id, 24 | callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit = 25 | js.native 26 | def getProcessIdForTab(tabId: Tab.Id, 27 | callback: js.Function1[Process.Id, _]): Unit = 28 | js.native 29 | def getProcessInfo( 30 | processIds: js.Array[Process.Id], 31 | includeMemory: Boolean, 32 | callback: js.Function1[Map[Process.Id, Process], _]): Unit = js.native 33 | 34 | } 35 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/Display.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display 2 | 3 | import chrome.ChromeAPI 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.permissions.Permission.API 7 | import chrome.system.display.bindings._ 8 | import chrome.utils.ErrorHandling._ 9 | 10 | import scala.concurrent.{Future, Promise} 11 | import scala.scalajs.js 12 | 13 | object Display extends ChromeAPI { 14 | 15 | val requiredPermissions: Set[API] = Set(API.System.Display) 16 | 17 | val onDisplayChanged: EventSource[Unit] = bindings.Display.onDisplayChanged 18 | 19 | def getInfo: Future[List[DisplayInfo]] = { 20 | val promise = Promise[List[DisplayInfo]]() 21 | bindings.Display.getInfo((info: js.Array[DisplayInfo]) => { 22 | promise.complete(lastErrorOrValue(info.toList)) 23 | }) 24 | promise.future 25 | } 26 | 27 | def setDisplayProperties( 28 | id: bindings.Display.ID, 29 | info: DisplayProperties): Future[bindings.Display.ID] = { 30 | val promise = Promise[bindings.Display.ID]() 31 | bindings.Display 32 | .setDisplayProperties(id, info, js.Any.fromFunction0(() => { 33 | promise.complete(lastErrorOrValue(id)) 34 | })) 35 | promise.future 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/RequestFilter.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object RequestFilter { 6 | def apply(tabId: js.UndefOr[Int] = js.undefined, 7 | types: js.UndefOr[js.Array[String]] = js.undefined, 8 | urls: js.UndefOr[js.Array[String]] = js.undefined, 9 | windowId: js.UndefOr[Int] = js.undefined): RequestFilter = { 10 | js.Dynamic.literal( 11 | tabId = tabId, 12 | types = types, 13 | urls = urls, 14 | windowId = windowId 15 | ).asInstanceOf[RequestFilter] 16 | } 17 | } 18 | 19 | @js.native 20 | trait RequestFilter extends js.Object { 21 | 22 | val tabId: js.UndefOr[Int] = js.native 23 | 24 | /** 25 | * A list of request types. Requests that cannot match any of the types will be filtered out. 26 | * Each element one of: "main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", 27 | * or "other" 28 | */ 29 | val types: js.UndefOr[js.Array[String]] = js.native 30 | 31 | /** A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out. */ 32 | val urls: js.UndefOr[js.Array[String]] = js.native 33 | 34 | val windowId: js.UndefOr[Int] = js.native 35 | } 36 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/TabCreateProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | object TabCreateProperties { 8 | 9 | def apply( 10 | windowId: js.UndefOr[Window.Id] = js.undefined, 11 | index: js.UndefOr[Int] = js.undefined, 12 | url: js.UndefOr[String] = js.undefined, 13 | active: js.UndefOr[Boolean] = js.undefined, 14 | pinned: js.UndefOr[Boolean] = js.undefined, 15 | openerTabId: js.UndefOr[Tab.Id] = js.undefined): TabCreateProperties = { 16 | js.Dynamic 17 | .literal( 18 | windowId = windowId, 19 | index = index, 20 | url = url, 21 | active = active, 22 | pinned = pinned, 23 | openerTabId = openerTabId 24 | ) 25 | .asInstanceOf[TabCreateProperties] 26 | } 27 | 28 | } 29 | 30 | @js.native 31 | trait TabCreateProperties extends js.Object { 32 | 33 | def windowId: js.UndefOr[Window.Id] = js.native 34 | 35 | def index: js.UndefOr[Int] = js.native 36 | 37 | def url: js.UndefOr[String] = js.native 38 | 39 | def active: js.UndefOr[Boolean] = js.native 40 | 41 | def pinned: js.UndefOr[Boolean] = js.native 42 | 43 | def openerTabId: js.UndefOr[Tab.Id] = js.native 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/wallpaper/bindings/Wallpaper.scala: -------------------------------------------------------------------------------- 1 | package chrome.wallpaper.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSGlobal 5 | 6 | @js.native 7 | trait WallpaperDetails extends js.Object { 8 | val binary: js.UndefOr[js.Any] = js.native 9 | val url: js.UndefOr[String] = js.native 10 | val layout: WallpaperLayout = js.native 11 | val filename: String = js.native 12 | val thumbnail: js.UndefOr[Boolean] = js.native 13 | } 14 | 15 | object WallpaperDetails { 16 | def apply( 17 | filename: String, 18 | layout: WallpaperLayout, 19 | binary: js.UndefOr[js.Any] = js.undefined, 20 | url: js.UndefOr[String] = js.undefined, 21 | thumbnail: js.UndefOr[Boolean] = js.undefined): WallpaperDetails = { 22 | js.Dynamic 23 | .literal( 24 | filename = filename, 25 | layout = layout, 26 | binary = binary, 27 | url = url, 28 | thumbnail = thumbnail 29 | ) 30 | .asInstanceOf[WallpaperDetails] 31 | } 32 | } 33 | 34 | @js.native 35 | @JSGlobal("chrome.wallpaper") 36 | object Wallpaper extends js.Object { 37 | 38 | def setWallpaper(details: WallpaperDetails, 39 | callback: js.Function1[js.UndefOr[js.Any], _]): Unit = 40 | js.native 41 | 42 | } 43 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/system/display/bindings/DisplayProperties.scala: -------------------------------------------------------------------------------- 1 | package chrome.system.display.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object DisplayProperties { 6 | 7 | def apply( 8 | mirroringSourceId: js.UndefOr[Display.ID] = js.undefined, 9 | isPrimary: js.UndefOr[Boolean] = js.undefined, 10 | overscan: js.UndefOr[Insets] = js.undefined, 11 | rotation: js.UndefOr[Int] = js.undefined, 12 | boundsOriginX: js.UndefOr[Int] = js.undefined, 13 | boundsOriginY: js.UndefOr[Int] = js.undefined): DisplayProperties = { 14 | js.Dynamic 15 | .literal( 16 | mirroringSourceId = mirroringSourceId, 17 | isPrimary = isPrimary, 18 | overscan = overscan, 19 | rotation = rotation, 20 | boundsOriginX = boundsOriginX, 21 | boundsOriginY = boundsOriginY 22 | ) 23 | .asInstanceOf[DisplayProperties] 24 | } 25 | 26 | } 27 | 28 | @js.native 29 | trait DisplayProperties extends js.Object { 30 | 31 | var mirroringSourceId: js.UndefOr[Display.ID] = js.native 32 | var isPrimary: js.UndefOr[Boolean] = js.native 33 | var overscan: js.UndefOr[Insets] = js.native 34 | var rotation: js.UndefOr[Int] = js.native 35 | var boundsOriginX: js.UndefOr[Int] = js.native 36 | var boundsOriginY: js.UndefOr[Int] = js.native 37 | 38 | } 39 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/CodeInjectionOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object CodeInjectionOptions { 6 | 7 | type ExeutionTime = String 8 | 9 | val DOCUMENT_START: ExeutionTime = "document_start" 10 | val DOCUMENT_END: ExeutionTime = "document_end" 11 | val DOCUMENT_IDLE: ExeutionTime = "document_idle" 12 | 13 | def apply(code: js.UndefOr[String] = js.undefined, 14 | file: js.UndefOr[String] = js.undefined, 15 | allFrames: js.UndefOr[Boolean] = js.undefined, 16 | matchAboutBlank: js.UndefOr[Boolean] = js.undefined, 17 | runAt: js.UndefOr[String] = js.undefined): CodeInjectionOptions = { 18 | js.Dynamic 19 | .literal( 20 | code = code, 21 | file = file, 22 | allFrames = allFrames, 23 | matchAboutBlank = matchAboutBlank, 24 | runAt = runAt 25 | ) 26 | .asInstanceOf[CodeInjectionOptions] 27 | } 28 | 29 | } 30 | 31 | @js.native 32 | trait CodeInjectionOptions extends js.Object { 33 | 34 | def code: js.UndefOr[String] = js.native 35 | 36 | def file: js.UndefOr[String] = js.native 37 | 38 | def allFrames: js.UndefOr[Boolean] = js.native 39 | 40 | def matchAboutBlank: js.UndefOr[Boolean] = js.native 41 | 42 | def runAt: js.UndefOr[String] = js.native 43 | 44 | } 45 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/BlockingRequestEventSource.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest 2 | 3 | import chrome.events._ 4 | import chrome.webRequest.bindings._ 5 | 6 | import scala.language.implicitConversions 7 | import scala.scalajs.js 8 | import scala.scalajs.js.UndefOr 9 | 10 | trait WebRequestEventSource[T <: js.Function] { 11 | def listen(callback: T, 12 | filter: RequestFilter, 13 | opt_extraInfoSpec: js.UndefOr[js.Array[String]] = js.undefined): Subscription 14 | } 15 | 16 | private[webRequest] class SubscriptionImpl[A <: js.Function](event: WebRequestEvent[A], fn: A) extends Subscription { 17 | override def cancel(): Unit = event.removeListener(fn) 18 | } 19 | 20 | class WebRequestEventSourceImpl[T <: js.Function](event: WebRequestEvent[T]) 21 | extends WebRequestEventSource[T] { 22 | 23 | override def listen(callback: T, 24 | filter: RequestFilter, 25 | opt_extraInfoSpec: UndefOr[js.Array[String]] = js.undefined): Subscription = { 26 | event.addListener(callback, filter, opt_extraInfoSpec) 27 | 28 | new SubscriptionImpl(event, callback) 29 | } 30 | } 31 | 32 | 33 | object WebRequestEventSource { 34 | implicit def eventAsEventSource[T <: js.Function](event: WebRequestEvent[T]): WebRequestEventSource[T] = 35 | new WebRequestEventSourceImpl(event) 36 | } 37 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/BrowserAction.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import chrome.events.bindings.Event 4 | import chrome.tabs.bindings.Tab 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js.annotation.JSGlobal 8 | 9 | @js.native 10 | @JSGlobal("chrome.browserAction") 11 | object BrowserAction extends js.Object { 12 | val onClicked: Event[js.Function1[Tab, _]] = js.native 13 | 14 | def setTitle(details: TitleDetails): Unit = js.native 15 | 16 | def getTitle(details: TabIdDetails, callback: js.Function1[String, _]): Unit = js.native 17 | 18 | def setIcon(details: IconDetails, callback: js.Function0[_]): Unit = js.native 19 | 20 | def setPopup(details: PopupDetails): Unit = js.native 21 | 22 | def getPopup(details: TabIdDetails, callback: js.Function1[String, _]): Unit = js.native 23 | 24 | def setBadgeText(details: BadgeTextDetails): Unit = js.native 25 | 26 | def getBadgeText(details: TabIdDetails, callback: js.Function1[String, _]): Unit = js.native 27 | 28 | def setBadgeBackgroundColor(details: BadgeBackgroundColorDetails): Unit = js.native 29 | 30 | def getBadgeBackgroundColor(details: TabIdDetails, callback: js.Function1[js.Array[Int], _]): Unit = js.native 31 | 32 | def enable(tabId: js.UndefOr[Int]): Unit = js.native 33 | 34 | def disable(tabId: js.UndefOr[Int]): Unit = js.native 35 | } 36 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/events/EventSource.scala: -------------------------------------------------------------------------------- 1 | package chrome.events 2 | 3 | import scala.collection.mutable 4 | 5 | trait Subscription { 6 | def cancel(): Unit 7 | } 8 | 9 | trait EventSource[+A] { 10 | 11 | def listen(fn: A => Unit): Subscription 12 | 13 | def map[B](fn: A => B): EventSource[B] = { 14 | new MappedEventSource[A, B](this, fn) 15 | } 16 | 17 | def filter(fn: A => Boolean): EventSource[A] = { 18 | new FilteredEventSource[A](this, fn) 19 | } 20 | 21 | def merge[B <: C, C >: A](other: EventSource[B]): EventSource[C] = { 22 | val source = new EventSourceController[C]() 23 | listen(source.emit) 24 | other.listen(source.emit) 25 | source 26 | } 27 | 28 | } 29 | 30 | class EventSourceController[A] extends EventSource[A] { 31 | 32 | val subcribers = new mutable.ListBuffer[A => Unit] 33 | 34 | def listen(fn: A => Unit): Subscription = { 35 | subcribers += fn 36 | new Subscription { 37 | override def cancel(): Unit = { 38 | subcribers -= fn 39 | } 40 | } 41 | } 42 | 43 | def emit(value: A): Unit = { 44 | subcribers.foreach( 45 | fn => 46 | scala.scalajs.concurrent.JSExecutionContext.queue 47 | .execute(new Runnable { 48 | override def run(): Unit = fn(value) 49 | })) 50 | } 51 | 52 | def source: EventSource[A] = this 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/OnBeforeNavigateDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js._ 5 | 6 | @js.native 7 | trait OnBeforeNavigateDetails extends js.Object { 8 | /** 9 | * The ID of the tab in which the navigation is about to occur. 10 | */ 11 | val tabId: Int = native 12 | val url: String = native 13 | /** 14 | * Deprecated since Chrome 50. 15 | * The processId is no longer set for this event, since the process which will render the resulting document is not 16 | * known until onCommit. 17 | * Always returns the value of -1. 18 | * 19 | * Missing in firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1248426 20 | */ 21 | val processId: js.UndefOr[Int] = native 22 | /** 23 | * 0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. 24 | * Frame IDs are unique for a given tab and process. 25 | */ 26 | val frameId: Int = native 27 | /** 28 | * Since Chrome 24. 29 | * ID of frame that wraps the frame. Set to -1 of no parent frame exists. 30 | */ 31 | val parentFrameId: Int = native 32 | /** 33 | * The time when the browser was about to start the navigation, in milliseconds since the epoch. 34 | */ 35 | val timeStamp: Double = native 36 | } 37 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/audio/Audio.scala: -------------------------------------------------------------------------------- 1 | package chrome.audio 2 | 3 | import chrome.audio.bindings._ 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object Audio { 12 | 13 | val onDeviceChanged: EventSource[Unit] = bindings.Audio.onDeviceChanged 14 | 15 | def getInfo: Future[(js.Array[OutputInfo], js.Array[InputInfo])] = { 16 | val promise = Promise[(js.Array[OutputInfo], js.Array[InputInfo])]() 17 | bindings.Audio.getInfo( 18 | (outoutInfo: js.Array[OutputInfo], inputInfo: js.Array[InputInfo]) => { 19 | promise.complete(lastErrorOrValue((outoutInfo, inputInfo))) 20 | }) 21 | promise.future 22 | } 23 | 24 | def setActiveDevice(ids: js.Array[bindings.Audio.DeviceID]): Future[Unit] = { 25 | val promise = Promise[Unit]() 26 | bindings.Audio.setActiveDevice(ids, () => { 27 | promise.complete(lastErrorOrValue(())) 28 | }) 29 | promise.future 30 | } 31 | 32 | def setProperties(id: bindings.Audio.DeviceID, 33 | properties: Properties): Future[Unit] = { 34 | val promise = Promise[Unit]() 35 | bindings.Audio.setProperties(id, properties, () => { 36 | promise.complete(lastErrorOrValue(())) 37 | }) 38 | promise.future 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/notifications/bindings/Notifications.scala: -------------------------------------------------------------------------------- 1 | package chrome.notifications.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.notifications") 10 | object Notifications extends js.Object { 11 | 12 | type Id = String 13 | 14 | val onClose: Event[js.Function2[Id, Boolean, _]] = js.native 15 | val onClicked: Event[js.Function1[Id, _]] = js.native 16 | val onButtonClicked: Event[js.Function2[Id, Int, _]] = js.native 17 | val onPermissionLevelChanged: Event[js.Function1[PermissionLevel, _]] = 18 | js.native 19 | val onShowSettings: Event[js.Function0[_]] = js.native 20 | 21 | def create(id: js.UndefOr[Id] = js.undefined, 22 | options: NotificationOptions, 23 | callback: js.UndefOr[js.Function1[Id, _]] = js.undefined): Unit = 24 | js.native 25 | 26 | def update( 27 | id: Id, 28 | options: NotificationOptions, 29 | callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit = 30 | js.native 31 | 32 | def clear( 33 | id: Id, 34 | callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit = 35 | js.native 36 | 37 | def getAll(callback: js.Function1[Map[Id, Boolean], _]): Unit = js.native 38 | 39 | def getPermissionLevel(callback: js.Function1[PermissionLevel, _]): Unit = 40 | js.native 41 | 42 | } 43 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/storage/bindings/Storage.scala: -------------------------------------------------------------------------------- 1 | package chrome.storage.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | trait StorageChange extends js.Object { 10 | 11 | val oldValue: js.UndefOr[js.Any] = js.native 12 | val newValue: js.UndefOr[js.Any] = js.native 13 | 14 | } 15 | 16 | @js.native 17 | trait StorageArea extends js.Object { 18 | 19 | def get(keys: js.UndefOr[js.Any] = js.undefined, 20 | callback: js.Function1[js.Dictionary[js.Any], _]): Unit = js.native 21 | def getBytesInUse(keys: js.UndefOr[js.Any] = js.undefined, 22 | callback: js.Function1[Int, _]): Unit = js.native 23 | def set(items: js.Dictionary[js.Any], 24 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 25 | js.native 26 | def remove(keys: js.Any, 27 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 28 | js.native 29 | def clear(callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 30 | js.native 31 | 32 | } 33 | 34 | @js.native 35 | @JSGlobal("chrome.storage") 36 | object Storage extends js.Object { 37 | 38 | val onChanged: Event[js.Function2[Map[String, StorageChange], String, _]] = 39 | js.native 40 | 41 | val sync: StorageArea = js.native 42 | val local: StorageArea = js.native 43 | val managed: StorageArea = js.native 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tts/TTS.scala: -------------------------------------------------------------------------------- 1 | package chrome.tts 2 | 3 | import chrome.ChromeAPI 4 | import chrome.permissions.Permission.API 5 | import chrome.tts.bindings._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object TTS extends ChromeAPI { 12 | 13 | val requiredPermissions: Set[API] = Set(API.TTS) 14 | 15 | def speak(utterance: String, 16 | options: js.UndefOr[SpeakOptions] = js.undefined): Future[Unit] = { 17 | val promise = Promise[Unit]() 18 | bindings.TTS.speak(utterance, options, js.Any.fromFunction0(() => { 19 | promise.complete(lastErrorOrValue(())) 20 | })) 21 | promise.future 22 | } 23 | 24 | def stop(): Unit = bindings.TTS.stop() 25 | 26 | def pause(): Unit = bindings.TTS.pause() 27 | 28 | def resume(): Unit = bindings.TTS.resume() 29 | 30 | def isSpeaking: Future[Boolean] = { 31 | val promise = Promise[Boolean]() 32 | bindings.TTS.isSpeaking(js.Any.fromFunction1((speaking: Boolean) => { 33 | promise.complete(lastErrorOrValue(speaking)) 34 | })) 35 | promise.future 36 | } 37 | 38 | def getVoices: Future[js.Array[TTSVoice]] = { 39 | val promise = Promise[js.Array[TTSVoice]]() 40 | bindings.TTS.getVoices( 41 | js.Any.fromFunction1((voices: js.Array[TTSVoice]) => { 42 | promise.complete(lastErrorOrValue(voices)) 43 | })) 44 | promise.future 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/AppWindow.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import org.scalajs.dom 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait AppWindow extends js.Object { 9 | 10 | def focus(): Unit = js.native 11 | 12 | def fullscreen(): Unit = js.native 13 | 14 | def isFullscreen(): Boolean = js.native 15 | 16 | def minimize(): Unit = js.native 17 | 18 | def isMinimized(): Boolean = js.native 19 | 20 | def maximize(): Unit = js.native 21 | 22 | def isMaximized(): Boolean = js.native 23 | 24 | def restore(): Unit = js.native 25 | 26 | def moveTo(top: Int, left: Int): Unit = js.native 27 | 28 | def resizeTo(width: Int, height: Int): Unit = js.native 29 | 30 | def drawAttention(): Unit = js.native 31 | 32 | def clearAttention(): Unit = js.native 33 | 34 | def close(): Unit = js.native 35 | 36 | def show(focused: js.UndefOr[Boolean] = js.undefined): Unit = js.native 37 | 38 | def hide(): Unit = js.native 39 | 40 | def isAlwaysOnTop(): Boolean = js.native 41 | 42 | def setAlwaysOnTop(alwaysOnTop: Boolean): Unit = js.native 43 | 44 | def setVisibleOnAllWorkspaces(alwaysVisible: Boolean): Unit = js.native 45 | 46 | def contentWindow: dom.Window = js.native 47 | 48 | def id: AppWindow.Id = js.native 49 | 50 | def innerBounds: Bounds = js.native 51 | 52 | def outerBounds: Bounds = js.native 53 | 54 | } 55 | 56 | object AppWindow { 57 | 58 | type Id = String 59 | 60 | } 61 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/BoundsSpecification.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object BoundsSpecification { 6 | 7 | def apply( 8 | left: js.UndefOr[Int] = js.undefined, 9 | top: js.UndefOr[Int] = js.undefined, 10 | width: js.UndefOr[Int] = js.undefined, 11 | height: js.UndefOr[Int] = js.undefined, 12 | minWidth: js.UndefOr[Int] = js.undefined, 13 | minHeight: js.UndefOr[Int] = js.undefined, 14 | maxWidth: js.UndefOr[Int] = js.undefined, 15 | maxHeight: js.UndefOr[Int] = js.undefined 16 | ): BoundsSpecification = { 17 | 18 | js.Dynamic 19 | .literal( 20 | left = left, 21 | top = top, 22 | width = width, 23 | height = height, 24 | minWidth = minWidth, 25 | minHeight = minHeight, 26 | maxWidth = maxWidth, 27 | maxHeight = maxHeight 28 | ) 29 | .asInstanceOf[BoundsSpecification] 30 | 31 | } 32 | 33 | } 34 | 35 | @js.native 36 | trait BoundsSpecification extends js.Object { 37 | 38 | var left: js.UndefOr[Int] = js.native 39 | var top: js.UndefOr[Int] = js.native 40 | var width: js.UndefOr[Int] = js.native 41 | var height: js.UndefOr[Int] = js.native 42 | 43 | var minWidth: js.UndefOr[Int] = js.native 44 | var minHeight: js.UndefOr[Int] = js.native 45 | var maxWidth: js.UndefOr[Int] = js.native 46 | var maxHeight: js.UndefOr[Int] = js.native 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/Window.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window 2 | 3 | import chrome.app.window.bindings._ 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object Window { 12 | 13 | val onBoundsChanged: EventSource[Unit] = bindings.Window.onBoundsChanged 14 | val onClosed: EventSource[Unit] = bindings.Window.onClosed 15 | val onFullscreened: EventSource[Unit] = bindings.Window.onFullscreened 16 | val onMaximized: EventSource[Unit] = bindings.Window.onMaximized 17 | val onMinimized: EventSource[Unit] = bindings.Window.onMinimized 18 | val onRestored: EventSource[Unit] = bindings.Window.onRestored 19 | 20 | def current: AppWindow = bindings.Window.current() 21 | 22 | def create(url: String, 23 | options: js.UndefOr[CreateWindowOptions] = js.undefined) 24 | : Future[AppWindow] = { 25 | val promise = Promise[AppWindow]() 26 | bindings.Window 27 | .create(url, options, js.Any.fromFunction1((appWindow: AppWindow) => { 28 | promise.complete(lastErrorOrValue(appWindow)) 29 | })) 30 | promise.future 31 | } 32 | 33 | def getAll: js.Array[AppWindow] = bindings.Window.getAll() 34 | 35 | def get(id: AppWindow.Id): AppWindow = bindings.Window.get(id) 36 | 37 | def canSetVisibleOnAllWorkspaces: Boolean = 38 | bindings.Window.canSetVisibleOnAllWorkspaces() 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/windows/bindings/Window.scala: -------------------------------------------------------------------------------- 1 | package chrome.windows.bindings 2 | 3 | import chrome.sessions.bindings.Session 4 | import chrome.tabs.bindings.Tab 5 | 6 | import scala.scalajs.js 7 | 8 | @js.native 9 | trait Window extends js.Object { 10 | 11 | val id: js.UndefOr[Window.Id] = js.native 12 | val focused: Boolean = js.native 13 | val top: js.UndefOr[Int] = js.native 14 | val left: js.UndefOr[Int] = js.native 15 | val width: js.UndefOr[Int] = js.native 16 | val height: js.UndefOr[Int] = js.native 17 | val tabs: js.UndefOr[js.Array[Tab]] = js.native 18 | val incognito: Boolean = js.native 19 | val `type`: js.UndefOr[Window.Type] = js.native 20 | val state: js.UndefOr[Window.State] = js.native 21 | val alwaysOnTop: Boolean = js.native 22 | val sessionId: js.UndefOr[Session.Id] = js.native 23 | 24 | } 25 | 26 | object Window { 27 | 28 | type Id = Int 29 | type Type = String 30 | type State = String 31 | type CreateType = String 32 | 33 | object Type { 34 | val NORMAL: Type = "normal" 35 | val POPUP: Type = "popup" 36 | val PANEL: Type = "panel" 37 | val APP: Type = "app" 38 | } 39 | 40 | object State { 41 | val NORMAL: State = "normal" 42 | val MINIMIZED: State = "minimized" 43 | val MAXIMIZED: State = "maximized" 44 | val FULLSCREEN: State = "fullscreen" 45 | } 46 | 47 | object CreateType { 48 | val NORMAL: CreateType = "normal" 49 | val POPUP: CreateType = "popup" 50 | val PANEL: CreateType = "panel" 51 | val DETACHED_PANEL: CreateType = "detached_panel" 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/permissions/bindings/Permissions.scala: -------------------------------------------------------------------------------- 1 | package chrome.permissions.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.{UndefOr, native, undefined} 8 | 9 | @js.native 10 | @JSGlobal("chrome.permissions") 11 | object Permissions extends js.Object { 12 | 13 | val onAdded: Event[js.Function1[PermissionList, _]] = native 14 | val onRemoved: Event[js.Function1[PermissionList, _]] = native 15 | 16 | def getAll(callback: js.Function1[PermissionList, _]): Unit = native 17 | 18 | def contains(permissions: PermissionList, 19 | callback: js.Function1[Boolean, _]): Unit = native 20 | 21 | def request(permissions: PermissionList, 22 | callback: UndefOr[js.Function1[Boolean, _]] = undefined): Unit = 23 | native 24 | 25 | def remove(permissions: PermissionList, 26 | callback: UndefOr[js.Function1[Boolean, _]] = undefined): Unit = 27 | native 28 | 29 | } 30 | 31 | @js.native 32 | trait PermissionList extends js.Object { 33 | 34 | var permissions: UndefOr[js.Array[String]] = native 35 | var origins: UndefOr[js.Array[String]] = native 36 | 37 | } 38 | 39 | object PermissionList { 40 | 41 | def apply(permissions: UndefOr[js.Array[String]] = undefined, 42 | origins: UndefOr[js.Array[String]] = undefined): PermissionList = { 43 | js.Dynamic 44 | .literal( 45 | permissions = permissions, 46 | origins = origins 47 | ) 48 | .asInstanceOf[PermissionList] 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/bindings/IconDetails.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction.bindings 2 | 3 | import org.scalajs.dom.ImageData 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.| 7 | import scala.scalajs.js.|.Evidence 8 | 9 | @js.native 10 | trait IconDetails extends TabIdDetails { 11 | val imageData: js.UndefOr[ImageData | js.Dictionary[ImageData]] = js.native 12 | 13 | val path: js.UndefOr[String | js.Dictionary[String]] = js.native 14 | } 15 | 16 | object IconDetails { 17 | // implicitly summon evidence that our union types subclass js.Any 18 | implicit val imageEvidence: Evidence[ImageData | js.Dictionary[ImageData], js.Any] = implicitly 19 | implicit val pathEvidence: Evidence[String | js.Dictionary[String], js.Any] = implicitly 20 | 21 | def apply(imageData: js.UndefOr[ImageData | js.Dictionary[ImageData]] = js.undefined, 22 | path: js.UndefOr[String | js.Dictionary[String]] = js.undefined, 23 | tabId: js.UndefOr[Int] = js.undefined): IconDetails = { 24 | // explicitly merge our union types so that dynamic is happy 25 | val anyImageData: js.UndefOr[js.Any] = imageData.map(_.merge) 26 | val anyPath: js.UndefOr[js.Any] = path.map(_.merge) 27 | 28 | if (anyImageData.isDefined) { 29 | js.Dynamic 30 | .literal( 31 | imageData = anyImageData, 32 | tabId = tabId 33 | ) 34 | .asInstanceOf[IconDetails] 35 | } 36 | else { 37 | js.Dynamic 38 | .literal( 39 | path = anyPath, 40 | tabId = tabId 41 | ) 42 | .asInstanceOf[IconDetails] 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/ResourceRequest.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSName 5 | 6 | @js.native 7 | trait ResourceRequest extends js.Object { 8 | 9 | val url: String = js.native 10 | 11 | /** 12 | * The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to 13 | * relate different events of the same request. 14 | */ 15 | val requestId: String = js.native 16 | 17 | /** 18 | * The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a 19 | * subframe in which the request happens. If the document of a (sub-)frame is loaded (type is main_frame or 20 | * sub_frame), frameId indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within 21 | * a tab. 22 | */ 23 | val frameId: Int = js.native 24 | 25 | /** ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists. */ 26 | val parentFrameId: Int = js.native 27 | 28 | /** The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab. */ 29 | val tabId: Int = js.native 30 | 31 | /** 32 | * How the requested resource will be used. 33 | * One of: "main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", or "other" 34 | */ 35 | @JSName("type") 36 | val resourceType: String = js.native 37 | 38 | /** The time when this signal is triggered, in milliseconds since the epoch. */ 39 | val timeStamp: Int = js.native 40 | } 41 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/alarms/Alarms.scala: -------------------------------------------------------------------------------- 1 | package chrome.alarms 2 | 3 | import chrome.alarms.bindings.{AlarmInfo, Alarm} 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object Alarms { 12 | 13 | val onAlarm: EventSource[Alarm] = bindings.Alarms.onAlarm 14 | 15 | def getAll(): Future[List[Alarm]] = { 16 | val promise = Promise[List[Alarm]]() 17 | bindings.Alarms.getAll((alarms: js.Array[bindings.Alarm]) => { 18 | promise.complete(lastErrorOrValue(alarms.toList)) 19 | }) 20 | promise.future 21 | } 22 | 23 | def clearAll(): Future[Boolean] = { 24 | val promise = Promise[Boolean]() 25 | bindings.Alarms.clearAll(js.Any.fromFunction1((wasCleared: Boolean) => { 26 | promise.complete(lastErrorOrValue(wasCleared)) 27 | })) 28 | promise.future 29 | } 30 | 31 | def create(name: String = "", alarmInfo: AlarmInfo): Unit = { 32 | bindings.Alarms.create(name, alarmInfo) 33 | } 34 | 35 | def get(name: String): Future[Option[Alarm]] = { 36 | val promise = Promise[Option[Alarm]] 37 | bindings.Alarms.get(name, (alarm: js.UndefOr[Alarm]) => { 38 | promise.complete(lastErrorOrValue(alarm.toOption)) 39 | }) 40 | promise.future 41 | } 42 | 43 | def clear(name: String = ""): Future[Boolean] = { 44 | val promise = Promise[Boolean]() 45 | bindings.Alarms.clear(name, js.Any.fromFunction1((wasCleared: Boolean) => { 46 | promise.complete(lastErrorOrValue(wasCleared)) 47 | })) 48 | promise.future 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/runtime/bindings/LaunchData.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.runtime.bindings 2 | 3 | import chrome.filesystem.bindings.FileEntry 4 | 5 | import scala.scalajs.js 6 | 7 | object LaunchData { 8 | 9 | type Source = String 10 | 11 | val APP_LAUNCHER: Source = "app_launcher" 12 | val NEW_TAB_PAGE: Source = "new_tab_page" 13 | val RELOAD: Source = "reload" 14 | val RESTART: Source = "restart" 15 | val LOAD_AND_LAUNCH: Source = "load_and_launch" 16 | val COMMAND_LINE: Source = "command_line" 17 | val FILE_HANDLER: Source = "file_handler" 18 | val URL_HANDLER: Source = "url_handler" 19 | val SYSTEM_TRAY: Source = "system_tray" 20 | val ABOUT_PAGE: Source = "about_page" 21 | val KEYBOARD: Source = "keyboard" 22 | val EXTENTIONS_PAGE: Source = "extensions_page" 23 | val MANAGEMENT_API: Source = "management_api" 24 | val EPHEMERAL_APP: Source = "ephemeral_app" 25 | val BACKGROUND: Source = "background" 26 | val KIOSK: Source = "kiosk" 27 | val CHROME_INTERNAL: Source = "chrome_internal" 28 | val TEST: Source = "test" 29 | 30 | } 31 | 32 | @js.native 33 | trait FileHandler extends js.Object { 34 | 35 | val entry: FileEntry = js.native 36 | val `type`: String = js.native 37 | 38 | } 39 | 40 | @js.native 41 | trait LaunchData extends js.Object { 42 | 43 | def id: js.UndefOr[String] = js.native 44 | 45 | def items: js.UndefOr[js.Array[FileHandler]] = js.native 46 | 47 | def url: js.UndefOr[String] = js.native 48 | 49 | def referrerUrl: js.UndefOr[String] = js.native 50 | 51 | def isKioskSession: js.UndefOr[Boolean] = js.native 52 | 53 | def source: js.UndefOr[LaunchData.Source] = js.native 54 | 55 | } 56 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/pageAction/PageAction.scala: -------------------------------------------------------------------------------- 1 | package chrome.pageAction 2 | 3 | import chrome.pageAction.bindings._ 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.tabs.bindings.Tab 7 | import chrome.utils.ErrorHandling._ 8 | 9 | import scala.concurrent.{Future, Promise} 10 | import scalajs.js 11 | 12 | object PageAction { 13 | 14 | val onClicked: EventSource[Tab] = bindings.PageAction.onClicked 15 | 16 | def show(tabId: Tab.Id): Unit = 17 | bindings.PageAction.show(tabId) 18 | 19 | def hide(tabId: Tab.Id): Unit = 20 | bindings.PageAction.hide(tabId) 21 | 22 | def setTitle(details: SetTitleDetails): Unit = 23 | bindings.PageAction.setTitle(details) 24 | 25 | def getTitle(details: GetTitleDetails): Future[String] = { 26 | val promise = Promise[String]() 27 | bindings.PageAction.getTitle(details, js.Any.fromFunction1((title) => { 28 | promise.complete(lastErrorOrValue(title)) 29 | })) 30 | promise.future 31 | } 32 | 33 | def setIcon(details: SetIconDetails): Future[Unit] = { 34 | val promise = Promise[Unit]() 35 | bindings.PageAction.setIcon(details, js.Any.fromFunction0(() => { 36 | promise.complete(lastErrorOrValue(())) 37 | })) 38 | promise.future 39 | } 40 | 41 | def setPopup(details: SetPopupDetails): Unit = 42 | bindings.PageAction.setPopup(details) 43 | 44 | def getPopup(details: GetPopupDetails): Future[String] = { 45 | val promise = Promise[String]() 46 | bindings.PageAction.getPopup(details, js.Any.fromFunction1((popup) => { 47 | promise.complete(lastErrorOrValue(popup)) 48 | })) 49 | promise.future 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/bindings/TCPServer.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.{UndefOr, native, undefined} 8 | 9 | @js.native 10 | @JSGlobal("chrome.sockets.tcpServer") 11 | object TCPServer extends js.Object { 12 | 13 | val onAccept: Event[js.Function1[AcceptEvent, _]] = native 14 | val onAcceptError: Event[js.Function1[AcceptErrorEvent, _]] = native 15 | 16 | def create(properties: UndefOr[SocketProperties] = undefined, 17 | callback: js.Function1[CreateInfo, _]): Unit = native 18 | 19 | def update(socketId: SocketId, 20 | properties: SocketProperties, 21 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 22 | 23 | def setPaused(socketId: SocketId, 24 | paused: Boolean, 25 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 26 | 27 | def listen(socketId: SocketId, 28 | address: String, 29 | port: Int, 30 | backlog: UndefOr[Int] = undefined, 31 | callback: js.Function1[Int, _]): Unit = native 32 | 33 | def disconnect(socketId: SocketId, 34 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 35 | 36 | def close(socketId: SocketId, 37 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 38 | 39 | def getInfo(socketId: SocketId, 40 | callback: js.Function1[SocketInfo, _]): Unit = native 41 | 42 | def getSockets(callback: js.Function1[js.Array[SocketInfo], _]): Unit = 43 | native 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/processes/bindings/Process.scala: -------------------------------------------------------------------------------- 1 | package chrome.processes.bindings 2 | 3 | import chrome.tabs.bindings.Tab 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait Process extends js.Object { 9 | 10 | val id: Process.Id = js.native 11 | val osProcessId: Process.Id = js.native 12 | val title: String = js.native 13 | val `type`: Process.Type = js.native 14 | val profile: String = js.native 15 | val naclDebugPort: Int = js.native 16 | val tabs: js.Array[Tab.Id] = js.native 17 | val cpu: js.UndefOr[Double] = js.native 18 | val network: js.UndefOr[Double] = js.native 19 | val privateMemory: js.UndefOr[Double] = js.native 20 | val jsMemoryAllocated: js.UndefOr[Double] = js.native 21 | val jsMemoryUsed: js.UndefOr[Double] = js.native 22 | val sqliteMemory: js.UndefOr[Double] = js.native 23 | val imageCache: js.UndefOr[Cache] = js.native 24 | val scriptCache: js.UndefOr[Cache] = js.native 25 | val cssCache: js.UndefOr[Cache] = js.native 26 | 27 | } 28 | 29 | object Process { 30 | type Id = Int 31 | type Type = String 32 | type ExitType = Int 33 | 34 | object ExitType { 35 | //TODO: find out the values of these 36 | val NORMAL: ExitType = ??? 37 | val ABNORMAL: ExitType = ??? 38 | val KILLED: ExitType = ??? 39 | val CRASHED: ExitType = ??? 40 | } 41 | 42 | object Type { 43 | val BROWSER: Type = "browser" 44 | val RENDERER: Type = "renderer" 45 | val EXTENTION: Type = "extension" 46 | val NOTIFICATION: Type = "notification" 47 | val PLUGIN: Type = "plugin" 48 | val WORKER: Type = "worker" 49 | val NACL: Type = "nacl" 50 | val UTILITY: Type = "utility" 51 | val GPU: Type = "gpu" 52 | val OTHER: Type = "other" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/contextMenus/ContextMenus.scala: -------------------------------------------------------------------------------- 1 | package chrome.contextMenus 2 | 3 | import chrome.ChromeAPI 4 | import chrome.contextMenus.bindings.{CreateProperties, MenuInfo, UpdateProperties} 5 | import chrome.events.EventSource 6 | import chrome.events.EventSourceImplicits._ 7 | import chrome.permissions.Permission.API 8 | import chrome.tabs.bindings.Tab 9 | 10 | import scala.concurrent.{Future, Promise} 11 | import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue 12 | import scala.scalajs.js 13 | import scala.scalajs.js.| 14 | 15 | object ContextMenus extends ChromeAPI { 16 | 17 | def onClicked: EventSource[(MenuInfo, Tab)] = bindings.ContextMenus.onClicked 18 | 19 | val requiredPermissions: Set[API] = Set(API.ContextMenus) 20 | 21 | def create(createProperties: CreateProperties): String | Int = 22 | bindings.ContextMenus.create(createProperties) 23 | 24 | def create(id: String, title: String, contexts: List[String]): String | Int = 25 | create( 26 | bindings 27 | .CreateProperties(id, title, contexts = js.Array(contexts: _*))) 28 | 29 | def update(id: String | Int, properties: UpdateProperties): Unit = 30 | bindings.ContextMenus.update(id, properties) 31 | 32 | def remove(menuItemId: String | Int): Future[String | Int] = { 33 | val promise = Promise[Unit] 34 | val result = bindings.ContextMenus 35 | .remove(menuItemId, js.Any.fromFunction0[Unit](() => { 36 | promise.success(Unit) 37 | })) 38 | promise.future.map(_ => result) 39 | } 40 | 41 | def removeAll(): Future[Unit] = { 42 | val promise = Promise[Unit] 43 | bindings.ContextMenus.removeAll(js.Any.fromFunction0[Unit](() => { 44 | promise.success(Unit) 45 | })) 46 | promise.future 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/runtime/bindings/Manifest.scala: -------------------------------------------------------------------------------- 1 | package chrome.runtime.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait App extends js.Object { 7 | val background: Background = js.native 8 | } 9 | 10 | @js.native 11 | trait Background extends js.Object { 12 | val scripts: js.Array[String] = js.native 13 | } 14 | 15 | @js.native 16 | trait AppManifest extends Manifest { 17 | val app: App = js.native 18 | } 19 | 20 | @js.native 21 | trait ExtensionManifest extends Manifest { 22 | val background: js.UndefOr[Background] = js.native 23 | } 24 | 25 | @js.native 26 | trait Manifest extends js.Object { 27 | 28 | val name: String = js.native 29 | val version: String = js.native 30 | val manifest_version: Int = js.native 31 | val defaultLocale: js.UndefOr[String] = js.native 32 | val shortName: js.UndefOr[String] = js.native 33 | val description: js.UndefOr[String] = js.native 34 | val offlineEnabled: js.UndefOr[Boolean] = js.native 35 | val permissions: js.UndefOr[js.Array[String]] = js.native 36 | val icons: js.UndefOr[Map[String, String]] = js.native 37 | val content_security_policy: js.UndefOr[String] = js.native 38 | 39 | } 40 | 41 | object Manifest { 42 | 43 | implicit class ManifestOps(val manifest: Manifest) extends AnyVal { 44 | 45 | def isAppManifest: Boolean = manifest.hasOwnProperty("app") 46 | 47 | def isExtensionManifest: Boolean = !isAppManifest 48 | 49 | def asAppManifest: Option[AppManifest] = { 50 | if (isAppManifest) { 51 | Some(manifest.asInstanceOf[AppManifest]) 52 | } else None 53 | } 54 | 55 | def asExtensionManifest: Option[ExtensionManifest] = { 56 | if (isExtensionManifest) { 57 | Some(manifest.asInstanceOf[ExtensionManifest]) 58 | } else None 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /sbt-plugin/src/main/scala/net/lullabyte/Chrome.scala: -------------------------------------------------------------------------------- 1 | package net.lullabyte 2 | 3 | import chrome.Manifest 4 | import io.circe.Printer 5 | import io.circe.syntax._ 6 | import sbt._ 7 | 8 | object Chrome { 9 | 10 | val manifestFileName = "manifest.json" 11 | 12 | def i18n(msg: String): String = s"__MSG_${msg}__" 13 | 14 | def icons(base: String, name: String, sizes: Set[Int]): Map[Int, String] = { 15 | sizes.map{ size => 16 | size -> s"$base/$size/$name" 17 | }.toMap 18 | } 19 | 20 | def buildUnpackedDirectory(unpacked: File)(manifest: File, jsLib: File, 21 | jsDeps: File, resources: Seq[File]): File = { 22 | 23 | val libsAndDependencies = List( 24 | jsLib -> unpacked / jsLib.getName, 25 | jsDeps -> unpacked / jsDeps.getName 26 | ) 27 | 28 | val sourceMaps = List(jsLib, jsDeps) map { sourceFile => 29 | val fileName = sourceFile.getName + ".map" 30 | val originalSourceMap = sourceFile.getParentFile / fileName 31 | originalSourceMap -> unpacked / fileName 32 | } filter (_._1.exists()) 33 | 34 | val chromeSpecific = List( 35 | manifest -> unpacked / manifestFileName 36 | ) 37 | 38 | IO.createDirectory(unpacked) 39 | 40 | resources.foreach { resource => 41 | IO.copyDirectory(resource, unpacked, overwrite = true, preserveLastModified = true) 42 | } 43 | 44 | IO.copy( 45 | libsAndDependencies ::: sourceMaps ::: chromeSpecific, 46 | overwrite = true, preserveLastModified = true, preserveExecutable = true 47 | ) 48 | 49 | unpacked 50 | } 51 | 52 | val printer = Printer.noSpaces.copy(dropNullValues = true) 53 | 54 | def generateManifest(out: File)(manifest: Manifest): File = { 55 | import JsonCodecs._ 56 | 57 | val content = printer.pretty(manifest.asJson) 58 | IO.write(out, content) 59 | out 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/app/window/bindings/CreateWindowOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.app.window.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object CreateWindowOptions { 6 | 7 | def apply(id: js.UndefOr[String] = js.undefined, 8 | innerBounds: js.UndefOr[BoundsSpecification] = js.undefined, 9 | outerBounds: js.UndefOr[BoundsSpecification] = js.undefined, 10 | alphaEnabled: js.UndefOr[Boolean] = js.undefined, 11 | state: js.UndefOr[String] = js.undefined, 12 | hidden: js.UndefOr[Boolean] = js.undefined, 13 | resizable: js.UndefOr[Boolean] = js.undefined, 14 | alwaysOnTop: js.UndefOr[Boolean] = js.undefined, 15 | focused: js.UndefOr[Boolean] = js.undefined, 16 | visibleOnAllWorkspaces: js.UndefOr[Boolean] = js.undefined) 17 | : CreateWindowOptions = { 18 | js.Dynamic 19 | .literal( 20 | id = id, 21 | alphaEnabled = alphaEnabled, 22 | state = state, 23 | hidden = hidden, 24 | resizable = resizable, 25 | alwaysOnTop = alwaysOnTop, 26 | focused = focused, 27 | visibleOnAllWorkspaces = visibleOnAllWorkspaces 28 | ) 29 | .asInstanceOf[CreateWindowOptions] 30 | } 31 | 32 | } 33 | 34 | @js.native 35 | trait CreateWindowOptions extends js.Object { 36 | 37 | val alphaEnabled: js.UndefOr[Boolean] = js.native 38 | val state: js.UndefOr[String] = js.native 39 | val hidden: js.UndefOr[Boolean] = js.native 40 | val resizable: js.UndefOr[Boolean] = js.native 41 | val alwaysOnTop: js.UndefOr[Boolean] = js.native 42 | val focused: js.UndefOr[Boolean] = js.native 43 | val visibleOnAllWorkspaces: js.UndefOr[Boolean] = js.native 44 | var id: js.UndefOr[String] = js.native 45 | var innerBounds: js.UndefOr[BoundsSpecification] = js.native 46 | var outerBounds: js.UndefOr[BoundsSpecification] = js.native 47 | 48 | } 49 | -------------------------------------------------------------------------------- /interop/monix/src/main/scala/chrome/interop/monix/package.scala: -------------------------------------------------------------------------------- 1 | package chrome.interop 2 | 3 | import _root_.monix.reactive._ 4 | import _root_.monix.execution._ 5 | import chrome.events.bindings.Event 6 | 7 | import scala.scalajs.js 8 | 9 | package object monix { 10 | 11 | implicit class Event0MonixOps(val event: Event[js.Function0[_]]) extends AnyVal { 12 | def toObservable(strategy: OverflowStrategy.Synchronous[Unit]): Observable[Unit] = 13 | Observable.create(strategy){ sub => 14 | val fn = () => sub.onNext(()) 15 | event.addListener(fn) 16 | Cancelable.apply(() => event.removeListener(fn)) 17 | } 18 | } 19 | 20 | implicit class Event1MonixOps[T1](val event: Event[js.Function1[T1, _]]) extends AnyVal { 21 | def toObservable(strategy: OverflowStrategy.Synchronous[T1]): Observable[T1] = 22 | Observable.create(strategy){ sub => 23 | val fn = (t1: T1) => sub.onNext(t1) 24 | event.addListener(fn) 25 | Cancelable.apply(() => event.removeListener(fn)) 26 | } 27 | } 28 | 29 | implicit class Event2MonixOps[T1, T2](val event: Event[js.Function2[T1, T2, _]]) extends AnyVal { 30 | def toObservable(strategy: OverflowStrategy.Synchronous[(T1, T2)]): Observable[(T1, T2)] = 31 | Observable.create(strategy){ sub => 32 | val fn = (t1: T1, t2: T2) => sub.onNext((t1, t2)) 33 | event.addListener(fn) 34 | Cancelable.apply(() => event.removeListener(fn)) 35 | } 36 | } 37 | 38 | implicit class Event3MonixOps[T1, T2, T3](val event: Event[js.Function3[T1, T2, T3, _]]) extends AnyVal { 39 | def toObservable(strategy: OverflowStrategy.Synchronous[(T1, T2, T3)]): Observable[(T1, T2, T3)] = 40 | Observable.create(strategy){ sub => 41 | val fn = (t1: T1, t2: T2, t3: T3) => sub.onNext((t1, t2, t3)) 42 | event.addListener(fn) 43 | Cancelable.apply(() => event.removeListener(fn)) 44 | } 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/Socket.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer 2 | 3 | import chrome.events.EventSource 4 | import chrome.sockets.tcp 5 | import chrome.sockets.tcpServer.bindings._ 6 | 7 | import scala.concurrent.Future 8 | import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue 9 | import scala.scalajs.js 10 | 11 | class Socket(val socketId: SocketId) { 12 | 13 | val onAccept = TCPServer.onAccept 14 | .filter(_.socketId == socketId) 15 | .map(event => Socket.Accepted(tcp.Socket(event.clientSocketId))) 16 | val onAcceptError = TCPServer.onAcceptError 17 | .filter(_.socketId == socketId) 18 | .map(event => Socket.Error(event.resultCode)) 19 | val all: EventSource[Socket.AcceptEvent] = onAccept.merge(onAcceptError) 20 | 21 | def update(properties: SocketProperties): Future[Unit] = { 22 | TCPServer.update(socketId, properties) 23 | } 24 | 25 | def setPaused(paused: Boolean): Future[Unit] = { 26 | TCPServer.setPaused(socketId, paused) 27 | } 28 | 29 | def listen(address: String, 30 | port: Int, 31 | backlog: js.UndefOr[Int] = js.undefined): Future[Int] = { 32 | TCPServer.listen(socketId, address, port, backlog) 33 | } 34 | 35 | def disconnect: Future[Unit] = { 36 | TCPServer.disconnect(socketId) 37 | } 38 | 39 | def close: Future[Unit] = { 40 | TCPServer.close(socketId) 41 | } 42 | 43 | def getInfo: Future[SocketInfo] = { 44 | TCPServer.getInfo(socketId) 45 | } 46 | 47 | } 48 | 49 | object Socket { 50 | 51 | sealed trait AcceptEvent 52 | case class Accepted(client: chrome.sockets.tcp.Socket) extends AcceptEvent 53 | case class Error(code: Int) extends AcceptEvent 54 | 55 | def apply(id: SocketId): Socket = new Socket(id) 56 | 57 | def apply(name: String = "", persistent: Boolean): Future[Socket] = { 58 | TCPServer 59 | .create(SocketProperties(persistent, name)) 60 | .map(i => Socket(i.socketId)) 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tts/bindings/SpeakOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.tts.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object SpeakOptions { 6 | 7 | def apply(enqueue: js.UndefOr[Boolean] = js.undefined, 8 | voiceName: js.UndefOr[String] = js.undefined, 9 | extensionId: js.UndefOr[String] = js.undefined, 10 | lang: js.UndefOr[String] = js.undefined, 11 | gender: js.UndefOr[TTSVoice.Gender] = js.undefined, 12 | rate: js.UndefOr[Double] = js.undefined, 13 | pitch: js.UndefOr[Double] = js.undefined, 14 | volume: js.UndefOr[Double] = js.undefined, 15 | requiredEventTypes: js.UndefOr[TTSEvent.Type] = js.undefined, 16 | desiredEventTypes: js.UndefOr[TTSEvent.Type] = js.undefined, 17 | onEvent: js.UndefOr[String] = js.undefined): SpeakOptions = { 18 | js.Dynamic 19 | .literal( 20 | enqueue = enqueue, 21 | voiceName = voiceName, 22 | extensionId = extensionId, 23 | lang = lang, 24 | gender = gender, 25 | rate = rate, 26 | pitch = pitch, 27 | volume = volume, 28 | requiredEventTypes = requiredEventTypes, 29 | desiredEventTypes = desiredEventTypes, 30 | onEvent = onEvent 31 | ) 32 | .asInstanceOf[SpeakOptions] 33 | } 34 | 35 | } 36 | 37 | @js.native 38 | trait SpeakOptions extends js.Object { 39 | 40 | val enqueue: js.UndefOr[Boolean] = js.native 41 | val voiceName: js.UndefOr[String] = js.native 42 | val extensionId: js.UndefOr[String] = js.native 43 | val lang: js.UndefOr[String] = js.native 44 | val gender: js.UndefOr[TTSVoice.Gender] = js.native 45 | val rate: js.UndefOr[Double] = js.native 46 | val pitch: js.UndefOr[Double] = js.native 47 | val volume: js.UndefOr[Double] = js.native 48 | val requiredEventTypes: js.UndefOr[TTSEvent.Type] = js.native 49 | val desiredEventTypes: js.UndefOr[TTSEvent.Type] = js.native 50 | val onEvent: js.UndefOr[String] = js.native 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/processes/Processes.scala: -------------------------------------------------------------------------------- 1 | package chrome.processes 2 | 3 | import chrome.events.EventSource 4 | import chrome.events.EventSourceImplicits._ 5 | import chrome.permissions.Permission.API 6 | import chrome.processes.bindings._ 7 | import chrome.tabs.bindings.Tab 8 | import chrome.utils.ErrorHandling._ 9 | 10 | import scala.concurrent.{Future, Promise} 11 | import scala.scalajs.js 12 | 13 | object Processes { 14 | 15 | val requiredPermissions: Set[API] = Set(API.Processes) 16 | 17 | val onUpdated: EventSource[Map[Process.Id, Process]] = 18 | bindings.Processes.onUpdated 19 | val onUpdatedWithMemory: EventSource[Map[Process.Id, Process]] = 20 | bindings.Processes.onUpdatedWithMemory 21 | val onCreated: EventSource[Process] = bindings.Processes.onCreated 22 | val onUnresponsive: EventSource[Process] = bindings.Processes.onUnresponsive 23 | val onExited: EventSource[(Process.Id, Process.ExitType, js.UndefOr[Int])] = 24 | bindings.Processes.onExited 25 | 26 | def terminate(processId: Process.Id): Future[Boolean] = { 27 | val promise = Promise[Boolean]() 28 | bindings.Processes 29 | .terminate(processId, js.Any.fromFunction1((terminated: Boolean) => { 30 | promise.complete(lastErrorOrValue(terminated)) 31 | })) 32 | promise.future 33 | } 34 | 35 | def getProcessIdForTab(tabId: Tab.Id): Future[Process.Id] = { 36 | val promise = Promise[Process.Id]() 37 | bindings.Processes.getProcessIdForTab(tabId, (pid: Process.Id) => { 38 | promise.complete(lastErrorOrValue(pid)) 39 | }) 40 | promise.future 41 | } 42 | 43 | def getProcessInfo( 44 | processIds: js.Array[Process.Id], 45 | includeMemory: Boolean): Future[Map[Process.Id, Process]] = { 46 | val promise = Promise[Map[Process.Id, Process]]() 47 | bindings.Processes.getProcessInfo( 48 | processIds, 49 | includeMemory, 50 | (info: Map[Process.Id, Process]) => { 51 | promise.complete(lastErrorOrValue(info)) 52 | }) 53 | promise.future 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/Downloads.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal("chrome.downloads") 10 | object Downloads extends js.Object { 11 | 12 | type Suggest = Option[Suggestion] => Unit 13 | 14 | val onCreated: Event[js.Function1[DownloadItem, _]] = js.native 15 | val onErased: Event[js.Function1[DownloadItem.Id, _]] = js.native 16 | val onChanged: Event[js.Function1[DownloadDelta, _]] = js.native 17 | val onDeterminingFilename: Event[js.Function2[DownloadItem, Suggest, _]] = js.native 18 | 19 | def download(options: DownloadOptions, callback: js.UndefOr[js.Function1[DownloadItem.Id, _]] = js.native): Unit = js.native 20 | 21 | def pause(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native 22 | def resume(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native 23 | def cancel(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native 24 | def getFileIcon( 25 | id: DownloadItem.Id, 26 | options: js.UndefOr[FileIconOptions] = js.native, 27 | callback: js.UndefOr[js.Function1[js.UndefOr[String], _]] 28 | ): Unit = js.native 29 | def open(id: DownloadItem.Id): Unit = js.native 30 | def show(id: DownloadItem.Id): Unit = js.native 31 | def showDefaultFolder(): Unit = js.native 32 | 33 | def erase(query: Query, callback: js.UndefOr[js.Function1[js.Array[DownloadItem.Id], _]] = js.native): Unit = js.native 34 | def search(query: Query, callback: js.Function1[js.Array[DownloadItem], _]): Unit = js.native 35 | 36 | def removeFile(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native 37 | def acceptDanger(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native 38 | def drag(id: DownloadItem.Id): Unit = js.native 39 | def setShelfEnabled(enabled: Boolean): Unit = js.native 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/tabs/bindings/TabQuery.scala: -------------------------------------------------------------------------------- 1 | package chrome.tabs.bindings 2 | 3 | import chrome.windows.bindings.Window 4 | 5 | import scala.scalajs.js 6 | 7 | @js.native 8 | trait TabQuery extends js.Object { 9 | 10 | def active: js.UndefOr[Boolean] = js.native 11 | 12 | def pinned: js.UndefOr[Boolean] = js.native 13 | 14 | def highlighted: js.UndefOr[Boolean] = js.native 15 | 16 | def currentWindow: js.UndefOr[Boolean] = js.native 17 | 18 | def lastFocusedWindow: js.UndefOr[Boolean] = js.native 19 | 20 | def status: js.UndefOr[Tab.Status] = js.native 21 | 22 | def title: js.UndefOr[String] = js.native 23 | 24 | def url: js.UndefOr[js.Any] = js.native 25 | 26 | def windowId: js.UndefOr[Window.Id] = js.native 27 | 28 | def windowType: js.UndefOr[Window.Type] = js.native 29 | 30 | def index: js.UndefOr[Int] = js.native 31 | 32 | } 33 | 34 | object TabQuery { 35 | 36 | def apply(active: js.UndefOr[Boolean] = js.undefined, 37 | pinned: js.UndefOr[Boolean] = js.undefined, 38 | highlighted: js.UndefOr[Boolean] = js.undefined, 39 | currentWindow: js.UndefOr[Boolean] = js.undefined, 40 | lastFocusedWindow: js.UndefOr[Boolean] = js.undefined, 41 | status: js.UndefOr[Tab.Status] = js.undefined, 42 | title: js.UndefOr[String] = js.undefined, 43 | url: js.UndefOr[js.Any] = js.undefined, 44 | windowId: js.UndefOr[Window.Id] = js.undefined, 45 | windowType: js.UndefOr[Window.Type] = js.undefined, 46 | index: js.UndefOr[Int] = js.undefined): TabQuery = { 47 | js.Dynamic 48 | .literal( 49 | active = active, 50 | pinned = pinned, 51 | highlighted = highlighted, 52 | currentWindow = currentWindow, 53 | lastFocusedWindow = lastFocusedWindow, 54 | status = status, 55 | title = title, 56 | url = url, 57 | windowId = windowId, 58 | windowType = windowType, 59 | index = index 60 | ) 61 | .asInstanceOf[TabQuery] 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/storage/Storage.scala: -------------------------------------------------------------------------------- 1 | package chrome.storage 2 | 3 | import chrome.ChromeAPI 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.permissions.Permission.API 7 | import chrome.storage.bindings.StorageChange 8 | import chrome.utils.ErrorHandling._ 9 | import scala.concurrent.{Promise, Future} 10 | import scala.scalajs.js 11 | 12 | object Storage extends ChromeAPI { 13 | 14 | implicit class StorageArea(area: bindings.StorageArea) { 15 | 16 | def get(keys: js.UndefOr[js.Any] = js.undefined) 17 | : Future[js.Dictionary[js.Any]] = { 18 | val promise = Promise[js.Dictionary[js.Any]]() 19 | area.get(keys, (results: js.Dictionary[js.Any]) => { 20 | promise.complete(lastErrorOrValue(results)) 21 | }) 22 | promise.future 23 | } 24 | 25 | def getBytesInUse(keys: js.UndefOr[js.Any] = js.undefined): Future[Int] = { 26 | val promise = Promise[Int]() 27 | area.getBytesInUse(keys, (result: Int) => { 28 | promise.complete(lastErrorOrValue(result)) 29 | }) 30 | promise.future 31 | } 32 | 33 | def set(items: js.Dictionary[js.Any]): Future[Unit] = { 34 | val promise = Promise[Unit]() 35 | area.set(items, js.Any.fromFunction0(() => { 36 | promise.complete(lastErrorOrValue(())) 37 | })) 38 | promise.future 39 | } 40 | 41 | def remove(keys: js.Any): Future[Unit] = { 42 | val promise = Promise[Unit]() 43 | area.remove(keys, js.Any.fromFunction0(() => { 44 | promise.complete(lastErrorOrValue(())) 45 | })) 46 | promise.future 47 | } 48 | 49 | def clear: Future[Unit] = { 50 | val promise = Promise[Unit]() 51 | area.clear(js.Any.fromFunction0(() => { 52 | promise.complete(lastErrorOrValue(())) 53 | })) 54 | promise.future 55 | } 56 | } 57 | 58 | val requiredPermissions: Set[API] = Set(API.Storage) 59 | val onChanged: EventSource[(Map[String, StorageChange], String)] = 60 | bindings.Storage.onChanged 61 | 62 | val sync: StorageArea = bindings.Storage.sync 63 | val local: StorageArea = bindings.Storage.local 64 | val managed: StorageArea = bindings.Storage.managed 65 | 66 | } 67 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/bindings/TCP.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.typedarray.ArrayBuffer 8 | import scala.scalajs.js.{UndefOr, native, undefined} 9 | 10 | @js.native 11 | @JSGlobal("chrome.sockets.tcp") 12 | object TCP extends js.Object { 13 | 14 | val onReceive: Event[js.Function1[ReceiveEvent, _]] = native 15 | val onReceiveError: Event[js.Function1[ReceiveErrorEvent, _]] = native 16 | 17 | def create(properties: UndefOr[SocketProperties] = undefined, 18 | callback: js.Function1[CreateInfo, _]): Unit = native 19 | 20 | def update(socketId: SocketId, 21 | properties: SocketProperties, 22 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 23 | 24 | def setPaused(socketId: SocketId, 25 | paused: Boolean, 26 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 27 | 28 | def setKeepAlive(socketId: SocketId, 29 | enable: Boolean, 30 | delay: UndefOr[Int] = undefined, 31 | callback: js.Function1[Int, _]): Unit = native 32 | 33 | def setNoDelay(socketId: SocketId, 34 | noDelay: Boolean, 35 | callback: js.Function1[Int, _]): Unit = native 36 | 37 | def connect(socketId: SocketId, 38 | peerAddress: String, 39 | peerPort: Int, 40 | callback: js.Function1[Int, _]): Unit = native 41 | 42 | def disconnect(socketId: SocketId, 43 | callback: UndefOr[js.Function0[_]] = undefined): Unit = native 44 | 45 | def secure(socketId: SocketId, 46 | options: UndefOr[SecureOptions] = undefined, 47 | callback: js.Function0[_]): Unit = native 48 | 49 | def send(socketId: SocketId, 50 | data: ArrayBuffer, 51 | callback: js.Function1[SendInfo, _]): Unit = native 52 | 53 | def close(socketId: SocketId, callback: js.Function0[_]): Unit = native 54 | 55 | def getInfo(socketId: SocketId, 56 | callback: js.Function1[SocketInfo, _]): Unit = native 57 | 58 | def getSockets(callback: js.Function1[js.Array[SocketInfo], _]): Unit = 59 | native 60 | 61 | } 62 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcp/Socket.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcp 2 | 3 | import chrome.events.EventSource 4 | import chrome.sockets.tcp.bindings._ 5 | 6 | import scala.concurrent.Future 7 | import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue 8 | import scala.scalajs.js 9 | import scala.scalajs.js.typedarray.ArrayBuffer 10 | 11 | class Socket(val socketId: SocketId) { 12 | 13 | val onReceive = TCP.onReceive 14 | .filter(_.socketId == socketId) 15 | .map((event) => Socket.Received(event.data)) 16 | val onReceiveError = TCP.onReceiveError 17 | .filter(_.socketId == socketId) 18 | .map((event) => Socket.Error(event.resultCode)) 19 | val all: EventSource[Socket.ReceiveEvent] = onReceive.merge(onReceiveError) 20 | 21 | def update(properties: SocketProperties): Future[Unit] = { 22 | TCP.update(socketId, properties) 23 | } 24 | 25 | def setPaused(paused: Boolean): Future[Unit] = { 26 | TCP.setPaused(socketId, paused) 27 | } 28 | 29 | def setKeepAlive(enable: Boolean, 30 | delay: js.UndefOr[Int] = js.undefined): Future[Int] = { 31 | TCP.setKeepAlive(socketId, enable, delay) 32 | } 33 | 34 | def setNoDelay(noDelay: Boolean): Future[Int] = { 35 | TCP.setNoDelay(socketId, noDelay) 36 | } 37 | 38 | def connect(peerAddress: String, peerPort: Int): Future[Int] = { 39 | TCP.connect(socketId, peerAddress, peerPort) 40 | } 41 | 42 | def disconnect: Future[Unit] = { 43 | TCP.disconnect(socketId) 44 | } 45 | 46 | def secure(options: js.UndefOr[SecureOptions]): Future[Unit] = { 47 | TCP.secure(socketId, options) 48 | } 49 | 50 | def send(data: ArrayBuffer): Future[SendInfo] = { 51 | TCP.send(socketId, data) 52 | } 53 | 54 | def close: Future[Unit] = { 55 | TCP.close(socketId) 56 | } 57 | 58 | def getInfo: Future[SocketInfo] = { 59 | TCP.getInfo(socketId) 60 | } 61 | 62 | } 63 | 64 | object Socket { 65 | 66 | sealed trait ReceiveEvent 67 | case class Received(data: ArrayBuffer) extends ReceiveEvent 68 | case class Error(code: Int) extends ReceiveEvent 69 | 70 | def apply(id: SocketId): Socket = new Socket(id) 71 | 72 | def apply(name: String = "", 73 | persistent: Boolean, 74 | bufferSize: Int): Future[Socket] = { 75 | TCP 76 | .create(SocketProperties(persistent, name, bufferSize)) 77 | .map(i => Socket(i.socketId)) 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/management/bindings/Management.scala: -------------------------------------------------------------------------------- 1 | package chrome.management.bindings 2 | 3 | import chrome.events.bindings.Event 4 | import chrome.management.bindings.ExtensionInfo.LaunchType 5 | import chrome.runtime.bindings.Runtime.AppID 6 | 7 | import scala.scalajs.js 8 | import scala.scalajs.js.annotation.JSGlobal 9 | 10 | @js.native 11 | @JSGlobal("chrome.management") 12 | object Management extends js.Object { 13 | 14 | val onInstalled: Event[js.Function1[ExtensionInfo, _]] = js.native 15 | val onUninstalled: Event[js.Function1[String, _]] = js.native 16 | val onEnabled: Event[js.Function1[ExtensionInfo, _]] = js.native 17 | val onDisabled: Event[js.Function1[ExtensionInfo, _]] = js.native 18 | 19 | def getAll(callback: js.Function1[js.Array[ExtensionInfo], _]): Unit = 20 | js.native 21 | 22 | def get(id: AppID, callback: js.Function1[ExtensionInfo, _]): Unit = 23 | js.native 24 | 25 | def getSelf(callback: js.Function1[ExtensionInfo, _]): Unit = js.native 26 | 27 | def getPermissionWarningsById( 28 | id: AppID, 29 | callback: js.Function1[js.Array[String], _]): Unit = js.native 30 | 31 | def getPermissionWarningsByManifest( 32 | manifestStr: String, 33 | callback: js.Function1[js.Array[String], _]): Unit = js.native 34 | 35 | def setEnabled(id: AppID, 36 | enabled: Boolean, 37 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 38 | js.native 39 | 40 | def uninstall(id: AppID, 41 | options: js.UndefOr[js.Object] = js.undefined, 42 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 43 | js.native 44 | 45 | def uninstallSelf( 46 | options: js.UndefOr[js.Object] = js.undefined, 47 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native 48 | 49 | def launchApp(id: AppID, 50 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = 51 | js.native 52 | 53 | def createAppShortcut( 54 | id: AppID, 55 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native 56 | 57 | def setLaunchType( 58 | id: AppID, 59 | launchType: LaunchType, 60 | callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native 61 | 62 | def generateAppForLink(url: String, 63 | title: String, 64 | callback: js.UndefOr[js.Function1[ExtensionInfo, _]] = 65 | js.undefined): Unit = js.native 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/management/bindings/ExtensionInfo.scala: -------------------------------------------------------------------------------- 1 | package chrome.management.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait ExtensionInfo extends js.Object { 7 | 8 | val id: String = js.native 9 | val name: String = js.native 10 | val shortName: String = js.native 11 | val description: String = js.native 12 | val version: String = js.native 13 | val mayDisable: Boolean = js.native 14 | val enabled: Boolean = js.native 15 | val disabledReason: js.UndefOr[ExtensionInfo.DisableReason] = js.native 16 | val `type`: ExtensionInfo.Type = js.native 17 | 18 | val homepageUrl: js.UndefOr[String] = js.native 19 | val updateUrl: js.UndefOr[String] = js.native 20 | val offlineEnabled: Boolean = js.native 21 | val optionsUrl: String = js.native 22 | val icons: js.UndefOr[js.Array[IconInfo]] = js.native 23 | val permissions: js.Array[String] = js.native 24 | val hostPermissions: js.Array[String] = js.native 25 | val installType: ExtensionInfo.InstallType = js.native 26 | 27 | //TODO: find a good way to make sure this can only be accessed if we are in a app (maybe using implicits) 28 | val appLaunchUrl: js.UndefOr[String] = js.native 29 | val launchType: js.UndefOr[ExtensionInfo.LaunchType] = js.native 30 | val availableLaunchTypes: js.UndefOr[js.Array[ExtensionInfo.LaunchType]] = 31 | js.native 32 | 33 | } 34 | 35 | object ExtensionInfo { 36 | 37 | type DisableReason = String 38 | type Type = String 39 | type InstallType = String 40 | type LaunchType = String 41 | 42 | object DisableReasons { 43 | 44 | val UNKNOWN: DisableReason = "unknown" 45 | val PERMISSIONS_INCREASE: DisableReason = "permissions_increase" 46 | 47 | } 48 | 49 | object Types { 50 | 51 | val EXTENSION: Type = "extension" 52 | val HOSTED_APP: Type = "hosted_app" 53 | val PACKAGED_APP: Type = "packaged_app" 54 | val LEGACY_PACKAGED_APP: Type = "legacy_packaged_app" 55 | val THEME: Type = "theme" 56 | 57 | } 58 | 59 | object InstallTypes { 60 | 61 | val ADMIN: InstallType = "admin" 62 | val DEVELOPMENT: InstallType = "development" 63 | val NORMAL: InstallType = "normal" 64 | val SIDELOAD: InstallType = "sideload" 65 | val OTHER: InstallType = "other" 66 | 67 | } 68 | 69 | object LaunchTypes { 70 | 71 | val OPEN_AS_REGULAR_TAB: LaunchType = "OPEN_AS_REGULAR_TAB" 72 | val OPEN_AS_PINNED_TAB: LaunchType = "OPEN_AS_PINNED_TAB" 73 | val OPEN_AS_WINDOW: LaunchType = "OPEN_AS_WINDOW" 74 | val OPEN_FULL_SCREEN: LaunchType = "OPEN_FULL_SCREEN" 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/notifications/Notifications.scala: -------------------------------------------------------------------------------- 1 | package chrome.notifications 2 | 3 | import bindings._ 4 | import bindings.Notifications.Id 5 | import chrome.ChromeAPI 6 | import chrome.events.EventSource 7 | import chrome.events.EventSourceImplicits._ 8 | import chrome.utils.ErrorHandling._ 9 | import chrome.permissions.Permission.API 10 | import scala.scalajs.js 11 | import scala.scalajs.js.JSConverters._ 12 | 13 | import scala.concurrent.{Promise, Future} 14 | 15 | object Notifications extends ChromeAPI { 16 | 17 | val requiredPermissions: Set[API] = Set(API.Notifications) 18 | 19 | val onClose: EventSource[(Id, Boolean)] = bindings.Notifications.onClose 20 | val onClicked: EventSource[Id] = bindings.Notifications.onClicked 21 | val onButtonClicked: EventSource[(Id, Int)] = 22 | bindings.Notifications.onButtonClicked 23 | val onPermissionLevelChanged: EventSource[PermissionLevel] = 24 | bindings.Notifications.onPermissionLevelChanged 25 | val onShowSettings: EventSource[Unit] = bindings.Notifications.onShowSettings 26 | 27 | def create(options: NotificationOptions, id: Option[Id] = None): Future[Id] = { 28 | val promise = Promise[Id]() 29 | bindings.Notifications 30 | .create(id.orUndefined, options, js.Any.fromFunction1((id: Id) => { 31 | promise.complete(lastErrorOrValue(id)) 32 | })) 33 | promise.future 34 | } 35 | 36 | def update(id: Id, options: NotificationOptions): Future[Boolean] = { 37 | val promise = Promise[Boolean]() 38 | bindings.Notifications 39 | .update(id, options, js.Any.fromFunction1((wasUpdated: Boolean) => { 40 | promise.complete(lastErrorOrValue(wasUpdated)) 41 | })) 42 | promise.future 43 | } 44 | 45 | def clear(id: Id): Future[Boolean] = { 46 | val promise = Promise[Boolean]() 47 | bindings.Notifications 48 | .clear(id, js.Any.fromFunction1((wasCleared: Boolean) => { 49 | promise.complete(lastErrorOrValue(wasCleared)) 50 | })) 51 | promise.future 52 | } 53 | 54 | def getAll: Future[Map[Id, Boolean]] = { 55 | val promise = Promise[Map[Id, Boolean]]() 56 | bindings.Notifications.getAll((result: Map[Id, Boolean]) => { 57 | promise.complete(lastErrorOrValue(result)) 58 | }) 59 | promise.future 60 | } 61 | 62 | def getPermissionLevel: Future[PermissionLevel] = { 63 | val promise = Promise[PermissionLevel]() 64 | bindings.Notifications.getPermissionLevel((permLevel: PermissionLevel) => { 65 | promise.complete(lastErrorOrValue(permLevel)) 66 | }) 67 | promise.future 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /sbt-plugin/src/main/scala/net/lullabyte/ChromeSbtPlugin.scala: -------------------------------------------------------------------------------- 1 | package net.lullabyte 2 | 3 | import chrome.Manifest 4 | import org.scalajs.sbtplugin.ScalaJSPlugin 5 | import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ 6 | import sbt.Keys._ 7 | import sbt._ 8 | 9 | object ChromeSbtPlugin extends AutoPlugin { 10 | 11 | override def requires: Plugins = ScalaJSPlugin 12 | 13 | object autoImport { 14 | 15 | val chromeUnpackedOpt = TaskKey[File]("chromeUnpackedOpt") 16 | val chromeUnpackedFast = TaskKey[File]("chromeUnpackedFast") 17 | val chromePackage = TaskKey[File]("chromePackage") 18 | val chromeGenerateManifest = TaskKey[File]("chromeGenerateManifest") 19 | val chromeManifest = TaskKey[Manifest]("chromeManifest") 20 | val fullOptJsLib = TaskKey[Attributed[File]]("fullOptJsLib") 21 | val fastOptJsLib = TaskKey[Attributed[File]]("fastOptJsLib") 22 | 23 | private val chromeDir = "chrome" 24 | 25 | lazy val baseSettings: Seq[Def.Setting[_]] = Seq( 26 | fastOptJsLib := (fastOptJS in Compile).value, 27 | chromeUnpackedFast := { 28 | Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-fast")( 29 | (chromeGenerateManifest in Compile).value, 30 | fastOptJsLib.value.data, 31 | (packageJSDependencies in Compile).value, 32 | (resourceDirectories in Compile).value 33 | ) 34 | }, 35 | fullOptJsLib := (fullOptJS in Compile).value, 36 | chromeUnpackedOpt := { 37 | Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-opt")( 38 | (chromeGenerateManifest in Compile).value, 39 | fullOptJsLib.value.data, 40 | (packageMinifiedJSDependencies in Compile).value, 41 | (resourceDirectories in Compile).value 42 | ) 43 | }, 44 | chromePackage := { 45 | val out = target.value / chromeDir 46 | val chromeAppDir = chromeUnpackedOpt.value 47 | val zipFile = new File(out, s"${name.value}.zip") 48 | val excludeFileNames = Set( 49 | ".DS_Store" 50 | ) 51 | val fileFilter = AllPassFilter - new SimpleFilter(excludeFileNames.contains) 52 | IO.zip(Path.selectSubpaths(chromeAppDir, fileFilter), zipFile) 53 | zipFile 54 | }, 55 | chromeGenerateManifest := { 56 | Chrome.generateManifest(target.value / chromeDir / "generated_manifest.json")( 57 | (chromeManifest in Compile).value 58 | ) 59 | } 60 | ) 61 | 62 | } 63 | 64 | 65 | import autoImport._ 66 | 67 | override val projectSettings = baseSettings 68 | 69 | } 70 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/downloads/bindings/InterruptReason.scala: -------------------------------------------------------------------------------- 1 | package chrome.downloads.bindings 2 | 3 | sealed trait InterruptReason 4 | object InterruptReason { 5 | val FILE_FAILED: InterruptReason = "FILE_FAILED".asInstanceOf[InterruptReason] 6 | val FILE_ACCESS_DENIED: InterruptReason = "FILE_ACCESS_DENIED".asInstanceOf[InterruptReason] 7 | val FILE_NO_SPACE: InterruptReason = "FILE_NO_SPACE".asInstanceOf[InterruptReason] 8 | val FILE_NAME_TOO_LONG: InterruptReason = "FILE_NAME_TOO_LONG".asInstanceOf[InterruptReason] 9 | val FILE_TOO_LARGE: InterruptReason = "FILE_TOO_LARGE".asInstanceOf[InterruptReason] 10 | val FILE_VIRUS_INFECTED: InterruptReason = "FILE_VIRUS_INFECTED".asInstanceOf[InterruptReason] 11 | val FILE_TRANSIENT_ERROR: InterruptReason = "FILE_TRANSIENT_ERROR".asInstanceOf[InterruptReason] 12 | val FILE_BLOCKED: InterruptReason = "FILE_BLOCKED".asInstanceOf[InterruptReason] 13 | val FILE_SECURITY_CHECK_FAILED: InterruptReason = "FILE_SECURITY_CHECK_FAILED".asInstanceOf[InterruptReason] 14 | val FILE_TOO_SHORT: InterruptReason = "FILE_TOO_SHORT".asInstanceOf[InterruptReason] 15 | val FILE_HASH_MISMATCH: InterruptReason = "FILE_HASH_MISMATCH".asInstanceOf[InterruptReason] 16 | val NETWORK_FAILED: InterruptReason = "NETWORK_FAILED".asInstanceOf[InterruptReason] 17 | val NETWORK_TIMEOUT: InterruptReason = "NETWORK_TIMEOUT".asInstanceOf[InterruptReason] 18 | val NETWORK_DISCONNECTED: InterruptReason = "NETWORK_DISCONNECTED".asInstanceOf[InterruptReason] 19 | val NETWORK_SERVER_DOWN: InterruptReason = "NETWORK_SERVER_DOWN".asInstanceOf[InterruptReason] 20 | val NETWORK_INVALID_REQUEST: InterruptReason = "NETWORK_INVALID_REQUEST".asInstanceOf[InterruptReason] 21 | val SERVER_FAILED: InterruptReason = "SERVER_FAILED".asInstanceOf[InterruptReason] 22 | val SERVER_NO_RANGE: InterruptReason = "SERVER_NO_RANGE".asInstanceOf[InterruptReason] 23 | val SERVER_BAD_CONTENT: InterruptReason = "SERVER_BAD_CONTENT".asInstanceOf[InterruptReason] 24 | val SERVER_UNAUTHORIZED: InterruptReason = "SERVER_UNAUTHORIZED".asInstanceOf[InterruptReason] 25 | val SERVER_CERT_PROBLEM: InterruptReason = "SERVER_CERT_PROBLEM".asInstanceOf[InterruptReason] 26 | val SERVER_FORBIDDEN: InterruptReason = "SERVER_FORBIDDEN".asInstanceOf[InterruptReason] 27 | val SERVER_UNREACHABLE: InterruptReason = "SERVER_UNREACHABLE".asInstanceOf[InterruptReason] 28 | val USER_CANCELED: InterruptReason = "USER_CANCELED".asInstanceOf[InterruptReason] 29 | val USER_SHUTDOWN: InterruptReason = "USER_SHUTDOWN".asInstanceOf[InterruptReason] 30 | val CRASH: InterruptReason = "CRASH".asInstanceOf[InterruptReason] 31 | } 32 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/pageAction/bindings/PageAction.scala: -------------------------------------------------------------------------------- 1 | package chrome.pageAction.bindings 2 | 3 | import chrome.events.bindings.Event 4 | import chrome.pageAction.bindings.PageAction.ImageDataType 5 | import chrome.tabs.bindings.Tab 6 | 7 | import scala.scalajs.js 8 | import scala.scalajs.js.annotation.JSGlobal 9 | import scala.scalajs.js.| 10 | 11 | @js.native 12 | @JSGlobal("chrome.pageAction") 13 | object PageAction extends js.Object { 14 | 15 | type ImageDataType = org.scalajs.dom.ImageData 16 | 17 | val onClicked: Event[js.Function1[Tab, _]] = js.native 18 | 19 | def show(tabId: Tab.Id): Unit = js.native 20 | 21 | def hide(tabId: Tab.Id): Unit = js.native 22 | 23 | def setTitle(details: SetTitleDetails): Unit = js.native 24 | 25 | def getTitle( 26 | details: GetTitleDetails, 27 | callback: js.Function1[String, _]): Unit = 28 | js.native 29 | 30 | def setIcon( 31 | details: SetIconDetails, 32 | callback: js.Function0[_]): Unit = 33 | js.native 34 | 35 | def setPopup(details: SetPopupDetails): Unit = js.native 36 | 37 | def getPopup( 38 | details: GetPopupDetails, 39 | callback: js.Function1[String, _]): Unit = 40 | js.native 41 | } 42 | 43 | class GetPopupDetails(val tabId: Tab.Id) extends js.Object 44 | 45 | object GetPopupDetails { 46 | 47 | def apply(tabId: Tab.Id): GetPopupDetails = 48 | new GetPopupDetails(tabId) 49 | } 50 | 51 | class GetTitleDetails(val tabId: Tab.Id) extends js.Object 52 | 53 | object GetTitleDetails { 54 | 55 | def apply(tabId: Tab.Id): GetTitleDetails = 56 | new GetTitleDetails(tabId) 57 | } 58 | 59 | class SetIconDetails( 60 | val tabId: Tab.Id, 61 | val imageData: js.UndefOr[ImageDataType | js.Dictionary[ImageDataType]], 62 | val path: js.UndefOr[String | js.Dictionary[String]] 63 | ) extends js.Object 64 | 65 | object SetIconDetails { 66 | 67 | def apply( 68 | tabId: Tab.Id, 69 | imageData: js.UndefOr[ImageDataType | js.Dictionary[ImageDataType]] = js.undefined, 70 | path: js.UndefOr[String | js.Dictionary[String]] = js.undefined 71 | ): SetIconDetails = new SetIconDetails(tabId, imageData, path) 72 | } 73 | 74 | class SetPopupDetails(val tabId: Tab.Id, val popup: String) extends js.Object 75 | 76 | object SetPopupDetails { 77 | 78 | def apply(tabId: Tab.Id, popup: String): SetPopupDetails = 79 | new SetPopupDetails(tabId, popup) 80 | } 81 | 82 | class SetTitleDetails(val tabId: Tab.Id, val title: String) extends js.Object 83 | 84 | object SetTitleDetails { 85 | 86 | def apply(tabId: Tab.Id, title: String): SetTitleDetails = 87 | new SetTitleDetails(tabId, title) 88 | } 89 | 90 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webRequest/bindings/BlockingResponse.scala: -------------------------------------------------------------------------------- 1 | package chrome.webRequest.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | object BlockingResponse { 6 | def apply(cancel: js.UndefOr[Boolean] = js.undefined, 7 | redirectUrl: js.UndefOr[String] = js.undefined, 8 | responseHeaders: js.UndefOr[js.Array[HttpHeader]] = js.undefined, 9 | authCredentials: js.UndefOr[AuthCredentials] = js.undefined, 10 | requestHeaders: js.UndefOr[js.Array[HttpHeader]] = js.undefined): BlockingResponse = { 11 | js.Dynamic.literal( 12 | cancel = cancel, 13 | redirectUrl = redirectUrl, 14 | responseHeaders = responseHeaders, 15 | authCredentials = authCredentials, 16 | requestHeaders = requestHeaders 17 | ).asInstanceOf[BlockingResponse] 18 | } 19 | } 20 | 21 | @js.native 22 | trait BlockingResponse extends js.Object { 23 | /** 24 | * Optional: 25 | * If true, the request is cancelled. Used in onBeforeRequest, this prevents the request from being sent. 26 | */ 27 | val cancel: js.UndefOr[Boolean] = js.native 28 | 29 | /** 30 | * Optional: 31 | * Only used as a response to the onBeforeRequest and onHeadersReceived events. If set, the original request is 32 | * prevented from being sent/completed and is instead redirected to the given URL. Redirections to non-HTTP 33 | * schemes such as data: are allowed. Redirects initiated by a redirect action use the original request method 34 | * for the redirect, with one exception: If the redirect is initiated at the onHeadersReceived stage, then the 35 | * redirect will be issued using the GET method. 36 | */ 37 | val redirectUrl: js.UndefOr[String] = js.native 38 | 39 | /** 40 | * Optional: 41 | * Only used as a response to the onHeadersReceived event. If set, the server is assumed to have responded with these 42 | * response headers instead. Only return responseHeaders if you really want to modify the headers in order to limit 43 | * the number of conflicts (only one extension may modify responseHeaders for each request). 44 | */ 45 | val responseHeaders: js.UndefOr[js.Array[HttpHeader]] = js.native 46 | 47 | /** 48 | * Optional: 49 | * Only used as a response to the onAuthRequired event. If set, the request is made using the supplied credentials. 50 | */ 51 | val authCredentials: js.UndefOr[AuthCredentials] = js.native 52 | 53 | /** 54 | * Optional: 55 | * Only used as a response to the onBeforeSendHeaders event. If set, the request is made with these request headers 56 | * instead. 57 | */ 58 | val requestHeaders: js.UndefOr[js.Array[HttpHeader]] = js.native 59 | } 60 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/events/EventSourceImplicits.scala: -------------------------------------------------------------------------------- 1 | package chrome.events 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | 7 | class EventSource0Impl(event: Event[js.Function0[_]]) 8 | extends EventSource[Unit] { 9 | 10 | class SubscriptionImpl(fn: Unit => Unit) extends Subscription { 11 | 12 | val fn2 = js.Any.fromFunction0(() => fn(())) 13 | 14 | event.addListener(fn2) 15 | 16 | def cancel(): Unit = { 17 | event.removeListener(fn2) 18 | } 19 | 20 | } 21 | 22 | def listen(fn: Unit => Unit): Subscription = { 23 | new SubscriptionImpl(fn) 24 | } 25 | 26 | } 27 | 28 | class EventSource1Impl[A](event: Event[js.Function1[A, _]]) 29 | extends EventSource[A] { 30 | 31 | class SubscriptionImpl(fn: A => Unit) extends Subscription { 32 | 33 | event.addListener(fn) 34 | 35 | def cancel(): Unit = { 36 | event.removeListener(fn) 37 | } 38 | 39 | } 40 | 41 | def listen(fn: A => Unit): Subscription = { 42 | new SubscriptionImpl(fn) 43 | } 44 | 45 | } 46 | 47 | class EventSource2Impl[A, B](event: Event[js.Function2[A, B, _]]) 48 | extends EventSource[(A, B)] { 49 | 50 | class SubscriptionImpl(fn: ((A, B)) => Unit) extends Subscription { 51 | 52 | val untupled = Function.untupled(fn) 53 | 54 | event.addListener(untupled) 55 | 56 | def cancel(): Unit = { 57 | event.removeListener(untupled) 58 | } 59 | 60 | } 61 | 62 | def listen(fn: ((A, B)) => Unit): Subscription = { 63 | new SubscriptionImpl(fn) 64 | } 65 | 66 | } 67 | 68 | class EventSource3Impl[A, B, C](event: Event[js.Function3[A, B, C, _]]) 69 | extends EventSource[(A, B, C)] { 70 | 71 | class SubscriptionImpl(fn: ((A, B, C)) => Unit) extends Subscription { 72 | 73 | val untupled = Function.untupled(fn) 74 | 75 | event.addListener(untupled) 76 | 77 | def cancel(): Unit = { 78 | event.removeListener(untupled) 79 | } 80 | 81 | } 82 | 83 | def listen(fn: ((A, B, C)) => Unit): Subscription = { 84 | new SubscriptionImpl(fn) 85 | } 86 | 87 | } 88 | 89 | object EventSourceImplicits { 90 | 91 | import scala.language.implicitConversions 92 | 93 | implicit def eventAsEventSource0( 94 | event: Event[js.Function0[_]]): EventSource[Unit] = 95 | new EventSource0Impl(event) 96 | implicit def eventAsEventSource1[A]( 97 | event: Event[js.Function1[A, _]]): EventSource[A] = 98 | new EventSource1Impl(event) 99 | implicit def eventAsEventSource2[A, B]( 100 | event: Event[js.Function2[A, B, _]]): EventSource[(A, B)] = 101 | new EventSource2Impl(event) 102 | implicit def eventAsEventSource3[A, B, C]( 103 | event: Event[js.Function3[A, B, C, _]]): EventSource[(A, B, C)] = 104 | new EventSource3Impl(event) 105 | 106 | } 107 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/windows/Windows.scala: -------------------------------------------------------------------------------- 1 | package chrome.windows 2 | 3 | import bindings._ 4 | import chrome.events.EventSource 5 | import chrome.events.EventSourceImplicits._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Promise, Future} 9 | import scala.scalajs.js 10 | 11 | object Windows { 12 | 13 | val WINDOW_ID_NONE: Window.Id = bindings.Windows.WINDOW_ID_NONE 14 | val WINDOW_ID_CURRENT: Window.Id = bindings.Windows.WINDOW_ID_CURRENT 15 | 16 | val onCreated: EventSource[Window] = bindings.Windows.onCreated 17 | val onRemoved: EventSource[Window.Id] = bindings.Windows.onRemoved 18 | val onFocusChanged: EventSource[Window.Id] = bindings.Windows.onFocusChanged 19 | 20 | def get(windowId: Window.Id, 21 | getInfo: js.UndefOr[GetOptions] = js.undefined): Future[Window] = { 22 | val promise = Promise[Window]() 23 | bindings.Windows.get(windowId, getInfo, (window: Window) => { 24 | promise.complete(lastErrorOrValue(window)) 25 | }) 26 | promise.future 27 | } 28 | 29 | def getCurrent( 30 | getInfo: js.UndefOr[GetOptions] = js.undefined): Future[Window] = { 31 | val promise = Promise[Window]() 32 | bindings.Windows.getCurrent(getInfo, (window: Window) => { 33 | promise.complete(lastErrorOrValue(window)) 34 | }) 35 | promise.future 36 | } 37 | 38 | def getLastFocused( 39 | getInfo: js.UndefOr[GetOptions] = js.undefined): Future[Window] = { 40 | val promise = Promise[Window]() 41 | bindings.Windows.getLastFocused(getInfo, (window: Window) => { 42 | promise.complete(lastErrorOrValue(window)) 43 | }) 44 | promise.future 45 | } 46 | 47 | def getAll( 48 | getInfo: js.UndefOr[GetOptions] = js.undefined): Future[List[Window]] = { 49 | val promise = Promise[List[Window]]() 50 | bindings.Windows.getAll(getInfo, (windows: js.Array[Window]) => { 51 | promise.complete(lastErrorOrValue(windows.toList)) 52 | }) 53 | promise.future 54 | } 55 | 56 | def create(createData: js.UndefOr[CreateOptions]): Future[Option[Window]] = { 57 | val promise = Promise[Option[Window]]() 58 | bindings.Windows.create( 59 | createData, 60 | js.Any.fromFunction1((window: js.UndefOr[Window]) => { 61 | promise.complete(lastErrorOrValue(window.toOption)) 62 | })) 63 | promise.future 64 | } 65 | 66 | def update(windowId: Window.Id, updateInfo: UpdateOptions): Future[Window] = { 67 | val promise = Promise[Window]() 68 | bindings.Windows 69 | .update(windowId, updateInfo, js.Any.fromFunction1((window: Window) => { 70 | promise.complete(lastErrorOrValue(window)) 71 | })) 72 | promise.future 73 | } 74 | 75 | def remove(windowId: Window.Id): Future[Unit] = { 76 | val promise = Promise[Unit]() 77 | bindings.Windows.remove(windowId, js.Any.fromFunction0(() => { 78 | promise.complete(lastErrorOrValue(())) 79 | })) 80 | promise.future 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/sockets/tcpServer/TCPServer.scala: -------------------------------------------------------------------------------- 1 | package chrome.sockets.tcpServer 2 | 3 | import chrome.events.EventSource 4 | import chrome.events.EventSourceImplicits._ 5 | import chrome.sockets.tcpServer.bindings._ 6 | import chrome.utils.ErrorHandling._ 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | 11 | object TCPServer { 12 | 13 | val onAccept: EventSource[AcceptEvent] = bindings.TCPServer.onAccept 14 | val onAcceptError: EventSource[AcceptErrorEvent] = 15 | bindings.TCPServer.onAcceptError 16 | 17 | def create(properties: js.UndefOr[SocketProperties] = js.undefined) 18 | : Future[CreateInfo] = { 19 | val promise = Promise[CreateInfo]() 20 | bindings.TCPServer.create(properties, (info: CreateInfo) => { 21 | promise.complete(lastErrorOrValue(info)) 22 | }) 23 | promise.future 24 | } 25 | 26 | def update(socketId: SocketId, properties: SocketProperties): Future[Unit] = { 27 | val promise = Promise[Unit]() 28 | bindings.TCPServer 29 | .update(socketId, properties, js.Any.fromFunction0(() => { 30 | promise.complete(lastErrorOrValue(())) 31 | })) 32 | promise.future 33 | } 34 | 35 | def setPaused(socketId: SocketId, paused: Boolean): Future[Unit] = { 36 | val promise = Promise[Unit]() 37 | bindings.TCPServer.setPaused(socketId, paused, js.Any.fromFunction0(() => { 38 | promise.complete(lastErrorOrValue(())) 39 | })) 40 | promise.future 41 | } 42 | 43 | def listen(socketId: SocketId, 44 | address: String, 45 | port: Int, 46 | backlog: js.UndefOr[Int] = js.undefined): Future[Int] = { 47 | val promise = Promise[Int]() 48 | bindings.TCPServer 49 | .listen(socketId, address, port, backlog, (result: Int) => { 50 | promise.complete(lastErrorOrValue(result)) 51 | }) 52 | promise.future 53 | } 54 | 55 | def disconnect(socketId: SocketId): Future[Unit] = { 56 | val promise = Promise[Unit]() 57 | bindings.TCPServer.disconnect(socketId, js.Any.fromFunction0(() => { 58 | promise.complete(lastErrorOrValue(())) 59 | })) 60 | promise.future 61 | } 62 | 63 | def close(socketId: SocketId): Future[Unit] = { 64 | val promise = Promise[Unit]() 65 | bindings.TCPServer.close(socketId, js.Any.fromFunction0(() => { 66 | promise.complete(lastErrorOrValue(())) 67 | })) 68 | promise.future 69 | } 70 | 71 | def getInfo(socketId: SocketId): Future[SocketInfo] = { 72 | val promise = Promise[SocketInfo]() 73 | bindings.TCPServer.getInfo(socketId, (info: SocketInfo) => { 74 | promise.complete(lastErrorOrValue(info)) 75 | }) 76 | promise.future 77 | } 78 | 79 | def getSockets: Future[js.Array[SocketInfo]] = { 80 | val promise = Promise[js.Array[SocketInfo]]() 81 | bindings.TCPServer.getSockets((info: js.Array[SocketInfo]) => { 82 | promise.complete(lastErrorOrValue(info)) 83 | }) 84 | promise.future 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/notifications/bindings/NotificationOptions.scala: -------------------------------------------------------------------------------- 1 | package chrome.notifications.bindings 2 | 3 | import scala.scalajs.js 4 | 5 | @js.native 6 | trait NotificationOptions extends js.Object { 7 | 8 | val `type`: js.UndefOr[TemplateType] = js.native 9 | val iconUrl: js.UndefOr[String] = js.native 10 | val appIconMaskUrl: js.UndefOr[String] = js.native 11 | val title: js.UndefOr[String] = js.native 12 | val message: js.UndefOr[String] = js.native 13 | val contextMessage: js.UndefOr[String] = js.native 14 | val priority: js.UndefOr[Int] = js.native 15 | val eventTime: js.UndefOr[Double] = js.native 16 | val buttons: js.UndefOr[js.Array[Button]] = js.native 17 | val imageUrl: js.UndefOr[String] = js.native 18 | val items: js.UndefOr[js.Array[Item]] = js.native 19 | val progress: js.UndefOr[Int] = js.native 20 | val isClickable: js.UndefOr[Boolean] = js.native 21 | 22 | } 23 | 24 | object NotificationOptions { 25 | def apply( 26 | `type`: js.UndefOr[TemplateType] = js.undefined, 27 | iconUrl: js.UndefOr[String] = js.undefined, 28 | appIconMaskUrl: js.UndefOr[String] = js.undefined, 29 | title: js.UndefOr[String] = js.undefined, 30 | message: js.UndefOr[String] = js.undefined, 31 | contextMessage: js.UndefOr[String] = js.undefined, 32 | priority: js.UndefOr[Int] = js.undefined, 33 | eventTime: js.UndefOr[Double] = js.undefined, 34 | buttons: js.UndefOr[js.Array[Button]] = js.undefined, 35 | imageUrl: js.UndefOr[String] = js.undefined, 36 | items: js.UndefOr[js.Array[Item]] = js.undefined, 37 | progress: js.UndefOr[Int] = js.undefined, 38 | isClickable: js.UndefOr[Boolean] = js.undefined): NotificationOptions = { 39 | js.Dynamic 40 | .literal( 41 | `type` = `type`, 42 | iconUrl = iconUrl, 43 | appIconMaskUrl = appIconMaskUrl, 44 | title = title, 45 | message = message, 46 | contextMessage = contextMessage, 47 | priority = priority, 48 | eventTime = eventTime, 49 | buttons = buttons, 50 | imageUrl = imageUrl, 51 | items = items, 52 | progress = progress, 53 | isClickable = isClickable 54 | ) 55 | .asInstanceOf[NotificationOptions] 56 | } 57 | } 58 | 59 | @js.native 60 | trait Button extends js.Object { 61 | val title: String = js.native 62 | val iconUrl: js.UndefOr[String] = js.native 63 | } 64 | 65 | object Button { 66 | 67 | def apply(title: String, 68 | iconUrl: js.UndefOr[String] = js.undefined): Button = { 69 | js.Dynamic 70 | .literal( 71 | title = title, 72 | iconUrl = iconUrl 73 | ) 74 | .asInstanceOf[Button] 75 | } 76 | 77 | } 78 | 79 | @js.native 80 | trait Item extends js.Object { 81 | val title: String = js.native 82 | val message: String = js.native 83 | } 84 | 85 | object Item { 86 | 87 | def apply(title: String, message: String): Item = { 88 | js.Dynamic 89 | .literal( 90 | title = title, 91 | message = message 92 | ) 93 | .asInstanceOf[Item] 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/contextMenus/bindings/ContextMenus.scala: -------------------------------------------------------------------------------- 1 | package chrome.contextMenus.bindings 2 | 3 | import chrome.events.bindings.Event 4 | import chrome.tabs.bindings.Tab 5 | 6 | import scala.scalajs.js 7 | import scala.scalajs.js.annotation.JSGlobal 8 | import scala.scalajs.js.| 9 | 10 | object MenuContexts { 11 | val ALL = "all" 12 | val PAGE = "page" 13 | val FRAME = "frame" 14 | val SELECTION = "selection" 15 | val LINKE = "link" 16 | val EDITABLE = "editable" 17 | val IMAGE = "image" 18 | val VIDEO = "video" 19 | val AUDIO = "audio" 20 | val LAUNCHER = "launcher" 21 | val BROWSER_ACTION = "browser_action" 22 | val PAGE_ACTION = "page_action" 23 | } 24 | 25 | object MenuType { 26 | val NORMAL = "normal" 27 | val CHECKBOX = "checkbox" 28 | val RADIO = "radio" 29 | val SEPARATOR = "separator" 30 | } 31 | 32 | @js.native 33 | @JSGlobal("chrome.contextMenus") 34 | object ContextMenus extends js.Object { 35 | 36 | def create(createProperties: CreateProperties): String | Int = js.native 37 | 38 | def update(id: String | Int, properties: UpdateProperties): Unit = js.native 39 | 40 | def remove(menuItemId: String | Int, 41 | callback: js.Function0[Unit]): String | Int = js.native 42 | 43 | def removeAll(callback: js.Function0[Unit]): Unit = js.native 44 | 45 | val onClicked: Event[js.Function2[MenuInfo, Tab, _]] = js.native 46 | 47 | } 48 | 49 | class UpdateProperties( 50 | val `type`: String = MenuType.NORMAL, 51 | val title: String, 52 | val checked: js.UndefOr[Boolean] = js.undefined, 53 | val contexts: js.UndefOr[js.Array[String]] = js.undefined, 54 | val onclick: js.UndefOr[js.Function2[MenuInfo, Tab, Unit]], 55 | val parentId: js.UndefOr[String | Int] = js.undefined, 56 | val documentUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined, 57 | val targetUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined, 58 | val enabled: Boolean = true 59 | ) extends js.Object 60 | 61 | object CreateProperties { 62 | 63 | def apply(id: String, 64 | title: String, 65 | contexts: js.Array[String] = js.Array(MenuContexts.ALL)) 66 | : CreateProperties = 67 | new CreateProperties(id = id, title = title, contexts = contexts) 68 | } 69 | 70 | class CreateProperties( 71 | val `type`: String = MenuType.NORMAL, 72 | val id: String | Int, 73 | val title: String, 74 | val checked: js.UndefOr[Boolean] = js.undefined, 75 | val contexts: js.UndefOr[js.Array[String]] = js.undefined, 76 | val onclick: js.UndefOr[js.Function2[MenuInfo, Tab, Unit]] = js.undefined, 77 | val parentId: js.UndefOr[String | Int] = js.undefined, 78 | val documentUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined, 79 | val targetUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined, 80 | val enabled: Boolean = true 81 | ) extends js.Object 82 | 83 | @js.native 84 | trait MenuInfo extends js.Object { 85 | val menuItemId: String | Int = js.native 86 | val parentMenuItemId: js.UndefOr[String | Int] 87 | val mediaType: js.UndefOr[String] 88 | val linkUrl: js.UndefOr[String] 89 | val srcUrl: js.UndefOr[String] 90 | val pageUrl: js.UndefOr[String] 91 | val frameUrl: js.UndefOr[String] 92 | val selectionText: js.UndefOr[String] 93 | val editable: Boolean 94 | val wasChecked: js.UndefOr[Boolean] 95 | val checked: js.UndefOr[Boolean] 96 | } 97 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/permissions/Permissions.scala: -------------------------------------------------------------------------------- 1 | package chrome.permissions 2 | 3 | import chrome.events.EventSource 4 | import chrome.events.EventSourceImplicits._ 5 | import chrome.permissions.bindings._ 6 | import chrome.permissions.Permission.{Host, API} 7 | import chrome.utils.ErrorHandling._ 8 | 9 | import scala.concurrent.{Future, Promise} 10 | import scala.scalajs.js 11 | 12 | object Permissions { 13 | 14 | implicit class PermissionOps(val permission: Permission) extends AnyVal { 15 | def granted: Future[Boolean] = Permissions.contains(permission) 16 | def request: Future[Boolean] = Permissions.request(permission) 17 | def drop: Future[Boolean] = Permissions.remove(permission) 18 | } 19 | 20 | val onAdded: EventSource[PermissionList] = bindings.Permissions.onAdded 21 | val onRemoved: EventSource[PermissionList] = bindings.Permissions.onRemoved 22 | 23 | def getAll: Future[js.Array[Permission]] = { 24 | val promise = Promise[js.Array[Permission]]() 25 | bindings.Permissions.getAll((perms: PermissionList) => { 26 | promise.complete(lastErrorOrValue({ 27 | val apiPerms = for { 28 | perm <- perms.permissions.getOrElse(js.Array()) 29 | result <- permissionFromString(perm) 30 | } yield result 31 | 32 | val hostPerms = for { 33 | pattern <- perms.origins.getOrElse(js.Array()) 34 | } yield new Host(pattern) 35 | 36 | apiPerms ++ hostPerms 37 | })) 38 | }) 39 | promise.future 40 | } 41 | 42 | def permissionFromString(perm: String): Option[Permission] = { 43 | API.All.get(perm).orElse(Some(Host(perm))) 44 | } 45 | 46 | def contains(permissions: Permission*): Future[Boolean] = { 47 | val promise = Promise[Boolean]() 48 | val (api, host) = permissions2PermissionList(permissions) 49 | bindings.Permissions 50 | .contains(PermissionList(api, host), (result: Boolean) => { 51 | promise.complete(lastErrorOrValue(result)) 52 | }) 53 | promise.future 54 | } 55 | 56 | private def permissions2PermissionList[A <: Seq[Permission]]( 57 | permissions: A): (js.Array[String], js.Array[String]) = { 58 | permissions.foldLeft((js.Array[String](), js.Array[String]())) { 59 | (acc, p) => 60 | p match { 61 | case api: API => acc._1.append(api.name) 62 | case host: Host => acc._2.append(host.urlPattern) 63 | } 64 | acc 65 | } 66 | } 67 | 68 | def request(permissions: Permission*): Future[Boolean] = { 69 | val promise = Promise[Boolean]() 70 | val (api, host) = permissions2PermissionList(permissions) 71 | bindings.Permissions.request(PermissionList(api, host), 72 | js.Any.fromFunction1((result: Boolean) => { 73 | promise.complete(lastErrorOrValue(result)) 74 | })) 75 | promise.future 76 | } 77 | 78 | def remove(permissions: Permission*): Future[Boolean] = { 79 | val promise = Promise[Boolean]() 80 | val (api, host) = permissions2PermissionList(permissions) 81 | bindings.Permissions.remove(PermissionList(api, host), 82 | js.Any.fromFunction1((result: Boolean) => { 83 | promise.complete(lastErrorOrValue(result)) 84 | })) 85 | promise.future 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/browserAction/BrowserAction.scala: -------------------------------------------------------------------------------- 1 | package chrome.browserAction 2 | 3 | import chrome.browserAction.bindings._ 4 | import chrome.events.bindings.Event 5 | import chrome.tabs.bindings.Tab 6 | import org.scalajs.dom.ImageData 7 | 8 | import scala.concurrent.{Future, Promise} 9 | import scala.scalajs.js 10 | import scala.scalajs.js.| 11 | 12 | object BrowserAction { 13 | val onClicked: Event[js.Function1[Tab, _]] = bindings.BrowserAction.onClicked 14 | 15 | def setTitle(title: String, tabId: js.UndefOr[Int] = js.undefined): Unit = { 16 | bindings.BrowserAction.setTitle(TitleDetails(title, tabId)) 17 | } 18 | 19 | def getTitle(tabId: js.UndefOr[Int] = js.undefined): Future[String] = { 20 | val promise = Promise[String]() 21 | bindings.BrowserAction.getTitle(TabIdDetails(tabId), (result: String) => { 22 | promise.success(result) 23 | }) 24 | promise.future 25 | } 26 | 27 | def setIconImageData(imageData: js.UndefOr[ImageData | js.Dictionary[ImageData]], 28 | tabId: js.UndefOr[Int] = js.undefined): Future[Unit] = { 29 | setIcon(imageData, js.undefined, tabId) 30 | } 31 | 32 | def setIconPath(pathData: js.UndefOr[String | js.Dictionary[String]], 33 | tabId: js.UndefOr[Int] = js.undefined): Future[Unit] = { 34 | setIcon(js.undefined, pathData, tabId) 35 | } 36 | 37 | def setIcon(imageData: js.UndefOr[ImageData | js.Dictionary[ImageData]], 38 | pathData: js.UndefOr[String | js.Dictionary[String]], 39 | tabId: js.UndefOr[Int]): Future[Unit] = { 40 | val promise = Promise[Unit]() 41 | bindings.BrowserAction.setIcon(IconDetails(imageData, pathData, tabId), () => { 42 | promise.success(()) 43 | }) 44 | 45 | promise.future 46 | } 47 | 48 | def setPopup(popup: String, tabId: js.UndefOr[Int] = js.undefined): Unit = { 49 | bindings.BrowserAction.setPopup(PopupDetails(popup, tabId)) 50 | } 51 | 52 | def getPopup(tabId: js.UndefOr[Int] = js.undefined): Future[String] = { 53 | val promise = Promise[String]() 54 | bindings.BrowserAction.getPopup(TabIdDetails(tabId), (result: String) => { 55 | promise.success(result) 56 | }) 57 | promise.future 58 | } 59 | 60 | def setBadgeText(text: String, tabId: js.UndefOr[Int] = js.undefined): Unit = { 61 | bindings.BrowserAction.setBadgeText(BadgeTextDetails(text, tabId)) 62 | } 63 | 64 | def getBadgeText(tabId: js.UndefOr[Int] = js.undefined): Future[String] = { 65 | val promise = Promise[String]() 66 | bindings.BrowserAction.getBadgeText(TabIdDetails(tabId), (result: String) => { 67 | promise.success(result) 68 | }) 69 | promise.future 70 | } 71 | 72 | def setBadgeBackgroundColor(color: String | js.Array[Int]): Unit = { 73 | bindings.BrowserAction.setBadgeBackgroundColor(BadgeBackgroundColorDetails(color)) 74 | } 75 | 76 | def getBadgeBackgroundColor(tabId: js.UndefOr[Int] = js.undefined): Future[js.Array[Int]] = { 77 | val promise = Promise[js.Array[Int]]() 78 | bindings.BrowserAction.getBadgeBackgroundColor(TabIdDetails(tabId), (result: js.Array[Int]) => { 79 | promise.success(result) 80 | }) 81 | promise.future 82 | } 83 | 84 | def enable(tabId: js.UndefOr[Int]): Unit = { 85 | bindings.BrowserAction.enable(tabId) 86 | } 87 | 88 | def disable(tabId: js.UndefOr[Int]): Unit = { 89 | bindings.BrowserAction.disable(tabId) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /bindings/src/main/scala/chrome/webNavigation/bindings/WebNavigation.scala: -------------------------------------------------------------------------------- 1 | package chrome.webNavigation.bindings 2 | 3 | import chrome.events.bindings.Event 4 | 5 | import scala.scalajs.js 6 | import scala.scalajs.js.annotation.JSGlobal 7 | import scala.scalajs.js.native 8 | 9 | /** 10 | * @see chrome.webNavigation API 11 | */ 12 | @js.native 13 | @JSGlobal("chrome.webNavigation") 14 | object WebNavigation extends js.Object { 15 | 16 | /** 17 | * Fired when a navigation is about to occur. 18 | */ 19 | val onBeforeNavigate: Event[js.Function1[OnBeforeNavigateDetails, _]] = native 20 | /** 21 | * Fired when a navigation is committed. The document (and the resources it refers to, such as images and subframes) 22 | * might still be downloading, but at least part of the document has been received from the server and the browser 23 | * has decided to switch to the new document. 24 | */ 25 | val onCommitted: Event[js.Function1[OnCommittedDetails, _]] = native 26 | /** 27 | * Fired when the page's DOM is fully constructed, but the referenced resources may not finish loading. 28 | */ 29 | val onDOMContentLoaded: Event[js.Function1[OnDOMContentLoadedDetails, _]] = native 30 | /** 31 | * Fired when a document, including the resources it refers to, is completely loaded and initialized. 32 | */ 33 | val onCompleted: Event[js.Function1[OnCompletedDetails, _]] = native 34 | /** 35 | * Fired when an error occurs and the navigation is aborted. This can happen if either a network error occurred, or 36 | * the user aborted the navigation. 37 | */ 38 | val onErrorOccurred: Event[js.Function1[OnErrorOccurredDetails, _]] = native 39 | /** 40 | * Fired when a new window, or a new tab in an existing window, is created to host a navigation. 41 | */ 42 | val onCreatedNavigationTarget: Event[js.Function1[OnCreatedNavigationTargetDetails, _]] = native 43 | /** 44 | * Fired when the reference fragment of a frame was updated. 45 | * All future events for that frame will use the updated URL. 46 | */ 47 | val onReferenceFragmentUpdated: Event[js.Function1[OnCommittedDetails, _]] = native 48 | /** 49 | * Fired when the contents of the tab is replaced by a different (usually previously pre-rendered) tab. 50 | */ 51 | val onTabReplaced: Event[js.Function1[OnTabReplacedDetails, _]] = native 52 | /** 53 | * Fired when the frame's history was updated to a new URL. 54 | * All future events for that frame will use the updated URL. 55 | */ 56 | val onHistoryStateUpdated: Event[js.Function1[OnCommittedDetails, _]] = native 57 | 58 | /** 59 | * Retrieves information about the given frame. A frame refers to an