| 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/callback_list.h" | 14 #include "base/callback_list.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 class BrowserContext; | 20 class BrowserContext; |
| 20 class ResourceContext; | 21 class ResourceContext; |
| 22 class SiteInstance; |
| 21 class WebContents; | 23 class WebContents; |
| 22 | 24 |
| 23 // Maps hostnames to custom zoom levels. Written on the UI thread and read on | 25 // Maps hostnames to custom zoom levels. Written on the UI thread and read on |
| 24 // any thread. One instance per browser context. Must be created on the UI | 26 // any thread. One instance per browser context. Must be created on the UI |
| 25 // thread, and it'll delete itself on the UI thread as well. | 27 // thread, and it'll delete itself on the UI thread as well. |
| 26 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom | 28 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom |
| 27 // for host with specific scheme. Setting any of the levels leaves settings | 29 // for host with specific scheme. Setting any of the levels leaves settings |
| 28 // for other settings intact. Getting the zoom level starts at the most | 30 // for other settings intact. Getting the zoom level starts at the most |
| 29 // specific setting and progresses to the less specific: first the zoom for the | 31 // specific setting and progresses to the less specific: first the zoom for the |
| 30 // host and scheme pair is checked, secondly the zoom for the host only and | 32 // host and scheme pair is checked, secondly the zoom for the host only and |
| 31 // lastly default zoom. | 33 // lastly default zoom. |
| 32 | 34 |
| 33 class HostZoomMap { | 35 class HostZoomMap { |
| 34 public: | 36 public: |
| 35 // Enum that indicates what was the scope of zoom level change. | 37 // Enum that indicates what was the scope of zoom level change. |
| 36 enum ZoomLevelChangeMode { | 38 enum ZoomLevelChangeMode { |
| 37 ZOOM_CHANGED_FOR_HOST, // Zoom level changed for host. | 39 ZOOM_CHANGED_FOR_HOST, // Zoom level changed for host. |
| 38 ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host | 40 ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host |
| 39 // pair. | 41 // pair. |
| 40 ZOOM_CHANGED_TEMPORARY_ZOOM, // Temporary zoom change for specific | 42 ZOOM_CHANGED_TEMPORARY_ZOOM, // Temporary zoom change for specific |
| 41 // renderer, no scheme/host is specified. | 43 // renderer, no scheme/host is specified. |
| 44 ZOOM_CHANGED_DEFAULT_ZOOM_LEVEL, // Notify when default level changes. |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 // Structure used to notify about zoom changes. Host and/or scheme are empty | 47 // Structure used to notify about zoom changes. Host and/or scheme are empty |
| 45 // if not applicable to |mode|. | 48 // if not applicable to |mode|. |
| 46 struct ZoomLevelChange { | 49 struct ZoomLevelChange { |
| 47 ZoomLevelChangeMode mode; | 50 ZoomLevelChangeMode mode; |
| 48 std::string host; | 51 std::string host; |
| 49 std::string scheme; | 52 std::string scheme; |
| 50 double zoom_level; | 53 double zoom_level; |
| 51 }; | 54 }; |
| 52 | 55 |
| 53 typedef std::vector<ZoomLevelChange> ZoomLevelVector; | 56 typedef std::vector<ZoomLevelChange> ZoomLevelVector; |
| 54 | 57 |
| 55 CONTENT_EXPORT static HostZoomMap* GetForBrowserContext( | 58 CONTENT_EXPORT static HostZoomMap* GetDefaultForBrowserContext( |
| 56 BrowserContext* browser_context); | 59 BrowserContext* browser_context); |
| 57 | 60 |
| 61 // Returns the HostZoomMap associated with this SiteInstance. The SiteInstance |
| 62 // may serve multiple WebContents, and the HostZoomMap is the same for all of |
| 63 // these WebContents. |
| 64 CONTENT_EXPORT static HostZoomMap* Get(SiteInstance* instance); |
| 65 |
| 66 // Returns the HostZoomMap associated with this WebContents. If multiple |
| 67 // WebContents share the same SiteInstance, then they share a single |
| 68 // HostZoomMap. |
| 69 CONTENT_EXPORT static HostZoomMap* GetForWebContents( |
| 70 const WebContents* contents); |
| 71 |
| 58 // Returns the current zoom level for the specified WebContents. May be | 72 // Returns the current zoom level for the specified WebContents. May be |
| 59 // temporary or host-specific. | 73 // temporary or host-specific. |
| 60 CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents); | 74 CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents); |
| 61 | 75 |
| 62 // Sets the current zoom level for the specified WebContents. The level may | 76 // Sets the current zoom level for the specified WebContents. The level may |
| 63 // be temporary or host-specific depending on the particular WebContents. | 77 // be temporary or host-specific depending on the particular WebContents. |
| 64 CONTENT_EXPORT static void SetZoomLevel(const WebContents* web_contents, | 78 CONTENT_EXPORT static void SetZoomLevel(const WebContents* web_contents, |
| 65 double level); | 79 double level); |
| 66 | 80 |
| 67 // Copy the zoom levels from the given map. Can only be called on the UI | 81 // Copy the zoom levels from the given map. Can only be called on the UI |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( | 153 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( |
| 140 const ZoomLevelChangedCallback& callback) = 0; | 154 const ZoomLevelChangedCallback& callback) = 0; |
| 141 | 155 |
| 142 protected: | 156 protected: |
| 143 virtual ~HostZoomMap() {} | 157 virtual ~HostZoomMap() {} |
| 144 }; | 158 }; |
| 145 | 159 |
| 146 } // namespace content | 160 } // namespace content |
| 147 | 161 |
| 148 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 162 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
| OLD | NEW |