Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1362)

Unified Diff: content/browser/host_zoom_map.cc

Issue 9296041: Create Content API around HostZoomMap. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/host_zoom_map.h ('k') | content/browser/host_zoom_map_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/host_zoom_map.cc
===================================================================
--- content/browser/host_zoom_map.cc (revision 119530)
+++ content/browser/host_zoom_map.cc (working copy)
@@ -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 <cmath>
-
-#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<HostZoomMap>(this),
- content::Details<const std::string>(&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<HostZoomMap>(this),
- content::Details<const std::string>(&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<RenderViewHost>(source)->routing_id();
- int render_process_id =
- content::Source<RenderViewHost>(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() {
-}
« no previous file with comments | « content/browser/host_zoom_map.h ('k') | content/browser/host_zoom_map_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698