Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: extensions/browser/api/app_runtime/app_runtime_api.cc

Issue 2212303003: Implement app launch changes for app runtime extension proposal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tool-screenshot
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "extensions/browser/entry_info.h" 15 #include "extensions/browser/entry_info.h"
15 #include "extensions/browser/event_router.h" 16 #include "extensions/browser/event_router.h"
16 #include "extensions/browser/extension_prefs.h" 17 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/browser/extensions_browser_client.h" 18 #include "extensions/browser/extensions_browser_client.h"
18 #include "extensions/browser/granted_file_entry.h" 19 #include "extensions/browser/granted_file_entry.h"
19 #include "extensions/common/api/app_runtime.h" 20 #include "extensions/common/api/app_runtime.h"
20 #include "extensions/common/constants.h" 21 #include "extensions/common/constants.h"
21 #include "extensions/common/feature_switch.h" 22 #include "extensions/common/feature_switch.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 using content::BrowserContext; 25 using content::BrowserContext;
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 namespace app_runtime = api::app_runtime; 29 namespace app_runtime = api::app_runtime;
29 30
30 namespace { 31 namespace {
31 32
33 // Converts an ActionType instance to an app_runtime::ActionType instance.
34 app_runtime::ActionType MapActionType(ActionType action_type) {
35 switch (action_type) {
36 case ActionType::NEW_NOTE:
37 return app_runtime::ActionType::ACTION_TYPE_NEW_NOTE;
38 default:
39 return app_runtime::ActionType::ACTION_TYPE_NONE;
40 }
41 }
42
43 // Converts an ActionData instance to an app_runtime::ActionData instance.
44 std::unique_ptr<app_runtime::ActionData> BuildActionData(
45 ActionData action_data) {
46 auto data = base::WrapUnique(new app_runtime::ActionData());
47 data->action_type = MapActionType(action_data.action_type);
48 return data;
49 }
50
32 void DispatchOnEmbedRequestedEventImpl( 51 void DispatchOnEmbedRequestedEventImpl(
33 const std::string& extension_id, 52 const std::string& extension_id,
34 std::unique_ptr<base::DictionaryValue> app_embedding_request_data, 53 std::unique_ptr<base::DictionaryValue> app_embedding_request_data,
35 content::BrowserContext* context) { 54 content::BrowserContext* context) {
36 std::unique_ptr<base::ListValue> args(new base::ListValue()); 55 std::unique_ptr<base::ListValue> args(new base::ListValue());
37 args->Append(std::move(app_embedding_request_data)); 56 args->Append(std::move(app_embedding_request_data));
38 std::unique_ptr<Event> event( 57 std::unique_ptr<Event> event(
39 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED, 58 new Event(events::APP_RUNTIME_ON_EMBED_REQUESTED,
40 app_runtime::OnEmbedRequested::kEventName, std::move(args))); 59 app_runtime::OnEmbedRequested::kEventName, std::move(args)));
41 event->restrict_to_browser_context = context; 60 event->restrict_to_browser_context = context;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 case extensions::SOURCE_BACKGROUND: 128 case extensions::SOURCE_BACKGROUND:
110 return app_runtime::LAUNCH_SOURCE_BACKGROUND; 129 return app_runtime::LAUNCH_SOURCE_BACKGROUND;
111 case extensions::SOURCE_KIOSK: 130 case extensions::SOURCE_KIOSK:
112 return app_runtime::LAUNCH_SOURCE_KIOSK; 131 return app_runtime::LAUNCH_SOURCE_KIOSK;
113 case extensions::SOURCE_CHROME_INTERNAL: 132 case extensions::SOURCE_CHROME_INTERNAL:
114 return app_runtime::LAUNCH_SOURCE_CHROME_INTERNAL; 133 return app_runtime::LAUNCH_SOURCE_CHROME_INTERNAL;
115 case extensions::SOURCE_TEST: 134 case extensions::SOURCE_TEST:
116 return app_runtime::LAUNCH_SOURCE_TEST; 135 return app_runtime::LAUNCH_SOURCE_TEST;
117 case extensions::SOURCE_INSTALLED_NOTIFICATION: 136 case extensions::SOURCE_INSTALLED_NOTIFICATION:
118 return app_runtime::LAUNCH_SOURCE_INSTALLED_NOTIFICATION; 137 return app_runtime::LAUNCH_SOURCE_INSTALLED_NOTIFICATION;
138 case extensions::SOURCE_ACTION:
139 return app_runtime::LAUNCH_SOURCE_ACTION;
119 140
120 default: 141 default:
121 return app_runtime::LAUNCH_SOURCE_NONE; 142 return app_runtime::LAUNCH_SOURCE_NONE;
122 } 143 }
123 } 144 }
124 145
125 } // namespace 146 } // namespace
126 147
127 // static 148 // static
128 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( 149 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent(
129 content::BrowserContext* context, 150 content::BrowserContext* context,
130 std::unique_ptr<base::DictionaryValue> embed_app_data, 151 std::unique_ptr<base::DictionaryValue> embed_app_data,
131 const Extension* extension) { 152 const Extension* extension) {
132 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data), 153 DispatchOnEmbedRequestedEventImpl(extension->id(), std::move(embed_app_data),
133 context); 154 context);
134 } 155 }
135 156
136 // static 157 // static
137 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( 158 void AppRuntimeEventRouter::DispatchOnLaunchedEvent(
138 BrowserContext* context, 159 BrowserContext* context,
139 const Extension* extension, 160 const Extension* extension,
140 extensions::AppLaunchSource source) { 161 extensions::AppLaunchSource source,
162 base::Optional<ActionData> action_data) {
141 app_runtime::LaunchData launch_data; 163 app_runtime::LaunchData launch_data;
142 164
143 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source); 165 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source);
144 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 166 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
145 launch_data.source = source_enum; 167 launch_data.source = source_enum;
146 } 168 }
169
170 if (action_data)
171 launch_data.action_data = BuildActionData(action_data.value());
172
147 DispatchOnLaunchedEventImpl(extension->id(), source_enum, 173 DispatchOnLaunchedEventImpl(extension->id(), source_enum,
148 launch_data.ToValue(), context); 174 launch_data.ToValue(), context);
149 } 175 }
150 176
151 // static 177 // static
152 void AppRuntimeEventRouter::DispatchOnRestartedEvent( 178 void AppRuntimeEventRouter::DispatchOnRestartedEvent(
153 BrowserContext* context, 179 BrowserContext* context,
154 const Extension* extension) { 180 const Extension* extension) {
155 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); 181 std::unique_ptr<base::ListValue> arguments(new base::ListValue());
156 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED, 182 std::unique_ptr<Event> event(new Event(events::APP_RUNTIME_ON_RESTARTED,
157 app_runtime::OnRestarted::kEventName, 183 app_runtime::OnRestarted::kEventName,
158 std::move(arguments))); 184 std::move(arguments)));
159 event->restrict_to_browser_context = context; 185 event->restrict_to_browser_context = context;
160 EventRouter::Get(context) 186 EventRouter::Get(context)
161 ->DispatchEventToExtension(extension->id(), std::move(event)); 187 ->DispatchEventToExtension(extension->id(), std::move(event));
162 } 188 }
163 189
164 // static 190 // static
165 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( 191 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries(
166 BrowserContext* context, 192 BrowserContext* context,
167 const Extension* extension, 193 const Extension* extension,
194 extensions::AppLaunchSource source,
168 const std::string& handler_id, 195 const std::string& handler_id,
169 const std::vector<EntryInfo>& entries, 196 const std::vector<EntryInfo>& entries,
170 const std::vector<GrantedFileEntry>& file_entries) { 197 const std::vector<GrantedFileEntry>& file_entries,
198 base::Optional<ActionData> action_data) {
199 app_runtime::LaunchSource source_enum = getLaunchSourceEnum(source);
200
171 // TODO(sergeygs): Use the same way of creating an event (using the generated 201 // TODO(sergeygs): Use the same way of creating an event (using the generated
172 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. 202 // boilerplate) as below in DispatchOnLaunchedEventWithUrl.
173 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); 203 std::unique_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue);
174 launch_data->SetString("id", handler_id); 204 launch_data->SetString("id", handler_id);
175 205
176 app_runtime::LaunchSource source_enum =
177 app_runtime::LAUNCH_SOURCE_FILE_HANDLER;
178 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 206 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
179 launch_data->SetString("source", app_runtime::ToString(source_enum)); 207 launch_data->SetString("source", app_runtime::ToString(source_enum));
180 } 208 }
181 209
210 if (action_data) {
211 launch_data->Set("action_data",
212 BuildActionData(action_data.value())->ToValue());
213 }
214
182 std::unique_ptr<base::ListValue> items(new base::ListValue); 215 std::unique_ptr<base::ListValue> items(new base::ListValue);
183 DCHECK(file_entries.size() == entries.size()); 216 DCHECK(file_entries.size() == entries.size());
184 for (size_t i = 0; i < file_entries.size(); ++i) { 217 for (size_t i = 0; i < file_entries.size(); ++i) {
185 std::unique_ptr<base::DictionaryValue> launch_item( 218 std::unique_ptr<base::DictionaryValue> launch_item(
186 new base::DictionaryValue); 219 new base::DictionaryValue);
187 220
188 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); 221 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id);
189 launch_item->SetString("baseName", file_entries[i].registered_name); 222 launch_item->SetString("baseName", file_entries[i].registered_name);
190 launch_item->SetString("mimeType", entries[i].mime_type); 223 launch_item->SetString("mimeType", entries[i].mime_type);
191 launch_item->SetString("entryId", file_entries[i].id); 224 launch_item->SetString("entryId", file_entries[i].id);
(...skipping 19 matching lines...) Expand all
211 launch_data.url.reset(new std::string(url.spec())); 244 launch_data.url.reset(new std::string(url.spec()));
212 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); 245 launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
213 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { 246 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) {
214 launch_data.source = source_enum; 247 launch_data.source = source_enum;
215 } 248 }
216 DispatchOnLaunchedEventImpl(extension->id(), source_enum, 249 DispatchOnLaunchedEventImpl(extension->id(), source_enum,
217 launch_data.ToValue(), context); 250 launch_data.ToValue(), context);
218 } 251 }
219 252
220 } // namespace extensions 253 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698