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 "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/render_process_host.h" | |
11 #include "content/public/browser/site_instance.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 | |
14 using content::WebContents; | |
15 | |
16 namespace chrome { | |
17 | |
18 namespace { | |
19 | |
20 typedef std::map<int, WebViewGuest*> WebViewGuestMap; | |
21 typedef std::map<void*, WebViewGuestMap> WebViewProfileMap; | |
22 static base::LazyInstance<WebViewProfileMap> g_webview_profile_map = | |
sky
2013/05/22 00:44:18
This isn't global, it's static to this file so no
Fady Samuel
2013/05/23 04:37:38
Done.
| |
23 LAZY_INSTANCE_INITIALIZER; | |
24 | |
25 void RemoveWebViewEventListenersOnIOThread( | |
26 void* profile, | |
27 const std::string& extension_id, | |
28 int embedder_process_id, | |
29 int web_view_instance_id) { | |
30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
31 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | |
32 profile, extension_id, embedder_process_id, web_view_instance_id); | |
33 } | |
34 | |
35 } // namespace | |
36 | |
37 WebViewGuest::WebViewGuest(WebContents* guest_web_contents, | |
38 WebContents* embedder_web_contents, | |
39 const std::string& extension_id) | |
40 : WebContentsObserver(guest_web_contents), | |
41 embedder_web_contents_(embedder_web_contents), | |
42 extension_id_(extension_id) { | |
43 profile_ = guest_web_contents->GetBrowserContext(); | |
sky
2013/05/22 00:44:18
Member initialize profile_ everything you can.
Fady Samuel
2013/05/23 04:37:38
Done.
| |
44 instance_id_ = guest_web_contents->GetEmbeddedInstanceID(); | |
45 // We cache the embedder's process ID and routing ID here as the embedder | |
46 // may be destroyed prior to the destruction of the guest. | |
47 embedder_render_process_id_ = | |
48 embedder_web_contents->GetRenderProcessHost()->GetID(); | |
49 g_webview_profile_map.Get()[profile_].insert( | |
50 std::make_pair(instance_id_, this)); | |
51 } | |
52 | |
53 WebViewGuest::~WebViewGuest() { | |
54 g_webview_profile_map.Get()[profile_].erase(instance_id_); | |
55 if (!g_webview_profile_map.Get()[profile_].size()) | |
sky
2013/05/22 00:44:18
.empty()
Fady Samuel
2013/05/23 04:37:38
Done.
| |
56 g_webview_profile_map.Get().erase(profile_); | |
57 } | |
58 | |
59 // static | |
60 WebViewGuest* WebViewGuest::From(void* profile, int instance_id) { | |
61 WebViewProfileMap* profile_map = g_webview_profile_map.Pointer(); | |
62 WebViewProfileMap::iterator it = profile_map->find(profile); | |
63 if (it == profile_map->end()) | |
64 return NULL; | |
65 const WebViewGuestMap& guest_map = it->second; | |
66 WebViewGuestMap::const_iterator guest_it = guest_map.find(instance_id); | |
67 return guest_it == guest_map.end() ? NULL : guest_it->second; | |
68 } | |
69 | |
70 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | |
71 content::BrowserThread::PostTask( | |
72 content::BrowserThread::IO, | |
73 FROM_HERE, | |
74 base::Bind( | |
75 &RemoveWebViewEventListenersOnIOThread, | |
76 profile_, extension_id_, | |
77 embedder_render_process_id_, | |
78 instance_id_)); | |
79 delete this; | |
sky
2013/05/22 00:44:18
Who owns this object? If this object owns its own
Fady Samuel
2013/05/23 04:37:38
Made destructor private.
| |
80 } | |
81 | |
82 } // namespace chrome | |
OLD | NEW |