Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_app_api.h" | 5 #include "chrome/browser/extensions/extension_app_api.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/app_notification_manager.h" | 8 #include "chrome/browser/extensions/app_notification_manager.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 | 14 |
| 15 const char kBodyTextKey[] = "bodyText"; | 15 const char kBodyTextKey[] = "bodyText"; |
| 16 const char kExtensionIdKey[] = "extensionId"; | 16 const char kExtensionIdKey[] = "extensionId"; |
| 17 const char kLinkTextKey[] = "linkText"; | 17 const char kLinkTextKey[] = "linkText"; |
| 18 const char kLinkUrlKey[] = "linkUrl"; | 18 const char kLinkUrlKey[] = "linkUrl"; |
| 19 const char kTitleKey[] = "title"; | 19 const char kTitleKey[] = "title"; |
| 20 const char kCreationKey[] = "creation_timestamp_ms"; | |
| 20 | 21 |
| 21 const char kInvalidExtensionIdError[] = | 22 const char kInvalidExtensionIdError[] = |
| 22 "Invalid extension id"; | 23 "Invalid extension id"; |
| 23 const char kMissingLinkTextError[] = | 24 const char kMissingLinkTextError[] = |
| 24 "You must specify linkText if you use linkUrl"; | 25 "You must specify linkText if you use linkUrl"; |
| 25 | 26 |
| 26 bool AppNotifyFunction::RunImpl() { | 27 bool AppNotifyFunction::RunImpl() { |
| 27 DictionaryValue* details; | 28 DictionaryValue* details; |
| 28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 29 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| 29 EXTENSION_FUNCTION_VALIDATE(details != NULL); | 30 EXTENSION_FUNCTION_VALIDATE(details != NULL); |
| 30 | 31 |
| 31 // TODO(asargent) remove this before the API leaves experimental. | 32 // TODO(asargent) remove this before the API leaves experimental. |
| 32 std::string id = extension_id(); | 33 std::string id = extension_id(); |
| 33 if (details->HasKey(kExtensionIdKey)) { | 34 if (details->HasKey(kExtensionIdKey)) { |
| 34 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 35 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
| 35 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 36 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
| 36 error_ = kInvalidExtensionIdError; | 37 error_ = kInvalidExtensionIdError; |
| 37 return false; | 38 return false; |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 std::string title; | 42 std::string title; |
| 42 if (details->HasKey(kTitleKey)) | 43 if (details->HasKey(kTitleKey)) |
| 43 EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title)); | 44 EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title)); |
| 44 | 45 |
| 45 std::string body; | 46 std::string body; |
| 46 if (details->HasKey(kBodyTextKey)) | 47 if (details->HasKey(kBodyTextKey)) |
| 47 EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body)); | 48 EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body)); |
| 48 | 49 |
| 50 double creation_timestamp_ms; | |
| 51 if (details->HasKey(kCreationKey)) | |
| 52 EXTENSION_FUNCTION_VALIDATE(details->GetDouble(kCreationKey, | |
| 53 &creation_timestamp_ms)); | |
|
Munjal (Google)
2011/11/17 19:45:32
Shouldn't we just fill in creation time ourselves
elvin
2011/11/17 22:28:17
Done.
asargent_no_longer_on_chrome
2011/11/17 22:36:24
Yeah, we should just use Time::Now()
elvin
2011/11/17 22:52:58
Done.
| |
| 54 | |
| 49 scoped_ptr<AppNotification> item(new AppNotification( | 55 scoped_ptr<AppNotification> item(new AppNotification( |
| 50 true, "", id, title, body)); | 56 true, 0, "", id, title, body)); |
| 51 | 57 |
| 52 if (details->HasKey(kLinkUrlKey)) { | 58 if (details->HasKey(kLinkUrlKey)) { |
| 53 std::string link_url; | 59 std::string link_url; |
| 54 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url)); | 60 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url)); |
| 55 item->set_link_url(GURL(link_url)); | 61 item->set_link_url(GURL(link_url)); |
| 56 if (!item->link_url().is_valid()) { | 62 if (!item->link_url().is_valid()) { |
| 57 error_ = "Invalid url: " + link_url; | 63 error_ = "Invalid url: " + link_url; |
| 58 return false; | 64 return false; |
| 59 } | 65 } |
| 60 if (!details->HasKey(kLinkTextKey)) { | 66 if (!details->HasKey(kLinkTextKey)) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 84 error_ = kInvalidExtensionIdError; | 90 error_ = kInvalidExtensionIdError; |
| 85 return false; | 91 return false; |
| 86 } | 92 } |
| 87 } | 93 } |
| 88 | 94 |
| 89 AppNotificationManager* manager = | 95 AppNotificationManager* manager = |
| 90 profile()->GetExtensionService()->app_notification_manager(); | 96 profile()->GetExtensionService()->app_notification_manager(); |
| 91 manager->ClearAll(id); | 97 manager->ClearAll(id); |
| 92 return true; | 98 return true; |
| 93 } | 99 } |
| OLD | NEW |