OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "apps/browser/api/app_runtime/app_runtime_api.h" | 5 #include "apps/browser/api/app_runtime/app_runtime_api.h" |
6 | 6 |
7 #include "apps/browser/file_handler_util.h" | 7 #include "apps/browser/file_handler_util.h" |
8 #include "apps/common/api/app_runtime.h" | 8 #include "apps/common/api/app_runtime.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 scoped_ptr<base::ListValue> arguments(new base::ListValue()); | 58 scoped_ptr<base::ListValue> arguments(new base::ListValue()); |
59 scoped_ptr<Event> event( | 59 scoped_ptr<Event> event( |
60 new Event(app_runtime::OnRestarted::kEventName, arguments.Pass())); | 60 new Event(app_runtime::OnRestarted::kEventName, arguments.Pass())); |
61 event->restrict_to_browser_context = context; | 61 event->restrict_to_browser_context = context; |
62 event->can_load_ephemeral_apps = true; | 62 event->can_load_ephemeral_apps = true; |
63 extensions::EventRouter::Get(context) | 63 extensions::EventRouter::Get(context) |
64 ->DispatchEventToExtension(extension->id(), event.Pass()); | 64 ->DispatchEventToExtension(extension->id(), event.Pass()); |
65 } | 65 } |
66 | 66 |
67 // static. | 67 // static. |
68 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 68 void AppEventRouter::DispatchOnLaunchedEventWithFileEntries( |
69 BrowserContext* context, | 69 BrowserContext* context, |
70 const Extension* extension, | 70 const Extension* extension, |
71 const std::string& handler_id, | 71 const std::string& handler_id, |
72 const std::string& mime_type, | 72 const std::vector<std::string>& mime_types, |
73 const file_handler_util::GrantedFileEntry& file_entry) { | 73 const std::vector<file_handler_util::GrantedFileEntry>& file_entries) { |
74 // TODO(sergeygs): Use the same way of creating an event (using the generated | 74 // TODO(sergeygs): Use the same way of creating an event (using the generated |
75 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. | 75 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
76 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); | 76 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); |
77 launch_data->SetString("id", handler_id); | 77 launch_data->SetString("id", handler_id); |
78 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); | |
79 launch_item->SetString("fileSystemId", file_entry.filesystem_id); | |
80 launch_item->SetString("baseName", file_entry.registered_name); | |
81 launch_item->SetString("mimeType", mime_type); | |
82 launch_item->SetString("entryId", file_entry.id); | |
83 scoped_ptr<base::ListValue> items(new base::ListValue); | 78 scoped_ptr<base::ListValue> items(new base::ListValue); |
84 items->Append(launch_item.release()); | 79 DCHECK(file_entries.size() == mime_types.size()); |
| 80 for (size_t i = 0; i < file_entries.size(); ++i) { |
| 81 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); |
| 82 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); |
| 83 launch_item->SetString("baseName", file_entries[i].registered_name); |
| 84 launch_item->SetString("mimeType", mime_types[i]); |
| 85 launch_item->SetString("entryId", file_entries[i].id); |
| 86 items->Append(launch_item.release()); |
| 87 } |
85 launch_data->Set("items", items.release()); | 88 launch_data->Set("items", items.release()); |
86 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); | 89 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); |
87 } | 90 } |
88 | 91 |
89 // static. | 92 // static. |
90 void AppEventRouter::DispatchOnLaunchedEventWithUrl( | 93 void AppEventRouter::DispatchOnLaunchedEventWithUrl( |
91 BrowserContext* context, | 94 BrowserContext* context, |
92 const Extension* extension, | 95 const Extension* extension, |
93 const std::string& handler_id, | 96 const std::string& handler_id, |
94 const GURL& url, | 97 const GURL& url, |
95 const GURL& referrer_url) { | 98 const GURL& referrer_url) { |
96 api::app_runtime::LaunchData launch_data; | 99 api::app_runtime::LaunchData launch_data; |
97 launch_data.id.reset(new std::string(handler_id)); | 100 launch_data.id.reset(new std::string(handler_id)); |
98 launch_data.url.reset(new std::string(url.spec())); | 101 launch_data.url.reset(new std::string(url.spec())); |
99 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 102 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
100 DispatchOnLaunchedEventImpl( | 103 DispatchOnLaunchedEventImpl( |
101 extension->id(), launch_data.ToValue().Pass(), context); | 104 extension->id(), launch_data.ToValue().Pass(), context); |
102 } | 105 } |
103 | 106 |
104 } // namespace apps | 107 } // namespace apps |
OLD | NEW |