Skip to content

Commit 8c57a13

Browse files
committed
[7.27]
1 parent dd548c7 commit 8c57a13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+512
-32
lines changed

CookieNotes.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# cookie domain
2+
3+
下一个选项是 domain,指定了 cookie 将要被发送至哪个或哪些域中。默认情况下,domain 会被设置为创建该 cookie 的页面所在的域名,所以当给相同域名发送请求时该 cookie 会被发送至服务器。例如,本博中 cookie 的默认值将是 bubkoo.com。domain 选项可用来扩充 cookie 可发送域的数量,例如:
4+
5+
> Set-Cookie: name=Nicholas; domain=nczonline.net
6+
7+
像 Yahoo! 这种大型网站,都会有许多 name.yahoo.com 形式的站点(例如:my.yahoo.com, finance.yahoo.com 等等)。将一个 cookie 的 domain 选项设置为 yahoo.com,就可以将该 cookie 的值发送至所有这些站点。浏览器会把 domain 的值与请求的域名做一个尾部比较(即从字符串的尾部开始比较),并将匹配的 cookie 发送至服务器。
8+
9+
domain 选项的值必须是发送 Set-Cookie 消息头的主机名的一部分,例如我不能在 google.com 上设置一个 cookie,因为这会产生安全问题。不合法的 domain 选择将直接被忽略
10+
11+
12+
# cookie path
13+
14+
另一个控制 Cookie 消息头发送时机的选项是 path 选项,和 domain 选项类似,path 选项指定了请求的资源 URL 中必须存在指定的路径时,才会发送Cookie 消息头。这个比较通常是将 path 选项的值与请求的 URL 从头开始逐字符比较完成的。如果字符匹配,则发送 Cookie 消息头,例如:
15+
16+
> Set-Cookie:name=Nicholas;path=/blog
17+
18+
在这个例子中,path 选项值会与 /blog,/blogrool 等等相匹配;任何以 /blog 开头的选项都是合法的。需要注意的是,只有在 domain 选项核实完毕之后才会对 path 属性进行比较。path 属性的默认值是发送 Set-Cookie 消息头所对应的 URL 中的 path 部分。
19+
20+
[link](http://bubkoo.com/2014/04/21/http-cookies-explained/)

DevLog/2018_7_27.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Android 开发
2+
> 高德地图
3+
- 发现Kotlin使用扩展方法可以被Java方法所接受,我对一个类进行扩展,但后这个kt文件会以xxxxKt的方式被引用,然后定义的参数会+1 多的那个一个参数是receiver。
4+
5+
- 高德debug,keystore
6+
目录在隐藏文件.android 中
7+
密码是默认的密码android
8+
9+
- 高德 使用Gradle操作之后不需要添加 so
10+
11+
- 注意要合理管理mapview的生命周期
12+
13+
> Anko
14+
- 递归学习开始:
15+
- Kotlin协程 是什么:{
16+
suspend lamda:
17+
暂时了解了以下携程可以替代线程做一些很炫酷的操作,相当于线程而言 更廉价而且简单
18+
19+
- 找到一个很好的例子:
20+
[例子]](https://github.com/CysionLiu/anko-sample){
21+
- [mastering kotlin functions](https://medium.com/@elye.project/mastering-kotlin-standard-functions-run-with-let-also-and-apply-9cd334b0ef84)
22+
}
23+
Anko 有很多很好的东西 比如attemp 函数 一些转换工具等等
24+
}
25+
- Kotlin 数据结构 MutableList:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

os/Android/AndroidJSBridge.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# A Simple note after Reading this [POST](https://blog.csdn.net/sbsujjbcy/article/details/50752595)
2+
3+
4+
5+
# the normal Stream of logic:
6+
7+
## from the View of frontend
8+
````
9+
<!DOCTYPE HTML>
10+
<html>
11+
<head>
12+
<meta charset="utf-8">
13+
<title>JSBridge</title>
14+
<meta name="viewport"
15+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1, user-scalable=no"/>
16+
<script src="file:///android_asset/JSBridge.js" type="text/javascript"></script>
17+
<script type="text/javascript">
18+
19+
</script>
20+
<style>
21+
22+
</style>
23+
</head>
24+
25+
<body>
26+
<div>
27+
<h3>JSBridge 测试</h3>
28+
</div>
29+
<ul class="list">
30+
<li>
31+
<div>
32+
<button onclick="JSBridge.call('bridge','showToast',{'msg':'Hello JSBridge'},function(res){alert(JSON.stringify(res))})">
33+
测试showToast
34+
</button>
35+
</div>
36+
</li>
37+
<br/>
38+
</ul>
39+
</body>
40+
</html>
41+
````
42+
43+
When the button is pressed: the logic inside the JSBrige.js file will be triggered:
44+
45+
````
46+
(function (win) {
47+
var hasOwnProperty = Object.prototype.hasOwnProperty;
48+
var JSBridge = win.JSBridge || (win.JSBridge = {});
49+
var JSBRIDGE_PROTOCOL = 'JSBridge';
50+
var Inner = {
51+
callbacks: {},
52+
call: function (obj, method, params, callback) {
53+
console.log(obj+" "+method+" "+params+" "+callback);
54+
var port = Util.getPort();
55+
console.log(port);
56+
this.callbacks[port] = callback;
57+
var uri=Util.getUri(obj,method,params,port);
58+
console.log(uri);
59+
window.prompt(uri, "");
60+
},
61+
onFinish: function (port, jsonObj){
62+
var callback = this.callbacks[port];
63+
callback && callback(jsonObj);
64+
delete this.callbacks[port];
65+
},
66+
};
67+
var Util = {
68+
getPort: function () {
69+
return Math.floor(Math.random() * (1 << 30));
70+
},
71+
getUri:function(obj, method, params, port){
72+
params = this.getParam(params);
73+
var uri = JSBRIDGE_PROTOCOL + '://' + obj + ':' + port + '/' + method + '?' + params;
74+
return uri;
75+
},
76+
getParam:function(obj){
77+
if (obj && typeof obj === 'object') {
78+
return JSON.stringify(obj);
79+
} else {
80+
return obj || '';
81+
}
82+
}
83+
};
84+
for (var key in Inner) {
85+
if (!hasOwnProperty.call(JSBridge, key)) {
86+
JSBridge[key] = Inner[key];
87+
}
88+
}
89+
})(window);
90+
````
91+
the called in the html passes in four paramerters:
92+
93+
``JSBridge.call('bridge','showToast',{'msg':'Hello JSBridge'},function(res){alert(JSON.stringify(res))})``
94+
95+
the name of the related class named ``brige`` and the method of the ``bridge`` class and the json string of the value then the callback function.
96+
97+
## from the view of Android side:
98+
99+
- inside JSBrige.java, we ought to use reflection to get the specific class and the method inside to be flexiable.
100+
101+
````
102+
public class JSBridge {
103+
private static Map<String, HashMap<String, Method>> exposedMethods = new HashMap<>();
104+
105+
public static void register(String exposedName, Class<? extends IBridge> clazz) {
106+
if (!exposedMethods.containsKey(exposedName)) {
107+
try {
108+
exposedMethods.put(exposedName, getAllMethod(clazz));
109+
} catch (Exception e) {
110+
e.printStackTrace();
111+
}
112+
}
113+
}
114+
115+
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
116+
HashMap<String, Method> mMethodsMap = new HashMap<>();
117+
Method[] methods = injectedCls.getDeclaredMethods();
118+
for (Method method : methods) {
119+
String name;
120+
if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
121+
continue;
122+
}
123+
Class[] parameters = method.getParameterTypes();
124+
if (null != parameters && parameters.length == 3) {
125+
if (parameters[0] == WebView.class && parameters[1] == JSONObject.class && parameters[2] == Callback.class) {
126+
mMethodsMap.put(name, method);
127+
}
128+
}
129+
}
130+
return mMethodsMap;
131+
}
132+
133+
public static String callJava(WebView webView, String uriString) {
134+
String methodName = "";
135+
String className = "";
136+
String param = "{}";
137+
String port = "";
138+
if (!TextUtils.isEmpty(uriString) && uriString.startsWith("JSBridge")) {
139+
Uri uri = Uri.parse(uriString);
140+
className = uri.getHost();
141+
param = uri.getQuery();
142+
port = uri.getPort() + "";
143+
String path = uri.getPath();
144+
if (!TextUtils.isEmpty(path)) {
145+
methodName = path.replace("/", "");
146+
}
147+
}
148+
149+
150+
if (exposedMethods.containsKey(className)) {
151+
HashMap<String, Method> methodHashMap = exposedMethods.get(className);
152+
153+
if (methodHashMap != null && methodHashMap.size() != 0 && methodHashMap.containsKey(methodName)) {
154+
Method method = methodHashMap.get(methodName);
155+
if (method != null) {
156+
try {
157+
method.invoke(null, webView, new JSONObject(param), new Callback(webView, port));
158+
} catch (Exception e) {
159+
e.printStackTrace();
160+
}
161+
}
162+
}
163+
}
164+
return null;
165+
}
166+
}
167+
168+
169+
````
170+
- and there is one more class for callback in Javascript -- to use webview to ``loadUrl()`` the callback in JSBridge.js
171+
172+
````
173+
public class Callback {
174+
private static Handler mHandler = new Handler(Looper.getMainLooper());
175+
private static final String CALLBACK_JS_FORMAT = "javascript:JSBridge.onFinish('%s', %s);";
176+
private String mPort;
177+
private WeakReference<WebView> mWebViewRef;
178+
179+
public Callback(WebView view, String port) {
180+
mWebViewRef = new WeakReference<>(view);
181+
mPort = port;
182+
}
183+
184+
185+
public void apply(JSONObject jsonObject) {
186+
final String execJs = String.format(CALLBACK_JS_FORMAT, mPort, String.valueOf(jsonObject));
187+
if (mWebViewRef != null && mWebViewRef.get() != null) {
188+
mHandler.post(new Runnable() {
189+
@Override
190+
public void run() {
191+
mWebViewRef.get().loadUrl(execJs);
192+
}
193+
});
194+
195+
}
196+
197+
}
198+
}
199+
````
200+

