1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/pdf/pdf_extension_util.h"
7 #include "base/strings/string_util.h"
8 #include "chrome/common/chrome_content_client.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/grit/browser_resources.h"
11 #include "ui/base/resource/resource_bundle.h"
13 namespace pdf_extension_util
{
17 // Tags in the manifest to be replaced.
18 const char kNameTag
[] = "<NAME>";
19 const char kIndexTag
[] = "<INDEX>";
21 // The index html pages to load for the material and non-material version of
23 const char kRegularIndex
[] = "index.html";
24 const char kMaterialIndex
[] = "index-material.html";
28 // These should match the keys for the Chrome and Chromium PDF Viewer entries in
29 // chrome/browser/resources/plugin_metadata/plugins_*.json.
30 #if defined(GOOGLE_CHROME_BUILD)
31 const char kPdfResourceIdentifier
[] = "google-chrome-pdf";
33 const char kPdfResourceIdentifier
[] = "chromium-pdf";
36 std::string
GetManifest() {
37 std::string manifest_contents
=
38 ResourceBundle::GetSharedInstance().GetRawDataResource(
39 IDR_PDF_MANIFEST
).as_string();
40 DCHECK(manifest_contents
.find(kNameTag
) != std::string::npos
);
41 ReplaceFirstSubstringAfterOffset(
42 &manifest_contents
, 0, kNameTag
, ChromeContentClient::kPDFPluginName
);
44 DCHECK(manifest_contents
.find(kIndexTag
) != std::string::npos
);
45 std::string index
= switches::PdfMaterialUIEnabled() ?
46 kMaterialIndex
: kRegularIndex
;
47 ReplaceSubstringsAfterOffset(&manifest_contents
, 0, kIndexTag
, index
);
48 return manifest_contents
;
51 } // namespace pdf_extension_util