| 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 "extensions/browser/api/app_runtime/app_runtime_api.h" | 5 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_LAUNCHED, | 68 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_LAUNCHED, |
| 69 app_runtime::OnLaunched::kEventName, | 69 app_runtime::OnLaunched::kEventName, |
| 70 std::move(args))); | 70 std::move(args))); |
| 71 event->restrict_to_browser_context = context; | 71 event->restrict_to_browser_context = context; |
| 72 EventRouter::Get(context) | 72 EventRouter::Get(context) |
| 73 ->DispatchEventWithLazyListener(extension_id, std::move(event)); | 73 ->DispatchEventWithLazyListener(extension_id, std::move(event)); |
| 74 ExtensionPrefs::Get(context) | 74 ExtensionPrefs::Get(context) |
| 75 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 75 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 app_runtime::LaunchSource getLaunchSourceEnum( | 78 app_runtime::LaunchSource GetLaunchSourceEnum( |
| 79 extensions::AppLaunchSource source) { | 79 extensions::AppLaunchSource source) { |
| 80 switch (source) { | 80 switch (source) { |
| 81 case extensions::SOURCE_APP_LAUNCHER: | 81 case extensions::SOURCE_APP_LAUNCHER: |
| 82 return app_runtime::LAUNCH_SOURCE_APP_LAUNCHER; | 82 return app_runtime::LAUNCH_SOURCE_APP_LAUNCHER; |
| 83 case extensions::SOURCE_NEW_TAB_PAGE: | 83 case extensions::SOURCE_NEW_TAB_PAGE: |
| 84 return app_runtime::LAUNCH_SOURCE_NEW_TAB_PAGE; | 84 return app_runtime::LAUNCH_SOURCE_NEW_TAB_PAGE; |
| 85 case extensions::SOURCE_RELOAD: | 85 case extensions::SOURCE_RELOAD: |
| 86 return app_runtime::LAUNCH_SOURCE_RELOAD; | 86 return app_runtime::LAUNCH_SOURCE_RELOAD; |
| 87 case extensions::SOURCE_RESTART: | 87 case extensions::SOURCE_RESTART: |
| 88 return app_runtime::LAUNCH_SOURCE_RESTART; | 88 return app_runtime::LAUNCH_SOURCE_RESTART; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 std::unique_ptr<base::DictionaryValue> embed_app_data, | 130 std::unique_ptr<base::DictionaryValue> embed_app_data, |
| 131 const Extension* extension) { | 131 const Extension* extension) { |
| 132 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), | 132 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), |
| 133 context); | 133 context); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | 136 // static |
| 137 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 137 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
| 138 BrowserContext* context, | 138 BrowserContext* context, |
| 139 const Extension* extension, | 139 const Extension* extension, |
| 140 extensions::AppLaunchSource source) { | 140 extensions::AppLaunchSource source, |
| 141 std::unique_ptr<app_runtime::ActionData> action_data) { |
| 141 app_runtime::LaunchData launch_data; | 142 app_runtime::LaunchData launch_data; |
| 142 | 143 |
| 143 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); | 144 app_runtime::LaunchSource source_enum = GetLaunchSourceEnum(source); |
| 144 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 145 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 145 launch_data.source = source_enum; | 146 launch_data.source = source_enum; |
| 146 } | 147 } |
| 148 |
| 149 launch_data.action_data = std::move(action_data); |
| 150 |
| 147 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 151 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 148 launch_data.ToValue(), context); | 152 launch_data.ToValue(), context); |
| 149 } | 153 } |
| 150 | 154 |
| 151 // static | 155 // static |
| 152 void AppRuntimeEventRouter::DispatchOnRestartedEvent( | 156 void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
| 153 BrowserContext* context, | 157 BrowserContext* context, |
| 154 const Extension* extension) { | 158 const Extension* extension) { |
| 155 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); | 159 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); |
| 156 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, | 160 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, |
| 157 app_runtime::OnRestarted::kEventName, | 161 app_runtime::OnRestarted::kEventName, |
| 158 std::move(arguments))); | 162 std::move(arguments))); |
| 159 event->restrict_to_browser_context = context; | 163 event->restrict_to_browser_context = context; |
| 160 EventRouter::Get(context) | 164 EventRouter::Get(context) |
| 161 ->DispatchEventToExtension(extension->id(), std::move(event)); | 165 ->DispatchEventToExtension(extension->id(), std::move(event)); |
| 162 } | 166 } |
| 163 | 167 |
| 164 // static | 168 // static |
| 165 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 169 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
| 166 BrowserContext* context, | 170 BrowserContext* context, |
| 167 const Extension* extension, | 171 const Extension* extension, |
| 172 extensions::AppLaunchSource source, |
| 168 const std::string& handler_id, | 173 const std::string& handler_id, |
| 169 const std::vector<EntryInfo>& entries, | 174 const std::vector<EntryInfo>& entries, |
| 170 const std::vector<GrantedFileEntry>& file_entries) { | 175 const std::vector<GrantedFileEntry>& file_entries, |
| 176 std::unique_ptr<app_runtime::ActionData> action_data) { |
| 177 app_runtime::LaunchSource source_enum = GetLaunchSourceEnum(source); |
| 178 |
| 171 // TODO(sergeygs): Use the same way of creating an event (using the generated | 179 // TODO(sergeygs): Use the same way of creating an event (using the generated |
| 172 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. | 180 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
| 173 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); | 181 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); |
| 174 launch_data->SetString("id", handler_id); | 182 launch_data->SetString("id", handler_id); |
| 175 | 183 |
| 176 app_runtime::LaunchSource source_enum = | |
| 177 app_runtime::LAUNCH_SOURCE_FILE_HANDLER; | |
| 178 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 184 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 179 launch_data->SetString("source", app_runtime::ToString(source_enum)); | 185 launch_data->SetString("source", app_runtime::ToString(source_enum)); |
| 180 } | 186 } |
| 181 | 187 |
| 188 if (action_data) |
| 189 launch_data->Set("actionData", action_data->ToValue()); |
| 190 |
| 182 std::unique_ptr<base::ListValue> items(new base::ListValue); | 191 std::unique_ptr<base::ListValue> items(new base::ListValue); |
| 183 DCHECK(file_entries.size() == entries.size()); | 192 DCHECK(file_entries.size() == entries.size()); |
| 184 for (size_t i = 0; i < file_entries.size(); ++i) { | 193 for (size_t i = 0; i < file_entries.size(); ++i) { |
| 185 std::unique_ptr<base::DictionaryValue> launch_item( | 194 std::unique_ptr<base::DictionaryValue> launch_item( |
| 186 new base::DictionaryValue); | 195 new base::DictionaryValue); |
| 187 | 196 |
| 197 // TODO: The launch item type should be documented in the idl so that this |
| 198 // entire function can be strongly typed and built using an |
| 199 // app_runtime::LaunchData instance. |
| 188 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); | 200 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); |
| 189 launch_item->SetString("baseName", file_entries[i].registered_name); | 201 launch_item->SetString("baseName", file_entries[i].registered_name); |
| 190 launch_item->SetString("mimeType", entries[i].mime_type); | 202 launch_item->SetString("mimeType", entries[i].mime_type); |
| 191 launch_item->SetString("entryId", file_entries[i].id); | 203 launch_item->SetString("entryId", file_entries[i].id); |
| 192 launch_item->SetBoolean("isDirectory", entries[i].is_directory); | 204 launch_item->SetBoolean("isDirectory", entries[i].is_directory); |
| 193 items->Append(std::move(launch_item)); | 205 items->Append(std::move(launch_item)); |
| 194 } | 206 } |
| 195 launch_data->Set("items", items.release()); | 207 launch_data->Set("items", items.release()); |
| 196 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 208 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 197 std::move(launch_data), context); | 209 std::move(launch_data), context); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 211 launch_data.url.reset(new std::string(url.spec())); | 223 launch_data.url.reset(new std::string(url.spec())); |
| 212 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 224 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
| 213 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | 225 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { |
| 214 launch_data.source = source_enum; | 226 launch_data.source = source_enum; |
| 215 } | 227 } |
| 216 DispatchOnLaunchedEventImpl(extension->id(), source_enum, | 228 DispatchOnLaunchedEventImpl(extension->id(), source_enum, |
| 217 launch_data.ToValue(), context); | 229 launch_data.ToValue(), context); |
| 218 } | 230 } |
| 219 | 231 |
| 220 } // namespace extensions | 232 } // namespace extensions |
| OLD | NEW |