| 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..e333fea8537346be19b6ee16ec16a0ee5e848299 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,45 @@ 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() : default_zoom_level_(0.0) {
|
| registrar_.Add(
|
| this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
|
| NotificationService::AllSources());
|
| @@ -140,6 +151,29 @@ double HostZoomMapImpl::GetZoomLevelForHostAndScheme(
|
| return GetZoomLevelForHost(host);
|
| }
|
|
|
| +scoped_ptr<base::DictionaryValue> HostZoomMapImpl::GetZoomLevelDictionary()
|
| + const {
|
| + scoped_ptr<base::DictionaryValue> zoom_level_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_)) continue;
|
| +
|
| + zoom_level_dictionary->SetDoubleWithoutPathExpansion(
|
| + i->first /* host */, i->second /* level */);
|
| + }
|
| + }
|
| + return zoom_level_dictionary.Pass();
|
| +}
|
| +
|
| +// 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;
|
| {
|
| @@ -225,7 +259,16 @@ double HostZoomMapImpl::GetDefaultZoomLevel() const {
|
| }
|
|
|
| void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
|
| + if (level == default_zoom_level_)
|
| + return;
|
| +
|
| default_zoom_level_ = level;
|
| +
|
| + HostZoomMap::ZoomLevelChange change;
|
| + change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM;
|
| + change.zoom_level = level;
|
| +
|
| + zoom_level_changed_callbacks_.Notify(change);
|
| }
|
|
|
| scoped_ptr<HostZoomMap::Subscription>
|
| @@ -374,8 +417,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 +428,7 @@ void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme,
|
| }
|
|
|
| HostZoomMapImpl::~HostZoomMapImpl() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| }
|
|
|
| } // namespace content
|
|
|