os/Android/AndroidWebView.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# WebView
2+
3+
[Webiew 基本介绍](https://blog.csdn.net/lowprofile_coding/article/details/77928614)
4+
5+
6+
## webViewClient #shouldOverridingUrlLoading 返回false 或者 true的问题
7+
一般情况下返回false 使用系统自带的 逻辑处理,正常情况下返回true 和 返回false的表现是没有区别的,
8+
但是在html 的head中存在location href 会存在使用上的区别
9+
[区别](https://juejin.im/post/5a5d8ef2f265da3e393a6b76)
10+
11+
12+
## 这个方法的使用
13+
是为了[拦截](https://blog.csdn.net/zhyh1986/article/details/42169159)这些链接的跳转在这个webView中进行
14+
15+
#java和 JavaScript 方法互相调用
16+
17+
## Java代码调用Javascript方法:
18+
webView.loadUrl("javascript:callJS()");
19+
20+
callJS is a function of the JavaScript file
21+
22+
# intercept from Android
23+
24+
from the view of Android, we can use WebViewClient shouldOverringUrlLoading to intercept the url and add some of our own logic
25+
26+
or we can use a set of methods exported by webChromeClient
27+
``onJsAlert()`` ``onJsConfirm()`` ``onJsPrompt()`` to intercept
28+
29+
````
30+
mWebView.setWebChromeClient(new WebChromeClient() {
31+
@Override
32+
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
33+
AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this);
34+
b.setTitle("Alert");
35+
b.setMessage(message);
36+
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
37+
@Override
38+
public void onClick(DialogInterface dialog, int which) {
39+
result.confirm();
40+
}
41+
});
42+
b.setCancelable(false);
43+
b.create().show();
44+
return true;
45+
}
46+
47+
});
48+
````
49+
50+
And there is another method called
51+
````
52+
mWebView.evaluateJavascript("javascript:callJS()", new ValueCallback<String>() {
53+
@Override
54+
public void onReceiveValue(String value) {
55+
//此处为 js 返回的结果
56+
}
57+
});
58+
````
59+
60+
## JavaScript calls Java code:
61+
62+
- object mapping
63+
mapping Java object to a JavaScript object:
64+
65+
`````
66+
public JavaClass {
67+
@JavaScriptInterface
68+
public void say(String msg){
69+
println(msg);
70+
}
71+
}
72+
`````
73+
74+
`````
75+
function callFromJava() {
76+
test.say("my name");
77+
}
78+
`````
79+
80+
````
81+
// test must be the same name in the Javascript
82+
webView.addJavascriptInterface(new JavaClass(),"test");
83+
````
84+
85+
- WebViewClient
86+
87+
````
88+
function callAndroid(){
89+
/*约定的url协议为:js://webview?arg1=111&arg2=222*/
90+
document.location = "js://webview?arg1=111&arg2=222";
91+
}
92+
````
93+
94+
````
95+
// 复写WebViewClient类的shouldOverrideUrlLoading方法
96+
mWebView.setWebViewClient(new WebViewClient() {
97+
@Override
98+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
99+
100+
// 步骤2:根据协议的参数,判断是否是所需要的url
101+
// 一般根据scheme(协议格式) & authority(协议名)判断(前两个参数)
102+
//假定传入进来的 url = "js://webview?arg1=111&arg2=222"(同时也是约定好的需要拦截的)
103+
104+
Uri uri = Uri.parse(url);
105+
// 如果url的协议 = 预先约定的 js 协议
106+
// 就解析往下解析参数
107+
if ( uri.getScheme().equals("js")) {
108+
109+
// 如果 authority = 预先约定协议里的 webview,即代表都符合约定的协议
110+
// 所以拦截url,下面JS开始调用Android需要的方法
111+
if (uri.getAuthority().equals("webview")) {
112+
113+
// 步骤3:
114+
// 执行JS所需要调用的逻辑
115+
System.out.println("js调用了Android的方法");
116+
// 可以在协议上带有参数并传递到Android上
117+
HashMap<String, String> params = new HashMap<>();
118+
Set<String> collection = uri.getQueryParameterNames();
119+
120+
}
121+
122+
return true;
123+
}
124+
return super.shouldOverrideUrlLoading(view, url);
125+
}
126+
}
127+
);
128+
}
129+
}
130+
````
131+
132+
This way is not technically to use javascript to run java code, but more like a way to transmit data.
133+
134+
JS may get data from Android using:
135+
``webView.loadUrl("javascript:returnReusult("+result+")")``
136+
137+
````
138+
function returnResult(result){
139+
alert("result is" + result);
140+
}
141+
````
142+
143+
- use WebChromeClient onJSAlert() get data in alert dialog in JS
144+
[all you need to know about webView ](https://blog.csdn.net/carson_ho/article/details/64904691)
145+
146+
File renamed without changes.

0 commit comments

Comments
 (0)