Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/browser_thread.h" | |
| 19 #include "content/public/browser/child_process_security_policy.h" | |
| 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 void DispatchPlatformAppIntentData(ExtensionHost* host) { | |
| 32 // See if there is a command line argument. | |
| 33 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 34 CommandLine::StringVector args = command_line->GetArgs(); | |
| 35 if (!args.size()) | |
| 36 return; | |
| 37 | |
| 38 FilePath file_path(args[0]); | |
| 39 std::string mime_type; | |
| 40 { | |
| 41 // TODO(benwells): Remove this ScopedAllowIO. This should be done by | |
| 42 // delaying the creation of the render view until after the MIME type has | |
| 43 // been retrieved on the FILE thread. This should be done once the platform | |
| 44 // app startup and windowing model has settled down. | |
| 45 base::ThreadRestrictions::ScopedAllowIO allow; | |
| 46 | |
| 47 // Get the MIME type of the file. | |
| 48 if (!net::GetMimeTypeFromFile(file_path, &mime_type)) | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 // Find the intent service from the platform app for the file being opened. | |
| 53 const string16 kOpenAction = ASCIIToUTF16("http://webintents.org/view"); | |
|
James Hawkins
2012/03/28 00:59:52
Can we find a better variable name than kOpenActio
benwells
2012/03/28 04:50:27
Done.
Greg Billock
2012/03/28 14:21:02
Can you put this constant in webkit/glue/web_inten
| |
| 54 webkit_glue::WebIntentServiceData service; | |
| 55 bool found_service = false; | |
| 56 | |
| 57 std::vector<webkit_glue::WebIntentServiceData> services = | |
| 58 host->extension()->intents_services(); | |
| 59 for (size_t i = 0; i < services.size(); i++) { | |
| 60 std::string service_type_ascii = UTF16ToASCII(services[i].type); | |
| 61 if (services[i].action == kOpenAction && | |
| 62 net::MatchesMimeType(service_type_ascii, mime_type)) { | |
| 63 service = services[i]; | |
| 64 found_service = true; | |
| 65 } | |
| 66 } | |
| 67 if (!found_service) | |
| 68 return; | |
| 69 | |
| 70 // Give the app permission to use the file:// scheme. | |
|
James Hawkins
2012/03/28 00:59:52
Just to make sure I'm reading this correctly, the
benwells
2012/03/28 04:50:27
Yes that's right. I've tried to make it more obvio
Greg Billock
2012/03/28 14:21:02
Don't you just want GrantReadFile?
On 2012/03/28
benwells
2012/03/29 03:29:18
GrantReadFile doesn't do what I want, as WebKit (o
| |
| 71 using content::ChildProcessSecurityPolicy; | |
| 72 ChildProcessSecurityPolicy* policy = | |
| 73 ChildProcessSecurityPolicy::GetInstance(); | |
| 74 DCHECK(policy); | |
| 75 int child_id = host->render_process_host()->GetID(); | |
| 76 policy->GrantScheme(child_id, chrome::kFileScheme); | |
| 77 | |
| 78 // Give the renderer permission to the given URL. | |
| 79 ExtensionAPIPermissionSet apis; | |
| 80 URLPatternSet script_hosts; | |
| 81 GURL file_url(net::FilePathToFileURL(file_path)); | |
| 82 URLPattern file_url_pattern(URLPattern::SCHEME_FILE, file_url.spec()); | |
| 83 URLPatternSet explicit_hosts; | |
| 84 explicit_hosts.AddPattern(file_url_pattern); | |
| 85 host->render_process_host()->Send(new ExtensionMsg_UpdatePermissions( | |
| 86 static_cast<int>(UpdatedExtensionPermissionsInfo::ADDED), | |
| 87 host->extension()->id(), apis, explicit_hosts, script_hosts)); | |
| 88 | |
| 89 // Dispatch the intent data to the renderer. | |
| 90 string16 mime_type_utf16 = ASCIIToUTF16(mime_type); | |
| 91 webkit_glue::WebIntentData intent_data(kOpenAction, mime_type_utf16, | |
| 92 ASCIIToUTF16(file_url.spec())); | |
| 93 DirectDispatchIntent(intent_data, host->render_view_host()); | |
| 94 } | |
| 95 | |
| 96 } // namespace extensions | |
| OLD | NEW |