1
Index: src/chrome/browser/extensions/api/tld/tld_api.cc
2
===================================================================
3
--- src/chrome/browser/extensions/api/tld/tld_api.cc (revision 0)
4
+++ src/chrome/browser/extensions/api/tld/tld_api.cc (revision 0)
6
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
7
+// Use of this source code is governed by a BSD-style license that can be
8
+// found in the LICENSE file.
10
+#include "chrome/browser/extensions/api/tld/tld_api.h"
12
+#include "base/time.h"
13
+#include "base/values.h"
14
+#include "chrome/browser/extensions/extension_service.h"
15
+#include "chrome/common/extensions/extension.h"
16
+#include "chrome/common/extensions/extension_constants.h"
17
+#include "googleurl/src/gurl.h"
18
+#include "googleurl/src/url_parse.h"
19
+#include "googleurl/src/url_util.h"
20
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
23
+const char kInvalidUriError[] = "Invalid or unsupported URI";
25
+bool IsValidUrl(const GURL& url) {
26
+ return url.is_valid() && url.IsStandard() &&
27
+ !url.SchemeIsFile() && !url.SchemeIsFileSystem();
31
+bool TldGetBaseDomainFunction::RunImpl() {
32
+ EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 1);
35
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &uri));
37
+ // We might delegate all the url validity check to GetDomainAndRegistry
38
+ // but try to be more explicit about the errors in some cases.
39
+ const GURL url(uri);
40
+ if (!IsValidUrl(url)) {
41
+ error_ = kInvalidUriError;
46
+ net::RegistryControlledDomainService::GetDomainAndRegistry(url);
48
+ SetResult(Value::CreateStringValue(tld));
54
+bool TldGetPublicSuffix::RunImpl() {
55
+ EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 2);
58
+ EXTENSION_FUNCTION_VALIDATE(!args_->GetString(0, &uri));
60
+ // We might delegate all the url validity check to GetDomainAndRegistry
61
+ // or GetRegistryLength but try to be more explicit about the errors in
63
+ const GURL url(uri);
64
+ if (!IsValidUrl(url)) {
65
+ error_ = kInvalidUriError;
72
+ net::RegistryControlledDomainService::GetRegistryLength(url, true);
74
+ if (std::string::npos == reg_len || 0 == reg_len)
78
+ net::RegistryControlledDomainService::GetDomainAndRegistry(url);
80
+ if (!tld.empty () && tld.size() > reg_len)
81
+ suffix = tld.substr(tld.size() - reg_len - 1, reg_len);
83
+ // An empty suffix is a acceptable value since the URL might be
84
+ // "properly formed" but might fall into cases such as:
85
+ // * http://co.uk/file.html
86
+ // * http://<IP address>/file.html
87
+ // which are described by GetRegistryLength to return 0 (i.e. a valid value).
88
+ SetResult(Value::CreateStringValue(suffix));
94
Index: src/chrome/browser/extensions/api/tld/tld_api.h
95
===================================================================
96
--- src/chrome/browser/extensions/api/tld/tld_api.h (revision 0)
97
+++ src/chrome/browser/extensions/api/tld/tld_api.h (revision 0)
99
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
100
+// Use of this source code is governed by a BSD-style license that can be
101
+// found in the LICENSE file.
103
+#ifndef CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
104
+#define CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
107
+#include "chrome/browser/extensions/extension_function.h"
109
+class TldGetBaseDomainFunction : public SyncExtensionFunction {
111
+ virtual ~TldGetBaseDomainFunction() {}
112
+ virtual bool RunImpl() OVERRIDE;
113
+ DECLARE_EXTENSION_FUNCTION_NAME("tld.getBaseDomain");
116
+class TldGetPublicSuffix : public SyncExtensionFunction {
118
+ virtual ~TldGetPublicSuffix() {}
119
+ virtual bool RunImpl() OVERRIDE;
120
+ DECLARE_EXTENSION_FUNCTION_NAME("tld.getPublicSuffix");
123
+#endif // CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
125
Index: src/chrome/chrome_browser_extensions.gypi
126
===================================================================
127
--- src/chrome/chrome_browser_extensions.gypi (revision 179520)
128
+++ src/chrome/chrome_browser_extensions.gypi (working copy)
130
'browser/extensions/api/terminal/terminal_private_api.h',
131
'browser/extensions/api/test/test_api.cc',
132
'browser/extensions/api/test/test_api.h',
133
+ 'browser/extensions/api/tld/tld_api.cc',
134
+ 'browser/extensions/api/tld/tld_api.h',
135
'browser/extensions/api/top_sites/top_sites_api.cc',
136
'browser/extensions/api/top_sites/top_sites_api.h',
137
'browser/extensions/api/usb/usb_api.cc',
138
Index: src/chrome/common/extensions_api_resources.grd
139
===================================================================
140
--- src/chrome/common/extensions_api_resources.grd (revision 179520)
141
+++ src/chrome/common/extensions_api_resources.grd (working copy)
143
<include name="IDR_EXTENSION_API_JSON_TABS" file="extensions\api\tabs.json" type="BINDATA" />
144
<include name="IDR_EXTENSION_API_JSON_TERMINALPRIVATE" file="extensions\api\terminal_private.json" type="BINDATA" />
145
<include name="IDR_EXTENSION_API_JSON_TEST" file="extensions\api\test.json" type="BINDATA" />
146
+ <include name="IDR_EXTENSION_API_JSON_TLD" file="extensions\api\tld.json" type="BINDATA" />
147
<include name="IDR_EXTENSION_API_JSON_TOPSITES" file="extensions\api\top_sites.json" type="BINDATA" />
148
<include name="IDR_EXTENSION_API_JSON_TTS" file="extensions\api\tts.json" type="BINDATA" />
149
<include name="IDR_EXTENSION_API_JSON_TTSENGINE" file="extensions\api\tts_engine.json" type="BINDATA" />
150
Index: src/chrome/common/extensions/permissions/permission_set.cc
151
===================================================================
152
--- src/chrome/common/extensions/permissions/permission_set.cc (revision 179520)
153
+++ src/chrome/common/extensions/permissions/permission_set.cc (working copy)
162
Index: src/chrome/common/extensions/api/extension_api.cc
163
===================================================================
164
--- src/chrome/common/extensions/api/extension_api.cc (revision 179520)
165
+++ src/chrome/common/extensions/api/extension_api.cc (working copy)
167
IDR_EXTENSION_API_JSON_TERMINALPRIVATE));
168
RegisterSchema("test", ReadFromResource(
169
IDR_EXTENSION_API_JSON_TEST));
170
+ RegisterSchema("tld", ReadFromResource(
171
+ IDR_EXTENSION_API_JSON_TLD));
172
RegisterSchema("topSites", ReadFromResource(
173
IDR_EXTENSION_API_JSON_TOPSITES));
174
RegisterSchema("ttsEngine", ReadFromResource(
175
Index: src/chrome/common/extensions/api/tld.json
176
===================================================================
177
--- src/chrome/common/extensions/api/tld.json (revision 0)
178
+++ src/chrome/common/extensions/api/tld.json (revision 0)
180
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
181
+// Use of this source code is governed by a BSD-style license that can be
182
+// found in the LICENSE file.
186
+ "namespace": "tld",
191
+ "name": "getBaseDomain",
192
+ "type": "function",
193
+ "description": "Returns the base domain of a URI; that is, the public suffix with a given number of additional domain name parts.",
201
+ "type": "function",
202
+ "name": "callback",
204
+ {"name": "domain", "type": "string", "description": "The base domain name of the associated URI if any"}
211
+ "name": "getPublicSuffix",
212
+ "type": "function",
213
+ "description": "Returns the public suffix of the domain part of a URI.",
221
+ "type": "function",
222
+ "name": "callback",
224
+ {"name": "suffix", "type": "string", "description": "The public suffix of the associated URI if any"}
233
Index: src/chrome/browser/extensions/extension_function_registry.cc
234
===================================================================
235
--- src/chrome/browser/extensions/extension_function_registry.cc (revision 179520)
236
+++ src/chrome/browser/extensions/extension_function_registry.cc (working copy)
238
#include "chrome/browser/extensions/api/tabs/execute_code_in_tab_function.h"
239
#include "chrome/browser/extensions/api/tabs/tabs.h"
240
#include "chrome/browser/extensions/api/test/test_api.h"
241
+#include "chrome/browser/extensions/api/tld/tld_api.h"
242
#include "chrome/browser/extensions/api/top_sites/top_sites_api.h"
243
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
244
#include "chrome/browser/extensions/api/web_request/web_request_api.h"
246
RegisterFunction<ExtensionTtsSpeakFunction>();
247
RegisterFunction<ExtensionTtsStopSpeakingFunction>();
250
+ RegisterFunction<TldGetBaseDomainFunction>();
251
+ RegisterFunction<TldGetPublicSuffix>();
254
RegisterFunction<GetAllCommandsFunction>();