Commit e684a21b authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Remove ScriptExecutor::WorldType

With the removal of the support for javascript: URLs in tabs.update
(https://crrev.com/fd8288b18270213143), we no longer need to include
the "world type" in ScriptExecutor. This also lets us remove the
in_main_world parameter from ExtensionMsg_ExecuteCode_Params, and
clean up various bits in the renderer code in ScriptInject[or|ion] and
friends.

Bug: None

Change-Id: I7ba549d072063264645f0b9db836e8d8fad114e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835264Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703155}
parent f63b3ef6
......@@ -167,7 +167,7 @@ bool ExecuteCodeFunction::Execute(const std::string& code_string,
executor->ExecuteScript(
host_id_, script_type, code_string, frame_scope, frame_id,
match_about_blank, run_at, ScriptExecutor::ISOLATED_WORLD,
match_about_blank, run_at,
IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS
: ScriptExecutor::DEFAULT_PROCESS,
GetWebViewSrc(), file_url_, user_gesture(), css_origin,
......
......@@ -242,7 +242,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id,
int frame_id,
ScriptExecutor::MatchAboutBlank about_blank,
UserScript::RunLocation run_at,
ScriptExecutor::WorldType world_type,
ScriptExecutor::ProcessType process_type,
const GURL& webview_src,
const GURL& file_url,
......@@ -268,7 +267,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id,
params.code = code;
params.match_about_blank = (about_blank == MATCH_ABOUT_BLANK);
params.run_at = run_at;
params.in_main_world = (world_type == MAIN_WORLD);
params.is_web_view = (process_type == WEB_VIEW_PROCESS);
params.webview_src = webview_src;
params.file_url = file_url;
......
......@@ -65,12 +65,6 @@ class ScriptExecutor {
MATCH_ABOUT_BLANK,
};
// The type of world to inject into (main world, or its own isolated world).
enum WorldType {
MAIN_WORLD,
ISOLATED_WORLD,
};
// The type of process the target is.
enum ProcessType {
DEFAULT_PROCESS,
......@@ -106,7 +100,6 @@ class ScriptExecutor {
int frame_id,
MatchAboutBlank match_about_blank,
UserScript::RunLocation run_at,
WorldType world_type,
ProcessType process_type,
const GURL& webview_src,
const GURL& file_url,
......
......@@ -171,10 +171,6 @@ IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params)
// When to inject the code.
IPC_STRUCT_MEMBER(extensions::UserScript::RunLocation, run_at)
// Whether to execute code in the main world (as opposed to an isolated
// world).
IPC_STRUCT_MEMBER(bool, in_main_world)
// Whether the request is coming from a <webview>.
IPC_STRUCT_MEMBER(bool, is_web_view)
......
......@@ -39,10 +39,6 @@ UserScript::InjectionType ProgrammaticScriptInjector::script_type()
return UserScript::PROGRAMMATIC_SCRIPT;
}
bool ProgrammaticScriptInjector::ShouldExecuteInMainWorld() const {
return params_->in_main_world;
}
bool ProgrammaticScriptInjector::IsUserGesture() const {
return params_->user_gesture;
}
......
......@@ -30,7 +30,6 @@ class ProgrammaticScriptInjector : public ScriptInjector {
private:
// ScriptInjector implementation.
UserScript::InjectionType script_type() const override;
bool ShouldExecuteInMainWorld() const override;
bool IsUserGesture() const override;
base::Optional<CSSOrigin> GetCssOrigin() const override;
const base::Optional<std::string> GetInjectionKey() const override;
......
......@@ -288,11 +288,8 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts,
std::vector<blink::WebScriptSource> sources = injector_->GetJsSources(
run_location_, executing_scripts, num_injected_js_scripts);
DCHECK(!sources.empty());
bool in_main_world = injector_->ShouldExecuteInMainWorld();
int world_id = in_main_world
? DOMActivityLogger::kMainWorldId
: GetIsolatedWorldIdForInstance(injection_host_.get(),
web_frame);
int world_id =
GetIsolatedWorldIdForInstance(injection_host_.get(), web_frame);
bool is_user_gesture = injector_->IsUserGesture();
std::unique_ptr<blink::WebScriptExecutionCallback> callback(
......@@ -301,31 +298,24 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts,
base::ElapsedTimer exec_timer;
if (injection_host_->id().type() == HostID::EXTENSIONS && log_activity_)
DOMActivityLogger::AttachToWorld(world_id, injection_host_->id().id());
if (in_main_world) {
// We only inject in the main world for javascript: urls.
DCHECK_EQ(1u, sources.size());
web_frame->RequestExecuteScriptAndReturnValue(
sources.front(), is_user_gesture, callback.release());
} else {
blink::WebLocalFrame::ScriptExecutionType option;
if (injector_->script_type() == UserScript::CONTENT_SCRIPT) {
switch (run_location_) {
case UserScript::DOCUMENT_END:
case UserScript::DOCUMENT_IDLE:
option = blink::WebLocalFrame::kAsynchronousBlockingOnload;
break;
default:
option = blink::WebLocalFrame::kSynchronous;
break;
}
} else {
option = blink::WebLocalFrame::kSynchronous;
blink::WebLocalFrame::ScriptExecutionType option;
if (injector_->script_type() == UserScript::CONTENT_SCRIPT) {
switch (run_location_) {
case UserScript::DOCUMENT_END:
case UserScript::DOCUMENT_IDLE:
option = blink::WebLocalFrame::kAsynchronousBlockingOnload;
break;
default:
option = blink::WebLocalFrame::kSynchronous;
break;
}
web_frame->RequestExecuteScriptInIsolatedWorld(
world_id, &sources.front(), sources.size(), is_user_gesture, option,
callback.release());
} else {
option = blink::WebLocalFrame::kSynchronous;
}
web_frame->RequestExecuteScriptInIsolatedWorld(
world_id, &sources.front(), sources.size(), is_user_gesture, option,
callback.release());
}
void ScriptInjection::OnJsInjectionCompleted(
......
......@@ -22,8 +22,8 @@ class WebLocalFrame;
namespace extensions {
// The pseudo-delegate class for a ScriptInjection that provides all necessary
// information about how to inject the script, including what code to inject,
// when (run location), and where (world), but without any injection logic.
// information about how to inject the script, including what code to inject and
// when (run location), but without any injection logic.
class ScriptInjector {
public:
// The possible reasons for not injecting the script.
......@@ -39,9 +39,6 @@ class ScriptInjector {
// Returns the script type of this particular injection.
virtual UserScript::InjectionType script_type() const = 0;
// Returns true if the script should execute in the main world.
virtual bool ShouldExecuteInMainWorld() const = 0;
// Returns true if the script is running inside a user gesture.
virtual bool IsUserGesture() const = 0;
......
......@@ -133,10 +133,6 @@ UserScript::InjectionType UserScriptInjector::script_type() const {
return UserScript::CONTENT_SCRIPT;
}
bool UserScriptInjector::ShouldExecuteInMainWorld() const {
return false;
}
bool UserScriptInjector::IsUserGesture() const {
return false;
}
......
......@@ -38,7 +38,6 @@ class UserScriptInjector : public ScriptInjector,
// ScriptInjector implementation.
UserScript::InjectionType script_type() const override;
bool ShouldExecuteInMainWorld() const override;
bool IsUserGesture() const override;
base::Optional<CSSOrigin> GetCssOrigin() const override;
const base::Optional<std::string> GetInjectionKey() const override;
......
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