Java Code Examples for org.chromium.chrome.browser.UrlConstants

The following examples show how to use org.chromium.chrome.browser.UrlConstants. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: 365browser   Source File: ActivityDelegate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example 2
Source Project: delion   Source File: LayoutManagerDocument.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initLayoutTabFromHost(final int tabId) {
    if (getTabModelSelector() == null || getActiveLayout() == null) return;

    TabModelSelector selector = getTabModelSelector();
    Tab tab = selector.getTabById(tabId);
    if (tab == null) return;

    LayoutTab layoutTab = mTabCache.get(tabId);
    if (layoutTab == null) return;

    String url = tab.getUrl();
    boolean isNativePage = url != null && url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);
    int themeColor = tab.getThemeColor();
    boolean canUseLiveTexture =
            tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;
    layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(), canUseLiveTexture,
            themeColor, ColorUtils.getTextBoxColorForToolbarBackground(
                                mContext.getResources(), tab, themeColor),
            ColorUtils.getTextBoxAlphaForToolbarBackground(tab));

    mHost.requestRender();
}
 
Example 3
Source Project: 365browser   Source File: CustomTabActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());

    // Intents fired for media viewers have an additional file:// URI passed along so that the
    // tab can display the actual filename to the user when it is loaded.
    if (mIntentDataProvider.isMediaViewer()) {
        String mediaViewerUrl = mIntentDataProvider.getMediaViewerUrl();
        if (!TextUtils.isEmpty(mediaViewerUrl)) {
            Uri mediaViewerUri = Uri.parse(mediaViewerUrl);
            if (UrlConstants.FILE_SCHEME.equals(mediaViewerUri.getScheme())) {
                url = mediaViewerUrl;
            }
        }
    }

    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }

    return url;
}
 
Example 4
Source Project: delion   Source File: CustomTabToolbar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setTitleToPageTitle() {
    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
        mTitleBar.setText("");
        return;
    }
    String title = currentTab.getTitle();

    // It takes some time to parse the title of the webcontent, and before that Tab#getTitle
    // always return the url. We postpone the title animation until the title is authentic.
    if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
            && !title.equals(currentTab.getUrl())
            && !title.equals(UrlConstants.ABOUT_BLANK)) {
        // Delay the title animation until security icon animation finishes.
        ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
    }

    mTitleBar.setText(title);
}
 
Example 5
Source Project: delion   Source File: RoundedIconGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the text which should be used for generating a rounded icon based on |url|.
 *
 * @param url URL to consider when getting the icon's text.
 * @param includePrivateRegistries Should private registries be considered as TLDs?
 * @return The text to use on the rounded icon, or NULL if |url| is empty or the domain cannot
 *         be resolved.
 */
@Nullable
@VisibleForTesting
public static String getIconTextForUrl(String url, boolean includePrivateRegistries) {
    String domain = UrlUtilities.getDomainAndRegistry(url, includePrivateRegistries);
    if (!TextUtils.isEmpty(domain)) return domain;

    // Special-case chrome:// and chrome-native:// URLs.
    if (url.startsWith(UrlConstants.CHROME_SCHEME)
            || url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME)) {
        return "chrome";
    }

    // Use the host component of |url| when it can be parsed as a URI.
    try {
        URI uri = new URI(url);
        if (!TextUtils.isEmpty(uri.getHost())) {
            return uri.getHost();
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to parse the URL for generating an icon: " + url);
    }

    return url;
}
 
Example 6
Source Project: AndroidChromium   Source File: HelpAndFeedback.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get help context ID from URL.
 *
 * @param url The URL to be checked.
 * @param isIncognito Whether we are in incognito mode or not.
 * @return Help context ID that matches the URL and incognito mode.
 */
