blob: f8e60e325825e700116c091c5eb2ecc0e8339af4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/app_notification.h"
#include "base/memory/scoped_ptr.h"
AppNotification::AppNotification(const std::string& title,
const std::string& body)
: title_(title), body_(body) {}
AppNotification::~AppNotification() {}
namespace {
const char* kTitleKey = "title";
const char* kBodyKey = "body";
const char* kLinkUrlKey = "link_url";
const char* kLinkTextKey = "link_text";
} // namespace
void AppNotification::ToDictionaryValue(DictionaryValue* result) {
CHECK(result);
if (!title_.empty())
result->SetString(kTitleKey, title_);
if (!body_.empty())
result->SetString(kBodyKey, body_);
if (!link_url_.is_empty()) {
result->SetString(kLinkUrlKey, link_url_.possibly_invalid_spec());
result->SetString(kLinkTextKey, link_text_);
}
}
// static
AppNotification* AppNotification::FromDictionaryValue(
const DictionaryValue& value) {
scoped_ptr<AppNotification> result(new AppNotification("", ""));
if (value.HasKey(kTitleKey) && !value.GetString(kTitleKey, &result->title_))
return NULL;
if (value.HasKey(kBodyKey) && !value.GetString(kBodyKey, &result->body_))
return NULL;
if (value.HasKey(kLinkUrlKey)) {
if (!value.HasKey(kLinkTextKey))
return NULL;
std::string url;
if (!value.GetString(kLinkUrlKey, &url) ||
!value.GetString(kLinkTextKey, &result->link_text_))
return NULL;
GURL gurl(url);
if (!gurl.is_valid())
return NULL;
result->set_link_url(gurl);
}
return result.release();
}
bool AppNotification::Equals(const AppNotification& other) const {
return (title_ == other.title_ &&
body_ == other.body_ &&
link_url_ == other.link_url_ &&
link_text_ == other.link_text_);
}
|