fix sublime plugin issue with ui mode, object prototype pollution, try for ui api

This commit is contained in:
hyb1996
2017-05-14 23:34:38 +08:00
parent 36ef8c8396
commit 6102f6e8fe
13 changed files with 50 additions and 43 deletions

View File

@@ -26,6 +26,8 @@ import com.stardust.util.AssetsCache;
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* Created by Stardust on 2017/5/3.
*/

View File

@@ -87,26 +87,22 @@ public class SublimePluginClient {
if (mSocket == null) {
throw new IllegalStateException("Socket is not listening ");
}
if (Looper.myLooper() == Looper.getMainLooper()) {
if (mExecutor == null) {
mExecutor = Executors.newSingleThreadExecutor();
}
mExecutor.execute(new Runnable() {
@Override
public void run() {
send(object);
if (mExecutor == null) {
mExecutor = Executors.newSingleThreadExecutor();
}
mExecutor.execute(new Runnable() {
@Override
public void run() {
try {
mOutputStream.write(object.toString().getBytes());
mOutputStream.write("\n".getBytes());
mOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
tryClose();
}
});
}
try {
mOutputStream.write(object.toString().getBytes());
mOutputStream.write("\n".getBytes());
mOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
tryClose();
}
}
});
}
public void close() throws IOException {

View File

@@ -29,6 +29,7 @@ dependencies {
})
testCompile 'junit:junit:4.12'
compile 'com.github.hyb1996:node-android-lib:1.0.14'
compile 'com.github.hyb1996:DynamicLayoutInflator:0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile project(path: ':common')
compile project(path: ':automator')

View File

@@ -13,12 +13,13 @@ if(__engine_name__ == "rhino"){
}
}
var __that__ = this;
var __asGlobal__ = function(obj, functions){
var len = functions.length;
for(var i = 0; i < len; i++) {
var funcName = functions[i];
this[funcName] = obj[funcName].bind(obj);
__that__[funcName] = obj[funcName].bind(obj);
}
}
@@ -32,4 +33,4 @@ require("__general__")(__runtime__, this);
var m = modules[i];
scope[m] = require('__' + m + '__')(scope.__runtime__, scope);
}
})(this);
})(__that__);

View File

@@ -1,6 +1,6 @@
module.exports = function(__runtime__, scope){
var app = new Object(__runtime__.app);
var app = Object.create(__runtime__.app);
var context = scope.context;
app.intent = function(i) {

View File

@@ -1,6 +1,6 @@
module.exports = function(__runtime__, scope){
var console = new Object(__runtime__.console);
var console = Object.create(__runtime__.console);
console.assert = function(value, message){
message = message || "";

View File

@@ -1,7 +1,7 @@
module.exports = function(__runtime__, scope){
var ui = Object(__runtime__.ui);
ui.layout = function(xml){
view = ui.inflate(xml);
view = ui.inflate(activity, xml);
ui.setView(view);
}

View File

@@ -120,6 +120,12 @@ public class ScriptEngineService {
task.setExecutionListener(mScriptExecutionObserver);
}
if (isUiMode(task)) {
mUiHandler.post(new Runnable() {
@Override
public void run() {
}
});
return ScriptExecuteActivity.execute(mContext, this, task);
} else {
RunnableScriptExecution scriptExecution = new RunnableScriptExecution(this, task);

View File

@@ -83,20 +83,26 @@ public class ScriptExecuteActivity extends Activity {
private ScriptEngine mScriptEngine;
private ScriptRuntime mScriptRuntime;
private ScriptEngineService mScriptEngineService;
ActivityScriptExecution(ScriptEngineService service, ScriptExecutionTask task) {
super(task);
mScriptEngine = service.createScriptEngine();
mScriptRuntime = service.createScriptRuntime();
mScriptEngineService = service;
}
@Override
public ScriptEngine getEngine() {
if (mScriptEngine == null) {
mScriptEngine = mScriptEngineService.createScriptEngine();
}
return mScriptEngine;
}
@Override
public ScriptRuntime getRuntime() {
if (mScriptRuntime == null) {
mScriptRuntime = mScriptEngineService.createScriptRuntime();
}
return mScriptRuntime;
}

View File

@@ -105,7 +105,7 @@ public interface AttributeHandler {
@Override
public boolean handle(String nodeName, Node attr, StringBuilder layoutXml) {
String dimen = convertToAndroidDimen(attr.getNodeName());
String dimen = convertToAndroidDimen(attr.getNodeValue());
layoutXml.append("android:").append(mAttrName).append("=\"").append(dimen).append("\"\n");
return true;
}

View File

@@ -4,6 +4,9 @@ import android.content.Context;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import com.nickandjerry.dynamiclayoutinflator.lib.DynamicLayoutInflator;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -16,22 +19,14 @@ import java.io.StringReader;
public class ConvertLayoutInflater implements JsLayoutInflater {
private Context mContext;
public ConvertLayoutInflater(Context context) {
mContext = context;
}
@Override
public View inflate(String xml) {
public View inflate(Context context, String xml) {
try {
// 我靠%>_<% 弄完了xml转换以后发现android并不能动态inflate非resources的xml啊啊啊啊啊啊
String androidLayoutXml = XmlConverter.convertToAndroidLayout(xml);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
LayoutInflater inflater = LayoutInflater.from(mContext);
parser.setInput(new StringReader(androidLayoutXml));
return inflater.inflate(parser, null);
FrameLayout root = new FrameLayout(context);
DynamicLayoutInflator.inflate(context, androidLayoutXml, root);
return root;
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@@ -9,5 +9,5 @@ import android.view.View;
public interface JsLayoutInflater {
View inflate(String xml);
View inflate(Context context, String xml);
}

View File

@@ -20,14 +20,14 @@ public class UI {
public UI(Context context) {
this(context, new ConvertLayoutInflater(context));
this(context, new ConvertLayoutInflater());
}
public JsLayoutInflater getLayoutInflater() {
return mJsLayoutInflater;
}
public View inflate(String xml) {
return mJsLayoutInflater.inflate(xml);
public View inflate(Context context, String xml) {
return mJsLayoutInflater.inflate(context, xml);
}
}