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

Delta Between Two Patch Sets: jni/utilityOps.cpp

Issue 9271056: ABP/Android V8 integration code (Closed)
Left Patch Set: Created Jan. 30, 2013, 9:27 a.m.
Right Patch Set: ABP/Android V8 integration code Created Feb. 1, 2013, 8:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « jni/timerOps.cpp ('k') | jni/wrap.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of the Adblock Plus, 2 * This file is part of the Adblock Plus,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <string> 18 #include <string>
19 #include <android/log.h> 19 #include "debug.h"
20 #include "ops.h" 20 #include "ops.h"
21 #include "wrap.h" 21 #include "wrap.h"
22 22
23 v8::Handle<v8::Value> loadImpl(const v8::Arguments& args) 23 v8::Handle<v8::Value> loadImpl(const v8::Arguments& args)
24 { 24 {
25 D(D_WARN, "load()");
25 v8::HandleScope handle_scope; 26 v8::HandleScope handle_scope;
27
28 JNIEnv* jniEnv = NULL;
29 if (globalJvm->AttachCurrentThread(&jniEnv, NULL) != 0)
30 return v8::ThrowException(v8::String::New("Failed to get JNI environment"));
31
26 if (args.Length() < 1) 32 if (args.Length() < 1)
27 return v8::ThrowException(v8::String::New("File name expected")); 33 return v8::ThrowException(v8::String::New("File name expected"));
28 34
29 v8::String::Utf8Value str(args[0]); 35 v8::String::Utf8Value str(args[0]);
30 if (!*str) 36 if (!*str)
31 return v8::ThrowException(v8::String::New("File name isn't a string")); 37 return v8::ThrowException(v8::String::New("File name isn't a string"));
32 38
33 jstring jstr = jniEnv->NewStringUTF(*str); 39 jstring jstr = jniEnv->NewStringUTF(*str);
34 40
35 jstring result; 41 jstring result;
(...skipping 11 matching lines...) Expand all
47 v8::Handle<v8::String> source = v8::Handle<v8::String>::Cast(wrapJavaObject(jn iEnv, result)); 53 v8::Handle<v8::String> source = v8::Handle<v8::String>::Cast(wrapJavaObject(jn iEnv, result));
48 v8::Handle<v8::Script> script = v8::Script::Compile(source, args[0]); 54 v8::Handle<v8::Script> script = v8::Script::Compile(source, args[0]);
49 if (!script.IsEmpty()) 55 if (!script.IsEmpty())
50 script->Run(); 56 script->Run();
51 57
52 return v8::Undefined(); 58 return v8::Undefined();
53 } 59 }
54 60
55 v8::Handle<v8::Value> setStatusImpl(const v8::Arguments& args) 61 v8::Handle<v8::Value> setStatusImpl(const v8::Arguments& args)
56 { 62 {
63 D(D_WARN, "setStatus()");
57 v8::HandleScope handle_scope; 64 v8::HandleScope handle_scope;
65
66 JNIEnv* jniEnv = NULL;
67 if (globalJvm->AttachCurrentThread(&jniEnv, NULL) != 0)
68 return v8::ThrowException(v8::String::New("Failed to get JNI environment"));
58 69
59 if (args.Length() < 2) 70 if (args.Length() < 2)
60 return v8::ThrowException(v8::String::New("Not enough parameters")); 71 return v8::ThrowException(v8::String::New("Not enough parameters"));
61 72
62 if (!args[0]->IsString()) 73 if (!args[0]->IsString())
63 return v8::ThrowException(v8::String::New("Parameter 0 must be a string")); 74 return v8::ThrowException(v8::String::New("Parameter 0 must be a string"));
64 if (!args[1]->IsNumber()) 75 if (!args[1]->IsNumber())
65 return v8::ThrowException(v8::String::New("Parameter 1 must be a number")); 76 return v8::ThrowException(v8::String::New("Parameter 1 must be a number"));
66 77
67 v8::String::Utf8Value str(args[0]); 78 v8::String::Utf8Value str(args[0]);
68 if (!*str) 79 if (!*str)
69 return v8::ThrowException(v8::String::New("Parameter cannot be converted to string")); 80 return v8::ThrowException(v8::String::New("Parameter cannot be converted to string"));
70 jstring jstr = jniEnv->NewStringUTF(*str); 81 jstring jstr = jniEnv->NewStringUTF(*str);
71 82
72 jlong jnum = (v8::Handle<v8::Integer>::Cast(args[1]))->Value(); 83 jlong jnum = (v8::Handle<v8::Integer>::Cast(args[1]))->Value();
73 84
74 static jclass cls = jniEnv->GetObjectClass(jniCallback); 85 static jclass cls = jniEnv->GetObjectClass(jniCallback);
75 static jmethodID mid = jniEnv->GetMethodID(cls, "setStatus", "(Ljava/lang/Stri ng;J)V"); 86 static jmethodID mid = jniEnv->GetMethodID(cls, "setStatus", "(Ljava/lang/Stri ng;J)V");
76 if (mid) 87 if (mid)
77 jniEnv->CallVoidMethod(jniCallback, mid, jstr, jnum); 88 jniEnv->CallVoidMethod(jniCallback, mid, jstr, jnum);
78 jniEnv->DeleteLocalRef(jstr); 89 jniEnv->DeleteLocalRef(jstr);
79 90
80 return v8::Undefined(); 91 return v8::Undefined();
81 } 92 }
82 93
83 v8::Handle<v8::Value> canAutoupdateImpl(const v8::Arguments& args) 94 v8::Handle<v8::Value> canAutoupdateImpl(const v8::Arguments& args)
84 { 95 {
96 D(D_WARN, "canAutoupdate()");
85 v8::HandleScope handle_scope; 97 v8::HandleScope handle_scope;
98
99 JNIEnv* jniEnv = NULL;
100 if (globalJvm->AttachCurrentThread(&jniEnv, NULL) != 0)
101 return v8::ThrowException(v8::String::New("Failed to get JNI environment"));
86 102
87 jboolean result; 103 jboolean result;
88 jclass cls = jniEnv->GetObjectClass(jniCallback); 104 jclass cls = jniEnv->GetObjectClass(jniCallback);
89 jmethodID mid = jniEnv->GetMethodID(cls, "canAutoupdate", "()Z"); 105 jmethodID mid = jniEnv->GetMethodID(cls, "canAutoupdate", "()Z");
90 if (mid) 106 if (mid)
91 result = jniEnv->CallBooleanMethod(jniCallback, mid); 107 result = jniEnv->CallBooleanMethod(jniCallback, mid);
92 return wrapJavaObject(jniEnv, NewBoolean(jniEnv, result)); 108 return wrapJavaObject(jniEnv, NewBoolean(jniEnv, result));
93 } 109 }
94 110
95 v8::Handle<v8::Value> showToastImpl(const v8::Arguments& args) 111 v8::Handle<v8::Value> showToastImpl(const v8::Arguments& args)
96 { 112 {
113 D(D_WARN, "showToast()");
97 v8::HandleScope handle_scope; 114 v8::HandleScope handle_scope;
115
116 JNIEnv* jniEnv = NULL;
117 if (globalJvm->AttachCurrentThread(&jniEnv, NULL) != 0)
118 return v8::ThrowException(v8::String::New("Failed to get JNI environment"));
119
98 if (args.Length() < 1) 120 if (args.Length() < 1)
99 return v8::ThrowException(v8::String::New("String expected")); 121 return v8::ThrowException(v8::String::New("String expected"));
100 122
101 v8::String::Utf8Value str(args[0]); 123 v8::String::Utf8Value str(args[0]);
102 if (!*str) 124 if (!*str)
103 return v8::ThrowException(v8::String::New("Parameter cannot be converted t o string")); 125 return v8::ThrowException(v8::String::New("Parameter cannot be converted t o string"));
104 __android_log_print(ANDROID_LOG_INFO, "ST", *str); 126
105 jstring jstr = jniEnv->NewStringUTF(*str); 127 jstring jstr = jniEnv->NewStringUTF(*str);
106 128
107 static jclass cls = jniEnv->GetObjectClass(jniCallback); 129 static jclass cls = jniEnv->GetObjectClass(jniCallback);
108 static jmethodID mid = jniEnv->GetMethodID(cls, "showToast", "(Ljava/lang/Stri ng;)V"); 130 static jmethodID mid = jniEnv->GetMethodID(cls, "showToast", "(Ljava/lang/Stri ng;)V");
109 if (mid) 131 if (mid)
110 jniEnv->CallVoidMethod(jniCallback, mid, jstr); 132 jniEnv->CallVoidMethod(jniCallback, mid, jstr);
111 jniEnv->DeleteLocalRef(jstr); 133 jniEnv->DeleteLocalRef(jstr);
112 134
113 return v8::Undefined(); 135 return v8::Undefined();
114 } 136 }
115 137
116 v8::Handle<v8::Value> printImpl(const v8::Arguments& args) 138 v8::Handle<v8::Value> printImpl(const v8::Arguments& args)
117 { 139 {
140 D(D_WARN, "print()");
118 bool first = true; 141 bool first = true;
119 std::string msg = ""; 142 std::string msg = "";
120 for (int i = 0; i < args.Length(); i++) 143 for (int i = 0; i < args.Length(); i++)
121 { 144 {
122 v8::HandleScope handle_scope; 145 v8::HandleScope handle_scope;
123 if (first) 146 if (first)
124 first = false; 147 first = false;
125 else 148 else
126 msg += " "; 149 msg += " ";
127 v8::String::Utf8Value str(args[i]); 150 v8::String::Utf8Value str(args[i]);
128 if (!*str) 151 if (!*str)
129 return v8::ThrowException(v8::String::New("Parameter cannot be converted t o string")); 152 return v8::ThrowException(v8::String::New("Parameter cannot be converted t o string"));
130 msg += *str; 153 msg += *str;
131 } 154 }
132 __android_log_print(ANDROID_LOG_INFO, "JS", msg.c_str()); 155
133 return v8::Undefined(); 156 return v8::Undefined();
134 } 157 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld