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

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: Profile* => void* 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
« no previous file with comments | « chrome/browser/webview/webview_guest.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 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 embedder_render_process_id_(
44 embedder_web_contents->GetRenderProcessHost()->GetID()),
45 profile_(guest_web_contents->GetBrowserContext()),
46 instance_id_(guest_web_contents->GetEmbeddedInstanceID()) {
47 webview_profile_map.Get()[profile_].insert(
48 std::make_pair(instance_id_, this));
49 }
50
51 // static
52 WebViewGuest* WebViewGuest::From(void* profile, int instance_id) {
53 WebViewProfileMap* profile_map = webview_profile_map.Pointer();
54 WebViewProfileMap::iterator it = profile_map->find(profile);
55 if (it == profile_map->end())
56 return NULL;
57 const WebViewGuestMap& guest_map = it->second;
58 WebViewGuestMap::const_iterator guest_it = guest_map.find(instance_id);
59 return guest_it == guest_map.end() ? NULL : guest_it->second;
60 }
61
62 WebViewGuest::~WebViewGuest() {
63 webview_profile_map.Get()[profile_].erase(instance_id_);
64 if (webview_profile_map.Get()[profile_].empty())
65 webview_profile_map.Get().erase(profile_);
66 }
67
68 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) {
69 content::BrowserThread::PostTask(
70 content::BrowserThread::IO,
71 FROM_HERE,
72 base::Bind(
73 &RemoveWebViewEventListenersOnIOThread,
74 profile_, extension_id_,
75 embedder_render_process_id_,
76 instance_id_));
77 delete this;
78 }
79
80 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/webview/webview_guest.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698