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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/webview/webview_guest.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webview/webview_guest.cc
diff --git a/chrome/browser/webview/webview_guest.cc b/chrome/browser/webview/webview_guest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d0213f5bfdeb04a57f7bd4f7d65e108aca49b941
--- /dev/null
+++ b/chrome/browser/webview/webview_guest.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/webview/webview_guest.h"
+
+#include "base/lazy_instance.h"
+#include "chrome/browser/extensions/api/web_request/web_request_api.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/web_contents.h"
+
+using content::WebContents;
+
+namespace chrome {
+
+namespace {
+
+typedef std::map<int, WebViewGuest*> WebViewGuestMap;
+typedef std::map<void*, WebViewGuestMap> WebViewProfileMap;
+static base::LazyInstance<WebViewProfileMap> webview_profile_map =
+ LAZY_INSTANCE_INITIALIZER;
+
+void RemoveWebViewEventListenersOnIOThread(
+ void* profile,
+ const std::string& extension_id,
+ int embedder_process_id,
+ int web_view_instance_id) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
+ profile, extension_id, embedder_process_id, web_view_instance_id);
+}
+
+} // namespace
+
+WebViewGuest::WebViewGuest(WebContents* guest_web_contents,
+ WebContents* embedder_web_contents,
+ const std::string& extension_id)
+ : WebContentsObserver(guest_web_contents),
+ embedder_web_contents_(embedder_web_contents),
+ extension_id_(extension_id),
+ embedder_render_process_id_(
+ embedder_web_contents->GetRenderProcessHost()->GetID()),
+ profile_(guest_web_contents->GetBrowserContext()),
+ instance_id_(guest_web_contents->GetEmbeddedInstanceID()) {
+ webview_profile_map.Get()[profile_].insert(
+ std::make_pair(instance_id_, this));
+}
+
+// static
+WebViewGuest* WebViewGuest::From(void* profile, int instance_id) {
+ WebViewProfileMap* profile_map = webview_profile_map.Pointer();
+ WebViewProfileMap::iterator it = profile_map->find(profile);
+ if (it == profile_map->end())
+ return NULL;
+ const WebViewGuestMap& guest_map = it->second;
+ WebViewGuestMap::const_iterator guest_it = guest_map.find(instance_id);
+ return guest_it == guest_map.end() ? NULL : guest_it->second;
+}
+
+WebViewGuest::~WebViewGuest() {
+ webview_profile_map.Get()[profile_].erase(instance_id_);
+ if (webview_profile_map.Get()[profile_].empty())
+ webview_profile_map.Get().erase(profile_);
+}
+
+void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &RemoveWebViewEventListenersOnIOThread,
+ profile_, extension_id_,
+ embedder_render_process_id_,
+ instance_id_));
+ delete this;
+}
+
+} // namespace chrome
« 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