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 "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/browser/event_router.h" | 9 #include "extensions/browser/event_router.h" |
10 #include "extensions/browser/extension_prefs.h" | 10 #include "extensions/browser/extension_prefs.h" |
11 #include "extensions/browser/extension_system.h" | 11 #include "extensions/browser/extension_system.h" |
12 #include "extensions/browser/extensions_browser_client.h" | 12 #include "extensions/browser/extensions_browser_client.h" |
13 #include "extensions/browser/granted_file_entry.h" | 13 #include "extensions/browser/granted_file_entry.h" |
14 #include "extensions/common/api/app_runtime.h" | 14 #include "extensions/common/api/app_runtime.h" |
15 #include "extensions/common/constants.h" | |
16 #include "extensions/common/feature_switch.h" | |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 | 18 |
17 using content::BrowserContext; | 19 using content::BrowserContext; |
18 | 20 |
19 namespace extensions { | 21 namespace extensions { |
20 | 22 |
21 namespace app_runtime = core_api::app_runtime; | 23 namespace app_runtime = core_api::app_runtime; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
(...skipping 25 matching lines...) Expand all Loading... | |
50 args->Append(launch_data.release()); | 52 args->Append(launch_data.release()); |
51 scoped_ptr<Event> event( | 53 scoped_ptr<Event> event( |
52 new Event(app_runtime::OnLaunched::kEventName, args.Pass())); | 54 new Event(app_runtime::OnLaunched::kEventName, args.Pass())); |
53 event->restrict_to_browser_context = context; | 55 event->restrict_to_browser_context = context; |
54 EventRouter::Get(context) | 56 EventRouter::Get(context) |
55 ->DispatchEventWithLazyListener(extension_id, event.Pass()); | 57 ->DispatchEventWithLazyListener(extension_id, event.Pass()); |
56 ExtensionPrefs::Get(context) | 58 ExtensionPrefs::Get(context) |
57 ->SetLastLaunchTime(extension_id, base::Time::Now()); | 59 ->SetLastLaunchTime(extension_id, base::Time::Now()); |
58 } | 60 } |
59 | 61 |
62 app_runtime::LaunchSource getLaunchSourceEnum( | |
63 extensions::AppLaunchSource source) { | |
64 switch (source) { | |
65 case extensions::SOURCE_APP_LAUNCHER: | |
benwells
2014/10/28 21:22:48
Can you do this with an array lookup instead?
cylee1
2014/10/29 16:39:59
Could you give me an example? Do you mean defining
benwells
2014/10/30 06:04:28
OK fair enough.
| |
66 return app_runtime::LAUNCH_SOURCE_APP_LAUNCHER; | |
67 case extensions::SOURCE_NEW_TAB_PAGE: | |
68 return app_runtime::LAUNCH_SOURCE_NEW_TAB_PAGE; | |
69 case extensions::SOURCE_RELOAD: | |
70 return app_runtime::LAUNCH_SOURCE_RELOAD; | |
71 case extensions::SOURCE_RESTART: | |
72 return app_runtime::LAUNCH_SOURCE_RESTART; | |
73 case extensions::SOURCE_LOAD_AND_LAUNCH: | |
74 return app_runtime::LAUNCH_SOURCE_LOAD_AND_LAUNCH; | |
75 case extensions::SOURCE_FILE_HANDLER: | |
76 return app_runtime::LAUNCH_SOURCE_FILE_HANDLER; | |
77 case extensions::SOURCE_URL_HANDLER: | |
78 return app_runtime::LAUNCH_SOURCE_URL_HANDLER; | |
79 | |
80 case extensions::SOURCE_ATHENA: | |
81 return app_runtime::LAUNCH_SOURCE_ATHENA; | |
82 case extensions::SOURCE_WIN_METRO: | |
83 return app_runtime::LAUNCH_SOURCE_WIN_METRO; | |
84 | |
85 case extensions::SOURCE_SYSTEM_TRAY: | |
86 return app_runtime::LAUNCH_SOURCE_SYSTEM_TRAY; | |
87 case extensions::SOURCE_ABOUT_PAGE: | |
88 return app_runtime::LAUNCH_SOURCE_ABOUT_PAGE; | |
89 case extensions::SOURCE_KEYBOARD: | |
90 return app_runtime::LAUNCH_SOURCE_KEYBOARD; | |
91 | |
92 default: | |
93 return app_runtime::LAUNCH_SOURCE_NONE; | |
94 } | |
95 } | |
96 | |
60 } // namespace | 97 } // namespace |
61 | 98 |
62 // static | 99 // static |
63 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 100 void AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
64 content::BrowserContext* context, | 101 content::BrowserContext* context, |
65 scoped_ptr<base::DictionaryValue> embed_app_data, | 102 scoped_ptr<base::DictionaryValue> embed_app_data, |
66 const Extension* extension) { | 103 const Extension* extension) { |
67 DispatchOnEmbedRequestedEventImpl( | 104 DispatchOnEmbedRequestedEventImpl( |
68 extension->id(), embed_app_data.Pass(), context); | 105 extension->id(), embed_app_data.Pass(), context); |
69 } | 106 } |
70 | 107 |
71 // static | 108 // static |
72 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( | 109 void AppRuntimeEventRouter::DispatchOnLaunchedEvent( |
73 BrowserContext* context, | 110 BrowserContext* context, |
74 const Extension* extension) { | 111 const Extension* extension, |
75 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue()); | 112 extensions::AppLaunchSource source) { |
76 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); | 113 app_runtime::LaunchData launch_data; |
benwells
2014/10/28 21:22:48
It would be great to do some UMA logging here of t
cylee1
2014/10/29 16:40:00
Added in DispatchOnLaunchedEventImpl to handle res
| |
114 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | |
115 launch_data.source = getLaunchSourceEnum(source); | |
116 } | |
117 DispatchOnLaunchedEventImpl( | |
118 extension->id(), launch_data.ToValue().Pass(), context); | |
77 } | 119 } |
78 | 120 |
79 // static | 121 // static |
80 void AppRuntimeEventRouter::DispatchOnRestartedEvent( | 122 void AppRuntimeEventRouter::DispatchOnRestartedEvent( |
81 BrowserContext* context, | 123 BrowserContext* context, |
82 const Extension* extension) { | 124 const Extension* extension) { |
83 scoped_ptr<base::ListValue> arguments(new base::ListValue()); | 125 scoped_ptr<base::ListValue> arguments(new base::ListValue()); |
84 scoped_ptr<Event> event( | 126 scoped_ptr<Event> event( |
85 new Event(app_runtime::OnRestarted::kEventName, arguments.Pass())); | 127 new Event(app_runtime::OnRestarted::kEventName, arguments.Pass())); |
86 event->restrict_to_browser_context = context; | 128 event->restrict_to_browser_context = context; |
87 EventRouter::Get(context) | 129 EventRouter::Get(context) |
88 ->DispatchEventToExtension(extension->id(), event.Pass()); | 130 ->DispatchEventToExtension(extension->id(), event.Pass()); |
89 } | 131 } |
90 | 132 |
91 // static | 133 // static |
92 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( | 134 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithFileEntries( |
93 BrowserContext* context, | 135 BrowserContext* context, |
94 const Extension* extension, | 136 const Extension* extension, |
95 const std::string& handler_id, | 137 const std::string& handler_id, |
96 const std::vector<std::string>& mime_types, | 138 const std::vector<std::string>& mime_types, |
97 const std::vector<GrantedFileEntry>& file_entries) { | 139 const std::vector<GrantedFileEntry>& file_entries) { |
98 // TODO(sergeygs): Use the same way of creating an event (using the generated | 140 // TODO(sergeygs): Use the same way of creating an event (using the generated |
99 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. | 141 // boilerplate) as below in DispatchOnLaunchedEventWithUrl. |
100 scoped_ptr<base::DictionaryValue> launch_data(new base::DictionaryValue); | 142 base::DictionaryValue* launch_data = new base::DictionaryValue(); |
benwells
2014/10/28 21:22:47
Why change this?
cylee1
2014/10/29 16:39:59
Because the ownership is meant to be transferred w
benwells
2014/10/30 06:04:28
If you want to change that please do it in another
cylee1
2014/10/30 13:03:43
Done.
| |
101 launch_data->SetString("id", handler_id); | 143 launch_data->SetString("id", handler_id); |
102 scoped_ptr<base::ListValue> items(new base::ListValue); | 144 launch_data->SetString( |
benwells
2014/10/28 21:22:48
Shouldn't this be gated on the feature switch too?
cylee1
2014/10/29 16:40:00
Was there but accidentally removed
Done.
| |
145 "source", app_runtime::ToString(app_runtime::LAUNCH_SOURCE_FILE_HANDLER)); | |
146 | |
147 base::ListValue* items = new base::ListValue(); | |
benwells
2014/10/28 21:22:48
Why is this all changing?
cylee1
2014/10/29 16:39:59
replied above
| |
103 DCHECK(file_entries.size() == mime_types.size()); | 148 DCHECK(file_entries.size() == mime_types.size()); |
104 for (size_t i = 0; i < file_entries.size(); ++i) { | 149 for (size_t i = 0; i < file_entries.size(); ++i) { |
105 scoped_ptr<base::DictionaryValue> launch_item(new base::DictionaryValue); | 150 base::DictionaryValue* launch_item = new base::DictionaryValue(); |
106 launch_item->SetString("fileSystemId", file_entries[i].filesystem_id); | 151 |
107 launch_item->SetString("baseName", file_entries[i].registered_name); | 152 base::DictionaryValue* raw_entry = new base::DictionaryValue(); |
108 launch_item->SetString("mimeType", mime_types[i]); | 153 raw_entry->SetString("fileSystemId", file_entries[i].filesystem_id); |
109 launch_item->SetString("entryId", file_entries[i].id); | 154 raw_entry->SetString("baseName", file_entries[i].registered_name); |
110 items->Append(launch_item.release()); | 155 raw_entry->SetString("entryId", file_entries[i].id); |
156 | |
157 launch_item->Set("rawEntry", raw_entry); | |
158 launch_item->SetString("type", mime_types[i]); | |
159 | |
160 items->Append(launch_item); | |
111 } | 161 } |
112 launch_data->Set("items", items.release()); | 162 launch_data->Set("items", items); |
113 DispatchOnLaunchedEventImpl(extension->id(), launch_data.Pass(), context); | 163 DispatchOnLaunchedEventImpl( |
164 extension->id(), | |
165 scoped_ptr<base::DictionaryValue>(launch_data).Pass(), | |
166 context); | |
114 } | 167 } |
115 | 168 |
116 // static | 169 // static |
117 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( | 170 void AppRuntimeEventRouter::DispatchOnLaunchedEventWithUrl( |
118 BrowserContext* context, | 171 BrowserContext* context, |
119 const Extension* extension, | 172 const Extension* extension, |
120 const std::string& handler_id, | 173 const std::string& handler_id, |
121 const GURL& url, | 174 const GURL& url, |
122 const GURL& referrer_url) { | 175 const GURL& referrer_url) { |
123 app_runtime::LaunchData launch_data; | 176 app_runtime::LaunchData launch_data; |
124 launch_data.id.reset(new std::string(handler_id)); | 177 launch_data.id.reset(new std::string(handler_id)); |
125 launch_data.url.reset(new std::string(url.spec())); | 178 launch_data.url.reset(new std::string(url.spec())); |
126 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); | 179 launch_data.referrer_url.reset(new std::string(referrer_url.spec())); |
180 if (extensions::FeatureSwitch::trace_app_source()->IsEnabled()) { | |
181 launch_data.source = app_runtime::LAUNCH_SOURCE_URL_HANDLER; | |
182 } | |
127 DispatchOnLaunchedEventImpl( | 183 DispatchOnLaunchedEventImpl( |
128 extension->id(), launch_data.ToValue().Pass(), context); | 184 extension->id(), launch_data.ToValue().Pass(), context); |
129 } | 185 } |
130 | 186 |
131 } // namespace extensions | 187 } // namespace extensions |
OLD | NEW |