Chromium Code Reviews| 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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 import org.chromium.chrome.browser.EmptyTabObserver; | 28 import org.chromium.chrome.browser.EmptyTabObserver; |
| 29 import org.chromium.chrome.browser.FrozenNativePage; | 29 import org.chromium.chrome.browser.FrozenNativePage; |
| 30 import org.chromium.chrome.browser.IntentHandler.TabOpenType; | 30 import org.chromium.chrome.browser.IntentHandler.TabOpenType; |
| 31 import org.chromium.chrome.browser.NativePage; | 31 import org.chromium.chrome.browser.NativePage; |
| 32 import org.chromium.chrome.browser.Tab; | 32 import org.chromium.chrome.browser.Tab; |
| 33 import org.chromium.chrome.browser.TabObserver; | 33 import org.chromium.chrome.browser.TabObserver; |
| 34 import org.chromium.chrome.browser.TabState; | 34 import org.chromium.chrome.browser.TabState; |
| 35 import org.chromium.chrome.browser.TabUma; | 35 import org.chromium.chrome.browser.TabUma; |
| 36 import org.chromium.chrome.browser.TabUma.TabCreationState; | 36 import org.chromium.chrome.browser.TabUma.TabCreationState; |
| 37 import org.chromium.chrome.browser.UrlConstants; | 37 import org.chromium.chrome.browser.UrlConstants; |
| 38 import org.chromium.chrome.browser.UrlUtilities; | |
| 38 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; | 39 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
| 39 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; | 40 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; |
| 40 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; | 41 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
| 41 import org.chromium.chrome.browser.contextualsearch.ContextualSearchTabHelper; | 42 import org.chromium.chrome.browser.contextualsearch.ContextualSearchTabHelper; |
| 42 import org.chromium.chrome.browser.crash.MinidumpUploadService; | 43 import org.chromium.chrome.browser.crash.MinidumpUploadService; |
| 43 import org.chromium.chrome.browser.dom_distiller.ReaderModeActivityDelegate; | 44 import org.chromium.chrome.browser.dom_distiller.ReaderModeActivityDelegate; |
| 44 import org.chromium.chrome.browser.dom_distiller.ReaderModeManager; | 45 import org.chromium.chrome.browser.dom_distiller.ReaderModeManager; |
| 45 import org.chromium.chrome.browser.download.ChromeDownloadDelegate; | 46 import org.chromium.chrome.browser.download.ChromeDownloadDelegate; |
| 46 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 47 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
| 47 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; | 48 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; |
| 48 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 49 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| 49 import org.chromium.chrome.browser.fullscreen.FullscreenManager; | 50 import org.chromium.chrome.browser.fullscreen.FullscreenManager; |
| 50 import org.chromium.chrome.browser.media.MediaNotificationService; | 51 import org.chromium.chrome.browser.media.MediaNotificationService; |
| 52 import org.chromium.chrome.browser.media.ui.MediaInfo; | |
| 53 import org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls; | |
| 51 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 54 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
| 52 import org.chromium.chrome.browser.ntp.NativePageAssassin; | 55 import org.chromium.chrome.browser.ntp.NativePageAssassin; |
| 53 import org.chromium.chrome.browser.ntp.NativePageFactory; | 56 import org.chromium.chrome.browser.ntp.NativePageFactory; |
| 54 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 57 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
| 55 import org.chromium.chrome.browser.policy.PolicyAuditor; | 58 import org.chromium.chrome.browser.policy.PolicyAuditor; |
| 56 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; | 59 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; |
| 57 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 60 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 58 import org.chromium.chrome.browser.rlz.RevenueStats; | 61 import org.chromium.chrome.browser.rlz.RevenueStats; |
| 59 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 62 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 60 import org.chromium.chrome.browser.tab.BackgroundContentViewHelper.BackgroundCon tentViewDelegate; | 63 import org.chromium.chrome.browser.tab.BackgroundContentViewHelper.BackgroundCon tentViewDelegate; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 77 import org.chromium.content_public.browser.LoadUrlParams; | 80 import org.chromium.content_public.browser.LoadUrlParams; |
| 78 import org.chromium.content_public.browser.NavigationController; | 81 import org.chromium.content_public.browser.NavigationController; |
| 79 import org.chromium.content_public.browser.WebContents; | 82 import org.chromium.content_public.browser.WebContents; |
| 80 import org.chromium.content_public.browser.WebContentsObserver; | 83 import org.chromium.content_public.browser.WebContentsObserver; |
| 81 import org.chromium.content_public.common.ConsoleMessageLevel; | 84 import org.chromium.content_public.common.ConsoleMessageLevel; |
| 82 import org.chromium.content_public.common.Referrer; | 85 import org.chromium.content_public.common.Referrer; |
| 83 import org.chromium.ui.WindowOpenDisposition; | 86 import org.chromium.ui.WindowOpenDisposition; |
| 84 import org.chromium.ui.base.PageTransition; | 87 import org.chromium.ui.base.PageTransition; |
| 85 import org.chromium.ui.base.WindowAndroid; | 88 import org.chromium.ui.base.WindowAndroid; |
| 86 | 89 |
| 90 import java.net.URI; | |
| 91 import java.net.URISyntaxException; | |
| 87 import java.util.Locale; | 92 import java.util.Locale; |
| 88 | 93 |
| 89 /** | 94 /** |
| 90 * A representation of a Tab for Chrome. This manages wrapping a WebContents and interacting with | 95 * A representation of a Tab for Chrome. This manages wrapping a WebContents and interacting with |
| 91 * most of Chromium while representing a consistent version of web content to th e front end. | 96 * most of Chromium while representing a consistent version of web content to th e front end. |
| 92 */ | 97 */ |
| 93 public class ChromeTab extends Tab { | 98 public class ChromeTab extends Tab { |
|
Ted C
2015/06/26 00:43:55
ChromeTab is going away, you should probably just
whywhat
2015/06/26 19:29:32
Ack.
| |
| 94 public static final int NTP_TAB_ID = -2; | 99 public static final int NTP_TAB_ID = -2; |
| 95 | 100 |
| 96 private static final String TAG = "ChromeTab"; | 101 private static final String TAG = "cr.ChromeTab"; |
| 97 | 102 |
| 98 // URL didFailLoad error code. Should match the value in net_error_list.h. | 103 // URL didFailLoad error code. Should match the value in net_error_list.h. |
| 99 public static final int BLOCKED_BY_ADMINISTRATOR = -22; | 104 public static final int BLOCKED_BY_ADMINISTRATOR = -22; |
| 100 | 105 |
| 101 public static final String PAGESPEED_PASSTHROUGH_HEADER = "Chrome-Proxy: pas s-through"; | 106 public static final String PAGESPEED_PASSTHROUGH_HEADER = "Chrome-Proxy: pas s-through"; |
| 102 | 107 |
| 103 private static final int MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD = 1; | 108 private static final int MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD = 1; |
| 104 | 109 |
| 105 /** The maximum amount of time to wait for a page to load before entering fu llscreen. -1 means | 110 /** The maximum amount of time to wait for a page to load before entering fu llscreen. -1 means |
| 106 * wait until the page finishes loading. */ | 111 * wait until the page finishes loading. */ |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 @Override | 356 @Override |
| 352 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() { | 357 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() { |
| 353 return new TabChromeWebContentsDelegateAndroidImpl(); | 358 return new TabChromeWebContentsDelegateAndroidImpl(); |
| 354 } | 359 } |
| 355 | 360 |
| 356 /** | 361 /** |
| 357 * An implementation for this tab's web contents delegate. | 362 * An implementation for this tab's web contents delegate. |
| 358 */ | 363 */ |
| 359 public class TabChromeWebContentsDelegateAndroidImpl | 364 public class TabChromeWebContentsDelegateAndroidImpl |
| 360 extends TabChromeWebContentsDelegateAndroid { | 365 extends TabChromeWebContentsDelegateAndroid { |
| 366 private NotificationMediaPlaybackControls.Listener mControlsListener = | |
|
Ted C
2015/06/26 00:43:55
I'd rather not see this logic within tab. I think
whywhat
2015/06/26 19:29:32
Ack. I'll need a tab id though to be able to come
Ted C
2015/06/30 04:56:13
Per my follow up comment, there is no reason you c
| |
| 367 new NotificationMediaPlaybackControls.Listener() { | |
| 368 @Override | |
| 369 public void onPlay() { | |
| 370 TabChromeWebContentsDelegateAndroidImpl | |
| 371 .nativeOnMediaControlsResume(getWebContents()); | |
| 372 } | |
| 373 | |
| 374 @Override | |
| 375 public void onPause() { | |
| 376 TabChromeWebContentsDelegateAndroidImpl | |
| 377 .nativeOnMediaControlsPause(getWebContents()); | |
| 378 } | |
| 379 }; | |
| 380 | |
| 361 /** | 381 /** |
| 362 * This method is meant to be overridden by DocumentTab because the | 382 * This method is meant to be overridden by DocumentTab because the |
| 363 * TabModelSelector returned by the activity is not correct. | 383 * TabModelSelector returned by the activity is not correct. |
| 364 * TODO(dfalcantara): remove this when DocumentActivity.getTabModelSelec tor() | 384 * TODO(dfalcantara): remove this when DocumentActivity.getTabModelSelec tor() |
| 365 * will return the right TabModelSelector. | 385 * will return the right TabModelSelector. |
| 366 */ | 386 */ |
| 367 protected TabModel getTabModel() { | 387 protected TabModel getTabModel() { |
| 368 return mActivity.getTabModelSelector().getModel(isIncognito()); | 388 return mActivity.getTabModelSelector().getModel(isIncognito()); |
| 369 } | 389 } |
| 370 | 390 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 // interfere with other parts of the activity (e.g. the URL bar) . | 503 // interfere with other parts of the activity (e.g. the URL bar) . |
| 484 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) { | 504 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) { |
| 485 WebContents wc = getWebContents(); | 505 WebContents wc = getWebContents(); |
| 486 if (wc != null) wc.stop(); | 506 if (wc != null) wc.stop(); |
| 487 return; | 507 return; |
| 488 } | 508 } |
| 489 } | 509 } |
| 490 handleMediaKey(event); | 510 handleMediaKey(event); |
| 491 } | 511 } |
| 492 | 512 |
| 513 @Override | |
| 514 public void updateMediaControls(boolean isControllable, boolean isPaused ) { | |
| 515 NotificationMediaPlaybackControls notificationControls = | |
| 516 NotificationMediaPlaybackControls.getOrCreate(getApplication Context()); | |
| 517 if (!isControllable) { | |
| 518 notificationControls.hide(getId()); | |
| 519 notificationControls.removeListener(mControlsListener); | |
| 520 return; | |
| 521 } | |
| 522 notificationControls.addListener(mControlsListener); | |
| 523 String origin = getUrl(); | |
| 524 try { | |
| 525 origin = UrlUtilities.getOriginForDisplay(new URI(getUrl()), tru e); | |
| 526 } catch (URISyntaxException e) { | |
| 527 Log.e(TAG, "Wrong syntax for the tab URL when playing media. Sho wing the URL."); | |
| 528 } | |
| 529 notificationControls.show(new MediaInfo(getTitle(), isPaused, origin , getId())); | |
| 530 } | |
| 531 | |
| 493 /** | 532 /** |
| 494 * Redispatches unhandled media keys. This allows bluetooth headphones w ith play/pause or | 533 * Redispatches unhandled media keys. This allows bluetooth headphones w ith play/pause or |
| 495 * other buttons to function correctly. | 534 * other buttons to function correctly. |
| 496 */ | 535 */ |
| 497 @TargetApi(19) | 536 @TargetApi(19) |
| 498 private void handleMediaKey(KeyEvent e) { | 537 private void handleMediaKey(KeyEvent e) { |
| 499 if (Build.VERSION.SDK_INT < 19) return; | 538 if (Build.VERSION.SDK_INT < 19) return; |
| 500 switch (e.getKeyCode()) { | 539 switch (e.getKeyCode()) { |
| 501 case KeyEvent.KEYCODE_MUTE: | 540 case KeyEvent.KEYCODE_MUTE: |
| 502 case KeyEvent.KEYCODE_HEADSETHOOK: | 541 case KeyEvent.KEYCODE_HEADSETHOOK: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 private boolean isCapturingVideo() { | 573 private boolean isCapturingVideo() { |
| 535 return !isClosing() && super.nativeIsCapturingVideo(getWebContents() ); | 574 return !isClosing() && super.nativeIsCapturingVideo(getWebContents() ); |
| 536 } | 575 } |
| 537 | 576 |
| 538 /** | 577 /** |
| 539 * @return Whether audio is being played. | 578 * @return Whether audio is being played. |
| 540 */ | 579 */ |
| 541 private boolean hasAudibleAudio() { | 580 private boolean hasAudibleAudio() { |
| 542 return !isClosing() && super.nativeHasAudibleAudio(getWebContents()) ; | 581 return !isClosing() && super.nativeHasAudibleAudio(getWebContents()) ; |
| 543 } | 582 } |
| 544 | |
| 545 } | 583 } |
| 546 | 584 |
| 547 /** | 585 /** |
| 548 * Check whether the context menu download should be intercepted. | 586 * Check whether the context menu download should be intercepted. |
| 549 * | 587 * |
| 550 * @param url URL to be downloaded. | 588 * @param url URL to be downloaded. |
| 551 * @return whether the download should be intercepted. | 589 * @return whether the download should be intercepted. |
| 552 */ | 590 */ |
| 553 protected boolean shouldInterceptContextMenuDownload(String url) { | 591 protected boolean shouldInterceptContextMenuDownload(String url) { |
| 554 return mDownloadDelegate.shouldInterceptContextMenuDownload(url); | 592 return mDownloadDelegate.shouldInterceptContextMenuDownload(url); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 public void didDetachInterstitialPage() { | 917 public void didDetachInterstitialPage() { |
| 880 if (!maybeShowNativePage(getUrl(), false)) { | 918 if (!maybeShowNativePage(getUrl(), false)) { |
| 881 showRenderedPage(); | 919 showRenderedPage(); |
| 882 } | 920 } |
| 883 } | 921 } |
| 884 | 922 |
| 885 @Override | 923 @Override |
| 886 public void destroy() { | 924 public void destroy() { |
| 887 MediaNotificationService.updateMediaNotificationForTab( | 925 MediaNotificationService.updateMediaNotificationForTab( |
| 888 getApplicationContext(), getId(), false, false, false, g etUrl()); | 926 getApplicationContext(), getId(), false, false, false, g etUrl()); |
| 927 NotificationMediaPlaybackControls notificationControls = | |
| 928 NotificationMediaPlaybackControls.getOrCreate(getApplica tionContext()); | |
| 929 notificationControls.hide(getId()); | |
|
Ted C
2015/06/26 00:43:55
should this be removing the listener as well?
Sho
whywhat
2015/06/26 19:29:32
I've put the listener to MediaInfo so now there's
| |
| 889 super.destroy(); | 930 super.destroy(); |
| 890 } | 931 } |
| 891 }; | 932 }; |
| 892 } | 933 } |
| 893 | 934 |
| 894 @Override | 935 @Override |
| 895 protected void didStartPageLoad(String validatedUrl, boolean showingErrorPag e) { | 936 protected void didStartPageLoad(String validatedUrl, boolean showingErrorPag e) { |
| 896 if (mBackgroundContentViewHelper.isPageSwappingInProgress()) { | 937 if (mBackgroundContentViewHelper.isPageSwappingInProgress()) { |
| 897 mLoadProgressAtViewSwapInTime = 0; | 938 mLoadProgressAtViewSwapInTime = 0; |
| 898 } | 939 } |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1400 didFinishPageLoad(); | 1441 didFinishPageLoad(); |
| 1401 } | 1442 } |
| 1402 } | 1443 } |
| 1403 }; | 1444 }; |
| 1404 | 1445 |
| 1405 @VisibleForTesting | 1446 @VisibleForTesting |
| 1406 public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() { | 1447 public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() { |
| 1407 return mLastOverrideUrlLoadingResult; | 1448 return mLastOverrideUrlLoadingResult; |
| 1408 } | 1449 } |
| 1409 } | 1450 } |
| OLD | NEW |