OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 7 #include "content/browser/host_zoom_map.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" |
11 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
12 #include "content/browser/renderer_host/render_process_host.h" | 12 #include "content/browser/renderer_host/render_process_host.h" |
13 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
14 #include "content/common/notification_service.h" | 14 #include "content/common/notification_service.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
18 | 18 |
19 using WebKit::WebView; | 19 using WebKit::WebView; |
20 | 20 |
21 HostZoomMap::HostZoomMap() : default_zoom_level_(0.0) { | 21 HostZoomMap::HostZoomMap() : default_zoom_level_(0.0) { |
22 registrar_.Add( | 22 registrar_.Add( |
23 this, NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, | 23 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
24 NotificationService::AllSources()); | 24 NotificationService::AllSources()); |
25 } | 25 } |
26 | 26 |
27 double HostZoomMap::GetZoomLevel(const std::string& host) const { | 27 double HostZoomMap::GetZoomLevel(const std::string& host) const { |
28 base::AutoLock auto_lock(lock_); | 28 base::AutoLock auto_lock(lock_); |
29 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); | 29 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); |
30 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; | 30 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; |
31 } | 31 } |
32 | 32 |
33 void HostZoomMap::SetZoomLevel(std::string host, double level) { | 33 void HostZoomMap::SetZoomLevel(std::string host, double level) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
35 | 35 |
36 { | 36 { |
37 base::AutoLock auto_lock(lock_); | 37 base::AutoLock auto_lock(lock_); |
38 if (level == default_zoom_level_) | 38 if (level == default_zoom_level_) |
39 host_zoom_levels_.erase(host); | 39 host_zoom_levels_.erase(host); |
40 else | 40 else |
41 host_zoom_levels_[host] = level; | 41 host_zoom_levels_[host] = level; |
42 } | 42 } |
43 | 43 |
44 NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED, | 44 NotificationService::current()->Notify( |
45 Source<HostZoomMap>(this), | 45 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
46 Details<const std::string>(&host)); | 46 Source<HostZoomMap>(this), |
| 47 Details<const std::string>(&host)); |
47 } | 48 } |
48 | 49 |
49 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, | 50 double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, |
50 int render_view_id) const { | 51 int render_view_id) const { |
51 base::AutoLock auto_lock(lock_); | 52 base::AutoLock auto_lock(lock_); |
52 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { | 53 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { |
53 if (temporary_zoom_levels_[i].render_process_id == render_process_id && | 54 if (temporary_zoom_levels_[i].render_process_id == render_process_id && |
54 temporary_zoom_levels_[i].render_view_id == render_view_id) { | 55 temporary_zoom_levels_[i].render_view_id == render_view_id) { |
55 return temporary_zoom_levels_[i].zoom_level; | 56 return temporary_zoom_levels_[i].zoom_level; |
56 } | 57 } |
(...skipping 24 matching lines...) Expand all Loading... |
81 if (level && i == temporary_zoom_levels_.size()) { | 82 if (level && i == temporary_zoom_levels_.size()) { |
82 TemporaryZoomLevel temp; | 83 TemporaryZoomLevel temp; |
83 temp.render_process_id = render_process_id; | 84 temp.render_process_id = render_process_id; |
84 temp.render_view_id = render_view_id; | 85 temp.render_view_id = render_view_id; |
85 temp.zoom_level = level; | 86 temp.zoom_level = level; |
86 temporary_zoom_levels_.push_back(temp); | 87 temporary_zoom_levels_.push_back(temp); |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 std::string host; | 91 std::string host; |
91 NotificationService::current()->Notify(NotificationType::ZOOM_LEVEL_CHANGED, | 92 NotificationService::current()->Notify( |
92 Source<HostZoomMap>(this), | 93 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
93 Details<const std::string>(&host)); | 94 Source<HostZoomMap>(this), |
| 95 Details<const std::string>(&host)); |
94 | 96 |
95 } | 97 } |
96 | 98 |
97 void HostZoomMap::Observe( | 99 void HostZoomMap::Observe( |
98 NotificationType type, | 100 int type, |
99 const NotificationSource& source, | 101 const NotificationSource& source, |
100 const NotificationDetails& details) { | 102 const NotificationDetails& details) { |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
102 | 104 |
103 switch (type.value) { | 105 switch (type) { |
104 case NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 106 case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
105 base::AutoLock auto_lock(lock_); | 107 base::AutoLock auto_lock(lock_); |
106 int render_view_id = Source<RenderViewHost>(source)->routing_id(); | 108 int render_view_id = Source<RenderViewHost>(source)->routing_id(); |
107 int render_process_id = Source<RenderViewHost>(source)->process()->id(); | 109 int render_process_id = Source<RenderViewHost>(source)->process()->id(); |
108 | 110 |
109 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { | 111 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { |
110 if (temporary_zoom_levels_[i].render_process_id == render_process_id && | 112 if (temporary_zoom_levels_[i].render_process_id == render_process_id && |
111 temporary_zoom_levels_[i].render_view_id == render_view_id) { | 113 temporary_zoom_levels_[i].render_view_id == render_view_id) { |
112 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); | 114 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); |
113 break; | 115 break; |
114 } | 116 } |
115 } | 117 } |
116 break; | 118 break; |
117 } | 119 } |
118 default: | 120 default: |
119 NOTREACHED() << "Unexpected preference observed."; | 121 NOTREACHED() << "Unexpected preference observed."; |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 HostZoomMap::~HostZoomMap() { | 125 HostZoomMap::~HostZoomMap() { |
124 } | 126 } |
OLD | NEW |