summaryrefslogtreecommitdiffstats
path: root/chrome/browser/pdf/pdf_extension_util.cc
blob: 1987a6851db45af9356f5311ec5f0dfd3e6119c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/pdf/pdf_extension_util.h"

#include "base/strings/string_util.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/browser_resources.h"
#include "ui/base/resource/resource_bundle.h"

namespace pdf_extension_util {

namespace {

// Tags in the manifest to be replaced.
const char kNameTag[] = "<NAME>";
const char kIndexTag[] = "<INDEX>";

// The index html pages to load for the material and non-material version of
// the viewer.
const char kRegularIndex[] = "index.html";
const char kMaterialIndex[] = "index-material.html";

}  // namespace

// These should match the keys for the Chrome and Chromium PDF Viewer entries in
// chrome/browser/resources/plugin_metadata/plugins_*.json.
#if defined(GOOGLE_CHROME_BUILD)
const char kPdfResourceIdentifier[] = "google-chrome-pdf";
#else
const char kPdfResourceIdentifier[] = "chromium-pdf";
#endif

std::string GetManifest() {
  std::string manifest_contents =
      ResourceBundle::GetSharedInstance().GetRawDataResource(
          IDR_PDF_MANIFEST).as_string();
  DCHECK(manifest_contents.find(kNameTag) != std::string::npos);
  base::ReplaceFirstSubstringAfterOffset(
      &manifest_contents, 0, kNameTag, ChromeContentClient::kPDFPluginName);

  DCHECK(manifest_contents.find(kIndexTag) != std::string::npos);
  std::string index = switches::PdfMaterialUIEnabled() ?
      kMaterialIndex : kRegularIndex;
  base::ReplaceSubstringsAfterOffset(&manifest_contents, 0, kIndexTag, index);
  return manifest_contents;
}

}  // namespace pdf_extension_util