Chromium Code Reviews| 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 "extensions/browser/guest_view/app_view/app_view_guest.h" | 5 #include "extensions/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 "components/guest_view/browser/guest_view_manager.h" | 8 #include "components/guest_view/browser/guest_view_manager.h" |
| 9 #include "content/public/browser/render_process_host.h" | |
| 9 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/common/renderer_preferences.h" | 11 #include "content/public/common/renderer_preferences.h" |
| 12 #include "content/public/common/result_codes.h" | |
| 11 #include "extensions/browser/api/app_runtime/app_runtime_api.h" | 13 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
| 12 #include "extensions/browser/api/extensions_api_client.h" | 14 #include "extensions/browser/api/extensions_api_client.h" |
| 13 #include "extensions/browser/app_window/app_delegate.h" | 15 #include "extensions/browser/app_window/app_delegate.h" |
| 14 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 15 #include "extensions/browser/extension_host.h" | 17 #include "extensions/browser/extension_host.h" |
| 16 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/browser/guest_view/app_view/app_view_constants.h" | 19 #include "extensions/browser/guest_view/app_view/app_view_constants.h" |
| 18 #include "extensions/browser/lazy_background_task_queue.h" | 20 #include "extensions/browser/lazy_background_task_queue.h" |
| 19 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
| 20 #include "extensions/browser/view_type_utils.h" | 22 #include "extensions/browser/view_type_utils.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } // namespace | 58 } // namespace |
| 57 | 59 |
| 58 // static. | 60 // static. |
| 59 const char AppViewGuest::Type[] = "appview"; | 61 const char AppViewGuest::Type[] = "appview"; |
| 60 | 62 |
| 61 // static. | 63 // static. |
| 62 bool AppViewGuest::CompletePendingRequest( | 64 bool AppViewGuest::CompletePendingRequest( |
| 63 content::BrowserContext* browser_context, | 65 content::BrowserContext* browser_context, |
| 64 const GURL& url, | 66 const GURL& url, |
| 65 int guest_instance_id, | 67 int guest_instance_id, |
| 66 const std::string& guest_extension_id) { | 68 const std::string& guest_extension_id, |
| 69 int guest_render_process_host_id) { | |
|
lfg
2015/06/12 21:43:47
Add a DCHECK that the render process host passed h
EhsanK
2015/06/25 16:19:50
I am not sure if I understand this comment correct
lfg
2015/06/26 21:46:05
Ah, I see. Please, add a comment explaining why we
EhsanK
2015/06/30 16:53:10
Done.
| |
| 67 PendingResponseMap* response_map = pending_response_map.Pointer(); | 70 PendingResponseMap* response_map = pending_response_map.Pointer(); |
| 68 PendingResponseMap::iterator it = response_map->find(guest_instance_id); | 71 PendingResponseMap::iterator it = response_map->find(guest_instance_id); |
| 69 if (it == response_map->end()) { | 72 if (it == response_map->end()) { |
| 70 // TODO(fsamuel): An app is sending invalid responses. We should probably | 73 // TODO(fsamuel): An app is sending invalid responses. We should probably |
| 71 // kill it. | 74 // kill it. |
|
lfg
2015/06/12 21:43:47
Remove the TODO.
EhsanK
2015/06/25 16:19:50
Done.
| |
| 75 content::RenderProcessHost::FromID(guest_render_process_host_id) | |
| 76 ->Shutdown(-1, false); | |
|
lfg
2015/06/12 21:43:47
We should add UMA metrics to track the kills here.
EhsanK
2015/06/25 16:19:50
Done.
| |
| 72 return false; | 77 return false; |
| 73 } | 78 } |
| 74 | 79 |
| 75 linked_ptr<ResponseInfo> response_info = it->second; | 80 linked_ptr<ResponseInfo> response_info = it->second; |
| 76 if (!response_info->app_view_guest || | 81 if (!response_info->app_view_guest || |
| 77 (response_info->guest_extension->id() != guest_extension_id)) { | 82 (response_info->guest_extension->id() != guest_extension_id)) { |
| 78 // TODO(fsamuel): An app is trying to respond to an <appview> that didn't | 83 // TODO(fsamuel): An app is trying to respond to an <appview> that didn't |
| 79 // initiate communication with it. We should kill the app here. | 84 // initiate communication with it. We should kill the app here. |
| 85 content::RenderProcessHost::FromID(guest_render_process_host_id) | |
| 86 ->Shutdown(-1, false); | |
|
lfg
2015/06/12 21:43:47
Same as above.
EhsanK
2015/06/25 16:19:50
Done.
| |
| 80 return false; | 87 return false; |
| 81 } | 88 } |
| 82 | 89 |
| 83 response_info->app_view_guest->CompleteCreateWebContents( | 90 response_info->app_view_guest->CompleteCreateWebContents( |
| 84 url, response_info->guest_extension.get(), response_info->callback); | 91 url, response_info->guest_extension.get(), response_info->callback); |
| 85 | 92 |
| 86 response_map->erase(guest_instance_id); | 93 response_map->erase(guest_instance_id); |
| 87 return true; | 94 return true; |
| 88 } | 95 } |
| 89 | 96 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 108 return nullptr; | 115 return nullptr; |
| 109 } | 116 } |
| 110 | 117 |
| 111 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { | 118 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { |
| 112 return web_contents(); | 119 return web_contents(); |
| 113 } | 120 } |
| 114 | 121 |
| 115 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { | 122 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { |
| 116 bool handled = true; | 123 bool handled = true; |
| 117 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) | 124 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) |
| 118 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 125 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 119 IPC_MESSAGE_UNHANDLED(handled = false) | 126 IPC_MESSAGE_UNHANDLED(handled = false) |
| 120 IPC_END_MESSAGE_MAP() | 127 IPC_END_MESSAGE_MAP() |
| 121 return handled; | 128 return handled; |
| 122 } | 129 } |
| 123 | 130 |
| 124 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) { | 131 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) { |
| 125 if (app_view_guest_delegate_) { | 132 if (app_view_guest_delegate_) { |
| 126 return app_view_guest_delegate_->HandleContextMenu(web_contents(), params); | 133 return app_view_guest_delegate_->HandleContextMenu(web_contents(), params); |
| 127 } | 134 } |
| 128 return false; | 135 return false; |
| 129 } | 136 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 const Extension* guest_extension = enabled_extensions.GetByID(app_id); | 198 const Extension* guest_extension = enabled_extensions.GetByID(app_id); |
| 192 const Extension* embedder_extension = | 199 const Extension* embedder_extension = |
| 193 enabled_extensions.GetByID(GetOwnerSiteURL().host()); | 200 enabled_extensions.GetByID(GetOwnerSiteURL().host()); |
| 194 | 201 |
| 195 if (!guest_extension || !guest_extension->is_platform_app() || | 202 if (!guest_extension || !guest_extension->is_platform_app() || |
| 196 !embedder_extension | !embedder_extension->is_platform_app()) { | 203 !embedder_extension | !embedder_extension->is_platform_app()) { |
| 197 callback.Run(nullptr); | 204 callback.Run(nullptr); |
| 198 return; | 205 return; |
| 199 } | 206 } |
| 200 | 207 |
| 201 pending_response_map.Get().insert( | 208 pending_response_map.Get().insert(std::make_pair( |
| 202 std::make_pair(guest_instance_id(), | 209 guest_instance_id(), |
| 203 make_linked_ptr(new ResponseInfo( | 210 make_linked_ptr(new ResponseInfo( |
| 204 guest_extension, | 211 guest_extension, weak_ptr_factory_.GetWeakPtr(), callback)))); |
| 205 weak_ptr_factory_.GetWeakPtr(), | |
| 206 callback)))); | |
| 207 | 212 |
| 208 LazyBackgroundTaskQueue* queue = | 213 LazyBackgroundTaskQueue* queue = |
| 209 LazyBackgroundTaskQueue::Get(browser_context()); | 214 LazyBackgroundTaskQueue::Get(browser_context()); |
| 210 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { | 215 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { |
| 211 queue->AddPendingTask(browser_context(), | 216 queue->AddPendingTask(browser_context(), |
| 212 guest_extension->id(), | 217 guest_extension->id(), |
| 213 base::Bind( | 218 base::Bind( |
| 214 &AppViewGuest::LaunchAppAndFireEvent, | 219 &AppViewGuest::LaunchAppAndFireEvent, |
| 215 weak_ptr_factory_.GetWeakPtr(), | 220 weak_ptr_factory_.GetWeakPtr(), |
| 216 base::Passed(make_scoped_ptr(data->DeepCopy())), | 221 base::Passed(make_scoped_ptr(data->DeepCopy())), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 embed_request->SetString(appview::kEmbedderID, owner_host()); | 291 embed_request->SetString(appview::kEmbedderID, owner_host()); |
| 287 embed_request->Set(appview::kData, data.release()); | 292 embed_request->Set(appview::kData, data.release()); |
| 288 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 293 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
| 289 browser_context(), embed_request.Pass(), extension_host->extension()); | 294 browser_context(), embed_request.Pass(), extension_host->extension()); |
| 290 } | 295 } |
| 291 | 296 |
| 292 void AppViewGuest::SetAppDelegateForTest(AppDelegate* delegate) { | 297 void AppViewGuest::SetAppDelegateForTest(AppDelegate* delegate) { |
| 293 app_delegate_.reset(delegate); | 298 app_delegate_.reset(delegate); |
| 294 } | 299 } |
| 295 | 300 |
| 301 // static | |
| 302 void AppViewGuest::AddFakeRequestInfoForTesting( | |
| 303 const Extension* guest_extension, | |
| 304 AppViewGuest* app_view_guest, | |
| 305 GuestViewBase::WebContentsCreatedCallback& callback, | |
| 306 int guest_instance_id) { | |
| 307 pending_response_map.Get().insert(std::make_pair( | |
| 308 guest_instance_id, | |
| 309 make_linked_ptr(new ResponseInfo( | |
| 310 guest_extension, app_view_guest->weak_ptr_factory_.GetWeakPtr(), | |
| 311 callback)))); | |
| 312 } | |
| 313 | |
| 296 } // namespace extensions | 314 } // namespace extensions |
| OLD | NEW |