# include "page_client.hh"
# include "utils/resource.hh"
# include <webkit2/webkit2.h>
# include <unistd.h>
# include <gtkmm.h>
# include <glib.h>
# include <glibmm.h>
# include <giomm.h>
# include <giomm/socket.h>
# include <gmime/gmime.h>
# include "utils/gmime/gmime-compat.h"
# include <boost/filesystem.hpp>
# include <iostream>
# include <thread>
# include <algorithm>
# include "astroid.hh"
# include "build_config.hh"
# include "modes/thread_view/webextension/ae_protocol.hh"
# include "modes/thread_view/webextension/dom_utils.hh"
# include "messages.pb.h"
# include "config.hh"
# include "thread_view.hh"
# include "message_thread.hh"
# include "chunk.hh"
# include "utils/utils.hh"
# include "utils/address.hh"
# include "utils/vector_utils.hh"
# include "utils/ustring_utils.hh"
# include "utils/gravatar.hh"
# ifndef DISABLE_PLUGINS
# include "plugin/manager.hh"
# endif
using namespace boost::filesystem;
namespace Astroid {
int PageClient::id = 0;
PageClient::PageClient (ThreadView * t) {
id++;
ready = false;
thread_view = t;
/* load attachment icon */
Glib::RefPtr<Gtk::IconTheme> theme = Gtk::IconTheme::get_default();
attachment_icon = theme->load_icon (
"mail-attachment-symbolic",
ATTACHMENT_ICON_WIDTH,
Gtk::ICON_LOOKUP_USE_BUILTIN );
extension_connect_id = g_signal_connect (thread_view->context,
"initialize-web-extensions",
G_CALLBACK (PageClient_init_web_extensions),
(gpointer) this);
}
extern "C" void PageClient_init_web_extensions (
WebKitWebContext * context,
gpointer user_data) {
((PageClient *) user_data)->init_web_extensions (context);
}
PageClient::~PageClient () {
LOG (debug) << "pc: destruct";
g_signal_handler_disconnect (thread_view->context,
extension_connect_id);
LOG (debug) << "pc: closing";
istream.clear ();
ostream.clear ();
ext->close ();
srv->close ();
}
void PageClient::init_web_extensions (WebKitWebContext * context) {
/* add path to Astroid web extension */
# ifdef DEBUG
if (exists (path (Resource::get_exe_dir ()) / path("libtvextension.so"))) {
LOG (warn) << "pc: DEBUG build - found local extension. adding: " << Resource::get_exe_dir().c_str () << " to web extensions search path.";
webkit_web_context_set_web_extensions_directory (
context,
Resource::get_exe_dir ().c_str());
} else {
LOG (warn) << "pc: DEBUG build. no local extension found. adding installed path.";
path wke = path (PREFIX) / path ("lib/astroid/web-extensions");
LOG (info) << "pc: adding " << wke.c_str () << " to web extension search path.";
webkit_web_context_set_web_extensions_directory (
context,
wke.c_str());
}
# else
path wke = path (PREFIX) / path ("lib/astroid/web-extensions");
LOG (info) << "pc: adding " << wke.c_str () << " to web extension search path.";
webkit_web_context_set_web_extensions_directory (
context,
wke.c_str());
# endif
/* set up unix socket */
LOG (warn) << "pc: id: " << id;
socket_addr = ustring::compose ("%1/astroid.%2.%3.%4",
astroid->standard_paths ().socket_dir.c_str(),
getpid(),
id,
UstringUtils::random_alphanumeric (30));
refptr<Gio::UnixSocketAddress> addr = Gio::UnixSocketAddress::create (socket_addr,
# if defined __FreeBSD__ || defined __APPLE__
Gio::UNIX_SOCKET_ADDRESS_PATH);
# elif
Gio::UNIX_SOCKET_ADDRESS_ABSTRACT);
# endif