Bug 1322575 - Add private mode support to GeckoView. r=jchen,esawin

This commit is contained in:
Dylan Roeh 2017-04-11 16:53:20 -05:00
Родитель f50eefe823
Коммит 739267098f
4 изменённых файлов: 50 добавлений и 15 удалений

Просмотреть файл

@ -95,7 +95,7 @@ public class GeckoView extends LayerView
static native void open(Window instance, GeckoView view,
Object compositor, EventDispatcher dispatcher,
String chromeUri, GeckoBundle settings,
int screenId);
int screenId, boolean privateMode);
@Override protected native void disposeNative();
@ -209,15 +209,24 @@ public class GeckoView extends LayerView
public GeckoView(Context context) {
super(context);
init(context);
init(context, null);
}
public GeckoView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
// TODO: Convert custom attributes to GeckoViewSettings
init(context, null);
}
private void init(Context context) {
public GeckoView(Context context, final GeckoViewSettings settings) {
super(context);
final GeckoViewSettings newSettings = new GeckoViewSettings(settings, getEventDispatcher());
init(context, newSettings);
}
private void init(Context context, final GeckoViewSettings settings) {
if (GeckoAppShell.getApplicationContext() == null) {
GeckoAppShell.setApplicationContext(context.getApplicationContext());
}
@ -235,7 +244,11 @@ public class GeckoView extends LayerView
initializeView();
mListener.registerListeners();
mSettings = new GeckoViewSettings(getEventDispatcher());
if (settings == null) {
mSettings = new GeckoViewSettings(getEventDispatcher());
} else {
mSettings = settings;
}
}
@Override
@ -270,7 +283,8 @@ public class GeckoView extends LayerView
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
Window.open(mWindow, this, getCompositor(), mEventDispatcher,
mChromeUri, mSettings.asBundle(), mScreenId);
mChromeUri, mSettings.asBundle(), mScreenId,
mSettings.getBoolean(GeckoViewSettings.USE_PRIVATE_MODE));
} else {
GeckoThread.queueNativeCallUntil(
GeckoThread.State.PROFILE_READY,
@ -280,7 +294,7 @@ public class GeckoView extends LayerView
EventDispatcher.class, mEventDispatcher,
String.class, mChromeUri,
GeckoBundle.class, mSettings.asBundle(),
mScreenId);
mScreenId, mSettings.getBoolean(GeckoViewSettings.USE_PRIVATE_MODE));
}
}

Просмотреть файл

@ -24,18 +24,30 @@ public final class GeckoViewSettings {
public static final Key<Boolean> USE_TRACKING_PROTECTION =
new Key<Boolean>("useTrackingProtection");
public static final Key<Boolean> USE_PRIVATE_MODE =
new Key<Boolean>("usePrivateMode");
private final EventDispatcher mEventDispatcher;
private final GeckoBundle mBundle;
public GeckoViewSettings() {
this(null);
}
/* package */ GeckoViewSettings(EventDispatcher eventDispatcher) {
mEventDispatcher = eventDispatcher;
mBundle = new GeckoBundle();
setBoolean(USE_TRACKING_PROTECTION, false);
setBoolean(USE_PRIVATE_MODE, false);
}
public void setBoolean(Key<Boolean> key, boolean value) {
/* package */ GeckoViewSettings(GeckoViewSettings settings, EventDispatcher eventDispatcher) {
mBundle = new GeckoBundle(settings.mBundle);
mEventDispatcher = eventDispatcher;
}
public void setBoolean(final Key<Boolean> key, boolean value) {
synchronized (mBundle) {
final Object old = mBundle.get(key.text);
if (old != null && old.equals(value)) {
@ -46,7 +58,7 @@ public final class GeckoViewSettings {
dispatchUpdate();
}
public Object getBoolean(Key<Boolean> key) {
public boolean getBoolean(final Key<Boolean> key) {
synchronized (mBundle) {
return mBundle.getBoolean(key.text);
}
@ -57,6 +69,8 @@ public final class GeckoViewSettings {
}
private void dispatchUpdate() {
mEventDispatcher.dispatch("GeckoView:UpdateSettings", null);
if (mEventDispatcher != null) {
mEventDispatcher.dispatch("GeckoView:UpdateSettings", null);
}
}
}

Просмотреть файл

@ -3015,10 +3015,11 @@ public:
mozilla::jni::Object::Param,
mozilla::jni::String::Param,
mozilla::jni::Object::Param,
int32_t> Args;
int32_t,
bool> Args;
static constexpr char name[] = "open";
static constexpr char signature[] =
"(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Lorg/mozilla/gecko/EventDispatcher;Ljava/lang/String;Lorg/mozilla/gecko/util/GeckoBundle;I)V";
"(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Lorg/mozilla/gecko/EventDispatcher;Ljava/lang/String;Lorg/mozilla/gecko/util/GeckoBundle;IZ)V";
static const bool isStatic = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;

Просмотреть файл

@ -290,7 +290,8 @@ public:
jni::Object::Param aDispatcher,
jni::String::Param aChromeURI,
jni::Object::Param aSettings,
int32_t screenId);
int32_t aScreenId,
bool aPrivateMode);
// Close and destroy the nsWindow.
void Close();
@ -1209,7 +1210,8 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
jni::Object::Param aDispatcher,
jni::String::Param aChromeURI,
jni::Object::Param aSettings,
int32_t aScreenId)
int32_t aScreenId,
bool aPrivateMode)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1236,8 +1238,12 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
androidView->mSettings = java::GeckoBundle::Ref::From(aSettings);
}
nsAutoCString chromeFlags("chrome,dialog=0,resizable,scrollbars");
if (aPrivateMode) {
chromeFlags += ",private";
}
nsCOMPtr<mozIDOMWindowProxy> domWindow;
ww->OpenWindow(nullptr, url, nullptr, "chrome,dialog=0,resizable,scrollbars=yes",
ww->OpenWindow(nullptr, url, nullptr, chromeFlags.get(),
androidView, getter_AddRefs(domWindow));
MOZ_RELEASE_ASSERT(domWindow);