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

Side by Side Diff: chrome/renderer/chrome_ppb_pdf_impl.cc

Issue 9188056: Start splitting out WebUI into an implementation class and an interface that each page implements... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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/renderer/chrome_ppb_pdf_impl.h" 5 #include "chrome/renderer/chrome_ppb_pdf_impl.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
11 #include "content/public/common/child_process_sandbox_support_linux.h" 11 #include "content/public/common/child_process_sandbox_support_linux.h"
12 #include "content/public/common/content_client.h"
12 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
13 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
14 #include "grit/webkit_resources.h" 15 #include "grit/webkit_resources.h"
15 #include "grit/webkit_strings.h" 16 #include "grit/webkit_strings.h"
16 #include "ppapi/c/pp_resource.h" 17 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/private/ppb_pdf.h" 18 #include "ppapi/c/private/ppb_pdf.h"
18 #include "ppapi/shared_impl/resource.h" 19 #include "ppapi/shared_impl/resource.h"
19 #include "ppapi/shared_impl/resource_tracker.h" 20 #include "ppapi/shared_impl/resource_tracker.h"
20 #include "ppapi/shared_impl/var.h" 21 #include "ppapi/shared_impl/var.h"
21 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7 }, 117 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7, IDR_PDF_PROGRESS_BAR_7 },
117 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8 }, 118 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8 },
118 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND, 119 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND,
119 IDR_PDF_PROGRESS_BAR_BACKGROUND }, 120 IDR_PDF_PROGRESS_BAR_BACKGROUND },
120 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW }, 121 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW },
121 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON }, 122 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON },
122 }; 123 };
123 124
124 PP_Var GetLocalizedString(PP_Instance instance_id, 125 PP_Var GetLocalizedString(PP_Instance instance_id,
125 PP_ResourceString string_id) { 126 PP_ResourceString string_id) {
126 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 127 PluginInstance* instance =
128 content::GetHostGlobals()->GetInstance(instance_id);
127 if (!instance) 129 if (!instance)
128 return PP_MakeUndefined(); 130 return PP_MakeUndefined();
129 131
130 std::string rv; 132 std::string rv;
131 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) { 133 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) {
132 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD)); 134 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD));
133 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) { 135 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) {
134 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING)); 136 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING));
135 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) { 137 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) {
136 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); 138 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED));
(...skipping 15 matching lines...) Expand all
152 break; 154 break;
153 } 155 }
154 } 156 }
155 if (res_id == 0) 157 if (res_id == 0)
156 return 0; 158 return 0;
157 159
158 SkBitmap* res_bitmap = 160 SkBitmap* res_bitmap =
159 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); 161 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id);
160 162
161 // Validate the instance. 163 // Validate the instance.
162 if (!HostGlobals::Get()->GetInstance(instance_id)) 164 if (!content::GetHostGlobals()->GetInstance(instance_id))
163 return 0; 165 return 0;
164 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( 166 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data(
165 new webkit::ppapi::PPB_ImageData_Impl(instance_id)); 167 new webkit::ppapi::PPB_ImageData_Impl(instance_id));
166 if (!image_data->Init( 168 if (!image_data->Init(
167 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), 169 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(),
168 res_bitmap->width(), res_bitmap->height(), false)) { 170 res_bitmap->width(), res_bitmap->height(), false)) {
169 return 0; 171 return 0;
170 } 172 }
171 173
172 webkit::ppapi::ImageDataAutoMapper mapper(image_data); 174 webkit::ppapi::ImageDataAutoMapper mapper(image_data);
173 if (!mapper.is_valid()) 175 if (!mapper.is_valid())
174 return 0; 176 return 0;
175 177
176 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); 178 skia::PlatformCanvas* canvas = image_data->mapped_canvas();
177 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will 179 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will
178 // ignore the allocated pixels in shared memory and re-allocate a new buffer. 180 // ignore the allocated pixels in shared memory and re-allocate a new buffer.
179 canvas->writePixels(*res_bitmap, 0, 0); 181 canvas->writePixels(*res_bitmap, 0, 0);
180 182
181 return image_data->GetReference(); 183 return image_data->GetReference();
182 } 184 }
183 185
184 PP_Resource GetFontFileWithFallback( 186 PP_Resource GetFontFileWithFallback(
185 PP_Instance instance_id, 187 PP_Instance instance_id,
186 const PP_FontDescription_Dev* description, 188 const PP_FontDescription_Dev* description,
187 PP_PrivateFontCharset charset) { 189 PP_PrivateFontCharset charset) {
188 #if defined(OS_LINUX) || defined(OS_OPENBSD) 190 #if defined(OS_LINUX) || defined(OS_OPENBSD)
189 // Validate the instance before using it below. 191 // Validate the instance before using it below.
190 if (!HostGlobals::Get()->GetInstance(instance_id)) 192 if (!content::GetHostGlobals()->GetInstance(instance_id))
191 return 0; 193 return 0;
192 194
193 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( 195 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar(
194 description->face)); 196 description->face));
195 if (!face_name) 197 if (!face_name)
196 return 0; 198 return 0;
197 199
198 int fd = content::MatchFontWithFallback( 200 int fd = content::MatchFontWithFallback(
199 face_name->value().c_str(), 201 face_name->value().c_str(),
200 description->weight >= PP_FONTWEIGHT_BOLD, 202 description->weight >= PP_FONTWEIGHT_BOLD,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 malloc(*count * sizeof(PP_PrivateFindResult))); 276 malloc(*count * sizeof(PP_PrivateFindResult)));
275 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult)); 277 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult));
276 } else { 278 } else {
277 *results = NULL; 279 *results = NULL;
278 } 280 }
279 281
280 usearch_close(searcher); 282 usearch_close(searcher);
281 } 283 }
282 284
283 void DidStartLoading(PP_Instance instance_id) { 285 void DidStartLoading(PP_Instance instance_id) {
284 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 286 PluginInstance* instance = content::GetHostGlobals()->GetInstance(instance_id) ;
285 if (!instance) 287 if (!instance)
286 return; 288 return;
287 instance->delegate()->DidStartLoading(); 289 instance->delegate()->DidStartLoading();
288 } 290 }
289 291
290 void DidStopLoading(PP_Instance instance_id) { 292 void DidStopLoading(PP_Instance instance_id) {
291 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 293 PluginInstance* instance =
294 content::GetHostGlobals()->GetInstance(instance_id);
292 if (!instance) 295 if (!instance)
293 return; 296 return;
294 instance->delegate()->DidStopLoading(); 297 instance->delegate()->DidStopLoading();
295 } 298 }
296 299
297 void SetContentRestriction(PP_Instance instance_id, int restrictions) { 300 void SetContentRestriction(PP_Instance instance_id, int restrictions) {
298 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 301 PluginInstance* instance =
302 content::GetHostGlobals()->GetInstance(instance_id);
299 if (!instance) 303 if (!instance)
300 return; 304 return;
301 instance->delegate()->SetContentRestriction(restrictions); 305 instance->delegate()->SetContentRestriction(restrictions);
302 } 306 }
303 307
304 void HistogramPDFPageCount(int count) { 308 void HistogramPDFPageCount(int count) {
305 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); 309 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count);
306 } 310 }
307 311
308 void UserMetricsRecordAction(PP_Var action) { 312 void UserMetricsRecordAction(PP_Var action) {
309 scoped_refptr<ppapi::StringVar> action_str( 313 scoped_refptr<ppapi::StringVar> action_str(
310 ppapi::StringVar::FromPPVar(action)); 314 ppapi::StringVar::FromPPVar(action));
311 if (action_str) 315 if (action_str)
312 RenderThread::Get()->RecordUserMetrics(action_str->value()); 316 RenderThread::Get()->RecordUserMetrics(action_str->value());
313 } 317 }
314 318
315 void HasUnsupportedFeature(PP_Instance instance_id) { 319 void HasUnsupportedFeature(PP_Instance instance_id) {
316 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 320 PluginInstance* instance =
321 content::GetHostGlobals()->GetInstance(instance_id);
317 if (!instance) 322 if (!instance)
318 return; 323 return;
319 324
320 // Only want to show an info bar if the pdf is the whole tab. 325 // Only want to show an info bar if the pdf is the whole tab.
321 if (!instance->IsFullPagePlugin()) 326 if (!instance->IsFullPagePlugin())
322 return; 327 return;
323 328
324 WebView* view = instance->container()->element().document().frame()->view(); 329 WebView* view = instance->container()->element().document().frame()->view();
325 content::RenderView* render_view = content::RenderView::FromWebView(view); 330 content::RenderView* render_view = content::RenderView::FromWebView(view);
326 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( 331 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature(
327 render_view->GetRoutingId())); 332 render_view->GetRoutingId()));
328 } 333 }
329 334
330 void SaveAs(PP_Instance instance_id) { 335 void SaveAs(PP_Instance instance_id) {
331 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); 336 PluginInstance* instance =
337 content::GetHostGlobals()->GetInstance(instance_id);
332 if (!instance) 338 if (!instance)
333 return; 339 return;
334 instance->delegate()->SaveURLAs(instance->plugin_url()); 340 instance->delegate()->SaveURLAs(instance->plugin_url());
335 } 341 }
336 342
337 const PPB_PDF ppb_pdf = { 343 const PPB_PDF ppb_pdf = {
338 &GetLocalizedString, 344 &GetLocalizedString,
339 &GetResourceImage, 345 &GetResourceImage,
340 &GetFontFileWithFallback, 346 &GetFontFileWithFallback,
341 &GetFontTableForPrivateFontFile, 347 &GetFontTableForPrivateFontFile,
342 &SearchString, 348 &SearchString,
343 &DidStartLoading, 349 &DidStartLoading,
344 &DidStopLoading, 350 &DidStopLoading,
345 &SetContentRestriction, 351 &SetContentRestriction,
346 &HistogramPDFPageCount, 352 &HistogramPDFPageCount,
347 &UserMetricsRecordAction, 353 &UserMetricsRecordAction,
348 &HasUnsupportedFeature, 354 &HasUnsupportedFeature,
349 &SaveAs 355 &SaveAs
350 }; 356 };
351 357
352 // static 358 // static
353 const PPB_PDF* PPB_PDF_Impl::GetInterface() { 359 const PPB_PDF* PPB_PDF_Impl::GetInterface() {
354 return &ppb_pdf; 360 return &ppb_pdf;
355 } 361 }
356 362
357 } // namespace chrome 363 } // namespace chrome
358 364
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/workers_ui.cc ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698