Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: Source/modules/navigatorcontentutils/NavigatorContentUtils.cpp

Issue 133273030: Change a WebString type of url parameter with WebURL (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/modules/navigatorcontentutils/NavigatorContentUtilsClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * Copyright (C) 2012, Samsung Electronics. All rights reserved. 3 * Copyright (C) 2012, Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 "tel", 60 "tel",
61 "urn", 61 "urn",
62 "webcal", 62 "webcal",
63 "wtai", 63 "wtai",
64 "xmpp", 64 "xmpp",
65 }; 65 };
66 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i) 66 for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i)
67 protocolWhitelist->add(protocols[i]); 67 protocolWhitelist->add(protocols[i]);
68 } 68 }
69 69
70 static bool verifyCustomHandlerURL(const String& baseURL, const String& url, Exc eptionState& exceptionState) 70 static bool verifyCustomHandlerURL(const KURL& baseURL, const String& url, Excep tionState& exceptionState)
71 { 71 {
72 // The specification requires that it is a SyntaxError if the "%s" token is 72 // The specification requires that it is a SyntaxError if the "%s" token is
73 // not present. 73 // not present.
74 static const char token[] = "%s"; 74 static const char token[] = "%s";
75 int index = url.find(token); 75 int index = url.find(token);
76 if (-1 == index) { 76 if (-1 == index) {
77 exceptionState.throwDOMException(SyntaxError, "The url provided ('" + ur l + "') does not contain '%s'."); 77 exceptionState.throwDOMException(SyntaxError, "The url provided ('" + ur l + "') does not contain '%s'.");
78 return false; 78 return false;
79 } 79 }
80 80
81 // It is also a SyntaxError if the custom handler URL, as created by removin g 81 // It is also a SyntaxError if the custom handler URL, as created by removin g
82 // the "%s" token and prepending the base url, does not resolve. 82 // the "%s" token and prepending the base url, does not resolve.
83 String newURL = url; 83 String newURL = url;
84 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1); 84 newURL.remove(index, WTF_ARRAY_LENGTH(token) - 1);
85 85
86 KURL base(ParsedURLString, baseURL); 86 KURL kurl(baseURL, newURL);
87 KURL kurl(base, newURL);
88 87
89 if (kurl.isEmpty() || !kurl.isValid()) { 88 if (kurl.isEmpty() || !kurl.isValid()) {
90 exceptionState.throwDOMException(SyntaxError, "The custom handler URL cr eated by removing '%s' and prepending '" + baseURL + "' is invalid."); 89 exceptionState.throwDOMException(SyntaxError, "The custom handler URL cr eated by removing '%s' and prepending '" + baseURL.string() + "' is invalid.");
91 return false; 90 return false;
92 } 91 }
93 92
94 return true; 93 return true;
95 } 94 }
96 95
97 static bool isProtocolWhitelisted(const String& scheme) 96 static bool isProtocolWhitelisted(const String& scheme)
98 { 97 {
99 if (!protocolWhitelist) 98 if (!protocolWhitelist)
100 initProtocolHandlerWhitelist(); 99 initProtocolHandlerWhitelist();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 135
137 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState) 136 void NavigatorContentUtils::registerProtocolHandler(Navigator* navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState)
138 { 137 {
139 if (!navigator->frame()) 138 if (!navigator->frame())
140 return; 139 return;
141 140
142 Document* document = navigator->frame()->document(); 141 Document* document = navigator->frame()->document();
143 if (!document) 142 if (!document)
144 return; 143 return;
145 144
146 String baseURL = document->baseURL().baseAsString(); 145 KURL baseURL = document->baseURL();
147 146
148 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 147 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
149 return; 148 return;
150 149
151 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState)) 150 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState))
152 return; 151 return;
153 152
154 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, url, title); 153 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, KURL(ParsedURLString, url), title);
155 } 154 }
156 155
157 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state) 156 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state)
158 { 157 {
159 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); 158 DEFINE_STATIC_LOCAL(const String, newHandler, ("new"));
160 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); 159 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered"));
161 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); 160 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined"));
162 161
163 switch (state) { 162 switch (state) {
164 case NavigatorContentUtilsClient::CustomHandlersNew: 163 case NavigatorContentUtilsClient::CustomHandlersNew:
165 return newHandler; 164 return newHandler;
166 case NavigatorContentUtilsClient::CustomHandlersRegistered: 165 case NavigatorContentUtilsClient::CustomHandlersRegistered:
167 return registeredHandler; 166 return registeredHandler;
168 case NavigatorContentUtilsClient::CustomHandlersDeclined: 167 case NavigatorContentUtilsClient::CustomHandlersDeclined:
169 return declinedHandler; 168 return declinedHandler;
170 } 169 }
171 170
172 ASSERT_NOT_REACHED(); 171 ASSERT_NOT_REACHED();
173 return String(); 172 return String();
174 } 173 }
175 174
176 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator, const String& scheme, const String& url, ExceptionState& exceptionState) 175 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator, const String& scheme, const String& url, ExceptionState& exceptionState)
177 { 176 {
178 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); 177 DEFINE_STATIC_LOCAL(const String, declined, ("declined"));
179 178
180 if (!navigator->frame()) 179 if (!navigator->frame())
181 return declined; 180 return declined;
182 181
183 Document* document = navigator->frame()->document(); 182 Document* document = navigator->frame()->document();
184 String baseURL = document->baseURL().baseAsString(); 183 KURL baseURL = document->baseURL();
185 184
186 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 185 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
187 return declined; 186 return declined;
188 187
189 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState)) 188 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState))
190 return declined; 189 return declined;
191 190
192 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, url)); 191 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, KURL(Parsed URLString, url)));
193 } 192 }
194 193
195 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState) 194 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState)
196 { 195 {
197 if (!navigator->frame()) 196 if (!navigator->frame())
198 return; 197 return;
199 198
200 Document* document = navigator->frame()->document(); 199 Document* document = navigator->frame()->document();
201 String baseURL = document->baseURL().baseAsString(); 200 KURL baseURL = document->baseURL();
202 201
203 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 202 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
204 return; 203 return;
205 204
206 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState)) 205 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState))
207 return; 206 return;
208 207
209 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, url); 208 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, KURL(ParsedURLString, url));
210 } 209 }
211 210
212 const char* NavigatorContentUtils::supplementName() 211 const char* NavigatorContentUtils::supplementName()
213 { 212 {
214 return "NavigatorContentUtils"; 213 return "NavigatorContentUtils";
215 } 214 }
216 215
217 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli ent) 216 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli ent)
218 { 217 {
219 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator ContentUtils::supplementName(), NavigatorContentUtils::create(client)); 218 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator ContentUtils::supplementName(), NavigatorContentUtils::create(client));
220 } 219 }
221 220
222 } // namespace WebCore 221 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/modules/navigatorcontentutils/NavigatorContentUtilsClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698