Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java

Issue 1464743005: Remove DocumentTabObserver and merge task description updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.document; 5 package org.chromium.chrome.browser.document;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.os.Build; 10 import android.os.Build;
(...skipping 11 matching lines...) Expand all
22 import org.chromium.base.library_loader.LibraryLoader; 22 import org.chromium.base.library_loader.LibraryLoader;
23 import org.chromium.base.metrics.RecordUserAction; 23 import org.chromium.base.metrics.RecordUserAction;
24 import org.chromium.chrome.R; 24 import org.chromium.chrome.R;
25 import org.chromium.chrome.browser.ChromeActivity; 25 import org.chromium.chrome.browser.ChromeActivity;
26 import org.chromium.chrome.browser.ChromeApplication; 26 import org.chromium.chrome.browser.ChromeApplication;
27 import org.chromium.chrome.browser.IntentHandler; 27 import org.chromium.chrome.browser.IntentHandler;
28 import org.chromium.chrome.browser.KeyboardShortcuts; 28 import org.chromium.chrome.browser.KeyboardShortcuts;
29 import org.chromium.chrome.browser.TabState; 29 import org.chromium.chrome.browser.TabState;
30 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason; 30 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason;
31 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; 31 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument;
32 import org.chromium.chrome.browser.document.DocumentTab.DocumentTabObserver;
33 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; 32 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils;
34 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; 33 import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
35 import org.chromium.chrome.browser.firstrun.FirstRunStatus; 34 import org.chromium.chrome.browser.firstrun.FirstRunStatus;
36 import org.chromium.chrome.browser.metrics.StartupMetrics; 35 import org.chromium.chrome.browser.metrics.StartupMetrics;
37 import org.chromium.chrome.browser.metrics.UmaUtils; 36 import org.chromium.chrome.browser.metrics.UmaUtils;
38 import org.chromium.chrome.browser.ntp.NewTabPage; 37 import org.chromium.chrome.browser.ntp.NewTabPage;
39 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 38 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
40 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 39 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
41 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPrefer ences; 40 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPrefer ences;
42 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoS creen; 41 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoS creen;
43 import org.chromium.chrome.browser.signin.SigninPromoScreen; 42 import org.chromium.chrome.browser.signin.SigninPromoScreen;
44 import org.chromium.chrome.browser.ssl.ConnectionSecurityLevel; 43 import org.chromium.chrome.browser.ssl.ConnectionSecurityLevel;
44 import org.chromium.chrome.browser.tab.EmptyTabObserver;
45 import org.chromium.chrome.browser.tab.Tab; 45 import org.chromium.chrome.browser.tab.Tab;
46 import org.chromium.chrome.browser.tab.TabUma.TabCreationState; 46 import org.chromium.chrome.browser.tab.TabUma.TabCreationState;
47 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; 47 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector;
48 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; 48 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
49 import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; 49 import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate;
50 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; 50 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
51 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParamsManag er; 51 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParamsManag er;
52 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel; 52 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel;
53 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Initializa tionObserver; 53 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Initializa tionObserver;
54 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl; 54 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl;
(...skipping 25 matching lines...) Expand all
80 "com.google.android.apps.chrome.document.IncognitoDocumentActivity"; 80 "com.google.android.apps.chrome.document.IncognitoDocumentActivity";
81 81
82 protected static final String KEY_INITIAL_URL = "DocumentActivity.KEY_INITIA L_URL"; 82 protected static final String KEY_INITIAL_URL = "DocumentActivity.KEY_INITIA L_URL";
83 83
84 private static final String TAG = "DocumentActivity"; 84 private static final String TAG = "DocumentActivity";
85 85
86 // Animation exit duration defined in chrome/android/java/res/anim/menu_exit .xml as 150ms, 86 // Animation exit duration defined in chrome/android/java/res/anim/menu_exit .xml as 150ms,
87 // plus add another 20ms for a re-layout. 87 // plus add another 20ms for a re-layout.
88 private static final int MENU_EXIT_ANIMATION_WAIT_MS = 170; 88 private static final int MENU_EXIT_ANIMATION_WAIT_MS = 170;
89 89
90 private class DocumentTabObserver extends EmptyTabObserver {
91 @Override
92 public void onPageLoadStarted(Tab tab, String url) {
93 // Discard startup navigation measurements when the user interfered and started the
94 // 2nd navigation (in activity lifetime) in parallel.
95 if (!sIsFirstPageLoadStart) {
96 UmaUtils.setRunningApplicationStart(false);
97 } else {
98 sIsFirstPageLoadStart = false;
99 }
100 }
101
102 @Override
103 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) {
104 if (!didStartLoad) return;
105 resetIcon();
106 }
107
108 @Override
109 public void onFaviconUpdated(Tab tab, Bitmap icon) {
110 if (mLargestFavicon == null || icon.getWidth() > mLargestFavicon.get Width()
111 || icon.getHeight() > mLargestFavicon.getHeight()) {
112 mLargestFavicon = icon;
113 updateTaskDescription();
114 }
115 }
116
117 @Override
118 public void onUrlUpdated(Tab tab) {
119 assert mDocumentTab == tab;
120
121 updateTaskDescription();
122 mTabModel.updateEntry(getIntent(), mDocumentTab);
123 }
124
125 @Override
126 public void onTitleUpdated(Tab tab) {
127 super.onTitleUpdated(tab);
128 updateTaskDescription();
129 }
130
131 @Override
132 public void onSSLStateUpdated(Tab tab) {
133 if (hasSecurityWarningOrError(tab)) resetIcon();
134 }
135
136 @Override
137 public void onDidNavigateMainFrame(Tab tab, String url, String baseUrl,
138 boolean isNavigationToDifferentPage, boolean isFragmentNavigatio n,
139 int statusCode) {
140 if (!isNavigationToDifferentPage) return;
141 mLargestFavicon = null;
142 }
143
144 @Override
145 public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
146 assert mDocumentTab == tab;
147
148 updateTaskDescription();
149 mTabModel.updateEntry(getIntent(), mDocumentTab);
150 }
151
152 @Override
153 public void onDidChangeThemeColor(Tab tab, int color) {
154 updateTaskDescription();
155 }
156
157 @Override
158 public void onDidAttachInterstitialPage(Tab tab) {
159 resetIcon();
160 }
161
162 @Override
163 public void onDidDetachInterstitialPage(Tab tab) {
164 resetIcon();
165 }
166
167 @Override
168 public void onCrash(Tab tab, boolean sadTabShown) {
169 int currentState = ApplicationStatus.getStateForActivity(DocumentAct ivity.this);
170 if (currentState != ActivityState.STOPPED) return;
171
172 if (!isTaskRoot() || IntentUtils.safeGetBooleanExtra(getIntent(),
173 IntentHandler.EXTRA_APPEND_TASK, false)) {
174 return;
175 }
176
177 // Finishing backgrounded Activities whose renderers have crashed al lows us to
178 // destroy them and return resources sooner than if we wait for Andr oid to destroy
179 // the Activities themselves. Problematically, this also removes
180 // IncognitoDocumentActivity instances from Android's Recents menu a nd auto-closes
181 // the tab. Instead, take a hit and keep the Activities alive -- An droid will
182 // eventually destroy the Activities, anyway (crbug.com/450292).
183 if (!isIncognito()) finish();
184 }
185
186 private boolean hasSecurityWarningOrError(Tab tab) {
187 int securityLevel = tab.getSecurityLevel();
188 return securityLevel == ConnectionSecurityLevel.SECURITY_ERROR
189 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING
190 || securityLevel == ConnectionSecurityLevel.SECURITY_POLICY_ WARNING;
191 }
192 }
90 private DocumentTabModel mTabModel; 193 private DocumentTabModel mTabModel;
91 private InitializationObserver mTabInitializationObserver; 194 private InitializationObserver mTabInitializationObserver;
92 195
93 /** 196 /**
94 * Generates the icon to use in the recent task list. 197 * Generates the icon to use in the recent task list.
95 */ 198 */
96 private DocumentActivityIcon mIcon; 199 private DocumentActivityIcon mIcon;
97 200
98 /** 201 /**
99 * The tab's largest favicon. 202 * The tab's largest favicon.
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 627
525 if (getContextualSearchManager() != null) { 628 if (getContextualSearchManager() != null) {
526 getContextualSearchManager().setFindToolbarManager(mFindToolbarManag er); 629 getContextualSearchManager().setFindToolbarManager(mFindToolbarManag er);
527 } 630 }
528 631
529 getToolbarManager().initializeWithNative(getTabModelSelector(), getFulls creenManager(), 632 getToolbarManager().initializeWithNative(getTabModelSelector(), getFulls creenManager(),
530 mFindToolbarManager, null, layoutDriver, null, null, null, null) ; 633 mFindToolbarManager, null, layoutDriver, null, null, null, null) ;
531 634
532 mDocumentTab.setFullscreenManager(getFullscreenManager()); 635 mDocumentTab.setFullscreenManager(getFullscreenManager());
533 636
534 mDocumentTab.addObserver(new DocumentTabObserver() { 637 mDocumentTab.addObserver(new DocumentTabObserver());
535 @Override
536 public void onPageLoadStarted(Tab tab, String url) {
537 // Discard startup navigation measurements when the user interfe red and started the
538 // 2nd navigation (in activity lifetime) in parallel.
539 if (!sIsFirstPageLoadStart) {
540 UmaUtils.setRunningApplicationStart(false);
541 } else {
542 sIsFirstPageLoadStart = false;
543 }
544 }
545
546 @Override
547 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, bool ean didFinishLoad) {
548 if (!didStartLoad) return;
549 resetIcon();
550 }
551
552 @Override
553 protected void onFaviconReceived(Bitmap image) {
554 super.onFaviconReceived(image);
555 if (mLargestFavicon == null || image.getWidth() > mLargestFavico n.getWidth()
556 || image.getHeight() > mLargestFavicon.getHeight()) {
557 mLargestFavicon = image;
558 updateTaskDescription();
559 }
560 }
561
562 @Override
563 public void onUrlUpdated(Tab tab) {
564 assert mDocumentTab == tab;
565
566 updateTaskDescription();
567 mTabModel.updateEntry(getIntent(), mDocumentTab);
568 }
569
570 @Override
571 public void onTitleUpdated(Tab tab) {
572 super.onTitleUpdated(tab);
573 updateTaskDescription();
574 }
575
576 @Override
577 public void onSSLStateUpdated(Tab tab) {
578 if (hasSecurityWarningOrError(tab)) resetIcon();
579 }
580
581 @Override
582 public void onDidNavigateMainFrame(Tab tab, String url, String baseU rl,
583 boolean isNavigationToDifferentPage, boolean isFragmentNavig ation,
584 int statusCode) {
585 if (!isNavigationToDifferentPage) return;
586 mLargestFavicon = null;
587 }
588
589 @Override
590 public void onLoadStopped(Tab tab, boolean toDifferentDocument) {
591 assert mDocumentTab == tab;
592
593 updateTaskDescription();
594 mTabModel.updateEntry(getIntent(), mDocumentTab);
595 }
596
597 @Override
598 public void onDidChangeThemeColor(Tab tab, int color) {
599 updateTaskDescription();
600 }
601
602 @Override
603 public void onDidAttachInterstitialPage(Tab tab) {
604 resetIcon();
605 }
606
607 @Override
608 public void onDidDetachInterstitialPage(Tab tab) {
609 resetIcon();
610 }
611
612 @Override
613 public void onCrash(Tab tab, boolean sadTabShown) {
614 int currentState = ApplicationStatus.getStateForActivity(Documen tActivity.this);
615 if (currentState != ActivityState.STOPPED) return;
616
617 if (!isTaskRoot() || IntentUtils.safeGetBooleanExtra(getIntent() ,
618 IntentHandler.EXTRA_APPEND_TASK, false)) {
619 return;
620 }
621
622 // Finishing backgrounded Activities whose renderers have crashe d allows us to
623 // destroy them and return resources sooner than if we wait for Android to destroy
624 // the Activities themselves. Problematically, this also remove s
625 // IncognitoDocumentActivity instances from Android's Recents me nu and auto-closes
626 // the tab. Instead, take a hit and keep the Activities alive - - Android will
627 // eventually destroy the Activities, anyway (crbug.com/450292).
628 if (!isIncognito()) finish();
629 }
630
631 private boolean hasSecurityWarningOrError(Tab tab) {
632 int securityLevel = tab.getSecurityLevel();
633 return securityLevel == ConnectionSecurityLevel.SECURITY_ERROR
634 || securityLevel == ConnectionSecurityLevel.SECURITY_WAR NING
635 || securityLevel == ConnectionSecurityLevel.SECURITY_POL ICY_WARNING;
636 }
637 });
638 638
639 removeWindowBackground(); 639 removeWindowBackground();
640 640
641 if (mDocumentTab != null) { 641 if (mDocumentTab != null) {
642 DataReductionPreferences.launchDataReductionSSLInfoBar( 642 DataReductionPreferences.launchDataReductionSSLInfoBar(
643 DocumentActivity.this, mDocumentTab.getWebContents()); 643 DocumentActivity.this, mDocumentTab.getWebContents());
644 } 644 }
645 } 645 }
646 646
647 private void resetIcon() { 647 private void resetIcon() {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 847
848 /** 848 /**
849 * Launch a new DocumentActivity showing the new tab page. 849 * Launch a new DocumentActivity showing the new tab page.
850 * @param incognito Whether the new NTP should be in incognito mode. 850 * @param incognito Whether the new NTP should be in incognito mode.
851 */ 851 */
852 private void launchNtp(boolean incognito) { 852 private void launchNtp(boolean incognito) {
853 if (incognito && !PrefServiceBridge.getInstance().isIncognitoModeEnabled ()) return; 853 if (incognito && !PrefServiceBridge.getInstance().isIncognitoModeEnabled ()) return;
854 getTabCreator(incognito).launchNTP(); 854 getTabCreator(incognito).launchNTP();
855 } 855 }
856 } 856 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698