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

Side by Side Diff: chrome/browser/ui/webui/offline_internals_ui.cc

Issue 2246563002: [Offline Pages]Allow multiple urls to be requested in internal page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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_internals_ui.h" 5 #include "chrome/browser/ui/webui/offline_internals_ui.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <sstream>
michaelpg 2016/08/14 21:31:20 alphabetize
romax 2016/08/19 18:53:35 removed c++ changes and moved to JS side.
10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/bind.h" 13 #include "base/bind.h"
12 #include "base/guid.h" 14 #include "base/guid.h"
13 #include "base/macros.h" 15 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 19 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
18 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 20 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 result.AppendStrings(logs); 314 result.AppendStrings(logs);
313 315
314 ResolveJavascriptCallback(*callback_id, result); 316 ResolveJavascriptCallback(*callback_id, result);
315 } 317 }
316 318
317 void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue( 319 void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue(
318 const base::ListValue* args) { 320 const base::ListValue* args) {
319 const base::Value* callback_id; 321 const base::Value* callback_id;
320 CHECK(args->Get(0, &callback_id)); 322 CHECK(args->Get(0, &callback_id));
321 323
322 std::string url; 324 std::string request_urls;
323 CHECK(args->GetString(1, &url)); 325 CHECK(args->GetString(1, &request_urls));
324 326
325 // To be visible in Downloads UI, these items need a well-formed GUID 327 // To be visible in Downloads UI, these items need a well-formed GUID
326 // and AsyncNamespace in their ClientId. 328 // and AsyncNamespace in their ClientId.
327 std::ostringstream id_stream; 329 std::ostringstream id_stream;
328 id_stream << base::GenerateGUID(); 330 id_stream << base::GenerateGUID();
329 331
330 ResolveJavascriptCallback( 332 std::vector<std::string> url_list;
331 *callback_id, 333 std::stringstream ss(request_urls);
michaelpg 2016/08/14 21:31:19 istringstream?
romax 2016/08/19 18:53:35 Done.
332 base::FundamentalValue( 334 std::string url;
333 request_coordinator_->SavePageLater( 335 while (getline(ss, url, ',') && (!url.empty())) {
michaelpg 2016/08/14 21:31:20 nit: parens not needed around !url.empty()
romax 2016/08/19 18:53:35 Done.
334 GURL(url), 336 url_list.push_back(url);
335 offline_pages::ClientId(offline_pages::kAsyncNamespace, 337 }
336 id_stream.str()), 338
337 true))); 339 for (auto url : url_list) {
340 ResolveJavascriptCallback(
michaelpg 2016/08/14 21:31:20 it doesn't make sense to repeatedly "resolve" a pr
chili 2016/08/15 18:27:08 +1. I believe ResolveJavascriptCallback might als
romax 2016/08/19 18:53:35 I think i'm going with parsing the urls in JS side
341 *callback_id,
342 base::FundamentalValue(
343 request_coordinator_->SavePageLater(
344 GURL(url),
345 offline_pages::ClientId(offline_pages::kAsyncNamespace,
346 id_stream.str()),
347 true)));
348 }
338 } 349 }
339 350
340 void OfflineInternalsUIMessageHandler::RegisterMessages() { 351 void OfflineInternalsUIMessageHandler::RegisterMessages() {
341 web_ui()->RegisterMessageCallback( 352 web_ui()->RegisterMessageCallback(
342 "deleteAllPages", 353 "deleteAllPages",
343 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages, 354 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteAllPages,
344 weak_ptr_factory_.GetWeakPtr())); 355 weak_ptr_factory_.GetWeakPtr()));
345 web_ui()->RegisterMessageCallback( 356 web_ui()->RegisterMessageCallback(
346 "deleteSelectedPages", 357 "deleteSelectedPages",
347 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages, 358 base::Bind(&OfflineInternalsUIMessageHandler::HandleDeleteSelectedPages,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 html_source->AddResourcePath("offline_internals_browser_proxy.js", 415 html_source->AddResourcePath("offline_internals_browser_proxy.js",
405 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS); 416 IDR_OFFLINE_INTERNALS_BROWSER_PROXY_JS);
406 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML); 417 html_source->SetDefaultResource(IDR_OFFLINE_INTERNALS_HTML);
407 418
408 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); 419 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source);
409 420
410 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler()); 421 web_ui->AddMessageHandler(new OfflineInternalsUIMessageHandler());
411 } 422 }
412 423
413 OfflineInternalsUI::~OfflineInternalsUI() {} 424 OfflineInternalsUI::~OfflineInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698