Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1242)

Side by Side Diff: chrome/browser/webview/webview_guest.cc

Issue 12189018: <webview>: Implement WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fix to tear down Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 =
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();
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())
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;
80 }
81
82 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698