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; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 public void onUpdateUrl(String url) { | 207 public void onUpdateUrl(String url) { |
208 for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.thi
s, url); | 208 for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.thi
s, url); |
209 } | 209 } |
210 | 210 |
211 @Override | 211 @Override |
212 public void showRepostFormWarningDialog(final ContentViewCore contentVie
wCore) { | 212 public void showRepostFormWarningDialog(final ContentViewCore contentVie
wCore) { |
213 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog( | 213 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog( |
214 new Runnable() { | 214 new Runnable() { |
215 @Override | 215 @Override |
216 public void run() { | 216 public void run() { |
217 contentViewCore.cancelPendingReload(); | 217 getWebContents().getNavigationController().cancelPen
dingReload(); |
218 } | 218 } |
219 }, new Runnable() { | 219 }, new Runnable() { |
220 @Override | 220 @Override |
221 public void run() { | 221 public void run() { |
222 contentViewCore.continuePendingReload(); | 222 getWebContents().getNavigationController().continueP
endingReload(); |
223 } | 223 } |
224 }); | 224 }); |
225 Activity activity = (Activity) mContext; | 225 Activity activity = (Activity) mContext; |
226 warningDialog.show(activity.getFragmentManager(), null); | 226 warningDialog.show(activity.getFragmentManager(), null); |
227 } | 227 } |
228 | 228 |
229 @Override | 229 @Override |
230 public void toggleFullscreenModeForTab(boolean enableFullscreen) { | 230 public void toggleFullscreenModeForTab(boolean enableFullscreen) { |
231 for (TabObserver observer : mObservers) { | 231 for (TabObserver observer : mObservers) { |
232 observer.onToggleFullscreenMode(Tab.this, enableFullscreen); | 232 observer.onToggleFullscreenMode(Tab.this, enableFullscreen); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 * @param observer The {@link TabObserver} to remove. | 356 * @param observer The {@link TabObserver} to remove. |
357 */ | 357 */ |
358 public void removeObserver(TabObserver observer) { | 358 public void removeObserver(TabObserver observer) { |
359 mObservers.removeObserver(observer); | 359 mObservers.removeObserver(observer); |
360 } | 360 } |
361 | 361 |
362 /** | 362 /** |
363 * @return Whether or not this tab has a previous navigation entry. | 363 * @return Whether or not this tab has a previous navigation entry. |
364 */ | 364 */ |
365 public boolean canGoBack() { | 365 public boolean canGoBack() { |
366 return mContentViewCore != null && mContentViewCore.canGoBack(); | 366 return getWebContents() != null && getWebContents().getNavigationControl
ler().canGoBack(); |
367 } | 367 } |
368 | 368 |
369 /** | 369 /** |
370 * @return Whether or not this tab has a navigation entry after the current
one. | 370 * @return Whether or not this tab has a navigation entry after the current
one. |
371 */ | 371 */ |
372 public boolean canGoForward() { | 372 public boolean canGoForward() { |
373 return mContentViewCore != null && mContentViewCore.canGoForward(); | 373 return getWebContents() != null && getWebContents().getNavigationControl
ler() |
| 374 .canGoForward(); |
374 } | 375 } |
375 | 376 |
376 /** | 377 /** |
377 * Goes to the navigation entry before the current one. | 378 * Goes to the navigation entry before the current one. |
378 */ | 379 */ |
379 public void goBack() { | 380 public void goBack() { |
380 if (mContentViewCore != null) mContentViewCore.goBack(); | 381 if (getWebContents() != null) getWebContents().getNavigationController()
.goBack(); |
381 } | 382 } |
382 | 383 |
383 /** | 384 /** |
384 * Goes to the navigation entry after the current one. | 385 * Goes to the navigation entry after the current one. |
385 */ | 386 */ |
386 public void goForward() { | 387 public void goForward() { |
387 if (mContentViewCore != null) mContentViewCore.goForward(); | 388 if (getWebContents() != null) getWebContents().getNavigationController()
.goForward(); |
388 } | 389 } |
389 | 390 |
390 @Override | 391 @Override |
391 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int
itemLimit) { | 392 public NavigationHistory getDirectedNavigationHistory(boolean isForward, int
itemLimit) { |
392 if (mContentViewCore != null) { | 393 if (getWebContents() != null) { |
393 return mContentViewCore.getDirectedNavigationHistory(isForward, item
Limit); | 394 return getWebContents().getNavigationController() |
| 395 .getDirectedNavigationHistory(isForward, itemLimit); |
394 } else { | 396 } else { |
395 return new NavigationHistory(); | 397 return new NavigationHistory(); |
396 } | 398 } |
397 } | 399 } |
398 | 400 |
399 @Override | 401 @Override |
400 public void goToNavigationIndex(int index) { | 402 public void goToNavigationIndex(int index) { |
401 if (mContentViewCore != null) mContentViewCore.goToNavigationIndex(index
); | 403 if (getWebContents() != null) { |
| 404 getWebContents().getNavigationController().goToNavigationIndex(index
); |
| 405 } |
402 } | 406 } |
403 | 407 |
404 /** | 408 /** |
405 * Loads the current navigation if there is a pending lazy load (after tab r
estore). | 409 * Loads the current navigation if there is a pending lazy load (after tab r
estore). |
406 */ | 410 */ |
407 public void loadIfNecessary() { | 411 public void loadIfNecessary() { |
408 if (mContentViewCore != null) mContentViewCore.loadIfNecessary(); | 412 if (getWebContents() != null) getWebContents().getNavigationController()
.loadIfNecessary(); |
409 } | 413 } |
410 | 414 |
411 /** | 415 /** |
412 * Requests the current navigation to be loaded upon the next call to loadIf
Necessary(). | 416 * Requests the current navigation to be loaded upon the next call to loadIf
Necessary(). |
413 */ | 417 */ |
414 protected void requestRestoreLoad() { | 418 protected void requestRestoreLoad() { |
415 if (mContentViewCore != null) mContentViewCore.requestRestoreLoad(); | 419 if (getWebContents() != null) { |
| 420 getWebContents().getNavigationController().requestRestoreLoad(); |
| 421 } |
416 } | 422 } |
417 | 423 |
418 /** | 424 /** |
419 * Causes this tab to navigate to the specified URL. | 425 * Causes this tab to navigate to the specified URL. |
420 * @param params parameters describing the url load. Note that it is importa
nt to set correct | 426 * @param params parameters describing the url load. Note that it is importa
nt to set correct |
421 * page transition as it is used for ranking URLs in the histo
ry so the omnibox | 427 * page transition as it is used for ranking URLs in the histo
ry so the omnibox |
422 * can report suggestions correctly. | 428 * can report suggestions correctly. |
423 * @return FULL_PRERENDERED_PAGE_LOAD or PARTIAL_PRERENDERED_PAGE_LOAD if th
e page has been | 429 * @return FULL_PRERENDERED_PAGE_LOAD or PARTIAL_PRERENDERED_PAGE_LOAD if th
e page has been |
424 * prerendered. DEFAULT_PAGE_LOAD if it had not. | 430 * prerendered. DEFAULT_PAGE_LOAD if it had not. |
425 */ | 431 */ |
(...skipping 21 matching lines...) Expand all Loading... |
447 observer.onLoadUrl(this, params.getUrl(), loadType); | 453 observer.onLoadUrl(this, params.getUrl(), loadType); |
448 } | 454 } |
449 return loadType; | 455 return loadType; |
450 } | 456 } |
451 | 457 |
452 /** | 458 /** |
453 * @return Whether or not the {@link Tab} is currently showing an interstiti
al page, such as | 459 * @return Whether or not the {@link Tab} is currently showing an interstiti
al page, such as |
454 * a bad HTTPS page. | 460 * a bad HTTPS page. |
455 */ | 461 */ |
456 public boolean isShowingInterstitialPage() { | 462 public boolean isShowingInterstitialPage() { |
457 ContentViewCore contentViewCore = getContentViewCore(); | 463 return getWebContents() != null && getWebContents().isShowingInterstitia
lPage(); |
458 return contentViewCore != null && contentViewCore.isShowingInterstitialP
age(); | |
459 } | 464 } |
460 | 465 |
461 /** | 466 /** |
462 * @return Whether or not the tab has something valid to render. | 467 * @return Whether or not the tab has something valid to render. |
463 */ | 468 */ |
464 public boolean isReady() { | 469 public boolean isReady() { |
465 return mNativePage != null || (mContentViewCore != null && mContentViewC
ore.isReady()); | 470 return mNativePage != null || (mContentViewCore != null && mContentViewC
ore.isReady()); |
466 } | 471 } |
467 | 472 |
468 /** | 473 /** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 public boolean print() { | 531 public boolean print() { |
527 assert mNativeTabAndroid != 0; | 532 assert mNativeTabAndroid != 0; |
528 return nativePrint(mNativeTabAndroid); | 533 return nativePrint(mNativeTabAndroid); |
529 } | 534 } |
530 | 535 |
531 /** | 536 /** |
532 * Reloads the current page content. | 537 * Reloads the current page content. |
533 */ | 538 */ |
534 public void reload() { | 539 public void reload() { |
535 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz
en? | 540 // TODO(dtrainor): Should we try to rebuild the ContentView if it's froz
en? |
536 if (mContentViewCore != null) mContentViewCore.reload(true); | 541 if (getWebContents() != null) getWebContents().getNavigationController()
.reload(true); |
537 } | 542 } |
538 | 543 |
539 /** | 544 /** |
540 * Reloads the current page content. | 545 * Reloads the current page content. |
541 * This version ignores the cache and reloads from the network. | 546 * This version ignores the cache and reloads from the network. |
542 */ | 547 */ |
543 public void reloadIgnoringCache() { | 548 public void reloadIgnoringCache() { |
544 if (mContentViewCore != null) mContentViewCore.reloadIgnoringCache(true)
; | 549 if (getWebContents() != null) { |
| 550 getWebContents().getNavigationController().reloadIgnoringCache(true)
; |
| 551 } |
545 } | 552 } |
546 | 553 |
547 /** Stop the current navigation. */ | 554 /** Stop the current navigation. */ |
548 public void stopLoading() { | 555 public void stopLoading() { |
549 if (mContentViewCore != null) mContentViewCore.stopLoading(); | 556 if (getWebContents() != null) getWebContents().stop(); |
550 } | 557 } |
551 | 558 |
552 /** | 559 /** |
553 * @return The background color of the tab. | 560 * @return The background color of the tab. |
554 */ | 561 */ |
555 public int getBackgroundColor() { | 562 public int getBackgroundColor() { |
556 if (mNativePage != null) return mNativePage.getBackgroundColor(); | 563 if (mNativePage != null) return mNativePage.getBackgroundColor(); |
557 if (mContentViewCore != null) return mContentViewCore.getBackgroundColor
(); | 564 if (getWebContents() != null) return getWebContents().getBackgroundColor
(); |
558 return Color.WHITE; | 565 return Color.WHITE; |
559 } | 566 } |
560 | 567 |
561 /** | 568 /** |
562 * @return The web contents associated with this tab. | 569 * @return The web contents associated with this tab. |
563 */ | 570 */ |
564 public WebContents getWebContents() { | 571 public WebContents getWebContents() { |
565 if (mNativeTabAndroid == 0) return null; | 572 if (mNativeTabAndroid == 0) return null; |
566 return nativeGetWebContents(mNativeTabAndroid); | 573 return nativeGetWebContents(mNativeTabAndroid); |
567 } | 574 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 return mNativePage != null; | 622 return mNativePage != null; |
616 } | 623 } |
617 | 624 |
618 /** | 625 /** |
619 * Set whether or not the {@link ContentViewCore} should be using a desktop
user agent for the | 626 * Set whether or not the {@link ContentViewCore} should be using a desktop
user agent for the |
620 * currently loaded page. | 627 * currently loaded page. |
621 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi
se use a mobile one. | 628 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi
se use a mobile one. |
622 * @param reloadOnChange Reload the page if the user agent has changed. | 629 * @param reloadOnChange Reload the page if the user agent has changed. |
623 */ | 630 */ |
624 public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChang
e) { | 631 public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChang
e) { |
625 if (mContentViewCore != null) { | 632 if (getWebContents() != null) { |
626 mContentViewCore.setUseDesktopUserAgent(useDesktop, reloadOnChange); | 633 getWebContents().getNavigationController() |
| 634 .setUseDesktopUserAgent(useDesktop, reloadOnChange); |
627 } | 635 } |
628 } | 636 } |
629 | 637 |
630 /** | 638 /** |
631 * @return Whether or not the {@link ContentViewCore} is using a desktop use
r agent. | 639 * @return Whether or not the {@link ContentViewCore} is using a desktop use
r agent. |
632 */ | 640 */ |
633 public boolean getUseDesktopUserAgent() { | 641 public boolean getUseDesktopUserAgent() { |
634 return mContentViewCore != null && mContentViewCore.getUseDesktopUserAge
nt(); | 642 return getWebContents() != null && getWebContents().getNavigationControl
ler() |
| 643 .getUseDesktopUserAgent(); |
635 } | 644 } |
636 | 645 |
637 /** | 646 /** |
638 * @return The current {ToolbarModelSecurityLevel} for the tab. | 647 * @return The current {ToolbarModelSecurityLevel} for the tab. |
639 */ | 648 */ |
640 public int getSecurityLevel() { | 649 public int getSecurityLevel() { |
641 if (mNativeTabAndroid == 0) return ToolbarModelSecurityLevel.NONE; | 650 if (mNativeTabAndroid == 0) return ToolbarModelSecurityLevel.NONE; |
642 return nativeGetSecurityLevel(mNativeTabAndroid); | 651 return nativeGetSecurityLevel(mNativeTabAndroid); |
643 } | 652 } |
644 | 653 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 */ | 882 */ |
874 public boolean isInitialized() { | 883 public boolean isInitialized() { |
875 return mNativeTabAndroid != 0; | 884 return mNativeTabAndroid != 0; |
876 } | 885 } |
877 | 886 |
878 /** | 887 /** |
879 * @return The url associated with the tab. | 888 * @return The url associated with the tab. |
880 */ | 889 */ |
881 @CalledByNative | 890 @CalledByNative |
882 public String getUrl() { | 891 public String getUrl() { |
883 return mContentViewCore != null ? mContentViewCore.getUrl() : ""; | 892 return getWebContents() != null ? getWebContents().getUrl() : ""; |
884 } | 893 } |
885 | 894 |
886 /** | 895 /** |
887 * @return The tab title. | 896 * @return The tab title. |
888 */ | 897 */ |
889 @CalledByNative | 898 @CalledByNative |
890 public String getTitle() { | 899 public String getTitle() { |
891 if (mNativePage != null) return mNativePage.getTitle(); | 900 if (mNativePage != null) return mNativePage.getTitle(); |
892 if (mContentViewCore != null) return mContentViewCore.getTitle(); | 901 if (getWebContents() != null) return getWebContents().getTitle(); |
893 return ""; | 902 return ""; |
894 } | 903 } |
895 | 904 |
896 /** | 905 /** |
897 * @return The bitmap of the favicon scaled to 16x16dp. null if no favicon | 906 * @return The bitmap of the favicon scaled to 16x16dp. null if no favicon |
898 * is specified or it requires the default favicon. | 907 * is specified or it requires the default favicon. |
899 */ | 908 */ |
900 public Bitmap getFavicon() { | 909 public Bitmap getFavicon() { |
901 String url = getUrl(); | 910 String url = getUrl(); |
902 // Invalidate our cached values if necessary. | 911 // Invalidate our cached values if necessary. |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e
xtraHeaders, | 1205 private native int nativeLoadUrl(long nativeTabAndroid, String url, String e
xtraHeaders, |
1197 byte[] postData, int transition, String referrerUrl, int referrerPol
icy, | 1206 byte[] postData, int transition, String referrerUrl, int referrerPol
icy, |
1198 boolean isRendererInitiated); | 1207 boolean isRendererInitiated); |
1199 private native int nativeGetSecurityLevel(long nativeTabAndroid); | 1208 private native int nativeGetSecurityLevel(long nativeTabAndroid); |
1200 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab
Android, String url, | 1209 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab
Android, String url, |
1201 String title); | 1210 String title); |
1202 private native boolean nativePrint(long nativeTabAndroid); | 1211 private native boolean nativePrint(long nativeTabAndroid); |
1203 private native Bitmap nativeGetFavicon(long nativeTabAndroid); | 1212 private native Bitmap nativeGetFavicon(long nativeTabAndroid); |
1204 private native boolean nativeIsFaviconValid(long nativeTabAndroid); | 1213 private native boolean nativeIsFaviconValid(long nativeTabAndroid); |
1205 } | 1214 } |
OLD | NEW |