Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed mime matching code, asserts that the mime-pattern "*" matches a blank mime-type (i.e. "*" mat… Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 396b5e9b836cd8b98e6e975bd3d9688826f87c00..93a6ac457fe52aa616224b2329a89b5a1c292733 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"
@@ -37,6 +39,7 @@
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_util.h"
+#include "webkit/fileapi/isolated_context.h"
using content::BrowserContext;
using content::BrowserThread;
@@ -118,8 +121,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)
@@ -133,7 +145,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));
@@ -188,11 +199,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) {
benwells 2012/08/27 08:02:59 Could you add a comment to explain the logic used
thorogood 2012/08/28 00:04:04 I've put the comment in front of the if statement,
+ // 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);
}
}
@@ -804,6 +831,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_)) {
benwells 2012/08/27 08:02:59 This is a bit of a monster function now. This bloc
thorogood 2012/08/29 06:34:46 I've modified platform_app_launcher to allow launc
+ 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, &registered_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);

Powered by Google App Engine
This is Rietveld 408576698