Migrate HostZoomMap to live in StoragePartition.
This CL changes the persistence of host zoom levels to be on
a per-storage-partition basis, as opposed to (the current)
per-profile basis. This is needed to allow WebView content
(withing apps) to keep their zoom levels independent of those
in the main browser window.
BUG=335317
Review URL: https://codereview.chromium.org/393133002
Cr-Commit-Position: refs/heads/master@{#303841}
diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc
index 81f8182..b6595b9 100644
--- a/content/browser/host_zoom_map_impl.cc
+++ b/content/browser/host_zoom_map_impl.cc
@@ -20,6 +20,8 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/resource_context.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/common/page_zoom.h"
#include "content/public/common/url_constants.h"
#include "net/base/net_util.h"
@@ -28,8 +30,6 @@
namespace {
-const char kHostZoomMapKeyName[] = "content_host_zoom_map";
-
std::string GetHostFromProcessView(int render_process_id, int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderViewHost* render_view_host =
@@ -61,29 +61,39 @@
}
HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) {
- HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>(
- context->GetUserData(kHostZoomMapKeyName));
- if (!rv) {
- rv = new HostZoomMapImpl();
- context->SetUserData(kHostZoomMapKeyName, rv);
- }
- return rv;
+ StoragePartition* partition =
+ BrowserContext::GetDefaultStoragePartition(context);
+ DCHECK(partition);
+ return partition->GetHostZoomMap();
+}
+
+HostZoomMap* HostZoomMap::Get(SiteInstance* instance) {
+ StoragePartition* partition = BrowserContext::GetStoragePartition(
+ instance->GetBrowserContext(), instance);
+ DCHECK(partition);
+ return partition->GetHostZoomMap();
+}
+
+HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) {
+ StoragePartition* partition =
+ BrowserContext::GetStoragePartition(contents->GetBrowserContext(),
+ contents->GetSiteInstance());
+ DCHECK(partition);
+ return partition->GetHostZoomMap();
}
// Helper function for setting/getting zoom levels for WebContents without
// having to import HostZoomMapImpl everywhere.
double HostZoomMap::GetZoomLevel(const WebContents* web_contents) {
- HostZoomMapImpl* host_zoom_map =
- static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext(
- web_contents->GetBrowserContext()));
+ HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
+ HostZoomMap::GetForWebContents(web_contents));
return host_zoom_map->GetZoomLevelForWebContents(
*static_cast<const WebContentsImpl*>(web_contents));
}
void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) {
- HostZoomMapImpl* host_zoom_map =
- static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext(
- web_contents->GetBrowserContext()));
+ HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
+ HostZoomMap::GetForWebContents(web_contents));
host_zoom_map->SetZoomLevelForWebContents(
*static_cast<const WebContentsImpl*>(web_contents), level);
}
@@ -243,10 +253,12 @@
}
double HostZoomMapImpl::GetDefaultZoomLevel() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
return default_zoom_level_;
}
void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
default_zoom_level_ = level;
}
@@ -396,8 +408,10 @@
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
RenderProcessHost* render_process_host = i.GetCurrentValue();
- if (HostZoomMap::GetDefaultForBrowserContext(
- render_process_host->GetBrowserContext()) == this) {
+ // TODO(wjmaclean) This will need to be cleaned up when
+ // RenderProcessHost::GetStoragePartition() goes away. Perhaps have
+ // RenderProcessHost expose a GetHostZoomMap() function?
+ if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) {
render_process_host->Send(
new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level));
}
@@ -413,6 +427,7 @@
}
HostZoomMapImpl::~HostZoomMapImpl() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
} // namespace content