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/history/history_extension_api.h" | 5 #include "chrome/browser/history/history_extension_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 content::Details<const history::URLsDeletedDetails>(details).ptr()); | 122 content::Details<const history::URLsDeletedDetails>(details).ptr()); |
123 break; | 123 break; |
124 default: | 124 default: |
125 NOTREACHED(); | 125 NOTREACHED(); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 void HistoryExtensionEventRouter::HistoryUrlVisited( | 129 void HistoryExtensionEventRouter::HistoryUrlVisited( |
130 Profile* profile, | 130 Profile* profile, |
131 const history::URLVisitedDetails* details) { | 131 const history::URLVisitedDetails* details) { |
132 ListValue args; | 132 ListValue* args = new ListValue(); |
133 DictionaryValue* dict = new DictionaryValue(); | 133 DictionaryValue* dict = new DictionaryValue(); |
134 GetHistoryItemDictionary(details->row, dict); | 134 GetHistoryItemDictionary(details->row, dict); |
135 args.Append(dict); | 135 args->Append(dict); |
136 | 136 |
137 std::string json_args; | 137 DispatchEvent(profile, kOnVisited, args); |
138 base::JSONWriter::Write(&args, &json_args); | |
139 DispatchEvent(profile, kOnVisited, json_args); | |
140 } | 138 } |
141 | 139 |
142 void HistoryExtensionEventRouter::HistoryUrlsRemoved( | 140 void HistoryExtensionEventRouter::HistoryUrlsRemoved( |
143 Profile* profile, | 141 Profile* profile, |
144 const history::URLsDeletedDetails* details) { | 142 const history::URLsDeletedDetails* details) { |
145 ListValue args; | 143 ListValue* args = new ListValue(); |
146 DictionaryValue* dict = new DictionaryValue(); | 144 DictionaryValue* dict = new DictionaryValue(); |
147 dict->SetBoolean(kAllHistoryKey, details->all_history); | 145 dict->SetBoolean(kAllHistoryKey, details->all_history); |
148 ListValue* urls = new ListValue(); | 146 ListValue* urls = new ListValue(); |
149 for (history::URLRows::const_iterator iterator = details->rows.begin(); | 147 for (history::URLRows::const_iterator iterator = details->rows.begin(); |
150 iterator != details->rows.end(); ++iterator) { | 148 iterator != details->rows.end(); ++iterator) { |
151 urls->Append(new StringValue(iterator->url().spec())); | 149 urls->Append(new StringValue(iterator->url().spec())); |
152 } | 150 } |
153 dict->Set(kUrlsKey, urls); | 151 dict->Set(kUrlsKey, urls); |
154 args.Append(dict); | 152 args->Append(dict); |
155 | 153 |
156 std::string json_args; | 154 DispatchEvent(profile, kOnVisitRemoved, args); |
157 base::JSONWriter::Write(&args, &json_args); | |
158 DispatchEvent(profile, kOnVisitRemoved, json_args); | |
159 } | 155 } |
160 | 156 |
161 void HistoryExtensionEventRouter::DispatchEvent(Profile* profile, | 157 void HistoryExtensionEventRouter::DispatchEvent(Profile* profile, |
162 const char* event_name, | 158 const char* event_name, |
163 const std::string& json_args) { | 159 ListValue* event_args) { |
164 if (profile && profile->GetExtensionEventRouter()) { | 160 if (profile && profile->GetExtensionEventRouter()) { |
165 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 161 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
166 event_name, json_args, profile, GURL()); | 162 event_name, event_args, profile, GURL()); |
167 } | 163 } |
168 } | 164 } |
169 | 165 |
170 void HistoryFunction::Run() { | 166 void HistoryFunction::Run() { |
171 if (!RunImpl()) { | 167 if (!RunImpl()) { |
172 SendResponse(false); | 168 SendResponse(false); |
173 } | 169 } |
174 } | 170 } |
175 | 171 |
176 bool HistoryFunction::GetUrlFromValue(Value* value, GURL* url) { | 172 bool HistoryFunction::GetUrlFromValue(Value* value, GURL* url) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 &cancelable_consumer_, | 401 &cancelable_consumer_, |
406 base::Bind(&DeleteAllHistoryFunction::DeleteComplete, | 402 base::Bind(&DeleteAllHistoryFunction::DeleteComplete, |
407 base::Unretained(this))); | 403 base::Unretained(this))); |
408 | 404 |
409 return true; | 405 return true; |
410 } | 406 } |
411 | 407 |
412 void DeleteAllHistoryFunction::DeleteComplete() { | 408 void DeleteAllHistoryFunction::DeleteComplete() { |
413 SendAsyncResponse(); | 409 SendAsyncResponse(); |
414 } | 410 } |
OLD | NEW |