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

Side by Side 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: Use ScopedAllowIO to avoid race, don't check file existence, windows compile fix 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/platform_app_intent_dispatcher.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/string16.h"
12 #include "base/threading/thread_restrictions.h"
13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/extensions/extension_host.h"
15 #include "chrome/common/extensions/extension_messages.h"
16 #include "chrome/common/extensions/url_pattern.h"
17 #include "chrome/common/extensions/url_pattern_set.h"
18 #include "content/public/browser/child_process_security_policy.h"
19 #include "content/public/browser/browser_thread.h"
James Hawkins 2012/03/26 19:55:57 nit: Alphabetize includes.
benwells 2012/03/27 04:24:12 Done.
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_intents_dispatcher.h"
22 #include "content/public/common/url_constants.h"
23 #include "googleurl/src/gurl.h"
24 #include "net/base/mime_util.h"
25 #include "net/base/net_util.h"
26 #include "webkit/glue/web_intent_data.h"
27 #include "webkit/glue/web_intent_service_data.h"
28
29 namespace extensions {
30
31 // static
32 void PlatformAppIntentDispatcher::DispatchIntentData(ExtensionHost* host) {
33 scoped_refptr<PlatformAppIntentDispatcher> dispatcher =
34 new PlatformAppIntentDispatcher(host);
35 dispatcher->DoDispatchIntentData();
36 }
37
38 PlatformAppIntentDispatcher::PlatformAppIntentDispatcher(ExtensionHost* host)
39 : host_(host) {}
40
41 void PlatformAppIntentDispatcher::DoDispatchIntentData() {
42 // See if we have a command line argument.
James Hawkins 2012/03/26 19:55:57 nit: Don't use 'we' (or pronouns in general) in co
benwells 2012/03/27 04:24:12 Done.
43 CommandLine* command_line = CommandLine::ForCurrentProcess();
44 CommandLine::StringVector args = command_line->GetArgs();
45 if (!args.size())
46 return;
47
48 FilePath file_path(args[0]);
49 std::string mime_type;
50 {
51 // TODO(benwells): Remove this ScopedAllowIO. This should be done by
52 // delaying the creation of the render view until after the MIME type has
53 // been retrieved on the FILE thread. This should be done once the platform
54 // app startup and windowing model has settled down.
55 base::ThreadRestrictions::ScopedAllowIO allow;
56
57 // Get the MIME type of the file.
58 if (!net::GetMimeTypeFromFile(file_path, &mime_type))
59 return;
60 }
61
62 // Find the intent service from the platform app for the file being opened.
63 const string16 open_action = ASCIIToUTF16("http://webintents.org/view");
James Hawkins 2012/03/26 19:55:57 s/open_action/kOpenAction/ for const variable.
benwells 2012/03/27 04:24:12 Done.
64 webkit_glue::WebIntentServiceData service;
65 bool found_service = false;
66
67 std::vector<webkit_glue::WebIntentServiceData> services =
68 host_->extension()->intents_services();
69 for (size_t i = 0; i < services.size(); i++) {
70 std::string service_type_ascii = UTF16ToASCII(services[i].type);
71 if (services[i].action == open_action &&
72 net::MatchesMimeType(service_type_ascii, mime_type)) {
73 service = services[i];
74 found_service = true;
75 }
76 }
77 if (!found_service)
78 return;
79
80 // Give the app permission to use the file:// scheme.
81 using content::ChildProcessSecurityPolicy;
82 ChildProcessSecurityPolicy* policy =
83 ChildProcessSecurityPolicy::GetInstance();
84 DCHECK(policy);
85 int child_id = host_->render_process_host()->GetID();
86 policy->GrantScheme(child_id, chrome::kFileScheme);
87
88 // Give the renderer permission to the given URL.
89 ExtensionAPIPermissionSet apis; // empty
James Hawkins 2012/03/26 19:55:57 nit: Two spaces before start of comments. Though
benwells 2012/03/27 04:24:12 Done (comment removed).
90 URLPatternSet script_hosts; // empty
91 GURL file_url(net::FilePathToFileURL(file_path));
92 URLPattern file_url_pattern(URLPattern::SCHEME_FILE, file_url.spec());
93 URLPatternSet explicit_hosts;
94 explicit_hosts.AddPattern(file_url_pattern);
95 host_->render_process_host()->Send(new ExtensionMsg_UpdatePermissions(
96 static_cast<int>(UpdatedExtensionPermissionsInfo::ADDED),
97 host_->extension()->id(),
James Hawkins 2012/03/26 19:55:57 Optional nit: Can save lines by moving parameters
benwells 2012/03/27 04:24:12 Done.
98 apis,
99 explicit_hosts,
100 script_hosts));
101
102 // Dispatch the intent data to the renderer.
103 string16 mime_type_utf16 = ASCIIToUTF16(mime_type);
104 webkit_glue::WebIntentData intent_data(open_action, mime_type_utf16,
105 ASCIIToUTF16(file_url.spec()));
106 DirectDispatchIntent(intent_data, host_->render_view_host());
107 }
108
109 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698