1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_
10 #include "base/callback_forward.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/extensions/tab_helper.h"
13 #include "extensions/common/user_script.h"
25 namespace extensions
{
27 // Interface for executing extension content scripts (e.g. executeScript) as
28 // described by the ExtensionMsg_ExecuteCode_Params IPC, and notifying the
29 // caller when responded with ExtensionHostMsg_ExecuteCodeFinished.
30 class ScriptExecutor
{
33 content::WebContents
* web_contents
,
34 // |script_observers| is assumed to be owned by |this|'s owner, and in
35 // such a way that |this| is destroyed first.
36 ObserverList
<TabHelper::ScriptExecutionObserver
>* script_observers
);
40 // The type of script being injected.
46 // The scope of the script injection across the frames.
52 // The type of world to inject into (main world, or its own isolated world).
58 // The type of process the target is.
64 // The type of result the caller is interested in.
67 JSON_SERIALIZED_RESULT
,
70 // Callback from ExecuteScript. The arguments are (error, on_page_id, on_url,
71 // result). Success is implied by an empty error.
72 typedef base::Callback
<void(const std::string
&, int32
, const GURL
&,
73 const base::ListValue
&)>
74 ExecuteScriptCallback
;
76 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in
77 // extension_messages.h (request_id is populated automatically).
79 // |callback| will always be called even if the IPC'd renderer is destroyed
80 // before a response is received (in this case the callback will be with a
81 // failure and appropriate error message).
82 void ExecuteScript(const std::string
& extension_id
,
83 ScriptType script_type
,
84 const std::string
& code
,
85 FrameScope frame_scope
,
86 UserScript::RunLocation run_at
,
88 ProcessType process_type
,
90 ResultType result_type
,
91 const ExecuteScriptCallback
& callback
);
94 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params.
97 content::WebContents
* web_contents_
;
99 ObserverList
<TabHelper::ScriptExecutionObserver
>* script_observers_
;
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_