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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PAGE_CAPTURE_PAGE_CAPTURE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_PAGE_CAPTURE_PAGE_CAPTURE_API_H_
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/common/extensions/api/page_capture.h"
13 #include "webkit/common/blob/shareable_file_reference.h"
23 namespace extensions {
25 class PageCaptureSaveAsMHTMLFunction : public ChromeAsyncExtensionFunction {
27 PageCaptureSaveAsMHTMLFunction();
29 // Test specific delegate used to test that the temporary file gets deleted.
32 // Called on the UI thread when the temporary file that contains the
33 // generated data has been created.
34 virtual void OnTemporaryFileCreated(const base::FilePath& temp_file) = 0;
36 static void SetTestDelegate(TestDelegate* delegate);
39 virtual ~PageCaptureSaveAsMHTMLFunction();
40 virtual bool RunImpl() OVERRIDE;
41 virtual bool OnMessageReceivedFromRenderView(
42 const IPC::Message& message) OVERRIDE;
44 // Called on the file thread.
45 void CreateTemporaryFile();
47 // Called on the UI thread.
48 void TemporaryFileCreated(bool success);
49 void ReturnFailure(const std::string& error);
50 void ReturnSuccess(int64 file_size);
52 // Callback called once the MHTML generation is done.
53 void MHTMLGenerated(int64 mhtml_file_size);
55 // Returns the WebContents we are associated with, NULL if it's been closed.
56 content::WebContents* GetWebContents();
58 scoped_ptr<extensions::api::page_capture::SaveAsMHTML::Params> params_;
60 // The path to the temporary file containing the MHTML data.
61 base::FilePath mhtml_path_;
63 // The file containing the MHTML.
64 scoped_refptr<webkit_blob::ShareableFileReference> mhtml_file_;
66 DECLARE_EXTENSION_FUNCTION("pageCapture.saveAsMHTML", PAGECAPTURE_SAVEASMHTML)
69 } // namespace extensions
71 #endif // CHROME_BROWSER_EXTENSIONS_API_PAGE_CAPTURE_PAGE_CAPTURE_API_H_