1
Index: src/chrome/browser/extensions/extension_function_registry.cc
2
===================================================================
3
--- src/chrome/browser/extensions/extension_function_registry.cc (revision 205727)
4
+++ src/chrome/browser/extensions/extension_function_registry.cc (working copy)
6
#include "chrome/browser/extensions/api/identity/experimental_identity_api.h"
7
#include "chrome/browser/extensions/api/preference/preference_api.h"
8
#include "chrome/browser/extensions/api/runtime/runtime_api.h"
9
+#include "chrome/browser/extensions/api/tld/tld_api.h"
10
#include "chrome/browser/extensions/api/web_request/web_request_api.h"
11
#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
12
#include "chrome/browser/rlz/rlz_extension_api.h"
14
RegisterFunction<extensions::ExperimentalIdentityGetAuthTokenFunction>();
15
RegisterFunction<extensions::ExperimentalIdentityLaunchWebAuthFlowFunction>();
18
+ RegisterFunction<TldGetBaseDomainFunction>();
19
+ RegisterFunction<TldGetPublicSuffix>();
22
extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
23
#endif // defined(ENABLE_EXTENSIONS)
24
Index: src/chrome/chrome_browser_extensions.gypi
25
===================================================================
26
--- src/chrome/chrome_browser_extensions.gypi (revision 205727)
27
+++ src/chrome/chrome_browser_extensions.gypi (working copy)
29
'browser/extensions/api/tabs/windows_event_router.h',
30
'browser/extensions/api/test/test_api.cc',
31
'browser/extensions/api/test/test_api.h',
32
+ 'browser/extensions/api/tld/tld_api.cc',
33
+ 'browser/extensions/api/tld/tld_api.h',
34
'browser/extensions/api/top_sites/top_sites_api.cc',
35
'browser/extensions/api/top_sites/top_sites_api.h',
36
'browser/extensions/api/usb/usb_api.cc',
37
Index: src/chrome/common/extensions/api/extension_api.cc
38
===================================================================
39
--- src/chrome/common/extensions/api/extension_api.cc (revision 205727)
40
+++ src/chrome/common/extensions/api/extension_api.cc (working copy)
42
IDR_EXTENSION_API_JSON_TTSENGINE));
43
RegisterSchema("tts", ReadFromResource(
44
IDR_EXTENSION_API_JSON_TTS));
45
+ RegisterSchema("tld", ReadFromResource(
46
+ IDR_EXTENSION_API_JSON_TLD));
47
RegisterSchema("types", ReadFromResource(
48
IDR_EXTENSION_API_JSON_TYPES));
49
RegisterSchema("webRequestInternal", ReadFromResource(
50
Index: src/chrome/common/extensions/permissions/permission_set.cc
51
===================================================================
52
--- src/chrome/common/extensions/permissions/permission_set.cc (revision 205727)
53
+++ src/chrome/common/extensions/permissions/permission_set.cc (working copy)
62
Index: src/chrome/common/extensions_api_resources.grd
63
===================================================================
64
--- src/chrome/common/extensions_api_resources.grd (revision 205727)
65
+++ src/chrome/common/extensions_api_resources.grd (working copy)
67
<include name="IDR_EXTENSION_API_JSON_RUNTIME" file="extensions\api\runtime.json" type="BINDATA" />
68
<include name="IDR_EXTENSION_API_JSON_SCRIPTBADGE" file="extensions\api\script_badge.json" type="BINDATA" />
69
<include name="IDR_EXTENSION_API_JSON_TTS" file="extensions\api\tts.json" type="BINDATA" />
70
+ <include name="IDR_EXTENSION_API_JSON_TLD" file="extensions\api\tld.json" type="BINDATA" />
71
<include name="IDR_EXTENSION_API_JSON_TTSENGINE" file="extensions\api\tts_engine.json" type="BINDATA" />
72
<include name="IDR_EXTENSION_API_JSON_TYPES" file="extensions\api\types.json" type="BINDATA" />
73
<include name="IDR_EXTENSION_API_JSON_WEBREQUESTINTERNAL" file="extensions\api\web_request_internal.json" type="BINDATA" />
74
Index: src/chrome/browser/extensions/api/tld/tld_api.cc
75
===================================================================
76
--- src/chrome/browser/extensions/api/tld/tld_api.cc (revision 0)
77
+++ src/chrome/browser/extensions/api/tld/tld_api.cc (working copy)
79
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
80
+// Use of this source code is governed by a BSD-style license that can be
81
+// found in the LICENSE file.
83
+#include "chrome/browser/extensions/api/tld/tld_api.h"
85
+#include "base/time.h"
86
+#include "base/values.h"
87
+#include "chrome/browser/extensions/extension_service.h"
88
+#include "chrome/common/extensions/extension.h"
89
+#include "chrome/common/extensions/extension_constants.h"
90
+#include "googleurl/src/gurl.h"
91
+#include "googleurl/src/url_parse.h"
92
+#include "googleurl/src/url_util.h"
93
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
96
+const char kInvalidUriError[] = "Invalid or unsupported URI";
98
+bool IsValidUrl(const GURL& url) {
99
+ return url.is_valid() && url.IsStandard() &&
100
+ !url.SchemeIsFile() && !url.SchemeIsFileSystem();
104
+bool TldGetBaseDomainFunction::RunImpl() {
105
+ EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 1);
108
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &uri));
110
+ // We might delegate all the url validity check to GetDomainAndRegistry
111
+ // but try to be more explicit about the errors in some cases.
112
+ const GURL url(uri);
113
+ if (!IsValidUrl(url)) {
114
+ error_ = kInvalidUriError;
119
+ net::RegistryControlledDomainService::GetDomainAndRegistry(url);
121
+ SetResult(Value::CreateStringValue(tld));
127
+bool TldGetPublicSuffix::RunImpl() {
128
+ EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 2);
131
+ EXTENSION_FUNCTION_VALIDATE(!args_->GetString(0, &uri));
133
+ // We might delegate all the url validity check to GetDomainAndRegistry
134
+ // or GetRegistryLength but try to be more explicit about the errors in
136
+ const GURL url(uri);
137
+ if (!IsValidUrl(url)) {
138
+ error_ = kInvalidUriError;
142
+ std::string suffix;
145
+ net::RegistryControlledDomainService::GetRegistryLength(url, true);
147
+ if (std::string::npos == reg_len || 0 == reg_len)
151
+ net::RegistryControlledDomainService::GetDomainAndRegistry(url);
153
+ if (!tld.empty () && tld.size() > reg_len)
154
+ suffix = tld.substr(tld.size() - reg_len - 1, reg_len);
156
+ // An empty suffix is a acceptable value since the URL might be
157
+ // "properly formed" but might fall into cases such as:
158
+ // * http://co.uk/file.html
159
+ // * http://<IP address>/file.html
160
+ // which are described by GetRegistryLength to return 0 (i.e. a valid value).
161
+ SetResult(Value::CreateStringValue(suffix));
167
Index: src/chrome/browser/extensions/api/tld/tld_api.h
168
===================================================================
169
--- src/chrome/browser/extensions/api/tld/tld_api.h (revision 0)
170
+++ src/chrome/browser/extensions/api/tld/tld_api.h (working copy)
172
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
173
+// Use of this source code is governed by a BSD-style license that can be
174
+// found in the LICENSE file.
176
+#ifndef CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
177
+#define CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
180
+#include "chrome/browser/extensions/extension_function.h"
182
+class TldGetBaseDomainFunction : public SyncExtensionFunction {
184
+ virtual ~TldGetBaseDomainFunction() {}
185
+ virtual bool RunImpl() OVERRIDE;
186
+ DECLARE_EXTENSION_FUNCTION("tld.getBaseDomain",TLD_GET_BASE_DOMAIN);
189
+class TldGetPublicSuffix : public SyncExtensionFunction {
191
+ virtual ~TldGetPublicSuffix() {}
192
+ virtual bool RunImpl() OVERRIDE;
193
+ DECLARE_EXTENSION_FUNCTION("tld.getPublicSuffix",TLD_GET_PUBLIC_SUFFIX);
196
+#endif // CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
198
Index: src/chrome/common/extensions/api/tld.json
199
===================================================================
200
--- src/chrome/common/extensions/api/tld.json (revision 0)
201
+++ src/chrome/common/extensions/api/tld.json (working copy)
203
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
204
+// Use of this source code is governed by a BSD-style license that can be
205
+// found in the LICENSE file.
209
+ "namespace": "tld",
214
+ "name": "getBaseDomain",
215
+ "type": "function",
216
+ "description": "Returns the base domain of a URI; that is, the public suffix with a given number of additional domain name parts.",
224
+ "type": "function",
225
+ "name": "callback",
227
+ {"name": "domain", "type": "string", "description": "The base domain name of the associated URI if any"}
234
+ "name": "getPublicSuffix",
235
+ "type": "function",
236
+ "description": "Returns the public suffix of the domain part of a URI.",
244
+ "type": "function",
245
+ "name": "callback",
247
+ {"name": "suffix", "type": "string", "description": "The public suffix of the associated URI if any"}
256
Index: src/chrome/browser/extensions/extension_function_histogram_value.h
257
===================================================================
258
--- src/chrome/browser/extensions/extension_function_histogram_value.h (revision 205727)
259
+++ src/chrome/browser/extensions/extension_function_histogram_value.h (working copy)
261
SYSTEMINDICATOR_DISABLE,
262
SCRIPTBADGE_SETPOPUP,
263
EXTENSION_ISALLOWEDFILESCHEMEACCESS,
264
+ EXTENSION_IS_CHROMELESS_WINDOW,
265
EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW,
266
FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE,
269
SOCKET_MULTICAST_GET_JOINED_GROUPS,
270
EXPERIMENTAL_ACCESSIBILITY_SETNATIVEACCESSIBILITYENABLED,
271
INPUTMETHODPRIVATE_STARTIME,
272
+ TLD_GET_BASE_DOMAIN,
273
+ TLD_GET_PUBLIC_SUFFIX,
274
ENUM_BOUNDARY // Last entry: Add new entries above.