guest_view_request.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_
  5. #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_
  6. #include <memory>
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/values.h"
  9. #include "v8/include/v8-forward.h"
  10. #include "v8/include/v8-persistent-handle.h"
  11. namespace guest_view {
  12. class GuestViewContainer;
  13. // This class represents an attach request from Javascript.
  14. // A GuestViewAttachRequest is an asynchronous operation performed on a
  15. // GuestView or GuestViewContainer from JavaScript. This operation may be queued
  16. // until the container is ready to be operated upon (it has geometry). A
  17. // GuestViewAttachRequest may or may not have a callback back into JavaScript.
  18. // Performing a request involves sending an IPC to the browser process in
  19. // PerformRequest which the browser will acknowledge.
  20. class GuestViewAttachRequest {
  21. public:
  22. GuestViewAttachRequest(GuestViewContainer* container,
  23. int render_frame_routing_id,
  24. int guest_instance_id,
  25. base::Value::Dict params,
  26. v8::Local<v8::Function> callback,
  27. v8::Isolate* isolate);
  28. GuestViewAttachRequest(const GuestViewAttachRequest&) = delete;
  29. GuestViewAttachRequest& operator=(const GuestViewAttachRequest&) = delete;
  30. ~GuestViewAttachRequest();
  31. // Performs the associated request.
  32. void PerformRequest();
  33. // Called to call the callback associated with this request if one is
  34. // available.
  35. // Note: the callback may be called even if a response has not been heard from
  36. // the browser process if the GuestViewContainer is being torn down.
  37. void ExecuteCallbackIfAvailable(int argc,
  38. std::unique_ptr<v8::Local<v8::Value>[]> argv);
  39. private:
  40. void OnAcknowledged();
  41. GuestViewContainer* const container_;
  42. v8::Global<v8::Function> callback_;
  43. v8::Isolate* const isolate_;
  44. const int render_frame_routing_id_;
  45. const int guest_instance_id_;
  46. base::Value::Dict params_;
  47. base::WeakPtrFactory<GuestViewAttachRequest> weak_ptr_factory_{this};
  48. };
  49. } // namespace guest_view
  50. #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_REQUEST_H_