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 #ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/ref_counted.h" | |
15 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
16 #include "content/public/browser/browser_thread.h" | |
17 | 15 |
18 namespace content { | 16 namespace content { |
19 | 17 |
| 18 class BrowserContext; |
| 19 class ResourceContext; |
| 20 |
20 // Maps hostnames to custom zoom levels. Written on the UI thread and read on | 21 // Maps hostnames to custom zoom levels. Written on the UI thread and read on |
21 // any thread. One instance per browser context. Must be created on the UI | 22 // any thread. One instance per browser context. Must be created on the UI |
22 // thread, and it'll delete itself on the UI thread as well. | 23 // thread, and it'll delete itself on the UI thread as well. |
23 class HostZoomMap | 24 class HostZoomMap { |
24 : public base::RefCountedThreadSafe< | |
25 HostZoomMap, content::BrowserThread::DeleteOnUIThread> { | |
26 public: | 25 public: |
27 CONTENT_EXPORT static HostZoomMap* Create(); | 26 CONTENT_EXPORT static HostZoomMap* GetForBrowserContext( |
| 27 BrowserContext* browser_context); |
28 | 28 |
29 // Copy the zoom levels from the given map. Can only be called on the UI | 29 // Copy the zoom levels from the given map. Can only be called on the UI |
30 // thread. | 30 // thread. |
31 virtual void CopyFrom(HostZoomMap* copy) = 0; | 31 virtual void CopyFrom(HostZoomMap* copy) = 0; |
32 | 32 |
33 // Returns the zoom level for the host or spec for a given url. The zoom | 33 // Returns the zoom level for the host or spec for a given url. The zoom |
34 // level is determined by the host portion of the URL, or (in the absence of | 34 // level is determined by the host portion of the URL, or (in the absence of |
35 // a host) the complete spec of the URL. In most cases, there is no custom | 35 // a host) the complete spec of the URL. In most cases, there is no custom |
36 // zoom level, and this returns the user's default zoom level. Otherwise, | 36 // zoom level, and this returns the user's default zoom level. Otherwise, |
37 // returns the saved zoom level, which may be positive (to zoom in) or | 37 // returns the saved zoom level, which may be positive (to zoom in) or |
38 // negative (to zoom out). | 38 // negative (to zoom out). |
39 // | 39 // |
40 // This may be called on any thread. | 40 // This may be called on any thread. |
41 virtual double GetZoomLevel(const std::string& host) const = 0; | 41 virtual double GetZoomLevel(const std::string& host) const = 0; |
42 | 42 |
43 // Sets the zoom level for the host or spec for a given url to |level|. If | 43 // Sets the zoom level for the host or spec for a given url to |level|. If |
44 // the level matches the current default zoom level, the host is erased | 44 // the level matches the current default zoom level, the host is erased |
45 // from the saved preferences; otherwise the new value is written out. | 45 // from the saved preferences; otherwise the new value is written out. |
46 // | 46 // |
47 // This should only be called on the UI thread. | 47 // This should only be called on the UI thread. |
48 virtual void SetZoomLevel(std::string host, double level) = 0; | 48 virtual void SetZoomLevel(std::string host, double level) = 0; |
49 | 49 |
50 // Get/Set the default zoom level for pages that don't override it. | 50 // Get/Set the default zoom level for pages that don't override it. |
51 virtual double GetDefaultZoomLevel() const = 0; | 51 virtual double GetDefaultZoomLevel() const = 0; |
52 virtual void SetDefaultZoomLevel(double level) = 0;; | 52 virtual void SetDefaultZoomLevel(double level) = 0;; |
53 | 53 |
54 protected: | 54 protected: |
55 virtual ~HostZoomMap() {} | 55 virtual ~HostZoomMap() {} |
56 | |
57 private: | |
58 friend class base::RefCountedThreadSafe< | |
59 HostZoomMap, content::BrowserThread::DeleteOnUIThread>; | |
60 friend struct content::BrowserThread::DeleteOnThread< | |
61 content::BrowserThread::UI>; | |
62 friend class base::DeleteHelper<HostZoomMap>; | |
63 }; | 56 }; |
64 | 57 |
65 } // namespace content | 58 } // namespace content |
66 | 59 |
67 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 60 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
OLD | NEW |