1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_
6 #define EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_
8 #include "base/callback_forward.h"
9 #include "base/observer_list.h"
10 #include "extensions/common/user_script.h"
13 struct ExtensionMsg_ExecuteCode_Params
;
23 namespace extensions
{
24 class ScriptExecutionObserver
;
26 // Interface for executing extension content scripts (e.g. executeScript) as
27 // described by the ExtensionMsg_ExecuteCode_Params IPC, and notifying the
28 // caller when responded with ExtensionHostMsg_ExecuteCodeFinished.
29 class ScriptExecutor
{
32 content::WebContents
* web_contents
,
33 // |script_observers| is assumed to be owned by |this|'s owner, and in
34 // such a way that |this| is destroyed first.
35 ObserverList
<ScriptExecutionObserver
>* script_observers
);
39 // The type of script being injected.
45 // The scope of the script injection across the frames.
51 // Whether to insert the script in about: frames when its origin matches
52 // the extension's host permissions.
53 enum MatchAboutBlank
{
54 DONT_MATCH_ABOUT_BLANK
,
58 // The type of world to inject into (main world, or its own isolated world).
64 // The type of process the target is.
70 // The type of result the caller is interested in.
73 JSON_SERIALIZED_RESULT
,
76 // Callback from ExecuteScript. The arguments are (error, on_url, result).
77 // Success is implied by an empty error.
78 typedef base::Callback
<
79 void(const std::string
&, const GURL
&, const base::ListValue
&)>
80 ExecuteScriptCallback
;
82 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in
83 // extension_messages.h (request_id is populated automatically).
85 // |callback| will always be called even if the IPC'd renderer is destroyed
86 // before a response is received (in this case the callback will be with a
87 // failure and appropriate error message).
88 void ExecuteScript(const HostID
& host_id
,
89 ScriptType script_type
,
90 const std::string
& code
,
91 FrameScope frame_scope
,
92 MatchAboutBlank match_about_blank
,
93 UserScript::RunLocation run_at
,
95 ProcessType process_type
,
96 const GURL
& webview_src
,
99 ResultType result_type
,
100 const ExecuteScriptCallback
& callback
);
103 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params.
104 int next_request_id_
;
106 content::WebContents
* web_contents_
;
108 ObserverList
<ScriptExecutionObserver
>* script_observers_
;
111 } // namespace extensions
113 #endif // EXTENSIONS_BROWSER_SCRIPT_EXECUTOR_H_