Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / page_capture / page_capture_api.h
blobad467bbd171fc82e803e4b64af2cf635951e90e4
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_
8 #include <string>
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 "storage/browser/blob/shareable_file_reference.h"
15 namespace base {
16 class FilePath;
19 namespace content {
20 class WebContents;
23 namespace extensions {
25 class PageCaptureSaveAsMHTMLFunction : public ChromeAsyncExtensionFunction {
26 public:
27 PageCaptureSaveAsMHTMLFunction();
29 // Test specific delegate used to test that the temporary file gets deleted.
30 class TestDelegate {
31 public:
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);
38 private:
39 ~PageCaptureSaveAsMHTMLFunction() override;
40 bool RunAsync() override;
41 bool OnMessageReceived(const IPC::Message& message) override;
43 // Called on the file thread.
44 void CreateTemporaryFile();
46 // Called on the UI thread.
47 void TemporaryFileCreated(bool success);
48 void ReturnFailure(const std::string& error);
49 void ReturnSuccess(int64 file_size);
51 // Callback called once the MHTML generation is done.
52 void MHTMLGenerated(int64 mhtml_file_size);
54 // Returns the WebContents we are associated with, NULL if it's been closed.
55 content::WebContents* GetWebContents();
57 scoped_ptr<extensions::api::page_capture::SaveAsMHTML::Params> params_;
59 // The path to the temporary file containing the MHTML data.
60 base::FilePath mhtml_path_;
62 // The file containing the MHTML.
63 scoped_refptr<storage::ShareableFileReference> mhtml_file_;
65 DECLARE_EXTENSION_FUNCTION("pageCapture.saveAsMHTML", PAGECAPTURE_SAVEASMHTML)
68 } // namespace extensions
70 #endif // CHROME_BROWSER_EXTENSIONS_API_PAGE_CAPTURE_PAGE_CAPTURE_API_H_