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/app_api.h" | 5 #include "chrome/browser/extensions/api/app/app_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | |
8 #include "base/string_number_conversions.h" | |
9 #include "base/time.h" | 7 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | |
11 #include "base/values.h" | 8 #include "base/values.h" |
12 #include "chrome/browser/extensions/app_notification_manager.h" | 9 #include "chrome/browser/extensions/app_notification_manager.h" |
13 #include "chrome/browser/extensions/event_router.h" | |
14 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_notification_types.h" | |
17 #include "chrome/common/extensions/extension.h" | |
18 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
19 #include "content/public/browser/notification_service.h" | |
20 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
21 #include "webkit/glue/web_intent_data.h" | |
22 | 14 |
23 namespace { | 15 namespace { |
24 | 16 |
25 const char kBodyTextKey[] = "bodyText"; | 17 const char kBodyTextKey[] = "bodyText"; |
26 const char kExtensionIdKey[] = "extensionId"; | 18 const char kExtensionIdKey[] = "extensionId"; |
27 const char kLinkTextKey[] = "linkText"; | 19 const char kLinkTextKey[] = "linkText"; |
28 const char kLinkUrlKey[] = "linkUrl"; | 20 const char kLinkUrlKey[] = "linkUrl"; |
29 const char kTitleKey[] = "title"; | 21 const char kTitleKey[] = "title"; |
30 | 22 |
31 const char kInvalidExtensionIdError[] = | 23 const char kInvalidExtensionIdError[] = |
32 "Invalid extension id"; | 24 "Invalid extension id"; |
33 const char kMissingLinkTextError[] = | 25 const char kMissingLinkTextError[] = |
34 "You must specify linkText if you use linkUrl"; | 26 "You must specify linkText if you use linkUrl"; |
35 const char kOnLaunchedEvent[] = "experimental.app.onLaunched"; | |
36 | 27 |
37 } // anonymous namespace | 28 } // anonymous namespace |
38 | 29 |
39 namespace extensions { | 30 namespace extensions { |
40 | 31 |
41 bool AppNotifyFunction::RunImpl() { | 32 bool AppNotifyFunction::RunImpl() { |
42 if (!include_incognito() && profile_->IsOffTheRecord()) { | 33 if (!include_incognito() && profile_->IsOffTheRecord()) { |
43 error_ = extension_misc::kAppNotificationsIncognitoError; | 34 error_ = extension_misc::kAppNotificationsIncognitoError; |
44 return false; | 35 return false; |
45 } | 36 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return false; | 102 return false; |
112 } | 103 } |
113 } | 104 } |
114 | 105 |
115 AppNotificationManager* manager = | 106 AppNotificationManager* manager = |
116 profile()->GetExtensionService()->app_notification_manager(); | 107 profile()->GetExtensionService()->app_notification_manager(); |
117 manager->ClearAll(id); | 108 manager->ClearAll(id); |
118 return true; | 109 return true; |
119 } | 110 } |
120 | 111 |
121 // static. | |
122 void AppEventRouter::DispatchOnLaunchedEvent( | |
123 Profile* profile, const Extension* extension) { | |
124 scoped_ptr<ListValue> arguments(new ListValue()); | |
125 profile->GetExtensionEventRouter()->DispatchEventToExtension( | |
126 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); | |
127 } | |
128 | |
129 // static. | |
130 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | |
131 Profile* profile, const Extension* extension, const string16& action, | |
132 const std::string& file_system_id, const std::string& base_name) { | |
133 scoped_ptr<ListValue> args(new ListValue()); | |
134 DictionaryValue* launch_data = new DictionaryValue(); | |
135 DictionaryValue* intent = new DictionaryValue(); | |
136 intent->SetString("action", UTF16ToUTF8(action)); | |
137 intent->SetString("type", "chrome-extension://fileentry"); | |
138 launch_data->Set("intent", intent); | |
139 args->Append(launch_data); | |
140 DictionaryValue* intent_data = new DictionaryValue(); | |
141 intent_data->SetString("format", "fileEntry"); | |
142 intent_data->SetString("fileSystemId", file_system_id); | |
143 intent_data->SetString("baseName", base_name); | |
144 args->Append(intent_data); | |
145 profile->GetExtensionEventRouter()->DispatchEventToExtension( | |
146 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | |
147 } | |
148 | |
149 // static. | |
150 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | |
151 Profile* profile, const Extension* extension, | |
152 const webkit_glue::WebIntentData web_intent_data) { | |
153 scoped_ptr<ListValue> args(new ListValue()); | |
154 DictionaryValue* launch_data = new DictionaryValue(); | |
155 DictionaryValue* intent = new DictionaryValue(); | |
156 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); | |
157 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); | |
158 launch_data->Set("intent", intent); | |
159 args->Append(launch_data); | |
160 DictionaryValue* intent_data; | |
161 switch (web_intent_data.data_type) { | |
162 case webkit_glue::WebIntentData::SERIALIZED: | |
163 intent_data = new DictionaryValue(); | |
164 intent_data->SetString("format", "serialized"); | |
165 intent_data->SetString("data", UTF16ToUTF8(web_intent_data.data)); | |
166 args->Append(intent_data); | |
167 break; | |
168 case webkit_glue::WebIntentData::UNSERIALIZED: | |
169 intent->SetString("data", UTF16ToUTF8(web_intent_data.unserialized_data)); | |
170 break; | |
171 case webkit_glue::WebIntentData::BLOB: | |
172 intent_data = new DictionaryValue(); | |
173 intent_data->SetString("format", "blob"); | |
174 intent_data->SetString("blobFileName", web_intent_data.blob_file.value()); | |
175 intent_data->SetString("blobLength", | |
176 base::Int64ToString(web_intent_data.blob_length)); | |
177 args->Append(intent_data); | |
178 break; | |
179 default: | |
180 NOTREACHED(); | |
181 break; | |
182 } | |
183 profile->GetExtensionEventRouter()->DispatchEventToExtension( | |
184 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | |
185 } | |
186 | |
187 } // namespace extensions | 112 } // namespace extensions |
OLD | NEW |