Index: content/browser/host_zoom_map_impl.cc |
diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc |
index 1b5f7a2f7d752a25cd4fef01246b7a277c975823..af0fc839ab58a4aad885c56010dbe424e3baeb47 100644 |
--- a/content/browser/host_zoom_map_impl.cc |
+++ b/content/browser/host_zoom_map_impl.cc |
@@ -20,11 +20,11 @@ |
#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 "net/base/net_util.h" |
-static const char* kHostZoomMapKeyName = "content_host_zoom_map"; |
- |
namespace content { |
namespace { |
@@ -49,33 +49,43 @@ std::string GetHostFromProcessView(int render_process_id, int render_view_id) { |
} // namespace |
HostZoomMap* HostZoomMap::GetForBrowserContext(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); |
awong
2014/08/11 22:36:33
How does API behave in the face of Chrome Apps? Sp
wjmaclean
2014/08/12 16:57:44
Chrome apps/WebView access their HostZoomMap via a
|
+ DCHECK(partition); |
+ return partition->GetHostZoomMap(); |
+} |
+ |
+HostZoomMap* HostZoomMap::GetForSite(SiteInstance* instance) { |
+ StoragePartition* partition = BrowserContext::GetStoragePartition( |
+ instance->GetBrowserContext(), instance); |
+ DCHECK(partition); |
+ return partition->GetHostZoomMap(); |
+} |
+ |
+HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) { |
+ return BrowserContext::GetStoragePartition(contents->GetBrowserContext(), |
+ contents->GetSiteInstance()) |
+ ->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::GetForBrowserContext(web_contents->GetBrowserContext())); |
+ 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::GetForBrowserContext(web_contents->GetBrowserContext())); |
+ HostZoomMap::GetForWebContents(web_contents)); |
host_zoom_map->SetZoomLevelForWebContents( |
*static_cast<const WebContentsImpl*>(web_contents), level); |
} |
-HostZoomMapImpl::HostZoomMapImpl() |
- : default_zoom_level_(0.0) { |
+HostZoomMapImpl::HostZoomMapImpl(double default_zoom_level) |
+ : default_zoom_level_(default_zoom_level) { |
registrar_.Add( |
this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
NotificationService::AllSources()); |
@@ -140,6 +150,27 @@ double HostZoomMapImpl::GetZoomLevelForHostAndScheme( |
return GetZoomLevelForHost(host); |
} |
+scoped_ptr<base::DictionaryValue> HostZoomMapImpl::ZoomLevelDictionary() const { |
+ base::DictionaryValue* dictionary = new base::DictionaryValue(); |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ |
+ for (HostZoomLevels::const_iterator i = host_zoom_levels_.begin(); |
+ i != host_zoom_levels_.end(); |
+ ++i) { |
+ if (!ZoomValuesEqual(i->second, default_zoom_level_)) { |
+ dictionary->SetDoubleWithoutPathExpansion(i->first /* host */, |
+ i->second /* level */); |
+ } |
+ } |
+ } |
+ return scoped_ptr<base::DictionaryValue>(dictionary); |
+} |
+ |
+// TODO(wjmaclean) The only non-test caller of this just throws away the non- |
+// host entries and makes a dictionary, and so could probably be converted to |
+// use ZoomLevelDictionary() instead. The test might also be amenable to |
+// something similar. |
HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const { |
HostZoomMap::ZoomLevelVector result; |
{ |
@@ -374,8 +405,8 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
!i.IsAtEnd(); i.Advance()) { |
RenderProcessHost* render_process_host = i.GetCurrentValue(); |
- if (HostZoomMap::GetForBrowserContext( |
- render_process_host->GetBrowserContext()) == this) { |
+ if (GetForBrowserContext(render_process_host->GetBrowserContext()) == |
+ this) { |
render_process_host->Send( |
new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
} |
@@ -383,6 +414,8 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
} |
HostZoomMapImpl::~HostZoomMapImpl() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
} |
+ |
} // namespace content |