OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.net.MailTo; | 8 import android.net.MailTo; |
9 import android.support.annotation.IntDef; | 9 import android.support.annotation.IntDef; |
10 import android.support.annotation.StringRes; | 10 import android.support.annotation.StringRes; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 titleText = params.getTitleText(); | 242 titleText = params.getTitleText(); |
243 } | 243 } |
244 return titleText; | 244 return titleText; |
245 } | 245 } |
246 | 246 |
247 @Override | 247 @Override |
248 public List<Pair<Integer, List<ContextMenuItem>>> buildContextMenu( | 248 public List<Pair<Integer, List<ContextMenuItem>>> buildContextMenu( |
249 ContextMenu menu, Context context, ContextMenuParams params) { | 249 ContextMenu menu, Context context, ContextMenuParams params) { |
250 // Add all items in a group | 250 // Add all items in a group |
251 Set<ContextMenuItem> supportedOptions = new HashSet<>(); | 251 Set<ContextMenuItem> supportedOptions = new HashSet<>(); |
252 supportedOptions.addAll(BASE_WHITELIST); | 252 if (FirstRunStatus.getFirstRunFlowComplete()) { |
253 if (mMode == FULLSCREEN_TAB_MODE) { | 253 supportedOptions.addAll(BASE_WHITELIST); |
254 supportedOptions.addAll(FULLSCREEN_TAB_MODE_WHITELIST); | 254 if (mMode == FULLSCREEN_TAB_MODE) { |
255 } else if (mMode == CUSTOM_TAB_MODE) { | 255 supportedOptions.addAll(FULLSCREEN_TAB_MODE_WHITELIST); |
256 supportedOptions.addAll(CUSTOM_TAB_MODE_WHITELIST); | 256 } else if (mMode == CUSTOM_TAB_MODE) { |
| 257 supportedOptions.addAll(CUSTOM_TAB_MODE_WHITELIST); |
| 258 } else { |
| 259 supportedOptions.addAll(NORMAL_MODE_WHITELIST); |
| 260 } |
257 } else { | 261 } else { |
258 supportedOptions.addAll(NORMAL_MODE_WHITELIST); | 262 supportedOptions.add(ContextMenuItem.COPY_LINK_ADDRESS); |
| 263 supportedOptions.add(ContextMenuItem.COPY_LINK_TEXT); |
| 264 supportedOptions.add(ContextMenuItem.COPY); |
259 } | 265 } |
260 | 266 |
261 Set<ContextMenuItem> disabledOptions = getDisabledOptions(params); | 267 Set<ContextMenuItem> disabledOptions = getDisabledOptions(params); |
262 // Split the items into their respective groups. | 268 // Split the items into their respective groups. |
263 List<Pair<Integer, List<ContextMenuItem>>> groupedItems = new ArrayList<
>(); | 269 List<Pair<Integer, List<ContextMenuItem>>> groupedItems = new ArrayList<
>(); |
264 if (params.isAnchor() | 270 if (params.isAnchor() |
265 && !ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT
_MENU)) { | 271 && !ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT
_MENU)) { |
266 populateItemGroup(LINK, R.string.contextmenu_link_title, groupedItem
s, supportedOptions, | 272 populateItemGroup(LINK, R.string.contextmenu_link_title, groupedItem
s, supportedOptions, |
267 disabledOptions); | 273 disabledOptions); |
268 } | 274 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 399 } |
394 | 400 |
395 if (mDelegate.isIncognito() || !mDelegate.isIncognitoSupported()) { | 401 if (mDelegate.isIncognito() || !mDelegate.isIncognitoSupported()) { |
396 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); | 402 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
397 } | 403 } |
398 | 404 |
399 if (params.getLinkText().trim().isEmpty() || params.isImage()) { | 405 if (params.getLinkText().trim().isEmpty() || params.isImage()) { |
400 disabledOptions.add(ContextMenuItem.COPY_LINK_TEXT); | 406 disabledOptions.add(ContextMenuItem.COPY_LINK_TEXT); |
401 } | 407 } |
402 | 408 |
403 if (params.isAnchor() && !UrlUtilities.isAcceptedScheme(params.getLinkUr
l())) { | 409 if (params.isAnchor() && !isAcceptedScheme(params.getLinkUrl())) { |
404 disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); | 410 disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); |
405 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); | 411 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); |
406 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); | 412 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
407 } | 413 } |
408 | 414 |
409 if (isEmptyUrl(params.getLinkUrl())) { | 415 if (isEmptyUrl(params.getLinkUrl())) { |
410 disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); | 416 disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); |
411 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); | 417 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); |
412 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); | 418 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
413 } | 419 } |
(...skipping 16 matching lines...) Expand all Loading... |
430 disabledOptions.add(ContextMenuItem.CALL); | 436 disabledOptions.add(ContextMenuItem.CALL); |
431 } | 437 } |
432 if (!mDelegate.supportsSendTextMessage()) { | 438 if (!mDelegate.supportsSendTextMessage()) { |
433 disabledOptions.add(ContextMenuItem.SEND_MESSAGE); | 439 disabledOptions.add(ContextMenuItem.SEND_MESSAGE); |
434 } | 440 } |
435 if (!mDelegate.supportsAddToContacts()) { | 441 if (!mDelegate.supportsAddToContacts()) { |
436 disabledOptions.add(ContextMenuItem.ADD_TO_CONTACTS); | 442 disabledOptions.add(ContextMenuItem.ADD_TO_CONTACTS); |
437 } | 443 } |
438 } | 444 } |
439 | 445 |
440 if (!UrlUtilities.isDownloadableScheme(params.getLinkUrl())) { | 446 if (!isDownloadableScheme(params.getLinkUrl())) { |
441 disabledOptions.add(ContextMenuItem.SAVE_LINK_AS); | 447 disabledOptions.add(ContextMenuItem.SAVE_LINK_AS); |
442 } | 448 } |
443 | 449 |
444 boolean isSrcDownloadableScheme = UrlUtilities.isDownloadableScheme(para
ms.getSrcUrl()); | 450 boolean isSrcDownloadableScheme = isDownloadableScheme(params.getSrcUrl(
)); |
445 if (params.isVideo()) { | 451 if (params.isVideo()) { |
446 boolean saveableAndDownloadable = params.canSaveMedia() && isSrcDown
loadableScheme; | 452 boolean saveableAndDownloadable = params.canSaveMedia() && isSrcDown
loadableScheme; |
447 if (!saveableAndDownloadable) { | 453 if (!saveableAndDownloadable) { |
448 disabledOptions.add(ContextMenuItem.SAVE_VIDEO); | 454 disabledOptions.add(ContextMenuItem.SAVE_VIDEO); |
449 } | 455 } |
450 } else if (params.isImage() && params.imageWasFetchedLoFi()) { | 456 } else if (params.isImage() && params.imageWasFetchedLoFi()) { |
451 DataReductionProxyUma.previewsLoFiContextMenuAction( | 457 DataReductionProxyUma.previewsLoFiContextMenuAction( |
452 DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_SH
OWN); | 458 DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_SH
OWN); |
453 // All image context menu items other than "Load image," "Open origi
nal image in | 459 // All image context menu items other than "Load image," "Open origi
nal image in |
454 // new tab," and "Copy image URL" should be disabled on Lo-Fi images
. | 460 // new tab," and "Copy image URL" should be disabled on Lo-Fi images
. |
455 disabledOptions.add(ContextMenuItem.SAVE_IMAGE); | 461 disabledOptions.add(ContextMenuItem.SAVE_IMAGE); |
456 disabledOptions.add(ContextMenuItem.OPEN_IMAGE); | 462 disabledOptions.add(ContextMenuItem.OPEN_IMAGE); |
457 disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); | 463 disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); |
458 disabledOptions.add(ContextMenuItem.SHARE_IMAGE); | 464 disabledOptions.add(ContextMenuItem.SHARE_IMAGE); |
459 } else if (params.isImage() && !params.imageWasFetchedLoFi()) { | 465 } else if (params.isImage() && !params.imageWasFetchedLoFi()) { |
460 disabledOptions.add(ContextMenuItem.LOAD_ORIGINAL_IMAGE); | 466 disabledOptions.add(ContextMenuItem.LOAD_ORIGINAL_IMAGE); |
461 | 467 |
462 if (!isSrcDownloadableScheme) { | 468 if (!isSrcDownloadableScheme) { |
463 disabledOptions.add(ContextMenuItem.SAVE_IMAGE); | 469 disabledOptions.add(ContextMenuItem.SAVE_IMAGE); |
464 } | 470 } |
465 | 471 |
466 // Avoid showing open image option for same image which is already o
pened. | 472 // Avoid showing open image option for same image which is already o
pened. |
467 if (mDelegate.getPageUrl().equals(params.getSrcUrl())) { | 473 if (mDelegate.getPageUrl().equals(params.getSrcUrl())) { |
468 disabledOptions.add(ContextMenuItem.OPEN_IMAGE); | 474 disabledOptions.add(ContextMenuItem.OPEN_IMAGE); |
469 } | 475 } |
470 final TemplateUrlService templateUrlServiceInstance = TemplateUrlSer
vice.getInstance(); | 476 final TemplateUrlService templateUrlServiceInstance = getTemplateUrl
Service(); |
471 final boolean isSearchByImageAvailable = isSrcDownloadableScheme | 477 final boolean isSearchByImageAvailable = isSrcDownloadableScheme |
472 && templateUrlServiceInstance.isLoaded() | 478 && templateUrlServiceInstance.isLoaded() |
473 && templateUrlServiceInstance.isSearchByImageAvailable() | 479 && templateUrlServiceInstance.isSearchByImageAvailable() |
474 && templateUrlServiceInstance.getDefaultSearchEngineTemplate
Url() != null; | 480 && templateUrlServiceInstance.getDefaultSearchEngineTemplate
Url() != null; |
475 | 481 |
476 if (!isSearchByImageAvailable) { | 482 if (!isSearchByImageAvailable) { |
477 disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); | 483 disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); |
478 } | 484 } |
479 } | 485 } |
480 | 486 |
481 // Hide all items that could spawn additional tabs until FRE has been co
mpleted. | |
482 if (!FirstRunStatus.getFirstRunFlowComplete()) { | |
483 disabledOptions.add(ContextMenuItem.OPEN_IMAGE_IN_NEW_TAB); | |
484 disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); | |
485 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); | |
486 disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); | |
487 disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); | |
488 disabledOptions.add(ContextMenuItem.OPEN_IN_CHROME); | |
489 } | |
490 | |
491 if (mMode == CUSTOM_TAB_MODE) { | 487 if (mMode == CUSTOM_TAB_MODE) { |
492 try { | 488 try { |
493 URI uri = new URI(getUrl(params)); | 489 URI uri = new URI(getUrl(params)); |
494 if (UrlUtilities.isInternalScheme(uri) || isEmptyUrl(getUrl(para
ms))) { | 490 if (UrlUtilities.isInternalScheme(uri) || isEmptyUrl(getUrl(para
ms))) { |
495 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_CHROME_TAB); | 491 disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_CHROME_TAB); |
496 disabledOptions.add(ContextMenuItem.OPEN_IN_CHROME_INCOGNITO
_TAB); | 492 disabledOptions.add(ContextMenuItem.OPEN_IN_CHROME_INCOGNITO
_TAB); |
497 disabledOptions.add(ContextMenuItem.OPEN_IN_BROWSER_ID); | 493 disabledOptions.add(ContextMenuItem.OPEN_IN_BROWSER_ID); |
498 } else if (ChromePreferenceManager.getInstance().getCachedChrome
DefaultBrowser()) { | 494 } else if (ChromePreferenceManager.getInstance().getCachedChrome
DefaultBrowser()) { |
499 disabledOptions.add(ContextMenuItem.OPEN_IN_BROWSER_ID); | 495 disabledOptions.add(ContextMenuItem.OPEN_IN_BROWSER_ID); |
500 if (!mDelegate.isIncognitoSupported()) { | 496 if (!mDelegate.isIncognitoSupported()) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_BROWSER)
; | 603 ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_BROWSER)
; |
608 mDelegate.onOpenInDefaultBrowser(getUrl(params)); | 604 mDelegate.onOpenInDefaultBrowser(getUrl(params)); |
609 } else { | 605 } else { |
610 assert false; | 606 assert false; |
611 } | 607 } |
612 | 608 |
613 return true; | 609 return true; |
614 } | 610 } |
615 | 611 |
616 /** | 612 /** |
| 613 * @return Whether the scheme of the URL is valid . |
| 614 */ |
| 615 protected boolean isAcceptedScheme(String url) { |
| 616 return UrlUtilities.isAcceptedScheme(url); |
| 617 } |
| 618 |
| 619 /** |
| 620 * @return Whether the scheme of the URL is valid for downloading. |
| 621 */ |
| 622 protected boolean isDownloadableScheme(String url) { |
| 623 return UrlUtilities.isDownloadableScheme(url); |
| 624 } |
| 625 |
| 626 /** |
| 627 * @return The service that handles TemplateUrls. |
| 628 */ |
| 629 protected TemplateUrlService getTemplateUrlService() { |
| 630 return TemplateUrlService.getInstance(); |
| 631 } |
| 632 |
| 633 /** |
617 * Checks whether a url is empty or blank. | 634 * Checks whether a url is empty or blank. |
618 * @param url The url need to be checked. | 635 * @param url The url need to be checked. |
619 * @return True if the url is empty or "about:blank". | 636 * @return True if the url is empty or "about:blank". |
620 */ | 637 */ |
621 private boolean isEmptyUrl(String url) { | 638 private boolean isEmptyUrl(String url) { |
622 if (TextUtils.isEmpty(url) || url.equals(ContentUrlConstants.ABOUT_BLANK
_DISPLAY_URL)) { | 639 if (TextUtils.isEmpty(url) || url.equals(ContentUrlConstants.ABOUT_BLANK
_DISPLAY_URL)) { |
623 return true; | 640 return true; |
624 } | 641 } |
625 return false; | 642 return false; |
626 } | 643 } |
627 | 644 |
628 /** | 645 /** |
629 * The valid url of a link is stored in the linkUrl of ContextMenuParams whi
le the | 646 * The valid url of a link is stored in the linkUrl of ContextMenuParams whi
le the |
630 * valid url of a image or video is stored in the srcUrl of ContextMenuParam
s. | 647 * valid url of a image or video is stored in the srcUrl of ContextMenuParam
s. |
631 * @param params The parameters used to decide the type of the content. | 648 * @param params The parameters used to decide the type of the content. |
632 */ | 649 */ |
633 private String getUrl(ContextMenuParams params) { | 650 private String getUrl(ContextMenuParams params) { |
634 if (params.isImage() || params.isVideo()) { | 651 if (params.isImage() || params.isVideo()) { |
635 return params.getSrcUrl(); | 652 return params.getSrcUrl(); |
636 } else { | 653 } else { |
637 return params.getLinkUrl(); | 654 return params.getLinkUrl(); |
638 } | 655 } |
639 } | 656 } |
640 } | 657 } |
OLD | NEW |