[WebView] Rename to DocumentStartJavaScript
Per Java style guide https://google.github.io/styleguide/javaguide.html#s5.3-camel-case, Javascript is better to be JavaScript. We will need to do a 3-way patching for the AndroidX boundary interface, so adding the addDocumentStartJavaScript() first in this CL, we need to remove the original addDocumentStartJavascript() after aosp/1329732 landed. We also upgrade the feature version to avoiding old AndroidX calling newer WebView or vice versa. Bug: 918065 Test: Covered by existing tests Change-Id: I1f5eee713d521ac5f480eee670f5f5be674de553 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2240283 Reviewed-by: Richard Coles <torne@chromium.org> Reviewed-by: Changwan Ryu <changwan@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Commit-Queue: Shimi Zhang <ctzsm@chromium.org> Cr-Commit-Position: refs/heads/master@{#777493}
This commit is contained in:
android_webview
browser
glue
java
src
com
android
webview
chromium
java
src
org
chromium
android_webview
javatests
src
org
chromium
android_webview
support_library
boundary_interfaces
src
org
chromium
support_lib_boundary
java
src
org
chromium
support_lib_glue
components/js_injection
@ -1323,7 +1323,7 @@ JsJavaConfiguratorHost* AwContents::GetJsJavaConfiguratorHost() {
|
||||
return js_java_configurator_host_.get();
|
||||
}
|
||||
|
||||
jint AwContents::AddDocumentStartJavascript(
|
||||
jint AwContents::AddDocumentStartJavaScript(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj,
|
||||
const base::android::JavaParamRef<jstring>& script,
|
||||
@ -1331,7 +1331,7 @@ jint AwContents::AddDocumentStartJavascript(
|
||||
std::vector<std::string> native_allowed_origin_rule_strings;
|
||||
AppendJavaStringArrayToStringVector(env, allowed_origin_rules,
|
||||
&native_allowed_origin_rule_strings);
|
||||
auto result = GetJsJavaConfiguratorHost()->AddDocumentStartJavascript(
|
||||
auto result = GetJsJavaConfiguratorHost()->AddDocumentStartJavaScript(
|
||||
base::android::ConvertJavaStringToUTF16(env, script),
|
||||
native_allowed_origin_rule_strings);
|
||||
if (result.error_message) {
|
||||
@ -1343,11 +1343,11 @@ jint AwContents::AddDocumentStartJavascript(
|
||||
return result.script_id.value();
|
||||
}
|
||||
|
||||
void AwContents::RemoveDocumentStartJavascript(
|
||||
void AwContents::RemoveDocumentStartJavaScript(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj,
|
||||
jint script_id) {
|
||||
GetJsJavaConfiguratorHost()->RemoveDocumentStartJavascript(script_id);
|
||||
GetJsJavaConfiguratorHost()->RemoveDocumentStartJavaScript(script_id);
|
||||
}
|
||||
|
||||
base::android::ScopedJavaLocalRef<jstring> AwContents::AddWebMessageListener(
|
||||
|
@ -223,13 +223,13 @@ class AwContents : public FindHelper::Listener,
|
||||
|
||||
js_injection::JsJavaConfiguratorHost* GetJsJavaConfiguratorHost();
|
||||
|
||||
jint AddDocumentStartJavascript(
|
||||
jint AddDocumentStartJavaScript(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj,
|
||||
const base::android::JavaParamRef<jstring>& script,
|
||||
const base::android::JavaParamRef<jobjectArray>& allowed_origin_rules);
|
||||
|
||||
void RemoveDocumentStartJavascript(
|
||||
void RemoveDocumentStartJavaScript(
|
||||
JNIEnv* env,
|
||||
const base::android::JavaParamRef<jobject>& obj,
|
||||
jint script_id);
|
||||
|
@ -137,13 +137,13 @@ public class SharedWebViewChromium {
|
||||
mAwContents.removeWebMessageListener(jsObjectName);
|
||||
}
|
||||
|
||||
public ScriptReference addDocumentStartJavascript(
|
||||
public ScriptReference addDocumentStartJavaScript(
|
||||
final String script, final String[] allowedOriginRules) {
|
||||
if (checkNeedsPost()) {
|
||||
return mRunQueue.runOnUiThreadBlocking(
|
||||
() -> addDocumentStartJavascript(script, allowedOriginRules));
|
||||
() -> addDocumentStartJavaScript(script, allowedOriginRules));
|
||||
}
|
||||
return mAwContents.addDocumentStartJavascript(script, allowedOriginRules);
|
||||
return mAwContents.addDocumentStartJavaScript(script, allowedOriginRules);
|
||||
}
|
||||
|
||||
public void setWebViewRendererClientAdapter(
|
||||
|
@ -2515,7 +2515,7 @@ public class AwContents implements SmartClipProvider {
|
||||
* jsObjectName and allowedOriginRules is {@code null}.
|
||||
* @return A {@link ScriptReference} for removing the script.
|
||||
*/
|
||||
public ScriptReference addDocumentStartJavascript(
|
||||
public ScriptReference addDocumentStartJavaScript(
|
||||
@NonNull String script, @NonNull String[] allowedOriginRules) {
|
||||
if (script == null) {
|
||||
throw new IllegalArgumentException("script shouldn't be null.");
|
||||
@ -2529,12 +2529,12 @@ public class AwContents implements SmartClipProvider {
|
||||
}
|
||||
|
||||
return new ScriptReference(AwContents.this,
|
||||
AwContentsJni.get().addDocumentStartJavascript(
|
||||
AwContentsJni.get().addDocumentStartJavaScript(
|
||||
mNativeAwContents, AwContents.this, script, allowedOriginRules));
|
||||
}
|
||||
|
||||
/* package */ void removeDocumentStartJavascript(int scriptId) {
|
||||
AwContentsJni.get().removeDocumentStartJavascript(
|
||||
/* package */ void removeDocumentStartJavaScript(int scriptId) {
|
||||
AwContentsJni.get().removeDocumentStartJavaScript(
|
||||
mNativeAwContents, AwContents.this, scriptId);
|
||||
}
|
||||
|
||||
@ -4088,9 +4088,9 @@ public class AwContents implements SmartClipProvider {
|
||||
void grantFileSchemeAccesstoChildProcess(long nativeAwContents, AwContents caller);
|
||||
void resumeLoadingCreatedPopupWebContents(long nativeAwContents, AwContents caller);
|
||||
AwRenderProcess getRenderProcess(long nativeAwContents, AwContents caller);
|
||||
int addDocumentStartJavascript(long nativeAwContents, AwContents caller, String script,
|
||||
int addDocumentStartJavaScript(long nativeAwContents, AwContents caller, String script,
|
||||
String[] allowedOriginRules);
|
||||
void removeDocumentStartJavascript(long nativeAwContents, AwContents caller, int scriptId);
|
||||
void removeDocumentStartJavaScript(long nativeAwContents, AwContents caller, int scriptId);
|
||||
String addWebMessageListener(long nativeAwContents, AwContents caller,
|
||||
WebMessageListenerHolder listener, String jsObjectName, String[] allowedOrigins);
|
||||
void removeWebMessageListener(
|
||||
|
@ -27,6 +27,6 @@ public class ScriptReference {
|
||||
|
||||
AwContents awContents = mAwContentsRef.get();
|
||||
if (awContents == null) return;
|
||||
awContents.removeDocumentStartJavascript(mScriptId);
|
||||
awContents.removeDocumentStartJavaScript(mScriptId);
|
||||
}
|
||||
}
|
||||
|
@ -1011,7 +1011,7 @@ public class JsJavaInteractionTest {
|
||||
javascriptInterfaceQueue.add(message);
|
||||
}
|
||||
}, "javaBridge");
|
||||
addDocumentStartJavascriptOnUiThread(
|
||||
addDocumentStartJavaScriptOnUiThread(
|
||||
mAwContents, "javaBridge.send('" + HELLO + "');", new String[] {"*"});
|
||||
|
||||
loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
@ -1026,7 +1026,7 @@ public class JsJavaInteractionTest {
|
||||
@Feature({"AndroidWebView", "JsJavaInteraction"})
|
||||
public void testDocumentStartJavaScript_jsObjectShouldBeAvaliable() throws Throwable {
|
||||
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
|
||||
addDocumentStartJavascriptOnUiThread(
|
||||
addDocumentStartJavaScriptOnUiThread(
|
||||
mAwContents, JS_OBJECT_NAME + ".postMessage('" + HELLO + "');", new String[] {"*"});
|
||||
|
||||
String url = loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
@ -1045,7 +1045,7 @@ public class JsJavaInteractionTest {
|
||||
@MediumTest
|
||||
@Feature({"AndroidWebView", "JsJavaInteraction"})
|
||||
public void testDocumentStartJavaScript_runBeforeUserScript() throws Throwable {
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents,
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents,
|
||||
JS_OBJECT_NAME + ".postMessage('" + HELLO + "1');", new String[] {"*"});
|
||||
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
|
||||
|
||||
@ -1071,9 +1071,9 @@ public class JsJavaInteractionTest {
|
||||
@Feature({"AndroidWebView", "JsJavaInteraction"})
|
||||
public void testDocumentStartJavaScript_multipleScripts() throws Throwable {
|
||||
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents,
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents,
|
||||
JS_OBJECT_NAME + ".postMessage('" + HELLO + "0');", new String[] {"*"});
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents,
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents,
|
||||
JS_OBJECT_NAME + ".postMessage('" + HELLO + "1');", new String[] {"*"});
|
||||
|
||||
String url = loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
@ -1095,12 +1095,12 @@ public class JsJavaInteractionTest {
|
||||
@Feature({"AndroidWebView", "JsJavaInteraction"})
|
||||
public void testDocumentStartJavaScript_callAgainAfterPageLoad() throws Throwable {
|
||||
addWebMessageListenerOnUiThread(mAwContents, JS_OBJECT_NAME, new String[] {"*"}, mListener);
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents,
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents,
|
||||
JS_OBJECT_NAME + ".postMessage('" + HELLO + "0');", new String[] {"*"});
|
||||
|
||||
String url = loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents,
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents,
|
||||
JS_OBJECT_NAME + ".postMessage('" + HELLO + "1');", new String[] {"*"});
|
||||
TestWebMessageListener.Data data = mListener.waitForOnPostMessage();
|
||||
|
||||
@ -1129,7 +1129,7 @@ public class JsJavaInteractionTest {
|
||||
throws Throwable {
|
||||
// With a standard origin rule.
|
||||
final String testObjectName = "test";
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents, "let " + testObjectName + " = {};",
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents, "let " + testObjectName + " = {};",
|
||||
new String[] {"https://www.example.com:443"});
|
||||
|
||||
Assert.assertTrue(didScriptRunWhenLoading("https://www.example.com", testObjectName));
|
||||
@ -1143,7 +1143,7 @@ public class JsJavaInteractionTest {
|
||||
|
||||
// Match all the origins.
|
||||
final String testObjectName2 = testObjectName + "2";
|
||||
addDocumentStartJavascriptOnUiThread(
|
||||
addDocumentStartJavaScriptOnUiThread(
|
||||
mAwContents, "let " + testObjectName2 + " = {};", new String[] {"*"});
|
||||
|
||||
Assert.assertTrue(didScriptRunWhenLoading("https://www.example.com", testObjectName2));
|
||||
@ -1164,7 +1164,7 @@ public class JsJavaInteractionTest {
|
||||
// Wrong origin rule.
|
||||
final String testObjectName5 = testObjectName + "5";
|
||||
try {
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents, "let " + testObjectName5 + " = {};",
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents, "let " + testObjectName5 + " = {};",
|
||||
new String[] {"https://www.example.com/index.html"});
|
||||
Assert.fail("You cannot use a full URL for allowedOriginRules.");
|
||||
} catch (RuntimeException e) {
|
||||
@ -1185,7 +1185,7 @@ public class JsJavaInteractionTest {
|
||||
+ "}";
|
||||
// Since we are matching both origins, the script will run in both iframe and main frame,
|
||||
// but it will send message in only iframe.
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
|
||||
final String frameUrl = mTestServer.getURL(HELLO_WORLD_HTML);
|
||||
final String html = createCrossOriginAccessTestPageHtml(frameUrl);
|
||||
@ -1218,7 +1218,7 @@ public class JsJavaInteractionTest {
|
||||
// Since we are matching both origins, the script will run in both iframe and main
|
||||
// frame, but it will send message in only iframe.
|
||||
references[i] =
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
}
|
||||
|
||||
final String url = loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
@ -1252,7 +1252,7 @@ public class JsJavaInteractionTest {
|
||||
|
||||
final String script = JS_OBJECT_NAME + ".postMessage('" + HELLO + "');";
|
||||
ScriptReference reference =
|
||||
addDocumentStartJavascriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
addDocumentStartJavaScriptOnUiThread(mAwContents, script, new String[] {"*"});
|
||||
|
||||
final String url = loadUrlFromPath(HELLO_WORLD_HTML);
|
||||
|
||||
@ -1334,10 +1334,10 @@ public class JsJavaInteractionTest {
|
||||
+ "</body></html>";
|
||||
}
|
||||
|
||||
private static ScriptReference addDocumentStartJavascriptOnUiThread(
|
||||
private static ScriptReference addDocumentStartJavaScriptOnUiThread(
|
||||
final AwContents awContents, final String script, final String[] allowedOriginRules) {
|
||||
return TestThreadUtils.runOnUiThreadBlockingNoException(
|
||||
() -> awContents.addDocumentStartJavascript(script, allowedOriginRules));
|
||||
() -> awContents.addDocumentStartJavaScript(script, allowedOriginRules));
|
||||
}
|
||||
|
||||
private static void addWebMessageListenerOnUiThread(final AwContents awContents,
|
||||
|
@ -20,8 +20,11 @@ public interface WebViewProviderBoundaryInterface {
|
||||
void addWebMessageListener(String jsObjectName, String[] allowedOriginRules,
|
||||
/* WebMessageListener */ InvocationHandler listener);
|
||||
void removeWebMessageListener(String jsObjectName);
|
||||
// TODO(ctzsm): Remove the following interface after AndroidX patch landed.
|
||||
/* ScriptReference */ InvocationHandler addDocumentStartJavascript(
|
||||
String script, String[] allowedOriginRules);
|
||||
/* ScriptReference */ InvocationHandler addDocumentStartJavaScript(
|
||||
String script, String[] allowedOriginRules);
|
||||
WebViewClient getWebViewClient();
|
||||
WebChromeClient getWebChromeClient();
|
||||
/* WebViewRenderer */ InvocationHandler getWebViewRenderer();
|
||||
|
@ -178,5 +178,5 @@ public class Features {
|
||||
public static final String SET_SUPPORT_LIBRARY_VERSION = "SET_SUPPORT_LIBRARY_VERSION";
|
||||
|
||||
// WebViewCompat.addDocumentStartJavascript
|
||||
public static final String DOCUMENT_START_SCRIPT = "DOCUMENT_START_SCRIPT";
|
||||
public static final String DOCUMENT_START_SCRIPT = "DOCUMENT_START_SCRIPT:1";
|
||||
}
|
||||
|
@ -88,13 +88,23 @@ class SupportLibWebViewChromium implements WebViewProviderBoundaryInterface {
|
||||
mSharedWebViewChromium.removeWebMessageListener(jsObjectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* ScriptReference */ InvocationHandler addDocumentStartJavaScript(
|
||||
final String script, final String[] allowedOriginRules) {
|
||||
recordApiCall(ApiCall.ADD_DOCUMENT_START_SCRIPT);
|
||||
return BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
|
||||
new SupportLibScriptReferenceAdapter(
|
||||
mSharedWebViewChromium.addDocumentStartJavaScript(
|
||||
script, allowedOriginRules)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public /* ScriptReference */ InvocationHandler addDocumentStartJavascript(
|
||||
final String script, final String[] allowedOriginRules) {
|
||||
recordApiCall(ApiCall.ADD_DOCUMENT_START_SCRIPT);
|
||||
return BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
|
||||
new SupportLibScriptReferenceAdapter(
|
||||
mSharedWebViewChromium.addDocumentStartJavascript(
|
||||
mSharedWebViewChromium.addDocumentStartJavaScript(
|
||||
script, allowedOriginRules)));
|
||||
}
|
||||
|
||||
|
@ -46,18 +46,18 @@ struct JsObject {
|
||||
std::unique_ptr<WebMessageHostFactory> factory;
|
||||
};
|
||||
|
||||
struct DocumentStartJavascript {
|
||||
DocumentStartJavascript(base::string16 script,
|
||||
struct DocumentStartJavaScript {
|
||||
DocumentStartJavaScript(base::string16 script,
|
||||
AwOriginMatcher allowed_origin_rules,
|
||||
int32_t script_id)
|
||||
: script_(std::move(script)),
|
||||
allowed_origin_rules_(allowed_origin_rules),
|
||||
script_id_(script_id) {}
|
||||
|
||||
DocumentStartJavascript(DocumentStartJavascript&) = delete;
|
||||
DocumentStartJavascript& operator=(DocumentStartJavascript&) = delete;
|
||||
DocumentStartJavascript(DocumentStartJavascript&&) = default;
|
||||
DocumentStartJavascript& operator=(DocumentStartJavascript&&) = default;
|
||||
DocumentStartJavaScript(DocumentStartJavaScript&) = delete;
|
||||
DocumentStartJavaScript& operator=(DocumentStartJavaScript&) = delete;
|
||||
DocumentStartJavaScript(DocumentStartJavaScript&&) = default;
|
||||
DocumentStartJavaScript& operator=(DocumentStartJavaScript&&) = default;
|
||||
|
||||
base::string16 script_;
|
||||
AwOriginMatcher allowed_origin_rules_;
|
||||
@ -79,7 +79,7 @@ JsJavaConfiguratorHost::JsJavaConfiguratorHost(
|
||||
JsJavaConfiguratorHost::~JsJavaConfiguratorHost() = default;
|
||||
|
||||
JsJavaConfiguratorHost::AddScriptResult
|
||||
JsJavaConfiguratorHost::AddDocumentStartJavascript(
|
||||
JsJavaConfiguratorHost::AddDocumentStartJavaScript(
|
||||
const base::string16& script,
|
||||
const std::vector<std::string>& allowed_origin_rules) {
|
||||
AwOriginMatcher origin_matcher;
|
||||
@ -94,18 +94,18 @@ JsJavaConfiguratorHost::AddDocumentStartJavascript(
|
||||
scripts_.emplace_back(script, origin_matcher, next_script_id_++);
|
||||
|
||||
web_contents()->ForEachFrame(base::BindRepeating(
|
||||
&JsJavaConfiguratorHost::NotifyFrameForAddDocumentStartJavascript,
|
||||
&JsJavaConfiguratorHost::NotifyFrameForAddDocumentStartJavaScript,
|
||||
base::Unretained(this), &*scripts_.rbegin()));
|
||||
result.script_id = scripts_.rbegin()->script_id_;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JsJavaConfiguratorHost::RemoveDocumentStartJavascript(int script_id) {
|
||||
bool JsJavaConfiguratorHost::RemoveDocumentStartJavaScript(int script_id) {
|
||||
for (auto it = scripts_.begin(); it != scripts_.end(); ++it) {
|
||||
if (it->script_id_ == script_id) {
|
||||
scripts_.erase(it);
|
||||
web_contents()->ForEachFrame(base::BindRepeating(
|
||||
&JsJavaConfiguratorHost::NotifyFrameForRemoveDocumentStartJavascript,
|
||||
&JsJavaConfiguratorHost::NotifyFrameForRemoveDocumentStartJavaScript,
|
||||
base::Unretained(this), script_id));
|
||||
return true;
|
||||
}
|
||||
@ -168,7 +168,7 @@ JsJavaConfiguratorHost::GetWebMessageHostFactories() {
|
||||
void JsJavaConfiguratorHost::RenderFrameCreated(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
NotifyFrameForWebMessageListener(render_frame_host);
|
||||
NotifyFrameForAllDocumentStartJavascripts(render_frame_host);
|
||||
NotifyFrameForAllDocumentStartJavaScripts(render_frame_host);
|
||||
}
|
||||
|
||||
void JsJavaConfiguratorHost::RenderFrameDeleted(
|
||||
@ -176,10 +176,10 @@ void JsJavaConfiguratorHost::RenderFrameDeleted(
|
||||
js_to_java_messagings_.erase(render_frame_host);
|
||||
}
|
||||
|
||||
void JsJavaConfiguratorHost::NotifyFrameForAllDocumentStartJavascripts(
|
||||
void JsJavaConfiguratorHost::NotifyFrameForAllDocumentStartJavaScripts(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
for (const auto& script : scripts_) {
|
||||
NotifyFrameForAddDocumentStartJavascript(&script, render_frame_host);
|
||||
NotifyFrameForAddDocumentStartJavaScript(&script, render_frame_host);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,19 +204,19 @@ void JsJavaConfiguratorHost::NotifyFrameForWebMessageListener(
|
||||
configurator_remote->SetJsObjects(std::move(js_objects));
|
||||
}
|
||||
|
||||
void JsJavaConfiguratorHost::NotifyFrameForAddDocumentStartJavascript(
|
||||
const DocumentStartJavascript* script,
|
||||
void JsJavaConfiguratorHost::NotifyFrameForAddDocumentStartJavaScript(
|
||||
const DocumentStartJavaScript* script,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
DCHECK(script);
|
||||
mojo::AssociatedRemote<mojom::JsJavaConfigurator> configurator_remote;
|
||||
render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
|
||||
&configurator_remote);
|
||||
configurator_remote->AddDocumentStartScript(
|
||||
mojom::DocumentStartJavascript::New(script->script_id_, script->script_,
|
||||
mojom::DocumentStartJavaScript::New(script->script_id_, script->script_,
|
||||
script->allowed_origin_rules_));
|
||||
}
|
||||
|
||||
void JsJavaConfiguratorHost::NotifyFrameForRemoveDocumentStartJavascript(
|
||||
void JsJavaConfiguratorHost::NotifyFrameForRemoveDocumentStartJavaScript(
|
||||
int32_t script_id,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
mojo::AssociatedRemote<mojom::JsJavaConfigurator> configurator_remote;
|
||||
|
@ -20,7 +20,7 @@ class RenderFrameHost;
|
||||
namespace js_injection {
|
||||
|
||||
class AwOriginMatcher;
|
||||
struct DocumentStartJavascript;
|
||||
struct DocumentStartJavaScript;
|
||||
struct JsObject;
|
||||
class JsToJavaMessaging;
|
||||
class WebMessageHostFactory;
|
||||
@ -48,13 +48,13 @@ class JsJavaConfiguratorHost : public content::WebContentsObserver {
|
||||
base::Optional<int> script_id;
|
||||
};
|
||||
|
||||
// Native side AddDocumentStartJavascript, returns an error message if the
|
||||
// Native side AddDocumentStartJavaScript, returns an error message if the
|
||||
// parameters didn't pass necessary checks.
|
||||
AddScriptResult AddDocumentStartJavascript(
|
||||
AddScriptResult AddDocumentStartJavaScript(
|
||||
const base::string16& script,
|
||||
const std::vector<std::string>& allowed_origin_rules);
|
||||
|
||||
bool RemoveDocumentStartJavascript(int script_id);
|
||||
bool RemoveDocumentStartJavaScript(int script_id);
|
||||
|
||||
// Adds a new WebMessageHostFactory. For any urls that match
|
||||
// |allowed_origin_rules|, |js_object_name| is registered as a JS object that
|
||||
@ -85,18 +85,18 @@ class JsJavaConfiguratorHost : public content::WebContentsObserver {
|
||||
private:
|
||||
void NotifyFrameForWebMessageListener(
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void NotifyFrameForAllDocumentStartJavascripts(
|
||||
void NotifyFrameForAllDocumentStartJavaScripts(
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void NotifyFrameForAddDocumentStartJavascript(
|
||||
const DocumentStartJavascript* script,
|
||||
void NotifyFrameForAddDocumentStartJavaScript(
|
||||
const DocumentStartJavaScript* script,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
|
||||
void NotifyFrameForRemoveDocumentStartJavascript(
|
||||
void NotifyFrameForRemoveDocumentStartJavaScript(
|
||||
int32_t script_id,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
|
||||
int32_t next_script_id_ = 0;
|
||||
std::vector<DocumentStartJavascript> scripts_;
|
||||
std::vector<DocumentStartJavaScript> scripts_;
|
||||
std::vector<std::unique_ptr<JsObject>> js_objects_;
|
||||
std::map<content::RenderFrameHost*,
|
||||
std::vector<std::unique_ptr<JsToJavaMessaging>>>
|
||||
|
@ -19,10 +19,10 @@ struct JsObject {
|
||||
js_injection.mojom.AwOriginMatcher origin_matcher;
|
||||
};
|
||||
|
||||
// DocumentStartJavascript struct contains the JavaScript snippet |script| and
|
||||
// DocumentStartJavaScript struct contains the JavaScript snippet |script| and
|
||||
// the corresponding |origin_matcher|. We will run the script if the frame's
|
||||
// origin matches any rules in the |origin_matcher|.
|
||||
struct DocumentStartJavascript {
|
||||
struct DocumentStartJavaScript {
|
||||
int32 script_id;
|
||||
mojo_base.mojom.String16 script;
|
||||
js_injection.mojom.AwOriginMatcher origin_matcher;
|
||||
@ -58,7 +58,7 @@ interface JsJavaConfigurator {
|
||||
// Called from browser, to add a script for a frame to run at document start
|
||||
// stage. The script will run only if the frame's origin matches any of the
|
||||
// allowed_origin_rules.
|
||||
AddDocumentStartScript(js_injection.mojom.DocumentStartJavascript script);
|
||||
AddDocumentStartScript(js_injection.mojom.DocumentStartJavaScript script);
|
||||
|
||||
// Called from browser, to remove the script by the given script_id.
|
||||
RemoveDocumentStartScript(int32 script_id);
|
||||
|
@ -23,7 +23,7 @@ struct JsJavaConfigurator::JsObjectInfo {
|
||||
mojo::AssociatedRemote<mojom::JsToJavaMessaging> js_to_java_messaging;
|
||||
};
|
||||
|
||||
struct JsJavaConfigurator::DocumentStartJavascript {
|
||||
struct JsJavaConfigurator::DocumentStartJavaScript {
|
||||
AwOriginMatcher origin_matcher;
|
||||
blink::WebString script;
|
||||
int32_t script_id;
|
||||
@ -55,11 +55,11 @@ void JsJavaConfigurator::SetJsObjects(
|
||||
}
|
||||
|
||||
void JsJavaConfigurator::AddDocumentStartScript(
|
||||
mojom::DocumentStartJavascriptPtr script_ptr) {
|
||||
DocumentStartJavascript* script = new DocumentStartJavascript{
|
||||
mojom::DocumentStartJavaScriptPtr script_ptr) {
|
||||
DocumentStartJavaScript* script = new DocumentStartJavaScript{
|
||||
script_ptr->origin_matcher,
|
||||
blink::WebString::FromUTF16(script_ptr->script), script_ptr->script_id};
|
||||
scripts_.push_back(std::unique_ptr<DocumentStartJavascript>(script));
|
||||
scripts_.push_back(std::unique_ptr<DocumentStartJavaScript>(script));
|
||||
}
|
||||
|
||||
void JsJavaConfigurator::RemoveDocumentStartScript(int32_t script_id) {
|
||||
|
@ -34,7 +34,7 @@ class JsJavaConfigurator
|
||||
// mojom::JsJavaConfigurator implementation
|
||||
void SetJsObjects(std::vector<mojom::JsObjectPtr> js_object_ptrs) override;
|
||||
void AddDocumentStartScript(
|
||||
mojom::DocumentStartJavascriptPtr script_ptr) override;
|
||||
mojom::DocumentStartJavaScriptPtr script_ptr) override;
|
||||
void RemoveDocumentStartScript(int32_t script_id) override;
|
||||
|
||||
// RenderFrameObserver implementation
|
||||
@ -50,7 +50,7 @@ class JsJavaConfigurator
|
||||
|
||||
private:
|
||||
struct JsObjectInfo;
|
||||
struct DocumentStartJavascript;
|
||||
struct DocumentStartJavaScript;
|
||||
|
||||
void BindPendingReceiver(
|
||||
mojo::PendingAssociatedReceiver<mojom::JsJavaConfigurator>
|
||||
@ -63,7 +63,7 @@ class JsJavaConfigurator
|
||||
// to prevent doing multiple injection in that case.
|
||||
bool inside_did_clear_window_object_ = false;
|
||||
|
||||
std::vector<std::unique_ptr<DocumentStartJavascript>> scripts_;
|
||||
std::vector<std::unique_ptr<DocumentStartJavaScript>> scripts_;
|
||||
std::vector<std::unique_ptr<JsBinding>> js_bindings_;
|
||||
|
||||
// Associated with legacy IPC channel.
|
||||
|
Reference in New Issue
Block a user