~ubuntu-branches/ubuntu/saucy/gnome-shell/saucy-proposed

« back to all changes in this revision

Viewing changes to browser-plugin/browser-plugin.c

Tags: upstream-3.3.90
ImportĀ upstreamĀ versionĀ 3.3.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
      "It can be used only by extensions.gnome.org"
42
42
#define PLUGIN_MIME_STRING "application/x-gnome-shell-integration::Gnome Shell Integration Dummy Content-Type";
43
43
 
44
 
#define PLUGIN_API_VERSION 1
 
44
#define PLUGIN_API_VERSION 3
45
45
 
46
46
typedef struct {
47
47
  GDBusProxy *proxy;
104
104
                          &location))
105
105
    goto out;
106
106
 
107
 
  if (!NPVARIANT_IS_OBJECT (document))
 
107
  if (!NPVARIANT_IS_OBJECT (location))
108
108
    goto out;
109
109
 
110
110
  hostname = get_string_property (instance,
262
262
/* =================== scripting interface =================== */
263
263
 
264
264
typedef struct {
265
 
        NPObject     parent;
266
 
        NPP          instance;
267
 
        GDBusProxy  *proxy;
268
 
        NPObject    *listener;
269
 
        gint         signal_id;
 
265
  NPObject     parent;
 
266
  NPP          instance;
 
267
  GDBusProxy  *proxy;
 
268
  NPObject    *listener;
 
269
  NPObject    *restart_listener;
 
270
  gint         signal_id;
 
271
  guint        watch_name_id;
270
272
} PluginObject;
271
273
 
272
274
static void
284
286
      gint32 status;
285
287
      gchar *error;
286
288
      NPVariant args[3];
287
 
      NPVariant result;
 
289
      NPVariant result = { NPVariantType_Void };
288
290
 
289
291
      g_variant_get (parameters, "(sis)", &uuid, &status, &error);
290
292
      STRINGZ_TO_NPVARIANT (uuid, args[0]);
300
302
    }
301
303
}
302
304
 
 
305
static void
 
306
on_shell_appeared (GDBusConnection *connection,
 
307
                   const gchar     *name,
 
308
                   const gchar     *name_owner,
 
309
                   gpointer         user_data)
 
310
{
 
311
  PluginObject *obj = (PluginObject*) user_data;
 
312
 
 
313
  if (obj->restart_listener)
 
314
    {
 
315
      NPVariant result = { NPVariantType_Void };
 
316
 
 
317
      funcs.invokeDefault (obj->instance, obj->restart_listener,
 
318
                           NULL, 0, &result);
 
319
 
 
320
      funcs.releasevariantvalue (&result);
 
321
    }
 
322
}
 
323
 
303
324
static NPObject *
304
325
plugin_object_allocate (NPP      instance,
305
326
                        NPClass *klass)
312
333
  obj->signal_id = g_signal_connect (obj->proxy, "g-signal",
313
334
                                     G_CALLBACK (on_shell_signal), obj);
314
335
 
 
336
  obj->watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
 
337
                                         "org.gnome.Shell",
 
338
                                         G_BUS_NAME_WATCHER_FLAGS_NONE,
 
339
                                         on_shell_appeared,
 
340
                                         NULL,
 
341
                                         obj,
 
342
                                         NULL);
 
343
 
315
344
  g_debug ("plugin object created");
316
345
 
317
346
  return (NPObject*)obj;
328
357
  if (obj->listener)
329
358
    funcs.releaseobject (obj->listener);
330
359
 
 
360
  if (obj->watch_name_id)
 
361
    g_bus_unwatch_name (obj->watch_name_id);
 
362
 
331
363
  g_debug ("plugin object destroyed");
332
364
 
333
365
  g_slice_free (PluginObject, obj);
341
373
static NPIdentifier install_extension_id;
342
374
static NPIdentifier uninstall_extension_id;
343
375
static NPIdentifier onextension_changed_id;
 
376
static NPIdentifier onrestart_id;
344
377
static NPIdentifier get_errors_id;
 
378
static NPIdentifier launch_extension_prefs_id;
345
379
 
346
380
static bool
347
381
plugin_object_has_method (NPObject     *npobj,
352
386
          name == enable_extension_id ||
353
387
          name == install_extension_id ||
354
388
          name == uninstall_extension_id ||
355
 
          name == get_errors_id);
 
389
          name == get_errors_id ||
 
390
          name == launch_extension_prefs_id);
356
391
}
357
392
 
