OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/pdf/pdf_extension_util.h" | 5 #include "chrome/browser/pdf/pdf_extension_util.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "chrome/common/chrome_content_client.h" | 8 #include "chrome/common/chrome_content_client.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/grit/browser_resources.h" | 10 #include "chrome/grit/browser_resources.h" |
11 #include "content/public/test/browser_test_utils.h" | |
12 #include "grit/component_extension_resources.h" | |
11 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
12 | 14 |
13 namespace pdf_extension_util { | 15 namespace pdf_extension_util { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // Tags in the manifest to be replaced. | 19 // Tags in the manifest to be replaced. |
18 const char kNameTag[] = "<NAME>"; | 20 const char kNameTag[] = "<NAME>"; |
19 const char kIndexTag[] = "<INDEX>"; | 21 const char kIndexTag[] = "<INDEX>"; |
20 | 22 |
(...skipping 20 matching lines...) Expand all Loading... | |
41 base::ReplaceFirstSubstringAfterOffset( | 43 base::ReplaceFirstSubstringAfterOffset( |
42 &manifest_contents, 0, kNameTag, ChromeContentClient::kPDFPluginName); | 44 &manifest_contents, 0, kNameTag, ChromeContentClient::kPDFPluginName); |
43 | 45 |
44 DCHECK(manifest_contents.find(kIndexTag) != std::string::npos); | 46 DCHECK(manifest_contents.find(kIndexTag) != std::string::npos); |
45 std::string index = switches::PdfMaterialUIEnabled() ? | 47 std::string index = switches::PdfMaterialUIEnabled() ? |
46 kMaterialIndex : kRegularIndex; | 48 kMaterialIndex : kRegularIndex; |
47 base::ReplaceSubstringsAfterOffset(&manifest_contents, 0, kIndexTag, index); | 49 base::ReplaceSubstringsAfterOffset(&manifest_contents, 0, kIndexTag, index); |
48 return manifest_contents; | 50 return manifest_contents; |
49 } | 51 } |
50 | 52 |
53 bool EnsurePDFHasLoaded(content::WebContents* web_contents) { | |
raymes
2015/07/21 01:20:14
This file is used in production code however this
lazyboy
2015/07/21 03:55:06
Oh I missed that seeing pdf_extension_util and pdf
| |
54 std::string scripting_api_js = | |
55 ResourceBundle::GetSharedInstance() | |
56 .GetRawDataResource(IDR_PDF_PDF_SCRIPTING_API_JS) | |
57 .as_string(); | |
58 CHECK(content::ExecuteScript(web_contents, scripting_api_js)); | |
59 | |
60 bool load_success = false; | |
61 CHECK(content::ExecuteScriptAndExtractBool( | |
62 web_contents, | |
63 "var scriptingAPI = new PDFScriptingAPI(window, " | |
64 " document.getElementsByTagName('embed')[0]);" | |
65 "scriptingAPI.setLoadCallback(function(success) {" | |
66 " window.domAutomationController.send(success);" | |
67 "});", | |
68 &load_success)); | |
69 return load_success; | |
70 } | |
71 | |
51 } // namespace pdf_extension_util | 72 } // namespace pdf_extension_util |
OLD | NEW |