Chromium Code Reviews| 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..4a3e0dd382b62cd712b7a752183409d7e57c7e3a 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 { |
| @@ -48,34 +48,46 @@ 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; |
| +HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { |
| + 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::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 +152,28 @@ double HostZoomMapImpl::GetZoomLevelForHostAndScheme( |
| return GetZoomLevelForHost(host); |
| } |
| +scoped_ptr<base::DictionaryValue> HostZoomMapImpl::GetZoomLevelDictionary() |
| + const { |
| + base::DictionaryValue* dictionary = new base::DictionaryValue(); |
|
Fady Samuel
2014/08/15 15:03:01
The convention is to create it within a scoped_ptr
wjmaclean
2014/08/15 22:13:50
Done.
For the record, I understood what you meant
|
| + { |
| + 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_)) continue; |
| + |
| + 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 GetZoomLevelDictionary() instead. The test might also be amenable to |
| +// something similar. |
| HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const { |
| HostZoomMap::ZoomLevelVector result; |
| { |
| @@ -374,8 +408,10 @@ 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) { |
| + // 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)); |
| } |
| @@ -383,6 +419,8 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
| } |
| HostZoomMapImpl::~HostZoomMapImpl() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| } |
| + |
|
Fady Samuel
2014/08/15 15:03:01
Remove extra space.
wjmaclean
2014/08/15 22:13:50
Done.
|
| } // namespace content |