public static String getHelpContextIdFromUrl(Context context, String url, boolean isIncognito) {
    if (TextUtils.isEmpty(url)) {
        return context.getString(R.string.help_context_general);
    } else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) {
        return context.getString(R.string.help_context_bookmarks);
    } else if (url.equals(UrlConstants.HISTORY_URL)) {
        return context.getString(R.string.help_context_history);
    // Note: For www.google.com the following function returns false.
    } else if (UrlUtilities.nativeIsGoogleSearchUrl(url)) {
        return context.getString(R.string.help_context_search_results);
    // For incognito NTP, we want to show incognito help.
    } else if (isIncognito) {
        return context.getString(R.string.help_context_incognito);
    } else if (url.equals(UrlConstants.NTP_URL)) {
        return context.getString(R.string.help_context_new_tab);
    }
    return context.getString(R.string.help_context_webpage);
}
 
Example 7
Source Project: AndroidChromium   Source File: ActivityDelegate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example 8
Source Project: 365browser   Source File: ChromeFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an unique uri to identify the file to be shared and block access to it till
 * notifyFileReady is called.
 *
 * This function clobbers any uri that was previously created and the client application
 * accessing those uri will get a null file descriptor.
 * @param context Activity context that is used to access package manager.
 */
public static Uri generateUriAndBlockAccess(final Context context) {
    String authority = context.getPackageName() + AUTHORITY_SUFFIX;
    String fileName = BLOCKED_FILE_PREFIX + String.valueOf(System.nanoTime());
    Uri blockingUri = new Uri.Builder()
                              .scheme(UrlConstants.CONTENT_SCHEME)
                              .authority(authority)
                              .path(fileName)
                              .build();
    synchronized (sLock) {
        sCurrentBlockingUri = blockingUri;
        sFileUri = null;
        sIsFileReady = false;
        // In case the previous file never got ready.
        sLock.notify();
    }
    return blockingUri;
}
 
Example 9
Source Project: AndroidChromium   Source File: DownloadUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Whether the user should be allowed to download the current page.
 * @param tab Tab displaying the page that will be downloaded.
 * @return    Whether the "Download Page" button should be enabled.
 */
public static boolean isAllowedToDownloadPage(Tab tab) {
    if (tab == null) return false;

    // Only allow HTTP and HTTPS pages, as that is these are the only scenarios supported by the
    // background/offline page saving.
    if (!tab.getUrl().startsWith(UrlConstants.HTTP_SCHEME)
            && !tab.getUrl().startsWith(UrlConstants.HTTPS_SCHEME)) {
        return false;
    }
    if (tab.isShowingErrorPage()) return false;
    if (tab.isShowingInterstitialPage()) return false;

    // Don't allow re-downloading the currently displayed offline page.
    if (tab.isOfflinePage()) return false;

    // Offline pages isn't supported in Incognito.
    if (tab.isIncognito()) return false;

    return true;
}
 
Example 10
Source Project: 365browser   Source File: SearchEngineAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private boolean locationShouldBeShown(TemplateUrl templateUrl) {
    String url = getSearchEngineUrl(templateUrl);
    if (url.isEmpty()) return false;

    // Do not show location if the scheme isn't HTTPS.
    Uri uri = Uri.parse(url);
    if (!UrlConstants.HTTPS_SCHEME.equals(uri.getScheme())) return false;

    // Only show the location setting if it is explicitly enabled or disabled.
    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    if (locationPermission != ContentSetting.ASK) return true;

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
        return WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(url, false);
    }

    return GeolocationHeader.isGeoHeaderEnabledForUrl(url, false);
}
 
Example 11
Source Project: AndroidChromium   Source File: RoundedIconGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the text which should be used for generating a rounded icon based on |url|.
 *
 * @param url URL to consider when getting the icon's text.
 * @param includePrivateRegistries Should private registries be considered as TLDs?
 * @return The text to use on the rounded icon, or NULL if |url| is empty or the domain cannot
 *         be resolved.
 */
