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

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

Issue 1226113002: Move protocol registration from WebViewClient to WebFrameClient, part 2/3. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "modules/navigatorcontentutils/NavigatorContentUtils.h" 28 #include "modules/navigatorcontentutils/NavigatorContentUtils.h"
29 29
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
33 #include "core/frame/LocalFrame.h" 33 #include "core/frame/LocalFrame.h"
34 #include "core/frame/Navigator.h" 34 #include "core/frame/Navigator.h"
35 #include "core/page/Page.h"
36 #include "wtf/HashSet.h" 35 #include "wtf/HashSet.h"
37 #include "wtf/text/StringBuilder.h" 36 #include "wtf/text/StringBuilder.h"
38 37
39 namespace blink { 38 namespace blink {
40 39
41 static HashSet<String>* schemeWhitelist; 40 static HashSet<String>* schemeWhitelist;
42 41
43 static void initCustomSchemeHandlerWhitelist() 42 static void initCustomSchemeHandlerWhitelist()
44 { 43 {
45 schemeWhitelist = new HashSet<String>; 44 schemeWhitelist = new HashSet<String>;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return false; 130 return false;
132 } 131 }
133 132
134 if (isSchemeWhitelisted(scheme)) 133 if (isSchemeWhitelisted(scheme))
135 return true; 134 return true;
136 135
137 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the scheme whitelist. Please prefix non-whitelisted schemes with the string 'web+'."); 136 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the scheme whitelist. Please prefix non-whitelisted schemes with the string 'web+'.");
138 return false; 137 return false;
139 } 138 }
140 139
141 NavigatorContentUtils* NavigatorContentUtils::from(Page& page) 140 NavigatorContentUtils* NavigatorContentUtils::from(LocalFrame& frame)
142 { 141 {
143 return static_cast<NavigatorContentUtils*>(WillBeHeapSupplement<Page>::from( page, supplementName())); 142 return static_cast<NavigatorContentUtils*>(WillBeHeapSupplement<LocalFrame>: :from(frame, supplementName()));
144 } 143 }
145 144
146 NavigatorContentUtils::~NavigatorContentUtils() 145 NavigatorContentUtils::~NavigatorContentUtils()
147 { 146 {
148 } 147 }
149 148
150 PassOwnPtrWillBeRawPtr<NavigatorContentUtils> NavigatorContentUtils::create(Pass OwnPtr<NavigatorContentUtilsClient> client) 149 PassOwnPtrWillBeRawPtr<NavigatorContentUtils> NavigatorContentUtils::create(Pass OwnPtr<NavigatorContentUtilsClient> client)
151 { 150 {
152 return adoptPtrWillBeNoop(new NavigatorContentUtils(client)); 151 return adoptPtrWillBeNoop(new NavigatorContentUtils(client));
153 } 152 }
154 153
155 void NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState) 154 void NavigatorContentUtils::registerProtocolHandler(Navigator& navigator, const String& scheme, const String& url, const String& title, ExceptionState& exceptio nState)
156 { 155 {
157 if (!navigator.frame()) 156 if (!navigator.frame())
158 return; 157 return;
159 158
160 Document* document = navigator.frame()->document(); 159 Document* document = navigator.frame()->document();
161 ASSERT(document); 160 ASSERT(document);
162 161
163 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 162 if (!verifyCustomHandlerURL(*document, url, exceptionState))
164 return; 163 return;
165 164
166 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 165 if (!verifyCustomHandlerScheme(scheme, exceptionState))
167 return; 166 return;
168 167
169 ASSERT(navigator.frame()->page()); 168 NavigatorContentUtils::from(*navigator.frame())->client()->registerProtocolH andler(scheme, document->completeURL(url), title);
170 NavigatorContentUtils::from(*navigator.frame()->page())->client()->registerP rotocolHandler(scheme, document->completeURL(url), title);
171 } 169 }
172 170
173 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state) 171 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state)
174 { 172 {
175 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); 173 DEFINE_STATIC_LOCAL(const String, newHandler, ("new"));
176 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); 174 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered"));
177 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); 175 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined"));
178 176
179 switch (state) { 177 switch (state) {
180 case NavigatorContentUtilsClient::CustomHandlersNew: 178 case NavigatorContentUtilsClient::CustomHandlersNew:
(...skipping 19 matching lines...) Expand all
200 ASSERT(document); 198 ASSERT(document);
201 if (document->activeDOMObjectsAreStopped()) 199 if (document->activeDOMObjectsAreStopped())
202 return declined; 200 return declined;
203 201
204 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 202 if (!verifyCustomHandlerURL(*document, url, exceptionState))
205 return declined; 203 return declined;
206 204
207 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 205 if (!verifyCustomHandlerScheme(scheme, exceptionState))
208 return declined; 206 return declined;
209 207
210 ASSERT(navigator.frame()->page()); 208 return customHandlersStateString(NavigatorContentUtils::from(*navigator.fram e())->client()->isProtocolHandlerRegistered(scheme, document->completeURL(url))) ;
211 return customHandlersStateString(NavigatorContentUtils::from(*navigator.fram e()->page())->client()->isProtocolHandlerRegistered(scheme, document->completeUR L(url)));
212 } 209 }
213 210
214 void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState) 211 void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState)
215 { 212 {
216 if (!navigator.frame()) 213 if (!navigator.frame())
217 return; 214 return;
218 215
219 Document* document = navigator.frame()->document(); 216 Document* document = navigator.frame()->document();
220 ASSERT(document); 217 ASSERT(document);
221 218
222 if (!verifyCustomHandlerURL(*document, url, exceptionState)) 219 if (!verifyCustomHandlerURL(*document, url, exceptionState))
223 return; 220 return;
224 221
225 if (!verifyCustomHandlerScheme(scheme, exceptionState)) 222 if (!verifyCustomHandlerScheme(scheme, exceptionState))
226 return; 223 return;
227 224
228 ASSERT(navigator.frame()->page()); 225 NavigatorContentUtils::from(*navigator.frame())->client()->unregisterProtoco lHandler(scheme, document->completeURL(url));
229 NavigatorContentUtils::from(*navigator.frame()->page())->client()->unregiste rProtocolHandler(scheme, document->completeURL(url));
230 } 226 }
231 227
232 const char* NavigatorContentUtils::supplementName() 228 const char* NavigatorContentUtils::supplementName()
233 { 229 {
234 return "NavigatorContentUtils"; 230 return "NavigatorContentUtils";
235 } 231 }
236 232
237 void provideNavigatorContentUtilsTo(Page& page, PassOwnPtr<NavigatorContentUtils Client> client) 233 void provideNavigatorContentUtilsTo(LocalFrame& frame, PassOwnPtr<NavigatorConte ntUtilsClient> client)
238 { 234 {
239 NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName (), NavigatorContentUtils::create(client)); 235 NavigatorContentUtils::provideTo(frame, NavigatorContentUtils::supplementNam e(), NavigatorContentUtils::create(client));
240 } 236 }
241 237
242 } // namespace blink 238 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698