Chromium Code Reviews| Index: chrome/browser/extensions/extension_save_page_api.cc |
| diff --git a/chrome/browser/extensions/extension_save_page_api.cc b/chrome/browser/extensions/extension_save_page_api.cc |
| index 7fb8416d1b14e8ad26b2ce0d26515b14a98b9579..e579ebbfab332c0b8679f09204791781b57db1ba 100644 |
| --- a/chrome/browser/extensions/extension_save_page_api.cc |
| +++ b/chrome/browser/extensions/extension_save_page_api.cc |
| @@ -8,6 +8,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/extensions/extension_tab_util.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| +#include "chrome/common/extensions/extension_messages.h" |
| #include "content/browser/child_process_security_policy.h" |
| #include "content/browser/renderer_host/render_view_host.h" |
| #include "content/browser/tab_contents/tab_contents.h" |
| @@ -42,6 +43,28 @@ bool SavePageAsMHTMLFunction::RunImpl() { |
| return true; |
| } |
| +bool SavePageAsMHTMLFunction::OnMessageReceivedFromRenderView( |
| + const IPC::Message& message) { |
| + if (message.type() != ExtensionHostMsg_ResponseAck::ID) |
| + return false; |
| + |
| + int message_request_id; |
| + void* iter = NULL; |
| + if (!message.ReadInt(&iter, &message_request_id)) { |
| + NOTREACHED() << "malformed extension message"; |
| + return true; |
| + } |
| + |
| + if (message_request_id != request_id()) |
| + return false; |
| + |
| + // The extension process has processed the response and has created a |
| + // reference to the blob, it is safe for us to go away. |
| + Release(); // Balanced in Run() |
| + |
| + return true; |
| +} |
| + |
| void SavePageAsMHTMLFunction::CreateTemporaryFile() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| // TODO(jcivelli): http://crbug.com/97489 we don't clean-up the temporary file |
| @@ -59,16 +82,18 @@ void SavePageAsMHTMLFunction::TemporaryFileCreated(bool success) { |
| return; |
| } |
| - Browser* browser = NULL; |
| - TabContentsWrapper* tab_contents_wrapper = NULL; |
| + // Sets a DeletableFileReference so the temporary file gets deleted once it is |
| + // no longer used. |
| + mhtml_file_ = webkit_blob::DeletableFileReference::GetOrCreate(mhtml_path_, |
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| - if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
| - &browser, NULL, &tab_contents_wrapper, NULL)) { |
| + |
| + TabContents* tab_contents = GetTabContents(); |
| + if (!tab_contents) { |
| ReturnFailure(kTabClosedError); |
| return; |
| } |
| - TabContents* tab_contents = tab_contents_wrapper->tab_contents(); |
| registrar_.Add( |
| this, content::NOTIFICATION_MHTML_GENERATED, |
| content::Source<RenderViewHost>(tab_contents->render_view_host())); |
| @@ -124,6 +149,12 @@ void SavePageAsMHTMLFunction::ReturnFailure(const std::string& error) { |
| void SavePageAsMHTMLFunction::ReturnSuccess(int64 file_size) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + TabContents* tab_contents = GetTabContents(); |
| + if (!tab_contents) { |
| + ReturnFailure(kTabClosedError); |
| + return; |
| + } |
| + |
| int child_id = render_view_host()->process()->id(); |
| ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( |
| child_id, mhtml_path_); |
| @@ -135,5 +166,17 @@ void SavePageAsMHTMLFunction::ReturnSuccess(int64 file_size) { |
| SendResponse(true); |
| - Release(); // Balanced in Run() |
| + // Note that we'll wait for a response ack message before we call Release() |
|
asargent_no_longer_on_chrome
2011/11/15 18:56:31
nit: might be worth mentioning that where this hap
Jay Civelli
2011/11/18 23:14:32
Done.
|
| + // (to prevent the blob file from being deleted). |
| +} |
| + |
| +TabContents* SavePageAsMHTMLFunction::GetTabContents() { |
| + Browser* browser = NULL; |
|
Mihai Parparita -not on Chrome
2011/11/15 18:51:42
Body of this function is indented one too many tim
Jay Civelli
2011/11/18 23:14:32
Done.
|
| + TabContentsWrapper* tab_contents_wrapper = NULL; |
| + |
| + if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
| + &browser, NULL, &tab_contents_wrapper, NULL)) { |
| + return NULL; |
| + } |
| + return tab_contents_wrapper->tab_contents(); |
| } |