OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 // (URLDropTargetController protocol) | 1021 // (URLDropTargetController protocol) |
1022 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { | 1022 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { |
1023 // TODO(viettrungluu): This code is more or less copied from the code in | 1023 // TODO(viettrungluu): This code is more or less copied from the code in |
1024 // |TabStripController|. I'll refactor this soon to make it common and expand | 1024 // |TabStripController|. I'll refactor this soon to make it common and expand |
1025 // its capabilities (e.g., allow text DnD). | 1025 // its capabilities (e.g., allow text DnD). |
1026 if ([urls count] < 1) { | 1026 if ([urls count] < 1) { |
1027 NOTREACHED(); | 1027 NOTREACHED(); |
1028 return; | 1028 return; |
1029 } | 1029 } |
1030 | 1030 |
1031 // TODO(viettrungluu): dropping multiple URLs? | 1031 for (id urlString in urls) { |
1032 if ([urls count] > 1) | 1032 // Refactor this code. |
1033 NOTIMPLEMENTED(); | 1033 // https://crbug.com/665261. |
| 1034 GURL url = url_formatter::FixupURL(base::SysNSStringToUTF8(urlString), |
| 1035 std::string()); |
1034 | 1036 |
1035 // Get the first URL and fix it up. | 1037 // If the URL isn't valid, don't bother. |
1036 GURL url(url_formatter::FixupURL( | 1038 if (!url.is_valid()) |
1037 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string())); | 1039 continue; |
1038 | 1040 |
1039 // Security: Sanitize text to prevent self-XSS. | 1041 // Security: Sanitize text to prevent self-XSS. |
1040 if (url.SchemeIs(url::kJavaScriptScheme)) { | 1042 if (url.SchemeIs(url::kJavaScriptScheme)) |
1041 browser_->window()->GetLocationBar()->GetOmniboxView()->SetUserText( | 1043 continue; |
1042 OmniboxView::StripJavascriptSchemas(base::UTF8ToUTF16(url.spec()))); | 1044 |
1043 return; | 1045 OpenURLParams params(url, Referrer(), |
| 1046 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 1047 ui::PAGE_TRANSITION_TYPED, false); |
| 1048 browser_->tab_strip_model()->GetActiveWebContents()->OpenURL(params); |
1044 } | 1049 } |
1045 | |
1046 OpenURLParams params(url, Referrer(), WindowOpenDisposition::CURRENT_TAB, | |
1047 ui::PAGE_TRANSITION_TYPED, false); | |
1048 browser_->tab_strip_model()->GetActiveWebContents()->OpenURL(params); | |
1049 } | 1050 } |
1050 | 1051 |
1051 // (URLDropTargetController protocol) | 1052 // (URLDropTargetController protocol) |
1052 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { | 1053 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { |
1053 // TODO(viettrungluu): This code is more or less copied from the code in | 1054 // TODO(viettrungluu): This code is more or less copied from the code in |
1054 // |TabStripController|. I'll refactor this soon to make it common and expand | 1055 // |TabStripController|. I'll refactor this soon to make it common and expand |
1055 // its capabilities (e.g., allow text DnD). | 1056 // its capabilities (e.g., allow text DnD). |
1056 | 1057 |
1057 // If the input is plain text, classify the input and make the URL. | 1058 // If the input is plain text, classify the input and make the URL. |
1058 AutocompleteMatch match; | 1059 AutocompleteMatch match; |
(...skipping 20 matching lines...) Expand all Loading... |
1079 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1080 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
1080 // Do nothing. | 1081 // Do nothing. |
1081 } | 1082 } |
1082 | 1083 |
1083 // (URLDropTargetController protocol) | 1084 // (URLDropTargetController protocol) |
1084 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1085 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
1085 return drag_util::IsUnsupportedDropData(profile_, info); | 1086 return drag_util::IsUnsupportedDropData(profile_, info); |
1086 } | 1087 } |
1087 | 1088 |
1088 @end | 1089 @end |
OLD | NEW |