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

Powered by Google App Engine
This is Rietveld 408576698