RegisterCmd, checked and enabled callback

Open and close tab event
import/tags/kmeleon75
boisso 7 years ago
parent 060acdca2f
commit 2e066bc080
  1. 1
      k-meleon/JSBridge/JSBridge.vcxproj
  2. 60
      k-meleon/JSBridge/jscomp.cpp
  3. 9
      k-meleon/JSBridge/jscomp.h
  4. 17
      k-meleon/JSBridge/jsplugin.cpp
  5. 2
      k-meleon/JSBridge/nsIJSBridge.idl

@ -94,6 +94,7 @@
<ImportLibrary>$(OutDir)JSBridge.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
</Link>
<PostBuildEvent>
<Command>copy jsbridge.xpt ..\..\release\browser\components</Command>

@ -55,6 +55,23 @@ CCmdList* GetCmdList() {
return cmdList;
}
int CCmdList::GetState(int command) {
auto eIter = eMap.find(command);
auto cIter = cMap.find(command);
if (eIter == eMap.end() && cIter == cMap.end()) return -1;
int res = 0;
bool b;
if (eIter != eMap.end()) {
eIter->second->Run(nullptr, &b);
if (b) res |= 0x1;
}
if (cIter != cMap.end()) {
cIter->second->Run(nullptr, &b);
if (b) res |= 0x2;
}
return res;
}
bool CCmdList::Run(HWND hwnd, UINT command, UINT mode) {
auto iter = cmdMap.find(command);
if (iter != cmdMap.end() && iter->second) {
@ -318,7 +335,7 @@ NS_IMETHODIMP CJSBridge::RegisterCmd(const char * name, const char * desc,
} else
id = kPlugin.kFuncs->RegisterCmd(name, desc, iconPath);
::GetCmdList()->Add(id, command);
::GetCmdList()->Add(id, command, enabled, checked);
if (iconPath) JS_free(cx, iconPath);
return NS_OK;
}
@ -430,7 +447,7 @@ NS_IMETHODIMP CJSBridge::GetWindows(uint32_t *length, kmIWindow * **list)
HWND* hList = new HWND[size];
kPlugin.kFuncs->GetWindowsList(hList, size);
kmIWindow** wins = static_cast<kmIWindow**>(NS_Alloc(size*sizeof(kmIWindow*)));
for (unsigned i = 0;i<size;i++) {
for (int i = 0;i<size;i++) {
CWin* win = new CWin();
win->hWnd = hList[i];
void *result;
@ -506,3 +523,42 @@ void CJSBridge::OnSwitchTab(HWND oldhWnd, HWND newhWnd)
mListeners.EnumerateForwards(notifySwitchTab, dom);
}
bool notifyCreateTab(nsIObserver *aListener, void* aData)
{
kmIWindow* winData = static_cast<kmIWindow*>(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);
}
bool notifyDestroyTab(nsIObserver *aListener, void* aData)
{
kmIWindow* winData = static_cast<kmIWindow*>(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);
}

@ -17,11 +17,16 @@ static NS_DEFINE_CID(kJSBridgeCID, JSBRIDGE_CID);
class CCmdList {
private:
std::map<UINT, nsCOMPtr<kmICommandFunction>> cmdMap;
std::map<UINT, nsCOMPtr<kmICallback>> eMap;
std::map<UINT, nsCOMPtr<kmICallback>> cMap;
public:
void Add(UINT id, kmICommandFunction* command) {
void Add(UINT id, kmICommandFunction* command, kmICallback* enabled = nullptr, kmICallback* checked = nullptr) {
cmdMap.insert(std::pair<UINT,kmICommandFunction*>(id, command));
if (enabled) eMap.insert(std::pair<UINT,kmICallback*>(id, enabled));
if (checked) cMap.insert(std::pair<UINT,kmICallback*>(id, checked));
}
bool Run(HWND hwnd, UINT command, UINT mode);
int GetState(int id);
};
typedef std::string string;
@ -67,6 +72,8 @@ public:
void OnCreateWindow(HWND hWnd, int flag);
void OnSwitchTab(HWND oldhWnd, HWND newhWnd);
void OnCreateTab(HWND hWnd);
void OnDestroyTab(HWND hWnd);
protected:
nsCOMArray<nsIObserver> mListeners;
};

@ -133,7 +133,14 @@ long DoMessage(const char *to, const char *from, const char *subject,
long data1, long data2)
{
if (to[0] == '*' || stricmp(to, kPlugin.dllname) == 0) {
if (strcmp(subject, "Init") == 0) {
if (strcmp(subject, "GetState") == 0) {
if (!cmdList) return 0;
unsigned res = cmdList->GetState(data1);
if (res == -1) return 0;
*((unsigned*)data2) = res;
return 1;
}
else if (strcmp(subject, "Init") == 0) {
Init();
}
@ -150,7 +157,13 @@ long DoMessage(const char *to, const char *from, const char *subject,
else if (strcmp(subject, "SwitchTab") == 0) {
if (getJSB()) getJSB()->OnSwitchTab((HWND)data1, (HWND)data2);
}
}
else if (strcmp(subject, "CreateTab") == 0) {
if (getJSB()) getJSB()->OnCreateTab((HWND)data1);
}
else if (strcmp(subject, "DestroyTab") == 0) {
if (getJSB()) getJSB()->OnDestroyTab((HWND)data1);
}
else return 0;
return 1;

@ -13,7 +13,7 @@ interface kmICommandFunction:nsISupports {
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef4)]
interface kmICallback:nsISupports {
void run();
bool run([optional] in string arg);
};
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef5)]

Loading…
Cancel
Save