Commit 5ea4ad87 authored by sgurun's avatar sgurun Committed by Commit bot

Move PostMessageToFrame to WebContentsAndroid

Move PostMessageToFrame method from ContentViewCore to WebContentsAndroid
which is a more suitable location.

BUG=393291

Review URL: https://codereview.chromium.org/649933006

Cr-Commit-Position: refs/heads/master@{#300615}
parent 0b8a0468
...@@ -1145,25 +1145,6 @@ long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { ...@@ -1145,25 +1145,6 @@ long ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) {
return rwhva->GetNativeImeAdapter(); return rwhva->GetNativeImeAdapter();
} }
// TODO(sgurun) add support for posting a frame whose name is known (only
// main frame is supported at this time, see crbug.com/389721)
// TODO(sgurun) add support for passing message ports
void ContentViewCoreImpl::PostMessageToFrame(JNIEnv* env, jobject obj,
jstring frame_name, jstring message, jstring source_origin,
jstring target_origin) {
RenderViewHost* host = web_contents_->GetRenderViewHost();
if (!host)
return;
ViewMsg_PostMessage_Params params;
params.source_origin = ConvertJavaStringToUTF16(env, source_origin);
params.target_origin = ConvertJavaStringToUTF16(env, target_origin);
params.data = ConvertJavaStringToUTF16(env, message);
params.is_data_raw_string = true;
params.source_routing_id = MSG_ROUTING_NONE;
host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params));
}
void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter, void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
int text_input_type, int text_input_type,
int text_input_flags, int text_input_flags,
......
...@@ -151,8 +151,6 @@ class ContentViewCoreImpl : public ContentViewCore, ...@@ -151,8 +151,6 @@ class ContentViewCoreImpl : public ContentViewCore,
jobject obj, jobject obj,
jboolean enabled); jboolean enabled);
void PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_id,
jstring message, jstring source_origin, jstring target_origin);
long GetNativeImeAdapter(JNIEnv* env, jobject obj); long GetNativeImeAdapter(JNIEnv* env, jobject obj);
void SetFocus(JNIEnv* env, jobject obj, jboolean focused); void SetFocus(JNIEnv* env, jobject obj, jboolean focused);
......
...@@ -363,4 +363,23 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env, ...@@ -363,4 +363,23 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env,
ConvertJavaStringToUTF16(env, script), js_callback); ConvertJavaStringToUTF16(env, script), js_callback);
} }
// TODO(sgurun) add support for posting a frame whose name is known (only
// main frame is supported at this time, see crbug.com/389721)
// TODO(sgurun) add support for passing message ports
void WebContentsAndroid::PostMessageToFrame(JNIEnv* env, jobject obj,
jstring frame_name, jstring message, jstring source_origin,
jstring target_origin) {
RenderViewHost* host = web_contents_->GetRenderViewHost();
if (!host)
return;
ViewMsg_PostMessage_Params params;
params.source_origin = ConvertJavaStringToUTF16(env, source_origin);
params.target_origin = ConvertJavaStringToUTF16(env, target_origin);
params.data = ConvertJavaStringToUTF16(env, message);
params.is_data_raw_string = true;
params.source_routing_id = MSG_ROUTING_NONE;
host->Send(new ViewMsg_PostMessageEvent(host->GetRoutingID(), params));
}
} // namespace content } // namespace content
...@@ -88,7 +88,8 @@ class CONTENT_EXPORT WebContentsAndroid ...@@ -88,7 +88,8 @@ class CONTENT_EXPORT WebContentsAndroid
jobject obj, jobject obj,
jstring script, jstring script,
jobject callback); jobject callback);
void PostMessageToFrame(JNIEnv* env, jobject obj, jstring frame_id,
jstring message, jstring source_origin, jstring target_origin);
private: private:
RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid(); RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
......
...@@ -1169,23 +1169,6 @@ public class ContentViewCore ...@@ -1169,23 +1169,6 @@ public class ContentViewCore
} }
} }
/**
* Post a message to a frame.
* TODO(sgurun) also add support for transferring a message channel port.
*
* @param frameName The name of the frame. If the name is null the message is posted
* to the main frame.
* @param message The message
* @param sourceOrigin The source origin
* @param targetOrigin The target origin
*/
public void postMessageToFrame(String frameName, String message,
String sourceOrigin, String targetOrigin) {
if (mNativeContentViewCore == 0) return;
nativePostMessageToFrame(mNativeContentViewCore, frameName, message, sourceOrigin,
targetOrigin);
}
/** /**
* To be called when the ContentView is shown. * To be called when the ContentView is shown.
*/ */
...@@ -2908,9 +2891,6 @@ public class ContentViewCore ...@@ -2908,9 +2891,6 @@ public class ContentViewCore
long nativeSelectPopupSourceFrame, int[] indices); long nativeSelectPopupSourceFrame, int[] indices);
private native void nativePostMessageToFrame(long nativeContentViewCoreImpl, String frameId,
String message, String sourceOrigin, String targetOrigin);
private native long nativeGetNativeImeAdapter(long nativeContentViewCoreImpl); private native long nativeGetNativeImeAdapter(long nativeContentViewCoreImpl);
private native int nativeGetCurrentRenderProcessId(long nativeContentViewCoreImpl); private native int nativeGetCurrentRenderProcessId(long nativeContentViewCoreImpl);
......
...@@ -227,6 +227,13 @@ import org.chromium.content_public.browser.WebContents; ...@@ -227,6 +227,13 @@ import org.chromium.content_public.browser.WebContents;
callback.handleJavaScriptResult(jsonResult); callback.handleJavaScriptResult(jsonResult);
} }
@Override
public void postMessageToFrame(String frameName, String message,
String sourceOrigin, String targetOrigin) {
nativePostMessageToFrame(mNativeWebContentsAndroid, frameName, message, sourceOrigin,
targetOrigin);
}
private native String nativeGetTitle(long nativeWebContentsAndroid); private native String nativeGetTitle(long nativeWebContentsAndroid);
private native String nativeGetVisibleURL(long nativeWebContentsAndroid); private native String nativeGetVisibleURL(long nativeWebContentsAndroid);
private native void nativeStop(long nativeWebContentsAndroid); private native void nativeStop(long nativeWebContentsAndroid);
...@@ -258,4 +265,6 @@ import org.chromium.content_public.browser.WebContents; ...@@ -258,4 +265,6 @@ import org.chromium.content_public.browser.WebContents;
String cssSelector); String cssSelector);
private native void nativeEvaluateJavaScript(long nativeWebContentsAndroid, private native void nativeEvaluateJavaScript(long nativeWebContentsAndroid,
String script, JavaScriptCallback callback); String script, JavaScriptCallback callback);
private native void nativePostMessageToFrame(long nativeWebContentsAndroid, String frameId,
String message, String sourceOrigin, String targetOrigin);
} }
...@@ -163,4 +163,16 @@ public interface WebContents { ...@@ -163,4 +163,16 @@ public interface WebContents {
*/ */
public void evaluateJavaScript(String script, JavaScriptCallback callback); public void evaluateJavaScript(String script, JavaScriptCallback callback);
/**
* Post a message to a frame.
* TODO(sgurun) also add support for transferring a message channel port.
*
* @param frameName The name of the frame. If the name is null the message is posted
* to the main frame.
* @param message The message
* @param sourceOrigin The source origin
* @param targetOrigin The target origin
*/
public void postMessageToFrame(String frameName, String message,
String sourceOrigin, String targetOrigin);
} }
...@@ -7,6 +7,7 @@ package org.chromium.content.browser; ...@@ -7,6 +7,7 @@ package org.chromium.content.browser;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content_public.browser.WebContents;
/** /**
* The tests for content postMessage API. * The tests for content postMessage API.
...@@ -71,10 +72,9 @@ public class PostMessageTest extends ContentViewTestBase { ...@@ -71,10 +72,9 @@ public class PostMessageTest extends ContentViewTestBase {
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-PostMessage"}) @Feature({"AndroidWebView", "Android-PostMessage"})
public void testPostMessageToMainFrame() throws Throwable { public void testPostMessageToMainFrame() throws Throwable {
ContentViewCore contentViewCore = getContentViewCore(); WebContents webContents = getContentViewCore().getWebContents();
loadDataSync(contentViewCore.getWebContents().getNavigationController(), URL1, "text/html", loadDataSync(webContents.getNavigationController(), URL1, "text/html", false);
false); webContents.postMessageToFrame(null, MESSAGE, SOURCE_ORIGIN, "*");
contentViewCore.postMessageToFrame(null, MESSAGE, SOURCE_ORIGIN, "*");
mMessageObject.waitForMessage(); mMessageObject.waitForMessage();
assertEquals(MESSAGE, mMessageObject.getData()); assertEquals(MESSAGE, mMessageObject.getData());
assertEquals(SOURCE_ORIGIN, mMessageObject.getOrigin()); assertEquals(SOURCE_ORIGIN, mMessageObject.getOrigin());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment