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_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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // Derived classes should implement this method to do their work and return | 156 // Derived classes should implement this method to do their work and return |
157 // success/failure. | 157 // success/failure. |
158 virtual bool RunImpl() = 0; | 158 virtual bool RunImpl() = 0; |
159 | 159 |
160 // Sends the result back to the extension. | 160 // Sends the result back to the extension. |
161 virtual void SendResponse(bool success) = 0; | 161 virtual void SendResponse(bool success) = 0; |
162 | 162 |
163 // Common implementation for SendResponse. | 163 // Common implementation for SendResponse. |
164 void SendResponseImpl(base::ProcessHandle process, | 164 void SendResponseImpl(base::ProcessHandle process, |
165 IPC::Sender* ipc_sender, | 165 IPC::Sender* ipc_sender, |
166 int routing_id, | |
167 bool success); | 166 bool success); |
168 | 167 |
169 // Called when we receive an extension api request that is invalid in a way | 168 // Called when we receive an extension api request that is invalid in a way |
170 // that JSON validation in the renderer should have caught. This should never | 169 // that JSON validation in the renderer should have caught. This should never |
171 // happen and could be an attacker trying to exploit the browser, so we crash | 170 // happen and could be an attacker trying to exploit the browser, so we crash |
172 // the renderer instead. | 171 // the renderer instead. |
173 void HandleBadMessage(base::ProcessHandle process); | 172 void HandleBadMessage(base::ProcessHandle process); |
174 | 173 |
175 // Return true if the argument to this function at |index| was provided and | 174 // Return true if the argument to this function at |index| was provided and |
176 // is non-null. | 175 // is non-null. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // extension process happens on the IO thread). It's intended to be used when | 349 // extension process happens on the IO thread). It's intended to be used when |
351 // performance is critical (e.g. the webRequest API which can block network | 350 // performance is critical (e.g. the webRequest API which can block network |
352 // requests). Generally, UIThreadExtensionFunction is more appropriate and will | 351 // requests). Generally, UIThreadExtensionFunction is more appropriate and will |
353 // be easier to use and interface with the rest of the browser. | 352 // be easier to use and interface with the rest of the browser. |
354 class IOThreadExtensionFunction : public ExtensionFunction { | 353 class IOThreadExtensionFunction : public ExtensionFunction { |
355 public: | 354 public: |
356 IOThreadExtensionFunction(); | 355 IOThreadExtensionFunction(); |
357 | 356 |
358 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() OVERRIDE; | 357 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() OVERRIDE; |
359 | 358 |
360 void set_ipc_sender(base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 359 void set_ipc_sender(base::WeakPtr<ChromeRenderMessageFilter> ipc_sender) { |
361 int routing_id) { | |
362 ipc_sender_ = ipc_sender; | 360 ipc_sender_ = ipc_sender; |
363 routing_id_ = routing_id; | |
364 } | 361 } |
365 ChromeRenderMessageFilter* ipc_sender() const { return ipc_sender_.get(); } | 362 ChromeRenderMessageFilter* ipc_sender() const { return ipc_sender_.get(); } |
366 int routing_id() const { return routing_id_; } | |
367 | 363 |
368 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const { | 364 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const { |
369 return ipc_sender_; | 365 return ipc_sender_; |
370 } | 366 } |
371 | 367 |
372 void set_extension_info_map(const ExtensionInfoMap* extension_info_map) { | 368 void set_extension_info_map(const ExtensionInfoMap* extension_info_map) { |
373 extension_info_map_ = extension_info_map; | 369 extension_info_map_ = extension_info_map; |
374 } | 370 } |
375 const ExtensionInfoMap* extension_info_map() const { | 371 const ExtensionInfoMap* extension_info_map() const { |
376 return extension_info_map_.get(); | 372 return extension_info_map_.get(); |
377 } | 373 } |
378 | 374 |
379 protected: | 375 protected: |
380 friend struct content::BrowserThread::DeleteOnThread< | 376 friend struct content::BrowserThread::DeleteOnThread< |
381 content::BrowserThread::IO>; | 377 content::BrowserThread::IO>; |
382 friend class base::DeleteHelper<IOThreadExtensionFunction>; | 378 friend class base::DeleteHelper<IOThreadExtensionFunction>; |
383 | 379 |
384 virtual ~IOThreadExtensionFunction(); | 380 virtual ~IOThreadExtensionFunction(); |
385 | 381 |
386 virtual void Destruct() const OVERRIDE; | 382 virtual void Destruct() const OVERRIDE; |
387 | 383 |
388 virtual void SendResponse(bool success) OVERRIDE; | 384 virtual void SendResponse(bool success) OVERRIDE; |
389 | 385 |
390 private: | 386 private: |
391 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; | 387 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; |
392 int routing_id_; | |
393 | 388 |
394 scoped_refptr<const ExtensionInfoMap> extension_info_map_; | 389 scoped_refptr<const ExtensionInfoMap> extension_info_map_; |
395 }; | 390 }; |
396 | 391 |
397 // Base class for an extension function that runs asynchronously *relative to | 392 // Base class for an extension function that runs asynchronously *relative to |
398 // the browser's UI thread*. | 393 // the browser's UI thread*. |
399 class AsyncExtensionFunction : public UIThreadExtensionFunction { | 394 class AsyncExtensionFunction : public UIThreadExtensionFunction { |
400 public: | 395 public: |
401 AsyncExtensionFunction(); | 396 AsyncExtensionFunction(); |
402 | 397 |
(...skipping 22 matching lines...) Expand all Loading... |
425 public: | 420 public: |
426 SyncIOThreadExtensionFunction(); | 421 SyncIOThreadExtensionFunction(); |
427 | 422 |
428 virtual void Run() OVERRIDE; | 423 virtual void Run() OVERRIDE; |
429 | 424 |
430 protected: | 425 protected: |
431 virtual ~SyncIOThreadExtensionFunction(); | 426 virtual ~SyncIOThreadExtensionFunction(); |
432 }; | 427 }; |
433 | 428 |
434 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 429 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
OLD | NEW |