Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/webview/webview_guest.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/render_process_host.h" | |
| 12 #include "content/public/browser/site_instance.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 | |
| 15 using content::WebContents; | |
| 16 | |
| 17 namespace chrome { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 typedef std::map<int, WebViewGuest*> WebViewGuestMap; | |
| 22 typedef std::map<Profile*, WebViewGuestMap> WebViewProfileMap; | |
| 23 static base::LazyInstance<WebViewProfileMap> webview_profile_map = | |
| 24 LAZY_INSTANCE_INITIALIZER; | |
| 25 | |
| 26 void RemoveWebViewEventListenersOnIOThread( | |
| 27 Profile* profile, | |
|
sky
2013/05/23 15:41:11
What if the profile is deleted between the time yo
Fady Samuel
2013/05/24 03:13:47
profile is used as a key to webview_profile_map bu
sky
2013/05/24 15:58:03
How about making this take a void* then.
| |
| 28 const std::string& extension_id, | |
| 29 int embedder_process_id, | |
| 30 int web_view_instance_id) { | |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 32 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | |
| 33 profile, extension_id, embedder_process_id, web_view_instance_id); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 WebViewGuest::WebViewGuest(WebContents* guest_web_contents, | |
| 39 WebContents* embedder_web_contents, | |
| 40 const std::string& extension_id) | |
| 41 : WebContentsObserver(guest_web_contents), | |
| 42 embedder_web_contents_(embedder_web_contents), | |
| 43 extension_id_(extension_id), | |
| 44 embedder_render_process_id_( | |
| 45 embedder_web_contents->GetRenderProcessHost()->GetID()), | |
| 46 profile_(static_cast<Profile*>(guest_web_contents->GetBrowserContext())), | |
| 47 instance_id_(guest_web_contents->GetEmbeddedInstanceID()) { | |
| 48 webview_profile_map.Get()[profile_].insert( | |
| 49 std::make_pair(instance_id_, this)); | |
| 50 } | |
| 51 | |
| 52 WebViewGuest::~WebViewGuest() { | |
|
sky
2013/05/23 15:41:11
Make order match header.
Fady Samuel
2013/05/24 03:13:47
Done.
| |
| 53 webview_profile_map.Get()[profile_].erase(instance_id_); | |
| 54 if (webview_profile_map.Get()[profile_].empty()) | |
| 55 webview_profile_map.Get().erase(profile_); | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 WebViewGuest* WebViewGuest::From(Profile* profile, int instance_id) { | |
| 60 WebViewProfileMap* profile_map = webview_profile_map.Pointer(); | |
| 61 WebViewProfileMap::iterator it = profile_map->find(profile); | |
| 62 if (it == profile_map->end()) | |
| 63 return NULL; | |
| 64 const WebViewGuestMap& guest_map = it->second; | |
| 65 WebViewGuestMap::const_iterator guest_it = guest_map.find(instance_id); | |
| 66 return guest_it == guest_map.end() ? NULL : guest_it->second; | |
| 67 } | |
| 68 | |
| 69 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | |
| 70 content::BrowserThread::PostTask( | |
| 71 content::BrowserThread::IO, | |
| 72 FROM_HERE, | |
| 73 base::Bind( | |
| 74 &RemoveWebViewEventListenersOnIOThread, | |
| 75 profile_, extension_id_, | |
| 76 embedder_render_process_id_, | |
| 77 instance_id_)); | |
| 78 delete this; | |
| 79 } | |
| 80 | |
| 81 } // namespace chrome | |
| OLD | NEW |