Commit 79b06900 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Use GURL for WebApp::launch_url data member.

To ensure URL correctness.

Bug: 891172
Change-Id: If2fad77d59a3675f30c168e55c376a5c53d43262
Reviewed-on: https://chromium-review.googlesource.com/c/1325573
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606356}
parent 26d05e6e
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <ostream> #include <ostream>
#include "base/logging.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
namespace web_app { namespace web_app {
...@@ -20,7 +21,8 @@ void WebApp::SetDescription(const std::string& description) { ...@@ -20,7 +21,8 @@ void WebApp::SetDescription(const std::string& description) {
description_ = description; description_ = description;
} }
void WebApp::SetLaunchUrl(const std::string& launch_url) { void WebApp::SetLaunchUrl(const GURL& launch_url) {
DCHECK(!launch_url.is_empty() && launch_url.is_valid());
launch_url_ = launch_url; launch_url_ = launch_url;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "url/gurl.h"
namespace web_app { namespace web_app {
...@@ -22,18 +23,18 @@ class WebApp { ...@@ -22,18 +23,18 @@ class WebApp {
const std::string& name() const { return name_; } const std::string& name() const { return name_; }
const std::string& description() const { return description_; } const std::string& description() const { return description_; }
const std::string& launch_url() const { return launch_url_; } const GURL& launch_url() const { return launch_url_; }
void SetName(const std::string& name); void SetName(const std::string& name);
void SetDescription(const std::string& description); void SetDescription(const std::string& description);
void SetLaunchUrl(const std::string& launch_url); void SetLaunchUrl(const GURL& launch_url);
private: private:
const AppId app_id_; const AppId app_id_;
std::string name_; std::string name_;
std::string description_; std::string description_;
std::string launch_url_; GURL launch_url_;
DISALLOW_COPY_AND_ASSIGN(WebApp); DISALLOW_COPY_AND_ASSIGN(WebApp);
}; };
......
...@@ -66,7 +66,7 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto( ...@@ -66,7 +66,7 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto(
proto->set_app_id(web_app.app_id()); proto->set_app_id(web_app.app_id());
proto->set_name(web_app.name()); proto->set_name(web_app.name());
proto->set_description(web_app.description()); proto->set_description(web_app.description());
proto->set_launch_url(web_app.launch_url()); proto->set_launch_url(web_app.launch_url().spec());
return proto; return proto;
} }
...@@ -75,9 +75,16 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto( ...@@ -75,9 +75,16 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto(
std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) { std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) {
auto web_app = std::make_unique<WebApp>(proto.app_id()); auto web_app = std::make_unique<WebApp>(proto.app_id());
GURL launch_url(proto.launch_url());
if (launch_url.is_empty() || !launch_url.is_valid()) {
LOG(ERROR) << "WebApp proto launch_url parse error: "
<< launch_url.possibly_invalid_spec();
return nullptr;
}
web_app->SetLaunchUrl(launch_url);
web_app->SetName(proto.name()); web_app->SetName(proto.name());
web_app->SetDescription(proto.description()); web_app->SetDescription(proto.description());
web_app->SetLaunchUrl(proto.launch_url());
return web_app; return web_app;
} }
......
...@@ -79,7 +79,7 @@ class WebAppDatabaseTest : public testing::Test { ...@@ -79,7 +79,7 @@ class WebAppDatabaseTest : public testing::Test {
app->SetName(name); app->SetName(name);
app->SetDescription(description); app->SetDescription(description);
app->SetLaunchUrl(launch_url); app->SetLaunchUrl(GURL(launch_url));
return app; return app;
} }
......
...@@ -147,7 +147,7 @@ void WebAppInstallManager::OnDidPerformInstallableCheck( ...@@ -147,7 +147,7 @@ void WebAppInstallManager::OnDidPerformInstallableCheck(
web_app->SetName(base::UTF16ToUTF8(web_app_info_->title)); web_app->SetName(base::UTF16ToUTF8(web_app_info_->title));
web_app->SetDescription(base::UTF16ToUTF8(web_app_info_->description)); web_app->SetDescription(base::UTF16ToUTF8(web_app_info_->description));
web_app->SetLaunchUrl(web_app_info_->app_url.spec()); web_app->SetLaunchUrl(web_app_info_->app_url);
registrar_->RegisterApp(std::move(web_app)); registrar_->RegisterApp(std::move(web_app));
......
...@@ -64,7 +64,7 @@ TEST(WebAppRegistrar, CreateRegisterUnregister) { ...@@ -64,7 +64,7 @@ TEST(WebAppRegistrar, CreateRegisterUnregister) {
web_app->SetName(name); web_app->SetName(name);
web_app->SetDescription(description); web_app->SetDescription(description);
web_app->SetLaunchUrl(launch_url.spec()); web_app->SetLaunchUrl(launch_url);
EXPECT_EQ(nullptr, registrar->GetAppById(app_id)); EXPECT_EQ(nullptr, registrar->GetAppById(app_id));
EXPECT_EQ(nullptr, registrar->GetAppById(app_id2)); EXPECT_EQ(nullptr, registrar->GetAppById(app_id2));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment