Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Move resource(_util*) under a new browser folder #570

Merged
merged 1 commit into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 42 additions & 31 deletions appshell/resource.h → appshell/browser/resource.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

Expand All @@ -10,7 +10,7 @@
#define IDC_STATIC -1

#define BINARY 256

#define IDC_MYICON 2
#define IDD_CEFCLIENT_DIALOG 102
#define IDS_APP_TITLE 103
#define IDD_ABOUTBOX 103
Expand All @@ -19,6 +19,7 @@
#define IDI_CEFCLIENT 107
#define IDI_SMALL 108
#define IDC_CEFCLIENT 109
#define IDS_OSR_WIDGET_CLASS 110
#define IDR_MAINFRAME 128
#define IDC_NAV_BACK 200
#define IDC_NAV_FORWARD 201
Expand Down Expand Up @@ -90,39 +91,49 @@
#define IDB_RESTORE_HOVER_BUTTON_2_5X 358
#define IDB_RESTORE_PRESSED_BUTTON_2_5X 359

#define IDS_BINDING 1000
#define IDS_DIALOGS 1001
#define IDS_LOGO 1002
#define IDS_LOGOBALL 1003
#define IDS_LOCALSTORAGE 1004
#define IDS_XMLHTTPREQUEST 1005
#define IDS_DOMACCESS 1006
#define IDS_APPSHELL_EXTENSIONS 1007

#define ID_WARN_CONSOLEMESSAGE 32000
#define ID_WARN_DOWNLOADCOMPLETE 32001
#define ID_WARN_DOWNLOADERROR 32002
#define ID_TESTS_GETSOURCE 32760
#define ID_TESTS_GETTEXT 32761
#define ID_TESTS_POPUP 32762
#define ID_TESTS_REQUEST 32763
#define ID_TESTS_SCHEME_HANDLER 32764
#define ID_TESTS_LOCALSTORAGE 32765
#define ID_TESTS_ACCELERATED2DCANVAS 32766
#define ID_TESTS_ACCELERATEDLAYERS 32767
#define ID_TESTS_WEBGL 32768
#define ID_TESTS_HTML5VIDEO 32769
#define ID_TESTS_XMLHTTPREQUEST 32770
#define ID_TESTS_DRAGDROP 32771
#define ID_TESTS_GEOLOCATION 32772
#define ID_TESTS_BINDING 32773
#define ID_TESTS_DIALOGS 32774
#define ID_TESTS_PLUGIN_INFO 32775
#define ID_TESTS_DOM_ACCESS 32776
#define ID_QUIT 32500
#define ID_FIND 32501
#define ID_TESTS_FIRST 32700
#define ID_TESTS_GETSOURCE 32700
#define ID_TESTS_GETTEXT 32701
#define ID_TESTS_OTHER_TESTS 32702
#define ID_TESTS_PLUGIN_INFO 32703
#define ID_TESTS_WINDOW_NEW 32704
#define ID_TESTS_WINDOW_POPUP 32705
#define ID_TESTS_PRINT 32706
#define ID_TESTS_REQUEST 32707
#define ID_TESTS_TRACING_BEGIN 32708
#define ID_TESTS_TRACING_END 32709
#define ID_TESTS_ZOOM_IN 32710
#define ID_TESTS_ZOOM_OUT 32711
#define ID_TESTS_ZOOM_RESET 32712
#define ID_TESTS_OSR_FPS 32713
#define ID_TESTS_OSR_DSF 32714
#define ID_TESTS_PRINT_TO_PDF 32715
#define ID_TESTS_LAST 32715

#define IDM_CLOSE 32777

// Avoid files associated with MacOS
#define _X86_
#define IDS_BINDING_HTML 1000
#define IDS_DIALOGS_HTML 1001
#define IDS_LOCALSTORAGE_HTML 1002
#define IDS_LOGO_PNG 1003
#define IDS_OSRTEST_HTML 1004
#define IDS_OTHER_TESTS_HTML 1005
#define IDS_PDF_HTML 1006
#define IDS_PDF_PDF 1007
#define IDS_PERFORMANCE_HTML 1008
#define IDS_PERFORMANCE2_HTML 1009
#define IDS_PREFERENCES_HTML 1010
#define IDS_RESPONSE_FILTER_HTML 1011
#define IDS_TRANSPARENCY_HTML 1012
#define IDS_URLREQUEST_HTML 1013
#define IDS_WINDOW_HTML 1014
#define IDS_XMLHTTPREQUEST_HTML 1015
#define IDS_APPSHELL_EXTENSIONS 1016

// Next default values for new objects
//
Expand All @@ -132,6 +143,6 @@
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32774
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#define _APS_NEXT_SYMED_VALUE 111
#endif
#endif
37 changes: 37 additions & 0 deletions appshell/browser/resource_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#ifndef CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_
#pragma once

