summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_save_page_api.h
blob: 4afdf62f2fcbb8c5c0e1655ed80634d6d134ee41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_

#include <string>

#include "chrome/browser/extensions/extension_function.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

class SavePageAsMHTMLFunction : public AsyncExtensionFunction,
                                public content::NotificationObserver {
 public:
  SavePageAsMHTMLFunction();

 private:
  virtual ~SavePageAsMHTMLFunction();

  virtual bool RunImpl() OVERRIDE;
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  // Called on the file thread.
  void CreateTemporaryFile();

  // Called on the UI thread.
  void TemporaryFileCreated(bool success);
  void ReturnFailure(const std::string& error);
  void ReturnSuccess(int64 file_size);

  int tab_id_;

  // The path to the temporary file containing the MHTML data.
  FilePath mhtml_path_;

  content::NotificationRegistrar registrar_;
  DECLARE_EXTENSION_FUNCTION_NAME("experimental.savePage.saveAsMHTML")
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_