summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2019-07-25 23:49:47 +0200
committerJan Holesovsky <kendy@collabora.com>2019-07-26 02:53:36 +0200
commitd410ff0e1751e120d793e6a4ee4728924db7df38 (patch)
tree753d0164bcb02d7ebb8d0bd4f8b6cf88cd79b577
parent8a43db7586c606048111b1058806ecfa17d67780 (diff)
android: Allow passing FileInfo via Intent() down to the document.coas-0.2.0
This is particularly useful for TemplateSource which can be used to create a new document from template. Change-Id: I97d03b91d7bc39a3b225649e1237404961b7c8ae
-rw-r--r--android/lib/src/main/cpp/androidapp.cpp32
-rw-r--r--android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java11
-rw-r--r--wsd/LOOLWSD.cpp22
-rw-r--r--wsd/LOOLWSD.hpp4
-rw-r--r--wsd/Storage.cpp22
5 files changed, 76 insertions, 15 deletions
diff --git a/android/lib/src/main/cpp/androidapp.cpp b/android/lib/src/main/cpp/androidapp.cpp
index 5f89ffcc4..99818e32b 100644
--- a/android/lib/src/main/cpp/androidapp.cpp
+++ b/android/lib/src/main/cpp/androidapp.cpp
@@ -30,6 +30,7 @@ const int SHOW_JS_MAXLEN = 70;
int loolwsd_server_socket_fd = -1;
static std::string fileURL;
+static std::string fileInfo;
static int fakeClientFd;
static int closeNotificationPipeForForwardingThread[2] = {-1, -1};
static JavaVM* javaVM = nullptr;
@@ -237,16 +238,24 @@ Java_org_libreoffice_androidlib_LOActivity_postMobileMessageNative(JNIEnv *env,
assert(false);
}).detach();
- // First we simply send it the URL. This corresponds to the GET request with Upgrade to
- // WebSocket.
- LOG_DBG("Actually sending to Online:" << fileURL);
+ // First we simply send it the URL. This corresponds to the GET
+ // request with Upgrade to WebSocket.
+ // The 2nd line of this is fileInfo that is a JSON, equivalent to
+ // the WOPI CheckFileInfo response.
+ std::string message = fileURL;
+ if (!fileInfo.empty())
+ {
+ message += '\n';
+ message += fileInfo;
+ }
+ LOG_DBG("Actually sending to Online:" << message);
// Send the document URL to LOOLWSD to setup the docBroker URL
struct pollfd pollfd;
pollfd.fd = currentFakeClientFd;
pollfd.events = POLLOUT;
fakeSocketPoll(&pollfd, 1, -1);
- fakeSocketWrite(currentFakeClientFd, fileURL.c_str(), fileURL.size());
+ fakeSocketWrite(currentFakeClientFd, message.c_str(), message.size());
}
else if (strcmp(string_value, "BYE") == 0)
{
@@ -276,9 +285,20 @@ extern "C" jboolean libreofficekit_initialize(JNIEnv* env, jstring dataDir, jstr
/// Create the LOOLWSD instance.
extern "C" JNIEXPORT void JNICALL
-Java_org_libreoffice_androidlib_LOActivity_createLOOLWSD(JNIEnv *env, jobject, jstring dataDir, jstring cacheDir, jstring apkFile, jobject assetManager, jstring loadFileURL)
+Java_org_libreoffice_androidlib_LOActivity_createLOOLWSD(JNIEnv *env, jobject, jstring dataDir, jstring cacheDir, jstring apkFile, jobject assetManager, jstring loadFileURL, jstring loadFileInfo)
{
- fileURL = std::string(env->GetStringUTFChars(loadFileURL, nullptr));
+ if (!loadFileURL)
+ return;
+
+ const char* pFileURL = env->GetStringUTFChars(loadFileURL, nullptr);
+ const char* pFileInfo = loadFileInfo? env->GetStringUTFChars(loadFileInfo, nullptr): "";
+
+ fileURL = std::string(pFileURL);
+ fileInfo = std::string(pFileInfo);
+
+ env->ReleaseStringUTFChars(loadFileURL, pFileURL);
+ if (loadFileInfo)
+ env->ReleaseStringUTFChars(loadFileInfo, pFileInfo);
// already initialized?
if (lokInitialized)
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 2258a78a2..8c8ae52b8 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -71,6 +71,7 @@ public class LOActivity extends AppCompatActivity {
private static final String KEY_DOCUMENT_URI = "documentUri";
private static final String KEY_IS_EDITABLE = "isEditable";
private static final String KEY_INTENT_URI = "intentUri";
+ private static final String KEY_FILE_INFO = "fileInfo";
private File mTempFile = null;
@@ -84,6 +85,9 @@ public class LOActivity extends AppCompatActivity {
private SharedPreferences sPrefs;
private Handler mainHandler;
+ /** If the document should be created from a template instead of loaded, this is the template. */
+ private String fileInfo;
+
private boolean isDocEditable = false;
private boolean isDocDebuggable = BuildConfig.DEBUG;
private boolean documentLoaded = false;
@@ -243,6 +247,7 @@ public class LOActivity extends AppCompatActivity {
"org.libreoffice.document_provider_id", 0);
documentUri = (URI) getIntent().getSerializableExtra(
"org.libreoffice.document_uri");
+ fileInfo = getIntent().getStringExtra("FileInfo");
}
} else if (savedInstanceState != null) {
getIntent().setAction(Intent.ACTION_VIEW)
@@ -258,6 +263,7 @@ public class LOActivity extends AppCompatActivity {
}
}
isDocEditable = savedInstanceState.getBoolean(KEY_IS_EDITABLE);
+ fileInfo = savedInstanceState.getString(KEY_FILE_INFO);
} else {
//User can't reach here but if he/she does then
Toast.makeText(this, getString(R.string.failed_to_load_file), Toast.LENGTH_SHORT).show();
@@ -335,6 +341,7 @@ public class LOActivity extends AppCompatActivity {
}
//If this activity was opened via contentUri
outState.putBoolean(KEY_IS_EDITABLE, isDocEditable);
+ outState.putString(KEY_FILE_INFO, fileInfo);
}
@Override
@@ -443,7 +450,7 @@ public class LOActivity extends AppCompatActivity {
String apkFile = getApplication().getPackageResourcePath();
AssetManager assetManager = getResources().getAssets();
- createLOOLWSD(dataDir, cacheDir, apkFile, assetManager, urlToLoad);
+ createLOOLWSD(dataDir, cacheDir, apkFile, assetManager, urlToLoad, fileInfo);
// trigger the load of the document
String finalUrlToLoad = "file:///android_asset/dist/loleaflet.html?file_path=" +
@@ -468,7 +475,7 @@ public class LOActivity extends AppCompatActivity {
/**
* Initialize the LOOLWSD to load 'loadFileURL'.
*/
- public native void createLOOLWSD(String dataDir, String cacheDir, String apkFile, AssetManager assetManager, String loadFileURL);
+ public native void createLOOLWSD(String dataDir, String cacheDir, String apkFile, AssetManager assetManager, String loadFileURL, String loadFileInfo);
/**
* Passing messages from JS (instead of the websocket communication).
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 14eabf0ac..326f03994 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -718,6 +718,10 @@ std::string LOOLWSD::OverrideWatermark;
std::set<const Poco::Util::AbstractConfiguration*> LOOLWSD::PluginConfigurations;
std::chrono::time_point<std::chrono::system_clock> LOOLWSD::StartTime;
+#if MOBILEAPP
+std::string LOOLWSD::MobileFileInfo;
+#endif
+
static std::string UnitTestLibrary;
unsigned int LOOLWSD::NumPreSpawnedChildren = 0;
@@ -2200,9 +2204,21 @@ private:
socket->eraseFirstInputBytes(map);
#else
Poco::Net::HTTPRequest request;
- // The 2nd parameter is the response to the HULLO message (which we
- // respond with the path of the document)
- handleClientWsUpgrade(request, std::string(socket->getInBuffer().data(), socket->getInBuffer().size()), disposition);
+
+ // This is the response to the HULLO message
+ // The first line is the document, the 2nd line (if it exists) the
+ // MobileFileInfo (equivalent to the CheckFileInfo response)
+ std::string fileURL(socket->getInBuffer().data(), socket->getInBuffer().size());
+ LOOLWSD::MobileFileInfo = "";
+
+ size_t newLine = fileURL.find("\n");
+ if (newLine != std::string::npos)
+ {
+ LOOLWSD::MobileFileInfo = fileURL.substr(newLine + 1);
+ fileURL.resize(newLine);
+ }
+
+ handleClientWsUpgrade(request, fileURL, disposition);
socket->getInBuffer().clear();
#endif
}
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index d08c2a0a5..1703e12ea 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -76,6 +76,10 @@ public:
static std::set<const Poco::Util::AbstractConfiguration*> PluginConfigurations;
static std::chrono::time_point<std::chrono::system_clock> StartTime;
+#if MOBILEAPP
+ static std::string MobileFileInfo;
+#endif
+
static std::vector<int> getKitPids();
static std::string GenSessionId()
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index c48319f9f..de4cebb0d 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -261,17 +261,31 @@ std::unique_ptr<StorageBase::WOPIFileInfo> LocalStorage::getWOPIFileInfo(const A
const Poco::Path path = Poco::Path(getUri().getPath());
LOG_DBG("Getting info for local uri [" << LOOLWSD::anonymizeUrl(getUri().toString()) << "], path [" << LOOLWSD::anonymizeUrl(path.toString()) << "].");
- const Poco::File file = Poco::File(path);
+ Poco::JSON::Object::Ptr object;
+#if MOBILEAPP
+ LOG_DBG("MobileFileInfo: " << LOOLWSD::MobileFileInfo);
+ if (LOOLWSD::MobileFileInfo.empty() || !JsonUtil::parseJSON(LOOLWSD::MobileFileInfo, object))
+#endif
+ object = new Poco::JSON::Object;
- Poco::JSON::Object::Ptr object = new Poco::JSON::Object;
object->set("BaseFileName", path.getFileName());
object->set("OwnerId", "localhost");
- object->set("LastModifiedTime", Poco::DateTimeFormatter::format(file.getLastModified(), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT));
- object->set("Size", file.getSize());
+
+ const Poco::File file = Poco::File(path);
+ if (file.exists())
+ {
+ object->set("LastModifiedTime", Poco::DateTimeFormatter::format(file.getLastModified(), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT));
+ object->set("Size", file.getSize());
+ }
+
object->set("UserId", "localhost" + std::to_string(LastLocalStorageId));
object->set("UserFriendlyName", "LocalHost#" + std::to_string(LastLocalStorageId++));
object->set("UserCanWrite", true);
+ std::ostringstream oss;
+ object->stringify(oss);
+ LOG_DBG("We have this fileInfo: " << oss.str());
+
return StorageBase::getWOPIFileInfo(object);
}