rhodes 2.0.0.beta4 → 2.0.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -224,6 +224,7 @@ lib/framework/rhom.rb
224
224
  lib/framework/singleton.rb
225
225
  lib/framework/time.rb
226
226
  lib/framework/version.rb
227
+ lib/rhodes/generator.rb
227
228
  lib/rhodes.rb
228
229
  lib/test/apps/rhoconfig.txt
229
230
  lib/test/framework_test.rb
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/../../res/generators/rhogen'
@@ -62,19 +62,16 @@ RHO_GLOBAL int rho_webview_active_tab()
62
62
 
63
63
  RHO_GLOBAL const char* rho_webview_execute_js(const char* js, int index)
64
64
  {
65
- static std::string result;
66
-
67
65
  JNIEnv *env = jnienv();
68
66
  jclass cls = getJNIClass(RHODES_JAVA_CLASS_WEB_VIEW);
69
67
  if (!cls) return NULL;
70
- jmethodID mid = getJNIClassStaticMethod(env, cls, "executeJs", "(Ljava/lang/String;I)Ljava/lang/String;");
68
+ jmethodID mid = getJNIClassStaticMethod(env, cls, "executeJs", "(Ljava/lang/String;I)V");
71
69
  if (!mid) return NULL;
72
70
 
73
- jstring objJs = rho_cast<jstring>(js);
74
- jstring str = (jstring)env->CallStaticObjectMethod(cls, mid, objJs, index);
71
+ jstring objJs = rho_cast<jstring>(env, js);
72
+ env->CallStaticObjectMethod(cls, mid, objJs, index);
75
73
  env->DeleteLocalRef(objJs);
76
- result = rho_cast<std::string>(str);
77
- return (char*)result.c_str();
74
+ return "";
78
75
  }
79
76
 
80
77
  RHO_GLOBAL void rho_webview_full_screen_mode(int enable)
@@ -62,6 +62,7 @@ import android.view.View;
62
62
  import android.view.Window;
63
63
  import android.view.WindowManager;
64
64
  import android.view.ViewGroup.LayoutParams;
65
+ import android.webkit.JsResult;
65
66
  import android.webkit.WebChromeClient;
66
67
  import android.webkit.WebSettings;
67
68
  import android.webkit.WebView;
@@ -363,6 +364,16 @@ public class Rhodes extends Activity {
363
364
  }
364
365
  super.onProgressChanged(view, newProgress);
365
366
  }
367
+
368
+ @Override
369
+ public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
370
+ return false;
371
+ }
372
+
373
+ @Override
374
+ public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
375
+ return false;
376
+ }
366
377
  });
367
378
 
368
379
  return w;
@@ -20,6 +20,7 @@
20
20
  */
21
21
  package com.rhomobile.rhodes;
22
22
 
23
+ import android.net.Uri;
23
24
  import android.webkit.CookieManager;
24
25
 
