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.content.browser.webcontents; | 5 package org.chromium.content.browser.webcontents; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
10 import android.os.Bundle; | 10 import android.os.Bundle; |
11 import android.os.Handler; | 11 import android.os.Handler; |
12 import android.os.Message; | 12 import android.os.Message; |
13 import android.os.Parcel; | 13 import android.os.Parcel; |
14 import android.os.ParcelUuid; | 14 import android.os.ParcelUuid; |
15 import android.os.Parcelable; | 15 import android.os.Parcelable; |
16 | 16 |
17 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
18 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
19 import org.chromium.base.annotations.CalledByNative; | 19 import org.chromium.base.annotations.CalledByNative; |
20 import org.chromium.base.annotations.JNINamespace; | 20 import org.chromium.base.annotations.JNINamespace; |
21 import org.chromium.content.browser.AppWebMessagePort; | 21 import org.chromium.content.browser.AppWebMessagePort; |
22 import org.chromium.content.browser.MediaSessionImpl; | 22 import org.chromium.content.browser.MediaSessionImpl; |
| 23 import org.chromium.content.browser.RenderCoordinates; |
23 import org.chromium.content.browser.framehost.RenderFrameHostDelegate; | 24 import org.chromium.content.browser.framehost.RenderFrameHostDelegate; |
24 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; | 25 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; |
25 import org.chromium.content_public.browser.AccessibilitySnapshotNode; | 26 import org.chromium.content_public.browser.AccessibilitySnapshotNode; |
26 import org.chromium.content_public.browser.ContentBitmapCallback; | 27 import org.chromium.content_public.browser.ContentBitmapCallback; |
27 import org.chromium.content_public.browser.ImageDownloadCallback; | 28 import org.chromium.content_public.browser.ImageDownloadCallback; |
28 import org.chromium.content_public.browser.JavaScriptCallback; | 29 import org.chromium.content_public.browser.JavaScriptCallback; |
29 import org.chromium.content_public.browser.MessagePort; | 30 import org.chromium.content_public.browser.MessagePort; |
30 import org.chromium.content_public.browser.NavigationController; | 31 import org.chromium.content_public.browser.NavigationController; |
31 import org.chromium.content_public.browser.RenderFrameHost; | 32 import org.chromium.content_public.browser.RenderFrameHost; |
32 import org.chromium.content_public.browser.SmartClipCallback; | 33 import org.chromium.content_public.browser.SmartClipCallback; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 private NavigationController mNavigationController; | 100 private NavigationController mNavigationController; |
100 private RenderFrameHost mMainFrame; | 101 private RenderFrameHost mMainFrame; |
101 | 102 |
102 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. | 103 // Lazily created proxy observer for handling all Java-based WebContentsObse
rvers. |
103 private WebContentsObserverProxy mObserverProxy; | 104 private WebContentsObserverProxy mObserverProxy; |
104 | 105 |
105 // The media session for this WebContents. It is constructed by the native M
ediaSession and has | 106 // The media session for this WebContents. It is constructed by the native M
ediaSession and has |
106 // the same life time as native MediaSession. | 107 // the same life time as native MediaSession. |
107 private MediaSessionImpl mMediaSession; | 108 private MediaSessionImpl mMediaSession; |
108 | 109 |
109 private SmartClipCallback mSmartClipCallback; | 110 class SmartClipCallbackImpl implements SmartClipCallback { |
| 111 public SmartClipCallbackImpl(final Handler smartClipHandler) { |
| 112 mHandler = smartClipHandler; |
| 113 } |
| 114 public void storeRequestRect(Rect rect) { |
| 115 mRect = rect; |
| 116 } |
| 117 |
| 118 @Override |
| 119 public void onSmartClipDataExtracted(String text, String html) { |
| 120 Bundle bundle = new Bundle(); |
| 121 bundle.putString("url", getVisibleUrl()); |
| 122 bundle.putString("title", getTitle()); |
| 123 bundle.putString("text", text); |
| 124 bundle.putString("html", html); |
| 125 bundle.putParcelable("rect", mRect); |
| 126 |
| 127 Message msg = Message.obtain(mHandler, 0); |
| 128 msg.setData(bundle); |
| 129 msg.sendToTarget(); |
| 130 } |
| 131 |
| 132 Rect mRect; |
| 133 final Handler mHandler; |
| 134 } |
| 135 private SmartClipCallbackImpl mSmartClipCallback; |
110 | 136 |
111 private EventForwarder mEventForwarder; | 137 private EventForwarder mEventForwarder; |
112 | 138 |
113 private WebContentsImpl( | 139 private WebContentsImpl( |
114 long nativeWebContentsAndroid, NavigationController navigationContro
ller) { | 140 long nativeWebContentsAndroid, NavigationController navigationContro
ller) { |
115 mNativeWebContentsAndroid = nativeWebContentsAndroid; | 141 mNativeWebContentsAndroid = nativeWebContentsAndroid; |
116 mNavigationController = navigationController; | 142 mNavigationController = navigationController; |
117 } | 143 } |
118 | 144 |
119 @CalledByNative | 145 @CalledByNative |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 String jsonResult, JavaScriptCallback callback) { | 419 String jsonResult, JavaScriptCallback callback) { |
394 callback.handleJavaScriptResult(jsonResult); | 420 callback.handleJavaScriptResult(jsonResult); |
395 } | 421 } |
396 | 422 |
397 @Override | 423 @Override |
398 public int getThemeColor() { | 424 public int getThemeColor() { |
399 return nativeGetThemeColor(mNativeWebContentsAndroid); | 425 return nativeGetThemeColor(mNativeWebContentsAndroid); |
400 } | 426 } |
401 | 427 |
402 @Override | 428 @Override |
403 public void requestSmartClipExtract(int x, int y, int width, int height) { | 429 public void requestSmartClipExtract( |
| 430 int x, int y, int width, int height, RenderCoordinates coordinateSpa
ce) { |
404 if (mSmartClipCallback == null) return; | 431 if (mSmartClipCallback == null) return; |
405 nativeRequestSmartClipExtract( | 432 mSmartClipCallback.storeRequestRect(new Rect(x, y, x + width, y + height
)); |
406 mNativeWebContentsAndroid, mSmartClipCallback, x, y, width, heig
ht); | 433 float dpi = coordinateSpace.getDeviceScaleFactor(); |
| 434 y -= coordinateSpace.getContentOffsetYPix(); |
| 435 nativeRequestSmartClipExtract(mNativeWebContentsAndroid, mSmartClipCallb
ack, |
| 436 (int) (x / dpi), (int) (y / dpi), (int) (width / dpi), (int) (he
ight / dpi)); |
407 } | 437 } |
408 | 438 |
409 @Override | 439 @Override |
410 public void setSmartClipResultHandler(final Handler smartClipHandler) { | 440 public void setSmartClipResultHandler(final Handler smartClipHandler) { |
411 if (smartClipHandler == null) { | 441 if (smartClipHandler == null) { |
412 mSmartClipCallback = null; | 442 mSmartClipCallback = null; |
413 return; | 443 return; |
414 } | 444 } |
415 mSmartClipCallback = new SmartClipCallback() { | 445 mSmartClipCallback = new SmartClipCallbackImpl(smartClipHandler); |
416 @Override | |
417 public void onSmartClipDataExtracted(String text, String html) { | |
418 Bundle bundle = new Bundle(); | |
419 bundle.putString("url", getVisibleUrl()); | |
420 bundle.putString("title", getTitle()); | |
421 bundle.putString("text", text); | |
422 bundle.putString("html", html); | |
423 | |
424 Message msg = Message.obtain(smartClipHandler, 0); | |
425 msg.setData(bundle); | |
426 msg.sendToTarget(); | |
427 } | |
428 }; | |
429 } | 446 } |
430 | 447 |
431 @CalledByNative | 448 @CalledByNative |
432 private static void onSmartClipDataExtracted( | 449 private static void onSmartClipDataExtracted( |
433 String text, String html, SmartClipCallback callback) { | 450 String text, String html, SmartClipCallback callback) { |
434 callback.onSmartClipDataExtracted(text, html); | 451 callback.onSmartClipDataExtracted(text, html); |
435 } | 452 } |
436 | 453 |
437 @Override | 454 @Override |
438 public void requestAccessibilitySnapshot(AccessibilitySnapshotCallback callb
ack) { | 455 public void requestAccessibilitySnapshot(AccessibilitySnapshotCallback callb
ack) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); | 663 private native void nativeReloadLoFiImages(long nativeWebContentsAndroid); |
647 private native int nativeDownloadImage(long nativeWebContentsAndroid, | 664 private native int nativeDownloadImage(long nativeWebContentsAndroid, |
648 String url, boolean isFavicon, int maxBitmapSize, | 665 String url, boolean isFavicon, int maxBitmapSize, |
649 boolean bypassCache, ImageDownloadCallback callback); | 666 boolean bypassCache, ImageDownloadCallback callback); |
650 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); | 667 private native void nativeDismissTextHandles(long nativeWebContentsAndroid); |
651 private native void nativeShowContextMenuAtPoint(long nativeWebContentsAndro
id, int x, int y); | 668 private native void nativeShowContextMenuAtPoint(long nativeWebContentsAndro
id, int x, int y); |
652 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); | 669 private native void nativeSetHasPersistentVideo(long nativeWebContentsAndroi
d, boolean value); |
653 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); | 670 private native boolean nativeHasActiveEffectivelyFullscreenVideo(long native
WebContentsAndroid); |
654 private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWeb
ContentsAndroid); | 671 private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWeb
ContentsAndroid); |
655 } | 672 } |
OLD | NEW |