| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import static org.chromium.chrome.browser.toolbar.ToolbarPhone.URL_FOCUS_CHANGE_
ANIMATION_DURATION_MS; | 7 import static org.chromium.chrome.browser.toolbar.ToolbarPhone.URL_FOCUS_CHANGE_
ANIMATION_DURATION_MS; |
| 8 | 8 |
| 9 import android.Manifest; | 9 import android.Manifest; |
| 10 import android.animation.Animator; | 10 import android.animation.Animator; |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 @Override | 895 @Override |
| 896 public void revertChanges() { | 896 public void revertChanges() { |
| 897 if (!mUrlHasFocus) { | 897 if (!mUrlHasFocus) { |
| 898 setUrlToPageUrl(); | 898 setUrlToPageUrl(); |
| 899 } else { | 899 } else { |
| 900 Tab tab = mToolbarDataProvider.getTab(); | 900 Tab tab = mToolbarDataProvider.getTab(); |
| 901 if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito(
))) { | 901 if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito(
))) { |
| 902 mUrlBar.setUrl("", null); | 902 mUrlBar.setUrl("", null); |
| 903 } else { | 903 } else { |
| 904 mUrlBar.setUrl( | 904 mUrlBar.setUrl( |
| 905 mToolbarDataProvider.getText(), getOnlineUrlFromTab()); | 905 mToolbarDataProvider.getText(), getCurrentTabUrl()); |
| 906 } | 906 } |
| 907 } | 907 } |
| 908 } | 908 } |
| 909 | 909 |
| 910 @Override | 910 @Override |
| 911 public long getFirstUrlBarFocusTime() { | 911 public long getFirstUrlBarFocusTime() { |
| 912 return mUrlBar.getFirstFocusTime(); | 912 return mUrlBar.getFirstFocusTime(); |
| 913 } | 913 } |
| 914 | 914 |
| 915 /** | 915 /** |
| (...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 | 2017 |
| 2018 /** | 2018 /** |
| 2019 * Sets the displayed URL to be the URL of the page currently showing. | 2019 * Sets the displayed URL to be the URL of the page currently showing. |
| 2020 * | 2020 * |
| 2021 * <p>The URL is converted to the most user friendly format (removing HTTP:/
/ for example). | 2021 * <p>The URL is converted to the most user friendly format (removing HTTP:/
/ for example). |
| 2022 * | 2022 * |
| 2023 * <p>If the current tab is null, the URL text will be cleared. | 2023 * <p>If the current tab is null, the URL text will be cleared. |
| 2024 */ | 2024 */ |
| 2025 @Override | 2025 @Override |
| 2026 public void setUrlToPageUrl() { | 2026 public void setUrlToPageUrl() { |
| 2027 String url = getOnlineUrlFromTab(); | 2027 String url = getCurrentTabUrl(); |
| 2028 | 2028 |
| 2029 // If the URL is currently focused, do not replace the text they have en
tered with the URL. | 2029 // If the URL is currently focused, do not replace the text they have en
tered with the URL. |
| 2030 // Once they stop editing the URL, the current tab's URL will automatica
lly be filled in. | 2030 // Once they stop editing the URL, the current tab's URL will automatica
lly be filled in. |
| 2031 if (mUrlBar.hasFocus()) { | 2031 if (mUrlBar.hasFocus()) { |
| 2032 if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url)) { | 2032 if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url)) { |
| 2033 // If we did not run the focus animations, then the user has not
typed any text. | 2033 // If we did not run the focus animations, then the user has not
typed any text. |
| 2034 // So, clear the focus and accept whatever URL the page is curre
ntly attempting to | 2034 // So, clear the focus and accept whatever URL the page is curre
ntly attempting to |
| 2035 // display. | 2035 // display. |
| 2036 setUrlBarFocus(false); | 2036 setUrlBarFocus(false); |
| 2037 } else { | 2037 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2057 return; | 2057 return; |
| 2058 } | 2058 } |
| 2059 | 2059 |
| 2060 if (setUrlBarText(url, mToolbarDataProvider.getText())) { | 2060 if (setUrlBarText(url, mToolbarDataProvider.getText())) { |
| 2061 mUrlBar.deEmphasizeUrl(); | 2061 mUrlBar.deEmphasizeUrl(); |
| 2062 emphasizeUrl(); | 2062 emphasizeUrl(); |
| 2063 } | 2063 } |
| 2064 updateCustomSelectionActionModeCallback(); | 2064 updateCustomSelectionActionModeCallback(); |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 /** | 2067 /** Gets the URL of the web page in the tab. */ |
| 2068 * Gets the URL of the web page in the tab. When displaying offline page it
gets the URL of the | 2068 private String getCurrentTabUrl() { |
| 2069 * original page. | |
| 2070 */ | |
| 2071 private String getOnlineUrlFromTab() { | |
| 2072 Tab currentTab = getCurrentTab(); | 2069 Tab currentTab = getCurrentTab(); |
| 2073 if (currentTab == null) return ""; | 2070 if (currentTab == null) return ""; |
| 2074 if (currentTab.isOfflinePage()) { | |
| 2075 return currentTab.getOriginalUrl().trim(); | |
| 2076 } | |
| 2077 return currentTab.getUrl().trim(); | 2071 return currentTab.getUrl().trim(); |
| 2078 } | 2072 } |
| 2079 | 2073 |
| 2080 /** | 2074 /** |
| 2081 * Changes the text on the url bar | 2075 * Changes the text on the url bar |
| 2082 * @param originalText The original text (URL or search terms) for copy/cut. | 2076 * @param originalText The original text (URL or search terms) for copy/cut. |
| 2083 * @param displayText The text (URL or search terms) for user display. | 2077 * @param displayText The text (URL or search terms) for user display. |
| 2084 * @return Whether the URL was changed as a result of this call. | 2078 * @return Whether the URL was changed as a result of this call. |
| 2085 */ | 2079 */ |
| 2086 private boolean setUrlBarText(String originalText, String displayText) { | 2080 private boolean setUrlBarText(String originalText, String displayText) { |
| 2087 mUrlBar.setIgnoreTextChangesForAutocomplete(true); | 2081 mUrlBar.setIgnoreTextChangesForAutocomplete(true); |
| 2088 boolean urlChanged = mUrlBar.setUrl(originalText, displayText); | 2082 boolean urlChanged = mUrlBar.setUrl(originalText, displayText); |
| 2089 mUrlBar.setIgnoreTextChangesForAutocomplete(false); | 2083 mUrlBar.setIgnoreTextChangesForAutocomplete(false); |
| 2090 return urlChanged; | 2084 return urlChanged; |
| 2091 } | 2085 } |
| 2092 | 2086 |
| 2093 private void loadUrlFromOmniboxMatch(String url, int transition, int matchPo
sition, int type) { | 2087 private void loadUrlFromOmniboxMatch(String url, int transition, int matchPo
sition, int type) { |
| 2094 // loadUrl modifies AutocompleteController's state clearing the native | 2088 // loadUrl modifies AutocompleteController's state clearing the native |
| 2095 // AutocompleteResults needed by onSuggestionsSelected. Therefore, | 2089 // AutocompleteResults needed by onSuggestionsSelected. Therefore, |
| 2096 // loadUrl should should be invoked last. | 2090 // loadUrl should should be invoked last. |
| 2097 Tab currentTab = getCurrentTab(); | 2091 Tab currentTab = getCurrentTab(); |
| 2098 String currentPageUrl = currentTab != null ? currentTab.getUrl() : ""; | 2092 String currentPageUrl = getCurrentTabUrl(); |
| 2099 WebContents webContents = currentTab != null ? currentTab.getWebContents
() : null; | 2093 WebContents webContents = currentTab != null ? currentTab.getWebContents
() : null; |
| 2100 long elapsedTimeSinceModified = mNewOmniboxEditSessionTimestamp > 0 | 2094 long elapsedTimeSinceModified = mNewOmniboxEditSessionTimestamp > 0 |
| 2101 ? (SystemClock.elapsedRealtime() - mNewOmniboxEditSessionTimesta
mp) : -1; | 2095 ? (SystemClock.elapsedRealtime() - mNewOmniboxEditSessionTimesta
mp) : -1; |
| 2102 mAutocomplete.onSuggestionSelected(matchPosition, type, currentPageUrl, | 2096 mAutocomplete.onSuggestionSelected(matchPosition, type, currentPageUrl, |
| 2103 mUrlFocusedFromFakebox, elapsedTimeSinceModified, mUrlBar.getAut
ocompleteLength(), | 2097 mUrlFocusedFromFakebox, elapsedTimeSinceModified, mUrlBar.getAut
ocompleteLength(), |
| 2104 webContents); | 2098 webContents); |
| 2105 loadUrl(url, transition); | 2099 loadUrl(url, transition); |
| 2106 } | 2100 } |
| 2107 | 2101 |
| 2108 private void loadUrl(String url, int transition) { | 2102 private void loadUrl(String url, int transition) { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2450 public View getContainerView() { | 2444 public View getContainerView() { |
| 2451 return this; | 2445 return this; |
| 2452 } | 2446 } |
| 2453 | 2447 |
| 2454 @Override | 2448 @Override |
| 2455 public void setTitleToPageTitle() { } | 2449 public void setTitleToPageTitle() { } |
| 2456 | 2450 |
| 2457 @Override | 2451 @Override |
| 2458 public void setShowTitle(boolean showTitle) { } | 2452 public void setShowTitle(boolean showTitle) { } |
| 2459 } | 2453 } |
| OLD | NEW |