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

Side by Side Diff: chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.cc

Issue 2274733002: [Offline pages] Add null pointer checks in offline internals code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/webui/offline/offline_internals_ui_message_handler.h " 5 #include "chrome/browser/ui/webui/offline/offline_internals_ui_message_handler.h "
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } else { 166 } else {
167 base::ListValue results; 167 base::ListValue results;
168 ResolveJavascriptCallback(base::StringValue(callback_id), results); 168 ResolveJavascriptCallback(base::StringValue(callback_id), results);
169 } 169 }
170 } 170 }
171 171
172 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel( 172 void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
173 const base::ListValue* args) { 173 const base::ListValue* args) {
174 bool should_record; 174 bool should_record;
175 CHECK(args->GetBoolean(0, &should_record)); 175 CHECK(args->GetBoolean(0, &should_record));
176 offline_page_model_->GetLogger()->SetIsLogging(should_record); 176 if (offline_page_model_)
Dan Beam 2016/08/24 01:27:23 all of these indents are off
chili 2016/08/24 01:31:17 For some reason, I was thinking Java @.@ Fixed!
177 offline_page_model_->GetLogger()->SetIsLogging(should_record);
177 } 178 }
178 179
179 void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus( 180 void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus(
180 const base::ListValue* args) { 181 const base::ListValue* args) {
181 const base::Value* callback_id; 182 const base::Value* callback_id;
182 CHECK(args->Get(0, &callback_id)); 183 CHECK(args->Get(0, &callback_id));
183 184
184 ResolveJavascriptCallback( 185 ResolveJavascriptCallback(
185 *callback_id, 186 *callback_id,
186 base::StringValue(net::NetworkChangeNotifier::IsOffline() ? "Offline" 187 base::StringValue(net::NetworkChangeNotifier::IsOffline() ? "Offline"
187 : "Online")); 188 : "Online"));
188 } 189 }
189 190
190 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue( 191 void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
191 const base::ListValue* args) { 192 const base::ListValue* args) {
192 bool should_record; 193 bool should_record;
193 CHECK(args->GetBoolean(0, &should_record)); 194 CHECK(args->GetBoolean(0, &should_record));
194 request_coordinator_->GetLogger()->SetIsLogging(should_record); 195 if (request_coordinator_)
196 request_coordinator_->GetLogger()->SetIsLogging(should_record);
195 } 197 }
196 198
197 void OfflineInternalsUIMessageHandler::HandleGetLoggingState( 199 void OfflineInternalsUIMessageHandler::HandleGetLoggingState(
198 const base::ListValue* args) { 200 const base::ListValue* args) {
199 AllowJavascript(); 201 AllowJavascript();
200 const base::Value* callback_id; 202 const base::Value* callback_id;
201 CHECK(args->Get(0, &callback_id)); 203 CHECK(args->Get(0, &callback_id));
202 204
203 base::DictionaryValue result; 205 base::DictionaryValue result;
204 result.SetBoolean("modelIsLogging", 206 result.SetBoolean("modelIsLogging",
205 offline_page_model_->GetLogger()->GetIsLogging()); 207 offline_page_model_ ?
208 offline_page_model_->GetLogger()->GetIsLogging() :
209 false);
206 result.SetBoolean("queueIsLogging", 210 result.SetBoolean("queueIsLogging",
207 request_coordinator_->GetLogger()->GetIsLogging()); 211 request_coordinator_ ?
212 request_coordinator_->GetLogger()->GetIsLogging() :
213 false);
208 ResolveJavascriptCallback(*callback_id, result); 214 ResolveJavascriptCallback(*callback_id, result);
209 } 215 }
210 216
211 void OfflineInternalsUIMessageHandler::HandleGetEventLogs( 217 void OfflineInternalsUIMessageHandler::HandleGetEventLogs(
212 const base::ListValue* args) { 218 const base::ListValue* args) {
213 AllowJavascript(); 219 AllowJavascript();
214 const base::Value* callback_id; 220 const base::Value* callback_id;
215 CHECK(args->Get(0, &callback_id)); 221 CHECK(args->Get(0, &callback_id));
216 222
217 std::vector<std::string> logs; 223 std::vector<std::string> logs;
218 offline_page_model_->GetLogger()->GetLogs(&logs); 224 if (offline_page_model_)
219 request_coordinator_->GetLogger()->GetLogs(&logs); 225 offline_page_model_->GetLogger()->GetLogs(&logs);
226 if (request_coordinator_)
227 request_coordinator_->GetLogger()->GetLogs(&logs);
220 std::sort(logs.begin(), logs.end()); 228 std::sort(logs.begin(), logs.end());
221 229
222 base::ListValue result; 230 base::ListValue result;
223 result.AppendStrings(logs); 231 result.AppendStrings(logs);
224 232
225 ResolveJavascriptCallback(*callback_id, result); 233 ResolveJavascriptCallback(*callback_id, result);
226 } 234 }
227 235
228 void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue( 236 void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue(
229 const base::ListValue* args) { 237 const base::ListValue* args) {
230 const base::Value* callback_id; 238 const base::Value* callback_id;
231 CHECK(args->Get(0, &callback_id)); 239 CHECK(args->Get(0, &callback_id));
232 240
233 std::string url; 241 std::string url;
234 CHECK(args->GetString(1, &url)); 242 CHECK(args->GetString(1, &url));
235 243
236 // To be visible in Downloads UI, these items need a well-formed GUID 244 // To be visible in Downloads UI, these items need a well-formed GUID
237 // and AsyncNamespace in their ClientId. 245 // and AsyncNamespace in their ClientId.
238 std::ostringstream id_stream; 246 std::ostringstream id_stream;
239 id_stream << base::GenerateGUID(); 247 id_stream << base::GenerateGUID();
240 248
241 ResolveJavascriptCallback( 249 if (request_coordinator_) {
242 *callback_id, 250 ResolveJavascriptCallback(
243 base::FundamentalValue(request_coordinator_->SavePageLater( 251 *callback_id,
244 GURL(url), offline_pages::ClientId(offline_pages::kAsyncNamespace, 252 base::FundamentalValue(request_coordinator_->SavePageLater(
245 id_stream.str()), 253 GURL(url), offline_pages::ClientId(offline_pages::kAsyncNamespace,
246 true))); 254 id_stream.str()),
255 true)));
256 } else {
257 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(false));
258 }
247 } 259 }
248 260
249 void OfflineInternalsUIMessageHandler::RegisterMessages() { 261 void OfflineInternalsUIMessageHandler::RegisterMessages() {
250 web_ui()->RegisterMessageCallback( 262 web_ui()->RegisterMessageCallback(
251 "deleteAllPages", 263 "deleteAllPages",
252 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, 264 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages,
253 weak_ptr_factory_.GetWeakPtr())); 265 weak_ptr_factory_.GetWeakPtr()));
254 web_ui()->RegisterMessageCallback( 266 web_ui()->RegisterMessageCallback(
255 "deleteSelectedPages", 267 "deleteSelectedPages",
256 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, 268 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 302
291 // Get the offline page model associated with this web ui. 303 // Get the offline page model associated with this web ui.
292 Profile* profile = Profile::FromWebUI(web_ui()); 304 Profile* profile = Profile::FromWebUI(web_ui());
293 offline_page_model_ = 305 offline_page_model_ =
294 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile); 306 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
295 request_coordinator_ = 307 request_coordinator_ =
296 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile); 308 offline_pages::RequestCoordinatorFactory::GetForBrowserContext(profile);
297 } 309 }
298 310
299 } // namespace offline_internals 311 } // namespace offline_internals
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698