@Nullable
@VisibleForTesting
public static String getIconTextForUrl(String url, boolean includePrivateRegistries) {
    String domain = UrlUtilities.getDomainAndRegistry(url, includePrivateRegistries);
    if (!TextUtils.isEmpty(domain)) return domain;

    // Special-case chrome:// and chrome-native:// URLs.
    if (url.startsWith(UrlConstants.CHROME_SCHEME)
            || url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME)) {
        return "chrome";
    }

    // Use the host component of |url| when it can be parsed as a URI.
    try {
        URI uri = new URI(url);
        if (!TextUtils.isEmpty(uri.getHost())) {
            return uri.getHost();
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to parse the URL for generating an icon: " + url);
    }

    return url;
}
 
Example 12
Source Project: 365browser   Source File: PaymentRequestHeader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the title and origin on the header.
 *
 * @param title         The title to display on the header.
 * @param origin        The origin to display on the header.
 * @param securityLevel The security level of the page that invoked PaymentRequest.
 */
public void setTitleAndOrigin(String title, String origin, int securityLevel) {
    ((TextView) findViewById(R.id.page_title)).setText(title);

    TextView hostName = (TextView) findViewById(R.id.hostname);
    Spannable url = new SpannableStringBuilder(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(url, mContext.getResources(),
            Profile.getLastUsedProfile(), securityLevel, false /* isInternalPage */,
            true /* useDarkColors */, true /* emphasizeHttpsScheme */);
    hostName.setText(url);

    if (origin.startsWith(UrlConstants.HTTPS_URL_PREFIX)) {
        // Add a lock icon.
        ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(hostName,
                TintedDrawable.constructTintedDrawable(mContext.getResources(),
                        R.drawable.omnibox_https_valid, R.color.google_green_700),
                null, null, null);

        // Remove left padding to align left compound drawable with the title. Note that the
        // left compound drawable has transparent boundary.
        hostName.setPaddingRelative(0, 0, 0, 0);
    }
}
 
Example 13
Source Project: 365browser   Source File: BookmarkUIState.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return A state corresponding to the URI object. If the URI is not valid,
 *         return all_bookmarks.
 */
static BookmarkUIState createStateFromUrl(Uri uri, BookmarkModel bookmarkModel) {
    BookmarkUIState state = new BookmarkUIState();
    state.mState = STATE_INVALID;
    state.mUrl = uri.toString();

    if (state.mUrl.equals(UrlConstants.BOOKMARKS_URL)) {
        return createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    } else if (state.mUrl.startsWith(UrlConstants.BOOKMARKS_FOLDER_URL)) {
        String path = uri.getLastPathSegment();
        if (!path.isEmpty()) {
            state.mFolder = BookmarkId.getBookmarkIdFromString(path);
            state.mState = STATE_FOLDER;
        }
    }

    if (!state.isValid(bookmarkModel)) {
        state = createFolderState(bookmarkModel.getDefaultFolder(), bookmarkModel);
    }

    return state;
}
 
Example 14
Source Project: delion   Source File: BookmarkUIState.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Depending on experiments we run, "all bookmarks" might be redirected to the default folder.
 */
static BookmarkUIState createAllBookmarksState(BookmarkModel bookmarkModel) {
    if (!BookmarkUtils.isAllBookmarksViewEnabled()) {
        return createFolderState(bookmarkModel.getDefaultFolder(), null);
    }
    BookmarkUIState state = new BookmarkUIState();
    state.mState = STATE_ALL_BOOKMARKS;
    state.mUrl = UrlConstants.BOOKMARKS_URL;
    return state;
}
 
Example 15
Source Project: 365browser   Source File: AppMenuPropertiesDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates the request desktop site item's visibility
 *
 * @param requstMenuItem {@link MenuItem} for request desktop site.
 * @param currentTab      Current tab being displayed.
 */
protected void updateRequestDesktopSiteMenuItem(
        MenuItem requstMenuItem, Tab currentTab) {
    String url = currentTab.getUrl();
    boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX)
            || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
    requstMenuItem.setVisible(!isChromeScheme || currentTab.isNativePage());
    requstMenuItem.setChecked(currentTab.getUseDesktopUserAgent());
    requstMenuItem.setTitleCondensed(requstMenuItem.isChecked()
            ? mActivity.getString(R.string.menu_request_desktop_site_on)
            : mActivity.getString(R.string.menu_request_desktop_site_off));
}
 
