blob: 1d1ac5de4b7df65f154044eafbe183b69f2a5f3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright 2015 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 "chrome/browser/extensions/api/settings_private/settings_private_api.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/settings_private/settings_private_delegate.h"
#include "chrome/browser/extensions/api/settings_private/settings_private_delegate_factory.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/extensions/api/settings_private.h"
#include "content/public/common/page_zoom.h"
#include "extensions/browser/extension_function_registry.h"
namespace extensions {
////////////////////////////////////////////////////////////////////////////////
// SettingsPrivateSetPrefFunction
////////////////////////////////////////////////////////////////////////////////
SettingsPrivateSetPrefFunction::~SettingsPrivateSetPrefFunction() {
}
ExtensionFunction::ResponseAction SettingsPrivateSetPrefFunction::Run() {
scoped_ptr<api::settings_private::SetPref::Params> parameters =
api::settings_private::SetPref::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters.get());
SettingsPrivateDelegate* delegate =
SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
PrefsUtil::SetPrefResult result =
delegate->SetPref(parameters->name, parameters->value.get());
switch (result) {
case PrefsUtil::SUCCESS:
return RespondNow(OneArgument(new base::FundamentalValue(true)));
case PrefsUtil::PREF_NOT_MODIFIABLE:
// Not an error, but return false to indicate setting the pref failed.
return RespondNow(OneArgument(new base::FundamentalValue(false)));
case PrefsUtil::PREF_NOT_FOUND:
return RespondNow(Error("Pref not found: *", parameters->name));
case PrefsUtil::PREF_TYPE_MISMATCH:
return RespondNow(Error("Incorrect type used for value of pref *",
parameters->name));
case PrefsUtil::PREF_TYPE_UNSUPPORTED:
return RespondNow(Error("Unsupported type used for value of pref *",
parameters->name));
}
NOTREACHED();
return RespondNow(OneArgument(new base::FundamentalValue(false)));
}
////////////////////////////////////////////////////////////////////////////////
// SettingsPrivateGetAllPrefsFunction
////////////////////////////////////////////////////////////////////////////////
SettingsPrivateGetAllPrefsFunction::~SettingsPrivateGetAllPrefsFunction() {
}
ExtensionFunction::ResponseAction SettingsPrivateGetAllPrefsFunction::Run() {
SettingsPrivateDelegate* delegate =
SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
return RespondNow(OneArgument(delegate->GetAllPrefs().release()));
}
////////////////////////////////////////////////////////////////////////////////
// SettingsPrivateGetPrefFunction
////////////////////////////////////////////////////////////////////////////////
SettingsPrivateGetPrefFunction::~SettingsPrivateGetPrefFunction() {
}
ExtensionFunction::ResponseAction SettingsPrivateGetPrefFunction::Run() {
scoped_ptr<api::settings_private::GetPref::Params> parameters =
api::settings_private::GetPref::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters.get());
SettingsPrivateDelegate* delegate =
SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
scoped_ptr<base::Value> value = delegate->GetPref(parameters->name);
if (value->IsType(base::Value::TYPE_NULL))
return RespondNow(Error("Pref * does not exist", parameters->name));
else
return RespondNow(OneArgument(value.release()));
}
////////////////////////////////////////////////////////////////////////////////
// SettingsPrivateGetDefaultZoomPercentFunction
////////////////////////////////////////////////////////////////////////////////
SettingsPrivateGetDefaultZoomPercentFunction::
~SettingsPrivateGetDefaultZoomPercentFunction() {
}
ExtensionFunction::ResponseAction
SettingsPrivateGetDefaultZoomPercentFunction::Run() {
SettingsPrivateDelegate* delegate =
SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
return RespondNow(OneArgument(delegate->GetDefaultZoomPercent().release()));
}
////////////////////////////////////////////////////////////////////////////////
// SettingsPrivateSetDefaultZoomPercentFunction
////////////////////////////////////////////////////////////////////////////////
SettingsPrivateSetDefaultZoomPercentFunction::
~SettingsPrivateSetDefaultZoomPercentFunction() {
}
ExtensionFunction::ResponseAction
SettingsPrivateSetDefaultZoomPercentFunction::Run() {
scoped_ptr<api::settings_private::SetDefaultZoomPercent::Params> parameters =
api::settings_private::SetDefaultZoomPercent::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters.get());
SettingsPrivateDelegate* delegate =
SettingsPrivateDelegateFactory::GetForBrowserContext(browser_context());
delegate->SetDefaultZoomPercent(parameters->percent);
return RespondNow(OneArgument(new base::FundamentalValue(true)));
}
} // namespace extensions
|