From 5c9250876fbe81ea49a9919804db4f3da33ef4a0 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Mon, 30 Jan 2012 17:24:05 +0000 Subject: Create Content API around HostZoomMap. BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9296041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119684 0039d316-1c4b-4281-b951-d872f2087c98 --- content/browser/host_zoom_map.cc | 160 ------------------- content/browser/host_zoom_map.h | 113 ------------- content/browser/host_zoom_map_impl.cc | 177 +++++++++++++++++++++ content/browser/host_zoom_map_impl.h | 84 ++++++++++ content/browser/host_zoom_map_impl_unittest.cc | 31 ++++ content/browser/host_zoom_map_unittest.cc | 32 ---- .../renderer_host/async_resource_handler.cc | 5 +- .../browser/renderer_host/async_resource_handler.h | 2 - content/browser/renderer_host/render_view_host.cc | 5 +- content/browser/resource_context.h | 3 +- content/browser/tab_contents/tab_contents.cc | 5 +- content/content_browser.gypi | 5 +- content/content_tests.gypi | 2 +- content/public/browser/browser_context.h | 2 +- content/public/browser/host_zoom_map.h | 67 ++++++++ content/shell/shell_browser_context.cc | 4 +- content/shell/shell_browser_context.h | 1 - content/test/test_browser_context.cc | 1 + content/test/test_browser_context.h | 2 +- 19 files changed, 378 insertions(+), 323 deletions(-) delete mode 100644 content/browser/host_zoom_map.cc delete mode 100644 content/browser/host_zoom_map.h create mode 100644 content/browser/host_zoom_map_impl.cc create mode 100644 content/browser/host_zoom_map_impl.h create mode 100644 content/browser/host_zoom_map_impl_unittest.cc delete mode 100644 content/browser/host_zoom_map_unittest.cc create mode 100644 content/public/browser/host_zoom_map.h (limited to 'content') diff --git a/content/browser/host_zoom_map.cc b/content/browser/host_zoom_map.cc deleted file mode 100644 index 770347e..0000000 --- a/content/browser/host_zoom_map.cc +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "content/browser/host_zoom_map.h" - -#include "base/string_piece.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "content/browser/renderer_host/render_process_host_impl.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/common/view_messages.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" -#include "content/public/common/page_zoom.h" -#include "googleurl/src/gurl.h" -#include "net/base/net_util.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" - -using WebKit::WebView; -using content::BrowserThread; -using content::RenderProcessHost; - -HostZoomMap::HostZoomMap() - : default_zoom_level_(0.0) { - registrar_.Add( - this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, - content::NotificationService::AllSources()); -} - -void HostZoomMap::CopyFrom(HostZoomMap* copy) { - // This can only be called on the UI thread to avoid deadlocks, otherwise - // UI: a.CopyFrom(b); - // IO: b.CopyFrom(a); - // can deadlock. - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - base::AutoLock auto_lock(lock_); - base::AutoLock copy_auto_lock(copy->lock_); - for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); - i != copy->host_zoom_levels_.end(); ++i) { - host_zoom_levels_[i->first] = i->second; - } -} - -double HostZoomMap::GetZoomLevel(const std::string& host) const { - base::AutoLock auto_lock(lock_); - HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); - return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; -} - -void HostZoomMap::SetZoomLevel(std::string host, double level) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - { - base::AutoLock auto_lock(lock_); - - if (content::ZoomValuesEqual(level, default_zoom_level_)) - host_zoom_levels_.erase(host); - else - host_zoom_levels_[host] = level; - } - - // Notify renderers from this browser context. - for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); - !i.IsAtEnd(); i.Advance()) { - RenderProcessHost* render_process_host = i.GetCurrentValue(); - if (render_process_host->GetBrowserContext()->GetHostZoomMap() == this) { - render_process_host->Send( - new ViewMsg_SetZoomLevelForCurrentURL(host, level)); - } - } - - content::NotificationService::current()->Notify( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source(this), - content::Details(&host)); -} - -double HostZoomMap::GetTemporaryZoomLevel(int render_process_id, - int render_view_id) const { - base::AutoLock auto_lock(lock_); - for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { - if (temporary_zoom_levels_[i].render_process_id == render_process_id && - temporary_zoom_levels_[i].render_view_id == render_view_id) { - return temporary_zoom_levels_[i].zoom_level; - } - } - return 0; -} - -void HostZoomMap::SetTemporaryZoomLevel(int render_process_id, - int render_view_id, - double level) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - { - base::AutoLock auto_lock(lock_); - size_t i; - for (i = 0; i < temporary_zoom_levels_.size(); ++i) { - if (temporary_zoom_levels_[i].render_process_id == render_process_id && - temporary_zoom_levels_[i].render_view_id == render_view_id) { - if (level) { - temporary_zoom_levels_[i].zoom_level = level; - } else { - temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); - } - break; - } - } - - if (level && i == temporary_zoom_levels_.size()) { - TemporaryZoomLevel temp; - temp.render_process_id = render_process_id; - temp.render_view_id = render_view_id; - temp.zoom_level = level; - temporary_zoom_levels_.push_back(temp); - } - } - - std::string host; - content::NotificationService::current()->Notify( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source(this), - content::Details(&host)); -} - -void HostZoomMap::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - switch (type) { - case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { - base::AutoLock auto_lock(lock_); - int render_view_id = - content::Source(source)->routing_id(); - int render_process_id = - content::Source(source)->process()->GetID(); - - for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { - if (temporary_zoom_levels_[i].render_process_id == render_process_id && - temporary_zoom_levels_[i].render_view_id == render_view_id) { - temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); - break; - } - } - break; - } - default: - NOTREACHED() << "Unexpected preference observed."; - } -} - -HostZoomMap::~HostZoomMap() { -} diff --git a/content/browser/host_zoom_map.h b/content/browser/host_zoom_map.h deleted file mode 100644 index 53dd770..0000000 --- a/content/browser/host_zoom_map.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Maps hostnames to custom zoom levels. Written on the UI thread and read on -// any thread. One instance per browser context. - -#ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_H_ -#define CONTENT_BROWSER_HOST_ZOOM_MAP_H_ -#pragma once - -#include -#include -#include - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "base/message_loop_helpers.h" -#include "base/synchronization/lock.h" -#include "content/common/content_export.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -// HostZoomMap needs to be deleted on the UI thread because it listens -// to notifications on there (and holds a NotificationRegistrar). -class CONTENT_EXPORT HostZoomMap - : public content::NotificationObserver, - public base::RefCountedThreadSafe< - HostZoomMap, content::BrowserThread::DeleteOnUIThread> { - public: - HostZoomMap(); - - // Copy the zoom levels from the given map. Can only be called on the UI - // thread. - void CopyFrom(HostZoomMap* copy); - - // Returns the zoom level for the host or spec for a given url. The zoom - // level is determined by the host portion of the URL, or (in the absence of - // a host) the complete spec of the URL. In most cases, there is no custom - // zoom level, and this returns the user's default zoom level. Otherwise, - // returns the saved zoom level, which may be positive (to zoom in) or - // negative (to zoom out). - // - // This may be called on any thread. - double GetZoomLevel(const std::string& host) const; - - // Sets the zoom level for the host or spec for a given url to |level|. If - // the level matches the current default zoom level, the host is erased - // from the saved preferences; otherwise the new value is written out. - // - // This should only be called on the UI thread. - void SetZoomLevel(std::string host, double level); - - // Returns the temporary zoom level that's only valid for the lifetime of - // the given tab (i.e. isn't saved and doesn't affect other tabs) if it - // exists, the default zoom level otherwise. - // - // This may be called on any thread. - double GetTemporaryZoomLevel(int render_process_id, - int render_view_id) const; - - // Sets the temporary zoom level that's only valid for the lifetime of this - // tab. - // - // This should only be called on the UI thread. - void SetTemporaryZoomLevel(int render_process_id, - int render_view_id, - double level); - - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - double default_zoom_level() const { return default_zoom_level_; } - void set_default_zoom_level(double level) { default_zoom_level_ = level; } - - private: - friend class base::RefCountedThreadSafe< - HostZoomMap, content::BrowserThread::DeleteOnUIThread>; - friend struct content::BrowserThread::DeleteOnThread< - content::BrowserThread::UI>; - friend class base::DeleteHelper; - - typedef std::map HostZoomLevels; - - virtual ~HostZoomMap(); - - // Copy of the pref data, so that we can read it on the IO thread. - HostZoomLevels host_zoom_levels_; - double default_zoom_level_; - - struct TemporaryZoomLevel { - int render_process_id; - int render_view_id; - double zoom_level; - }; - - // Don't expect more than a couple of tabs that are using a temporary zoom - // level, so vector is fine for now. - std::vector temporary_zoom_levels_; - - // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and - // |temporary_zoom_levels_| to guarantee thread safety. - mutable base::Lock lock_; - - content::NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(HostZoomMap); -}; - -#endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc new file mode 100644 index 0000000..5223c96 --- /dev/null +++ b/content/browser/host_zoom_map_impl.cc @@ -0,0 +1,177 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "content/browser/host_zoom_map_impl.h" + +#include "base/string_piece.h" +#include "base/utf_string_conversions.h" +#include "base/values.h" +#include "content/browser/renderer_host/render_process_host_impl.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/common/view_messages.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_types.h" +#include "content/public/common/page_zoom.h" +#include "googleurl/src/gurl.h" +#include "net/base/net_util.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" + +using WebKit::WebView; +using content::BrowserThread; +using content::RenderProcessHost; + +namespace content { + +HostZoomMap* HostZoomMap::Create() { + return new HostZoomMapImpl(); +} + +} // namespace content + +HostZoomMapImpl::HostZoomMapImpl() + : default_zoom_level_(0.0) { + registrar_.Add( + this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, + content::NotificationService::AllSources()); +} + +void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { + // This can only be called on the UI thread to avoid deadlocks, otherwise + // UI: a.CopyFrom(b); + // IO: b.CopyFrom(a); + // can deadlock. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + HostZoomMapImpl* copy = static_cast(copy_interface); + base::AutoLock auto_lock(lock_); + base::AutoLock copy_auto_lock(copy->lock_); + for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); + i != copy->host_zoom_levels_.end(); ++i) { + host_zoom_levels_[i->first] = i->second; + } +} + +double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { + base::AutoLock auto_lock(lock_); + HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); + return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; +} + +void HostZoomMapImpl::SetZoomLevel(std::string host, double level) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + { + base::AutoLock auto_lock(lock_); + + if (content::ZoomValuesEqual(level, default_zoom_level_)) + host_zoom_levels_.erase(host); + else + host_zoom_levels_[host] = level; + } + + // Notify renderers from this browser context. + for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); + !i.IsAtEnd(); i.Advance()) { + RenderProcessHost* render_process_host = i.GetCurrentValue(); + if (render_process_host->GetBrowserContext()->GetHostZoomMap() == this) { + render_process_host->Send( + new ViewMsg_SetZoomLevelForCurrentURL(host, level)); + } + } + + content::NotificationService::current()->Notify( + content::NOTIFICATION_ZOOM_LEVEL_CHANGED, + content::Source(this), + content::Details(&host)); +} + +double HostZoomMapImpl::GetDefaultZoomLevel() const { + return default_zoom_level_; +} + +void HostZoomMapImpl::SetDefaultZoomLevel(double level) { + default_zoom_level_ = level; +} + +double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, + int render_view_id) const { + base::AutoLock auto_lock(lock_); + for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { + if (temporary_zoom_levels_[i].render_process_id == render_process_id && + temporary_zoom_levels_[i].render_view_id == render_view_id) { + return temporary_zoom_levels_[i].zoom_level; + } + } + return 0; +} + +void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id, + int render_view_id, + double level) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + { + base::AutoLock auto_lock(lock_); + size_t i; + for (i = 0; i < temporary_zoom_levels_.size(); ++i) { + if (temporary_zoom_levels_[i].render_process_id == render_process_id && + temporary_zoom_levels_[i].render_view_id == render_view_id) { + if (level) { + temporary_zoom_levels_[i].zoom_level = level; + } else { + temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); + } + break; + } + } + + if (level && i == temporary_zoom_levels_.size()) { + TemporaryZoomLevel temp; + temp.render_process_id = render_process_id; + temp.render_view_id = render_view_id; + temp.zoom_level = level; + temporary_zoom_levels_.push_back(temp); + } + } + + std::string host; + content::NotificationService::current()->Notify( + content::NOTIFICATION_ZOOM_LEVEL_CHANGED, + content::Source(this), + content::Details(&host)); +} + +void HostZoomMapImpl::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + switch (type) { + case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { + base::AutoLock auto_lock(lock_); + int render_view_id = + content::Source(source)->routing_id(); + int render_process_id = + content::Source(source)->process()->GetID(); + + for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { + if (temporary_zoom_levels_[i].render_process_id == render_process_id && + temporary_zoom_levels_[i].render_view_id == render_view_id) { + temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); + break; + } + } + break; + } + default: + NOTREACHED() << "Unexpected preference observed."; + } +} + +HostZoomMapImpl::~HostZoomMapImpl() { +} diff --git a/content/browser/host_zoom_map_impl.h b/content/browser/host_zoom_map_impl.h new file mode 100644 index 0000000..6d5cdd1 --- /dev/null +++ b/content/browser/host_zoom_map_impl.h @@ -0,0 +1,84 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ +#define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ +#pragma once + +#include +#include +#include + +#include "base/compiler_specific.h" +#include "base/message_loop_helpers.h" +#include "base/synchronization/lock.h" +#include "content/public/browser/host_zoom_map.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +// HostZoomMap needs to be deleted on the UI thread because it listens +// to notifications on there (and holds a NotificationRegistrar). +class CONTENT_EXPORT HostZoomMapImpl + : public NON_EXPORTED_BASE(content::HostZoomMap), + public content::NotificationObserver { + public: + HostZoomMapImpl(); + + // HostZoomMap implementation: + virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; + virtual double GetZoomLevel(const std::string& host) const OVERRIDE; + virtual void SetZoomLevel(std::string host, double level) OVERRIDE; + virtual double GetDefaultZoomLevel() const OVERRIDE; + virtual void SetDefaultZoomLevel(double level) OVERRIDE; + + // Returns the temporary zoom level that's only valid for the lifetime of + // the given tab (i.e. isn't saved and doesn't affect other tabs) if it + // exists, the default zoom level otherwise. + // + // This may be called on any thread. + double GetTemporaryZoomLevel(int render_process_id, + int render_view_id) const; + + // Sets the temporary zoom level that's only valid for the lifetime of this + // tab. + // + // This should only be called on the UI thread. + void SetTemporaryZoomLevel(int render_process_id, + int render_view_id, + double level); + + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + private: + typedef std::map HostZoomLevels; + + virtual ~HostZoomMapImpl(); + + // Copy of the pref data, so that we can read it on the IO thread. + HostZoomLevels host_zoom_levels_; + double default_zoom_level_; + + struct TemporaryZoomLevel { + int render_process_id; + int render_view_id; + double zoom_level; + }; + + // Don't expect more than a couple of tabs that are using a temporary zoom + // level, so vector is fine for now. + std::vector temporary_zoom_levels_; + + // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and + // |temporary_zoom_levels_| to guarantee thread safety. + mutable base::Lock lock_; + + content::NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); +}; + +#endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ diff --git a/content/browser/host_zoom_map_impl_unittest.cc b/content/browser/host_zoom_map_impl_unittest.cc new file mode 100644 index 0000000..cb0aba4 --- /dev/null +++ b/content/browser/host_zoom_map_impl_unittest.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/host_zoom_map_impl.h" + +#include "base/memory/ref_counted.h" +#include "base/message_loop.h" +#include "content/public/browser/browser_thread.h" +#include "content/test/test_browser_thread.h" +#include "testing/gtest/include/gtest/gtest.h" + +class HostZoomMapTest : public testing::Test { + public: + HostZoomMapTest() : ui_thread_(content::BrowserThread::UI, &message_loop_) { + } + + protected: + MessageLoop message_loop_; + content::TestBrowserThread ui_thread_; +}; + +TEST_F(HostZoomMapTest, GetSetZoomLevel) { + scoped_refptr host_zoom_map = new HostZoomMapImpl; + + double zoomed = 2.5; + host_zoom_map->SetZoomLevel("zoomed.com", zoomed); + + EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("normal.com"), 0); + EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("zoomed.com"), zoomed); +} diff --git a/content/browser/host_zoom_map_unittest.cc b/content/browser/host_zoom_map_unittest.cc deleted file mode 100644 index d151362..0000000 --- a/content/browser/host_zoom_map_unittest.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/host_zoom_map.h" - -#include "base/memory/ref_counted.h" -#include "base/message_loop.h" -#include "content/public/browser/browser_thread.h" -#include "content/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -class HostZoomMapTest : public testing::Test { - public: - HostZoomMapTest() : ui_thread_(content::BrowserThread::UI, &message_loop_) { - } - - protected: - MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; -}; - -TEST_F(HostZoomMapTest, GetSetZoomLevel) { - scoped_refptr host_zoom_map = new HostZoomMap; - - double zoomed = 2.5; - host_zoom_map->SetZoomLevel("zoomed.com", zoomed); - - EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("normal.com"), 0); - EXPECT_DOUBLE_EQ(host_zoom_map->GetZoomLevel("zoomed.com"), zoomed); -} - diff --git a/content/browser/renderer_host/async_resource_handler.cc b/content/browser/renderer_host/async_resource_handler.cc index c7fe3ff..4b1bf18 100644 --- a/content/browser/renderer_host/async_resource_handler.cc +++ b/content/browser/renderer_host/async_resource_handler.cc @@ -12,7 +12,7 @@ #include "base/logging.h" #include "base/shared_memory.h" #include "content/browser/debugger/devtools_netlog_observer.h" -#include "content/browser/host_zoom_map.h" +#include "content/browser/host_zoom_map_impl.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "content/browser/renderer_host/resource_message_filter.h" @@ -84,7 +84,6 @@ AsyncResourceHandler::AsyncResourceHandler( ResourceDispatcherHost* resource_dispatcher_host) : filter_(filter), routing_id_(routing_id), - host_zoom_map_(NULL), rdh_(resource_dispatcher_host), next_buffer_size_(kInitialReadBufSize), url_(url) { @@ -136,7 +135,7 @@ bool AsyncResourceHandler::OnResponseStarted( const content::ResourceContext& resource_context = filter_->resource_context(); - HostZoomMap* host_zoom_map = resource_context.host_zoom_map(); + content::HostZoomMap* host_zoom_map = resource_context.host_zoom_map(); ResourceDispatcherHostRequestInfo* info = rdh_->InfoForRequest(request); if (info->resource_type() == ResourceType::MAIN_FRAME && host_zoom_map) { diff --git a/content/browser/renderer_host/async_resource_handler.h b/content/browser/renderer_host/async_resource_handler.h index ee5fc81..5e43615 100644 --- a/content/browser/renderer_host/async_resource_handler.h +++ b/content/browser/renderer_host/async_resource_handler.h @@ -11,7 +11,6 @@ #include "content/browser/renderer_host/resource_handler.h" #include "googleurl/src/gurl.h" -class HostZoomMap; class ResourceDispatcherHost; class ResourceMessageFilter; class SharedIOBuffer; @@ -59,7 +58,6 @@ class AsyncResourceHandler : public ResourceHandler { scoped_refptr read_buffer_; scoped_refptr filter_; int routing_id_; - HostZoomMap* host_zoom_map_; ResourceDispatcherHost* rdh_; // |next_buffer_size_| is the size of the buffer to be allocated on the next diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 3b6ba75..d8b3fab 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -20,7 +20,7 @@ #include "content/browser/child_process_security_policy.h" #include "content/browser/cross_site_request_manager.h" #include "content/browser/gpu/gpu_surface_tracker.h" -#include "content/browser/host_zoom_map.h" +#include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/power_save_blocker.h" #include "content/browser/renderer_host/render_process_host_impl.h" @@ -1466,7 +1466,8 @@ void RenderViewHost::OnScriptEvalResponse(int id, const ListValue& result) { void RenderViewHost::OnDidZoomURL(double zoom_level, bool remember, const GURL& url) { - HostZoomMap* host_zoom_map = process()->GetBrowserContext()->GetHostZoomMap(); + HostZoomMapImpl* host_zoom_map = static_cast( + process()->GetBrowserContext()->GetHostZoomMap()); if (remember) { host_zoom_map->SetZoomLevel(net::GetHostOrSpecFromURL(url), zoom_level); } else { diff --git a/content/browser/resource_context.h b/content/browser/resource_context.h index 22803e3..61785fa 100644 --- a/content/browser/resource_context.h +++ b/content/browser/resource_context.h @@ -15,7 +15,6 @@ class AudioManager; class ChromeAppCacheService; class ChromeBlobStorageContext; -class HostZoomMap; class MediaObserver; namespace fileapi { class FileSystemContext; @@ -36,6 +35,8 @@ class DatabaseTracker; namespace content { +class HostZoomMap; + // ResourceContext contains the relevant context information required for // resource loading. It lives on the IO thread, although it is constructed on // the UI thread. ResourceContext doesn't own anything it points to, it just diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 6e2780a..de5ee52 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -17,7 +17,7 @@ #include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/download/download_stats.h" #include "content/browser/download/save_package.h" -#include "content/browser/host_zoom_map.h" +#include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/intents/web_intents_dispatcher_impl.h" #include "content/browser/load_from_memory_cache_details.h" @@ -1044,7 +1044,8 @@ bool TabContents::GetClosedByUserGesture() const { } double TabContents::GetZoomLevel() const { - HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap(); + HostZoomMapImpl* zoom_map = static_cast( + GetBrowserContext()->GetHostZoomMap()); if (!zoom_map) return 0; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index c2d9bcf..975b4fe 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -61,6 +61,7 @@ 'public/browser/favicon_status.h', 'public/browser/geolocation_permission_context.h', 'public/browser/global_request_id.h', + 'public/browser/host_zoom_map.h', 'public/browser/invalidate_type.h', 'public/browser/native_web_keyboard_event.h', 'public/browser/navigation_controller.h', @@ -318,8 +319,8 @@ 'browser/gpu/gpu_process_host_ui_shim.h', 'browser/gpu/gpu_surface_tracker.cc', 'browser/gpu/gpu_surface_tracker.h', - 'browser/host_zoom_map.cc', - 'browser/host_zoom_map.h', + 'browser/host_zoom_map_impl.cc', + 'browser/host_zoom_map_impl.h', 'browser/in_process_webkit/browser_webkitplatformsupport_impl.cc', 'browser/in_process_webkit/browser_webkitplatformsupport_impl.h', 'browser/in_process_webkit/dom_storage_area.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index e525382..1287348 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -218,7 +218,7 @@ 'browser/geolocation/win7_location_api_unittest_win.cc', 'browser/geolocation/win7_location_provider_unittest_win.cc', 'browser/gpu/gpu_blacklist_unittest.cc', - 'browser/host_zoom_map_unittest.cc', + 'browser/host_zoom_map_impl_unittest.cc', 'browser/in_process_webkit/dom_storage_unittest.cc', 'browser/in_process_webkit/indexed_db_quota_client_unittest.cc', 'browser/in_process_webkit/webkit_context_unittest.cc', diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index cc8cce5..e2ba765 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -28,7 +28,6 @@ class ChromeAppCacheService; class ChromeBlobStorageContext; class FilePath; class SpeechInputPreferences; -class HostZoomMap; class SSLHostState; class WebKitContext; @@ -36,6 +35,7 @@ namespace content { class DownloadManager; class GeolocationPermissionContext; +class HostZoomMap; class ResourceContext; // This class holds the context needed for a browsing session. diff --git a/content/public/browser/host_zoom_map.h b/content/public/browser/host_zoom_map.h new file mode 100644 index 0000000..0ebf28f --- /dev/null +++ b/content/public/browser/host_zoom_map.h @@ -0,0 +1,67 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ +#define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ +#pragma once + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "content/common/content_export.h" +#include "content/public/browser/browser_thread.h" + +namespace content { + +// Maps hostnames to custom zoom levels. Written on the UI thread and read on +// any thread. One instance per browser context. Must be created on the UI +// thread, and it'll delete itself on the UI thread as well. +class HostZoomMap + : public base::RefCountedThreadSafe< + HostZoomMap, content::BrowserThread::DeleteOnUIThread> { + public: + CONTENT_EXPORT static HostZoomMap* Create(); + + // Copy the zoom levels from the given map. Can only be called on the UI + // thread. + virtual void CopyFrom(HostZoomMap* copy) = 0; + + // Returns the zoom level for the host or spec for a given url. The zoom + // level is determined by the host portion of the URL, or (in the absence of + // a host) the complete spec of the URL. In most cases, there is no custom + // zoom level, and this returns the user's default zoom level. Otherwise, + // returns the saved zoom level, which may be positive (to zoom in) or + // negative (to zoom out). + // + // This may be called on any thread. + virtual double GetZoomLevel(const std::string& host) const = 0; + + // Sets the zoom level for the host or spec for a given url to |level|. If + // the level matches the current default zoom level, the host is erased + // from the saved preferences; otherwise the new value is written out. + // + // This should only be called on the UI thread. + virtual void SetZoomLevel(std::string host, double level) = 0; + + // Get/Set the default zoom level for pages that don't override it. + virtual double GetDefaultZoomLevel() const = 0; + virtual void SetDefaultZoomLevel(double level) = 0;; + + protected: + virtual ~HostZoomMap() {} + + private: + friend class base::RefCountedThreadSafe< + HostZoomMap, content::BrowserThread::DeleteOnUIThread>; + friend struct content::BrowserThread::DeleteOnThread< + content::BrowserThread::UI>; + friend class base::DeleteHelper; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index f6dff1e..7cca20e 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -15,7 +15,7 @@ #include "content/browser/download/download_manager_impl.h" #include "content/browser/download/download_status_updater.h" #include "content/browser/file_system/browser_file_system_helper.h" -#include "content/browser/host_zoom_map.h" +#include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/speech/speech_input_preferences.h" #include "content/browser/ssl/ssl_host_state.h" @@ -181,7 +181,7 @@ const ResourceContext& ShellBrowserContext::GetResourceContext() { HostZoomMap* ShellBrowserContext::GetHostZoomMap() { if (!host_zoom_map_) - host_zoom_map_ = new HostZoomMap(); + host_zoom_map_ = HostZoomMap::Create(); return host_zoom_map_.get(); } diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index b1b8a7b..6828165 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -14,7 +14,6 @@ class DownloadManager; class DownloadStatusUpdater; -class HostZoomMap; class SSLHostState; namespace content { diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc index 4461eb8..e5dac19 100644 --- a/content/test/test_browser_context.cc +++ b/content/test/test_browser_context.cc @@ -10,6 +10,7 @@ #include "testing/gtest/include/gtest/gtest.h" using content::DownloadManager; +using content::HostZoomMap; TestBrowserContext::TestBrowserContext() { EXPECT_TRUE(browser_context_dir_.CreateUniqueTempDir()); diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h index 3824d49..3229a29 100644 --- a/content/test/test_browser_context.h +++ b/content/test/test_browser_context.h @@ -29,7 +29,7 @@ class TestBrowserContext : public content::BrowserContext { int renderer_child_id) OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE; virtual const content::ResourceContext& GetResourceContext() OVERRIDE; - virtual HostZoomMap* GetHostZoomMap() OVERRIDE; + virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE; virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; -- cgit v1.1