OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" | 5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
12 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
20 | 21 |
21 namespace { | 22 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
44 | 45 |
45 } // anonymous namespace | 46 } // anonymous namespace |
46 | 47 |
47 // static. | 48 // static. |
48 void AppEventRouter::DispatchOnLaunchedEvent( | 49 void AppEventRouter::DispatchOnLaunchedEvent( |
49 Profile* profile, const Extension* extension) { | 50 Profile* profile, const Extension* extension) { |
50 scoped_ptr<ListValue> arguments(new ListValue()); | 51 scoped_ptr<ListValue> arguments(new ListValue()); |
51 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); | 52 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); |
52 } | 53 } |
53 | 54 |
| 55 DictionaryValue* DictionaryFromSavedFileEntry( |
| 56 const app_file_handler_util::GrantedFileEntry& file_entry) { |
| 57 DictionaryValue* result = new DictionaryValue(); |
| 58 result->SetString("id", file_entry.id); |
| 59 result->SetString("fileSystemId", file_entry.filesystem_id); |
| 60 result->SetString("baseName", file_entry.registered_name); |
| 61 return result; |
| 62 } |
| 63 |
54 // static. | 64 // static. |
55 void AppEventRouter::DispatchOnRestartedEvent( | 65 void AppEventRouter::DispatchOnRestartedEvent( |
56 Profile* profile, const Extension* extension) { | 66 Profile* profile, |
| 67 const Extension* extension, |
| 68 const std::vector<app_file_handler_util::GrantedFileEntry>& file_entries) { |
| 69 ListValue* file_entries_list = new ListValue(); |
| 70 for (std::vector<extensions::app_file_handler_util::GrantedFileEntry> |
| 71 ::const_iterator it = file_entries.begin(); it != file_entries.end(); |
| 72 ++it) { |
| 73 file_entries_list->Append(DictionaryFromSavedFileEntry(*it)); |
| 74 } |
57 scoped_ptr<ListValue> arguments(new ListValue()); | 75 scoped_ptr<ListValue> arguments(new ListValue()); |
| 76 arguments->Append(file_entries_list); |
58 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass())); | 77 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass())); |
59 event->restrict_to_profile = profile; | 78 event->restrict_to_profile = profile; |
60 extensions::ExtensionSystem::Get(profile)->event_router()-> | 79 extensions::ExtensionSystem::Get(profile)->event_router()-> |
61 DispatchEventToExtension(extension->id(), event.Pass()); | 80 DispatchEventToExtension(extension->id(), event.Pass()); |
62 } | 81 } |
63 | 82 |
64 // static. | 83 // static. |
65 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 84 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
66 Profile* profile, const Extension* extension, | 85 Profile* profile, const Extension* extension, |
67 const std::string& handler_id, const std::string& mime_type, | 86 const std::string& handler_id, const std::string& mime_type, |
68 const std::string& file_system_id, const std::string& base_name) { | 87 const std::string& file_system_id, const std::string& base_name) { |
69 scoped_ptr<ListValue> args(new ListValue()); | 88 scoped_ptr<ListValue> args(new ListValue()); |
70 DictionaryValue* launch_data = new DictionaryValue(); | 89 DictionaryValue* launch_data = new DictionaryValue(); |
71 launch_data->SetString("id", handler_id); | 90 launch_data->SetString("id", handler_id); |
72 DictionaryValue* launch_item = new DictionaryValue; | 91 DictionaryValue* launch_item = new DictionaryValue; |
73 launch_item->SetString("fileSystemId", file_system_id); | 92 launch_item->SetString("fileSystemId", file_system_id); |
74 launch_item->SetString("baseName", base_name); | 93 launch_item->SetString("baseName", base_name); |
75 launch_item->SetString("mimeType", mime_type); | 94 launch_item->SetString("mimeType", mime_type); |
76 ListValue* items = new ListValue; | 95 ListValue* items = new ListValue; |
77 items->Append(launch_item); | 96 items->Append(launch_item); |
78 launch_data->Set("items", items); | 97 launch_data->Set("items", items); |
79 args->Append(launch_data); | 98 args->Append(launch_data); |
80 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); | 99 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
81 } | 100 } |
82 | 101 |
83 } // namespace extensions | 102 } // namespace extensions |
OLD | NEW |