Fix: savePage API saves external resources in a wrong directory.
This commit is contained in:
parent
facd0fbc08
commit
49d25d0069
5 changed files with 28 additions and 6 deletions
|
@ -36,8 +36,13 @@ bool SavePageHandler::Handle(const base::FilePath& full_path,
|
||||||
auto download_manager = content::BrowserContext::GetDownloadManager(
|
auto download_manager = content::BrowserContext::GetDownloadManager(
|
||||||
web_contents_->GetBrowserContext());
|
web_contents_->GetBrowserContext());
|
||||||
download_manager->AddObserver(this);
|
download_manager->AddObserver(this);
|
||||||
|
// Chromium will create a 'foo_files' directory under the directory of saving
|
||||||
|
// page 'foo.html' for holding other resource files of 'foo.html'.
|
||||||
|
base::FilePath saved_main_directory_path = full_path.DirName().Append(
|
||||||
|
full_path.RemoveExtension().BaseName().value() +
|
||||||
|
FILE_PATH_LITERAL("_files"));
|
||||||
bool result = web_contents_->SavePage(full_path,
|
bool result = web_contents_->SavePage(full_path,
|
||||||
full_path.DirName(),
|
saved_main_directory_path,
|
||||||
save_type);
|
save_type);
|
||||||
download_manager->RemoveObserver(this);
|
download_manager->RemoveObserver(this);
|
||||||
// If initialization fails which means fail to create |DownloadItem|, we need
|
// If initialization fails which means fail to create |DownloadItem|, we need
|
||||||
|
|
|
@ -303,13 +303,22 @@ describe 'browser-window module', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'save page', ->
|
describe 'save page', ->
|
||||||
savePagePath = path.join fixtures, 'save_page.html'
|
savePageDir = path.join fixtures, 'save_page'
|
||||||
|
savePageHtmlPath = path.join savePageDir, 'save_page.html'
|
||||||
|
savePageJsPath = path.join savePageDir, 'save_page_files', 'test.js'
|
||||||
|
savePageCssPath = path.join savePageDir, 'save_page_files', 'test.css'
|
||||||
it 'should save page', (done) ->
|
it 'should save page', (done) ->
|
||||||
w.webContents.on 'did-finish-load', ->
|
w.webContents.on 'did-finish-load', ->
|
||||||
w.webContents.savePage savePagePath, 'HTMLComplete', (error) ->
|
w.webContents.savePage savePageHtmlPath, 'HTMLComplete', (error) ->
|
||||||
assert.equal error, null
|
assert.equal error, null
|
||||||
assert fs.existsSync savePagePath
|
assert fs.existsSync savePageHtmlPath
|
||||||
fs.unlinkSync savePagePath
|
assert fs.existsSync savePageJsPath
|
||||||
|
assert fs.existsSync savePageCssPath
|
||||||
|
fs.unlinkSync savePageCssPath
|
||||||
|
fs.unlinkSync savePageJsPath
|
||||||
|
fs.unlinkSync savePageHtmlPath
|
||||||
|
fs.rmdirSync path.join savePageDir, 'save_page_files'
|
||||||
|
fs.rmdirSync savePageDir
|
||||||
done()
|
done()
|
||||||
|
|
||||||
w.loadUrl "file://#{fixtures}/api/blank.html"
|
w.loadUrl "file://#{fixtures}/pages/save_page/index.html"
|
||||||
|
|
6
spec/fixtures/pages/save_page/index.html
vendored
Normal file
6
spec/fixtures/pages/save_page/index.html
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<script type="text/javascript" src="test.js"></script>
|
||||||
|
<script type="text/javascript" src="test.css"></script>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
spec/fixtures/pages/save_page/test.css
vendored
Normal file
1
spec/fixtures/pages/save_page/test.css
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
h1 { }
|
1
spec/fixtures/pages/save_page/test.js
vendored
Normal file
1
spec/fixtures/pages/save_page/test.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
console.log('save_page');
|
Loading…
Add table
Add a link
Reference in a new issue