OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "content/browser/host_zoom_map_impl.h" | 7 #include "content/browser/host_zoom_map_impl.h" |
8 | 8 |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { | 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { |
49 // This can only be called on the UI thread to avoid deadlocks, otherwise | 49 // This can only be called on the UI thread to avoid deadlocks, otherwise |
50 // UI: a.CopyFrom(b); | 50 // UI: a.CopyFrom(b); |
51 // IO: b.CopyFrom(a); | 51 // IO: b.CopyFrom(a); |
52 // can deadlock. | 52 // can deadlock. |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); | 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); |
55 base::AutoLock auto_lock(lock_); | 55 base::AutoLock auto_lock(lock_); |
56 base::AutoLock copy_auto_lock(copy->lock_); | 56 base::AutoLock copy_auto_lock(copy->lock_); |
57 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); | 57 host_zoom_levels_. |
58 i != copy->host_zoom_levels_.end(); ++i) { | 58 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end()); |
59 host_zoom_levels_[i->first] = i->second; | 59 for (SchemeHostZoomLevels::const_iterator i(copy-> |
| 60 scheme_host_zoom_levels_.begin()); |
| 61 i != copy->scheme_host_zoom_levels_.end(); ++i) { |
| 62 scheme_host_zoom_levels_[i->first] = HostZoomLevels(); |
| 63 scheme_host_zoom_levels_[i->first]. |
| 64 insert(i->second.begin(), i->second.end()); |
60 } | 65 } |
61 default_zoom_level_ = copy->default_zoom_level_; | 66 default_zoom_level_ = copy->default_zoom_level_; |
62 } | 67 } |
63 | 68 |
64 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { | 69 double HostZoomMapImpl::GetZoomLevel(const std::string& scheme, |
| 70 const std::string& host) const { |
65 base::AutoLock auto_lock(lock_); | 71 base::AutoLock auto_lock(lock_); |
| 72 |
| 73 SchemeHostZoomLevels::const_iterator scheme_iterator( |
| 74 scheme_host_zoom_levels_.find(scheme)); |
| 75 if (scheme_iterator != scheme_host_zoom_levels_.end()) { |
| 76 HostZoomLevels::const_iterator i(scheme_iterator->second.find(host)); |
| 77 if (i != scheme_iterator->second.end()) |
| 78 return i->second; |
| 79 } |
| 80 |
66 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); | 81 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); |
67 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; | 82 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; |
68 } | 83 } |
69 | 84 |
70 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { | 85 |
| 86 void HostZoomMapImpl::SetZoomLevel(const std::string& scheme, |
| 87 const std::string& host, |
| 88 double level) { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
72 | |
73 { | 90 { |
74 base::AutoLock auto_lock(lock_); | 91 base::AutoLock auto_lock(lock_); |
75 | 92 if (!scheme.empty()) { |
76 if (ZoomValuesEqual(level, default_zoom_level_)) | 93 scheme_host_zoom_levels_[scheme][host] = level; |
77 host_zoom_levels_.erase(host); | 94 } else { |
78 else | 95 if (ZoomValuesEqual(level, default_zoom_level_)) |
79 host_zoom_levels_[host] = level; | 96 host_zoom_levels_.erase(host); |
| 97 else |
| 98 host_zoom_levels_[host] = level; |
| 99 } |
80 } | 100 } |
81 | 101 |
82 // Notify renderers from this browser context. | 102 // Notify renderers from this browser context. |
83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 103 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
84 !i.IsAtEnd(); i.Advance()) { | 104 !i.IsAtEnd(); i.Advance()) { |
85 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 105 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
86 if (HostZoomMap::GetForBrowserContext( | 106 if (HostZoomMap::GetForBrowserContext( |
87 render_process_host->GetBrowserContext()) == this) { | 107 render_process_host->GetBrowserContext()) == this) { |
88 render_process_host->Send( | 108 render_process_host->Send( |
89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 109 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
90 } | 110 } |
91 } | 111 } |
92 | 112 |
93 NotificationService::current()->Notify( | 113 NotificationService::current()->Notify( |
94 NOTIFICATION_ZOOM_LEVEL_CHANGED, | 114 NOTIFICATION_ZOOM_LEVEL_CHANGED, |
95 Source<HostZoomMap>(this), | 115 Source<HostZoomMap>(this), |
96 Details<const std::string>(&host)); | 116 Details<const std::string>(&host)); |
97 } | 117 } |
98 | 118 |
99 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 119 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 193 } |
174 default: | 194 default: |
175 NOTREACHED() << "Unexpected preference observed."; | 195 NOTREACHED() << "Unexpected preference observed."; |
176 } | 196 } |
177 } | 197 } |
178 | 198 |
179 HostZoomMapImpl::~HostZoomMapImpl() { | 199 HostZoomMapImpl::~HostZoomMapImpl() { |
180 } | 200 } |
181 | 201 |
182 } // namespace content | 202 } // namespace content |
OLD | NEW |