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, ...@@ -167,7 +167,7 @@ bool ExecuteCodeFunction::Execute(const std::string& code_string,
executor->ExecuteScript( executor->ExecuteScript(
host_id_, script_type, code_string, frame_scope, frame_id, 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 IsWebView() ? ScriptExecutor::WEB_VIEW_PROCESS
: ScriptExecutor::DEFAULT_PROCESS, : ScriptExecutor::DEFAULT_PROCESS,
GetWebViewSrc(), file_url_, user_gesture(), css_origin, GetWebViewSrc(), file_url_, user_gesture(), css_origin,
......
...@@ -242,7 +242,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id, ...@@ -242,7 +242,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id,
int frame_id, int frame_id,
ScriptExecutor::MatchAboutBlank about_blank, ScriptExecutor::MatchAboutBlank about_blank,
UserScript::RunLocation run_at, UserScript::RunLocation run_at,
ScriptExecutor::WorldType world_type,
ScriptExecutor::ProcessType process_type, ScriptExecutor::ProcessType process_type,
const GURL& webview_src, const GURL& webview_src,
const GURL& file_url, const GURL& file_url,
...@@ -268,7 +267,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id, ...@@ -268,7 +267,6 @@ void ScriptExecutor::ExecuteScript(const HostID& host_id,
params.code = code; params.code = code;
params.match_about_blank = (about_blank == MATCH_ABOUT_BLANK); params.match_about_blank = (about_blank == MATCH_ABOUT_BLANK);
params.run_at = run_at; params.run_at = run_at;
params.in_main_world = (world_type == MAIN_WORLD);
params.is_web_view = (process_type == WEB_VIEW_PROCESS); params.is_web_view = (process_type == WEB_VIEW_PROCESS);
params.webview_src = webview_src; params.webview_src = webview_src;
params.file_url = file_url; params.file_url = file_url;
......
...@@ -65,12 +65,6 @@ class ScriptExecutor { ...@@ -65,12 +65,6 @@ class ScriptExecutor {
MATCH_ABOUT_BLANK, 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. // The type of process the target is.
enum ProcessType { enum ProcessType {
DEFAULT_PROCESS, DEFAULT_PROCESS,
...@@ -106,7 +100,6 @@ class ScriptExecutor { ...@@ -106,7 +100,6 @@ class ScriptExecutor {
int frame_id, int frame_id,
MatchAboutBlank match_about_blank, MatchAboutBlank match_about_blank,
UserScript::RunLocation run_at, UserScript::RunLocation run_at,
WorldType world_type,
ProcessType process_type, ProcessType process_type,
const GURL& webview_src, const GURL& webview_src,
const GURL& file_url, const GURL& file_url,
......
...@@ -171,10 +171,6 @@ IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params) ...@@ -171,10 +171,6 @@ IPC_STRUCT_BEGIN(ExtensionMsg_ExecuteCode_Params)
// When to inject the code. // When to inject the code.
IPC_STRUCT_MEMBER(extensions::UserScript::RunLocation, run_at) 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>. // Whether the request is coming from a <webview>.
IPC_STRUCT_MEMBER(bool, is_web_view) IPC_STRUCT_MEMBER(bool, is_web_view)
......
...@@ -39,10 +39,6 @@ UserScript::InjectionType ProgrammaticScriptInjector::script_type() ...@@ -39,10 +39,6 @@ UserScript::InjectionType ProgrammaticScriptInjector::script_type()
return UserScript::PROGRAMMATIC_SCRIPT; return UserScript::PROGRAMMATIC_SCRIPT;
} }
bool ProgrammaticScriptInjector::ShouldExecuteInMainWorld() const {
return params_->in_main_world;
}
bool ProgrammaticScriptInjector::IsUserGesture() const { bool ProgrammaticScriptInjector::IsUserGesture() const {
return params_->user_gesture; return params_->user_gesture;
} }
......
...@@ -30,7 +30,6 @@ class ProgrammaticScriptInjector : public ScriptInjector { ...@@ -30,7 +30,6 @@ class ProgrammaticScriptInjector : public ScriptInjector {
private: private:
// ScriptInjector implementation. // ScriptInjector implementation.
UserScript::InjectionType script_type() const override; UserScript::InjectionType script_type() const override;
bool ShouldExecuteInMainWorld() const override;
bool IsUserGesture() const override; bool IsUserGesture() const override;
base::Optional<CSSOrigin> GetCssOrigin() const override; base::Optional<CSSOrigin> GetCssOrigin() const override;
const base::Optional<std::string> GetInjectionKey() const override; const base::Optional<std::string> GetInjectionKey() const override;
......
...@@ -288,11 +288,8 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts, ...@@ -288,11 +288,8 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts,
std::vector<blink::WebScriptSource> sources = injector_->GetJsSources( std::vector<blink::WebScriptSource> sources = injector_->GetJsSources(
run_location_, executing_scripts, num_injected_js_scripts); run_location_, executing_scripts, num_injected_js_scripts);
DCHECK(!sources.empty()); DCHECK(!sources.empty());
bool in_main_world = injector_->ShouldExecuteInMainWorld(); int world_id =
int world_id = in_main_world GetIsolatedWorldIdForInstance(injection_host_.get(), web_frame);
? DOMActivityLogger::kMainWorldId
: GetIsolatedWorldIdForInstance(injection_host_.get(),
web_frame);
bool is_user_gesture = injector_->IsUserGesture(); bool is_user_gesture = injector_->IsUserGesture();
std::unique_ptr<blink::WebScriptExecutionCallback> callback( std::unique_ptr<blink::WebScriptExecutionCallback> callback(
...@@ -301,31 +298,24 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts, ...@@ -301,31 +298,24 @@ void ScriptInjection::InjectJs(std::set<std::string>* executing_scripts,
base::ElapsedTimer exec_timer; base::ElapsedTimer exec_timer;
if (injection_host_->id().type() == HostID::EXTENSIONS && log_activity_) if (injection_host_->id().type() == HostID::EXTENSIONS && log_activity_)
DOMActivityLogger::AttachToWorld(world_id, injection_host_->id().id()); 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( blink::WebLocalFrame::ScriptExecutionType option;
sources.front(), is_user_gesture, callback.release()); if (injector_->script_type() == UserScript::CONTENT_SCRIPT) {
} else { switch (run_location_) {
blink::WebLocalFrame::ScriptExecutionType option; case UserScript::DOCUMENT_END:
if (injector_->script_type() == UserScript::CONTENT_SCRIPT) { case UserScript::DOCUMENT_IDLE:
switch (run_location_) { option = blink::WebLocalFrame::kAsynchronousBlockingOnload;
case UserScript::DOCUMENT_END: break;
case UserScript::DOCUMENT_IDLE: default:
option = blink::WebLocalFrame::kAsynchronousBlockingOnload; option = blink::WebLocalFrame::kSynchronous;
break; break;
default:
option = blink::WebLocalFrame::kSynchronous;
break;
}
} else {
option = blink::WebLocalFrame::kSynchronous;
} }
web_frame->RequestExecuteScriptInIsolatedWorld( } else {
world_id, &sources.front(), sources.size(), is_user_gesture, option, option = blink::WebLocalFrame::kSynchronous;
callback.release());
} }
web_frame->RequestExecuteScriptInIsolatedWorld(
world_id, &sources.front(), sources.size(), is_user_gesture, option,
callback.release());
} }
void ScriptInjection::OnJsInjectionCompleted( void ScriptInjection::OnJsInjectionCompleted(
......
...@@ -22,8 +22,8 @@ class WebLocalFrame; ...@@ -22,8 +22,8 @@ class WebLocalFrame;
namespace extensions { namespace extensions {
// The pseudo-delegate class for a ScriptInjection that provides all necessary // The pseudo-delegate class for a ScriptInjection that provides all necessary
// information about how to inject the script, including what code to inject, // information about how to inject the script, including what code to inject and
// when (run location), and where (world), but without any injection logic. // when (run location), but without any injection logic.
class ScriptInjector { class ScriptInjector {
public: public:
// The possible reasons for not injecting the script. // The possible reasons for not injecting the script.
...@@ -39,9 +39,6 @@ class ScriptInjector { ...@@ -39,9 +39,6 @@ class ScriptInjector {
// Returns the script type of this particular injection. // Returns the script type of this particular injection.
virtual UserScript::InjectionType script_type() const = 0; 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. // Returns true if the script is running inside a user gesture.
virtual bool IsUserGesture() const = 0; virtual bool IsUserGesture() const = 0;
......
...@@ -133,10 +133,6 @@ UserScript::InjectionType UserScriptInjector::script_type() const { ...@@ -133,10 +133,6 @@ UserScript::InjectionType UserScriptInjector::script_type() const {
return UserScript::CONTENT_SCRIPT; return UserScript::CONTENT_SCRIPT;
} }
bool UserScriptInjector::ShouldExecuteInMainWorld() const {
return false;
}
bool UserScriptInjector::IsUserGesture() const { bool UserScriptInjector::IsUserGesture() const {
return false; return false;
} }
......
...@@ -38,7 +38,6 @@ class UserScriptInjector : public ScriptInjector, ...@@ -38,7 +38,6 @@ class UserScriptInjector : public ScriptInjector,
// ScriptInjector implementation. // ScriptInjector implementation.
UserScript::InjectionType script_type() const override; UserScript::InjectionType script_type() const override;
bool ShouldExecuteInMainWorld() const override;
bool IsUserGesture() const override; bool IsUserGesture() const override;
base::Optional<CSSOrigin> GetCssOrigin() const override; base::Optional<CSSOrigin> GetCssOrigin() const override;
const base::Optional<std::string> GetInjectionKey() 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