| 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.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.view.Gravity; | 8 import android.view.Gravity; |
| 9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
| 10 import android.widget.FrameLayout; | 10 import android.widget.FrameLayout; |
| 11 | 11 |
| 12 import org.chromium.base.ObserverList; | 12 import org.chromium.base.ObserverList; |
| 13 import org.chromium.base.VisibleForTesting; | 13 import org.chromium.base.VisibleForTesting; |
| 14 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
| 15 import org.chromium.chrome.browser.banners.SwipableOverlayView; | 15 import org.chromium.chrome.browser.banners.SwipableOverlayView; |
| 16 import org.chromium.chrome.browser.tab.Tab; | 16 import org.chromium.chrome.browser.tab.Tab; |
| 17 import org.chromium.chrome.browser.tab.TabObserver; | |
| 18 import org.chromium.content.browser.ContentViewCore; | 17 import org.chromium.content.browser.ContentViewCore; |
| 19 import org.chromium.content_public.browser.WebContents; | 18 import org.chromium.content_public.browser.WebContents; |
| 20 import org.chromium.ui.base.DeviceFormFactor; | 19 import org.chromium.ui.base.DeviceFormFactor; |
| 21 | 20 |
| 22 import java.util.ArrayList; | 21 import java.util.ArrayList; |
| 23 | 22 |
| 24 | 23 |
| 25 /** | 24 /** |
| 26 * A container for all the infobars of a specific tab. | 25 * A container for all the infobars of a specific tab. |
| 27 * Note that infobars creation can be initiated from Java of from native code. | 26 * Note that infobars creation can be initiated from Java of from native code. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 * this container. | 167 * this container. |
| 169 */ | 168 */ |
| 170 public void onParentViewChanged(int tabId, ViewGroup parentView) { | 169 public void onParentViewChanged(int tabId, ViewGroup parentView) { |
| 171 mTabId = tabId; | 170 mTabId = tabId; |
| 172 mParentView = parentView; | 171 mParentView = parentView; |
| 173 | 172 |
| 174 removeFromParentView(); | 173 removeFromParentView(); |
| 175 addToParentView(); | 174 addToParentView(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 @Override | |
| 179 protected TabObserver createTabObserver() { | |
| 180 return new SwipableOverlayViewTabObserver() { | |
| 181 @Override | |
| 182 public void onPageLoadStarted(Tab tab, String url) { | |
| 183 onPageStarted(); | |
| 184 } | |
| 185 }; | |
| 186 } | |
| 187 | |
| 188 /** | 177 /** |
| 189 * Adds an InfoBar to the view hierarchy. | 178 * Adds an InfoBar to the view hierarchy. |
| 190 * @param infoBar InfoBar to add to the View hierarchy. | 179 * @param infoBar InfoBar to add to the View hierarchy. |
| 191 */ | 180 */ |
| 192 @CalledByNative | 181 @CalledByNative |
| 193 public void addInfoBar(InfoBar infoBar) { | 182 private void addInfoBar(InfoBar infoBar) { |
| 194 assert !mDestroyed; | 183 assert !mDestroyed; |
| 195 if (infoBar == null) { | 184 if (infoBar == null) { |
| 196 return; | 185 return; |
| 197 } | 186 } |
| 198 if (mInfoBars.contains(infoBar)) { | 187 if (mInfoBars.contains(infoBar)) { |
| 199 assert false : "Trying to add an info bar that has already been adde
d."; | 188 assert false : "Trying to add an info bar that has already been adde
d."; |
| 200 return; | 189 return; |
| 201 } | 190 } |
| 202 addToParentView(); | 191 addToParentView(); |
| 203 | 192 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 221 * Notifies that an infobar's View ({@link InfoBar#getView}) has changed. If
the infobar is | 210 * Notifies that an infobar's View ({@link InfoBar#getView}) has changed. If
the infobar is |
| 222 * visible, a view swapping animation will be run. | 211 * visible, a view swapping animation will be run. |
| 223 */ | 212 */ |
| 224 public void notifyInfoBarViewChanged() { | 213 public void notifyInfoBarViewChanged() { |
| 225 assert !mDestroyed; | 214 assert !mDestroyed; |
| 226 mLayout.notifyInfoBarViewChanged(); | 215 mLayout.notifyInfoBarViewChanged(); |
| 227 } | 216 } |
| 228 | 217 |
| 229 /** | 218 /** |
| 230 * Removes an InfoBar from the view hierarchy. | 219 * Removes an InfoBar from the view hierarchy. |
| 220 * |
| 221 * This should only be called by the base InfoBar class and by tests. |
| 222 * |
| 231 * @param infoBar InfoBar to remove from the View hierarchy. | 223 * @param infoBar InfoBar to remove from the View hierarchy. |
| 232 */ | 224 */ |
| 233 public void removeInfoBar(InfoBar infoBar) { | 225 public void removeInfoBar(InfoBar infoBar) { |
| 234 assert !mDestroyed; | 226 assert !mDestroyed; |
| 235 | 227 |
| 236 if (!mInfoBars.remove(infoBar)) { | 228 if (!mInfoBars.remove(infoBar)) { |
| 237 assert false : "Trying to remove an InfoBar that is not in this cont
ainer."; | 229 assert false : "Trying to remove an InfoBar that is not in this cont
ainer."; |
| 238 return; | 230 return; |
| 239 } | 231 } |
| 240 | 232 |
| 241 // Notify observers immediately, before any animations begin. | 233 // Notify observers immediately, before any animations begin. |
| 242 for (InfoBarContainerObserver observer : mObservers) { | 234 for (InfoBarContainerObserver observer : mObservers) { |
| 243 observer.onRemoveInfoBar(this, infoBar, mInfoBars.isEmpty()); | 235 observer.onRemoveInfoBar(this, infoBar, mInfoBars.isEmpty()); |
| 244 } | 236 } |
| 245 | 237 |
| 246 mLayout.removeInfoBar(infoBar); | 238 mLayout.removeInfoBar(infoBar); |
| 247 } | 239 } |
| 248 | 240 |
| 249 /** | 241 /** |
| 250 * @return True when this container has been emptied and its native counterp
art has been | 242 * @return True when this container has been emptied and its native counterp
art has been |
| 251 * destroyed. | 243 * destroyed. |
| 252 */ | 244 */ |
| 253 public boolean hasBeenDestroyed() { | 245 public boolean hasBeenDestroyed() { |
| 254 return mDestroyed; | 246 return mDestroyed; |
| 255 } | 247 } |
| 256 | 248 |
| 257 // Called by the tab when it has started loading a new page. | |
| 258 public void onPageStarted() { | |
| 259 ArrayList<InfoBar> barsToRemove = new ArrayList<>(); | |
| 260 | |
| 261 for (InfoBar infoBar : mInfoBars) { | |
| 262 if (infoBar.shouldExpire()) { | |
| 263 barsToRemove.add(infoBar); | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 for (InfoBar infoBar : barsToRemove) { | |
| 268 infoBar.dismissJavaOnlyInfoBar(); | |
| 269 } | |
| 270 } | |
| 271 | |
| 272 public void destroy() { | 249 public void destroy() { |
| 273 mDestroyed = true; | 250 mDestroyed = true; |
| 274 if (mNativeInfoBarContainer != 0) { | 251 if (mNativeInfoBarContainer != 0) { |
| 275 nativeDestroy(mNativeInfoBarContainer); | 252 nativeDestroy(mNativeInfoBarContainer); |
| 276 } | 253 } |
| 277 } | 254 } |
| 278 | 255 |
| 279 /** | 256 /** |
| 280 * @return all of the InfoBars held in this container. | 257 * @return all of the InfoBars held in this container. |
| 281 */ | 258 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 296 @Override | 273 @Override |
| 297 protected boolean isAllowedToAutoHide() { | 274 protected boolean isAllowedToAutoHide() { |
| 298 return sIsAllowedToAutoHide; | 275 return sIsAllowedToAutoHide; |
| 299 } | 276 } |
| 300 | 277 |
| 301 private native long nativeInit(); | 278 private native long nativeInit(); |
| 302 private native void nativeSetWebContents( | 279 private native void nativeSetWebContents( |
| 303 long nativeInfoBarContainerAndroid, WebContents webContents); | 280 long nativeInfoBarContainerAndroid, WebContents webContents); |
| 304 private native void nativeDestroy(long nativeInfoBarContainerAndroid); | 281 private native void nativeDestroy(long nativeInfoBarContainerAndroid); |
| 305 } | 282 } |
| OLD | NEW |