25
26
  public class WebView {
@@ -85,7 +86,8 @@ public class WebView {
85
86
  private String cookie;
86
87
 
87
88
  public SetCookieTask(String u, String c) {
88
- url = u;
89
+ Uri uri = Uri.parse(u);
90
+ url = uri.getScheme() + "://" + uri.getHost() + "/" + uri.getPath();
89
91
  cookie = c;
90
92
  }
91
93
 
@@ -135,15 +137,13 @@ public class WebView {
135
137
  return 0;
136
138
  }
137
139
 
138
- public static String executeJs(String js, int index) {
140
+ public static void executeJs(String js, int index) {
139
141
  try {
140
142
  Rhodes.performOnUiThread(new NavigateTask("javascript:" + js, index), false);
141
143
  }
142
144
  catch (Exception e) {
143
145
  reportFail("executeJs", e);
144
146
  }
145
-
146
- return "";
147
147
  }
148
148
 
149
149
  public static void setCookie(String url, String cookie) {
@@ -709,7 +709,7 @@ namespace "build" do
709
709
  f.puts "public class NativeLibraries {"
710
710
  f.puts " public static void load() {"
711
711
  f.puts " // Load native .so libraries"
712
- Dir.glob($extensionsdir + "/lib*.so").each do |lib|
712
+ Dir.glob($extensionsdir + "/lib*.so").reverse.each do |lib|
713
713
  libname = File.basename(lib).gsub(/^lib/, '').gsub(/\.so$/, '')
714
714
  f.puts " System.loadLibrary(\"#{libname}\");"
715
715
  end
@@ -163,7 +163,7 @@ def cc_link(outname, objects, additional = nil, deps = nil)
163
163
  args << "-Wl,-z,defs"
164
164
  args << "-shared"
165
165
  args << "-fPIC"
166
- args << "-Wl,-soname,#{outname}"
166
+ args << "-Wl,-soname,#{File.basename(outname)}"
167
167
  args << "-o"
168
168
  args << outname
169
169
  args += objects
@@ -172,9 +172,12 @@ def cc_link(outname, objects, additional = nil, deps = nil)
172
172
  args << "-Wl,-rpath-link=#{$ndksysroot}/usr/lib"
173
173
  args << "#{$ndksysroot}/usr/lib/libstdc++.so"
174
174
  args << "#{$ndksysroot}/usr/lib/libsupc++.so" unless USE_STLPORT
175
- args << "#{$ndktools}/lib/gcc/arm-eabi/#{$ndkgccver}/libgcc.a"
175
+ libgccdir = File.join($ndktools, "lib/gcc/arm-eabi", $ndkgccver)
176
+ libgccdir = File.join(libgccdir, "interwork") if $ndkgccver == "4.2.1"
177
+ args << "#{libgccdir}/libgcc.a" if $ndkgccver != "4.2.1"
176
178
  args << "#{$ndksysroot}/usr/lib/libc.so"
177
179
  args << "#{$ndksysroot}/usr/lib/libm.so"
180
+ args << "#{libgccdir}/libgcc.a" if $ndkgccver == "4.2.1"
178
181
  cc_run($gccbin, args)
179
182
  end
180
183
 
@@ -137,11 +137,15 @@ static Rhodes *instance = NULL;
137
137
  }
138
138
 
139
139
  - (void)setCookie:(NSString*)cookie forUrl:(NSString*)url {
140
- [cookies setObject:cookie forKey:url];
140
+ NSURL *parsed = [NSURL URLWithString:url];
141
+ NSString *basicUrl = [NSString stringWithFormat:@"%@://%@/%@", parsed.scheme, parsed.host, parsed.path];
142
+ [cookies setObject:cookie forKey:basicUrl];
141
143
  }
142
144
 
143
145
  - (NSString*)cookie:(NSString*)url {
144
- NSString *c = [cookies objectForKey:url];
146
+ NSURL *parsed = [NSURL URLWithString:url];
147
+ NSString *basicUrl = [NSString stringWithFormat:@"%@://%@/%@", parsed.scheme, parsed.host, parsed.path];
148
+ NSString *c = [cookies objectForKey:basicUrl];
145
149
  return c;
146
150
  }
147
151
 
@@ -1,6 +1,7 @@
1
1
  #include "JSONIterator.h"
2
2
 
3
3
  #include "json/json.h"
4
+ #include "ruby/ext/rho/rhoruby.h"
4
5
 
5
6
  #if defined(OS_WINCE) || defined (OS_WINDOWS)
6
7
  #define rho_atoi64 _atoi64
@@ -242,5 +243,70 @@ CJSONEntry CJSONEntry::getEntry(const char* name)const
242
243
  return CJSONEntry(obj);
243
244
  }
244
245
 
246
+ /*static*/ String CJSONEntry::quoteValue(const String& strValue)
247
+ {
248
+ int pos = 0, start_offset = 0;
249
+ unsigned char c;
250
+ String strRes = "\"";
251
+ const char* str = strValue.c_str();
252
+ do
253
+ {
254
+ c = str[pos];
255
+ switch(c) {
256
+ case '\0':
257
+ break;
258
+ case '\b':
259
+ case '\n':
260
+ case '\r':
261
+ case '\t':
262
+ case '"':
263
+ case '\\':
264
+ case '/':
265
+ if(pos - start_offset > 0)
266
+ strRes.append(str + start_offset, pos - start_offset);
267
+
268
+ if(c == '\b') strRes.append( "\\b", 2 );
269
+ else if(c == '\n') strRes.append( "\\n", 2);
270
+ else if(c == '\r') strRes.append( "\\r", 2);
271
+ else if(c == '\t') strRes.append( "\\t", 2);
272
+ else if(c == '"') strRes.append( "\\\"", 2);
273
+ else if(c == '\\') strRes.append( "\\\\", 2);
274
+ else if(c == '/') strRes.append( "\\/", 2);
275
+
276
+ start_offset = ++pos;
277
+ break;
278
+ default:
279
+ if(c < ' ')
280
+ {
281
+ if(pos - start_offset > 0)
282
+ strRes.append( str + start_offset, pos - start_offset);
283
+
284
+ char buf[128];
285
+ int nSize = snprintf(buf, 128, "\\u00%c%c", json_hex_chars[c >> 4], json_hex_chars[c & 0xf]);
286
+ strRes.append(buf, nSize);
287
+
288
+ start_offset = ++pos;
289
+ }else
290
+ pos++;
291
+ }
292
+ } while(c);
293
+
294
+ if ( strRes.length() == 1 )
295
+ return "\"" + strValue + "\"";
296
+
297
+ if ( pos - start_offset > 0 )
298
+ strRes.append( str + start_offset, pos - start_offset);
299
+
300
+ strRes.append("\"");
301
+ return strRes;
302
+ }
303
+
245
304
  }
246
305
  }
