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 #include "components/guest_view/renderer/guest_view_request.h" | 5 #include "components/guest_view/renderer/guest_view_request.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "components/guest_view/common/guest_view_messages.h" | 9 #include "components/guest_view/common/guest_view_messages.h" |
10 #include "components/guest_view/renderer/guest_view_container.h" | 10 #include "components/guest_view/renderer/guest_view_container.h" |
11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
13 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
14 #include "third_party/WebKit/public/web/WebRemoteFrame.h" | 14 #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
15 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 15 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
16 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
17 | 17 |
18 namespace guest_view { | 18 namespace guest_view { |
19 | 19 |
20 GuestViewRequest::GuestViewRequest(GuestViewContainer* container, | 20 GuestViewRequest::GuestViewRequest(GuestViewContainer* container) |
21 v8::Local<v8::Function> callback, | 21 : container_(container) {} |
22 v8::Isolate* isolate) | 22 |
23 : container_(container), | 23 GuestViewRequest::~GuestViewRequest() {} |
| 24 |
| 25 GuestViewJavaScriptRequest::GuestViewJavaScriptRequest( |
| 26 GuestViewContainer* container, |
| 27 v8::Local<v8::Function> callback, |
| 28 v8::Isolate* isolate) |
| 29 : GuestViewRequest(container), |
24 callback_(isolate, callback), | 30 callback_(isolate, callback), |
25 isolate_(isolate) { | 31 isolate_(isolate) {} |
26 } | |
27 | 32 |
28 GuestViewRequest::~GuestViewRequest() { | 33 GuestViewJavaScriptRequest::~GuestViewJavaScriptRequest() {} |
29 } | |
30 | 34 |
31 void GuestViewRequest::ExecuteCallbackIfAvailable( | 35 void GuestViewJavaScriptRequest::ExecuteCallbackIfAvailable( |
32 int argc, | 36 int argc, |
33 scoped_ptr<v8::Local<v8::Value>[]> argv) { | 37 scoped_ptr<v8::Local<v8::Value>[]> argv) { |
34 if (callback_.IsEmpty()) | 38 if (callback_.IsEmpty()) |
35 return; | 39 return; |
36 | 40 |
37 v8::HandleScope handle_scope(isolate()); | 41 v8::HandleScope handle_scope(isolate()); |
38 v8::Local<v8::Function> callback = | 42 v8::Local<v8::Function> callback = |
39 v8::Local<v8::Function>::New(isolate_, callback_); | 43 v8::Local<v8::Function>::New(isolate_, callback_); |
40 v8::Local<v8::Context> context = callback->CreationContext(); | 44 v8::Local<v8::Context> context = callback->CreationContext(); |
41 if (context.IsEmpty()) | 45 if (context.IsEmpty()) |
42 return; | 46 return; |
43 | 47 |
44 v8::Context::Scope context_scope(context); | 48 v8::Context::Scope context_scope(context); |
45 blink::WebScopedMicrotaskSuppression suppression; | 49 blink::WebScopedMicrotaskSuppression suppression; |
46 | 50 |
47 callback->Call(context->Global(), argc, argv.get()); | 51 callback->Call(context->Global(), argc, argv.get()); |
48 } | 52 } |
49 | 53 |
| 54 void GuestViewJavaScriptRequest::HandleDefaultResponse() { |
| 55 ExecuteCallbackIfAvailable(0 /* argc */, nullptr); |
| 56 } |
| 57 |
50 GuestViewAttachRequest::GuestViewAttachRequest( | 58 GuestViewAttachRequest::GuestViewAttachRequest( |
51 GuestViewContainer* container, | 59 GuestViewContainer* container, |
52 int guest_instance_id, | 60 int guest_instance_id, |
53 scoped_ptr<base::DictionaryValue> params, | 61 scoped_ptr<base::DictionaryValue> params, |
54 v8::Local<v8::Function> callback, | 62 v8::Local<v8::Function> callback, |
55 v8::Isolate* isolate) | 63 v8::Isolate* isolate) |
56 : GuestViewRequest(container, callback, isolate), | 64 : GuestViewJavaScriptRequest(container, callback, isolate), |
57 guest_instance_id_(guest_instance_id), | 65 guest_instance_id_(guest_instance_id), |
58 params_(std::move(params)) {} | 66 params_(std::move(params)) {} |
59 | 67 |
60 GuestViewAttachRequest::~GuestViewAttachRequest() { | 68 GuestViewAttachRequest::~GuestViewAttachRequest() { |
61 } | 69 } |
62 | 70 |
63 void GuestViewAttachRequest::PerformRequest() { | 71 void GuestViewAttachRequest::PerformRequest() { |
64 if (!container()->render_frame()) | 72 if (!container()->render_frame()) |
65 return; | 73 return; |
66 | 74 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 110 |
103 const int argc = 1; | 111 const int argc = 1; |
104 scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]); | 112 scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]); |
105 argv[0] = window; | 113 argv[0] = window; |
106 | 114 |
107 // Call the AttachGuest API's callback with the guest proxy as the first | 115 // Call the AttachGuest API's callback with the guest proxy as the first |
108 // parameter. | 116 // parameter. |
109 ExecuteCallbackIfAvailable(argc, std::move(argv)); | 117 ExecuteCallbackIfAvailable(argc, std::move(argv)); |
110 } | 118 } |
111 | 119 |
112 GuestViewDetachRequest::GuestViewDetachRequest( | 120 GuestViewDetachRequest::GuestViewDetachRequest(GuestViewContainer* container, |
113 GuestViewContainer* container, | 121 v8::Local<v8::Function> callback, |
114 v8::Local<v8::Function> callback, | 122 v8::Isolate* isolate) |
115 v8::Isolate* isolate) | 123 : GuestViewJavaScriptRequest(container, callback, isolate) {} |
116 : GuestViewRequest(container, callback, isolate) { | |
117 } | |
118 | 124 |
119 GuestViewDetachRequest::~GuestViewDetachRequest() { | 125 GuestViewDetachRequest::~GuestViewDetachRequest() { |
120 } | 126 } |
121 | 127 |
122 void GuestViewDetachRequest::PerformRequest() { | 128 void GuestViewDetachRequest::PerformRequest() { |
123 if (!container()->render_frame()) | 129 if (!container()->render_frame()) |
124 return; | 130 return; |
125 | 131 |
126 container()->render_frame()->DetachGuest(container()->element_instance_id()); | 132 container()->render_frame()->DetachGuest(container()->element_instance_id()); |
127 } | 133 } |
128 | 134 |
129 void GuestViewDetachRequest::HandleResponse(const IPC::Message& message) { | 135 void GuestViewDetachRequest::HandleResponse(const IPC::Message& message) { |
130 ExecuteCallbackIfAvailable(0 /* argc */, nullptr); | 136 ExecuteCallbackIfAvailable(0 /* argc */, nullptr); |
131 } | 137 } |
132 | 138 |
133 } // namespace guest_view | 139 } // namespace guest_view |
OLD | NEW |