Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / file_manager / private_api_file_system.cc
index 61e10b0..f0c04de 100644 (file)
@@ -29,6 +29,7 @@
 #include "content/public/browser/child_process_security_policy.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
+#include "content/public/common/url_constants.h"
 #include "net/base/escape.h"
 #include "storage/browser/fileapi/file_system_context.h"
 #include "storage/browser/fileapi/file_system_file_util.h"
@@ -201,6 +202,13 @@ void CancelCopyOnIOThread(
       operation_id, base::Bind(&OnCopyCancelled));
 }
 
+// Converts a status code to a bool value and calls the |callback| with it.
+void StatusCallbackToResponseCallback(
+    const base::Callback<void(bool)>& callback,
+    base::File::Error result) {
+  callback.Run(result == base::File::FILE_OK);
+}
+
 }  // namespace
 
 void FileManagerPrivateRequestFileSystemFunction::DidFail(
@@ -222,14 +230,6 @@ FileManagerPrivateRequestFileSystemFunction::SetupFileSystemAccessPermissions(
   if (!extension.get())
     return false;
 
-  // Make sure that only component extension can access the entire
-  // local file system.
-  if (extension_->location() != extensions::Manifest::COMPONENT) {
-    NOTREACHED() << "Private method access by non-component extension "
-                 << extension->id();
-    return false;
-  }
-
   storage::ExternalFileSystemBackend* backend =
       file_system_context->external_backend();
   if (!backend)
@@ -259,6 +259,11 @@ FileManagerPrivateRequestFileSystemFunction::SetupFileSystemAccessPermissions(
     }
   }
 
+  // Grant permission to request externalfile scheme. The permission is needed
+  // to start drag for external file URL.
+  ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
+      child_id, content::kExternalFileScheme);
+
   return true;
 }
 
@@ -275,7 +280,7 @@ bool FileManagerPrivateRequestFileSystemFunction::RunAsync() {
 
   using file_manager::VolumeManager;
   using file_manager::VolumeInfo;
-  VolumeManager* volume_manager = VolumeManager::Get(GetProfile());
+  VolumeManager* const volume_manager = VolumeManager::Get(GetProfile());
   if (!volume_manager)
     return false;
 
@@ -362,42 +367,67 @@ bool FileWatchFunctionBase::RunAsync() {
       file_manager::util::GetFileSystemContextForRenderViewHost(
           GetProfile(), render_view_host());
 
-  FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url));
-  base::FilePath local_path = file_watch_url.path();
-  base::FilePath virtual_path = file_watch_url.virtual_path();
-  if (local_path.empty()) {
+  const FileSystemURL file_system_url =
+      file_system_context->CrackURL(GURL(url));
+  if (file_system_url.path().empty()) {
     Respond(false);
     return true;
   }
-  PerformFileWatchOperation(local_path, virtual_path, extension_id());
 
+  PerformFileWatchOperation(file_system_context, file_system_url,
+                            extension_id());
   return true;
 }
 
 void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation(
-    const base::FilePath& local_path,
-    const base::FilePath& virtual_path,
+    scoped_refptr<storage::FileSystemContext> file_system_context,
+    const storage::FileSystemURL& file_system_url,
     const std::string& extension_id) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  file_manager::EventRouter* event_router =
+  file_manager::EventRouter* const event_router =
       file_manager::EventRouterFactory::GetForProfile(GetProfile());
+
+  storage::WatcherManager* const watcher_manager =
+      file_system_context->GetWatcherManager(file_system_url.type());
+  if (watcher_manager) {
+    watcher_manager->AddWatcher(
+        file_system_url, false /* recursive */,
+        base::Bind(
+            &StatusCallbackToResponseCallback,
+            base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this)),
+        base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification,
+                   event_router->GetWeakPtr(), file_system_url, extension_id));
+    return;
+  }
+
+  // Obsolete. Fallback code if storage::WatcherManager is not implemented.
   event_router->AddFileWatch(
-      local_path,
-      virtual_path,
-      extension_id,
+      file_system_url.path(), file_system_url.virtual_path(), extension_id,
       base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this));
 }
 
 void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation(
-    const base::FilePath& local_path,
-    const base::FilePath& unused,
+    scoped_refptr<storage::FileSystemContext> file_system_context,
+    const storage::FileSystemURL& file_system_url,
     const std::string& extension_id) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  file_manager::EventRouter* event_router =
+  file_manager::EventRouter* const event_router =
       file_manager::EventRouterFactory::GetForProfile(GetProfile());
-  event_router->RemoveFileWatch(local_path, extension_id);
+
+  storage::WatcherManager* const watcher_manager =
+      file_system_context->GetWatcherManager(file_system_url.type());
+  if (watcher_manager) {
+    watcher_manager->RemoveWatcher(
+        file_system_url, false /* recursive */,
+        base::Bind(&StatusCallbackToResponseCallback,
+                   base::Bind(&FileWatchFunctionBase::Respond, this)));
+    return;
+  }
+
+  // Obsolete. Fallback code if storage::WatcherManager is not implemented.
+  event_router->RemoveFileWatch(file_system_url.path(), extension_id);
   Respond(true);
 }