host_zoom_map.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserContext;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceContext;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Maps hostnames to custom zoom levels.  Written on the UI thread and read on
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// any thread.  One instance per browser context. Must be created on the UI
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread, and it'll delete itself on the UI thread as well.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Zoom can be defined at three levels: default zoom, zoom for host, and zoom
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// for host with specific scheme. Setting any of the levels leaves settings
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// for other settings intact. Getting the zoom level starts at the most
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// specific setting and progresses to the less specific: first the zoom for the
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// host and scheme pair is checked, secondly the zoom for the host only and
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// lastly default zoom.
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostZoomMap {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Enum that indicates what was the scope of zoom level change.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum ZoomLevelChangeMode {
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ZOOM_CHANGED_FOR_HOST,            // Zoom level changed for host.
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      // pair.
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ZOOM_CHANGED_TEMPORARY_ZOOM,      // Temporary zoom change for specific
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      // renderer, no scheme/host is specified.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Structure used to notify about zoom changes. Host and/or scheme are empty
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // if not applicable to |mode|.
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  struct ZoomLevelChange {
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ZoomLevelChangeMode mode;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string host;
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string scheme;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    double zoom_level;
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static HostZoomMap* GetForBrowserContext(
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      BrowserContext* browser_context);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Copy the zoom levels from the given map. Can only be called on the UI
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // thread.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CopyFrom(HostZoomMap* copy) = 0;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Here |host| is the host portion of URL, or (in the absence of a host)
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the complete spec of the URL.
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the zoom for the specified |scheme| and |host|. See class
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // description for details.
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This may be called on any thread.
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual double GetZoomLevelForHostAndScheme(
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& scheme,
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const std::string& host) const = 0;
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Here |host| is the host portion of URL, or (in the absence of a host)
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the complete spec of the URL.
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the zoom level for the |host| to |level|.  If the level matches the
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // current default zoom level, the host is erased from the saved preferences;
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // otherwise the new value is written out.
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Zoom levels specified for both scheme and host are not affected.
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This should only be called on the UI thread.
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetZoomLevelForHost(const std::string& host, double level) = 0;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Here |host| is the host portion of URL, or (in the absence of a host)
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the complete spec of the URL.
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the zoom level for the |scheme|/|host| pair to |level|. No values
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // will be erased during this operation, and this value will not be stored in
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the preferences.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This should only be called on the UI thread.
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetZoomLevelForHostAndScheme(const std::string& scheme,
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                            const std::string& host,
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                            double level) = 0;
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get/Set the default zoom level for pages that don't override it.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual double GetDefaultZoomLevel() const = 0;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetDefaultZoomLevel(double level) = 0;;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef base::Callback<void(const ZoomLevelChange&)> ZoomLevelChangedCallback;
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Add and remove zoom level changed callbacks.
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void AddZoomLevelChangedCallback(
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const ZoomLevelChangedCallback& callback) = 0;
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RemoveZoomLevelChangedCallback(
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const ZoomLevelChangedCallback& callback) = 0;
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~HostZoomMap() {}
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
108