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/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 "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 | 15 |
| 16 const char kBodyTextKey[] = "bodyText"; | 16 const char kBodyTextKey[] = "bodyText"; |
| 17 const char kExtensionIdKey[] = "extensionId"; | 17 const char kExtensionIdKey[] = "extensionId"; |
| 18 const char kLinkTextKey[] = "linkText"; | 18 const char kLinkTextKey[] = "linkText"; |
| 19 const char kLinkUrlKey[] = "linkUrl"; | 19 const char kLinkUrlKey[] = "linkUrl"; |
| 20 const char kTitleKey[] = "title"; | 20 const char kTitleKey[] = "title"; |
| 21 | 21 |
| 22 const char kInvalidExtensionIdError[] = | 22 const char kInvalidExtensionIdError[] = |
| 23 "Invalid extension id"; | 23 "Invalid extension id"; |
| 24 const char kMissingLinkTextError[] = | 24 const char kMissingLinkTextError[] = |
| 25 "You must specify linkText if you use linkUrl"; | 25 "You must specify linkText if you use linkUrl"; |
| 26 const char kIncognitoError[] = | |
| 27 "This API is not accessible by 'split' mode " | |
| 28 "extensions in incognito windows."; | |
| 26 | 29 |
| 27 bool AppNotifyFunction::RunImpl() { | 30 bool AppNotifyFunction::RunImpl() { |
| 31 if (!include_incognito() && profile_->IsOffTheRecord()) { | |
|
Mihai Parparita -not on Chrome
2012/03/22 19:44:20
There are actually two app notification APIs:
1) T
jstritar
2012/03/22 20:21:10
Oh yeah, done. Do you know why this needs such cus
asargent_no_longer_on_chrome
2012/03/22 20:58:11
Because it's exposed to hosted apps, which the reg
jstritar
2012/03/23 15:31:43
Thanks for the explanation! We might be able to ge
| |
| 32 error_ = kIncognitoError; | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 28 DictionaryValue* details; | 36 DictionaryValue* details; |
| 29 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 37 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| 30 EXTENSION_FUNCTION_VALIDATE(details != NULL); | 38 EXTENSION_FUNCTION_VALIDATE(details != NULL); |
| 31 | 39 |
| 32 // TODO(asargent) remove this before the API leaves experimental. | 40 // TODO(asargent) remove this before the API leaves experimental. |
| 33 std::string id = extension_id(); | 41 std::string id = extension_id(); |
| 34 if (details->HasKey(kExtensionIdKey)) { | 42 if (details->HasKey(kExtensionIdKey)) { |
| 35 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 43 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
| 36 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 44 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
| 37 error_ = kInvalidExtensionIdError; | 45 error_ = kInvalidExtensionIdError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 78 |
| 71 AppNotificationManager* manager = | 79 AppNotificationManager* manager = |
| 72 profile()->GetExtensionService()->app_notification_manager(); | 80 profile()->GetExtensionService()->app_notification_manager(); |
| 73 | 81 |
| 74 manager->Add(item.release()); | 82 manager->Add(item.release()); |
| 75 | 83 |
| 76 return true; | 84 return true; |
| 77 } | 85 } |
| 78 | 86 |
| 79 bool AppClearAllNotificationsFunction::RunImpl() { | 87 bool AppClearAllNotificationsFunction::RunImpl() { |
| 88 if (!include_incognito() && profile_->IsOffTheRecord()) { | |
| 89 error_ = kIncognitoError; | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 80 std::string id = extension_id(); | 93 std::string id = extension_id(); |
| 81 DictionaryValue* details = NULL; | 94 DictionaryValue* details = NULL; |
| 82 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { | 95 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { |
| 83 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 96 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
| 84 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 97 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
| 85 error_ = kInvalidExtensionIdError; | 98 error_ = kInvalidExtensionIdError; |
| 86 return false; | 99 return false; |
| 87 } | 100 } |
| 88 } | 101 } |
| 89 | 102 |
| 90 AppNotificationManager* manager = | 103 AppNotificationManager* manager = |
| 91 profile()->GetExtensionService()->app_notification_manager(); | 104 profile()->GetExtensionService()->app_notification_manager(); |
| 92 manager->ClearAll(id); | 105 manager->ClearAll(id); |
| 93 return true; | 106 return true; |
| 94 } | 107 } |
| OLD | NEW |