OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/drag_util.h" | 5 #import "chrome/browser/ui/cocoa/drag_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "components/mime_util/mime_util.h" | 13 #include "components/mime_util/mime_util.h" |
14 #include "content/public/browser/plugin_service.h" | 14 #include "content/public/browser/plugin_service.h" |
15 #include "content/public/common/webplugininfo.h" | 15 #include "content/public/common/webplugininfo.h" |
16 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
17 #include "net/base/filename_util.h" | 17 #include "net/base/filename_util.h" |
18 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
19 #import "third_party/mozilla/NSPasteboard+Utils.h" | 19 #import "third_party/mozilla/NSPasteboard+Utils.h" |
20 #import "ui/base/dragdrop/cocoa_dnd_util.h" | 20 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
23 #include "ui/resources/grit/ui_resources.h" | 23 #include "ui/resources/grit/ui_resources.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 #include "url/origin.h" |
25 #include "url/url_constants.h" | 26 #include "url/url_constants.h" |
26 | 27 |
27 using content::PluginService; | 28 using content::PluginService; |
28 | 29 |
29 namespace drag_util { | 30 namespace drag_util { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 BOOL IsSupportedFileURL(Profile* profile, const GURL& url) { | 34 BOOL IsSupportedFileURL(Profile* profile, const GURL& url) { |
34 base::FilePath full_path; | 35 base::FilePath full_path; |
35 net::FileURLToFilePath(url, &full_path); | 36 net::FileURLToFilePath(url, &full_path); |
36 | 37 |
37 std::string mime_type; | 38 std::string mime_type; |
38 net::GetMimeTypeFromFile(full_path, &mime_type); | 39 net::GetMimeTypeFromFile(full_path, &mime_type); |
39 | 40 |
40 // This logic mirrors |BufferedResourceHandler::ShouldDownload()|. | 41 // This logic mirrors |BufferedResourceHandler::ShouldDownload()|. |
41 // TODO(asvitkine): Refactor this out to a common location instead of | 42 // TODO(asvitkine): Refactor this out to a common location instead of |
42 // duplicating code. | 43 // duplicating code. |
43 if (mime_util::IsSupportedMimeType(mime_type)) | 44 if (mime_util::IsSupportedMimeType(mime_type)) |
44 return YES; | 45 return YES; |
45 | 46 |
46 // Check whether there is a plugin that supports the mime type. (e.g. PDF) | 47 // Check whether there is a plugin that supports the mime type. (e.g. PDF) |
47 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not | 48 // TODO(bauerb): This possibly uses stale information, but it's guaranteed not |
48 // to do disk access. | 49 // to do disk access. |
49 bool allow_wildcard = false; | 50 bool allow_wildcard = false; |
50 content::WebPluginInfo plugin; | 51 content::WebPluginInfo plugin; |
51 return PluginService::GetInstance()->GetPluginInfo( | 52 return PluginService::GetInstance()->GetPluginInfo( |
52 -1, // process ID | 53 -1, // process ID |
53 MSG_ROUTING_NONE, // routing ID | 54 MSG_ROUTING_NONE, // routing ID |
54 profile->GetResourceContext(), | 55 profile->GetResourceContext(), url, url::Origin(), mime_type, |
55 url, GURL(), mime_type, allow_wildcard, | 56 allow_wildcard, NULL, &plugin, NULL); |
56 NULL, &plugin, NULL); | |
57 } | 57 } |
58 | 58 |
59 // Draws string |title| within box |frame|, positioning it at the origin. | 59 // Draws string |title| within box |frame|, positioning it at the origin. |
60 // Truncates text with fading if it is too long to fit horizontally. | 60 // Truncates text with fading if it is too long to fit horizontally. |
61 // Based on code from GradientButtonCell but simplified where possible. | 61 // Based on code from GradientButtonCell but simplified where possible. |
62 void DrawTruncatedTitle(NSAttributedString* title, NSRect frame) { | 62 void DrawTruncatedTitle(NSAttributedString* title, NSRect frame) { |
63 NSSize size = [title size]; | 63 NSSize size = [title size]; |
64 if (std::floor(size.width) <= NSWidth(frame)) { | 64 if (std::floor(size.width) <= NSWidth(frame)) { |
65 [title drawAtPoint:frame.origin]; | 65 [title drawAtPoint:frame.origin]; |
66 return; | 66 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 fraction:0.7]; | 160 fraction:0.7]; |
161 NSRect target_text_rect = NSMakeRect(text_left, 0, | 161 NSRect target_text_rect = NSMakeRect(text_left, 0, |
162 text_size.width, drag_image_size.height); | 162 text_size.width, drag_image_size.height); |
163 DrawTruncatedTitle(rich_title, target_text_rect); | 163 DrawTruncatedTitle(rich_title, target_text_rect); |
164 [drag_image unlockFocus]; | 164 [drag_image unlockFocus]; |
165 | 165 |
166 return drag_image; | 166 return drag_image; |
167 } | 167 } |
168 | 168 |
169 } // namespace drag_util | 169 } // namespace drag_util |
OLD | NEW |