| 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_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 public base::SupportsUserData::Data { | 28 public base::SupportsUserData::Data { |
| 29 public: | 29 public: |
| 30 HostZoomMapImpl(); | 30 HostZoomMapImpl(); |
| 31 virtual ~HostZoomMapImpl(); | 31 virtual ~HostZoomMapImpl(); |
| 32 | 32 |
| 33 // HostZoomMap implementation: | 33 // HostZoomMap implementation: |
| 34 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; | 34 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; |
| 35 virtual double GetZoomLevelForHostAndScheme( | 35 virtual double GetZoomLevelForHostAndScheme( |
| 36 const std::string& scheme, | 36 const std::string& scheme, |
| 37 const std::string& host) const OVERRIDE; | 37 const std::string& host) const OVERRIDE; |
| 38 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486 |
| 39 virtual bool HasZoomLevel(const std::string& scheme, |
| 40 const std::string& host) const OVERRIDE; |
| 38 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; | 41 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; |
| 39 virtual void SetZoomLevelForHost( | 42 virtual void SetZoomLevelForHost( |
| 40 const std::string& host, | 43 const std::string& host, |
| 41 double level) OVERRIDE; | 44 double level) OVERRIDE; |
| 42 virtual void SetZoomLevelForHostAndScheme( | 45 virtual void SetZoomLevelForHostAndScheme( |
| 43 const std::string& scheme, | 46 const std::string& scheme, |
| 44 const std::string& host, | 47 const std::string& host, |
| 45 double level) OVERRIDE; | 48 double level) OVERRIDE; |
| 49 virtual bool UsesTemporaryZoomLevel(int render_process_id, |
| 50 int render_view_id) const OVERRIDE; |
| 51 virtual void SetTemporaryZoomLevel(int render_process_id, |
| 52 int render_view_id, |
| 53 double level) OVERRIDE; |
| 54 |
| 55 virtual void ClearTemporaryZoomLevel(int render_process_id, |
| 56 int render_view_id) OVERRIDE; |
| 46 virtual double GetDefaultZoomLevel() const OVERRIDE; | 57 virtual double GetDefaultZoomLevel() const OVERRIDE; |
| 47 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 58 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
| 48 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( | 59 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( |
| 49 const ZoomLevelChangedCallback& callback) OVERRIDE; | 60 const ZoomLevelChangedCallback& callback) OVERRIDE; |
| 50 | 61 |
| 51 // Returns the current zoom level for the specified WebContents. This may | 62 // Returns the current zoom level for the specified WebContents. This may |
| 52 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). | 63 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). |
| 53 double GetZoomLevelForWebContents( | 64 double GetZoomLevelForWebContents( |
| 54 const WebContentsImpl& web_contents_impl) const; | 65 const WebContentsImpl& web_contents_impl) const; |
| 55 | 66 |
| 56 // Sets the zoom level for this WebContents. If this WebContents is using | 67 // Sets the zoom level for this WebContents. If this WebContents is using |
| 57 // a temporary zoom level, then level is only applied to this WebContents. | 68 // a temporary zoom level, then level is only applied to this WebContents. |
| 58 // Otherwise, the level will be applied on a host level. | 69 // Otherwise, the level will be applied on a host level. |
| 59 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl, | 70 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl, |
| 60 double level); | 71 double level); |
| 61 | 72 |
| 62 // Sets the zoom level for the specified view. The level may be set for only | 73 // Sets the zoom level for the specified view. The level may be set for only |
| 63 // this view, or for the host, depending on UsesTemporaryZoomLevel(). | 74 // this view, or for the host, depending on UsesTemporaryZoomLevel(). |
| 64 void SetZoomLevelForView(int render_process_id, | 75 void SetZoomLevelForView(int render_process_id, |
| 65 int render_view_id, | 76 int render_view_id, |
| 66 double level, | 77 double level, |
| 67 const std::string& host); | 78 const std::string& host); |
| 68 | 79 |
| 69 // Returns whether the view manages its zoom level independently of other tabs | |
| 70 // displaying content from the same host. | |
| 71 bool UsesTemporaryZoomLevel(int render_process_id, int render_view_id) const; | |
| 72 | |
| 73 // Sets whether the view manages its zoom level independently of other tabs | |
| 74 // displaying content from the same host, based on whether | |
| 75 // |uses_temporary_zoom_level| is true. | |
| 76 void SetUsesTemporaryZoomLevel(int render_process_id, | |
| 77 int render_view_id, | |
| 78 bool uses_temporary_zoom_level); | |
| 79 | |
| 80 // Returns the temporary zoom level that's only valid for the lifetime of | 80 // Returns the temporary zoom level that's only valid for the lifetime of |
| 81 // the given WebContents (i.e. isn't saved and doesn't affect other | 81 // the given WebContents (i.e. isn't saved and doesn't affect other |
| 82 // WebContentses) if it exists, the default zoom level otherwise. | 82 // WebContentses) if it exists, the default zoom level otherwise. |
| 83 // | 83 // |
| 84 // This may be called on any thread. | 84 // This may be called on any thread. |
| 85 double GetTemporaryZoomLevel(int render_process_id, | 85 double GetTemporaryZoomLevel(int render_process_id, |
| 86 int render_view_id) const; | 86 int render_view_id) const; |
| 87 | 87 |
| 88 // Sets the temporary zoom level that's only valid for the lifetime of this | |
| 89 // WebContents. | |
| 90 // | |
| 91 // This should only be called on the UI thread. | |
| 92 void SetTemporaryZoomLevel(int render_process_id, | |
| 93 int render_view_id, | |
| 94 double level); | |
| 95 | |
| 96 // NotificationObserver implementation. | 88 // NotificationObserver implementation. |
| 97 virtual void Observe(int type, | 89 virtual void Observe(int type, |
| 98 const NotificationSource& source, | 90 const NotificationSource& source, |
| 99 const NotificationDetails& details) OVERRIDE; | 91 const NotificationDetails& details) OVERRIDE; |
| 100 | 92 |
| 101 private: | 93 private: |
| 102 typedef std::map<std::string, double> HostZoomLevels; | 94 typedef std::map<std::string, double> HostZoomLevels; |
| 103 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; | 95 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; |
| 104 | 96 |
| 105 struct TemporaryZoomLevel { | 97 struct RenderViewKey { |
| 106 TemporaryZoomLevel(int process_id, int view_id, double level); | |
| 107 TemporaryZoomLevel(int process_id, int view_id); | |
| 108 bool operator==(const TemporaryZoomLevel& other) const; | |
| 109 | |
| 110 int render_process_id; | 98 int render_process_id; |
| 111 int render_view_id; | 99 int render_view_id; |
| 112 double zoom_level; | 100 RenderViewKey(int render_process_id, int render_view_id) |
| 101 : render_process_id(render_process_id), |
| 102 render_view_id(render_view_id) {} |
| 103 bool operator<(const RenderViewKey& other) const { |
| 104 return render_process_id < other.render_process_id || |
| 105 ((render_process_id == other.render_process_id) && |
| 106 (render_view_id < other.render_view_id)); |
| 107 } |
| 113 }; | 108 }; |
| 114 | 109 |
| 115 typedef std::vector<TemporaryZoomLevel> TemporaryZoomLevels; | 110 typedef std::map<RenderViewKey, double> TemporaryZoomLevels; |
| 116 | 111 |
| 117 double GetZoomLevelForHost(const std::string& host) const; | 112 double GetZoomLevelForHost(const std::string& host) const; |
| 118 | 113 |
| 114 // Notifies the renderers from this browser context to change the zoom level |
| 115 // for the specified host and scheme. |
| 116 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486 |
| 117 void SendZoomLevelChange(const std::string& scheme, |
| 118 const std::string& host, |
| 119 double level); |
| 120 |
| 119 // Callbacks called when zoom level changes. | 121 // Callbacks called when zoom level changes. |
| 120 base::CallbackList<void(const ZoomLevelChange&)> | 122 base::CallbackList<void(const ZoomLevelChange&)> |
| 121 zoom_level_changed_callbacks_; | 123 zoom_level_changed_callbacks_; |
| 122 | 124 |
| 123 // Copy of the pref data, so that we can read it on the IO thread. | 125 // Copy of the pref data, so that we can read it on the IO thread. |
| 124 HostZoomLevels host_zoom_levels_; | 126 HostZoomLevels host_zoom_levels_; |
| 125 SchemeHostZoomLevels scheme_host_zoom_levels_; | 127 SchemeHostZoomLevels scheme_host_zoom_levels_; |
| 126 double default_zoom_level_; | 128 double default_zoom_level_; |
| 127 | 129 |
| 128 // Don't expect more than a couple of tabs that are using a temporary zoom | 130 // Don't expect more than a couple of tabs that are using a temporary zoom |
| 129 // level, so vector is fine for now. | 131 // level, so vector is fine for now. |
| 130 TemporaryZoomLevels temporary_zoom_levels_; | 132 TemporaryZoomLevels temporary_zoom_levels_; |
| 131 | 133 |
| 132 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 134 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
| 133 // |temporary_zoom_levels_| to guarantee thread safety. | 135 // |temporary_zoom_levels_| to guarantee thread safety. |
| 134 mutable base::Lock lock_; | 136 mutable base::Lock lock_; |
| 135 | 137 |
| 136 NotificationRegistrar registrar_; | 138 NotificationRegistrar registrar_; |
| 137 | 139 |
| 138 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 140 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
| 139 }; | 141 }; |
| 140 | 142 |
| 141 } // namespace content | 143 } // namespace content |
| 142 | 144 |
| 143 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 145 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
| OLD | NEW |