Example 16
Source Project: delion   Source File: BookmarkActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBookmarkManager = new BookmarkManager(this, true);
    String url = getIntent().getDataString();
    if (TextUtils.isEmpty(url)) url = UrlConstants.BOOKMARKS_URL;
    mBookmarkManager.updateForUrl(url);

    setContentView(mBookmarkManager.getView());
    BookmarkUtils.setTaskDescriptionInDocumentMode(this, getString(R.string.bookmarks));

    // Hack to work around inferred theme false lint error: http://crbug.com/445633
    assert (R.layout.bookmark_main_content != 0);
}
 
Example 17
Source Project: 365browser   Source File: HttpRequest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a Request object.
 * @param url The URL to make an HTTP request to.
 * @param userAgent The string to set as the User-Agent request header.
 * @param acceptLanguage The string to set as the Accept-Language request header.
 * @param callback The callback run when the HTTP response is received.
 *     The callback will be run on the main thread.
 * @throws MalformedURLException on invalid url
 */
public HttpRequest(String url, String userAgent, String acceptLanguage,
        HttpRequestCallback<T> callback)
        throws MalformedURLException {
    mUrl = new URL(url);
    mUserAgent = userAgent;
    mAcceptLanguage = acceptLanguage;
    if (!mUrl.getProtocol().equals(UrlConstants.HTTP_SCHEME)
            && !mUrl.getProtocol().equals(UrlConstants.HTTPS_SCHEME)) {
        throw new MalformedURLException("This is not a http or https URL: " + url);
    }
    mCallback = callback;
}
 
Example 18
Source Project: 365browser   Source File: DownloadFilter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return The URL representing the filter.
 */
public static String getUrlForFilter(int filter) {
    if (filter == FILTER_ALL) {
        return UrlConstants.DOWNLOADS_URL;
    }
    return UrlConstants.DOWNLOADS_FILTER_URL + filter;
}
 
Example 19
@Override
public boolean isHidingBrowserControlsEnabled() {
    WebContents webContents = mTab.getWebContents();
    if (webContents == null || webContents.isDestroyed()) return false;

    String url = mTab.getUrl();
    boolean enableHidingBrowserControls = url != null;
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_URL_PREFIX);
    enableHidingBrowserControls &= !url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);

    int securityState = mTab.getSecurityLevel();
    enableHidingBrowserControls &= (securityState != ConnectionSecurityLevel.DANGEROUS
            && securityState != ConnectionSecurityLevel.SECURITY_WARNING);

    enableHidingBrowserControls &= !AccessibilityUtil.isAccessibilityEnabled();

    ContentViewCore cvc = mTab.getContentViewCore();
    enableHidingBrowserControls &= cvc == null || !cvc.isFocusedNodeEditable();
    enableHidingBrowserControls &= !mTab.isShowingErrorPage();
    enableHidingBrowserControls &= !webContents.isShowingInterstitialPage();
    enableHidingBrowserControls &= !mTab.isRendererUnresponsive();
    enableHidingBrowserControls &= (mTab.getFullscreenManager() != null);
    enableHidingBrowserControls &= DeviceClassManager.enableFullscreen();
    enableHidingBrowserControls &= !mIsFullscreenWaitingForLoad;

    return enableHidingBrowserControls;
}
 
Example 20
Source Project: delion   Source File: GoogleActivityController.java    License: Apache License 2.0 5 votes vote down vote up
/**
* Opens the "Web & App Activity" settings that allows the user to control how Google uses Chrome
* browsing history.
* @param activity The activity to open the settings.
* @param accountName The account for which is requested.
*/
public void openWebAndAppActivitySettings(Activity activity, String accountName) {
    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(UrlConstants.GOOGLE_ACCOUNT_ACTIVITY_CONTROLS_URL));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    intent.setPackage(activity.getPackageName());
    activity.startActivity(intent);
}
 
