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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PLATFORM_UTIL_H_ 6 #define CHROME_BROWSER_PLATFORM_UTIL_H_ 7 8 #include <string> 9 10 #include "base/callback_forward.h" 11 #include "base/strings/string16.h" 12 #include "build/build_config.h" 13 #include "chrome/common/buildflags.h" 14 #include "ui/gfx/native_widget_types.h" 15 16 class Browser; 17 class GURL; 18 class Profile; 19 20 namespace base { 21 class FilePath; 22 } 23 24 namespace platform_util { 25 26 // Result of calling OpenFile() or OpenFolder() passed into OpenOperationResult. 27 enum OpenOperationResult { 28 OPEN_SUCCEEDED, 29 OPEN_FAILED_PATH_NOT_FOUND, // Specified path does not exist. 30 OPEN_FAILED_INVALID_TYPE, // Type of object found at path did not match what 31 // was expected. I.e. OpenFile was called on a 32 // folder or OpenFolder called on a file. 33 OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE, // There was no file handler capable of 34 // opening file. Only returned on 35 // ChromeOS. 36 OPEN_FAILED_FILE_ERROR, // Open operation failed due to some other file 37 // error. 38 }; 39 40 // Type of item that is the target of the OpenItem() call. 41 enum OpenItemType { 42 OPEN_FILE, 43 OPEN_FOLDER, 44 }; 45 46 // Callback used with OpenFile and OpenFolder. 47 typedef base::OnceCallback<void(OpenOperationResult)> OpenOperationCallback; 48 49 // Opens the item specified by |full_path|, which is expected to be the type 50 // indicated by |item_type| in the desktop's default manner. 51 // |callback| will be invoked on the UI thread with the result of the open 52 // operation. 53 // 54 // It is an error if the object at |full_path| does not match the intended type 55 // specified in |item_type|. This error will be reported to |callback|. 56 // 57 // Note: On all platforms, the user may be shown additional UI if there is no 58 // suitable handler for |full_path|. On Chrome OS, all errors will result in 59 // visible error messages iff |callback| is not specified. 60 // Must be called on the UI thread. 61 void OpenItem(Profile* profile, 62 const base::FilePath& full_path, 63 OpenItemType item_type, 64 OpenOperationCallback callback); 65 66 // Opens the folder containing the item specified by |full_path| in the 67 // desktop's default manner. If possible, the item will be selected. The 68 // |profile| is used to determine the running profile of file manager app in 69 // Chrome OS only. |profile| is not used in platforms other than Chrome OS. Must 70 // be called on the UI thread. 71 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path); 72 73 // Open the given external protocol URL in the desktop's default manner. 74 // (For example, mailto: URLs in the default mail user agent.) 75 // Must be called from the UI thread. 76 void OpenExternal(Profile* profile, const GURL& url); 77 78 // Get the top level window for the native view. This can return NULL. 79 gfx::NativeWindow GetTopLevel(gfx::NativeView view); 80 81 // Returns a NativeView handle for parenting dialogs off |window|. This can be 82 // used to position a dialog using a NativeWindow, when a NativeView (e.g. 83 // browser tab) isn't available. 84 gfx::NativeView GetViewForWindow(gfx::NativeWindow window); 85 86 // Get the direct parent of |view|, may return NULL. 87 gfx::NativeView GetParent(gfx::NativeView view); 88 89 // Returns true if |window| is the foreground top level window. 90 bool IsWindowActive(gfx::NativeWindow window); 91 92 // Activate the window, bringing it to the foreground top level. 93 void ActivateWindow(gfx::NativeWindow window); 94 95 // Returns true if the view is visible. The exact definition of this is 96 // platform-specific, but it is generally not "visible to the user", rather 97 // whether the view has the visible attribute set. 98 bool IsVisible(gfx::NativeView view); 99 100 #if defined(OS_MAC) 101 // On 10.7+, back and forward swipe gestures can be triggered using a scroll 102 // gesture, if enabled in System Preferences. This function returns true if 103 // the feature is supported and enabled, and false otherwise. 104 bool IsSwipeTrackingFromScrollEventsEnabled(); 105 #endif 106 107 // Returns true if the given browser window is in locked fullscreen mode 108 // (a special type of fullscreen where the user is locked into one browser 109 // window). 110 bool IsBrowserLockedFullscreen(const Browser* browser); 111 112 } // namespace platform_util 113 114 #endif // CHROME_BROWSER_PLATFORM_UTIL_H_ 115