306
+
307
+ extern "C" VALUE rho_json_quote_value(VALUE v,VALUE str)
308
+ {
309
+ rho::String strRes = rho::json::CJSONEntry::quoteValue(getStringFromValue(str));
310
+
311
+ return rho_ruby_create_string(strRes.c_str());
312
+ }
@@ -31,6 +31,8 @@ public:
31
31
  CJSONEntry getEntry(const char* name)const;
32
32
 
33
33
  struct json_object* getObject()const{ return m_object; }
34
+
35
+ static String quoteValue(const String& strValue);
34
36
  };
35
37
 
36
38
  class CJSONArrayIterator
@@ -580,4 +580,4 @@ VALUE rho_json_parse(VALUE v,VALUE str)
580
580
  free(szError);
581
581
 
582
582
  return rho_ruby_get_NIL();
583
- }
583
+ }
@@ -545,6 +545,7 @@ static void Init_RhoLog(){
545
545
  static VALUE rb_RhoModule;
546
546
  static VALUE rb_RhoJSON;
547
547
  extern VALUE rho_json_parse(VALUE,VALUE);
548
+ extern VALUE rho_json_quote_value(VALUE,VALUE);
548
549
  static void Init_RhoJSON()
549
550
  {
550
551
 
@@ -554,6 +555,7 @@ static void Init_RhoJSON()
554
555
  rb_RhoJSON = rb_define_class_under(rb_RhoModule, "JSON", rb_cObject);
555
556
 
556
557
  rb_define_singleton_method(rb_RhoJSON, "parse", rho_json_parse, 1);
558
+ rb_define_singleton_method(rb_RhoJSON, "quote_value", rho_json_quote_value, 1);
557
559
  }
558
560
 
559
561
  const char* rho_ruby_internal_getMessageText(const char* szName)
@@ -17,6 +17,9 @@
17
17
  #include <sys/resource.h>
18
18
  #endif
19
19
 
20
+ void *rho_nativethread_start();
21
+ void rho_nativethread_end(void *arg);
22
+
20
23
  /*static*/ void native_mutex_lock(pthread_mutex_t *lock);
21
24
  /*static*/ void native_mutex_unlock(pthread_mutex_t *lock);
22
25
  static int native_mutex_trylock(pthread_mutex_t *lock);
@@ -350,8 +353,10 @@ thread_start_func_1(void *th_ptr)
350
353
  rb_thread_t *th = th_ptr;
351
354
  VALUE stack_start;
352
355
 
356
+ void *p = rho_nativethread_start();
353
357
  /* run */
354
358
  thread_start_func_2(th, &stack_start, rb_ia64_bsp());
359
+ rho_nativethread_end(p);
355
360
  }
