Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/extensions/extension_app_api.cc

Issue 8567018: Limit number of notifications that can be received by the client. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/time.h"
8 #include "chrome/browser/extensions/app_notification_manager.h" 9 #include "chrome/browser/extensions/app_notification_manager.h"
9 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
14 15
15 const char kBodyTextKey[] = "bodyText"; 16 const char kBodyTextKey[] = "bodyText";
16 const char kExtensionIdKey[] = "extensionId"; 17 const char kExtensionIdKey[] = "extensionId";
17 const char kLinkTextKey[] = "linkText"; 18 const char kLinkTextKey[] = "linkText";
18 const char kLinkUrlKey[] = "linkUrl"; 19 const char kLinkUrlKey[] = "linkUrl";
19 const char kTitleKey[] = "title"; 20 const char kTitleKey[] = "title";
21 const char kCreationKey[] = "creation_timestamp_ms";
asargent_no_longer_on_chrome 2011/11/17 23:40:14 nit: remove this
elvin 2011/11/18 00:10:18 Done.
20 22
21 const char kInvalidExtensionIdError[] = 23 const char kInvalidExtensionIdError[] =
22 "Invalid extension id"; 24 "Invalid extension id";
23 const char kMissingLinkTextError[] = 25 const char kMissingLinkTextError[] =
24 "You must specify linkText if you use linkUrl"; 26 "You must specify linkText if you use linkUrl";
25 27
26 bool AppNotifyFunction::RunImpl() { 28 bool AppNotifyFunction::RunImpl() {
27 DictionaryValue* details; 29 DictionaryValue* details;
28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 30 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
29 EXTENSION_FUNCTION_VALIDATE(details != NULL); 31 EXTENSION_FUNCTION_VALIDATE(details != NULL);
30 32
31 // TODO(asargent) remove this before the API leaves experimental. 33 // TODO(asargent) remove this before the API leaves experimental.
32 std::string id = extension_id(); 34 std::string id = extension_id();
33 if (details->HasKey(kExtensionIdKey)) { 35 if (details->HasKey(kExtensionIdKey)) {
34 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); 36 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id));
35 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { 37 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) {
36 error_ = kInvalidExtensionIdError; 38 error_ = kInvalidExtensionIdError;
37 return false; 39 return false;
38 } 40 }
39 } 41 }
40 42
41 std::string title; 43 std::string title;
42 if (details->HasKey(kTitleKey)) 44 if (details->HasKey(kTitleKey))
43 EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title)); 45 EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title));
44 46
45 std::string body; 47 std::string body;
46 if (details->HasKey(kBodyTextKey)) 48 if (details->HasKey(kBodyTextKey))
47 EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body)); 49 EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body));
48 50
51 double creation_timestamp_ms;
52 if (details->HasKey(kCreationKey))
53 EXTENSION_FUNCTION_VALIDATE(details->GetDouble(kCreationKey,
54 &creation_timestamp_ms));
asargent_no_longer_on_chrome 2011/11/17 23:40:14 nit: remove this block since we're just passing Ti
elvin 2011/11/18 00:10:18 Done.
55
49 scoped_ptr<AppNotification> item(new AppNotification( 56 scoped_ptr<AppNotification> item(new AppNotification(
50 true, "", id, title, body)); 57 true, base::Time::Now(), "", id, title, body));
51 58
52 if (details->HasKey(kLinkUrlKey)) { 59 if (details->HasKey(kLinkUrlKey)) {
53 std::string link_url; 60 std::string link_url;
54 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url)); 61 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url));
55 item->set_link_url(GURL(link_url)); 62 item->set_link_url(GURL(link_url));
56 if (!item->link_url().is_valid()) { 63 if (!item->link_url().is_valid()) {
57 error_ = "Invalid url: " + link_url; 64 error_ = "Invalid url: " + link_url;
58 return false; 65 return false;
59 } 66 }
60 if (!details->HasKey(kLinkTextKey)) { 67 if (!details->HasKey(kLinkTextKey)) {
(...skipping 23 matching lines...) Expand all
84 error_ = kInvalidExtensionIdError; 91 error_ = kInvalidExtensionIdError;
85 return false; 92 return false;
86 } 93 }
87 } 94 }
88 95
89 AppNotificationManager* manager = 96 AppNotificationManager* manager =
90 profile()->GetExtensionService()->app_notification_manager(); 97 profile()->GetExtensionService()->app_notification_manager();
91 manager->ClearAll(id); 98 manager->ClearAll(id);
92 return true; 99 return true;
93 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698