Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,479 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2015 University of Szeged. | ||
// Copyright (c) 2015 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 copyright holders 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// Copyright (c) 2015 University of Szeged. | ||
// Copyright (c) 2015 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 "minibrowser/browser/browser_context.h" | ||
|
||
#include "base/command_line.h" | ||
#include "base/environment.h" | ||
#include "base/files/file_util.h" | ||
#include "base/path_service.h" | ||
#include "base/nix/xdg_util.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/storage_partition.h" | ||
#include "content/public/common/content_switches.h" | ||
|
||
MiniBrowserBrowserContext::MiniBrowserResourceContext::MiniBrowserResourceContext() | ||
: getter_(NULL) { | ||
} | ||
|
||
MiniBrowserBrowserContext::MiniBrowserResourceContext::~MiniBrowserResourceContext() { | ||
} | ||
|
||
net::HostResolver* | ||
MiniBrowserBrowserContext::MiniBrowserResourceContext::GetHostResolver() { | ||
CHECK(getter_); | ||
return getter_->host_resolver(); | ||
} | ||
|
||
net::URLRequestContext* | ||
MiniBrowserBrowserContext::MiniBrowserResourceContext::GetRequestContext() { | ||
CHECK(getter_); | ||
return getter_->GetURLRequestContext(); | ||
} | ||
|
||
MiniBrowserBrowserContext::MiniBrowserBrowserContext(bool off_the_record) | ||
: resource_context_(new MiniBrowserResourceContext), | ||
ignore_certificate_errors_(false), | ||
off_the_record_(off_the_record) { | ||
InitWhileIOAllowed(); | ||
} | ||
|
||
MiniBrowserBrowserContext::~MiniBrowserBrowserContext() { | ||
if (resource_context_) { | ||
content::BrowserThread::DeleteSoon( | ||
content::BrowserThread::IO, FROM_HERE, resource_context_.release()); | ||
} | ||
} | ||
|
||
void MiniBrowserBrowserContext::InitWhileIOAllowed() { | ||
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | ||
if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors)) | ||
ignore_certificate_errors_ = true; | ||
|
||
scoped_ptr<base::Environment> env(base::Environment::Create()); | ||
base::FilePath config_dir( | ||
base::nix::GetXDGDirectory(env.get(), | ||
base::nix::kXdgConfigHomeEnvVar, | ||
base::nix::kDotConfigDir)); | ||
path_ = config_dir.Append("minibrowser"); | ||
if (!base::PathExists(path_)) | ||
base::CreateDirectory(path_); | ||
} | ||
|
||
base::FilePath MiniBrowserBrowserContext::GetPath() const { | ||
return path_; | ||
} | ||
|
||
scoped_ptr<content::ZoomLevelDelegate> | ||
MiniBrowserBrowserContext::CreateZoomLevelDelegate( | ||
const base::FilePath& partition_path) { | ||
return scoped_ptr<content::ZoomLevelDelegate>(); | ||
} | ||
|
||
bool MiniBrowserBrowserContext::IsOffTheRecord() const { | ||
return off_the_record_; | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::GetRequestContext() { | ||
return GetDefaultStoragePartition(this)->GetURLRequestContext(); | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::GetRequestContextForRenderProcess( | ||
int renderer_child_id) { | ||
return GetRequestContext(); | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::GetMediaRequestContext() { | ||
return GetRequestContext(); | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::GetMediaRequestContextForRenderProcess( | ||
int renderer_child_id) { | ||
return GetRequestContext(); | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::GetMediaRequestContextForStoragePartition( | ||
const base::FilePath& partition_path, | ||
bool in_memory) { | ||
return GetRequestContext(); | ||
} | ||
|
||
content::ResourceContext* | ||
MiniBrowserBrowserContext::GetResourceContext() { | ||
return resource_context_.get(); | ||
} | ||
|
||
content::DownloadManagerDelegate* | ||
MiniBrowserBrowserContext::GetDownloadManagerDelegate() { | ||
return NULL; | ||
} | ||
|
||
content::BrowserPluginGuestManager* | ||
MiniBrowserBrowserContext::GetGuestManager() { | ||
return NULL; | ||
} | ||
|
||
storage::SpecialStoragePolicy* | ||
MiniBrowserBrowserContext::GetSpecialStoragePolicy() { | ||
return NULL; | ||
} | ||
|
||
content::PushMessagingService* | ||
MiniBrowserBrowserContext::GetPushMessagingService() { | ||
return NULL; | ||
} | ||
|
||
content::SSLHostStateDelegate* | ||
MiniBrowserBrowserContext::GetSSLHostStateDelegate() { | ||
return NULL; | ||
} | ||
|
||
MiniBrowserURLRequestContextGetter* | ||
MiniBrowserBrowserContext::CreateURLRequestContextGetter( | ||
content::ProtocolHandlerMap* protocol_handlers, | ||
content::URLRequestInterceptorScopedVector request_interceptors) { | ||
return new MiniBrowserURLRequestContextGetter( | ||
ignore_certificate_errors_, | ||
GetPath(), | ||
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO), | ||
content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE), | ||
protocol_handlers, | ||
request_interceptors.Pass()); | ||
} | ||
|
||
net::URLRequestContextGetter* | ||
MiniBrowserBrowserContext::CreateRequestContext( | ||
content::ProtocolHandlerMap* protocol_handlers, | ||
content::URLRequestInterceptorScopedVector request_interceptors) { | ||
url_request_getter_ = CreateURLRequestContextGetter( | ||
protocol_handlers, request_interceptors.Pass()); | ||
resource_context_->set_url_request_context_getter(url_request_getter_.get()); | ||
return url_request_getter_.get(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2015 University of Szeged. | ||
// Copyright (c) 2015 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. | ||
|
||
#ifndef MINI_BROWSER_BROWSER_BROWSER_CONTEXT_H_ | ||
#define MINI_BROWSER_BROWSER_BROWSER_CONTEXT_H_ | ||
|
||
#include "base/files/file_path.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "content/public/browser/content_browser_client.h" | ||
#include "content/public/browser/resource_context.h" | ||
#include "minibrowser/browser/net/url_request_context_getter.h" | ||
|
||
class MiniBrowserBrowserContext : public content::BrowserContext { | ||
public: | ||
MiniBrowserBrowserContext(bool off_the_record); | ||
~MiniBrowserBrowserContext() override; | ||
|
||
// BrowserContext implementation. | ||
base::FilePath GetPath() const override; | ||
scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( | ||
const base::FilePath& partition_path) override; | ||
bool IsOffTheRecord() const override; | ||
net::URLRequestContextGetter* GetRequestContext() override; | ||
net::URLRequestContextGetter* GetRequestContextForRenderProcess( | ||
int renderer_child_id) override; | ||
net::URLRequestContextGetter* GetMediaRequestContext() override; | ||
net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( | ||
int renderer_child_id) override; | ||
net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( | ||
const base::FilePath& partition_path, | ||
bool in_memory) override; | ||
content::ResourceContext* GetResourceContext() override; | ||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; | ||
content::BrowserPluginGuestManager* GetGuestManager() override; | ||
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; | ||
content::PushMessagingService* GetPushMessagingService() override; | ||
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; | ||
net::URLRequestContextGetter* CreateRequestContext( | ||
content::ProtocolHandlerMap* protocol_handlers, | ||
content::URLRequestInterceptorScopedVector request_interceptors); | ||
|
||
protected: | ||
// Contains URLRequestContextGetter required for resource loading. | ||
class MiniBrowserResourceContext : public content::ResourceContext { | ||
public: | ||
MiniBrowserResourceContext(); | ||
~MiniBrowserResourceContext() override; | ||
|
||
// ResourceContext implementation: | ||
net::HostResolver* GetHostResolver() override; | ||
net::URLRequestContext* GetRequestContext() override; | ||
|
||
void set_url_request_context_getter(MiniBrowserURLRequestContextGetter* getter) { | ||
getter_ = getter; | ||
} | ||
|
||
private: | ||
MiniBrowserURLRequestContextGetter* getter_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MiniBrowserResourceContext); | ||
}; | ||
|
||
MiniBrowserURLRequestContextGetter* url_request_context_getter() { | ||
return url_request_getter_.get(); | ||
} | ||
|
||
// Used by MiniBrowserBrowserContext to initiate and set different types of | ||
// URLRequestContextGetter. | ||
virtual MiniBrowserURLRequestContextGetter* CreateURLRequestContextGetter( | ||
content::ProtocolHandlerMap* protocol_handlers, | ||
content::URLRequestInterceptorScopedVector request_interceptors); | ||
void set_url_request_context_getter(MiniBrowserURLRequestContextGetter* getter) { | ||
url_request_getter_ = getter; | ||
} | ||
|
||
bool ignore_certificate_errors() const { return ignore_certificate_errors_; } | ||
|
||
scoped_ptr<MiniBrowserResourceContext> resource_context_; | ||
bool ignore_certificate_errors_; | ||
|
||
private: | ||
void InitWhileIOAllowed(); | ||
|
||
bool off_the_record_; | ||
base::FilePath path_; | ||
scoped_refptr<MiniBrowserURLRequestContextGetter> url_request_getter_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MiniBrowserBrowserContext); | ||
}; | ||
|
||
|
||
#endif // MINI_BROWSER_BROWSER_BROWSER_CONTEXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2015 University of Szeged. | ||
// Copyright (c) 2015 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 "minibrowser/browser/browser_main.h" | ||
|
||
#include "base/memory/scoped_ptr.h" | ||
#include "content/public/browser/browser_main_runner.h" | ||
|
||
// Main routine for running as the Browser process. | ||
int BrowserMain( | ||
const content::MainFunctionParams& parameters, | ||
const scoped_ptr<content::BrowserMainRunner>& main_runner) { | ||
int exit_code = main_runner->Initialize(parameters); | ||
|
||
if (exit_code >= 0) | ||
return exit_code; | ||
|
||
exit_code = main_runner->Run(); | ||
|
||
main_runner->Shutdown(); | ||
|
||
return exit_code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2015 University of Szeged. | ||
// Copyright (c) 2015 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. | ||
|
||
#ifndef MINI_BROWSER_BROWSER_BROWSER_MAIN_H_ | ||
#define MINI_BROWSER_BROWSER_BROWSER_MAIN_H_ | ||
|
||
#include "base/memory/scoped_ptr.h" | ||
|
||
namespace content { | ||
class BrowserMainRunner; | ||
struct MainFunctionParams; | ||
} | ||
|
||
int BrowserMain( | ||
const content::MainFunctionParams& parameters, | ||
const scoped_ptr<content::BrowserMainRunner>& main_runner); | ||
|
||
#endif // MINI_BROWSER_BROWSER_BROWSER_MAIN_H_ |
Oops, something went wrong.