Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/extensions/api/page_capture/page_capture_api.cc

Issue 10806072: Refactor chrome.pageCapture to use JSON schema compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_messages.h" 12 #include "chrome/common/extensions/extension_messages.h"
13 #include "content/public/browser/child_process_security_policy.h" 13 #include "content/public/browser/child_process_security_policy.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 20
21 #include <limits> 21 #include <limits>
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using content::ChildProcessSecurityPolicy; 24 using content::ChildProcessSecurityPolicy;
25 using content::WebContents; 25 using content::WebContents;
26 using extensions::PageCaptureSaveAsMHTMLFunction; 26 using extensions::PageCaptureSaveAsMHTMLFunction;
27 using webkit_blob::ShareableFileReference; 27 using webkit_blob::ShareableFileReference;
28 28
29 namespace SaveAsMHTML = extensions::api::page_capture::SaveAsMHTML;
30
29 namespace { 31 namespace {
30 32
31 // Error messages. 33 // Error messages.
32 const char* const kFileTooBigError = "The MHTML file generated is too big."; 34 const char* const kFileTooBigError = "The MHTML file generated is too big.";
33 const char* const kMHTMLGenerationFailedError = "Failed to generate MHTML."; 35 const char* const kMHTMLGenerationFailedError = "Failed to generate MHTML.";
34 const char* const kSizeRetrievalError = 36 const char* const kSizeRetrievalError =
35 "Failed to retrieve size of generated MHTML."; 37 "Failed to retrieve size of generated MHTML.";
36 const char* const kTemporaryFileError = "Failed to create a temporary file."; 38 const char* const kTemporaryFileError = "Failed to create a temporary file.";
37 const char* const kTabClosedError = "Cannot find the tab for thie request."; 39 const char* const kTabClosedError = "Cannot find the tab for thie request.";
38 40
39 } // namespace 41 } // namespace
40 42
41 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL; 43 static PageCaptureSaveAsMHTMLFunction::TestDelegate* test_delegate_ = NULL;
42 44
43 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() : tab_id_(0) { 45 PageCaptureSaveAsMHTMLFunction::PageCaptureSaveAsMHTMLFunction() {
44 } 46 }
45 47
46 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() { 48 PageCaptureSaveAsMHTMLFunction::~PageCaptureSaveAsMHTMLFunction() {
47 if (mhtml_file_.get()) { 49 if (mhtml_file_.get()) {
48 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, 50 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE,
49 mhtml_file_.release()); 51 mhtml_file_.release());
50 } 52 }
51 } 53 }
52 54
53 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) { 55 void PageCaptureSaveAsMHTMLFunction::SetTestDelegate(TestDelegate* delegate) {
54 test_delegate_ = delegate; 56 test_delegate_ = delegate;
55 } 57 }
56 58
57 bool PageCaptureSaveAsMHTMLFunction::RunImpl() { 59 bool PageCaptureSaveAsMHTMLFunction::RunImpl() {
58 DictionaryValue* args; 60 params_ = SaveAsMHTML::Params::Create(*args_);
59 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 61 EXTENSION_FUNCTION_VALIDATE(params_.get());
60
61 if (!args->HasKey("tabId"))
62 return false;
63
64 EXTENSION_FUNCTION_VALIDATE(args->GetInteger("tabId", &tab_id_));
65 62
66 AddRef(); // Balanced in ReturnFailure/ReturnSuccess() 63 AddRef(); // Balanced in ReturnFailure/ReturnSuccess()
67 64
68 BrowserThread::PostTask( 65 BrowserThread::PostTask(
69 BrowserThread::FILE, FROM_HERE, 66 BrowserThread::FILE, FROM_HERE,
70 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this)); 67 base::Bind(&PageCaptureSaveAsMHTMLFunction::CreateTemporaryFile, this));
71 return true; 68 return true;
72 } 69 }
73 70
74 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView( 71 bool PageCaptureSaveAsMHTMLFunction::OnMessageReceivedFromRenderView(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 183
187 // Note that we'll wait for a response ack message received in 184 // Note that we'll wait for a response ack message received in
188 // OnMessageReceivedFromRenderView before we call Release() (to prevent the 185 // OnMessageReceivedFromRenderView before we call Release() (to prevent the
189 // blob file from being deleted). 186 // blob file from being deleted).
190 } 187 }
191 188
192 WebContents* PageCaptureSaveAsMHTMLFunction::GetWebContents() { 189 WebContents* PageCaptureSaveAsMHTMLFunction::GetWebContents() {
193 Browser* browser = NULL; 190 Browser* browser = NULL;
194 TabContents* tab_contents = NULL; 191 TabContents* tab_contents = NULL;
195 192
196 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), 193 if (!ExtensionTabUtil::GetTabById(params_->details.tab_id, profile(),
197 &browser, NULL, &tab_contents, NULL)) { 194 include_incognito(), &browser, NULL,
195 &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 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/page_capture/page_capture_api.h ('k') | chrome/common/extensions/api/api.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698