| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/page_capture/page_capture_api.h" | 5 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 return false; | 82 return false; |
| 83 | 83 |
| 84 // The extension process has processed the response and has created a | 84 // The extension process has processed the response and has created a |
| 85 // reference to the blob, it is safe for us to go away. | 85 // reference to the blob, it is safe for us to go away. |
| 86 Release(); // Balanced in Run() | 86 Release(); // Balanced in Run() |
| 87 | 87 |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile() { | 91 void PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile() { |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 92 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 93 bool success = base::CreateTemporaryFile(&mhtml_path_); | 93 bool success = base::CreateTemporaryFile(&mhtml_path_); |
| 94 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 95 BrowserThread::IO, FROM_HERE, | 95 BrowserThread::IO, FROM_HERE, |
| 96 base::Bind(&PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, this, | 96 base::Bind(&PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, this, |
| 97 success)); | 97 success)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated(bool success) { | 100 void PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated(bool success) { |
| 101 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 101 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 102 if (success) { | 102 if (success) { |
| 103 // Setup a ShareableFileReference so the temporary file gets deleted | 103 // Setup a ShareableFileReference so the temporary file gets deleted |
| 104 // once it is no longer used. | 104 // once it is no longer used. |
| 105 mhtml_file_ = ShareableFileReference::GetOrCreate( | 105 mhtml_file_ = ShareableFileReference::GetOrCreate( |
| 106 mhtml_path_, | 106 mhtml_path_, |
| 107 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 107 ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
| 108 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | 108 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
| 109 .get()); | 109 .get()); |
| 110 } | 110 } |
| 111 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
| 112 BrowserThread::UI, FROM_HERE, | 112 BrowserThread::UI, FROM_HERE, |
| 113 base::Bind(&PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, this, | 113 base::Bind(&PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, this, |
| 114 success)); | 114 success)); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| 117 | 117 |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 if (!success) { | 119 if (!success) { |
| 120 ReturnFailure(kTemporaryFileError); | 120 ReturnFailure(kTemporaryFileError); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (test_delegate_) | 124 if (test_delegate_) |
| 125 test_delegate_->OnTemporaryFileCreated(mhtml_path_); | 125 test_delegate_->OnTemporaryFileCreated(mhtml_path_); |
| 126 | 126 |
| 127 WebContents* web_contents = GetWebContents(); | 127 WebContents* web_contents = GetWebContents(); |
| 128 if (!web_contents) { | 128 if (!web_contents) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 | 144 |
| 145 if (mhtml_file_size > std::numeric_limits<int>::max()) { | 145 if (mhtml_file_size > std::numeric_limits<int>::max()) { |
| 146 ReturnFailure(kFileTooBigError); | 146 ReturnFailure(kFileTooBigError); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 ReturnSuccess(mhtml_file_size); | 150 ReturnSuccess(mhtml_file_size); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void PageCaptureSaveAsMHTMLFunction::ReturnFailure(const std::string& error) { | 153 void PageCaptureSaveAsMHTMLFunction::ReturnFailure(const std::string& error) { |
| 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 154 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 155 | 155 |
| 156 error_ = error; | 156 error_ = error; |
| 157 | 157 |
| 158 SendResponse(false); | 158 SendResponse(false); |
| 159 | 159 |
| 160 Release(); // Balanced in Run() | 160 Release(); // Balanced in Run() |
| 161 } | 161 } |
| 162 | 162 |
| 163 void PageCaptureSaveAsMHTMLFunction::ReturnSuccess(int64 file_size) { | 163 void PageCaptureSaveAsMHTMLFunction::ReturnSuccess(int64 file_size) { |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 165 | 165 |
| 166 WebContents* web_contents = GetWebContents(); | 166 WebContents* web_contents = GetWebContents(); |
| 167 if (!web_contents || !render_view_host()) { | 167 if (!web_contents || !render_view_host()) { |
| 168 ReturnFailure(kTabClosedError); | 168 ReturnFailure(kTabClosedError); |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 | 171 |
| 172 int child_id = render_view_host()->GetProcess()->GetID(); | 172 int child_id = render_view_host()->GetProcess()->GetID(); |
| 173 ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( | 173 ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( |
| 174 child_id, mhtml_path_); | 174 child_id, mhtml_path_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 193 GetProfile(), | 193 GetProfile(), |
| 194 include_incognito(), | 194 include_incognito(), |
| 195 &browser, | 195 &browser, |
| 196 NULL, | 196 NULL, |
| 197 &web_contents, | 197 &web_contents, |
| 198 NULL)) { | 198 NULL)) { |
| 199 return NULL; | 199 return NULL; |
| 200 } | 200 } |
| 201 return web_contents; | 201 return web_contents; |
| 202 } | 202 } |
| OLD | NEW |