Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: extensions/browser/script_executor.cc

Issue 1162943002: Replace more ObserverList with base::ObserverList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@observer
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/script_executor.h ('k') | extensions/browser/user_script_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "extensions/browser/script_executor.h" 5 #include "extensions/browser/script_executor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 const char* kRendererDestroyed = "The tab was closed."; 29 const char* kRendererDestroyed = "The tab was closed.";
30 30
31 // A handler for a single injection request. On creation this will send the 31 // A handler for a single injection request. On creation this will send the
32 // injection request to the renderer, and it will be destroyed after either the 32 // injection request to the renderer, and it will be destroyed after either the
33 // corresponding response comes from the renderer, or the renderer is destroyed. 33 // corresponding response comes from the renderer, or the renderer is destroyed.
34 class Handler : public content::WebContentsObserver { 34 class Handler : public content::WebContentsObserver {
35 public: 35 public:
36 Handler(ObserverList<ScriptExecutionObserver>* script_observers, 36 Handler(base::ObserverList<ScriptExecutionObserver>* script_observers,
37 content::WebContents* web_contents, 37 content::WebContents* web_contents,
38 ExtensionMsg_ExecuteCode_Params* params, 38 ExtensionMsg_ExecuteCode_Params* params,
39 ScriptExecutor::FrameScope scope, 39 ScriptExecutor::FrameScope scope,
40 int* request_id_counter, 40 int* request_id_counter,
41 const ScriptExecutor::ExecuteScriptCallback& callback) 41 const ScriptExecutor::ExecuteScriptCallback& callback)
42 : content::WebContentsObserver(web_contents), 42 : content::WebContentsObserver(web_contents),
43 script_observers_(AsWeakPtr(script_observers)), 43 script_observers_(AsWeakPtr(script_observers)),
44 host_id_(params->host_id), 44 host_id_(params->host_id),
45 main_request_id_((*request_id_counter)++), 45 main_request_id_((*request_id_counter)++),
46 sub_request_id_(scope == ScriptExecutor::ALL_FRAMES ? 46 sub_request_id_(scope == ScriptExecutor::ALL_FRAMES ?
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 void Finish(const std::string& error, 142 void Finish(const std::string& error,
143 const GURL& url, 143 const GURL& url,
144 const base::ListValue& result) { 144 const base::ListValue& result) {
145 if (!callback_.is_null()) 145 if (!callback_.is_null())
146 callback_.Run(error, url, result); 146 callback_.Run(error, url, result);
147 delete this; 147 delete this;
148 } 148 }
149 149
150 base::WeakPtr<ObserverList<ScriptExecutionObserver>> script_observers_; 150 base::WeakPtr<base::ObserverList<ScriptExecutionObserver>> script_observers_;
151 151
152 // The id of the host (the extension or the webui) doing the injection. 152 // The id of the host (the extension or the webui) doing the injection.
153 HostID host_id_; 153 HostID host_id_;
154 154
155 // The request id of the injection into the main frame. 155 // The request id of the injection into the main frame.
156 int main_request_id_; 156 int main_request_id_;
157 157
158 // The request id of the injection into any sub frames. We need a separate id 158 // The request id of the injection into any sub frames. We need a separate id
159 // for these so that we know which frame to use as the first result, and which 159 // for these so that we know which frame to use as the first result, and which
160 // error (if any) to use. 160 // error (if any) to use.
(...skipping 17 matching lines...) Expand all
178 DISALLOW_COPY_AND_ASSIGN(Handler); 178 DISALLOW_COPY_AND_ASSIGN(Handler);
179 }; 179 };
180 180
181 } // namespace 181 } // namespace
182 182
183 ScriptExecutionObserver::~ScriptExecutionObserver() { 183 ScriptExecutionObserver::~ScriptExecutionObserver() {
184 } 184 }
185 185
186 ScriptExecutor::ScriptExecutor( 186 ScriptExecutor::ScriptExecutor(
187 content::WebContents* web_contents, 187 content::WebContents* web_contents,
188 ObserverList<ScriptExecutionObserver>* script_observers) 188 base::ObserverList<ScriptExecutionObserver>* script_observers)
189 : next_request_id_(0), 189 : next_request_id_(0),
190 web_contents_(web_contents), 190 web_contents_(web_contents),
191 script_observers_(script_observers) { 191 script_observers_(script_observers) {
192 CHECK(web_contents_); 192 CHECK(web_contents_);
193 } 193 }
194 194
195 ScriptExecutor::~ScriptExecutor() { 195 ScriptExecutor::~ScriptExecutor() {
196 } 196 }
197 197
198 void ScriptExecutor::ExecuteScript(const HostID& host_id, 198 void ScriptExecutor::ExecuteScript(const HostID& host_id,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 params.file_url = file_url; 231 params.file_url = file_url;
232 params.wants_result = (result_type == JSON_SERIALIZED_RESULT); 232 params.wants_result = (result_type == JSON_SERIALIZED_RESULT);
233 params.user_gesture = user_gesture; 233 params.user_gesture = user_gesture;
234 234
235 // Handler handles IPCs and deletes itself on completion. 235 // Handler handles IPCs and deletes itself on completion.
236 new Handler(script_observers_, web_contents_, &params, frame_scope, 236 new Handler(script_observers_, web_contents_, &params, frame_scope,
237 &next_request_id_, callback); 237 &next_request_id_, callback);
238 } 238 }
239 239
240 } // namespace extensions 240 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/script_executor.h ('k') | extensions/browser/user_script_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698