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

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

Issue 8344025: Add a new globals object for PPAPI tracking information. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | content/ppapi_plugin/ppapi_thread.h » ('j') | 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) 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"
(...skipping 11 matching lines...) Expand all
22 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "unicode/usearch.h" 31 #include "unicode/usearch.h"
32 #include "webkit/plugins/ppapi/host_globals.h"
32 #include "webkit/plugins/ppapi/plugin_delegate.h" 33 #include "webkit/plugins/ppapi/plugin_delegate.h"
33 #include "webkit/plugins/ppapi/plugin_module.h" 34 #include "webkit/plugins/ppapi/plugin_module.h"
34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 35 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
35 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 36 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
36 #include "webkit/plugins/ppapi/resource_tracker.h" 37 #include "webkit/plugins/ppapi/resource_tracker.h"
37 38
39 using ppapi::PpapiGlobals;
40 using webkit::ppapi::HostGlobals;
38 using WebKit::WebView; 41 using WebKit::WebView;
39 using content::RenderThread; 42 using content::RenderThread;
40 43
41 namespace chrome { 44 namespace chrome {
42 45
43 #if defined(OS_LINUX) 46 #if defined(OS_LINUX)
44 class PrivateFontFile : public ppapi::Resource { 47 class PrivateFontFile : public ppapi::Resource {
45 public: 48 public:
46 PrivateFontFile(PP_Instance instance, int fd) : Resource(instance), fd_(fd) { 49 PrivateFontFile(PP_Instance instance, int fd) : Resource(instance), fd_(fd) {
47 } 50 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8 }, 119 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8, IDR_PDF_PROGRESS_BAR_8 },
117 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND, 120 { PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND,
118 IDR_PDF_PROGRESS_BAR_BACKGROUND }, 121 IDR_PDF_PROGRESS_BAR_BACKGROUND },
119 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW }, 122 { PP_RESOURCEIMAGE_PDF_PAGE_DROPSHADOW, IDR_PDF_PAGE_DROPSHADOW },
120 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON }, 123 { PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON, IDR_PAN_SCROLL_ICON },
121 }; 124 };
122 125
123 PP_Var GetLocalizedString(PP_Instance instance_id, 126 PP_Var GetLocalizedString(PP_Instance instance_id,
124 PP_ResourceString string_id) { 127 PP_ResourceString string_id) {
125 webkit::ppapi::PluginInstance* instance = 128 webkit::ppapi::PluginInstance* instance =
126 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 129 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
127 if (!instance) 130 if (!instance)
128 return PP_MakeUndefined(); 131 return PP_MakeUndefined();
129 132
130 std::string rv; 133 std::string rv;
131 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) { 134 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) {
132 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD)); 135 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_NEED_PASSWORD));
133 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) { 136 } else if (string_id == PP_RESOURCESTRING_PDFLOADING) {
134 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING)); 137 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOADING));
135 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) { 138 } else if (string_id == PP_RESOURCESTRING_PDFLOAD_FAILED) {
136 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED)); 139 rv = UTF16ToUTF8(l10n_util::GetStringUTF16(IDS_PDF_PAGE_LOAD_FAILED));
(...skipping 15 matching lines...) Expand all
152 break; 155 break;
153 } 156 }
154 } 157 }
155 if (res_id == 0) 158 if (res_id == 0)
156 return 0; 159 return 0;
157 160
158 SkBitmap* res_bitmap = 161 SkBitmap* res_bitmap =
159 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); 162 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id);
160 163
161 // Validate the instance. 164 // Validate the instance.
162 if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id)) 165 if (!HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id))
163 return 0; 166 return 0;
164 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( 167 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data(
165 new webkit::ppapi::PPB_ImageData_Impl(instance_id)); 168 new webkit::ppapi::PPB_ImageData_Impl(instance_id));
166 if (!image_data->Init( 169 if (!image_data->Init(
167 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), 170 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(),
168 res_bitmap->width(), res_bitmap->height(), false)) { 171 res_bitmap->width(), res_bitmap->height(), false)) {
169 return 0; 172 return 0;
170 } 173 }
171 174
172 webkit::ppapi::ImageDataAutoMapper mapper(image_data); 175 webkit::ppapi::ImageDataAutoMapper mapper(image_data);
173 if (!mapper.is_valid()) 176 if (!mapper.is_valid())
174 return 0; 177 return 0;
175 178
176 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); 179 skia::PlatformCanvas* canvas = image_data->mapped_canvas();
177 // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will 180 // 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. 181 // ignore the allocated pixels in shared memory and re-allocate a new buffer.
179 skia::GetTopDevice(*canvas)->writePixels(*res_bitmap, 0, 0); 182 skia::GetTopDevice(*canvas)->writePixels(*res_bitmap, 0, 0);
180 183
181 return image_data->GetReference(); 184 return image_data->GetReference();
182 } 185 }
183 186
184 PP_Resource GetFontFileWithFallback( 187 PP_Resource GetFontFileWithFallback(
185 PP_Instance instance_id, 188 PP_Instance instance_id,
186 const PP_FontDescription_Dev* description, 189 const PP_FontDescription_Dev* description,
187 PP_PrivateFontCharset charset) { 190 PP_PrivateFontCharset charset) {
188 #if defined(OS_LINUX) 191 #if defined(OS_LINUX)
189 // Validate the instance before using it below. 192 // Validate the instance before using it below.
190 if (!webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id)) 193 if (!HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id))
191 return 0; 194 return 0;
192 195
193 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar( 196 scoped_refptr<ppapi::StringVar> face_name(ppapi::StringVar::FromPPVar(
194 description->face)); 197 description->face));
195 if (!face_name) 198 if (!face_name)
196 return 0; 199 return 0;
197 200
198 int fd = content::MatchFontWithFallback( 201 int fd = content::MatchFontWithFallback(
199 face_name->value().c_str(), 202 face_name->value().c_str(),
200 description->weight >= PP_FONTWEIGHT_BOLD, 203 description->weight >= PP_FONTWEIGHT_BOLD,
(...skipping 11 matching lines...) Expand all
212 return 0; 215 return 0;
213 #endif 216 #endif
214 } 217 }
215 218
216 bool GetFontTableForPrivateFontFile(PP_Resource font_file, 219 bool GetFontTableForPrivateFontFile(PP_Resource font_file,
217 uint32_t table, 220 uint32_t table,
218 void* output, 221 void* output,
219 uint32_t* output_length) { 222 uint32_t* output_length) {
220 #if defined(OS_LINUX) 223 #if defined(OS_LINUX)
221 ppapi::Resource* resource = 224 ppapi::Resource* resource =
222 ppapi::TrackerBase::Get()->GetResourceTracker()->GetResource(font_file); 225 PpapiGlobals::Get()->GetResourceTracker()->GetResource(font_file);
223 if (!resource) 226 if (!resource)
224 return false; 227 return false;
225 228
226 PrivateFontFile* font = static_cast<PrivateFontFile*>(resource); 229 PrivateFontFile* font = static_cast<PrivateFontFile*>(resource);
227 return font->GetFontTable(table, output, output_length); 230 return font->GetFontTable(table, output, output_length);
228 #else 231 #else
229 return false; 232 return false;
230 #endif 233 #endif
231 } 234 }
232 235
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult)); 278 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult));
276 } else { 279 } else {
277 *results = NULL; 280 *results = NULL;
278 } 281 }
279 282
280 usearch_close(searcher); 283 usearch_close(searcher);
281 } 284 }
282 285
283 void DidStartLoading(PP_Instance instance_id) { 286 void DidStartLoading(PP_Instance instance_id) {
284 webkit::ppapi::PluginInstance* instance = 287 webkit::ppapi::PluginInstance* instance =
285 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 288 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
286 if (!instance) 289 if (!instance)
287 return; 290 return;
288 instance->delegate()->DidStartLoading(); 291 instance->delegate()->DidStartLoading();
289 } 292 }
290 293
291 void DidStopLoading(PP_Instance instance_id) { 294 void DidStopLoading(PP_Instance instance_id) {
292 webkit::ppapi::PluginInstance* instance = 295 webkit::ppapi::PluginInstance* instance =
293 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 296 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
294 if (!instance) 297 if (!instance)
295 return; 298 return;
296 instance->delegate()->DidStopLoading(); 299 instance->delegate()->DidStopLoading();
297 } 300 }
298 301
299 void SetContentRestriction(PP_Instance instance_id, int restrictions) { 302 void SetContentRestriction(PP_Instance instance_id, int restrictions) {
300 webkit::ppapi::PluginInstance* instance = 303 webkit::ppapi::PluginInstance* instance =
301 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 304 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
302 if (!instance) 305 if (!instance)
303 return; 306 return;
304 instance->delegate()->SetContentRestriction(restrictions); 307 instance->delegate()->SetContentRestriction(restrictions);
305 } 308 }
306 309
307 void HistogramPDFPageCount(int count) { 310 void HistogramPDFPageCount(int count) {
308 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count); 311 UMA_HISTOGRAM_COUNTS_10000("PDF.PageCount", count);
309 } 312 }
310 313
311 void UserMetricsRecordAction(PP_Var action) { 314 void UserMetricsRecordAction(PP_Var action) {
312 scoped_refptr<ppapi::StringVar> action_str( 315 scoped_refptr<ppapi::StringVar> action_str(
313 ppapi::StringVar::FromPPVar(action)); 316 ppapi::StringVar::FromPPVar(action));
314 if (action_str) 317 if (action_str)
315 RenderThread::Get()->RecordUserMetrics(action_str->value()); 318 RenderThread::Get()->RecordUserMetrics(action_str->value());
316 } 319 }
317 320
318 void HasUnsupportedFeature(PP_Instance instance_id) { 321 void HasUnsupportedFeature(PP_Instance instance_id) {
319 webkit::ppapi::PluginInstance* instance = 322 webkit::ppapi::PluginInstance* instance =
320 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 323 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
321 if (!instance) 324 if (!instance)
322 return; 325 return;
323 326
324 // Only want to show an info bar if the pdf is the whole tab. 327 // Only want to show an info bar if the pdf is the whole tab.
325 if (!instance->IsFullPagePlugin()) 328 if (!instance->IsFullPagePlugin())
326 return; 329 return;
327 330
328 WebView* view = instance->container()->element().document().frame()->view(); 331 WebView* view = instance->container()->element().document().frame()->view();
329 content::RenderView* render_view = content::RenderView::FromWebView(view); 332 content::RenderView* render_view = content::RenderView::FromWebView(view);
330 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature( 333 render_view->Send(new ChromeViewHostMsg_PDFHasUnsupportedFeature(
331 render_view->GetRoutingId())); 334 render_view->GetRoutingId()));
332 } 335 }
333 336
334 void SaveAs(PP_Instance instance_id) { 337 void SaveAs(PP_Instance instance_id) {
335 webkit::ppapi::PluginInstance* instance = 338 webkit::ppapi::PluginInstance* instance =
336 webkit::ppapi::ResourceTracker::Get()->GetInstance(instance_id); 339 HostGlobals::Get()->host_resource_tracker()->GetInstance(instance_id);
337 if (!instance) 340 if (!instance)
338 return; 341 return;
339 instance->delegate()->SaveURLAs(instance->plugin_url()); 342 instance->delegate()->SaveURLAs(instance->plugin_url());
340 } 343 }
341 344
342 const PPB_PDF ppb_pdf = { 345 const PPB_PDF ppb_pdf = {
343 &GetLocalizedString, 346 &GetLocalizedString,
344 &GetResourceImage, 347 &GetResourceImage,
345 &GetFontFileWithFallback, 348 &GetFontFileWithFallback,
346 &GetFontTableForPrivateFontFile, 349 &GetFontTableForPrivateFontFile,
347 &SearchString, 350 &SearchString,
348 &DidStartLoading, 351 &DidStartLoading,
349 &DidStopLoading, 352 &DidStopLoading,
350 &SetContentRestriction, 353 &SetContentRestriction,
351 &HistogramPDFPageCount, 354 &HistogramPDFPageCount,
352 &UserMetricsRecordAction, 355 &UserMetricsRecordAction,
353 &HasUnsupportedFeature, 356 &HasUnsupportedFeature,
354 &SaveAs 357 &SaveAs
355 }; 358 };
356 359
357 // static 360 // static
358 const PPB_PDF* PPB_PDF_Impl::GetInterface() { 361 const PPB_PDF* PPB_PDF_Impl::GetInterface() {
359 return &ppb_pdf; 362 return &ppb_pdf;
360 } 363 }
361 364
362 } // namespace chrome 365 } // namespace chrome
363 366
OLDNEW
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | content/ppapi_plugin/ppapi_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698