Index: content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java |
index 4ea75bdf7b623cf5889b5e20a017e3b0556f4564..ce2dae20dcfbbf19c9735ec65e1c4c1e640cec95 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/SandboxedProcessLauncher.java |
@@ -9,7 +9,9 @@ import android.os.RemoteException; |
import android.util.Log; |
import android.view.Surface; |
+import java.util.Arrays; |
import java.util.ArrayList; |
+import java.util.List; |
import java.util.Map; |
import java.util.concurrent.ConcurrentHashMap; |
@@ -17,7 +19,6 @@ import org.chromium.base.CalledByNative; |
import org.chromium.base.JNINamespace; |
import org.chromium.base.ThreadUtils; |
import org.chromium.content.app.LibraryLoader; |
-import org.chromium.content.common.CommandLine; |
import org.chromium.content.common.ISandboxedProcessCallback; |
import org.chromium.content.common.ISandboxedProcessService; |
@@ -29,6 +30,10 @@ import org.chromium.content.common.ISandboxedProcessService; |
public class SandboxedProcessLauncher { |
private static String TAG = "SandboxedProcessLauncher"; |
+ private static final int CALLBACK_FOR_UNKNOWN_PROCESS = 0; |
+ private static final int CALLBACK_FOR_GPU_PROCESS = 1; |
+ private static final int CALLBACK_FOR_RENDERER_PROCESS = 2; |
+ |
// The upper limit on the number of simultaneous service process instances supported. |
// This must not exceed total number of SandboxedProcessServiceX classes declared in |
// this package, and defined as services in the embedding application's manifest file. |
@@ -206,7 +211,17 @@ public class SandboxedProcessLauncher { |
nativeOnSandboxedProcessStarted(clientContext, pid); |
} |
}; |
- connection.setupConnection(commandLine, filesToBeMapped, createCallback(), onConnect); |
+ int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; |
+ List<String> commandLineList = Arrays.asList(commandLine); |
+ if (commandLineList.contains("--type=renderer")) { |
+ callbackType = CALLBACK_FOR_RENDERER_PROCESS; |
+ } else if (commandLineList.contains("--type=gpu-process")) { |
+ callbackType = CALLBACK_FOR_GPU_PROCESS; |
+ } |
+ assert callbackType != CALLBACK_FOR_UNKNOWN_PROCESS; |
+ |
+ connection.setupConnection( |
+ commandLine, filesToBeMapped, createCallback(callbackType), onConnect); |
} |
/** |
@@ -260,7 +275,7 @@ public class SandboxedProcessLauncher { |
/** |
* This implementation is used to receive callbacks from the remote service. |
*/ |
- private static ISandboxedProcessCallback createCallback() { |
+ private static ISandboxedProcessCallback createCallback(final int callbackType) { |
return new ISandboxedProcessCallback.Stub() { |
/** |
* This is called by the remote service regularly to tell us about |
@@ -269,13 +284,34 @@ public class SandboxedProcessLauncher { |
* NOT be running in our main thread -- so, to update the UI, we need |
* to use a Handler. |
*/ |
+ @Override |
public void establishSurfacePeer( |
int pid, Surface surface, int primaryID, int secondaryID) { |
- // TODO(sievers): This should call into native and pass the Surface to the |
- // right media player instance. |
+ // Do not allow a malicious renderer to connect to a producer. This is only |
+ // used from stream textures managed by the GPU process. |
+ if (callbackType != CALLBACK_FOR_GPU_PROCESS) { |
+ Log.e(TAG, "Illegal callback for non-GPU process."); |
+ return; |
+ } |
+ |
+ nativeEstablishSurfacePeer(pid, surface, primaryID, secondaryID); |
+ } |
+ |
+ @Override |
+ public Surface getViewSurface(int surfaceId) { |
+ // Do not allow a malicious renderer to get to our view surface. |
+ if (callbackType != CALLBACK_FOR_GPU_PROCESS) { |
+ Log.e(TAG, "Illegal callback for non-GPU process."); |
+ return null; |
+ } |
+ |
+ return nativeGetViewSurface(surfaceId); |
} |
}; |
}; |
private static native void nativeOnSandboxedProcessStarted(int clientContext, int pid); |
+ private static native Surface nativeGetViewSurface(int surfaceId); |
+ private static native void nativeEstablishSurfacePeer( |
+ int pid, Surface surface, int primaryID, int secondaryID); |
} |