| Index: chrome/browser/chromeos/extensions/file_handler_util.cc
|
| diff --git a/chrome/browser/chromeos/extensions/file_handler_util.cc b/chrome/browser/chromeos/extensions/file_handler_util.cc
|
| index b461c9d0072826e9c1127672279060c758605b97..1f58eaacd2bef6f5d4e88bb582e27f06db4b210b 100644
|
| --- a/chrome/browser/chromeos/extensions/file_handler_util.cc
|
| +++ b/chrome/browser/chromeos/extensions/file_handler_util.cc
|
| @@ -14,8 +14,10 @@
|
| #include "chrome/browser/chromeos/gdata/gdata_util.h"
|
| #include "chrome/browser/chromeos/extensions/file_manager_util.h"
|
| #include "chrome/browser/chromeos/gdata/drive_task_executor.h"
|
| +#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
|
| #include "chrome/browser/extensions/event_router.h"
|
| #include "chrome/browser/extensions/extension_host.h"
|
| +#include "chrome/browser/extensions/extension_process_manager.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/extensions/extension_tab_util.h"
|
| @@ -38,6 +40,7 @@
|
| #include "webkit/fileapi/file_system_context.h"
|
| #include "webkit/fileapi/file_system_url.h"
|
| #include "webkit/fileapi/file_system_util.h"
|
| +#include "webkit/fileapi/isolated_context.h"
|
|
|
| using content::BrowserContext;
|
| using content::BrowserThread;
|
| @@ -119,8 +122,17 @@ const FileBrowserHandler* FindFileBrowserHandler(const Extension* extension,
|
| return NULL;
|
| }
|
|
|
| +bool IsWebIntentAction(const std::string& action_id) {
|
| + if (action_id.compare(0, 4, std::string("http")) == 0)
|
| + return true;
|
| + return false;
|
| +}
|
| +
|
| unsigned int GetAccessPermissionsForHandler(const Extension* extension,
|
| const std::string& action_id) {
|
| + if (IsWebIntentAction(action_id))
|
| + return kReadOnlyFilePermissions;
|
| +
|
| const FileBrowserHandler* action =
|
| FindFileBrowserHandler(extension, action_id);
|
| if (!action)
|
| @@ -134,7 +146,6 @@ unsigned int GetAccessPermissionsForHandler(const Extension* extension,
|
| return result;
|
| }
|
|
|
| -
|
| std::string EscapedUtf8ToLower(const std::string& str) {
|
| string16 utf16 = UTF8ToUTF16(
|
| net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL));
|
| @@ -189,11 +200,27 @@ bool SortByTaskName(const LastUsedHandler& a, const LastUsedHandler& b) {
|
| b.handler->title().c_str()) > 0;
|
| }
|
|
|
| +// Does this LastUsedHandlerList contain entries with only a common timestamp?
|
| +bool HasCommonTimestamp(LastUsedHandlerList* list) {
|
| + DCHECK(!list->empty());
|
| + int common_timestamp = list->begin()->timestamp;
|
| + for (LastUsedHandlerList::const_iterator iter = list->begin() + 1;
|
| + iter != list->end(); ++iter) {
|
| + if (common_timestamp != iter->timestamp)
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| void SortLastUsedHandlerList(LastUsedHandlerList *list) {
|
| - // Sort by the last used descending.
|
| - std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc);
|
| - if (list->size() > 1) {
|
| - // Sort the rest by name.
|
| + if (list->size() <= 1) {
|
| + // Ok, we're alreay sorted.
|
| + } else if (HasCommonTimestamp(list)) {
|
| + // Sort only by name.
|
| + std::sort(list->begin(), list->end(), SortByTaskName);
|
| + } else {
|
| + // Bring the last used descending to the front, and sort the rest by name.
|
| + std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc);
|
| std::sort(list->begin() + 1, list->end(), SortByTaskName);
|
| }
|
| }
|
| @@ -794,6 +821,55 @@ void ExtensionTaskExecutor::SetupPermissionsAndDispatchEvent(
|
| return;
|
| }
|
|
|
| + // If we're a Web Intent action (to an extension), short-circuit and deliver
|
| + // each file as an onLaunched event to the packaged app's background page.
|
| + if (IsWebIntentAction(action_id_)) {
|
| + for (FileDefinitionList::const_iterator iter = file_list.begin();
|
| + iter != file_list.end(); ++iter) {
|
| +
|
| + // TODO(thorogood): Literally entirely stolen
|
| + // from platform_app_launcher.cc, around line 180.
|
| +
|
| + const FilePath file_path = iter->absolute_path;
|
| +
|
| + ExtensionProcessManager* process_manager =
|
| + extensions::ExtensionSystem::Get(profile())->process_manager();
|
| + extensions::ExtensionHost* host =
|
| + process_manager->GetBackgroundHostForExtension(extension_id_);
|
| +
|
| + content::ChildProcessSecurityPolicy* policy =
|
| + content::ChildProcessSecurityPolicy::GetInstance();
|
| + int renderer_id = host->render_process_host()->GetID();
|
| +
|
| + // Granting read file permission to allow reading file content.
|
| + // If the renderer already has permission to read these paths, it is not
|
| + // regranted, as this would overwrite any other permissions which the
|
| + // renderer may already have.
|
| + if (!policy->CanReadFile(renderer_id, file_path))
|
| + policy->GrantReadFile(renderer_id, file_path);
|
| +
|
| + std::string registered_name;
|
| + fileapi::IsolatedContext* isolated_context =
|
| + fileapi::IsolatedContext::GetInstance();
|
| + DCHECK(isolated_context);
|
| + std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
|
| + fileapi::kFileSystemTypeIsolated, file_path, ®istered_name);
|
| + // Granting read file system permission as well to allow file-system
|
| + // read operations.
|
| + policy->GrantReadFileSystem(renderer_id, filesystem_id);
|
| +
|
| + extensions::AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
|
| + profile(),
|
| + GetExtension(),
|
| + UTF8ToUTF16(action_id_),
|
| + filesystem_id,
|
| + registered_name);
|
| + }
|
| +
|
| + ExecuteDoneOnUIThread(true);
|
| + return;
|
| + }
|
| +
|
| extensions::EventRouter* event_router = profile()->GetExtensionEventRouter();
|
| if (!event_router) {
|
| ExecuteDoneOnUIThread(false);
|
|
|