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

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

Issue 171333003: Pass implementation object to supplemental classes by reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 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 | Annotate | Revision Log
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 exceptionState.throwSecurityError("The scheme '" + scheme + "' is le ss than five characters long."); 112 exceptionState.throwSecurityError("The scheme '" + scheme + "' is le ss than five characters long.");
113 return false; 113 return false;
114 } 114 }
115 115
116 if (isProtocolWhitelisted(scheme)) 116 if (isProtocolWhitelisted(scheme))
117 return true; 117 return true;
118 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the protocol whitelist. Please prefix non-whitelisted schemes with the stri ng 'web+'."); 118 exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belon g to the protocol whitelist. Please prefix non-whitelisted schemes with the stri ng 'web+'.");
119 return false; 119 return false;
120 } 120 }
121 121
122 NavigatorContentUtils* NavigatorContentUtils::from(Page* page) 122 NavigatorContentUtils* NavigatorContentUtils::from(Page& page)
123 { 123 {
124 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga torContentUtils>::from(page, NavigatorContentUtils::supplementName())); 124 return static_cast<NavigatorContentUtils*>(RefCountedSupplement<Page, Naviga torContentUtils>::from(page, NavigatorContentUtils::supplementName()));
125 } 125 }
126 126
127 NavigatorContentUtils::~NavigatorContentUtils() 127 NavigatorContentUtils::~NavigatorContentUtils()
128 { 128 {
129 } 129 }
130 130
131 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent UtilsClient* client) 131 PassRefPtr<NavigatorContentUtils> NavigatorContentUtils::create(NavigatorContent UtilsClient* client)
132 { 132 {
133 return adoptRef(new NavigatorContentUtils(client)); 133 return adoptRef(new NavigatorContentUtils(client));
134 } 134 }
135 135
136 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)
137 { 137 {
138 if (!navigator->frame()) 138 if (!navigator.frame())
139 return; 139 return;
140 140
141 Document* document = navigator->frame()->document(); 141 Document* document = navigator.frame()->document();
142 if (!document) 142 if (!document)
143 return; 143 return;
144 144
145 KURL baseURL = document->baseURL(); 145 KURL baseURL = document->baseURL();
146 146
147 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 147 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
148 return; 148 return;
149 149
150 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState)) 150 if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptio nState))
151 return; 151 return;
152 152
153 NavigatorContentUtils::from(navigator->frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, KURL(ParsedURLString, url), title); 153 ASSERT(navigator.frame()->page());
154 NavigatorContentUtils::from(*navigator.frame()->page())->client()->registerP rotocolHandler(scheme, baseURL, KURL(ParsedURLString, url), title);
154 } 155 }
155 156
156 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state) 157 static String customHandlersStateString(const NavigatorContentUtilsClient::Custo mHandlersState state)
157 { 158 {
158 DEFINE_STATIC_LOCAL(const String, newHandler, ("new")); 159 DEFINE_STATIC_LOCAL(const String, newHandler, ("new"));
159 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered")); 160 DEFINE_STATIC_LOCAL(const String, registeredHandler, ("registered"));
160 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined")); 161 DEFINE_STATIC_LOCAL(const String, declinedHandler, ("declined"));
161 162
162 switch (state) { 163 switch (state) {
163 case NavigatorContentUtilsClient::CustomHandlersNew: 164 case NavigatorContentUtilsClient::CustomHandlersNew:
164 return newHandler; 165 return newHandler;
165 case NavigatorContentUtilsClient::CustomHandlersRegistered: 166 case NavigatorContentUtilsClient::CustomHandlersRegistered:
166 return registeredHandler; 167 return registeredHandler;
167 case NavigatorContentUtilsClient::CustomHandlersDeclined: 168 case NavigatorContentUtilsClient::CustomHandlersDeclined:
168 return declinedHandler; 169 return declinedHandler;
169 } 170 }
170 171
171 ASSERT_NOT_REACHED(); 172 ASSERT_NOT_REACHED();
172 return String(); 173 return String();
173 } 174 }
174 175
175 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator* navigator, const String& scheme, const String& url, ExceptionState& exceptionState) 176 String NavigatorContentUtils::isProtocolHandlerRegistered(Navigator& navigator, const String& scheme, const String& url, ExceptionState& exceptionState)
176 { 177 {
177 DEFINE_STATIC_LOCAL(const String, declined, ("declined")); 178 DEFINE_STATIC_LOCAL(const String, declined, ("declined"));
178 179
179 if (!navigator->frame()) 180 if (!navigator.frame())
180 return declined; 181 return declined;
181 182
182 Document* document = navigator->frame()->document(); 183 Document* document = navigator.frame()->document();
183 KURL baseURL = document->baseURL(); 184 KURL baseURL = document->baseURL();
184 185
185 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 186 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
186 return declined; 187 return declined;
187 188
188 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState)) 189 if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exce ptionState))
189 return declined; 190 return declined;
190 191
191 return customHandlersStateString(NavigatorContentUtils::from(navigator->fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, KURL(Parsed URLString, url))); 192 ASSERT(navigator.frame()->page());
193 return customHandlersStateString(NavigatorContentUtils::from(*navigator.fram e()->page())->client()->isProtocolHandlerRegistered(scheme, baseURL, KURL(Parsed URLString, url)));
192 } 194 }
193 195
194 void NavigatorContentUtils::unregisterProtocolHandler(Navigator* navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState) 196 void NavigatorContentUtils::unregisterProtocolHandler(Navigator& navigator, cons t String& scheme, const String& url, ExceptionState& exceptionState)
195 { 197 {
196 if (!navigator->frame()) 198 if (!navigator.frame())
197 return; 199 return;
198 200
199 Document* document = navigator->frame()->document(); 201 Document* document = navigator.frame()->document();
200 KURL baseURL = document->baseURL(); 202 KURL baseURL = document->baseURL();
201 203
202 if (!verifyCustomHandlerURL(baseURL, url, exceptionState)) 204 if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
203 return; 205 return;
204 206
205 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState)) 207 if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", except ionState))
206 return; 208 return;
207 209
208 NavigatorContentUtils::from(navigator->frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, KURL(ParsedURLString, url)); 210 ASSERT(navigator.frame()->page());
211 NavigatorContentUtils::from(*navigator.frame()->page())->client()->unregiste rProtocolHandler(scheme, baseURL, KURL(ParsedURLString, url));
209 } 212 }
210 213
211 const char* NavigatorContentUtils::supplementName() 214 const char* NavigatorContentUtils::supplementName()
212 { 215 {
213 return "NavigatorContentUtils"; 216 return "NavigatorContentUtils";
214 } 217 }
215 218
216 void provideNavigatorContentUtilsTo(Page* page, NavigatorContentUtilsClient* cli ent) 219 void provideNavigatorContentUtilsTo(Page& page, NavigatorContentUtilsClient* cli ent)
217 { 220 {
218 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator ContentUtils::supplementName(), NavigatorContentUtils::create(client)); 221 RefCountedSupplement<Page, NavigatorContentUtils>::provideTo(page, Navigator ContentUtils::supplementName(), NavigatorContentUtils::create(client));
219 } 222 }
220 223
221 } // namespace WebCore 224 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698