fix sublime plugin issue with ui mode, object prototype pollution, try for ui api
This commit is contained in:
@@ -26,6 +26,8 @@ import com.stardust.util.AssetsCache;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/3.
|
* Created by Stardust on 2017/5/3.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -87,26 +87,22 @@ public class SublimePluginClient {
|
|||||||
if (mSocket == null) {
|
if (mSocket == null) {
|
||||||
throw new IllegalStateException("Socket is not listening ");
|
throw new IllegalStateException("Socket is not listening ");
|
||||||
}
|
}
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
if (mExecutor == null) {
|
||||||
if (mExecutor == null) {
|
mExecutor = Executors.newSingleThreadExecutor();
|
||||||
mExecutor = Executors.newSingleThreadExecutor();
|
}
|
||||||
}
|
mExecutor.execute(new Runnable() {
|
||||||
mExecutor.execute(new Runnable() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
try {
|
||||||
send(object);
|
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 {
|
public void close() throws IOException {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ dependencies {
|
|||||||
})
|
})
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
compile 'com.github.hyb1996:node-android-lib:1.0.14'
|
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 'org.greenrobot:eventbus:3.0.0'
|
||||||
compile project(path: ':common')
|
compile project(path: ':common')
|
||||||
compile project(path: ':automator')
|
compile project(path: ':automator')
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ if(__engine_name__ == "rhino"){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var __that__ = this;
|
||||||
|
|
||||||
var __asGlobal__ = function(obj, functions){
|
var __asGlobal__ = function(obj, functions){
|
||||||
var len = functions.length;
|
var len = functions.length;
|
||||||
for(var i = 0; i < len; i++) {
|
for(var i = 0; i < len; i++) {
|
||||||
var funcName = functions[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];
|
var m = modules[i];
|
||||||
scope[m] = require('__' + m + '__')(scope.__runtime__, scope);
|
scope[m] = require('__' + m + '__')(scope.__runtime__, scope);
|
||||||
}
|
}
|
||||||
})(this);
|
})(__that__);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
module.exports = function(__runtime__, scope){
|
module.exports = function(__runtime__, scope){
|
||||||
var app = new Object(__runtime__.app);
|
var app = Object.create(__runtime__.app);
|
||||||
var context = scope.context;
|
var context = scope.context;
|
||||||
|
|
||||||
app.intent = function(i) {
|
app.intent = function(i) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
module.exports = function(__runtime__, scope){
|
module.exports = function(__runtime__, scope){
|
||||||
var console = new Object(__runtime__.console);
|
var console = Object.create(__runtime__.console);
|
||||||
|
|
||||||
console.assert = function(value, message){
|
console.assert = function(value, message){
|
||||||
message = message || "";
|
message = message || "";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module.exports = function(__runtime__, scope){
|
module.exports = function(__runtime__, scope){
|
||||||
var ui = Object(__runtime__.ui);
|
var ui = Object(__runtime__.ui);
|
||||||
ui.layout = function(xml){
|
ui.layout = function(xml){
|
||||||
view = ui.inflate(xml);
|
view = ui.inflate(activity, xml);
|
||||||
ui.setView(view);
|
ui.setView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,12 @@ public class ScriptEngineService {
|
|||||||
task.setExecutionListener(mScriptExecutionObserver);
|
task.setExecutionListener(mScriptExecutionObserver);
|
||||||
}
|
}
|
||||||
if (isUiMode(task)) {
|
if (isUiMode(task)) {
|
||||||
|
mUiHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
return ScriptExecuteActivity.execute(mContext, this, task);
|
return ScriptExecuteActivity.execute(mContext, this, task);
|
||||||
} else {
|
} else {
|
||||||
RunnableScriptExecution scriptExecution = new RunnableScriptExecution(this, task);
|
RunnableScriptExecution scriptExecution = new RunnableScriptExecution(this, task);
|
||||||
|
|||||||
@@ -83,20 +83,26 @@ public class ScriptExecuteActivity extends Activity {
|
|||||||
|
|
||||||
private ScriptEngine mScriptEngine;
|
private ScriptEngine mScriptEngine;
|
||||||
private ScriptRuntime mScriptRuntime;
|
private ScriptRuntime mScriptRuntime;
|
||||||
|
private ScriptEngineService mScriptEngineService;
|
||||||
|
|
||||||
ActivityScriptExecution(ScriptEngineService service, ScriptExecutionTask task) {
|
ActivityScriptExecution(ScriptEngineService service, ScriptExecutionTask task) {
|
||||||
super(task);
|
super(task);
|
||||||
mScriptEngine = service.createScriptEngine();
|
mScriptEngineService = service;
|
||||||
mScriptRuntime = service.createScriptRuntime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptEngine getEngine() {
|
public ScriptEngine getEngine() {
|
||||||
|
if (mScriptEngine == null) {
|
||||||
|
mScriptEngine = mScriptEngineService.createScriptEngine();
|
||||||
|
}
|
||||||
return mScriptEngine;
|
return mScriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptRuntime getRuntime() {
|
public ScriptRuntime getRuntime() {
|
||||||
|
if (mScriptRuntime == null) {
|
||||||
|
mScriptRuntime = mScriptEngineService.createScriptRuntime();
|
||||||
|
}
|
||||||
return mScriptRuntime;
|
return mScriptRuntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public interface AttributeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(String nodeName, Node attr, StringBuilder layoutXml) {
|
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");
|
layoutXml.append("android:").append(mAttrName).append("=\"").append(dimen).append("\"\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import android.content.Context;
|
|||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import com.nickandjerry.dynamiclayoutinflator.lib.DynamicLayoutInflator;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
@@ -16,22 +19,14 @@ import java.io.StringReader;
|
|||||||
|
|
||||||
public class ConvertLayoutInflater implements JsLayoutInflater {
|
public class ConvertLayoutInflater implements JsLayoutInflater {
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public ConvertLayoutInflater(Context context) {
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View inflate(String xml) {
|
public View inflate(Context context, String xml) {
|
||||||
try {
|
try {
|
||||||
// 我靠%>_<% 弄完了xml转换以后发现android并不能动态inflate非resources的xml啊啊啊啊啊啊
|
|
||||||
String androidLayoutXml = XmlConverter.convertToAndroidLayout(xml);
|
String androidLayoutXml = XmlConverter.convertToAndroidLayout(xml);
|
||||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
FrameLayout root = new FrameLayout(context);
|
||||||
XmlPullParser parser = factory.newPullParser();
|
DynamicLayoutInflator.inflate(context, androidLayoutXml, root);
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
return root;
|
||||||
parser.setInput(new StringReader(androidLayoutXml));
|
|
||||||
return inflater.inflate(parser, null);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ import android.view.View;
|
|||||||
|
|
||||||
public interface JsLayoutInflater {
|
public interface JsLayoutInflater {
|
||||||
|
|
||||||
View inflate(String xml);
|
View inflate(Context context, String xml);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ public class UI {
|
|||||||
|
|
||||||
|
|
||||||
public UI(Context context) {
|
public UI(Context context) {
|
||||||
this(context, new ConvertLayoutInflater(context));
|
this(context, new ConvertLayoutInflater());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsLayoutInflater getLayoutInflater() {
|
public JsLayoutInflater getLayoutInflater() {
|
||||||
return mJsLayoutInflater;
|
return mJsLayoutInflater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public View inflate(String xml) {
|
public View inflate(Context context, String xml) {
|
||||||
return mJsLayoutInflater.inflate(xml);
|
return mJsLayoutInflater.inflate(context, xml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user