356
361
  #if USE_THREAD_CACHE
357
362
  if (1) {
@@ -225,6 +225,23 @@ public class RJSONTokener extends JSONTokener
225
225
  throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
226
226
  }
227
227
  }
228
+ });
229
+
230
+ klass.getSingletonClass().defineMethod("quote_value", new RubyOneArgMethod(){
231
+ protected RubyValue run(RubyValue receiver, RubyValue arg, RubyBlock block )
232
+ {
233
+ try {
234
+ String str = arg.toStr();
235
+
236
+ String strRes = JSONObject.quote(str);
237
+
238
+ return ObjectFactory.createString(strRes);
239
+ } catch(Exception e) {
240
+ LOG.ERROR("parse failed", e);
241
+ throw (e instanceof RubyException ? (RubyException)e : new RubyException(e.getMessage()));
242
+ }
243
+ }
228
244
  });
245
+
229
246
  }
230
247
  }
@@ -26,6 +26,11 @@ class JSONEntry
26
26
  return m_object.has(name);
27
27
  }
28
28
 
29
+ static String quoteValue(String str)
30
+ {
31
+ return JSONObject.quote(str);
32
+ }
33
+
29
34
  String getString(String name)throws JSONException
30
35
  {
31
36
  String szRes = null;
@@ -272,7 +272,7 @@ class SyncSource
272
272
 
273
273
  m_arMultipartItems.removeAllElements();
274
274
  m_arBlobAttrs.removeAllElements();
275
- String strBody = "{\"source_name\":\"" + getName() + "\",\"client_id\":\"" + getSync().getClientID() + "\"";
275
+ String strBody = "{\"source_name\":" + JSONEntry.quoteValue(getName()) + ",\"client_id\":" + JSONEntry.quoteValue(getSync().getClientID());
276
276
  boolean bSend = false;
277
277
  int i = 0;
278
278
  for( i = 0; i < 3 && getSync().isContinueSync(); i++ )
@@ -289,7 +289,7 @@ class SyncSource
289
289
  if ( strBlobAttrs.length() > 0 )
290
290
  strBlobAttrs += ",";
291
291
 
292
- strBlobAttrs += "\"" + m_arBlobAttrs.elementAt(j) + "\"";
292
+ strBlobAttrs += JSONEntry.quoteValue((String)m_arBlobAttrs.elementAt(j));
293
293
  }
294
294
 
295
295
  if ( strBlobAttrs.length() > 0 )
@@ -398,7 +398,7 @@ class SyncSource
398
398
  }
399
399
 
400
400
  bFirst = true;
401
- strBody += "\"" + strObject + "\"";
401
+ strBody += JSONEntry.quoteValue(strObject);
402
402
  strCurObject = strObject;
403
403
  }
404
404
 
@@ -410,7 +410,7 @@ class SyncSource
410
410
  if ( bFirst )
411
411
  strBody += ":{";
412
412
 
413
- strBody += "\"" + strAttrib + "\":\"" + value + "\"";
413
+ strBody += JSONEntry.quoteValue(strAttrib) + ":" + JSONEntry.quoteValue(value);
414
414
  bFirst = false;
415
415
  }
416
416
  }
@@ -42,7 +42,7 @@ CSyncSource::CSyncSource(CSyncEngine& syncEngine, db::CDBAdapter& db ) : m_sync
42
42
 
43
43
  m_nCurPageCount = 0;
44
44
  m_nInserted = 0;
