Browse Source

Add dom window in command function parameters

master
boisso 8 years ago
parent
commit
fae7e519db
  1. 18
      k-meleon/JSBridge/jscomp.cpp
  2. 9
      k-meleon/JSBridge/jscomp.h
  3. 2
      k-meleon/JSBridge/jsplugin.cpp
  4. 5
      k-meleon/JSBridge/nsIJSBridge.idl

18
k-meleon/JSBridge/jscomp.cpp

@ -22,6 +22,19 @@ CCmdList* GetCmdList() {
return cmdList;
}
bool CCmdList::Run(HWND hwnd, UINT command, UINT mode) {
nsCOMPtr<nsIWebBrowser> browser;
kPlugin.kFuncs->GetMozillaWebBrowser(hwnd, getter_AddRefs(browser));
nsCOMPtr<nsIDOMWindow> dom;
browser->GetContentDOMWindow(getter_AddRefs(dom));
auto iter = cmdMap.find(command);
if (iter != cmdMap.end() && iter->second) {
iter->second->OnCommand(dom, mode, nullptr);
return true;
}
return false;
}
NS_IMPL_ISUPPORTS (CJSCommand, kmICommand)
NS_IMETHODIMP CJSCommand::GetName(char * *aName)
{
@ -204,7 +217,7 @@ NS_IMETHODIMP CJSBridge::RegisterCmd(const char * name, const char * desc,
kmICallback *enabled, kmICallback *checked, JSContext* cx, int32_t *_retval)
{
if (!kPlugin.kFuncs) return NS_ERROR_NOT_INITIALIZED;
char* iconPath;
char* iconPath = nullptr;
UINT id = 0;
if (icon.isObject()) {
JS::RootedObject obj(cx);
@ -232,7 +245,8 @@ NS_IMETHODIMP CJSBridge::RegisterCmd(const char * name, const char * desc,
iconPath = JS_EncodeString(cx, vpath.toString());
kPlugin.kFuncs->SetCmdIcon(name, iconPath, &rect, nullptr, nullptr, nullptr, nullptr);
} else {
iconPath = JS_EncodeString(cx, icon.toString());
if (icon.isString())
iconPath = JS_EncodeString(cx, icon.toString());
id = kPlugin.kFuncs->RegisterCmd(name, desc, iconPath);
}

9
k-meleon/JSBridge/jscomp.h

@ -18,14 +18,7 @@ public:
void Add(UINT id, kmICommandFunction* command) {
cmdMap.insert(std::pair<UINT,kmICommandFunction*>(id, command));
}
bool Run(UINT command, UINT mode) {
auto iter = cmdMap.find(command);
if (iter != cmdMap.end() && iter->second) {
iter->second->OnCommand(mode, nullptr);
return true;
}
return false;
}
bool Run(HWND hwnd, UINT command, UINT mode);
};
typedef std::string string;

2
k-meleon/JSBridge/jsplugin.cpp

@ -159,7 +159,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message) {
case WM_COMMAND:
if (cmdList && cmdList->Run(LOWORD(wParam), lParam)) return 0;
if (cmdList && cmdList->Run(hWnd, LOWORD(wParam), lParam)) return 0;
}
return CallWindowProc(KMeleonWndProc, hWnd, message, wParam, lParam);
}

5
k-meleon/JSBridge/nsIJSBridge.idl

@ -3,10 +3,13 @@
#include "nsIWebBrowser.idl"
interface nsISimpleEnumerator;
interface nsIArray;
interface nsIDOMWindow;
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef3)]
interface kmICommandFunction:nsISupports {
void onCommand(in unsigned long mode, [optional] in string arg);
void onCommand(in nsIDOMWindow win, in unsigned long mode, [optional] in string arg);
};
[scriptable,function, uuid(83910267-7670-4493-99c1-dd540a036ef4)]

Loading…
Cancel
Save