| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/extensions/app_notification_manager.h" | 9 #include "chrome/browser/extensions/app_notification_manager.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 15 | 16 |
| 16 const char kBodyTextKey[] = "bodyText"; | 17 const char kBodyTextKey[] = "bodyText"; |
| 17 const char kExtensionIdKey[] = "extensionId"; | 18 const char kExtensionIdKey[] = "extensionId"; |
| 18 const char kLinkTextKey[] = "linkText"; | 19 const char kLinkTextKey[] = "linkText"; |
| 19 const char kLinkUrlKey[] = "linkUrl"; | 20 const char kLinkUrlKey[] = "linkUrl"; |
| 20 const char kTitleKey[] = "title"; | 21 const char kTitleKey[] = "title"; |
| 21 | 22 |
| 22 const char kInvalidExtensionIdError[] = | 23 const char kInvalidExtensionIdError[] = |
| 23 "Invalid extension id"; | 24 "Invalid extension id"; |
| 24 const char kMissingLinkTextError[] = | 25 const char kMissingLinkTextError[] = |
| 25 "You must specify linkText if you use linkUrl"; | 26 "You must specify linkText if you use linkUrl"; |
| 26 | 27 |
| 27 bool AppNotifyFunction::RunImpl() { | 28 bool AppNotifyFunction::RunImpl() { |
| 29 if (!include_incognito() && profile_->IsOffTheRecord()) { |
| 30 error_ = extension_misc::kAppNotificationsIncognitoError; |
| 31 return false; |
| 32 } |
| 33 |
| 28 DictionaryValue* details; | 34 DictionaryValue* details; |
| 29 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 35 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| 30 EXTENSION_FUNCTION_VALIDATE(details != NULL); | 36 EXTENSION_FUNCTION_VALIDATE(details != NULL); |
| 31 | 37 |
| 32 // TODO(asargent) remove this before the API leaves experimental. | 38 // TODO(asargent) remove this before the API leaves experimental. |
| 33 std::string id = extension_id(); | 39 std::string id = extension_id(); |
| 34 if (details->HasKey(kExtensionIdKey)) { | 40 if (details->HasKey(kExtensionIdKey)) { |
| 35 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 41 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
| 36 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 42 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
| 37 error_ = kInvalidExtensionIdError; | 43 error_ = kInvalidExtensionIdError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 76 |
| 71 AppNotificationManager* manager = | 77 AppNotificationManager* manager = |
| 72 profile()->GetExtensionService()->app_notification_manager(); | 78 profile()->GetExtensionService()->app_notification_manager(); |
| 73 | 79 |
| 74 manager->Add(item.release()); | 80 manager->Add(item.release()); |
| 75 | 81 |
| 76 return true; | 82 return true; |
| 77 } | 83 } |
| 78 | 84 |
| 79 bool AppClearAllNotificationsFunction::RunImpl() { | 85 bool AppClearAllNotificationsFunction::RunImpl() { |
| 86 if (!include_incognito() && profile_->IsOffTheRecord()) { |
| 87 error_ = extension_misc::kAppNotificationsIncognitoError; |
| 88 return false; |
| 89 } |
| 90 |
| 80 std::string id = extension_id(); | 91 std::string id = extension_id(); |
| 81 DictionaryValue* details = NULL; | 92 DictionaryValue* details = NULL; |
| 82 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { | 93 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { |
| 83 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 94 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
| 84 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 95 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
| 85 error_ = kInvalidExtensionIdError; | 96 error_ = kInvalidExtensionIdError; |
| 86 return false; | 97 return false; |
| 87 } | 98 } |
| 88 } | 99 } |
| 89 | 100 |
| 90 AppNotificationManager* manager = | 101 AppNotificationManager* manager = |
| 91 profile()->GetExtensionService()->app_notification_manager(); | 102 profile()->GetExtensionService()->app_notification_manager(); |
| 92 manager->ClearAll(id); | 103 manager->ClearAll(id); |
| 93 return true; | 104 return true; |
| 94 } | 105 } |
| OLD | NEW |