OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 org.chromium.base.ObserverList; | 7 import org.chromium.base.ObserverList; |
8 import org.chromium.base.ObserverList.RewindableIterator; | 8 import org.chromium.base.ObserverList.RewindableIterator; |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.content_public.browser.WebContentsObserver; | 13 import org.chromium.content_public.browser.WebContentsObserver; |
14 import org.chromium.content_public.common.MediaMetadata; | |
15 | 14 |
16 /** | 15 /** |
17 * Serves as a compound observer proxy for dispatching WebContentsObserver callb
acks, | 16 * Serves as a compound observer proxy for dispatching WebContentsObserver callb
acks, |
18 * avoiding redundant JNI-related work when there are multiple Java-based observ
ers. | 17 * avoiding redundant JNI-related work when there are multiple Java-based observ
ers. |
19 */ | 18 */ |
20 @JNINamespace("content") | 19 @JNINamespace("content") |
21 class WebContentsObserverProxy extends WebContentsObserver { | 20 class WebContentsObserverProxy extends WebContentsObserver { |
22 private long mNativeWebContentsObserverProxy; | 21 private long mNativeWebContentsObserverProxy; |
23 private final ObserverList<WebContentsObserver> mObservers; | 22 private final ObserverList<WebContentsObserver> mObservers; |
24 private final RewindableIterator<WebContentsObserver> mObserversIterator; | 23 private final RewindableIterator<WebContentsObserver> mObserversIterator; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 @Override | 240 @Override |
242 @CalledByNative | 241 @CalledByNative |
243 public void didStartNavigationToPendingEntry(String url) { | 242 public void didStartNavigationToPendingEntry(String url) { |
244 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | 243 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { |
245 mObserversIterator.next().didStartNavigationToPendingEntry(url); | 244 mObserversIterator.next().didStartNavigationToPendingEntry(url); |
246 } | 245 } |
247 } | 246 } |
248 | 247 |
249 @Override | 248 @Override |
250 @CalledByNative | 249 @CalledByNative |
251 public void mediaSessionStateChanged(boolean isControllable, boolean isSuspe
nded) { | |
252 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | |
253 mObserversIterator.next().mediaSessionStateChanged(isControllable, i
sSuspended); | |
254 } | |
255 } | |
256 | |
257 @Override | |
258 @CalledByNative | |
259 public void mediaSessionMetadataChanged(MediaMetadata metadata) { | |
260 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | |
261 mObserversIterator.next().mediaSessionMetadataChanged(metadata); | |
262 } | |
263 } | |
264 | |
265 @Override | |
266 @CalledByNative | |
267 public void destroy() { | 250 public void destroy() { |
268 // Super destruction semantics (removing the observer from the | 251 // Super destruction semantics (removing the observer from the |
269 // Java-based WebContents) are quite different, so we explicitly avoid | 252 // Java-based WebContents) are quite different, so we explicitly avoid |
270 // calling it here. | 253 // calling it here. |
271 ThreadUtils.assertOnUiThread(); | 254 ThreadUtils.assertOnUiThread(); |
272 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | 255 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { |
273 mObserversIterator.next().destroy(); | 256 mObserversIterator.next().destroy(); |
274 } | 257 } |
275 // All observer destroy() implementations should result in their removal | 258 // All observer destroy() implementations should result in their removal |
276 // from the proxy. | 259 // from the proxy. |
277 assert mObservers.isEmpty(); | 260 assert mObservers.isEmpty(); |
278 mObservers.clear(); | 261 mObservers.clear(); |
279 | 262 |
280 if (mNativeWebContentsObserverProxy != 0) { | 263 if (mNativeWebContentsObserverProxy != 0) { |
281 nativeDestroy(mNativeWebContentsObserverProxy); | 264 nativeDestroy(mNativeWebContentsObserverProxy); |
282 mNativeWebContentsObserverProxy = 0; | 265 mNativeWebContentsObserverProxy = 0; |
283 } | 266 } |
284 } | 267 } |
285 | 268 |
286 private native long nativeInit(WebContentsImpl webContents); | 269 private native long nativeInit(WebContentsImpl webContents); |
287 private native void nativeDestroy(long nativeWebContentsObserverProxy); | 270 private native void nativeDestroy(long nativeWebContentsObserverProxy); |
288 } | 271 } |
OLD | NEW |