Commit 5843e9a1 authored by Tatiana Meshkova's avatar Tatiana Meshkova

Move default embedlite components to standalone repository

parents
EXTRA_DIST = \
autogen.sh
SUBDIRS = history chromehelper prompt
INCLUDES = $(DEPS_CFLAGS)
#!/bin/sh
set -x
libtoolize --automake
aclocal
autoconf
autoheader
automake --add-missing --foreign
./configure
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "EmbedChromeListener.h"
#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "mozilla/embedlite/EmbedLog.h"
#include "nsStringGlue.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDOMWindow.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEvent.h"
#include "nsPIDOMWindow.h"
#include "nsIEmbedLiteJSON.h"
#include "nsComponentManagerUtils.h"
#include "nsIVariant.h"
#include "nsHashPropertyBag.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDOMHTMLLinkElement.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMPageTransitionEvent.h"
#include "nsIFocusManager.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
EmbedChromeListener::EmbedChromeListener(nsIDOMWindow* aWin)
: DOMWindow(aWin)
, mWindowCounter(0)
{
if (!mService) {
mService = do_GetService("@mozilla.org/embedlite-app-service;1");
}
}
EmbedChromeListener::~EmbedChromeListener()
{
}
NS_IMPL_ISUPPORTS1(EmbedChromeListener, nsIDOMEventListener)
nsresult
GetDOMWindowByNode(nsIDOMNode *aNode, nsIDOMWindow **aDOMWindow)
{
nsresult rv;
nsCOMPtr<nsIDOMDocument> ctDoc = do_QueryInterface(aNode, &rv);
NS_ENSURE_SUCCESS(rv , rv);
nsCOMPtr<nsIDOMWindow> targetWin;
rv = ctDoc->GetDefaultView(getter_AddRefs(targetWin));
NS_ENSURE_SUCCESS(rv , rv);
*aDOMWindow = targetWin.forget().get();
return rv;
}
NS_IMETHODIMP
GetTopWindow(nsIDOMWindow* aWin, nsIDOMWindow **aDOMWindow)
{
nsCOMPtr<nsIDOMWindow> window;
nsCOMPtr<nsIWebNavigation> navNav(do_GetInterface(aWin));
nsCOMPtr<nsIDocShellTreeItem> navItem(do_QueryInterface(navNav));
NS_ENSURE_TRUE(navItem, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> rootItem;
navItem->GetRootTreeItem(getter_AddRefs(rootItem));
nsCOMPtr<nsIDOMWindow> rootWin(do_GetInterface(rootItem));
NS_ENSURE_TRUE(rootWin, NS_ERROR_FAILURE);
rootWin->GetTop(getter_AddRefs(window));
*aDOMWindow = window.forget().get();
return NS_OK;
}
NS_IMETHODIMP
EmbedChromeListener::HandleEvent(nsIDOMEvent* aEvent)
{
nsresult rv;
nsString type;
if (aEvent) {
aEvent->GetType(type);
}
// LOGT("Event:'%s'", NS_ConvertUTF16toUTF8(type).get());
nsString messageName;
nsString message;
// Just simple property bag support still
nsCOMPtr<nsIEmbedLiteJSON> json = do_GetService("@mozilla.org/embedlite-json;1", &rv);
if (!json) {
LOGT("Failed to create json component");
}
nsCOMPtr<nsIWritablePropertyBag2> root;
json->CreateObject(getter_AddRefs(root));
nsCOMPtr<nsIDOMWindow> docWin = do_GetInterface(DOMWindow);
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(DOMWindow);
uint32_t winid;
mService->GetIDByWindow(window, &winid);
NS_ENSURE_TRUE(winid , NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
if (type.EqualsLiteral(MOZ_DOMMetaAdded)) {
messageName.AssignLiteral("chrome:metaadded");
} else if (type.EqualsLiteral(MOZ_DOMTitleChanged)) {
nsCOMPtr<nsIDOMDocument> ctDoc;
window->GetDocument(getter_AddRefs(ctDoc));
nsString title;
ctDoc->GetTitle(title);
messageName.AssignLiteral("chrome:title");
root->SetPropertyAsAString(NS_LITERAL_STRING("title"), title);
} else if (type.EqualsLiteral(MOZ_DOMContentLoaded)) {
nsCOMPtr<nsIDOMDocument> ctDoc;
window->GetDocument(getter_AddRefs(ctDoc));
nsString docURI;
ctDoc->GetDocumentURI(docURI);
if (!docURI.EqualsLiteral("about:blank")) {
messageName.AssignLiteral("chrome:contentloaded");
root->SetPropertyAsAString(NS_LITERAL_STRING("docuri"), docURI);
}
// Need send session history from here
} else if (type.EqualsLiteral(MOZ_DOMLinkAdded)) {
nsCOMPtr<nsIDOMEventTarget> origTarget;
aEvent->GetOriginalTarget(getter_AddRefs(origTarget));
nsCOMPtr<nsIDOMHTMLLinkElement> disabledIface = do_QueryInterface(origTarget);
nsString href;
bool disabled = true;
disabledIface->GetDisabled(&disabled);
if (!disabledIface || disabled) {
return NS_OK;
}
disabledIface->GetHref(href);
nsCOMPtr<nsIDOMDocument> ctDoc;
window->GetDocument(getter_AddRefs(ctDoc));
nsString charset, title, rel, type;
ctDoc->GetCharacterSet(charset);
ctDoc->GetTitle(title);
disabledIface->GetRel(rel);
disabledIface->GetType(type);
nsString sizes;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(origTarget);
bool hasSizesAttr = false;
if (NS_SUCCEEDED(element->HasAttribute(NS_LITERAL_STRING("sizes"), &hasSizesAttr)) && hasSizesAttr) {
element->GetAttribute(NS_LITERAL_STRING("sizes"), sizes);
}
messageName.AssignLiteral("chrome:linkadded");
root->SetPropertyAsAString(NS_LITERAL_STRING("href"), href);
root->SetPropertyAsAString(NS_LITERAL_STRING("charset"), charset);
root->SetPropertyAsAString(NS_LITERAL_STRING("title"), title);
root->SetPropertyAsAString(NS_LITERAL_STRING("rel"), rel);
root->SetPropertyAsAString(NS_LITERAL_STRING("sizes"), sizes);
root->SetPropertyAsAString(NS_LITERAL_STRING("get"), type);
} else if (type.EqualsLiteral(MOZ_DOMWillOpenModalDialog) ||
type.EqualsLiteral(MOZ_DOMModalDialogClosed) ||
type.EqualsLiteral(MOZ_DOMWindowClose)) {
messageName.AssignLiteral("chrome:winopenclose");
root->SetPropertyAsAString(NS_LITERAL_STRING("type"), type);
} else if (type.EqualsLiteral(MOZ_DOMPopupBlocked)) {
uint64_t outerWindowID = 0;
utils->GetOuterWindowID(&outerWindowID);
nsCOMPtr<nsIDOMPopupBlockedEvent> popupEvent = do_QueryInterface(aEvent);
nsCOMPtr<nsIURI> popupUri;
popupEvent->GetPopupWindowURI(getter_AddRefs(popupUri));
nsString popupWinFeatures, popupWindowName;
nsCString spec, origCharset;
popupUri->GetSpec(spec);
popupUri->GetOriginCharset(origCharset);
popupEvent->GetPopupWindowFeatures(popupWinFeatures);
popupEvent->GetPopupWindowName(popupWindowName);
messageName.AssignLiteral("chrome:popupblocked");
root->SetPropertyAsACString(NS_LITERAL_STRING("spec"), spec);
root->SetPropertyAsACString(NS_LITERAL_STRING("origCharset"), origCharset);
root->SetPropertyAsAString(NS_LITERAL_STRING("popupWinFeatures"), popupWinFeatures);
root->SetPropertyAsAString(NS_LITERAL_STRING("popupWindowName"), popupWindowName);
} else if (type.EqualsLiteral(MOZ_pageshow) ||
type.EqualsLiteral(MOZ_pagehide)) {
nsCOMPtr<nsIDOMEventTarget> target;
aEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIDOMDocument> ctDoc = do_QueryInterface(target);
nsCOMPtr<nsIDOMWindow> targetWin;
ctDoc->GetDefaultView(getter_AddRefs(targetWin));
if (targetWin != docWin) {
return NS_OK;
}
nsCOMPtr<nsIDOMWindowUtils> tutils = do_GetInterface(targetWin);
uint64_t outerWindowID = 0, tinnerID = 0;
tutils->GetOuterWindowID(&outerWindowID);
tutils->GetCurrentInnerWindowID(&tinnerID);
int32_t innerWidth, innerHeight;
docWin->GetInnerWidth(&innerWidth);
docWin->GetInnerHeight(&innerHeight);
nsCOMPtr<nsIDOMPageTransitionEvent> transEvent = do_QueryInterface(aEvent);
bool persisted = false;
transEvent->GetPersisted(&persisted);
messageName.AssignLiteral("chrome:");
messageName.Append(type);
root->SetPropertyAsBool(NS_LITERAL_STRING("persisted"), persisted);
} else {
return NS_OK;
}
nsString outStr;
json->CreateJSON(root, message);
mService->SendAsyncMessage(winid, messageName.get(), message.get());
return NS_OK;
}
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef EmbedChromeListener_H_
#define EmbedChromeListener_H_
#include "nsWeakReference.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "nsIEmbedAppService.h"
#include "nsIDOMWindow.h"
#define MOZ_DOMTitleChanged "DOMTitleChanged"
#define MOZ_DOMContentLoaded "DOMContentLoaded"
#define MOZ_DOMLinkAdded "DOMLinkAdded"
#define MOZ_DOMWillOpenModalDialog "DOMWillOpenModalDialog"
#define MOZ_DOMModalDialogClosed "DOMModalDialogClosed"
#define MOZ_DOMWindowClose "DOMWindowClose"
#define MOZ_DOMPopupBlocked "DOMPopupBlocked"
#define MOZ_pageshow "pageshow"
#define MOZ_pagehide "pagehide"
#define MOZ_DOMMetaAdded "DOMMetaAdded"
class EmbedChromeListener : public nsIDOMEventListener
{
public:
EmbedChromeListener(nsIDOMWindow* aWin);
virtual ~EmbedChromeListener();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
nsCOMPtr<nsIDOMWindow> DOMWindow;
private:
nsCOMPtr<nsIEmbedAppService> mService;
int mWindowCounter;
};
#endif /*EmbedChromeListener_H_*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#define LOG_COMPONENT "EmbedChromeManager"
#include "mozilla/embedlite/EmbedLog.h"
#include "EmbedChromeManager.h"
#include "EmbedChromeListener.h"
#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "nsStringGlue.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDOMWindow.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEvent.h"
#include "nsPIDOMWindow.h"
#include "nsIEmbedLiteJSON.h"
#include "nsComponentManagerUtils.h"
#include "nsIVariant.h"
#include "nsHashPropertyBag.h"
#include "nsIDOMWindowUtils.h"
#include "nsIDOMHTMLLinkElement.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMPageTransitionEvent.h"
#include "nsIFocusManager.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
EmbedChromeManager::EmbedChromeManager()
: mWindowCounter(0)
{
}
EmbedChromeManager::~EmbedChromeManager()
{
}
NS_IMPL_ISUPPORTS2(EmbedChromeManager, nsIObserver, nsSupportsWeakReference)
nsresult
EmbedChromeManager::Init()
{
nsresult rv;
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (observerService) {
rv = observerService->AddObserver(this,
"domwindowopened",
true);
NS_ENSURE_SUCCESS(rv, rv);
rv = observerService->AddObserver(this,
"domwindowclosed",
true);
NS_ENSURE_SUCCESS(rv, rv);
rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
false);
NS_ENSURE_SUCCESS(rv, rv);
}
return rv;
}
NS_IMETHODIMP
EmbedChromeManager::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsresult rv;
if (!strcmp(aTopic, "domwindowopened")) {
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(aSubject, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
WindowCreated(win);
} else if (!strcmp(aTopic, "domwindclosed")) {
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(aSubject, &rv);
NS_ENSURE_SUCCESS(rv, NS_OK);
WindowDestroyed(win);
} else {
LOGT("obj:%p, top:%s", aSubject, aTopic);
}
return NS_OK;
}
void
EmbedChromeManager::WindowCreated(nsIDOMWindow* aWin)
{
LOGT("WindowOpened: %p", aWin);
nsCOMPtr<nsPIDOMWindow> pidomWindow = do_GetInterface(aWin);
NS_ENSURE_TRUE(pidomWindow, );
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(pidomWindow->GetChromeEventHandler());
NS_ENSURE_TRUE(target, );
nsCOMPtr<EmbedChromeListener> listener = new EmbedChromeListener(aWin);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMTitleChanged), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMContentLoaded), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMLinkAdded), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMWillOpenModalDialog), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMModalDialogClosed), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMWindowClose), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMPopupBlocked), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_pageshow), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_pagehide), listener, PR_FALSE);
target->AddEventListener(NS_LITERAL_STRING(MOZ_DOMMetaAdded), listener, PR_FALSE);
mArray.AppendObject(listener);
mWindowCounter++;
if (!mService) {
mService = do_GetService("@mozilla.org/embedlite-app-service;1");
}
}
void
EmbedChromeManager::WindowDestroyed(nsIDOMWindow* aWin)
{
LOGT("WindowClosed: %p", aWin);
nsCOMPtr<nsPIDOMWindow> pidomWindow = do_GetInterface(aWin);
NS_ENSURE_TRUE(pidomWindow, );
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(pidomWindow->GetChromeEventHandler());
NS_ENSURE_TRUE(target, );
nsCOMPtr<EmbedChromeListener> listener;
int i = 0;
for (i = 0; i < mArray.Count(); ++i) {
if (mArray[i]->DOMWindow.get() == aWin) {
listener = mArray[i];
break;
}
}
mArray.RemoveObjectAt(i);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMTitleChanged), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMContentLoaded), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMLinkAdded), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMWillOpenModalDialog), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMModalDialogClosed), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMWindowClose), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMPopupBlocked), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_pageshow), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_pagehide), listener, PR_FALSE);
target->RemoveEventListener(NS_LITERAL_STRING(MOZ_DOMMetaAdded), listener, PR_FALSE);
mWindowCounter--;
if (!mWindowCounter) {
mService = nullptr;
}
}
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef EmbedChromeManager_H_
#define EmbedChromeManager_H_
#include "nsWeakReference.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "nsIEmbedAppService.h"
#include "EmbedChromeListener.h"
#include "nsCOMArray.h"
class EmbedChromeManager : public nsIObserver,
public nsSupportsWeakReference
{
public:
EmbedChromeManager();
virtual ~EmbedChromeManager();
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
nsresult Init();
private:
void WindowCreated(nsIDOMWindow* aWin);
void WindowDestroyed(nsIDOMWindow* aWin);
nsCOMPtr<nsIEmbedAppService> mService;
int mWindowCounter;
typedef nsCOMArray<EmbedChromeListener> ObserversArray;
ObserversArray mArray;
};
#define NS_EMBED_CHROME_CONTRACTID "@mozilla.org/embed-chrome-component;1"
#define NS_EMBED_CHROME_SERVICE_CLASSNAME "Embed Chrome Listener Component"
#define NS_EMBED_CHROME_SERVICE_CID \
{ 0xab157a4c, \
0x6aaf, \
0x12e2, \
{ 0xa6, 0x9f, 0x4f, 0xcc, 0xae, 0x4e, 0x8e, 0xc6 }}
#endif /*EmbedChromeManager_H_*/
libbzdir = $(libdir)/mozembedlite/components
libbz_LTLIBRARIES = libchromehelper.la
libchromehelper_la_SOURCES = \
EmbedChromeListener.cpp \
EmbedChromeManager.cpp \
nsEmbedChromeModule.cpp \
$(NULL)
libchromehelper_la_CPPFLAGS = \
$(ENGINE_CFLAGS) \
$(NULL)
libchromehelper_la_LDFLAGS = -module -avoid-version
libchromehelper_la_LIBADD = \
$(ENGINE_LIBS) \
$(NULL)
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsServiceManagerUtils.h"
#include "nsICategoryManager.h"
#include "mozilla/ModuleUtils.h"
#include "nsIAppStartupNotifier.h"
#include "EmbedChromeManager.h"
#include "nsNetCID.h"
#include <iostream>
// XPCOMGlueStartup
#include "nsXPCOMGlue.h"
/* ===== XPCOM registration stuff ======== */
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(EmbedChromeManager, Init)
NS_DEFINE_NAMED_CID(NS_EMBED_CHROME_SERVICE_CID);
static const mozilla::Module::CIDEntry kEMBEDCHROMECIDs[] = {
{ &kNS_EMBED_CHROME_SERVICE_CID, false, NULL, EmbedChromeManagerConstructor },
{ NULL }
};
static const mozilla::Module::ContractIDEntry kEMBEDCHROMEContracts[] = {
{ NS_EMBED_CHROME_CONTRACTID, &kNS_EMBED_CHROME_SERVICE_CID },
{ NULL }
};
static const mozilla::Module::CategoryEntry kEMBEDCHROMECategories[] = {
{ APPSTARTUP_CATEGORY, NS_EMBED_CHROME_SERVICE_CLASSNAME, NS_EMBED_CHROME_CONTRACTID },
{ NULL }
};
static nsresult
EmbedChrome_Initialize()
{
#ifdef XPCOM_GLUE
XPCOMGlueStartup(getenv("XRE_LIBXPCOM_PATH"));
#endif
return NS_OK;
}
static void
EmbedChrome_Shutdown()
{
}
static const mozilla::Module kEMBEDCHROMEModule = {
mozilla::Module::kVersion,
kEMBEDCHROMECIDs,
kEMBEDCHROMEContracts,
kEMBEDCHROMECategories,
NULL,
EmbedChrome_Initialize,
EmbedChrome_Shutdown
};
NSMODULE_DEFN(nsEmbedChromeModule) = &kEMBEDCHROMEModule;
AC_INIT(configure.ac)
AM_CONFIG_HEADER(config.h)
VERSION=1.0.0
AM_INIT_AUTOMAKE(historycomponent, $VERSION)
AC_PROG_CXX
AC_PROG_CXXCPP
AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_CHECK_TOOL(AR, ar)
AC_HEADER_STDC
AC_LIBTOOL_DLOPEN
AM_PROG_LIBTOOL
AC_PROG_CPP
AC_HEADER_STDC
PKG_CHECK_MODULES(ENGINE, libxul nspr,
[
SDK_DIR=`pkg-config --variable=sdkdir libxul`
IDL_DIR=`pkg-config --variable=idldir libxul`
AC_SUBST(SDK_DIR)
AC_SUBST(IDL_DIR)
])
CXXFLAGS+=" -include mozilla-config.h -std=gnu++0x "
CXXFLAGS+=" -Wno-attributes -Wno-ignored-qualifiers -Wall "
CXXFLAGS+=" -Wno-unused-parameter -Wpointer-arith -Woverloaded-virtual "
CXXFLAGS+=" -Werror=return-type -Wtype-limits -Wempty-body -Wno-ctor-dtor-privacy "
CXXFLAGS+=" -Wno-format -Wno-overlength-strings -Wno-invalid-offsetof "
CXXFLAGS+=" -Wno-variadic-macros -Wno-long-long -Wno-psabi "
AC_SUBST(ENGINE_CFLAGS)
AC_SUBST(ENGINE_LIBS)
AC_OUTPUT([
Makefile
history/Makefile
chromehelper/Makefile
prompt/Makefile
])
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "EmbedHistoryListener.h"
#include "nsIURI.h"
#include "mozilla/dom/Link.h"
#include "nsIEmbedLiteJSON.h"
#include "nsIObserverService.h"
using namespace mozilla;
using mozilla::dom::Link;
NS_IMPL_ISUPPORTS2(EmbedHistoryListener, IHistory, nsIRunnable)
EmbedHistoryListener* EmbedHistoryListener::sHistory = NULL;
/*static*/
EmbedHistoryListener*
EmbedHistoryListener::GetSingleton()
{
if (!sHistory) {
sHistory = new EmbedHistoryListener();
NS_ENSURE_TRUE(sHistory, nullptr);
}
NS_ADDREF(sHistory);
return sHistory;
}
EmbedHistoryListener::EmbedHistoryListener()
{
mListeners.Init();
}
NS_IMETHODIMP
EmbedHistoryListener::RegisterVisitedCallback(nsIURI *aURI, Link *aContent)
{
if (!aContent || !aURI)
return NS_OK;
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;
NS_ConvertUTF8toUTF16 uriString(uri);
nsTArray<Link*>* list = mListeners.Get(uriString);
if (! list) {
list = new nsTArray<Link*>();
mListeners.Put(uriString, list);
}
list->AppendElement(aContent);
nsString message;
// Just simple property bag support still
nsCOMPtr<nsIEmbedLiteJSON> json = do_GetService("@mozilla.org/embedlite-json;1");
nsCOMPtr<nsIWritablePropertyBag2> root;
json->CreateObject(getter_AddRefs(root));
root->SetPropertyAsACString(NS_LITERAL_STRING("uri"), uri);
json->CreateJSON(root, message);
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (observerService)
observerService->NotifyObservers(nullptr, "history:checkurivisited", message.get());
return NS_OK;
}
NS_IMETHODIMP
EmbedHistoryListener::UnregisterVisitedCallback(nsIURI *aURI, Link *aContent)
{
if (!aContent || !aURI)
return NS_OK;
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;
NS_ConvertUTF8toUTF16 uriString(uri);
nsTArray<Link*>* list = mListeners.Get(uriString);
if (! list)
return NS_OK;
list->RemoveElement(aContent);
if (list->IsEmpty()) {
mListeners.Remove(uriString);
delete list;
}
return NS_OK;
}
NS_IMETHODIMP
EmbedHistoryListener::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, uint32_t aFlags)
{
if (!aURI)
return NS_OK;
if (!(aFlags & VisitFlags::TOP_LEVEL))
return NS_OK;
if (aFlags & VisitFlags::REDIRECT_SOURCE)
return NS_OK;
if (aFlags & VisitFlags::UNRECOVERABLE_ERROR)
return NS_OK;
nsAutoCString uri;
nsresult rv = aURI->GetSpec(uri);
if (NS_FAILED(rv)) return rv;
nsString message;
// Just simple property bag support still
nsCOMPtr<nsIEmbedLiteJSON> json = do_GetService("@mozilla.org/embedlite-json;1");
nsCOMPtr<nsIWritablePropertyBag2> root;
json->CreateObject(getter_AddRefs(root));
root->SetPropertyAsACString(NS_LITERAL_STRING("uri"), uri);
json->CreateJSON(root, message);
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (observerService)
observerService->NotifyObservers(nullptr, "history:markurivisited", message.get());