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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); | 57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); |
58 // Careful: The returned value could be NULL if the pref has never been set. | 58 // Careful: The returned value could be NULL if the pref has never been set. |
59 if (host_zoom_dictionary != NULL) { | 59 if (host_zoom_dictionary != NULL) { |
60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); | 60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); |
61 i != host_zoom_dictionary->end_keys(); ++i) { | 61 i != host_zoom_dictionary->end_keys(); ++i) { |
62 const std::string& host(*i); | 62 const std::string& host(*i); |
63 double zoom_level = 0; | 63 double zoom_level = 0; |
64 | 64 |
65 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( | 65 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( |
66 host, &zoom_level); | 66 host, &zoom_level); |
67 if (!success) { | |
68 // The data used to be stored as ints, so try that. | |
69 int int_zoom_level; | |
70 success = host_zoom_dictionary->GetIntegerWithoutPathExpansion( | |
71 host, &int_zoom_level); | |
72 if (success) { | |
73 zoom_level = static_cast<double>(int_zoom_level); | |
74 // Since the values were once stored as non-clamped, clamp now. | |
75 double zoom_factor = WebView::zoomLevelToZoomFactor(zoom_level); | |
76 if (zoom_factor < WebView::minTextSizeMultiplier) { | |
77 zoom_level = | |
78 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier); | |
79 } else if (zoom_factor > WebView::maxTextSizeMultiplier) { | |
80 zoom_level = | |
81 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier); | |
82 } | |
83 } | |
84 } | |
85 DCHECK(success); | 67 DCHECK(success); |
86 host_zoom_levels_[host] = zoom_level; | 68 host_zoom_levels_[host] = zoom_level; |
87 } | 69 } |
88 } | 70 } |
89 } | 71 } |
90 | 72 |
91 // static | 73 // static |
92 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) { | 74 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) { |
93 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); | 75 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); |
94 prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels); | 76 prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 break; | 219 break; |
238 } | 220 } |
239 default: | 221 default: |
240 NOTREACHED() << "Unexpected preference observed."; | 222 NOTREACHED() << "Unexpected preference observed."; |
241 } | 223 } |
242 } | 224 } |
243 | 225 |
244 HostZoomMap::~HostZoomMap() { | 226 HostZoomMap::~HostZoomMap() { |
245 Shutdown(); | 227 Shutdown(); |
246 } | 228 } |
OLD | NEW |