OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.help; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.content.Context; |
| 9 import android.content.Intent; |
| 10 import android.graphics.Bitmap; |
| 11 import android.net.Uri; |
| 12 import android.provider.Browser; |
| 13 import android.text.TextUtils; |
| 14 |
| 15 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.annotations.SuppressFBWarnings; |
| 17 import org.chromium.chrome.browser.ChromeMobileApplication; |
| 18 import org.chromium.chrome.browser.UrlConstants; |
| 19 import org.chromium.chrome.browser.UrlUtilities; |
| 20 |
| 21 /** |
| 22 * Launches an activity that displays a relevant support page and has an option
to provide feedback. |
| 23 */ |
| 24 public class HelpAndFeedback { |
| 25 |
| 26 // These constants should be in sync with the context names on go/mobilehelp
recs. |
| 27 // If the context ID cannot be found, the default help page will be shown to
the user. |
| 28 public static final String CONTEXT_NEW_TAB = "mobile_new_tab"; |
| 29 public static final String CONTEXT_SEARCH_RESULTS = "mobile_search_results"; |
| 30 public static final String CONTEXT_WEBPAGE = "mobile_webpage"; |
| 31 public static final String CONTEXT_SETTINGS = "mobile_settings"; |
| 32 public static final String CONTEXT_INCOGNITO = "mobile_incognito"; |
| 33 public static final String CONTEXT_BOOKMARKS = "mobile_bookmarks"; |
| 34 public static final String CONTEXT_HISTORY = "mobile_history"; |
| 35 public static final String CONTEXT_ERROR = "mobile_error"; // not used for
now |
| 36 public static final String CONTEXT_PRIVACY = "mobile_privacy"; // not added
for now |
| 37 public static final String CONTEXT_TRANSLATE = "mobile_translate"; // not a
dded for now |
| 38 public static final String CONTEXT_GENERAL = "mobile_general"; |
| 39 |
| 40 protected static final String FALLBACK_SUPPORT_URL = |
| 41 "https://support.google.com/chrome/topic/6069782"; |
| 42 |
| 43 private static HelpAndFeedback sInstance; |
| 44 |
| 45 /** |
| 46 * Returns the singleton instance of HelpAndFeedback, creating it if needed. |
| 47 */ |
| 48 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
| 49 public static HelpAndFeedback getInstance(Context context) { |
| 50 ThreadUtils.assertOnUiThread(); |
| 51 if (sInstance == null) { |
| 52 sInstance = ((ChromeMobileApplication) context.getApplicationContext
()) |
| 53 .createHelpAndFeedback(); |
| 54 } |
| 55 return sInstance; |
| 56 } |
| 57 |
| 58 /** |
| 59 * Starts an activity showing a help page for the specified context ID. |
| 60 * |
| 61 * @param activity The activity to use for starting the help activity and to
take a |
| 62 * screenshot of. |
| 63 * @param helpContext One of the CONTEXT_* constants. This should describe t
he user's current |
| 64 * context and will be used to show a more relevant help
page. |
| 65 * @param screenshot A screenshot of the current activity to include in the
feedback the |
| 66 * user sends, if any. If null, this method will take a sc
reenshot of the |
| 67 * activity (which will show a rendered page as black). |
| 68 * @param url The URL of the current tab to include in the feedback the user
sends, if any. |
| 69 * This parameter can be null. |
| 70 */ |
| 71 public void show(Activity activity, String helpContext, Bitmap screenshot, S
tring url) { |
| 72 launchFallbackSupportUri(activity); |
| 73 } |
| 74 |
| 75 /** |
| 76 * Get help context ID from URL. |
| 77 * |
| 78 * @param url The URL to be checked. |
| 79 * @param isIncognito Whether we are in incognito mode or not. |
| 80 * @return Help context ID that matches the URL and incognito mode. |
| 81 */ |
| 82 public static String getHelpContextIdFromUrl(String url, boolean isIncognito
) { |
| 83 if (TextUtils.isEmpty(url)) { |
| 84 return CONTEXT_GENERAL; |
| 85 } else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) { |
| 86 return CONTEXT_BOOKMARKS; |
| 87 } else if (url.equals(UrlConstants.HISTORY_URL)) { |
| 88 return CONTEXT_HISTORY; |
| 89 // Note: For www.google.com the following function returns false. |
| 90 } else if (UrlUtilities.nativeIsGoogleSearchUrl(url)) { |
| 91 return CONTEXT_SEARCH_RESULTS; |
| 92 // For incognito NTP, we want to show incognito help. |
| 93 } else if (isIncognito) { |
| 94 return CONTEXT_INCOGNITO; |
| 95 } else if (url.equals(UrlConstants.NTP_URL)) { |
| 96 return CONTEXT_NEW_TAB; |
| 97 } |
| 98 return CONTEXT_WEBPAGE; |
| 99 } |
| 100 |
| 101 protected static void launchFallbackSupportUri(Context context) { |
| 102 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(FALLBACK_SUPPOR
T_URL)); |
| 103 // Let Chrome know that this intent is from Chrome, so that it does not
close the app when |
| 104 // the user presses 'back' button. |
| 105 intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); |
| 106 intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
| 107 intent.setPackage(context.getPackageName()); |
| 108 context.startActivity(intent); |
| 109 } |
| 110 } |
OLD | NEW |