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/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/autocomplete/autocomplete.h" | 16 #include "chrome/browser/autocomplete/autocomplete.h" |
17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
20 #include "chrome/browser/command_updater.h" | 20 #include "chrome/browser/command_updater.h" |
21 #include "chrome/browser/net/url_fixer_upper.h" | 21 #include "chrome/browser/net/url_fixer_upper.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/search_engines/template_url_service.h" | 24 #include "chrome/browser/search_engines/template_url_service.h" |
25 #include "chrome/browser/themes/theme_service.h" | 25 #include "chrome/browser/themes/theme_service.h" |
26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
28 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 29 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
29 #include "chrome/browser/ui/cocoa/drag_util.h" | 30 #include "chrome/browser/ui/cocoa/drag_util.h" |
30 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 31 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
31 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 32 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
32 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 33 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
33 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" | 34 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" |
34 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 35 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
36 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // Get the first URL and fix it up. | 762 // Get the first URL and fix it up. |
762 GURL url(URLFixerUpper::FixupURL( | 763 GURL url(URLFixerUpper::FixupURL( |
763 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string())); | 764 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string())); |
764 | 765 |
765 if (url.SchemeIs(chrome::kJavaScriptScheme)) { | 766 if (url.SchemeIs(chrome::kJavaScriptScheme)) { |
766 browser_->window()->GetLocationBar()->GetLocationEntry()->SetUserText( | 767 browser_->window()->GetLocationBar()->GetLocationEntry()->SetUserText( |
767 OmniboxView::StripJavascriptSchemas(UTF8ToUTF16(url.spec()))); | 768 OmniboxView::StripJavascriptSchemas(UTF8ToUTF16(url.spec()))); |
768 } | 769 } |
769 OpenURLParams params( | 770 OpenURLParams params( |
770 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); | 771 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); |
771 browser_->GetActiveWebContents()->OpenURL(params); | 772 chrome::GetActiveWebContents(browser_)->OpenURL(params); |
772 } | 773 } |
773 | 774 |
774 // (URLDropTargetController protocol) | 775 // (URLDropTargetController protocol) |
775 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { | 776 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { |
776 // TODO(viettrungluu): This code is more or less copied from the code in | 777 // TODO(viettrungluu): This code is more or less copied from the code in |
777 // |TabStripController|. I'll refactor this soon to make it common and expand | 778 // |TabStripController|. I'll refactor this soon to make it common and expand |
778 // its capabilities (e.g., allow text DnD). | 779 // its capabilities (e.g., allow text DnD). |
779 | 780 |
780 // If the input is plain text, classify the input and make the URL. | 781 // If the input is plain text, classify the input and make the URL. |
781 AutocompleteMatch match; | 782 AutocompleteMatch match; |
782 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( | 783 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( |
783 base::SysNSStringToUTF16(text), string16(), false, false, &match, NULL); | 784 base::SysNSStringToUTF16(text), string16(), false, false, &match, NULL); |
784 GURL url(match.destination_url); | 785 GURL url(match.destination_url); |
785 | 786 |
786 OpenURLParams params( | 787 OpenURLParams params( |
787 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); | 788 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); |
788 browser_->GetActiveWebContents()->OpenURL(params); | 789 chrome::GetActiveWebContents(browser_)->OpenURL(params); |
789 } | 790 } |
790 | 791 |
791 // (URLDropTargetController protocol) | 792 // (URLDropTargetController protocol) |
792 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 793 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
793 // Do nothing. | 794 // Do nothing. |
794 } | 795 } |
795 | 796 |
796 // (URLDropTargetController protocol) | 797 // (URLDropTargetController protocol) |
797 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 798 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
798 // Do nothing. | 799 // Do nothing. |
799 } | 800 } |
800 | 801 |
801 // (URLDropTargetController protocol) | 802 // (URLDropTargetController protocol) |
802 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 803 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
803 return drag_util::IsUnsupportedDropData(profile_, info); | 804 return drag_util::IsUnsupportedDropData(profile_, info); |
804 } | 805 } |
805 | 806 |
806 @end | 807 @end |
OLD | NEW |