Example 21
Source Project: delion   Source File: NewTabPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param url The URL to check whether it is for the NTP.
 * @return Whether the passed in URL is used to render the NTP.
 */
public static boolean isNTPUrl(String url) {
    // Also handle the legacy chrome://newtab URL since that will redirect to
    // chrome-native://newtab natively.
    return url != null
            && (url.startsWith(UrlConstants.NTP_URL) || url.startsWith("chrome://newtab"));
}
 
Example 22
Source Project: 365browser   Source File: TabContextMenuItemDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks if spdy proxy is enabled for input url.
 * @param url Input url to check for spdy setting.
 * @return true if url is enabled for spdy proxy.
*/
private boolean isSpdyProxyEnabledForUrl(String url) {
    if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()
            && url != null && !url.toLowerCase(Locale.US).startsWith(
                    UrlConstants.HTTPS_URL_PREFIX)
            && !isIncognito()) {
        return true;
    }
    return false;
}
 
Example 23
Source Project: 365browser   Source File: GoogleActivityController.java    License: Apache License 2.0 5 votes vote down vote up
/**
* Opens the "Web & App Activity" settings that allows the user to control how Google uses Chrome
* browsing history.
* @param activity The activity to open the settings.
* @param accountName The account for which is requested.
*/
public void openWebAndAppActivitySettings(Activity activity, String accountName) {
    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(UrlConstants.GOOGLE_ACCOUNT_ACTIVITY_CONTROLS_URL));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    intent.setPackage(activity.getPackageName());
    activity.startActivity(intent);
}
 
Example 24
Source Project: delion   Source File: ToolbarManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void openHomepage() {
    Tab currentTab = mToolbarModel.getTab();
    if (currentTab == null) return;
    Context context = mToolbar.getContext();
    String homePageUrl = HomepageManager.getHomepageUri(context);
    if (TextUtils.isEmpty(homePageUrl)) {
        homePageUrl = UrlConstants.NTP_URL;
    }
    currentTab.loadUrl(new LoadUrlParams(homePageUrl, PageTransition.HOME_PAGE));
}
 
Example 25
Source Project: 365browser   Source File: ChromeBrowserProvider.java    License: Apache License 2.0 5 votes vote down vote up
private Cursor getBookmarkHistorySuggestions(String selection, String[] selectionArgs,
        String sortOrder, boolean excludeHistory) {
    boolean matchTitles = false;
    Vector<String> args = new Vector<String>();
    String like = selectionArgs[0] + "%";
    if (selectionArgs[0].startsWith(UrlConstants.HTTP_SCHEME)
            || selectionArgs[0].startsWith(UrlConstants.FILE_SCHEME)) {
        args.add(like);
    } else {
        // Match against common URL prefixes.
        args.add(UrlConstants.HTTP_URL_PREFIX + like);
        args.add(UrlConstants.HTTPS_URL_PREFIX + like);
        args.add(UrlConstants.HTTP_URL_PREFIX + "www." + like);
        args.add(UrlConstants.HTTPS_URL_PREFIX + "www." + like);
        args.add(UrlConstants.FILE_URL_PREFIX + like);
        matchTitles = true;
    }

    StringBuilder urlWhere = new StringBuilder("(");
    urlWhere.append(buildSuggestWhere(selection, args.size()));
    if (matchTitles) {
        args.add(like);
        urlWhere.append(" OR title LIKE ?");
    }
    urlWhere.append(")");

    if (excludeHistory) {
        urlWhere.append(" AND bookmark=?");
        args.add("1");
    }

    selectionArgs = args.toArray(selectionArgs);
    Cursor cursor = queryBookmarkFromAPI(SUGGEST_PROJECTION, urlWhere.toString(),
            selectionArgs, sortOrder);
    return new ChromeBrowserProviderSuggestionsCursor(cursor);
}
 
