OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/api/page_capture/page_capture_api.h" | 5 #include "chrome/browser/extensions/api/page_capture/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" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/common/extensions/api/page_capture.h" | |
12 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
13 #include "content/public/browser/child_process_security_policy.h" | 14 #include "content/public/browser/child_process_security_policy.h" |
14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 | 21 |
21 #include <limits> | 22 #include <limits> |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 using content::ChildProcessSecurityPolicy; | 25 using content::ChildProcessSecurityPolicy; |
25 using content::WebContents; | 26 using content::WebContents; |
26 using extensions::PageCaptureSaveAsMHTMLFunction; | 27 using extensions::PageCaptureSaveAsMHTMLFunction; |
27 using webkit_blob::ShareableFileReference; | 28 using webkit_blob::ShareableFileReference; |
28 | 29 |
30 namespace SaveAsMHTML = extensions::api::page_capture::SaveAsMHTML; | |
31 | |
29 namespace { | 32 namespace { |
30 | 33 |
31 // Error messages. | 34 // Error messages. |
32 const char* const kFileTooBigError = "The MHTML file generated is too big."; | 35 const char* const kFileTooBigError = "The MHTML file generated is too big."; |
33 const char* const kMHTMLGenerationFailedError = "Failed to generate MHTML."; | 36 const char* const kMHTMLGenerationFailedError = "Failed to generate MHTML."; |
34 const char* const kSizeRetrievalError = | 37 const char* const kSizeRetrievalError = |
35 "Failed to retrieve size of generated MHTML."; | 38 "Failed to retrieve size of generated MHTML."; |
36 const char* const kTemporaryFileError = "Failed to create a temporary file."; | 39 const char* const kTemporaryFileError = "Failed to create a temporary file."; |
37 const char* const kTabClosedError = "Cannot find the tab for thie request."; | 40 const char* const kTabClosedError = "Cannot find the tab for thie request."; |
38 | 41 |
39 } // namespace | 42 } // namespace |
40 | 43 |
41 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL; | 44 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL; |
42 | 45 |
43 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() : tab_id_(0) { | 46 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() : tab_id_(0) { |
44 } | 47 } |
45 | 48 |
46 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() { | 49 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() { |
47 if (mhtml_file_.get()) { | 50 if (mhtml_file_.get()) { |
48 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, | 51 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, |
49 mhtml_file_.release()); | 52 mhtml_file_.release()); |
50 } | 53 } |
51 } | 54 } |
52 | 55 |
53 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) { | 56 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) { |
54 test_delegate_ = delegate; | 57 test_delegate_ = delegate; |
55 } | 58 } |
56 | 59 |
57 bool PageCaptureSaveAsMHTMLFunction::RunImpl() { | 60 bool PageCaptureSaveAsMHTMLFunction::RunImpl() { |
58 DictionaryValue* args; | 61 scoped_ptr<SaveAsMHTML::Params> params(SaveAsMHTML::Params::Create(*args_)); |
59 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 62 EXTENSION_FUNCTION_VALIDATE(params.get()); |
60 | |
61 if (!args->HasKey("tabId")) | |
62 return false; | |
63 | |
64 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id_)); | |
Mihai Parparita -not on Chrome
2012/07/30 23:51:26
Seems like you still need to populate the tab_id_
mitchellwrosen
2012/07/31 00:22:29
Whoops, my mistake. You're right.
| |
65 | 63 |
66 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() | 64 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() |
67 | 65 |
68 BrowserThread::PostTask( | 66 BrowserThread::PostTask( |
69 BrowserThread::FILE, FROM_HERE, | 67 BrowserThread::FILE, FROM_HERE, |
70 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); | 68 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); |
71 return true; | 69 return true; |
72 } | 70 } |
73 | 71 |
74 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView( | 72 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 WebContents* PageCaptureSaveAsMHTMLFunction::GetWebContents() { | 190 WebContents* PageCaptureSaveAsMHTMLFunction::GetWebContents() { |
193 Browser* browser = NULL; | 191 Browser* browser = NULL; |
194 TabContents* tab_contents = NULL; | 192 TabContents* tab_contents = NULL; |
195 | 193 |
196 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), | 194 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
197 &browser, NULL, &tab_contents, NULL)) { | 195 &browser, NULL, &tab_contents, NULL)) { |
198 return NULL; | 196 return NULL; |
199 } | 197 } |
200 return tab_contents->web_contents(); | 198 return tab_contents->web_contents(); |
201 } | 199 } |
OLD | NEW |