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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java

Issue 1371553002: Remove mActivity from Tab and look at windowAndroid for tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.app.Activity; 8 import android.app.Activity;
9 import android.app.ActivityManager; 9 import android.app.ActivityManager;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.content.res.Resources; 12 import android.content.res.Resources;
13 import android.graphics.Bitmap; 13 import android.graphics.Bitmap;
14 import android.graphics.Color; 14 import android.graphics.Color;
15 import android.graphics.Rect; 15 import android.graphics.Rect;
16 import android.media.AudioManager; 16 import android.media.AudioManager;
17 import android.os.Build; 17 import android.os.Build;
18 import android.os.Handler; 18 import android.os.Handler;
19 import android.os.Message; 19 import android.os.Message;
20 import android.provider.Browser; 20 import android.provider.Browser;
21 import android.text.TextUtils; 21 import android.text.TextUtils;
22 import android.util.Log; 22 import android.util.Log;
23 import android.util.Pair; 23 import android.util.Pair;
24 import android.view.ContextMenu; 24 import android.view.ContextMenu;
25 import android.view.ContextThemeWrapper;
25 import android.view.KeyEvent; 26 import android.view.KeyEvent;
26 import android.view.View; 27 import android.view.View;
27 import android.view.View.OnClickListener; 28 import android.view.View.OnClickListener;
28 import android.view.ViewGroup; 29 import android.view.ViewGroup;
29 import android.view.ViewGroup.LayoutParams; 30 import android.view.ViewGroup.LayoutParams;
30 import android.widget.FrameLayout; 31 import android.widget.FrameLayout;
31 32
32 import org.chromium.base.ActivityState; 33 import org.chromium.base.ActivityState;
33 import org.chromium.base.ApiCompatibilityUtils; 34 import org.chromium.base.ApiCompatibilityUtils;
34 import org.chromium.base.ApplicationState; 35 import org.chromium.base.ApplicationState;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 157
157 /** 158 /**
158 * The required page load percentage for the page to be considered ready ass uming the 159 * The required page load percentage for the page to be considered ready ass uming the
159 * TextureView is also ready. 160 * TextureView is also ready.
160 */ 161 */
161 private static final int CONSIDERED_READY_LOAD_PERCENTAGE = 100; 162 private static final int CONSIDERED_READY_LOAD_PERCENTAGE = 100;
162 163
163 /** Used for logging. */ 164 /** Used for logging. */
164 private static final String TAG = "Tab"; 165 private static final String TAG = "Tab";
165 166
166 /**
167 * The {@link Activity} used to create {@link View}s and other Android compo nents. Unlike
168 * {@link #mApplicationContext}, this is not publicly exposed to help preven t leaking the
169 * {@link Activity}.
170 */
171 protected final ChromeActivity mActivity;
172
173 private long mNativeTabAndroid; 167 private long mNativeTabAndroid;
174 168
175 /** Unique id of this tab (within its container). */ 169 /** Unique id of this tab (within its container). */
176 private final int mId; 170 private final int mId;
177 171
178 /** Whether or not this tab is an incognito tab. */ 172 /** Whether or not this tab is an incognito tab. */
179 private final boolean mIncognito; 173 private final boolean mIncognito;
180 174
181 /** 175 /**
182 * An Application {@link Context}. Unlike {@link #mActivity}, this is the o nly one that is 176 * An Application {@link Context}. Unlike {@link #mActivity}, this is the o nly one that is
183 * publicly exposed to help prevent leaking the {@link Activity}. 177 * publicly exposed to help prevent leaking the {@link Activity}.
184 */ 178 */
185 private final Context mApplicationContext; 179 private final Context mApplicationContext;
186 180
181 private final ContextThemeWrapper mThemedContext;
182
187 /** Gives {@link Tab} a way to interact with the Android window. */ 183 /** Gives {@link Tab} a way to interact with the Android window. */
188 private final WindowAndroid mWindowAndroid; 184 private final WindowAndroid mWindowAndroid;
189 185
190 /** Whether or not this {@link Tab} is initialized and should be interacted with. */ 186 /** Whether or not this {@link Tab} is initialized and should be interacted with. */
191 private boolean mIsInitialized; 187 private boolean mIsInitialized;
192 188
193 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */ 189 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */
194 private NativePage mNativePage; 190 private NativePage mNativePage;
195 191
196 /** InfoBar container to show InfoBars for this tab. */ 192 /** InfoBar container to show InfoBars for this tab. */
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 */ 377 */
382 protected boolean mLastPageLoadHasSpdyProxyPassthroughHeaders; 378 protected boolean mLastPageLoadHasSpdyProxyPassthroughHeaders;
383 379
384 private ChromeDownloadDelegate mDownloadDelegate; 380 private ChromeDownloadDelegate mDownloadDelegate;
385 381
386 protected Handler mHandler; 382 protected Handler mHandler;
387 383
388 private final Runnable mCloseContentsRunnable = new Runnable() { 384 private final Runnable mCloseContentsRunnable = new Runnable() {
389 @Override 385 @Override
390 public void run() { 386 public void run() {
391 boolean isSelected = mActivity.getTabModelSelector().getCurrentTab() == Tab.this; 387 TabModelSelector selector = getTabModelSelector();
392 mActivity.getTabModelSelector().closeTab(Tab.this); 388 if (selector == null) return;
389 boolean isSelected = selector.getCurrentTab() == Tab.this;
390 selector.closeTab(Tab.this);
393 391
394 // If the parent Tab belongs to another Activity, fire the Intent to bring it back. 392 // If the parent Tab belongs to another Activity, fire the Intent to bring it back.
395 if (isSelected && getParentIntent() != null 393 if (isSelected && getParentIntent() != null
396 && mActivity.getIntent() != getParentIntent()) { 394 && getActivity().getIntent() != getParentIntent()) {
397 boolean mayLaunch = FeatureUtilities.isDocumentMode(mActivity) 395 boolean mayLaunch = FeatureUtilities.isDocumentMode(mApplication Context)
398 ? isParentInAndroidOverview() : true; 396 ? isParentInAndroidOverview() : true;
399 if (mayLaunch) mActivity.startActivity(getParentIntent()); 397 if (mayLaunch) getActivity().startActivity(getParentIntent());
400 } 398 }
401 } 399 }
402 400
403 /** If the API allows it, returns whether a Task still exists for the pa rent Activity. */ 401 /** If the API allows it, returns whether a Task still exists for the pa rent Activity. */
404 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 402 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
405 private boolean isParentInAndroidOverview() { 403 private boolean isParentInAndroidOverview() {
406 ActivityManager activityManager = 404 ActivityManager activityManager = (ActivityManager) mApplicationCont ext.
407 (ActivityManager) mActivity.getSystemService(Context.ACTIVIT Y_SERVICE); 405 getSystemService(Context.ACTIVITY_SERVICE);
408 for (ActivityManager.AppTask task : activityManager.getAppTasks()) { 406 for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
409 Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task); 407 Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
410 if (taskIntent != null && taskIntent.filterEquals(getParentInten t())) return true; 408 if (taskIntent != null && taskIntent.filterEquals(getParentInten t())) return true;
411 } 409 }
412 return false; 410 return false;
413 } 411 }
414 }; 412 };
415 413
416 /** 414 /**
417 * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu 415 * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 mClipboard.setText(text, text); 458 mClipboard.setText(text, text);
461 } 459 }
462 460
463 @Override 461 @Override
464 public void onSaveImageToClipboard(String url) { 462 public void onSaveImageToClipboard(String url) {
465 mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url); 463 mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url);
466 } 464 }
467 465
468 @Override 466 @Override
469 public void onOpenInNewTab(String url, Referrer referrer) { 467 public void onOpenInNewTab(String url, Referrer referrer) {
468 if (getTabModelSelector() == null) return;
470 RecordUserAction.record("MobileNewTabOpened"); 469 RecordUserAction.record("MobileNewTabOpened");
471 LoadUrlParams loadUrlParams = new LoadUrlParams(url); 470 LoadUrlParams loadUrlParams = new LoadUrlParams(url);
472 loadUrlParams.setReferrer(referrer); 471 loadUrlParams.setReferrer(referrer);
473 mActivity.getTabModelSelector().openNewTab(loadUrlParams, 472 getTabModelSelector().openNewTab(loadUrlParams,
474 TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.this, isIncogni to()); 473 TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.this, isIncogni to());
475 } 474 }
476 475
477 @Override 476 @Override
478 public void onReloadIgnoringCache() { 477 public void onReloadIgnoringCache() {
479 reloadIgnoringCache(); 478 reloadIgnoringCache();
480 } 479 }
481 480
482 @Override 481 @Override
483 public void onLoadOriginalImage() { 482 public void onLoadOriginalImage() {
484 if (mNativeTabAndroid != 0) nativeLoadOriginalImage(mNativeTabAndroi d); 483 if (mNativeTabAndroid != 0) nativeLoadOriginalImage(mNativeTabAndroi d);
485 } 484 }
486 485
487 @Override 486 @Override
488 public void onOpenInNewIncognitoTab(String url) { 487 public void onOpenInNewIncognitoTab(String url) {
488 if (getTabModelSelector() == null) return;
489 RecordUserAction.record("MobileNewTabOpened"); 489 RecordUserAction.record("MobileNewTabOpened");
490 mActivity.getTabModelSelector().openNewTab(new LoadUrlParams(url), 490 getTabModelSelector().openNewTab(new LoadUrlParams(url),
491 TabLaunchType.FROM_LONGPRESS_FOREGROUND, Tab.this, true); 491 TabLaunchType.FROM_LONGPRESS_FOREGROUND, Tab.this, true);
492 } 492 }
493 493
494 @Override 494 @Override
495 public String getPageUrl() { 495 public String getPageUrl() {
496 return getUrl(); 496 return getUrl();
497 } 497 }
498 498
499 @Override 499 @Override
500 public void onOpenImageUrl(String url, Referrer referrer) { 500 public void onOpenImageUrl(String url, Referrer referrer) {
501 LoadUrlParams loadUrlParams = new LoadUrlParams(url); 501 LoadUrlParams loadUrlParams = new LoadUrlParams(url);
502 loadUrlParams.setTransitionType(PageTransition.LINK); 502 loadUrlParams.setTransitionType(PageTransition.LINK);
503 loadUrlParams.setReferrer(referrer); 503 loadUrlParams.setReferrer(referrer);
504 loadUrl(loadUrlParams); 504 loadUrl(loadUrlParams);
505 } 505 }
506 506
507 @Override 507 @Override
508 public void onOpenImageInNewTab(String url, Referrer referrer) { 508 public void onOpenImageInNewTab(String url, Referrer referrer) {
509 if (getTabModelSelector() == null) return;
509 boolean useOriginal = isSpdyProxyEnabledForUrl(url); 510 boolean useOriginal = isSpdyProxyEnabledForUrl(url);
510 LoadUrlParams loadUrlParams = new LoadUrlParams(url); 511 LoadUrlParams loadUrlParams = new LoadUrlParams(url);
511 loadUrlParams.setVerbatimHeaders(useOriginal ? PAGESPEED_PASSTHROUGH _HEADERS : null); 512 loadUrlParams.setVerbatimHeaders(useOriginal ? PAGESPEED_PASSTHROUGH _HEADERS : null);
512 loadUrlParams.setReferrer(referrer); 513 loadUrlParams.setReferrer(referrer);
513 mActivity.getTabModelSelector().openNewTab(loadUrlParams, 514 getTabModelSelector().openNewTab(loadUrlParams,
514 TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.this, isIncogni to()); 515 TabLaunchType.FROM_LONGPRESS_BACKGROUND, Tab.this, isIncogni to());
515 } 516 }
516 517
517 @Override 518 @Override
518 public void onSearchByImageInNewTab() { 519 public void onSearchByImageInNewTab() {
519 triggerSearchByImage(); 520 triggerSearchByImage();
520 } 521 }
521 } 522 }
522 523
523 /** 524 /**
(...skipping 21 matching lines...) Expand all
545 @Override 546 @Override
546 public void onUpdateUrl(String url) { 547 public void onUpdateUrl(String url) {
547 for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.thi s, url); 548 for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.thi s, url);
548 } 549 }
549 550
550 @Override 551 @Override
551 public void showRepostFormWarningDialog() { 552 public void showRepostFormWarningDialog() {
552 // When the dialog is visible, keeping the refresh animation active 553 // When the dialog is visible, keeping the refresh animation active
553 // in the background is distracting and unnecessary (and likely to 554 // in the background is distracting and unnecessary (and likely to
554 // jank when the dialog is shown). 555 // jank when the dialog is shown).
555 if (mSwipeRefreshHandler != null) { 556 if (mSwipeRefreshHandler != null) mSwipeRefreshHandler.reset();
556 mSwipeRefreshHandler.reset(); 557 if (getActivity() == null) return;
557 }
558 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog( 558 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog(
559 new Runnable() { 559 new Runnable() {
560 @Override 560 @Override
561 public void run() { 561 public void run() {
562 getWebContents().getNavigationController().cancelPen dingReload(); 562 getWebContents().getNavigationController().cancelPen dingReload();
563 } 563 }
564 }, new Runnable() { 564 }, new Runnable() {
565 @Override 565 @Override
566 public void run() { 566 public void run() {
567 getWebContents().getNavigationController().continueP endingReload(); 567 getWebContents().getNavigationController().continueP endingReload();
568 } 568 }
569 }); 569 });
570 warningDialog.show(mActivity.getFragmentManager(), null); 570 warningDialog.show(getActivity().getFragmentManager(), null);
571 } 571 }
572 572
573 @Override 573 @Override
574 public void toggleFullscreenModeForTab(boolean enableFullscreen) { 574 public void toggleFullscreenModeForTab(boolean enableFullscreen) {
575 if (mFullscreenManager != null) { 575 if (mFullscreenManager != null) {
576 mFullscreenManager.setPersistentFullscreenMode(enableFullscreen) ; 576 mFullscreenManager.setPersistentFullscreenMode(enableFullscreen) ;
577 } 577 }
578 578
579 for (TabObserver observer : mObservers) { 579 for (TabObserver observer : mObservers) {
580 observer.onToggleFullscreenMode(Tab.this, enableFullscreen); 580 observer.onToggleFullscreenMode(Tab.this, enableFullscreen);
(...skipping 21 matching lines...) Expand all
602 for (TabObserver observer : mObservers) observer.onSSLStateUpdated(T ab.this); 602 for (TabObserver observer : mObservers) observer.onSSLStateUpdated(T ab.this);
603 } 603 }
604 604
605 @Override 605 @Override
606 public void webContentsCreated(WebContents sourceWebContents, long opene rRenderFrameId, 606 public void webContentsCreated(WebContents sourceWebContents, long opene rRenderFrameId,
607 String frameName, String targetUrl, WebContents newWebContents) { 607 String frameName, String targetUrl, WebContents newWebContents) {
608 for (TabObserver observer : mObservers) { 608 for (TabObserver observer : mObservers) {
609 observer.webContentsCreated(Tab.this, sourceWebContents, openerR enderFrameId, 609 observer.webContentsCreated(Tab.this, sourceWebContents, openerR enderFrameId,
610 frameName, targetUrl, newWebContents); 610 frameName, targetUrl, newWebContents);
611 } 611 }
612 if (getActivity() == null) return;
612 // The URL can't be taken from the WebContents if it's paused. Save it for later. 613 // The URL can't be taken from the WebContents if it's paused. Save it for later.
613 assert mWebContentsUrlMapping == null; 614 assert mWebContentsUrlMapping == null;
614 mWebContentsUrlMapping = Pair.create(newWebContents, targetUrl); 615 mWebContentsUrlMapping = Pair.create(newWebContents, targetUrl);
615 616
616 // TODO(dfalcantara): Re-remove this once crbug.com/508366 is fixed. 617 // TODO(dfalcantara): Re-remove this once crbug.com/508366 is fixed.
617 TabCreator tabCreator = mActivity.getTabCreator(isIncognito()); 618 TabCreator tabCreator = getActivity().getTabCreator(isIncognito());
618 619
619 if (tabCreator != null && tabCreator.createsTabsAsynchronously()) { 620 if (tabCreator != null && tabCreator.createsTabsAsynchronously()) {
620 DocumentWebContentsDelegate.getInstance().attachDelegate(newWebC ontents); 621 DocumentWebContentsDelegate.getInstance().attachDelegate(newWebC ontents);
621 } 622 }
622 } 623 }
623 624
624 @Override 625 @Override
625 public void rendererUnresponsive() { 626 public void rendererUnresponsive() {
626 super.rendererUnresponsive(); 627 super.rendererUnresponsive();
627 if (mNativeTabAndroid != 0) nativeOnRendererUnresponsive(mNativeTabA ndroid); 628 if (mNativeTabAndroid != 0) nativeOnRendererUnresponsive(mNativeTabA ndroid);
(...skipping 21 matching lines...) Expand all
649 @Override 650 @Override
650 public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition, 651 public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition,
651 boolean isRendererInitiated) { 652 boolean isRendererInitiated) {
652 Tab.this.openNewTab( 653 Tab.this.openNewTab(
653 url, extraHeaders, postData, disposition, true, isRendererIn itiated); 654 url, extraHeaders, postData, disposition, true, isRendererIn itiated);
654 } 655 }
655 656
656 private Pair<WebContents, String> mWebContentsUrlMapping; 657 private Pair<WebContents, String> mWebContentsUrlMapping;
657 658
658 protected TabModel getTabModel() { 659 protected TabModel getTabModel() {
660 if (getTabModelSelector() == null) return null;
659 // TODO(dfalcantara): Remove this when DocumentActivity.getTabModelS elector() 661 // TODO(dfalcantara): Remove this when DocumentActivity.getTabModelS elector()
660 // can return a TabModelSelector that activateCon tents() can use. 662 // can return a TabModelSelector that activateCon tents() can use.
661 return mActivity.getTabModelSelector().getModel(isIncognito()); 663 return getTabModelSelector().getModel(isIncognito());
662 } 664 }
663 665
664 @Override 666 @Override
665 public boolean shouldResumeRequestsForCreatedWindow() { 667 public boolean shouldResumeRequestsForCreatedWindow() {
668 if (getActivity() == null) return false;
666 // Pause the WebContents if an Activity has to be created for it fir st. 669 // Pause the WebContents if an Activity has to be created for it fir st.
667 TabCreator tabCreator = mActivity.getTabCreator(isIncognito()); 670 TabCreator tabCreator = getActivity().getTabCreator(isIncognito());
668 assert tabCreator != null; 671 assert tabCreator != null;
669 return !tabCreator.createsTabsAsynchronously(); 672 return !tabCreator.createsTabsAsynchronously();
670 } 673 }
671 674
672 @Override 675 @Override
673 public boolean addNewContents(WebContents sourceWebContents, WebContents webContents, 676 public boolean addNewContents(WebContents sourceWebContents, WebContents webContents,
674 int disposition, Rect initialPosition, boolean userGesture) { 677 int disposition, Rect initialPosition, boolean userGesture) {
675 assert mWebContentsUrlMapping.first == webContents; 678 assert mWebContentsUrlMapping.first == webContents;
676 679 if (getActivity() == null) return false;
677 TabCreator tabCreator = mActivity.getTabCreator(isIncognito()); 680 TabCreator tabCreator = getActivity().getTabCreator(isIncognito());
678 assert tabCreator != null; 681 assert tabCreator != null;
679 682
680 // Grab the URL, which might not be available via the Tab. 683 // Grab the URL, which might not be available via the Tab.
681 String url = mWebContentsUrlMapping.second; 684 String url = mWebContentsUrlMapping.second;
682 mWebContentsUrlMapping = null; 685 mWebContentsUrlMapping = null;
683 686
684 // Skip opening a new Tab if it doesn't make sense. 687 // Skip opening a new Tab if it doesn't make sense.
685 if (isClosing()) return false; 688 if (isClosing()) return false;
686 689
687 // Creating new Tabs asynchronously requires starting a new Activity to create the Tab, 690 // Creating new Tabs asynchronously requires starting a new Activity to create the Tab,
688 // so the Tab returned will always be null. There's no way to know synchronously 691 // so the Tab returned will always be null. There's no way to know synchronously
689 // whether the Tab is created, so assume it's always successful. 692 // whether the Tab is created, so assume it's always successful.
690 boolean createdSuccessfully = tabCreator.createTabWithWebContents( 693 boolean createdSuccessfully = tabCreator.createTabWithWebContents(
691 webContents, getId(), TabLaunchType.FROM_LONGPRESS_FOREGROUN D, url); 694 webContents, getId(), TabLaunchType.FROM_LONGPRESS_FOREGROUN D, url);
692 boolean success = tabCreator.createsTabsAsynchronously() || createdS uccessfully; 695 boolean success = tabCreator.createsTabsAsynchronously() || createdS uccessfully;
693 if (success && disposition == WindowOpenDisposition.NEW_POPUP) { 696 if (success && disposition == WindowOpenDisposition.NEW_POPUP) {
694 PolicyAuditor auditor = 697 PolicyAuditor auditor =
695 ((ChromeApplication) getApplicationContext()).getPolicyA uditor(); 698 ((ChromeApplication) getApplicationContext()).getPolicyA uditor();
696 auditor.notifyAuditEvent(getApplicationContext(), AuditEvent.OPE N_POPUP_URL_SUCCESS, 699 auditor.notifyAuditEvent(getApplicationContext(), AuditEvent.OPE N_POPUP_URL_SUCCESS,
697 url, ""); 700 url, "");
698 } 701 }
699 702
700 return success; 703 return success;
701 } 704 }
702 705
703 @Override 706 @Override
704 public void activateContents() { 707 public void activateContents() {
705 boolean activityIsDestroyed = false; 708 boolean activityIsDestroyed = false;
706 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 709 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
707 activityIsDestroyed = mActivity.isDestroyed(); 710 && getActivity() != null) {
711 activityIsDestroyed = getActivity().isDestroyed();
708 } 712 }
709 if (activityIsDestroyed || !isInitialized()) { 713 if (activityIsDestroyed || !isInitialized()) {
710 Log.e(TAG, "Activity destroyed before calling activateContents() . Bailing out."); 714 Log.e(TAG, "Activity destroyed before calling activateContents() . Bailing out.");
711 return; 715 return;
712 } 716 }
713 717
714 TabModel model = getTabModel(); 718 TabModel model = getTabModel();
715 int index = model.indexOf(Tab.this); 719 int index = model.indexOf(Tab.this);
716 if (index == TabModel.INVALID_TAB_INDEX) return; 720 if (index == TabModel.INVALID_TAB_INDEX) return;
717 TabModelUtils.setIndex(model, index); 721 TabModelUtils.setIndex(model, index);
(...skipping 23 matching lines...) Expand all
741 @Override 745 @Override
742 public void closeContents() { 746 public void closeContents() {
743 // Execute outside of callback, otherwise we end up deleting the nat ive 747 // Execute outside of callback, otherwise we end up deleting the nat ive
744 // objects in the middle of executing methods on them. 748 // objects in the middle of executing methods on them.
745 mHandler.removeCallbacks(mCloseContentsRunnable); 749 mHandler.removeCallbacks(mCloseContentsRunnable);
746 mHandler.post(mCloseContentsRunnable); 750 mHandler.post(mCloseContentsRunnable);
747 } 751 }
748 752
749 @Override 753 @Override
750 public boolean takeFocus(boolean reverse) { 754 public boolean takeFocus(boolean reverse) {
755 if (getActivity() == null) return false;
756 Activity activity = getActivity();
751 if (reverse) { 757 if (reverse) {
752 View menuButton = mActivity.findViewById(R.id.menu_button); 758 View menuButton = activity.findViewById(R.id.menu_button);
753 if (menuButton == null || !menuButton.isShown()) { 759 if (menuButton == null || !menuButton.isShown()) {
754 menuButton = mActivity.findViewById(R.id.document_menu_butto n); 760 menuButton = activity.findViewById(R.id.document_menu_button );
755 } 761 }
756 if (menuButton != null && menuButton.isShown()) { 762 if (menuButton != null && menuButton.isShown()) {
757 return menuButton.requestFocus(); 763 return menuButton.requestFocus();
758 } 764 }
759 765
760 View tabSwitcherButton = mActivity.findViewById(R.id.tab_switche r_button); 766 View tabSwitcherButton = activity.findViewById(R.id.tab_switcher _button);
761 if (tabSwitcherButton != null && tabSwitcherButton.isShown()) { 767 if (tabSwitcherButton != null && tabSwitcherButton.isShown()) {
762 return tabSwitcherButton.requestFocus(); 768 return tabSwitcherButton.requestFocus();
763 } 769 }
764 } else { 770 } else {
765 View urlBar = mActivity.findViewById(R.id.url_bar); 771 View urlBar = activity.findViewById(R.id.url_bar);
766 if (urlBar != null) return urlBar.requestFocus(); 772 if (urlBar != null) return urlBar.requestFocus();
767 } 773 }
768 return false; 774 return false;
769 } 775 }
770 776
771 @Override 777 @Override
772 public void handleKeyboardEvent(KeyEvent event) { 778 public void handleKeyboardEvent(KeyEvent event) {
779 if (getActivity() == null) return;
773 if (event.getAction() == KeyEvent.ACTION_DOWN) { 780 if (event.getAction() == KeyEvent.ACTION_DOWN) {
774 if (mActivity.onKeyDown(event.getKeyCode(), event)) return; 781 if (getActivity().onKeyDown(event.getKeyCode(), event)) return;
775 782
776 // Handle the Escape key here (instead of in KeyboardShortcuts.j ava), so it doesn't 783 // Handle the Escape key here (instead of in KeyboardShortcuts.j ava), so it doesn't
777 // interfere with other parts of the activity (e.g. the URL bar) . 784 // interfere with other parts of the activity (e.g. the URL bar) .
778 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) { 785 if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNo Modifiers()) {
779 WebContents wc = getWebContents(); 786 WebContents wc = getWebContents();
780 if (wc != null) wc.stop(); 787 if (wc != null) wc.stop();
781 return; 788 return;
782 } 789 }
783 } 790 }
784 handleMediaKey(event); 791 handleMediaKey(event);
(...skipping 14 matching lines...) Expand all
799 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: 806 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
800 case KeyEvent.KEYCODE_MEDIA_STOP: 807 case KeyEvent.KEYCODE_MEDIA_STOP:
801 case KeyEvent.KEYCODE_MEDIA_NEXT: 808 case KeyEvent.KEYCODE_MEDIA_NEXT:
802 case KeyEvent.KEYCODE_MEDIA_PREVIOUS: 809 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
803 case KeyEvent.KEYCODE_MEDIA_REWIND: 810 case KeyEvent.KEYCODE_MEDIA_REWIND:
804 case KeyEvent.KEYCODE_MEDIA_RECORD: 811 case KeyEvent.KEYCODE_MEDIA_RECORD:
805 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: 812 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
806 case KeyEvent.KEYCODE_MEDIA_CLOSE: 813 case KeyEvent.KEYCODE_MEDIA_CLOSE:
807 case KeyEvent.KEYCODE_MEDIA_EJECT: 814 case KeyEvent.KEYCODE_MEDIA_EJECT:
808 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: 815 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
809 AudioManager am = (AudioManager) mActivity.getSystemService( 816 AudioManager am = (AudioManager) mApplicationContext.getSyst emService(
810 Context.AUDIO_SERVICE); 817 Context.AUDIO_SERVICE);
811 am.dispatchMediaKeyEvent(e); 818 am.dispatchMediaKeyEvent(e);
812 break; 819 break;
813 default: 820 default:
814 break; 821 break;
815 } 822 }
816 } 823 }
817 824
818 /** 825 /**
819 * @return Whether audio is being captured. 826 * @return Whether audio is being captured.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 updateFullscreenEnabledState(); 885 updateFullscreenEnabledState();
879 } 886 }
880 887
881 @Override 888 @Override
882 public boolean doesPerformWebSearch() { 889 public boolean doesPerformWebSearch() {
883 return true; 890 return true;
884 } 891 }
885 892
886 @Override 893 @Override
887 public void performWebSearch(String searchQuery) { 894 public void performWebSearch(String searchQuery) {
888 if (TextUtils.isEmpty(searchQuery)) return; 895 if (TextUtils.isEmpty(searchQuery) || getTabModelSelector() == null) return;
889 String url = TemplateUrlService.getInstance().getUrlForSearchQuery(s earchQuery); 896 String url = TemplateUrlService.getInstance().getUrlForSearchQuery(s earchQuery);
890 String headers = GeolocationHeader.getGeoHeader(getApplicationContex t(), url, 897 String headers = GeolocationHeader.getGeoHeader(getApplicationContex t(), url,
891 isIncognito()); 898 isIncognito());
892 899
893 LoadUrlParams loadUrlParams = new LoadUrlParams(url); 900 LoadUrlParams loadUrlParams = new LoadUrlParams(url);
894 loadUrlParams.setVerbatimHeaders(headers); 901 loadUrlParams.setVerbatimHeaders(headers);
895 loadUrlParams.setTransitionType(PageTransition.GENERATED); 902 loadUrlParams.setTransitionType(PageTransition.GENERATED);
896 mActivity.getTabModelSelector().openNewTab(loadUrlParams, 903 getTabModelSelector().openNewTab(loadUrlParams,
897 TabLaunchType.FROM_LONGPRESS_FOREGROUND, Tab.this, isIncogni to()); 904 TabLaunchType.FROM_LONGPRESS_FOREGROUND, Tab.this, isIncogni to());
898 } 905 }
899 906
900 @Override 907 @Override
901 public ContentVideoViewClient getContentVideoViewClient() { 908 public ContentVideoViewClient getContentVideoViewClient() {
902 return new ActivityContentVideoViewClient(mActivity) { 909 assert getActivity() != null;
910 return new ActivityContentVideoViewClient(getActivity()) {
903 @Override 911 @Override
904 public void enterFullscreenVideo(View view) { 912 public void enterFullscreenVideo(View view) {
905 super.enterFullscreenVideo(view); 913 super.enterFullscreenVideo(view);
906 FullscreenManager fullscreenManager = getFullscreenManager() ; 914 FullscreenManager fullscreenManager = getFullscreenManager() ;
907 if (fullscreenManager != null) { 915 if (fullscreenManager != null) {
908 fullscreenManager.setOverlayVideoMode(true); 916 fullscreenManager.setOverlayVideoMode(true);
909 // Disable double tap for video. 917 // Disable double tap for video.
910 if (getContentViewCore() != null) { 918 if (getContentViewCore() != null) {
911 getContentViewCore().updateDoubleTapSupport(false); 919 getContentViewCore().updateDoubleTapSupport(false);
912 } 920 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 1155
1148 /** 1156 /**
1149 * Creates an instance of a {@link Tab}. 1157 * Creates an instance of a {@link Tab}.
1150 * @param id The id this tab should be identified with. 1158 * @param id The id this tab should be identified with.
1151 * @param parentId The id id of the tab that caused this tab to be opened . 1159 * @param parentId The id id of the tab that caused this tab to be opened .
1152 * @param incognito Whether or not this tab is incognito. 1160 * @param incognito Whether or not this tab is incognito.
1153 * @param activity An instance of a {@link Context}. 1161 * @param activity An instance of a {@link Context}.
1154 * @param window An instance of a {@link WindowAndroid}. 1162 * @param window An instance of a {@link WindowAndroid}.
1155 * @param frozenState State containing information about this Tab, if it was persisted. 1163 * @param frozenState State containing information about this Tab, if it was persisted.
1156 */ 1164 */
1157 public Tab(int id, int parentId, boolean incognito, ChromeActivity activity, 1165 public Tab(int id, int parentId, boolean incognito, Context context,
1158 WindowAndroid window, TabLaunchType type, TabState frozenState) { 1166 WindowAndroid window, TabLaunchType type, TabState frozenState) {
1159 mId = TabIdManager.getInstance().generateValidId(id); 1167 mId = TabIdManager.getInstance().generateValidId(id);
1160 mParentId = parentId; 1168 mParentId = parentId;
1161 mIncognito = incognito; 1169 mIncognito = incognito;
1162 mActivity = activity; 1170 mApplicationContext = context != null ? context.getApplicationContext() : null;
1163 mApplicationContext = activity != null ? activity.getApplicationContext( ) : null; 1171 mThemedContext = new ContextThemeWrapper(mApplicationContext, R.style.Ma inTheme);
1164 mWindowAndroid = window; 1172 mWindowAndroid = window;
1165 mLaunchType = type; 1173 mLaunchType = type;
1166 if (mActivity != null) { 1174 if (mApplicationContext != null) {
1167 Resources resources = mActivity.getResources(); 1175 Resources resources = mApplicationContext.getResources();
1168 mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_ favicon_size); 1176 mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_ favicon_size);
1169 mDefaultThemeColor = mIncognito 1177 mDefaultThemeColor = mIncognito
1170 ? ApiCompatibilityUtils.getColor(resources, R.color.incognit o_primary_color) 1178 ? ApiCompatibilityUtils.getColor(resources, R.color.incognit o_primary_color)
1171 : ApiCompatibilityUtils.getColor(resources, R.color.default_ primary_color); 1179 : ApiCompatibilityUtils.getColor(resources, R.color.default_ primary_color);
1172 mThemeColor = mDefaultThemeColor; 1180 mThemeColor = mDefaultThemeColor;
1173 } else { 1181 } else {
1174 mIdealFaviconSize = 16; 1182 mIdealFaviconSize = 16;
1175 mDefaultThemeColor = 0; 1183 mDefaultThemeColor = 0;
1176 } 1184 }
1177 1185
(...skipping 11 matching lines...) Expand all
1189 @Override 1197 @Override
1190 public void handleMessage(Message msg) { 1198 public void handleMessage(Message msg) {
1191 if (msg == null) return; 1199 if (msg == null) return;
1192 if (msg.what == MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD) { 1200 if (msg.what == MSG_ID_ENABLE_FULLSCREEN_AFTER_LOAD) {
1193 enableFullscreenAfterLoad(); 1201 enableFullscreenAfterLoad();
1194 } 1202 }
1195 } 1203 }
1196 }; 1204 };
1197 } 1205 }
1198 1206
1207 protected ChromeActivity getActivity() {
1208 if (getWindowAndroid() == null) return null;
1209 Activity activity = getWindowAndroid().getActivity().get();
1210 if (!(activity instanceof ChromeActivity)) return null;
1211 return (ChromeActivity) activity;
1212 }
1213
1214 protected TabModelSelector getTabModelSelector() {
1215 if (getActivity() == null) return null;
1216 return getActivity().getTabModelSelector();
1217 }
1218
1199 /** 1219 /**
1200 * TODO(aurimas): remove this method once Tab and ChromeTab are merged. 1220 * TODO(aurimas): remove this method once Tab and ChromeTab are merged.
1201 */ 1221 */
1202 protected void enableFullscreenAfterLoad() {} 1222 protected void enableFullscreenAfterLoad() {}
1203 1223
1204 /** 1224 /**
1205 * Sets the mTabUma object for stats reporting. 1225 * Sets the mTabUma object for stats reporting.
1206 * @param tabUma TabUma object to use to report UMA stats. 1226 * @param tabUma TabUma object to use to report UMA stats.
1207 */ 1227 */
1208 protected void setTabUma(TabUma tabUma) { 1228 protected void setTabUma(TabUma tabUma) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 assert mNativeTabAndroid != 0; 1464 assert mNativeTabAndroid != 0;
1445 return nativePrint(mNativeTabAndroid); 1465 return nativePrint(mNativeTabAndroid);
1446 } 1466 }
1447 1467
1448 @CalledByNative 1468 @CalledByNative
1449 public void setPendingPrint() { 1469 public void setPendingPrint() {
1450 PrintingController printingController = PrintingControllerImpl.getInstan ce(); 1470 PrintingController printingController = PrintingControllerImpl.getInstan ce();
1451 if (printingController == null) return; 1471 if (printingController == null) return;
1452 1472
1453 printingController.setPendingPrint(new TabPrinter(this), 1473 printingController.setPendingPrint(new TabPrinter(this),
1454 new PrintManagerDelegateImpl(mActivity)); 1474 new PrintManagerDelegateImpl(mApplicationContext));
1455 } 1475 }
1456 1476
1457 /** 1477 /**
1458 * Reloads the current page content. 1478 * Reloads the current page content.
1459 */ 1479 */
1460 public void reload() { 1480 public void reload() {
1461 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz en? 1481 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz en?
1462 if (getWebContents() != null) getWebContents().getNavigationController() .reload(true); 1482 if (getWebContents() != null) getWebContents().getNavigationController() .reload(true);
1463 } 1483 }
1464 1484
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 if (AppBannerManager.isEnabled()) { 1870 if (AppBannerManager.isEnabled()) {
1851 mAppBannerManager = createAppBannerManager(); 1871 mAppBannerManager = createAppBannerManager();
1852 if (mAppBannerManager != null) addObserver(mAppBannerManager); 1872 if (mAppBannerManager != null) addObserver(mAppBannerManager);
1853 } 1873 }
1854 } 1874 }
1855 1875
1856 /** 1876 /**
1857 * @return {@link AppBannerManager} to be used for this tab. May be null. 1877 * @return {@link AppBannerManager} to be used for this tab. May be null.
1858 */ 1878 */
1859 protected AppBannerManager createAppBannerManager() { 1879 protected AppBannerManager createAppBannerManager() {
1860 return new AppBannerManager(this, mActivity); 1880 return new AppBannerManager(this);
1861 } 1881 }
1862 1882
1863 /** 1883 /**
1864 * Used to get a list of Android {@link View}s that represent both the norma l content as well as 1884 * Used to get a list of Android {@link View}s that represent both the norma l content as well as
1865 * overlays. This does not return {@link View}s for {@link NativePage}s. 1885 * overlays. This does not return {@link View}s for {@link NativePage}s.
1866 * @param content A {@link List} that will be populated with {@link View}s t hat represent all of 1886 * @param content A {@link List} that will be populated with {@link View}s t hat represent all of
1867 * the content in this {@link Tab}. 1887 * the content in this {@link Tab}.
1868 */ 1888 */
1869 public void getAllContentViews(List<View> content) { 1889 public void getAllContentViews(List<View> content) {
1870 if (!isNativePage()) { 1890 if (!isNativePage()) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 mIsInitialized = true; 2022 mIsInitialized = true;
2003 } 2023 }
2004 2024
2005 /** 2025 /**
2006 * Creates and initializes the {@link ContentViewCore}. 2026 * Creates and initializes the {@link ContentViewCore}.
2007 * 2027 *
2008 * @param webContents The WebContents object that will be used to build the 2028 * @param webContents The WebContents object that will be used to build the
2009 * {@link ContentViewCore}. 2029 * {@link ContentViewCore}.
2010 */ 2030 */
2011 protected void initContentViewCore(WebContents webContents) { 2031 protected void initContentViewCore(WebContents webContents) {
2012 ContentViewCore cvc = new ContentViewCore(mActivity); 2032 ContentViewCore cvc = new ContentViewCore(mThemedContext);
2013 ContentView cv = ContentView.createContentView(mActivity, cvc); 2033 ContentView cv = ContentView.createContentView(mThemedContext, cvc);
2014 cv.setContentDescription(mActivity.getResources().getString( 2034 cv.setContentDescription(mApplicationContext.getResources().getString(
2015 R.string.accessibility_content_view)); 2035 R.string.accessibility_content_view));
2016 cvc.initialize(cv, cv, webContents, getWindowAndroid()); 2036 cvc.initialize(cv, cv, webContents, getWindowAndroid());
2017 setContentViewCore(cvc); 2037 setContentViewCore(cvc);
2018 } 2038 }
2019 2039
2020 /** 2040 /**
2021 * Completes the {@link ContentViewCore} specific initialization around a na tive WebContents 2041 * Completes the {@link ContentViewCore} specific initialization around a na tive WebContents
2022 * pointer. {@link #getNativePage()} will still return the {@link NativePage } if there is one. 2042 * pointer. {@link #getNativePage()} will still return the {@link NativePage } if there is one.
2023 * All initialization that needs to reoccur after a web contents swap should be added here. 2043 * All initialization that needs to reoccur after a web contents swap should be added here.
2024 * <p /> 2044 * <p />
(...skipping 13 matching lines...) Expand all
2038 2058
2039 // Wrap the ContentView in a FrameLayout, which will contain both the Co ntentView and the 2059 // Wrap the ContentView in a FrameLayout, which will contain both the Co ntentView and the
2040 // InfoBarContainer. The alternative -- placing the InfoBarContainer ins ide the ContentView 2060 // InfoBarContainer. The alternative -- placing the InfoBarContainer ins ide the ContentView
2041 // -- causes problems since then the ContentView would contain both real views (the 2061 // -- causes problems since then the ContentView would contain both real views (the
2042 // infobars) and virtual views (the web page elements), which breaks And roid accessibility. 2062 // infobars) and virtual views (the web page elements), which breaks And roid accessibility.
2043 // http://crbug.com/416663 2063 // http://crbug.com/416663
2044 if (mContentViewParent != null) { 2064 if (mContentViewParent != null) {
2045 assert false; 2065 assert false;
2046 mContentViewParent.removeAllViews(); 2066 mContentViewParent.removeAllViews();
2047 } 2067 }
2048 mContentViewParent = new FrameLayout(mActivity); 2068 mContentViewParent = new FrameLayout(mThemedContext);
2049 mContentViewParent.addView(cvc.getContainerView(), 2069 mContentViewParent.addView(cvc.getContainerView(),
2050 new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutPa rams.MATCH_PARENT)); 2070 new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutPa rams.MATCH_PARENT));
2051 2071
2052 mWebContentsDelegate = createWebContentsDelegate(); 2072 mWebContentsDelegate = createWebContentsDelegate();
2053 mWebContentsObserver = new TabWebContentsObserver(mContentViewCore.getWe bContents()); 2073 mWebContentsObserver = new TabWebContentsObserver(mContentViewCore.getWe bContents());
2054 2074
2055 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient); 2075 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient);
2056 2076
2057 assert mNativeTabAndroid != 0; 2077 assert mNativeTabAndroid != 0;
2058 nativeInitWebContents( 2078 nativeInitWebContents(
2059 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate, 2079 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate,
2060 new TabContextMenuPopulator(createContextMenuPopulator())); 2080 new TabContextMenuPopulator(createContextMenuPopulator()));
2061 2081
2062 // In the case where restoring a Tab or showing a prerendered one we alr eady have a 2082 // In the case where restoring a Tab or showing a prerendered one we alr eady have a
2063 // valid infobar container, no need to recreate one. 2083 // valid infobar container, no need to recreate one.
2064 if (mInfoBarContainer == null) { 2084 if (mInfoBarContainer == null) {
2065 // The InfoBarContainer needs to be created after the ContentView ha s been natively 2085 // The InfoBarContainer needs to be created after the ContentView ha s been natively
2066 // initialized. 2086 // initialized.
2067 mInfoBarContainer = new InfoBarContainer(mActivity, getId(), mConten tViewParent, this); 2087 mInfoBarContainer = new InfoBarContainer(
2088 mThemedContext, getId(), mContentViewParent, this);
2068 } else { 2089 } else {
2069 mInfoBarContainer.onParentViewChanged(getId(), mContentViewParent); 2090 mInfoBarContainer.onParentViewChanged(getId(), mContentViewParent);
2070 } 2091 }
2071 mInfoBarContainer.setContentViewCore(mContentViewCore); 2092 mInfoBarContainer.setContentViewCore(mContentViewCore);
2072 2093
2073 mSwipeRefreshHandler = new SwipeRefreshHandler(mActivity); 2094 mSwipeRefreshHandler = new SwipeRefreshHandler(mThemedContext);
2074 mSwipeRefreshHandler.setContentViewCore(mContentViewCore); 2095 mSwipeRefreshHandler.setContentViewCore(mContentViewCore);
2075 2096
2076 for (TabObserver observer : mObservers) observer.onContentChanged(this); 2097 for (TabObserver observer : mObservers) observer.onContentChanged(this);
2077 2098
2078 // For browser tabs, we want to set accessibility focus to the page 2099 // For browser tabs, we want to set accessibility focus to the page
2079 // when it loads. This is not the default behavior for embedded 2100 // when it loads. This is not the default behavior for embedded
2080 // web views. 2101 // web views.
2081 mContentViewCore.setShouldSetAccessibilityFocusOnPageLoad(true); 2102 mContentViewCore.setShouldSetAccessibilityFocusOnPageLoad(true);
2082 2103
2083 mDownloadDelegate = new ChromeDownloadDelegate(mActivity, 2104 mDownloadDelegate = new ChromeDownloadDelegate(mThemedContext, this);
2084 mActivity.getTabModelSelector(), this);
2085 cvc.setDownloadDelegate(mDownloadDelegate); 2105 cvc.setDownloadDelegate(mDownloadDelegate);
2086 } 2106 }
2087 2107
2108 public boolean closeTab() {
2109 if (getTabModelSelector() == null) return false;
2110 return getTabModelSelector().closeTab(this);
2111 }
2112
2088 /** 2113 /**
2089 * Constructs and shows a sad tab (Aw, Snap!). 2114 * Constructs and shows a sad tab (Aw, Snap!).
2090 */ 2115 */
2091 protected void showSadTab() { 2116 protected void showSadTab() {
2092 if (getContentViewCore() != null) { 2117 if (getContentViewCore() != null) {
2093 OnClickListener suggestionAction = new OnClickListener() { 2118 OnClickListener suggestionAction = new OnClickListener() {
2094 @Override 2119 @Override
2095 public void onClick(View view) { 2120 public void onClick(View view) {
2096 Activity activity = mWindowAndroid.getActivity().get(); 2121 Activity activity = mWindowAndroid.getActivity().get();
2097 assert activity != null; 2122 assert activity != null;
2098 HelpAndFeedback.getInstance(activity).show(activity, 2123 HelpAndFeedback.getInstance(activity).show(activity,
2099 activity.getString(R.string.help_context_sad_tab), 2124 activity.getString(R.string.help_context_sad_tab),
2100 Profile.getLastUsedProfile(), null); 2125 Profile.getLastUsedProfile(), null);
2101 } 2126 }
2102 }; 2127 };
2103 OnClickListener reloadButtonAction = new OnClickListener() { 2128 OnClickListener reloadButtonAction = new OnClickListener() {
2104 @Override 2129 @Override
2105 public void onClick(View view) { 2130 public void onClick(View view) {
2106 reload(); 2131 reload();
2107 } 2132 }
2108 }; 2133 };
2109 2134
2110 // Make sure we are not adding the "Aw, snap" view over an existing one. 2135 // Make sure we are not adding the "Aw, snap" view over an existing one.
2111 assert mSadTabView == null; 2136 assert mSadTabView == null;
2112 mSadTabView = SadTabViewFactory.createSadTabView( 2137 mSadTabView = SadTabViewFactory.createSadTabView(
2113 mActivity, suggestionAction, reloadButtonAction); 2138 mThemedContext, suggestionAction, reloadButtonAction);
2114 2139
2115 // Show the sad tab inside ContentView. 2140 // Show the sad tab inside ContentView.
2116 getContentViewCore().getContainerView().addView( 2141 getContentViewCore().getContainerView().addView(
2117 mSadTabView, new FrameLayout.LayoutParams( 2142 mSadTabView, new FrameLayout.LayoutParams(
2118 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT )); 2143 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT ));
2119 for (TabObserver observer : mObservers) observer.onContentChanged(th is); 2144 for (TabObserver observer : mObservers) observer.onContentChanged(th is);
2120 } 2145 }
2121 FullscreenManager fullscreenManager = getFullscreenManager(); 2146 FullscreenManager fullscreenManager = getFullscreenManager();
2122 if (fullscreenManager != null) { 2147 if (fullscreenManager != null) {
2123 fullscreenManager.setPositionsForTabToNonFullscreen(); 2148 fullscreenManager.setPositionsForTabToNonFullscreen();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 } 2334 }
2310 2335
2311 /** 2336 /**
2312 * Loads the tab if it's not loaded (e.g. because it was killed in backgroun d). 2337 * Loads the tab if it's not loaded (e.g. because it was killed in backgroun d).
2313 * This will trigger a regular load for tabs with pending lazy first load (t abs opened in 2338 * This will trigger a regular load for tabs with pending lazy first load (t abs opened in
2314 * background on low-memory devices). 2339 * background on low-memory devices).
2315 * @return true iff the Tab handled the request. 2340 * @return true iff the Tab handled the request.
2316 */ 2341 */
2317 @CalledByNative 2342 @CalledByNative
2318 public boolean loadIfNeeded() { 2343 public boolean loadIfNeeded() {
2319 if (mActivity == null) { 2344 if (getActivity() == null) {
2320 Log.e(TAG, "Tab couldn't be loaded because Context was null."); 2345 Log.e(TAG, "Tab couldn't be loaded because Context was null.");
2321 return false; 2346 return false;
2322 } 2347 }
2323 2348
2324 if (mPendingLoadParams != null) { 2349 if (mPendingLoadParams != null) {
2325 assert isFrozen(); 2350 assert isFrozen();
2326 initContentViewCore(WebContentsFactory.createWebContents(isIncognito (), isHidden())); 2351 initContentViewCore(WebContentsFactory.createWebContents(isIncognito (), isHidden()));
2327 loadUrl(mPendingLoadParams); 2352 loadUrl(mPendingLoadParams);
2328 mPendingLoadParams = null; 2353 mPendingLoadParams = null;
2329 return true; 2354 return true;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 @CalledByNative 2648 @CalledByNative
2624 protected void onNavEntryChanged() { 2649 protected void onNavEntryChanged() {
2625 mIsTabStateDirty = true; 2650 mIsTabStateDirty = true;
2626 } 2651 }
2627 2652
2628 /** 2653 /**
2629 * Returns the SnackbarManager for the activity that owns this Tab, if any. May 2654 * Returns the SnackbarManager for the activity that owns this Tab, if any. May
2630 * return null. 2655 * return null.
2631 */ 2656 */
2632 public SnackbarManager getSnackbarManager() { 2657 public SnackbarManager getSnackbarManager() {
2633 return mActivity.getSnackbarManager(); 2658 return getActivity() != null ? getActivity().getSnackbarManager() : null ;
2634 } 2659 }
2635 2660
2636 /** 2661 /**
2637 * @return The native pointer representing the native side of this {@link Ta b} object. 2662 * @return The native pointer representing the native side of this {@link Ta b} object.
2638 */ 2663 */
2639 @CalledByNative 2664 @CalledByNative
2640 private long getNativePtr() { 2665 private long getNativePtr() {
2641 return mNativeTabAndroid; 2666 return mNativeTabAndroid;
2642 } 2667 }
2643 2668
2644 /** This is currently called when committing a pre-rendered page. */ 2669 /** This is currently called when committing a pre-rendered page. */
2645 @VisibleForTesting 2670 @VisibleForTesting
2646 @CalledByNative 2671 @CalledByNative
2647 public void swapWebContents( 2672 public void swapWebContents(
2648 WebContents webContents, boolean didStartLoad, boolean didFinishLoad ) { 2673 WebContents webContents, boolean didStartLoad, boolean didFinishLoad ) {
2649 ContentViewCore cvc = new ContentViewCore(mActivity); 2674 ContentViewCore cvc = new ContentViewCore(mThemedContext);
2650 ContentView cv = ContentView.createContentView(mActivity, cvc); 2675 ContentView cv = ContentView.createContentView(mThemedContext, cvc);
2651 cv.setContentDescription(mActivity.getResources().getString( 2676 cv.setContentDescription(mApplicationContext.getResources().getString(
2652 R.string.accessibility_content_view)); 2677 R.string.accessibility_content_view));
2653 cvc.initialize(cv, cv, webContents, getWindowAndroid()); 2678 cvc.initialize(cv, cv, webContents, getWindowAndroid());
2654 swapContentViewCore(cvc, false, didStartLoad, didFinishLoad); 2679 swapContentViewCore(cvc, false, didStartLoad, didFinishLoad);
2655 } 2680 }
2656 2681
2657 /** 2682 /**
2658 * Called to swap out the current view with the one passed in. 2683 * Called to swap out the current view with the one passed in.
2659 * 2684 *
2660 * @param newContentViewCore The content view that should be swapped into th e tab. 2685 * @param newContentViewCore The content view that should be swapped into th e tab.
2661 * @param deleteOldNativeWebContents Whether to delete the native web 2686 * @param deleteOldNativeWebContents Whether to delete the native web
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3100 case WindowOpenDisposition.OFF_THE_RECORD: 3125 case WindowOpenDisposition.OFF_THE_RECORD:
3101 assert incognito; 3126 assert incognito;
3102 incognito = true; 3127 incognito = true;
3103 break; 3128 break;
3104 default: 3129 default:
3105 assert false; 3130 assert false;
3106 } 3131 }
3107 3132
3108 // If shouldIgnoreNewTab returns true, the intent is handled by another 3133 // If shouldIgnoreNewTab returns true, the intent is handled by another
3109 // activity. As a result, don't launch a new tab to open the URL. 3134 // activity. As a result, don't launch a new tab to open the URL.
3110 if (shouldIgnoreNewTab(url, incognito)) return; 3135 if (shouldIgnoreNewTab(url, incognito) || getTabModelSelector() == null) return;
3111 3136
3112 LoadUrlParams loadUrlParams = new LoadUrlParams(url); 3137 LoadUrlParams loadUrlParams = new LoadUrlParams(url);
3113 loadUrlParams.setVerbatimHeaders(extraHeaders); 3138 loadUrlParams.setVerbatimHeaders(extraHeaders);
3114 loadUrlParams.setPostData(postData); 3139 loadUrlParams.setPostData(postData);
3115 loadUrlParams.setIsRendererInitiated(isRendererInitiated); 3140 loadUrlParams.setIsRendererInitiated(isRendererInitiated);
3116 mActivity.getTabModelSelector().openNewTab( 3141 getTabModelSelector().openNewTab(
3117 loadUrlParams, tabLaunchType, parentTab, incognito); 3142 loadUrlParams, tabLaunchType, parentTab, incognito);
3118 } 3143 }
3119 3144
3120 /** 3145 /**
3121 * @return True if the Tab should block the creation of new tabs via {@link #openNewTab}. 3146 * @return True if the Tab should block the creation of new tabs via {@link #openNewTab}.
3122 */ 3147 */
3123 protected boolean shouldIgnoreNewTab(String url, boolean incognito) { 3148 protected boolean shouldIgnoreNewTab(String url, boolean incognito) {
3124 return false; 3149 return false;
3125 } 3150 }
3126 3151
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3318 private native void nativeAttachOverlayContentViewCore(long nativeTabAndroid , 3343 private native void nativeAttachOverlayContentViewCore(long nativeTabAndroid ,
3319 ContentViewCore content, boolean visible); 3344 ContentViewCore content, boolean visible);
3320 private native void nativeDetachOverlayContentViewCore(long nativeTabAndroid , 3345 private native void nativeDetachOverlayContentViewCore(long nativeTabAndroid ,
3321 ContentViewCore content); 3346 ContentViewCore content);
3322 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); 3347 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url);
3323 private native void nativeOnRendererUnresponsive(long nativeTabAndroid); 3348 private native void nativeOnRendererUnresponsive(long nativeTabAndroid);
3324 private native void nativeOnRendererResponsive(long nativeTabAndroid); 3349 private native void nativeOnRendererResponsive(long nativeTabAndroid);
3325 3350
3326 private static native void nativeRecordStartupToCommitUma(); 3351 private static native void nativeRecordStartupToCommitUma();
3327 } 3352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698