| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_page_capture_api.h" | 5 #include "chrome/browser/extensions/extension_page_capture_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 DictionaryValue* args; | 44 DictionaryValue* args; |
| 45 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 45 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 46 | 46 |
| 47 if (!args->HasKey("tabId")) | 47 if (!args->HasKey("tabId")) |
| 48 return false; | 48 return false; |
| 49 | 49 |
| 50 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id_)); | 50 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id_)); |
| 51 | 51 |
| 52 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() | 52 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() |
| 53 | 53 |
| 54 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 54 BrowserThread::PostTask( |
| 55 NewRunnableMethod(this, | 55 BrowserThread::FILE, FROM_HERE, |
| 56 &PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile)); | 56 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView( | 60 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView( |
| 61 const IPC::Message& message) { | 61 const IPC::Message& message) { |
| 62 if (message.type() != ExtensionHostMsg_ResponseAck::ID) | 62 if (message.type() != ExtensionHostMsg_ResponseAck::ID) |
| 63 return false; | 63 return false; |
| 64 | 64 |
| 65 int message_request_id; | 65 int message_request_id; |
| 66 void* iter = NULL; | 66 void* iter = NULL; |
| 67 if (!message.ReadInt(&iter, &message_request_id)) { | 67 if (!message.ReadInt(&iter, &message_request_id)) { |
| 68 NOTREACHED() << "malformed extension message"; | 68 NOTREACHED() << "malformed extension message"; |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (message_request_id != request_id()) | 72 if (message_request_id != request_id()) |
| 73 return false; | 73 return false; |
| 74 | 74 |
| 75 // The extension process has processed the response and has created a | 75 // The extension process has processed the response and has created a |
| 76 // reference to the blob, it is safe for us to go away. | 76 // reference to the blob, it is safe for us to go away. |
| 77 Release(); // Balanced in Run() | 77 Release(); // Balanced in Run() |
| 78 | 78 |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile() { | 82 void PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile() { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 84 bool success = file_util::CreateTemporaryFile(&mhtml_path_); | 84 bool success = file_util::CreateTemporaryFile(&mhtml_path_); |
| 85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 85 BrowserThread::PostTask( |
| 86 NewRunnableMethod(this, | 86 BrowserThread::UI, FROM_HERE, |
| 87 &PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, | 87 base::Bind(&PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated, this, |
| 88 success)); | 88 success)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated(bool success) { | 91 void PageCaptureSaveAsMHTMLFunction::TemporaryFileCreated(bool success) { |
| 92 if (!success) { | 92 if (!success) { |
| 93 ReturnFailure(kTemporaryFileError); | 93 ReturnFailure(kTemporaryFileError); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 if (test_delegate_) | 97 if (test_delegate_) |
| 98 test_delegate_->OnTemporaryFileCreated(mhtml_path_); | 98 test_delegate_->OnTemporaryFileCreated(mhtml_path_); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 TabContents* PageCaptureSaveAsMHTMLFunction::GetTabContents() { | 169 TabContents* PageCaptureSaveAsMHTMLFunction::GetTabContents() { |
| 170 Browser* browser = NULL; | 170 Browser* browser = NULL; |
| 171 TabContentsWrapper* tab_contents_wrapper = NULL; | 171 TabContentsWrapper* tab_contents_wrapper = NULL; |
| 172 | 172 |
| 173 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), | 173 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
| 174 &browser, NULL, &tab_contents_wrapper, NULL)) { | 174 &browser, NULL, &tab_contents_wrapper, NULL)) { |
| 175 return NULL; | 175 return NULL; |
| 176 } | 176 } |
| 177 return tab_contents_wrapper->tab_contents(); | 177 return tab_contents_wrapper->tab_contents(); |
| 178 } | 178 } |
| OLD | NEW |