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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java

Issue 258273002: Cut and Copy option should not be avilable for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased because of conflict in AUTHORS file Created 6 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.ClipboardManager; 7 import android.content.ClipboardManager;
8 import android.content.Context; 8 import android.content.Context;
9 import android.view.ActionMode; 9 import android.view.ActionMode;
10 import android.view.Menu; 10 import android.view.Menu;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 /** 65 /**
66 * @return Whether or not share is available. 66 * @return Whether or not share is available.
67 */ 67 */
68 boolean isShareAvailable(); 68 boolean isShareAvailable();
69 69
70 /** 70 /**
71 * @return Whether or not web search is available. 71 * @return Whether or not web search is available.
72 */ 72 */
73 boolean isWebSearchAvailable(); 73 boolean isWebSearchAvailable();
74
75 /**
76 * @return true if the current selection is of password type.
77 */
78 boolean isSelectionPassword();
74 } 79 }
75 80
76 private final Context mContext; 81 private final Context mContext;
77 private final ActionHandler mActionHandler; 82 private final ActionHandler mActionHandler;
78 private final boolean mIncognito; 83 private final boolean mIncognito;
79 private boolean mEditable; 84 private boolean mEditable;
85 private boolean mIsPasswordType;
80 86
81 protected SelectActionModeCallback( 87 protected SelectActionModeCallback(
82 Context context, ActionHandler actionHandler, boolean incognito) { 88 Context context, ActionHandler actionHandler, boolean incognito) {
83 mContext = context; 89 mContext = context;
84 mActionHandler = actionHandler; 90 mActionHandler = actionHandler;
85 mIncognito = incognito; 91 mIncognito = incognito;
86 } 92 }
87 93
88 protected Context getContext() { 94 protected Context getContext() {
89 return mContext; 95 return mContext;
90 } 96 }
91 97
92 @Override 98 @Override
93 public boolean onCreateActionMode(ActionMode mode, Menu menu) { 99 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
94 mode.setTitle(null); 100 mode.setTitle(null);
95 mode.setSubtitle(null); 101 mode.setSubtitle(null);
96 mEditable = mActionHandler.isSelectionEditable(); 102 mEditable = mActionHandler.isSelectionEditable();
103 mIsPasswordType = mActionHandler.isSelectionPassword();
97 createActionMenu(mode, menu); 104 createActionMenu(mode, menu);
98 return true; 105 return true;
99 } 106 }
100 107
101 @Override 108 @Override
102 public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 109 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
103 boolean isEditableNow = mActionHandler.isSelectionEditable(); 110 boolean isEditableNow = mActionHandler.isSelectionEditable();
104 if (mEditable != isEditableNow) { 111 boolean isPasswordNow = mActionHandler.isSelectionPassword();
112 if (mEditable != isEditableNow || mIsPasswordType != isPasswordNow) {
105 mEditable = isEditableNow; 113 mEditable = isEditableNow;
114 mIsPasswordType = isPasswordNow;
106 menu.clear(); 115 menu.clear();
107 createActionMenu(mode, menu); 116 createActionMenu(mode, menu);
108 return true; 117 return true;
109 } 118 }
110 return false; 119 return false;
111 } 120 }
112 121
113 private void createActionMenu(ActionMode mode, Menu menu) { 122 private void createActionMenu(ActionMode mode, Menu menu) {
114 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu); 123 mode.getMenuInflater().inflate(R.menu.select_action_menu, menu);
115 if (!mEditable || !canPaste()) { 124 if (!mEditable || !canPaste()) {
116 menu.removeItem(R.id.select_action_menu_paste); 125 menu.removeItem(R.id.select_action_menu_paste);
117 } 126 }
118 127
119 if (!mEditable) { 128 if (!mEditable) {
120 menu.removeItem(R.id.select_action_menu_cut); 129 menu.removeItem(R.id.select_action_menu_cut);
121 } 130 }
122 131
123 if (mEditable || !mActionHandler.isShareAvailable()) { 132 if (mEditable || !mActionHandler.isShareAvailable()) {
124 menu.removeItem(R.id.select_action_menu_share); 133 menu.removeItem(R.id.select_action_menu_share);
125 } 134 }
126 135
127 if (mEditable || mIncognito || !mActionHandler.isWebSearchAvailable()) { 136 if (mEditable || mIncognito || !mActionHandler.isWebSearchAvailable()) {
128 menu.removeItem(R.id.select_action_menu_web_search); 137 menu.removeItem(R.id.select_action_menu_web_search);
129 } 138 }
139 if (mIsPasswordType) {
140 menu.removeItem(R.id.select_action_menu_copy);
141 menu.removeItem(R.id.select_action_menu_cut);
142 }
130 } 143 }
131 144
132 @Override 145 @Override
133 public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 146 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
134 int id = item.getItemId(); 147 int id = item.getItemId();
135 148
136 if (id == R.id.select_action_menu_select_all) { 149 if (id == R.id.select_action_menu_select_all) {
137 mActionHandler.selectAll(); 150 mActionHandler.selectAll();
138 } else if (id == R.id.select_action_menu_cut) { 151 } else if (id == R.id.select_action_menu_cut) {
139 mActionHandler.cut(); 152 mActionHandler.cut();
(...skipping 18 matching lines...) Expand all
158 public void onDestroyActionMode(ActionMode mode) { 171 public void onDestroyActionMode(ActionMode mode) {
159 mActionHandler.onDestroyActionMode(); 172 mActionHandler.onDestroyActionMode();
160 } 173 }
161 174
162 private boolean canPaste() { 175 private boolean canPaste() {
163 ClipboardManager clipMgr = (ClipboardManager) 176 ClipboardManager clipMgr = (ClipboardManager)
164 getContext().getSystemService(Context.CLIPBOARD_SERVICE); 177 getContext().getSystemService(Context.CLIPBOARD_SERVICE);
165 return clipMgr.hasPrimaryClip(); 178 return clipMgr.hasPrimaryClip();
166 } 179 }
167 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698