JB43R11 Save for offline readings
MENU>Save for offline readingをクリックすると以下の処理を通る。
1:packages/apps/Browser/src/com/android/browser/Controller.java
1741 @Override 1742 protected Long doInBackground(Void... params) { 1743 if (!mTab.saveViewState(mValues)) { => snapshot.tab経由 =>2へ 1744 return null; 1745 } 1746 if (isCancelled()) { 1747 String path = mValues.getAsString(Snapshots.VIEWSTATE_PATH); 1748 File file = mActivity.getFileStreamPath(path); 1749 if (!file.delete()) { 1750 file.deleteOnExit(); 1751 } 1752 return null; 1753 } 1754 final ContentResolver cr = mActivity.getContentResolver(); 1755 Uri result = cr.insert(Snapshots.CONTENT_URI, mValues); 1756 if (result == null) { 1757 return null; 1758 } 1759 long id = ContentUris.parseId(result); 1760 return id; 1761 }
2:packages/apps/Browser/src/com/android/browser/Tab.java
1842 /** 1843 * Probably want to call this on a background thread 1844 */ 1845 public boolean saveViewState(ContentValues values) { 1846 WebViewClassic web = getWebViewClassic(); 1847 if (web == null) return false; 1848 String path = UUID.randomUUID().toString(); 1849 SaveCallback callback = new SaveCallback(); 1850 OutputStream outs = null; 1851 try { 1852 outs = mContext.openFileOutput(path, Context.MODE_PRIVATE); 1853 GZIPOutputStream stream = new GZIPOutputStream(outs); 1854 synchronized (callback) { 1855 web.saveViewState(stream, callback); =>3へ =>CBをセットして3から戻ってくる。 1856 callback.wait(); 1857 } 1858 stream.flush(); 1859 stream.close(); 1860 } catch (Exception e) { 1861 Log.w(LOGTAG, "Failed to save view state", e); 1862 if (outs != null) { 1863 try { 1864 outs.close(); 1865 } catch (IOException ignore) {} 1866 } 1867 File file = mContext.getFileStreamPath(path); 1868 if (file.exists() && !file.delete()) { 1869 file.deleteOnExit(); 1870 } 1871 return false; 1872 } 1873 File savedFile = mContext.getFileStreamPath(path); 1874 if (!callback.mResult) { 1875 if (!savedFile.delete()) { 1876 savedFile.deleteOnExit(); 1877 } 1878 return false; 1879 } 1880 long size = savedFile.length(); 1881 values.put(Snapshots.VIEWSTATE_PATH, path); 1882 values.put(Snapshots.VIEWSTATE_SIZE, size); 1883 return true; 1884 }
3:frameworks/base/core/java/android/webkit/WebViewClassic.java
2428 /** 2429 * Saves the view data to the output stream. The output is highly 2430 * version specific, and may not be able to be loaded by newer versions 2431 * of WebView. 2432 * @param stream The {@link OutputStream} to save to 2433 * @param callback The {@link ValueCallback} to call with the result 2434 */ 2435 public void saveViewState(OutputStream stream, ValueCallback<Boolean> callback) { 2436 if (mWebViewCore == null) { 2437 callback.onReceiveValue(false); 2438 return; 2439 } 2440 mWebViewCore.sendMessageAtFrontOfQueue(EventHub.SAVE_VIEW_STATE, 2441 new WebViewCore.SaveViewStateRequest(stream, callback)); => 4のコンストラクタでObject作成 => 5へ 2442 }
4:frameworks/base/core/java/android/webkit/WebViewCore.java
1051 static class SaveViewStateRequest { コンストラクタ 1052 SaveViewStateRequest(OutputStream s, ValueCallback<Boolean> cb) { 1053 mStream = s; 1054 mCallback = cb; 1055 } 1056 public OutputStream mStream; 1057 public ValueCallback<Boolean> mCallback; 1058 }
5:frameworks/base/core/java/android/webkit/WebViewCore.java
1961 void sendMessageAtFrontOfQueue(int what, Object obj) { 1962 mEventHub.sendMessageAtFrontOfQueue(Message.obtain( 1963 null, what, obj)); =>EventHubのQueueへメッセージを送る。 1964 }
6:frameworks/base/core/java/android/webkit/WebViewCore.java
1753 case SAVE_VIEW_STATE:<=メッセージ受信 1754 SaveViewStateRequest request = (SaveViewStateRequest) msg.obj; 1755 saveViewState(request.mStream, request.mCallback); 1756 break;
7:frameworks/base/core/java/android/webkit/WebViewCore.java
2255 private void saveViewState(OutputStream stream, 2256 ValueCallback<Boolean> callback) { 2257 // TODO: Create a native method to do this better without overloading 2258 // the draw path (and fix saving <canvas>) 2259 DrawData draw = new DrawData(); 2260 if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "saveViewState start"); 2261 draw.mBaseLayer = nativeRecordContent(mNativeClass, draw.mContentSize);<==Native 2262 boolean result = false; 2263 try { 2264 result = ViewStateSerializer.serializeViewState(stream, draw); 2265 } catch (Throwable t) { 2266 Log.w(LOGTAG, "Failed to save view state", t); 2267 } 2268 callback.onReceiveValue(result); 2269 if (draw.mBaseLayer != 0) { 2270 if (mDrawIsScheduled) { 2271 mDrawIsScheduled = false; 2272 mEventHub.removeMessages(EventHub.WEBKIT_DRAW); 2273 } 2274 mLastDrawData = draw; 2275 webkitDraw(draw); 2276 } 2277 }
C++の方へ入る。