~ubuntu-branches/ubuntu/natty/adblock-plus/natty

« back to all changes in this revision

Viewing changes to kmeleon/misc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-11-05 18:42:36 UTC
  • mto: (25.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20101105184236-h7dnu8mbfjaoya62
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "adblockplus.h"
26
26
 
27
 
JSObject* UnwrapJSObject(nsISupports* native) {
28
 
  nsCOMPtr<nsIXPConnectWrappedJS> holder = do_QueryInterface(native);
29
 
  if (holder == nsnull)
30
 
    return nsnull;
31
 
 
32
 
  JSObject* innerObj;
33
 
  nsresult rv = holder->GetJSObject(&innerObj);
34
 
  if (NS_FAILED(rv))
35
 
    return nsnull;
36
 
 
37
 
  return innerObj;
 
27
JSBool CallModuleMethod(char* methodName, uintN argc, jsval* argv, jsval* retval, ArgsInitCallback callback, void* data)
 
28
{
 
29
  jsval localResult;
 
30
  if (!retval)
 
31
    retval = &localResult;
 
32
 
 
33
  nsCOMPtr<xpcIJSModuleLoader> moduleLoader = do_GetService("@mozilla.org/moz/jsloader;1");
 
34
  if (!moduleLoader)
 
35
    return JS_FALSE;
 
36
 
 
37
  nsresult rv;
 
38
  JSObject* globalObj;
 
39
  rv = moduleLoader->ImportInto(NS_LITERAL_CSTRING("resource:///modules/adblockplus/AppIntegrationKMeleon.jsm"), nsnull, nsnull, &globalObj);
 
40
  if (NS_FAILED(rv) || !globalObj)
 
41
    return JS_FALSE;
 
42
 
 
43
  abpJSContextHolder holder;
 
44
  JSContext* cx = holder.get();
 
45
  if (!cx)
 
46
    return JS_FALSE;
 
47
 
 
48
  if (callback && !callback(cx, globalObj, argv, data))
 
49
    return JS_FALSE;
 
50
 
 
51
  return JS_CallFunctionName(cx, globalObj, methodName, argc, argv, retval);
38
52
}
39
53
 
40
54
nsISupports* UnwrapNative(JSContext* cx, JSObject* obj) {
69
83
    kFuncs->SendMessage("layers", PLUGIN_NAME, "AddLayersToWindow", (LONG)"1", (LONG)url);
70
84
}
71
85
 
72
 
void ShowContextMenu(HWND hWnd, PRBool status) {
73
 
  abpJSContextHolder holder;
74
 
  JSObject* overlay = UnwrapJSObject(fakeBrowserWindow);
75
 
  JSContext* cx = holder.get();
76
 
  if (cx != nsnull && overlay != nsnull) {
77
 
    jsval arg = (status ? JSVAL_TRUE : JSVAL_FALSE);
78
 
    jsval retval;
79
 
    if (JS_CallFunctionName(cx, overlay, "buildContextMenu", 1, &arg, &retval)) {
80
 
      HMENU hMenu = NS_REINTERPRET_CAST(HMENU, JSVAL_TO_INT(retval));
 
86
void ShowContextMenu(HWND hWnd, PRBool status)
 
87
{
 
88
  jsval args[] = {
 
89
    INT_TO_JSVAL(hWnd),
 
90
    status ? JSVAL_TRUE : JSVAL_FALSE
 
91
  };
 
92
  jsval retval;
 
93
  if (CallModuleMethod("buildContextMenu", 2, args, &retval))
 
94
  {
 
95
    HMENU hMenu = reinterpret_cast<HMENU>(JSVAL_TO_INT(retval));
81
96
 
82
 
      POINT pt;
83
 
      GetCursorPos(&pt);
84
 
      TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
85
 
    }
 
97
    POINT pt;
 
98
    GetCursorPos(&pt);
 
99
    TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
86
100
  }
87
101
}
88
102