358
393
static inline gboolean
457
492
{
458
493
  gchar *uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
459
494
  if (!uuid_is_valid (uuid_str))
460
 
    return FALSE;
 
495
    {
 
496
      g_free (uuid_str);
 
497
      return FALSE;
 
498
    }
461
499
 
462
500
  g_dbus_proxy_call (obj->proxy,
463
501
                     (enabled ? "EnableExtension" : "DisableExtension"),
616
654
  return jsonify_variant (res, result);
617
655
}
618
656
 
 
657
static gboolean
 
658
plugin_launch_extension_prefs (PluginObject *obj,
 
659
                               NPString      uuid,
 
660
                               NPVariant    *result)
 
661
{
 
662
  gchar *uuid_str;
 
663
 
 
664
  uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
 
665
  if (!uuid_is_valid (uuid_str))
 
666
    {
 
667
      g_free (uuid_str);
 
668
      return FALSE;
 
669
    }
 
670
 
 
671
  g_dbus_proxy_call (obj->proxy,
 
672
                     "LaunchExtensionPrefs",
 
673
                     g_variant_new ("(s)", uuid_str),
 
674
                     G_DBUS_CALL_FLAGS_NONE,
 
675
                     -1, /* timeout */
 
676
                     NULL, /* cancellable */
 
677
                     NULL, /* callback */
 
678
                     NULL /* user_data */);
 
679
 
 
680
  g_free (uuid_str);
 
681
  return TRUE;
 
682
}
 
683
 
619
684
static int
620
685
plugin_get_api_version (PluginObject  *obj,
621
686
                        NPVariant     *result)
726
791
                                NPVARIANT_TO_STRING(args[0]),
727
792
                                result);
728
793
    }
 
794
  else if (name == launch_extension_prefs_id)
 
795
    {
 
796
      if (!NPVARIANT_IS_STRING(args[0])) return FALSE;
 
797
 
 
798
      return plugin_launch_extension_prefs (obj,
 
799
                                            NPVARIANT_TO_STRING(args[0]),
 
800
                                            result);
 
801
    }
729
802
 
730
803
  return TRUE;
731
804
}
735
808
                            NPIdentifier  name)
736
809
{
737
810
  return (name == onextension_changed_id ||
 
811
          name == onrestart_id ||
738
812
          name == api_version_id ||
739
813
          name == shell_version_id);
740
814
}
761
835
      else
762
836
        NULL_TO_NPVARIANT (*result);
763
837
    }
 
838
  else if (name == onrestart_id)
 
839
    {
 
840
      if (obj->restart_listener)
 
841
        OBJECT_TO_NPVARIANT (obj->restart_listener, *result);
 
842
      else
 
843
        NULL_TO_NPVARIANT (*result);
 
844
    }
 
845
 
 
846
  return TRUE;
 
847
}
 
848
 
 
849
static bool
 
850
plugin_object_set_callback (NPObject        **listener,
 
851
                            const NPVariant  *value)
 
852
{
 
853
  if (!NPVARIANT_IS_OBJECT (*value) && !NPVARIANT_IS_NULL (*value))
 
854
    return FALSE;
 
855
 
 
856
  if (*listener)
 
857
    funcs.releaseobject (*listener);
 
858
  *listener = NULL;
 
859
 
 
860
  if (NPVARIANT_IS_OBJECT (*value))
 
861
    {
 
862
      *listener = NPVARIANT_TO_OBJECT (*value);
 
863
      funcs.retainobject (*listener);
 
864
    }
764
865
 
765
866
  return TRUE;
766
867
}
772
873
{
773
874
  PluginObject *obj;
774
875
 
775
 
  if (!plugin_object_has_property (npobj, name))
776
 
    return FALSE;
 
876
  obj = (PluginObject *)npobj;
777
877
 
778
878
  if (name == onextension_changed_id)
779
 
    {
780
 
      obj = (PluginObject*) npobj;
781
 
      if (obj->listener)
782
 
        funcs.releaseobject (obj->listener);
 
879
    return plugin_object_set_callback (&obj->listener, value);
783
880
 
784
 
      obj->listener = NULL;
785
 
      if (NPVARIANT_IS_OBJECT (*value))
786
 
        {
787
 
          obj->listener = NPVARIANT_TO_OBJECT (*value);
788
 
          funcs.retainobject (obj->listener);
789
 
          return TRUE;
790
 
        }
791
 
      else if (NPVARIANT_IS_NULL (*value))
792
 
        return TRUE;
793
 
    }
 
881
  if (name == onrestart_id)
 
882
    return plugin_object_set_callback (&obj->restart_listener, value);
794
883
 
795
884
  return FALSE;
796
885
}
824
913
  install_extension_id = funcs.getstringidentifier ("installExtension");
825
914
  uninstall_extension_id = funcs.getstringidentifier ("uninstallExtension");
826
915
  get_errors_id = funcs.getstringidentifier ("getExtensionErrors");
 
916
  launch_extension_prefs_id = funcs.getstringidentifier ("launchExtensionPrefs");
827
917
 
 
918
  onrestart_id = funcs.getstringidentifier ("onshellrestart");
828
919
  onextension_changed_id = funcs.getstringidentifier ("onchange");
829
920
}
830
921