| 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "content/browser/tab_contents/tab_contents_observer.h" | 12 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 #include "webkit/blob/deletable_file_reference.h" | 13 #include "webkit/blob/deletable_file_reference.h" |
| 16 | 14 |
| 17 class SavePageAsMHTMLFunction : public AsyncExtensionFunction, | 15 class FilePath; |
| 18 public content::NotificationObserver { | 16 |
| 17 class SavePageAsMHTMLFunction : public AsyncExtensionFunction { |
| 19 public: | 18 public: |
| 20 SavePageAsMHTMLFunction(); | 19 SavePageAsMHTMLFunction(); |
| 21 | 20 |
| 22 // Test specific delegate used to test that the temporary file gets deleted. | 21 // Test specific delegate used to test that the temporary file gets deleted. |
| 23 class TestDelegate { | 22 class TestDelegate { |
| 24 public: | 23 public: |
| 25 // Called on the UI thread when the temporary file that contains the | 24 // Called on the UI thread when the temporary file that contains the |
| 26 // generated data has been created. | 25 // generated data has been created. |
| 27 virtual void OnTemporaryFileCreated(const FilePath& temp_file) = 0; | 26 virtual void OnTemporaryFileCreated(const FilePath& temp_file) = 0; |
| 28 }; | 27 }; |
| 29 static void SetTestDelegate(TestDelegate* delegate); | 28 static void SetTestDelegate(TestDelegate* delegate); |
| 30 | 29 |
| 31 private: | 30 private: |
| 32 virtual ~SavePageAsMHTMLFunction(); | 31 virtual ~SavePageAsMHTMLFunction(); |
| 33 virtual bool RunImpl() OVERRIDE; | 32 virtual bool RunImpl() OVERRIDE; |
| 34 virtual void Observe(int type, | |
| 35 const content::NotificationSource& source, | |
| 36 const content::NotificationDetails& details) OVERRIDE; | |
| 37 virtual bool OnMessageReceivedFromRenderView( | 33 virtual bool OnMessageReceivedFromRenderView( |
| 38 const IPC::Message& message) OVERRIDE; | 34 const IPC::Message& message) OVERRIDE; |
| 39 | 35 |
| 40 // Called on the file thread. | 36 // Called on the file thread. |
| 41 void CreateTemporaryFile(); | 37 void CreateTemporaryFile(); |
| 42 | 38 |
| 43 // Called on the UI thread. | 39 // Called on the UI thread. |
| 44 void TemporaryFileCreated(bool success); | 40 void TemporaryFileCreated(bool success); |
| 45 void ReturnFailure(const std::string& error); | 41 void ReturnFailure(const std::string& error); |
| 46 void ReturnSuccess(int64 file_size); | 42 void ReturnSuccess(int64 file_size); |
| 47 | 43 |
| 44 // Callback called once the MHTML generation is done. |
| 45 void MHTMLGenerated(const FilePath& file_path, int64 mhtml_file_size); |
| 46 |
| 48 // Returns the TabContents we are associated with, NULL if it's been closed. | 47 // Returns the TabContents we are associated with, NULL if it's been closed. |
| 49 TabContents* GetTabContents(); | 48 TabContents* GetTabContents(); |
| 50 | 49 |
| 51 int tab_id_; | 50 int tab_id_; |
| 52 | 51 |
| 53 // The path to the temporary file containing the MHTML data. | 52 // The path to the temporary file containing the MHTML data. |
| 54 FilePath mhtml_path_; | 53 FilePath mhtml_path_; |
| 55 | 54 |
| 56 // The file containing the MHTML. | 55 // The file containing the MHTML. |
| 57 scoped_refptr<webkit_blob::DeletableFileReference> mhtml_file_; | 56 scoped_refptr<webkit_blob::DeletableFileReference> mhtml_file_; |
| 58 | 57 |
| 59 content::NotificationRegistrar registrar_; | |
| 60 | |
| 61 DECLARE_EXTENSION_FUNCTION_NAME("experimental.savePage.saveAsMHTML") | 58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.savePage.saveAsMHTML") |
| 62 }; | 59 }; |
| 63 | 60 |
| 64 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ | 61 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SAVE_PAGE_API_H_ |
| OLD | NEW |