{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.WebKit2WebExtension.Objects.WebExtension
    ( 

-- * Exported types
    WebExtension(..)                        ,
    IsWebExtension                          ,
    toWebExtension                          ,
    noWebExtension                          ,


 -- * Methods
-- ** getPage #method:getPage#
    WebExtensionGetPageMethodInfo           ,
    webExtensionGetPage                     ,




 -- * Signals
-- ** pageCreated #signal:pageCreated#
    C_WebExtensionPageCreatedCallback       ,
    WebExtensionPageCreatedCallback         ,
    WebExtensionPageCreatedSignalInfo       ,
    afterWebExtensionPageCreated            ,
    genClosure_WebExtensionPageCreated      ,
    mk_WebExtensionPageCreatedCallback      ,
    noWebExtensionPageCreatedCallback       ,
    onWebExtensionPageCreated               ,
    wrap_WebExtensionPageCreatedCallback    ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.WebKit2WebExtension.Objects.WebPage as WebKit2WebExtension.WebPage

newtype WebExtension = WebExtension (ManagedPtr WebExtension)
foreign import ccall "webkit_web_extension_get_type"
    c_webkit_web_extension_get_type :: IO GType

instance GObject WebExtension where
    gobjectType _ = c_webkit_web_extension_get_type
    

class GObject o => IsWebExtension o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError WebExtension a) =>
    IsWebExtension a
#endif
instance IsWebExtension WebExtension
instance GObject.Object.IsObject WebExtension

toWebExtension :: IsWebExtension o => o -> IO WebExtension
toWebExtension = unsafeCastTo WebExtension

noWebExtension :: Maybe WebExtension
noWebExtension = Nothing

type family ResolveWebExtensionMethod (t :: Symbol) (o :: *) :: * where
    ResolveWebExtensionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveWebExtensionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveWebExtensionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveWebExtensionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveWebExtensionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveWebExtensionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveWebExtensionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveWebExtensionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveWebExtensionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveWebExtensionMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveWebExtensionMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveWebExtensionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveWebExtensionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveWebExtensionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveWebExtensionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveWebExtensionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveWebExtensionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveWebExtensionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveWebExtensionMethod "getPage" o = WebExtensionGetPageMethodInfo
    ResolveWebExtensionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveWebExtensionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveWebExtensionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveWebExtensionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveWebExtensionMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveWebExtensionMethod t WebExtension, O.MethodInfo info WebExtension p) => O.IsLabelProxy t (WebExtension -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveWebExtensionMethod t WebExtension, O.MethodInfo info WebExtension p) => O.IsLabel t (WebExtension -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

-- signal WebExtension::page-created
type WebExtensionPageCreatedCallback =
    WebKit2WebExtension.WebPage.WebPage ->
    IO ()

noWebExtensionPageCreatedCallback :: Maybe WebExtensionPageCreatedCallback
noWebExtensionPageCreatedCallback = Nothing

type C_WebExtensionPageCreatedCallback =
    Ptr () ->                               -- object
    Ptr WebKit2WebExtension.WebPage.WebPage ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_WebExtensionPageCreatedCallback :: C_WebExtensionPageCreatedCallback -> IO (FunPtr C_WebExtensionPageCreatedCallback)

genClosure_WebExtensionPageCreated :: WebExtensionPageCreatedCallback -> IO Closure
genClosure_WebExtensionPageCreated cb = do
    let cb' = wrap_WebExtensionPageCreatedCallback cb
    mk_WebExtensionPageCreatedCallback cb' >>= newCClosure


wrap_WebExtensionPageCreatedCallback ::
    WebExtensionPageCreatedCallback ->
    Ptr () ->
    Ptr WebKit2WebExtension.WebPage.WebPage ->
    Ptr () ->
    IO ()
wrap_WebExtensionPageCreatedCallback _cb _ webPage _ = do
    webPage' <- (newObject WebKit2WebExtension.WebPage.WebPage) webPage
    _cb  webPage'


onWebExtensionPageCreated :: (IsWebExtension a, MonadIO m) => a -> WebExtensionPageCreatedCallback -> m SignalHandlerId
onWebExtensionPageCreated obj cb = liftIO $ do
    let cb' = wrap_WebExtensionPageCreatedCallback cb
    cb'' <- mk_WebExtensionPageCreatedCallback cb'
    connectSignalFunPtr obj "page-created" cb'' SignalConnectBefore

afterWebExtensionPageCreated :: (IsWebExtension a, MonadIO m) => a -> WebExtensionPageCreatedCallback -> m SignalHandlerId
afterWebExtensionPageCreated obj cb = liftIO $ do
    let cb' = wrap_WebExtensionPageCreatedCallback cb
    cb'' <- mk_WebExtensionPageCreatedCallback cb'
    connectSignalFunPtr obj "page-created" cb'' SignalConnectAfter


instance O.HasAttributeList WebExtension
type instance O.AttributeList WebExtension = WebExtensionAttributeList
type WebExtensionAttributeList = ('[ ] :: [(Symbol, *)])

data WebExtensionPageCreatedSignalInfo
instance SignalInfo WebExtensionPageCreatedSignalInfo where
    type HaskellCallbackType WebExtensionPageCreatedSignalInfo = WebExtensionPageCreatedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_WebExtensionPageCreatedCallback cb
        cb'' <- mk_WebExtensionPageCreatedCallback cb'
        connectSignalFunPtr obj "page-created" cb'' connectMode

type instance O.SignalList WebExtension = WebExtensionSignalList
type WebExtensionSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo), '("pageCreated", WebExtensionPageCreatedSignalInfo)] :: [(Symbol, *)])

-- method WebExtension::get_page
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "extension", argType = TInterface (Name {namespace = "WebKit2WebExtension", name = "WebExtension"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitWebExtension", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "page_id", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the identifier of the #WebKitWebPage to get", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2WebExtension", name = "WebPage"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_web_extension_get_page" webkit_web_extension_get_page :: 
    Ptr WebExtension ->                     -- extension : TInterface (Name {namespace = "WebKit2WebExtension", name = "WebExtension"})
    Word64 ->                               -- page_id : TBasicType TUInt64
    IO (Ptr WebKit2WebExtension.WebPage.WebPage)

{- |
Get the web page of the given /@pageId@/.
-}
webExtensionGetPage ::
    (B.CallStack.HasCallStack, MonadIO m, IsWebExtension a) =>
    a
    {- ^ /@extension@/: a 'GI.WebKit2WebExtension.Objects.WebExtension.WebExtension' -}
    -> Word64
    {- ^ /@pageId@/: the identifier of the 'GI.WebKit2WebExtension.Objects.WebPage.WebPage' to get -}
    -> m WebKit2WebExtension.WebPage.WebPage
    {- ^ __Returns:__ the 'GI.WebKit2WebExtension.Objects.WebPage.WebPage' for the given /@pageId@/, or 'Nothing' if the
   identifier doesn\'t correspond to an exsiting web page. -}
webExtensionGetPage extension pageId = liftIO $ do
    extension' <- unsafeManagedPtrCastPtr extension
    result <- webkit_web_extension_get_page extension' pageId
    checkUnexpectedReturnNULL "webExtensionGetPage" result
    result' <- (newObject WebKit2WebExtension.WebPage.WebPage) result
    touchManagedPtr extension
    return result'

data WebExtensionGetPageMethodInfo
instance (signature ~ (Word64 -> m WebKit2WebExtension.WebPage.WebPage), MonadIO m, IsWebExtension a) => O.MethodInfo WebExtensionGetPageMethodInfo a signature where
    overloadedMethod _ = webExtensionGetPage