OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "chrome/common/extensions/user_script.h" | 12 #include "chrome/common/extensions/user_script.h" |
13 | 13 |
14 class GURL; | |
15 | |
14 namespace base { | 16 namespace base { |
15 class ListValue; | 17 class ListValue; |
16 } // namespace base | 18 } // namespace base |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 class WebContents; | 21 class WebContents; |
20 } | 22 } |
21 | 23 |
22 namespace extensions { | 24 namespace extensions { |
23 | 25 |
(...skipping 17 matching lines...) Expand all Loading... | |
41 TOP_FRAME, | 43 TOP_FRAME, |
42 ALL_FRAMES, | 44 ALL_FRAMES, |
43 }; | 45 }; |
44 | 46 |
45 // The type of world to inject into (main world, or its own isolated world). | 47 // The type of world to inject into (main world, or its own isolated world). |
46 enum WorldType { | 48 enum WorldType { |
47 MAIN_WORLD, | 49 MAIN_WORLD, |
48 ISOLATED_WORLD, | 50 ISOLATED_WORLD, |
49 }; | 51 }; |
50 | 52 |
51 // Callback from ExecuteScript. The arguments are (success, page_id, error, | 53 // Callback from ExecuteScript. The arguments are (error, on_page_id, on_url, |
52 // result). page_id is only valid on success, error is only valid on !success. | 54 // result). Success is implied by an empty error. |
Jeffrey Yasskin
2012/08/06 11:39:02
Probably keep "on_page_id is only valid on success
| |
53 typedef base::Callback<void(bool, int32, const std::string&, | 55 typedef base::Callback<void(const std::string&, int32, const GURL&, |
54 const base::ListValue&)> | 56 const base::ListValue&)> |
55 ExecuteScriptCallback; | 57 ExecuteScriptCallback; |
56 | 58 |
57 class Observer { | 59 class Observer { |
58 public: | 60 public: |
59 // Automatically observes and unobserves *script_executor on construction | 61 // Automatically observes and unobserves *script_executor on construction |
60 // and destruction. *script_executor must outlive *this. | 62 // and destruction. *script_executor must outlive *this. |
61 explicit Observer(ScriptExecutor* script_executor); | 63 explicit Observer(ScriptExecutor* script_executor); |
62 virtual ~Observer(); | 64 virtual ~Observer(); |
63 | 65 |
64 virtual void OnExecuteScriptFinished(const std::string& extension_id, | 66 virtual void OnExecuteScriptFinished(const std::string& extension_id, |
65 bool success, | |
66 int32 page_id, | |
67 const std::string& error, | 67 const std::string& error, |
68 int32 on_page_id, | |
69 const GURL& on_url, | |
68 const base::ListValue&) = 0; | 70 const base::ListValue&) = 0; |
69 private: | 71 private: |
70 ScriptExecutor& script_executor_; | 72 ScriptExecutor& script_executor_; |
71 }; | 73 }; |
72 | 74 |
73 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in | 75 // Executes a script. The arguments match ExtensionMsg_ExecuteCode_Params in |
74 // extension_messages.h (request_id is populated automatically). | 76 // extension_messages.h (request_id is populated automatically). |
75 // | 77 // |
76 // |callback| will always be called even if the IPC'd renderer is destroyed | 78 // |callback| will always be called even if the IPC'd renderer is destroyed |
77 // before a response is received (in this case the callback will be with a | 79 // before a response is received (in this case the callback will be with a |
(...skipping 20 matching lines...) Expand all Loading... | |
98 | 100 |
99 // The WebContents this is bound to. | 101 // The WebContents this is bound to. |
100 content::WebContents* web_contents_; | 102 content::WebContents* web_contents_; |
101 | 103 |
102 ObserverList<Observer> observer_list_; | 104 ObserverList<Observer> observer_list_; |
103 }; | 105 }; |
104 | 106 |
105 } // namespace extensions | 107 } // namespace extensions |
106 | 108 |
107 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ | 109 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_EXECUTOR_H_ |
OLD | NEW |