Skip to content

Commit

Permalink
Implement Copy Paste (#1883)
Browse files Browse the repository at this point in the history
* Implement Copy Paste

* Address review feedback

* Fix rebase issue
  • Loading branch information
MortimerGoro committed Oct 14, 2019
1 parent f13c317 commit a0a133f
Show file tree
Hide file tree
Showing 36 changed files with 1,026 additions and 512 deletions.
Expand Up @@ -20,6 +20,7 @@

import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.GeckoResponse;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoSession;
Expand Down Expand Up @@ -54,7 +55,7 @@
public class SessionStack implements ContentBlocking.Delegate, GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate, GeckoSession.TextInputDelegate,
GeckoSession.PromptDelegate, GeckoSession.MediaDelegate, GeckoSession.HistoryDelegate,
SharedPreferences.OnSharedPreferenceChangeListener {
GeckoSession.SelectionActionDelegate, SharedPreferences.OnSharedPreferenceChangeListener {

private static final String LOGTAG = SystemUtils.createLogtag(SessionStack.class);
// You can test a local file using: "resource://android/assets/webvr/index.html"
Expand All @@ -66,6 +67,7 @@ public class SessionStack implements ContentBlocking.Delegate, GeckoSession.Navi
private transient LinkedList<SessionChangeListener> mSessionChangeListeners;
private transient LinkedList<GeckoSession.TextInputDelegate> mTextInputListeners;
private transient LinkedList<VideoAvailabilityListener> mVideoAvailabilityListeners;
private transient LinkedList<GeckoSession.SelectionActionDelegate> mSelectionActionListeners;
private transient UserAgentOverride mUserAgentOverride;

private transient GeckoSession mCurrentSession;
Expand All @@ -92,6 +94,7 @@ protected SessionStack(Context context, GeckoRuntime runtime, boolean usePrivate
mSessionChangeListeners = new LinkedList<>();
mTextInputListeners = new LinkedList<>();
mVideoAvailabilityListeners = new LinkedList<>();
mSelectionActionListeners = new LinkedList<>();

if (mPrefs != null) {
mPrefs.registerOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -122,6 +125,7 @@ protected void shutdown() {
mSessionChangeListeners.clear();
mTextInputListeners.clear();
mVideoAvailabilityListeners.clear();
mSelectionActionListeners.clear();

if (mPrefs != null) {
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -267,6 +271,27 @@ public void removeVideoAvailabilityListener(VideoAvailabilityListener aListener)
mVideoAvailabilityListeners.remove(aListener);
}

public void addSelectionActionListener(GeckoSession.SelectionActionDelegate aListener) {
mSelectionActionListeners.add(aListener);
}

public void removeSelectionActionListener(GeckoSession.ContentDelegate aListener) {
mSelectionActionListeners.remove(aListener);
}

private void setUpListeners(GeckoSession aSession) {
aSession.setNavigationDelegate(this);
aSession.setProgressDelegate(this);
aSession.setContentDelegate(this);
aSession.getTextInput().setDelegate(this);
aSession.setPermissionDelegate(mPermissionDelegate);
aSession.setPromptDelegate(mPromptDelegate);
aSession.setContentBlockingDelegate(this);
aSession.setMediaDelegate(this);
aSession.setHistoryDelegate(this);
aSession.setSelectionActionDelegate(this);
}

public void restore(SessionStack store, int currentSessionId) {
mSessions.clear();

Expand Down Expand Up @@ -301,16 +326,8 @@ public void restore(SessionStack store, int currentSessionId) {
}

int newSessionId = state.mSession.hashCode();
setUpListeners(state.mSession);

state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setContentDelegate(this);
state.mSession.getTextInput().setDelegate(this);
state.mSession.setPermissionDelegate(mPermissionDelegate);
state.mSession.setPromptDelegate(mPromptDelegate);
state.mSession.setContentBlockingDelegate(this);
state.mSession.setMediaDelegate(this);
state.mSession.setHistoryDelegate(this);
for (SessionChangeListener listener: mSessionChangeListeners) {
listener.onNewSession(state.mSession, newSessionId);
}
Expand Down Expand Up @@ -368,15 +385,7 @@ private int createSession(@NonNull SessionSettings aSettings) {
state.mSession.getSettings().setSuspendMediaWhenInactive(aSettings.isSuspendMediaWhenInactiveEnabled());
state.mSession.getSettings().setUserAgentMode(aSettings.getUserAgentMode());
state.mSession.getSettings().setUserAgentOverride(aSettings.getUserAgentOverride());
state.mSession.setNavigationDelegate(this);
state.mSession.setProgressDelegate(this);
state.mSession.setContentDelegate(this);
state.mSession.getTextInput().setDelegate(this);
state.mSession.setPermissionDelegate(mPermissionDelegate);
state.mSession.setPromptDelegate(mPromptDelegate);
state.mSession.setContentBlockingDelegate(this);
state.mSession.setMediaDelegate(this);
state.mSession.setHistoryDelegate(this);
setUpListeners(state.mSession);
for (SessionChangeListener listener: mSessionChangeListeners) {
listener.onNewSession(state.mSession, result);
}
Expand Down Expand Up @@ -417,6 +426,7 @@ private void removeSession(int aSessionId) {
session.setContentBlockingDelegate(null);
session.setMediaDelegate(null);
session.setHistoryDelegate(null);
session.setSelectionActionDelegate(this);
mSessions.remove(aSessionId);
for (SessionChangeListener listener: mSessionChangeListeners) {
listener.onRemoveSession(session, aSessionId);
Expand Down Expand Up @@ -1419,4 +1429,24 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}
}

// GeckoSession.SelectionActionDelegate

@Override
public void onShowActionRequest(@NonNull GeckoSession aSession, @NonNull Selection selection, @NonNull String[] strings, @NonNull GeckoResponse<String> geckoResponse) {
if (aSession == mCurrentSession) {
for (GeckoSession.SelectionActionDelegate listener : mSelectionActionListeners) {
listener.onShowActionRequest(aSession, selection, strings, geckoResponse);
}
}
}

@Override
public void onHideAction(@NonNull GeckoSession aSession, int aHideReason) {
if (aSession == mCurrentSession) {
for (GeckoSession.SelectionActionDelegate listener : mSelectionActionListeners) {
listener.onHideAction(aSession, aHideReason);
}
}
}
}

This file was deleted.

This file was deleted.

104 changes: 0 additions & 104 deletions app/src/common/shared/org/mozilla/vrbrowser/ui/views/ContextMenu.java

This file was deleted.

0 comments on commit a0a133f

Please sign in to comment.