Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: ui/android/java/src/org/chromium/ui/base/Clipboard.java

Issue 2409963003: Don't let WebView crash on copy-paste (Closed)
Patch Set: Catch generic Exception Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/Clipboard.java
diff --git a/ui/android/java/src/org/chromium/ui/base/Clipboard.java b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
index e02b58817e382f84db417e1923bbe355fc407040..4497c60fa49b925005f3322337b1146f626c9770 100644
--- a/ui/android/java/src/org/chromium/ui/base/Clipboard.java
+++ b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
@@ -67,14 +67,16 @@ public class Clipboard {
@SuppressWarnings("javadoc")
@CalledByNative
private String getCoercedText() {
- final ClipData clip = mClipboardManager.getPrimaryClip();
- if (clip != null && clip.getItemCount() > 0) {
- final CharSequence sequence = clip.getItemAt(0).coerceToText(mContext);
- if (sequence != null) {
- return sequence.toString();
- }
+ // getPrimaryClip() has been observed to throw unexpected exceptions for some devices (see
+ // crbug.com/654802 and b/31501780)
+ try {
+ return mClipboardManager.getPrimaryClip()
+ .getItemAt(0)
+ .coerceToText(mContext)
+ .toString();
+ } catch (Exception e) {
+ return null;
}
- return null;
}
/**
@@ -85,11 +87,13 @@ public class Clipboard {
*/
@CalledByNative
private String getHTMLText() {
- final ClipData clip = mClipboardManager.getPrimaryClip();
- if (clip != null && clip.getItemCount() > 0) {
- return clip.getItemAt(0).getHtmlText();
+ // getPrimaryClip() has been observed to throw unexpected exceptions for some devices (see
+ // crbug/654802 and b/31501780)
+ try {
+ return mClipboardManager.getPrimaryClip().getItemAt(0).getHtmlText();
+ } catch (Exception e) {
+ return null;
}
- return null;
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698