| 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.chrome.browser.tab; | 5 package org.chromium.chrome.browser.tab; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.graphics.Color; | |
| 9 import android.os.SystemClock; | 7 import android.os.SystemClock; |
| 10 import android.support.annotation.IntDef; | 8 import android.support.annotation.IntDef; |
| 11 import android.view.View; | 9 import android.view.View; |
| 12 | 10 |
| 13 import org.chromium.base.ActivityState; | 11 import org.chromium.base.ActivityState; |
| 14 import org.chromium.base.ApplicationState; | 12 import org.chromium.base.ApplicationState; |
| 15 import org.chromium.base.ApplicationStatus; | 13 import org.chromium.base.ApplicationStatus; |
| 16 import org.chromium.base.Log; | 14 import org.chromium.base.Log; |
| 17 import org.chromium.base.ObserverList.RewindableIterator; | 15 import org.chromium.base.ObserverList.RewindableIterator; |
| 18 import org.chromium.base.metrics.RecordHistogram; | 16 import org.chromium.base.metrics.RecordHistogram; |
| 19 import org.chromium.chrome.browser.ChromeApplication; | 17 import org.chromium.chrome.browser.ChromeApplication; |
| 20 import org.chromium.chrome.browser.fullscreen.FullscreenManager; | 18 import org.chromium.chrome.browser.fullscreen.FullscreenManager; |
| 21 import org.chromium.chrome.browser.media.MediaCaptureNotificationService; | 19 import org.chromium.chrome.browser.media.MediaCaptureNotificationService; |
| 22 import org.chromium.chrome.browser.metrics.UmaSessionStats; | 20 import org.chromium.chrome.browser.metrics.UmaSessionStats; |
| 23 import org.chromium.chrome.browser.metrics.UmaUtils; | 21 import org.chromium.chrome.browser.metrics.UmaUtils; |
| 24 import org.chromium.chrome.browser.policy.PolicyAuditor; | 22 import org.chromium.chrome.browser.policy.PolicyAuditor; |
| 25 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; | 23 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; |
| 26 import org.chromium.components.security_state.ConnectionSecurityLevel; | |
| 27 import org.chromium.content_public.browser.WebContents; | 24 import org.chromium.content_public.browser.WebContents; |
| 28 import org.chromium.content_public.browser.WebContentsObserver; | 25 import org.chromium.content_public.browser.WebContentsObserver; |
| 29 import org.chromium.ui.base.DeviceFormFactor; | |
| 30 | 26 |
| 31 import java.util.concurrent.TimeUnit; | 27 import java.util.concurrent.TimeUnit; |
| 32 | 28 |
| 33 /** | 29 /** |
| 34 * WebContentsObserver used by Tab. | 30 * WebContentsObserver used by Tab. |
| 35 */ | 31 */ |
| 36 public class TabWebContentsObserver extends WebContentsObserver { | 32 public class TabWebContentsObserver extends WebContentsObserver { |
| 37 // URL didFailLoad error code. Should match the value in net_error_list.h. | 33 // URL didFailLoad error code. Should match the value in net_error_list.h. |
| 38 public static final int BLOCKED_BY_ADMINISTRATOR = -22; | 34 public static final int BLOCKED_BY_ADMINISTRATOR = -22; |
| 39 | 35 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 private @interface TabRendererExitStatus {} | 54 private @interface TabRendererExitStatus {} |
| 59 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_RUNNING_A
PP = 0; | 55 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_RUNNING_A
PP = 0; |
| 60 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_PAUSED_AP
P = 1; | 56 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_PAUSED_AP
P = 1; |
| 61 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_BACKGROUN
D_APP = 2; | 57 private static final int TAB_RENDERER_EXIT_STATUS_OOM_PROTECTED_IN_BACKGROUN
D_APP = 2; |
| 62 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_RUNNING_A
PP = 3; | 58 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_RUNNING_A
PP = 3; |
| 63 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_PAUSED_AP
P = 4; | 59 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_PAUSED_AP
P = 4; |
| 64 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_BACKGROUN
D_APP = 5; | 60 private static final int TAB_RENDERER_EXIT_STATUS_NOT_PROTECTED_IN_BACKGROUN
D_APP = 5; |
| 65 private static final int TAB_RENDERER_EXIT_STATUS_MAX = 6; | 61 private static final int TAB_RENDERER_EXIT_STATUS_MAX = 6; |
| 66 | 62 |
| 67 private final Tab mTab; | 63 private final Tab mTab; |
| 68 private int mThemeColor; | |
| 69 | 64 |
| 70 public TabWebContentsObserver(WebContents webContents, Tab tab) { | 65 public TabWebContentsObserver(WebContents webContents, Tab tab) { |
| 71 super(webContents); | 66 super(webContents); |
| 72 mTab = tab; | 67 mTab = tab; |
| 73 mThemeColor = mTab.getDefaultThemeColor(); | |
| 74 } | 68 } |
| 75 | 69 |
| 76 @Override | 70 @Override |
| 77 public void renderProcessGone(boolean processWasOomProtected) { | 71 public void renderProcessGone(boolean processWasOomProtected) { |
| 78 Log.i(TAG, "renderProcessGone() for tab id: " + mTab.getId() | 72 Log.i(TAG, "renderProcessGone() for tab id: " + mTab.getId() |
| 79 + ", oom protected: " + Boolean.toString(processWasOomProtected) | 73 + ", oom protected: " + Boolean.toString(processWasOomProtected) |
| 80 + ", already needs reload: " + Boolean.toString(mTab.needsReload
())); | 74 + ", already needs reload: " + Boolean.toString(mTab.needsReload
())); |
| 81 // Do nothing for subsequent calls that happen while the tab remains cra
shed. This | 75 // Do nothing for subsequent calls that happen while the tab remains cra
shed. This |
| 82 // can occur when the tab is in the background and it shares the rendere
r with other | 76 // can occur when the tab is in the background and it shares the rendere
r with other |
| 83 // tabs. After the renderer crashes, the WebContents of its tabs are sti
ll around | 77 // tabs. After the renderer crashes, the WebContents of its tabs are sti
ll around |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 @Override | 254 @Override |
| 261 public void didFirstVisuallyNonEmptyPaint() { | 255 public void didFirstVisuallyNonEmptyPaint() { |
| 262 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); | 256 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); |
| 263 while (observers.hasNext()) { | 257 while (observers.hasNext()) { |
| 264 observers.next().didFirstVisuallyNonEmptyPaint(mTab); | 258 observers.next().didFirstVisuallyNonEmptyPaint(mTab); |
| 265 } | 259 } |
| 266 } | 260 } |
| 267 | 261 |
| 268 @Override | 262 @Override |
| 269 public void didChangeThemeColor(int color) { | 263 public void didChangeThemeColor(int color) { |
| 270 int securityLevel = mTab.getSecurityLevel(); | 264 mTab.updateThemeColorIfNeeded(); |
| 271 if (securityLevel == ConnectionSecurityLevel.SECURITY_ERROR | |
| 272 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING | |
| 273 || securityLevel == ConnectionSecurityLevel.SECURITY_POLICY_WARN
ING) { | |
| 274 color = mTab.getDefaultThemeColor(); | |
| 275 } | |
| 276 if (mTab.isShowingInterstitialPage()) color = mTab.getDefaultThemeColor(
); | |
| 277 if (!isThemeColorEnabled(mTab.getApplicationContext())) { | |
| 278 color = mTab.getDefaultThemeColor(); | |
| 279 } | |
| 280 if (color == Color.TRANSPARENT) color = mTab.getDefaultThemeColor(); | |
| 281 if (mTab.isIncognito()) color = mTab.getDefaultThemeColor(); | |
| 282 color |= 0xFF000000; | |
| 283 if (mTab.getThemeColor() == color) return; | |
| 284 mThemeColor = color; | |
| 285 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); | |
| 286 while (observers.hasNext()) { | |
| 287 observers.next().onDidChangeThemeColor(mTab, mTab.getThemeColor()); | |
| 288 } | |
| 289 } | 265 } |
| 290 | 266 |
| 291 @Override | 267 @Override |
| 292 public void didAttachInterstitialPage() { | 268 public void didAttachInterstitialPage() { |
| 293 mTab.getInfoBarContainer().setVisibility(View.INVISIBLE); | 269 mTab.getInfoBarContainer().setVisibility(View.INVISIBLE); |
| 294 mTab.showRenderedPage(); | 270 mTab.showRenderedPage(); |
| 295 didChangeThemeColor(mTab.getDefaultThemeColor()); | 271 mTab.updateThemeColorIfNeeded(); |
| 296 | 272 |
| 297 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); | 273 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); |
| 298 while (observers.hasNext()) { | 274 while (observers.hasNext()) { |
| 299 observers.next().onDidAttachInterstitialPage(mTab); | 275 observers.next().onDidAttachInterstitialPage(mTab); |
| 300 } | 276 } |
| 301 mTab.notifyLoadProgress(mTab.getProgress()); | 277 mTab.notifyLoadProgress(mTab.getProgress()); |
| 302 | 278 |
| 303 mTab.updateFullscreenEnabledState(); | 279 mTab.updateFullscreenEnabledState(); |
| 304 | 280 |
| 305 PolicyAuditor auditor = | 281 PolicyAuditor auditor = |
| 306 ((ChromeApplication) mTab.getApplicationContext()).getPolicyAudi
tor(); | 282 ((ChromeApplication) mTab.getApplicationContext()).getPolicyAudi
tor(); |
| 307 auditor.notifyCertificateFailure( | 283 auditor.notifyCertificateFailure( |
| 308 PolicyAuditor.nativeGetCertificateFailure(mTab.getWebContents())
, | 284 PolicyAuditor.nativeGetCertificateFailure(mTab.getWebContents())
, |
| 309 mTab.getApplicationContext()); | 285 mTab.getApplicationContext()); |
| 310 } | 286 } |
| 311 | 287 |
| 312 @Override | 288 @Override |
| 313 public void didDetachInterstitialPage() { | 289 public void didDetachInterstitialPage() { |
| 314 mTab.getInfoBarContainer().setVisibility(View.VISIBLE); | 290 mTab.getInfoBarContainer().setVisibility(View.VISIBLE); |
| 315 didChangeThemeColor(mTab.getWebContents().getThemeColor(mTab.getDefaultT
hemeColor())); | 291 mTab.updateThemeColorIfNeeded(); |
| 316 | 292 |
| 317 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); | 293 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); |
| 318 while (observers.hasNext()) { | 294 while (observers.hasNext()) { |
| 319 observers.next().onDidDetachInterstitialPage(mTab); | 295 observers.next().onDidDetachInterstitialPage(mTab); |
| 320 } | 296 } |
| 321 mTab.notifyLoadProgress(mTab.getProgress()); | 297 mTab.notifyLoadProgress(mTab.getProgress()); |
| 322 | 298 |
| 323 mTab.updateFullscreenEnabledState(); | 299 mTab.updateFullscreenEnabledState(); |
| 324 | 300 |
| 325 if (!mTab.maybeShowNativePage(mTab.getUrl(), false)) { | 301 if (!mTab.maybeShowNativePage(mTab.getUrl(), false)) { |
| 326 mTab.showRenderedPage(); | 302 mTab.showRenderedPage(); |
| 327 } | 303 } |
| 328 } | 304 } |
| 329 | 305 |
| 330 @Override | 306 @Override |
| 331 public void didStartNavigationToPendingEntry(String url) { | 307 public void didStartNavigationToPendingEntry(String url) { |
| 332 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); | 308 RewindableIterator<TabObserver> observers = mTab.getTabObservers(); |
| 333 while (observers.hasNext()) { | 309 while (observers.hasNext()) { |
| 334 observers.next().onDidStartNavigationToPendingEntry(mTab, url); | 310 observers.next().onDidStartNavigationToPendingEntry(mTab, url); |
| 335 } | 311 } |
| 336 } | 312 } |
| 337 | 313 |
| 338 @Override | 314 @Override |
| 339 public void destroy() { | 315 public void destroy() { |
| 340 MediaCaptureNotificationService.updateMediaNotificationForTab( | 316 MediaCaptureNotificationService.updateMediaNotificationForTab( |
| 341 mTab.getApplicationContext(), mTab.getId(), false, false, mTab.g
etUrl()); | 317 mTab.getApplicationContext(), mTab.getId(), false, false, mTab.g
etUrl()); |
| 342 super.destroy(); | 318 super.destroy(); |
| 343 } | 319 } |
| 344 | |
| 345 /** | |
| 346 * @return The theme-color for this web contents. | |
| 347 */ | |
| 348 int getThemeColor() { | |
| 349 return mThemeColor; | |
| 350 } | |
| 351 | |
| 352 private static boolean isThemeColorEnabled(Context context) { | |
| 353 return !DeviceFormFactor.isTablet(context); | |
| 354 } | |
| 355 } | 320 } |
| OLD | NEW |