Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: jni/Utils.cpp

Issue 5327480814567424: Issue 1108 - Support notifications (Closed)
Patch Set: Even more renaming, ignore INVALID/QUESTION Created Feb. 18, 2015, 3 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 } 80 }
81 81
82 JNIEnvAcquire::~JNIEnvAcquire() 82 JNIEnvAcquire::~JNIEnvAcquire()
83 { 83 {
84 if (attachmentStatus == JNI_EDETACHED) 84 if (attachmentStatus == JNI_EDETACHED)
85 { 85 {
86 javaVM->DetachCurrentThread(); 86 javaVM->DetachCurrentThread();
87 } 87 }
88 } 88 }
89
90 template<typename T>
91 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass)
92 {
93 if (!value.get())
94 {
95 return 0;
96 }
97
98 JniLocalReference<jclass> clazz(
99 env,
100 env->FindClass(javaClass));
101 jmethodID method = env->GetMethodID(*clazz, "<init>", "(J)V");
102
103 return env->NewObject(
104 *clazz,
105 method,
106 JniPtrToLong(new T(value)));
107 }
108
109 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter)
110 {
111 return NewJniObject(env, filter, PKG("Filter"));
112 }
113
114 jobject NewJniSubscription(JNIEnv* env,
115 const AdblockPlus::SubscriptionPtr& subscription)
116 {
117 return NewJniObject(env, subscription, PKG("Subscription"));
118 }
119
120 jobject NewJniNotification(JNIEnv* env,
121 const AdblockPlus::NotificationPtr& notification)
122 {
123 return NewJniObject(env, notification, PKG("Notification"));
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld