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" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/callback_list.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserContext; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceContext; 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class WebContents; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Maps hostnames to custom zoom levels. Written on the UI thread and read on 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// any thread. One instance per browser context. Must be created on the UI 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread, and it'll delete itself on the UI thread as well. 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Zoom can be defined at three levels: default zoom, zoom for host, and zoom 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// for host with specific scheme. Setting any of the levels leaves settings 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// for other settings intact. Getting the zoom level starts at the most 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// specific setting and progresses to the less specific: first the zoom for the 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// host and scheme pair is checked, secondly the zoom for the host only and 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// lastly default zoom. 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostZoomMap { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Enum that indicates what was the scope of zoom level change. 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enum ZoomLevelChangeMode { 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ZOOM_CHANGED_FOR_HOST, // Zoom level changed for host. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // pair. 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ZOOM_CHANGED_TEMPORARY_ZOOM, // Temporary zoom change for specific 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // renderer, no scheme/host is specified. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Structure used to notify about zoom changes. Host and/or scheme are empty 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // if not applicable to |mode|. 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct ZoomLevelChange { 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ZoomLevelChangeMode mode; 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string host; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string scheme; 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) double zoom_level; 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) typedef std::vector<ZoomLevelChange> ZoomLevelVector; 5423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci CONTENT_EXPORT static HostZoomMap* GetDefaultForBrowserContext( 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserContext* browser_context); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns the current zoom level for the specified WebContents. May be 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // temporary or host-specific. 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents); 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Sets the current zoom level for the specified WebContents. The level may 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // be temporary or host-specific depending on the particular WebContents. 64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CONTENT_EXPORT static void SetZoomLevel(const WebContents* web_contents, 65cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) double level); 66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Copy the zoom levels from the given map. Can only be called on the UI 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thread. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void CopyFrom(HostZoomMap* copy) = 0; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Here |host| is the host portion of URL, or (in the absence of a host) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the complete spec of the URL. 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the zoom for the specified |scheme| and |host|. See class 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // description for details. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This may be called on any thread. 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual double GetZoomLevelForHostAndScheme( 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& scheme, 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& host) const = 0; 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 81f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Returns true if the specified |scheme| and/or |host| has a zoom level 82f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // currently set. 83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // 84f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // This may be called on any thread. 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual bool HasZoomLevel(const std::string& scheme, 86f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const std::string& host) const = 0; 87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Returns all non-temporary zoom levels. Can be called on any thread. 8923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual ZoomLevelVector GetAllZoomLevels() const = 0; 9023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Here |host| is the host portion of URL, or (in the absence of a host) 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the complete spec of the URL. 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the zoom level for the |host| to |level|. If the level matches the 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // current default zoom level, the host is erased from the saved preferences; 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // otherwise the new value is written out. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Zoom levels specified for both scheme and host are not affected. 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This should only be called on the UI thread. 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetZoomLevelForHost(const std::string& host, double level) = 0; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Here |host| is the host portion of URL, or (in the absence of a host) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the complete spec of the URL. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the zoom level for the |scheme|/|host| pair to |level|. No values 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // will be erased during this operation, and this value will not be stored in 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the preferences. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This should only be called on the UI thread. 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetZoomLevelForHostAndScheme(const std::string& scheme, 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& host, 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) double level) = 0; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Returns whether the view manages its zoom level independently of other 113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // views displaying content from the same host. 114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual bool UsesTemporaryZoomLevel(int render_process_id, 115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) int render_view_id) const = 0; 116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Sets the temporary zoom level that's only valid for the lifetime of this 118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // WebContents. 119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // 120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // This should only be called on the UI thread. 121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual void SetTemporaryZoomLevel(int render_process_id, 122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) int render_view_id, 123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) double level) = 0; 124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Clears the temporary zoom level stored for this WebContents. 126f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // 127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // This should only be called on the UI thread. 128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual void ClearTemporaryZoomLevel(int render_process_id, 129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) int render_view_id) = 0; 130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get/Set the default zoom level for pages that don't override it. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual double GetDefaultZoomLevel() const = 0; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetDefaultZoomLevel(double level) = 0;; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef base::Callback<void(const ZoomLevelChange&)> ZoomLevelChangedCallback; 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef base::CallbackList<void(const ZoomLevelChange&)>::Subscription 1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Subscription; 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add and remove zoom level changed callbacks. 1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ZoomLevelChangedCallback& callback) = 0; 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~HostZoomMap() {} 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ 149