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

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: 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 side-by-side diff with in-line comments
Download patch
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..977af017251ee4fb5b8464ac6862ec735c8f1e37
--- /dev/null
+++ b/chrome/browser/webview/webview_guest.cc
@@ -0,0 +1,82 @@
+// 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> g_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) {
+ profile_ = guest_web_contents->GetBrowserContext();
+ instance_id_ = guest_web_contents->GetEmbeddedInstanceID();
+ // We cache the embedder's process ID and routing ID here as the embedder
+ // may be destroyed prior to the destruction of the guest.
+ embedder_render_process_id_ =
+ embedder_web_contents->GetRenderProcessHost()->GetID();
+ g_webview_profile_map.Get()[profile_].insert(
+ std::make_pair(instance_id_, this));
+}
+
+WebViewGuest::~WebViewGuest() {
+ g_webview_profile_map.Get()[profile_].erase(instance_id_);
+ if (!g_webview_profile_map.Get()[profile_].size())
+ g_webview_profile_map.Get().erase(profile_);
+}
+
+// static
+WebViewGuest* WebViewGuest::From(void* profile, int instance_id) {
+ WebViewProfileMap* profile_map = g_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;
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698