Testing code for open/close tab event

master
Dorian 7 years ago
parent d6bd255c6c
commit 440b84241b
  1. 9
      k-meleon/kplugins/jsbridge/idl/nsIJSBridge.idl
  2. 70
      k-meleon/kplugins/jsbridge/jscomp.cpp
  3. 4
      k-meleon/kplugins/jsbridge/jsplugin.cpp

@ -16,12 +16,19 @@ interface kmICallback:nsISupports {
bool run([optional] in string arg);
};
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef5)]
[scriptable, uuid(83910267-7670-4493-99c1-dd540a036ef5)]
interface kmIWindow:nsISupports {
readonly attribute voidPtr handle;
void getTabs([optional] out unsigned long length, [array, size_is(length), retval] out nsIWebBrowser list);
};
[scriptable, uuid(83910267-7670-4493-99c1-dd540a036ef6)]
interface kmITab :nsISupports {
readonly attribute voidPtr handle;
readonly attribute nsIWebBrowser browser;
readonly attribute nsIDOMEventTarget root;
};
[scriptable, uuid(3d8ce8f0-5214-11db-b0de-0800200c9a65)]
interface kmICommand : nsISupports
{

@ -449,7 +449,19 @@ public:
HWND hWnd;
};
NS_IMPL_ISUPPORTS (CWin, kmIWindow)
NS_IMPL_ISUPPORTS(CWin, kmIWindow)
class CTab : public kmITab {
public:
NS_DECL_ISUPPORTS
NS_DECL_KMITAB
CTab(HWND ahWnd) : hWnd(ahWnd) {};
virtual ~CTab() {};
HWND hWnd;
};
NS_IMPL_ISUPPORTS(CTab, kmITab)
NS_IMETHODIMP CWin::GetHandle(void **aHandle)
{
@ -479,6 +491,33 @@ NS_IMETHODIMP CWin::GetTabs(uint32_t *length, nsIWebBrowser * **list)
return NS_OK;
}
NS_IMETHODIMP CTab::GetHandle(void **aHandle)
{
*aHandle = hWnd;
return NS_OK;
}
NS_IMETHODIMP CTab::GetBrowser(nsIWebBrowser **browser)
{
BOOL s = kPlugin.kFuncs->GetMozillaWebBrowser(hWnd, browser);
return s ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP CTab::GetRoot(nsIDOMEventTarget **root)
{
nsCOMPtr<nsIWebBrowser> browser;
kPlugin.kFuncs->GetMozillaWebBrowser(hWnd, getter_AddRefs(browser));
if (!browser) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> dom;
browser->GetContentDOMWindow(getter_AddRefs(dom));
if (!dom) return NS_ERROR_FAILURE;
dom->GetWindowRoot(root);
if (!root) return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP CJSBridge::GetWindows(uint32_t *length, kmIWindow * **list)
{
*list = nullptr;
@ -572,45 +611,34 @@ void CJSBridge::OnSwitchTab(HWND oldhWnd, HWND newhWnd)
browser->GetContentDOMWindow(getter_AddRefs(dom));
if (!dom) return;
nsCOMPtr<nsIDOMEventTarget> root;
dom->GetWindowRoot(getter_AddRefs(root));
mListeners.EnumerateForwards(notifySwitchTab, dom);
}
bool notifyCreateTab(nsIObserver *aListener, void* aData)
{
kmIWindow* winData = static_cast<kmIWindow*>(aData);
kmITab* winData = static_cast<kmITab*>(aData);
aListener->Observe(winData, "kmeleon-opentab", nullptr);
return true;
}
void CJSBridge::OnCreateTab(HWND hWnd)
{
nsCOMPtr<nsIWebBrowser> browser;
kPlugin.kFuncs->GetMozillaWebBrowser(hWnd, getter_AddRefs(browser));
if (!browser) return;
nsCOMPtr<nsIDOMWindow> dom;
browser->GetContentDOMWindow(getter_AddRefs(dom));
if (!dom) return;
mListeners.EnumerateForwards(notifyCreateTab, dom);
nsCOMPtr<kmITab> tab = new CTab(hWnd);
mListeners.EnumerateForwards(notifyCreateTab, tab.get());
}
bool notifyDestroyTab(nsIObserver *aListener, void* aData)
{
kmIWindow* winData = static_cast<kmIWindow*>(aData);
nsISupports* winData = static_cast<nsISupports*>(aData);
aListener->Observe(winData, "kmeleon-closetab", nullptr);
return true;
}
void CJSBridge::OnDestroyTab(HWND hWnd)
{
nsCOMPtr<nsIWebBrowser> browser;
kPlugin.kFuncs->GetMozillaWebBrowser(hWnd, getter_AddRefs(browser));
if (!browser) return;
nsCOMPtr<nsIDOMWindow> dom;
browser->GetContentDOMWindow(getter_AddRefs(dom));
if (!dom) return;
mListeners.EnumerateForwards(notifyDestroyTab, dom);
nsCOMPtr<kmITab> tab = new CTab(hWnd);
mListeners.EnumerateForwards(notifyDestroyTab, tab.get());
}

@ -160,10 +160,10 @@ long DoMessage(const char *to, const char *from, const char *subject,
if (getJSB()) getJSB()->OnSwitchTab((HWND)data1, (HWND)data2);
}
else if (strcmp(subject, "CreateTab") == 0) {
if (getJSB()) getJSB()->OnCreateTab((HWND)data1);
if (getJSB()) getJSB()->OnCreateTab((HWND)data2);
}
else if (strcmp(subject, "DestroyTab") == 0) {
if (getJSB()) getJSB()->OnDestroyTab((HWND)data1);
if (getJSB()) getJSB()->OnDestroyTab((HWND)data2);
}
else return 0;

Loading…
Cancel
Save