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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 } // anonymous namespace | 46 } // anonymous namespace |
47 | 47 |
48 // static. | 48 // static. |
49 void AppEventRouter::DispatchOnLaunchedEvent( | 49 void AppEventRouter::DispatchOnLaunchedEvent( |
50 Profile* profile, const Extension* extension) { | 50 Profile* profile, const Extension* extension) { |
51 scoped_ptr<ListValue> arguments(new ListValue()); | 51 scoped_ptr<ListValue> arguments(new ListValue()); |
52 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); | 52 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); |
53 } | 53 } |
54 | 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 | |
64 // static. | 55 // static. |
65 void AppEventRouter::DispatchOnRestartedEvent( | 56 void AppEventRouter::DispatchOnRestartedEvent(Profile* profile, |
66 Profile* profile, | 57 const Extension* extension) { |
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 } | |
75 scoped_ptr<ListValue> arguments(new ListValue()); | 58 scoped_ptr<ListValue> arguments(new ListValue()); |
76 arguments->Append(file_entries_list); | |
77 scoped_ptr<Event> event(new Event(kOnRestarted, arguments.Pass())); | 59 scoped_ptr<Event> event(new Event(kOnRestarted, arguments.Pass())); |
78 event->restrict_to_profile = profile; | 60 event->restrict_to_profile = profile; |
79 extensions::ExtensionSystem::Get(profile)->event_router()-> | 61 extensions::ExtensionSystem::Get(profile)->event_router()-> |
80 DispatchEventToExtension(extension->id(), event.Pass()); | 62 DispatchEventToExtension(extension->id(), event.Pass()); |
81 } | 63 } |
82 | 64 |
83 // static. | 65 // static. |
84 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 66 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
85 Profile* profile, const Extension* extension, | 67 Profile* profile, const Extension* extension, |
86 const std::string& handler_id, const std::string& mime_type, | 68 const std::string& handler_id, const std::string& mime_type, |
87 const extensions::app_file_handler_util::GrantedFileEntry& file_entry) { | 69 const extensions::app_file_handler_util::GrantedFileEntry& file_entry) { |
88 scoped_ptr<ListValue> args(new ListValue()); | 70 scoped_ptr<ListValue> args(new ListValue()); |
89 DictionaryValue* launch_data = new DictionaryValue(); | 71 DictionaryValue* launch_data = new DictionaryValue(); |
90 launch_data->SetString("id", handler_id); | 72 launch_data->SetString("id", handler_id); |
91 DictionaryValue* launch_item = new DictionaryValue; | 73 DictionaryValue* launch_item = new DictionaryValue; |
92 launch_item->SetString("fileSystemId", file_entry.filesystem_id); | 74 launch_item->SetString("fileSystemId", file_entry.filesystem_id); |
93 launch_item->SetString("baseName", file_entry.registered_name); | 75 launch_item->SetString("baseName", file_entry.registered_name); |
94 launch_item->SetString("mimeType", mime_type); | 76 launch_item->SetString("mimeType", mime_type); |
95 launch_item->SetString("entryId", file_entry.id); | 77 launch_item->SetString("entryId", file_entry.id); |
96 ListValue* items = new ListValue; | 78 ListValue* items = new ListValue; |
97 items->Append(launch_item); | 79 items->Append(launch_item); |
98 launch_data->Set("items", items); | 80 launch_data->Set("items", items); |
99 args->Append(launch_data); | 81 args->Append(launch_data); |
100 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); | 82 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); |
101 } | 83 } |
102 | 84 |
103 } // namespace extensions | 85 } // namespace extensions |
OLD | NEW |