OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Helper method for ExtensionFunctionDeleteTraits. Deletes this object. | 135 // Helper method for ExtensionFunctionDeleteTraits. Deletes this object. |
136 virtual void Destruct() const = 0; | 136 virtual void Destruct() const = 0; |
137 | 137 |
138 // Derived classes should implement this method to do their work and return | 138 // Derived classes should implement this method to do their work and return |
139 // success/failure. | 139 // success/failure. |
140 virtual bool RunImpl() = 0; | 140 virtual bool RunImpl() = 0; |
141 | 141 |
142 // Sends the result back to the extension. | 142 // Sends the result back to the extension. |
143 virtual void SendResponse(bool success) = 0; | 143 virtual void SendResponse(bool success) = 0; |
144 | 144 |
145 // Common implementation for SenderResponse. | 145 // Common implementation for SendResponse. |
146 void SendResponseImpl(base::ProcessHandle process, | 146 void SendResponseImpl(base::ProcessHandle process, |
147 IPC::Message::Sender* ipc_sender, | 147 IPC::Message::Sender* ipc_sender, |
148 int routing_id, | 148 int routing_id, |
149 bool success); | 149 bool success); |
150 | 150 |
151 // Called when we receive an extension api request that is invalid in a way | 151 // Called when we receive an extension api request that is invalid in a way |
152 // that JSON validation in the renderer should have caught. This should never | 152 // that JSON validation in the renderer should have caught. This should never |
153 // happen and could be an attacker trying to exploit the browser, so we crash | 153 // happen and could be an attacker trying to exploit the browser, so we crash |
154 // the renderer instead. | 154 // the renderer instead. |
155 void HandleBadMessage(base::ProcessHandle process); | 155 void HandleBadMessage(base::ProcessHandle process); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; | 333 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; |
334 int routing_id_; | 334 int routing_id_; |
335 | 335 |
336 scoped_refptr<const ExtensionInfoMap> extension_info_map_; | 336 scoped_refptr<const ExtensionInfoMap> extension_info_map_; |
337 }; | 337 }; |
338 | 338 |
339 // Base class for an extension function that runs asynchronously *relative to | 339 // Base class for an extension function that runs asynchronously *relative to |
340 // the browser's UI thread*. | 340 // the browser's UI thread*. |
341 class AsyncExtensionFunction : public UIThreadExtensionFunction { | 341 class AsyncExtensionFunction : public UIThreadExtensionFunction { |
342 public: | 342 public: |
| 343 // A delegate for use in testing, to intercept the call to SendResponse. |
| 344 class DelegateForTests { |
| 345 public: |
| 346 virtual void OnSendResponse(AsyncExtensionFunction* function, |
| 347 bool success) = 0; |
| 348 }; |
| 349 |
343 AsyncExtensionFunction(); | 350 AsyncExtensionFunction(); |
| 351 virtual void SendResponse(bool success) OVERRIDE; |
| 352 |
| 353 void set_test_delegate(DelegateForTests* delegate) { |
| 354 delegate_ = delegate; |
| 355 } |
344 | 356 |
345 protected: | 357 protected: |
346 virtual ~AsyncExtensionFunction(); | 358 virtual ~AsyncExtensionFunction(); |
| 359 |
| 360 DelegateForTests* delegate_; |
347 }; | 361 }; |
348 | 362 |
349 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously | 363 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously |
350 // *relative to the browser's UI thread*. Note that this has nothing to do with | 364 // *relative to the browser's UI thread*. Note that this has nothing to do with |
351 // running synchronously relative to the extension process. From the extension | 365 // running synchronously relative to the extension process. From the extension |
352 // process's point of view, the function is still asynchronous. | 366 // process's point of view, the function is still asynchronous. |
353 // | 367 // |
354 // This kind of function is convenient for implementing simple APIs that just | 368 // This kind of function is convenient for implementing simple APIs that just |
355 // need to interact with things on the browser UI thread. | 369 // need to interact with things on the browser UI thread. |
356 class SyncExtensionFunction : public UIThreadExtensionFunction { | 370 class SyncExtensionFunction : public UIThreadExtensionFunction { |
(...skipping 10 matching lines...) Expand all Loading... |
367 public: | 381 public: |
368 SyncIOThreadExtensionFunction(); | 382 SyncIOThreadExtensionFunction(); |
369 | 383 |
370 virtual void Run() OVERRIDE; | 384 virtual void Run() OVERRIDE; |
371 | 385 |
372 protected: | 386 protected: |
373 virtual ~SyncIOThreadExtensionFunction(); | 387 virtual ~SyncIOThreadExtensionFunction(); |
374 }; | 388 }; |
375 | 389 |
376 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 390 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
OLD | NEW |