blob: 596232f0aa98100104bc06bb40f9111b991848ed [file] [log] [blame]
[email protected]895585e2012-04-19 18:24:071// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1a9e11dc2009-03-24 20:40:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]14a000d2010-04-29 21:44:245#ifndef CHROME_BROWSER_PLATFORM_UTIL_H_
6#define CHROME_BROWSER_PLATFORM_UTIL_H_
[email protected]1a9e11dc2009-03-24 20:40:447
[email protected]bca64fb2011-04-25 17:52:528#include <string>
9
asanka655d1112015-03-07 05:33:4110#include "base/callback_forward.h"
[email protected]76fb05c2013-06-11 04:38:0511#include "base/strings/string16.h"
avib896c712015-12-26 02:10:4312#include "build/build_config.h"
sievers2f1e8112015-12-04 18:43:5613#include "chrome/common/features.h"
[email protected]08397d52011-02-05 01:53:3814#include "ui/gfx/native_widget_types.h"
[email protected]076700e62009-04-01 18:41:2315
[email protected]59b2e322009-09-01 22:32:2616class GURL;
[email protected]7f0a3efa2013-12-12 17:16:1217class Profile;
[email protected]1a9e11dc2009-03-24 20:40:4418
[email protected]a3ef4832013-02-02 05:12:3319namespace base {
20class FilePath;
21}
22
[email protected]1a9e11dc2009-03-24 20:40:4423namespace platform_util {
24
asanka655d1112015-03-07 05:33:4125// Result of calling OpenFile() or OpenFolder() passed into OpenOperationResult.
26enum 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]1a9e11dc2009-03-24 20:40:4438
asanka655d1112015-03-07 05:33:4139// Type of item that is the target of the OpenItem() call.
maksim.sisov4e6a58a62016-05-02 19:34:4740enum OpenItemType {
41 OPEN_FILE,
42 OPEN_FOLDER,
43#if defined(OS_LINUX)
44 SHOW_ITEM_IN_FOLDER
45#endif
46};
asanka655d1112015-03-07 05:33:4147
48// Callback used with OpenFile and OpenFolder.
49typedef 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.
63void 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.
73void ShowItemInFolder(Profile* profile, const base::FilePath& full_path);
[email protected]de86a8512009-05-28 20:29:4074
[email protected]59b2e322009-09-01 22:32:2675// 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]7f0a3efa2013-12-12 17:16:1277// Must be called from the UI thread.
78void OpenExternal(Profile* profile, const GURL& url);
[email protected]59b2e322009-09-01 22:32:2679
[email protected]076700e62009-04-01 18:41:2380// Get the top level window for the native view. This can return NULL.
81gfx::NativeWindow GetTopLevel(gfx::NativeView view);
82
andresantosof8f9fd182014-11-15 01:14:3983// 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.
86gfx::NativeView GetViewForWindow(gfx::NativeWindow window);
87
[email protected]ba6680f2010-11-01 20:35:0888// Get the direct parent of |view|, may return NULL.
89gfx::NativeView GetParent(gfx::NativeView view);
90
[email protected]d2cc6ed2009-04-24 00:26:1791// Returns true if |window| is the foreground top level window.
92bool IsWindowActive(gfx::NativeWindow window);
93
[email protected]9fa8af62010-06-03 17:15:2294// Activate the window, bringing it to the foreground top level.
95void ActivateWindow(gfx::NativeWindow window);
96
[email protected]bd1ad682009-05-15 22:19:1797// 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.
100bool IsVisible(gfx::NativeView view);
101
[email protected]895585e2012-04-19 18:24:07102#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.
106bool IsSwipeTrackingFromScrollEventsEnabled();
107#endif
108
sievers2f1e8112015-12-04 18:43:56109#if BUILDFLAG(ANDROID_JAVA_UI)
qinmind4599b42015-09-08 20:06:20110bool RegisterPlatformUtil(JNIEnv* env);
111#endif
[email protected]7f0a3efa2013-12-12 17:16:12112} // namespace platform_util
[email protected]1a9e11dc2009-03-24 20:40:44113
[email protected]14a000d2010-04-29 21:44:24114#endif // CHROME_BROWSER_PLATFORM_UTIL_H_