OLD | NEW |
---|---|
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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Color; | 10 import android.graphics.Color; |
11 import android.view.ContextMenu; | 11 import android.view.ContextMenu; |
12 import android.view.View; | 12 import android.view.View; |
13 | 13 |
14 import org.chromium.base.CalledByNative; | 14 import org.chromium.base.CalledByNative; |
15 import org.chromium.base.ObserverList; | 15 import org.chromium.base.ObserverList; |
16 import org.chromium.base.TraceEvent; | |
17 import org.chromium.base.VisibleForTesting; | 16 import org.chromium.base.VisibleForTesting; |
18 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
19 import org.chromium.chrome.browser.banners.AppBannerManager; | 18 import org.chromium.chrome.browser.banners.AppBannerManager; |
20 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate; | 19 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate; |
21 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; | 20 import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; |
22 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; | 21 import org.chromium.chrome.browser.contextmenu.ContextMenuParams; |
23 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; | 22 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; |
24 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper; | 23 import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper; |
25 import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegat e; | 24 import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegat e; |
26 import org.chromium.chrome.browser.dom_distiller.DomDistillerFeedbackReporter; | 25 import org.chromium.chrome.browser.dom_distiller.DomDistillerFeedbackReporter; |
27 import org.chromium.chrome.browser.infobar.AutoLoginProcessor; | 26 import org.chromium.chrome.browser.infobar.AutoLoginProcessor; |
28 import org.chromium.chrome.browser.infobar.InfoBarContainer; | 27 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
29 import org.chromium.chrome.browser.profiles.Profile; | 28 import org.chromium.chrome.browser.profiles.Profile; |
30 import org.chromium.chrome.browser.toolbar.ToolbarModel; | 29 import org.chromium.chrome.browser.toolbar.ToolbarModel; |
31 import org.chromium.content.browser.ContentView; | 30 import org.chromium.content.browser.ContentView; |
32 import org.chromium.content.browser.ContentViewClient; | 31 import org.chromium.content.browser.ContentViewClient; |
33 import org.chromium.content.browser.ContentViewCore; | 32 import org.chromium.content.browser.ContentViewCore; |
34 import org.chromium.content.browser.NavigationClient; | |
35 import org.chromium.content.browser.WebContentsObserver; | 33 import org.chromium.content.browser.WebContentsObserver; |
36 import org.chromium.content_public.browser.LoadUrlParams; | 34 import org.chromium.content_public.browser.LoadUrlParams; |
35 import org.chromium.content_public.browser.NavigationController; | |
36 import org.chromium.content_public.browser.NavigationEntry; | |
37 import org.chromium.content_public.browser.NavigationHistory; | 37 import org.chromium.content_public.browser.NavigationHistory; |
38 import org.chromium.content_public.browser.WebContents; | 38 import org.chromium.content_public.browser.WebContents; |
39 import org.chromium.ui.base.Clipboard; | 39 import org.chromium.ui.base.Clipboard; |
40 import org.chromium.ui.base.WindowAndroid; | 40 import org.chromium.ui.base.WindowAndroid; |
41 | 41 |
42 import java.util.concurrent.atomic.AtomicInteger; | 42 import java.util.concurrent.atomic.AtomicInteger; |
43 | 43 |
44 /** | 44 /** |
45 * The basic Java representation of a tab. Contains and manages a {@link Conten tView}. | 45 * The basic Java representation of a tab. Contains and manages a {@link Conten tView}. |
46 * | 46 * |
(...skipping 18 matching lines...) Expand all Loading... | |
65 * to the parameter passed to that method. This should be used when doing thin gs like loading | 65 * to the parameter passed to that method. This should be used when doing thin gs like loading |
66 * persisted {@link Tab}s from disk on process start to ensure all new {@link T ab}s don't have id | 66 * persisted {@link Tab}s from disk on process start to ensure all new {@link T ab}s don't have id |
67 * collision. | 67 * collision. |
68 * Some {@link Activity}s will not call this because they do not persist stat e, which means those | 68 * Some {@link Activity}s will not call this because they do not persist stat e, which means those |
69 * ids can potentially conflict with the ones restored from persisted state dep ending on which | 69 * ids can potentially conflict with the ones restored from persisted state dep ending on which |
70 * {@link Activity} runs first on process start. If {@link Tab}s are ever shar ed across | 70 * {@link Activity} runs first on process start. If {@link Tab}s are ever shar ed across |
71 * {@link Activity}s or mixed with {@link Tab}s from other {@link Activity}s co nflicts can occur | 71 * {@link Activity}s or mixed with {@link Tab}s from other {@link Activity}s co nflicts can occur |
72 * unless special care is taken to make sure {@link Tab#incrementIdCounterTo(in t)} is called with | 72 * unless special care is taken to make sure {@link Tab#incrementIdCounterTo(in t)} is called with |
73 * the correct value across all affected {@link Activity}s. | 73 * the correct value across all affected {@link Activity}s. |
74 */ | 74 */ |
75 public class Tab implements NavigationClient { | 75 public class Tab implements NavigationController { |
Ted C
2014/10/22 17:41:33
We shouldn't be doing this.
Some of these methods
Yaron
2014/10/22 17:54:04
Ya, I definitely agree with Ted here
AKVT
2014/10/23 13:34:27
Done. Thank you
AKVT
2014/10/23 13:34:27
Done. Thank you
| |
76 public static final int INVALID_TAB_ID = -1; | 76 public static final int INVALID_TAB_ID = -1; |
77 | 77 |
78 /** Used for automatically generating tab ids. */ | 78 /** Used for automatically generating tab ids. */ |
79 private static final AtomicInteger sIdCounter = new AtomicInteger(); | 79 private static final AtomicInteger sIdCounter = new AtomicInteger(); |
80 | 80 |
81 private long mNativeTabAndroid; | 81 private long mNativeTabAndroid; |
82 | 82 |
83 /** Unique id of this tab (within its container). */ | 83 /** Unique id of this tab (within its container). */ |
84 private final int mId; | 84 private final int mId; |
85 | 85 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 * Removes a {@link TabObserver}. | 376 * Removes a {@link TabObserver}. |
377 * @param observer The {@link TabObserver} to remove. | 377 * @param observer The {@link TabObserver} to remove. |
378 */ | 378 */ |
379 public void removeObserver(TabObserver observer) { | 379 public void removeObserver(TabObserver observer) { |
380 mObservers.removeObserver(observer); | 380 mObservers.removeObserver(observer); |
381 } | 381 } |
382 | 382 |
383 /** | 383 /** |
384 * @return Whether or not this tab has a previous navigation entry. | 384 * @return Whether or not this tab has a previous navigation entry. |
385 */ | 385 */ |
386 @Override | |
386 public boolean canGoBack() { | 387 public boolean canGoBack() { |
387 return getWebContents() != null && getWebContents().getNavigationControl ler().canGoBack(); | 388 return getWebContents() != null && getWebContents().getNavigationControl ler().canGoBack(); |
388 } | 389 } |
389 | 390 |
390 /** | 391 /** |
391 * @return Whether or not this tab has a navigation entry after the current one. | 392 * @return Whether or not this tab has a navigation entry after the current one. |
392 */ | 393 */ |
394 @Override | |
393 public boolean canGoForward() { | 395 public boolean canGoForward() { |
394 return getWebContents() != null && getWebContents().getNavigationControl ler() | 396 return getWebContents() != null && getWebContents().getNavigationControl ler() |
395 .canGoForward(); | 397 .canGoForward(); |
396 } | 398 } |
397 | 399 |
398 /** | 400 /** |
399 * Goes to the navigation entry before the current one. | 401 * Goes to the navigation entry before the current one. |
400 */ | 402 */ |
403 @Override | |
401 public void goBack() { | 404 public void goBack() { |
402 if (getWebContents() != null) getWebContents().getNavigationController() .goBack(); | 405 if (getWebContents() != null) getWebContents().getNavigationController() .goBack(); |
403 } | 406 } |
404 | 407 |
405 /** | 408 /** |
406 * Goes to the navigation entry after the current one. | 409 * Goes to the navigation entry after the current one. |
407 */ | 410 */ |
411 @Override | |
408 public void goForward() { | 412 public void goForward() { |
409 if (getWebContents() != null) getWebContents().getNavigationController() .goForward(); | 413 if (getWebContents() != null) getWebContents().getNavigationController() .goForward(); |
410 } | 414 } |
411 | 415 |
412 @Override | 416 @Override |
413 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) { | 417 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) { |
414 if (getWebContents() != null) { | 418 if (getWebContents() != null) { |
415 return getWebContents().getNavigationController() | 419 return getWebContents().getNavigationController() |
416 .getDirectedNavigationHistory(isForward, itemLimit); | 420 .getDirectedNavigationHistory(isForward, itemLimit); |
417 } else { | 421 } else { |
418 return new NavigationHistory(); | 422 return new NavigationHistory(); |
419 } | 423 } |
420 } | 424 } |
421 | 425 |
422 @Override | 426 @Override |
423 public void goToNavigationIndex(int index) { | 427 public void goToNavigationIndex(int index) { |
424 if (getWebContents() != null) { | 428 if (getWebContents() != null) { |
425 getWebContents().getNavigationController().goToNavigationIndex(index ); | 429 getWebContents().getNavigationController().goToNavigationIndex(index ); |
426 } | 430 } |
427 } | 431 } |
428 | 432 |
429 /** | 433 /** |
434 * @return The pending {@link NavigationEntry} for this tab or {@code null} if none | |
435 * exists. | |
436 */ | |
437 @Override | |
438 public NavigationEntry getPendingEntry() { | |
439 if (getWebContents() == null) return null; | |
440 return getWebContents().getNavigationController().getPendingEntry(); | |
441 } | |
442 | |
443 /** | |
430 * Loads the current navigation if there is a pending lazy load (after tab r estore). | 444 * Loads the current navigation if there is a pending lazy load (after tab r estore). |
431 */ | 445 */ |
446 @Override | |
432 public void loadIfNecessary() { | 447 public void loadIfNecessary() { |
433 if (getWebContents() != null) getWebContents().getNavigationController() .loadIfNecessary(); | 448 if (getWebContents() != null) getWebContents().getNavigationController() .loadIfNecessary(); |
434 } | 449 } |
435 | 450 |
436 /** | 451 /** |
437 * Requests the current navigation to be loaded upon the next call to loadIf Necessary(). | 452 * Requests the current navigation to be loaded upon the next call to loadIf Necessary(). |
438 */ | 453 */ |
439 protected void requestRestoreLoad() { | 454 @Override |
455 public void requestRestoreLoad() { | |
440 if (getWebContents() != null) { | 456 if (getWebContents() != null) { |
441 getWebContents().getNavigationController().requestRestoreLoad(); | 457 getWebContents().getNavigationController().requestRestoreLoad(); |
442 } | 458 } |
443 } | 459 } |
444 | 460 |
445 /** | 461 /** |
446 * Causes this tab to navigate to the specified URL. | 462 * Causes this tab to navigate to the specified URL. |
447 * @param params parameters describing the url load. Note that it is importa nt to set correct | 463 * @param params parameters describing the url load. Note that it is importa nt to set correct |
448 * page transition as it is used for ranking URLs in the histo ry so the omnibox | 464 * page transition as it is used for ranking URLs in the histo ry so the omnibox |
449 * can report suggestions correctly. | 465 * can report suggestions correctly. |
450 * @return FULL_PRERENDERED_PAGE_LOAD or PARTIAL_PRERENDERED_PAGE_LOAD if th e page has been | |
451 * prerendered. DEFAULT_PAGE_LOAD if it had not. | |
452 */ | 466 */ |
453 public int loadUrl(LoadUrlParams params) { | 467 @Override |
454 TraceEvent.begin(); | 468 public void loadUrl(LoadUrlParams params) { |
455 | 469 if (getWebContents() != null) getWebContents().getNavigationController() .loadUrl(params); |
456 // We load the URL from the tab rather than directly from the ContentVie w so the tab has a | |
457 // chance of using a prerenderer page is any. | |
458 int loadType = nativeLoadUrl( | |
459 mNativeTabAndroid, | |
460 params.getUrl(), | |
461 params.getVerbatimHeaders(), | |
462 params.getPostData(), | |
463 params.getTransitionType(), | |
464 params.getReferrer() != null ? params.getReferrer().getUrl() : n ull, | |
465 // Policy will be ignored for null referrer url, 0 is just a pla ceholder. | |
466 // TODO(ppi): Should we pass Referrer jobject and add JNI method s to read it from | |
467 // the native? | |
468 params.getReferrer() != null ? params.getReferrer().getPolicy() : 0, | |
469 params.getIsRendererInitiated()); | |
470 | |
471 TraceEvent.end(); | |
472 | |
473 for (TabObserver observer : mObservers) { | |
474 observer.onLoadUrl(this, params.getUrl(), loadType); | |
475 } | |
476 return loadType; | |
477 } | 470 } |
478 | 471 |
479 /** | 472 /** |
473 * Clears SSL preferences for this Tab. | |
474 */ | |
475 @Override | |
476 public void clearSslPreferences() { | |
477 if (getWebContents() != null) { | |
478 getWebContents().getNavigationController().clearSslPreferences(); | |
479 } | |
480 } | |
481 | |
482 /** | |
483 * Get Original URL for current Navigation entry of Tab. | |
484 * @return The original request URL for the current navigation entry, or nul l if there is no | |
485 * current entry. | |
486 */ | |
487 @Override | |
488 public String getOriginalUrlForVisibleNavigationEntry() { | |
489 if (getWebContents() == null) return null; | |
490 return getWebContents().getNavigationController() | |
491 .getOriginalUrlForVisibleNavigationEntry(); | |
492 } | |
493 | |
494 /** | |
495 * Get a copy of the navigation history of NavigationController. | |
496 * @return navigation history of Tab. | |
497 */ | |
498 @Override | |
499 public NavigationHistory getNavigationHistory() { | |
500 if (getWebContents() == null) return null; | |
501 return getWebContents().getNavigationController().getNavigationHistory() ; | |
502 } | |
503 | |
504 /** | |
505 * Clears Tab's page history in both backwards and | |
506 * forwards directions. | |
507 */ | |
508 @Override | |
509 public void clearHistory() { | |
510 if (getWebContents() != null) getWebContents().getNavigationController() .clearHistory(); | |
511 } | |
512 | |
513 /** | |
514 * Continue the pending reload. | |
515 */ | |
516 @Override | |
517 public void continuePendingReload() { | |
518 if (getWebContents() != null) { | |
519 getWebContents().getNavigationController().continuePendingReload(); | |
520 } | |
521 } | |
522 | |
523 /** | |
524 * Cancel the pending reload. | |
525 */ | |
526 @Override | |
527 public void cancelPendingReload() { | |
528 if (getWebContents() != null) { | |
529 getWebContents().getNavigationController().continuePendingReload(); | |
530 } | |
531 } | |
532 | |
533 /** | |
534 * @param offset The offset into the navigation history. | |
535 * @return Whether we can move in history by given offset | |
536 */ | |
537 @Override | |
538 public boolean canGoToOffset(int offset) { | |
539 if (getWebContents() == null) return false; | |
540 return getWebContents().getNavigationController().canGoToOffset(offset); | |
541 } | |
542 | |
543 /** | |
544 * Navigates to the specified offset from the "current entry". Does nothing if the offset is | |
545 * out of bounds. | |
546 * @param offset The offset into the navigation history. | |
547 */ | |
548 @Override | |
549 public void goToOffset(int offset) { | |
550 if (getWebContents() != null) { | |
551 getWebContents().getNavigationController().goToOffset(offset); | |
552 } | |
553 } | |
554 | |
555 /** | |
480 * @return Whether or not the {@link Tab} is currently showing an interstiti al page, such as | 556 * @return Whether or not the {@link Tab} is currently showing an interstiti al page, such as |
481 * a bad HTTPS page. | 557 * a bad HTTPS page. |
482 */ | 558 */ |
483 public boolean isShowingInterstitialPage() { | 559 public boolean isShowingInterstitialPage() { |
484 return getWebContents() != null && getWebContents().isShowingInterstitia lPage(); | 560 return getWebContents() != null && getWebContents().isShowingInterstitia lPage(); |
485 } | 561 } |
486 | 562 |
487 /** | 563 /** |
488 * @return Whether or not the tab has something valid to render. | 564 * @return Whether or not the tab has something valid to render. |
489 */ | 565 */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 * @return Whether the printing process is started successfully. | 626 * @return Whether the printing process is started successfully. |
551 **/ | 627 **/ |
552 public boolean print() { | 628 public boolean print() { |
553 assert mNativeTabAndroid != 0; | 629 assert mNativeTabAndroid != 0; |
554 return nativePrint(mNativeTabAndroid); | 630 return nativePrint(mNativeTabAndroid); |
555 } | 631 } |
556 | 632 |
557 /** | 633 /** |
558 * Reloads the current page content. | 634 * Reloads the current page content. |
559 */ | 635 */ |
560 public void reload() { | 636 @Override |
637 public void reload(boolean checkForRepost) { | |
561 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz en? | 638 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz en? |
562 if (getWebContents() != null) getWebContents().getNavigationController() .reload(true); | 639 if (getWebContents() != null) { |
640 getWebContents().getNavigationController().reload(checkForRepost); | |
641 } | |
563 } | 642 } |
564 | 643 |
565 /** | 644 /** |
566 * Reloads the current page content. | 645 * Reloads the current page content. |
567 * This version ignores the cache and reloads from the network. | 646 * This version ignores the cache and reloads from the network. |
568 */ | 647 */ |
569 public void reloadIgnoringCache() { | 648 @Override |
649 public void reloadIgnoringCache(boolean checkForRepost) { | |
570 if (getWebContents() != null) { | 650 if (getWebContents() != null) { |
571 getWebContents().getNavigationController().reloadIgnoringCache(true) ; | 651 getWebContents().getNavigationController().reloadIgnoringCache(check ForRepost); |
572 } | 652 } |
573 } | 653 } |
574 | 654 |
575 /** Stop the current navigation. */ | 655 /** Stop the current navigation. */ |
576 public void stopLoading() { | 656 public void stopLoading() { |
577 if (getWebContents() != null) getWebContents().stop(); | 657 if (getWebContents() != null) getWebContents().stop(); |
578 } | 658 } |
579 | 659 |
580 /** | 660 /** |
581 * @return The background color of the tab. | 661 * @return The background color of the tab. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 public boolean isNativePage() { | 721 public boolean isNativePage() { |
642 return mNativePage != null; | 722 return mNativePage != null; |
643 } | 723 } |
644 | 724 |
645 /** | 725 /** |
646 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the | 726 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the |
647 * currently loaded page. | 727 * currently loaded page. |
648 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi se use a mobile one. | 728 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi se use a mobile one. |
649 * @param reloadOnChange Reload the page if the user agent has changed. | 729 * @param reloadOnChange Reload the page if the user agent has changed. |
650 */ | 730 */ |
731 @Override | |
651 public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChang e) { | 732 public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChang e) { |
652 if (getWebContents() != null) { | 733 if (getWebContents() != null) { |
653 getWebContents().getNavigationController() | 734 getWebContents().getNavigationController() |
654 .setUseDesktopUserAgent(useDesktop, reloadOnChange); | 735 .setUseDesktopUserAgent(useDesktop, reloadOnChange); |
655 } | 736 } |
656 } | 737 } |
657 | 738 |
658 /** | 739 /** |
659 * @return Whether or not the {@link ContentViewCore} is using a desktop use r agent. | 740 * @return Whether or not the {@link ContentViewCore} is using a desktop use r agent. |
660 */ | 741 */ |
742 @Override | |
661 public boolean getUseDesktopUserAgent() { | 743 public boolean getUseDesktopUserAgent() { |
662 return getWebContents() != null && getWebContents().getNavigationControl ler() | 744 return getWebContents() != null && getWebContents().getNavigationControl ler() |
663 .getUseDesktopUserAgent(); | 745 .getUseDesktopUserAgent(); |
664 } | 746 } |
665 | 747 |
666 /** | 748 /** |
667 * @return The current {ToolbarModelSecurityLevel} for the tab. | 749 * @return The current {ToolbarModelSecurityLevel} for the tab. |
668 */ | 750 */ |
669 // TODO(tedchoc): Remove this and transition all clients to use ToolbarModel directly. | 751 // TODO(tedchoc): Remove this and transition all clients to use ToolbarModel directly. |
670 public int getSecurityLevel() { | 752 public int getSecurityLevel() { |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); | 1309 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); |
1228 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e xtraHeaders, | 1310 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e xtraHeaders, |
1229 byte[] postData, int transition, String referrerUrl, int referrerPol icy, | 1311 byte[] postData, int transition, String referrerUrl, int referrerPol icy, |
1230 boolean isRendererInitiated); | 1312 boolean isRendererInitiated); |
1231 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url, | 1313 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url, |
1232 String title); | 1314 String title); |
1233 private native boolean nativePrint(long nativeTabAndroid); | 1315 private native boolean nativePrint(long nativeTabAndroid); |
1234 private native Bitmap nativeGetFavicon(long nativeTabAndroid); | 1316 private native Bitmap nativeGetFavicon(long nativeTabAndroid); |
1235 private native boolean nativeIsFaviconValid(long nativeTabAndroid); | 1317 private native boolean nativeIsFaviconValid(long nativeTabAndroid); |
1236 } | 1318 } |
OLD | NEW |