#include <string>
#include "include/cef_stream.h"

#if defined(OS_WIN)
#include "include/wrapper/cef_resource_manager.h"
#endif

namespace client {

#if defined(OS_POSIX)
// Returns the directory containing resource files.
bool GetResourceDir(std::string& dir);
#endif

// Retrieve a resource as a string.
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);

// Retrieve a resource as a steam reader.
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);

#if defined(OS_WIN)
// Create a new provider for loading binary resources.
CefResourceManager::Provider* CreateBinaryResourceProvider(
const std::string& url_path);
#endif

} // namespace client

#endif // CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_
35 changes: 35 additions & 0 deletions appshell/browser/resource_util_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "appshell/browser/resource_util.h"

#include <stdio.h>
#include <string.h>
#include <unistd.h>

namespace client {

bool GetResourceDir(std::string& dir) {
char buff[1024];

// Retrieve the executable path.
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len == -1)
return false;

buff[len] = 0;

// Remove the executable name from the path.
char* pos = strrchr(buff, '/');
if (!pos)
return false;

// Add "files" to the path.
strcpy(pos+1, "files"); // NOLINT(runtime/printf)
dir = std::string(buff);
return true;
}

} // namespace client
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
// Copyright (c) 2013 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "appshell/browser/resource_util.h"

#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include "resource_util.h"
#include "include/cef_stream.h"

#include "include/base/cef_logging.h"

namespace client {

namespace {

bool AmIBundled() {
// Implementation adapted from Chromium's base/mac/foundation_util.mm
ProcessSerialNumber psn = {0, kCurrentProcess};

FSRef fsref;
OSStatus pbErr;
if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
DCHECK(false);
NOTREACHED();
return false;
}

FSCatalogInfo info;
OSErr fsErr;
if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
NULL, NULL, NULL)) != noErr) {
DCHECK(false);
NOTREACHED();
return false;
}

return (info.nodeFlags & kFSNodeIsDirectoryMask);
}

} // namespace

bool GetResourceDir(std::string& dir) {
// Implementation adapted from Chromium's base/base_path_mac.mm
if (AmIBundled()) {
// Implementation adapted from Chromium's base/base_path_mac.mm
if (AmIBundled()) {
// Retrieve the executable directory.
uint32_t pathSize = 0;
_NSGetExecutablePath(NULL, &pathSize);
if (pathSize > 0) {
if (pathSize > 0) {
dir.resize(pathSize);
_NSGetExecutablePath(const_cast<char*>(dir.c_str()), &pathSize);
}
Expand All @@ -52,46 +57,9 @@ bool GetResourceDir(std::string& dir) {
return true;
} else {
// TODO: Provide unbundled path
DCHECK(false);
NOTIMPLEMENTED();
return false;
}
}

bool ReadFileToString(const char* path, std::string& data) {
// Implementation adapted from base/file_util.cc
FILE* file = fopen(path, "rb");
if (!file)
return false;

char buf[1 << 16];
size_t len;
while ((len = fread(buf, 1, sizeof(buf), file)) > 0)
data.append(buf, len);
fclose(file);

return true;
}

} // namespace

bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
std::string path;
if (!GetResourceDir(path))
return false;

path.append("/");
path.append(resource_name);

return ReadFileToString(path.c_str(), resource_data);
}

CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
std::string path;
if (!GetResourceDir(path))
return NULL;

path.append("/");
path.append(resource_name);

return CefStreamReader::CreateForFile(path);
}
} // namespace client
64 changes: 64 additions & 0 deletions appshell/browser/resource_util_posix.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#include "appshell/browser/resource_util.h"

#include <stdio.h>

namespace client {

namespace {

bool FileExists(const char* path) {
FILE* f = fopen(path, "rb");
if (f) {
fclose(f);
return true;
}
return false;
}

bool ReadFileToString(const char* path, std::string& data) {
// Implementation adapted from base/file_util.cc
FILE* file = fopen(path, "rb");
if (!file)
return false;

char buf[1 << 16];
size_t len;
while ((len = fread(buf, 1, sizeof(buf), file)) > 0)
data.append(buf, len);
fclose(file);

return true;
}

} // namespace

bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
std::string path;
if (!GetResourceDir(path))
return false;

path.append("/");
path.append(resource_name);

return ReadFileToString(path.c_str(), resource_data);
}

CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
std::string path;
if (!GetResourceDir(path))
return NULL;

path.append("/");
path.append(resource_name);

if (!FileExists(path.c_str()))
return NULL;

return CefStreamReader::CreateForFile(path);
}

} // namespace client
Loading