aboutsummaryrefslogtreecommitdiffstats
path: root/embed/web-extension/ephy-embed-form-auth.c
blob: 9eda22064a69a6ad9178631f70acbda170452ef3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2013 Igalia S.L.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include <config.h>
#include "ephy-embed-form-auth.h"

struct _EphyEmbedFormAuthPrivate
{
  guint64 page_id;
  SoupURI *uri;
  WebKitDOMNode *username_node;
  WebKitDOMNode *password_node;
};

G_DEFINE_TYPE (EphyEmbedFormAuth, ephy_embed_form_auth, G_TYPE_OBJECT)

static void
ephy_embed_form_auth_finalize (GObject *object)
{
  EphyEmbedFormAuthPrivate *priv = EPHY_EMBED_FORM_AUTH (object)->priv;

  if (priv->uri)
    soup_uri_free (priv->uri);
  g_clear_object (&priv->username_node);
  g_clear_object (&priv->password_node);

  G_OBJECT_CLASS (ephy_embed_form_auth_parent_class)->finalize (object);
}

static void
ephy_embed_form_auth_init (EphyEmbedFormAuth *form_auth)
{
  form_auth->priv = G_TYPE_INSTANCE_GET_PRIVATE (form_auth, EPHY_TYPE_EMBED_FORM_AUTH, EphyEmbedFormAuthPrivate);
}

static void
ephy_embed_form_auth_class_init (EphyEmbedFormAuthClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = ephy_embed_form_auth_finalize;
  g_type_class_add_private (object_class, sizeof (EphyEmbedFormAuthPrivate));
}

EphyEmbedFormAuth *
ephy_embed_form_auth_new (WebKitWebPage *web_page,
                          WebKitDOMNode *username_node,
                          WebKitDOMNode *password_node)
{
  EphyEmbedFormAuth *form_auth;

  g_return_val_if_fail (WEBKIT_DOM_IS_NODE (username_node), NULL);
  g_return_val_if_fail (WEBKIT_DOM_IS_NODE (password_node), NULL);

  form_auth = EPHY_EMBED_FORM_AUTH (g_object_new (EPHY_TYPE_EMBED_FORM_AUTH, NULL));

  form_auth->priv->page_id = webkit_web_page_get_id (web_page);
  form_auth->priv->uri = soup_uri_new (webkit_web_page_get_uri (web_page));
  form_auth->priv->username_node = username_node;
  form_auth->priv->password_node = password_node;

  return form_auth;
}

WebKitDOMNode *
ephy_embed_form_auth_get_username_node (EphyEmbedFormAuth *form_auth)
{
  return form_auth->priv->username_node;
}

WebKitDOMNode *
ephy_embed_form_auth_get_password_node (EphyEmbedFormAuth *form_auth)
{
  return form_auth->priv->password_node;
}

SoupURI *
ephy_embed_form_auth_get_uri (EphyEmbedFormAuth *form_auth)
{
  return form_auth->priv->uri;
}

guint64
ephy_embed_form_auth_get_page_id (EphyEmbedFormAuth *form_auth)
{
  return form_auth->priv->page_id;
}