{- |
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.Frame
    ( 

-- * Exported types
    Frame(..)                               ,
    IsFrame                                 ,
    toFrame                                 ,
    noFrame                                 ,


 -- * Methods
-- ** getJavascriptContextForScriptWorld #method:getJavascriptContextForScriptWorld#
    FrameGetJavascriptContextForScriptWorldMethodInfo,
    frameGetJavascriptContextForScriptWorld ,


-- ** getJavascriptGlobalContext #method:getJavascriptGlobalContext#
    FrameGetJavascriptGlobalContextMethodInfo,
    frameGetJavascriptGlobalContext         ,


-- ** getUri #method:getUri#
    FrameGetUriMethodInfo                   ,
    frameGetUri                             ,


-- ** isMainFrame #method:isMainFrame#
    FrameIsMainFrameMethodInfo              ,
    frameIsMainFrame                        ,




    ) 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 qualified GI.JavaScriptCore.Structs.GlobalContext as JavaScriptCore.GlobalContext
import {-# SOURCE #-} qualified GI.WebKit2WebExtension.Objects.ScriptWorld as WebKit2WebExtension.ScriptWorld

newtype Frame = Frame (ManagedPtr Frame)
foreign import ccall "webkit_frame_get_type"
    c_webkit_frame_get_type :: IO GType

instance GObject Frame where
    gobjectType _ = c_webkit_frame_get_type
    

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

toFrame :: IsFrame o => o -> IO Frame
toFrame = unsafeCastTo Frame

noFrame :: Maybe Frame
noFrame = Nothing

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

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

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

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

type instance O.SignalList Frame = FrameSignalList
type FrameSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method Frame::get_javascript_context_for_script_world
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "frame", argType = TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFrame", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},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 (TInterface (Name {namespace = "JavaScriptCore", name = "GlobalContext"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_frame_get_javascript_context_for_script_world" webkit_frame_get_javascript_context_for_script_world :: 
    Ptr Frame ->                            -- frame : TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"})
    Ptr WebKit2WebExtension.ScriptWorld.ScriptWorld -> -- world : TInterface (Name {namespace = "WebKit2WebExtension", name = "ScriptWorld"})
    IO (Ptr JavaScriptCore.GlobalContext.GlobalContext)

{- |
Gets the JavaScript execution context of /@frame@/ for the given 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld'.

@since 2.2
-}
frameGetJavascriptContextForScriptWorld ::
    (B.CallStack.HasCallStack, MonadIO m, IsFrame a, WebKit2WebExtension.ScriptWorld.IsScriptWorld b) =>
    a
    {- ^ /@frame@/: a 'GI.WebKit2WebExtension.Objects.Frame.Frame' -}
    -> b
    {- ^ /@world@/: a 'GI.WebKit2WebExtension.Objects.ScriptWorld.ScriptWorld' -}
    -> m JavaScriptCore.GlobalContext.GlobalContext
    {- ^ __Returns:__ the JavaScript context of /@frame@/ for /@world@/ -}
frameGetJavascriptContextForScriptWorld frame world = liftIO $ do
    frame' <- unsafeManagedPtrCastPtr frame
    world' <- unsafeManagedPtrCastPtr world
    result <- webkit_frame_get_javascript_context_for_script_world frame' world'
    checkUnexpectedReturnNULL "frameGetJavascriptContextForScriptWorld" result
    result' <- (newPtr JavaScriptCore.GlobalContext.GlobalContext) result
    touchManagedPtr frame
    touchManagedPtr world
    return result'

data FrameGetJavascriptContextForScriptWorldMethodInfo
instance (signature ~ (b -> m JavaScriptCore.GlobalContext.GlobalContext), MonadIO m, IsFrame a, WebKit2WebExtension.ScriptWorld.IsScriptWorld b) => O.MethodInfo FrameGetJavascriptContextForScriptWorldMethodInfo a signature where
    overloadedMethod _ = frameGetJavascriptContextForScriptWorld

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

foreign import ccall "webkit_frame_get_javascript_global_context" webkit_frame_get_javascript_global_context :: 
    Ptr Frame ->                            -- frame : TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"})
    IO (Ptr JavaScriptCore.GlobalContext.GlobalContext)

{- |
Gets the global JavaScript execution context. Use this function to bridge
between the WebKit and JavaScriptCore APIs.

@since 2.2
-}
frameGetJavascriptGlobalContext ::
    (B.CallStack.HasCallStack, MonadIO m, IsFrame a) =>
    a
    {- ^ /@frame@/: a 'GI.WebKit2WebExtension.Objects.Frame.Frame' -}
    -> m JavaScriptCore.GlobalContext.GlobalContext
    {- ^ __Returns:__ the global JavaScript context of /@frame@/ -}
frameGetJavascriptGlobalContext frame = liftIO $ do
    frame' <- unsafeManagedPtrCastPtr frame
    result <- webkit_frame_get_javascript_global_context frame'
    checkUnexpectedReturnNULL "frameGetJavascriptGlobalContext" result
    result' <- (newPtr JavaScriptCore.GlobalContext.GlobalContext) result
    touchManagedPtr frame
    return result'

data FrameGetJavascriptGlobalContextMethodInfo
instance (signature ~ (m JavaScriptCore.GlobalContext.GlobalContext), MonadIO m, IsFrame a) => O.MethodInfo FrameGetJavascriptGlobalContextMethodInfo a signature where
    overloadedMethod _ = frameGetJavascriptGlobalContext

-- method Frame::get_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "frame", argType = TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFrame", 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_frame_get_uri" webkit_frame_get_uri :: 
    Ptr Frame ->                            -- frame : TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"})
    IO CString

{- |
Gets the current active URI of /@frame@/.

@since 2.2
-}
frameGetUri ::
    (B.CallStack.HasCallStack, MonadIO m, IsFrame a) =>
    a
    {- ^ /@frame@/: a 'GI.WebKit2WebExtension.Objects.Frame.Frame' -}
    -> m T.Text
    {- ^ __Returns:__ the current active URI of /@frame@/ or 'Nothing' if nothing has been
   loaded yet. -}
frameGetUri frame = liftIO $ do
    frame' <- unsafeManagedPtrCastPtr frame
    result <- webkit_frame_get_uri frame'
    checkUnexpectedReturnNULL "frameGetUri" result
    result' <- cstringToText result
    touchManagedPtr frame
    return result'

data FrameGetUriMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsFrame a) => O.MethodInfo FrameGetUriMethodInfo a signature where
    overloadedMethod _ = frameGetUri

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

foreign import ccall "webkit_frame_is_main_frame" webkit_frame_is_main_frame :: 
    Ptr Frame ->                            -- frame : TInterface (Name {namespace = "WebKit2WebExtension", name = "Frame"})
    IO CInt

{- |
Gets whether /@frame@/ is the a main frame of a 'GI.WebKit2WebExtension.Objects.WebPage.WebPage'

@since 2.2
-}
frameIsMainFrame ::
    (B.CallStack.HasCallStack, MonadIO m, IsFrame a) =>
    a
    {- ^ /@frame@/: a 'GI.WebKit2WebExtension.Objects.Frame.Frame' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@frame@/ is a main frame or 'False' otherwise -}
frameIsMainFrame frame = liftIO $ do
    frame' <- unsafeManagedPtrCastPtr frame
    result <- webkit_frame_is_main_frame frame'
    let result' = (/= 0) result
    touchManagedPtr frame
    return result'

data FrameIsMainFrameMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsFrame a) => O.MethodInfo FrameIsMainFrameMethodInfo a signature where
    overloadedMethod _ = frameIsMainFrame