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 19 matching lines...) Expand all Loading... | |
30 import org.chromium.chrome.browser.EmptyTabObserver; | 30 import org.chromium.chrome.browser.EmptyTabObserver; |
31 import org.chromium.chrome.browser.FrozenNativePage; | 31 import org.chromium.chrome.browser.FrozenNativePage; |
32 import org.chromium.chrome.browser.IntentHandler.TabOpenType; | 32 import org.chromium.chrome.browser.IntentHandler.TabOpenType; |
33 import org.chromium.chrome.browser.NativePage; | 33 import org.chromium.chrome.browser.NativePage; |
34 import org.chromium.chrome.browser.Tab; | 34 import org.chromium.chrome.browser.Tab; |
35 import org.chromium.chrome.browser.TabObserver; | 35 import org.chromium.chrome.browser.TabObserver; |
36 import org.chromium.chrome.browser.TabState; | 36 import org.chromium.chrome.browser.TabState; |
37 import org.chromium.chrome.browser.TabUma; | 37 import org.chromium.chrome.browser.TabUma; |
38 import org.chromium.chrome.browser.TabUma.TabCreationState; | 38 import org.chromium.chrome.browser.TabUma.TabCreationState; |
39 import org.chromium.chrome.browser.UrlConstants; | 39 import org.chromium.chrome.browser.UrlConstants; |
40 import org.chromium.chrome.browser.UrlUtilities; | |
40 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; | 41 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
41 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; | 42 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; |
42 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; | 43 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
43 import org.chromium.chrome.browser.contextualsearch.ContextualSearchTabHelper; | 44 import org.chromium.chrome.browser.contextualsearch.ContextualSearchTabHelper; |
44 import org.chromium.chrome.browser.crash.MinidumpUploadService; | 45 import org.chromium.chrome.browser.crash.MinidumpUploadService; |
45 import org.chromium.chrome.browser.dom_distiller.ReaderModeActivityDelegate; | 46 import org.chromium.chrome.browser.dom_distiller.ReaderModeActivityDelegate; |
46 import org.chromium.chrome.browser.dom_distiller.ReaderModeManager; | 47 import org.chromium.chrome.browser.dom_distiller.ReaderModeManager; |
47 import org.chromium.chrome.browser.download.ChromeDownloadDelegate; | 48 import org.chromium.chrome.browser.download.ChromeDownloadDelegate; |
48 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; | 49 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; |
49 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; | 50 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; |
50 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 51 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
51 import org.chromium.chrome.browser.fullscreen.FullscreenManager; | 52 import org.chromium.chrome.browser.fullscreen.FullscreenManager; |
52 import org.chromium.chrome.browser.media.MediaNotificationService; | 53 import org.chromium.chrome.browser.media.MediaNotificationService; |
54 import org.chromium.chrome.browser.media.ui.MediaInfo; | |
55 import org.chromium.chrome.browser.media.ui.MediaPlaybackControls; | |
56 import org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls; | |
53 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 57 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
54 import org.chromium.chrome.browser.ntp.NativePageAssassin; | 58 import org.chromium.chrome.browser.ntp.NativePageAssassin; |
55 import org.chromium.chrome.browser.ntp.NativePageFactory; | 59 import org.chromium.chrome.browser.ntp.NativePageFactory; |
56 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 60 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
57 import org.chromium.chrome.browser.policy.PolicyAuditor; | 61 import org.chromium.chrome.browser.policy.PolicyAuditor; |
58 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; | 62 import org.chromium.chrome.browser.policy.PolicyAuditor.AuditEvent; |
59 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 63 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
60 import org.chromium.chrome.browser.rlz.RevenueStats; | 64 import org.chromium.chrome.browser.rlz.RevenueStats; |
61 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 65 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
62 import org.chromium.chrome.browser.tab.BackgroundContentViewHelper.BackgroundCon tentViewDelegate; | 66 import org.chromium.chrome.browser.tab.BackgroundContentViewHelper.BackgroundCon tentViewDelegate; |
(...skipping 16 matching lines...) Expand all Loading... | |
79 import org.chromium.content_public.browser.LoadUrlParams; | 83 import org.chromium.content_public.browser.LoadUrlParams; |
80 import org.chromium.content_public.browser.NavigationController; | 84 import org.chromium.content_public.browser.NavigationController; |
81 import org.chromium.content_public.browser.WebContents; | 85 import org.chromium.content_public.browser.WebContents; |
82 import org.chromium.content_public.browser.WebContentsObserver; | 86 import org.chromium.content_public.browser.WebContentsObserver; |
83 import org.chromium.content_public.common.ConsoleMessageLevel; | 87 import org.chromium.content_public.common.ConsoleMessageLevel; |
84 import org.chromium.content_public.common.Referrer; | 88 import org.chromium.content_public.common.Referrer; |
85 import org.chromium.ui.WindowOpenDisposition; | 89 import org.chromium.ui.WindowOpenDisposition; |
86 import org.chromium.ui.base.PageTransition; | 90 import org.chromium.ui.base.PageTransition; |
87 import org.chromium.ui.base.WindowAndroid; | 91 import org.chromium.ui.base.WindowAndroid; |
88 | 92 |
93 import java.net.URI; | |
94 import java.net.URISyntaxException; | |
89 import java.util.Locale; | 95 import java.util.Locale; |
90 | 96 |
91 /** | 97 /** |
92 * A representation of a Tab for Chrome. This manages wrapping a WebContents and interacting with | 98 * A representation of a Tab for Chrome. This manages wrapping a WebContents and interacting with |
93 * most of Chromium while representing a consistent version of web content to th e front end. | 99 * most of Chromium while representing a consistent version of web content to th e front end. |
94 */ | 100 */ |
95 public class ChromeTab extends Tab { | 101 public class ChromeTab extends Tab { |
96 public static final int NTP_TAB_ID = -2; | 102 public static final int NTP_TAB_ID = -2; |
97 | 103 |
98 private static final String TAG = "ChromeTab"; | 104 private static final String TAG = "cr.ChromeTab"; |
99 | 105 |
100 // URL didFailLoad error code. Should match the value in net_error_list.h. | 106 // URL didFailLoad error code. Should match the value in net_error_list.h. |
101 public static final int BLOCKED_BY_ADMINISTRATOR = -22; | 107 public static final int BLOCKED_BY_ADMINISTRATOR = -22; |
102 | 108 |
103 public static final String PAGESPEED_PASSTHROUGH_HEADER = "Chrome-Proxy: pas s-through"; | 109 public static final String PAGESPEED_PASSTHROUGH_HEADER = "Chrome-Proxy: pas s-through"; |
104 | 110 |
105 private static final int MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD = 1; | 111 private static final int MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD = 1; |
106 | 112 |
107 /** The maximum amount of time to wait for a page to load before entering fu llscreen. -1 means | 113 /** The maximum amount of time to wait for a page to load before entering fu llscreen. -1 means |
108 * wait until the page finishes loading. */ | 114 * wait until the page finishes loading. */ |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 @Override | 359 @Override |
354 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() { | 360 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() { |
355 return new TabChromeWebContentsDelegateAndroidImpl(); | 361 return new TabChromeWebContentsDelegateAndroidImpl(); |
356 } | 362 } |
357 | 363 |
358 /** | 364 /** |
359 * An implementation for this tab's web contents delegate. | 365 * An implementation for this tab's web contents delegate. |
360 */ | 366 */ |
361 public class TabChromeWebContentsDelegateAndroidImpl | 367 public class TabChromeWebContentsDelegateAndroidImpl |
362 extends TabChromeWebContentsDelegateAndroid { | 368 extends TabChromeWebContentsDelegateAndroid { |
369 private MediaPlaybackControls.Listener mControlsListener = | |
370 new MediaPlaybackControls.Listener() { | |
371 @Override | |
372 public void onPlay() { | |
373 TabChromeWebContentsDelegateAndroidImpl | |
374 .nativeOnMediaControlsResume(getWebContents()); | |
375 NotificationMediaPlaybackControls notificationControls = | |
376 NotificationMediaPlaybackControls.getOrCreate(getApplica tionContext()); | |
377 notificationControls.onPlaybackStateChanged( | |
378 MediaInfo.PAUSED, MediaInfo.PLAYING); | |
379 } | |
380 | |
381 @Override | |
382 public void onPause() { | |
383 TabChromeWebContentsDelegateAndroidImpl | |
384 .nativeOnMediaControlsPause(getWebContents()); | |
385 NotificationMediaPlaybackControls notificationControls = | |
386 NotificationMediaPlaybackControls.getOrCreate(getApplica tionContext()); | |
387 notificationControls.onPlaybackStateChanged( | |
388 MediaInfo.PLAYING, MediaInfo.PAUSED); | |
389 } | |
390 }; | |
391 | |
363 /** | 392 /** |
364 * This method is meant to be overridden by DocumentTab because the | 393 * This method is meant to be overridden by DocumentTab because the |
365 * TabModelSelector returned by the activity is not correct. | 394 * TabModelSelector returned by the activity is not correct. |
366 * TODO(dfalcantara): remove this when DocumentActivity.getTabModelSelec tor() | 395 * TODO(dfalcantara): remove this when DocumentActivity.getTabModelSelec tor() |
367 * will return the right TabModelSelector. | 396 * will return the right TabModelSelector. |
368 */ | 397 */ |
369 protected TabModel getTabModel() { | 398 protected TabModel getTabModel() { |
370 return mActivity.getTabModelSelector().getModel(isIncognito()); | 399 return mActivity.getTabModelSelector().getModel(isIncognito()); |
371 } | 400 } |
372 | 401 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 // interfere with other parts of the activity (e.g. the URL bar) . | 514 // interfere with other parts of the activity (e.g. the URL bar) . |
486 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) { | 515 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) { |
487 WebContents wc = getWebContents(); | 516 WebContents wc = getWebContents(); |
488 if (wc != null) wc.stop(); | 517 if (wc != null) wc.stop(); |
489 return; | 518 return; |
490 } | 519 } |
491 } | 520 } |
492 handleMediaKey(event); | 521 handleMediaKey(event); |
493 } | 522 } |
494 | 523 |
524 @Override | |
525 public void showMediaControls(boolean isPaused) { | |
526 NotificationMediaPlaybackControls notificationControls = | |
527 NotificationMediaPlaybackControls.getOrCreate(getApplication Context()); | |
528 notificationControls.addListener(mControlsListener); | |
529 String originForDisplay = getUrl(); | |
mlamouri (slow - plz ping)
2015/06/18 16:43:22
That means that we show the origin of the top fram
mlamouri (slow - plz ping)
2015/06/22 14:34:17
You didn't address that, did you? Maybe we should
whywhat
2015/06/23 19:39:10
It would be confusing for the user to see "youtube
| |
530 try { | |
531 originForDisplay = UrlUtilities.getOriginForDisplay(new URI(getU rl()), true); | |
532 } catch (URISyntaxException e) { | |
533 Log.e(TAG, "Wrong syntax for the tab URL when playing media. Sho wing the URL."); | |
534 } | |
535 notificationControls.show(new MediaInfo( | |
536 getTitle(), | |
537 isPaused ? MediaInfo.PAUSED : MediaInfo.PLAYING, | |
538 originForDisplay, | |
539 getId())); | |
540 } | |
541 | |
542 @Override | |
543 public void hideMediaControls() { | |
544 NotificationMediaPlaybackControls notificationControls = | |
545 NotificationMediaPlaybackControls.getOrCreate(getApplication Context()); | |
546 notificationControls.hide(getId()); | |
547 notificationControls.removeListener(mControlsListener); | |
548 } | |
549 | |
495 /** | 550 /** |
496 * Redispatches unhandled media keys. This allows bluetooth headphones w ith play/pause or | 551 * Redispatches unhandled media keys. This allows bluetooth headphones w ith play/pause or |
497 * other buttons to function correctly. | 552 * other buttons to function correctly. |
498 */ | 553 */ |
499 @TargetApi(19) | 554 @TargetApi(19) |
500 private void handleMediaKey(KeyEvent e) { | 555 private void handleMediaKey(KeyEvent e) { |
501 if (Build.VERSION.SDK_INT < 19) return; | 556 if (Build.VERSION.SDK_INT < 19) return; |
502 switch (e.getKeyCode()) { | 557 switch (e.getKeyCode()) { |
503 case KeyEvent.KEYCODE_MUTE: | 558 case KeyEvent.KEYCODE_MUTE: |
504 case KeyEvent.KEYCODE_HEADSETHOOK: | 559 case KeyEvent.KEYCODE_HEADSETHOOK: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 private boolean isCapturingVideo() { | 591 private boolean isCapturingVideo() { |
537 return !isClosing() && super.nativeIsCapturingVideo(getWebContents() ); | 592 return !isClosing() && super.nativeIsCapturingVideo(getWebContents() ); |
538 } | 593 } |
539 | 594 |
540 /** | 595 /** |
541 * @return Whether audio is being played. | 596 * @return Whether audio is being played. |
542 */ | 597 */ |
543 private boolean hasAudibleAudio() { | 598 private boolean hasAudibleAudio() { |
544 return !isClosing() && super.nativeHasAudibleAudio(getWebContents()) ; | 599 return !isClosing() && super.nativeHasAudibleAudio(getWebContents()) ; |
545 } | 600 } |
546 | |
547 } | 601 } |
548 | 602 |
549 /** | 603 /** |
550 * Check whether the context menu download should be intercepted. | 604 * Check whether the context menu download should be intercepted. |
551 * | 605 * |
552 * @param url URL to be downloaded. | 606 * @param url URL to be downloaded. |
553 * @return whether the download should be intercepted. | 607 * @return whether the download should be intercepted. |
554 */ | 608 */ |
555 protected boolean shouldInterceptContextMenuDownload(String url) { | 609 protected boolean shouldInterceptContextMenuDownload(String url) { |
556 return mDownloadDelegate.shouldInterceptContextMenuDownload(url); | 610 return mDownloadDelegate.shouldInterceptContextMenuDownload(url); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 public void didDetachInterstitialPage() { | 935 public void didDetachInterstitialPage() { |
882 if (!maybeShowNativePage(getUrl(), false)) { | 936 if (!maybeShowNativePage(getUrl(), false)) { |
883 showRenderedPage(); | 937 showRenderedPage(); |
884 } | 938 } |
885 } | 939 } |
886 | 940 |
887 @Override | 941 @Override |
888 public void destroy() { | 942 public void destroy() { |
889 MediaNotificationService.updateMediaNotificationForTab( | 943 MediaNotificationService.updateMediaNotificationForTab( |
890 getApplicationContext(), getId(), false, false, false, g etUrl()); | 944 getApplicationContext(), getId(), false, false, false, g etUrl()); |
945 NotificationMediaPlaybackControls notificationControls = | |
946 NotificationMediaPlaybackControls.getOrCreate(getApplica tionContext()); | |
947 notificationControls.hide(getId()); | |
891 super.destroy(); | 948 super.destroy(); |
892 } | 949 } |
893 }; | 950 }; |
894 } | 951 } |
895 | 952 |
896 @Override | 953 @Override |
897 protected void didStartPageLoad(String validatedUrl, boolean showingErrorPag e) { | 954 protected void didStartPageLoad(String validatedUrl, boolean showingErrorPag e) { |
898 if (mBackgroundContentViewHelper.isPageSwappingInProgress()) { | 955 if (mBackgroundContentViewHelper.isPageSwappingInProgress()) { |
899 mLoadProgressAtViewSwapInTime = 0; | 956 mLoadProgressAtViewSwapInTime = 0; |
900 } | 957 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1403 didFinishPageLoad(); | 1460 didFinishPageLoad(); |
1404 } | 1461 } |
1405 } | 1462 } |
1406 }; | 1463 }; |
1407 | 1464 |
1408 @VisibleForTesting | 1465 @VisibleForTesting |
1409 public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() { | 1466 public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() { |
1410 return mLastOverrideUrlLoadingResult; | 1467 return mLastOverrideUrlLoadingResult; |
1411 } | 1468 } |
1412 } | 1469 } |
OLD | NEW |