Chromium Code Reviews| 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" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/app_notification_manager.h" | 12 #include "chrome/browser/extensions/app_notification_manager.h" |
| 13 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/web_intent_callbacks.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/web_intents_dispatcher.h" | |
| 20 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 21 #include "webkit/glue/web_intent_data.h" | 23 #include "webkit/glue/web_intent_data.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 const char kBodyTextKey[] = "bodyText"; | 27 const char kBodyTextKey[] = "bodyText"; |
| 26 const char kExtensionIdKey[] = "extensionId"; | 28 const char kExtensionIdKey[] = "extensionId"; |
| 27 const char kLinkTextKey[] = "linkText"; | 29 const char kLinkTextKey[] = "linkText"; |
| 28 const char kLinkUrlKey[] = "linkUrl"; | 30 const char kLinkUrlKey[] = "linkUrl"; |
| 29 const char kTitleKey[] = "title"; | 31 const char kTitleKey[] = "title"; |
| 32 const char kIntentIdKey[] = "intentId"; | |
| 33 const char kIntentSuccessKey[] = "success"; | |
| 34 const char kIntentDataKey[] = "data"; | |
| 30 | 35 |
| 31 const char kInvalidExtensionIdError[] = | 36 const char kInvalidExtensionIdError[] = |
| 32 "Invalid extension id"; | 37 "Invalid extension id"; |
| 33 const char kMissingLinkTextError[] = | 38 const char kMissingLinkTextError[] = |
| 34 "You must specify linkText if you use linkUrl"; | 39 "You must specify linkText if you use linkUrl"; |
| 40 const char kCallbackNotFoundError[] = | |
| 41 "WebIntent callback not found; perhaps already responded to"; | |
| 35 const char kOnLaunchedEvent[] = "experimental.app.onLaunched"; | 42 const char kOnLaunchedEvent[] = "experimental.app.onLaunched"; |
| 36 | |
| 37 } // anonymous namespace | 43 } // anonymous namespace |
| 38 | 44 |
| 39 namespace extensions { | 45 namespace extensions { |
| 40 | 46 |
| 41 bool AppNotifyFunction::RunImpl() { | 47 bool AppNotifyFunction::RunImpl() { |
| 42 if (!include_incognito() && profile_->IsOffTheRecord()) { | 48 if (!include_incognito() && profile_->IsOffTheRecord()) { |
| 43 error_ = extension_misc::kAppNotificationsIncognitoError; | 49 error_ = extension_misc::kAppNotificationsIncognitoError; |
| 44 return false; | 50 return false; |
| 45 } | 51 } |
| 46 | 52 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 return false; | 117 return false; |
| 112 } | 118 } |
| 113 } | 119 } |
| 114 | 120 |
| 115 AppNotificationManager* manager = | 121 AppNotificationManager* manager = |
| 116 profile()->GetExtensionService()->app_notification_manager(); | 122 profile()->GetExtensionService()->app_notification_manager(); |
| 117 manager->ClearAll(id); | 123 manager->ClearAll(id); |
| 118 return true; | 124 return true; |
| 119 } | 125 } |
| 120 | 126 |
| 127 bool PostIntentResponseFunction::RunImpl() { | |
| 128 DictionaryValue* details; | |
|
koz (OOO until 15th September)
2012/08/13 00:29:40
nit: initialize to NULL.
thorogood
2012/08/13 05:00:12
Done.
| |
| 129 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
| 130 EXTENSION_FUNCTION_VALIDATE(details != NULL); | |
|
koz (OOO until 15th September)
2012/08/13 00:29:40
I think this case is handled by the previous line,
thorogood
2012/08/13 05:00:12
Done.
| |
| 131 | |
| 132 int intent_id; | |
| 133 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); | |
| 134 | |
| 135 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); | |
| 136 content::WebIntentsDispatcher* intents_dispatcher = | |
| 137 callbacks->RetrieveCallback(GetExtension(), intent_id); | |
| 138 if (!intents_dispatcher) { | |
| 139 error_ = kCallbackNotFoundError; | |
| 140 return false; | |
| 141 } | |
| 142 | |
| 143 webkit_glue::WebIntentReplyType reply_type = | |
| 144 webkit_glue::WEB_INTENT_REPLY_FAILURE; | |
| 145 bool success; | |
| 146 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIntentSuccessKey, &success)); | |
| 147 if (success) | |
| 148 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; | |
| 149 | |
| 150 std::string data; | |
| 151 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); | |
| 152 | |
| 153 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); | |
| 154 return true; | |
| 155 } | |
| 156 | |
| 121 // static. | 157 // static. |
| 122 void AppEventRouter::DispatchOnLaunchedEvent( | 158 void AppEventRouter::DispatchOnLaunchedEvent( |
| 123 Profile* profile, const Extension* extension) { | 159 Profile* profile, const Extension* extension) { |
| 124 scoped_ptr<ListValue> arguments(new ListValue()); | 160 scoped_ptr<ListValue> arguments(new ListValue()); |
| 125 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 161 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 126 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); | 162 extension->id(), kOnLaunchedEvent, arguments.Pass(), NULL, GURL()); |
| 127 } | 163 } |
| 128 | 164 |
| 129 // static. | 165 // static. |
| 130 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 166 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 142 intent_data->SetString("fileSystemId", file_system_id); | 178 intent_data->SetString("fileSystemId", file_system_id); |
| 143 intent_data->SetString("baseName", base_name); | 179 intent_data->SetString("baseName", base_name); |
| 144 args->Append(intent_data); | 180 args->Append(intent_data); |
| 145 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 181 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 146 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | 182 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); |
| 147 } | 183 } |
| 148 | 184 |
| 149 // static. | 185 // static. |
| 150 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( | 186 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
| 151 Profile* profile, const Extension* extension, | 187 Profile* profile, const Extension* extension, |
| 152 const webkit_glue::WebIntentData web_intent_data) { | 188 content::WebIntentsDispatcher* intents_dispatcher) { |
| 189 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); | |
| 190 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); | |
| 191 int intent_id = callbacks->RegisterCallback(extension, intents_dispatcher); | |
| 192 | |
| 153 scoped_ptr<ListValue> args(new ListValue()); | 193 scoped_ptr<ListValue> args(new ListValue()); |
| 194 args->Append(base::Value::CreateIntegerValue(intent_id)); | |
| 195 | |
| 154 DictionaryValue* launch_data = new DictionaryValue(); | 196 DictionaryValue* launch_data = new DictionaryValue(); |
| 155 DictionaryValue* intent = new DictionaryValue(); | 197 DictionaryValue* intent = new DictionaryValue(); |
| 156 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); | 198 intent->SetString("action", UTF16ToUTF8(web_intent_data.action)); |
| 157 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); | 199 intent->SetString("type", UTF16ToUTF8(web_intent_data.type)); |
| 158 launch_data->Set("intent", intent); | 200 launch_data->Set("intent", intent); |
| 159 args->Append(launch_data); | 201 args->Append(launch_data); |
| 160 DictionaryValue* intent_data; | 202 DictionaryValue* intent_data; |
| 161 switch (web_intent_data.data_type) { | 203 switch (web_intent_data.data_type) { |
| 162 case webkit_glue::WebIntentData::SERIALIZED: | 204 case webkit_glue::WebIntentData::SERIALIZED: |
| 163 intent_data = new DictionaryValue(); | 205 intent_data = new DictionaryValue(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 178 break; | 220 break; |
| 179 default: | 221 default: |
| 180 NOTREACHED(); | 222 NOTREACHED(); |
| 181 break; | 223 break; |
| 182 } | 224 } |
| 183 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 225 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 184 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); | 226 extension->id(), kOnLaunchedEvent, args.Pass(), NULL, GURL()); |
| 185 } | 227 } |
| 186 | 228 |
| 187 } // namespace extensions | 229 } // namespace extensions |
| OLD | NEW |