[email protected] | 895585e | 2012-04-19 18:24:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PLATFORM_UTIL_H_ |
| 6 | #define CHROME_BROWSER_PLATFORM_UTIL_H_ |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 7 | |
[email protected] | bca64fb | 2011-04-25 17:52:52 | [diff] [blame] | 8 | #include <string> |
| 9 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 11 | #include "base/strings/string16.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 12 | #include "build/build_config.h" |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 13 | #include "chrome/common/features.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 14 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 076700e6 | 2009-04-01 18:41:23 | [diff] [blame] | 15 | |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 16 | class GURL; |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 17 | class Profile; |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 18 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 19 | namespace base { |
| 20 | class FilePath; |
| 21 | } |
| 22 | |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 23 | namespace platform_util { |
| 24 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 25 | // Result of calling OpenFile() or OpenFolder() passed into OpenOperationResult. |
| 26 | enum OpenOperationResult { |
| 27 | OPEN_SUCCEEDED, |
| 28 | OPEN_FAILED_PATH_NOT_FOUND, // Specified path does not exist. |
| 29 | OPEN_FAILED_INVALID_TYPE, // Type of object found at path did not match what |
| 30 | // was expected. I.e. OpenFile was called on a |
| 31 | // folder or OpenFolder called on a file. |
| 32 | OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE, // There was no file handler capable of |
| 33 | // opening file. Only returned on |
| 34 | // ChromeOS. |
| 35 | OPEN_FAILED_FILE_ERROR, // Open operation failed due to some other file |
| 36 | // error. |
| 37 | }; |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 38 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 39 | // Type of item that is the target of the OpenItem() call. |
maksim.sisov | 4e6a58a6 | 2016-05-02 19:34:47 | [diff] [blame] | 40 | enum OpenItemType { |
| 41 | OPEN_FILE, |
| 42 | OPEN_FOLDER, |
| 43 | #if defined(OS_LINUX) |
| 44 | SHOW_ITEM_IN_FOLDER |
| 45 | #endif |
| 46 | }; |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 47 | |
| 48 | // Callback used with OpenFile and OpenFolder. |
| 49 | typedef base::Callback<void(OpenOperationResult)> OpenOperationCallback; |
| 50 | |
| 51 | // Opens the item specified by |full_path|, which is expected to be the type |
| 52 | // indicated by |item_type| in the desktop's default manner. |
| 53 | // |callback| will be invoked on the UI thread with the result of the open |
| 54 | // operation. |
| 55 | // |
| 56 | // It is an error if the object at |full_path| does not match the intended type |
| 57 | // specified in |item_type|. This error will be reported to |callback|. |
| 58 | // |
| 59 | // Note: On all platforms, the user may be shown additional UI if there is no |
| 60 | // suitable handler for |full_path|. On Chrome OS, all errors will result in |
| 61 | // visible error messages iff |callback| is not specified. |
| 62 | // Must be called on the UI thread. |
| 63 | void OpenItem(Profile* profile, |
| 64 | const base::FilePath& full_path, |
| 65 | OpenItemType item_type, |
| 66 | const OpenOperationCallback& callback); |
| 67 | |
| 68 | // Opens the folder containing the item specified by |full_path| in the |
| 69 | // desktop's default manner. If possible, the item will be selected. The |
| 70 | // |profile| is used to determine the running profile of file manager app in |
| 71 | // Chrome OS only. |profile| is not used in platforms other than Chrome OS. Must |
| 72 | // be called on the UI thread. |
| 73 | void ShowItemInFolder(Profile* profile, const base::FilePath& full_path); |
[email protected] | de86a851 | 2009-05-28 20:29:40 | [diff] [blame] | 74 | |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 75 | // Open the given external protocol URL in the desktop's default manner. |
| 76 | // (For example, mailto: URLs in the default mail user agent.) |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 77 | // Must be called from the UI thread. |
| 78 | void OpenExternal(Profile* profile, const GURL& url); |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 79 | |
[email protected] | 076700e6 | 2009-04-01 18:41:23 | [diff] [blame] | 80 | // Get the top level window for the native view. This can return NULL. |
| 81 | gfx::NativeWindow GetTopLevel(gfx::NativeView view); |
| 82 | |
andresantoso | f8f9fd18 | 2014-11-15 01:14:39 | [diff] [blame] | 83 | // Returns a NativeView handle for parenting dialogs off |window|. This can be |
| 84 | // used to position a dialog using a NativeWindow, when a NativeView (e.g. |
| 85 | // browser tab) isn't available. |
| 86 | gfx::NativeView GetViewForWindow(gfx::NativeWindow window); |
| 87 | |
[email protected] | ba6680f | 2010-11-01 20:35:08 | [diff] [blame] | 88 | // Get the direct parent of |view|, may return NULL. |
| 89 | gfx::NativeView GetParent(gfx::NativeView view); |
| 90 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 91 | // Returns true if |window| is the foreground top level window. |
| 92 | bool IsWindowActive(gfx::NativeWindow window); |
| 93 | |
[email protected] | 9fa8af6 | 2010-06-03 17:15:22 | [diff] [blame] | 94 | // Activate the window, bringing it to the foreground top level. |
| 95 | void ActivateWindow(gfx::NativeWindow window); |
| 96 | |
[email protected] | bd1ad68 | 2009-05-15 22:19:17 | [diff] [blame] | 97 | // Returns true if the view is visible. The exact definition of this is |
| 98 | // platform-specific, but it is generally not "visible to the user", rather |
| 99 | // whether the view has the visible attribute set. |
| 100 | bool IsVisible(gfx::NativeView view); |
| 101 | |
[email protected] | 895585e | 2012-04-19 18:24:07 | [diff] [blame] | 102 | #if defined(OS_MACOSX) |
| 103 | // On 10.7+, back and forward swipe gestures can be triggered using a scroll |
| 104 | // gesture, if enabled in System Preferences. This function returns true if |
| 105 | // the feature is supported and enabled, and false otherwise. |
| 106 | bool IsSwipeTrackingFromScrollEventsEnabled(); |
| 107 | #endif |
| 108 | |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 109 | #if BUILDFLAG(ANDROID_JAVA_UI) |
qinmin | d4599b4 | 2015-09-08 20:06:20 | [diff] [blame] | 110 | bool RegisterPlatformUtil(JNIEnv* env); |
| 111 | #endif |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 112 | } // namespace platform_util |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 113 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 114 | #endif // CHROME_BROWSER_PLATFORM_UTIL_H_ |