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

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

Issue 2627413003: NavigatorContentUtils should be a supplement of Navigator (Closed)
Patch Set: temp Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * Copyright (C) 2014, Samsung Electronics. All rights reserved. 3 * Copyright (C) 2014, 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (isSchemeWhitelisted(scheme)) 121 if (isSchemeWhitelisted(scheme))
122 return true; 122 return true;
123 123
124 exceptionState.throwSecurityError("The scheme '" + scheme + 124 exceptionState.throwSecurityError("The scheme '" + scheme +
125 "' doesn't belong to the scheme whitelist. " 125 "' doesn't belong to the scheme whitelist. "
126 "Please prefix non-whitelisted schemes " 126 "Please prefix non-whitelisted schemes "
127 "with the string 'web+'."); 127 "with the string 'web+'.");
128 return false; 128 return false;
129 } 129 }
130 130
131 NavigatorContentUtils* NavigatorContentUtils::from(LocalFrame& frame) { 131 NavigatorContentUtils* NavigatorContentUtils::from(Navigator& navigator) {
132 return static_cast<NavigatorContentUtils*>( 132 return static_cast<NavigatorContentUtils*>(
133 Supplement<LocalFrame>::from(frame, supplementName())); 133 Supplement<Navigator>::from(navigator, supplementName()));
134 } 134 }
135 135
136 NavigatorContentUtils::~NavigatorContentUtils() {} 136 NavigatorContentUtils::~NavigatorContentUtils() {}
137 137
138 NavigatorContentUtils* NavigatorContentUtils::create(
139 NavigatorContentUtilsClient* client) {
140 return new NavigatorContentUtils(client);
141 }
142
143 void NavigatorContentUtils::registerProtocolHandler( 138 void NavigatorContentUtils::registerProtocolHandler(
144 Navigator& navigator, 139 Navigator& navigator,
145 const String& scheme, 140 const String& scheme,
146 const String& url, 141 const String& url,
147 const String& title, 142 const String& title,
148 ExceptionState& exceptionState) { 143 ExceptionState& exceptionState) {
149 if (!navigator.frame()) 144 if (!navigator.frame())
150 return; 145 return;
151 146
152 Document* document = navigator.frame()->document(); 147 Document* document = navigator.frame()->document();
153 ASSERT(document); 148 ASSERT(document);
154 149
155 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 150 if (!verifyCustomHandlerURL(*document, url, exceptionState))
156 return; 151 return;
157 152
158 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 153 if (!verifyCustomHandlerScheme(scheme, exceptionState))
159 return; 154 return;
160 155
161 // Count usage; perhaps we can lock this to secure contexts. 156 // Count usage; perhaps we can lock this to secure contexts.
162 UseCounter::count(*document, 157 UseCounter::count(*document,
163 document->isSecureContext() 158 document->isSecureContext()
164 ? UseCounter::RegisterProtocolHandlerSecureOrigin 159 ? UseCounter::RegisterProtocolHandlerSecureOrigin
165 : UseCounter::RegisterProtocolHandlerInsecureOrigin); 160 : UseCounter::RegisterProtocolHandlerInsecureOrigin);
166 161
167 NavigatorContentUtils::from(*navigator.frame()) 162 NavigatorContentUtils::from(navigator)->client()->registerProtocolHandler(
168 ->client() 163 scheme, document->completeURL(url), title);
169 ->registerProtocolHandler(scheme, document->completeURL(url), title);
170 } 164 }
171 165
172 static String customHandlersStateString( 166 static String customHandlersStateString(
173 const NavigatorContentUtilsClient::CustomHandlersState state) { 167 const NavigatorContentUtilsClient::CustomHandlersState state) {
174 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); 168 DEFINE_STATIC_LOCAL(const String, newHandler, ("new"));
175 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); 169 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered"));
176 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); 170 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined"));
177 171
178 switch (state) { 172 switch (state) {
179 case NavigatorContentUtilsClient::CustomHandlersNew: 173 case NavigatorContentUtilsClient::CustomHandlersNew:
(...skipping 23 matching lines...) Expand all
203 if (document->isContextDestroyed()) 197 if (document->isContextDestroyed())
204 return declined; 198 return declined;
205 199
206 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 200 if (!verifyCustomHandlerURL(*document, url, exceptionState))
207 return declined; 201 return declined;
208 202
209 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 203 if (!verifyCustomHandlerScheme(scheme, exceptionState))
210 return declined; 204 return declined;
211 205
212 return customHandlersStateString( 206 return customHandlersStateString(
213 NavigatorContentUtils::from(*navigator.frame()) 207 NavigatorContentUtils::from(navigator)
214 ->client() 208 ->client()
215 ->isProtocolHandlerRegistered(scheme, document->completeURL(url))); 209 ->isProtocolHandlerRegistered(scheme, document->completeURL(url)));
216 } 210 }
217 211
218 void NavigatorContentUtils::unregisterProtocolHandler( 212 void NavigatorContentUtils::unregisterProtocolHandler(
219 Navigator& navigator, 213 Navigator& navigator,
220 const String& scheme, 214 const String& scheme,
221 const String& url, 215 const String& url,
222 ExceptionState& exceptionState) { 216 ExceptionState& exceptionState) {
223 if (!navigator.frame()) 217 if (!navigator.frame())
224 return; 218 return;
225 219
226 Document* document = navigator.frame()->document(); 220 Document* document = navigator.frame()->document();
227 ASSERT(document); 221 ASSERT(document);
228 222
229 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 223 if (!verifyCustomHandlerURL(*document, url, exceptionState))
230 return; 224 return;
231 225
232 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 226 if (!verifyCustomHandlerScheme(scheme, exceptionState))
233 return; 227 return;
234 228
235 NavigatorContentUtils::from(*navigator.frame()) 229 NavigatorContentUtils::from(navigator)->client()->unregisterProtocolHandler(
236 ->client() 230 scheme, document->completeURL(url));
237 ->unregisterProtocolHandler(scheme, document->completeURL(url));
238 } 231 }
239 232
240 DEFINE_TRACE(NavigatorContentUtils) { 233 DEFINE_TRACE(NavigatorContentUtils) {
241 visitor->trace(m_client); 234 visitor->trace(m_client);
242 Supplement<LocalFrame>::trace(visitor); 235 Supplement<Navigator>::trace(visitor);
243 } 236 }
244 237
245 const char* NavigatorContentUtils::supplementName() { 238 const char* NavigatorContentUtils::supplementName() {
246 return "NavigatorContentUtils"; 239 return "NavigatorContentUtils";
247 } 240 }
248 241
249 void provideNavigatorContentUtilsTo(LocalFrame& frame, 242 void NavigatorContentUtils::provideTo(Navigator& navigator,
250 NavigatorContentUtilsClient* client) { 243 NavigatorContentUtilsClient* client) {
251 NavigatorContentUtils::provideTo(frame, 244 Supplement<Navigator>::provideTo(
252 NavigatorContentUtils::supplementName(), 245 navigator, NavigatorContentUtils::supplementName(),
253 NavigatorContentUtils::create(client)); 246 new NavigatorContentUtils(navigator, client));
254 } 247 }
255 248
256 } // namespace blink 249 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698