| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 @Override | 224 @Override |
| 226 @CalledByNative | 225 @CalledByNative |
| 227 public void didStartNavigationToPendingEntry(String url) { | 226 public void didStartNavigationToPendingEntry(String url) { |
| 228 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | 227 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { |
| 229 mObserversIterator.next().didStartNavigationToPendingEntry(url); | 228 mObserversIterator.next().didStartNavigationToPendingEntry(url); |
| 230 } | 229 } |
| 231 } | 230 } |
| 232 | 231 |
| 233 @Override | 232 @Override |
| 234 @CalledByNative | 233 @CalledByNative |
| 235 public void mediaSessionStateChanged(boolean isControllable, boolean isSuspe
nded) { | |
| 236 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | |
| 237 mObserversIterator.next().mediaSessionStateChanged(isControllable, i
sSuspended); | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 @Override | |
| 242 @CalledByNative | |
| 243 public void mediaSessionMetadataChanged(MediaMetadata metadata) { | |
| 244 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | |
| 245 mObserversIterator.next().mediaSessionMetadataChanged(metadata); | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 @Override | |
| 250 @CalledByNative | |
| 251 public void destroy() { | 234 public void destroy() { |
| 252 // Super destruction semantics (removing the observer from the | 235 // Super destruction semantics (removing the observer from the |
| 253 // Java-based WebContents) are quite different, so we explicitly avoid | 236 // Java-based WebContents) are quite different, so we explicitly avoid |
| 254 // calling it here. | 237 // calling it here. |
| 255 ThreadUtils.assertOnUiThread(); | 238 ThreadUtils.assertOnUiThread(); |
| 256 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { | 239 for (mObserversIterator.rewind(); mObserversIterator.hasNext();) { |
| 257 mObserversIterator.next().destroy(); | 240 mObserversIterator.next().destroy(); |
| 258 } | 241 } |
| 259 // All observer destroy() implementations should result in their removal | 242 // All observer destroy() implementations should result in their removal |
| 260 // from the proxy. | 243 // from the proxy. |
| 261 assert mObservers.isEmpty(); | 244 assert mObservers.isEmpty(); |
| 262 mObservers.clear(); | 245 mObservers.clear(); |
| 263 | 246 |
| 264 if (mNativeWebContentsObserverProxy != 0) { | 247 if (mNativeWebContentsObserverProxy != 0) { |
| 265 nativeDestroy(mNativeWebContentsObserverProxy); | 248 nativeDestroy(mNativeWebContentsObserverProxy); |
| 266 mNativeWebContentsObserverProxy = 0; | 249 mNativeWebContentsObserverProxy = 0; |
| 267 } | 250 } |
| 268 } | 251 } |
| 269 | 252 |
| 270 private native long nativeInit(WebContentsImpl webContents); | 253 private native long nativeInit(WebContentsImpl webContents); |
| 271 private native void nativeDestroy(long nativeWebContentsObserverProxy); | 254 private native void nativeDestroy(long nativeWebContentsObserverProxy); |
| 272 } | 255 } |
| OLD | NEW |