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

« back to all changes in this revision

Viewing changes to chromium-patches/stable-23.0.1271.64/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/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)
5
 
@@ -0,0 +1,88 @@
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.
9
 
+
10
 
+#include "chrome/browser/extensions/api/tld/tld_api.h"
11
 
+
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"
21
 
+
22
 
+namespace {
23
 
+const char kInvalidUriError[] = "Invalid or unsupported URI";
24
 
+
25
 
+bool IsValidUrl(const GURL& url) {
26
 
+  return url.is_valid() && url.IsStandard() &&
27
 
+     !url.SchemeIsFile() && !url.SchemeIsFileSystem();
28
 
+}
29
 
+}  // namespace
30
 
+
31
 
+bool TldGetBaseDomainFunction::RunImpl() {
32
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 1);
33
 
+
34
 
+  std::string uri;
35
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &uri));
36
 
+
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;
42
 
+    return false;
43
 
+  }
44
 
+
45
 
+  std::string tld =
46
 
+      net::RegistryControlledDomainService::GetDomainAndRegistry(url);
47
 
+
48
 
+  SetResult(Value::CreateStringValue(tld));
49
 
+
50
 
+  return true;
51
 
+}
52
 
+
53
 
+
54
 
+bool TldGetPublicSuffix::RunImpl() {
55
 
+  EXTENSION_FUNCTION_VALIDATE(args_->GetSize() == 2);
56
 
+
57
 
+  std::string uri;
58
 
+  EXTENSION_FUNCTION_VALIDATE(!args_->GetString(0, &uri));
59
 
+
60
 
+  // We might delegate all the url validity check to GetDomainAndRegistry
61
 
+  // or GetRegistryLength but try to be more explicit about the errors in
62
 
+  // some cases.
63
 
+  const GURL url(uri);
64
 
+  if (!IsValidUrl(url)) {
65
 
+    error_ = kInvalidUriError;
66
 
+    return false;
67
 
+  }
68
 
+
69
 
+  std::string suffix;
70
 
+
71
 
+  size_t reg_len =
72
 
+      net::RegistryControlledDomainService::GetRegistryLength(url, true);
73
 
+
74
 
+  if (std::string::npos == reg_len || 0 == reg_len)
75
 
+    return false;
76
 
+
77
 
+  std::string tld =
78
 
+      net::RegistryControlledDomainService::GetDomainAndRegistry(url);
79
 
+
80
 
+  if (!tld.empty () && tld.size() > reg_len)
81
 
+    suffix = tld.substr(tld.size() - reg_len - 1, reg_len);
82
 
+
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));
89
 
+
90
 
+  return true;
91
 
+}
92
 
+
93
 
+
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)
98
 
@@ -0,0 +1,26 @@
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.
102
 
+
103
 
+#ifndef CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
104
 
+#define CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
105
 
+#pragma once
106
 
+
107
 
+#include "chrome/browser/extensions/extension_function.h"
108
 
+
109
 
+class TldGetBaseDomainFunction : public SyncExtensionFunction {
110
 
+ public:
111
 
+  virtual ~TldGetBaseDomainFunction() {}
112
 
+  virtual bool RunImpl() OVERRIDE;
113
 
+  DECLARE_EXTENSION_FUNCTION_NAME("tld.getBaseDomain");
114
 
+};
115
 
+
116
 
+class TldGetPublicSuffix : public SyncExtensionFunction {
117
 
+ public:
118
 
+  virtual ~TldGetPublicSuffix() {}
119
 
+  virtual bool RunImpl() OVERRIDE;
120
 
+  DECLARE_EXTENSION_FUNCTION_NAME("tld.getPublicSuffix");
121
 
+};
122
 
+
123
 
+#endif  // CHROME_BROWSER_EXTENSIONS_API_TLD_TLD_API_H_
124
 
+
125
 
Index: src/chrome/chrome_browser_extensions.gypi
126
 
===================================================================
127
 
