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

Side by Side Diff: chrome/browser/ui/webui/print_preview_ui.cc

Issue 7063030: PrintPreview: Print Preview is not staying associated with initiator renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/webui/print_preview_ui.h" 5 #include "chrome/browser/ui/webui/print_preview_ui.h"
6 6
7 #include "base/string_util.h"
7 #include "base/values.h" 8 #include "base/values.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/printing/print_preview_data_service_factory.h"
11 #include "chrome/browser/printing/print_preview_data_service.h"
12 #include "chrome/browser/ui/webui/print_preview_data_source.h"
9 #include "chrome/browser/ui/webui/print_preview_handler.h" 13 #include "chrome/browser/ui/webui/print_preview_handler.h"
10 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h"
11 #include "content/browser/browser_thread.h"
12 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
13 15
14 PrintPreviewUI::PrintPreviewUI(TabContents* contents) 16 PrintPreviewUI::PrintPreviewUI(TabContents* contents) : WebUI(contents) {
15 : WebUI(contents),
16 html_source_(new PrintPreviewUIHTMLSource()) {
17 // PrintPreviewUI owns |handler|. 17 // PrintPreviewUI owns |handler|.
18 PrintPreviewHandler* handler = new PrintPreviewHandler(); 18 PrintPreviewHandler* handler = new PrintPreviewHandler();
19 AddMessageHandler(handler->Attach(this)); 19 AddMessageHandler(handler->Attach(this));
20 20
21 // Set up the chrome://print/ source. 21 // Set up the chrome://print/ data source.
22 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source_); 22 PrintPreviewDataSource* data_source =
23 new PrintPreviewDataSource(contents->profile());
24 contents->profile()->GetChromeURLDataManager()->AddDataSource(data_source);
25
26 // Store the PrintPreviewUIAddress as a string.
27 char preview_ui_addr[(2 * sizeof(this)) + 3];
Lei Zhang 2011/05/27 17:26:53 add a comment to explain the math here.
kmadhusu 2011/05/27 23:44:42 Done.
28 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this);
29 preview_ui_addr_str_ = preview_ui_addr;
23 } 30 }
24 31
25 PrintPreviewUI::~PrintPreviewUI() { 32 PrintPreviewUI::~PrintPreviewUI() {
33 PrintPreviewDataServiceFactory::GetForProfile(tab_contents()->profile())->
34 RemoveEntry(preview_ui_addr_str_);
26 } 35 }
27 36
28 PrintPreviewUIHTMLSource* PrintPreviewUI::html_source() { 37 void PrintPreviewUI::GetPrintPreviewData(scoped_refptr<RefCountedBytes>* data) {
29 return html_source_.get(); 38 PrintPreviewDataServiceFactory::GetForProfile(tab_contents()->profile())->
Lei Zhang 2011/05/27 17:26:53 You call PrintPreviewDataServiceFactory::GetForPro
Elliot Glaysher 2011/05/27 17:45:50 I'd prefer not to cache that value now that there'
kmadhusu 2011/05/27 23:44:42 Created a helper function.
39 GetDataEntry(preview_ui_addr_str_, data);
40 }
41
42 void PrintPreviewUI::SetPrintPreviewData(const RefCountedBytes* data) {
43 PrintPreviewDataServiceFactory::GetForProfile(tab_contents()->profile())->
44 SetDataEntry(preview_ui_addr_str_, data);
30 } 45 }
31 46
32 void PrintPreviewUI::OnInitiatorTabClosed( 47 void PrintPreviewUI::OnInitiatorTabClosed(
33 const std::string& initiator_url) { 48 const std::string& initiator_url) {
34 StringValue initiator_tab_url(initiator_url); 49 StringValue initiator_tab_url(initiator_url);
35 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); 50 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url);
36 } 51 }
37 52
38 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, 53 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
39 const string16& job_title, 54 const string16& job_title,
40 bool modifiable) { 55 bool modifiable) {
41 VLOG(1) << "Print preview request finished with " 56 VLOG(1) << "Print preview request finished with "
42 << expected_pages_count << " pages"; 57 << expected_pages_count << " pages";
43 FundamentalValue pages_count(expected_pages_count); 58 FundamentalValue pages_count(expected_pages_count);
44 StringValue title(job_title); 59 StringValue title(job_title);
45 FundamentalValue is_preview_modifiable(modifiable); 60 FundamentalValue is_preview_modifiable(modifiable);
61 StringValue ui_identifier(preview_ui_addr_str_);
46 CallJavascriptFunction("updatePrintPreview", pages_count, title, 62 CallJavascriptFunction("updatePrintPreview", pages_count, title,
47 is_preview_modifiable); 63 is_preview_modifiable, ui_identifier);
48 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698