| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 ResponseInfo(const Extension* guest_extension, | 46 ResponseInfo(const Extension* guest_extension, |
| 47 const base::WeakPtr<AppViewGuest>& app_view_guest, | 47 const base::WeakPtr<AppViewGuest>& app_view_guest, |
| 48 const GuestViewBase::WebContentsCreatedCallback& callback) | 48 const GuestViewBase::WebContentsCreatedCallback& callback) |
| 49 : guest_extension(guest_extension), | 49 : guest_extension(guest_extension), |
| 50 app_view_guest(app_view_guest), | 50 app_view_guest(app_view_guest), |
| 51 callback(callback) {} | 51 callback(callback) {} |
| 52 | 52 |
| 53 ~ResponseInfo() {} | 53 ~ResponseInfo() {} |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 typedef std::map<int, linked_ptr<ResponseInfo> > PendingResponseMap; | 56 using PendingResponseMap = std::map<int, std::unique_ptr<ResponseInfo>>; |
| 57 static base::LazyInstance<PendingResponseMap> pending_response_map = | 57 static base::LazyInstance<PendingResponseMap> pending_response_map = |
| 58 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 // static. | 62 // static. |
| 63 const char AppViewGuest::Type[] = "appview"; | 63 const char AppViewGuest::Type[] = "appview"; |
| 64 | 64 |
| 65 // static. | 65 // static. |
| 66 bool AppViewGuest::CompletePendingRequest( | 66 bool AppViewGuest::CompletePendingRequest( |
| 67 content::BrowserContext* browser_context, | 67 content::BrowserContext* browser_context, |
| 68 const GURL& url, | 68 const GURL& url, |
| 69 int guest_instance_id, | 69 int guest_instance_id, |
| 70 const std::string& guest_extension_id, | 70 const std::string& guest_extension_id, |
| 71 content::RenderProcessHost* guest_render_process_host) { | 71 content::RenderProcessHost* guest_render_process_host) { |
| 72 PendingResponseMap* response_map = pending_response_map.Pointer(); | 72 PendingResponseMap* response_map = pending_response_map.Pointer(); |
| 73 PendingResponseMap::iterator it = response_map->find(guest_instance_id); | 73 PendingResponseMap::iterator it = response_map->find(guest_instance_id); |
| 74 // Kill the requesting process if it is not the real guest. | 74 // Kill the requesting process if it is not the real guest. |
| 75 if (it == response_map->end()) { | 75 if (it == response_map->end()) { |
| 76 // The requester used an invalid |guest_instance_id|. | 76 // The requester used an invalid |guest_instance_id|. |
| 77 bad_message::ReceivedBadMessage(guest_render_process_host, | 77 bad_message::ReceivedBadMessage(guest_render_process_host, |
| 78 bad_message::AVG_BAD_INST_ID); | 78 bad_message::AVG_BAD_INST_ID); |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 linked_ptr<ResponseInfo> response_info = it->second; | 82 ResponseInfo* response_info = it->second.get(); |
| 83 if (!response_info->app_view_guest || | 83 if (!response_info->app_view_guest || |
| 84 (response_info->guest_extension->id() != guest_extension_id)) { | 84 (response_info->guest_extension->id() != guest_extension_id)) { |
| 85 // The app is trying to communicate with an <appview> not assigned to it, or | 85 // The app is trying to communicate with an <appview> not assigned to it, or |
| 86 // the <appview> is already dead "nullptr". | 86 // the <appview> is already dead "nullptr". |
| 87 bad_message::BadMessageReason reason = !response_info->app_view_guest | 87 bad_message::BadMessageReason reason = !response_info->app_view_guest |
| 88 ? bad_message::AVG_NULL_AVG | 88 ? bad_message::AVG_NULL_AVG |
| 89 : bad_message::AVG_BAD_EXT_ID; | 89 : bad_message::AVG_BAD_EXT_ID; |
| 90 bad_message::ReceivedBadMessage(guest_render_process_host, reason); | 90 bad_message::ReceivedBadMessage(guest_render_process_host, reason); |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 const Extension* guest_extension = enabled_extensions.GetByID(app_id); | 184 const Extension* guest_extension = enabled_extensions.GetByID(app_id); |
| 185 const Extension* embedder_extension = | 185 const Extension* embedder_extension = |
| 186 enabled_extensions.GetByID(GetOwnerSiteURL().host()); | 186 enabled_extensions.GetByID(GetOwnerSiteURL().host()); |
| 187 | 187 |
| 188 if (!guest_extension || !guest_extension->is_platform_app() || | 188 if (!guest_extension || !guest_extension->is_platform_app() || |
| 189 !embedder_extension | !embedder_extension->is_platform_app()) { | 189 !embedder_extension | !embedder_extension->is_platform_app()) { |
| 190 callback.Run(nullptr); | 190 callback.Run(nullptr); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 pending_response_map.Get().insert( | 194 pending_response_map.Get().insert(std::make_pair( |
| 195 std::make_pair(guest_instance_id(), | 195 guest_instance_id(), |
| 196 make_linked_ptr(new ResponseInfo( | 196 base::MakeUnique<ResponseInfo>( |
| 197 guest_extension, | 197 guest_extension, weak_ptr_factory_.GetWeakPtr(), callback))); |
| 198 weak_ptr_factory_.GetWeakPtr(), | |
| 199 callback)))); | |
| 200 | 198 |
| 201 LazyBackgroundTaskQueue* queue = | 199 LazyBackgroundTaskQueue* queue = |
| 202 LazyBackgroundTaskQueue::Get(browser_context()); | 200 LazyBackgroundTaskQueue::Get(browser_context()); |
| 203 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { | 201 if (queue->ShouldEnqueueTask(browser_context(), guest_extension)) { |
| 204 queue->AddPendingTask( | 202 queue->AddPendingTask( |
| 205 browser_context(), guest_extension->id(), | 203 browser_context(), guest_extension->id(), |
| 206 base::Bind(&AppViewGuest::LaunchAppAndFireEvent, | 204 base::Bind(&AppViewGuest::LaunchAppAndFireEvent, |
| 207 weak_ptr_factory_.GetWeakPtr(), | 205 weak_ptr_factory_.GetWeakPtr(), |
| 208 base::Passed(base::WrapUnique(data->DeepCopy())), callback)); | 206 base::Passed(base::WrapUnique(data->DeepCopy())), callback)); |
| 209 return; | 207 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 279 |
| 282 std::vector<int> AppViewGuest::GetAllRegisteredInstanceIdsForTesting() { | 280 std::vector<int> AppViewGuest::GetAllRegisteredInstanceIdsForTesting() { |
| 283 std::vector<int> instances; | 281 std::vector<int> instances; |
| 284 for (const auto& key_value : pending_response_map.Get()) { | 282 for (const auto& key_value : pending_response_map.Get()) { |
| 285 instances.push_back(key_value.first); | 283 instances.push_back(key_value.first); |
| 286 } | 284 } |
| 287 return instances; | 285 return instances; |
| 288 } | 286 } |
| 289 | 287 |
| 290 } // namespace extensions | 288 } // namespace extensions |
| OLD | NEW |