#include "base/android/jni_string.h"
#include "base/base_paths_android.h"
#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
#include "base/path_service.h"
#include "base/pickle.h"
#include "content/public/browser/browser_context.h"
using navigation_interception::InterceptNavigationDelegate;
using xwalk::application_manifest_keys::kDisplay;
+namespace keys = xwalk::application_manifest_keys;
+
namespace xwalk {
namespace {
XWalkContent* content_;
};
+// FIXME(wang16): Remove following methods after deprecated fields
+// are not supported any more.
+void PrintManifestDeprecationWarning(std::string field) {
+ LOG(WARNING) << "\"" << field << "\" is deprecated for Crosswalk. "
+ << "Please follow "
+ << "https://www.crosswalk-project.org/#documentation/manifest.";
+}
+
+bool ManifestHasPath(const xwalk::application::Manifest& manifest,
+ const std::string& path,
+ const std::string& deprecated_path) {
+ if (manifest.HasPath(path))
+ return true;
+ if (manifest.HasPath(deprecated_path)) {
+ PrintManifestDeprecationWarning(deprecated_path);
+ return true;
+ }
+ return false;
+}
+
+bool ManifestGetString(const xwalk::application::Manifest& manifest,
+ const std::string& path,
+ const std::string& deprecated_path,
+ std::string* out_value) {
+ if (manifest.GetString(path, out_value))
+ return true;
+ if (manifest.GetString(deprecated_path, out_value)) {
+ PrintManifestDeprecationWarning(deprecated_path);
+ return true;
+ }
+ return false;
+}
+
} // namespace
XWalkContent::XWalkContent(JNIEnv* env,
return XWalkContentUserData::GetContents(web_contents);
}
-jint XWalkContent::GetWebContents(
+jlong XWalkContent::GetWebContents(
JNIEnv* env, jobject obj, jobject io_thread_client,
jobject intercept_navigation_delegate) {
if (!web_contents_) {
render_view_host_ext_.reset(
new XWalkRenderViewHostExt(web_contents_.get()));
}
- return reinterpret_cast<jint>(web_contents_.get());
+ return reinterpret_cast<intptr_t>(web_contents_.get());
}
content::WebContents* XWalkContent::CreateWebContents(
contents_client_bridge_.get());
XWalkContentsIoThreadClientImpl::Associate(web_contents,
ScopedJavaLocalRef<jobject>(env, io_thread_client));
- int child_id = web_contents->GetRenderProcessHost()->GetID();
- int route_id = web_contents->GetRoutingID();
+ int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+ int render_frame_id = web_contents->GetRoutingID();
RuntimeResourceDispatcherHostDelegateAndroid::OnIoThreadClientReady(
- child_id, route_id);
+ render_process_id, render_frame_id);
InterceptNavigationDelegate::Associate(web_contents,
make_scoped_ptr(new InterceptNavigationDelegate(
env, intercept_navigation_delegate)));
manifest_dictionary_ptr.Pass());
std::string url;
- if (manifest.GetString(
- xwalk::application_manifest_keys::kLaunchLocalPathKey, &url)) {
+ if (manifest.GetString(keys::kStartURLKey, &url)) {
+ std::string scheme = GURL(url).scheme();
+ if (scheme.empty())
+ url = path_str + url;
+ } else if (manifest.GetString(keys::kLaunchLocalPathKey, &url)) {
+ PrintManifestDeprecationWarning(keys::kLaunchLocalPathKey);
// According to original proposal for "app:launch:local_path", the "http"
// and "https" schemes are supported. So |url| should do nothing when it
// already has "http" or "https" scheme.
std::string scheme = GURL(url).scheme();
- if (scheme != content::kHttpScheme && scheme != content::kHttpsScheme)
+ if (scheme != url::kHttpScheme && scheme != url::kHttpsScheme)
url = path_str + url;
+ } else if (manifest.GetString(keys::kLaunchWebURLKey, &url)) {
+ PrintManifestDeprecationWarning(keys::kLaunchWebURLKey);
} else {
- manifest.GetString(
- xwalk::application_manifest_keys::kLaunchWebURLKey, &url);
+ NOTIMPLEMENTED();
}
+ std::string match_patterns;
+ const base::ListValue* xwalk_hosts = NULL;
+ if (manifest.GetList(
+ xwalk::application_manifest_keys::kXWalkHostsKey, &xwalk_hosts)) {
+ base::JSONWriter::Write(xwalk_hosts, &match_patterns);
+ }
+ render_view_host_ext_->SetOriginAccessWhitelist(url, match_patterns);
+
std::string csp;
- manifest.GetString(
- xwalk::application_manifest_keys::kCSPKey, &csp);
+ ManifestGetString(manifest, keys::kCSPKey, keys::kCSPKeyLegacy, &csp);
RuntimeContext* runtime_context =
XWalkRunner::GetInstance()->runtime_context();
CHECK(runtime_context);
}
// Check whether need to display launch screen. (Read from manifest.json)
- if (manifest.HasPath(
- xwalk::application_manifest_keys::kLaunchScreen)) {
+ if (ManifestHasPath(manifest,
+ keys::kXWalkLaunchScreen,
+ keys::kLaunchScreen)) {
std::string ready_when;
- // Get the value of 'ready_when' from manifest.json and callback
- // to Java side.
- manifest.GetString(
- xwalk::application_manifest_keys::kLaunchScreenReadyWhen, &ready_when);
+ // Get the value of 'ready_when' from manifest.json
+ ManifestGetString(manifest,
+ keys::kXWalkLaunchScreenReadyWhen,
+ keys::kLaunchScreenReadyWhen,
+ &ready_when);
ScopedJavaLocalRef<jstring> ready_when_buffer =
base::android::ConvertUTF8ToJavaString(env, ready_when);
+
+ // Get the value of 'image_border'
+ // 1. When 'launch_screen.[orientation]' was defined, but no 'image_border'
+ // The value of 'image_border' will be set as 'empty'.
+ // 2. Otherwise, there is no 'launch_screen.[orientation]' defined,
+ // The value of 'image_border' will be empty.
+ const char empty[] = "empty";
+ std::string image_border_default;
+ ManifestGetString(manifest,
+ keys::kXWalkLaunchScreenImageBorderDefault,
+ keys::kLaunchScreenImageBorderDefault,
+ &image_border_default);
+ if (image_border_default.empty() &&
+ ManifestHasPath(manifest,
+ keys::kXWalkLaunchScreenDefault,
+ keys::kLaunchScreenDefault)) {
+ image_border_default = empty;
+ }
+
+ std::string image_border_landscape;
+ ManifestGetString(manifest,
+ keys::kXWalkLaunchScreenImageBorderLandscape,
+ keys::kLaunchScreenImageBorderLandscape,
+ &image_border_landscape);
+ if (image_border_landscape.empty() &&
+ ManifestHasPath(manifest,
+ keys::kXWalkLaunchScreenLandscape,
+ keys::kLaunchScreenLandscape)) {
+ image_border_landscape = empty;
+ }
+
+ std::string image_border_portrait;
+ ManifestGetString(manifest,
+ keys::kXWalkLaunchScreenImageBorderPortrait,
+ keys::kLaunchScreenImageBorderPortrait,
+ &image_border_portrait);
+ if (image_border_portrait.empty() &&
+ ManifestHasPath(manifest,
+ keys::kXWalkLaunchScreenPortrait,
+ keys::kLaunchScreenPortrait)) {
+ image_border_portrait = empty;
+ }
+
+ std::string image_border = image_border_default + ';' +
+ image_border_landscape + ';' + image_border_portrait;
+ ScopedJavaLocalRef<jstring> image_border_buffer =
+ base::android::ConvertUTF8ToJavaString(env, image_border);
+
Java_XWalkContent_onGetUrlAndLaunchScreenFromManifest(
- env, obj, url_buffer.obj(), ready_when_buffer.obj());
+ env, obj, url_buffer.obj(), ready_when_buffer.obj(),
+ image_border_buffer.obj());
} else {
// No need to display launch screen, load the url directly.
Java_XWalkContent_onGetUrlFromManifest(env, obj, url_buffer.obj());
return RestoreFromPickle(&iterator, web_contents_.get());
}
-static jint Init(JNIEnv* env, jobject obj, jobject web_contents_delegate,
+static jlong Init(JNIEnv* env, jobject obj, jobject web_contents_delegate,
jobject contents_client_bridge) {
XWalkContent* xwalk_core_content =
new XWalkContent(env, obj, web_contents_delegate, contents_client_bridge);
- return reinterpret_cast<jint>(xwalk_core_content);
+ return reinterpret_cast<intptr_t>(xwalk_core_content);
}
bool RegisterXWalkContent(JNIEnv* env) {
void XWalkContent::ShowGeolocationPrompt(
const GURL& requesting_frame,
- const base::Callback<void(bool)>& callback) {
+ const base::Callback<void(bool)>& callback) { // NOLINT
GURL origin = requesting_frame.GetOrigin();
bool show_prompt = pending_geolocation_prompts_.empty();
pending_geolocation_prompts_.push_back(OriginCallback(origin, callback));