~ps-jenkins/unity-chromium-extension/trusty-proposed

« back to all changes in this revision

Viewing changes to chromium-patches/stable-28.0.1500.45/2-get-domain-tld.patch

  • Committer: CI bot
  • Author(s): Justin McPherson
  • Date: 2014-02-17 23:43:23 UTC
  • mfrom: (239.2.1 remove-patches)
  • Revision ID: ps-jenkins@lists.canonical.com-20140217234323-4pw656wfrooeinde
Chromium patches are no longer maintained in this repo, remove them to avoid confusion. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
5
 
@@ -8,6 +8,7 @@
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"
13
 
@@ -83,6 +84,10 @@
14
 
   RegisterFunction<extensions::ExperimentalIdentityGetAuthTokenFunction>();
15
 
   RegisterFunction<extensions::ExperimentalIdentityLaunchWebAuthFlowFunction>();
16
 
 
17
 
+  // TLD.
18
 
+  RegisterFunction<TldGetBaseDomainFunction>();
19
 
+  RegisterFunction<TldGetPublicSuffix>();
20
 
+
21
 
   // Generated APIs
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)
28
 
@@ -445,6 +445,8 @@
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)
41
 
@@ -329,6 +329,8 @@
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)
54
 
@@ -53,6 +53,7 @@
55
 
   "scriptBadge",
56
 
   "tabs",
57
 
   "test",
58
 
+  "tld",
59
 
   "types",
60
 
   "windows"
61
 
 };
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)
66
 
@@ -31,6 +31,7 @@
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)
78
 
@@ -0,0 +1,88 @@
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.
82
 
+
83
 
+#include "chrome/browser/extensions/api/tld/tld_api.h"
84
 
+
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"
94
 
+
95
 
+namespace {
96
 
+const char kInvalidUriError[] = "Invalid or unsupported URI";
97
 
+
98
 
+bool IsValidUrl(const GURL& url) {
99
 
+  return url.is_valid() && url.IsStandard() &&
100
 
+     !url.SchemeIsFile() && !url.SchemeIsFileSystem();
101
 
+}
102
 
+}  // namespace
103
 
+
104
 
+bool TldGetBaseDomainFunction::RunImpl() {
105
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 1);
106
 
+
107
 
+  std::string uri;
108
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &uri));
109
 
+
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;
115
 
+    return false;
116
 
+  }
117
 
+
118
 
+  std::string tld =
119
 
+      net::RegistryControlledDomainService::GetDomainAndRegistry(url);
120
 
+
121
 
+  SetResult(Value::CreateStringValue(tld));
122
 
+
123
 
+  return true;
124
 
+}
125
 
+
126
 
+
127
 
+bool TldGetPublicSuffix::RunImpl() {
128
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 2);
129
 
+
130
 
+  std::string uri;
131
 
+  EXTENSION_FUNCTION_VALIDATE(!args_->GetString(0, &uri));
132
 
+
133
 
+  // We might delegate all the url validity check to GetDomainAndRegistry
134
 
+  // or GetRegistryLength but try to be more explicit about the errors in
135
 
+  // some cases.
136
 
+  const GURL url(uri);
137
 
+  if (!IsValidUrl(url)) {
138
 
+    error_ = kInvalidUriError;
139
 
+    return false;
140
 
+  }
141
 
+
142
 
+  std::string suffix;
143
 
+
144
 
+  size_t reg_len =
145
 
+      net::RegistryControlledDomainService::GetRegistryLength(url, true);
146
 
+
147
 
+  if (std::string::npos == reg_len || 0 == reg_len)
148
 
+    return false;
149
 
+
150
 
+  std::string tld =
151
 
+      net::RegistryControlledDomainService::GetDomainAndRegistry(url);
152
 
+
153
 
+  if (!tld.empty () && tld.size() > reg_len)
154
 
+    suffix = tld.substr(tld.size() - reg_len - 1, reg_len);
155
 
+
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));
162
 
+
163
 
+  return true;
164
 
+}
165
 
+
166
 
+
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)
171
 
@@ -0,0 +1,26 @@
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.
175
 
+
176
 
+#ifndef CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
177
 
+#define CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
178
 
+#pragma once
179
 
+
180
 
+#include "chrome/browser/extensions/extension_function.h"
181
 
+
182
 
+class TldGetBaseDomainFunction : public SyncExtensionFunction {
183
 
+ public:
184
 
+  virtual ~TldGetBaseDomainFunction() {}
185
 
+  virtual bool RunImpl() OVERRIDE;
186
 
+  DECLARE_EXTENSION_FUNCTION("tld.getBaseDomain",TLD_GET_BASE_DOMAIN);
187
 
+};
188
 
+
189
 
+class TldGetPublicSuffix : public SyncExtensionFunction {
190
 
+ public:
191
 
+  virtual ~TldGetPublicSuffix() {}
192
 
+  virtual bool RunImpl() OVERRIDE;
193
 
+  DECLARE_EXTENSION_FUNCTION("tld.getPublicSuffix",TLD_GET_PUBLIC_SUFFIX);
194
 
+};
195
 
+
196
 
+#endif  // CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
197
 
+
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)
202
 
@@ -0,0 +1,53 @@
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.
206
 
+
207
 
+[
208
 
+  {
209
 
+    "namespace": "tld",
210
 
+    "nodoc": "true",
211
 
+    "types": [],
212
 
+    "functions": [
213
 
+      {
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.",
217
 
+        "nodoc": "true",
218
 
+        "parameters": [
219
 
+          {
220
 
+            "name": "uri",
221
 
+            "type": "string"
222
 
+          },
223
 
+          {
224
 
+            "type": "function",
225
 
+            "name": "callback",
226
 
+            "parameters": [
227
 
+              {"name": "domain", "type": "string", "description": "The base domain name of the associated URI if any"}
228
 
+            ]
229
 
+          }
230
 
+        ]
231
 
+      }
232
 
+      ,
233
 
+      {
234
 
+        "name": "getPublicSuffix",
235
 
+        "type": "function",
236
 
+        "description": "Returns the public suffix of the domain part of a URI.",
237
 
+        "nodoc": "true",
238
 
+        "parameters": [
239
 
+          {
240
 
+            "name": "uri",
241
 
+            "type": "string"
242
 
+          },
243
 
+          {
244
 
+            "type": "function",
245
 
+            "name": "callback",
246
 
+            "parameters": [
247
 
+              {"name": "suffix", "type": "string", "description": "The public suffix of the associated URI if any"}
248
 
+            ]
249
 
+          }
250
 
+        ]
251
 
+      }
252
 
+    ]
253
 
+  }
254
 
+
255
 
+]
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)
260
 
@@ -391,6 +391,7 @@
261
 
   SYSTEMINDICATOR_DISABLE,
262
 
   SCRIPTBADGE_SETPOPUP,
263
 
   EXTENSION_ISALLOWEDFILESCHEMEACCESS,
264
 
+  EXTENSION_IS_CHROMELESS_WINDOW,
265
 
   EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW,
266
 
   FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE,
267
 
   TABS_DETECTLANGUAGE,
268
 
@@ -527,6 +528,8 @@
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.
275
 
 };
276