--- src/chrome/chrome_browser_extensions.gypi   (revision 165188)
128
 
+++ src/chrome/chrome_browser_extensions.gypi   (working copy)
129
 
@@ -279,6 +279,8 @@
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/usb/usb_api.cc',
136
 
         'browser/extensions/api/usb/usb_api.h',
137
 
         'browser/extensions/api/usb/usb_device_resource.cc',
138
 
Index: src/chrome/common/extensions_api_resources.grd
139
 
===================================================================
140
 
--- src/chrome/common/extensions_api_resources.grd      (revision 158531)
141
 
+++ src/chrome/common/extensions_api_resources.grd      (working copy)
142
 
@@ -62,6 +62,7 @@
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 165188)
153
 
+++ src/chrome/common/extensions/permissions/permission_set.cc  (working copy)
154
 
@@ -49,6 +49,7 @@
155
 
   "scriptBadge",
156
 
   "tabs",
157
 
   "test",
158
 
+  "tld",
159
 
   "types",
160
 
   "windows"
161
 
 };
162
 
Index: src/chrome/common/extensions/api/extension_api.cc
163
 
===================================================================
164
 
--- src/chrome/common/extensions/api/extension_api.cc   (revision 158531)
165
 
+++ src/chrome/common/extensions/api/extension_api.cc   (working copy)
166
 
@@ -448,6 +448,8 @@
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)
179
 
@@ -0,0 +1,53 @@
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.
183
 
+
184
 
+[
185
 
+  {
186
 
+    "namespace": "tld",
187
 
+    "nodoc": "true",
188
 
+    "types": [],
189
 
+    "functions": [
190
 
+      {
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.",
194
 
+        "nodoc": "true",
195
 
+        "parameters": [
196
 
+          {
197
 
+            "name": "uri",
198
 
+            "type": "string"
199
 
+          },
200
 
+          {
201
 
+            "type": "function",
202
 
+            "name": "callback",
203
 
+            "parameters": [
204
 
+              {"name": "domain", "type": "string", "description": "The base domain name of the associated URI if any"}
205
 
+            ]
206
 
+          }
207
 
+        ]
208
 
+      }
209
 
+      ,
210
 
+      {
211
 
+        "name": "getPublicSuffix",
212
 
+        "type": "function",
213
 
+        "description": "Returns the public suffix of the domain part of a URI.",
214
 
+        "nodoc": "true",
215
 
+        "parameters": [
216
 
+          {
217
 
+            "name": "uri",
218
 
+            "type": "string"
219
 
+          },
220
 
+          {
221
 
+            "type": "function",
222
 
+            "name": "callback",
223
 
+            "parameters": [
224
 
+              {"name": "suffix", "type": "string", "description": "The public suffix of the associated URI if any"}
225
 
+            ]
226
 
+          }
227
 
+        ]
228
 
+      }
229
 
+    ]
230
 
+  }
231
 
+
232
 
+]
233
 
Index: src/chrome/browser/extensions/extension_function_registry.cc
234
 
===================================================================
235
 
--- src/chrome/browser/extensions/extension_function_registry.cc        (revision 158531)
236
 
+++ src/chrome/browser/extensions/extension_function_registry.cc        (working copy)
237
 
@@ -35,6 +35,7 @@
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/web_navigation/web_navigation_api.h"
243
 
 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
244
 
 #include "chrome/browser/extensions/api/web_socket_proxy_private/web_socket_proxy_private_api.h"
245
 
@@ -171,6 +172,10 @@
246
 
   RegisterFunction<MoveBookmarkFunction>();
247
 
   RegisterFunction<UpdateBookmarkFunction>();
248
 
 
249
 
+  // TLD.
250
 
+  RegisterFunction<TldGetBaseDomainFunction>();
251
 
+  RegisterFunction<TldGetPublicSuffix>();
252
 
+
253
 
   // Infobars.
254
 
   RegisterFunction<ShowInfoBarFunction>();
255