45
- m_nDeleted = 0;
45
+ m_nDeleted = 0;
46
46
  m_nTotalCount = 0;
47
47
  m_bGetAtLeastOnePage = false;
48
48
 
@@ -176,7 +176,7 @@ void CSyncSource::doSyncClientChanges()
176
176
 
177
177
  m_arMultipartItems.removeAllElements();
178
178
  m_arBlobAttrs.removeAllElements();
179
- String strBody = "{\"source_name\":\"" + getName() + "\",\"client_id\":\"" + getSync().getClientID() + "\"";
179
+ String strBody = "{\"source_name\":" + CJSONEntry::quoteValue(getName()) + ",\"client_id\":" + CJSONEntry::quoteValue(getSync().getClientID());
180
180
  boolean bSend = false;
181
181
  int i = 0;
182
182
  for( i = 0; i < 3 && getSync().isContinueSync(); i++ )
@@ -193,7 +193,7 @@ void CSyncSource::doSyncClientChanges()
193
193
  if ( strBlobAttrs.length() > 0 )
194
194
  strBlobAttrs += ",";
195
195
 
196
- strBlobAttrs += "\"" + m_arBlobAttrs.elementAt(j) + "\"";
196
+ strBlobAttrs += CJSONEntry::quoteValue(m_arBlobAttrs.elementAt(j));
197
197
  }
198
198
 
199
199
  if ( strBlobAttrs.length() > 0 )
@@ -252,7 +252,7 @@ void CSyncSource::doSyncClientChanges()
252
252
  m_arMultipartItems.removeAllElements();
253
253
  m_arBlobAttrs.removeAllElements();
254
254
  }
255
-
255
+ /*
256
256
  static void escapeDoubleQuotes(String& str)
257
257
  {
258
258
  const char* szQuote = strchr(str.c_str(), '\"');
@@ -265,7 +265,7 @@ static void escapeDoubleQuotes(String& str)
265
265
  else
266
266
  szQuote = 0;
267
267
  }
268
- }
268
+ }*/
269
269
 
270
270
  //{"source_name":"SampleAdapter","client_id":1,"create":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}}
271
271
  //{"source_name":"SampleAdapter","client_id":1,"update":{"1":{"brand":"Apple","name":"iPhone","price":"199.99"}}}
@@ -317,7 +317,7 @@ void CSyncSource::makePushBody_Ver3(String& strBody, const String& strUpdateType
317
317
  }
318
318
 
319
319
  bFirst = true;
320
- strBody += "\"" + strObject + "\"";
320
+ strBody += CJSONEntry::quoteValue(strObject);
321
321
  strCurObject = strObject;
322
322
  }
323
323
 
@@ -329,8 +329,7 @@ void CSyncSource::makePushBody_Ver3(String& strBody, const String& strUpdateType
329
329
  if ( bFirst )
330
330
  strBody += ":{";
331
331
 
332
- escapeDoubleQuotes(value);
333
- strBody += "\"" + strAttrib + "\":\"" + value + "\"";
332
+ strBody += CJSONEntry::quoteValue(strAttrib) + ":" + CJSONEntry::quoteValue(value);
334
333
  bFirst = false;
335
334
  }
336
335
  }
data/rhodes.gemspec CHANGED
@@ -3,7 +3,7 @@ require "lib/rhodes.rb"
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{rhodes}
6
- s.version = '2.0.0.beta4'
6
+ s.version = '2.0.0.beta6'
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Rhomobile"]
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 2
7
7
  - 0
8
8
  - 0
9
- - beta4
10
- version: 2.0.0.beta4
9
+ - beta6
10
+ version: 2.0.0.beta6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rhomobile
@@ -327,6 +327,7 @@ files:
327
327
  - lib/framework/singleton.rb
328
328
  - lib/framework/time.rb
329
329
  - lib/framework/version.rb
330
+ - lib/rhodes/generator.rb
330
331
  - lib/rhodes.rb
331
332
  - lib/test/apps/rhoconfig.txt
332
333
  - lib/test/framework_test.rb