OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
6 | 6 |
7 import android.util.SparseArray; | 7 import android.util.SparseArray; |
8 import android.webkit.ValueCallback; | 8 import android.webkit.ValueCallback; |
9 | 9 |
10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 public final long[] mQuotas; | 43 public final long[] mQuotas; |
44 | 44 |
45 Origins(String[] origins, long[] usages, long[] quotas) { | 45 Origins(String[] origins, long[] usages, long[] quotas) { |
46 mOrigins = origins; | 46 mOrigins = origins; |
47 mUsages = usages; | 47 mUsages = usages; |
48 mQuotas = quotas; | 48 mQuotas = quotas; |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 // This is not owning. The native object is owned by the native AwBrowserCon
text. | 52 // This is not owning. The native object is owned by the native AwBrowserCon
text. |
53 private long mNativeAwQuotaManagerBridgeImpl; | 53 private long mNativeAwQuotaManagerBridge; |
54 | 54 |
55 // The Java callbacks are saved here. An incrementing callback id is generat
ed for each saved | 55 // The Java callbacks are saved here. An incrementing callback id is generat
ed for each saved |
56 // callback and is passed to the native side to identify callback. | 56 // callback and is passed to the native side to identify callback. |
57 private int mNextId; | 57 private int mNextId; |
58 private SparseArray<ValueCallback<Origins>> mPendingGetOriginCallbacks; | 58 private SparseArray<ValueCallback<Origins>> mPendingGetOriginCallbacks; |
59 private SparseArray<ValueCallback<Long>> mPendingGetQuotaForOriginCallbacks; | 59 private SparseArray<ValueCallback<Long>> mPendingGetQuotaForOriginCallbacks; |
60 private SparseArray<ValueCallback<Long>> mPendingGetUsageForOriginCallbacks; | 60 private SparseArray<ValueCallback<Long>> mPendingGetUsageForOriginCallbacks; |
61 | 61 |
62 private AwQuotaManagerBridge(long nativeAwQuotaManagerBridgeImpl) { | 62 private AwQuotaManagerBridge(long nativeAwQuotaManagerBridge) { |
63 mNativeAwQuotaManagerBridgeImpl = nativeAwQuotaManagerBridgeImpl; | 63 mNativeAwQuotaManagerBridge = nativeAwQuotaManagerBridge; |
64 mPendingGetOriginCallbacks = | 64 mPendingGetOriginCallbacks = |
65 new SparseArray<ValueCallback<Origins>>(); | 65 new SparseArray<ValueCallback<Origins>>(); |
66 mPendingGetQuotaForOriginCallbacks = new SparseArray<ValueCallback<Long>
>(); | 66 mPendingGetQuotaForOriginCallbacks = new SparseArray<ValueCallback<Long>
>(); |
67 mPendingGetUsageForOriginCallbacks = new SparseArray<ValueCallback<Long>
>(); | 67 mPendingGetUsageForOriginCallbacks = new SparseArray<ValueCallback<Long>
>(); |
68 nativeInit(mNativeAwQuotaManagerBridgeImpl); | 68 nativeInit(mNativeAwQuotaManagerBridge); |
69 } | 69 } |
70 | 70 |
71 private int getNextId() { | 71 private int getNextId() { |
72 ThreadUtils.assertOnUiThread(); | 72 ThreadUtils.assertOnUiThread(); |
73 return ++mNextId; | 73 return ++mNextId; |
74 } | 74 } |
75 | 75 |
76 /* | 76 /* |
77 * There are five HTML5 offline storage APIs. | 77 * There are five HTML5 offline storage APIs. |
78 * 1) Web Storage (ie the localStorage and sessionStorage variables) | 78 * 1) Web Storage (ie the localStorage and sessionStorage variables) |
79 * 2) Web SQL database | 79 * 2) Web SQL database |
80 * 3) Application cache | 80 * 3) Application cache |
81 * 4) Indexed Database | 81 * 4) Indexed Database |
82 * 5) Filesystem API | 82 * 5) Filesystem API |
83 */ | 83 */ |
84 | 84 |
85 /** | 85 /** |
86 * Implements WebStorage.deleteAllData(). Clear the storage of all five offl
ine APIs. | 86 * Implements WebStorage.deleteAllData(). Clear the storage of all five offl
ine APIs. |
87 * | 87 * |
88 * TODO(boliu): Actually clear Web Storage. | 88 * TODO(boliu): Actually clear Web Storage. |
89 */ | 89 */ |
90 public void deleteAllData() { | 90 public void deleteAllData() { |
91 nativeDeleteAllData(mNativeAwQuotaManagerBridgeImpl); | 91 nativeDeleteAllData(mNativeAwQuotaManagerBridge); |
92 } | 92 } |
93 | 93 |
94 /** | 94 /** |
95 * Implements WebStorage.deleteOrigin(). Clear the storage of APIs 2-5 for t
he given origin. | 95 * Implements WebStorage.deleteOrigin(). Clear the storage of APIs 2-5 for t
he given origin. |
96 */ | 96 */ |
97 public void deleteOrigin(String origin) { | 97 public void deleteOrigin(String origin) { |
98 nativeDeleteOrigin(mNativeAwQuotaManagerBridgeImpl, origin); | 98 nativeDeleteOrigin(mNativeAwQuotaManagerBridge, origin); |
99 } | 99 } |
100 | 100 |
101 /** | 101 /** |
102 * Implements WebStorage.getOrigins. Get the per origin usage and quota of A
PIs 2-5 in | 102 * Implements WebStorage.getOrigins. Get the per origin usage and quota of A
PIs 2-5 in |
103 * aggregate. | 103 * aggregate. |
104 */ | 104 */ |
105 public void getOrigins(ValueCallback<Origins> callback) { | 105 public void getOrigins(ValueCallback<Origins> callback) { |
106 int callbackId = getNextId(); | 106 int callbackId = getNextId(); |
107 assert mPendingGetOriginCallbacks.get(callbackId) == null; | 107 assert mPendingGetOriginCallbacks.get(callbackId) == null; |
108 mPendingGetOriginCallbacks.put(callbackId, callback); | 108 mPendingGetOriginCallbacks.put(callbackId, callback); |
109 nativeGetOrigins(mNativeAwQuotaManagerBridgeImpl, callbackId); | 109 nativeGetOrigins(mNativeAwQuotaManagerBridge, callbackId); |
110 } | 110 } |
111 | 111 |
112 /** | 112 /** |
113 * Implements WebStorage.getQuotaForOrigin. Get the quota of APIs 2-5 in agg
regate for given | 113 * Implements WebStorage.getQuotaForOrigin. Get the quota of APIs 2-5 in agg
regate for given |
114 * origin. | 114 * origin. |
115 */ | 115 */ |
116 public void getQuotaForOrigin(String origin, ValueCallback<Long> callback) { | 116 public void getQuotaForOrigin(String origin, ValueCallback<Long> callback) { |
117 int callbackId = getNextId(); | 117 int callbackId = getNextId(); |
118 assert mPendingGetQuotaForOriginCallbacks.get(callbackId) == null; | 118 assert mPendingGetQuotaForOriginCallbacks.get(callbackId) == null; |
119 mPendingGetQuotaForOriginCallbacks.put(callbackId, callback); | 119 mPendingGetQuotaForOriginCallbacks.put(callbackId, callback); |
120 nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridgeImpl, origin,
callbackId, true); | 120 nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridge, origin, cal
lbackId, true); |
121 } | 121 } |
122 | 122 |
123 /** | 123 /** |
124 * Implements WebStorage.getUsageForOrigin. Get the usage of APIs 2-5 in agg
regate for given | 124 * Implements WebStorage.getUsageForOrigin. Get the usage of APIs 2-5 in agg
regate for given |
125 * origin. | 125 * origin. |
126 */ | 126 */ |
127 public void getUsageForOrigin(String origin, ValueCallback<Long> callback) { | 127 public void getUsageForOrigin(String origin, ValueCallback<Long> callback) { |
128 int callbackId = getNextId(); | 128 int callbackId = getNextId(); |
129 assert mPendingGetUsageForOriginCallbacks.get(callbackId) == null; | 129 assert mPendingGetUsageForOriginCallbacks.get(callbackId) == null; |
130 mPendingGetUsageForOriginCallbacks.put(callbackId, callback); | 130 mPendingGetUsageForOriginCallbacks.put(callbackId, callback); |
131 nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridgeImpl, origin,
callbackId, false); | 131 nativeGetUsageAndQuotaForOrigin(mNativeAwQuotaManagerBridge, origin, cal
lbackId, false); |
132 } | 132 } |
133 | 133 |
134 @CalledByNative | 134 @CalledByNative |
135 private void onGetOriginsCallback(int callbackId, String[] origin, long[] us
ages, | 135 private void onGetOriginsCallback(int callbackId, String[] origin, long[] us
ages, |
136 long[] quotas) { | 136 long[] quotas) { |
137 assert mPendingGetOriginCallbacks.get(callbackId) != null; | 137 assert mPendingGetOriginCallbacks.get(callbackId) != null; |
138 mPendingGetOriginCallbacks.get(callbackId).onReceiveValue( | 138 mPendingGetOriginCallbacks.get(callbackId).onReceiveValue( |
139 new Origins(origin, usages, quotas)); | 139 new Origins(origin, usages, quotas)); |
140 mPendingGetOriginCallbacks.remove(callbackId); | 140 mPendingGetOriginCallbacks.remove(callbackId); |
141 } | 141 } |
142 | 142 |
143 @CalledByNative | 143 @CalledByNative |
144 private void onGetUsageAndQuotaForOriginCallback( | 144 private void onGetUsageAndQuotaForOriginCallback( |
145 int callbackId, boolean isQuota, long usage, long quota) { | 145 int callbackId, boolean isQuota, long usage, long quota) { |
146 if (isQuota) { | 146 if (isQuota) { |
147 assert mPendingGetQuotaForOriginCallbacks.get(callbackId) != null; | 147 assert mPendingGetQuotaForOriginCallbacks.get(callbackId) != null; |
148 mPendingGetQuotaForOriginCallbacks.get(callbackId).onReceiveValue(qu
ota); | 148 mPendingGetQuotaForOriginCallbacks.get(callbackId).onReceiveValue(qu
ota); |
149 mPendingGetQuotaForOriginCallbacks.remove(callbackId); | 149 mPendingGetQuotaForOriginCallbacks.remove(callbackId); |
150 } else { | 150 } else { |
151 assert mPendingGetUsageForOriginCallbacks.get(callbackId) != null; | 151 assert mPendingGetUsageForOriginCallbacks.get(callbackId) != null; |
152 mPendingGetUsageForOriginCallbacks.get(callbackId).onReceiveValue(us
age); | 152 mPendingGetUsageForOriginCallbacks.get(callbackId).onReceiveValue(us
age); |
153 mPendingGetUsageForOriginCallbacks.remove(callbackId); | 153 mPendingGetUsageForOriginCallbacks.remove(callbackId); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 private native void nativeInit(long nativeAwQuotaManagerBridgeImpl); | 157 private native void nativeInit(long nativeAwQuotaManagerBridge); |
158 private native void nativeDeleteAllData(long nativeAwQuotaManagerBridgeImpl)
; | 158 private native void nativeDeleteAllData(long nativeAwQuotaManagerBridge); |
159 private native void nativeDeleteOrigin(long nativeAwQuotaManagerBridgeImpl,
String origin); | 159 private native void nativeDeleteOrigin(long nativeAwQuotaManagerBridge, Stri
ng origin); |
160 private native void nativeGetOrigins(long nativeAwQuotaManagerBridgeImpl, in
t callbackId); | 160 private native void nativeGetOrigins(long nativeAwQuotaManagerBridge, int ca
llbackId); |
161 private native void nativeGetUsageAndQuotaForOrigin(long nativeAwQuotaManage
rBridgeImpl, | 161 private native void nativeGetUsageAndQuotaForOrigin( |
162 String origin, int callbackId, boolean isQuota); | 162 long nativeAwQuotaManagerBridge, String origin, int callbackId, bool
ean isQuota); |
163 } | 163 } |
OLD | NEW |