Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / extensions / script_executor.h
blobaf2ec57f048e5900695d21da13e362c3cb96ffa4
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_
8 #include <string>
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"
15 class GURL;
16 struct ExtensionMsg_ExecuteCode_Params;
18 namespace base {
19 class ListValue;
20 } // namespace base
22 namespace content {
23 class WebContents;
26 namespace extensions {
28 // Interface for executing extension content scripts (e.g. executeScript) as
29 // described by the ExtensionMsg_ExecuteCode_Params IPC, and notifying the
30 // caller when responded with ExtensionHostMsg_ExecuteCodeFinished.
31 class ScriptExecutor {
32 public:
33 ScriptExecutor(
34 content::WebContents* web_contents,
35 // |script_observers| is assumed to be owned by |this|'s owner, and in
36 // such a way that |this| is destroyed first.
37 ObserverList<TabHelper::ScriptExecutionObserver>* script_observers);
39 ~ScriptExecutor();
41 // The type of script being injected.
42 enum ScriptType {
43 JAVASCRIPT,
44 CSS,
47 // The scope of the script injection across the frames.
48 enum FrameScope {
49 TOP_FRAME,
50 ALL_FRAMES,
53 // Whether to insert the script in about: frames when its origin matches
54 // the extension's host permissions.
55 enum MatchAboutBlank {
56 DONT_MATCH_ABOUT_BLANK,
57 MATCH_ABOUT_BLANK,
60 // The type of world to inject into (main world, or its own isolated world).
61 enum WorldType {
62 MAIN_WORLD,
63 ISOLATED_WORLD,
66 // The type of process the target is.
67 enum ProcessType {
68 DEFAULT_PROCESS,
69 WEB_VIEW_PROCESS,
72 // The type of result the caller is interested in.
73 enum ResultType {
74 NO_RESULT,
75 JSON_SERIALIZED_RESULT,
78 // Callback from ExecuteScript. The arguments are (error, on_page_id, on_url,
79 // result). Success is implied by an empty error.
80 typedef base::Callback<void(const std::string&, int32, const GURL&,
81 const base::ListValue&)>
82 ExecuteScriptCallback;
84 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in
85 // extension_messages.h (request_id is populated automatically).
87 // |callback| will always be called even if the IPC'd renderer is destroyed
88 // before a response is received (in this case the callback will be with a
89 // failure and appropriate error message).
90 void ExecuteScript(const std::string& extension_id,
91 ScriptType script_type,
92 const std::string& code,
93 FrameScope frame_scope,
94 MatchAboutBlank match_about_blank,
95 UserScript::RunLocation run_at,
96 WorldType world_type,
97 ProcessType process_type,
98 const GURL& webview_src,
99 const GURL& file_url,
100 bool user_gesture,
101 ResultType result_type,
102 const ExecuteScriptCallback& callback);
104 private:
105 // Called upon a request being given to execute the script.
106 void ExecuteScriptHelper(scoped_ptr<ExtensionMsg_ExecuteCode_Params> params,
107 const ExecuteScriptCallback& callback);
109 // The next value to use for request_id in ExtensionMsg_ExecuteCode_Params.
110 int next_request_id_;
112 content::WebContents* web_contents_;
114 ObserverList<TabHelper::ScriptExecutionObserver>* script_observers_;
117 } // namespace extensions
119 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_