OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // A delegate for use in testing, to intercept the call to SendResponse. | 399 // A delegate for use in testing, to intercept the call to SendResponse. |
400 class DelegateForTests { | 400 class DelegateForTests { |
401 public: | 401 public: |
402 virtual void OnSendResponse(UIThreadExtensionFunction* function, | 402 virtual void OnSendResponse(UIThreadExtensionFunction* function, |
403 bool success, | 403 bool success, |
404 bool bad_message) = 0; | 404 bool bad_message) = 0; |
405 }; | 405 }; |
406 | 406 |
407 UIThreadExtensionFunction(); | 407 UIThreadExtensionFunction(); |
408 | 408 |
409 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction() OVERRIDE; | 409 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction() override; |
410 | 410 |
411 void set_test_delegate(DelegateForTests* delegate) { | 411 void set_test_delegate(DelegateForTests* delegate) { |
412 delegate_ = delegate; | 412 delegate_ = delegate; |
413 } | 413 } |
414 | 414 |
415 // Called when a message was received. | 415 // Called when a message was received. |
416 // Should return true if it processed the message. | 416 // Should return true if it processed the message. |
417 virtual bool OnMessageReceived(const IPC::Message& message); | 417 virtual bool OnMessageReceived(const IPC::Message& message); |
418 | 418 |
419 // Set the browser context which contains the extension that has originated | 419 // Set the browser context which contains the extension that has originated |
(...skipping 28 matching lines...) Expand all Loading... |
448 // Emits a message to the extension's devtools console. | 448 // Emits a message to the extension's devtools console. |
449 void WriteToConsole(content::ConsoleMessageLevel level, | 449 void WriteToConsole(content::ConsoleMessageLevel level, |
450 const std::string& message); | 450 const std::string& message); |
451 | 451 |
452 friend struct content::BrowserThread::DeleteOnThread< | 452 friend struct content::BrowserThread::DeleteOnThread< |
453 content::BrowserThread::UI>; | 453 content::BrowserThread::UI>; |
454 friend class base::DeleteHelper<UIThreadExtensionFunction>; | 454 friend class base::DeleteHelper<UIThreadExtensionFunction>; |
455 | 455 |
456 virtual ~UIThreadExtensionFunction(); | 456 virtual ~UIThreadExtensionFunction(); |
457 | 457 |
458 virtual void SendResponse(bool success) OVERRIDE; | 458 virtual void SendResponse(bool success) override; |
459 | 459 |
460 // Sets the Blob UUIDs whose ownership is being transferred to the renderer. | 460 // Sets the Blob UUIDs whose ownership is being transferred to the renderer. |
461 void SetTransferredBlobUUIDs(const std::vector<std::string>& blob_uuids); | 461 void SetTransferredBlobUUIDs(const std::vector<std::string>& blob_uuids); |
462 | 462 |
463 // The dispatcher that will service this extension function call. | 463 // The dispatcher that will service this extension function call. |
464 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_; | 464 base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_; |
465 | 465 |
466 // The RenderViewHost we will send responses to. | 466 // The RenderViewHost we will send responses to. |
467 content::RenderViewHost* render_view_host_; | 467 content::RenderViewHost* render_view_host_; |
468 | 468 |
469 // The RenderFrameHost we will send responses to. | 469 // The RenderFrameHost we will send responses to. |
470 // NOTE: either render_view_host_ or render_frame_host_ will be set, as we | 470 // NOTE: either render_view_host_ or render_frame_host_ will be set, as we |
471 // port code to use RenderFrames for OOPIF. See http://crbug.com/304341. | 471 // port code to use RenderFrames for OOPIF. See http://crbug.com/304341. |
472 content::RenderFrameHost* render_frame_host_; | 472 content::RenderFrameHost* render_frame_host_; |
473 | 473 |
474 // The content::BrowserContext of this function's extension. | 474 // The content::BrowserContext of this function's extension. |
475 content::BrowserContext* context_; | 475 content::BrowserContext* context_; |
476 | 476 |
477 private: | 477 private: |
478 class RenderHostTracker; | 478 class RenderHostTracker; |
479 | 479 |
480 virtual void Destruct() const OVERRIDE; | 480 virtual void Destruct() const override; |
481 | 481 |
482 // TODO(tommycli): Remove once RenderViewHost is gone. | 482 // TODO(tommycli): Remove once RenderViewHost is gone. |
483 IPC::Sender* GetIPCSender(); | 483 IPC::Sender* GetIPCSender(); |
484 int GetRoutingID(); | 484 int GetRoutingID(); |
485 | 485 |
486 scoped_ptr<RenderHostTracker> tracker_; | 486 scoped_ptr<RenderHostTracker> tracker_; |
487 | 487 |
488 DelegateForTests* delegate_; | 488 DelegateForTests* delegate_; |
489 | 489 |
490 // The blobs transferred to the renderer process. | 490 // The blobs transferred to the renderer process. |
491 std::vector<std::string> transferred_blob_uuids_; | 491 std::vector<std::string> transferred_blob_uuids_; |
492 }; | 492 }; |
493 | 493 |
494 // Extension functions that run on the IO thread. This type of function avoids | 494 // Extension functions that run on the IO thread. This type of function avoids |
495 // a roundtrip to and from the UI thread (because communication with the | 495 // a roundtrip to and from the UI thread (because communication with the |
496 // extension process happens on the IO thread). It's intended to be used when | 496 // extension process happens on the IO thread). It's intended to be used when |
497 // performance is critical (e.g. the webRequest API which can block network | 497 // performance is critical (e.g. the webRequest API which can block network |
498 // requests). Generally, UIThreadExtensionFunction is more appropriate and will | 498 // requests). Generally, UIThreadExtensionFunction is more appropriate and will |
499 // be easier to use and interface with the rest of the browser. | 499 // be easier to use and interface with the rest of the browser. |
500 class IOThreadExtensionFunction : public ExtensionFunction { | 500 class IOThreadExtensionFunction : public ExtensionFunction { |
501 public: | 501 public: |
502 IOThreadExtensionFunction(); | 502 IOThreadExtensionFunction(); |
503 | 503 |
504 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() OVERRIDE; | 504 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() override; |
505 | 505 |
506 void set_ipc_sender( | 506 void set_ipc_sender( |
507 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender, | 507 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender, |
508 int routing_id) { | 508 int routing_id) { |
509 ipc_sender_ = ipc_sender; | 509 ipc_sender_ = ipc_sender; |
510 routing_id_ = routing_id; | 510 routing_id_ = routing_id; |
511 } | 511 } |
512 | 512 |
513 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_weak() const { | 513 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_weak() const { |
514 return ipc_sender_; | 514 return ipc_sender_; |
515 } | 515 } |
516 | 516 |
517 int routing_id() const { return routing_id_; } | 517 int routing_id() const { return routing_id_; } |
518 | 518 |
519 void set_extension_info_map(const extensions::InfoMap* extension_info_map) { | 519 void set_extension_info_map(const extensions::InfoMap* extension_info_map) { |
520 extension_info_map_ = extension_info_map; | 520 extension_info_map_ = extension_info_map; |
521 } | 521 } |
522 const extensions::InfoMap* extension_info_map() const { | 522 const extensions::InfoMap* extension_info_map() const { |
523 return extension_info_map_.get(); | 523 return extension_info_map_.get(); |
524 } | 524 } |
525 | 525 |
526 protected: | 526 protected: |
527 friend struct content::BrowserThread::DeleteOnThread< | 527 friend struct content::BrowserThread::DeleteOnThread< |
528 content::BrowserThread::IO>; | 528 content::BrowserThread::IO>; |
529 friend class base::DeleteHelper<IOThreadExtensionFunction>; | 529 friend class base::DeleteHelper<IOThreadExtensionFunction>; |
530 | 530 |
531 virtual ~IOThreadExtensionFunction(); | 531 virtual ~IOThreadExtensionFunction(); |
532 | 532 |
533 virtual void Destruct() const OVERRIDE; | 533 virtual void Destruct() const override; |
534 | 534 |
535 virtual void SendResponse(bool success) OVERRIDE; | 535 virtual void SendResponse(bool success) override; |
536 | 536 |
537 private: | 537 private: |
538 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_; | 538 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_; |
539 int routing_id_; | 539 int routing_id_; |
540 | 540 |
541 scoped_refptr<const extensions::InfoMap> extension_info_map_; | 541 scoped_refptr<const extensions::InfoMap> extension_info_map_; |
542 }; | 542 }; |
543 | 543 |
544 // Base class for an extension function that runs asynchronously *relative to | 544 // Base class for an extension function that runs asynchronously *relative to |
545 // the browser's UI thread*. | 545 // the browser's UI thread*. |
546 class AsyncExtensionFunction : public UIThreadExtensionFunction { | 546 class AsyncExtensionFunction : public UIThreadExtensionFunction { |
547 public: | 547 public: |
548 AsyncExtensionFunction(); | 548 AsyncExtensionFunction(); |
549 | 549 |
550 protected: | 550 protected: |
551 virtual ~AsyncExtensionFunction(); | 551 virtual ~AsyncExtensionFunction(); |
552 | 552 |
553 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead. | 553 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead. |
554 // | 554 // |
555 // AsyncExtensionFunctions implement this method. Return true to indicate that | 555 // AsyncExtensionFunctions implement this method. Return true to indicate that |
556 // nothing has gone wrong yet; SendResponse must be called later. Return false | 556 // nothing has gone wrong yet; SendResponse must be called later. Return false |
557 // to respond immediately with an error. | 557 // to respond immediately with an error. |
558 virtual bool RunAsync() = 0; | 558 virtual bool RunAsync() = 0; |
559 | 559 |
560 // ValidationFailure override to match RunAsync(). | 560 // ValidationFailure override to match RunAsync(). |
561 static bool ValidationFailure(AsyncExtensionFunction* function); | 561 static bool ValidationFailure(AsyncExtensionFunction* function); |
562 | 562 |
563 private: | 563 private: |
564 virtual ResponseAction Run() OVERRIDE; | 564 virtual ResponseAction Run() override; |
565 }; | 565 }; |
566 | 566 |
567 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously | 567 // A SyncExtensionFunction is an ExtensionFunction that runs synchronously |
568 // *relative to the browser's UI thread*. Note that this has nothing to do with | 568 // *relative to the browser's UI thread*. Note that this has nothing to do with |
569 // running synchronously relative to the extension process. From the extension | 569 // running synchronously relative to the extension process. From the extension |
570 // process's point of view, the function is still asynchronous. | 570 // process's point of view, the function is still asynchronous. |
571 // | 571 // |
572 // This kind of function is convenient for implementing simple APIs that just | 572 // This kind of function is convenient for implementing simple APIs that just |
573 // need to interact with things on the browser UI thread. | 573 // need to interact with things on the browser UI thread. |
574 class SyncExtensionFunction : public UIThreadExtensionFunction { | 574 class SyncExtensionFunction : public UIThreadExtensionFunction { |
575 public: | 575 public: |
576 SyncExtensionFunction(); | 576 SyncExtensionFunction(); |
577 | 577 |
578 protected: | 578 protected: |
579 virtual ~SyncExtensionFunction(); | 579 virtual ~SyncExtensionFunction(); |
580 | 580 |
581 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead. | 581 // Deprecated: Override UIThreadExtensionFunction and implement Run() instead. |
582 // | 582 // |
583 // SyncExtensionFunctions implement this method. Return true to respond | 583 // SyncExtensionFunctions implement this method. Return true to respond |
584 // immediately with success, false to respond immediately with an error. | 584 // immediately with success, false to respond immediately with an error. |
585 virtual bool RunSync() = 0; | 585 virtual bool RunSync() = 0; |
586 | 586 |
587 // ValidationFailure override to match RunSync(). | 587 // ValidationFailure override to match RunSync(). |
588 static bool ValidationFailure(SyncExtensionFunction* function); | 588 static bool ValidationFailure(SyncExtensionFunction* function); |
589 | 589 |
590 private: | 590 private: |
591 virtual ResponseAction Run() OVERRIDE; | 591 virtual ResponseAction Run() override; |
592 }; | 592 }; |
593 | 593 |
594 class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction { | 594 class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction { |
595 public: | 595 public: |
596 SyncIOThreadExtensionFunction(); | 596 SyncIOThreadExtensionFunction(); |
597 | 597 |
598 protected: | 598 protected: |
599 virtual ~SyncIOThreadExtensionFunction(); | 599 virtual ~SyncIOThreadExtensionFunction(); |
600 | 600 |
601 // Deprecated: Override IOThreadExtensionFunction and implement Run() instead. | 601 // Deprecated: Override IOThreadExtensionFunction and implement Run() instead. |
602 // | 602 // |
603 // SyncIOThreadExtensionFunctions implement this method. Return true to | 603 // SyncIOThreadExtensionFunctions implement this method. Return true to |
604 // respond immediately with success, false to respond immediately with an | 604 // respond immediately with success, false to respond immediately with an |
605 // error. | 605 // error. |
606 virtual bool RunSync() = 0; | 606 virtual bool RunSync() = 0; |
607 | 607 |
608 // ValidationFailure override to match RunSync(). | 608 // ValidationFailure override to match RunSync(). |
609 static bool ValidationFailure(SyncIOThreadExtensionFunction* function); | 609 static bool ValidationFailure(SyncIOThreadExtensionFunction* function); |
610 | 610 |
611 private: | 611 private: |
612 virtual ResponseAction Run() OVERRIDE; | 612 virtual ResponseAction Run() override; |
613 }; | 613 }; |
614 | 614 |
615 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 615 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
OLD | NEW |