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

Side by Side Diff: chrome/browser/printing/print_dialog_gtk.cc

Issue 12374003: Fix crash in chrome when trying to print with CUPS down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/printing/print_dialog_gtk.h" 5 #include "chrome/browser/printing/print_dialog_gtk.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <gtk/gtkunixprint.h> 8 #include <gtk/gtkunixprint.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 page_setup_ = NULL; 123 page_setup_ = NULL;
124 } 124 }
125 if (printer_) { 125 if (printer_) {
126 g_object_unref(printer_); 126 g_object_unref(printer_);
127 printer_ = NULL; 127 printer_ = NULL;
128 } 128 }
129 } 129 }
130 130
131 void PrintDialogGtk::UseDefaultSettings() { 131 void PrintDialogGtk::UseDefaultSettings() {
132 DCHECK(!page_setup_); 132 DCHECK(!page_setup_);
133 DCHECK(!printer_);
133 134
134 // |gtk_settings_| is a new object. 135 // |gtk_settings_| is a new object.
135 gtk_settings_ = gtk_print_settings_new(); 136 gtk_settings_ = gtk_print_settings_new();
136 137 page_setup_ = gtk_page_setup_new();
137 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList);
138 printer_ = printer_list->default_printer();
139 if (printer_) {
140 g_object_ref(printer_);
141 gtk_print_settings_set_printer(gtk_settings_,
142 gtk_printer_get_name(printer_));
143 page_setup_ = gtk_printer_get_default_page_size(printer_);
144 }
145
146 if (!page_setup_)
147 page_setup_ = gtk_page_setup_new();
148 138
149 // No page range to initialize for default settings. 139 // No page range to initialize for default settings.
150 PageRanges ranges_vector; 140 PageRanges ranges_vector;
151 PrintSettings settings; 141 PrintSettings settings;
152 InitPrintSettings(ranges_vector, &settings); 142 InitPrintSettings(ranges_vector, &settings);
153 } 143 }
154 144
155 bool PrintDialogGtk::UpdateSettings(const base::DictionaryValue& job_settings, 145 bool PrintDialogGtk::UpdateSettings(const base::DictionaryValue& job_settings,
156 const printing::PageRanges& ranges, 146 const printing::PageRanges& ranges,
157 printing::PrintSettings* settings) { 147 printing::PrintSettings* settings) {
158 bool collate; 148 bool collate;
159 int color; 149 int color;
160 bool landscape; 150 bool landscape;
161 bool print_to_pdf; 151 bool print_to_pdf;
162 int copies; 152 int copies;
163 int duplex_mode; 153 int duplex_mode;
164 std::string device_name; 154 std::string device_name;
165 155
166 if (!job_settings.GetBoolean(printing::kSettingLandscape, &landscape) || 156 if (!job_settings.GetBoolean(printing::kSettingLandscape, &landscape) ||
167 !job_settings.GetBoolean(printing::kSettingCollate, &collate) || 157 !job_settings.GetBoolean(printing::kSettingCollate, &collate) ||
168 !job_settings.GetInteger(printing::kSettingColor, &color) || 158 !job_settings.GetInteger(printing::kSettingColor, &color) ||
169 !job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || 159 !job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) ||
170 !job_settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || 160 !job_settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) ||
171 !job_settings.GetInteger(printing::kSettingCopies, &copies) || 161 !job_settings.GetInteger(printing::kSettingCopies, &copies) ||
172 !job_settings.GetString(printing::kSettingDeviceName, &device_name)) { 162 !job_settings.GetString(printing::kSettingDeviceName, &device_name)) {
173 return false; 163 return false;
174 } 164 }
175 165
166 bool is_cloud_print = job_settings.HasKey(printing::kSettingCloudPrintId);
167
176 if (!gtk_settings_) 168 if (!gtk_settings_)
177 gtk_settings_ = gtk_print_settings_new(); 169 gtk_settings_ = gtk_print_settings_new();
178 170
179 if (!print_to_pdf) { 171 if (!print_to_pdf && !is_cloud_print) {
180 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); 172 scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList);
181 printer_ = printer_list->GetPrinterWithName(device_name.c_str()); 173 printer_ = printer_list->GetPrinterWithName(device_name.c_str());
182 if (printer_) { 174 if (printer_) {
183 g_object_ref(printer_); 175 g_object_ref(printer_);
184 gtk_print_settings_set_printer(gtk_settings_, 176 gtk_print_settings_set_printer(gtk_settings_,
185 gtk_printer_get_name(printer_)); 177 gtk_printer_get_name(printer_));
186 if (!page_setup_) { 178 if (!page_setup_) {
187 page_setup_ = gtk_printer_get_default_page_size(printer_); 179 page_setup_ = gtk_printer_get_default_page_size(printer_);
188 } 180 }
189 } 181 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // Printing finished. Matches AddRef() in PrintDocument(); 412 // Printing finished. Matches AddRef() in PrintDocument();
421 Release(); 413 Release();
422 } 414 }
423 415
424 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges, 416 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges,
425 PrintSettings* settings) { 417 PrintSettings* settings) {
426 printing::PrintSettingsInitializerGtk::InitPrintSettings( 418 printing::PrintSettingsInitializerGtk::InitPrintSettings(
427 gtk_settings_, page_setup_, page_ranges, false, settings); 419 gtk_settings_, page_setup_, page_ranges, false, settings);
428 context_->InitWithSettings(*settings); 420 context_->InitWithSettings(*settings);
429 } 421 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698