<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>175937</bug_id>
          
          <creation_ts>2017-08-24 08:52:34 -0700</creation_ts>
          <short_desc>[GTK] gtk_builder_get_type_from_name doesn&apos;t work with WebKitWebView</short_desc>
          <delta_ts>2017-08-28 11:00:18 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Debarshi Ray">rishi.is</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>cgarcia</cc>
    
    <cc>christian</cc>
    
    <cc>mcatanzaro</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1342048</commentid>
    <comment_count>0</comment_count>
      <attachid>318990</attachid>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-24 08:52:34 -0700</bug_when>
    <thetext>Created attachment 318990
Test case

For any child widget inside a GTK+ widget template, GtkBuilder uses gtk_builder_get_type_from_name to get a GType corresponding to the class name. If a WebKitWebView is used it will use:
  type = gtk_builder_get_type_from_name (builder, &quot;WebKitWebView&quot;);

GtkBuilder has some heuristics to get the *_get_type method corresponding to the class name so that it can register the type, if needed. See _gtk_builder_resolve_type_lazily in gtk/gtkbuilder.c.

This isn&apos;t working with WebKitWebView. However, it works with VteTerminal, which also offers a GtkWidget with a public C API that&apos;s internally implemented using C++.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342049</commentid>
    <comment_count>1</comment_count>
      <attachid>318991</attachid>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-24 08:55:06 -0700</bug_when>
    <thetext>Created attachment 318991
Test case

