зеркало из https://github.com/mozilla/gecko-dev.git
Bug 906088 - part 5 - send preference requests to JS through JNI and XPConnect rather than JSON; r=blassey,mfinkle
This commit is contained in:
Родитель
b43f8d38c9
Коммит
59855089b3
|
@ -67,7 +67,9 @@ public class GeckoEvent {
|
|||
REMOVE_OBSERVER(34),
|
||||
LOW_MEMORY(35),
|
||||
NETWORK_LINK_CHANGE(36),
|
||||
TELEMETRY_HISTOGRAM_ADD(37);
|
||||
TELEMETRY_HISTOGRAM_ADD(37),
|
||||
PREFERENCES_OBSERVE(38),
|
||||
PREFERENCES_GET(39);
|
||||
|
||||
public final int value;
|
||||
|
||||
|
@ -186,6 +188,8 @@ public class GeckoEvent {
|
|||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
private String[] mPrefNames;
|
||||
|
||||
private GeckoEvent(NativeGeckoEvent event) {
|
||||
mType = event.value;
|
||||
}
|
||||
|
@ -689,6 +693,20 @@ public class GeckoEvent {
|
|||
return event;
|
||||
}
|
||||
|
||||
public static GeckoEvent createPreferencesObserveEvent(int requestId, String[] prefNames) {
|
||||
GeckoEvent event = new GeckoEvent(NativeGeckoEvent.PREFERENCES_OBSERVE);
|
||||
event.mCount = requestId;
|
||||
event.mPrefNames = prefNames;
|
||||
return event;
|
||||
}
|
||||
|
||||
public static GeckoEvent createPreferencesGetEvent(int requestId, String[] prefNames) {
|
||||
GeckoEvent event = new GeckoEvent(NativeGeckoEvent.PREFERENCES_GET);
|
||||
event.mCount = requestId;
|
||||
event.mPrefNames = prefNames;
|
||||
return event;
|
||||
}
|
||||
|
||||
public static GeckoEvent createLowMemoryEvent(int level) {
|
||||
GeckoEvent event = new GeckoEvent(NativeGeckoEvent.LOW_MEMORY);
|
||||
event.mMetaState = level;
|
||||
|
|
|
@ -28,28 +28,18 @@ public final class PrefsHelper {
|
|||
private static int sUniqueRequestId = 1;
|
||||
|
||||
public static int getPref(String prefName, PrefHandler callback) {
|
||||
JSONArray prefs = new JSONArray();
|
||||
prefs.put(prefName);
|
||||
return getPrefs(prefs, callback);
|
||||
return getPrefsInternal(new String[] { prefName }, callback);
|
||||
}
|
||||
|
||||
public static int getPrefs(String[] prefNames, PrefHandler callback) {
|
||||
JSONArray prefs = new JSONArray();
|
||||
for (String p : prefNames) {
|
||||
prefs.put(p);
|
||||
}
|
||||
return getPrefs(prefs, callback);
|
||||
return getPrefsInternal(prefNames, callback);
|
||||
}
|
||||
|
||||
public static int getPrefs(ArrayList<String> prefNames, PrefHandler callback) {
|
||||
JSONArray prefs = new JSONArray();
|
||||
for (String p : prefNames) {
|
||||
prefs.put(p);
|
||||
}
|
||||
return getPrefs(prefs, callback);
|
||||
return getPrefsInternal(prefNames.toArray(new String[prefNames.size()]), callback);
|
||||
}
|
||||
|
||||
public static int getPrefs(JSONArray prefNames, PrefHandler callback) {
|
||||
private static int getPrefsInternal(String[] prefNames, PrefHandler callback) {
|
||||
int requestId;
|
||||
synchronized (PrefsHelper.class) {
|
||||
ensureRegistered();
|
||||
|
@ -59,25 +49,12 @@ public final class PrefsHelper {
|
|||
}
|
||||
|
||||
GeckoEvent event;
|
||||
try {
|
||||
JSONObject message = new JSONObject();
|
||||
message.put("requestId", Integer.toString(requestId));
|
||||
message.put("preferences", prefNames);
|
||||
event = GeckoEvent.createBroadcastEvent(callback.isObserver() ?
|
||||
"Preferences:Observe" : "Preferences:Get", message.toString());
|
||||
GeckoAppShell.sendEventToGecko(event);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Error while composing Preferences:" +
|
||||
(callback.isObserver() ? "Observe" : "Get") + " message", e);
|
||||
|
||||
// if we failed to send the message, drop our reference to the callback because
|
||||
// otherwise it will leak since we will never get the response
|
||||
synchronized (PrefsHelper.class) {
|
||||
sCallbacks.remove(requestId);
|
||||
}
|
||||
|
||||
return -1;
|
||||
if (callback.isObserver()) {
|
||||
event = GeckoEvent.createPreferencesObserveEvent(requestId, prefNames);
|
||||
} else {
|
||||
event = GeckoEvent.createPreferencesGetEvent(requestId, prefNames);
|
||||
}
|
||||
GeckoAppShell.sendEventToGecko(event);
|
||||
|
||||
return requestId;
|
||||
}
|
||||
|
|
|
@ -278,9 +278,7 @@ var BrowserApp = {
|
|||
Services.obs.addObserver(this, "Session:Stop", false);
|
||||
Services.obs.addObserver(this, "SaveAs:PDF", false);
|
||||
Services.obs.addObserver(this, "Browser:Quit", false);
|
||||
Services.obs.addObserver(this, "Preferences:Get", false);
|
||||
Services.obs.addObserver(this, "Preferences:Set", false);
|
||||
Services.obs.addObserver(this, "Preferences:Observe", false);
|
||||
Services.obs.addObserver(this, "Preferences:RemoveObservers", false);
|
||||
Services.obs.addObserver(this, "ScrollTo:FocusedInput", false);
|
||||
Services.obs.addObserver(this, "Sanitize:ClearData", false);
|
||||
|
@ -988,18 +986,10 @@ var BrowserApp = {
|
|||
|
||||
notifyPrefObservers: function(aPref) {
|
||||
this._prefObservers[aPref].forEach(function(aRequestId) {
|
||||
let request = { requestId : aRequestId,
|
||||
preferences : [aPref] };
|
||||
this.getPreferences(request);
|
||||
this.getPreferences(aRequestId, [aPref], 1);
|
||||
}, this);
|
||||
},
|
||||
|
||||
getPreferences: function getPreferences(aPrefsRequest, aListen) {
|
||||
this.handlePreferencesRequest(aPrefsRequest.requestId,
|
||||
aPrefsRequest.preferences,
|
||||
aListen);
|
||||
},
|
||||
|
||||
handlePreferencesRequest: function handlePreferencesRequest(aRequestId,
|
||||
aPrefNames,
|
||||
aListen) {
|
||||
|
@ -1447,18 +1437,10 @@ var BrowserApp = {
|
|||
this.saveAsPDF(browser);
|
||||
break;
|
||||
|
||||
case "Preferences:Get":
|
||||
this.getPreferences(JSON.parse(aData));
|
||||
break;
|
||||
|
||||
case "Preferences:Set":
|
||||
this.setPreferences(aData);
|
||||
break;
|
||||
|
||||
case "Preferences:Observe":
|
||||
this.getPreferences(JSON.parse(aData), true);
|
||||
break;
|
||||
|
||||
case "Preferences:RemoveObservers":
|
||||
this.removePreferenceObservers(aData);
|
||||
break;
|
||||
|
@ -1536,6 +1518,14 @@ var BrowserApp = {
|
|||
return this.getTabForId(tabId);
|
||||
},
|
||||
|
||||
getPreferences: function getPreferences(requestId, prefNames, count) {
|
||||
this.handlePreferencesRequest(requestId, prefNames, false);
|
||||
},
|
||||
|
||||
observePreferences: function observePreferences(requestId, prefNames, count) {
|
||||
this.handlePreferencesRequest(requestId, prefNames, true);
|
||||
},
|
||||
|
||||
// This method will print a list from fromIndex to toIndex, optionally
|
||||
// selecting selIndex(if fromIndex<=selIndex<=toIndex)
|
||||
showHistory: function(fromIndex, toIndex, selIndex) {
|
||||
|
|
|
@ -541,6 +541,22 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|||
mObserversHash.Remove(curEvent->Characters());
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::PREFERENCES_GET:
|
||||
case AndroidGeckoEvent::PREFERENCES_OBSERVE: {
|
||||
const nsTArray<nsString> &prefNames = curEvent->PrefNames();
|
||||
size_t count = prefNames.Length();
|
||||
nsAutoArrayPtr<const PRUnichar*> prefNamePtrs(new const PRUnichar*[count]);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
prefNamePtrs[i] = prefNames[i].get();
|
||||
}
|
||||
|
||||
if (curEvent->Type() == AndroidGeckoEvent::PREFERENCES_GET) {
|
||||
mBrowserApp->GetPreferences(curEvent->RequestId(), prefNamePtrs, count);
|
||||
} else {
|
||||
mBrowserApp->ObservePreferences(curEvent->RequestId(), prefNamePtrs, count);
|
||||
}
|
||||
}
|
||||
|
||||
case AndroidGeckoEvent::LOW_MEMORY:
|
||||
// TODO hook in memory-reduction stuff for different levels here
|
||||
if (curEvent->MetaState() >= AndroidGeckoEvent::MEMORY_PRESSURE_MEDIUM) {
|
||||
|
|
|
@ -11,9 +11,15 @@ interface nsIBrowserTab : nsISupports {
|
|||
readonly attribute float scale;
|
||||
};
|
||||
|
||||
[scriptable, uuid(d10377b4-1c90-493a-a532-63cb3f16ee2b)]
|
||||
[scriptable, uuid(6455c49b-7497-4eb6-b137-c9e9b68462ec)]
|
||||
interface nsIAndroidBrowserApp : nsISupports {
|
||||
nsIBrowserTab getBrowserTab(in int32_t tabId);
|
||||
void getPreferences(in int32_t requestId,
|
||||
[array, size_is(count)] in wstring prefNames,
|
||||
in unsigned long count);
|
||||
void observePreferences(in int32_t requestId,
|
||||
[array, size_is(count)] in wstring prefNames,
|
||||
in unsigned long count);
|
||||
};
|
||||
[scriptable, uuid(59cfcb35-69b7-47b2-8155-32b193272666)]
|
||||
interface nsIAndroidViewport : nsISupports {
|
||||
|
|
Загрузка…
Ссылка в новой задаче