OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/app_view/app_view_guest.h" | 5 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/guest_view/app_view/app_view_constants.h" | 10 #include "chrome/browser/guest_view/app_view/app_view_constants.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 using content::RenderFrameHost; | 29 using content::RenderFrameHost; |
30 using content::WebContents; | 30 using content::WebContents; |
31 using extensions::ExtensionHost; | 31 using extensions::ExtensionHost; |
32 | 32 |
33 namespace extensions { | 33 namespace extensions { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 struct ResponseInfo { | 37 struct ResponseInfo { |
38 scoped_refptr<const extensions::Extension> guest_extension; | 38 scoped_refptr<const Extension> guest_extension; |
39 base::WeakPtr<AppViewGuest> app_view_guest; | 39 base::WeakPtr<AppViewGuest> app_view_guest; |
40 GuestViewBase::WebContentsCreatedCallback callback; | 40 GuestViewBase::WebContentsCreatedCallback callback; |
41 | 41 |
42 ResponseInfo(const extensions::Extension* guest_extension, | 42 ResponseInfo(const Extension* guest_extension, |
43 const base::WeakPtr<AppViewGuest>& app_view_guest, | 43 const base::WeakPtr<AppViewGuest>& app_view_guest, |
44 const GuestViewBase::WebContentsCreatedCallback& callback) | 44 const GuestViewBase::WebContentsCreatedCallback& callback) |
45 : guest_extension(guest_extension), | 45 : guest_extension(guest_extension), |
46 app_view_guest(app_view_guest), | 46 app_view_guest(app_view_guest), |
47 callback(callback) {} | 47 callback(callback) {} |
48 | 48 |
49 ~ResponseInfo() {} | 49 ~ResponseInfo() {} |
50 }; | 50 }; |
51 | 51 |
52 typedef std::map<int, linked_ptr<ResponseInfo> > PendingResponseMap; | 52 typedef std::map<int, linked_ptr<ResponseInfo> > PendingResponseMap; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 | 101 |
102 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, | 102 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, |
103 int guest_instance_id) | 103 int guest_instance_id) |
104 : GuestView<AppViewGuest>(browser_context, guest_instance_id), | 104 : GuestView<AppViewGuest>(browser_context, guest_instance_id), |
105 weak_ptr_factory_(this) { | 105 weak_ptr_factory_(this) { |
106 } | 106 } |
107 | 107 |
108 AppViewGuest::~AppViewGuest() { | 108 AppViewGuest::~AppViewGuest() { |
109 } | 109 } |
110 | 110 |
111 extensions::WindowController* AppViewGuest::GetExtensionWindowController() | 111 WindowController* AppViewGuest::GetExtensionWindowController() |
112 const { | 112 const { |
Fady Samuel
2014/08/12 21:25:30
can this now go on the line above?
Xi Han
2014/08/12 21:53:48
Done.
| |
113 return NULL; | 113 return NULL; |
114 } | 114 } |
115 | 115 |
116 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { | 116 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { |
117 return guest_web_contents(); | 117 return guest_web_contents(); |
118 } | 118 } |
119 | 119 |
120 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { | 120 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { |
121 bool handled = true; | 121 bool handled = true; |
122 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) | 122 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) |
(...skipping 23 matching lines...) Expand all Loading... | |
146 int embedder_render_process_id, | 146 int embedder_render_process_id, |
147 const base::DictionaryValue& create_params, | 147 const base::DictionaryValue& create_params, |
148 const WebContentsCreatedCallback& callback) { | 148 const WebContentsCreatedCallback& callback) { |
149 std::string app_id; | 149 std::string app_id; |
150 if (!create_params.GetString(appview::kAppID, &app_id)) { | 150 if (!create_params.GetString(appview::kAppID, &app_id)) { |
151 callback.Run(NULL); | 151 callback.Run(NULL); |
152 return; | 152 return; |
153 } | 153 } |
154 | 154 |
155 ExtensionService* service = | 155 ExtensionService* service = |
156 extensions::ExtensionSystem::Get(browser_context())->extension_service(); | 156 ExtensionSystem::Get(browser_context())->extension_service(); |
Fady Samuel
2014/08/12 21:25:29
Can this go on the previous line?
Xi Han
2014/08/12 21:53:48
Done.
| |
157 const extensions::Extension* guest_extension = | 157 const Extension* guest_extension = |
158 service->GetExtensionById(app_id, false); | 158 service->GetExtensionById(app_id, false); |
Fady Samuel
2014/08/12 21:25:29
Can this go on the previous line?
Xi Han
2014/08/12 21:53:48
Done.
| |
159 const extensions::Extension* embedder_extension = | 159 const Extension* embedder_extension = |
160 service->GetExtensionById(embedder_extension_id, false); | 160 service->GetExtensionById(embedder_extension_id, false); |
Fady Samuel
2014/08/12 21:25:29
can this go on the previous line?
Xi Han
2014/08/12 21:53:48
This line exceeds the limits.
| |
161 | 161 |
162 if (!guest_extension || !guest_extension->is_platform_app() || | 162 if (!guest_extension || !guest_extension->is_platform_app() || |
163 !embedder_extension | !embedder_extension->is_platform_app()) { | 163 !embedder_extension | !embedder_extension->is_platform_app()) { |
164 callback.Run(NULL); | 164 callback.Run(NULL); |
165 return; | 165 return; |
166 } | 166 } |
167 | 167 |
168 pending_response_map.Get().insert( | 168 pending_response_map.Get().insert( |
169 std::make_pair(GetGuestInstanceID(), | 169 std::make_pair(GetGuestInstanceID(), |
170 make_linked_ptr(new ResponseInfo( | 170 make_linked_ptr(new ResponseInfo( |
171 guest_extension, | 171 guest_extension, |
172 weak_ptr_factory_.GetWeakPtr(), | 172 weak_ptr_factory_.GetWeakPtr(), |
173 callback)))); | 173 callback)))); |
174 | 174 |
175 extensions::LazyBackgroundTaskQueue* queue = | 175 LazyBackgroundTaskQueue* queue = |
176 extensions::ExtensionSystem::Get(browser_context())-> | 176 ExtensionSystem::Get(browser_context())-> |
Fady Samuel
2014/08/12 21:25:29
Move to previous line?
Xi Han
2014/08/12 21:53:48
Done.
| |
177 lazy_background_task_queue(); | 177 lazy_background_task_queue(); |
178 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { | 178 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { |
179 queue->AddPendingTask(browser_context(), | 179 queue->AddPendingTask(browser_context(), |
180 guest_extension->id(), | 180 guest_extension->id(), |
181 base::Bind(&AppViewGuest::LaunchAppAndFireEvent, | 181 base::Bind(&AppViewGuest::LaunchAppAndFireEvent, |
182 weak_ptr_factory_.GetWeakPtr(), | 182 weak_ptr_factory_.GetWeakPtr(), |
183 callback)); | 183 callback)); |
184 return; | 184 return; |
185 } | 185 } |
186 | 186 |
187 extensions::ProcessManager* process_manager = | 187 ProcessManager* process_manager = |
188 extensions::ExtensionSystem::Get(browser_context())->process_manager(); | 188 ExtensionSystem::Get(browser_context())->process_manager(); |
189 ExtensionHost* host = | 189 ExtensionHost* host = |
190 process_manager->GetBackgroundHostForExtension(guest_extension->id()); | 190 process_manager->GetBackgroundHostForExtension(guest_extension->id()); |
191 DCHECK(host); | 191 DCHECK(host); |
192 LaunchAppAndFireEvent(callback, host); | 192 LaunchAppAndFireEvent(callback, host); |
193 } | 193 } |
194 | 194 |
195 void AppViewGuest::DidAttachToEmbedder() { | 195 void AppViewGuest::DidAttachToEmbedder() { |
196 // This is called after the guest process has been attached to a host | 196 // This is called after the guest process has been attached to a host |
197 // element. This means that the host element knows how to route input | 197 // element. This means that the host element knows how to route input |
198 // events to the guest, and the guest knows how to get frames to the | 198 // events to the guest, and the guest knows how to get frames to the |
199 // embedder. | 199 // embedder. |
200 guest_web_contents()->GetController().LoadURL( | 200 guest_web_contents()->GetController().LoadURL( |
201 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 201 url_, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
202 } | 202 } |
203 | 203 |
204 void AppViewGuest::DidInitialize() { | 204 void AppViewGuest::DidInitialize() { |
205 extension_function_dispatcher_.reset( | 205 extension_function_dispatcher_.reset( |
206 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | 206 new ExtensionFunctionDispatcher(browser_context(), this)); |
207 } | 207 } |
208 | 208 |
209 void AppViewGuest::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 209 void AppViewGuest::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
210 extension_function_dispatcher_->Dispatch( | 210 extension_function_dispatcher_->Dispatch( |
211 params, guest_web_contents()->GetRenderViewHost()); | 211 params, guest_web_contents()->GetRenderViewHost()); |
212 } | 212 } |
213 | 213 |
214 void AppViewGuest::CompleteCreateWebContents( | 214 void AppViewGuest::CompleteCreateWebContents( |
215 const GURL& url, | 215 const GURL& url, |
216 const extensions::Extension* guest_extension, | 216 const Extension* guest_extension, |
217 const WebContentsCreatedCallback& callback) { | 217 const WebContentsCreatedCallback& callback) { |
218 if (!url.is_valid()) { | 218 if (!url.is_valid()) { |
219 callback.Run(NULL); | 219 callback.Run(NULL); |
220 return; | 220 return; |
221 } | 221 } |
222 url_ = url; | 222 url_ = url; |
223 guest_extension_id_ = guest_extension->id(); | 223 guest_extension_id_ = guest_extension->id(); |
224 | 224 |
225 WebContents::CreateParams params( | 225 WebContents::CreateParams params( |
226 browser_context(), | 226 browser_context(), |
227 content::SiteInstance::CreateForURL(browser_context(), | 227 content::SiteInstance::CreateForURL(browser_context(), |
228 guest_extension->url())); | 228 guest_extension->url())); |
229 params.guest_delegate = this; | 229 params.guest_delegate = this; |
230 callback.Run(WebContents::Create(params)); | 230 callback.Run(WebContents::Create(params)); |
231 } | 231 } |
232 | 232 |
233 void AppViewGuest::LaunchAppAndFireEvent( | 233 void AppViewGuest::LaunchAppAndFireEvent( |
234 const WebContentsCreatedCallback& callback, | 234 const WebContentsCreatedCallback& callback, |
235 ExtensionHost* extension_host) { | 235 ExtensionHost* extension_host) { |
236 extensions::ExtensionSystem* system = | 236 ExtensionSystem* system = |
237 extensions::ExtensionSystem::Get(browser_context()); | 237 ExtensionSystem::Get(browser_context()); |
Fady Samuel
2014/08/12 21:25:30
Move to previous line?
Xi Han
2014/08/12 21:53:48
Done.
| |
238 bool has_event_listener = system->event_router()->ExtensionHasEventListener( | 238 bool has_event_listener = system->event_router()->ExtensionHasEventListener( |
239 extension_host->extension()->id(), | 239 extension_host->extension()->id(), |
240 app_runtime::OnEmbedRequested::kEventName); | 240 app_runtime::OnEmbedRequested::kEventName); |
241 if (!has_event_listener) { | 241 if (!has_event_listener) { |
242 callback.Run(NULL); | 242 callback.Run(NULL); |
243 return; | 243 return; |
244 } | 244 } |
245 | 245 |
246 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); | 246 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); |
247 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); | 247 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); |
248 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); | 248 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); |
249 extensions::AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 249 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
250 browser_context(), embed_request.Pass(), extension_host->extension()); | 250 browser_context(), embed_request.Pass(), extension_host->extension()); |
251 } | 251 } |
252 | 252 |
253 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |