diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 09:18:29 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 09:18:29 +0000 |
commit | 7bc8299dccc300184e850e1a76db110a85234db1 (patch) | |
tree | 668a92aea8b994e089644b20c1d7832e935a4c1a /chrome/renderer | |
parent | 82222efbc0eb7758d69671099971f1b6dd3eb20d (diff) | |
download | chromium_src-7bc8299dccc300184e850e1a76db110a85234db1.zip chromium_src-7bc8299dccc300184e850e1a76db110a85234db1.tar.gz chromium_src-7bc8299dccc300184e850e1a76db110a85234db1.tar.bz2 |
Allow platform apps to get writable FileEntry objects from readable ones.
This propts the user to choose a path to save to, using the file entry passed
in as a reference of where to save to.
BUG=130196
TEST=Manual testing performed
Review URL: https://chromiumcodereview.appspot.com/10539101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/extensions/extension_dispatcher.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/extensions/file_system_natives.cc (renamed from chrome/renderer/extensions/experimental.app_custom_bindings.cc) | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/file_system_natives.h (renamed from chrome/renderer/extensions/experimental.app_custom_bindings.h) | 12 | ||||
-rw-r--r-- | chrome/renderer/resources/extensions/experimental.app_custom_bindings.js | 4 | ||||
-rw-r--r-- | chrome/renderer/resources/extensions/file_system_custom_bindings.js | 42 |
5 files changed, 53 insertions, 19 deletions
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc index 23af146..add0813 100644 --- a/chrome/renderer/extensions/extension_dispatcher.cc +++ b/chrome/renderer/extensions/extension_dispatcher.cc @@ -25,7 +25,6 @@ #include "chrome/renderer/extensions/chrome_v8_extension.h" #include "chrome/renderer/extensions/context_menus_custom_bindings.h" #include "chrome/renderer/extensions/event_bindings.h" -#include "chrome/renderer/extensions/experimental.app_custom_bindings.h" #include "chrome/renderer/extensions/experimental.usb_custom_bindings.h" #include "chrome/renderer/extensions/extension_custom_bindings.h" #include "chrome/renderer/extensions/extension_groups.h" @@ -33,6 +32,7 @@ #include "chrome/renderer/extensions/extension_request_sender.h" #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" +#include "chrome/renderer/extensions/file_system_natives.h" #include "chrome/renderer/extensions/i18n_custom_bindings.h" #include "chrome/renderer/extensions/media_gallery_custom_bindings.h" #include "chrome/renderer/extensions/miscellaneous_bindings.h" @@ -78,13 +78,13 @@ using extensions::ApiDefinitionsNatives; using extensions::AppWindowCustomBindings; using extensions::ContextMenusCustomBindings; using extensions::Extension; -using extensions::ExperimentalAppCustomBindings; using extensions::ExperimentalUsbCustomBindings; using extensions::ExtensionAPI; using extensions::ExtensionCustomBindings; using extensions::Feature; using extensions::FileBrowserHandlerCustomBindings; using extensions::FileBrowserPrivateCustomBindings; +using extensions::FileSystemNatives; using extensions::I18NCustomBindings; using extensions::MiscellaneousBindings; using extensions::MediaGalleryCustomBindings; @@ -500,6 +500,10 @@ void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, scoped_ptr<NativeHandler>( new SetIconNatives(this, request_sender_.get()))); + // Natives used by multiple APIs. + module_system->RegisterNativeHandler("file_system_natives", + scoped_ptr<NativeHandler>(new FileSystemNatives())); + // Custom bindings. module_system->RegisterNativeHandler("app", scoped_ptr<NativeHandler>(new AppBindings(this, context))); @@ -512,8 +516,6 @@ void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, new ExtensionCustomBindings(this))); module_system->RegisterNativeHandler("experimental_mediaGalleries", scoped_ptr<NativeHandler>(new MediaGalleryCustomBindings())); - module_system->RegisterNativeHandler("experimental_app", - scoped_ptr<NativeHandler>(new ExperimentalAppCustomBindings())); module_system->RegisterNativeHandler("experimental_usb", scoped_ptr<NativeHandler>(new ExperimentalUsbCustomBindings())); module_system->RegisterNativeHandler("file_browser_handler", diff --git a/chrome/renderer/extensions/experimental.app_custom_bindings.cc b/chrome/renderer/extensions/file_system_natives.cc index 65f7a6d..7ed653f 100644 --- a/chrome/renderer/extensions/experimental.app_custom_bindings.cc +++ b/chrome/renderer/extensions/file_system_natives.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/extensions/experimental.app_custom_bindings.h" +#include "chrome/renderer/extensions/file_system_natives.h" #include <string> @@ -48,7 +48,7 @@ static v8::Handle<v8::Value> GetIsolatedFileSystem( namespace extensions { -ExperimentalAppCustomBindings::ExperimentalAppCustomBindings() +FileSystemNatives::FileSystemNatives() : ChromeV8Extension(NULL) { RouteStaticFunction("GetIsolatedFileSystem", &GetIsolatedFileSystem); } diff --git a/chrome/renderer/extensions/experimental.app_custom_bindings.h b/chrome/renderer/extensions/file_system_natives.h index aa11c49a..d873f5c 100644 --- a/chrome/renderer/extensions/experimental.app_custom_bindings.h +++ b/chrome/renderer/extensions/file_system_natives.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_RENDERER_EXTENSIONS_EXPERIMENTAL_APP_CUSTOM_BINDINGS_H_ -#define CHROME_RENDERER_EXTENSIONS_EXPERIMENTAL_APP_CUSTOM_BINDINGS_H_ +#ifndef CHROME_RENDERER_EXTENSIONS_FILE_SYSTEM_NATIVES_H_ +#define CHROME_RENDERER_EXTENSIONS_FILE_SYSTEM_NATIVES_H_ #pragma once #include "base/compiler_specific.h" @@ -12,14 +12,14 @@ namespace extensions { // Custom bindings for the nativeFileSystem API. -class ExperimentalAppCustomBindings : public ChromeV8Extension { +class FileSystemNatives : public ChromeV8Extension { public: - ExperimentalAppCustomBindings(); + FileSystemNatives(); private: - DISALLOW_COPY_AND_ASSIGN(ExperimentalAppCustomBindings); + DISALLOW_COPY_AND_ASSIGN(FileSystemNatives); }; } // namespace extensions -#endif // CHROME_RENDERER_EXTENSIONS_EXPERIMENTAL_APP_CUSTOM_BINDINGS_H_ +#endif // CHROME_RENDERER_EXTENSIONS_FILE_SYSTEM_NATIVES_H_ diff --git a/chrome/renderer/resources/extensions/experimental.app_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.app_custom_bindings.js index 8f0cd1c..52284c7 100644 --- a/chrome/renderer/resources/extensions/experimental.app_custom_bindings.js +++ b/chrome/renderer/resources/extensions/experimental.app_custom_bindings.js @@ -5,8 +5,8 @@ // Custom bindings for the experimental.app API. var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); -var experimentalAppNatives = requireNative('experimental_app'); -var GetIsolatedFileSystem = experimentalAppNatives.GetIsolatedFileSystem; +var fileSystemHelpers = requireNative('file_system_natives'); +var GetIsolatedFileSystem = fileSystemHelpers.GetIsolatedFileSystem; chromeHidden.registerCustomHook('experimental.app', function(bindingsAPI) { chrome.experimental.app.onLaunched.dispatch = diff --git a/chrome/renderer/resources/extensions/file_system_custom_bindings.js b/chrome/renderer/resources/extensions/file_system_custom_bindings.js index 0e6da3a..1847279 100644 --- a/chrome/renderer/resources/extensions/file_system_custom_bindings.js +++ b/chrome/renderer/resources/extensions/file_system_custom_bindings.js @@ -5,12 +5,44 @@ // Custom bindings for the fileSystem API. var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); +var fileSystemNatives = requireNative('file_system_natives'); +var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; chromeHidden.registerCustomHook('fileSystem', function(bindingsAPI) { - bindingsAPI.apiFunctions.setUpdateArgumentsPostValidate( - 'getDisplayPath', function(fileEntry, callback) { - var fileSystemName = fileEntry.filesystem.name; - var relativePath = fileEntry.fullPath.slice(1); - return [fileSystemName, relativePath, callback]; + var apiFunctions = bindingsAPI.apiFunctions; + function bindFileEntryFunction(functionName) { + apiFunctions.setUpdateArgumentsPostValidate( + functionName, function(fileEntry, callback) { + var fileSystemName = fileEntry.filesystem.name; + var relativePath = fileEntry.fullPath.slice(1); + return [fileSystemName, relativePath, callback]; + }); + } + ['getDisplayPath', 'getWritableFileEntry'].forEach(bindFileEntryFunction); + + apiFunctions.setCustomCallback('getWritableFileEntry', + function(name, request, response) { + if (request.callback && response) { + var callback = request.callback; + request.callback = null; + + var fileSystemId = response.fileSystemId; + var baseName = response.baseName; + var fs = GetIsolatedFileSystem(fileSystemId); + + try { + fs.root.getFile(baseName, {}, function(fileEntry) { + callback(fileEntry); + }, function(fileError) { + chrome.extension.lastError = + 'Error getting fileEntry, code: ' + fileError.code; + callback(); + }); + } catch (e) { + chrome.extension.lastError = + 'Error in event handler for onLaunched: ' + e.stack; + callback(); + } + } }); }); |