2017-01-17 14:23:13 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/atom_web_ui_controller_factory.h"
|
|
|
|
|
2017-01-18 17:53:54 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-01-21 14:57:29 +00:00
|
|
|
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
|
2017-02-03 09:36:53 +00:00
|
|
|
#include "atom/common/atom_constants.h"
|
2017-01-17 17:10:15 +00:00
|
|
|
#include "base/strings/string_split.h"
|
2017-01-18 17:53:54 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2017-01-17 14:23:13 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
// static
|
|
|
|
AtomWebUIControllerFactory* AtomWebUIControllerFactory::GetInstance() {
|
|
|
|
return base::Singleton<AtomWebUIControllerFactory>::get();
|
|
|
|
}
|
|
|
|
|
|
|
|
AtomWebUIControllerFactory::AtomWebUIControllerFactory() {}
|
|
|
|
|
|
|
|
AtomWebUIControllerFactory::~AtomWebUIControllerFactory() {}
|
|
|
|
|
|
|
|
content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url) const {
|
2017-02-03 09:36:53 +00:00
|
|
|
if (url.host() == kPdfViewerUIHost) {
|
2017-01-17 14:23:13 +00:00
|
|
|
return const_cast<AtomWebUIControllerFactory*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomWebUIControllerFactory::UseWebUIForURL(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url) const {
|
|
|
|
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomWebUIControllerFactory::UseWebUIBindingsForURL(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const GURL& url) const {
|
|
|
|
return UseWebUIForURL(browser_context, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
content::WebUIController*
|
|
|
|
AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
|
|
|
|
const GURL& url) const {
|
2017-02-03 09:36:53 +00:00
|
|
|
if (url.host() == kPdfViewerUIHost) {
|
2017-01-17 17:10:15 +00:00
|
|
|
base::StringPairs toplevel_params;
|
|
|
|
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
|
2017-02-03 10:16:23 +00:00
|
|
|
std::string stream_id, src;
|
2017-01-17 17:10:15 +00:00
|
|
|
for (const auto& param : toplevel_params) {
|
2017-02-27 06:10:49 +00:00
|
|
|
if (param.first == kPdfPluginSrc) {
|
2017-01-23 11:12:39 +00:00
|
|
|
src = param.second;
|
2017-01-17 17:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-17 14:23:13 +00:00
|
|
|
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
2017-02-27 06:10:49 +00:00
|
|
|
return new PdfViewerUI(browser_context, web_ui, src);
|
2017-01-17 14:23:13 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|