Index: content/browser/web_contents/web_contents_impl.cc |
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
index 6749aafe832138b29352a637eb1107f508b56817..8277786d58b4204e14812bc6e381faed5d15b932 100644 |
--- a/content/browser/web_contents/web_contents_impl.cc |
+++ b/content/browser/web_contents/web_contents_impl.cc |
@@ -10,6 +10,7 @@ |
#include <utility> |
#include <vector> |
+#include "base/atomic_sequence_num.h" |
#include "base/command_line.h" |
#include "base/debug/dump_without_crashing.h" |
#include "base/feature_list.h" |
@@ -125,13 +126,14 @@ |
#include "content/public/common/web_preferences.h" |
#include "device/geolocation/geolocation_service_context.h" |
#include "device/nfc/nfc.mojom.h" |
-#include "device/wake_lock/wake_lock_service_context.h" |
#include "net/base/url_util.h" |
#include "net/http/http_cache.h" |
#include "net/http/http_transaction_factory.h" |
#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "ppapi/features/features.h" |
+#include "services/device/public/interfaces/constants.mojom.h" |
+#include "services/service_manager/public/cpp/connector.h" |
#include "services/service_manager/public/cpp/interface_provider.h" |
#include "third_party/WebKit/public/platform/WebSecurityStyle.h" |
#include "third_party/WebKit/public/web/WebSandboxFlags.h" |
@@ -176,9 +178,14 @@ const char kDotGoogleDotCom[] = ".google.com"; |
const char kWebContentsAndroidKey[] = "web_contents_android"; |
#endif // OS_ANDROID |
+base::StaticAtomicSequenceNumber g_unique_id; |
+ |
base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
+base::LazyInstance<std::map<int, WebContents*>> g_id_to_web_contents = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
void NotifyCacheOnIO( |
scoped_refptr<net::URLRequestContextGetter> request_context, |
const GURL& url, |
@@ -302,6 +309,19 @@ void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
} |
} |
+gfx::NativeView WebContentsImpl::GetNativeViewForWebContents( |
+ int web_contents_id) { |
+ WebContents* web_contents = WebContents::FromId(web_contents_id); |
+ if (web_contents) |
+ return web_contents->GetNativeView(); |
+ return nullptr; |
+} |
+ |
+WebContents* WebContents::FromId(int id) { |
+ auto it = g_id_to_web_contents.Get().find(id); |
+ return it != g_id_to_web_contents.Get().end() ? it->second : nullptr; |
+} |
+ |
WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
if (!rvh) |
return nullptr; |
@@ -422,7 +442,8 @@ void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
// WebContentsImpl ------------------------------------------------------------- |
WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
- : delegate_(NULL), |
+ : id_(g_unique_id.GetNext()), |
+ delegate_(NULL), |
controller_(this, browser_context), |
render_view_host_delegate_view_(NULL), |
created_with_opener_(false), |
@@ -484,16 +505,25 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
#if BUILDFLAG(ENABLE_PLUGINS) |
pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
#endif |
+ |
+ if (ServiceManagerConnection::GetForProcess()) { |
+ service_manager::Connector* connector = |
+ ServiceManagerConnection::GetForProcess()->GetConnector(); |
+ DCHECK(connector); |
+ connector->BindInterface(device::mojom::kServiceName, |
+ mojo::MakeRequest(&wake_lock_service_context_)); |
+ wake_lock_service_context_->SetContextID(GetId()); |
+ } |
+ |
loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
- wake_lock_service_context_.reset(new device::WakeLockServiceContext( |
- BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
- base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this)))); |
host_zoom_map_observer_.reset(new HostZoomMapObserver(this)); |
} |
WebContentsImpl::~WebContentsImpl() { |
is_being_destroyed_ = true; |
+ g_id_to_web_contents.Get()[id_] = nullptr; |
+ |
// A WebContents should never be deleted while it is notifying observers, |
// since this will lead to a use-after-free as it continues to notfiy later |
// observers. |
@@ -827,6 +857,10 @@ const GURL& WebContentsImpl::GetLastCommittedURL() const { |
return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
} |
+int WebContentsImpl::GetId() { |
+ return id_; |
+} |
+ |
WebContentsDelegate* WebContentsImpl::GetDelegate() { |
return delegate_; |
} |
@@ -1640,6 +1674,8 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
// happens after RenderFrameHostManager::Init. |
NotifySwappedFromRenderManager( |
nullptr, GetRenderManager()->current_frame_host(), true); |
+ |
+ g_id_to_web_contents.Get()[id_] = this; |
} |
void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
@@ -2465,7 +2501,8 @@ WebContentsImpl::GetGeolocationServiceContext() { |
return geolocation_service_context_.get(); |
} |
-device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() { |
+device::mojom::WakeLockServiceContext* |
+WebContentsImpl::GetWakeLockServiceContext() { |
return wake_lock_service_context_.get(); |
} |