Example 26
Source Project: 365browser   Source File: NativePageFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static NativePageType nativePageType(String url, NativePage candidatePage,
        boolean isIncognito) {
    if (url == null) return NativePageType.NONE;

    Uri uri = Uri.parse(url);
    if (!UrlConstants.CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
        return NativePageType.NONE;
    }

    String host = uri.getHost();
    if (candidatePage != null && candidatePage.getHost().equals(host)) {
        return NativePageType.CANDIDATE;
    }

    if (UrlConstants.NTP_HOST.equals(host)) {
        return NativePageType.NTP;
    } else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
        return NativePageType.BOOKMARKS;
    } else if (UrlConstants.DOWNLOADS_HOST.equals(host)) {
        return NativePageType.DOWNLOADS;
    } else if (UrlConstants.HISTORY_HOST.equals(host)) {
        return NativePageType.HISTORY;
    } else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
        return NativePageType.RECENT_TABS;
    } else if (UrlConstants.PHYSICAL_WEB_DIAGNOSTICS_HOST.equals(host)) {
        if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
            return NativePageType.PHYSICAL_WEB;
        } else {
            return NativePageType.NONE;
        }
    } else {
        return NativePageType.NONE;
    }
}
 
Example 27
Source Project: AndroidChromium   Source File: BookmarkActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBookmarkManager = new BookmarkManager(this, true);
    String url = getIntent().getDataString();
    if (TextUtils.isEmpty(url)) url = UrlConstants.BOOKMARKS_URL;
    mBookmarkManager.updateForUrl(url);
    setContentView(mBookmarkManager.getView());
    // Hack to work around inferred theme false lint error: http://crbug.com/445633
    assert (R.layout.bookmark_main_content != 0);
}
 
Example 28
Source Project: AndroidChromium   Source File: LayoutManagerDocument.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initLayoutTabFromHost(final int tabId) {
    if (getTabModelSelector() == null || getActiveLayout() == null) return;

    TabModelSelector selector = getTabModelSelector();
    Tab tab = selector.getTabById(tabId);
    if (tab == null) return;

    LayoutTab layoutTab = mTabCache.get(tabId);
    if (layoutTab == null) return;

    String url = tab.getUrl();
    boolean isNativePage = url != null && url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);
    int themeColor = tab.getThemeColor();
    // TODO(xingliu): Remove this override themeColor for Blimp tabs. See crbug.com/644774.
    if (tab.isBlimpTab() && tab.getBlimpContents() != null) {
        themeColor = tab.getBlimpContents().getThemeColor();
    }

    boolean canUseLiveTexture = tab.isBlimpTab()
            || tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;

    boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(),
            canUseLiveTexture, themeColor, ColorUtils.getTextBoxColorForToolbarBackground(
                                mContext.getResources(), tab, themeColor),
            ColorUtils.getTextBoxAlphaForToolbarBackground(tab));
    if (needsUpdate) requestUpdate();

    mHost.requestRender();
}
 
Example 29
Source Project: AndroidChromium   Source File: TabCreatorManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new tab and loads the NTP.
 */
public final void launchNTP() {
    try {
        TraceEvent.begin("TabCreator.launchNTP");
        launchUrl(UrlConstants.NTP_URL, TabModel.TabLaunchType.FROM_CHROME_UI);
    } finally {
        TraceEvent.end("TabCreator.launchNTP");
    }
}
 
Example 30
Source Project: 365browser   Source File: BeamCallback.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether given URL is valid and sharable via Beam.
 */
private static boolean isValidUrl(String url) {
    if (TextUtils.isEmpty(url)) return false;
    try {
        String urlProtocol = (new URL(url)).getProtocol();
        return (UrlConstants.HTTP_SCHEME.equals(urlProtocol)
                || UrlConstants.HTTPS_SCHEME.equals(urlProtocol));
    } catch (MalformedURLException e) {
        return false;
    }
}