| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_ | 5 #ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_ |
| 6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_ | 6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 10 #include "v8/include/v8.h" | 10 #include "v8/include/v8.h" |
| 11 | 11 |
| 12 namespace guest_view { | 12 namespace guest_view { |
| 13 | 13 |
| 14 class GuestViewContainer; | 14 class GuestViewContainer; |
| 15 | 15 |
| 16 // A GuestViewRequest is the base class for an asynchronous operation performed | 16 // A GuestViewRequest is the base class for an asynchronous operation performed |
| 17 // on a GuestView or GuestViewContainer from JavaScript. This operation may be | 17 // on a GuestView or GuestViewContainer. This operation may be queued until the |
| 18 // queued until the container is ready to be operated upon (it has geometry). | 18 // container is ready to be operated upon (it has geometry). |
| 19 // A GuestViewRequest may or may not have a callback back into JavaScript. | 19 // A GuestViewRequest may or may not have a callback back into JavaScript. |
| 20 // Typically, performing a request involves sending an IPC to the browser | 20 // Typically, performing a request involves sending an IPC to the browser |
| 21 // process in PerformRequest. Handling a response involves receiving a related | 21 // process in PerformRequest. Handling a response involves receiving a related |
| 22 // IPC from the browser process in HandleResponse. | 22 // IPC from the browser process in HandleResponse. |
| 23 class GuestViewRequest { | 23 class GuestViewRequest { |
| 24 public: | 24 public: |
| 25 GuestViewRequest(GuestViewContainer* container, | 25 GuestViewRequest(GuestViewContainer* container); |
| 26 v8::Local<v8::Function> callback, | |
| 27 v8::Isolate* isolate); | |
| 28 virtual ~GuestViewRequest(); | 26 virtual ~GuestViewRequest(); |
| 29 | 27 |
| 30 // Performs the associated request. | 28 // Performs the associated request. |
| 31 virtual void PerformRequest() = 0; | 29 virtual void PerformRequest() = 0; |
| 32 | 30 |
| 33 // Called by GuestViewContainer when the browser process has responded to the | 31 // Called by GuestViewContainer when the browser process has responded to the |
| 34 // request initiated by PerformRequest. | 32 // request initiated by PerformRequest. |
| 35 virtual void HandleResponse(const IPC::Message& message) = 0; | 33 virtual void HandleResponse(const IPC::Message& message) = 0; |
| 36 | 34 |
| 37 // Called to call the callback associated with this request if one is | 35 // Called during tear down to perform the default response action. |
| 38 // available. | 36 virtual void HandleDefaultResponse() = 0; |
| 39 // Note: the callback may be called even if a response has not been heard from | 37 |
| 40 // the browser process if the GuestViewContainer is being torn down. | 38 GuestViewContainer* container() const { return container_; } |
| 39 |
| 40 private: |
| 41 GuestViewContainer* const container_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(GuestViewRequest); |
| 44 }; |
| 45 |
| 46 // A GuestViewJavaScriptRequest is an asynchronous GuestView operation initiated |
| 47 // from JavaScript |
| 48 class GuestViewJavaScriptRequest : public GuestViewRequest { |
| 49 public: |
| 50 GuestViewJavaScriptRequest(GuestViewContainer* container, |
| 51 v8::Local<v8::Function> callback, |
| 52 v8::Isolate* isolate); |
| 53 ~GuestViewJavaScriptRequest() override; |
| 54 |
| 41 void ExecuteCallbackIfAvailable(int argc, | 55 void ExecuteCallbackIfAvailable(int argc, |
| 42 scoped_ptr<v8::Local<v8::Value>[]> argv); | 56 scoped_ptr<v8::Local<v8::Value>[]> argv); |
| 43 | 57 |
| 44 GuestViewContainer* container() const { return container_; } | 58 // GuestViewRequest implementation: |
| 59 void HandleDefaultResponse() override; |
| 45 | 60 |
| 46 v8::Isolate* isolate() const { return isolate_; } | 61 v8::Isolate* isolate() const { return isolate_; } |
| 47 | 62 |
| 48 private: | 63 private: |
| 49 GuestViewContainer* const container_; | |
| 50 v8::Global<v8::Function> callback_; | 64 v8::Global<v8::Function> callback_; |
| 51 v8::Isolate* const isolate_; | 65 v8::Isolate* const isolate_; |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(GuestViewRequest); | |
| 54 }; | 66 }; |
| 55 | 67 |
| 56 // This class represents an AttachGuest request from Javascript. It includes | 68 // This class represents an AttachGuest request from Javascript. It includes |
| 57 // the input parameters and the callback function. The Attach operation may | 69 // the input parameters and the callback function. The Attach operation may |
| 58 // not execute immediately, if the container is not ready or if there are | 70 // not execute immediately, if the container is not ready or if there are |
| 59 // other GuestViewRequests in flight. | 71 // other GuestViewRequests in flight. |
| 60 class GuestViewAttachRequest : public GuestViewRequest { | 72 class GuestViewAttachRequest : public GuestViewJavaScriptRequest { |
| 61 public: | 73 public: |
| 62 GuestViewAttachRequest(GuestViewContainer* container, | 74 GuestViewAttachRequest(GuestViewContainer* container, |
| 63 int guest_instance_id, | 75 int guest_instance_id, |
| 64 scoped_ptr<base::DictionaryValue> params, | 76 scoped_ptr<base::DictionaryValue> params, |
| 65 v8::Local<v8::Function> callback, | 77 v8::Local<v8::Function> callback, |
| 66 v8::Isolate* isolate); | 78 v8::Isolate* isolate); |
| 67 ~GuestViewAttachRequest() override; | 79 ~GuestViewAttachRequest() override; |
| 68 | 80 |
| 69 void PerformRequest() override; | 81 void PerformRequest() override; |
| 70 void HandleResponse(const IPC::Message& message) override; | 82 void HandleResponse(const IPC::Message& message) override; |
| 71 | 83 |
| 72 private: | 84 private: |
| 73 const int guest_instance_id_; | 85 const int guest_instance_id_; |
| 74 scoped_ptr<base::DictionaryValue> params_; | 86 scoped_ptr<base::DictionaryValue> params_; |
| 75 | 87 |
| 76 DISALLOW_COPY_AND_ASSIGN(GuestViewAttachRequest); | 88 DISALLOW_COPY_AND_ASSIGN(GuestViewAttachRequest); |
| 77 }; | 89 }; |
| 78 | 90 |
| 79 // This class represents a DetachGuest request from Javascript. The Detach | 91 // This class represents a DetachGuest request from Javascript. The Detach |
| 80 // operation may not execute immediately, if the container is not ready or if | 92 // operation may not execute immediately, if the container is not ready or if |
| 81 // there are other GuestViewRequests in flight. | 93 // there are other GuestViewRequests in flight. |
| 82 class GuestViewDetachRequest : public GuestViewRequest { | 94 class GuestViewDetachRequest : public GuestViewJavaScriptRequest { |
| 83 public: | 95 public: |
| 84 GuestViewDetachRequest(GuestViewContainer* container, | 96 GuestViewDetachRequest(GuestViewContainer* container, |
| 85 v8::Local<v8::Function> callback, | 97 v8::Local<v8::Function> callback, |
| 86 v8::Isolate* isolate); | 98 v8::Isolate* isolate); |
| 87 ~GuestViewDetachRequest() override; | 99 ~GuestViewDetachRequest() override; |
| 88 | 100 |
| 89 void PerformRequest() override; | 101 void PerformRequest() override; |
| 90 void HandleResponse(const IPC::Message& message) override; | 102 void HandleResponse(const IPC::Message& message) override; |
| 91 | 103 |
| 92 private: | 104 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(GuestViewDetachRequest); | 105 DISALLOW_COPY_AND_ASSIGN(GuestViewDetachRequest); |
| 94 }; | 106 }; |
| 95 | 107 |
| 96 } // namespace guest_view | 108 } // namespace guest_view |
| 97 | 109 |
| 98 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ | 110 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_ |
| OLD | NEW |