From 65183064f18d6076abeda5d499a4df70fe719725 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Sat, 18 Feb 2012 18:32:50 -0500 Subject: [PATCH] [mq]: meta_viewport_query --HG-- extra : rebase_source : 586dfca0cf7d9446e532ecfa38fd126225db36b9 --- mobile/android/base/GeckoApp.java | 10 +++++++++ mobile/android/base/GeckoEvent.java | 22 ++++++++++++++++++++ widget/android/AndroidJavaWrappers.cpp | 23 ++++++++++++++++----- widget/android/AndroidJavaWrappers.h | 7 +++++++ widget/android/nsAppShell.cpp | 28 +++++++++++++++++++++++++- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index c55b95d3208..fc827152fef 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1302,6 +1302,16 @@ abstract public class GeckoApp Runnable r = new SessionSnapshotRunnable(tab); GeckoAppShell.getHandler().postDelayed(r, 500); } + + GeckoAppShell.sendEventToGecko( + GeckoEvent.createMetaViewportQueryEvent(tab.getId(), + new GeckoEvent.Callback() { + public void callback(GeckoEvent ev, String data) { + Log.i(LOGTAG, "Meta Viewport Data:" + data); + // To do: do something with this data + } + }) + ); } void handleShowToast(final String message, final String duration) { diff --git a/mobile/android/base/GeckoEvent.java b/mobile/android/base/GeckoEvent.java index bfea49b4edc..2c9c998dc13 100644 --- a/mobile/android/base/GeckoEvent.java +++ b/mobile/android/base/GeckoEvent.java @@ -62,6 +62,10 @@ import android.util.Log; */ public class GeckoEvent { + public interface Callback { + public void callback(GeckoEvent event, String jsonData); + } + private static final String LOGTAG = "GeckoEvent"; private static final int INVALID = -1; @@ -89,6 +93,7 @@ public class GeckoEvent { private static final int PROXIMITY_EVENT = 23; private static final int ACTIVITY_RESUMING = 24; private static final int SCREENSHOT = 25; + private static final int META_VIEWPORT_QUERY = 26; public static final int IME_COMPOSITION_END = 0; public static final int IME_COMPOSITION_BEGIN = 1; @@ -136,6 +141,9 @@ public class GeckoEvent { public boolean mCanBeMetered; public int mNativeWindow; + public int mTabId; + + Callback mCallback; private GeckoEvent(int evType) { mType = evType; @@ -382,6 +390,14 @@ public class GeckoEvent { return event; } + public static GeckoEvent createMetaViewportQueryEvent(int tabId, Callback callback) { + Log.i("GeckoEvent", "createMetaViewportQueryEvent"); + GeckoEvent event = new GeckoEvent(META_VIEWPORT_QUERY); + event.mCallback = callback; + event.mTabId = tabId; + return event; + } + public static GeckoEvent createLoadEvent(String uri) { GeckoEvent event = new GeckoEvent(LOAD_URI); event.mCharacters = uri; @@ -409,4 +425,10 @@ public class GeckoEvent { event.mMetaState = tabId; return event; } + + public void doCallback(String jsonData) { + if (mCallback != null) { + mCallback.callback(this, jsonData); + } + } } diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index ced9ccbdc11..58e208af92a 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -76,6 +76,8 @@ jfieldID AndroidGeckoEvent::jLocationField = 0; jfieldID AndroidGeckoEvent::jAddressField = 0; jfieldID AndroidGeckoEvent::jBandwidthField = 0; jfieldID AndroidGeckoEvent::jCanBeMeteredField = 0; +jfieldID AndroidGeckoEvent::jTabIdField = 0; +jmethodID AndroidGeckoEvent::jDoCallbackMethod = 0; jclass AndroidPoint::jPointClass = 0; jfieldID AndroidPoint::jXField = 0; @@ -208,6 +210,9 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv) jAddressField = getField("mAddress", "Landroid/location/Address;"); jBandwidthField = getField("mBandwidth", "D"); jCanBeMeteredField = getField("mCanBeMetered", "Z"); + + jTabIdField = getField("mTabId", "I"); + jDoCallbackMethod = getMethod("doCallback", "(Ljava/lang/String;)V"); } void @@ -585,6 +590,10 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj) break; } + case META_VIEWPORT_QUERY: + mTabId = jenv->GetIntField(jobj, jTabIdField); + break; + case VIEWPORT: case BROADCAST: { ReadCharactersField(jenv); @@ -616,11 +625,6 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj) break; } - case SCREENSHOT: { - mMetaState = jenv->GetIntField(jobj, jMetaStateField); - ReadPointArray(mPoints, jenv, jPoints, 2); - } - default: break; } @@ -665,6 +669,15 @@ AndroidPoint::Init(JNIEnv *jenv, jobject jobj) } } +void +AndroidGeckoEvent::DoCallback(const nsAString& data) { + JNIEnv* env = AndroidBridge::GetJNIEnv(); + if (!env) + return; + jstring jData = env->NewString(nsPromiseFlatString(data).get(), data.Length()); + env->CallVoidMethod(wrapped_obj, jDoCallbackMethod, jData); +} + void AndroidGeckoGLLayerClient::Init(jobject jobj) { diff --git a/widget/android/AndroidJavaWrappers.h b/widget/android/AndroidJavaWrappers.h index f096a132e32..5b71b842015 100644 --- a/widget/android/AndroidJavaWrappers.h +++ b/widget/android/AndroidJavaWrappers.h @@ -546,6 +546,8 @@ public: nsGeoPositionAddress* GeoAddress() { return mGeoAddress; } double Bandwidth() { return mBandwidth; } bool CanBeMetered() { return mCanBeMetered; } + int TabId() { return mTabId; } + void DoCallback(const nsAString& data); protected: int mAction; @@ -571,6 +573,7 @@ protected: nsRefPtr mGeoAddress; double mBandwidth; bool mCanBeMetered; + int mTabId; void ReadIntArray(nsTArray &aVals, JNIEnv *jenv, @@ -625,6 +628,9 @@ protected: static jfieldID jBandwidthField; static jfieldID jCanBeMeteredField; + static jfieldID jTabIdField; + + static jmethodID jDoCallbackMethod; public: enum { @@ -653,6 +659,7 @@ public: PROXIMITY_EVENT = 23, ACTIVITY_RESUMING = 24, SCREENSHOT = 25, + META_VIEWPORT_QUERY = 26, dummy_java_enum_list_end }; diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp index 37192c2c24a..100630bf892 100644 --- a/widget/android/nsAppShell.cpp +++ b/widget/android/nsAppShell.cpp @@ -60,7 +60,7 @@ #include #include #include - +#include "nsContentUtils.h" #ifdef MOZ_ANDROID_HISTORY #include "nsAndroidHistory.h" #endif @@ -453,6 +453,32 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait) break; } + + case AndroidGeckoEvent::META_VIEWPORT_QUERY: + { + nsCOMPtr domWindow; + mBrowserApp->GetWindowForTab(curEvent->TabId(), getter_AddRefs(domWindow)); + if (!domWindow) + break; + nsCOMPtr domDocument; + domWindow->GetDocument(getter_AddRefs(domDocument)); + nsCOMPtr doc = do_QueryInterface(domDocument); + ViewportInfo vi = nsContentUtils::GetViewportInfo(doc); + nsAutoString data; + data.AppendLiteral("{"); + data.AppendPrintf("\"defaultZoom\": %f,", vi.defaultZoom); + data.AppendPrintf("\"minZoom\": %f,", vi.minZoom); + data.AppendPrintf("\"maxZoom\": %f,", vi.maxZoom); + data.AppendPrintf("\"width\": %d,", vi.width); + data.AppendPrintf("\"height\": %d,", vi.height); + data.AppendPrintf("\"autoSize\": %s,", vi.autoSize ? "true" : "false"); + data.AppendPrintf("\"allowZoom\": %s,", vi.allowZoom ? "true" : "false"); + data.AppendPrintf("\"autoScale\": %s", vi.autoScale ? "true" : "false"); + data.AppendLiteral("}"); + + curEvent->DoCallback(data); + } + break; case AndroidGeckoEvent::VIEWPORT: case AndroidGeckoEvent::BROADCAST: {