]> git.decadent.org.uk Git - videolink.git/commitdiff
Added support for XULRunner/GRE 1.9:
authorBen Hutchings <ben@decadent.org.uk>
Sat, 12 Apr 2008 16:10:53 +0000 (16:10 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 2 Nov 2008 23:58:16 +0000 (23:58 +0000)
- Use XPCOM and GtkMozEmbed glue code
  - Do not set rpath in executable
- Use <nsStringAPI.h> not <nsString.h> since the internal string API is not
  exported
  - Do not define MOZILLA_INTERNAL_API macro
- Do not use nsACString::{Begin,End}Reading since they are not exported (bug?)
- Do not add per-module directories to include search path, since they no
  longer exist
- Add NSPR header directory to include search path, since
  mozilla-gtkmozembed-embedding.pc doesn't do that (bug)
- Move use of nsPresContext to a separate source file since its header still
  requires MOZILLA_INTERNAL_API to be defined (bug?)

ChangeLog
Makefile
browser_widget.cpp
event_state_manager.cpp [new file with mode: 0644]
event_state_manager.hpp [new file with mode: 0644]
videolink.cpp

index 9211033e43d20104f009459f77b0dd67168560d1..e616abc6f5ef6e7bdc5ccdca67e18839a998c94a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+videolink (1.2.3) unstable; urgency=low
+
+  * Added support for XULRunner 1.9
+
+ -- Ben Hutchings <ben@decadent.org.uk>  Tue, 08 Apr 2008 01:22:08 +0100
+
 videolink (1.2.2) unstable; urgency=low
 
   * Fixed build failure with g++ 4.3
index 3226da67427bbb747d1f3c6e9a9acc61e2e49d4f..bf159592a6cfc8ae6eae67a562ed174a07c566c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,25 @@ sharedir := $(prefix)/share
 docdir := $(sharedir)/doc
 mandir := $(sharedir)/man
 
-# Prefer XULRunner to the old Mozilla
-ifeq ($(shell pkg-config --exists xulrunner-gtkmozembed && echo yes),yes)
+ifeq ($(shell pkg-config --atleast-version 1.9 mozilla-gtkmozembed-embedding && echo yes),yes)
+    moz_name := xulrunner-1.9
+    moz_pc := mozilla-gtkmozembed-embedding
+    moz_cppflags_extra := $(shell pkg-config --cflags xulrunner-nspr)
+    moz_unstable_cppflags_extra :=
+    moz_ldflags_extra :=
+else
+    ifeq ($(shell pkg-config --exists xulrunner-gtkmozembed && echo yes),yes)
     moz_name := xulrunner
     moz_pc := xulrunner-gtkmozembed
-else
+    else
     moz_name := mozilla
     moz_pc := mozilla-gtkmozembed
+    endif
+    moz_unstable_cppflags_extra = \
+       $(addprefix -I$(moz_include_dir)/, \
+          content docshell dom gfx imglib2 layout locale necko uconv webshell widget) \
+       -DMOZILLA_INTERNAL_API
+    moz_ldflags_extra = -Wl,-rpath,$(moz_lib_dir)
 endif
 
 moz_prefix := $(shell pkg-config --variable=prefix $(moz_pc))
@@ -27,7 +39,7 @@ CPPFLAGS := -D_REENTRANT
 CXXFLAGS := -ansi -Wall -Wunused
 LDFLAGS := -lpthread                                           \
            $(shell pkg-config --libs gtkmm-2.4 $(moz_pc))      \
-           -Wl,-rpath -Wl,$(moz_lib_dir) -lexpat
+           $(moz_ldflags_extra) -lexpat
 
 ifdef NDEBUG
     CPPFLAGS += -DNDEBUG
@@ -38,9 +50,10 @@ else
 endif
 
 cxxsources := \
-    auto_proc.cpp browser_widget.cpp child_iterator.cpp generate_dvd.cpp   \
-    link_iterator.cpp null_prompt_service.cpp pixbufs.cpp style_sheets.cpp \
-    temp_file.cpp video.cpp vob_list.cpp videolink.cpp warp_pointer.cpp    \
+    auto_proc.cpp browser_widget.cpp child_iterator.cpp                    \
+    event_state_manager.cpp generate_dvd.cpp link_iterator.cpp             \
+    null_prompt_service.cpp pixbufs.cpp style_sheets.cpp temp_file.cpp     \
+    video.cpp vob_list.cpp videolink.cpp warp_pointer.cpp                  \
     x_frame_buffer.cpp xml_utils.cpp xpcom_support.cpp
 csources := jquant2.c
 
@@ -48,10 +61,12 @@ sources_using_gtkmm :=                                                     \
     browser_widget.cpp generate_dvd.cpp pixbufs.cpp temp_file.cpp          \
     vob_list.cpp videolink.cpp warp_pointer.cpp
 sources_using_moz :=                                                       \
-    browser_widget.cpp child_iterator.cpp link_iterator.cpp                \
-    null_prompt_service.cpp style_sheets.cpp videolink.cpp xpcom_support.cpp
+    browser_widget.cpp child_iterator.cpp event_state_manager.cpp          \
+    link_iterator.cpp null_prompt_service.cpp style_sheets.cpp             \
+    videolink.cpp xpcom_support.cpp
 sources_using_moz_unstable := \
-    link_iterator.cpp null_prompt_service.cpp style_sheets.cpp videolink.cpp
+    browser_widget.cpp event_state_manager.cpp link_iterator.cpp           \
+    null_prompt_service.cpp style_sheets.cpp videolink.cpp
 
 videolink : $(cxxsources:%.cpp=.objs/%.o) $(csources:%.c=.objs/%.o)
        $(CXX) $^ $(LDFLAGS) -o $@
@@ -84,16 +99,13 @@ $(sources_using_gtkmm:%.cpp=.objs/%.o) \
     : CPPFLAGS += $(shell pkg-config --cflags gtkmm-2.4)
 
 $(sources_using_moz:%.cpp=.objs/%.o) \
-    : CPPFLAGS += $(shell pkg-config --cflags $(moz_pc))
+    : CPPFLAGS += $(shell pkg-config --cflags $(moz_pc)) $(moz_cppflags_extra)
 # Non-virtual destructors are fine in XPCOM interface classes since
 # instances are only ever called by the Release function which is virtual.
 $(sources_using_moz:%.cpp=.objs/%.o) : CXXFLAGS += -Wno-non-virtual-dtor
 
 $(sources_using_moz_unstable:%.cpp=.objs/%.o)                          \
-    : CPPFLAGS += $(addprefix -I$(moz_include_dir)/,                   \
-                    content docshell dom gfx imglib2 layout locale     \
-                    necko uconv webshell widget)                       \
-                 -DMOZILLA_INTERNAL_API                               \
+    : CPPFLAGS += $(moz_unstable_cppflags_extra)                       \
                   -DMOZ_VERSION_MAJOR=$(moz_version_major)             \
                   -DMOZ_VERSION_MINOR=$(moz_version_minor)
 
index 46d1fb5e0ba97706c4d72414b9dad053464c9046..07df0d0e86250c72957526144c57b27f1b23b769 100644 (file)
@@ -1,11 +1,21 @@
-// Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
+// Copyright 2005-8 Ben Hutchings <ben@decadent.org.uk>.
 // See the file "COPYING" for licence details.
 
 #include "browser_widget.hpp"
 
 #include <cassert>
+#include <cstring>
+
+#include <limits.h>
 
 #include <gtkmozembed_internal.h>
+#if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR == 9
+#include <gtkmozembed_glue.cpp>
+#endif
+
+#include "xpcom_support.hpp"
+
+using xpcom_support::check;
 
 browser_widget::browser_widget()
        : Gtk::Bin(GTK_BIN(gtk_moz_embed_new()))
@@ -518,7 +528,26 @@ Glib::ObjectBase * browser_widget::wrap_new(GObject * gobject)
 
 browser_widget::initialiser::initialiser()
 {
+#if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR == 9
+    static const GREVersionRange gre_versions = {
+       "1.9a", PR_TRUE,
+       "1.9.*", PR_TRUE
+    };
+    char path[PATH_MAX];
+    check(GRE_GetGREPathWithProperties(&gre_versions, 1, 0, 0,
+                                      path, sizeof(path)));
+
+    check(XPCOMGlueStartup(path));
+    check(GTKEmbedGlueStartup());
+
+    char * last_slash = std::strrchr(path, '/');
+    if (last_slash != path)
+       *last_slash = '\0';
+    gtk_moz_embed_set_path(path);
+#else
     gtk_moz_embed_set_comp_path(MOZ_LIB_DIR);
+#endif
+
     gtk_moz_embed_push_startup();
 
     wrap_register(gtk_moz_embed_get_type(), wrap_new);
@@ -527,6 +556,10 @@ browser_widget::initialiser::initialiser()
 browser_widget::initialiser::~initialiser()
 {
     gtk_moz_embed_pop_startup();
+
+#if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR == 9
+    XPCOMGlueShutdown();
+#endif
 }
 
 namespace Glib
diff --git a/event_state_manager.cpp b/event_state_manager.cpp
new file mode 100644 (file)
index 0000000..50b068a
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2008 Ben Hutchings <ben@decadent.org.uk>.
+// See the file "COPYING" for licence details.
+
+#ifndef MOZILLA_INTERNAL_API
+#define MOZILLA_INTERNAL_API
+#endif
+#include <nsIDocShell.h>
+#include <nsPresContext.h>
+
+#include "event_state_manager.hpp"
+#include "xpcom_support.hpp"
+
+using xpcom_support::check;
+
+nsIEventStateManager * get_event_state_manager(nsIDocShell * doc_shell)
+{
+    nsCOMPtr<nsPresContext> pres_context;
+    check(doc_shell->GetPresContext(getter_AddRefs(pres_context)));
+    return pres_context->EventStateManager();
+}
diff --git a/event_state_manager.hpp b/event_state_manager.hpp
new file mode 100644 (file)
index 0000000..de06b15
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2008 Ben Hutchings <ben@decadent.org.uk>.
+// See the file "COPYING" for licence details.
+
+#ifndef INC_EVENT_STATE_MANAGER_HPP
+#define INC_EVENT_STATE_MANAGER_HPP
+
+class nsIDocShell;
+class nsIEventStateManager;
+
+// This function works with nsPresContext, defined in
+// <nsPresContext.h>, which includes <nsString.h>, which is mutually
+// exclusive with including <nsStringAPI.h>.  What a mess.
+nsIEventStateManager * get_event_state_manager(nsIDocShell * doc_shell);
+
+#endif // !INC_EVENT_STATE_MANAGER_HPP
index 5867023ae9aa0b0e8d0511b8dbe6017d096ea4b5..cec4eccad2e8dfe5d11e3ddfe1cc5cdbcf8c7937 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
+// Copyright 2005-8 Ben Hutchings <ben@decadent.org.uk>.
 // See the file "COPYING" for licence details.
 
 #include <cassert>
 #include <gtkmm/window.h>
 
 #include <ImageErrors.h>
+#if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR == 9
+#include <nsWeakPtr.h>
+/* For some reason <nsWeakPtr.h> no longer defines this */
+typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
+#endif
 #include <nsGUIEvent.h>
 #include <nsIBoxObject.h>
 #include <nsIContent.h>
 #include <nsIURI.h> // required before nsILink.h
 #include <nsILink.h>
 #include <nsIPrefBranch.h>
-#include <nsPresContext.h>
 #include <nsIPrefService.h>
 #include <nsIPresShell.h>
 #include <nsServiceManagerUtils.h>
 #include <nsIWebBrowser.h>
+#ifdef MOZILLA_INTERNAL_API
 #include <nsString.h>
+#else
+#include <nsStringAPI.h>
+#endif
 
 #include "browser_widget.hpp"
 #include "child_iterator.hpp"
 #include "dvd.hpp"
+#include "event_state_manager.hpp"
 #include "generate_dvd.hpp"
 #include "geometry.hpp"
 #include "link_iterator.hpp"
@@ -237,8 +246,7 @@ namespace
        bool process_links(
            page_state * state,
            nsIDOMDocument * basic_doc,
-           nsIPresShell * pres_shell,
-           nsPresContext * pres_context,
+           nsIDocShell * doc_shell,
            nsIDOMWindow * dom_window);
 
        std::string output_dir_;
@@ -508,10 +516,6 @@ namespace
        nsCOMPtr<nsIWebBrowser> browser(browser_widget_.get_browser());
        nsCOMPtr<nsIDocShell> doc_shell(do_GetInterface(browser));
        assert(doc_shell);
-       nsCOMPtr<nsIPresShell> pres_shell;
-       check(doc_shell->GetPresShell(getter_AddRefs(pres_shell)));
-       nsCOMPtr<nsPresContext> pres_context;
-       check(doc_shell->GetPresContext(getter_AddRefs(pres_context)));
        nsCOMPtr<nsIDOMWindow> dom_window;
        check(browser->GetContentDOMWindow(getter_AddRefs(dom_window)));
 
@@ -524,9 +528,7 @@ namespace
                new page_state(
                    get_screenshot(),
                    basic_doc, frame_params_.width, frame_params_.height));
-       if (!process_links(
-               page_state_.get(),
-               basic_doc, pres_shell, pres_context, dom_window))
+       if (!process_links(page_state_.get(), basic_doc, doc_shell, dom_window))
        {
            // We've finished work on the links so generate the
            // menu VOB.
@@ -569,8 +571,7 @@ namespace
     bool conversion_window::process_links(
        page_state * state,
        nsIDOMDocument * basic_doc,
-       nsIPresShell * pres_shell,
-       nsPresContext * pres_context,
+       nsIDocShell * doc_shell,
        nsIDOMWindow * dom_window)
     {
        Glib::RefPtr<Gdk::Window> window(get_window());
@@ -578,8 +579,10 @@ namespace
 
        nsCOMPtr<nsIDOMNSDocument> ns_doc(do_QueryInterface(basic_doc));
        assert(ns_doc);
+       nsCOMPtr<nsIPresShell> pres_shell;
+       check(doc_shell->GetPresShell(getter_AddRefs(pres_shell)));
        nsCOMPtr<nsIEventStateManager> event_state_man(
-           pres_context->EventStateManager()); // does not AddRef
+           get_event_state_manager(doc_shell));
        assert(event_state_man);
        nsCOMPtr<nsIDOMDocumentEvent> event_factory(
            do_QueryInterface(basic_doc));
@@ -610,8 +613,9 @@ namespace
            {
                nsCString link_target_ns;
                check(uri_iface->GetSpec(link_target_ns));
-               state->link_target.assign(link_target_ns.BeginReading(),
-                                         link_target_ns.EndReading());
+               const char * str;
+               PRUint32 len = NS_CStringGetData(link_target_ns, &str);
+               state->link_target.assign(str, len);
 
                std::size_t hash_pos = state->link_target.find('#');
                uri.assign(state->link_target, 0, hash_pos);