OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.browseractions; | 5 package org.chromium.chrome.browser.browseractions; |
6 | 6 |
7 import android.app.PendingIntent; | 7 import android.app.PendingIntent; |
8 import android.support.customtabs.browseractions.BrowserActionItem; | 8 import android.support.customtabs.browseractions.BrowserActionItem; |
9 import android.support.customtabs.browseractions.BrowserActionsIntent; | 9 import android.support.customtabs.browseractions.BrowserActionsIntent; |
10 import android.util.Pair; | 10 import android.util.Pair; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 private final ContextMenuParams mCurrentContextMenuParams; | 57 private final ContextMenuParams mCurrentContextMenuParams; |
58 private final BrowserActionsContextMenuItemDelegate mDelegate; | 58 private final BrowserActionsContextMenuItemDelegate mDelegate; |
59 private final BrowserActionActivity mActivity; | 59 private final BrowserActionActivity mActivity; |
60 private final Callback<Integer> mItemSelectedCallback; | 60 private final Callback<Integer> mItemSelectedCallback; |
61 private final Runnable mOnMenuShown; | 61 private final Runnable mOnMenuShown; |
62 private final Runnable mOnMenuClosed; | 62 private final Runnable mOnMenuClosed; |
63 private final Runnable mOnShareClickedRunnable; | 63 private final Runnable mOnShareClickedRunnable; |
64 | 64 |
65 private final List<Pair<Integer, List<ContextMenuItem>>> mItems; | 65 private final List<Pair<Integer, List<ContextMenuItem>>> mItems; |
66 | 66 |
67 private boolean mIsOpenInBackgroundPending; | |
68 | |
67 public BrowserActionsContextMenuHelper(BrowserActionActivity activity, Conte xtMenuParams params, | 69 public BrowserActionsContextMenuHelper(BrowserActionActivity activity, Conte xtMenuParams params, |
68 List<BrowserActionItem> customItems, String sourcePackageName) { | 70 List<BrowserActionItem> customItems, String sourcePackageName) { |
69 mActivity = activity; | 71 mActivity = activity; |
70 mCurrentContextMenuParams = params; | 72 mCurrentContextMenuParams = params; |
71 mOnMenuShown = new Runnable() { | 73 mOnMenuShown = new Runnable() { |
72 @Override | 74 @Override |
73 public void run() { | 75 public void run() { |
74 mActivity.onMenuShown(); | 76 mActivity.onMenuShown(); |
75 } | 77 } |
76 }; | 78 }; |
77 mOnMenuClosed = new Runnable() { | 79 mOnMenuClosed = new Runnable() { |
78 @Override | 80 @Override |
79 public void run() { | 81 public void run() { |
80 mActivity.finish(); | 82 if (!mIsOpenInBackgroundPending) { |
83 mActivity.finish(); | |
Yusuf
2017/06/29 19:05:26
one line
ltian
2017/06/30 23:57:56
The "git cl format" forces this to be into multipl
| |
84 } | |
81 } | 85 } |
82 }; | 86 }; |
83 mItemSelectedCallback = new Callback<Integer>() { | 87 mItemSelectedCallback = new Callback<Integer>() { |
84 @Override | 88 @Override |
85 public void onResult(Integer result) { | 89 public void onResult(Integer result) { |
86 onItemSelected(result); | 90 onItemSelected(result); |
87 } | 91 } |
88 }; | 92 }; |
89 mOnShareClickedRunnable = new Runnable() { | 93 mOnShareClickedRunnable = new Runnable() { |
90 @Override | 94 @Override |
(...skipping 29 matching lines...) Expand all Loading... | |
120 for (int i = 0; i < customItems.size() && i < BrowserActionsIntent.MAX_C USTOM_ITEMS; i++) { | 124 for (int i = 0; i < customItems.size() && i < BrowserActionsIntent.MAX_C USTOM_ITEMS; i++) { |
121 items.add(new BrowserActionsCustomContextMenuItem( | 125 items.add(new BrowserActionsCustomContextMenuItem( |
122 CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i))) ; | 126 CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i))) ; |
123 mCustomItemActionMap.put( | 127 mCustomItemActionMap.put( |
124 CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).g etAction()); | 128 CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).g etAction()); |
125 } | 129 } |
126 } | 130 } |
127 | 131 |
128 private boolean onItemSelected(int itemId) { | 132 private boolean onItemSelected(int itemId) { |
129 if (itemId == R.id.browser_actions_open_in_background) { | 133 if (itemId == R.id.browser_actions_open_in_background) { |
130 mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()) ; | 134 if (mActivity.isNatvieInitialized()) { |
135 mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUr l()); | |
Yusuf
2017/06/29 19:05:26
maybe this is all the delegate's job?
ltian
2017/06/30 23:57:56
I feel the delegate is only responsible for execut
| |
136 } else { | |
137 mIsOpenInBackgroundPending = true; | |
138 mActivity.waitNativeInitialized(); | |
139 } | |
131 } else if (itemId == R.id.browser_actions_open_in_incognito_tab) { | 140 } else if (itemId == R.id.browser_actions_open_in_incognito_tab) { |
132 mDelegate.onOpenInIncognitoTab(mCurrentContextMenuParams.getLinkUrl( )); | 141 mDelegate.onOpenInIncognitoTab(mCurrentContextMenuParams.getLinkUrl( )); |
133 } else if (itemId == R.id.browser_actions_save_link_as) { | 142 } else if (itemId == R.id.browser_actions_save_link_as) { |
134 mDelegate.startDownload(mCurrentContextMenuParams.getLinkUrl()); | 143 mDelegate.startDownload(mCurrentContextMenuParams.getLinkUrl()); |
135 } else if (itemId == R.id.browser_actions_copy_address) { | 144 } else if (itemId == R.id.browser_actions_copy_address) { |
136 mDelegate.onSaveToClipboard(mCurrentContextMenuParams.getLinkUrl()); | 145 mDelegate.onSaveToClipboard(mCurrentContextMenuParams.getLinkUrl()); |
137 } else if (itemId == R.id.browser_actions_share) { | 146 } else if (itemId == R.id.browser_actions_share) { |
138 mDelegate.share(false, mCurrentContextMenuParams.getLinkUrl()); | 147 mDelegate.share(false, mCurrentContextMenuParams.getLinkUrl()); |
139 } else if (mCustomItemActionMap.indexOfKey(itemId) >= 0) { | 148 } else if (mCustomItemActionMap.indexOfKey(itemId) >= 0) { |
140 mDelegate.onCustomItemSelected(mCustomItemActionMap.get(itemId)); | 149 mDelegate.onCustomItemSelected(mCustomItemActionMap.get(itemId)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 181 |
173 @Override | 182 @Override |
174 public void onViewAttachedToWindow(View view) { | 183 public void onViewAttachedToWindow(View view) { |
175 if (view.showContextMenu()) { | 184 if (view.showContextMenu()) { |
176 mOnMenuShown.run(); | 185 mOnMenuShown.run(); |
177 } | 186 } |
178 } | 187 } |
179 | 188 |
180 @Override | 189 @Override |
181 public void onViewDetachedFromWindow(View v) {} | 190 public void onViewDetachedFromWindow(View v) {} |
191 | |
192 /** | |
193 * Finishes all pending actions which requires Chrome native libraries. | |
194 */ | |
195 public void handlePendingActions() { | |
196 if (mIsOpenInBackgroundPending) { | |
197 mIsOpenInBackgroundPending = false; | |
198 mDelegate.onOpenInBackground(mCurrentContextMenuParams.getLinkUrl()) ; | |
199 mActivity.finish(); | |
200 } | |
201 } | |
182 } | 202 } |
OLD | NEW |