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

Side by Side Diff: chrome/browser/cocoa/web_drop_target.mm

Issue 373016: Bulletproof the url going into a std::string and ensure it's not going to... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/cocoa/web_drop_target.h" 5 #import "chrome/browser/cocoa/web_drop_target.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 9 #include "chrome/browser/tab_contents/tab_contents.h"
10 #import "third_party/mozilla/include/NSPasteboard+Utils.h" 10 #import "third_party/mozilla/include/NSPasteboard+Utils.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // The getURLs:andTitles: will already validate URIs so we don't need to 178 // The getURLs:andTitles: will already validate URIs so we don't need to
179 // again. However, if the URI is a local file, it won't be prefixed with 179 // again. However, if the URI is a local file, it won't be prefixed with
180 // file://, which is what GURL expects. We can detect that case because the 180 // file://, which is what GURL expects. We can detect that case because the
181 // resulting URI will have no valid scheme, and we'll assume it's a local 181 // resulting URI will have no valid scheme, and we'll assume it's a local
182 // file. The arrays returned are both of NSString's. 182 // file. The arrays returned are both of NSString's.
183 NSArray* urls = nil; 183 NSArray* urls = nil;
184 NSArray* titles = nil; 184 NSArray* titles = nil;
185 [pboard getURLs:&urls andTitles:&titles]; 185 [pboard getURLs:&urls andTitles:&titles];
186 NSString* urlString = [urls objectAtIndex:0]; 186 NSString* urlString = [urls objectAtIndex:0];
187 NSURL* url = [NSURL URLWithString:urlString]; 187 if ([urlString length]) {
188 if (![url scheme]) 188 NSURL* url = [NSURL URLWithString:urlString];
189 urlString = [[NSURL fileURLWithPath:urlString] absoluteString]; 189 if (![url scheme])
190 data->url = GURL([urlString UTF8String]); 190 urlString = [[NSURL fileURLWithPath:urlString] absoluteString];
191 data->url_title = base::SysNSStringToUTF16([titles objectAtIndex:0]); 191 // Check again just to make sure to not assign NULL into a std::string,
192 // which throws an exception.
193 const char* utf8Url = [urlString UTF8String];
194 if (utf8Url) {
195 data->url = GURL(utf8Url);
196 data->url_title = base::SysNSStringToUTF16([titles objectAtIndex:0]);
viettrungluu 2009/11/06 21:29:17 I'm 99.99% sure that |SysNSStringToUTF16()| chokes
197 }
198 }
192 } 199 }
193 200
194 // Given |data|, which should not be nil, fill it in using the contents of the 201 // Given |data|, which should not be nil, fill it in using the contents of the
195 // given pasteboard. 202 // given pasteboard.
196 - (void)populateWebDropData:(WebDropData*)data 203 - (void)populateWebDropData:(WebDropData*)data
197 fromPasteboard:(NSPasteboard*)pboard { 204 fromPasteboard:(NSPasteboard*)pboard {
198 DCHECK(data); 205 DCHECK(data);
199 DCHECK(pboard); 206 DCHECK(pboard);
200 NSArray* types = [pboard types]; 207 NSArray* types = [pboard types];
201 208
(...skipping 25 matching lines...) Expand all
227 if (exists && !isDir) 234 if (exists && !isDir)
228 data->filenames.push_back(base::SysNSStringToUTF16(filename)); 235 data->filenames.push_back(base::SysNSStringToUTF16(filename));
229 } 236 }
230 } 237 }
231 } 238 }
232 239
233 // TODO(pinkerton): Get file contents. 240 // TODO(pinkerton): Get file contents.
234 } 241 }
235 242
236 @end 243 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698