Permalink
Browse files

Initial commit

  • Loading branch information...
aroben committed Mar 13, 2013
0 parents commit e451d9212179197b88abeb752602de3859bb1765
@@ -0,0 +1,2 @@
/brightray.xcodeproj/
/build/
@@ -0,0 +1,3 @@
[submodule "vendor/libchromiumcontent"]
path = vendor/libchromiumcontent
url = https://github.com/aroben/libchromiumcontent
@@ -0,0 +1,19 @@
Copyright (c) 2013 Adam Roben <adam@roben.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,27 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,34 @@
# Brightray

Brightray is a static library that makes
[libchromiumcontent](https://github.com/aroben/libchromiumcontent) easier to
use in applications.

## Using it in your app

See [brightray_example](https://github.com/aroben/brightray_example) for a
sample application written using Brightray.

## Development

### One-time setup

You must previously have built and uploaded libchromiumcontent using its
`script/upload` script.

$ script/bootstrap http://base.url.com/used/by/script/upload

### Building

$ script/build

Building Brightray on its own isn’t all that interesting, since it’s just a
static library. Building it into an application (like
[brightray_example](https://github.com/aroben/brightray_example)) is the only
way to test it.

## License

In general, everything is covered by the [`LICENSE`](LICENSE) file. Some files
specify at the top that they are covered by the
[`LICENSE-CHROMIUM`](LICENSE-CHROMIUM) file instead.
@@ -0,0 +1,47 @@
{
'includes': [
'brightray.gypi',
],
'targets': [
{
'target_name': 'brightray',
'type': 'static_library',
'include_dirs': [
'<(libchromiumcontent_include_dir)',
],
'direct_dependent_settings': {
'include_dirs': [
'<(libchromiumcontent_include_dir)',
],
},
'sources': [
'browser/browser_client.cc',
'browser/browser_client.h',
'browser/browser_context.cc',
'browser/browser_context.h',
'browser/browser_main_parts.cc',
'browser/browser_main_parts.h',
'browser/browser_main_parts_mac.mm',
'browser/mac/bry_application.h',
'browser/mac/bry_application.mm',
'browser/network_delegate.cc',
'browser/network_delegate.h',
'browser/url_request_context_getter.cc',
'browser/url_request_context_getter.h',
'common/main_delegate.cc',
'common/main_delegate.h',
'common/main_delegate_mac.mm',
],
'conditions': [
['OS=="mac"', {
'link_settings': {
'libraries': [
'libchromiumcontent.dylib',
'$(SDKROOT)/System/Library/Frameworks/AppKit.framework',
],
},
}],
],
},
],
}
@@ -0,0 +1,39 @@
{
'variables': {
'libchromiumcontent_dir': 'vendor/download/libchromiumcontent',
'libchromiumcontent_library_dir': '<(libchromiumcontent_dir)/Release',
'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/include',
'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)',
},
'target_defaults': {
'defines': [
'NDEBUG',
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11',
'CLANG_CXX_LIBRARY': 'libstdc++',
'COMBINE_HIDPI_IMAGES': 'YES',
'GCC_ENABLE_CPP_RTTI': 'NO',
'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'RUN_CLANG_STATIC_ANALYZER': 'YES',
'SDKROOT': 'macosx10.7',
'WARNING_CFLAGS': [
'-Wall',
'-Wextra',
'-Wno-unused-parameter',
'-Wno-missing-field-initializers',
],
},
'configurations': {
'Debug': {
'xcode_settings': {
'COPY_PHASE_STRIP': 'NO',
'GCC_OPTIMIZATION_LEVEL': '0',
},
},
'Release': {
},
},
},
}
@@ -0,0 +1,35 @@
// Copyright (c) 2012 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-CHROMIUM file.

#include "browser_client.h"

#include "browser_context.h"
#include "browser_main_parts.h"

namespace brightray {

BrowserClient::BrowserClient() {
}

BrowserClient::~BrowserClient() {
}

BrowserContext* BrowserClient::browser_context() {
return browser_main_parts_->browser_context();
}

BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::MainFunctionParams&) {
return new BrowserMainParts;
}

content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(const content::MainFunctionParams& parameters) {
browser_main_parts_.reset(OverrideCreateBrowserMainParts(parameters));
return browser_main_parts_.get();
}

net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers) {
return static_cast<BrowserContext*>(browser_context)->CreateRequestContext(protocol_handlers);
}

}
@@ -0,0 +1,39 @@
// Copyright (c) 2012 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-CHROMIUM file.

#ifndef __brightray__browser_client__
#define __brightray__browser_client__

#include "content/public/browser/content_browser_client.h"

namespace brightray {

class BrowserContext;
class BrowserMainParts;

class BrowserClient : public content::ContentBrowserClient {
public:
BrowserClient();
~BrowserClient();

BrowserContext* browser_context();
BrowserMainParts* browser_main_parts() { return browser_main_parts_.get(); }

protected:
// Subclasses should override this to provide their own BrowserMainParts implementation. The
// lifetime of the returned instance is managed by the caller.
virtual BrowserMainParts* OverrideCreateBrowserMainParts(const content::MainFunctionParams&);

private:
virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE;
virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE;

scoped_ptr<BrowserMainParts> browser_main_parts_;

DISALLOW_COPY_AND_ASSIGN(BrowserClient);
};

}

#endif /* defined(__brightray__browser_client__) */
@@ -0,0 +1,106 @@
// Copyright (c) 2012 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-CHROMIUM file.

#include "browser_context.h"

#include "base/files/file_path.h"
#include "base/path_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/host_resolver.h"
#include "url_request_context_getter.h"

namespace brightray {

class BrowserContext::ResourceContext : public content::ResourceContext {
public:
ResourceContext() : getter_(nullptr) {}

void set_url_request_context_getter(URLRequestContextGetter* getter) {
getter_ = getter;
}

private:
virtual net::HostResolver* GetHostResolver() OVERRIDE {
return getter_->host_resolver();
}

virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
return getter_->GetURLRequestContext();
}

URLRequestContextGetter* getter_;
scoped_ptr<net::HostResolver> host_resolver_;
};

BrowserContext::BrowserContext() : resource_context_(new ResourceContext) {
}

BrowserContext::~BrowserContext() {
}

net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) {
DCHECK(!url_request_getter_);
url_request_getter_.reset(new URLRequestContextGetter(
GetPath(),
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO),
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE),
protocol_handlers));
resource_context_->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}

base::FilePath BrowserContext::GetPath() {
// FIXME: This should be an application-specific path.
base::FilePath path;
CHECK(PathService::Get(base::DIR_APP_DATA, &path));
return path.Append("Brightray");
}

bool BrowserContext::IsOffTheRecord() const {
return false;
}

net::URLRequestContextGetter* BrowserContext::GetRequestContext() {
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}

net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) {
return GetRequestContext();
}

net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() {
return GetRequestContext();
}

net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForRenderProcess(int renderer_child_id) {
return GetRequestContext();
}

net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory) {
return GetRequestContext();
}

content::ResourceContext* BrowserContext::GetResourceContext() {
return resource_context_.get();
}

content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() {
return nullptr;
}

content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionContext() {
return nullptr;
}

content::SpeechRecognitionPreferences* BrowserContext::GetSpeechRecognitionPreferences() {
return nullptr;
}

quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}

}
Oops, something went wrong.

0 comments on commit e451d92

Please sign in to comment.