Use %u, not %d, with guint.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342218</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-24 16:09:25 -0700</bug_when>
    <thetext>(In reply to Debarshi Ray from comment #0)
&gt; GtkBuilder has some heuristics to get the *_get_type method corresponding to
&gt; the class name so that it can register the type, if needed. See
&gt; _gtk_builder_resolve_type_lazily in gtk/gtkbuilder.c.

The problem is it is looking for the symbol web_kit_web_view_get_type, when it needs to look for webkit_web_view_get_type. This is unfortunate. I&apos;m not sure what to do about this.

Workaround: manually register the type before creating the GtkBuilder. Something like g_object_unref (g_object_ref_sink (webkit_web_view_new ())) should work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342221</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-24 16:10:47 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #2) 
&gt; The problem is it is looking for the symbol web_kit_web_view_get_type, when
&gt; it needs to look for webkit_web_view_get_type. This is unfortunate. I&apos;m not
&gt; sure what to do about this.

To be clear, it would surely work automatically if the widget was named WebkitWebView rather than WebKitWebView. I think this problem came up somewhere else recently, but I don&apos;t remember where.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342222</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-24 16:12:57 -0700</bug_when>
    <thetext>And we already use C linkage, so C++ is not the issue.

(In reply to Michael Catanzaro from comment #2)
&gt; Workaround: manually register the type before creating the GtkBuilder.
&gt; Something like g_object_unref (g_object_ref_sink (webkit_web_view_new ()))
&gt; should work.

I guess that&apos;s overkill. Just calling webkit_web_view_get_type() would be the usual workaround. I&apos;m sure similar workarounds exist elsewhere in GNOME.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342264</commentid>
    <comment_count>5</comment_count>
    <who name="Christian Hergert">christian</who>
    <bug_when>2017-08-24 17:19:49 -0700</bug_when>
    <thetext>With &quot;Kit&quot; being more and more common, maybe it makes sense to teach GtkBuilder that words followed by &quot;Kit&quot; should be joined?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342343</commentid>
    <comment_count>6</comment_count>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-25 01:07:31 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #2)
&gt; The problem is it is looking for the symbol web_kit_web_view_get_type, when
&gt; it needs to look for webkit_web_view_get_type.

Oh, yes, of course! :)

(In reply to Michael Catanzaro from comment #4)
&gt; (In reply to Michael Catanzaro from comment #2)
&gt;&gt; Workaround: manually register the type before creating the GtkBuilder.
&gt;&gt; Something like g_object_unref (g_object_ref_sink (webkit_web_view_new ()))
&gt;&gt; should work.
&gt; 
&gt; I guess that&apos;s overkill. Just calling webkit_web_view_get_type() would be
&gt; the usual workaround. I&apos;m sure similar workarounds exist elsewhere in GNOME.

The &quot;recommended workaround&quot; would be:
  g_type_ensure (WEBKIT_TYPE_WEB_VIEW)

(In reply to Christian Hergert from comment #5)
&gt; With &quot;Kit&quot; being more and more common, maybe it makes sense to teach
&gt; GtkBuilder that words followed by &quot;Kit&quot; should be joined?

Or, I wonder if webkitgtk should have a compatibility shim called web_kit_web_view_get_type that just calls webkit_web_view_get_type?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342386</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-25 07:51:27 -0700</bug_when>
    <thetext>(In reply to Debarshi Ray from comment #6)
&gt; Or, I wonder if webkitgtk should have a compatibility shim called
&gt; web_kit_web_view_get_type that just calls webkit_web_view_get_type?

Good idea. Let&apos;s do that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342387</commentid>
    <comment_count>8</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-25 07:55:29 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #7)
&gt; Good idea. Let&apos;s do that.

Hm, is it only needed for WebKitWebView, since that&apos;s the only GtkBuildable thing in the API? Maybe there are other things in glib that will look for web_kit_*_get_type()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342513</commentid>
    <comment_count>9</comment_count>
    <who name="Christian Hergert">christian</who>
    <bug_when>2017-08-25 14:07:02 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #8)
&gt; (In reply to Michael Catanzaro from comment #7)
&gt; &gt; Good idea. Let&apos;s do that.
&gt; 
&gt; Hm, is it only needed for WebKitWebView, since that&apos;s the only GtkBuildable
&gt; thing in the API? Maybe there are other things in glib that will look for
&gt; web_kit_*_get_type()?

GtkBuilder files can be used for plenty of things not-widgetry. So starting down this path is likely going to just add more things later on.

Another option is to just use static constructors to register the types you care about. Since GObject should be initialized first (as a dependency of your library) you can probably just g_type_ensure() from a single static constructor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342591</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-25 17:06:25 -0700</bug_when>
    <thetext>(In reply to Christian Hergert from comment #9) 
&gt; Another option is to just use static constructors to register the types you
&gt; care about. Since GObject should be initialized first (as a dependency of
&gt; your library) you can probably just g_type_ensure() from a single static
&gt; constructor.

This seems like the path of least-resistance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342647</commentid>
    <comment_count>11</comment_count>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-26 05:45:04 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #10)
&gt; (In reply to Christian Hergert from comment #9) 
&gt; &gt; Another option is to just use static constructors to register the types you
&gt; &gt; care about. Since GObject should be initialized first (as a dependency of
&gt; &gt; your library) you can probably just g_type_ensure() from a single static
&gt; &gt; constructor.
&gt; 
&gt; This seems like the path of least-resistance.

By constructor, I&apos;d expect something like this:
https://git.gnome.org/browse/gnome-online-accounts/commit/src/goabackend?id=bbab1cebf4d976b51680a2ab6c4730b9580f5098

And in that case, you&apos;d still be fixing this bug. :)

I don&apos;t think we should be placing the onus on the application to register the type. That reflects very badly on our platform since it will trip up anybody using GTK+ widget templates - something that we expect people to use to build UIs. If we are not going to make the effort to make these things just work, then it is dishonest for us to advertise them. Especially when there are multiple ways to fix the problem in the platform.

Minutes before I myself hit this problem, I was helping a newcomer on #webkitgtk+ who was puzzled why his GTK+ widget templates were not working in PyGObject. I myself hit this problem while programming in Vala. Having to figure out how g_type_ensure translates into a language binding is a pretty sucky experience, even for someone who has been programming in C/GObject for years.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342648</commentid>
    <comment_count>12</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-26 07:37:22 -0700</bug_when>
    <thetext>So what types do we need to register in our library constructor? Everything?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342694</commentid>
    <comment_count>13</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-26 19:21:31 -0700</bug_when>
    <thetext>On IRC we agreed the best way to solve this is to just add a web_kit_web_view_get_type() that calls webkit_web_view_get_type(), like Rishi suggested originally. So that&apos;s easy. Only hard part is figuring out how to export the symbol. I&apos;m not sure where in the build system our linker configuration is hiding!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342784</commentid>
    <comment_count>14</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-08-28 02:46:05 -0700</bug_when>
    <thetext>(In reply to Christian Hergert from comment #5)
&gt; With &quot;Kit&quot; being more and more common, maybe it makes sense to teach
&gt; GtkBuilder that words followed by &quot;Kit&quot; should be joined?

I like this approach.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342821</commentid>
    <comment_count>15</comment_count>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-28 06:04:02 -0700</bug_when>
    <thetext>(In reply to Christian Hergert from comment #5)
&gt; With &quot;Kit&quot; being more and more common, maybe it makes sense to teach
&gt; GtkBuilder that words followed by &quot;Kit&quot; should be joined?

Do you know of any other *Kits where this would be a problem? I looked at PackageKit (Pk, pk_), PolKit (Polkit, polkit) and P11-Kit (P11Kit, p11_kit). The last doesn&apos;t seem to use gtk+, so probably not relevant.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342845</commentid>
    <comment_count>16</comment_count>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-28 09:32:11 -0700</bug_when>
    <thetext>By the way, Vala doesn&apos;t know about GtkBuilder&apos;s &quot;type-func&quot; attribute, and GtkBuilder ignores the &quot;type-func&quot; attribute if &quot;class&quot; is also present. This means when valac looks at the template class&apos; [GtkChild] variable and tries to find its XML counterpart, it will fail, because it will ignore objects without the &quot;class&quot; attribute.

So, if you want to waste your time (please don&apos;t :) debating the merits of g_type_ensure and type-func as possible workarounds, then the former seems like the better option.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1342860</commentid>
    <comment_count>17</comment_count>
    <who name="Debarshi Ray">rishi.is</who>
    <bug_when>2017-08-28 11:00:18 -0700</bug_when>
    <thetext>(In reply to Debarshi Ray from comment #16)
&gt; By the way, Vala doesn&apos;t know about GtkBuilder&apos;s &quot;type-func&quot; attribute, and
&gt; GtkBuilder ignores the &quot;type-func&quot; attribute if &quot;class&quot; is also present.
&gt; This means when valac looks at the template class&apos; [GtkChild] variable and
&gt; tries to find its XML counterpart, it will fail, because it will ignore
&gt; objects without the &quot;class&quot; attribute.

Filed these against gtk+:
https://bugzilla.gnome.org/show_bug.cgi?id=786931
https://bugzilla.gnome.org/show_bug.cgi?id=786932</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="0"
              isprivate="0"
          >
            <attachid>318990</attachid>
            <date>2017-08-24 08:52:34 -0700</date>
            <delta_ts>2017-08-24 08:55:06 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>webkit-get-type-from-name.c</filename>
            <type>text/plain</type>
            <size>554</size>
            <attacher name="Debarshi Ray">rishi.is</attacher>
            
              <data encoding="base64">LyogZ2NjIHdlYmtpdC1nZXQtdHlwZS1mcm9tLW5hbWUuYyAkKHBrZy1jb25maWcgLS1jZmxhZ3Mg
LS1saWJzCiAgIHdlYmtpdDJndGstNC4wIHZ0ZS0yLjkxIGd0aystMy4wIGdsaWItMi4wKSAqLwoK
I2luY2x1ZGUgPGdsaWIuaD4KI2luY2x1ZGUgPGd0ay9ndGsuaD4KCmludAptYWluICh2b2lkKQp7
CiAgR1R5cGUgdHlwZSA9IDA7CiAgR3RrQnVpbGRlciAqYnVpbGRlciA9IE5VTEw7CgogIGd0a19p
bml0IChOVUxMLCBOVUxMKTsKCiAgYnVpbGRlciA9IGd0a19idWlsZGVyX25ldyAoKTsKCiAgdHlw
ZSA9IGd0a19idWlsZGVyX2dldF90eXBlX2Zyb21fbmFtZSAoYnVpbGRlciwgIlZ0ZVRlcm1pbmFs
Iik7CiAgZ19tZXNzYWdlICgiVnRlVGVybWluYWw6ICVkIiwgKGd1aW50KSB0eXBlKTsKCiAgdHlw
ZSA9IGd0a19idWlsZGVyX2dldF90eXBlX2Zyb21fbmFtZSAoYnVpbGRlciwgIldlYktpdFdlYlZp
ZXciKTsKICBnX21lc3NhZ2UgKCJXZWJLaXRXZWJWaWV3OiAlZCIsIChndWludCkgdHlwZSk7Cgog
IGdfb2JqZWN0X3VucmVmIChidWlsZGVyKTsKICByZXR1cm4gMDsKfQo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>318991</attachid>
            <date>2017-08-24 08:55:06 -0700</date>
            <delta_ts>2017-08-24 08:55:06 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>webkit-get-type-from-name.c</filename>
            <type>text/plain</type>
            <size>554</size>
            <attacher name="Debarshi Ray">rishi.is</attacher>
            
              <data encoding="base64">LyogZ2NjIHdlYmtpdC1nZXQtdHlwZS1mcm9tLW5hbWUuYyAkKHBrZy1jb25maWcgLS1jZmxhZ3Mg
LS1saWJzCiAgIHdlYmtpdDJndGstNC4wIHZ0ZS0yLjkxIGd0aystMy4wIGdsaWItMi4wKSAqLwoK
I2luY2x1ZGUgPGdsaWIuaD4KI2luY2x1ZGUgPGd0ay9ndGsuaD4KCmludAptYWluICh2b2lkKQp7
CiAgR1R5cGUgdHlwZSA9IDA7CiAgR3RrQnVpbGRlciAqYnVpbGRlciA9IE5VTEw7CgogIGd0a19p
bml0IChOVUxMLCBOVUxMKTsKCiAgYnVpbGRlciA9IGd0a19idWlsZGVyX25ldyAoKTsKCiAgdHlw
ZSA9IGd0a19idWlsZGVyX2dldF90eXBlX2Zyb21fbmFtZSAoYnVpbGRlciwgIlZ0ZVRlcm1pbmFs
Iik7CiAgZ19tZXNzYWdlICgiVnRlVGVybWluYWw6ICV1IiwgKGd1aW50KSB0eXBlKTsKCiAgdHlw
ZSA9IGd0a19idWlsZGVyX2dldF90eXBlX2Zyb21fbmFtZSAoYnVpbGRlciwgIldlYktpdFdlYlZp
ZXciKTsKICBnX21lc3NhZ2UgKCJXZWJLaXRXZWJWaWV3OiAldSIsIChndWludCkgdHlwZSk7Cgog
IGdfb2JqZWN0X3VucmVmIChidWlsZGVyKTsKICByZXR1cm4gMDsKfQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>