{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

/No description available in the introspection data./
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.WebKit2WebExtension.Objects.ScriptWorld
    (

-- * Exported types
    ScriptWorld(..)                         ,
    IsScriptWorld                           ,
    toScriptWorld                           ,
    noScriptWorld                           ,


 -- * Methods
-- ** getDefault #method:getDefault#

    scriptWorldGetDefault                   ,


-- ** getName #method:getName#

#if ENABLE_OVERLOADING
    ScriptWorldGetNameMethodInfo            ,
#endif
    scriptWorldGetName                      ,


-- ** new #method:new#

    scriptWorldNew                          ,


-- ** newWithName #method:newWithName#

    scriptWorldNewWithName                  ,




 -- * Signals
-- ** windowObjectCleared #signal:windowObjectCleared#

    C_ScriptWorldWindowObjectClearedCallback,
    ScriptWorldWindowObjectClearedCallback  ,
#if ENABLE_OVERLOADING
    ScriptWorldWindowObjectClearedSignalInfo,
#endif
    afterScriptWorldWindowObjectCleared     ,
    genClosure_ScriptWorldWindowObjectCleared,
    mk_ScriptWorldWindowObjectClearedCallback,
    noScriptWorldWindowObjectClearedCallback,
    onScriptWorldWindowObjectCleared        ,
    wrap_ScriptWorldWindowObjectClearedCallback,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.WebKit2WebExtension.Objects.Frame as WebKit2WebExtension.Frame
import {-# SOURCE #-} qualified GI.WebKit2WebExtension.Objects.WebPage as WebKit2WebExtension.WebPage

-- | Memory-managed wrapper type.
newtype ScriptWorld = ScriptWorld (ManagedPtr ScriptWorld)
foreign import ccall "webkit_script_world_get_type"
    c_webkit_script_world_get_type :: IO GType

instance GObject ScriptWorld where
    gobjectType = c_webkit_script_world_get_type


-- | Type class for types which can be safely cast to `ScriptWorld`, for instance with `toScriptWorld`.
class (GObject o, O.IsDescendantOf ScriptWorld o) => IsScriptWorld o
instance (GObject o, O.IsDescendantOf ScriptWorld o) => IsScriptWorld o

instance O.HasParentTypes ScriptWorld
type instance O.ParentTypes ScriptWorld = '[GObject.Object.Object]

-- | Cast to `ScriptWorld`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toScriptWorld :: (MonadIO m, IsScriptWorld o) => o -> m ScriptWorld
toScriptWorld = liftIO . unsafeCastTo ScriptWorld

-- | A convenience alias for `Nothing` :: `Maybe` `ScriptWorld`.
noScriptWorld :: Maybe ScriptWorld
noScriptWorld = Nothing

#if ENABLE_OVERLOADING
type family ResolveScriptWorldMethod (t :: Symbol) (o :: *) :: * where
    ResolveScriptWorldMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveScriptWorldMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveScriptWorldMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveScriptWorldMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveScriptWorldMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveScriptWorldMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveScriptWorldMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveScriptWorldMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveScriptWorldMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveScriptWorldMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveScriptWorldMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveScriptWorldMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveScriptWorldMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveScriptWorldMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveScriptWorldMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveScriptWorldMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveScriptWorldMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveScriptWorldMethod "getName" o = ScriptWorldGetNameMethodInfo
    ResolveScriptWorldMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveScriptWorldMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveScriptWorldMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveScriptWorldMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveScriptWorldMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveScriptWorldMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveScriptWorldMethod t ScriptWorld, O.MethodInfo info ScriptWorld p) => OL.IsLabel t (ScriptWorld -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

-- signal ScriptWorld::window-object-cleared
{- |
Emitted when the JavaScript window object in a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' has been
cleared. This is the preferred place to set custom properties on the window
object using the JavaScriptCore API. You can get the window object of /@frame@/
from the JavaScript execution context of /@world@/ that is returned by
@/webkit_frame_get_javascript_context_for_script_world()/@.

/Since: 2.2/
-}
type ScriptWorldWindowObjectClearedCallback =
    WebKit2WebExtension.WebPage.WebPage
    {- ^ /@page@/: a 'GI.WebKit2WebExtension.Objects.WebPage.WebPage' -}
    -> WebKit2WebExtension.Frame.Frame
    {- ^ /@frame@/: the 'GI.WebKit2WebExtension.Objects.Frame.Frame'  to which /@world@/ belongs -}
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ScriptWorldWindowObjectClearedCallback`@.
noScriptWorldWindowObjectClearedCallback :: Maybe ScriptWorldWindowObjectClearedCallback
noScriptWorldWindowObjectClearedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_ScriptWorldWindowObjectClearedCallback =
    Ptr () ->                               -- object
    Ptr WebKit2WebExtension.WebPage.WebPage ->
    Ptr WebKit2WebExtension.Frame.Frame ->
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_ScriptWorldWindowObjectClearedCallback`.
foreign import ccall "wrapper"
    mk_ScriptWorldWindowObjectClearedCallback :: C_ScriptWorldWindowObjectClearedCallback -> IO (FunPtr C_ScriptWorldWindowObjectClearedCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_ScriptWorldWindowObjectCleared :: MonadIO m => ScriptWorldWindowObjectClearedCallback -> m (GClosure C_ScriptWorldWindowObjectClearedCallback)
genClosure_ScriptWorldWindowObjectCleared cb = liftIO $ do
    let cb' = wrap_ScriptWorldWindowObjectClearedCallback cb
    mk_ScriptWorldWindowObjectClearedCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `ScriptWorldWindowObjectClearedCallback` into a `C_ScriptWorldWindowObjectClearedCallback`.
wrap_ScriptWorldWindowObjectClearedCallback ::
    ScriptWorldWindowObjectClearedCallback ->
    C_ScriptWorldWindowObjectClearedCallback
wrap_ScriptWorldWindowObjectClearedCallback _cb _ page frame _ = do
    page' <- (newObject WebKit2WebExtension.WebPage.WebPage) page
    frame' <- (newObject WebKit2WebExtension.Frame.Frame) frame
    _cb  page' frame'


{- |
Connect a signal handler for the “@window-object-cleared@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' scriptWorld #windowObjectCleared callback
@
-}
onScriptWorldWindowObjectCleared :: (IsScriptWorld a, MonadIO m) => a -> ScriptWorldWindowObjectClearedCallback -> m SignalHandlerId
onScriptWorldWindowObjectCleared obj cb = liftIO $ do
    let cb' = wrap_ScriptWorldWindowObjectClearedCallback cb
    cb'' <- mk_ScriptWorldWindowObjectClearedCallback cb'
    connectSignalFunPtr obj "window-object-cleared" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@window-object-cleared@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' scriptWorld #windowObjectCleared callback
@
-}
afterScriptWorldWindowObjectCleared :: (IsScriptWorld a, MonadIO m) => a -> ScriptWorldWindowObjectClearedCallback -> m SignalHandlerId
afterScriptWorldWindowObjectCleared obj cb = liftIO $ do
    let cb' = wrap_ScriptWorldWindowObjectClearedCallback cb
    cb'' <- mk_ScriptWorldWindowObjectClearedCallback cb'
    connectSignalFunPtr obj "window-object-cleared" cb'' SignalConnectAfter


#if ENABLE_OVERLOADING
instance O.HasAttributeList ScriptWorld
type instance O.AttributeList ScriptWorld = ScriptWorldAttributeList
type ScriptWorldAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
data ScriptWorldWindowObjectClearedSignalInfo
instance SignalInfo ScriptWorldWindowObjectClearedSignalInfo where
    type HaskellCallbackType ScriptWorldWindowObjectClearedSignalInfo = ScriptWorldWindowObjectClearedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_ScriptWorldWindowObjectClearedCallback cb
        cb'' <- mk_ScriptWorldWindowObjectClearedCallback cb'
        connectSignalFunPtr obj "window-object-cleared" cb'' connectMode

type instance O.SignalList ScriptWorld = ScriptWorldSignalList
type ScriptWorldSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo), '("windowObjectCleared", ScriptWorldWindowObjectClearedSignalInfo)] :: [(Symbol, *)])

#endif

-- method ScriptWorld::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_script_world_new" webkit_script_world_new ::
    IO (Ptr ScriptWorld)

{- |
Creates a new isolated 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'. Scripts executed in
isolated worlds have access to the DOM but not to other variable
or functions created by the page.
The 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' is created with a generated unique name. Use
'GI.WebKit2WebExtension.Objects.ScriptWorld.scriptWorldNewWithName' if you want to create it with a
custom name.
You can get the JavaScript execution context of a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'
for a given 'GI.WebKit2WebExtension.Objects.Frame.Frame' with @/webkit_frame_get_javascript_context_for_script_world()/@.

/Since: 2.2/
-}
scriptWorldNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m ScriptWorld
    {- ^ __Returns:__ a new isolated 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' -}
scriptWorldNew  = liftIO $ do
    result <- webkit_script_world_new
    checkUnexpectedReturnNULL "scriptWorldNew" result
    result' <- (wrapObject ScriptWorld) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method ScriptWorld::new_with_name
-- method type : Constructor
-- Args : [Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a name for the script world", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_script_world_new_with_name" webkit_script_world_new_with_name ::
    CString ->                              -- name : TBasicType TUTF8
    IO (Ptr ScriptWorld)

{- |
Creates a new isolated 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' with a name. Scripts executed in
isolated worlds have access to the DOM but not to other variable
or functions created by the page.
You can get the JavaScript execution context of a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'
for a given 'GI.WebKit2WebExtension.Objects.Frame.Frame' with @/webkit_frame_get_javascript_context_for_script_world()/@.

/Since: 2.22/
-}
scriptWorldNewWithName ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@name@/: a name for the script world -}
    -> m ScriptWorld
    {- ^ __Returns:__ a new isolated 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' -}
scriptWorldNewWithName name = liftIO $ do
    name' <- textToCString name
    result <- webkit_script_world_new_with_name name'
    checkUnexpectedReturnNULL "scriptWorldNewWithName" result
    result' <- (wrapObject ScriptWorld) result
    freeMem name'
    return result'

#if ENABLE_OVERLOADING
#endif

-- method ScriptWorld::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "world", argType = TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitScriptWorld", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_script_world_get_name" webkit_script_world_get_name ::
    Ptr ScriptWorld ->                      -- world : TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"})
    IO CString

{- |
Get the name of a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'.

/Since: 2.22/
-}
scriptWorldGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsScriptWorld a) =>
    a
    {- ^ /@world@/: a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' -}
    -> m T.Text
    {- ^ __Returns:__ the name of /@world@/ -}
scriptWorldGetName world = liftIO $ do
    world' <- unsafeManagedPtrCastPtr world
    result <- webkit_script_world_get_name world'
    checkUnexpectedReturnNULL "scriptWorldGetName" result
    result' <- cstringToText result
    touchManagedPtr world
    return result'

#if ENABLE_OVERLOADING
data ScriptWorldGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsScriptWorld a) => O.MethodInfo ScriptWorldGetNameMethodInfo a signature where
    overloadedMethod _ = scriptWorldGetName

#endif

-- method ScriptWorld::get_default
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_script_world_get_default" webkit_script_world_get_default ::
    IO (Ptr ScriptWorld)

{- |
Get the default 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'. This is the normal script world
where all scripts are executed by default.
You can get the JavaScript execution context of a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'
for a given 'GI.WebKit2WebExtension.Objects.Frame.Frame' with @/webkit_frame_get_javascript_context_for_script_world()/@.

/Since: 2.2/
-}
scriptWorldGetDefault ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m ScriptWorld
    {- ^ __Returns:__ the default 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' -}
scriptWorldGetDefault  = liftIO $ do
    result <- webkit_script_world_get_default
    checkUnexpectedReturnNULL "scriptWorldGetDefault" result
    result' <- (newObject ScriptWorld) result
    return result'

#if ENABLE_OVERLOADING
#endif