Index: extensions/browser/guest_view/app_view/app_view_guest.cc |
diff --git a/extensions/browser/guest_view/app_view/app_view_guest.cc b/extensions/browser/guest_view/app_view/app_view_guest.cc |
index 108b9b3e2c0092de4954d070dff88d7ec48d277f..c7157edaa5a6ab424db1c66015d0a35171abb745 100644 |
--- a/extensions/browser/guest_view/app_view/app_view_guest.cc |
+++ b/extensions/browser/guest_view/app_view/app_view_guest.cc |
@@ -6,7 +6,8 @@ |
#include "base/command_line.h" |
#include "components/guest_view/browser/guest_view_manager.h" |
-#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/user_metrics.h" |
#include "content/public/common/renderer_preferences.h" |
#include "extensions/browser/api/app_runtime/app_runtime_api.h" |
#include "extensions/browser/api/extensions_api_client.h" |
@@ -53,6 +54,13 @@ typedef std::map<int, linked_ptr<ResponseInfo> > PendingResponseMap; |
static base::LazyInstance<PendingResponseMap> pending_response_map = |
LAZY_INSTANCE_INITIALIZER; |
+void KillRenderProcessHostAndRecordUMAMetric(int render_process_host_id) { |
+ content::RecordAction( |
+ base::UserMetricsAction("BadExtensionTerminate_AppViewTag")); |
+ content::RenderProcessHost::FromID(render_process_host_id) |
+ ->Shutdown(-1, false); |
+} |
+ |
} // namespace |
// static. |
@@ -63,20 +71,21 @@ bool AppViewGuest::CompletePendingRequest( |
content::BrowserContext* browser_context, |
const GURL& url, |
int guest_instance_id, |
- const std::string& guest_extension_id) { |
+ const std::string& guest_extension_id, |
+ int guest_render_process_host_id) { |
PendingResponseMap* response_map = pending_response_map.Pointer(); |
PendingResponseMap::iterator it = response_map->find(guest_instance_id); |
if (it == response_map->end()) { |
- // TODO(fsamuel): An app is sending invalid responses. We should probably |
- // kill it. |
+ // The app is asking for a non-existent <appview>. |
+ KillRenderProcessHostAndRecordUMAMetric(guest_render_process_host_id); |
return false; |
} |
linked_ptr<ResponseInfo> response_info = it->second; |
if (!response_info->app_view_guest || |
(response_info->guest_extension->id() != guest_extension_id)) { |
- // TODO(fsamuel): An app is trying to respond to an <appview> that didn't |
- // initiate communication with it. We should kill the app here. |
+ // The app is trying to communicate with an <appview> not assigned to it. |
+ KillRenderProcessHostAndRecordUMAMetric(guest_render_process_host_id); |
return false; |
} |
@@ -270,4 +279,37 @@ void AppViewGuest::SetAppDelegateForTest(AppDelegate* delegate) { |
app_delegate_.reset(delegate); |
} |
+// static |
+base::WeakPtr<AppViewGuest> |
+AppViewGuest::GetAppViewGuestFromExtensionIdForTesting( |
+ const std::string& extension_id) { |
+ for (auto it = pending_response_map.Get().begin(); |
+ it != pending_response_map.Get().end(); ++it) { |
+ if (it->second->guest_extension->id() == extension_id) { |
+ return it->second->app_view_guest->weak_ptr_factory_.GetWeakPtr(); |
+ } |
+ } |
+ return base::WeakPtr<AppViewGuest>(); |
+} |
+ |
+void AppViewGuest::SetAppViewGuestForExtensionIdForTesting( |
+ const std::string& extension_id, |
+ base::WeakPtr<AppViewGuest> weak_ptr) { |
+ for (auto it = pending_response_map.Get().begin(); |
+ it != pending_response_map.Get().end(); ++it) { |
+ if (it->second->guest_extension->id() == extension_id) { |
+ it->second->app_view_guest = weak_ptr; |
+ } |
+ } |
+} |
+ |
+std::vector<int> AppViewGuest::GetAllRegisteredInstanceIdsForTesting() { |
+ std::vector<int> instances; |
+ for (auto it = pending_response_map.Get().begin(); |
+ it != pending_response_map.Get().end(); ++it) { |
+ instances.push_back(it->first); |
+ } |
+ return instances; |
+} |
+ |
} // namespace extensions |