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

Unified Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 197523002: Show Zoom Levels as content settings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
Index: chrome/browser/ui/webui/options/content_settings_handler.cc
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc
index 7850af24a5e326879a513d9f1e93b1f1466f9f6d..e98ce9fcb530dda1186aa607041b8f5c358ec927 100644
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/webui/options/content_settings_handler.h"
+#include <algorithm>
#include <map>
#include <vector>
@@ -11,6 +12,7 @@
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
@@ -39,6 +41,7 @@
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/page_zoom.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/permissions/api_permission.h"
#include "grit/generated_resources.h"
@@ -83,6 +86,7 @@ const char* kAppId = "appId";
const char* kEmbeddingOrigin = "embeddingOrigin";
const char* kPreferencesSource = "preference";
const char* kVideoSetting = "video";
+const char* kZoom = "zoom";
const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
{CONTENT_SETTINGS_TYPE_COOKIES, "cookies"},
@@ -107,6 +111,10 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
#endif
};
+// A pseudo content type. We use it to display data like a content setting even
+// though it is not a real content setting.
+const char* kZoomContentType = "zoomlevels";
+
ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) {
for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) {
if (name == kContentSettingsTypeGroupNames[i].name)
@@ -250,6 +258,17 @@ void AddExceptionsGrantedByHostedApps(
}
}
+// Sort ZoomLevelChanges by host and scheme
+// (a.com < http://a.com < https://a.com < b.com)
+bool ZoomLevelChangeLessThan(const content::HostZoomMap::ZoomLevelChange& a,
+ const content::HostZoomMap::ZoomLevelChange& b) {
+ if (a.host < b.host)
+ return true;
+ if (a.host > b.host)
+ return false;
+ return a.scheme < b.scheme;
+}
+
} // namespace
namespace options {
@@ -291,6 +310,7 @@ void ContentSettingsHandler::GetLocalizedValues(
{ "manage_handlers", IDS_HANDLERS_MANAGE },
{ "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER },
{ "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER },
+ { "exceptionZoomHeader", IDS_EXCEPTIONS_ZOOM_HEADER },
{ "embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST },
// Cookies filter.
{ "cookies_tab_label", IDS_COOKIES_TAB_LABEL },
@@ -400,6 +420,8 @@ void ContentSettingsHandler::GetLocalizedValues(
{ "midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO },
{ "midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO },
{ "midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO },
+ { "zoomlevels_header", IDS_ZOOMLEVELS_HEADER },
+ { "zoomLevelsManage", IDS_ZOOMLEVELS_MANAGE_BUTTON },
};
RegisterStrings(localized_strings, resources, arraysize(resources));
@@ -438,6 +460,8 @@ void ContentSettingsHandler::GetLocalizedValues(
IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL);
RegisterTitle(localized_strings, "midi-sysex",
IDS_MIDI_SYSEX_TAB_LABEL);
+ RegisterTitle(localized_strings, "zoomlevels",
+ IDS_ZOOMLEVELS_TAB_LABEL);
localized_strings->SetBoolean("newContentSettings",
CommandLine::ForCurrentProcess()->HasSwitch(switches::kContentSettings2));
@@ -486,6 +510,13 @@ void ContentSettingsHandler::InitializeHandler() {
&ContentSettingsHandler::UpdateProtectedContentExceptionsButton,
base::Unretained(this)));
+ content::HostZoomMap* host_zoom_map =
+ content::HostZoomMap::GetForBrowserContext(profile);
+ host_zoom_map_subscription_ =
+ host_zoom_map->AddZoomLevelChangedCallback(
+ base::Bind(&ContentSettingsHandler::OnZoomLevelChanged,
+ base::Unretained(this)));
+
flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile));
}
@@ -677,6 +708,7 @@ void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() {
type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type));
}
+ UpdateZoomLevelsExceptionsView();
}
void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() {
@@ -958,6 +990,48 @@ void ContentSettingsHandler::UpdateMIDISysExExceptionsView() {
CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
}
+void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() {
+ base::ListValue zoom_levels_exceptions;
+
+ content::HostZoomMap* host_zoom_map =
+ content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui()));
+ content::HostZoomMap::ZoomLevelVector zoom_levels(
+ host_zoom_map->GetAllZoomLevels());
+ std::sort(zoom_levels.begin(), zoom_levels.end(), ZoomLevelChangeLessThan);
+
+ for (content::HostZoomMap::ZoomLevelVector::const_iterator i =
+ zoom_levels.begin();
+ i != zoom_levels.end();
+ ++i) {
+ base::DictionaryValue* exception = new base::DictionaryValue();
+ switch (i->mode) {
+ case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST:
+ exception->SetString(kOrigin, i->host);
+ break;
+ case content::HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST:
+ exception->SetString(kOrigin, i->scheme + "://" + i->host);
+ break;
+ case content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM:
+ NOTREACHED();
+ }
+ exception->SetString(kSetting,
+ ContentSettingToString(CONTENT_SETTING_DEFAULT));
+
+ // Calculate the zoom percent from the factor. Round up to the nearest whole
+ // number.
+ int percent = static_cast<int>(
+ content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5);
+ exception->SetString(kZoom, base::IntToString(percent) + "%");
markusheintz_ 2014/03/12 16:31:06 hm ... I guess the string concatenation should wor
battre 2014/03/13 09:22:14 Done.
+ exception->SetString(kSource, kPreferencesSource);
+ // Append the new entry to the list and map.
+ zoom_levels_exceptions.Append(exception);
+ }
+
+ base::StringValue type_string(kZoomContentType);
+ web_ui()->CallJavascriptFunction("ContentSettings.setExceptions",
+ type_string, zoom_levels_exceptions);
+}
+
void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap(
ContentSettingsType type) {
base::ListValue exceptions;
@@ -1155,6 +1229,30 @@ void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap(
}
}
+void ContentSettingsHandler::RemoveZoomLevelException(
+ const base::ListValue* args, size_t arg_index) {
+ std::string mode;
+ bool rv = args->GetString(arg_index++, &mode);
+ DCHECK(rv);
+
+ std::string pattern;
+ rv = args->GetString(arg_index++, &pattern);
+ DCHECK(rv);
+
+ content::HostZoomMap* host_zoom_map =
+ content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui()));
+ double default_level = host_zoom_map->GetDefaultZoomLevel();
+
+ std::string::size_type scheme_separator_position = pattern.find("://");
markusheintz_ 2014/03/12 16:31:06 In src/content/public/common/url_constants.cc ther
battre 2014/03/13 09:22:14 Done.
battre 2014/03/13 09:22:14 Done.
+ if (scheme_separator_position == std::string::npos) {
+ host_zoom_map->SetZoomLevelForHost(pattern, default_level);
+ } else {
+ std::string scheme = pattern.substr(0, scheme_separator_position);
+ std::string host = pattern.substr(scheme_separator_position + 3);
markusheintz_ 2014/03/12 16:31:06 Please replace the '3' with the length of the cont
battre 2014/03/13 09:22:14 Done.
+ host_zoom_map->SetZoomLevelForHostAndScheme(scheme, host, default_level);
+ }
+}
+
void ContentSettingsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("setContentFilter",
base::Bind(&ContentSettingsHandler::SetContentFilter,
@@ -1282,6 +1380,11 @@ void ContentSettingsHandler::RemoveException(const base::ListValue* args) {
std::string type_string;
CHECK(args->GetString(arg_i++, &type_string));
+ if (type_string == kZoomContentType) {
markusheintz_ 2014/03/12 16:31:06 Please add a comment why this needs to go before t
battre 2014/03/13 09:22:14 Done.
+ RemoveZoomLevelException(args, arg_i);
+ return;
+ }
+
ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
switch (type) {
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
@@ -1400,6 +1503,11 @@ void ContentSettingsHandler::OnPepperFlashPrefChanged() {
media_settings_.flash_settings_initialized = false;
}
+void ContentSettingsHandler::OnZoomLevelChanged(
+ const content::HostZoomMap::ZoomLevelChange& change) {
+ UpdateZoomLevelsExceptionsView();
+}
+
void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) {
bool& show_link = link_type == DEFAULT_SETTING ?
media_settings_.show_flash_default_link :

Powered by Google App Engine
This is Rietveld 408576698