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

Unified Diff: content/browser/renderer_host/pepper/pepper_truetype_font_win.cc

Issue 337203003: Move PPB_TrueTypeFont_Dev host from renderer to browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/pepper/pepper_truetype_font_win.cc
diff --git a/content/renderer/pepper/pepper_truetype_font_win.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_win.cc
similarity index 84%
rename from content/renderer/pepper/pepper_truetype_font_win.cc
rename to content/browser/renderer_host/pepper/pepper_truetype_font_win.cc
index 9b8cdb482b030b5d1b2438df71a50b4f6a6dd73c..8e936056205ca31619a290603e7834de6c1a8fcc 100644
--- a/content/renderer/pepper/pepper_truetype_font_win.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/renderer/pepper/pepper_truetype_font.h"
+#include "content/browser/renderer_host/pepper/pepper_truetype_font.h"
#include <windows.h>
#include <set>
@@ -13,7 +13,6 @@
#include "base/sys_byteorder.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
-#include "content/public/renderer/render_thread.h"
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
#include "ppapi/c/pp_errors.h"
@@ -25,24 +24,25 @@ class PepperTrueTypeFontWin : public PepperTrueTypeFont {
public:
explicit PepperTrueTypeFontWin(
const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
- virtual ~PepperTrueTypeFontWin();
// PepperTrueTypeFont overrides.
- virtual bool IsValid() OVERRIDE;
- virtual int32_t Describe(ppapi::proxy::SerializedTrueTypeFontDesc* desc)
- OVERRIDE;
- virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE;
+ virtual bool IsValid() const OVERRIDE;
+ virtual int32_t Describe(
+ ppapi::proxy::SerializedTrueTypeFontDesc* desc) const OVERRIDE;
+ virtual int32_t GetTableTags(std::vector<uint32_t>* tags) const OVERRIDE;
virtual int32_t GetTable(uint32_t table_tag,
int32_t offset,
int32_t max_data_length,
- std::string* data) OVERRIDE;
+ std::string* data) const OVERRIDE;
private:
+ virtual ~PepperTrueTypeFontWin();
+
DWORD GetFontData(HDC hdc,
DWORD table,
DWORD offset,
LPVOID buffer,
- DWORD length);
+ DWORD length) const;
HFONT font_;
piman 2014/06/19 20:03:42 What deletes this? Should this be a ScopedHFONT?
bbudge 2014/06/21 14:12:50 Done.
@@ -87,12 +87,15 @@ PepperTrueTypeFontWin::PepperTrueTypeFontWin(
base::UTF8ToUTF16(desc.family).c_str());
}
-PepperTrueTypeFontWin::~PepperTrueTypeFontWin() {}
+PepperTrueTypeFontWin::~PepperTrueTypeFontWin() {
+}
-bool PepperTrueTypeFontWin::IsValid() { return font_ != NULL; }
+bool PepperTrueTypeFontWin::IsValid() const {
+ return font_ != NULL;
+}
int32_t PepperTrueTypeFontWin::Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
+ ppapi::proxy::SerializedTrueTypeFontDesc* desc) const {
LOGFONT font_desc;
if (!::GetObject(font_, sizeof(LOGFONT), &font_desc))
return PP_ERROR_FAILED;
@@ -137,29 +140,15 @@ DWORD PepperTrueTypeFontWin::GetFontData(HDC hdc,
DWORD table,
DWORD offset,
void* buffer,
- DWORD length) {
+ DWORD length) const {
// If this is a zero byte read, return a successful result.
if (buffer && !length)
return 0;
- DWORD result = ::GetFontData(hdc, table, offset, buffer, length);
- if (result == GDI_ERROR) {
- // The font may not be cached by the OS, causing an attempt to read it in
- // the renderer process to fail. Attempt to pre-cache it.
- LOGFONTW logfont;
- if (!::GetObject(font_, sizeof(LOGFONTW), &logfont))
- return GDI_ERROR;
- RenderThread* render_thread = RenderThread::Get();
- if (!render_thread)
- return GDI_ERROR;
- render_thread->PreCacheFont(logfont);
-
- result = ::GetFontData(hdc, table, offset, buffer, length);
- }
- return result;
+ return ::GetFontData(hdc, table, offset, buffer, length);
}
-int32_t PepperTrueTypeFontWin::GetTableTags(std::vector<uint32_t>* tags) {
+int32_t PepperTrueTypeFontWin::GetTableTags(std::vector<uint32_t>* tags) const {
base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL));
if (!hdc)
return PP_ERROR_FAILED;
@@ -202,7 +191,7 @@ int32_t PepperTrueTypeFontWin::GetTableTags(std::vector<uint32_t>* tags) {
int32_t PepperTrueTypeFontWin::GetTable(uint32_t table_tag,
int32_t offset,
int32_t max_data_length,
- std::string* data) {
+ std::string* data) const {
base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL));
if (!hdc)
return PP_ERROR_FAILED;
@@ -237,9 +226,12 @@ int32_t PepperTrueTypeFontWin::GetTable(uint32_t table_tag,
} // namespace
// static
-PepperTrueTypeFont* PepperTrueTypeFont::Create(
+scoped_refptr<PepperTrueTypeFont> PepperTrueTypeFont::Create(
const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- return new PepperTrueTypeFontWin(desc);
+ scoped_refptr<PepperTrueTypeFont> font = new PepperTrueTypeFontWin(desc);
+ if (!font->IsValid())
+ font = NULL;
+ return font;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698