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

Unified Diff: chrome/browser/extensions/platform_app_intent_dispatcher.cc

Issue 9845003: Pass command line arguments onto platform apps which provide the right intent. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Include files Created 8 years, 9 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/extensions/platform_app_intent_dispatcher.cc
diff --git a/chrome/browser/extensions/platform_app_intent_dispatcher.cc b/chrome/browser/extensions/platform_app_intent_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f6e5ecf339f28a85b04da4ee65bc2f434db2ddbc
--- /dev/null
+++ b/chrome/browser/extensions/platform_app_intent_dispatcher.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/platform_app_intent_dispatcher.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/string16.h"
+#include "base/threading/thread_restrictions.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/common/extensions/extension_messages.h"
+#include "chrome/common/extensions/url_pattern.h"
+#include "chrome/common/extensions/url_pattern_set.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_intents_dispatcher.h"
+#include "content/public/common/url_constants.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/mime_util.h"
+#include "net/base/net_util.h"
+#include "webkit/glue/web_intent_data.h"
+#include "webkit/glue/web_intent_service_data.h"
+
+namespace extensions {
+
+void DispatchPlatformAppIntentData(ExtensionHost* host) {
+ // See if there is a command line argument.
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ CommandLine::StringVector args = command_line->GetArgs();
+ if (!args.size())
+ return;
+
+ FilePath file_path(args[0]);
+ std::string mime_type;
+ {
+ // TODO(benwells): Remove this ScopedAllowIO. This should be done by
+ // delaying the creation of the render view until after the MIME type has
+ // been retrieved on the FILE thread. This should be done once the platform
+ // app startup and windowing model has settled down.
+ base::ThreadRestrictions::ScopedAllowIO allow;
+
+ // Get the MIME type of the file.
+ if (!net::GetMimeTypeFromFile(file_path, &mime_type))
+ return;
+ }
+
+ // Find the intent service from the platform app for the file being opened.
+ const string16 kViewAction = ASCIIToUTF16("http://webintents.org/view");
+ webkit_glue::WebIntentServiceData service;
+ bool found_service = false;
+
+ std::vector<webkit_glue::WebIntentServiceData> services =
+ host->extension()->intents_services();
+ for (size_t i = 0; i < services.size(); i++) {
+ std::string service_type_ascii = UTF16ToASCII(services[i].type);
+ if (services[i].action == kViewAction &&
+ net::MatchesMimeType(service_type_ascii, mime_type)) {
+ service = services[i];
+ found_service = true;
+ }
+ }
+ if (!found_service)
+ return;
+
+ // Give the app permission to use the file:// scheme. This alone gives the
+ // browser process permission to handle URLs of this scheme, but does not
+ // change any cross origin security policies.
+ using content::ChildProcessSecurityPolicy;
+ ChildProcessSecurityPolicy* policy =
+ ChildProcessSecurityPolicy::GetInstance();
+ DCHECK(policy);
+ int child_id = host->render_process_host()->GetID();
+ policy->GrantScheme(child_id, chrome::kFileScheme);
+
+ // Give the renderer permission to the given URL. This updates the renderer
+ // process's cross origin policy to allow the access to this particular file
+ // URL, but only from the platform app extension page.
+ ExtensionAPIPermissionSet apis;
+ URLPatternSet script_hosts;
+ GURL file_url(net::FilePathToFileURL(file_path));
+ URLPattern file_url_pattern(URLPattern::SCHEME_FILE, file_url.spec());
+ URLPatternSet explicit_hosts;
+ explicit_hosts.AddPattern(file_url_pattern);
+ host->render_process_host()->Send(new ExtensionMsg_UpdatePermissions(
+ static_cast<int>(UpdatedExtensionPermissionsInfo::ADDED),
+ host->extension()->id(), apis, explicit_hosts, script_hosts));
+
+ // Dispatch the intent data to the renderer.
+ string16 mime_type_utf16 = ASCIIToUTF16(mime_type);
+ webkit_glue::WebIntentData intent_data(kViewAction, mime_type_utf16,
+ ASCIIToUTF16(file_url.spec()));
+ DirectDispatchIntent(intent_data, host->render_view_host());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698